diff --git a/COPYRIGHT b/COPYRIGHT index 6dc5d16b4687..8130d57c1aaf 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -4,7 +4,7 @@ The compilation of software known as FreeBSD is distributed under the following terms: -Copyright (c) 1992-2011 The FreeBSD Project. All rights reserved. +Copyright (c) 1992-2012 The FreeBSD Project. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions diff --git a/Makefile.inc1 b/Makefile.inc1 index 122df0a4c4f4..59e74c328643 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -59,8 +59,6 @@ SUBDIR+=games .endif .if ${MK_CDDL} != "no" SUBDIR+=cddl -.else -NO_CTF=1 .endif SUBDIR+=gnu include .if ${MK_KERBEROS} != "no" @@ -239,7 +237,7 @@ BMAKE= MAKEOBJDIRPREFIX=${WORLDTMP} \ BOOTSTRAPPING=${OSRELDATE} \ SSP_CFLAGS= \ -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \ - -DNO_PIC -DWITHOUT_PROFILE -DNO_SHARED \ + -DNO_PIC -DNO_PROFILE -DNO_SHARED \ -DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF # build-tools stage @@ -278,7 +276,6 @@ LIB32CPUFLAGS= -march=i686 -mmmx -msse -msse2 .else LIB32CPUFLAGS= -march=${TARGET_CPUTYPE} .endif -LIB32CPUFLAGS+= -mfancy-math-387 LIB32WMAKEENV= MACHINE=i386 MACHINE_ARCH=i386 \ MACHINE_CPU="i686 mmx sse sse2" \ LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32" \ @@ -438,7 +435,7 @@ _libraries: @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; \ ${WMAKE} -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \ - -DWITHOUT_MAN -DWITHOUT_PROFILE libraries + -DWITHOUT_MAN -DNO_PROFILE libraries _depend: @echo @echo "--------------------------------------------------------------" @@ -1218,6 +1215,9 @@ _startup_libs+= lib/csu/${MACHINE_CPUARCH} _startup_libs+= gnu/lib/libgcc _startup_libs+= lib/libcompiler_rt _startup_libs+= lib/libc +.if ${MK_LIBCPLUSPLUS} != "no" +_startup_libs+= lib/libcxxrt +.endif gnu/lib/libgcc__L: lib/libc__L @@ -1230,13 +1230,12 @@ _prebuild_libs= ${_kerberos5_lib_libasn1} ${_kerberos5_lib_libhdb} \ ${_lib_libgssapi} ${_lib_libipx} \ lib/libkiconv lib/libkvm lib/liblzma lib/libmd \ lib/ncurses/ncurses lib/ncurses/ncursesw \ - lib/libopie ${_lib_libthr} \ + lib/libopie lib/libpam ${_lib_libthr} \ lib/libradius lib/libsbuf lib/libtacplus \ ${_cddl_lib_libumem} \ lib/libutil ${_lib_libypclnt} lib/libz lib/msun \ ${_secure_lib_libcrypto} ${_secure_lib_libssh} \ - ${_secure_lib_libssl} \ - lib/libpam + ${_secure_lib_libssl} .if ${MK_LIBTHR} != "no" _lib_libthr= lib/libthr @@ -1319,12 +1318,12 @@ ${_lib}__PL: .PHONY cd ${.CURDIR}/${_lib}; \ ${MAKE} DIRPRFX=${_lib}/ obj; \ ${MAKE} DIRPRFX=${_lib}/ depend; \ - ${MAKE} -DWITHOUT_PROFILE -DNO_PIC DIRPRFX=${_lib}/ all; \ - ${MAKE} -DWITHOUT_PROFILE -DNO_PIC DIRPRFX=${_lib}/ install + ${MAKE} -DNO_PROFILE -DNO_PIC DIRPRFX=${_lib}/ all; \ + ${MAKE} -DNO_PROFILE -DNO_PIC DIRPRFX=${_lib}/ install .endif .endfor -.for _lib in ${_startup_libs} ${_prebuild_libs} ${_generic_libs} +.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs} ${_lib}__L: .PHONY .if exists(${.CURDIR}/${_lib}) ${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \ @@ -1336,6 +1335,17 @@ ${_lib}__L: .PHONY .endif .endfor +# libpam is special: we need to build static PAM modules before +# static PAM library, and dynamic PAM library before dynamic PAM +# modules. +lib/libpam__L: .PHONY + ${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \ + cd ${.CURDIR}/lib/libpam; \ + ${MAKE} DIRPRFX=lib/libpam/ obj; \ + ${MAKE} DIRPRFX=lib/libpam/ depend; \ + ${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \ + ${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install + _prereq_libs: ${_prereq_libs:S/$/__PL/} _startup_libs: ${_startup_libs:S/$/__L/} _prebuild_libs: ${_prebuild_libs:S/$/__L/} @@ -1542,7 +1552,7 @@ XDEV_CPUTYPE?=${TARGET_CPUTYPE} .endif NOFUN=-DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \ - -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_PROFILE \ + -DWITHOUT_MAN -DWITHOUT_NLS -DNO_PROFILE \ -DWITHOUT_KERBEROS -DWITHOUT_RESCUE -DNO_WARNS \ TARGET=${XDEV} TARGET_ARCH=${XDEV_ARCH} \ CPUTYPE=${XDEV_CPUTYPE} @@ -1626,4 +1636,7 @@ _xi-links: ln -sf ../../${XDTP}/usr/bin/$$i \ ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \ done +.else +xdev xdev-buil xdev-install: + @echo "*** Error: Both XDEV and XDEV_ARCH must be defined for \"${.TARGET}\" target" .endif diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc index 8744e2f70368..2fa99559bdf1 100644 --- a/ObsoleteFiles.inc +++ b/ObsoleteFiles.inc @@ -38,6 +38,21 @@ # xargs -n1 | sort | uniq -d; # done +# 20111214: eventtimers(7) moved to eventtimers(4) +OLD_FILES+=usr/share/man/man7/eventtimers.7.gz +# 20111125: amd(4) removed +OLD_FILES+=usr/share/man/man4/amd.4.gz +# 20111125: libodialog removed +OLD_FILES+=usr/lib/libodialog.a +OLD_FILES+=usr/lib/libodialog.so +OLD_LIBS+=usr/lib/libodialog.so.7 +OLD_FILES+=usr/lib/libodialog_p.a +.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64" +OLD_FILES+=usr/lib32/libodialog.a +OLD_FILES+=usr/lib32/libodialog.so +OLD_LIBS+=usr/lib32/libodialog.so.7 +OLD_FILES+=usr/lib32/libodialog_p.a +.endif # 20110930: sysinstall removed OLD_FILES+=usr/sbin/sysinstall OLD_FILES+=usr/share/man/man8/sysinstall.8.gz diff --git a/UPDATING b/UPDATING index dc17383414ef..575a037f9317 100644 --- a/UPDATING +++ b/UPDATING @@ -22,6 +22,21 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 10.x IS SLOW: machines to maximize performance. (To disable malloc debugging, run ln -s aj /etc/malloc.conf.) +20111215: + The carp(4) facility has been changed significantly. Configuration + of the CARP protocol via ifconfig(8) has changed, as well as format + of CARP events submitted to devd(8) has changed. See manual pages + for more information. The arpbalance feature of carp(4) is currently + not supported anymore. + + Size of struct in_aliasreq, struct in6_aliasreq has changed. User + utilities using SIOCAIFADDR, SIOCAIFADDR_IN6, e.g. ifconfig(8), + need to be recompiled. + +20111122: + The acpi_wmi(4) status device /dev/wmistat has been renamed to + /dev/wmistat0. + 20111108: The option VFS_ALLOW_NONMPSAFE option has been added in order to explicitely support non-MPSAFE filesystems. diff --git a/bin/chio/chio.c b/bin/chio/chio.c index 16e88007011a..9bb11d75f325 100644 --- a/bin/chio/chio.c +++ b/bin/chio/chio.c @@ -87,7 +87,7 @@ static int do_voltag(const char *, int, char **); #endif /* Valid changer element types. */ -const struct element_type elements[] = { +static const struct element_type elements[] = { { "drive", CHET_DT }, { "picker", CHET_MT }, { "portal", CHET_IE }, @@ -97,7 +97,7 @@ const struct element_type elements[] = { }; /* Valid commands. */ -const struct changer_command commands[] = { +static const struct changer_command commands[] = { { "exchange", do_exchange }, { "getpicker", do_getpicker }, { "ielem", do_ielem }, @@ -112,7 +112,7 @@ const struct changer_command commands[] = { }; /* Valid special words. */ -const struct special_word specials[] = { +static const struct special_word specials[] = { { "inv", SW_INVERT }, { "inv1", SW_INVERT1 }, { "inv2", SW_INVERT2 }, diff --git a/bin/ed/io.c b/bin/ed/io.c index 85ba0de0812e..63fe10c489eb 100644 --- a/bin/ed/io.c +++ b/bin/ed/io.c @@ -53,7 +53,8 @@ read_file(char *fn, long n) errmsg = "cannot close input file"; return ERR; } - fprintf(stdout, !scripted ? "%lu\n" : "", size); + if (!scripted) + fprintf(stdout, "%lu\n", size); return current_addr - n; } @@ -161,7 +162,8 @@ write_file(char *fn, const char *mode, long n, long m) errmsg = "cannot close output file"; return ERR; } - fprintf(stdout, !scripted ? "%lu\n" : "", size); + if (!scripted) + fprintf(stdout, "%lu\n", size); return n ? m - n + 1 : 0; } diff --git a/bin/ed/main.c b/bin/ed/main.c index fad1866d5344..f414d40f17d2 100644 --- a/bin/ed/main.c +++ b/bin/ed/main.c @@ -192,9 +192,10 @@ main(volatile int argc, char ** volatile argv) fputs("?\n", stderr); errmsg = "warning: file modified"; if (!isatty(0)) { - fprintf(stderr, garrulous ? - "script, line %d: %s\n" : - "", lineno, errmsg); + if (garrulous) + fprintf(stderr, + "script, line %d: %s\n", + lineno, errmsg); quit(2); } clearerr(stdin); @@ -225,27 +226,26 @@ main(volatile int argc, char ** volatile argv) fputs("?\n", stderr); /* give warning */ errmsg = "warning: file modified"; if (!isatty(0)) { - fprintf(stderr, garrulous ? - "script, line %d: %s\n" : - "", lineno, errmsg); + if (garrulous) + fprintf(stderr, "script, line %d: %s\n", + lineno, errmsg); quit(2); } break; case FATAL: - if (!isatty(0)) - fprintf(stderr, garrulous ? - "script, line %d: %s\n" : "", - lineno, errmsg); - else - fprintf(stderr, garrulous ? "%s\n" : "", - errmsg); + if (!isatty(0)) { + if (garrulous) + fprintf(stderr, "script, line %d: %s\n", + lineno, errmsg); + } else if (garrulous) + fprintf(stderr, "%s\n", errmsg); quit(3); default: fputs("?\n", stderr); if (!isatty(0)) { - fprintf(stderr, garrulous ? - "script, line %d: %s\n" : "", - lineno, errmsg); + if (garrulous) + fprintf(stderr, "script, line %d: %s\n", + lineno, errmsg); quit(2); } break; diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 1787b400507f..ca5e0b210ead 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -29,7 +29,7 @@ .\" @(#)ps.1 8.3 (Berkeley) 4/18/94 .\" $FreeBSD$ .\" -.Dd October 30, 2011 +.Dd November 22, 2011 .Dt PS 1 .Os .Sh NAME @@ -98,12 +98,6 @@ The default output format includes, for each process, the process' ID, controlling terminal, state, CPU time (including both user and system time) and associated command. .Pp -The process file system (see -.Xr procfs 5 ) -should be mounted when -.Nm -is executed, otherwise not all information will be available. -.Pp The options are as follows: .Bl -tag -width indent .It Fl a @@ -686,9 +680,6 @@ attempts to automatically determine the terminal width. .Bl -tag -width ".Pa /boot/kernel/kernel" -compact .It Pa /boot/kernel/kernel default system namelist -.It Pa /proc -the mount point of -.Xr procfs 5 .El .Sh SEE ALSO .Xr kill 1 , diff --git a/bin/ps/ps.c b/bin/ps/ps.c index eb2d6301dc7b..2171bc1e5b87 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -130,7 +130,6 @@ struct listinfo { } l; }; -static int check_procfs(void); static int addelem_gid(struct listinfo *, const char *); static int addelem_pid(struct listinfo *, const char *); static int addelem_tty(struct listinfo *, const char *); @@ -410,14 +409,6 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - /* - * If the user specified ps -e then they want a copy of the process - * environment kvm_getenvv(3) attempts to open /proc//mem. - * Check to make sure that procfs is mounted on /proc, otherwise - * print a warning informing the user that output will be incomplete. - */ - if (needenv == 1 && check_procfs() == 0) - warnx("Process environment requires procfs(5)"); /* * If there arguments after processing all the options, attempt * to treat them as a list of process ids. @@ -1360,18 +1351,6 @@ kludge_oldps_options(const char *optlist, char *origval, const char *nextarg) return (newopts); } -static int -check_procfs(void) -{ - struct statfs mnt; - - if (statfs("/proc", &mnt) < 0) - return (0); - if (strcmp(mnt.f_fstypename, "procfs") != 0) - return (0); - return (1); -} - static void usage(void) { diff --git a/bin/sh/eval.c b/bin/sh/eval.c index d5da7d3022c3..e3b93a3e61ea 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -89,7 +89,7 @@ int oexitstatus; /* saved exit status */ static void evalloop(union node *, int); static void evalfor(union node *, int); -static void evalcase(union node *, int); +static union node *evalcase(union node *, int); static void evalsubshell(union node *, int); static void evalredir(union node *, int); static void expredir(union node *); @@ -256,7 +256,7 @@ evaltree(union node *n, int flags) evalfor(n, flags & ~EV_EXIT); break; case NCASE: - evalcase(n, flags); + next = evalcase(n, flags); break; case NDEFUN: defun(n->narg.text, n->narg.next); @@ -343,8 +343,6 @@ evalfor(union node *n, int flags) for (argp = n->nfor.args ; argp ; argp = argp->narg.next) { oexitstatus = exitstatus; expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); - if (evalskip) - goto out; } *arglist.lastp = NULL; @@ -364,13 +362,12 @@ evalfor(union node *n, int flags) } } loopnest--; -out: popstackmark(&smark); } -static void +static union node * evalcase(union node *n, int flags) { union node *cp; @@ -383,26 +380,24 @@ evalcase(union node *n, int flags) oexitstatus = exitstatus; exitstatus = 0; expandarg(n->ncase.expr, &arglist, EXP_TILDE); - for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) { + for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) { for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) { if (casematch(patp, arglist.list->text)) { + popstackmark(&smark); while (cp->nclist.next && cp->type == NCLISTFALLTHRU) { - if (evalskip != 0) - break; evaltree(cp->nclist.body, flags & ~EV_EXIT); + if (evalskip != 0) + return (NULL); cp = cp->nclist.next; } - if (evalskip == 0) { - evaltree(cp->nclist.body, flags); - } - goto out; + return (cp->nclist.body); } } } -out: popstackmark(&smark); + return (NULL); } @@ -983,7 +978,6 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) memout.nextc = memout.buf; memout.bufsize = 64; mode |= REDIR_BACKQ; - cmdentry.special = 0; } savecmdname = commandname; savetopfile = getcurrentfile(); @@ -1004,7 +998,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) * If there is no command word, redirection errors should * not be fatal but assignment errors should. */ - if (argc == 0 && !(flags & EV_BACKCMD)) + if (argc == 0) cmdentry.special = 1; listsetvar(cmdenviron, cmdentry.special ? 0 : VNOSET); if (argc > 0) diff --git a/bin/sh/exec.c b/bin/sh/exec.c index 044fc3031d16..468f940de201 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -100,6 +100,7 @@ static void tryexec(char *, char **, char **); static void printentry(struct tblentry *, int); static struct tblentry *cmdlookup(const char *, int); static void delete_cmd_entry(void); +static void addcmdentry(const char *, struct cmdentry *); @@ -593,7 +594,7 @@ delete_cmd_entry(void) * the same name. */ -void +static void addcmdentry(const char *name, struct cmdentry *entry) { struct tblentry *cmdp; diff --git a/bin/sh/exec.h b/bin/sh/exec.h index 31f11c09c287..0948421f40be 100644 --- a/bin/sh/exec.h +++ b/bin/sh/exec.h @@ -70,7 +70,6 @@ void find_command(const char *, struct cmdentry *, int, const char *); int find_builtin(const char *, int *); void hashcd(void); void changepath(const char *); -void addcmdentry(const char *, struct cmdentry *); void defun(const char *, union node *); int unsetfunc(const char *); int typecmd_impl(int, char **, int, const char *); diff --git a/bin/sh/expand.c b/bin/sh/expand.c index ea8d78d26b83..d43cc359c66b 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -113,6 +113,7 @@ static void expmeta(char *, char *); static void addfname(char *); static struct strlist *expsort(struct strlist *); static struct strlist *msort(struct strlist *, int); +static int patmatch(const char *, const char *, int); static char *cvtnum(int, char *); static int collate_range_cmp(wchar_t, wchar_t); @@ -1186,6 +1187,7 @@ expmeta(char *enddir, char *name) int atend; int matchdot; int esc; + int namlen; metaflag = 0; start = name; @@ -1284,17 +1286,22 @@ expmeta(char *enddir, char *name) if (dp->d_name[0] == '.' && ! matchdot) continue; if (patmatch(start, dp->d_name, 0)) { - if (enddir + dp->d_namlen + 1 > expdir_end) + namlen = dp->d_namlen; + if (enddir + namlen + 1 > expdir_end) continue; - memcpy(enddir, dp->d_name, dp->d_namlen + 1); + memcpy(enddir, dp->d_name, namlen + 1); if (atend) addfname(expdir); else { - if (enddir + dp->d_namlen + 2 > expdir_end) + if (dp->d_type != DT_UNKNOWN && + dp->d_type != DT_DIR && + dp->d_type != DT_LNK) continue; - enddir[dp->d_namlen] = '/'; - enddir[dp->d_namlen + 1] = '\0'; - expmeta(enddir + dp->d_namlen + 1, endname); + if (enddir + namlen + 2 > expdir_end) + continue; + enddir[namlen] = '/'; + enddir[namlen + 1] = '\0'; + expmeta(enddir + namlen + 1, endname); } } } @@ -1435,61 +1442,67 @@ match_charclass(const char *p, wchar_t chr, const char **end) * Returns true if the pattern matches the string. */ -int +static int patmatch(const char *pattern, const char *string, int squoted) { const char *p, *q, *end; + const char *bt_p, *bt_q; char c; wchar_t wc, wc2; p = pattern; q = string; + bt_p = NULL; + bt_q = NULL; for (;;) { switch (c = *p++) { case '\0': - goto breakloop; + if (*q != '\0') + goto backtrack; + return 1; case CTLESC: if (squoted && *q == CTLESC) q++; if (*q++ != *p++) - return 0; + goto backtrack; break; case CTLQUOTEMARK: continue; case '?': if (squoted && *q == CTLESC) q++; - if (localeisutf8) - wc = get_wc(&q); - else - wc = (unsigned char)*q++; - if (wc == '\0') + if (*q == '\0') return 0; + if (localeisutf8) { + wc = get_wc(&q); + /* + * A '?' does not match invalid UTF-8 but a + * '*' does, so backtrack. + */ + if (wc == 0) + goto backtrack; + } else + wc = (unsigned char)*q++; break; case '*': c = *p; while (c == CTLQUOTEMARK || c == '*') c = *++p; - if (c != CTLESC && c != CTLQUOTEMARK && - c != '?' && c != '*' && c != '[') { - while (*q != c) { - if (squoted && *q == CTLESC && - q[1] == c) - break; - if (*q == '\0') - return 0; - if (squoted && *q == CTLESC) - q++; - q++; - } - } - do { - if (patmatch(p, q, squoted)) - return 1; - if (squoted && *q == CTLESC) - q++; - } while (*q++ != '\0'); - return 0; + /* + * If the pattern ends here, we know the string + * matches without needing to look at the rest of it. + */ + if (c == '\0') + return 1; + /* + * First try the shortest match for the '*' that + * could work. We can forget any earlier '*' since + * there is no way having it match more characters + * can help us, given that we are already here. + */ + bt_p = p; + bt_q = q; + break; case '[': { const char *endp; int invert, found; @@ -1501,7 +1514,7 @@ patmatch(const char *pattern, const char *string, int squoted) for (;;) { while (*endp == CTLQUOTEMARK) endp++; - if (*endp == '\0') + if (*endp == 0) goto dft; /* no matching ] */ if (*endp == CTLESC) endp++; @@ -1516,12 +1529,14 @@ patmatch(const char *pattern, const char *string, int squoted) found = 0; if (squoted && *q == CTLESC) q++; - if (localeisutf8) - chr = get_wc(&q); - else - chr = (unsigned char)*q++; - if (chr == '\0') + if (*q == '\0') return 0; + if (localeisutf8) { + chr = get_wc(&q); + if (chr == 0) + goto backtrack; + } else + chr = (unsigned char)*q++; c = *p++; do { if (c == CTLQUOTEMARK) @@ -1562,21 +1577,34 @@ patmatch(const char *pattern, const char *string, int squoted) } } while ((c = *p++) != ']'); if (found == invert) - return 0; + goto backtrack; break; } dft: default: if (squoted && *q == CTLESC) q++; - if (*q++ != c) + if (*q == '\0') return 0; + if (*q++ == c) + break; +backtrack: + /* + * If we have a mismatch (other than hitting the end + * of the string), go back to the last '*' seen and + * have it match one additional character. + */ + if (bt_p == NULL) + return 0; + if (squoted && *bt_q == CTLESC) + bt_q++; + if (*bt_q == '\0') + return 0; + bt_q++; + p = bt_p; + q = bt_q; break; } } -breakloop: - if (*q != '\0') - return 0; - return 1; } diff --git a/bin/sh/expand.h b/bin/sh/expand.h index 5029552fe284..8114e2bf7ac6 100644 --- a/bin/sh/expand.h +++ b/bin/sh/expand.h @@ -60,6 +60,5 @@ union node; void expandhere(union node *, int); void expandarg(union node *, struct arglist *, int); void expari(int); -int patmatch(const char *, const char *, int); void rmescapes(char *); int casematch(union node *, const char *); diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c index 4619baf7856e..e29bcab8ff1e 100644 --- a/bin/sh/histedit.c +++ b/bin/sh/histedit.c @@ -70,6 +70,8 @@ int displayhist; static FILE *el_in, *el_out, *el_err; static char *fc_replace(const char *, char *, char *); +static int not_fcnumber(const char *); +static int str_to_event(const char *, int); /* * Set history and editing status. Called whenever the status may @@ -425,7 +427,7 @@ fc_replace(const char *s, char *p, char *r) return (dest); } -int +static int not_fcnumber(const char *s) { if (s == NULL) @@ -435,7 +437,7 @@ not_fcnumber(const char *s) return (!is_number(s)); } -int +static int str_to_event(const char *str, int last) { HistEvent he; diff --git a/bin/sh/input.c b/bin/sh/input.c index c8b1a4533d14..671bbdf38e91 100644 --- a/bin/sh/input.c +++ b/bin/sh/input.c @@ -106,6 +106,7 @@ EditLine *el; /* cookie for editline package */ static void pushfile(void); static int preadfd(void); +static void popstring(void); #ifdef mkinit INCLUDE "input.h" @@ -372,7 +373,7 @@ pushstring(char *s, int len, void *ap) INTON; } -void +static void popstring(void) { struct strpush *sp = parsefile->strpush; diff --git a/bin/sh/input.h b/bin/sh/input.h index abbb2ce5fc59..92aba45b2681 100644 --- a/bin/sh/input.h +++ b/bin/sh/input.h @@ -53,7 +53,6 @@ int preadbuffer(void); int preadateof(void); void pungetc(void); void pushstring(char *, int, void *); -void popstring(void); void setinputfile(const char *, int); void setinputfd(int, int); void setinputstring(char *, int); diff --git a/bin/sh/main.c b/bin/sh/main.c index e6c8a209de5b..5eb12e07dacb 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -79,6 +79,7 @@ int rootshell; struct jmploc main_handler; int localeisutf8, initial_localeisutf8; +static void cmdloop(int); static void read_profile(char *); static char *find_dot_file(char *); @@ -184,7 +185,7 @@ main(int argc, char *argv[]) * loop; it turns on prompting if the shell is interactive. */ -void +static void cmdloop(int top) { union node *n; diff --git a/bin/sh/main.h b/bin/sh/main.h index 6d4cc4a9b992..3c48e330218a 100644 --- a/bin/sh/main.h +++ b/bin/sh/main.h @@ -38,4 +38,3 @@ extern int rootshell; /* true if we aren't a child of the main shell */ extern struct jmploc main_handler; /* top level exception handler */ void readcmdfile(const char *); -void cmdloop(int); diff --git a/bin/sh/mksyntax.c b/bin/sh/mksyntax.c index 9aa7450772b7..07dc2f188e50 100644 --- a/bin/sh/mksyntax.c +++ b/bin/sh/mksyntax.c @@ -219,16 +219,16 @@ main(int argc __unused, char **argv __unused) add("`", "CBQUOTE"); add("$", "CVAR"); add("}", "CENDVAR"); - /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */ - add("!*?[=~:/-", "CCTL"); + /* ':/' for tilde expansion, '-^]' for [a\-x] pattern ranges */ + add("!*?[]=~:/-^", "CCTL"); print("dqsyntax"); init(); fputs("\n/* syntax table used when in single quotes */\n", cfile); add("\n", "CNL"); add("\\", "CSBACK"); add("'", "CENDQUOTE"); - /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */ - add("!*?[=~:/-", "CCTL"); + /* ':/' for tilde expansion, '-^]' for [a\-x] pattern ranges */ + add("!*?[]=~:/-^", "CCTL"); print("sqsyntax"); init(); fputs("\n/* syntax table used when in arithmetic */\n", cfile); diff --git a/bin/sh/myhistedit.h b/bin/sh/myhistedit.h index 9a649ecccddf..e31276daf4b0 100644 --- a/bin/sh/myhistedit.h +++ b/bin/sh/myhistedit.h @@ -39,6 +39,4 @@ extern int displayhist; void histedit(void); void sethistsize(const char *); void setterm(const char *); -int not_fcnumber(const char *); -int str_to_event(const char *, int); diff --git a/bin/sh/mystring.c b/bin/sh/mystring.c index 53d703d55b59..67617ec04876 100644 --- a/bin/sh/mystring.c +++ b/bin/sh/mystring.c @@ -43,7 +43,6 @@ __FBSDID("$FreeBSD$"); * * equal(s1, s2) Return true if strings are equal. * scopy(from, to) Copy a string. - * scopyn(from, to, n) Like scopy, but checks for overflow. * number(s) Convert a string of digits to an integer. * is_number(s) Return true if s is a string of digits. */ @@ -66,24 +65,6 @@ char nullstr[1]; /* zero length string */ */ -/* - * scopyn - copy a string from "from" to "to", truncating the string - * if necessary. "To" is always nul terminated, even if - * truncation is performed. "Size" is the size of "to". - */ - -void -scopyn(const char *from, char *to, int size) -{ - - while (--size > 0) { - if ((*to++ = *from++) == '\0') - return; - } - *to = '\0'; -} - - /* * prefix -- see if pfx is a prefix of string. */ diff --git a/bin/sh/mystring.h b/bin/sh/mystring.h index 1b27a1b008a8..5a6e3d8a4001 100644 --- a/bin/sh/mystring.h +++ b/bin/sh/mystring.h @@ -35,7 +35,6 @@ #include -void scopyn(const char *, char *, int); int prefix(const char *, const char *); int number(const char *); int is_number(const char *); diff --git a/bin/stty/modes.c b/bin/stty/modes.c index cc18d2cd4959..2bf211e427d7 100644 --- a/bin/stty/modes.c +++ b/bin/stty/modes.c @@ -52,7 +52,7 @@ struct modes { * The code in optlist() depends on minus options following regular * options, i.e. "foo" must immediately precede "-foo". */ -struct modes cmodes[] = { +static const struct modes cmodes[] = { { "cs5", CS5, CSIZE }, { "cs6", CS6, CSIZE }, { "cs7", CS7, CSIZE }, @@ -94,7 +94,7 @@ struct modes cmodes[] = { { NULL, 0, 0 }, }; -struct modes imodes[] = { +static const struct modes imodes[] = { { "ignbrk", IGNBRK, 0 }, { "-ignbrk", 0, IGNBRK }, { "brkint", BRKINT, 0 }, @@ -130,7 +130,7 @@ struct modes imodes[] = { { NULL, 0, 0 }, }; -struct modes lmodes[] = { +static const struct modes lmodes[] = { { "echo", ECHO, 0 }, { "-echo", 0, ECHO }, { "echoe", ECHOE, 0 }, @@ -182,7 +182,7 @@ struct modes lmodes[] = { { NULL, 0, 0 }, }; -struct modes omodes[] = { +static const struct modes omodes[] = { { "opost", OPOST, 0 }, { "-opost", 0, OPOST }, { "litout", 0, OPOST }, @@ -209,7 +209,7 @@ struct modes omodes[] = { int msearch(char ***argvp, struct info *ip) { - struct modes *mp; + const struct modes *mp; char *name; name = **argvp; diff --git a/bin/test/test.c b/bin/test/test.c index 394988e387ab..96aa9f54970f 100644 --- a/bin/test/test.c +++ b/bin/test/test.c @@ -119,7 +119,7 @@ enum token_types { }; static struct t_op { - const char *op_text; + char op_text[4]; short op_num, op_type; } const ops [] = { {"-r", FILRD, UNOP}, @@ -162,7 +162,7 @@ static struct t_op { {"-o", BOR, BBINOP}, {"(", LPAREN, PAREN}, {")", RPAREN, PAREN}, - {0, 0, 0} + {"", 0, 0} }; static struct t_op const *t_wp_op; @@ -427,7 +427,7 @@ t_lex(char *s) t_wp_op = NULL; return EOI; } - while (op->op_text) { + while (*op->op_text) { if (strcmp(s, op->op_text) == 0) { if (((op->op_type == UNOP || op->op_type == BUNOP) && isunopoperand()) || @@ -456,7 +456,7 @@ isunopoperand(void) if (nargc == 2) return parenlevel == 1 && strcmp(s, ")") == 0; t = *(t_wp + 2); - while (op->op_text) { + while (*op->op_text) { if (strcmp(s, op->op_text) == 0) return op->op_type == BINOP && (parenlevel == 0 || t[0] != ')' || t[1] != '\0'); @@ -478,7 +478,7 @@ islparenoperand(void) return parenlevel == 1 && strcmp(s, ")") == 0; if (nargc != 3) return 0; - while (op->op_text) { + while (*op->op_text) { if (strcmp(s, op->op_text) == 0) return op->op_type == BINOP; op++; diff --git a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c index 63721abc7132..a2766593607b 100644 --- a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c +++ b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c @@ -671,9 +671,12 @@ link_prog(dtrace_cmd_t *dcp) p[0] = '\0'; /* strip .d suffix */ (void) snprintf(dcp->dc_ofile, sizeof (dcp->dc_ofile), "%s.o", basename(dcp->dc_arg)); + } else if (g_cmdc > 1) { + (void) snprintf(dcp->dc_ofile, sizeof (dcp->dc_ofile), + "d.out.%td", dcp - g_cmdv); } else { (void) snprintf(dcp->dc_ofile, sizeof (dcp->dc_ofile), - g_cmdc > 1 ? "%s.%d" : "%s", "d.out", (int)(dcp - g_cmdv)); + "d.out"); } if (dtrace_program_link(g_dtp, dcp->dc_prog, DTRACE_D_PROBES, diff --git a/cddl/contrib/opensolaris/cmd/zdb/zdb.8 b/cddl/contrib/opensolaris/cmd/zdb/zdb.8 index 1ed18038bb84..f84bf9acd927 100644 --- a/cddl/contrib/opensolaris/cmd/zdb/zdb.8 +++ b/cddl/contrib/opensolaris/cmd/zdb/zdb.8 @@ -1,65 +1,79 @@ '\" te +.\" Copyright (c) 2011, Martin Matuska . +.\" All Rights Reserved. +.\" +.\" The contents of this file are subject to the terms of the +.\" Common Development and Distribution License (the "License"). +.\" You may not use this file except in compliance with the License. +.\" +.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +.\" or http://www.opensolaris.org/os/licensing. +.\" See the License for the specific language governing permissions +.\" and limitations under the License. +.\" +.\" When distributing Covered Code, include this CDDL HEADER in each +.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. +.\" If applicable, add the following below this CDDL HEADER, with the +.\" fields enclosed by brackets "[]" replaced with your own identifying +.\" information: Portions Copyright [yyyy] [name of copyright owner] +.\" .\" Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved. -.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. -.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. -.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.\" Portions Copyright 2011 Martin Matuska -.TH ZDB 8 "Oct 31, 2005" -.SH NAME -zdb \- ZFS debugger -.SH SYNOPSIS -.LP -.nf -\fBzdb\fR \fIpool\fR -.fi - -.SH DESCRIPTION -.sp -.LP -The \fBzdb\fR command is used by support engineers to diagnose failures and -gather statistics. Since the \fBZFS\fR file system is always consistent on disk -and is self-repairing, \fBzdb\fR should only be run under the direction by a -support engineer. -.sp -.LP -If no arguments are specified, \fBzdb\fR, performs basic consistency checks on -the pool and associated datasets, and report any problems detected. -.sp -.LP +.\" +.\" $FreeBSD$ +.\" +.Dd November 26, 2011 +.Dt ZDB 8 +.Os +.Sh NAME +.Nm zdb +.Nd ZFS debugger +.Sh SYNOPSIS +.Nm +.Ar pool +.Sh DESCRIPTION +The +.Nm +command is used by support engineers to diagnose failures and +gather statistics. Since the +.Tn ZFS +file system is always consistent on disk and is self-repairing, +.Nm +should only be run under the direction by a support engineer. +.Pp +If no arguments are specified, +.Nm +performs basic consistency checks on the pool and associated datasets, and +report any problems detected. +.Nm Any options supported by this command are internal to Sun and subject to change at any time. -.SH EXIT STATUS -.sp -.LP +.Sh EXIT STATUS The following exit values are returned: -.sp -.ne 2 -.na -\fB\fB0\fR\fR -.ad -.RS 5n +.Bl -tag -offset 2n -width 2n +.It 0 The pool is consistent. -.RE - -.sp -.ne 2 -.na -\fB\fB1\fR\fR -.ad -.RS 5n +.It 1 An error was detected. -.RE - -.sp -.ne 2 -.na -\fB\fB2\fR\fR -.ad -.RS 5n +.It 2 Invalid command line options were specified. -.RE - -.SH SEE ALSO -.sp -.LP -zfs(8), zpool(8) +.El +.Sh SEE ALSO +.Xr zfs 8 , +.Xr zpool 8 +.Sh AUTHORS +This manual page is a +.Xr mdoc 7 +reimplementation of the +.Tn OpenSolaris +manual page +.Em zdb(1M) , +modified and customized for +.Fx +and licensed under the +.Tn Common Development and Distribution License +.Pq Tn CDDL . +.Pp +The +.Xr mdoc 7 +implementation of this manual page was initially written by +.An Martin Matuska Aq mm@FreeBSD.org . diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs.8 b/cddl/contrib/opensolaris/cmd/zfs/zfs.8 index c32bfa2b79a5..d1793adca445 100644 --- a/cddl/contrib/opensolaris/cmd/zfs/zfs.8 +++ b/cddl/contrib/opensolaris/cmd/zfs/zfs.8 @@ -1,561 +1,543 @@ '\" te -.\" Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. -.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. -.\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with -.\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. -.\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with -.\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] +.\" Copyright (c) 2011, Martin Matuska . +.\" All Rights Reserved. +.\" +.\" The contents of this file are subject to the terms of the +.\" Common Development and Distribution License (the "License"). +.\" You may not use this file except in compliance with the License. +.\" +.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +.\" or http://www.opensolaris.org/os/licensing. +.\" See the License for the specific language governing permissions +.\" and limitations under the License. +.\" +.\" When distributing Covered Code, include this CDDL HEADER in each +.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. +.\" If applicable, add the following below this CDDL HEADER, with the +.\" fields enclosed by brackets "[]" replaced with your own identifying +.\" information: Portions Copyright [yyyy] [name of copyright owner] +.\" +.\" Copyright (c) 2010, Sun Microsystems, Inc. All Rights Reserved. .\" Copyright 2011 Nexenta Systems, Inc. All rights reserved. -.\" Copyright 2011 by Delphix. All rights reserved. -.\" Portions Copyright 2011 Pawel Jakub Dawidek -.\" Portions Copyright 2011 Martin Matuska -.TH ZFS 8 "September 24, 2009" FreeBSD -.SH NAME -zfs \- configures ZFS file systems -.SH SYNOPSIS -.LP -.nf -\fBzfs\fR [\fB-?\fR] -.fi - -.LP -.nf -\fBzfs\fR \fBcreate\fR [\fB-p\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... \fIfilesystem\fR -.fi - -.LP -.nf -\fBzfs\fR \fBcreate\fR [\fB-ps\fR] [\fB-b\fR \fIblocksize\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... \fB-V\fR \fIsize\fR \fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBdestroy\fR [\fB-rRf\fR] \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBdestroy\fR [\fB-rRd\fR] \fIsnapshot\fR -.fi - -.LP -.nf -\fBzfs\fR \fBsnapshot\fR [\fB-r\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR]... - \fIfilesystem@snapname\fR|\fIvolume@snapname\fR -.fi - -.LP -.nf -\fBzfs\fR \fBrollback\fR [\fB-rRf\fR] \fIsnapshot\fR -.fi - -.LP -.nf -\fBzfs\fR \fBclone\fR [\fB-p\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... \fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBpromote\fR \fIclone-filesystem\fR -.fi - -.LP -.nf -\fBzfs\fR \fBrename\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR - \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR -.fi - -.LP -.nf -\fBzfs\fR \fBrename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBrename\fR \fB-r\fR \fIsnapshot\fR \fIsnapshot\fR -.fi - -.LP -.nf -\fBzfs\fR \fBrename\fR \fB-u\fR [\fB-p\fR] \fIfilesystem\fR \fIfilesystem\fR -.fi - -.LP -.nf -\fBzfs\fR \fBlist\fR [\fB-r\fR|\fB-d\fR \fIdepth\fR][\fB-H\fR][\fB-o\fR \fIproperty\fR[,...]] [\fB-t\fR \fItype\fR[,...]] - [\fB-s\fR \fIproperty\fR] ... [\fB-S\fR \fIproperty\fR] ... [\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR] ... -.fi - -.LP -.nf -\fBzfs\fR \fBset\fR \fIproperty\fR=\fIvalue\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ... -.fi - -.LP -.nf -\fBzfs\fR \fBget\fR [\fB-r\fR|\fB-d\fR \fIdepth\fR][\fB-Hp\fR][\fB-o\fR \fIfield\fR[,...]] [\fB-s\fR \fIsource\fR[,...]] - "\fIall\fR" | \fIproperty\fR[,...] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ... -.fi - -.LP -.nf -\fBzfs\fR \fBinherit\fR [\fB-r\fR] \fIproperty\fR \fIfilesystem\fR|\fIvolume|snapshot\fR ... -.fi - -.LP -.nf -\fBzfs\fR \fBupgrade\fR [\fB-v\fR] -.fi - -.LP -.nf -\fBzfs\fR \fBupgrade\fR [\fB-r\fR] [\fB-V\fR \fIversion\fR] \fB-a\fR | \fIfilesystem\fR -.fi - -.LP -.nf -\fBzfs\fR \fBuserspace\fR [\fB-niHp\fR] [\fB-o\fR \fIfield\fR[,...]] [\fB-sS\fR \fIfield\fR] ... - [\fB-t\fR \fItype\fR [,...]] \fIfilesystem\fR|\fIsnapshot\fR -.fi - -.LP -.nf -\fBzfs\fR \fBgroupspace\fR [\fB-niHp\fR] [\fB-o\fR \fIfield\fR[,...]] [\fB-sS\fR \fIfield\fR] ... - [\fB-t\fR \fItype\fR [,...]] \fIfilesystem\fR|\fIsnapshot\fR -.fi - -.LP -.nf -\fBzfs\fR \fBmount\fR -.fi - -.LP -.nf -\fBzfs\fR \fBmount\fR [\fB-vO\fR] [\fB-o \fIoptions\fR\fR] \fB-a\fR | \fIfilesystem\fR -.fi - -.LP -.nf -\fBzfs\fR \fBunmount\fR [\fB-f\fR] \fB-a\fR | \fIfilesystem\fR|\fImountpoint\fR -.fi - -.LP -.nf -\fBzfs\fR \fBshare\fR \fB-a\fR | \fIfilesystem\fR -.fi - -.LP -.nf -\fBzfs\fR \fBunshare\fR \fB-a\fR \fIfilesystem\fR|\fImountpoint\fR -.fi - -.LP -.nf -\fBzfs\fR \fBsend\fR [\fB-vR\fR] [\fB-\fR[\fBiI\fR] \fIsnapshot\fR] \fIsnapshot\fR -.fi - -.LP -.nf -\fBzfs\fR \fBreceive\fR [\fB-vnFu\fR] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR -.fi - -.LP -.nf -\fBzfs\fR \fBreceive\fR [\fB-vnFu\fR] \fB-d\fR \fIfilesystem\fR -.fi - -.LP -.nf -\fBzfs\fR \fBallow\fR \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBallow\fR [\fB-ldug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...] \fIperm\fR|\fI@setname\fR[,...] - \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBallow\fR [\fB-ld\fR] \fB-e\fR \fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBallow\fR \fB-c\fR \fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBallow\fR \fB-s\fR @\fIsetname\fR \fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBunallow\fR [\fB-rldug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...] [\fIperm\fR|@\fIsetname\fR[,... ]] - \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBunallow\fR [\fB-rld\fR] \fB-e\fR [\fIperm\fR|@\fIsetname\fR[,... ]] \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBunallow\fR [\fB-r\fR] \fB-c\fR [\fIperm\fR|@\fIsetname\fR[ ... ]] \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBunallow\fR [\fB-r\fR] \fB-s\fR @\fIsetname\fR [\fIperm\fR|@\fIsetname\fR[,... ]] \fIfilesystem\fR|\fIvolume\fR -.fi - -.LP -.nf -\fBzfs\fR \fBhold\fR [\fB-r\fR] \fItag\fR \fIsnapshot\fR... -.fi - -.LP -.nf -\fBzfs\fR \fBholds\fR [\fB-r\fR] \fIsnapshot\fR... -.fi - -.LP -.nf -\fBzfs\fR \fBrelease\fR [\fB-r\fR] \fItag\fR \fIsnapshot\fR... -.fi - -.LP -.nf -\fBzfs\fR \fBjail\fR \fIjailid\fR \fIfilesystem\fR -.fi - -.LP -.nf -\fBzfs\fR \fBunjail\fR \fIjailid\fR \fIfilesystem\fR -.fi - -.SH DESCRIPTION -.sp -.LP -The \fBzfs\fR command configures \fBZFS\fR datasets within a \fBZFS\fR storage -pool, as described in \fBzpool\fR(8). A dataset is identified by a unique path -within the \fBZFS\fR namespace. For example: -.sp -.in +2 -.nf -pool/{filesystem,volume,snapshot} -.fi -.in -2 -.sp - -.sp -.LP -where the maximum length of a dataset name is \fBMAXNAMELEN\fR (256 bytes). -.sp -.LP +.\" Copyright (c) 2011 by Delphix. All rights reserved. +.\" Copyright (c) 2011, Pawel Jakub Dawidek +.\" +.\" $FreeBSD$ +.\" +.Dd November 26, 2011 +.Dt ZFS 8 +.Os +.Sh NAME +.Nm zfs +.Nd configures ZFS file systems +.Sh SYNOPSIS +.Nm +.Op Fl \&? +.Nm +.Cm create +.Op Fl p +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... filesystem +.Nm +.Cm create +.Op Fl ps +.Op Fl b Ar blocksize +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... +.Fl V +.Ar size volume +.Nm +.Cm destroy +.Op Fl fnpRrv +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm destroy +.Op Fl dnpRrv +.Sm off +.Ar snapshot +.Ns Op % Ns Ar snapname +.Ns Op , Ns Ar ... +.Sm on +.Nm +.Cm snapshot +.Op Fl r +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... filesystem@snapname Ns | Ns Ar volume@snapname +.Nm +.Cm rollback +.Op Fl rRf +.Ar snapshot +.Nm +.Cm clone +.Op Fl p +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... snapshot filesystem Ns | Ns Ar volume +.Nm +.Cm promote +.Ar clone-filesystem +.Nm +.Cm rename +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Nm +.Cm rename +.Fl p +.Ar filesystem Ns | Ns Ar volume +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm rename +.Fl r +.Ar snapshot snapshot +.Nm +.Cm rename +.Fl u +.Op Fl p +.Ar filesystem filesystem +.Nm +.Cm list +.Op Fl r Ns | Ns Fl d Ar depth +.Op Fl H +.Op Fl o Ar property Ns Op , Ns Ar ... +.Op Fl t Ar type Ns Op , Ns Ar ... +.Op Fl s Ar property +.Ar ... +.Op Fl S Ar property +.Ar ... +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Nm +.Cm set +.Ar property Ns = Ns Ar value +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Nm +.Cm get +.Op Fl r Ns | Ns Fl d Ar depth +.Op Fl Hp +.Op Fl o Ar all | field Ns Op , Ns Ar ... +.Op Fl s Ar source Ns Op , Ns Ar ... +.Ar all | property Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Nm +.Cm inherit +.Op Fl rS +.Ar property +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Nm +.Cm upgrade +.Op Fl v +.Nm +.Cm upgrade +.Op Fl r +.Op Fl V Ar version +.Fl a | Ar filesystem +.Nm +.Cm userspace +.Op Fl niHp +.Op Fl o Ar field Ns Op , Ns Ar ... +.Op Fl sS Ar field +.Ar ... +.Op Fl t Ar type Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar snapshot +.Nm +.Cm groupspace +.Op Fl niHp +.Op Fl o Ar field Ns Op , Ns Ar ... +.Op Fl sS Ar field +.Ar ... +.Op Fl t Ar type Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar snapshot +.Nm +.Cm mount +.Nm +.Cm mount +.Op Fl vO +.Op Fl o Ar property Ns Op , Ns Ar ... +.Fl a | Ar filesystem +.Nm +.Cm unmount +.Op Fl f +.Fl a | Ar filesystem Ns | Ns Ar mountpoint +.Nm +.Cm share +.Fl a | Ar filesystem +.Nm +.Cm unshare +.Fl a | Ar filesystem Ns | Ns Ar mountpoint +.Nm +.Cm send +.Op Fl DnPpRrv +.Op Fl i Ar snapshot | Fl I Ar snapshot +.Ar snapshot +.Nm +.Cm receive +.Op Fl vnFu +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Nm +.Cm receive +.Op Fl vnFu +.Op Fl d | e +.Ar filesystem +.Nm +.Cm allow +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm allow +.Op Fl ldug +.Cm everyone Ns | Ns Ar user Ns | Ns Ar group Ns Op , Ns Ar ... +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm allow +.Op Fl ld +.Fl e +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm allow +.Fl c +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm allow +.Fl s +.Ar @setname +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm unallow +.Op Fl rldug +.Cm everyone Ns | Ns Ar user Ns | Ns Ar group Ns Op , Ns Ar ... +.Op Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm unallow +.Op Fl rld +.Fl e +.Op Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm unallow +.Op Fl r +.Fl c +.Op Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm unallow +.Op Fl r +.Fl s +.Ar @setname +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Nm +.Cm hold +.Op Fl r +.Ar tag snapshot ... +.Nm +.Cm holds +.Op Fl r +.Ar snapshot ... +.Nm +.Cm release +.Op Fl r +.Ar tag snapshot ... +.Nm +.Cm diff +.Op Fl FHt +.Ar snapshot +.Op Ar snapshot Ns | Ns Ar filesystem +.Nm +.Cm jail +.Ar jailid filesystem +.Nm +.Cm unjail +.Ar jailid filesystem +.Sh DESCRIPTION +The +.Nm +command configures +.Tn ZFS +datasets within a +.Tn ZFS +storage pool, as described in +.Xr zpool 8 . +A dataset is identified by a unique path within the +.Tn ZFS +namespace. For example: +.Bd -ragged -offset 4n +.No pool/ Ns Brq filesystem,volume,snapshot +.Ed +.Pp +where the maximum length of a dataset name is +.Dv MAXNAMELEN +(256 bytes). +.Pp A dataset can be one of the following: -.sp -.ne 2 -.na -\fB\fIfile system\fR\fR -.ad -.sp .6 -.RS 4n -A \fBZFS\fR dataset of type \fBfilesystem\fR can be mounted within the standard -system namespace and behaves like other file systems. While \fBZFS\fR file -systems are designed to be \fBPOSIX\fR compliant, known issues exist that -prevent compliance in some cases. Applications that depend on standards -conformance might fail due to nonstandard behavior when checking file system -free space. -.RE - -.sp -.ne 2 -.na -\fB\fIvolume\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -hang -width 12n +.It Sy file system +A +.Tn ZFS +dataset of type +.Em filesystem +can be mounted within the standard system namespace and behaves like other file +systems. While +.Tn ZFS +file systems are designed to be +.Tn POSIX +compliant, known issues exist that prevent compliance in some cases. +Applications that depend on standards conformance might fail due to nonstandard +behavior when checking file system free space. +.It Sy volume A logical volume exported as a raw or block device. This type of dataset should only be used under special circumstances. File systems are typically used in most environments. -.RE - -.sp -.ne 2 -.na -\fB\fIsnapshot\fR\fR -.ad -.sp .6 -.RS 4n +.It Sy snapshot A read-only version of a file system or volume at a given point in time. It is -specified as \fIfilesystem@name\fR or \fIvolume@name\fR. -.RE - -.SS "ZFS File System Hierarchy" -.sp -.LP -A \fBZFS\fR storage pool is a logical collection of devices that provide space -for datasets. A storage pool is also the root of the \fBZFS\fR file system -hierarchy. -.sp -.LP +specified as +.Em filesystem@name +or +.Em volume@name . +.El +.Ss ZFS File System Hierarchy +A +.Tn ZFS +storage pool is a logical collection of devices that provide space for +datasets. A storage pool is also the root of the +.Tn ZFS +file system hierarchy. +.Pp The root of the pool can be accessed as a file system, such as mounting and unmounting, taking snapshots, and setting properties. The physical storage -characteristics, however, are managed by the \fBzpool\fR(8) command. -.sp -.LP -See \fBzpool\fR(8) for more information on creating and administering pools. -.SS "Snapshots" -.sp -.LP +characteristics, however, are managed by the +.Xr zpool 8 +command. +.Pp +See +.Xr zpool 8 +for more information on creating and administering pools. +.Ss Snapshots A snapshot is a read-only copy of a file system or volume. Snapshots can be created extremely quickly, and initially consume no additional space within the pool. As data within the active dataset changes, the snapshot consumes more data than would otherwise be shared with the active dataset. -.sp -.LP +.Pp Snapshots can have arbitrary names. Snapshots of volumes can be cloned or rolled back, but cannot be accessed independently. -.sp -.LP -File system snapshots can be accessed under the \fB\&.zfs/snapshot\fR directory -in the root of the file system. Snapshots are automatically mounted on demand -and may be unmounted at regular intervals. The visibility of the \fB\&.zfs\fR -directory can be controlled by the \fBsnapdir\fR property. -.SS "Clones" -.sp -.LP +.Pp +File system snapshots can be accessed under the +.Pa \&.zfs/snapshot +directory in the root of the file system. Snapshots are automatically mounted +on demand and may be unmounted at regular intervals. The visibility of the +.Pa \&.zfs +directory can be controlled by the +.Sy snapdir +property. +.Ss Clones A clone is a writable volume or file system whose initial contents are the same as another dataset. As with snapshots, creating a clone is nearly instantaneous, and initially consumes no additional space. -.sp -.LP +.Pp Clones can only be created from a snapshot. When a snapshot is cloned, it creates an implicit dependency between the parent and child. Even though the clone is created somewhere else in the dataset hierarchy, the original snapshot -cannot be destroyed as long as a clone exists. The \fBorigin\fR property -exposes this dependency, and the \fBdestroy\fR command lists any such -dependencies, if they exist. -.sp -.LP +cannot be destroyed as long as a clone exists. The +.Sy origin +property exposes this dependency, and the +.Cm destroy +command lists any such dependencies, if they exist. +.Pp The clone parent-child dependency relationship can be reversed by using the -\fBpromote\fR subcommand. This causes the "origin" file system to become a -clone of the specified file system, which makes it possible to destroy the file -system that the clone was created from. -.SS "Mount Points" -.sp -.LP -Creating a \fBZFS\fR file system is a simple operation, so the number of file -systems per system is likely to be numerous. To cope with this, \fBZFS\fR +.Cm promote +subcommand. This causes the "origin" file system to become a clone of the +specified file system, which makes it possible to destroy the file system that +the clone was created from. +.Ss Mount Points +Creating a +.Tn ZFS +file system is a simple operation, so the number of file systems per system is +likely to be numerous. To cope with this, +.Tn ZFS automatically manages mounting and unmounting file systems without the need to -edit the \fB/etc/fstab\fR file. All automatically managed file systems are -mounted by \fBZFS\fR at boot time. -.sp -.LP -By default, file systems are mounted under \fB/\fIpath\fR\fR, where \fIpath\fR -is the name of the file system in the \fBZFS\fR namespace. Directories are -created and destroyed as needed. -.sp -.LP -A file system can also have a mount point set in the \fBmountpoint\fR property. -This directory is created as needed, and \fBZFS\fR automatically mounts the -file system when the \fBzfs mount -a\fR command is invoked (without editing -\fB/etc/fstab\fR). The \fBmountpoint\fR property can be inherited, so if -\fBpool/home\fR has a mount point of \fB/export/stuff\fR, then -\fBpool/home/user\fR automatically inherits a mount point of -\fB/export/stuff/user\fR. -.sp -.LP -A file system \fBmountpoint\fR property of \fBnone\fR prevents the file system -from being mounted. -.sp -.LP -If needed, \fBZFS\fR file systems can also be managed with traditional tools -(\fBmount\fR, \fBumount\fR, \fB/etc/fstab\fR). If a file system's mount point -is set to \fBlegacy\fR, \fBZFS\fR makes no attempt to manage the file system, -and the administrator is responsible for mounting and unmounting the file -system. -.SS "Jails" -.sp -.LP -A \fBZFS\fR dataset can be attached to a jail by using the \fBzfs\fR -\fBjail\fR subcommand. You cannot attach a dataset to one jail and the -children of the same dataset to another jails. To allow managment of the -dataset from within a jail, the "\fBjailed\fR" property has to be set. -The \fBquota\fR property cannot be changed from within a jail. -.sp -.LP -A \fBZFS\fR dataset can be detached from a jail using the \fBzfs\fR -\fBunjail\fR subcommand. -.sp -.LP -After a dataset is attached to a jail and the \fBjailed\fR property is set, -a jailed file system cannot be mounted outside the jail, since the jail -administrator might have set the mount point to an unacceptable value. -.SS "Native Properties" -.sp -.LP +edit the +.Pa /etc/fstab +file. All automatically managed file systems are mounted by +.Tn ZFS +at boot time. +.Pp +By default, file systems are mounted under +.Pa /path , +where +.Ar path +is the name of the file system in the +.Tn ZFS +namespace. Directories are created and destroyed as needed. +.Pp +A file system can also have a mount point set in the +.Sy mountpoint +property. This directory is created as needed, and +.Tn ZFS +automatically mounts the file system when the +.Qq Nm Cm mount Fl a +command is invoked (without editing +.Pa /etc/fstab ) . +The +.Sy mountpoint +property can be inherited, so if +.Em pool/home +has a mount point of +.Pa /home , +then +.Em pool/home/user +automatically inherits a mount point of +.Pa /home/user . +.Pp +A file system +.Sy mountpoint +property of +.Cm none +prevents the file system from being mounted. +.Pp +If needed, +.Tn ZFS +file systems can also be managed with traditional tools +.Pq Xr mount 8 , Xr umount 8 , Xr fstab 5 . +If a file system's mount point is set to +.Cm legacy , +.Tn ZFS +makes no attempt to manage the file system, and the administrator is +responsible for mounting and unmounting the file system. +.Ss Jails +.No A Tn ZFS +dataset can be attached to a jail by using the +.Qq Nm Cm jail +subcommand. You cannot attach a dataset to one jail and the children of the +same dataset to another jails. To allow management of the dataset from within +a jail, the +.Sy jailed +property has to be set. The +.Sy quota +property cannot be changed from within a jail. +.Pp +.No A Tn ZFS +dataset can be detached from a jail using the +.Qq Nm Cm unjail +subcommand. +.Pp +After a dataset is attached to a jail and the jailed property is set, a jailed +file system cannot be mounted outside the jail, since the jail administrator +might have set the mount point to an unacceptable value. +.Ss Deduplication +Deduplication is the process for removing redundant data at the block-level, +reducing the total amount of data stored. If a file system has the +.Cm dedup +property enabled, duplicate data blocks are removed synchronously. The result +is that only unique data is stored and common components are shared among +files. +.Ss Native Properties Properties are divided into two types, native properties and user-defined (or "user") properties. Native properties either export internal statistics or -control \fBZFS\fR behavior. In addition, native properties are either editable -or read-only. User properties have no effect on \fBZFS\fR behavior, but you can -use them to annotate datasets in a way that is meaningful in your environment. -For more information about user properties, see the "User Properties" section, -below. -.sp -.LP +control +.Tn ZFS +behavior. In addition, native properties are either editable or read-only. User +properties have no effect on +.Tn ZFS +behavior, but you can use them to annotate datasets in a way that is meaningful +in your environment. For more information about user properties, see the +.Qq Sx User Properties +section, below. +.Pp Every dataset has a set of properties that export statistics about the dataset as well as control various behaviors. Properties are inherited from the parent unless overridden by the child. Some properties apply only to certain types of datasets (file systems, volumes, or snapshots). -.sp -.LP +.Pp The values of numeric properties can be specified using human-readable suffixes -(for example, \fBk\fR, \fBKB\fR, \fBM\fR, \fBGb\fR, and so forth, up to \fBZ\fR +(for example, +.Sy k , KB , M , Gb , +and so forth, up to +.Sy Z for zettabyte). The following are all valid (and equal) specifications: -.sp -.in +2 -.nf +.Bd -ragged -offset 4n 1536M, 1.5g, 1.50GB -.fi -.in -2 -.sp - -.sp -.LP +.Ed +.Pp The values of non-numeric properties are case sensitive and must be lowercase, -except for \fBmountpoint\fR, \fBsharenfs\fR, and \fBsharesmb\fR. -.sp -.LP +except for +.Sy mountpoint , sharenfs , No and Sy sharesmb . +.Pp The following native properties consist of read-only statistics about the dataset. These properties can be neither set, nor inherited. Native properties apply to all dataset types unless otherwise noted. -.sp -.ne 2 -.na -\fB\fBavailable\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width 2n +.It Sy available The amount of space available to the dataset and all its children, assuming that there is no other activity in the pool. Because space is shared within a pool, availability can be limited by any number of factors, including physical pool size, quotas, reservations, or other datasets within the pool. -.sp +.Pp This property can also be referred to by its shortened column name, -\fBavail\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBcompressratio\fR\fR -.ad -.sp .6 -.RS 4n -For non-snapshots, the compression ratio achieved for the \fBused\fR -space of this dataset, expressed as a multiplier. The \fBused\fR +.Sy avail . +.It Sy compressratio +For non-snapshots, the compression ratio achieved for the +.Sy used +space of this dataset, expressed as a multiplier. The +.Sy used property includes descendant datasets, and, for clones, does not include the space shared with the origin snapshot. For snapshots, the -\fBcompressratio\fR is the same as the \fBrefcompressratio\fR property. -Compression can be turned on by running: \fBzfs set compression=on -\fIdataset\fR\fR. The default value is \fBoff\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBcreation\fR\fR -.ad -.sp .6 -.RS 4n +.Sy compressratio +is the same as the +.Sy refcompressratio +property. Compression can be turned on by running: +.Qq Nm Cm set compression=on Ar dataset +The default value is +.Cm off . +.It Sy creation The time this dataset was created. -.RE - -.sp -.ne 2 -.na -\fB\fBdefer_destroy\fR\fR -.ad -.sp .6 -.RS 4n -This property is \fBon\fR if the snapshot has been marked for deferred destroy -by using the \fBzfs destroy\fR \fB-d\fR command. Otherwise, the property is -\fBoff\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBmounted\fR\fR -.ad -.sp .6 -.RS 4n +.It Sy clones +For snapshots, this property is a comma-separated list of filesystems or +volumes which are clones of this snapshot. The clones' +.Sy origin +property is this snapshot. If the +.Sy clones +property is not empty, then this snapshot can not be destroyed (even with the +.Fl r +or +.Fl f +options). +.It Sy defer_destroy +This property is +.Cm on +if the snapshot has been marked for deferred destroy by using the +.Qq Nm Cm destroy -d +command. Otherwise, the property is +.Cm off . +.It Sy mounted For file systems, indicates whether the file system is currently mounted. This -property can be either \fByes\fR or \fBno\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBorigin\fR\fR -.ad -.sp .6 -.RS 4n +property can be either +.Cm yes +or +.Cm no . +.It Sy origin For cloned file systems or volumes, the snapshot from which the clone was -created. The origin cannot be destroyed (even with the \fB-r\fR or \fB-f\fR -options) so long as a clone exists. -.RE - -.sp -.ne 2 -.na -\fB\fBreferenced\fR\fR -.ad -.sp .6 -.RS 4n +created. See also the +.Sy clones +property. +.It Sy referenced The amount of data that is accessible by this dataset, which may or may not be shared with other datasets in the pool. When a snapshot or clone is created, it initially references the same amount of space as the file system or snapshot it was created from, since its contents are identical. -.sp +.Pp This property can also be referred to by its shortened column name, -\fBrefer\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBrefcompressratio\fR\fR -.ad -.sp .6 -.RS 4n -The compression ratio achieved for the \fBreferenced\fR space of this -dataset, expressed as a multiplier. See also the \fBcompressratio\fR +.Sy refer . +.It Sy refcompressratio +The compression ratio achieved for the +.Sy referenced +space of this dataset, expressed as a multiplier. See also the +.Sy compressratio property. -.RE - -.sp -.ne 2 -.na -\fB\fBtype\fR\fR -.ad -.sp .6 -.RS 4n -The type of dataset: \fBfilesystem\fR, \fBvolume\fR, or \fBsnapshot\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBused\fR\fR -.ad -.sp .6 -.RS 4n +.It Sy type +The type of dataset: +.Sy filesystem , volume , No or Sy snapshot . +.It Sy used The amount of space consumed by this dataset and all its descendents. This is the value that is checked against this dataset's quota and reservation. The space used does not include this dataset's reservation, but does take into @@ -563,2555 +545,2279 @@ account the reservations of any descendent datasets. The amount of space that a dataset consumes from its parent, as well as the amount of space that are freed if this dataset is recursively destroyed, is the greater of its space used and its reservation. -.sp -When snapshots (see the "Snapshots" section) are created, their space is +.Pp +When snapshots (see the +.Qq Sx Snapshots +section) are created, their space is initially shared between the snapshot and the file system, and possibly with previous snapshots. As the file system changes, space that was previously shared becomes unique to the snapshot, and counted in the snapshot's space used. Additionally, deleting snapshots can increase the amount of space unique to (and used by) other snapshots. -.sp +.Pp The amount of space used, available, or referenced does not take into account pending changes. Pending changes are generally accounted for within a few -seconds. Committing a change to a disk using \fBfsync\fR(2) or \fBO_SYNC\fR +seconds. Committing a change to a disk using +.Xr fsync 2 +or +.Sy O_SYNC does not necessarily guarantee that the space usage information is updated immediately. -.RE - -.sp -.ne 2 -.na -\fB\fBusedby*\fR\fR -.ad -.sp .6 -.RS 4n -The \fBusedby*\fR properties decompose the \fBused\fR properties into the -various reasons that space is used. Specifically, \fBused\fR = -\fBusedbychildren\fR + \fBusedbydataset\fR + \fBusedbyrefreservation\fR +, -\fBusedbysnapshots\fR. These properties are only available for datasets created -on \fBzpool\fR "version 13" pools. -.RE - -.sp -.ne 2 -.na -\fB\fBusedbychildren\fR\fR -.ad -.sp .6 -.RS 4n -The amount of space used by children of this dataset, which would be freed if -all the dataset's children were destroyed. -.RE - -.sp -.ne 2 -.na -\fB\fBusedbydataset\fR\fR -.ad -.sp .6 -.RS 4n -The amount of space used by this dataset itself, which would be freed if the -dataset were destroyed (after first removing any \fBrefreservation\fR and -destroying any necessary snapshots or descendents). -.RE - -.sp -.ne 2 -.na -\fB\fBusedbyrefreservation\fR\fR -.ad -.sp .6 -.RS 4n -The amount of space used by a \fBrefreservation\fR set on this dataset, which -would be freed if the \fBrefreservation\fR was removed. -.RE - -.sp -.ne 2 -.na -\fB\fBusedbysnapshots\fR\fR -.ad -.sp .6 -.RS 4n +.It Sy usedby* +The +.Sy usedby* +properties decompose the +.Sy used +properties into the various reasons that space is used. Specifically, +.Sy used No = +.Sy usedbysnapshots + usedbydataset + usedbychildren + usedbyrefreservation . +These properties are only available for datasets created +with +.Tn ZFS +pool version 13 pools and higher. +.It Sy usedbysnapshots The amount of space consumed by snapshots of this dataset. In particular, it is the amount of space that would be freed if all of this dataset's snapshots were -destroyed. Note that this is not simply the sum of the snapshots' \fBused\fR +destroyed. Note that this is not simply the sum of the snapshots' +.Sy used properties because space can be shared by multiple snapshots. -.RE - -.sp -.ne 2 -.na -\fB\fBuserused@\fR\fIuser\fR\fR -.ad -.sp .6 -.RS 4n +.It Sy usedbydataset +The amount of space used by this dataset itself, which would be freed if the +dataset were destroyed (after first removing any +.Sy refreservation +and destroying any necessary snapshots or descendents). +.It Sy usedbychildren +The amount of space used by children of this dataset, which would be freed if +all the dataset's children were destroyed. +.It Sy usedbyrefreservation +The amount of space used by a +.Sy refreservation +set on this dataset, which would be freed if the +.Sy refreservation +was removed. +.It Sy userused@ Ns Ar user The amount of space consumed by the specified user in this dataset. Space is -charged to the owner of each file, as displayed by \fBls\fR \fB-l\fR. The -amount of space charged is displayed by \fBdu\fR and \fBls\fR \fB-s\fR. See the -\fBzfs userspace\fR subcommand for more information. -.sp +charged to the owner of each file, as displayed by +.Qq Nm ls Fl l . +The amount of space charged is displayed by +.Qq Nm du +and +.Qq Nm ls Fl s . +See the +.Qq Nm Cm userspace +subcommand for more information. +.Pp Unprivileged users can access only their own space usage. The root user, or a -user who has been granted the \fBuserused\fR privilege with \fBzfs allow\fR, +user who has been granted the +.Sy userused +privilege with +.Qq Nm Cm allow , can access everyone's usage. -.sp -The \fBuserused@\fR... properties are not displayed by \fBzfs get all\fR. The -user's name must be appended after the \fB@\fR symbol, using one of the -following forms: -.RS +4 -.TP -.ie t \(bu -.el o -\fIPOSIX name\fR (for example, \fBjoe\fR) -.RE -.RS +4 -.TP -.ie t \(bu -.el o -\fIPOSIX numeric ID\fR (for example, \fB789\fR) -.RE -.RS +4 -.TP -.ie t \(bu -.el o -\fISID name\fR (for example, \fBjoe.smith@mydomain\fR) -.RE -.RS +4 -.TP -.ie t \(bu -.el o -\fISID numeric ID\fR (for example, \fBS-1-123-456-789\fR) -.RE -.RE - -.sp -.ne 2 -.na -\fB\fBuserrefs\fR\fR -.ad -.sp .6 -.RS 4n +.Pp +The +.Sy userused@ Ns ... +properties are not displayed by +.Qq Nm Cm get all . +The user's name must be appended after the +.Sy @ +symbol, using one of the following forms: +.Bl -bullet -offset 2n +.It +POSIX name (for example, +.Em joe ) +.It +POSIX numeric ID (for example, +.Em 1001 ) +.El +.It Sy userrefs This property is set to the number of user holds on this snapshot. User holds -are set by using the \fBzfs hold\fR command. -.RE - -.sp -.ne 2 -.na -\fB\fBgroupused@\fR\fIgroup\fR\fR -.ad -.sp .6 -.RS 4n +are set by using the +.Qq Nm Cm hold +command. +.It Sy groupused@ Ns Ar group The amount of space consumed by the specified group in this dataset. Space is -charged to the group of each file, as displayed by \fBls\fR \fB-l\fR. See the -\fBuserused@\fR\fIuser\fR property for more information. -.sp +charged to the group of each file, as displayed by +.Nm ls Fl l . +See the +.Sy userused@ Ns Ar user +property for more information. +.Pp Unprivileged users can only access their own groups' space usage. The root -user, or a user who has been granted the \fBgroupused\fR privilege with \fBzfs -allow\fR, can access all groups' usage. -.RE - -.sp -.ne 2 -.na -\fB\fBvolblocksize\fR=\fIblocksize\fR\fR -.ad -.sp .6 -.RS 4n -For volumes, specifies the block size of the volume. The \fBblocksize\fR cannot -be changed once the volume has been written, so it should be set at volume -creation time. The default \fBblocksize\fR for volumes is 8 Kbytes. Any power -of 2 from 512 bytes to 128 Kbytes is valid. -.sp +user, or a user who has been granted the +.Sy groupused +privilege with +.Qq Nm Cm allow , +can access all groups' usage. +.It Sy volblocksize Ns = Ns Ar blocksize +For volumes, specifies the block size of the volume. The +.Ar blocksize +cannot be changed once the volume has been written, so it should be set at +volume creation time. The default +.Ar blocksize +for volumes is 8 Kbytes. Any +power of 2 from 512 bytes to 128 Kbytes is valid. +.Pp This property can also be referred to by its shortened column name, -\fBvolblock\fR. -.RE - -.sp -.LP +.Sy volblock . +.It Sy written +The amount of +.Sy referenced +space written to this dataset since the previous snapshot. +.It Sy written@ Ns Ar snapshot +The amount of +.Sy referenced +space written to this dataset since the specified snapshot. This is the space +that is referenced by this dataset but was not referenced by the specified +snapshot. +.Pp +The +.Ar snapshot +may be specified as a short snapshot name (just the part after the +.Sy @ ) , +in which case it will be interpreted as a snapshot in the same filesystem as +this dataset. The +.Ar snapshot +may be a full snapshot name +.Pq Em filesystem@snapshot , +which for clones may be a snapshot in the origin's filesystem (or the origin of +the origin's filesystem, etc). +.El +.Pp The following native properties can be used to change the behavior of a -\fBZFS\fR dataset. -.sp -.ne 2 -.na -\fB\fBaclinherit\fR=\fBdiscard\fR | \fBnoallow\fR | \fBrestricted\fR | -\fBpassthrough\fR | \fBpassthrough-x\fR\fR -.ad -.sp .6 -.RS 4n -Controls how \fBACL\fR entries are inherited when files and directories are -created. A file system with an \fBaclinherit\fR property of \fBdiscard\fR does -not inherit any \fBACL\fR entries. A file system with an \fBaclinherit\fR -property value of \fBnoallow\fR only inherits inheritable \fBACL\fR entries -that specify "deny" permissions. The property value \fBrestricted\fR (the -default) removes the \fBwrite_acl\fR and \fBwrite_owner\fR permissions when the -\fBACL\fR entry is inherited. A file system with an \fBaclinherit\fR property -value of \fBpassthrough\fR inherits all inheritable \fBACL\fR entries without -any modifications made to the \fBACL\fR entries when they are inherited. A file -system with an \fBaclinherit\fR property value of \fBpassthrough-x\fR has the -same meaning as \fBpassthrough\fR, except that the \fBowner@\fR, \fBgroup@\fR, -and \fBeveryone@\fR \fBACE\fRs inherit the execute permission only if the file -creation mode also requests the execute bit. -.sp -When the property value is set to \fBpassthrough\fR, files are created with a -mode determined by the inheritable \fBACE\fRs. If no inheritable \fBACE\fRs +.Tn ZFS +dataset. +.Bl -tag -width 2n +.It Xo +.Sy aclinherit Ns = Ns Cm discard | +.Cm noallow | +.Cm restricted | +.Cm passthrough | +.Cm passthrough-x +.Xc +Controls how +.Tn ACL +entries are inherited when files and directories are created. A file system +with an +.Sy aclinherit +property of +.Cm discard +does not inherit any +.Tn ACL +entries. A file system with an +.Sy aclinherit +property value of +.Cm noallow +only inherits inheritable +.Tn ACL +entries that specify "deny" permissions. The property value +.Cm restricted +(the default) removes the +.Em write_acl +and +.Em write_owner +permissions when the +.Tn ACL +entry is inherited. A file system with an +.Sy aclinherit +property value of +.Cm passthrough +inherits all inheritable +.Tn ACL +entries without any modifications made to the +.Tn ACL +entries when they are inherited. A file system with an +.Sy aclinherit +property value of +.Cm passthrough-x +has the same meaning as +.Cm passthrough , +except that the +.Em owner@ , group@ , No and Em everyone@ Tn ACE Ns s +inherit the execute permission only if the file creation mode also requests the +execute bit. +.Pp +When the property value is set to +.Cm passthrough , +files are created with a mode determined by the inheritable +.Tn ACE Ns s. +If no inheritable +.Tn ACE Ns s exist that affect the mode, then the mode is set in accordance to the requested mode from the application. -.RE - -.sp -.ne 2 -.na -\fB\fBaclmode\fR=\fBdiscard\fR | \fBgroupmask\fR | \fBpassthrough\fR\fR -.ad -.sp .6 -.RS 4n -Controls how an \fBACL\fR is modified during \fBchmod\fR(2). A file system with -an \fBaclmode\fR property of \fBdiscard\fR (the default) deletes all \fBACL\fR -entries that do not represent the mode of the file. An \fBaclmode\fR property -of \fBgroupmask\fR reduces permissions granted in all \fBALLOW\fR entries found -in the \fBACL\fR such that they are no greater than the group permissions -specified by \fBchmod\fR. A file system with an \fBaclmode\fR property of -\fBpassthrough\fR indicates that no changes are made to the \fBACL\fR other -than creating or updating the necessary \fBACL\fR entries to -represent the new mode of the file or directory. -.RE - -.sp -.ne 2 -.na -\fB\fBatime\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n +.It Sy aclmode Ns = Ns Cm discard | groupmask | passthrough +Controls how an +.Tn ACL +is modified during +.Xr chmod 2 . +A file system with an +.Sy aclmode +property of +.Cm discard +(the default) deletes all +.Tn ACL +entries that do not represent the mode of the file. An +.Sy aclmode +property of +.Cm groupmask +reduces permissions granted in all +.Em ALLOW +entries found in the +.Tn ACL +such that they are no greater than the group permissions specified by +.Xr chmod 2 . +A file system with an +.Sy aclmode +property of +.Cm passthrough +indicates that no changes are made to the +.Tn ACL +other than creating or updating the necessary +.Tn ACL +entries to represent the new mode of the file or directory. +.It Sy atime Ns = Ns Cm on | off Controls whether the access time for files is updated when they are read. Turning this property off avoids producing write traffic when reading files and can result in significant performance gains, though it might confuse mailers -and other similar utilities. The default value is \fBon\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBcanmount\fR=\fBon\fR | \fBoff\fR | \fBnoauto\fR\fR -.ad -.sp .6 -.RS 4n -If this property is set to \fBoff\fR, the file system cannot be mounted, and is -ignored by \fBzfs mount -a\fR. Setting this property to \fBoff\fR is similar to -setting the \fBmountpoint\fR property to \fBnone\fR, except that the dataset -still has a normal \fBmountpoint\fR property, which can be inherited. Setting -this property to \fBoff\fR allows datasets to be used solely as a mechanism to -inherit properties. One example of setting \fBcanmount=\fR\fBoff\fR is to have -two datasets with the same \fBmountpoint\fR, so that the children of both -datasets appear in the same directory, but might have different inherited -characteristics. -.sp -When the \fBnoauto\fR option is set, a dataset can only be mounted and -unmounted explicitly. The dataset is not mounted automatically when the dataset -is created or imported, nor is it mounted by the \fBzfs mount -a\fR command or -unmounted by the \fBzfs unmount -a\fR command. -.sp +and other similar utilities. The default value is +.Cm on . +.It Sy canmount Ns = Ns Cm on | off | noauto +If this property is set to +.Cm off , +the file system cannot be mounted, and is ignored by +.Qq Nm Cm mount Fl a . +Setting this property to +.Cm off +is similar to setting the +.Sy mountpoint +property to +.Cm none , +except that the dataset still has a normal +.Sy mountpoint +property, which can be inherited. Setting this property to +.Cm off +allows datasets to be used solely as a mechanism to inherit properties. One +example of setting +.Sy canmount Ns = Ns Cm off +is to have two datasets with the same +.Sy mountpoint , +so that the children of both datasets appear in the same directory, but might +have different inherited characteristics. +.Pp +When the +.Cm noauto +value is set, a dataset can only be mounted and unmounted explicitly. The +dataset is not mounted automatically when the dataset is created or imported, +nor is it mounted by the +.Qq Nm Cm mount Fl a +command or unmounted by the +.Qq Nm Cm umount Fl a +command. +.Pp This property is not inherited. -.RE - -.sp -.ne 2 -.na -\fB\fBchecksum\fR=\fBon\fR | \fBoff\fR | \fBfletcher2,\fR| \fBfletcher4\fR | -\fBsha256\fR\fR -.ad -.sp .6 -.RS 4n +.It Sy checksum Ns = Ns Cm on | off | fletcher2 | fletcher4 Controls the checksum used to verify data integrity. The default value is -\fBon\fR, which automatically selects an appropriate algorithm (currently, -\fBfletcher4\fR, but this may change in future releases). The value \fBoff\fR -disables integrity checking on user data. Disabling checksums is \fBNOT\fR a -recommended practice. -.sp -Changing this property affects only newly-written data. -.RE - -.sp -.ne 2 -.na -\fB\fBcompression\fR=\fBon\fR | \fBoff\fR | \fBlzjb\fR | \fBgzip\fR | -\fBgzip-\fR\fIN\fR\fR -.ad -.sp .6 -.RS 4n -Controls the compression algorithm used for this dataset. The \fBlzjb\fR +.Cm on , +which automatically selects an appropriate algorithm (currently, +.Cm fletcher4 , +but this may change in future releases). The value +.Cm off +disables integrity checking on user data. Disabling checksums is +.Em NOT +a recommended practice. +.It Sy compression Ns = Ns Cm on | off | lzjb | gzip | gzip- Ns Ar N | Cm zle +Controls the compression algorithm used for this dataset. The +.CM lzjb compression algorithm is optimized for performance while providing decent data -compression. Setting compression to \fBon\fR uses the \fBlzjb\fR compression -algorithm. The \fBgzip\fR compression algorithm uses the same compression as -the \fBgzip\fR(1) command. You can specify the \fBgzip\fR level by using the -value \fBgzip-\fR\fIN\fR where \fIN\fR is an integer from 1 (fastest) to 9 -(best compression ratio). Currently, \fBgzip\fR is equivalent to \fBgzip-6\fR -(which is also the default for \fBgzip\fR(1)). -.sp +compression. Setting compression to +.Cm on +uses the +.Cm lzjb +compression algorithm. The +.Cm gzip +compression algorithm uses the same compression as the +.Xr gzip 1 +command. You can specify the +.Cm gzip +level by using the value +.Cm gzip- Ns Ar N +where +.Ar N +is an integer from 1 (fastest) to 9 (best compression ratio). Currently, +.Cm gzip +is equivalent to +.Cm gzip-6 +(which is also the default for +.Xr gzip 1 ) . +The +.Cm zle +compression algorithm compresses runs of zeros. +.Pp This property can also be referred to by its shortened column name -\fBcompress\fR. Changing this property affects only newly-written data. -.RE - -.sp -.ne 2 -.na -\fB\fBcopies\fR=\fB1\fR | \fB2\fR | \fB3\fR\fR -.ad -.sp .6 -.RS 4n +.Cm compress . +Changing this property affects only newly-written data. +.It Sy copies Ns = Ns Cm 1 | 2 | 3 Controls the number of copies of data stored for this dataset. These copies are in addition to any redundancy provided by the pool, for example, mirroring or RAID-Z. The copies are stored on different disks, if possible. The space used by multiple copies is charged to the associated file and dataset, changing the -\fBused\fR property and counting against quotas and reservations. -.sp +.Sy used +property and counting against quotas and reservations. +.Pp Changing this property only affects newly-written data. Therefore, set this -property at file system creation time by using the \fB-o\fR -\fBcopies=\fR\fIN\fR option. -.RE - -.sp -.ne 2 -.na -\fB\fBdevices\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n -Controls whether device nodes can be opened on this file system. The default -value is \fBon\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBexec\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n +property at file system creation time by using the +.Fl o Cm copies= Ns Ar N +option. +.It Sy dedup Ns = Ns Cm on | off | verify | sha256 Ns Op Cm ,verify +Configures deduplication for a dataset. The default value is +.Cm off . +The default deduplication checksum is +.Cm sha256 +(this may change in the future). +When +.Sy dedup +is enabled, the checksum defined here overrides the +.Sy checksum +property. Setting the value to +.Cm verify +has the same effect as the setting +.Cm sha256,verify . +.Pp +If set to +.Cm verify , +.Tn ZFS +will do a byte-to-byte comparsion in case of two blocks having the same +signature to make sure the block contents are identical. +.It Sy devices Ns = Ns Cm on | off +The +.Sy devices +property is currently not supported on +.Fx . +.It Sy exec Ns = Ns Cm on | off Controls whether processes can be executed from within this file system. The -default value is \fBon\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBjailed\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n -Controls whether the dataset is managed from within a jail. See the "Jails" -section for more information. The default value is \fBoff\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBmountpoint\fR=\fIpath\fR | \fBnone\fR | \fBlegacy\fR\fR -.ad -.sp .6 -.RS 4n -Controls the mount point used for this file system. See the "Mount Points" +default value is +.Cm on . +.It Sy mlslabel Ns = Ns Ar label | Cm none +The +.Sy mlslabel +property is currently not supported on +.Fx . +.It Sy mountpoint Ns = Ns Ar path | Cm none | legacy +Controls the mount point used for this file system. See the +.Qq Sx Mount Points section for more information on how this property is used. -.sp -When the \fBmountpoint\fR property is changed for a file system, the file -system and any children that inherit the mount point are unmounted. If the new -value is \fBlegacy\fR, then they remain unmounted. Otherwise, they are -automatically remounted in the new location if the property was previously -\fBlegacy\fR or \fBnone\fR, or if they were mounted before the property was -changed. In addition, any shared file systems are unshared and shared in the -new location. -.RE - -.sp -.ne 2 -.na -\fB\fBnbmand\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n -Controls whether the file system should be mounted with \fBnbmand\fR (Non -Blocking mandatory locks). This is used for \fBCIFS\fR clients. Changes to this -property only take effect when the file system is umounted and remounted. See -\fBmount\fR(8) for more information on \fBnbmand\fR mounts. -.RE - -.sp -.ne 2 -.na -\fB\fBprimarycache\fR=\fBall\fR | \fBnone\fR | \fBmetadata\fR\fR -.ad -.sp .6 -.RS 4n +.Pp +When the +.Sy mountpoint +property is changed for a file system, the file system and any children that +inherit the mount point are unmounted. If the new value is +.Cm legacy , +then they remain unmounted. Otherwise, they are automatically remounted in the +new location if the property was previously +.Cm legacy +or +.Cm none , +or if they were mounted before the property was changed. In addition, any +shared file systems are unshared and shared in the new location. +.It Sy nbmand Ns = Ns Cm on | off +The +.Sy nbmand +property is currently not supported on +.Fx . +.It Sy primarycache Ns = Ns Cm all | none | metadata Controls what is cached in the primary cache (ARC). If this property is set to -\fBall\fR, then both user data and metadata is cached. If this property is set -to \fBnone\fR, then neither user data nor metadata is cached. If this property -is set to \fBmetadata\fR, then only metadata is cached. The default value is -\fBall\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBquota\fR=\fIsize\fR | \fBnone\fR\fR -.ad -.sp .6 -.RS 4n +.Cm all , +then both user data and metadata is cached. If this property is set to +.Cm none , +then neither user data nor metadata is cached. If this property is set to +.Cm metadata , +then only metadata is cached. The default value is +.Cm all . +.It Sy quota Ns = Ns Ar size | Cm none Limits the amount of space a dataset and its descendents can consume. This property enforces a hard limit on the amount of space used. This includes all space consumed by descendents, including file systems and snapshots. Setting a quota on a descendent of a dataset that already has a quota does not override the ancestor's quota, but rather imposes an additional limit. -.sp -Quotas cannot be set on volumes, as the \fBvolsize\fR property acts as an -implicit quota. -.RE - -.sp -.ne 2 -.na -\fB\fBuserquota@\fR\fIuser\fR=\fIsize\fR | \fBnone\fR\fR -.ad -.sp .6 -.RS 4n -Limits the amount of space consumed by the specified user. User space -consumption is identified by the \fBuserspace@\fR\fIuser\fR property. -.sp +.Pp +Quotas cannot be set on volumes, as the +.Sy volsize +property acts as an implicit quota. +.It Sy userquota@ Ns Ar user Ns = Ns Ar size | Cm none +Limits the amount of space consumed by the specified user. +Similar to the +.Sy refquota +property, the +.Sy userquota +space calculation does not include space that is used by descendent datasets, +such as snapshots and clones. User space consumption is identified by the +.Sy userspace@ Ns Ar user +property. +.Pp Enforcement of user quotas may be delayed by several seconds. This delay means that a user might exceed their quota before the system notices that they are -over quota and begins to refuse additional writes with the \fBEDQUOT\fR error -message . See the \fBzfs userspace\fR subcommand for more information. -.sp +over quota and begins to refuse additional writes with the +.Em EDQUOT +error message. See the +.Cm userspace +subcommand for more information. +.Pp Unprivileged users can only access their own groups' space usage. The root -user, or a user who has been granted the \fBuserquota\fR privilege with \fBzfs -allow\fR, can get and set everyone's quota. -.sp +user, or a user who has been granted the +.Sy userquota +privilege with +.Qq Nm Cm allow , +can get and set everyone's quota. +.Pp This property is not available on volumes, on file systems before version 4, or -on pools before version 15. The \fBuserquota@\fR... properties are not -displayed by \fBzfs get all\fR. The user's name must be appended after the -\fB@\fR symbol, using one of the following forms: -.RS +4 -.TP -.ie t \(bu -.el o -\fIPOSIX name\fR (for example, \fBjoe\fR) -.RE -.RS +4 -.TP -.ie t \(bu -.el o -\fIPOSIX numeric ID\fR (for example, \fB789\fR) -.RE -.RS +4 -.TP -.ie t \(bu -.el o -\fISID name\fR (for example, \fBjoe.smith@mydomain\fR) -.RE -.RS +4 -.TP -.ie t \(bu -.el o -\fISID numeric ID\fR (for example, \fBS-1-123-456-789\fR) -.RE -.RE - -.sp -.ne 2 -.na -\fB\fBgroupquota@\fR\fIgroup\fR=\fIsize\fR | \fBnone\fR\fR -.ad -.sp .6 -.RS 4n +on pools before version 15. The +.Sy userquota@ Ns ... +properties are not displayed by +.Qq Nm Cm get all . +The user's name must be appended after the +.Sy @ +symbol, using one of the following forms: +.Bl -bullet -offset 2n +.It +POSIX name (for example, +.Em joe ) +.It +POSIX numeric ID (for example, +.Em 1001 ) +.El +.It Sy groupquota@ Ns Ar group Ns = Ns Ar size | Cm none Limits the amount of space consumed by the specified group. Group space -consumption is identified by the \fBuserquota@\fR\fIuser\fR property. -.sp +consumption is identified by the +.Sy userquota@ Ns Ar user +property. +.Pp Unprivileged users can access only their own groups' space usage. The root -user, or a user who has been granted the \fBgroupquota\fR privilege with \fBzfs -allow\fR, can get and set all groups' quotas. -.RE - -.sp -.ne 2 -.na -\fB\fBreadonly\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n -Controls whether this dataset can be modified. The default value is \fBoff\fR. -.sp -This property can also be referred to by its shortened column name, -\fBrdonly\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBrecordsize\fR=\fIsize\fR\fR -.ad -.sp .6 -.RS 4n +user, or a user who has been granted the +.Sy groupquota +privilege with +.Qq Nm Cm allow , +can get and set all groups' quotas. +.It Sy readonly Ns = Ns Cm on | off +Controls whether this dataset can be modified. The default value is +.Cm off . +.It Sy recordsize Ns = Ns Ar size Specifies a suggested block size for files in the file system. This property is designed solely for use with database workloads that access files in fixed-size -records. \fBZFS\fR automatically tunes block sizes according to internal -algorithms optimized for typical access patterns. -.sp +records. +.Tn ZFS +automatically tunes block sizes according to internal algorithms optimized for +typical access patterns. +.Pp For databases that create very large files but access them in small random -chunks, these algorithms may be suboptimal. Specifying a \fBrecordsize\fR +chunks, these algorithms may be suboptimal. Specifying a +.Sy recordsize greater than or equal to the record size of the database can result in significant performance gains. Use of this property for general purpose file systems is strongly discouraged, and may adversely affect performance. -.sp +.Pp The size specified must be a power of two greater than or equal to 512 and less than or equal to 128 Kbytes. -.sp -Changing the file system's \fBrecordsize\fR affects only files created -afterward; existing files are unaffected. -.sp +.Pp +Changing the file system's +.Sy recordsize +affects only files created afterward; existing files are unaffected. +.Pp This property can also be referred to by its shortened column name, -\fBrecsize\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBrefquota\fR=\fIsize\fR | \fBnone\fR\fR -.ad -.sp .6 -.RS 4n +.Sy recsize . +.It Sy refquota Ns = Ns Ar size | Cm none Limits the amount of space a dataset can consume. This property enforces a hard limit on the amount of space used. This hard limit does not include space used by descendents, including file systems and snapshots. -.RE - -.sp -.ne 2 -.na -\fB\fBrefreservation\fR=\fIsize\fR | \fBnone\fR\fR -.ad -.sp .6 -.RS 4n +.It Sy refreservation Ns = Ns Ar size | Cm none The minimum amount of space guaranteed to a dataset, not including its descendents. When the amount of space used is below this value, the dataset is treated as if it were taking up the amount of space specified by -\fBrefreservation\fR. The \fBrefreservation\fR reservation is accounted for in -the parent datasets' space used, and counts against the parent datasets' quotas -and reservations. -.sp -If \fBrefreservation\fR is set, a snapshot is only allowed if there is enough -free pool space outside of this reservation to accommodate the current number -of "referenced" bytes in the dataset. -.sp +.Sy refreservation . +The +.Sy refreservation +reservation is accounted for in the parent datasets' space used, and counts +against the parent datasets' quotas and reservations. +.Pp +If +.Sy refreservation +is set, a snapshot is only allowed if there is enough free pool space outside +of this reservation to accommodate the current number of "referenced" bytes in +the dataset. +.Pp This property can also be referred to by its shortened column name, -\fBrefreserv\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBreservation\fR=\fIsize\fR | \fBnone\fR\fR -.ad -.sp .6 -.RS 4n +.Sy refreserv . +.It Sy reservation Ns = Ns Ar size | Cm none The minimum amount of space guaranteed to a dataset and its descendents. When the amount of space used is below this value, the dataset is treated as if it were taking up the amount of space specified by its reservation. Reservations are accounted for in the parent datasets' space used, and count against the parent datasets' quotas and reservations. -.sp +.Pp This property can also be referred to by its shortened column name, -\fBreserv\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBsecondarycache\fR=\fBall\fR | \fBnone\fR | \fBmetadata\fR\fR -.ad -.sp .6 -.RS 4n +.Sy reserv . +.It Sy secondarycache Ns = Ns Cm all | none | metadata Controls what is cached in the secondary cache (L2ARC). If this property is set -to \fBall\fR, then both user data and metadata is cached. If this property is -set to \fBnone\fR, then neither user data nor metadata is cached. If this -property is set to \fBmetadata\fR, then only metadata is cached. The default -value is \fBall\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBsetuid\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n -Controls whether the set-\fBUID\fR bit is respected for the file system. The -default value is \fBon\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBsharesmb\fR=\fBon\fR | \fBoff\fR | \fIopts\fR\fR -.ad -.sp .6 -.RS 4n -The \fB\fBsharesmb\fR property has currently no effect on FreeBSD. -.RE - -.sp -.ne 2 -.na -\fB\fBsharenfs\fR=\fBon\fR | \fBoff\fR | \fIopts\fR\fR -.ad -.sp .6 -.RS 4n -Controls whether the file system is shared via \fBNFS\fR, and what options are -used. A file system with a \fBsharenfs\fR property of \fBoff\fR is managed -the traditional way via \fBexports\fR(5). Otherwise, the file system is -automatically shared and unshared with the \fBzfs share\fR and -\fBzfs unshare\fR commands. If the property is set to \fBon\fR, no NFS export -options are used. Otherwise, NFS export options are equivalent to the contents -of this property. -.sp -When the \fBsharenfs\fR property is changed for a dataset, the \fBmountd\fR(8) -daemon is reloaded. -.RE - -.sp -.ne 2 -.na -\fB\fBlogbias\fR = \fBlatency\fR | \fBthroughput\fR\fR -.ad -.sp .6 -.RS 4n -Provide a hint to ZFS about handling of synchronous requests in this dataset. -If \fBlogbias\fR is set to \fBlatency\fR (the default), ZFS will use pool log -devices (if configured) to handle the requests at low latency. If \fBlogbias\fR -is set to \fBthroughput\fR, ZFS will not use configured pool log devices. ZFS +to +.Cm all , +then both user data and metadata is cached. If this property is set to +.Cm none , +then neither user data nor metadata is cached. If this property is set to +.Cm metadata , +then only metadata is cached. The default value is +.Cm all . +.It Sy setuid Ns = Ns Cm on | off +Controls whether the +.No set- Ns Tn UID +bit is respected for the file system. The default value is +.Cm on . +.It Sy sharesmb Ns = Ns Cm on | off | Ar opts +The +.Sy sharesmb +property has currently no effect o +.Fx . +.It Sy sharenfs Ns = Ns Cm on | off | Ar opts +Controls whether the file system is shared via +.Tn NFS , +and what options are used. A file system with a +.Sy sharenfs +property of +.Cm off +is managed the traditional way via +.Xr exports 5 . +Otherwise, the file system is automatically shared and unshared with the +.Qq Nm Cm share +and +.Qq Nm Cm unshare +commands. If the property is set to +.Cm on +no +.Tn NFS +export options are used. Otherwise, +.Tn NFS +export options are equivalent to the contents of this property. The export +options may be comma-separated. See +.Xr exports 5 +for a list of valid options. +.Pp +When the +.Sy sharenfs +property is changed for a dataset, the +.Xr mountd 8 +dameon is reloaded. +.It Sy logbias Ns = Ns Cm latency | throughput +Provide a hint to +.Tn ZFS +about handling of synchronous requests in this dataset. +If +.Sy logbias +is set to +.Cm latency +(the default), +.Tn ZFS +will use pool log devices (if configured) to handle the requests at low +latency. If +.Sy logbias +is set to +.Cm throughput , +.Tn ZFS +will not use configured pool log devices. +.Tn ZFS will instead optimize synchronous operations for global pool throughput and efficient use of resources. -.RE - -.sp -.ne 2 -.na -\fB\fBsnapdir\fR=\fBhidden\fR | \fBvisible\fR\fR -.ad -.sp .6 -.RS 4n -Controls whether the \fB\&.zfs\fR directory is hidden or visible in the root of -the file system as discussed in the "Snapshots" section. The default value is -\fBhidden\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBversion\fR=\fB1\fR | \fB2\fR | \fBcurrent\fR\fR -.ad -.sp .6 -.RS 4n -The on-disk version of this file system, which is independent of the pool -version. This property can only be set to later supported versions. See the -\fBzfs upgrade\fR command. -.RE - -.sp -.ne 2 -.na -\fB\fBvolsize\fR=\fIsize\fR\fR -.ad -.sp .6 -.RS 4n +.It Sy snapdir Ns = Ns Cm hidden | visible +Controls whether the +.Pa \&.zfs +directory is hidden or visible in the root of the file system as discussed in +the +.Qq Sx Snapshots +section. The default value is +.Cm hidden . +.It Sy sync Ns = Ns Cm standard | always | disabled +Controls the behavior of synchronous requests (e.g. +.Xr fsync 2 , +O_DSYNC). This property accepts the following values: +.Bl -tag -offset 4n -width 8n +.It Sy standard +This is the POSIX specified behavior of ensuring all synchronous requests are +written to stable storage and all devices are flushed to ensure data is not +cached by device controllers (this is the default). +.It Sy always +All file system transactions are written and flushed before their system calls +return. This has a large performance penalty. +.It Sy disabled +Disables synchronous requests. File system transactions are only committed to +stable storage periodically. This option will give the highest performance. +However, it is very dangerous as +.Tn ZFS +would be ignoring the synchronous transaction demands of applications such as +databases or +.Tn NFS . +Administrators should only use this option when the risks are understood. +.El +.It Sy volsize Ns = Ns Ar size For volumes, specifies the logical size of the volume. By default, creating a volume establishes a reservation of equal size. For storage pools with a -version number of 9 or higher, a \fBrefreservation\fR is set instead. Any -changes to \fBvolsize\fR are reflected in an equivalent change to the -reservation (or \fBrefreservation\fR). The \fBvolsize\fR can only be set to a -multiple of \fBvolblocksize\fR, and cannot be zero. -.sp +version number of 9 or higher, a +.Sy refreservation +is set instead. Any changes to +.Sy volsize +are reflected in an equivalent change to the reservation (or +.Sy refreservation ) . +The +.Sy volsize +can only be set to a multiple of +.Cm volblocksize , +and cannot be zero. +.Pp The reservation is kept equal to the volume's logical size to prevent unexpected behavior for consumers. Without the reservation, the volume could run out of space, resulting in undefined behavior or data corruption, depending on how the volume is used. These effects can also occur when the volume size is changed while it is in use (particularly when shrinking the size). Extreme care should be used when adjusting the volume size. -.sp +.Pp Though not recommended, a "sparse volume" (also known as "thin provisioning") -can be created by specifying the \fB-s\fR option to the \fBzfs create -V\fR +can be created by specifying the +.Fl s +option to the +.Qq Nm Cm create Fl V command, or by changing the reservation after the volume has been created. A "sparse volume" is a volume where the reservation is less then the volume size. -Consequently, writes to a sparse volume can fail with \fBENOSPC\fR when the -pool is low on space. For a sparse volume, changes to \fBvolsize\fR are not -reflected in the reservation. -.RE - -.sp -.ne 2 -.na -\fB\fBvscan\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n -Controls whether regular files should be scanned for viruses when a file is -opened and closed. In addition to enabling this property, the virus scan -service must also be enabled for virus scanning to occur. The default value is -\fBoff\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBxattr\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n -Controls whether extended attributes are enabled for this file system. The -default value is \fBon\fR. -.RE - -.sp -.LP +Consequently, writes to a sparse volume can fail with +.Sy ENOSPC +when the pool is low on space. For a sparse volume, changes to +.Sy volsize +are not reflected in the reservation. +.It Sy vscan Ns = Ns Cm off | on +The +.Sy vscan +property is currently not supported on +.Fx . +.It Sy xattr Ns = Ns Cm off | on +The +.Sy xattr +property is currently not supported on +.Fx . +.It Sy jailed Ns = Ns Cm off | on +Controls whether the dataset is managed from a jail. See the +.Qq Sx Jails +section for more information. The default value is +.Cm off . +.El +.Pp The following three properties cannot be changed after the file system is created, and therefore, should be set when the file system is created. If the -properties are not set with the \fBzfs create\fR or \fBzpool create\fR +properties are not set with the +.Qq Nm Cm create +or +.Nm zpool Cm create commands, these properties are inherited from the parent dataset. If the parent dataset lacks these properties due to having been created prior to these features being supported, the new file system will have the default values for these properties. -.sp -.ne 2 -.na -\fB\fBcasesensitivity\fR=\fBsensitive\fR | \fBinsensitive\fR | \fBmixed\fR\fR -.ad -.sp .6 -.RS 4n -The \fB\fBcasesensitivity\fR property is currently not supported on FreeBSD. -.RE - -.sp -.ne 2 -.na -\fB\fBnormalization\fR = \fBnone\fR | \fBformC\fR | \fBformD\fR | \fBformKC\fR -| \fBformKD\fR\fR -.ad -.sp .6 -.RS 4n -Indicates whether the file system should perform a \fBunicode\fR normalization -of file names whenever two file names are compared, and which normalization -algorithm should be used. File names are always stored unmodified, names are -normalized as part of any comparison process. If this property is set to a -legal value other than \fBnone\fR, and the \fButf8only\fR property was left -unspecified, the \fButf8only\fR property is automatically set to \fBon\fR. The -default value of the \fBnormalization\fR property is \fBnone\fR. This property -cannot be changed after the file system is created. -.RE - -.sp -.ne 2 -.na -\fB\fButf8only\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width 4n +.It Sy casesensitivity Ns = Ns Cm sensitive | insensitive | mixed +The +.Sy casesensitivity +property is currently not supported on +.Fx . +.It Sy normalization Ns = Ns Cm none | formC | formD | formKC | formKD +Indicates whether the file system should perform a +.Sy unicode +normalization of file names whenever two file names are compared, and which +normalization algorithm should be used. File names are always stored +unmodified, names are normalized as part of any comparison process. If this +property is set to a legal value other than +.Cm none , +and the +.Sy utf8only +property was left unspecified, the +.Sy utf8only +property is automatically set to +.Cm on . +The default value of the +.Sy normalization +property is +.Cm none . +This property cannot be changed after the file system is created. +.It Sy utf8only Ns = Ns Cm on | off Indicates whether the file system should reject file names that include -characters that are not present in the \fBUTF-8\fR character code set. If this -property is explicitly set to \fBoff\fR, the normalization property must either -not be explicitly set or be set to \fBnone\fR. The default value for the -\fButf8only\fR property is \fBoff\fR. This property cannot be changed after the -file system is created. -.RE - -.sp -.LP -The \fBcasesensitivity\fR, \fBnormalization\fR, and \fButf8only\fR properties -are also new permissions that can be assigned to non-privileged users by using -the \fBZFS\fR delegated administration feature. -.SS "Temporary Mount Point Properties" -.sp -.LP -When a file system is mounted, either through \fBmount\fR(8) for legacy mounts -or the \fBzfs mount\fR command for normal file systems, its mount options are -set according to its properties. The correlation between properties and mount -options is as follows: -.sp -.in +2 -.nf - PROPERTY MOUNT OPTION - devices devices/nodevices - exec exec/noexec - readonly ro/rw - setuid setuid/nosetuid - xattr xattr/noxattr -.fi -.in -2 -.sp - -.sp -.LP -In addition, these options can be set on a per-mount basis using the \fB-o\fR +characters that are not present in the +.Sy UTF-8 +character code set. If this property is explicitly set to +.Cm off , +the normalization property must either not be explicitly set or be set to +.Cm none . +The default value for the +.Sy utf8only +property is +.Cm off . +This property cannot be changed after the file system is created. +.El +.Pp +The +.Sy casesensitivity , normalization , No and Sy utf8only +properties are also new permissions that can be assigned to non-privileged +users by using the +.Tn ZFS +delegated administration feature. +.Ss Temporary Mount Point Properties +When a file system is mounted, either through +.Xr mount 8 +for legacy mounts or the +.Qq Nm Cm mount +command for normal file systems, its mount options are set according to its +properties. The correlation between properties and mount options is as follows: +.Bl -column -offset 4n "PROPERTY" "MOUNT OPTION" +.It PROPERTY MOUNT OPTION +.It atime atime/noatime +.It exec exec/noexec +.It readonly ro/rw +.It setuid suid/nosuid +.El +.Pp +In addition, these options can be set on a per-mount basis using the +.Fl o option, without affecting the property that is stored on disk. The values -specified on the command line override the values stored in the dataset. The -\fB-nosuid\fR option is an alias for \fBnodevices,nosetuid\fR. These properties -are reported as "temporary" by the \fBzfs get\fR command. If the properties are -changed while the dataset is mounted, the new setting overrides any temporary -settings. -.SS "User Properties" -.sp -.LP -In addition to the standard native properties, \fBZFS\fR supports arbitrary -user properties. User properties have no effect on \fBZFS\fR behavior, but -applications or administrators can use them to annotate datasets (file systems, -volumes, and snapshots). -.sp -.LP -User property names must contain a colon (\fB:\fR) character to distinguish -them from native properties. They may contain lowercase letters, numbers, and -the following punctuation characters: colon (\fB:\fR), dash (\fB-\fR), period -(\fB\&.\fR), and underscore (\fB_\fR). The expected convention is that the -property name is divided into two portions such as -\fImodule\fR\fB:\fR\fIproperty\fR, but this namespace is not enforced by -\fBZFS\fR. User property names can be at most 256 characters, and cannot begin -with a dash (\fB-\fR). -.sp -.LP +specified on the command line override the values stored in the dataset. These +properties are reported as "temporary" by the +.Qq Nm Cm get +command. If the properties are changed while the dataset is mounted, the new +setting overrides any temporary settings. +.Ss User Properties +In addition to the standard native properties, +.Tn ZFS +supports arbitrary user properties. User properties have no effect on +.Tn ZFS +behavior, but applications or administrators can use them to annotate datasets +(file systems, volumes, and snapshots). +.Pp +User property names must contain a colon +.Pq Sy \&: +character to distinguish them from native properties. They may contain +lowercase letters, numbers, and the following punctuation characters: colon +.Pq Sy \&: , +dash +.Pq Sy \&- , +period +.Pq Sy \&. +and underscore +.Pq Sy \&_ . +The expected convention is that the property name is divided into two portions +such as +.Em module Ns Sy \&: Ns Em property , +but this namespace is not enforced by +.Tn ZFS . +User property names can be at most 256 characters, and cannot begin with a dash +.Pq Sy \&- . +.Pp When making programmatic use of user properties, it is strongly suggested to -use a reversed \fBDNS\fR domain name for the \fImodule\fR component of property -names to reduce the chance that two independently-developed packages use the -same property name for different purposes. Property names beginning with -\fBcom.sun\fR. are reserved for use by Sun Microsystems. -.sp -.LP +use a reversed +.Tn DNS +domain name for the +.Ar module +component of property names to reduce the chance that two +independently-developed packages use the same property name for different +purposes. Property names beginning with +.Em com.sun +are reserved for use by Sun Microsystems. +.Pp The values of user properties are arbitrary strings, are always inherited, and -are never validated. All of the commands that operate on properties (\fBzfs -list\fR, \fBzfs get\fR, \fBzfs set\fR, and so forth) can be used to manipulate -both native properties and user properties. Use the \fBzfs inherit\fR command -to clear a user property . If the property is not defined in any parent +are never validated. All of the commands that operate on properties +.Po +.Qq Nm Cm list , +.Qq Nm Cm get , +.Qq Nm Cm set +and so forth +.Pc +can be used to manipulate both native properties and user properties. Use the +.Qq Nm Cm inherit +command to clear a user property. If the property is not defined in any parent dataset, it is removed entirely. Property values are limited to 1024 characters. -.SH SUBCOMMANDS -.sp -.LP +.Sh SUBCOMMANDS All subcommands that modify state are logged persistently to the pool in their original form. -.sp -.ne 2 -.na -\fB\fBzfs ?\fR\fR -.ad -.br -.na -\fB\fBzfs rename\fR \fB-u\fR [\fB-p\fR] \fIfilesystem\fR \fIfilesystem\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width 2n +.It Xo +.Nm +.Op Fl \&? +.Xc +.Pp Displays a help message. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs create\fR [\fB-p\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... -\fIfilesystem\fR\fR -.ad -.sp .6 -.RS 4n -Creates a new \fBZFS\fR file system. The file system is automatically mounted -according to the \fBmountpoint\fR property inherited from the parent. -.sp -.ne 2 -.na -\fB\fB-p\fR\fR -.ad -.sp .6 -.RS 4n +.It Xo +.Nm +.Cm create +.Op Fl p +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... filesystem +.Xc +.Pp +Creates a new +.Tn ZFS +file system. The file system is automatically mounted according to the +.Sy mountpoint +property inherited from the parent. +.Bl -tag -width indent +.It Fl p Creates all the non-existing parent datasets. Datasets created in this manner -are automatically mounted according to the \fBmountpoint\fR property inherited -from their parent. Any property specified on the command line using the -\fB-o\fR option is ignored. If the target filesystem already exists, the -operation completes successfully. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIproperty\fR=\fIvalue\fR\fR -.ad -.sp .6 -.RS 4n -Sets the specified property as if the command \fBzfs set\fR -\fIproperty\fR=\fIvalue\fR was invoked at the same time the dataset was -created. Any editable \fBZFS\fR property can also be set at creation time. -Multiple \fB-o\fR options can be specified. An error results if the same -property is specified in multiple \fB-o\fR options. -.RE - -.sp -.ne 2 -.mk -.na -\fB\fB-u\fR\fR -.ad -.sp .6 -.RS 4n -Do not remount file systems during rename. If a file system's \fBmountpoint\fR property is set to \fBlegacy\fR or \fBnone\fR, file system is not unmounted even if this option is not given. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs create\fR [\fB-ps\fR] [\fB-b\fR \fIblocksize\fR] [\fB-o\fR -\fIproperty\fR=\fIvalue\fR] ... \fB-V\fR \fIsize\fR \fIvolume\fR\fR -.ad -.sp .6 -.RS 4n +are automatically mounted according to the +.Sy mountpoint +property inherited from their parent. Any property specified on the command +line using the +.Fl o +option is ignored. If the target filesystem already exists, the operation +completes successfully. +.It Fl o Ar property Ns = Ns Ar value +Sets the specified property as if the command +.Qq Nm Cm set Ar property Ns = Ns Ar value +was invoked at the same time the dataset was created. Any editable +.Tn ZFS +property can also be set at creation time. Multiple +.Fl o +options can be specified. An error results if the same property is specified in +multiple +.Fl o +options. +.El +.It Xo +.Nm +.Cm create +.Op Fl ps +.Op Fl b Ar blocksize +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... +.Fl V +.Ar size volume +.Xc +.Pp Creates a volume of the given size. The volume is exported as a block device in -\fB/dev/zvol/{dsk,rdsk}/\fR\fIpath\fR, where \fIpath\fR is the name of the -volume in the \fBZFS\fR namespace. The size represents the logical size as -exported by the device. By default, a reservation of equal size is created. -.sp -\fIsize\fR is automatically rounded up to the nearest 128 Kbytes to ensure that -the volume has an integral number of blocks regardless of \fIblocksize\fR. -.sp -.ne 2 -.na -\fB\fB-p\fR\fR -.ad -.sp .6 -.RS 4n +.Pa /dev/zvol/path , +where +.Ar path +is the name of the volume in the +.Tn ZFS +namespace. The size represents the logical size as exported by the device. By +default, a reservation of equal size is created. +.Pp +.Ar size +is automatically rounded up to the nearest 128 Kbytes to ensure that +the volume has an integral number of blocks regardless of +.Ar blocksize . +.Bl -tag -width indent +.It Fl p Creates all the non-existing parent datasets. Datasets created in this manner -are automatically mounted according to the \fBmountpoint\fR property inherited -from their parent. Any property specified on the command line using the -\fB-o\fR option is ignored. If the target filesystem already exists, the -operation completes successfully. -.RE - -.sp -.ne 2 -.na -\fB\fB-s\fR\fR -.ad -.sp .6 -.RS 4n -Creates a sparse volume with no reservation. See \fBvolsize\fR in the Native -Properties section for more information about sparse volumes. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIproperty\fR=\fIvalue\fR\fR -.ad -.sp .6 -.RS 4n -Sets the specified property as if the \fBzfs set\fR \fIproperty\fR=\fIvalue\fR +are automatically mounted according to the +.Sy mountpoint +property inherited from their parent. Any property specified on the command +line using the +.Fl o +option is ignored. If the target filesystem already exists, the operation +completes successfully. +.It Fl s +Creates a sparse volume with no reservation. See +.Sy volsize +in the +.Qq Sx Native Properties +section for more information about sparse volumes. +.It Fl b Ar blocksize +Equivalent to +.Fl o Cm volblocksize Ns = Ns Ar blocksize . +If this option is specified in conjunction with +.Fl o Cm volblocksize , +the resulting behavior is undefined. +.It Fl o Ar property Ns = Ns Ar value +Sets the specified property as if the +.Qq Nm Cm set Ar property Ns = Ns Ar value command was invoked at the same time the dataset was created. Any editable -\fBZFS\fR property can also be set at creation time. Multiple \fB-o\fR options -can be specified. An error results if the same property is specified in -multiple \fB-o\fR options. -.RE - -.sp -.ne 2 -.na -\fB\fB-b\fR \fIblocksize\fR\fR -.ad -.sp .6 -.RS 4n -Equivalent to \fB-o\fR \fBvolblocksize\fR=\fIblocksize\fR. If this option is -specified in conjunction with \fB-o\fR \fBvolblocksize\fR, the resulting -behavior is undefined. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs destroy\fR [\fB-rRf\fR] \fIfilesystem\fR|\fIvolume\fR\fR -.ad -.sp .6 -.RS 4n +.Tn ZFS +property can also be set at creation time. Multiple +.Fl o +options can be specified. An error results if the same property is specified in +multiple +.Fl o +options. +.El +.It Xo +.Nm +.Cm destroy +.Op Fl fnpRrv +.Ar filesystem Ns | Ns Ar volume +.Xc +.Pp Destroys the given dataset. By default, the command unshares any file systems that are currently shared, unmounts any file systems that are currently mounted, and refuses to destroy a dataset that has active dependents (children or clones). -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width indent +.It Fl r Recursively destroy all children. -.RE - -.sp -.ne 2 -.na -\fB\fB-R\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl R Recursively destroy all dependents, including cloned file systems outside the target hierarchy. -.RE - -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.sp .6 -.RS 4n -Force an unmount of any file systems using the \fBunmount -f\fR command. This -option has no effect on non-file systems or unmounted file systems. -.RE - -Extreme care should be taken when applying either the \fB-r\fR or the \fB-R\fR +.It Fl f +Force an unmount of any file systems using the +.Qq Nm Cm unmount Fl f +command. This option has no effect on non-file systems or unmounted file +systems. +.It Fl n +Do a dry-run ("No-op") deletion. No data will be deleted. This is useful in +conjunction with the +.Fl v +or +.Fl p +flags to determine what data would be deleted. +.It Fl p +Print machine-parsable verbose information about the deleted data. +.It Fl v +Print verbose information about the deleted data. +.El +.Pp +Extreme care should be taken when applying either the +.Fl r +or the +.Fl R options, as they can destroy large portions of a pool and cause unexpected behavior for mounted file systems in use. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs destroy\fR [\fB-rRd\fR] \fIsnapshot\fR\fR -.ad -.sp .6 -.RS 4n -The given snapshot is destroyed immediately if and only if the \fBzfs -destroy\fR command without the \fB-d\fR option would have destroyed it. Such -immediate destruction would occur, for example, if the snapshot had no clones -and the user-initiated reference count were zero. -.sp -If the snapshot does not qualify for immediate destruction, it is marked for +.It Xo +.Nm +.Cm destroy +.Op Fl dnpRrv +.Sm off +.Ar snapshot +.Ns Op % Ns Ar snapname +.Ns Op , Ns Ar ... +.Sm on +.Xc +.Pp +The given snapshots are destroyed immediately if and only if the +.Qq Nm Cm destroy +command without the +.Fl d +option would have destroyed it. Such immediate destruction would occur, for +example, if the snapshot had no clones and the user-initiated reference count +were zero. +.Pp +If a snapshot does not qualify for immediate destruction, it is marked for deferred deletion. In this state, it exists as a usable, visible snapshot until both of the preconditions listed above are met, at which point it is destroyed. -.sp -.ne 2 -.na -\fB\fB-d\fR\fR -.ad -.sp .6 -.RS 4n -Defer snapshot deletion. -.RE - -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n +.Pp +An inclusive range of snapshots may be specified by separating the +first and last snapshots with a percent sign +.Pq Sy % . +The first and/or last snapshots may be left blank, in which case the +filesystem's oldest or newest snapshot will be implied. +.Pp +Multiple snapshots +(or ranges of snapshots) of the same filesystem or volume may be specified +in a comma-separated list of snapshots. +Only the snapshot's short name (the +part after the +.Sy @ ) +should be specified when using a range or comma-separated list to identify +multiple snapshots. +.Bl -tag -width indent +.It Fl r Destroy (or mark for deferred deletion) all snapshots with this name in descendent file systems. -.RE - -.sp -.ne 2 -.na -\fB\fB-R\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl R Recursively destroy all dependents. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs snapshot\fR [\fB-r\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... -\fIfilesystem@snapname\fR|\fIvolume@snapname\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl n +Do a dry-run ("No-op") deletion. No data will be deleted. This is useful in +conjunction with the +.Fl v +or +.Fl p +flags to determine what data would be deleted. +.It Fl p +Print machine-parsable verbose information about the deleted data. +.It Fl v +Print verbose information about the deleted data. +.It Fl d +Defer snapshot deletion. +.El +.Pp +Extreme care should be taken when applying either the +.Fl r +or the +.Fl R +options, as they can destroy large portions of a pool and cause unexpected +behavior for mounted file systems in use. +.It Xo +.Nm +.Cm snapshot +.Op Fl r +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... +.Ar filesystem@snapname Ns | Ns volume@snapname +.Xc +.Pp Creates a snapshot with the given name. All previous modifications by successful system calls to the file system are part of the snapshot. See the -"Snapshots" section for details. -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n +.Qq Sx Snapshots +section for details. +.Bl -tag -width indent +.It Fl r Recursively create snapshots of all descendent datasets. Snapshots are taken atomically, so that all recursive snapshots correspond to the same moment in time. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIproperty\fR=\fIvalue\fR\fR -.ad -.sp .6 -.RS 4n -Sets the specified property; see \fBzfs create\fR for details. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs rollback\fR [\fB-rRf\fR] \fIsnapshot\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl o Ar property Ns = Ns Ar value +Sets the specified property; see +.Qq Nm Cm create +for details. +.El +.It Xo +.Nm +.Cm rollback +.Op Fl rRf +.Ar snapshot +.Xc +.Pp Roll back the given dataset to a previous snapshot. When a dataset is rolled back, all data that has changed since the snapshot is discarded, and the dataset reverts to the state at the time of the snapshot. By default, the command refuses to roll back to a snapshot other than the most recent one. In order to do so, all intermediate snapshots must be destroyed by specifying the -\fB-r\fR option. -.sp -The \fB-rR\fR options do not recursively destroy the child snapshots of a -recursive snapshot. Only the top-level recursive snapshot is destroyed by -either of these options. To completely roll back a recursive snapshot, you must -rollback the individual child snapshots. -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n +.Fl r +option. +.Bl -tag -width indent +.It Fl r Recursively destroy any snapshots more recent than the one specified. -.RE - -.sp -.ne 2 -.na -\fB\fB-R\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl R Recursively destroy any more recent snapshots, as well as any clones of those snapshots. -.RE - -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.sp .6 -.RS 4n -Used with the \fB-R\fR option to force an unmount of any clone file systems -that are to be destroyed. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs clone\fR [\fB-p\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... -\fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR\fR -.ad -.sp .6 -.RS 4n -Creates a clone of the given snapshot. See the "Clones" section for details. -The target dataset can be located anywhere in the \fBZFS\fR hierarchy, and is -created as the same type as the original. -.sp -.ne 2 -.na -\fB\fB-p\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl f +Used with the +.Fl R +option to force an unmount of any clone file systems that are to be destroyed. +.El +.It Xo +.Nm +.Cm clone +.Op Fl p +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... snapshot filesystem Ns | Ns Ar volume +.Xc +.Pp +Creates a clone of the given snapshot. See the +.Qq Sx Clones +section for details. The target dataset can be located anywhere in the +.Tn ZFS +hierarchy, and is created as the same type as the original. +.Bl -tag -width indent +.It Fl p Creates all the non-existing parent datasets. Datasets created in this manner -are automatically mounted according to the \fBmountpoint\fR property inherited -from their parent. If the target filesystem or volume already exists, the -operation completes successfully. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIproperty\fR=\fIvalue\fR\fR -.ad -.sp .6 -.RS 4n -Sets the specified property; see \fBzfs create\fR for details. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs promote\fR \fIclone-filesystem\fR\fR -.ad -.sp .6 -.RS 4n +are automatically mounted according to the +.Sy mountpoint +property inherited from their parent. If the target filesystem or volume +already exists, the operation completes successfully. +.It Fl o Ar property Ns = Ns Ar value +Sets the specified property; see +.Qq Nm Cm create +for details. +.El +.It Xo +.Nm +.Cm promote +.Ar clone-filesystem +.Xc +.Pp Promotes a clone file system to no longer be dependent on its "origin" snapshot. This makes it possible to destroy the file system that the clone was created from. The clone parent-child dependency relationship is reversed, so that the origin file system becomes a clone of the specified file system. -.sp +.Pp The snapshot that was cloned, and any snapshots previous to this snapshot, are now owned by the promoted clone. The space they use moves from the origin file system to the promoted clone, so enough space must be available to accommodate these snapshots. No new space is consumed by this operation, but the space accounting is adjusted. The promoted clone must not have any conflicting -snapshot names of its own. The \fBrename\fR subcommand can be used to rename -any conflicting snapshots. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs rename\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR -.ad -.br -.na -\fB\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR -.ad -.br -.na -\fB\fBzfs rename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR -\fIfilesystem\fR|\fIvolume\fR\fR -.ad -.sp .6 -.RS 4n +snapshot names of its own. The +.Cm rename +subcommand can be used to rename any conflicting snapshots. +.It Xo +.Nm +.Cm rename +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Xc +.It Xo +.Nm +.Cm rename +.Fl p +.Ar filesystem Ns | Ns Ar volume +.Ar filesystem Ns | Ns Ar volume +.Xc +.It Xo +.Nm +.Cm rename +.Fl u +.Op Fl p +.Ar filesystem filesystem +.Xc +.Pp Renames the given dataset. The new target can be located anywhere in the -\fBZFS\fR hierarchy, with the exception of snapshots. Snapshots can only be -renamed within the parent file system or volume. When renaming a snapshot, the -parent file system of the snapshot does not need to be specified as part of the -second argument. Renamed file systems can inherit new mount points, in which -case they are unmounted and remounted at the new mount point. -.sp -.ne 2 -.na -\fB\fB-p\fR\fR -.ad -.sp .6 -.RS 4n +.Tn ZFS +hierarchy, with the exception of snapshots. Snapshots can only be renamed +within the parent file system or volume. When renaming a snapshot, the parent +file system of the snapshot does not need to be specified as part of the second +argument. Renamed file systems can inherit new mount points, in which case they +are unmounted and remounted at the new mount point. +.Bl -tag -width indent +.It Fl p Creates all the nonexistent parent datasets. Datasets created in this manner -are automatically mounted according to the \fBmountpoint\fR property inherited -from their parent. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs rename\fR \fB-r\fR \fIsnapshot\fR \fIsnapshot\fR\fR -.ad -.sp .6 -.RS 4n +are automatically mounted according to the +.Sy mountpoint +property inherited from their parent. +.It Fl u +Do not remount file systems during rename. If a file system's +.Sy mountpoint +property is set to +.Cm legacy +or +.Cm none , +file system is not unmounted even if this option is not given. +.El +.It Xo +.Nm +.Cm rename +.Fl r +.Ar snapshot snapshot +.Xc +.Pp Recursively rename the snapshots of all descendent datasets. Snapshots are the only dataset that can be renamed recursively. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs\fR \fBlist\fR [\fB-r\fR|\fB-d\fR \fIdepth\fR] [\fB-H\fR] [\fB-o\fR -\fIproperty\fR[,\fI\&...\fR]] [ \fB-t\fR \fItype\fR[,\fI\&...\fR]] [ \fB-s\fR -\fIproperty\fR ] ... [ \fB-S\fR \fIproperty\fR ] ... -[\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR] ...\fR -.ad -.sp .6 -.RS 4n +.It Xo +.Nm +.Cm list +.Op Fl r Ns | Ns Fl d Ar depth +.Op Fl H +.Op Fl o Ar property Ns Op , Ns Ar ... +.Op Fl t Ar type Ns Op , Ns Ar ... +.Op Fl s Ar property +.Ar ... +.Op Fl S Ar property +.Ar ... +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Xc +.Pp Lists the property information for the given datasets in tabular form. If specified, you can list property information by the absolute pathname or the relative pathname. By default, all file systems and volumes are displayed. -Snapshots are displayed if the \fBlistsnaps\fR property is \fBon\fR (the -default is \fBoff\fR) . The following fields are displayed, -\fBname,used,available,referenced,mountpoint\fR. -.sp -.ne 2 -.na -\fB\fB-H\fR\fR -.ad -.sp .6 -.RS 4n +Snapshots are displayed if the +.Sy listsnaps +property is +.Cm on +(the default is +.Cm off ) . +The following fields are displayed, +.Sy name , used , available , referenced , mountpoint . +.Bl -tag -width indent +.It Fl r +Recursively display any children of the dataset on the command line. +.It Fl d Ar depth +Recursively display any children of the dataset, limiting the recursion to +.Ar depth . +A depth of +.Sy 1 +will display only the dataset and its direct children. +.It Fl H Used for scripting mode. Do not print headers and separate fields by a single tab instead of arbitrary white space. -.RE - -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n -Recursively display any children of the dataset on the command line. -.RE - -.sp -.ne 2 -.na -\fB\fB-d\fR \fIdepth\fR\fR -.ad -.sp .6 -.RS 4n -Recursively display any children of the dataset, limiting the recursion to -\fIdepth\fR. A depth of \fB1\fR will display only the dataset and its direct -children. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIproperty\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl o Ar property Ns Op , Ns Ar ... A comma-separated list of properties to display. The property must be: -.RS +4 -.TP -.ie t \(bu -.el o -One of the properties described in the "Native Properties" section -.RE -.RS +4 -.TP -.ie t \(bu -.el o +.Bl -bullet -offset 2n +.It +One of the properties described in the +.Qq Sx Native Properties +section +.It A user property -.RE -.RS +4 -.TP -.ie t \(bu -.el o -The value \fBname\fR to display the dataset name -.RE -.RS +4 -.TP -.ie t \(bu -.el o -The value \fBspace\fR to display space usage properties on file systems and -volumes. This is a shortcut for specifying \fB-o -name,avail,used,usedsnap,usedds,usedrefreserv,usedchild\fR \fB-t -filesystem,volume\fR syntax. -.RE -.RE - -.sp -.ne 2 -.na -\fB\fB-s\fR \fIproperty\fR\fR -.ad -.sp .6 -.RS 4n +.It +The value +.Cm name +to display the dataset name +.It +The value +.Cm space +to display space usage properties on file systems and volumes. This is a +shortcut for specifying +.Fl o +.Sy name,avail,used,usedsnap,usedds,usedrefreserv,usedchild +.Fl t +.Sy filesystem,volume +syntax. +.El +.It Fl t Ar type Ns Op , Ns Ar ... +A comma-separated list of types to display, where +.Ar type +is one of +.Sy filesystem , snapshot , volume , No or Sy all . +For example, specifying +.Fl o Cm snapshot +displays only snapshots. +.It Fl s Ar property A property for sorting the output by column in ascending order based on the value of the property. The property must be one of the properties described in -the "Properties" section, or the special value \fBname\fR to sort by the -dataset name. Multiple properties can be specified at one time using multiple -\fB-s\fR property options. Multiple \fB-s\fR options are evaluated from left to -right in decreasing order of importance. -.sp +the +.Qq Sx Properties +section, or the special value +.Cm name +to sort by the dataset name. Multiple properties can be specified at one time +using multiple +.Fl s +property options. Multiple +.Fl s +options are evaluated from left to right in decreasing order of importance. +.Pp The following is a list of sorting criteria: -.RS +4 -.TP -.ie t \(bu -.el o +.Bl -bullet -offset 2n +.It Numeric types sort in numeric order. -.RE -.RS +4 -.TP -.ie t \(bu -.el o +.It String types sort in alphabetical order. -.RE -.RS +4 -.TP -.ie t \(bu -.el o +.It Types inappropriate for a row sort that row to the literal bottom, regardless of the specified ordering. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -If no sorting options are specified the existing behavior of \fBzfs list\fR is -preserved. -.RE -.RE - -.sp -.ne 2 -.na -\fB\fB-S\fR \fIproperty\fR\fR -.ad -.sp .6 -.RS 4n -Same as the \fB-s\fR option, but sorts by property in descending order. -.RE - -.sp -.ne 2 -.na -\fB\fB-t\fR \fItype\fR\fR -.ad -.sp .6 -.RS 4n -A comma-separated list of types to display, where \fItype\fR is one of -\fBfilesystem\fR, \fBsnapshot\fR , \fBvolume\fR, or \fBall\fR. For example, -specifying \fB-t snapshot\fR displays only snapshots. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs set\fR \fIproperty\fR=\fIvalue\fR -\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...\fR -.ad -.sp .6 -.RS 4n +.It +If no sorting options are specified the existing behavior of +.Qq Nm Cm list +is preserved. +.El +.It Fl S Ar property +Same as the +.Fl s +option, but sorts by property in descending order. +.El +.It Xo +.Nm +.Cm set +.Ar property Ns = Ns Ar value +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Xc +.Pp Sets the property to the given value for each dataset. Only some properties can be edited. See the "Properties" section for more information on what properties can be set and acceptable values. Numeric values can be specified as exact -values, or in a human-readable form with a suffix of \fBB\fR, \fBK\fR, \fBM\fR, -\fBG\fR, \fBT\fR, \fBP\fR, \fBE\fR, \fBZ\fR (for bytes, kilobytes, megabytes, -gigabytes, terabytes, petabytes, exabytes, or zettabytes, respectively). User -properties can be set on snapshots. For more information, see the "User -Properties" section. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs get\fR [\fB-r\fR|\fB-d\fR \fIdepth\fR] [\fB-Hp\fR] [\fB-o\fR -\fIfield\fR[,...] [\fB-s\fR \fIsource\fR[,...] "\fIall\fR" | -\fIproperty\fR[,...] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...\fR -.ad -.sp .6 -.RS 4n +values, or in a human-readable form with a suffix of +.Sy B , K , M , G , T , P , E , Z +(for bytes, kilobytes, megabytes, gigabytes, terabytes, petabytes, exabytes, or +zettabytes, respectively). User properties can be set on snapshots. For more +information, see the +.Qq Sx User Properties +section. +.It Xo +.Nm +.Cm get +.Op Fl r Ns | Ns Fl d Ar depth +.Op Fl Hp +.Op Fl o Ar all | field Ns Op , Ns Ar ... +.Op Fl s Ar source Ns Op , Ns Ar ... +.Ar all | property Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Xc +.Pp Displays properties for the given datasets. If no datasets are specified, then the command displays properties for all datasets on the system. For each property, the following columns are displayed: -.sp -.in +2 -.nf - name Dataset name - property Property name - value Property value - source Property source. Can either be local, default, - temporary, inherited, or none (-). -.fi -.in -2 -.sp - -All columns are displayed by default, though this can be controlled by using -the \fB-o\fR option. This command takes a comma-separated list of properties as -described in the "Native Properties" and "User Properties" sections. -.sp -The special value \fBall\fR can be used to display all properties that apply to -the given dataset's type (filesystem, volume, or snapshot). -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n +.Pp +.Bl -hang -width "property" -offset indent -compact +.It name +Dataset name +.It property +Property name +.It value +Property value +.It source +Property source. Can either be local, default, temporary, inherited, or none +(\&-). +.El +.Pp +All columns except the +.Sy RECEIVED +column are displayed by default. The columns to display can be specified +by using the +.Fl o +option. This command takes a comma-separated list of properties as described in +the +.Qq Sx Native Properties +and +.Qq Sx User Properties +sections. +.Pp +The special value +.Cm all +can be used to display all properties that apply to the given dataset's type +(filesystem, volume, or snapshot). +.Bl -tag -width indent +.It Fl r Recursively display properties for any children. -.RE - -.sp -.ne 2 -.na -\fB\fB-d\fR \fIdepth\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl d Ar depth Recursively display any children of the dataset, limiting the recursion to -\fIdepth\fR. A depth of \fB1\fR will display only the dataset and its direct -children. -.RE - -.sp -.ne 2 -.na -\fB\fB-H\fR\fR -.ad -.sp .6 -.RS 4n +.Ar depth . +A depth of +.Sy 1 +will display only the dataset and its direct children. +.It Fl H Display output in a form more easily parsed by scripts. Any headers are omitted, and fields are explicitly separated by a single tab instead of an arbitrary amount of space. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIfield\fR\fR -.ad -.sp .6 -.RS 4n -A comma-separated list of columns to display. \fBname,property,value,source\fR -is the default value. -.RE - -.sp -.ne 2 -.na -\fB\fB-s\fR \fIsource\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl p +Display numbers in parseable (exact) values. +.It Fl o Cm all | Ar field Ns Op , Ns Ar ... +A comma-separated list of columns to display. Supported values are +.Sy name,property,value,received,source . +Default values are +.Sy name,property,value,source . +The keyword +.Cm all +specifies all columns. +.It Fl s Ar source Ns Op , Ns Ar ... A comma-separated list of sources to display. Those properties coming from a source other than those in this list are ignored. Each source must be one of -the following: \fBlocal,default,inherited,temporary,none\fR. The default value -is all sources. -.RE - -.sp -.ne 2 -.na -\fB\fB-p\fR\fR -.ad -.sp .6 -.RS 4n -Display numbers in parseable (exact) values. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs inherit\fR [\fB-r\fR] \fIproperty\fR -\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...\fR -.ad -.sp .6 -.RS 4n +the following: +.Sy local,default,inherited,temporary,received,none . +The default value is all sources. +.El +.It Xo +.Nm +.Cm inherit +.Op Fl rS +.Ar property +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Xc +.Pp Clears the specified property, causing it to be inherited from an ancestor. If no ancestor has the property set, then the default value is used. See the -"Properties" section for a listing of default values, and details on which -properties can be inherited. -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n +.Qq Sx Properties +section for a listing of default values, and details on which properties can be +inherited. +.Bl -tag -width indent +.It Fl r Recursively inherit the given property for all children. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs upgrade\fR [\fB-v\fR]\fR -.ad -.sp .6 -.RS 4n +.It Fl S +For properties with a received value, revert to this value. This flag has no +effect on properties that do not have a received value. +.El +.It Xo +.Nm +.Cm upgrade +.Op Fl v +.Xc +.Pp Displays a list of file systems that are not the most recent version. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs upgrade\fR [\fB-r\fR] [\fB-V\fR \fIversion\fR] [\fB-a\fR | -\fIfilesystem\fR]\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width indent +.It Fl v +Displays +.Tn ZFS +filesystem versions supported by the current software. The current +.Tn ZFS +filesystem version and all previous supported versions are displayed, along +with an explanation of the features provided with each version. +.El +.It Xo +.Nm +.Cm upgrade +.Op Fl r +.Op Fl V Ar version +.Fl a | Ar filesystem +.Xc +.Pp Upgrades file systems to a new on-disk version. Once this is done, the file systems will no longer be accessible on systems running older versions of the -software. \fBzfs send\fR streams generated from new snapshots of these file -systems cannot be accessed on systems running older versions of the software. -.sp +software. +.Qq Nm Cm send +streams generated from new snapshots of these file systems cannot be accessed +on systems running older versions of the software. +.Pp In general, the file system version is independent of the pool version. See -\fBzpool\fR(8) for information on the \fBzpool upgrade\fR command. -.sp +.Xr zpool 8 +for information on the +.Nm zpool Cm upgrade +command. +.Pp In some cases, the file system version and the pool version are interrelated and the pool version must be upgraded before the file system version can be upgraded. -.sp -.ne 2 -.na -\fB\fB-a\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width indent +.It Fl r +Upgrade the specified file system and all descendent file systems. +.It Fl V Ar version +Upgrade to the specified +.Ar version . +If the +.Fl V +flag is not specified, this command upgrades to the most recent version. This +option can only be used to increase the version number, and only up to the most +recent version supported by this software. +.It Fl a Upgrade all file systems on all imported pools. -.RE - -.sp -.ne 2 -.na -\fB\fIfilesystem\fR\fR -.ad -.sp .6 -.RS 4n +.It Ar filesystem Upgrade the specified file system. -.RE - -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n -Upgrade the specified file system and all descendent file systems -.RE - -.sp -.ne 2 -.na -\fB\fB-V\fR \fIversion\fR\fR -.ad -.sp .6 -.RS 4n -Upgrade to the specified \fIversion\fR. If the \fB-V\fR flag is not specified, -this command upgrades to the most recent version. This option can only be used -to increase the version number, and only up to the most recent version -supported by this software. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs userspace\fR [\fB-niHp\fR] [\fB-o\fR \fIfield\fR[,...]] [\fB-sS\fR -\fIfield\fR]... [\fB-t\fR \fItype\fR [,...]] \fIfilesystem\fR | -\fIsnapshot\fR\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm userspace +.Op Fl niHp +.Op Fl o Ar field Ns Op , Ns Ar ... +.Op Fl sS Ar field +.Ar ... +.Op Fl t Ar type Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar snapshot +.Xc +.Pp Displays space consumed by, and quotas on, each user in the specified -filesystem or snapshot. This corresponds to the \fBuserused@\fR\fIuser\fR and -\fBuserquota@\fR\fIuser\fR properties. -.sp -.ne 2 -.na -\fB\fB-n\fR\fR -.ad -.sp .6 -.RS 4n +filesystem or snapshot. This corresponds to the +.Sy userused@ Ns Ar user +and +.Sy userquota@ Ns Ar user +properties. +.Bl -tag -width indent +.It Fl n Print numeric ID instead of user/group name. -.RE - -.sp -.ne 2 -.na -\fB\fB-H\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl H Do not print headers, use tab-delimited output. -.RE - -.sp -.ne 2 -.na -\fB\fB-p\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl p Use exact (parseable) numeric output. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIfield\fR[,...]\fR -.ad -.sp .6 -.RS 4n +.It Fl o Ar field Ns Op , Ns Ar ... Display only the specified fields from the following set, -\fBtype,name,used,quota\fR.The default is to display all fields. -.RE - -.sp -.ne 2 -.na -\fB\fB-s\fR \fIfield\fR\fR -.ad -.sp .6 -.RS 4n -Sort output by this field. The \fIs\fR and \fIS\fR flags may be specified -multiple times to sort first by one field, then by another. The default is -\fB-s type\fR \fB-s name\fR. -.RE - -.sp -.ne 2 -.na -\fB\fB-S\fR \fIfield\fR\fR -.ad -.sp .6 -.RS 4n -Sort by this field in reverse order. See \fB-s\fR. -.RE - -.sp -.ne 2 -.na -\fB\fB-t\fR \fItype\fR[,...]\fR -.ad -.sp .6 -.RS 4n +.Sy type,name,used,quota . +The default is to display all fields. +.It Fl s Ar field +Sort output by this field. The +.Fl s +and +.Fl S +flags may be specified multiple times to sort first by one field, then by +another. The default is +.Fl s Cm type Fl s Cm name . +.It Fl S Ar field +Sort by this field in reverse order. See +.Fl s . +.It Fl t Ar type Ns Op , Ns Ar ... Print only the specified types from the following set, -\fBall,posixuser,smbuser,posixgroup,smbgroup\fR. -.sp -The default is \fB-t posixuser,smbuser\fR -.sp +.Sy all,posixuser,smbuser,posixgroup,smbgroup . +.Pp +The default is +.Fl t Cm posixuser,smbuser . +.Pp The default can be changed to include group types. -.RE - -.sp -.ne 2 -.na -\fB\fB-i\fR\fR -.ad -.sp .6 -.RS 4n -Translate SID to POSIX ID. The POSIX ID may be ephemeral if no mapping exists. -Normal POSIX interfaces (for example, \fBstat\fR(2), \fBls\fR \fB-l\fR) perform -this translation, so the \fB-i\fR option allows the output from \fBzfs -userspace\fR to be compared directly with those utilities. However, \fB-i\fR -may lead to confusion if some files were created by an SMB user before a -SMB-to-POSIX name mapping was established. In such a case, some files are owned -by the SMB entity and some by the POSIX entity. However, the \fB-i\fR option -will report that the POSIX entity has the total usage and quota for both. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs groupspace\fR [\fB-niHp\fR] [\fB-o\fR \fIfield\fR[,...]] [\fB-sS\fR -\fIfield\fR]... [\fB-t\fR \fItype\fR [,...]] \fIfilesystem\fR | -\fIsnapshot\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl i +Translate SID to POSIX ID. This flag has currently no effect on +.Fx . +.El +.It Xo +.Nm +.Cm groupspace +.Op Fl niHp +.Op Fl o Ar field Ns Op , Ns Ar ... +.Op Fl sS Ar field +.Ar ... +.Op Fl t Ar type Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar snapshot +.Xc +.Pp Displays space consumed by, and quotas on, each group in the specified -filesystem or snapshot. This subcommand is identical to \fBzfs userspace\fR, -except that the default types to display are \fB-t posixgroup,smbgroup\fR. -.sp -.in +2 -.nf -- -.fi -.in -2 -.sp - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs mount\fR\fR -.ad -.sp .6 -.RS 4n -Displays all \fBZFS\fR file systems currently mounted. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs mount\fR [\fB-vO\fR] [\fB-o\fR \fIoptions\fR] \fB-a\fR | -\fIfilesystem\fR\fR -.ad -.sp .6 -.RS 4n -Mounts \fBZFS\fR file systems. Invoked automatically as part of the boot -process. -.sp -.ne 2 -.na -\fB\fB-o\fR \fIoptions\fR\fR -.ad -.sp .6 -.RS 4n -An optional, comma-separated list of mount options to use temporarily for the -duration of the mount. See the "Temporary Mount Point Properties" section for -details. -.RE - -.sp -.ne 2 -.na -\fB\fB-O\fR\fR -.ad -.sp .6 -.RS 4n -Perform an overlay mount. See \fBmount\fR(8) for more information. -.RE - -.sp -.ne 2 -.na -\fB\fB-v\fR\fR -.ad -.sp .6 -.RS 4n +filesystem or snapshot. This subcommand is identical to +.Qq Nm Cm userspace , +except that the default types to display are +.Fl t Sy posixgroup,smbgroup . +.It Xo +.Nm +.Cm mount +.Xc +.Pp +Displays all +.Tn ZFS +file systems currently mounted. +.Bl -tag -width indent +.It Fl f +.El +.It Xo +.Nm +.Cm mount +.Op Fl vO +.Op Fl o Ar property Ns Op , Ns Ar ... +.Fl a | Ar filesystem +.Xc +.Pp +Mounts +.Tn ZFS +file systems. +.Bl -tag -width indent +.It Fl v Report mount progress. -.RE - -.sp -.ne 2 -.na -\fB\fB-a\fR\fR -.ad -.sp .6 -.RS 4n -Mount all available \fBZFS\fR file systems. Invoked automatically as part of -the boot process. -.RE - -.sp -.ne 2 -.na -\fB\fIfilesystem\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl O +Perform an overlay mount. Overlay mounts are not supported on +.Fx . +.It Fl o Ar property Ns Op , Ns Ar ... +An optional, comma-separated list of mount options to use temporarily for the +duration of the mount. See the +.Qq Sx Temporary Mount Point Properties +section for details. +.It Fl a +Mount all available +.Tn ZFS +file systems. +This command may be executed on +.Fx +system startup by +.Pa /etc/rc.d/zfs . +For more information, see variable +.Va zfs_enable +in +.Xr rc.conf 5 . +.It Ar filesystem Mount the specified filesystem. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs unmount\fR [\fB-f\fR] \fB-a\fR | \fIfilesystem\fR|\fImountpoint\fR\fR -.ad -.sp .6 -.RS 4n -Unmounts currently mounted \fBZFS\fR file systems. Invoked automatically as -part of the shutdown process. -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm unmount +.Op Fl f +.Fl a | Ar filesystem Ns | Ns Ar mountpoint +.Xc +.Pp +Unmounts currently mounted +.Tn ZFS +file systems. +.Bl -tag -width indent +.It Fl f Forcefully unmount the file system, even if it is currently in use. -.RE - -.sp -.ne 2 -.na -\fB\fB-a\fR\fR -.ad -.sp .6 -.RS 4n -Unmount all available \fBZFS\fR file systems. Invoked automatically as part of -the boot process. -.RE - -.sp -.ne 2 -.na -\fB\fIfilesystem\fR|\fImountpoint\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl a +Unmount all available +.Tn ZFS +file systems. +.It Ar filesystem | mountpoint Unmount the specified filesystem. The command can also be given a path to a -\fBZFS\fR file system mount point on the system. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs share\fR \fB-a\fR | \fIfilesystem\fR\fR -.ad -.sp .6 -.RS 4n -Shares available \fBZFS\fR file systems. -.sp -.ne 2 -.na -\fB\fB-a\fR\fR -.ad -.sp .6 -.RS 4n -Share all available \fBZFS\fR file systems. Invoked automatically as part of -the boot process. -.RE - -.sp -.ne 2 -.na -\fB\fIfilesystem\fR\fR -.ad -.sp .6 -.RS 4n -Share the specified filesystem according to the \fBsharenfs\fR and -\fBsharesmb\fR properties. File systems are shared when the \fBsharenfs\fR or -\fBsharesmb\fR property is set. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs unshare\fR \fB-a\fR | \fIfilesystem\fR|\fImountpoint\fR\fR -.ad -.sp .6 -.RS 4n -Unshares currently shared \fBZFS\fR file systems. This is invoked automatically -as part of the shutdown process. -.sp -.ne 2 -.na -\fB\fB-a\fR\fR -.ad -.sp .6 -.RS 4n -Unshare all available \fBZFS\fR file systems. Invoked automatically as part of -the boot process. -.RE - -.sp -.ne 2 -.na -\fB\fIfilesystem\fR|\fImountpoint\fR\fR -.ad -.sp .6 -.RS 4n +.Tn ZFS +file system mount point on the system. +.El +.It Xo +.Nm +.Cm share +.Fl a | Ar filesystem +.Xc +.Pp +Shares +.Tn ZFS +file systems that have the +.Sy sharenfs +property set. +.Bl -tag -width indent +.It Fl a +Share all +.Tn ZFS +file systems that have the +.Sy sharenfs +property set. +This command may be executed on +.Fx +system startup by +.Pa /etc/rc.d/zfs . +For more information, see variable +.Va zfs_enable +in +.Xr rc.conf 5 . +.It Ar filesystem +Share the specified filesystem according to the +.Tn sharenfs +property. File systems are shared when the +.Tn sharenfs +property is set. +.El +.It Xo +.Nm +.Cm unshare +.Fl a | Ar filesystem Ns | Ns Ar mountpoint +.Xc +.Pp +Unshares +.Tn ZFS +file systems that have the +.Tn sharenfs +property set. +.Bl -tag -width indent +.It Fl a +Unshares +.Tn ZFS +file systems that have the +.Sy sharenfs +property set. +This command may be executed on +.Fx +system shutdown by +.Pa /etc/rc.d/zfs . +For more information, see variable +.Va zfs_enable +in +.Xr rc.conf 5 . +.It Ar filesystem | mountpoint Unshare the specified filesystem. The command can also be given a path to a -\fBZFS\fR file system shared on the system. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs send\fR [\fB-vR\fR] [\fB-\fR[\fBiI\fR] \fIsnapshot\fR] -\fIsnapshot\fR\fR -.ad -.sp .6 -.RS 4n -Creates a stream representation of the second \fIsnapshot\fR, which is written -to standard output. The output can be redirected to a file or to a different -system (for example, using \fBssh\fR(1). By default, a full stream is -generated. -.sp -.ne 2 -.na -\fB\fB-i\fR \fIsnapshot\fR\fR -.ad -.sp .6 -.RS 4n -Generate an incremental stream from the first \fIsnapshot\fR to the second -\fIsnapshot\fR. The incremental source (the first \fIsnapshot\fR) can be -specified as the last component of the snapshot name (for example, the part -after the \fB@\fR), and it is assumed to be from the same file system as the -second \fIsnapshot\fR. -.sp +.Tn ZFS +file system shared on the system. +.El +.It Xo +.Nm +.Cm send +.Op Fl DnPpRrv +.Op Fl i Ar snapshot | Fl I Ar snapshot +.Ar snapshot +.Xc +.Pp +Creates a stream representation of the last +.Ar snapshot +argument (not part of +.Fl i +or +.Fl I ) +which is written to standard output. The output can be redirected to +a file or to a different system (for example, using +.Xr ssh 1 ) . +By default, a full stream is generated. +.Bl -tag -width indent +.It Fl i Ar snapshot +Generate an incremental stream from the +.Fl i Ar snapshot +to the last +.Ar snapshot . +The incremental source (the +.Fl i Ar snapshot ) +can be specified as the last component of the snapshot name (for example, the +part after the +.Sy @ ) , +and it is assumed to be from the same file system as the last +.Ar snapshot . +.Pp If the destination is a clone, the source may be the origin snapshot, which -must be fully specified (for example, \fBpool/fs@origin\fR, not just -\fB@origin\fR). -.RE - -.sp -.ne 2 -.na -\fB\fB-I\fR \fIsnapshot\fR\fR -.ad -.sp .6 -.RS 4n -Generate a stream package that sends all intermediary snapshots from the first -snapshot to the second snapshot. For example, \fB-I @a fs@d\fR is similar to -\fB-i @a fs@b; -i @b fs@c; -i @c fs@d\fR. The incremental source snapshot may -be specified as with the \fB-i\fR option. -.RE - -.sp -.ne 2 -.na -\fB\fB-R\fR\fR -.ad -.sp .6 -.RS 4n +must be fully specified (for example, +.Cm pool/fs@origin , +not just +.Cm @origin ) . +.It Fl I Ar snapshot +Generate a stream package that sends all intermediary snapshots from the +.Fl I Ar snapshot +to the last +.Ar snapshot . +For example, +.Ic -I @a fs@d +is similar to +.Ic -i @a fs@b; -i @b fs@c; -i @c fs@d . +The incremental source snapshot may be specified as with the +.Fl i +option. +.It Fl R Generate a replication stream package, which will replicate the specified filesystem, and all descendent file systems, up to the named snapshot. When received, all properties, snapshots, descendent file systems, and clones are preserved. -.sp -If the \fB-i\fR or \fB-I\fR flags are used in conjunction with the \fB-R\fR +.Pp +If the +.Fl i +or +.Fl I +flags are used in conjunction with the +.Fl R flag, an incremental replication stream is generated. The current values of properties, and current snapshot and file system names are set when the stream -is received. If the \fB-F\fR flag is specified when this stream is received, -snapshots and file systems that do not exist on the sending side are destroyed. -.RE - -.sp -.ne 2 -.na -\fB\fB-v\fR\fR -.ad -.sp .6 -.RS 4n +is received. If the +.Fl F +flag is specified when this stream is received, snapshots and file systems that + do not exist on the sending side are destroyed. +.It Fl D +Generate a deduplicated stream. Blocks which would have been sent multiple +times in the send stream will only be sent once. The receiving system must +also support this feature to receive a deduplicated stream. This flag can +be used regardless of the dataset's +.Sy dedup +property, but performance will be much better if the filesystem uses a +dedup-capable checksum (eg. +.Sy sha256 ) . +.It Fl r +Recursively send all descendant snapshots. This is similar to the +.Fl R +flag, but information about deleted and renamed datasets is not included, and +property information is only included if the +.Fl p +flag is specified. +.It Fl p +Include the dataset's properties in the stream. This flag is implicit when +.Fl R +is specified. The receiving system must also support this feature. +.It Fl n +Do a dry-run ("No-op") send. Do not generate any actual send data. This is +useful in conjunction with the +.Fl v +or +.Fl P +flags to determine what data will be sent. +.It Fl P +Print machine-parsable verbose information about the stream package generated. +.It Fl v Print verbose information about the stream package generated. -.RE - +.El +.Pp The format of the stream is committed. You will be able to receive your streams -on future versions of \fBZFS\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs receive\fR [\fB-vnFu\fR] -\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR -.ad -.br -.na -\fB\fBzfs receive\fR [\fB-vnFu\fR] \fB-d\fR \fIfilesystem\fR\fR -.ad -.sp .6 -.RS 4n +on future versions of +.Tn ZFS . +.It Xo +.Nm +.Cm receive +.Op Fl vnFu +.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot +.Xc +.It Xo +.Nm +.Cm receive +.Op Fl vnFu +.Op Fl d | e +.Ar filesystem +.Xc +.Pp Creates a snapshot whose contents are as specified in the stream provided on standard input. If a full stream is received, then a new file system is created -as well. Streams are created using the \fBzfs send\fR subcommand, which by -default creates a full stream. \fBzfs recv\fR can be used as an alias for -\fBzfs receive\fR. -.sp +as well. Streams are created using the +.Qq Nm Cm send +subcommand, which by default creates a full stream. +.Qq Nm Cm recv +can be used as an alias for +.Qq Nm Cm receive . +.Pp If an incremental stream is received, then the destination file system must already exist, and its most recent snapshot must match the incremental stream's -source. For \fBzvols\fR, the destination device link is destroyed and -recreated, which means the \fBzvol\fR cannot be accessed during the -\fBreceive\fR operation. -.sp +source. For +.Sy zvol Ns s, +the destination device link is destroyed and recreated, which means the +.Sy zvol +cannot be accessed during the +.Sy receive +operation. +.Pp When a snapshot replication package stream that is generated by using the -\fBzfs send\fR \fB-R\fR command is received, any snapshots that do not exist -on the sending location are destroyed by using the \fBzfs destroy\fR \fB-d\fR +.Qq Nm Cm send Fl R +command is received, any snapshots that do not exist on the sending location +are destroyed by using the +.Qq Nm Cm destroy Fl d command. -.sp +.Pp The name of the snapshot (and file system, if a full stream is received) that -this subcommand creates depends on the argument type and the \fB-d\fR option. -.sp -If the argument is a snapshot name, the specified \fIsnapshot\fR is created. If -the argument is a file system or volume name, a snapshot with the same name as -the sent snapshot is created within the specified \fIfilesystem\fR or -\fIvolume\fR. If the \fB-d\fR option is specified, the snapshot name is -determined by appending the sent snapshot's name to the specified -\fIfilesystem\fR. If the \fB-d\fR option is specified, any required file -systems within the specified one are created. -.sp -.ne 2 -.na -\fB\fB-d\fR\fR -.ad -.sp .6 -.RS 4n -Use the name of the sent snapshot to determine the name of the new snapshot as -described in the paragraph above. -.RE - -.sp -.ne 2 -.na -\fB\fB-u\fR\fR -.ad -.sp .6 -.RS 4n +this subcommand creates depends on the argument type and the +.Fl d +or +.Fl e +option. +.Pp +If the argument is a snapshot name, the specified +.Ar snapshot +is created. If the argument is a file system or volume name, a snapshot with +the same name as the sent snapshot is created within the specified +.Ar filesystem +or +.Ar volume . +If the +.Fl d +or +.Fl e +option is specified, the snapshot name is determined by appending the sent +snapshot's name to the specified +.Ar filesystem . +If the +.Fl d +option is specified, all but the pool name of the sent snapshot path is +appended (for example, +.Sy b/c@1 +appended from sent snapshot +.Sy a/b/c@1 ) , +and if the +.Fl e +option is specified, only the tail of the sent snapshot path is appended (for +example, +.Sy c@1 +appended from sent snapshot +.Sy a/b/c@1 ) . +In the case of +.Fl d , +any file systems needed to replicate the path of the sent snapshot are created +within the specified file system. +.Bl -tag -width indent +.It Fl d +Use the full sent snapshot path without the first element (without pool name) +to determine the name of the new snapshot as described in the paragraph above. +.It Fl e +Use only the last element of the sent snapshot path to determine the name of +the new snapshot as described in the paragraph above. +.It Fl u File system that is associated with the received stream is not mounted. -.RE - -.sp -.ne 2 -.na -\fB\fB-v\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl v Print verbose information about the stream and the time required to perform the receive operation. -.RE - -.sp -.ne 2 -.na -\fB\fB-n\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl n Do not actually receive the stream. This can be useful in conjunction with the -\fB-v\fR option to verify the name the receive operation would use. -.RE - -.sp -.ne 2 -.na -\fB\fB-F\fR\fR -.ad -.sp .6 -.RS 4n +.Fl v +option to verify the name the receive operation would use. +.It Fl F Force a rollback of the file system to the most recent snapshot before performing the receive operation. If receiving an incremental replication -stream (for example, one generated by \fBzfs send -R -[iI]\fR), destroy -snapshots and file systems that do not exist on the sending side. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs allow\fR \fIfilesystem\fR | \fIvolume\fR\fR -.ad -.sp .6 -.RS 4n +stream (for example, one generated by +.Qq Nm Cm send Fl R Fi iI ) , +destroy snapshots and file systems that do not exist on the sending side. +.El +.It Xo +.Nm +.Cm allow +.Ar filesystem Ns | Ns Ar volume +.Xc +.Pp Displays permissions that have been delegated on the specified filesystem or -volume. See the other forms of \fBzfs allow\fR for more information. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs allow\fR [\fB-ldug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...] -\fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR| \fIvolume\fR\fR -.ad -.br -.na -\fB\fBzfs allow\fR [\fB-ld\fR] \fB-e\fR \fIperm\fR|@\fIsetname\fR[,...] -\fIfilesystem\fR | \fIvolume\fR\fR -.ad -.sp .6 -.RS 4n -Delegates \fBZFS\fR administration permission for the file systems to -non-privileged users. -.sp -.ne 2 -.na -\fB[\fB-ug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...]\fR -.ad -.sp .6 -.RS 4n +volume. See the other forms of +.Qq Nm Cm allow +for more information. +.It Xo +.Nm +.Cm allow +.Op Fl ldug +.Cm everyone Ns | Ns Ar user Ns | Ns Ar group Ns Op , Ns Ar ... +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Xc +.It Xo +.Nm +.Cm allow +.Op Fl ld +.Fl e +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Xc +.Pp +Delegates +.Tn ZFS +administration permission for the file systems to non-privileged users. +.Bl -tag -width indent +.It Xo +.Op Fl ug +.Cm everyone Ns | Ns Ar user Ns | Ns Ar group Ns Op , Ns Ar ... +.Xc Specifies to whom the permissions are delegated. Multiple entities can be -specified as a comma-separated list. If neither of the \fB-ug\fR options are -specified, then the argument is interpreted preferentially as the keyword -"everyone", then as a user name, and lastly as a group name. To specify a user -or group named "everyone", use the \fB-u\fR or \fB-g\fR options. To specify a -group with the same name as a user, use the \fB-g\fR options. -.RE - -.sp -.ne 2 -.na -\fB[\fB-e\fR] \fIperm\fR|@\fIsetname\fR[,...]\fR -.ad -.sp .6 -.RS 4n -Specifies that the permissions be delegated to "everyone." Multiple permissions +specified as a comma-separated list. If neither of the +.Fl ug +options are specified, then the argument is interpreted preferentially as the +keyword "everyone", then as a user name, and lastly as a group name. To specify +a user or group named "everyone", use the +.Fl u +or +.Fl g +options. To specify a group with the same name as a user, use the +.Fl g +option. +.It Xo +.Op Fl e +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Xc +Specifies that the permissions be delegated to "everyone". +Multiple permissions may be specified as a comma-separated list. Permission names are the same as -\fBZFS\fR subcommand and property names. See the property list below. Property -set names, which begin with an at sign (\fB@\fR) , may be specified. See the -\fB-s\fR form below for details. -.RE - -.sp -.ne 2 -.na -\fB[\fB-ld\fR] \fIfilesystem\fR|\fIvolume\fR\fR -.ad -.sp .6 -.RS 4n -Specifies where the permissions are delegated. If neither of the \fB-ld\fR +.Tn ZFS +subcommand and property names. See the property list below. Property set names, +which begin with an at sign +.Pq Sy @ , +may be specified. See the +.Fl s +form below for details. +.It Xo +.Op Fl ld +.Ar filesystem Ns | Ns Ar volume +.Xc +Specifies where the permissions are delegated. If neither of the +.Fl ld options are specified, or both are, then the permissions are allowed for the -file system or volume, and all of its descendents. If only the \fB-l\fR option -is used, then is allowed "locally" only for the specified file system. If only -the \fB-d\fR option is used, then is allowed only for the descendent file -systems. -.RE - -.RE - -.sp -.LP -Permissions are generally the ability to use a \fBZFS\fR subcommand or change a -\fBZFS\fR property. The following permissions are available: -.sp -.in +2 -.nf -NAME TYPE NOTES -allow subcommand Must also have the permission that is being - allowed -clone subcommand Must also have the 'create' ability and 'mount' - ability in the origin file system -create subcommand Must also have the 'mount' ability -destroy subcommand Must also have the 'mount' ability -mount subcommand Allows mount/umount of ZFS datasets -promote subcommand Must also have the 'mount' - and 'promote' ability in the origin file system -receive subcommand Must also have the 'mount' and 'create' ability -rename subcommand Must also have the 'mount' and 'create' - ability in the new parent -rollback subcommand Must also have the 'mount' ability -send subcommand -share subcommand Allows sharing file systems over NFS or SMB - protocols -snapshot subcommand Must also have the 'mount' ability -groupquota other Allows accessing any groupquota@... property -groupused other Allows reading any groupused@... property -userprop other Allows changing any user property -userquota other Allows accessing any userquota@... property -userused other Allows reading any userused@... property - -aclinherit property -aclmode property -atime property -canmount property -casesensitivity property -checksum property -compression property -copies property -devices property -exec property -jailed property -mountpoint property -nbmand property -normalization property -primarycache property -quota property -readonly property -recordsize property -refquota property -refreservation property -reservation property -secondarycache property -setuid property -sharenfs property -sharesmb property -snapdir property -utf8only property -version property -volblocksize property -volsize property -vscan property -xattr property -.fi -.in -2 -.sp - -.sp -.ne 2 -.na -\fB\fBzfs allow\fR \fB-c\fR \fIperm\fR|@\fIsetname\fR[,...] -\fIfilesystem\fR|\fIvolume\fR\fR -.ad -.sp .6 -.RS 4n +file system or volume, and all of its descendents. If only the +.Fl l +option is used, then is allowed "locally" only for the specified file system. +If only the +.Fl d +option is used, then is allowed only for the descendent file systems. +.El +.Pp +Permissions are generally the ability to use a +.Tn ZFS +subcommand or change a +.Tn ZFS +property. The following permissions are available: +.Bl -column -offset 4n "secondarycache" "subcommand" +.It NAME Ta TYPE Ta NOTES +.It Xo allow Ta subcommand Ta Must +also have the permission that is being allowed +.Xc +.It Xo clone Ta subcommand Ta Must +also have the 'create' ability and 'mount' ability in the origin file system +.Xc +.It create Ta subcommand Ta Must also have the 'mount' ability +.It destroy Ta subcommand Ta Must also have the 'mount' ability +.It hold Ta subcommand Ta Allows adding a user hold to a snapshot +.It mount Ta subcommand Ta Allows mount/umount of Tn ZFS No datasets +.It Xo promote Ta subcommand Ta Must +also have the 'mount' and 'promote' ability in the origin file system +.Xc +.It receive Ta subcommand Ta Must also have the 'mount' and 'create' ability +.It Xo release Ta subcommand Ta Allows +releasing a user hold which might destroy the snapshot +.Xc +.It Xo rename Ta subcommand Ta Must +also have the 'mount' and 'create' ability in the new parent +.Xc +.It rollback Ta subcommand Ta Must also have the 'mount' ability +.It send Ta subcommand +.It share Ta subcommand Ta Allows Xo +sharing file systems over the +.Tn NFS +protocol +.Xc +.It snapshot Ta subcommand Ta Must also have the 'mount' ability +.It groupquota Ta other Ta Allows accessing any groupquota@... property +.It groupused Ta other Ta Allows reading any groupused@... property +.It userprop Ta other Ta Allows changing any user property +.It userquota Ta other Ta Allows accessing any userquota@... property +.It userused Ta other Ta Allows reading any userused@... property +.It Ta +.It aclinherit Ta property +.It aclmode Ta property +.It atime Ta property +.It canmount Ta property +.It casesensitivity Ta property +.It checksum Ta property +.It compression Ta property +.It copies Ta property +.It dedup Ta property +.It devices Ta property +.It exec Ta property +.It logbias Ta property +.It jailed Ta property +.It mlslabel Ta property +.It mountpoint Ta property +.It nbmand Ta property +.It normalization Ta property +.It primarycache Ta property +.It quota Ta property +.It readonly Ta property +.It recordsize Ta property +.It refquota Ta property +.It refreservation Ta property +.It reservation Ta property +.It secondarycache Ta property +.It setuid Ta property +.It sharenfs Ta property +.It sharesmb Ta property +.It snapdir Ta property +.It sync Ta property +.It utf8only Ta property +.It version Ta property +.It volblocksize Ta property +.It volsize Ta property +.It vscan Ta property +.It xattr Ta property +.El +.It Xo +.Nm +.Cm allow +.Fl c +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Xc +.Pp Sets "create time" permissions. These permissions are granted (locally) to the creator of any newly-created descendent file system. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs allow\fR \fB-s\fR @\fIsetname\fR \fIperm\fR|@\fIsetname\fR[,...] -\fIfilesystem\fR|\fIvolume\fR\fR -.ad -.sp .6 -.RS 4n +.It Xo +.Nm +.Cm allow +.Fl s +.Ar @setname +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Xc +.Pp Defines or adds permissions to a permission set. The set can be used by other -\fBzfs allow\fR commands for the specified file system and its descendents. -Sets are evaluated dynamically, so changes to a set are immediately reflected. -Permission sets follow the same naming restrictions as ZFS file systems, but -the name must begin with an "at sign" (\fB@\fR), and can be no more than 64 -characters long. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs unallow\fR [\fB-rldug\fR] -"\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...] -[\fIperm\fR|@\fIsetname\fR[, ...]] \fIfilesystem\fR|\fIvolume\fR\fR -.ad -.br -.na -\fB\fBzfs unallow\fR [\fB-rld\fR] \fB-e\fR [\fIperm\fR|@\fIsetname\fR [,...]] -\fIfilesystem\fR|\fIvolume\fR\fR -.ad -.br -.na -\fB\fBzfs unallow\fR [\fB-r\fR] \fB-c\fR [\fIperm\fR|@\fIsetname\fR[,...]]\fR -.ad -.br -.na -\fB\fIfilesystem\fR|\fIvolume\fR\fR -.ad -.sp .6 -.RS 4n -Removes permissions that were granted with the \fBzfs allow\fR command. No -permissions are explicitly denied, so other permissions granted are still in -effect. For example, if the permission is granted by an ancestor. If no -permissions are specified, then all permissions for the specified \fIuser\fR, -\fIgroup\fR, or \fIeveryone\fR are removed. Specifying "everyone" (or using the -\fB-e\fR option) only removes the permissions that were granted to "everyone", -not all permissions for every user and group. See the \fBzfs allow\fR command -for a description of the \fB-ldugec\fR options. -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n +.Qq Nm Cm allow +commands for the specified file system and its descendents. Sets are evaluated +dynamically, so changes to a set are immediately reflected. Permission sets +follow the same naming restrictions as ZFS file systems, but the name must +begin with an "at sign" +.Pq Sy @ , +and can be no more than 64 characters long. +.It Xo +.Nm +.Cm unallow +.Op Fl rldug +.Cm everyone Ns | Ns Ar user Ns | Ns Ar group Ns Op , Ns Ar ... +.Op Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Xc +.It Xo +.Nm +.Cm unallow +.Op Fl rld +.Fl e +.Op Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Xc +.It Xo +.Nm +.Cm unallow +.Op Fl r +.Fl c +.Op Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Xc +.Pp +Removes permissions that were granted with the +.Qq Nm Cm allow +command. No permissions are explicitly denied, so other permissions granted are +still in effect. For example, if the permission is granted by an ancestor. If +no permissions are specified, then all permissions for the specified +.Ar user , group , No or Ar everyone +are removed. Specifying "everyone" (or using the +.Fl e +option) only removes the permissions that were granted to "everyone", +not all permissions for every user and group. See the +.Qq Nm Cm allow +command for a description of the +.Fl ldugec +options. +.Bl -tag -width indent +.It Fl r Recursively remove the permissions from this file system and all descendents. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs unallow\fR [\fB-r\fR] \fB-s\fR @\fIsetname\fR -[\fIperm\fR|@\fIsetname\fR[,...]]\fR -.ad -.br -.na -\fB\fIfilesystem\fR|\fIvolume\fR\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm unallow +.Op Fl r +.Fl s +.Ar @setname +.Ar perm Ns | Ns Ar @setname Ns Op , Ns Ar ... +.Ar filesystem Ns | Ns Ar volume +.Xc +.Pp Removes permissions from a permission set. If no permissions are specified, then all permissions are removed, thus removing the set entirely. -.RE - -.sp -.ne 2 -.na -\fB\fBzfs hold\fR [\fB-r\fR] \fItag\fR \fIsnapshot\fR...\fR -.ad -.sp .6 -.RS 4n -Adds a single reference, named with the \fItag\fR argument, to the specified -snapshot or snapshots. Each snapshot has its own tag namespace, and tags must -be unique within that space. -.sp +.It Xo +.Nm +.Cm hold +.Op Fl r +.Ar tag snapshot ... +.Xc +.Pp +Adds a single reference, named with the +.Ar tag +argument, to the specified snapshot or snapshots. Each snapshot has its own tag +namespace, and tags must be unique within that space. +.Pp If a hold exists on a snapshot, attempts to destroy that snapshot by using the -\fBzfs destroy\fR command return \fBEBUSY\fR. -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n +.Qq Nm Cm destroy +command returns +.Em EBUSY . +.Bl -tag -width indent +.It Fl r Specifies that a hold with the given tag is applied recursively to the snapshots of all descendent file systems. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs holds\fR [\fB-r\fR] \fIsnapshot\fR...\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm holds +.Op Fl r +.Ar snapshot ... +.Xc +.Pp Lists all existing user references for the given snapshot or snapshots. -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width indent +.It Fl r Lists the holds that are set on the named descendent snapshots, in addition to listing the holds on the named snapshot. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs release\fR [\fB-r\fR] \fItag\fR \fIsnapshot\fR...\fR -.ad -.sp .6 -.RS 4n -Removes a single reference, named with the \fItag\fR argument, from the -specified snapshot or snapshots. The tag must already exist for each snapshot. -.sp -If a hold exists on a snapshot, attempts to destroy that snapshot by using the -\fBzfs destroy\fR command return \fBEBUSY\fR. -.sp -.ne 2 -.na -\fB\fB-r\fR\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm release +.Op Fl r +.Ar tag snapshot ... +.Xc +.Pp +Removes a single reference, named with the +.Ar tag +argument, from the specified snapshot or snapshots. The tag must already exist +for each snapshot. +.Bl -tag -width indent +.It Fl r Recursively releases a hold with the given tag on the snapshots of all descendent file systems. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzfs jail\fR \fIjailid\fR \fIfilesystem\fR\fR -.ad -.sp .6 -.RS 4n -Attaches the given file system to the given jail. From now on this file system -tree can be managed from within a jail if the "\fBjailed\fR" property has been -set. To use this functionality, sysctl \fBsecurity.jail.enforce_statfs\fR -should be set to 0 and sysctl \fBsecurity.jail.mount_allowed\fR should be set -to 1. -.RE - -.sp -.ne 2 -.mk -.na -\fB\fBzfs unjail\fR \fIjailid\fR \fIfilesystem\fR\fR -.ad -.sp .6 -.RS 4n -Detaches the given file system from the given jail. -.RE - -.RE - -.SH EXAMPLES -.LP -\fBExample 1 \fRCreating a ZFS File System Hierarchy -.sp -.LP -The following commands create a file system named \fBpool/home\fR and a file -system named \fBpool/home/bob\fR. The mount point \fB/export/home\fR is set for -the parent file system, and is automatically inherited by the child file -system. - -.sp -.in +2 -.nf -# \fBzfs create pool/home\fR -# \fBzfs set mountpoint=/export/home pool/home\fR -# \fBzfs create pool/home/bob\fR -.fi -.in -2 -.sp - -.LP -\fBExample 2 \fRCreating a ZFS Snapshot -.sp -.LP -The following command creates a snapshot named \fByesterday\fR. This snapshot -is mounted on demand in the \fB\&.zfs/snapshot\fR directory at the root of the -\fBpool/home/bob\fR file system. - -.sp -.in +2 -.nf -# \fBzfs snapshot pool/home/bob@yesterday\fR -.fi -.in -2 -.sp - -.LP -\fBExample 3 \fRCreating and Destroying Multiple Snapshots -.sp -.LP -The following command creates snapshots named \fByesterday\fR of -\fBpool/home\fR and all of its descendent file systems. Each snapshot is -mounted on demand in the \fB\&.zfs/snapshot\fR directory at the root of its -file system. The second command destroys the newly created snapshots. - -.sp -.in +2 -.nf -# \fBzfs snapshot -r pool/home@yesterday\fR -# \fBzfs destroy -r pool/home@yesterday\fR -.fi -.in -2 -.sp - -.LP -\fBExample 4 \fRDisabling and Enabling File System Compression -.sp -.LP -The following command disables the \fBcompression\fR property for all file -systems under \fBpool/home\fR. The next command explicitly enables -\fBcompression\fR for \fBpool/home/anne\fR. - -.sp -.in +2 -.nf -# \fBzfs set compression=off pool/home\fR -# \fBzfs set compression=on pool/home/anne\fR -.fi -.in -2 -.sp - -.LP -\fBExample 5 \fRListing ZFS Datasets -.sp -.LP +.El +.It Xo +.Nm +.Cm diff +.Op Fl FHt +.Ar snapshot +.Op Ar snapshot Ns | Ns Ar filesystem +.Xc +.Pp +Describes differences between a snapshot and a successor dataset. The +successor dataset can be a later snapshot or the current filesystem. +.Pp +The changed files are displayed including the change type. The change type +is displayed useing a single character. If a file or directory was renamed, +the old and the new names are displayed. +.Pp +The following change types can be displayed: +.Pp +.Bl -column -offset indent "CHARACTER" "CHANGE TYPE" +.It CHARACTER Ta CHANGE TYPE +.It \&+ Ta file was added +.It \&- Ta file was removed +.It \&M Ta file was modified +.It \&R Ta file was renamed +.El +.Bl -tag -width indent +.It Fl F +Display a single letter for the file type in second to last column. +.Pp +The following file types can be displayed: +.Pp +.Bl -column -offset indent "CHARACTER" "FILE TYPE" +.It CHARACTER Ta FILE TYPE +.It \&F Ta file +.It \&/ Ta directory +.It \&B Ta block device +.It \&@ Ta symbolic link +.It \&= Ta socket +.It \&> Ta door (not supported on Fx ) +.It \&| Ta FIFO (not supported on Fx ) +.It \&P Ta event portal (not supported on Fx ) +.El +.It Fl H +Machine-parseable output, fields separated a tab character. +.It Fl t +Display a change timestamp in the first column. +.El +.It Xo +.Nm +.Cm jail +.Ar jailid filesystem +.Xc +.Pp +Attaches the specified +.Ar filesystem +to the jail identified by JID +.Ar jailid . +From now on this file system tree can be managed from within a jail if the +.Sy jailed +property has been set. To use this functionality, the jail needs the +.Va enforce_statfs +parameter set to +.Sy 0 +and the +.Va allow.mount +parameter set to +.Sy 1 . +.Pp +See +.Xr jail 8 +for more information on managing jails and configuring the parameters above. +.It Xo +.Nm +.Cm unjail +.Ar jailid filesystem +.Xc +.Pp +Detaches the specified +.Ar filesystem +from the jail identified by JID +.Ar jailid . +.El +.Sh EXAMPLES +.Bl -tag -width 0n +.It Sy Example 1 No Creating a Tn ZFS No File System Hierarchy +.Pp +The following commands create a file system named +.Em pool/home +and a file system named +.Em pool/home/bob . +The mount point +.Pa /home +is set for the parent file system, and is automatically inherited by the child +file system. +.Bd -literal -offset 2n +.Li # Ic zfs create pool/home +.Li # Ic zfs set mountpoint=/home pool/home +.Li # Ic zfs create pool/home/bob +.Ed +.It Sy Example 2 No Creating a Tn ZFS No Snapshot +.Pp +The following command creates a snapshot named +.Sy yesterday . +This snapshot is mounted on demand in the +.Pa \&.zfs/snapshot +directory at the root of the +.Em pool/home/bob +file system. +.Bd -literal -offset 2n +.Li # Ic zfs snapshot pool/home/bob@yesterday +.Ed +.It Sy Example 3 No Creating and Destroying Multiple Snapshots +.Pp +The following command creates snapshots named +.Em yesterday +of +.Em pool/home +and all of its descendent file systems. Each snapshot is mounted on demand in +the +.Pa \&.zfs/snapshot +directory at the root of its file system. The second command destroys the newly +created snapshots. +.Bd -literal -offset 2n +.Li # Ic zfs snapshot -r pool/home@yesterday +.Li # Ic zfs destroy -r pool/home@yesterday +.Ed +.It Sy Example 4 No Disabling and Enabling File System Compression +.Pp +The following command disables the +.Sy compression +property for all file systems under +.Em pool/home . +The next command explicitly enables +.Sy compression +for +.Em pool/home/anne . +.Bd -literal -offset 2n +.Li # Ic zfs set compression=off pool/home +.Li # Ic zfs set compression=on pool/home/anne +.Ed +.It Sy Example 5 No Listing Tn ZFS No Datasets +.Pp The following command lists all active file systems and volumes in the system. -Snapshots are displayed if the \fBlistsnaps\fR property is \fBon\fR. The -default is \fBoff\fR. See \fBzpool\fR(8) for more information on pool -properties. - -.sp -.in +2 -.nf -# \fBzfs list\fR +Snapshots are displayed if the +.Sy listsnaps +property is +.Cm on . +The default is +.Cm off . +See +.Xr zpool 8 +for more information on pool properties. +.Bd -literal -offset 2n +.Li # Ic zfs list NAME USED AVAIL REFER MOUNTPOINT pool 450K 457G 18K /pool - pool/home 315K 457G 21K /export/home - pool/home/anne 18K 457G 18K /export/home/anne - pool/home/bob 276K 457G 276K /export/home/bob -.fi -.in -2 -.sp - -.LP -\fBExample 6 \fRSetting a Quota on a ZFS File System -.sp -.LP -The following command sets a quota of 50 Gbytes for \fBpool/home/bob\fR. - -.sp -.in +2 -.nf -# \fBzfs set quota=50G pool/home/bob\fR -.fi -.in -2 -.sp - -.LP -\fBExample 7 \fRListing ZFS Properties -.sp -.LP -The following command lists all properties for \fBpool/home/bob\fR. - -.sp -.in +2 -.nf -# \fBzfs get all pool/home/bob\fR + pool/home 315K 457G 21K /home + pool/home/anne 18K 457G 18K /home/anne + pool/home/bob 276K 457G 276K /home/bob +.Ed +.It Sy Example 6 No Setting a Quota on a Tn ZFS No File System +.Pp +The following command sets a quota of 50 Gbytes for +.Em pool/home/bob . +.Bd -literal -offset 2n +.Li # Ic zfs set quota=50G pool/home/bob +.Ed +.It Sy Example 7 No Listing Tn ZFS No Properties +.Pp +The following command lists all properties for +.Em pool/home/bob . +.Bd -literal -offset 2n +.Li # Ic zfs get all pool/home/bob NAME PROPERTY VALUE SOURCE pool/home/bob type filesystem - pool/home/bob creation Tue Jul 21 15:53 2009 - @@ -3123,7 +2829,7 @@ pool/home/bob mounted yes - pool/home/bob quota 20G local pool/home/bob reservation none default pool/home/bob recordsize 128K default -pool/home/bob mountpoint /pool/home/bob default +pool/home/bob mountpoint /home/bob default pool/home/bob sharenfs off default pool/home/bob checksum on default pool/home/bob compression on local @@ -3139,7 +2845,7 @@ pool/home/bob aclinherit restricted default pool/home/bob canmount on default pool/home/bob xattr on default pool/home/bob copies 1 default -pool/home/bob version 4 - +pool/home/bob version 5 - pool/home/bob utf8only off - pool/home/bob normalization none - pool/home/bob casesensitivity sensitive - @@ -3154,284 +2860,238 @@ pool/home/bob usedbysnapshots 0 - pool/home/bob usedbydataset 21K - pool/home/bob usedbychildren 0 - pool/home/bob usedbyrefreservation 0 - -.fi -.in -2 -.sp - -.sp -.LP +pool/home/bob logbias latency default +pool/home/bob dedup off default +pool/home/bob mlslabel - +pool/home/bob sync standard default +pool/home/bob refcompressratio 1.00x - +.Ed +.Pp The following command gets a single property value. - -.sp -.in +2 -.nf -# \fBzfs get -H -o value compression pool/home/bob\fR +.Bd -literal -offset 2n +.Li # Ic zfs get -H -o value compression pool/home/bob on -.fi -.in -2 -.sp - -.sp -.LP +.Ed +.Pp The following command lists all properties with local settings for -\fBpool/home/bob\fR. - -.sp -.in +2 -.nf -# \fBzfs get -r -s local -o name,property,value all pool/home/bob\fR +.Em pool/home/bob . +.Bd -literal -offset 2n +.Li # Ic zfs get -s local -o name,property,value all pool/home/bob NAME PROPERTY VALUE pool/home/bob quota 20G pool/home/bob compression on -.fi -.in -2 -.sp - -.LP -\fBExample 8 \fRRolling Back a ZFS File System -.sp -.LP -The following command reverts the contents of \fBpool/home/anne\fR to the -snapshot named \fByesterday\fR, deleting all intermediate snapshots. - -.sp -.in +2 -.nf -# \fBzfs rollback -r pool/home/anne@yesterday\fR -.fi -.in -2 -.sp - -.LP -\fBExample 9 \fRCreating a ZFS Clone -.sp -.LP +.Ed +.It Sy Example 8 No Rolling Back a Tn ZFS No File System +.Pp +The following command reverts the contents of +.Em pool/home/anne +to the snapshot named +.Em yesterday , +deleting all intermediate snapshots. +.Bd -literal -offset 2n +.Li # Ic zfs rollback -r pool/home/anne@yesterday +.Ed +.It Sy Example 9 No Creating a Tn ZFS No Clone +.Pp The following command creates a writable file system whose initial contents are -the same as \fBpool/home/bob@yesterday\fR. - -.sp -.in +2 -.nf -# \fBzfs clone pool/home/bob@yesterday pool/clone\fR -.fi -.in -2 -.sp - -.LP -\fBExample 10 \fRPromoting a ZFS Clone -.sp -.LP +the same as +.Em pool/home/bob@yesterday . +.Bd -literal -offset 2n +.Li # Ic zfs clone pool/home/bob@yesterday pool/clone +.Ed +.It Sy Example 10 No Promoting a Tn ZFS No Clone +.Pp The following commands illustrate how to test out changes to a file system, and then replace the original file system with the changed one, using clones, clone promotion, and renaming: - -.sp -.in +2 -.nf -# \fBzfs create pool/project/production\fR - populate /pool/project/production with data -# \fBzfs snapshot pool/project/production@today\fR -# \fBzfs clone pool/project/production@today pool/project/beta\fR -make changes to /pool/project/beta and test them -# \fBzfs promote pool/project/beta\fR -# \fBzfs rename pool/project/production pool/project/legacy\fR -# \fBzfs rename pool/project/beta pool/project/production\fR -once the legacy version is no longer needed, it can be destroyed -# \fBzfs destroy pool/project/legacy\fR -.fi -.in -2 -.sp - -.LP -\fBExample 11 \fRInheriting ZFS Properties -.sp -.LP -The following command causes \fBpool/home/bob\fR and \fBpool/home/anne\fR to -inherit the \fBchecksum\fR property from their parent. - -.sp -.in +2 -.nf -# \fBzfs inherit checksum pool/home/bob pool/home/anne\fR -.fi -.in -2 -.sp - -.LP -\fBExample 12 \fRRemotely Replicating ZFS Data -.sp -.LP +.Bd -literal -offset 2n +.Li # Ic zfs create pool/project/production +.Ed +.Pp +Populate +.Pa /pool/project/production +with data and continue with the following commands: +.Bd -literal -offset 2n +.Li # Ic zfs snapshot pool/project/production@today +.Li # Ic zfs clone pool/project/production@today pool/project/beta +.Ed +.Pp +Now make changes to +.Pa /pool/project/beta +and continue with the following commands: +.Bd -literal -offset 2n +.Li # Ic zfs promote pool/project/beta +.Li # Ic zfs rename pool/project/production pool/project/legacy +.Li # Ic zfs rename pool/project/beta pool/project/production +.Ed +.Pp +Once the legacy version is no longer needed, it can be destroyed. +.Bd -literal -offset 2n +.Li # Ic zfs destroy pool/project/legacy +.Ed +.It Sy Example 11 No Inheriting Tn ZFS No Properties +.Pp +The following command causes +.Em pool/home/bob +and +.Em pool/home/anne +to inherit the +.Sy checksum +property from their parent. +.Bd -literal -offset 2n +.Li # Ic zfs inherit checksum pool/home/bob pool/home/anne +.Ed +.It Sy Example 12 No Remotely Replicating Tn ZFS No Data +.Pp The following commands send a full stream and then an incremental stream to a -remote machine, restoring them into \fBpoolB/received/fs@a\fRand -\fBpoolB/received/fs@b\fR, respectively. \fBpoolB\fR must contain the file -system \fBpoolB/received\fR, and must not initially contain -\fBpoolB/received/fs\fR. - -.sp -.in +2 -.nf -# \fBzfs send pool/fs@a | \e\fR - \fBssh host zfs receive poolB/received/fs@a\fR -# \fBzfs send -i a pool/fs@b | ssh host \e\fR - \fBzfs receive poolB/received/fs\fR -.fi -.in -2 -.sp - -.LP -\fBExample 13 \fRUsing the \fBzfs receive\fR \fB-d\fR Option -.sp -.LP -The following command sends a full stream of \fBpoolA/fsA/fsB@snap\fR to a -remote machine, receiving it into \fBpoolB/received/fsA/fsB@snap\fR. The -\fBfsA/fsB@snap\fR portion of the received snapshot's name is determined from -the name of the sent snapshot. \fBpoolB\fR must contain the file system -\fBpoolB/received\fR. If \fBpoolB/received/fsA\fR does not exist, it is created -as an empty file system. - -.sp -.in +2 -.nf -# \fBzfs send poolA/fsA/fsB@snap | \e - ssh host zfs receive -d poolB/received\fR -.fi -.in -2 -.sp - -.LP -\fBExample 14 \fRSetting User Properties -.sp -.LP -The following example sets the user-defined \fBcom.example:department\fR +remote machine, restoring them into +.Sy poolB/received/fs@a +and +.Sy poolB/received/fs@b , +respectively. +.Sy poolB +must contain the file system +.Sy poolB/received , +and must not initially contain +.Sy poolB/received/fs . +.Bd -literal -offset 2n +.Li # Ic zfs send pool/fs@a | ssh host zfs receive poolB/received/fs@a +.Li # Ic zfs send -i a pool/fs@b | ssh host zfs receive poolB/received/fs +.Ed +.It Xo +.Sy Example 13 +Using the +.Qq zfs receive -d +Option +.Xc +.Pp +The following command sends a full stream of +.Sy poolA/fsA/fsB@snap +to a remote machine, receiving it into +.Sy poolB/received/fsA/fsB@snap . +The +.Sy fsA/fsB@snap +portion of the received snapshot's name is determined from the name of the sent +snapshot. +.Sy poolB +must contain the file system +.Sy poolB/received . +If +.Sy poolB/received/fsA +does not exist, it is created as an empty file system. +.Bd -literal -offset 2n +.Li # Ic zfs send poolA/fsA/fsB@snap | ssh host zfs receive -d poolB/received +.Ed +.It Sy Example 14 No Setting User Properties +.Pp +The following example sets the user-defined +.Sy com.example:department property for a dataset. - -.sp -.in +2 -.nf -# \fBzfs set com.example:department=12345 tank/accounting\fR -.fi -.in -2 -.sp - -.LP -\fBExample 16 \fRPerforming a Rolling Snapshot -.sp -.LP +.Bd -literal -offset 2n +.Li # Ic zfs set com.example:department=12345 tank/accounting +.Ed +.It Sy Example 15 No Performing a Rolling Snapshot +.Pp The following example shows how to maintain a history of snapshots with a consistent naming scheme. To keep a week's worth of snapshots, the user destroys the oldest snapshot, renames the remaining snapshots, and then creates a new snapshot, as follows: - -.sp -.in +2 -.nf -# \fBzfs destroy -r pool/users@7daysago\fR -# \fBzfs rename -r pool/users@6daysago @7daysago\fR -# \fBzfs rename -r pool/users@5daysago @6daysago\fR -# \fBzfs rename -r pool/users@yesterday @5daysago\fR -# \fBzfs rename -r pool/users@yesterday @4daysago\fR -# \fBzfs rename -r pool/users@yesterday @3daysago\fR -# \fBzfs rename -r pool/users@yesterday @2daysago\fR -# \fBzfs rename -r pool/users@today @yesterday\fR -# \fBzfs snapshot -r pool/users@today\fR -.fi -.in -2 -.sp - -.LP -\fBExample 17 \fRSetting \fBsharenfs\fR Property Options on a ZFS File System -.sp -.LP -The following commands show how to set \fBsharenfs\fR property options to -enable \fBrw\fR access for a set of \fBIP\fR addresses and to enable root -access for system \fBneo\fR on the \fBtank/home\fR file system. - -.sp -.in +2 -.nf -# \fB# zfs set sharenfs='rw=@123.123.0.0/16,root=neo' tank/home\fR -.fi -.in -2 -.sp - -.sp -.LP -If you are using \fBDNS\fR for host name resolution, specify the fully -qualified hostname. - -.LP -\fBExample 18 \fRDelegating ZFS Administration Permissions on a ZFS Dataset -.sp -.LP -The following example shows how to set permissions so that user \fBcindys\fR -can create, destroy, mount, and take snapshots on \fBtank/cindys\fR. The -permissions on \fBtank/cindys\fR are also displayed. - -.sp -.in +2 -.nf -# \fBzfs allow cindys create,destroy,mount,snapshot tank/cindys\fR -# \fBzfs allow tank/cindys\fR +.Bd -literal -offset 2n +.Li # Ic zfs destroy -r pool/users@7daysago +.Li # Ic zfs rename -r pool/users@6daysago @7daysago +.Li # Ic zfs rename -r pool/users@5daysago @6daysago +.Li # Ic zfs rename -r pool/users@yesterday @5daysago +.Li # Ic zfs rename -r pool/users@yesterday @4daysago +.Li # Ic zfs rename -r pool/users@yesterday @3daysago +.Li # Ic zfs rename -r pool/users@yesterday @2daysago +.Li # Ic zfs rename -r pool/users@today @yesterday +.Li # Ic zfs snapshot -r pool/users@today +.Ed +.It Xo +.Sy Example 16 +Setting +.Qq sharenfs +Property Options on a ZFS File System +.Xc +.Pp +The following command shows how to set +.Sy sharenfs +property options to enable root access for a specific network on the +.Em tank/home +file system. The contents of the +.Sy sharenfs +property are valid +.Xr exports 5 +options. +.Bd -literal -offset 2n +.Li # Ic zfs set sharenfs="maproot=root,network 192.168.0.0/24" tank/home +.Ed +.Pp +Another way to write this command with the same result is: +.Bd -literal -offset 2n +.Li # Ic set zfs sharenfs="-maproot=root -network 192.168.0.0/24" tank/home +.Ed +.It Xo +.Sy Example 17 +Delegating +.Tn ZFS +Administration Permissions on a +.Tn ZFS +Dataset +.Xc +.Pp +The following example shows how to set permissions so that user +.Em cindys +can create, destroy, mount, and take snapshots on +.Em tank/cindys . +The permissions on +.Em tank/cindys +are also displayed. +.Bd -literal -offset 2n +.Li # Ic zfs allow cindys create,destroy,mount,snapshot tank/cindys +.Li # Ic zfs allow tank/cindys ------------------------------------------------------------- Local+Descendent permissions on (tank/cindys) user cindys create,destroy,mount,snapshot ------------------------------------------------------------- -.fi -.in -2 -.sp - -.sp -.LP -Because the \fBtank/cindys\fR mount point permission is set to 755 by default, -user \fBcindys\fR will be unable to mount file systems under \fBtank/cindys\fR. -Set an \fBACL\fR similar to the following syntax to provide mount point access: -.sp -.in +2 -.nf -# \fBchmod A+user:cindys:add_subdirectory:allow /tank/cindys\fR -.fi -.in -2 -.sp - -.LP -\fBExample 19 \fRDelegating Create Time Permissions on a ZFS Dataset -.sp -.LP -The following example shows how to grant anyone in the group \fBstaff\fR to -create file systems in \fBtank/users\fR. This syntax also allows staff members -to destroy their own file systems, but not destroy anyone else's file system. -The permissions on \fBtank/users\fR are also displayed. - -.sp -.in +2 -.nf -# \fB# zfs allow staff create,mount tank/users\fR -# \fBzfs allow -c destroy tank/users\fR -# \fBzfs allow tank/users\fR +.Ed +.It Sy Example 18 No Delegating Create Time Permissions on a Tn ZFS No Dataset +.Pp +The following example shows how to grant anyone in the group +.Em staff +to create file systems in +.Em tank/users . +This syntax also allows staff members to destroy their own file systems, but +not destroy anyone else's file system. The permissions on +.Em tank/users +are also displayed. +.Bd -literal -offset 2n +.Li # Ic zfs allow staff create,mount tank/users +.Li # Ic zfs allow -c destroy tank/users +.Li # Ic zfs allow tank/users ------------------------------------------------------------- Create time permissions on (tank/users) create,destroy Local+Descendent permissions on (tank/users) group staff create,mount ------------------------------------------------------------- -.fi -.in -2 -.sp - -.LP -\fBExample 20 \fRDefining and Granting a Permission Set on a ZFS Dataset -.sp -.LP +.Ed +.It Xo +.Sy Example 19 +Defining and Granting a Permission Set on a +.Tn ZFS +Dataset +.Xc +.Pp The following example shows how to define and grant a permission set on the -\fBtank/users\fR file system. The permissions on \fBtank/users\fR are also -displayed. - -.sp -.in +2 -.nf -# \fBzfs allow -s @pset create,destroy,snapshot,mount tank/users\fR -# \fBzfs allow staff @pset tank/users\fR -# \fBzfs allow tank/users\fR +.Em tank/users +file system. The permissions on +.Em tank/users +are also displayed. +.Bd -literal -offset 2n +.Li # Ic zfs allow -s @pset create,destroy,snapshot,mount tank/users +.Li # Ic zfs allow staff @pset tank/users +.Li # Ic zfs allow tank/users ------------------------------------------------------------- Permission sets on (tank/users) @pset create,destroy,mount,snapshot @@ -3440,48 +3100,40 @@ Create time permissions on (tank/users) Local+Descendent permissions on (tank/users) group staff @pset,create,mount ------------------------------------------------------------- -.fi -.in -2 -.sp - -.LP -\fBExample 21 \fRDelegating Property Permissions on a ZFS Dataset -.sp -.LP +.Ed +.It Sy Example 20 No Delegating Property Permissions on a Tn ZFS No Dataset +.Pp The following example shows to grant the ability to set quotas and reservations -on the \fBusers/home\fR file system. The permissions on \fBusers/home\fR are -also displayed. - -.sp -.in +2 -.nf -# \fBzfs allow cindys quota,reservation users/home\fR -# \fBzfs allow users/home\fR +on the +.Sy users/home +file system. The permissions on +.Sy users/home +are also displayed. +.Bd -literal -offset 2n +.Li # Ic zfs allow cindys quota,reservation users/home +.Li # Ic zfs allow cindys ------------------------------------------------------------- Local+Descendent permissions on (users/home) user cindys quota,reservation ------------------------------------------------------------- -cindys% \fBzfs set quota=10G users/home/marks\fR -cindys% \fBzfs get quota users/home/marks\fR +.Li # Ic su - cindys +.Li cindys% Ic zfs set quota=10G users/home/marks +.Li cindys% Ic zfs get quota users/home/marks NAME PROPERTY VALUE SOURCE users/home/marks quota 10G local -.fi -.in -2 -.sp - -.LP -\fBExample 22 \fRRemoving ZFS Delegated Permissions on a ZFS Dataset -.sp -.LP +.Ed +.It Sy Example 21 No Removing ZFS Delegated Permissions on a Tn ZFS No Dataset +.Pp The following example shows how to remove the snapshot permission from the -\fBstaff\fR group on the \fBtank/users\fR file system. The permissions on -\fBtank/users\fR are also displayed. - -.sp -.in +2 -.nf -# \fBzfs unallow staff snapshot tank/users\fR -# \fBzfs allow tank/users\fR +.Em staff +group on the +.Em tank/users +file system. The permissions on +.Em tank/users +are also displayed. +.Bd -literal -offset 2n +.Li # Ic zfs unallow staff snapshot tank/users +.Li # Ic zfs allow tank/users ------------------------------------------------------------- Permission sets on (tank/users) @pset create,destroy,mount,snapshot @@ -3490,45 +3142,42 @@ Create time permissions on (tank/users) Local+Descendent permissions on (tank/users) group staff @pset,create,mount ------------------------------------------------------------- -.fi -.in -2 -.sp - -.SH EXIT STATUS -.sp -.LP +.Ed +.El +.Sh EXIT STATUS The following exit values are returned: -.sp -.ne 2 -.na -\fB\fB0\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -offset 2n -width 2n +.It 0 Successful completion. -.RE - -.sp -.ne 2 -.na -\fB\fB1\fR\fR -.ad -.sp .6 -.RS 4n +.It 1 An error occurred. - -.RE -.sp -.ne 2 -.na -\fB\fB2\fR\fR -.ad -.sp .6 -.RS 4n +.It 2 Invalid command line options were specified. -.RE - -.SH SEE ALSO -.sp -.LP -chmod(2), fsync(2), exports(5), fstab(5), jail(8), mount(8), zpool(8) +.El +.Sh SEE ALSO +.Xr chmod 2 , +.Xr fsync 2 , +.Xr exports 5 , +.Xr fstab 5 , +.Xr rc.conf 5 , +.Xr jail 8 , +.Xr mount 8 , +.Xr umount 8 , +.Xr zpool 8 +.Sh AUTHORS +This manual page is a +.Xr mdoc 7 +reimplementation of the +.Tn OpenSolaris +manual page +.Em zfs(1M) , +modified and customized for +.Fx +and licensed under the +Common Development and Distribution License +.Pq Tn CDDL . +.Pp +The +.Xr mdoc 7 +implementation of this manual page was initially written by +.An Martin Matuska Aq mm@FreeBSD.org . diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c index ff8984759857..78037d47923d 100644 --- a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c +++ b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c @@ -22,8 +22,9 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2011 Nexenta Systems, Inc. All rights reserved. + * Copyright (c) 2011 by Delphix. All rights reserved. * Copyright (c) 2011 Pawel Jakub Dawidek . - * All rights reserved. + * Copyright (c) 2011 Martin Matuska . All rights reserved. */ #include @@ -145,7 +146,7 @@ typedef enum { HELP_HOLD, HELP_HOLDS, HELP_RELEASE, - HELP_DIFF + HELP_DIFF, } zfs_help_t; typedef struct zfs_command { @@ -220,8 +221,9 @@ get_usage(zfs_help_t idx) "\tcreate [-ps] [-b blocksize] [-o property=value] ... " "-V \n")); case HELP_DESTROY: - return (gettext("\tdestroy [-rRf] \n" - "\tdestroy [-rRd] \n")); + return (gettext("\tdestroy [-fnpRrv] \n" + "\tdestroy [-dnpRrv] " + "[%][,...]\n")); case HELP_GET: return (gettext("\tget [-rHp] [-d max] " "[-o \"all\" | field[,...]] [-s source[,...]]\n" @@ -260,7 +262,8 @@ get_usage(zfs_help_t idx) case HELP_ROLLBACK: return (gettext("\trollback [-rRf] \n")); case HELP_SEND: - return (gettext("\tsend [-RDp] [-[iI] snapshot] \n")); + return (gettext("\tsend [-DnPpRrv] " + "[-i snapshot | -I snapshot] \n")); case HELP_SET: return (gettext("\tset " " ...\n")); @@ -296,11 +299,11 @@ get_usage(zfs_help_t idx) "\tunallow [-r] -s @setname [[,...]] " "\n")); case HELP_USERSPACE: - return (gettext("\tuserspace [-hniHp] [-o field[,...]] " + return (gettext("\tuserspace [-niHp] [-o field[,...]] " "[-sS field] ... [-t type[,...]]\n" "\t \n")); case HELP_GROUPSPACE: - return (gettext("\tgroupspace [-hniHpU] [-o field[,...]] " + return (gettext("\tgroupspace [-niHp] [-o field[,...]] " "[-sS field] ... [-t type[,...]]\n" "\t \n")); case HELP_HOLD: @@ -439,6 +442,8 @@ usage(boolean_t requested) (void) fprintf(fp, "YES NO | none\n"); (void) fprintf(fp, "\t%-15s ", "groupquota@..."); (void) fprintf(fp, "YES NO | none\n"); + (void) fprintf(fp, "\t%-15s ", "written@"); + (void) fprintf(fp, " NO NO \n"); (void) fprintf(fp, gettext("\nSizes are specified in bytes " "with standard units such as K, M, G, etc.\n")); @@ -884,15 +889,23 @@ zfs_do_create(int argc, char **argv) */ typedef struct destroy_cbdata { boolean_t cb_first; - int cb_force; - int cb_recurse; - int cb_error; - int cb_needforce; - int cb_doclones; - boolean_t cb_closezhp; + boolean_t cb_force; + boolean_t cb_recurse; + boolean_t cb_error; + boolean_t cb_doclones; zfs_handle_t *cb_target; - char *cb_snapname; boolean_t cb_defer_destroy; + boolean_t cb_verbose; + boolean_t cb_parsable; + boolean_t cb_dryrun; + nvlist_t *cb_nvl; + + /* first snap in contiguous run */ + zfs_handle_t *cb_firstsnap; + /* previous snap in contiguous run */ + zfs_handle_t *cb_prevsnap; + int64_t cb_snapused; + char *cb_snapspec; } destroy_cbdata_t; /* @@ -922,7 +935,7 @@ destroy_check_dependent(zfs_handle_t *zhp, void *data) (void) fprintf(stderr, gettext("use '-r' to destroy " "the following datasets:\n")); cbp->cb_first = B_FALSE; - cbp->cb_error = 1; + cbp->cb_error = B_TRUE; } (void) fprintf(stderr, "%s\n", zfs_get_name(zhp)); @@ -943,7 +956,8 @@ destroy_check_dependent(zfs_handle_t *zhp, void *data) (void) fprintf(stderr, gettext("use '-R' to destroy " "the following datasets:\n")); cbp->cb_first = B_FALSE; - cbp->cb_error = 1; + cbp->cb_error = B_TRUE; + cbp->cb_dryrun = B_TRUE; } (void) fprintf(stderr, "%s\n", zfs_get_name(zhp)); @@ -957,7 +971,20 @@ destroy_check_dependent(zfs_handle_t *zhp, void *data) static int destroy_callback(zfs_handle_t *zhp, void *data) { - destroy_cbdata_t *cbp = data; + destroy_cbdata_t *cb = data; + const char *name = zfs_get_name(zhp); + + if (cb->cb_verbose) { + if (cb->cb_parsable) { + (void) printf("destroy\t%s\n", name); + } else if (cb->cb_dryrun) { + (void) printf(gettext("would destroy %s\n"), + name); + } else { + (void) printf(gettext("will destroy %s\n"), + name); + } + } /* * Ignore pools (which we've already flagged as an error before getting @@ -969,13 +996,12 @@ destroy_callback(zfs_handle_t *zhp, void *data) return (0); } - /* - * Bail out on the first error. - */ - if (zfs_unmount(zhp, NULL, cbp->cb_force ? MS_FORCE : 0) != 0 || - zfs_destroy(zhp, cbp->cb_defer_destroy) != 0) { - zfs_close(zhp); - return (-1); + if (!cb->cb_dryrun) { + if (zfs_unmount(zhp, NULL, cb->cb_force ? MS_FORCE : 0) != 0 || + zfs_destroy(zhp, cb->cb_defer_destroy) != 0) { + zfs_close(zhp); + return (-1); + } } zfs_close(zhp); @@ -983,39 +1009,142 @@ destroy_callback(zfs_handle_t *zhp, void *data) } static int -destroy_snap_clones(zfs_handle_t *zhp, void *arg) +destroy_print_cb(zfs_handle_t *zhp, void *arg) { - destroy_cbdata_t *cbp = arg; - char thissnap[MAXPATHLEN]; - zfs_handle_t *szhp; - boolean_t closezhp = cbp->cb_closezhp; - int rv; + destroy_cbdata_t *cb = arg; + const char *name = zfs_get_name(zhp); + int err = 0; - (void) snprintf(thissnap, sizeof (thissnap), - "%s@%s", zfs_get_name(zhp), cbp->cb_snapname); - - libzfs_print_on_error(g_zfs, B_FALSE); - szhp = zfs_open(g_zfs, thissnap, ZFS_TYPE_SNAPSHOT); - libzfs_print_on_error(g_zfs, B_TRUE); - if (szhp) { - /* - * Destroy any clones of this snapshot - */ - if (zfs_iter_dependents(szhp, B_FALSE, destroy_callback, - cbp) != 0) { - zfs_close(szhp); - if (closezhp) - zfs_close(zhp); - return (-1); + if (nvlist_exists(cb->cb_nvl, name)) { + if (cb->cb_firstsnap == NULL) + cb->cb_firstsnap = zfs_handle_dup(zhp); + if (cb->cb_prevsnap != NULL) + zfs_close(cb->cb_prevsnap); + /* this snap continues the current range */ + cb->cb_prevsnap = zfs_handle_dup(zhp); + if (cb->cb_verbose) { + if (cb->cb_parsable) { + (void) printf("destroy\t%s\n", name); + } else if (cb->cb_dryrun) { + (void) printf(gettext("would destroy %s\n"), + name); + } else { + (void) printf(gettext("will destroy %s\n"), + name); + } } - zfs_close(szhp); + } else if (cb->cb_firstsnap != NULL) { + /* end of this range */ + uint64_t used = 0; + err = zfs_get_snapused_int(cb->cb_firstsnap, + cb->cb_prevsnap, &used); + cb->cb_snapused += used; + zfs_close(cb->cb_firstsnap); + cb->cb_firstsnap = NULL; + zfs_close(cb->cb_prevsnap); + cb->cb_prevsnap = NULL; + } + zfs_close(zhp); + return (err); +} + +static int +destroy_print_snapshots(zfs_handle_t *fs_zhp, destroy_cbdata_t *cb) +{ + int err; + assert(cb->cb_firstsnap == NULL); + assert(cb->cb_prevsnap == NULL); + err = zfs_iter_snapshots_sorted(fs_zhp, destroy_print_cb, cb); + if (cb->cb_firstsnap != NULL) { + uint64_t used = 0; + if (err == 0) { + err = zfs_get_snapused_int(cb->cb_firstsnap, + cb->cb_prevsnap, &used); + } + cb->cb_snapused += used; + zfs_close(cb->cb_firstsnap); + cb->cb_firstsnap = NULL; + zfs_close(cb->cb_prevsnap); + cb->cb_prevsnap = NULL; + } + return (err); +} + +static int +snapshot_to_nvl_cb(zfs_handle_t *zhp, void *arg) +{ + destroy_cbdata_t *cb = arg; + int err = 0; + + /* Check for clones. */ + if (!cb->cb_doclones) { + cb->cb_target = zhp; + cb->cb_first = B_TRUE; + err = zfs_iter_dependents(zhp, B_TRUE, + destroy_check_dependent, cb); } - cbp->cb_closezhp = B_TRUE; - rv = zfs_iter_filesystems(zhp, destroy_snap_clones, arg); - if (closezhp) - zfs_close(zhp); - return (rv); + if (err == 0) { + if (nvlist_add_boolean(cb->cb_nvl, zfs_get_name(zhp))) + nomem(); + } + zfs_close(zhp); + return (err); +} + +static int +gather_snapshots(zfs_handle_t *zhp, void *arg) +{ + destroy_cbdata_t *cb = arg; + int err = 0; + + err = zfs_iter_snapspec(zhp, cb->cb_snapspec, snapshot_to_nvl_cb, cb); + if (err == ENOENT) + err = 0; + if (err != 0) + goto out; + + if (cb->cb_verbose) { + err = destroy_print_snapshots(zhp, cb); + if (err != 0) + goto out; + } + + if (cb->cb_recurse) + err = zfs_iter_filesystems(zhp, gather_snapshots, cb); + +out: + zfs_close(zhp); + return (err); +} + +static int +destroy_clones(destroy_cbdata_t *cb) +{ + nvpair_t *pair; + for (pair = nvlist_next_nvpair(cb->cb_nvl, NULL); + pair != NULL; + pair = nvlist_next_nvpair(cb->cb_nvl, pair)) { + zfs_handle_t *zhp = zfs_open(g_zfs, nvpair_name(pair), + ZFS_TYPE_SNAPSHOT); + if (zhp != NULL) { + boolean_t defer = cb->cb_defer_destroy; + int err; + + /* + * We can't defer destroy non-snapshots, so set it to + * false while destroying the clones. + */ + cb->cb_defer_destroy = B_FALSE; + err = zfs_iter_dependents(zhp, B_FALSE, + destroy_callback, cb); + cb->cb_defer_destroy = defer; + zfs_close(zhp); + if (err != 0) + return (err); + } + } + return (0); } static int @@ -1024,25 +1153,35 @@ zfs_do_destroy(int argc, char **argv) destroy_cbdata_t cb = { 0 }; int c; zfs_handle_t *zhp; - char *cp; + char *at; zfs_type_t type = ZFS_TYPE_DATASET; /* check options */ - while ((c = getopt(argc, argv, "dfrR")) != -1) { + while ((c = getopt(argc, argv, "vpndfrR")) != -1) { switch (c) { + case 'v': + cb.cb_verbose = B_TRUE; + break; + case 'p': + cb.cb_verbose = B_TRUE; + cb.cb_parsable = B_TRUE; + break; + case 'n': + cb.cb_dryrun = B_TRUE; + break; case 'd': cb.cb_defer_destroy = B_TRUE; type = ZFS_TYPE_SNAPSHOT; break; case 'f': - cb.cb_force = 1; + cb.cb_force = B_TRUE; break; case 'r': - cb.cb_recurse = 1; + cb.cb_recurse = B_TRUE; break; case 'R': - cb.cb_recurse = 1; - cb.cb_doclones = 1; + cb.cb_recurse = B_TRUE; + cb.cb_doclones = B_TRUE; break; case '?': default: @@ -1057,7 +1196,7 @@ zfs_do_destroy(int argc, char **argv) /* check number of arguments */ if (argc == 0) { - (void) fprintf(stderr, gettext("missing path argument\n")); + (void) fprintf(stderr, gettext("missing dataset argument\n")); usage(B_FALSE); } if (argc > 1) { @@ -1065,92 +1204,118 @@ zfs_do_destroy(int argc, char **argv) usage(B_FALSE); } - /* - * If we are doing recursive destroy of a snapshot, then the - * named snapshot may not exist. Go straight to libzfs. - */ - if (cb.cb_recurse && (cp = strchr(argv[0], '@'))) { - int ret; + at = strchr(argv[0], '@'); + if (at != NULL) { + int err; - *cp = '\0'; - if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET)) == NULL) + /* Build the list of snaps to destroy in cb_nvl. */ + if (nvlist_alloc(&cb.cb_nvl, NV_UNIQUE_NAME, 0) != 0) + nomem(); + + *at = '\0'; + zhp = zfs_open(g_zfs, argv[0], + ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); + if (zhp == NULL) return (1); - *cp = '@'; - cp++; - if (cb.cb_doclones) { - boolean_t defer = cb.cb_defer_destroy; + cb.cb_snapspec = at + 1; + if (gather_snapshots(zfs_handle_dup(zhp), &cb) != 0 || + cb.cb_error) { + zfs_close(zhp); + nvlist_free(cb.cb_nvl); + return (1); + } - /* - * Temporarily ignore the defer_destroy setting since - * it's not supported for clones. - */ - cb.cb_defer_destroy = B_FALSE; - cb.cb_snapname = cp; - if (destroy_snap_clones(zhp, &cb) != 0) { - zfs_close(zhp); - return (1); + if (nvlist_empty(cb.cb_nvl)) { + (void) fprintf(stderr, gettext("could not find any " + "snapshots to destroy; check snapshot names.\n")); + zfs_close(zhp); + nvlist_free(cb.cb_nvl); + return (1); + } + + if (cb.cb_verbose) { + char buf[16]; + zfs_nicenum(cb.cb_snapused, buf, sizeof (buf)); + if (cb.cb_parsable) { + (void) printf("reclaim\t%llu\n", + cb.cb_snapused); + } else if (cb.cb_dryrun) { + (void) printf(gettext("would reclaim %s\n"), + buf); + } else { + (void) printf(gettext("will reclaim %s\n"), + buf); } - cb.cb_defer_destroy = defer; } - ret = zfs_destroy_snaps(zhp, cp, cb.cb_defer_destroy); - zfs_close(zhp); - if (ret) { - (void) fprintf(stderr, - gettext("no snapshots destroyed\n")); + if (!cb.cb_dryrun) { + if (cb.cb_doclones) + err = destroy_clones(&cb); + if (err == 0) { + err = zfs_destroy_snaps_nvl(zhp, cb.cb_nvl, + cb.cb_defer_destroy); + } } - return (ret != 0); - } - /* Open the given dataset */ - if ((zhp = zfs_open(g_zfs, argv[0], type)) == NULL) - return (1); - - cb.cb_target = zhp; - - /* - * Perform an explicit check for pools before going any further. - */ - if (!cb.cb_recurse && strchr(zfs_get_name(zhp), '/') == NULL && - zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) { - (void) fprintf(stderr, gettext("cannot destroy '%s': " - "operation does not apply to pools\n"), - zfs_get_name(zhp)); - (void) fprintf(stderr, gettext("use 'zfs destroy -r " - "%s' to destroy all datasets in the pool\n"), - zfs_get_name(zhp)); - (void) fprintf(stderr, gettext("use 'zpool destroy %s' " - "to destroy the pool itself\n"), zfs_get_name(zhp)); zfs_close(zhp); - return (1); + nvlist_free(cb.cb_nvl); + if (err != 0) + return (1); + } else { + /* Open the given dataset */ + if ((zhp = zfs_open(g_zfs, argv[0], type)) == NULL) + return (1); + + cb.cb_target = zhp; + + /* + * Perform an explicit check for pools before going any further. + */ + if (!cb.cb_recurse && strchr(zfs_get_name(zhp), '/') == NULL && + zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) { + (void) fprintf(stderr, gettext("cannot destroy '%s': " + "operation does not apply to pools\n"), + zfs_get_name(zhp)); + (void) fprintf(stderr, gettext("use 'zfs destroy -r " + "%s' to destroy all datasets in the pool\n"), + zfs_get_name(zhp)); + (void) fprintf(stderr, gettext("use 'zpool destroy %s' " + "to destroy the pool itself\n"), zfs_get_name(zhp)); + zfs_close(zhp); + return (1); + } + + /* + * Check for any dependents and/or clones. + */ + cb.cb_first = B_TRUE; + if (!cb.cb_doclones && + zfs_iter_dependents(zhp, B_TRUE, destroy_check_dependent, + &cb) != 0) { + zfs_close(zhp); + return (1); + } + + if (cb.cb_error) { + zfs_close(zhp); + return (1); + } + + if (zfs_iter_dependents(zhp, B_FALSE, destroy_callback, + &cb) != 0) { + zfs_close(zhp); + return (1); + } + + /* + * Do the real thing. The callback will close the + * handle regardless of whether it succeeds or not. + */ + if (destroy_callback(zhp, &cb) != 0) + return (1); } - /* - * Check for any dependents and/or clones. - */ - cb.cb_first = B_TRUE; - if (!cb.cb_doclones && !cb.cb_defer_destroy && - zfs_iter_dependents(zhp, B_TRUE, destroy_check_dependent, - &cb) != 0) { - zfs_close(zhp); - return (1); - } - - if (cb.cb_error || (!cb.cb_defer_destroy && - (zfs_iter_dependents(zhp, B_FALSE, destroy_callback, &cb) != 0))) { - zfs_close(zhp); - return (1); - } - - /* - * Do the real thing. The callback will close the handle regardless of - * whether it succeeds or not. - */ - - if (destroy_callback(zhp, &cb) != 0) - return (1); - return (0); } @@ -1249,6 +1414,17 @@ get_callback(zfs_handle_t *zhp, void *data) (void) strlcpy(buf, "-", sizeof (buf)); } + zprop_print_one_property(zfs_get_name(zhp), cbp, + pl->pl_user_prop, buf, sourcetype, source, NULL); + } else if (zfs_prop_written(pl->pl_user_prop)) { + sourcetype = ZPROP_SRC_LOCAL; + + if (zfs_prop_get_written(zhp, pl->pl_user_prop, + buf, sizeof (buf), cbp->cb_literal) != 0) { + sourcetype = ZPROP_SRC_NONE; + (void) strlcpy(buf, "-", sizeof (buf)); + } + zprop_print_one_property(zfs_get_name(zhp), cbp, pl->pl_user_prop, buf, sourcetype, source, NULL); } else { @@ -1795,8 +1971,8 @@ zfs_do_upgrade(int argc, char **argv) "---------------\n"); (void) printf(gettext(" 1 Initial ZFS filesystem version\n")); (void) printf(gettext(" 2 Enhanced directory entries\n")); - (void) printf(gettext(" 3 Case insensitive and File system " - "unique identifier (FUID)\n")); + (void) printf(gettext(" 3 Case insensitive and filesystem " + "user identifier (FUID)\n")); (void) printf(gettext(" 4 userquota, groupquota " "properties\n")); (void) printf(gettext(" 5 System attributes\n")); @@ -2676,6 +2852,13 @@ print_dataset(zfs_handle_t *zhp, zprop_list_t *pl, boolean_t scripted) else propstr = property; right_justify = B_TRUE; + } else if (zfs_prop_written(pl->pl_user_prop)) { + if (zfs_prop_get_written(zhp, pl->pl_user_prop, + property, sizeof (property), B_FALSE) != 0) + propstr = "-"; + else + propstr = property; + right_justify = B_TRUE; } else { if (nvlist_lookup_nvlist(userprops, pl->pl_user_prop, &propval) != 0) @@ -3302,9 +3485,6 @@ zfs_do_snapshot(int argc, char **argv) } /* - * zfs send [-vDp] -R [-i|-I <@snap>] - * zfs send [-vDp] [-i|-I <@snap>] - * * Send a backup stream to stdout. */ static int @@ -3316,11 +3496,11 @@ zfs_do_send(int argc, char **argv) zfs_handle_t *zhp; sendflags_t flags = { 0 }; int c, err; - nvlist_t *dbgnv; + nvlist_t *dbgnv = NULL; boolean_t extraverbose = B_FALSE; /* check options */ - while ((c = getopt(argc, argv, ":i:I:RDpv")) != -1) { + while ((c = getopt(argc, argv, ":i:I:RDpvnP")) != -1) { switch (c) { case 'i': if (fromname) @@ -3339,6 +3519,10 @@ zfs_do_send(int argc, char **argv) case 'p': flags.props = B_TRUE; break; + case 'P': + flags.parsable = B_TRUE; + flags.verbose = B_TRUE; + break; case 'v': if (flags.verbose) extraverbose = B_TRUE; @@ -3347,6 +3531,9 @@ zfs_do_send(int argc, char **argv) case 'D': flags.dedup = B_TRUE; break; + case 'n': + flags.dryrun = B_TRUE; + break; case ':': (void) fprintf(stderr, gettext("missing argument for " "'%c' option\n"), optopt); @@ -3372,7 +3559,7 @@ zfs_do_send(int argc, char **argv) usage(B_FALSE); } - if (isatty(STDOUT_FILENO)) { + if (!flags.dryrun && isatty(STDOUT_FILENO)) { (void) fprintf(stderr, gettext("Error: Stream can not be written to a terminal.\n" "You must redirect standard output.\n")); @@ -3426,10 +3613,10 @@ zfs_do_send(int argc, char **argv) if (flags.replicate && fromname == NULL) flags.doall = B_TRUE; - err = zfs_send(zhp, fromname, toname, flags, STDOUT_FILENO, NULL, 0, + err = zfs_send(zhp, fromname, toname, &flags, STDOUT_FILENO, NULL, 0, extraverbose ? &dbgnv : NULL); - if (extraverbose) { + if (extraverbose && dbgnv != NULL) { /* * dump_nvlist prints to stdout, but that's been * redirected to a file. Make it print to stderr @@ -3510,7 +3697,7 @@ zfs_do_receive(int argc, char **argv) return (1); } - err = zfs_receive(g_zfs, argv[0], flags, STDIN_FILENO, NULL); + err = zfs_receive(g_zfs, argv[0], &flags, STDIN_FILENO, NULL); return (err != 0); } diff --git a/cddl/contrib/opensolaris/cmd/zpool/zpool.8 b/cddl/contrib/opensolaris/cmd/zpool/zpool.8 index 8c41f42e1f12..cea41bcb5821 100644 --- a/cddl/contrib/opensolaris/cmd/zpool/zpool.8 +++ b/cddl/contrib/opensolaris/cmd/zpool/zpool.8 @@ -1,492 +1,492 @@ '\" te -.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved. -.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. -.\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the -.\" fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.\" Portions Copyright 2011 Justin T. Gibbs -.\" Portions Copyright 2011 Martin Matuska -.TH ZPOOL 8 "September 21, 2009" FreeBSD -.SH NAME -zpool \- configures ZFS storage pools -.SH SYNOPSIS -.LP -.nf -\fBzpool\fR [\fB-?\fR] -.fi - -.LP -.nf -\fBzpool add\fR [\fB-fn\fR] \fIpool\fR \fIvdev\fR ... -.fi - -.LP -.nf -\fBzpool attach\fR [\fB-f\fR] \fIpool\fR \fIdevice\fR \fInew_device\fR -.fi - -.LP -.nf -\fBzpool clear\fR \fIpool\fR [\fIdevice\fR] -.fi - -.LP -.nf -\fBzpool create\fR [\fB-fn\fR] [\fB-o\fR \fIproperty=value\fR] ... [\fB-O\fR \fIfile-system-property=value\fR] - ... [\fB-m\fR \fImountpoint\fR] [\fB-R\fR \fIroot\fR] \fIpool\fR \fIvdev\fR ... -.fi - -.LP -.nf -\fBzpool destroy\fR [\fB-f\fR] \fIpool\fR -.fi - -.LP -.nf -\fBzpool detach\fR \fIpool\fR \fIdevice\fR -.fi - -.LP -.nf -\fBzpool export\fR [\fB-f\fR] \fIpool\fR ... -.fi - -.LP -.nf -\fBzpool get\fR "\fIall\fR" | \fIproperty\fR[,...] \fIpool\fR ... -.fi - -.LP -.nf -\fBzpool history\fR [\fB-il\fR] [\fIpool\fR] ... -.fi - -.LP -.nf -\fBzpool import\fR [\fB-d\fR \fIdir\fR] [\fB-D\fR] -.fi - -.LP -.nf -\fBzpool import\fR [\fB-o \fImntopts\fR\fR] [\fB-o\fR \fIproperty=value\fR] ... [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR] - [\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fB-a\fR -.fi - -.LP -.nf -\fBzpool import\fR [\fB-o \fImntopts\fR\fR] [\fB-o\fR \fIproperty=value\fR] ... [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR] - [\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fIpool\fR |\fIid\fR [\fInewpool\fR] -.fi - -.LP -.nf -\fBzpool iostat\fR [\fB-T\fR u | d ] [\fB-v\fR] [\fIpool\fR] ... [\fIinterval\fR[\fIcount\fR]] -.fi - -.LP -.nf -\fBzpool labelclear\fR [\fB-f\fR] \fIdevice\fR -.fi - -.LP -.nf -\fBzpool list\fR [\fB-H\fR] [\fB-o\fR \fIproperty\fR[,...]] [\fIpool\fR] ... -.fi - -.LP -.nf -\fBzpool offline\fR [\fB-t\fR] \fIpool\fR \fIdevice\fR ... -.fi - -.LP -.nf -\fBzpool online\fR \fIpool\fR \fIdevice\fR ... -.fi - -.LP -.nf -\fBzpool remove\fR \fIpool\fR \fIdevice\fR ... -.fi - -.LP -.nf -\fBzpool replace\fR [\fB-f\fR] \fIpool\fR \fIdevice\fR [\fInew_device\fR] -.fi - -.LP -.nf -\fBzpool scrub\fR [\fB-s\fR] \fIpool\fR ... -.fi - -.LP -.nf -\fBzpool set\fR \fIproperty\fR=\fIvalue\fR \fIpool\fR -.fi - -.LP -.nf -\fBzpool status\fR [\fB-xv\fR] [\fIpool\fR] ... -.fi - -.LP -.nf -\fBzpool upgrade\fR -.fi - -.LP -.nf -\fBzpool upgrade\fR \fB-v\fR -.fi - -.LP -.nf -\fBzpool upgrade\fR [\fB-V\fR \fIversion\fR] \fB-a\fR | \fIpool\fR ... -.fi - -.SH DESCRIPTION -.sp -.LP -The \fBzpool\fR command configures \fBZFS\fR storage pools. A storage pool is a -collection of devices that provides physical storage and data replication for -\fBZFS\fR datasets. -.sp -.LP -All datasets within a storage pool share the same space. See \fBzfs\fR(8) for -information on managing datasets. -.SS "Virtual Devices (\fBvdev\fRs)" -.sp -.LP -A "virtual device" describes a single device or a collection of devices -organized according to certain performance and fault characteristics. The -following virtual devices are supported: -.sp -.ne 2 -.na -\fB\fBdisk\fR\fR -.ad -.RS 10n -A block device, typically located under \fB/dev\fR. \fBZFS\fR can use -individual slices, partitions or \fBgeom(4)\fR objects, though the recommended -mode of operation is to use whole disks. A disk can be specified by a full -path, or it can be a shorthand name (the relative portion of the path under -"/dev"). For example, "da0" is equivalent to "/dev/da0". -.RE - -.sp -.ne 2 -.na -\fB\fBfile\fR\fR -.ad -.RS 10n +.\" Copyright (c) 2011, Martin Matuska . +.\" All Rights Reserved. +.\" +.\" The contents of this file are subject to the terms of the +.\" Common Development and Distribution License (the "License"). +.\" You may not use this file except in compliance with the License. +.\" +.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +.\" or http://www.opensolaris.org/os/licensing. +.\" See the License for the specific language governing permissions +.\" and limitations under the License. +.\" +.\" When distributing Covered Code, include this CDDL HEADER in each +.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. +.\" If applicable, add the following below this CDDL HEADER, with the +.\" fields enclosed by brackets "[]" replaced with your own identifying +.\" information: Portions Copyright [yyyy] [name of copyright owner] +.\" +.\" Copyright (c) 2010, Sun Microsystems, Inc. All Rights Reserved. +.\" Copyright 2011, Nexenta Systems, Inc. All Rights Reserved. +.\" Copyright (c) 2011, Justin T. Gibbs +.\" +.\" $FreeBSD$ +.\" +.Dd November 28, 2011 +.Dt ZPOOL 8 +.Os +.Sh NAME +.Nm zpool +.Nd configures ZFS storage pools +.Sh SYNOPSIS +.Nm +.Op Fl \&? +.Nm +.Cm add +.Op Fl fn +.Ar pool vdev ... +.Nm +.Cm attach +.Op Fl f +.Ar pool device new_device +.Nm +.Cm clear +.Op Fl F Op Fl n +.Ar pool +.Op Ar device +.Nm +.Cm create +.Op Fl fn +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... +.Op Fl O Ar file-system-property Ns = Ns Ar value +.Ar ... +.Op Fl m Ar mountpoint +.Op Fl R Ar root +.Ar pool vdev ... +.Nm +.Cm destroy +.Op Fl f +.Ar pool +.Nm +.Cm detach +.Ar pool device +.Nm +.Cm export +.Op Fl f +.Ar pool ... +.Nm +.Cm get +.Ar all | property Ns Op , Ns Ar ... +.Ar pool ... +.Nm +.Cm history +.Op Fl il +.Op Ar pool +.Ar ... +.Nm +.Cm import +.Op Fl d Ar dir | Fl c Ar cachefile +.Op Fl D +.Nm +.Cm import +.Op Fl o Ar mntopts +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... +.Op Fl d Ar dir | Fl c Ar cachefile +.Op Fl D +.Op Fl f +.Op Fl m +.Op Fl N +.Op Fl R Ar root +.Op Fl F Op Fl n +.Fl a +.Nm +.Cm import +.Op Fl o Ar mntopts +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... +.Op Fl d Ar dir | Fl c Ar cachefile +.Op Fl D +.Op Fl f +.Op Fl m +.Op Fl N +.Op Fl R Ar root +.Op Fl F Op Fl n +.Ar pool | id +.Op Ar newpool +.Nm +.Cm iostat +.Op Fl T Cm d Ns | Ns Cm u +.Op Fl v +.Op Ar pool +.Ar ... +.Nm +.Cm labelclear +.Op Fl f +.Ar device +.Nm +.Cm list +.Op Fl H +.Op Fl o Ar property Ns Op , Ns Ar ... +.Op Fl T Cm d Ns | Ns Cm u +.Op Ar pool +.Ar ... +.Op Ar inverval Op Ar count +.Nm +.Cm offline +.Op Fl t +.Ar pool device ... +.Nm +.Cm online +.Op Fl e +.Ar pool device ... +.Nm +.Cm reguid +.Ar pool +.Nm +.Cm remove +.Ar pool device ... +.Nm +.Cm replace +.Op Fl f +.Ar pool device +.Op Ar new_device +.Nm +.Cm scrub +.Op Fl s +.Ar pool ... +.Nm +.Cm set +.Ar property Ns = Ns Ar value pool +.Nm +.Cm split +.Op Fl n +.Op Fl R Ar altroot +.Op Fl o Ar mntopts +.Op Fl o Ar property Ns = Ns Ar value +.Ar pool newpool +.Op Ar device ... +.Nm +.Cm status +.Op Fl vx +.Op Fl T Cm d Ns | Ns Cm u +.Op Ar pool +.Ar ... +.Op Ar interval Op Ar count +.Nm +.Cm upgrade +.Op Fl v +.Nm +.Cm upgrade +.Op Fl V Ar version +.Fl a | Ar pool ... +.Sh DESCRIPTION +The +.Nm +command configures +.Tn ZFS +storage pools. A storage pool is a collection of devices that provides physical +storage and data replication for +.Tn ZFS +datasets. +.Pp +All datasets within a storage pool share the same space. See +.Xr zfs 8 +for information on managing datasets. +.Ss Virtual Devices (vdevs) +A +.Qq virtual device +.Pq No vdev +describes a single device or a collection of devices organized according to +certain performance and fault characteristics. The following virtual devices +are supported: +.Bl -tag +.It Sy disk +A block device, typically located under +.Pa /dev . +.Tn ZFS +can use individual slices or partitions, though the recommended mode of +operation is to use whole disks. A disk can be specified by a full path to the +device or the +.Xr geom 4 +provider name. When given a whole disk, +.Tn ZFS +automatically labels the disk, if necessary. +.It Sy file A regular file. The use of files as a backing store is strongly discouraged. It is designed primarily for experimental purposes, as the fault tolerance of a -file is only as good as the file system of which it is a part. A file must be +file is only as good the file system of which it is a part. A file must be specified by a full path. -.RE - -.sp -.ne 2 -.na -\fB\fBmirror\fR\fR -.ad -.RS 10n +.It Sy mirror A mirror of two or more devices. Data is replicated in an identical fashion -across all components of a mirror. A mirror with \fIN\fR disks of size \fIX\fR -can hold \fIX\fR bytes and can withstand (\fIN-1\fR) devices failing before -data integrity is compromised. -.RE - -.sp -.ne 2 -.na -\fB\fBraidz\fR\fR -.ad -.br -.na -\fB\fBraidz1\fR\fR -.ad -.br -.na -\fB\fBraidz2\fR\fR -.ad -.br -.na -\fB\fBraidz3\fR\fR -.ad -.RS 10n -A variation on \fBRAID-5\fR that allows for better distribution of parity and -eliminates the "\fBRAID-5\fR write hole" (in which data and parity become -inconsistent after a power loss). Data and parity is striped across all disks -within a \fBraidz\fR group. -.sp -A \fBraidz\fR group can have single-, double- , or triple parity, meaning that -the \fBraidz\fR group can sustain one, two, or three failures, respectively, -without losing any data. The \fBraidz1\fR \fBvdev\fR type specifies a -single-parity \fBraidz\fR group; the \fBraidz2\fR \fBvdev\fR type specifies a -double-parity \fBraidz\fR group; and the \fBraidz3\fR \fBvdev\fR type specifies -a triple-parity \fBraidz\fR group. The \fBraidz\fR \fBvdev\fR type is an alias -for \fBraidz1\fR. -.sp -A \fBraidz\fR group with \fIN\fR disks of size \fIX\fR with \fIP\fR parity -disks can hold approximately (\fIN-P\fR)*\fIX\fR bytes and can withstand -\fIP\fR device(s) failing before data integrity is compromised. The minimum -number of devices in a \fBraidz\fR group is one more than the number of parity -disks. The recommended number is between 3 and 9 to help increase performance. -.RE - -.sp -.ne 2 -.na -\fB\fBspare\fR\fR -.ad -.RS 10n -A special pseudo-\fBvdev\fR which keeps track of available hot spares for a -pool. For more information, see the "Hot Spares" section. -.RE - -.sp -.ne 2 -.na -\fB\fBlog\fR\fR -.ad -.RS 10n +across all components of a mirror. A mirror with +.Em N +disks of size +.Em X +can hold +.Em X +bytes and can withstand +.Pq Em N-1 +devices failing before data integrity is compromised. +.It Sy raidz +(or +.Sy raidz1 raidz2 raidz3 ) . +A variation on +.Sy RAID-5 +that allows for better distribution of parity and eliminates the +.Qq Sy RAID-5 +write hole (in which data and parity become inconsistent after a power loss). +Data and parity is striped across all disks within a +.No raidz +group. +.Pp +A +.No raidz +group can have single-, double- , or triple parity, meaning that the +.No raidz +group can sustain one, two, or three failures, respectively, without +losing any data. The +.Sy raidz1 No vdev +type specifies a single-parity +.No raidz +group; the +.Sy raidz2 No vdev +type specifies a double-parity +.No raidz +group; and the +.Sy raidz3 No vdev +type specifies a triple-parity +.No raidz +group. The +.Sy raidz No vdev +type is an alias for +.Sy raidz1 . +.Pp +A +.No raidz +group with +.Em N +disks of size +.Em X +with +.Em P +parity disks can hold approximately +.Sm off +.Pq Em N-P +*X +.Sm on +bytes and can withstand +.Em P +device(s) failing before data integrity is compromised. The minimum number of +devices in a +.No raidz +group is one more than the number of parity disks. The +recommended number is between 3 and 9 to help increase performance. +.It Sy spare +A special +.No pseudo- Ns No vdev +which keeps track of available hot spares for a pool. +For more information, see the +.Qq Sx Hot Spares +section. +.It Sy log A separate-intent log device. If more than one log device is specified, then writes are load-balanced between devices. Log devices can be mirrored. However, -\fBraidz\fR \fBvdev\fR types are not supported for the intent log. For more -information, see the "Intent Log" section. -.RE - -.sp -.ne 2 -.na -\fB\fBcache\fR\fR -.ad -.RS 10n -A device used to cache storage pool data. A cache device cannot be cannot be -configured as a mirror or \fBraidz\fR group. For more information, see the -"Cache Devices" section. -.RE - -.sp -.LP -Virtual devices cannot be nested, so a mirror or \fBraidz\fR virtual device can -only contain files or disks. Mirrors of mirrors (or other combinations) are not +.No raidz +.No vdev +types are not supported for the intent log. For more information, +see the +.Qq Sx Intent Log +section. +.It Sy cache +A device used to cache storage pool data. A cache device cannot be configured +as a mirror or +.No raidz +group. For more information, see the +.Qq Sx Cache Devices +section. +.El +.Pp +Virtual devices cannot be nested, so a mirror or +.No raidz +virtual device can only +contain files or disks. Mirrors of mirrors (or other combinations) are not allowed. -.sp -.LP +.Pp A pool can have any number of virtual devices at the top of the configuration -(known as "root vdevs"). Data is dynamically distributed across all top-level -devices to balance data among devices. As new virtual devices are added, -\fBZFS\fR automatically places data on the newly available devices. -.sp -.LP +(known as +.Qq root +.No vdev Ns s). +Data is dynamically distributed across all top-level devices to balance data +among devices. As new virtual devices are added, +.Tn ZFS +automatically places data on the newly available devices. +.Pp Virtual devices are specified one at a time on the command line, separated by -whitespace. The keywords "mirror" and "raidz" are used to distinguish where a -group ends and another begins. For example, the following creates two root -vdevs, each a mirror of two disks: -.sp -.in +2 -.nf -# \fBzpool create mypool mirror da0 da1 mirror da2 da3\fR -.fi -.in -2 -.sp - -.SS "Device Failure and Recovery" -.sp -.LP -\fBZFS\fR supports a rich set of mechanisms for handling device failure and -data corruption. All metadata and data is checksummed, and \fBZFS\fR +whitespace. The keywords +.Qq mirror +and +.Qq raidz +are used to distinguish where a group ends and another begins. For example, the +following creates two root +.No vdev Ns s, +each a mirror of two disks: +.Bd -literal -offset 2n +.Li # Ic zpool create mypool mirror da0 da1 mirror da2 da3 +.Ed +.Ss Device Failure and Recovery +.Tn ZFS +supports a rich set of mechanisms for handling device failure and data +corruption. All metadata and data is checksummed, and +.Tn ZFS automatically repairs bad data from a good copy when corruption is detected. -.sp -.LP +.Pp In order to take advantage of these features, a pool must make use of some form -of redundancy, using either mirrored or \fBraidz\fR groups. While \fBZFS\fR -supports running in a non-redundant configuration, where each root vdev is -simply a disk or file, this is strongly discouraged. A single case of bit +of redundancy, using either mirrored or +.No raidz +groups. While +.Tn ZFS +supports running in a non-redundant configuration, where each root +.No vdev +is simply a disk or file, this is strongly discouraged. A single case of bit corruption can render some or all of your data unavailable. -.sp -.LP +.Pp A pool's health status is described by one of three states: online, degraded, or faulted. An online pool has all devices operating normally. A degraded pool is one in which one or more devices have failed, but the data is still available due to a redundant configuration. A faulted pool has corrupted metadata, or one or more faulted devices, and insufficient replicas to continue functioning. -.sp -.LP -The health of the top-level vdev, such as mirror or \fBraidz\fR device, is -potentially impacted by the state of its associated vdevs, or component -devices. A top-level vdev or component device is in one of the following -states: -.sp -.ne 2 -.na -\fB\fBDEGRADED\fR\fR -.ad -.RS 12n -One or more top-level vdevs is in the degraded state because one or more +.Pp +The health of the top-level +.No vdev , +such as mirror or +.No raidz +device, is +potentially impacted by the state of its associated +.No vdev Ns s, +or component devices. A top-level +.No vdev +or component device is in one of the following states: +.Bl -tag -width "DEGRADED" +.It Sy DEGRADED +One or more top-level +.No vdev Ns s +is in the degraded state because one or more component devices are offline. Sufficient replicas exist to continue functioning. -.sp +.Pp One or more component devices is in the degraded or faulted state, but sufficient replicas exist to continue functioning. The underlying conditions are as follows: -.RS +4 -.TP -.ie t \(bu -.el o +.Bl -bullet -offset 2n +.It The number of checksum errors exceeds acceptable levels and the device is -degraded as an indication that something may be wrong. \fBZFS\fR continues to -use the device as necessary. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -The number of I/O errors exceeds acceptable levels. The device could not be +degraded as an indication that something may be wrong. +.Tn ZFS +continues to use the device as necessary. +.It +The number of +.Tn I/O +errors exceeds acceptable levels. The device could not be marked as faulted because there are insufficient replicas to continue functioning. -.RE -.RE - -.sp -.ne 2 -.na -\fB\fBFAULTED\fR\fR -.ad -.RS 12n -One or more top-level vdevs is in the faulted state because one or more +.El +.It Sy FAULTED +One or more top-level +.No vdev Ns s +is in the faulted state because one or more component devices are offline. Insufficient replicas exist to continue functioning. -.sp +.Pp One or more component devices is in the faulted state, and insufficient replicas exist to continue functioning. The underlying conditions are as follows: -.RS +4 -.TP -.ie t \(bu -.el o +.Bl -bullet -offset 2n +.It The device could be opened, but the contents did not match expected values. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -The number of I/O errors exceeds acceptable levels and the device is faulted to +.It +The number of +.Tn I/O +errors exceeds acceptable levels and the device is faulted to prevent further use of the device. -.RE -.RE - -.sp -.ne 2 -.na -\fB\fBOFFLINE\fR\fR -.ad -.RS 12n -The device was explicitly taken offline by the "\fBzpool offline\fR" command. -.RE - -.sp -.ne 2 -.na -\fB\fBONLINE\fR\fR -.ad -.RS 12n +.El +.It Sy OFFLINE +The device was explicitly taken offline by the +.Qq Nm Cm offline +command. +.It Sy ONLINE The device is online and functioning. -.RE - -.sp -.ne 2 -.na -\fB\fBREMOVED\fR\fR -.ad -.RS 12n +.It Sy REMOVED The device was physically removed while the system was running. Device removal detection is hardware-dependent and may not be supported on all platforms. -.RE - -.sp -.ne 2 -.na -\fB\fBUNAVAIL\fR\fR -.ad -.RS 12n +.It Sy UNAVAIL The device could not be opened. If a pool is imported when a device was unavailable, then the device will be identified by a unique identifier instead of its path since the path was never correct in the first place. -.RE - -.sp -.LP -If a device is removed and later re-attached to the system, \fBZFS\fR attempts -to put the device online automatically. Device attach detection is +.El +.Pp +If a device is removed and later reattached to the system, +.Tn ZFS +attempts to put the device online automatically. Device attach detection is hardware-dependent and might not be supported on all platforms. -.SS "Hot Spares" -.sp -.LP -\fBZFS\fR allows devices to be associated with pools as "hot spares". These -devices are not actively used in the pool, but when an active device fails, it -is automatically replaced by a hot spare. To create a pool with hot spares, -specify a "spare" \fBvdev\fR with any number of devices. For example, -.sp -.in +2 -.nf -# zpool create pool mirror da0 da1 spare da2 da3 -.fi -.in -2 -.sp - -.sp -.LP -Spares can be shared across multiple pools, and can be added with the "\fBzpool -add\fR" command and removed with the "\fBzpool remove\fR" command. Once a spare -replacement is initiated, a new "spare" \fBvdev\fR is created within the -configuration that will remain there until the original device is replaced. At -this point, the hot spare becomes available again if another device fails. -.sp -.LP +.Ss Hot Spares +.Tn ZFS +allows devices to be associated with pools as +.Qq hot spares . +These devices are not actively used in the pool, but when an active device +fails, it is automatically replaced by a hot spare. To create a pool with hot +spares, specify a +.Qq spare +.No vdev +with any number of devices. For example, +.Bd -literal -offset 2n +.Li # Ic zpool create pool mirror da0 da1 spare da2 da3 +.Ed +.Pp +Spares can be shared across multiple pools, and can be added with the +.Qq Nm Cm add +command and removed with the +.Qq Nm Cm remove +command. Once a spare replacement is initiated, a new "spare" +.No vdev +is created +within the configuration that will remain there until the original device is +replaced. At this point, the hot spare becomes available again if another +device fails. +.Pp If a pool has a shared spare that is currently being used, the pool can not be exported since other pools may use this shared spare, which may lead to potential data corruption. -.sp -.LP +.Pp An in-progress spare replacement can be cancelled by detaching the hot spare. If the original faulted device is detached, then the hot spare assumes its place in the configuration, and is removed from the spare list of all active pools. -.sp -.LP +.Pp Spares cannot replace log devices. -.SS "Intent Log" -.sp -.LP -The \fBZFS\fR Intent Log (\fBZIL\fR) satisfies \fBPOSIX\fR requirements for -synchronous transactions. For instance, databases often require their -transactions to be on stable storage devices when returning from a system call. -\fBNFS\fR and other applications can also use \fBfsync\fR() to ensure data -stability. By default, the intent log is allocated from blocks within the main -pool. However, it might be possible to get better performance using separate -intent log devices such as \fBNVRAM\fR or a dedicated disk. For example: -.sp -.in +2 -.nf -\fB# zpool create pool da0 da1 log da3\fR -.fi -.in -2 -.sp - -.sp -.LP +.Ss Intent Log +The +.Tn ZFS +Intent Log +.Pq Tn ZIL +satisfies +.Tn POSIX +requirements for synchronous transactions. For instance, databases often +require their transactions to be on stable storage devices when returning from +a system call. +.Tn NFS +and other applications can also use +.Xr fsync 2 +to ensure data stability. By default, the intent log is allocated from blocks +within the main pool. However, it might be possible to get better performance +using separate intent log devices such as +.Tn NVRAM +or a dedicated disk. For example: +.Bd -literal -offset 2n +.Li # Ic zpool create pool da0 da1 log da2 +.Ed +.Pp Multiple log devices can also be specified, and they can be mirrored. See the -EXAMPLES section for an example of mirroring multiple log devices. -.sp -.LP -Log devices can be added, replaced, attached, detached, and imported and -exported as part of the larger pool. Mirrored log devices can be removed by -specifying the top-level mirror for the log. -.SS "Cache Devices" -.sp -.LP +.Sx EXAMPLES +section for an example of mirroring multiple log devices. +.Pp +Log devices can be added, replaced, attached, detached, imported and exported +as part of the larger pool. Mirrored log devices can be removed by specifying +the top-level mirror for the log. +.Ss Cache devices Devices can be added to a storage pool as "cache devices." These devices provide an additional layer of caching between main memory and disk. For read-heavy workloads, where the working set size is much larger than what can @@ -494,172 +494,150 @@ be cached in main memory, using cache devices allow much more of this working set to be served from low latency media. Using cache devices provides the greatest performance improvement for random read-workloads of mostly static content. -.sp -.LP -To create a pool with cache devices, specify a "cache" \fBvdev\fR with any -number of devices. For example: -.sp -.in +2 -.nf -\fB# zpool create pool da0 da1 cache da2 da3\fR -.fi -.in -2 -.sp - -.sp -.LP -Cache devices cannot be mirrored or part of a \fBraidz\fR configuration. If a -read error is encountered on a cache device, that read \fBI/O\fR is reissued to -the original storage pool device, which might be part of a mirrored or -\fBraidz\fR configuration. -.sp -.LP +.Pp +To create a pool with cache devices, specify a "cache" +.No vdev +with any number of devices. For example: +.Bd -literal -offset 2n +.Li # Ic zpool create pool da0 da1 cache da2 da3 +.Ed +.Pp +Cache devices cannot be mirrored or part of a +.No raidz +configuration. If a read +error is encountered on a cache device, that read +.Tn I/O +is reissued to the original storage pool device, which might be part of a +mirrored or +.No raidz +configuration. +.Pp The content of the cache devices is considered volatile, as is the case with other system caches. -.SS "Properties" -.sp -.LP +.Ss Properties Each pool has several properties associated with it. Some properties are read-only statistics while others are configurable and change the behavior of the pool. The following are read-only properties: -.sp -.ne 2 -.na -\fB\fBavailable\fR\fR -.ad -.RS 20n -Amount of storage available within the pool. This property can also be referred -to by its shortened column name, "avail". -.RE - -.sp -.ne 2 -.na -\fB\fBcapacity\fR\fR -.ad -.RS 20n +.Bl -tag -width "dedupratio" +.It Sy alloc +Amount of storage space within the pool that has been physically allocated. +.It Sy capacity Percentage of pool space used. This property can also be referred to by its shortened column name, "cap". -.RE - -.sp -.ne 2 -.na -\fB\fBhealth\fR\fR -.ad -.RS 20n -The current health of the pool. Health can be "\fBONLINE\fR", "\fBDEGRADED\fR", -"\fBFAULTED\fR", " \fBOFFLINE\fR", "\fBREMOVED\fR", or "\fBUNAVAIL\fR". -.RE - -.sp -.ne 2 -.na -\fB\fBguid\fR\fR -.ad -.RS 20n +.It Sy comment +A text string consisting of printable ASCII characters that will be stored +such that it is available even if the pool becomes faulted. An administrator +can provide additional information about a pool using this property. +.It Sy dedupratio +The deduplication ratio specified for a pool, expressed as a multiplier. +For example, a +.S dedupratio +value of 1.76 indicates that 1.76 units of data were stored but only 1 unit of disk space was actually consumed. See +.Xr zfs 8 +for a description of the deduplication feature. +.It Sy free +Number of blocks within the pool that are not allocated. +.It Sy guid A unique identifier for the pool. -.RE - -.sp -.ne 2 -.na -\fB\fBsize\fR\fR -.ad -.RS 20n +.It Sy health +The current health of the pool. Health can be +.Qq Sy ONLINE , +.Qq Sy DEGRADED , +.Qq Sy FAULTED , +.Qq Sy OFFLINE , +.Qq Sy REMOVED , +or +.Qq Sy UNAVAIL . +.It Sy size Total size of the storage pool. -.RE - -.sp -.ne 2 -.na -\fB\fBused\fR\fR -.ad -.RS 20n +.It Sy used Amount of storage space used within the pool. -.RE - -.sp -.LP +.El +.Pp These space usage properties report actual physical space available to the storage pool. The physical space can be different from the total amount of space that any contained datasets can actually use. The amount of space used in -a \fBraidz\fR configuration depends on the characteristics of the data being -written. In addition, \fBZFS\fR reserves some space for internal accounting -that the \fBzfs\fR(8) command takes into account, but the \fBzpool\fR command -does not. For non-full pools of a reasonable size, these effects should be -invisible. For small pools, or pools that are close to being completely full, -these discrepancies may become more noticeable. -.sp -.LP +a +.No raidz +configuration depends on the characteristics of the data being written. +In addition, +.Tn ZFS +reserves some space for internal accounting that the +.Xr zfs 8 +command takes into account, but the +.Xr zpool 8 +command does not. For non-full pools of a reasonable size, these effects should +be invisible. For small pools, or pools that are close to being completely +full, these discrepancies may become more noticeable. +.Pp The following property can be set at creation time and import time: -.sp -.ne 2 -.na -\fB\fBaltroot\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width 2n +.It Sy altroot Alternate root directory. If set, this directory is prepended to any mount points within the pool. This can be used when examining an unknown pool where the mount points cannot be trusted, or in an alternate boot environment, where -the typical paths are not valid. \fBaltroot\fR is not a persistent property. It -is valid only while the system is up. Setting \fBaltroot\fR defaults to using -\fBcachefile\fR=none, though this may be overridden using an explicit setting. -.RE - -.sp -.LP +the typical paths are not valid. +.Sy altroot +is not a persistent property. It is valid only while the system is up. +Setting +.Sy altroot +defaults to using +.Cm cachefile=none , +though this may be overridden using an explicit setting. +.El +.Pp +The following property can only be set at import time: +.Bl -tag -width 2n +.It Sy readonly Ns = Ns Cm on No | Cm off +If set to +.Cm on , +pool will be imported in read-only mode with the following restrictions: +.Bl -bullet -offset 2n +.It +Synchronous data in the intent log will not be accessible +.It +Properties of the pool can not be changed +.It +Datasets of this pool can only be mounted read-only +.It +To write to a read-only pool, a export and import of the pool is required. +.El +.El +.Pp The following properties can be set at creation time and import time, and later -changed with the \fBzpool set\fR command: -.sp -.ne 2 -.na -\fB\fBautoexpand\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n +changed with the +.Ic zpool set +command: +.Bl -tag -width 2n +.It Sy autoexpand Ns = Ns Cm on No | Cm off Controls automatic pool expansion when the underlying LUN is grown. If set to -\fBon\fR, the pool will be resized according to the size of the expanded -device. If the device is part of a mirror or \fBraidz\fR then all devices -within that mirror/\fBraidz\fR group must be expanded before the new space is -made available to the pool. The default behavior is \fBoff\fR. This property -can also be referred to by its shortened column name, \fBexpand\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBautoreplace\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n -Controls automatic device replacement. If set to "\fBoff\fR", device -replacement must be initiated by the administrator by using the "\fBzpool -replace\fR" command. If set to "\fBon\fR", any new device, found in the same +.Qq Cm on , +the pool will be resized according to the size of the expanded +device. If the device is part of a mirror or +.No raidz +then all devices within that +.No mirror/ Ns No raidz +group must be expanded before the new space is made available to +the pool. The default behavior is +.Qq off . +This property can also be referred to by its shortened column name, +.Sy expand . +.It Sy autoreplace Ns = Ns Cm on No | Cm off +Controls automatic device replacement. If set to +.Qq Cm off , +device replacement must be initiated by the administrator by using the +.Qq Nm Cm replace +command. If set to +.Qq Cm on , +any new device, found in the same physical location as a device that previously belonged to the pool, is -automatically formatted and replaced. The default behavior is "\fBoff\fR". This -property can also be referred to by its shortened column name, "replace". -.RE - -.sp -.ne 2 -.na -\fB\fBbootfs\fR=\fIpool\fR/\fIdataset\fR\fR -.ad -.sp .6 -.RS 4n +automatically formatted and replaced. The default behavior is +.Qq Cm off . +This property can also be referred to by its shortened column name, "replace". +.It Sy bootfs Ns = Ns Ar pool Ns / Ns Ar dataset Identifies the default bootable dataset for the root pool. This property is expected to be set mainly by the installation and upgrade programs. -.RE - -.sp -.ne 2 -.na -\fB\fBcachefile\fR=\fIpath\fR | \fBnone\fR\fR -.ad -.sp .6 -.RS 4n +.It Sy cachefile Ns = Ns Ar path No | Cm none Controls the location of where the pool configuration is cached. Discovering all pools on system startup requires a cached copy of the configuration data that is stored on the root file system. All pools in this cache are @@ -667,1137 +645,1083 @@ automatically imported when the system boots. Some environments, such as install and clustering, need to cache this information in a different location so that pools are not automatically imported. Setting this property caches the pool configuration in a different location that can later be imported with -"\fBzpool import -c\fR". Setting it to the special value "\fBnone\fR" creates a -temporary pool that is never cached, and the special value \fB\&''\fR (empty -string) uses the default location. -.sp -Multiple pools can share the same cache file. Because the kernel destroys and -recreates this file when pools are added and removed, care should be taken when -attempting to access this file. When the last pool using a \fBcachefile\fR is -exported or destroyed, the file is removed. -.RE - -.sp -.ne 2 -.na -\fB\fBdelegation\fR=\fBon\fR | \fBoff\fR\fR -.ad -.sp .6 -.RS 4n +.Qq Nm Cm import Fl c . +Setting it to the special value +.Qq Cm none +creates a temporary pool that is never cached, and the special value +.Cm '' +(empty string) uses the default location. +.It Sy dedupditto Ns = Ns Ar number +Threshold for the number of block ditto copies. If the reference count for a +deduplicated block increases above this number, a new ditto copy of this block +is automatically stored. Deafult setting is +.Cm 0 . +.It Sy delegation Ns = Ns Cm on No | Cm off Controls whether a non-privileged user is granted access based on the dataset -permissions defined on the dataset. See \fBzfs\fR(8) for more information on -\fBZFS\fR delegated administration. -.RE - -.sp -.ne 2 -.na -\fB\fBfailmode\fR=\fBwait\fR | \fBcontinue\fR | \fBpanic\fR\fR -.ad -.sp .6 -.RS 4n +permissions defined on the dataset. See +.Xr zfs 8 +for more information on +.Tn ZFS +delegated administration. +.It Sy failmode Ns = Ns Cm wait No | Cm continue No | Cm panic Controls the system behavior in the event of catastrophic pool failure. This condition is typically a result of a loss of connectivity to the underlying storage device(s) or a failure of all devices within the pool. The behavior of such an event is determined as follows: -.sp -.ne 2 -.na -\fB\fBwait\fR\fR -.ad -.RS 12n -Blocks all \fBI/O\fR access until the device connectivity is recovered and the -errors are cleared. This is the default behavior. -.RE - -.sp -.ne 2 -.na -\fB\fBcontinue\fR\fR -.ad -.RS 12n -Returns \fBEIO\fR to any new write \fBI/O\fR requests but allows reads to any -of the remaining healthy devices. Any write requests that have yet to be -committed to disk would be blocked. -.RE - -.sp -.ne 2 -.na -\fB\fBpanic\fR\fR -.ad -.RS 12n +.Bl -tag -width indent +.It Sy wait +Blocks all +.Tn I/O +access until the device connectivity is recovered and the errors are cleared. +This is the default behavior. +.It Sy continue +Returns +.Em EIO +to any new write +.Tn I/O +requests but allows reads to any of the remaining healthy devices. Any write +requests that have yet to be committed to disk would be blocked. +.It Sy panic Prints out a message to the console and generates a system crash dump. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBlistsnaps\fR=on | off\fR -.ad -.sp .6 -.RS 4n +.El +.It Sy listsnaps Ns = Ns Cm on No | Cm off Controls whether information about snapshots associated with this pool is -output when "\fBzfs list\fR" is run without the \fB-t\fR option. The default -value is "off". -.RE - -.sp -.ne 2 -.na -\fB\fBversion\fR=\fIversion\fR\fR -.ad -.sp .6 -.RS 4n +output when +.Qq Nm zfs Cm list +is run without the +.Fl t +option. The default value is +.Cm off . +.It Sy version Ns = Ns Ar version The current on-disk version of the pool. This can be increased, but never -decreased. The preferred method of updating pools is with the "\fBzpool -upgrade\fR" command, though this property can be used when a specific version -is needed for backwards compatibility. This property can be any number between -1 and the current version reported by "\fBzpool upgrade -v\fR". -.RE - -.SS "Subcommands" -.sp -.LP +decreased. The preferred method of updating pools is with the +.Qq Nm Cm upgrade +command, though this property can be used when a specific version is needed +for backwards compatibility. This property can be any number between 1 and the +current version reported by +.Qo Ic zpool upgrade -v Qc . +.El +.Sh SUBCOMMANDS All subcommands that modify state are logged persistently to the pool in their original form. -.sp -.LP -The \fBzpool\fR command provides subcommands to create and destroy storage -pools, add capacity to storage pools, and provide information about the storage -pools. The following subcommands are supported: -.sp -.ne 2 -.na -\fB\fBzpool\fR \fB-?\fR\fR -.ad -.sp .6 -.RS 4n +.Pp +The +.Nm +command provides subcommands to create and destroy storage pools, add capacity +to storage pools, and provide information about the storage pools. The following +subcommands are supported: +.Bl -tag -width 2n +.It Xo +.Nm +.Op Fl \&? +.Xc +.Pp Displays a help message. -.RE - -.sp -.ne 2 -.na -\fB\fBzpool add\fR [\fB-fn\fR] \fIpool\fR \fIvdev\fR ...\fR -.ad -.sp .6 -.RS 4n -Adds the specified virtual devices to the given pool. The \fIvdev\fR -specification is described in the "Virtual Devices" section. The behavior of -the \fB-f\fR option, and the device checks performed are described in the -"zpool create" subcommand. -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.RS 6n -Forces use of \fBvdev\fRs, even if they appear in use or specify a conflicting -replication level. Not all devices can be overridden in this manner. -.RE - -.sp -.ne 2 -.na -\fB\fB-n\fR\fR -.ad -.RS 6n +.It Xo +.Nm +.Cm add +.Op Fl fn +.Ar pool vdev ... +.Xc +.Pp +Adds the specified virtual devices to the given pool. The +.No vdev +specification is described in the +.Qq Sx Virtual Devices +section. The behavior of the +.Fl f +option, and the device checks performed are described in the +.Qq Nm Cm create +subcommand. +.Bl -tag -width indent +.It Fl f +Forces use of +.Ar vdev , +even if they appear in use or specify a conflicting replication level. +Not all devices can be overridden in this manner. +.It Fl n Displays the configuration that would be used without actually adding the -\fBvdev\fRs. The actual pool creation can still fail due to insufficient -privileges or device sharing. -.RE - +.Ar vdev Ns s. +The actual pool creation can still fail due to insufficient privileges or device +sharing. +.Pp Do not add a disk that is currently configured as a quorum device to a zpool. After a disk is in the pool, that disk can then be configured as a quorum device. -.RE - -.sp -.ne 2 -.na -\fB\fBzpool attach\fR [\fB-f\fR] \fIpool\fR \fIdevice\fR \fInew_device\fR\fR -.ad -.sp .6 -.RS 4n -Attaches \fInew_device\fR to an existing \fBzpool\fR device. The existing -device cannot be part of a \fBraidz\fR configuration. If \fIdevice\fR is not -currently part of a mirrored configuration, \fIdevice\fR automatically -transforms into a two-way mirror of \fIdevice\fR and \fInew_device\fR. If -\fIdevice\fR is part of a two-way mirror, attaching \fInew_device\fR creates a -three-way mirror, and so on. In either case, \fInew_device\fR begins to -resilver immediately. -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.RS 6n -Forces use of \fInew_device\fR, even if its appears to be in use. Not all -devices can be overridden in this manner. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool clear\fR \fIpool\fR [\fIdevice\fR] ...\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm attach +.Op Fl f +.Ar pool device new_device +.Xc +.Pp +Attaches +.Ar new_device +to an existing +.Sy zpool +device. The existing device cannot be part of a +.No raidz +configuration. If +.Ar device +is not currently part of a mirrored configuration, +.Ar device +automatically transforms into a two-way mirror of +.Ar device No and Ar new_device . +If +.Ar device +is part of a two-way mirror, attaching +.Ar new_device +creates a three-way mirror, and so on. In either case, +.Ar new_device +begins to resilver immediately. +.Bl -tag -width indent +.It Fl f +Forces use of +.Ar new_device , +even if its appears to be in use. Not all devices can be overridden in this +manner. +.El +.It Xo +.Nm +.Cm clear +.Op Fl F Op Fl n +.Ar pool +.Op Ar device +.Xc +.Pp Clears device errors in a pool. If no arguments are specified, all device errors within the pool are cleared. If one or more devices is specified, only those errors associated with the specified device or devices are cleared. -.RE - -.sp -.ne 2 -.na -\fB\fBzpool create\fR [\fB-fn\fR] [\fB-o\fR \fIproperty=value\fR] ... [\fB-O\fR -\fIfile-system-property=value\fR] ... [\fB-m\fR \fImountpoint\fR] [\fB-R\fR -\fIroot\fR] \fIpool\fR \fIvdev\fR ...\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width indent +.It Fl F +Initiates recovery mode for an unopenable pool. Attempts to discard the last +few transactions in the pool to return it to an openable state. Not all damaged +pools can be recovered by using this option. If successful, the data from the +discarded transactions is irretrievably lost. +.It Fl n +Used in combination with the +.Fl F +flag. Check whether discarding transactions would make the pool openable, but +do not actually discard any transactions. +.El +.It Xo +.Nm +.Cm create +.Op Fl fn +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... +.Op Fl O Ar file-system-property Ns = Ns Ar value +.Ar ... +.Op Fl m Ar mountpoint +.Op Fl R Ar root +.Ar pool vdev ... +.Xc +.Pp Creates a new storage pool containing the virtual devices specified on the command line. The pool name must begin with a letter, and can only contain alphanumeric characters as well as underscore ("_"), dash ("-"), and period ("."). The pool names "mirror", "raidz", "spare" and "log" are reserved, as are -names beginning with the pattern "c[0-9]". The \fBvdev\fR specification is -described in the "Virtual Devices" section. -.sp +names beginning with the pattern "c[0-9]". The +.No vdev +specification is described in the +.Qq Sx Virtual Devices +section. +.Pp The command verifies that each device specified is accessible and not currently in use by another subsystem. There are some uses, such as being currently mounted, or specified as the dedicated dump device, that prevents a device from -ever being used by \fBZFS\fR. Other uses, such as having a preexisting -\fBUFS\fR file system, can be overridden with the \fB-f\fR option. -.sp +ever being used by +.Tn ZFS +Other uses, such as having a preexisting +.Sy UFS +file system, can be overridden with the +.Fl f +option. +.Pp The command also checks that the replication strategy for the pool is consistent. An attempt to combine redundant and non-redundant storage in a -single pool, or to mix disks and files, results in an error unless \fB-f\fR is -specified. The use of differently sized devices within a single \fBraidz\fR or -mirror group is also flagged as an error unless \fB-f\fR is specified. -.sp -Unless the \fB-R\fR option is specified, the default mount point is -"/\fIpool\fR". The mount point must not exist or must be empty, or else the -root dataset cannot be mounted. This can be overridden with the \fB-m\fR +single pool, or to mix disks and files, results in an error unless +.Fl f +is specified. The use of differently sized devices within a single +.No raidz +or mirror group is also flagged as an error unless +.Fl f +is specified. +.Pp +Unless the +.Fl R +option is specified, the default mount point is +.Qq Pa /pool . +The mount point must not exist or must be empty, or else the +root dataset cannot be mounted. This can be overridden with the +.Fl m option. -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.sp .6 -.RS 4n -Forces use of \fBvdev\fRs, even if they appear in use or specify a conflicting -replication level. Not all devices can be overridden in this manner. -.RE - -.sp -.ne 2 -.na -\fB\fB-n\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width indent +.It Fl f +Forces use of +.Ar vdev Ns s, +even if they appear in use or specify a conflicting replication level. +Not all devices can be overridden in this manner. +.It Fl n Displays the configuration that would be used without actually creating the pool. The actual pool creation can still fail due to insufficient privileges or device sharing. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIproperty=value\fR [\fB-o\fR \fIproperty=value\fR] ...\fR -.ad -.sp .6 -.RS 4n -Sets the given pool properties. See the "Properties" section for a list of -valid properties that can be set. -.RE - -.sp -.ne 2 -.na -\fB\fB-O\fR \fIfile-system-property=value\fR\fR -.ad -.br -.na -\fB[\fB-O\fR \fIfile-system-property=value\fR] ...\fR -.ad -.sp .6 -.RS 4n +.It Xo +.Fl o Ar property Ns = Ns Ar value +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... +.Xc +Sets the given pool properties. See the +.Qq Sx Properties +section for a list of valid properties that can be set. +.It Xo +.Fl O +.Ar file-system-property Ns = Ns Ar value +.Op Fl O Ar file-system-property Ns = Ns Ar value +.Ar ... +.Xc Sets the given file system properties in the root file system of the pool. See -the "Properties" section of \fBzfs\fR(8) for a list of valid properties that +.Xr zfs 8 Properties +for a list of valid properties that can be set. -.RE - -.sp -.ne 2 -.na -\fB\fB-R\fR \fIroot\fR\fR -.ad -.sp .6 -.RS 4n -Equivalent to "-o cachefile=none,altroot=\fIroot\fR" -.RE - -.sp -.ne 2 -.na -\fB\fB-m\fR \fImountpoint\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl R Ar root +Equivalent to +.Qq Fl o Cm cachefile=none,altroot= Ns Pa root +.It Fl m Ar mountpoint Sets the mount point for the root dataset. The default mount point is -"/\fIpool\fR" or "\fBaltroot\fR/\fIpool\fR" if \fBaltroot\fR is specified. The -mount point must be an absolute path, "\fBlegacy\fR", or "\fBnone\fR". For more -information on dataset mount points, see \fBzfs\fR(8). -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool destroy\fR [\fB-f\fR] \fIpool\fR\fR -.ad -.sp .6 -.RS 4n +.Qq Pa /pool +or +.Qq Cm altroot Ns Pa /pool +if +.Sy altroot +is specified. The mount point must be an absolute path, +.Qq Cm legacy , +or +.Qq Cm none . +For more information on dataset mount points, see +.Xr zfs 8 . +.El +.It Xo +.Nm +.Cm destroy +.Op Fl f +.Ar pool +.Xc +.Pp Destroys the given pool, freeing up any devices for other use. This command tries to unmount any active datasets before destroying the pool. -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.RS 6n +.Bl -tag -width indent +.It Fl f Forces any active datasets contained within the pool to be unmounted. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool detach\fR \fIpool\fR \fIdevice\fR\fR -.ad -.sp .6 -.RS 4n -Detaches \fIdevice\fR from a mirror. The operation is refused if there are no -other valid replicas of the data. -.RE - -.sp -.ne 2 -.na -\fB\fBzpool export\fR [\fB-f\fR] \fIpool\fR ...\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm detach +.Ar pool device +.Xc +.Pp +Detaches +.Ar device +from a mirror. The operation is refused if there are no other valid replicas +of the data. +.It Xo +.Nm +.Cm export +.Op Fl f +.Ar pool ... +.Xc +.Pp Exports the given pools from the system. All devices are marked as exported, but are still considered in use by other subsystems. The devices can be moved between systems (even those of different endianness) and imported as long as a sufficient number of devices are present. -.sp +.Pp Before exporting the pool, all datasets within the pool are unmounted. A pool can not be exported if it has a shared spare that is currently being used. -.sp -For pools to be portable, you must give the \fBzpool\fR command whole disks, -not just slices, so that \fBZFS\fR can label the disks with portable \fBEFI\fR +.Pp +For pools to be portable, you must give the +.Nm +command whole disks, not just slices, so that +.Tn ZFS +can label the disks with portable +.Sy EFI labels. Otherwise, disk drivers on platforms of different endianness will not recognize the disks. -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.RS 6n -Forcefully unmount all datasets, using the "\fBunmount -f\fR" command. -.sp +.Bl -tag -width indent +.It Fl f +Forcefully unmount all datasets, using the +.Qq Nm unmount Fl f +command. +.Pp This command will forcefully export the pool even if it has a shared spare that is currently being used. This may lead to potential data corruption. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool get\fR "\fIall\fR" | \fIproperty\fR[,...] \fIpool\fR ...\fR -.ad -.sp .6 -.RS 4n -Retrieves the given list of properties (or all properties if "\fBall\fR" is -used) for the specified storage pool(s). These properties are displayed with +.El +.It Xo +.Nm +.Cm get +.Ar all | property Ns Op , Ns Ar ... +.Ar pool ... +.Xc +.Pp +Retrieves the given list of properties (or all properties if +.Qq Cm all +is used) for the specified storage pool(s). These properties are displayed with the following fields: -.sp -.in +2 -.nf - name Name of storage pool - property Property name - value Property value - source Property source, either 'default' or 'local'. -.fi -.in -2 -.sp - -See the "Properties" section for more information on the available pool -properties. -.RE - -.sp -.ne 2 -.na -\fB\fBzpool history\fR [\fB-il\fR] [\fIpool\fR] ...\fR -.ad -.sp .6 -.RS 4n +.Bl -column -offset indent "property" +.It name Ta Name of storage pool +.It property Ta Property name +.It value Ta Property value +.It source Ta Property source, either 'default' or 'local'. +.El +.Pp +See the +.Qq Sx Properties +section for more information on the available pool properties. +.It Xo +.Nm +.Cm history +.Op Fl il +.Op Ar pool +.Ar ... +.Xc +.Pp Displays the command history of the specified pools or all pools if no pool is specified. -.sp -.ne 2 -.na -\fB\fB-i\fR\fR -.ad -.RS 6n -Displays internally logged \fBZFS\fR events in addition to user initiated -events. -.RE - -.sp -.ne 2 -.na -\fB\fB-l\fR\fR -.ad -.RS 6n +.Bl -tag -width indent +.It Fl i +Displays internally logged +.Tn ZFS +events in addition to user initiated events. +.It Fl l Displays log records in long format, which in addition to standard format -includes, the user name, the hostname, and the jail in which the operation was +includes, the user name, the hostname, and the zone in which the operation was performed. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool import\fR [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR] -[\fB-D\fR]\fR -.ad -.sp .6 -.RS 4n -Lists pools available to import. If the \fB-d\fR option is not specified, this -command searches for devices in "/dev/dsk". The \fB-d\fR option can be -specified multiple times, and all directories are searched. If the device -appears to be part of an exported pool, this command displays a summary of the -pool with the name of the pool, a numeric identifier, as well as the \fIvdev\fR -layout and current health of the device for each device or file. Destroyed -pools, pools that were previously destroyed with the "\fBzpool destroy\fR" -command, are not listed unless the \fB-D\fR option is specified. -.sp +.El +.It Xo +.Nm +.Cm import +.Op Fl d Ar dir | Fl c Ar cachefile +.Op Fl D +.Xc +.Pp +Lists pools available to import. If the +.Fl d +option is not specified, this command searches for devices in +.Qq Pa /dev . +The +.Fl d +option can be specified multiple times, and all directories are searched. If +the device appears to be part of an exported pool, this command displays a +summary of the pool with the name of the pool, a numeric identifier, as well as +the +.No vdev +layout and current health of the device for each device or file. +Destroyed pools, pools that were previously destroyed with the +.Qq Nm Cm destroy +command, are not listed unless the +.Fl D +option is specified. +.Pp The numeric identifier is unique, and can be used instead of the pool name when multiple exported pools of the same name are available. -.sp -.ne 2 -.na -\fB\fB-c\fR \fIcachefile\fR\fR -.ad -.RS 16n -Reads configuration from the given \fBcachefile\fR that was created with the -"\fBcachefile\fR" pool property. This \fBcachefile\fR is used instead of -searching for devices. -.RE - -.sp -.ne 2 -.na -\fB\fB-d\fR \fIdir\fR\fR -.ad -.RS 16n -Searches for devices or files in \fIdir\fR. The \fB-d\fR option can be -specified multiple times. -.RE - -.sp -.ne 2 -.na -\fB\fB-D\fR\fR -.ad -.RS 16n +.Bl -tag -width indent +.It Fl c Ar cachefile +Reads configuration from the given +.Ar cachefile +that was created with the +.Qq Sy cachefile +pool property. This +.Ar cachefile +is used instead of searching for devices. +.It Fl d Ar dir +Searches for devices or files in +.Ar dir . +The +.Fl d +option can be specified multiple times. +.It Fl D Lists destroyed pools only. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool import\fR [\fB-o\fR \fImntopts\fR] [ \fB-o\fR -\fIproperty\fR=\fIvalue\fR] ... [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR] -[\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fB-a\fR\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm import +.Op Fl o Ar mntopts +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... +.Op Fl d Ar dir | Fl c Ar cachefile +.Op Fl D +.Op Fl f +.Op Fl m +.Op Fl N +.Op Fl R Ar root +.Op Fl F Op Fl n +.Fl a +.Xc +.Pp Imports all pools found in the search directories. Identical to the previous command, except that all pools with a sufficient number of devices available are imported. Destroyed pools, pools that were previously destroyed with the -"\fBzpool destroy\fR" command, will not be imported unless the \fB-D\fR option -is specified. -.sp -.ne 2 -.na -\fB\fB-o\fR \fImntopts\fR\fR -.ad -.RS 21n +.Qq Nm Cm destroy +command, will not be imported unless the +.Fl D +option is specified. +.Bl -tag -width indent +.It Fl o Ar mntopts Comma-separated list of mount options to use when mounting datasets within the -pool. See \fBzfs\fR(8) for a description of dataset properties and mount -options. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIproperty=value\fR\fR -.ad -.RS 21n -Sets the specified property on the imported pool. See the "Properties" section -for more information on the available pool properties. -.RE - -.sp -.ne 2 -.na -\fB\fB-c\fR \fIcachefile\fR\fR -.ad -.RS 21n -Reads configuration from the given \fBcachefile\fR that was created with the -"\fBcachefile\fR" pool property. This \fBcachefile\fR is used instead of -searching for devices. -.RE - -.sp -.ne 2 -.na -\fB\fB-d\fR \fIdir\fR\fR -.ad -.RS 21n -Searches for devices or files in \fIdir\fR. The \fB-d\fR option can be -specified multiple times. This option is incompatible with the \fB-c\fR option. -.RE - -.sp -.ne 2 -.na -\fB\fB-D\fR\fR -.ad -.RS 21n -Imports destroyed pools only. The \fB-f\fR option is also required. -.RE - -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.RS 21n +pool. See +.Xr zfs 8 +for a description of dataset properties and mount options. +.It Fl o Ar property Ns = Ns Ar value +Sets the specified property on the imported pool. See the +.Qq Sx Properties +section for more information on the available pool properties. +.It Fl c Ar cachefile +Reads configuration from the given +.Ar cachefile +that was created with the +.Qq Sy cachefile +pool property. This +.Ar cachefile +is used instead of searching for devices. +.It Fl d Ar dir +Searches for devices or files in +.Ar dir . +The +.Fl d +option can be specified multiple times. This option is incompatible with the +.Fl c +option. +.It Fl D +Imports destroyed pools only. The +.Fl f +option is also required. +.It Fl f Forces import, even if the pool appears to be potentially active. -.RE - -.sp -.ne 2 -.na -\fB\fB-a\fR\fR -.ad -.RS 21n +.It Fl m +Enables import with missing log devices. +.It Fl N +Do not mount any filesystems from the imported pool. +.It Fl R Ar root +Sets the +.Qq Sy cachefile +property to +.Qq Cm none +and the +.Qq Sy altroot +property to +.Qq Ar root +.It Fl F +Recovery mode for a non-importable pool. Attempt to return the pool to an +importable state by discarding the last few transactions. Not all damaged pools +can be recovered by using this option. If successful, the data from the +discarded transactions is irretrievably lost. This option is ignored if the +pool is importable or already imported. +.It Fl n +Used with the +.Fl F +recovery option. Determines whether a non-importable pool can be made +importable again, but does not actually perform the pool recovery. For more +details about pool recovery mode, see the +.Fl F +option, above. +.It Fl a Searches for and imports all pools found. -.RE - -.sp -.ne 2 -.na -\fB\fB-R\fR \fIroot\fR\fR -.ad -.RS 21n -Sets the "\fBcachefile\fR" property to "\fBnone\fR" and the "\fIaltroot\fR" -property to "\fIroot\fR". -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool import\fR [\fB-o\fR \fImntopts\fR] [ \fB-o\fR -\fIproperty\fR=\fIvalue\fR] ... [\fB-d\fR \fIdir\fR | \fB-c\fR \fIcachefile\fR] -[\fB-D\fR] [\fB-f\fR] [\fB-R\fR \fIroot\fR] \fIpool\fR | \fIid\fR -[\fInewpool\fR]\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm import +.Op Fl o Ar mntopts +.Op Fl o Ar property Ns = Ns Ar value +.Ar ... +.Op Fl d Ar dir | Fl c Ar cachefile +.Op Fl D +.Op Fl f +.Op Fl m +.Op Fl N +.Op Fl R Ar root +.Op Fl F Op Fl n +.Ar pool | id +.Op Ar newpool +.Xc +.Pp Imports a specific pool. A pool can be identified by its name or the numeric -identifier. If \fInewpool\fR is specified, the pool is imported using the name -\fInewpool\fR. Otherwise, it is imported with the same name as its exported -name. -.sp -If a device is removed from a system without running "\fBzpool export\fR" +identifier. If +.Ar newpool +is specified, the pool is imported using the name +.Ar newpool . +Otherwise, it is imported with the same name as its exported name. +.Pp +If a device is removed from a system without running +.Qq Nm Cm export first, the device appears as potentially active. It cannot be determined if this was a failed export, or whether the device is really in use from another -host. To import a pool in this state, the \fB-f\fR option is required. -.sp -.ne 2 -.na -\fB\fB-o\fR \fImntopts\fR\fR -.ad -.sp .6 -.RS 4n +host. To import a pool in this state, the +.Fl f +option is required. +.Bl -tag -width indent +.It Fl o Ar mntopts Comma-separated list of mount options to use when mounting datasets within the -pool. See \fBzfs\fR(8) for a description of dataset properties and mount -options. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIproperty=value\fR\fR -.ad -.sp .6 -.RS 4n -Sets the specified property on the imported pool. See the "Properties" section -for more information on the available pool properties. -.RE - -.sp -.ne 2 -.na -\fB\fB-c\fR \fIcachefile\fR\fR -.ad -.sp .6 -.RS 4n -Reads configuration from the given \fBcachefile\fR that was created with the -"\fBcachefile\fR" pool property. This \fBcachefile\fR is used instead of -searching for devices. -.RE - -.sp -.ne 2 -.na -\fB\fB-d\fR \fIdir\fR\fR -.ad -.sp .6 -.RS 4n -Searches for devices or files in \fIdir\fR. The \fB-d\fR option can be -specified multiple times. This option is incompatible with the \fB-c\fR option. -.RE - -.sp -.ne 2 -.na -\fB\fB-D\fR\fR -.ad -.sp .6 -.RS 4n -Imports destroyed pool. The \fB-f\fR option is also required. -.RE - -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.sp .6 -.RS 4n +pool. See +.Xr zfs 8 +for a description of dataset properties and mount options. +.It Fl o Ar property Ns = Ns Ar value +Sets the specified property on the imported pool. See the +.Qq Sx Properties +section for more information on the available pool properties. +.It Fl c Ar cachefile +Reads configuration from the given +.Ar cachefile +that was created with the +.Qq Sy cachefile +pool property. This +.Ar cachefile +is used instead of searching for devices. +.It Fl d Ar dir +Searches for devices or files in +.Ar dir . +The +.Fl d +option can be specified multiple times. This option is incompatible with the +.Fl c +option. +.It Fl D +Imports destroyed pools only. The +.Fl f +option is also required. +.It Fl f Forces import, even if the pool appears to be potentially active. -.RE - -.sp -.ne 2 -.na -\fB\fB-R\fR \fIroot\fR\fR -.ad -.sp .6 -.RS 4n -Sets the "\fBcachefile\fR" property to "\fBnone\fR" and the "\fIaltroot\fR" -property to "\fIroot\fR". -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool iostat\fR [\fB-T\fR \fBu\fR | \fBd\fR] [\fB-v\fR] [\fIpool\fR] ... -[\fIinterval\fR[\fIcount\fR]]\fR -.ad -.sp .6 -.RS 4n -Displays \fBI/O\fR statistics for the given pools. When given an interval, the -statistics are printed every \fIinterval\fR seconds until \fBCtrl-C\fR is -pressed. If no \fIpools\fR are specified, statistics for every pool in the -system is shown. If \fIcount\fR is specified, the command exits after -\fIcount\fR reports are printed. -.sp -.ne 2 -.na -\fB\fB-T\fR \fBu\fR | \fBd\fR\fR -.ad -.RS 12n -Display a time stamp. -.sp -Specify \fBu\fR for a printed representation of the internal representation of -time. See \fBtime\fR(2). Specify \fBd\fR for standard date format. See -\fBdate\fR(1). -.RE - -.sp -.ne 2 -.na -\fB\fB-v\fR\fR -.ad -.RS 12n -Verbose statistics. Reports usage statistics for individual \fIvdevs\fR within -the pool, in addition to the pool-wide statistics. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool labelclear\fR [\fB-f\fR] \fIdevice\fR -.ad -.sp .6 -.RS 4n -Removes ZFS label information from the specified device. The device must not -be part of an active pool configuration. -.sp -.ne 2 -.mk -.na -\fB\fB-f\fR\fR -.ad -.RS 12n -.rt +.It Fl m +Enables import with missing log devices. +.It Fl N +Do not mount any filesystems from the imported pool. +.It Fl R Ar root +Equivalent to +.Qq Fl o Cm cachefile=none,altroot= Ns Pa root +.It Fl F +Recovery mode for a non-importable pool. Attempt to return the pool to an +importable state by discarding the last few transactions. Not all damaged pools +can be recovered by using this option. If successful, the data from the +discarded transactions is irretrievably lost. This option is ignored if the +pool is importable or already imported. +.It Fl n +Used with the +.Fl F +recovery option. Determines whether a non-importable pool can be made +importable again, but does not actually perform the pool recovery. For more +details about pool recovery mode, see the +.Fl F +option, above. +.El +.It Xo +.Nm +.Cm iostat +.Op Fl T Cm d Ns | Ns Cm u +.Op Fl v +.Op Ar pool +.Ar ... +.Op Ar interval Op Ar count +.Xc +.Pp +Displays +.Tn I/O +statistics for the given pools. When given an interval, the statistics are +printed every +.Ar interval +seconds until +.Sy Ctrl-C +is pressed. If no +.Ar pools +are specified, statistics for every pool in the system is shown. If +.Ar count +is specified, the command exits after +.Ar count +reports are printed. +.Bl -tag -width indent +.It Fl T Cm d Ns | Ns Cm u +Print a timestamp. +.Pp +Use modifier +.Cm d +for standard date format. See +.Xr date 1 . +Use modifier +.Cm u +for unixtime +.Pq equals Qq Ic date +%s . +.It Fl v +Verbose statistics. Reports usage statistics for individual +.No vdev Ns s +within the pool, in addition to the pool-wide statistics. +.El +.It Xo +.Nm +.Cm labelclear +.Op Fl f +.Ar device +.Xc +.Pp +Removes +.Tn ZFS +label information from the specified +.Ar device . +The +.Ar device +must not be part of an active pool configuration. +.Bl -tag -width indent +.It Fl v Treat exported or foreign devices as inactive. -.RE - -.RE - -.sp -.ne 2 -.mk -.na -\fB\fBzpool list\fR [\fB-H\fR] [\fB-o\fR \fIprops\fR[,...]] [\fIpool\fR] ...\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm list +.Op Fl H +.Op Fl o Ar property Ns Op , Ns Ar ... +.Op Fl T Cm d Ns | Ns Cm u +.Op Ar pool +.Ar ... +.Op Ar inverval Op Ar count +.Xc +.Pp Lists the given pools along with a health status and space usage. When given no arguments, all pools in the system are listed. -.sp -.ne 2 -.na -\fB\fB-H\fR\fR -.ad -.RS 12n +.Pp +When given an interval, the output is printed every +.Ar interval +seconds until +.Sy Ctrl-C +is pressed. If +.Ar count +is specified, the command exits after +.Ar count +reports are printed. +.Bl -tag -width indent +.It Fl H Scripted mode. Do not display headers, and separate fields by a single tab instead of arbitrary space. -.RE - -.sp -.ne 2 -.na -\fB\fB-o\fR \fIprops\fR\fR -.ad -.RS 12n -Comma-separated list of properties to display. See the "Properties" section for -a list of valid properties. The default list is "name, size, used, available, -capacity, health, altroot" -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool offline\fR [\fB-t\fR] \fIpool\fR \fIdevice\fR ...\fR -.ad -.sp .6 -.RS 4n -Takes the specified physical device offline. While the \fIdevice\fR is offline, -no attempt is made to read or write to the device. -.sp -This command is not applicable to spares or cache devices. -.sp -.ne 2 -.na -\fB\fB-t\fR\fR -.ad -.RS 6n +.It Fl o Ar property Ns Op , Ns Ar ... +Comma-separated list of properties to display. See the +.Qq Sx Properties +section for a list of valid properties. The default list is +.Sy name , +.Sy size , +.Sy used , +.Sy available , +.Sy capacity , +.Sy health , +.Sy altroot . +.It Fl T Cm d Ns | Ns Cm u +Print a timestamp. +.Pp +Use modifier +.Cm d +for standard date format. See +.Xr date 1 . +Use modifier +.Cm u +for unixtime +.Pq equals Qq Ic date +%s . +.El +.It Xo +.Nm +.Cm offline +.Op Fl t +.Ar pool device ... +.Xc +.Pp +Takes the specified physical device offline. While the +.Ar device +is offline, no attempt is made to read or write to the device. +.Bl -tag -width indent +.It Fl t Temporary. Upon reboot, the specified physical device reverts to its previous state. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool online\fR [\fB-e\fR] \fIpool\fR \fIdevice\fR...\fR -.ad -.sp .6 -.RS 4n +.El +.It Xo +.Nm +.Cm online +.Op Fl e +.Ar pool device ... +.Xc +.Pp Brings the specified physical device online. -.sp +.Pp This command is not applicable to spares or cache devices. -.sp -.ne 2 -.na -\fB\fB-e\fR\fR -.ad -.RS 6n +.Bl -tag -width indent +.It Fl e Expand the device to use all available space. If the device is part of a mirror -or \fBraidz\fR then all devices must be expanded before the new space will -become available to the pool. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool remove\fR \fIpool\fR \fIdevice\fR ...\fR -.ad -.sp .6 -.RS 4n +or +.No raidz +then all devices must be expanded before the new space will become +available to the pool. +.El +.It Xo +.Nm +.Cm reguid +.Ar pool +.Xc +.Pp +Generates a new unique identifier for the pool. You must ensure that all +devices in this pool are online and healthy before performing this action. +.It Xo +.Nm +.Cm remove +.Ar pool device ... +.Xc +.Pp Removes the specified device from the pool. This command currently only supports removing hot spares, cache, and log devices. A mirrored log device can be removed by specifying the top-level mirror for the log. Non-log devices that -are part of a mirrored configuration can be removed using the \fBzpool -detach\fR command. Non-redundant and \fBraidz\fR devices cannot be removed from -a pool. -.RE - -.sp -.ne 2 -.na -\fB\fBzpool replace\fR [\fB-f\fR] \fIpool\fR \fIold_device\fR -[\fInew_device\fR]\fR -.ad -.sp .6 -.RS 4n -Replaces \fIold_device\fR with \fInew_device\fR. This is equivalent to -attaching \fInew_device\fR, waiting for it to resilver, and then detaching -\fIold_device\fR. -.sp -The size of \fInew_device\fR must be greater than or equal to the minimum size -of all the devices in a mirror or \fBraidz\fR configuration. -.sp -\fInew_device\fR is required if the pool is not redundant. If \fInew_device\fR -is not specified, it defaults to \fIold_device\fR. This form of replacement is -useful after an existing disk has failed and has been physically replaced. In -this case, the new disk may have the same \fB/dev/dsk\fR path as the old -device, even though it is actually a different disk. \fBZFS\fR recognizes this. -.sp -.ne 2 -.na -\fB\fB-f\fR\fR -.ad -.RS 6n -Forces use of \fInew_device\fR, even if its appears to be in use. Not all -devices can be overridden in this manner. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool scrub\fR [\fB-s\fR] \fIpool\fR ...\fR -.ad -.sp .6 -.RS 4n +are part of a mirrored configuration can be removed using the +.Qq Nm Cm detach +command. Non-redundant and +.No raidz +devices cannot be removed from a pool. +.It Xo +.Nm +.Cm replace +.Op Fl f +.Ar pool device +.Op Ar new_device +.Xc +.Pp +Replaces +.Ar old_device +with +.Ar new_device . +This is equivalent to attaching +.Ar new_device , +waiting for it to resilver, and then detaching +.Ar old_device . +.Pp +The size of +.Ar new_device +must be greater than or equal to the minimum size +of all the devices in a mirror or +.No raidz +configuration. +.Pp +.Ar new_device +is required if the pool is not redundant. If +.Ar new_device +is not specified, it defaults to +.Ar old_device . +This form of replacement is useful after an existing disk has failed and has +been physically replaced. In this case, the new disk may have the same +.Pa /dev +path as the old device, even though it is actually a different disk. +.Tn ZFS +recognizes this. +.Bl -tag -width indent +.It Fl f +Forces use of +.Ar new_device , +even if its appears to be in use. Not all devices can be overridden in this +manner. +.El +.It Xo +.Nm +.Cm scrub +.Op Fl s +.Ar pool ... +.Xc +.Pp Begins a scrub. The scrub examines all data in the specified pools to verify -that it checksums correctly. For replicated (mirror or \fBraidz\fR) devices, -\fBZFS\fR automatically repairs any damage discovered during the scrub. The -"\fBzpool status\fR" command reports the progress of the scrub and summarizes -the results of the scrub upon completion. -.sp +that it checksums correctly. For replicated (mirror or +.No raidz ) +devices, +.Tn ZFS +automatically repairs any damage discovered during the scrub. The +.Qq Nm Cm status +command reports the progress of the scrub and summarizes the results of the +scrub upon completion. +.Pp Scrubbing and resilvering are very similar operations. The difference is that -resilvering only examines data that \fBZFS\fR knows to be out of date (for -example, when attaching a new device to a mirror or replacing an existing -device), whereas scrubbing examines all data to discover silent errors due to -hardware faults or disk failure. -.sp -Because scrubbing and resilvering are \fBI/O\fR-intensive operations, \fBZFS\fR -only allows one at a time. If a scrub is already in progress, the "\fBzpool -scrub\fR" command terminates it and starts a new scrub. If a resilver is in -progress, \fBZFS\fR does not allow a scrub to be started until the resilver -completes. -.sp -.ne 2 -.na -\fB\fB-s\fR\fR -.ad -.RS 6n +resilvering only examines data that +.Tn ZFS +knows to be out of date (for example, when attaching a new device to a mirror +or replacing an existing device), whereas scrubbing examines all data to +discover silent errors due to hardware faults or disk failure. +.Pp +Because scrubbing and resilvering are +.Tn I/O Ns -intensive +operations, +.Tn ZFS +only allows one at a time. If a scrub is already in progress, the +.Qq Nm Cm scrub +command returns an error. To start a new scrub, you have to stop the old scrub +with the +.Qq Nm Cm scrub Fl s +command first. If a resilver is in progress, +.Tn ZFS +does not allow a scrub to be started until the resilver completes. +.Bl -tag -width indent +.It Fl s Stop scrubbing. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool set\fR \fIproperty\fR=\fIvalue\fR \fIpool\fR\fR -.ad -.sp .6 -.RS 4n -Sets the given property on the specified pool. See the "Properties" section for -more information on what properties can be set and acceptable values. -.RE - -.sp -.ne 2 -.na -\fB\fBzpool status\fR [\fB-xv\fR] [\fIpool\fR] ...\fR -.ad -.sp .6 -.RS 4n -Displays the detailed health status for the given pools. If no \fIpool\fR is -specified, then the status of each pool in the system is displayed. For more -information on pool and device health, see the "Device Failure and Recovery" +.El +.It Xo +.Nm +.Cm set +.Ar property Ns = Ns Ar value pool +.Xc +.Pp +Sets the given property on the specified pool. See the +.Qq Sx Properties +section for more information on what properties can be set and acceptable +values. +.It Xo +.Nm +.Cm split +.Op Fl n +.Op Fl R Ar altroot +.Op Fl o Ar mntopts +.Op Fl o Ar property Ns = Ns Ar value +.Ar pool newpool +.Op Ar device ... +.Xc +.Pp +Splits off one disk from each mirrored top-level +.No vdev +in a pool and creates a new pool from the split-off disks. The original pool +must be made up of one or more mirrors and must not be in the process of +resilvering. The +.Cm split +subcommand chooses the last device in each mirror +.No vdev +unless overridden by a device specification on the command line. +.Pp +When using a +.Ar device +argument, +.Cm split +includes the specified device(s) in a new pool and, should any devices remain +unspecified, assigns the last device in each mirror +.No vdev +to that pool, as it does normally. If you are uncertain about the outcome of a +.Cm split +command, use the +.Fl n +("dry-run") option to ensure your command will have the effect you intend. +.Bl -tag -width indent +.It Fl R Ar altroot +Automatically import the newly created pool after splitting, using the +specified +.Ar altroot +parameter for the new pool's alternate root. See the +.Sy altroot +description in the +.Qq Sx Properties +section, above. +.It Fl n +Displays the configuration that would be created without actually splitting the +pool. The actual pool split could still fail due to insufficient privileges or +device status. +.It Fl o Ar mntopts +Comma-separated list of mount options to use when mounting datasets within the +pool. See +.Xr zfs 8 +for a description of dataset properties and mount options. Valid only in +conjunction with the +.Fl R +option. +.It Fl o Ar property Ns = Ns Ar value +Sets the specified property on the new pool. See the +.Qq Sx Properties +section, above, for more information on the available pool properties. +.El +.It Xo +.Nm +.Cm status +.Op Fl vx +.Op Fl T Cm d Ns | Ns Cm u +.Op Ar pool +.Ar ... +.Op Ar interval Op Ar count +.Xc +.Pp +Displays the detailed health status for the given pools. If no +.Ar pool +is specified, then the status of each pool in the system is displayed. For more +information on pool and device health, see the +.Qq Sx Device Failure and Recovery section. -.sp +.Pp +When given an interval, the output is printed every +.Ar interval +seconds until +.Sy Ctrl-C +is pressed. If +.Ar count +is specified, the command exits after +.Ar count +reports are printed. +.Pp If a scrub or resilver is in progress, this command reports the percentage done and the estimated time to completion. Both of these are only approximate, because the amount of data in the pool and the other workloads on the system can change. -.sp -.ne 2 -.na -\fB\fB-x\fR\fR -.ad -.RS 6n +.Bl -tag -width indent +.It Fl x Only display status for pools that are exhibiting errors or are otherwise unavailable. -.RE - -.sp -.ne 2 -.na -\fB\fB-v\fR\fR -.ad -.RS 6n +.It Fl v Displays verbose data error information, printing out a complete list of all data errors since the last complete pool scrub. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBzpool upgrade\fR\fR -.ad -.sp .6 -.RS 4n -Displays all pools formatted using a different \fBZFS\fR on-disk version. Older -versions can continue to be used, but some features may not be available. These -pools can be upgraded using "\fBzpool upgrade -a\fR". Pools that are formatted -with a more recent version are also displayed, although these pools will be -inaccessible on the system. -.RE - -.sp -.ne 2 -.na -\fB\fBzpool upgrade\fR \fB-v\fR\fR -.ad -.sp .6 -.RS 4n -Displays \fBZFS\fR versions supported by the current software. The current -\fBZFS\fR versions and all previous supported versions are displayed, along +.It Fl T Cm d Ns | Ns Cm u +Print a timestamp. +.Pp +Use modifier +.Cm d +for standard date format. See +.Xr date 1 . +Use modifier +.Cm u +for unixtime +.Pq equals Qq Ic date +%s . +.El +.It Xo +.Nm +.Cm upgrade +.Op Fl v +.Xc +.Pp +Displays all pools formatted using a different +.Tn ZFS +pool on-disk version. Older versions can continue to be used, but some +features may not be available. These pools can be upgraded using +.Qq Nm Cm upgrade Fl a . +Pools that are formatted with a more recent version are also displayed, +although these pools will be inaccessible on the system. +.Bl -tag -width indent +.It Fl v +Displays +.Tn ZFS +pool versions supported by the current software. The current +.Tn ZFS +pool version and all previous supported versions are displayed, along with an explanation of the features provided with each version. -.RE - -.sp -.ne 2 -.na -\fB\fBzpool upgrade\fR [\fB-V\fR \fIversion\fR] \fB-a\fR | \fIpool\fR ...\fR -.ad -.sp .6 -.RS 4n -Upgrades the given pool to the latest on-disk version. Once this is done, the -pool will no longer be accessible on systems running older versions of the +.El +.It Xo +.Nm +.Cm upgrade +.Op Fl V Ar version +.Fl a | Ar pool ... +.Xc +.Pp +Upgrades the given pool to the latest on-disk pool version. Once this is done, +the pool will no longer be accessible on systems running older versions of the software. -.sp -.ne 2 -.na -\fB\fB-a\fR\fR -.ad -.RS 14n +.Bl -tag -width indent +.It Fl a Upgrades all pools. -.RE - -.sp -.ne 2 -.na -\fB\fB-V\fR \fIversion\fR\fR -.ad -.RS 14n -Upgrade to the specified version. If the \fB-V\fR flag is not specified, the -pool is upgraded to the most recent version. This option can only be used to -increase the version number, and only up to the most recent version supported -by this software. -.RE - -.RE - -.SH EXAMPLES -.LP -\fBExample 1 \fRCreating a RAID-Z Storage Pool -.sp -.LP -The following command creates a pool with a single \fBraidz\fR root \fIvdev\fR +.It Fl V Ar version +Upgrade to the specified version. If the +.Fl V +flag is not specified, the pool is upgraded to the most recent version. This +option can only be used to increase the version number, and only up to the most +recent version supported by this software. +.El +.El +.Sh EXAMPLES +.Bl -tag -width 0n +.It Sy Example 1 No Creating a RAID-Z Storage Pool +.Pp +The following command creates a pool with a single +.No raidz +root +.No vdev that consists of six disks. - -.sp -.in +2 -.nf -# \fBzpool create tank raidz da0 da1 da2 da3 da4 da5\fR -.fi -.in -2 -.sp - -.LP -\fBExample 2 \fRCreating a Mirrored Storage Pool -.sp -.LP +.Bd -literal -offset 2n +.Li # Ic zpool create tank raidz da0 da1 da2 da3 da4 da5 +.Ed +.It Sy Example 2 No Creating a Mirrored Storage Pool +.Pp The following command creates a pool with two mirrors, where each mirror contains two disks. - -.sp -.in +2 -.nf -# \fBzpool create tank mirror da0 da1 mirror da2 da3\fR -.fi -.in -2 -.sp - -.LP -\fBExample 3 \fRCreating a ZFS Storage Pool by Using Slices -.sp -.LP -The following command creates an unmirrored pool using two disk slices. - -.sp -.in +2 -.nf -# \fBzpool create tank /dev/da0s1 da1s4\fR -.fi -.in -2 -.sp - -.LP -\fBExample 4 \fRCreating a ZFS Storage Pool by Using Files -.sp -.LP +.Bd -literal -offset 2n +.Li # Ic zpool create tank mirror da0 da1 mirror da2 da3 +.Ed +.It Sy Example 3 No Creating a Tn ZFS No Storage Pool by Using Partitions +.Pp +The following command creates an unmirrored pool using two GPT partitions. +.Bd -literal -offset 2n +.Li # Ic zpool create tank da0p3 da1p3 +.Ed +.It Sy Example 4 No Creating a Tn ZFS No Storage Pool by Using Files +.Pp The following command creates an unmirrored pool using files. While not recommended, a pool based on files can be useful for experimental purposes. - -.sp -.in +2 -.nf -# \fBzpool create tank /path/to/file/a /path/to/file/b\fR -.fi -.in -2 -.sp - -.LP -\fBExample 5 \fRAdding a Mirror to a ZFS Storage Pool -.sp -.LP -The following command adds two mirrored disks to the pool "\fItank\fR", +.Bd -literal -offset 2n +.Li # Ic zpool create tank /path/to/file/a /path/to/file/b +.Ed +.It Sy Example 5 No Adding a Mirror to a Tn ZFS No Storage Pool +.Pp +The following command adds two mirrored disks to the pool +.Em tank , assuming the pool is already made up of two-way mirrors. The additional space is immediately available to any datasets within the pool. - -.sp -.in +2 -.nf -# \fBzpool add tank mirror da0 da1\fR -.fi -.in -2 -.sp - -.LP -\fBExample 6 \fRListing Available ZFS Storage Pools -.sp -.LP -The following command lists all available pools on the system. In this case, -the pool \fIzion\fR is faulted due to a missing device. - -.sp -.LP -The results from this command are similar to the following: - -.sp -.in +2 -.nf -# \fBzpool list\fR - NAME SIZE USED AVAIL CAP HEALTH ALTROOT - pool 67.5G 2.92M 67.5G 0% ONLINE - - tank 67.5G 2.92M 67.5G 0% ONLINE - - zion - - - 0% FAULTED - -.fi -.in -2 -.sp - -.LP -\fBExample 7 \fRDestroying a ZFS Storage Pool -.sp -.LP -The following command destroys the pool "\fItank\fR" and any datasets contained -within. - -.sp -.in +2 -.nf -# \fBzpool destroy -f tank\fR -.fi -.in -2 -.sp - -.LP -\fBExample 8 \fRExporting a ZFS Storage Pool -.sp -.LP -The following command exports the devices in pool \fItank\fR so that they can -be relocated or later imported. - -.sp -.in +2 -.nf -# \fBzpool export tank\fR -.fi -.in -2 -.sp - -.LP -\fBExample 9 \fRImporting a ZFS Storage Pool -.sp -.LP +.Bd -literal -offset 2n +.Li # Ic zpool add tank mirror da2 da3 +.Ed +.It Sy Example 6 No Listing Available Tn ZFS No Storage Pools +.Pp +The following command lists all available pools on the system. +.Bd -literal -offset 2n +.Li # Ic zpool list +NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT +pool 2.70T 473G 2.24T 17% 1.00x ONLINE - +test 1.98G 89.5K 1.98G 0% 1.00x ONLINE - +.Ed +.It Sy Example 7 No Listing All Properties for a Pool +.Pp +The following command lists all the properties for a pool. +.Bd -literal -offset 2n +.Li # Ic zpool get all pool +pool size 2.70T - +pool capacity 17% - +pool altroot - default +pool health ONLINE - +pool guid 2501120270416322443 default +pool version 28 default +pool bootfs pool/root local +pool delegation on default +pool autoreplace off default +pool cachefile - default +pool failmode wait default +pool listsnapshots off default +pool autoexpand off default +pool dedupditto 0 default +pool dedupratio 1.00x - +pool free 2.24T - +pool allocated 473G - +pool readonly off - +.Ed +.It Sy Example 8 No Destroying a Tn ZFS No Storage Pool +.Pp +The following command destroys the pool +.Qq Em tank +and any datasets contained within. +.Bd -literal -offset 2n +.Li # Ic zpool destroy -f tank +.Ed +.It Sy Example 9 No Exporting a Tn ZFS No Storage Pool +.Pp +The following command exports the devices in pool +.Em tank +so that they can be relocated or later imported. +.Bd -literal -offset 2n +.Li # Ic zpool export tank +.Ed +.It Sy Example 10 No Importing a Tn ZFS No Storage Pool +.Pp The following command displays available pools, and then imports the pool -"tank" for use on the system. - -.sp -.LP +.Qq Em tank +for use on the system. +.Pp The results from this command are similar to the following: +.Bd -literal -offset 2n +.Li # Ic zpool import -.sp -.in +2 -.nf -# \fBzpool import\fR pool: tank id: 15451357997522795478 state: ONLINE @@ -1808,132 +1732,83 @@ config: mirror ONLINE da0 ONLINE da1 ONLINE - -# \fBzpool import tank\fR -.fi -.in -2 -.sp - -.LP -\fBExample 10 \fRUpgrading All ZFS Storage Pools to the Current Version -.sp -.LP -The following command upgrades all ZFS Storage pools to the current version of +.Ed +.It Xo +.Sy Example 11 +Upgrading All +.Tn ZFS +Storage Pools to the Current Version +.Xc +.Pp +The following command upgrades all +.Tn ZFS +Storage pools to the current version of the software. - -.sp -.in +2 -.nf -# \fBzpool upgrade -a\fR -This system is currently running ZFS version 2. -.fi -.in -2 -.sp - -.LP -\fBExample 11 \fRManaging Hot Spares -.sp -.LP +.Bd -literal -offset 2n +.Li # Ic zpool upgrade -a +This system is currently running ZFS pool version 28. +.Ed +.It Sy Example 12 No Managing Hot Spares +.Pp The following command creates a new pool with an available hot spare: - -.sp -.in +2 -.nf -# \fBzpool create tank mirror da0 da1 spare da2\fR -.fi -.in -2 -.sp - -.sp -.LP +.Bd -literal -offset 2n +.Li # Ic zpool create tank mirror da0 da1 spare da2 +.Ed +.Pp If one of the disks were to fail, the pool would be reduced to the degraded state. The failed device can be replaced using the following command: - -.sp -.in +2 -.nf -# \fBzpool replace tank da0 da2\fR -.fi -.in -2 -.sp - -.sp -.LP +.Bd -literal -offset 2n +.Li # Ic zpool replace tank da0 da2 +.Ed +.Pp Once the data has been resilvered, the spare is automatically removed and is made available should another device fails. The hot spare can be permanently removed from the pool using the following command: - -.sp -.in +2 -.nf -# \fBzpool remove tank da3\fR -.fi -.in -2 -.sp - -.LP -\fBExample 12 \fRCreating a ZFS Pool with Mirrored Separate Intent Logs -.sp -.LP -The following command creates a ZFS storage pool consisting of two, two-way +.Bd -literal -offset 2n +.Li # Ic zpool remove tank da2 +.Ed +.It Xo +.Sy Example 13 +Creating a +.Tn ZFS +Pool with Mirrored Separate Intent Logs +.Xc +.Pp +The following command creates a +.Tn ZFS +storage pool consisting of two, two-way mirrors and mirrored log devices: - -.sp -.in +2 -.nf -# \fBzpool create pool mirror da0 da1 mirror da2 da3 log mirror \e - da4 da5\fR -.fi -.in -2 -.sp - -.LP -\fBExample 13 \fRAdding Cache Devices to a ZFS Pool -.sp -.LP -The following command adds two disks for use as cache devices to a ZFS storage -pool: - -.sp -.in +2 -.nf -# \fBzpool add pool cache c2d0 c3d0\fR -.fi -.in -2 -.sp - -.sp -.LP +.Bd -literal -offset 2n +.Li # Ic zpool create pool mirror da0 da1 mirror da2 da3 log miror da4 da5 +.Ed +.It Sy Example 14 No Adding Cache Devices to a Tn ZFS No Pool +.Pp +The following command adds two disks for use as cache devices to a +.Tn ZFS +storage pool: +.Bd -literal -offset 2n +.Li # Ic zpool add pool cache da2 da3 +.Ed +.Pp Once added, the cache devices gradually fill with content from main memory. Depending on the size of your cache devices, it could take over an hour for -them to fill. Capacity and reads can be monitored using the \fBiostat\fR option -as follows: - -.sp -.in +2 -.nf -# \fBzpool iostat -v pool 5\fR -.fi -.in -2 -.sp - -.LP -\fBExample 14 \fRRemoving a Mirrored Log Device -.sp -.LP -The following command removes the mirrored log device \fBmirror-2\fR. - -.sp -.LP +them to fill. Capacity and reads can be monitored using the +.Cm iostat +subcommand as follows: +.Bd -literal -offset 2n +.Li # Ic zpool iostat -v pool 5 +.Ed +.It Sy Example 15 No Removing a Mirrored Log Device +.Pp +The following command removes the mirrored log device +.Em mirror-2 . +.Pp Given this configuration: - -.sp -.in +2 -.nf +.Bd -literal -offset 2n pool: tank state: ONLINE scrub: none requested -config: + config: NAME STATE READ WRITE CKSUM tank ONLINE 0 0 0 @@ -1947,54 +1822,68 @@ config: mirror-2 ONLINE 0 0 0 da4 ONLINE 0 0 0 da5 ONLINE 0 0 0 -.fi -.in -2 -.sp - -.sp -.LP -The command to remove the mirrored log \fBmirror-2\fR is: - -.sp -.in +2 -.nf -# \fBzpool remove tank mirror-2\fR -.fi -.in -2 -.sp - -.SH EXIT STATUS -.sp -.LP +.Ed +.Pp +The command to remove the mirrored log +.Em mirror-2 +is: +.Bd -literal -offset 2n +.Li # Ic zpool remove tank mirror-2 +.Ed +.It Sy Example 16 No Recovering a Faulted Tn ZFS No Pool +.Pp +If a pool is faulted but recoverable, a message indicating this state is +provided by +.Qq Nm Cm status +if the pool was cached (see the +.Fl c Ar cachefile +argument above), or as part of the error output from a failed +.Qq Nm Cm import +of the pool. +.Pp +Recover a cached pool with the +.Qq Nm Cm clear +command: +.Bd -literal -offset 2n +.Li # Ic zpool clear -F data +Pool data returned to its state as of Tue Sep 08 13:23:35 2009. +Discarded approximately 29 seconds of transactions. +.Ed +.Pp +If the pool configuration was not cached, use +.Qq Nm Cm import +with the recovery mode flag: +.Bd -literal -offset 2n +.Li # Ic zpool import -F data +Pool data returned to its state as of Tue Sep 08 13:23:35 2009. +Discarded approximately 29 seconds of transactions. +.Ed +.El +.Sh EXIT STATUS The following exit values are returned: -.sp -.ne 2 -.na -\fB\fB0\fR\fR -.ad -.RS 5n +.Bl -tag -offset 2n -width 2n +.It 0 Successful completion. -.RE - -.sp -.ne 2 -.na -\fB\fB1\fR\fR -.ad -.RS 5n +.It 1 An error occurred. -.RE - -.sp -.ne 2 -.na -\fB\fB2\fR\fR -.ad -.RS 5n +.It 2 Invalid command line options were specified. -.RE - -.SH SEE ALSO -.sp -.LP -zfs(8) +.El +.Sh SEE ALSO +.Xr zfs 8 +.Sh AUTHORS +This manual page is a +.Xr mdoc 7 +reimplementation of the +.Tn OpenSolaris +manual page +.Em zpool(1M) , +modified and customized for +.Fx +and licensed under the Common Development and Distribution License +.Pq Tn CDDL . +.Pp +The +.Xr mdoc 7 +implementation of this manual page was initially written by +.An Martin Matuska Aq mm@FreeBSD.org . diff --git a/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c b/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c index cb09d7b541f5..fe76250f2f68 100644 --- a/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c +++ b/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c @@ -22,6 +22,8 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2011 Nexenta Systems, Inc. All rights reserved. + * Copyright (c) 2011 by Delphix. All rights reserved. + * Copyright (c) 2011 Martin Matuska . All rights reserved. */ #include @@ -68,6 +70,8 @@ static int zpool_do_online(int, char **); static int zpool_do_offline(int, char **); static int zpool_do_clear(int, char **); +static int zpool_do_reguid(int, char **); + static int zpool_do_attach(int, char **); static int zpool_do_detach(int, char **); static int zpool_do_replace(int, char **); @@ -126,7 +130,8 @@ typedef enum { HELP_UPGRADE, HELP_GET, HELP_SET, - HELP_SPLIT + HELP_SPLIT, + HELP_REGUID } zpool_help_t; @@ -172,6 +177,7 @@ static zpool_command_t command_table[] = { { "import", zpool_do_import, HELP_IMPORT }, { "export", zpool_do_export, HELP_EXPORT }, { "upgrade", zpool_do_upgrade, HELP_UPGRADE }, + { "reguid", zpool_do_reguid, HELP_REGUID }, { NULL }, { "history", zpool_do_history, HELP_HISTORY }, { "get", zpool_do_get, HELP_GET }, @@ -228,7 +234,7 @@ get_usage(zpool_help_t idx) { case HELP_OFFLINE: return (gettext("\toffline [-t] ...\n")); case HELP_ONLINE: - return (gettext("\tonline ...\n")); + return (gettext("\tonline [-e] ...\n")); case HELP_REPLACE: return (gettext("\treplace [-f] " "[new-device]\n")); @@ -240,8 +246,7 @@ get_usage(zpool_help_t idx) { return (gettext("\tstatus [-vx] [-T d|u] [pool] ... [interval " "[count]]\n")); case HELP_UPGRADE: - return (gettext("\tupgrade\n" - "\tupgrade -v\n" + return (gettext("\tupgrade [-v]\n" "\tupgrade [-V version] <-a | pool ...>\n")); case HELP_GET: return (gettext("\tget <\"all\" | property[,...]> " @@ -252,6 +257,8 @@ get_usage(zpool_help_t idx) { return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n" "\t [-o property=value] " "[ ...]\n")); + case HELP_REGUID: + return (gettext("\treguid \n")); } abort(); @@ -1455,6 +1462,7 @@ show_import(nvlist_t *config) const char *health; uint_t vsc; int namewidth; + char *comment; verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME, &name) == 0); @@ -1471,9 +1479,9 @@ show_import(nvlist_t *config) reason = zpool_import_status(config, &msgid); - (void) printf(gettext(" pool: %s\n"), name); - (void) printf(gettext(" id: %llu\n"), (u_longlong_t)guid); - (void) printf(gettext(" state: %s"), health); + (void) printf(gettext(" pool: %s\n"), name); + (void) printf(gettext(" id: %llu\n"), (u_longlong_t)guid); + (void) printf(gettext(" state: %s"), health); if (pool_state == POOL_STATE_DESTROYED) (void) printf(gettext(" (DESTROYED)")); (void) printf("\n"); @@ -1482,58 +1490,59 @@ show_import(nvlist_t *config) case ZPOOL_STATUS_MISSING_DEV_R: case ZPOOL_STATUS_MISSING_DEV_NR: case ZPOOL_STATUS_BAD_GUID_SUM: - (void) printf(gettext("status: One or more devices are missing " - "from the system.\n")); + (void) printf(gettext(" status: One or more devices are " + "missing from the system.\n")); break; case ZPOOL_STATUS_CORRUPT_LABEL_R: case ZPOOL_STATUS_CORRUPT_LABEL_NR: - (void) printf(gettext("status: One or more devices contains " + (void) printf(gettext(" status: One or more devices contains " "corrupted data.\n")); break; case ZPOOL_STATUS_CORRUPT_DATA: - (void) printf(gettext("status: The pool data is corrupted.\n")); + (void) printf( + gettext(" status: The pool data is corrupted.\n")); break; case ZPOOL_STATUS_OFFLINE_DEV: - (void) printf(gettext("status: One or more devices " + (void) printf(gettext(" status: One or more devices " "are offlined.\n")); break; case ZPOOL_STATUS_CORRUPT_POOL: - (void) printf(gettext("status: The pool metadata is " + (void) printf(gettext(" status: The pool metadata is " "corrupted.\n")); break; case ZPOOL_STATUS_VERSION_OLDER: - (void) printf(gettext("status: The pool is formatted using an " + (void) printf(gettext(" status: The pool is formatted using an " "older on-disk version.\n")); break; case ZPOOL_STATUS_VERSION_NEWER: - (void) printf(gettext("status: The pool is formatted using an " + (void) printf(gettext(" status: The pool is formatted using an " "incompatible version.\n")); break; case ZPOOL_STATUS_HOSTID_MISMATCH: - (void) printf(gettext("status: The pool was last accessed by " + (void) printf(gettext(" status: The pool was last accessed by " "another system.\n")); break; case ZPOOL_STATUS_FAULTED_DEV_R: case ZPOOL_STATUS_FAULTED_DEV_NR: - (void) printf(gettext("status: One or more devices are " + (void) printf(gettext(" status: One or more devices are " "faulted.\n")); break; case ZPOOL_STATUS_BAD_LOG: - (void) printf(gettext("status: An intent log record cannot be " + (void) printf(gettext(" status: An intent log record cannot be " "read.\n")); break; case ZPOOL_STATUS_RESILVERING: - (void) printf(gettext("status: One or more devices were being " + (void) printf(gettext(" status: One or more devices were being " "resilvered.\n")); break; @@ -1549,26 +1558,26 @@ show_import(nvlist_t *config) */ if (vs->vs_state == VDEV_STATE_HEALTHY) { if (reason == ZPOOL_STATUS_VERSION_OLDER) - (void) printf(gettext("action: The pool can be " + (void) printf(gettext(" action: The pool can be " "imported using its name or numeric identifier, " "though\n\tsome features will not be available " "without an explicit 'zpool upgrade'.\n")); else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH) - (void) printf(gettext("action: The pool can be " + (void) printf(gettext(" action: The pool can be " "imported using its name or numeric " "identifier and\n\tthe '-f' flag.\n")); else - (void) printf(gettext("action: The pool can be " + (void) printf(gettext(" action: The pool can be " "imported using its name or numeric " "identifier.\n")); } else if (vs->vs_state == VDEV_STATE_DEGRADED) { - (void) printf(gettext("action: The pool can be imported " + (void) printf(gettext(" action: The pool can be imported " "despite missing or damaged devices. The\n\tfault " "tolerance of the pool may be compromised if imported.\n")); } else { switch (reason) { case ZPOOL_STATUS_VERSION_NEWER: - (void) printf(gettext("action: The pool cannot be " + (void) printf(gettext(" action: The pool cannot be " "imported. Access the pool on a system running " "newer\n\tsoftware, or recreate the pool from " "backup.\n")); @@ -1576,16 +1585,20 @@ show_import(nvlist_t *config) case ZPOOL_STATUS_MISSING_DEV_R: case ZPOOL_STATUS_MISSING_DEV_NR: case ZPOOL_STATUS_BAD_GUID_SUM: - (void) printf(gettext("action: The pool cannot be " + (void) printf(gettext(" action: The pool cannot be " "imported. Attach the missing\n\tdevices and try " "again.\n")); break; default: - (void) printf(gettext("action: The pool cannot be " + (void) printf(gettext(" action: The pool cannot be " "imported due to damaged devices or data.\n")); } } + /* Print the comment attached to the pool. */ + if (nvlist_lookup_string(config, ZPOOL_CONFIG_COMMENT, &comment) == 0) + (void) printf(gettext("comment: %s\n"), comment); + /* * If the state is "closed" or "can't open", and the aux state * is "corrupt data": @@ -1606,7 +1619,7 @@ show_import(nvlist_t *config) (void) printf(gettext(" see: http://www.sun.com/msg/%s\n"), msgid); - (void) printf(gettext("config:\n\n")); + (void) printf(gettext(" config:\n\n")); namewidth = max_width(NULL, nvroot, 0, 0); if (namewidth < 10) @@ -3321,6 +3334,52 @@ zpool_do_clear(int argc, char **argv) return (ret); } +/* + * zpool reguid + */ +int +zpool_do_reguid(int argc, char **argv) +{ + int c; + char *poolname; + zpool_handle_t *zhp; + int ret = 0; + + /* check options */ + while ((c = getopt(argc, argv, "")) != -1) { + switch (c) { + case '?': + (void) fprintf(stderr, gettext("invalid option '%c'\n"), + optopt); + usage(B_FALSE); + } + } + + argc -= optind; + argv += optind; + + /* get pool name and check number of arguments */ + if (argc < 1) { + (void) fprintf(stderr, gettext("missing pool name\n")); + usage(B_FALSE); + } + + if (argc > 1) { + (void) fprintf(stderr, gettext("too many arguments\n")); + usage(B_FALSE); + } + + poolname = argv[0]; + if ((zhp = zpool_open(g_zfs, poolname)) == NULL) + return (1); + + ret = zpool_reguid(zhp); + + zpool_close(zhp); + return (ret); +} + + typedef struct scrub_cbdata { int cb_type; int cb_argc; diff --git a/cddl/contrib/opensolaris/cmd/zstreamdump/zstreamdump.1 b/cddl/contrib/opensolaris/cmd/zstreamdump/zstreamdump.1 index 6e77d395b2e0..f800a0513b93 100644 --- a/cddl/contrib/opensolaris/cmd/zstreamdump/zstreamdump.1 +++ b/cddl/contrib/opensolaris/cmd/zstreamdump/zstreamdump.1 @@ -1,49 +1,67 @@ '\" te -.\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved -.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. -.\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with -.\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.\" Portions Copyright 2011 Martin Matuska -.TH ZSTREAMDUMP 1 "Sep 21, 2009" -.SH NAME -zstreamdump \- filter data in zfs send stream -.SH SYNOPSIS -.LP -.nf -\fBzstreamdump\fR [\fB-C\fR] [\fB-v\fR] -.fi - -.SH DESCRIPTION -.sp -.LP -The \fBzstreamdump\fR utility reads from the output of the \fBzfs send\fR -command, then displays headers and some statistics from that output. See -\fBzfs\fR(1M). -.SH OPTIONS -.sp -.LP +.\" Copyright (c) 2011, Martin Matuska . +.\" All Rights Reserved. +.\" +.\" The contents of this file are subject to the terms of the +.\" Common Development and Distribution License (the "License"). +.\" You may not use this file except in compliance with the License. +.\" +.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +.\" or http://www.opensolaris.org/os/licensing. +.\" See the License for the specific language governing permissions +.\" and limitations under the License. +.\" +.\" When distributing Covered Code, include this CDDL HEADER in each +.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. +.\" If applicable, add the following below this CDDL HEADER, with the +.\" fields enclosed by brackets "[]" replaced with your own identifying +.\" information: Portions Copyright [yyyy] [name of copyright owner] +.\" +.\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved. +.\" +.\" $FreeBSD$ +.\" +.Dd November 26, 2011 +.Dt ZSTREAMDUMP 8 +.Os +.Sh NAME +.Nm zdb +.Nd filter data in zfs send stream +.Sh SYNOPSIS +.Nm +.Op Fl C +.Op Fl v +.Sh DESCRIPTION +The +.Nm +utility reads from the output of the +.Qq Nm zfs Cm send +command, then displays headers and some statistics from that output. See +.Xr zfs 8 . +.Pp The following options are supported: -.sp -.ne 2 -.na -\fB\fB-C\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width indent +.It Fl C Suppress the validation of checksums. -.RE - -.sp -.ne 2 -.na -\fB\fB-v\fR\fR -.ad -.sp .6 -.RS 4n +.It Fl v Verbose. Dump all headers, not only begin and end headers. -.RE - -.SH SEE ALSO -.sp -.LP -zfs(8) +.El +.Sh SEE ALSO +.Xr zfs 8 +.Sh AUTHORS +This manual page is a +.Xr mdoc 7 +reimplementation of the +.Tn OpenSolaris +manual page +.Em zstreamdump(1M) , +modified and customized for +.Fx +and licensed under the +.Tn Common Development and Distribution License +.Pq Tn CDDL . +.Pp +The +.Xr mdoc 7 +implementation of this manual page was initially written by +.An Martin Matuska Aq mm@FreeBSD.org . diff --git a/cddl/contrib/opensolaris/cmd/ztest/ztest.c b/cddl/contrib/opensolaris/cmd/ztest/ztest.c index d90961e50a8b..3a6c35035fc4 100644 --- a/cddl/contrib/opensolaris/cmd/ztest/ztest.c +++ b/cddl/contrib/opensolaris/cmd/ztest/ztest.c @@ -21,6 +21,7 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011 by Delphix. All rights reserved. + * Copyright 2011 Nexenta Systems, Inc. All rights reserved. */ /* @@ -259,6 +260,7 @@ ztest_func_t ztest_vdev_LUN_growth; ztest_func_t ztest_vdev_add_remove; ztest_func_t ztest_vdev_aux_add_remove; ztest_func_t ztest_split_pool; +ztest_func_t ztest_reguid; uint64_t zopt_always = 0ULL * NANOSEC; /* all the time */ uint64_t zopt_incessant = 1ULL * NANOSEC / 10; /* every 1/10 second */ @@ -289,6 +291,7 @@ ztest_info_t ztest_info[] = { { ztest_fault_inject, 1, &zopt_sometimes }, { ztest_ddt_repair, 1, &zopt_sometimes }, { ztest_dmu_snapshot_hold, 1, &zopt_sometimes }, + { ztest_reguid, 1, &zopt_sometimes }, { ztest_spa_rename, 1, &zopt_rarely }, { ztest_scrub, 1, &zopt_rarely }, { ztest_dsl_dataset_promote_busy, 1, &zopt_rarely }, @@ -325,6 +328,7 @@ typedef struct ztest_shared { uint64_t zs_vdev_aux; uint64_t zs_alloc; uint64_t zs_space; + uint64_t zs_guid; mutex_t zs_vdev_lock; rwlock_t zs_name_lock; ztest_info_t zs_info[ZTEST_FUNCS]; @@ -4646,7 +4650,7 @@ ztest_ddt_repair(ztest_ds_t *zd, uint64_t id) object = od[0].od_object; blocksize = od[0].od_blocksize; - pattern = spa_guid(spa) ^ dmu_objset_fsid_guid(os); + pattern = zs->zs_guid ^ dmu_objset_fsid_guid(os); ASSERT(object != 0); @@ -4716,6 +4720,31 @@ ztest_scrub(ztest_ds_t *zd, uint64_t id) (void) spa_scan(spa, POOL_SCAN_SCRUB); } +/* + * Change the guid for the pool. + */ +/* ARGSUSED */ +void +ztest_reguid(ztest_ds_t *zd, uint64_t id) +{ + ztest_shared_t *zs = ztest_shared; + spa_t *spa = zs->zs_spa; + uint64_t orig, load; + + orig = spa_guid(spa); + load = spa_load_guid(spa); + if (spa_change_guid(spa) != 0) + return; + + if (zopt_verbose >= 3) { + (void) printf("Changed guid old %llu -> %llu\n", + (u_longlong_t)orig, (u_longlong_t)spa_guid(spa)); + } + + VERIFY3U(orig, !=, spa_guid(spa)); + VERIFY3U(load, ==, spa_load_guid(spa)); +} + /* * Rename the pool to a different name and then rename it back. */ @@ -5145,6 +5174,7 @@ ztest_run(ztest_shared_t *zs) { thread_t *tid; spa_t *spa; + objset_t *os; thread_t resume_tid; int error; @@ -5176,6 +5206,10 @@ ztest_run(ztest_shared_t *zs) spa->spa_debug = B_TRUE; zs->zs_spa = spa; + VERIFY3U(0, ==, dmu_objset_hold(zs->zs_pool, FTAG, &os)); + zs->zs_guid = dmu_objset_fsid_guid(os); + dmu_objset_rele(os, FTAG); + spa->spa_dedup_ditto = 2 * ZIO_DEDUPDITTO_MIN; /* diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c b/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c index 7a14dd38d31e..3b4a38ce34ab 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/drti.c @@ -102,7 +102,7 @@ fixsymbol(Elf *e, Elf_Data *data, size_t idx, int nprobes, char *buf, int ndx; while (gelf_getsym(data, j++, &sym) != NULL) { - prb = (dof_probe_t *)(buf + sec->dofs_offset); + prb = (dof_probe_t *)(void *)(buf + sec->dofs_offset); for (ndx = nprobes; ndx; ndx--, prb += 1) { funcname = dofstrtab + prb->dofpr_func; diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c index 911478ee0753..af4af8a38e4d 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c @@ -873,7 +873,7 @@ dt_print_stack(dtrace_hdl_t *dtp, FILE *fp, const char *format, if (pc > sym.st_value) { (void) snprintf(c, sizeof (c), "%s`%s+0x%llx", dts.dts_object, dts.dts_name, - pc - sym.st_value); + (u_longlong_t)(pc - sym.st_value)); } else { (void) snprintf(c, sizeof (c), "%s`%s", dts.dts_object, dts.dts_name); @@ -886,9 +886,10 @@ dt_print_stack(dtrace_hdl_t *dtp, FILE *fp, const char *format, */ if (dtrace_lookup_by_addr(dtp, pc, NULL, &dts) == 0) { (void) snprintf(c, sizeof (c), "%s`0x%llx", - dts.dts_object, pc); + dts.dts_object, (u_longlong_t)pc); } else { - (void) snprintf(c, sizeof (c), "0x%llx", pc); + (void) snprintf(c, sizeof (c), "0x%llx", + (u_longlong_t)pc); } } diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_handle.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_handle.c index ea039e993bd2..fe1ec7a80f71 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_handle.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_handle.c @@ -335,7 +335,8 @@ dt_handle_cpudrop(dtrace_hdl_t *dtp, processorid_t cpu, } (void) snprintf(s, size, "%llu %sdrop%s on CPU %d\n", - howmany, what == DTRACEDROP_PRINCIPAL ? "" : "aggregation ", + (u_longlong_t)howmany, + what == DTRACEDROP_PRINCIPAL ? "" : "aggregation ", howmany > 1 ? "s" : "", cpu); if (dtp->dt_drophdlr == NULL) @@ -427,7 +428,8 @@ dt_handle_status(dtrace_hdl_t *dtp, dtrace_status_t *old, dtrace_status_t *new) size = sizeof (str); } - (void) snprintf(s, size, "%llu %s%s%s\n", nval - oval, + (void) snprintf(s, size, "%llu %s%s%s\n", + (u_longlong_t)(nval - oval), _dt_droptab[i].dtdrt_str, (nval - oval > 1) ? "s" : "", _dt_droptab[i].dtdrt_msg != NULL ? _dt_droptab[i].dtdrt_msg : ""); diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c index ca355eacdd77..2d0428aabb51 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c @@ -1106,7 +1106,7 @@ process_obj(dtrace_hdl_t *dtp, const char *obj, int *eprobesp) static const char dt_prefix[] = "__dtrace"; static const char dt_enabled[] = "enabled"; static const char dt_symprefix[] = "$dtrace"; - static const char dt_symfmt[] = "%s%d.%s"; + static const char dt_symfmt[] = "%s%ld.%s"; int fd, i, ndx, eprobe, mod = 0; Elf *elf = NULL; GElf_Ehdr ehdr; diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_subr.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_subr.c index ea4607f995b9..839ce0628ace 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_subr.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_subr.c @@ -27,6 +27,7 @@ #if defined(sun) #include #endif +#include #include #include diff --git a/cddl/contrib/opensolaris/lib/libdtrace/i386/dt_isadep.c b/cddl/contrib/opensolaris/lib/libdtrace/i386/dt_isadep.c index ad1c0324de6a..f11ae480a807 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/i386/dt_isadep.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/i386/dt_isadep.c @@ -436,7 +436,7 @@ dt_pid_create_glob_offset_probes(struct ps_prochandle *P, dtrace_hdl_t *dtp, char name[sizeof (i) * 2 + 1]; for (i = 0; i < end; i += size) { - (void) snprintf(name, sizeof (name), "%x", i); + (void) snprintf(name, sizeof (name), "%lx", i); if (gmatch(name, pattern)) ftp->ftps_offs[ftp->ftps_noffs++] = i; diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h index 6b25879ed5fe..e1d9c932c5d4 100644 --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h @@ -21,8 +21,8 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2010 Nexenta Systems, Inc. All rights reserved. - * Copyright (c) 2011 Pawel Jakub Dawidek . + * Copyright 2011 Nexenta Systems, Inc. All rights reserved. + * Copyright (c) 2011 by Delphix. All rights reserved. * All rights reserved. */ @@ -233,6 +233,7 @@ typedef struct splitflags { */ extern int zpool_scan(zpool_handle_t *, pool_scan_func_t); extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *); +extern int zpool_reguid(zpool_handle_t *); extern int zpool_vdev_online(zpool_handle_t *, const char *, int, vdev_state_t *); @@ -384,6 +385,7 @@ extern void zpool_explain_recover(libzfs_handle_t *, const char *, int, * underlying datasets, only the references to them. */ extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int); +extern zfs_handle_t *zfs_handle_dup(zfs_handle_t *); extern void zfs_close(zfs_handle_t *); extern zfs_type_t zfs_get_type(const zfs_handle_t *); extern const char *zfs_get_name(const zfs_handle_t *); @@ -417,12 +419,20 @@ extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname, uint64_t *propvalue); extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname, char *propbuf, int proplen, boolean_t literal); +extern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname, + uint64_t *propvalue); +extern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname, + char *propbuf, int proplen, boolean_t literal); +extern int zfs_get_snapused_int(zfs_handle_t *firstsnap, zfs_handle_t *lastsnap, + uint64_t *usedp); extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t); extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t); extern const char *zfs_prop_values(zfs_prop_t); extern int zfs_prop_is_string(zfs_prop_t prop); extern nvlist_t *zfs_get_user_props(zfs_handle_t *); extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *); +extern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *); + typedef struct zprop_list { int pl_prop; @@ -497,6 +507,7 @@ extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *); extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *); extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *); extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *); +extern int zfs_iter_snapspec(zfs_handle_t *, const char *, zfs_iter_f, void *); typedef struct get_all_cb { zfs_handle_t **cb_handles; @@ -517,6 +528,7 @@ extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t, extern int zfs_create_ancestors(libzfs_handle_t *, const char *); extern int zfs_destroy(zfs_handle_t *, boolean_t); extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t); +extern int zfs_destroy_snaps_nvl(zfs_handle_t *, nvlist_t *, boolean_t); extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *); extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t); @@ -533,29 +545,34 @@ extern int zfs_rename(zfs_handle_t *, const char *, renameflags_t flags); typedef struct sendflags { /* print informational messages (ie, -v was specified) */ - int verbose : 1; + boolean_t verbose; /* recursive send (ie, -R) */ - int replicate : 1; + boolean_t replicate; /* for incrementals, do all intermediate snapshots */ - int doall : 1; /* (ie, -I) */ + boolean_t doall; /* if dataset is a clone, do incremental from its origin */ - int fromorigin : 1; + boolean_t fromorigin; /* do deduplication */ - int dedup : 1; + boolean_t dedup; /* send properties (ie, -p) */ - int props : 1; + boolean_t props; + + /* do not send (no-op, ie. -n) */ + boolean_t dryrun; + + /* parsable verbose output (ie. -P) */ + boolean_t parsable; } sendflags_t; typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *); -extern int zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, - sendflags_t flags, int outfd, snapfilter_cb_t filter_func, - void *cb_arg, nvlist_t **debugnvp); +extern int zfs_send(zfs_handle_t *, const char *, const char *, + sendflags_t *, int, snapfilter_cb_t, void *, nvlist_t **); extern int zfs_promote(zfs_handle_t *); extern int zfs_hold(zfs_handle_t *, const char *, const char *, boolean_t, @@ -575,34 +592,34 @@ extern int zfs_set_fsacl(zfs_handle_t *, boolean_t, nvlist_t *); typedef struct recvflags { /* print informational messages (ie, -v was specified) */ - int verbose : 1; + boolean_t verbose; /* the destination is a prefix, not the exact fs (ie, -d) */ - int isprefix : 1; + boolean_t isprefix; /* * Only the tail of the sent snapshot path is appended to the * destination to determine the received snapshot name (ie, -e). */ - int istail : 1; + boolean_t istail; /* do not actually do the recv, just check if it would work (ie, -n) */ - int dryrun : 1; + boolean_t dryrun; /* rollback/destroy filesystems as necessary (eg, -F) */ - int force : 1; + boolean_t force; /* set "canmount=off" on all modified filesystems */ - int canmountoff : 1; + boolean_t canmountoff; /* byteswap flag is used internally; callers need not specify */ - int byteswap : 1; + boolean_t byteswap; /* do not mount file systems as they are extracted (private) */ - int nomount : 1; + boolean_t nomount; } recvflags_t; -extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t, +extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t *, int, avl_tree_t *); typedef enum diff_flags { diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c index a65b0793cab3..bff0586f14b2 100644 --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c @@ -496,7 +496,7 @@ make_dataset_handle(libzfs_handle_t *hdl, const char *path) return (zhp); } -static zfs_handle_t * +zfs_handle_t * make_dataset_handle_zc(libzfs_handle_t *hdl, zfs_cmd_t *zc) { zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1); @@ -513,6 +513,53 @@ make_dataset_handle_zc(libzfs_handle_t *hdl, zfs_cmd_t *zc) return (zhp); } +zfs_handle_t * +zfs_handle_dup(zfs_handle_t *zhp_orig) +{ + zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1); + + if (zhp == NULL) + return (NULL); + + zhp->zfs_hdl = zhp_orig->zfs_hdl; + zhp->zpool_hdl = zhp_orig->zpool_hdl; + (void) strlcpy(zhp->zfs_name, zhp_orig->zfs_name, + sizeof (zhp->zfs_name)); + zhp->zfs_type = zhp_orig->zfs_type; + zhp->zfs_head_type = zhp_orig->zfs_head_type; + zhp->zfs_dmustats = zhp_orig->zfs_dmustats; + if (zhp_orig->zfs_props != NULL) { + if (nvlist_dup(zhp_orig->zfs_props, &zhp->zfs_props, 0) != 0) { + (void) no_memory(zhp->zfs_hdl); + zfs_close(zhp); + return (NULL); + } + } + if (zhp_orig->zfs_user_props != NULL) { + if (nvlist_dup(zhp_orig->zfs_user_props, + &zhp->zfs_user_props, 0) != 0) { + (void) no_memory(zhp->zfs_hdl); + zfs_close(zhp); + return (NULL); + } + } + if (zhp_orig->zfs_recvd_props != NULL) { + if (nvlist_dup(zhp_orig->zfs_recvd_props, + &zhp->zfs_recvd_props, 0)) { + (void) no_memory(zhp->zfs_hdl); + zfs_close(zhp); + return (NULL); + } + } + zhp->zfs_mntcheck = zhp_orig->zfs_mntcheck; + if (zhp_orig->zfs_mntopts != NULL) { + zhp->zfs_mntopts = zfs_strdup(zhp_orig->zfs_hdl, + zhp_orig->zfs_mntopts); + } + zhp->zfs_props_table = zhp_orig->zfs_props_table; + return (zhp); +} + /* * Opens the given snapshot, filesystem, or volume. The 'types' * argument is a mask of acceptable types. The function will print an @@ -876,6 +923,12 @@ zfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl, goto error; } continue; + } else if (prop == ZPROP_INVAL && zfs_prop_written(propname)) { + zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, + "'%s' is readonly"), + propname); + (void) zfs_error(hdl, EZFS_PROPREADONLY, errbuf); + goto error; } if (prop == ZPROP_INVAL) { @@ -1869,8 +1922,6 @@ zfs_prop_get_recvd(zfs_handle_t *zhp, const char *propname, char *propbuf, err = zfs_prop_get(zhp, prop, propbuf, proplen, NULL, NULL, 0, literal); zfs_unset_recvd_props_mode(zhp, &cookie); - } else if (zfs_prop_userquota(propname)) { - return (-1); } else { nvlist_t *propval; char *recvdval; @@ -1885,6 +1936,120 @@ zfs_prop_get_recvd(zfs_handle_t *zhp, const char *propname, char *propbuf, return (err == 0 ? 0 : -1); } +static int +get_clones_string(zfs_handle_t *zhp, char *propbuf, size_t proplen) +{ + nvlist_t *value; + nvpair_t *pair; + + value = zfs_get_clones_nvl(zhp); + if (value == NULL) + return (-1); + + propbuf[0] = '\0'; + for (pair = nvlist_next_nvpair(value, NULL); pair != NULL; + pair = nvlist_next_nvpair(value, pair)) { + if (propbuf[0] != '\0') + (void) strlcat(propbuf, ",", proplen); + (void) strlcat(propbuf, nvpair_name(pair), proplen); + } + + return (0); +} + +struct get_clones_arg { + uint64_t numclones; + nvlist_t *value; + const char *origin; + char buf[ZFS_MAXNAMELEN]; +}; + +int +get_clones_cb(zfs_handle_t *zhp, void *arg) +{ + struct get_clones_arg *gca = arg; + + if (gca->numclones == 0) { + zfs_close(zhp); + return (0); + } + + if (zfs_prop_get(zhp, ZFS_PROP_ORIGIN, gca->buf, sizeof (gca->buf), + NULL, NULL, 0, B_TRUE) != 0) + goto out; + if (strcmp(gca->buf, gca->origin) == 0) { + if (nvlist_add_boolean(gca->value, zfs_get_name(zhp)) != 0) { + zfs_close(zhp); + return (no_memory(zhp->zfs_hdl)); + } + gca->numclones--; + } + +out: + (void) zfs_iter_children(zhp, get_clones_cb, gca); + zfs_close(zhp); + return (0); +} + +nvlist_t * +zfs_get_clones_nvl(zfs_handle_t *zhp) +{ + nvlist_t *nv, *value; + + if (nvlist_lookup_nvlist(zhp->zfs_props, + zfs_prop_to_name(ZFS_PROP_CLONES), &nv) != 0) { + struct get_clones_arg gca; + + /* + * if this is a snapshot, then the kernel wasn't able + * to get the clones. Do it by slowly iterating. + */ + if (zhp->zfs_type != ZFS_TYPE_SNAPSHOT) + return (NULL); + if (nvlist_alloc(&nv, NV_UNIQUE_NAME, 0) != 0) + return (NULL); + if (nvlist_alloc(&value, NV_UNIQUE_NAME, 0) != 0) { + nvlist_free(nv); + return (NULL); + } + + gca.numclones = zfs_prop_get_int(zhp, ZFS_PROP_NUMCLONES); + gca.value = value; + gca.origin = zhp->zfs_name; + + if (gca.numclones != 0) { + zfs_handle_t *root; + char pool[ZFS_MAXNAMELEN]; + char *cp = pool; + + /* get the pool name */ + (void) strlcpy(pool, zhp->zfs_name, sizeof (pool)); + (void) strsep(&cp, "/@"); + root = zfs_open(zhp->zfs_hdl, pool, + ZFS_TYPE_FILESYSTEM); + + (void) get_clones_cb(root, &gca); + } + + if (gca.numclones != 0 || + nvlist_add_nvlist(nv, ZPROP_VALUE, value) != 0 || + nvlist_add_nvlist(zhp->zfs_props, + zfs_prop_to_name(ZFS_PROP_CLONES), nv) != 0) { + nvlist_free(nv); + nvlist_free(value); + return (NULL); + } + nvlist_free(nv); + nvlist_free(value); + verify(0 == nvlist_lookup_nvlist(zhp->zfs_props, + zfs_prop_to_name(ZFS_PROP_CLONES), &nv)); + } + + verify(nvlist_lookup_nvlist(nv, ZPROP_VALUE, &value) == 0); + + return (value); +} + /* * Retrieve a property from the given object. If 'literal' is specified, then * numbers are left as exact values. Otherwise, numbers are converted to a @@ -2013,6 +2178,11 @@ zfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen, return (-1); break; + case ZFS_PROP_CLONES: + if (get_clones_string(zhp, propbuf, proplen) != 0) + return (-1); + break; + case ZFS_PROP_QUOTA: case ZFS_PROP_REFQUOTA: case ZFS_PROP_RESERVATION: @@ -2385,7 +2555,7 @@ zfs_prop_get_userquota_common(zfs_handle_t *zhp, const char *propname, int err; zfs_cmd_t zc = { 0 }; - (void) strncpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); + (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); err = userquota_propname_decode(propname, zfs_prop_get_int(zhp, ZFS_PROP_ZONED), @@ -2437,6 +2607,79 @@ zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname, return (0); } +int +zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname, + uint64_t *propvalue) +{ + int err; + zfs_cmd_t zc = { 0 }; + const char *snapname; + + (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); + + snapname = strchr(propname, '@') + 1; + if (strchr(snapname, '@')) { + (void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value)); + } else { + /* snapname is the short name, append it to zhp's fsname */ + char *cp; + + (void) strlcpy(zc.zc_value, zhp->zfs_name, + sizeof (zc.zc_value)); + cp = strchr(zc.zc_value, '@'); + if (cp != NULL) + *cp = '\0'; + (void) strlcat(zc.zc_value, "@", sizeof (zc.zc_value)); + (void) strlcat(zc.zc_value, snapname, sizeof (zc.zc_value)); + } + + err = ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_SPACE_WRITTEN, &zc); + if (err) + return (err); + + *propvalue = zc.zc_cookie; + return (0); +} + +int +zfs_prop_get_written(zfs_handle_t *zhp, const char *propname, + char *propbuf, int proplen, boolean_t literal) +{ + int err; + uint64_t propvalue; + + err = zfs_prop_get_written_int(zhp, propname, &propvalue); + + if (err) + return (err); + + if (literal) { + (void) snprintf(propbuf, proplen, "%llu", propvalue); + } else { + zfs_nicenum(propvalue, propbuf, proplen); + } + return (0); +} + +int +zfs_get_snapused_int(zfs_handle_t *firstsnap, zfs_handle_t *lastsnap, + uint64_t *usedp) +{ + int err; + zfs_cmd_t zc = { 0 }; + + (void) strlcpy(zc.zc_name, lastsnap->zfs_name, sizeof (zc.zc_name)); + (void) strlcpy(zc.zc_value, firstsnap->zfs_name, sizeof (zc.zc_value)); + + err = ioctl(lastsnap->zfs_hdl->libzfs_fd, ZFS_IOC_SPACE_SNAPS, &zc); + if (err) + return (err); + + *usedp = zc.zc_cookie; + + return (0); +} + /* * Returns the name of the given zfs handle. */ @@ -2455,128 +2698,6 @@ zfs_get_type(const zfs_handle_t *zhp) return (zhp->zfs_type); } -static int -zfs_do_list_ioctl(zfs_handle_t *zhp, unsigned long arg, zfs_cmd_t *zc) -{ - int rc; - uint64_t orig_cookie; - - orig_cookie = zc->zc_cookie; -top: - (void) strlcpy(zc->zc_name, zhp->zfs_name, sizeof (zc->zc_name)); - rc = ioctl(zhp->zfs_hdl->libzfs_fd, arg, zc); - - if (rc == -1) { - switch (errno) { - case ENOMEM: - /* expand nvlist memory and try again */ - if (zcmd_expand_dst_nvlist(zhp->zfs_hdl, zc) != 0) { - zcmd_free_nvlists(zc); - return (-1); - } - zc->zc_cookie = orig_cookie; - goto top; - /* - * An errno value of ESRCH indicates normal completion. - * If ENOENT is returned, then the underlying dataset - * has been removed since we obtained the handle. - */ - case ESRCH: - case ENOENT: - rc = 1; - break; - default: - rc = zfs_standard_error(zhp->zfs_hdl, errno, - dgettext(TEXT_DOMAIN, - "cannot iterate filesystems")); - break; - } - } - return (rc); -} - -/* - * Iterate over all child filesystems - */ -int -zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data) -{ - zfs_cmd_t zc = { 0 }; - zfs_handle_t *nzhp; - int ret; - - if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM) - return (0); - - if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0) - return (-1); - - while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_DATASET_LIST_NEXT, - &zc)) == 0) { - /* - * Silently ignore errors, as the only plausible explanation is - * that the pool has since been removed. - */ - if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl, - &zc)) == NULL) { - continue; - } - - if ((ret = func(nzhp, data)) != 0) { - zcmd_free_nvlists(&zc); - return (ret); - } - } - zcmd_free_nvlists(&zc); - return ((ret < 0) ? ret : 0); -} - -/* - * Iterate over all snapshots - */ -int -zfs_iter_snapshots(zfs_handle_t *zhp, zfs_iter_f func, void *data) -{ - zfs_cmd_t zc = { 0 }; - zfs_handle_t *nzhp; - int ret; - - if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) - return (0); - - if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0) - return (-1); - while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_SNAPSHOT_LIST_NEXT, - &zc)) == 0) { - - if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl, - &zc)) == NULL) { - continue; - } - - if ((ret = func(nzhp, data)) != 0) { - zcmd_free_nvlists(&zc); - return (ret); - } - } - zcmd_free_nvlists(&zc); - return ((ret < 0) ? ret : 0); -} - -/* - * Iterate over all children, snapshots and filesystems - */ -int -zfs_iter_children(zfs_handle_t *zhp, zfs_iter_f func, void *data) -{ - int ret; - - if ((ret = zfs_iter_filesystems(zhp, func, data)) != 0) - return (ret); - - return (zfs_iter_snapshots(zhp, func, data)); -} - /* * Is one dataset name a child dataset of another? * @@ -2600,18 +2721,19 @@ is_descendant(const char *ds1, const char *ds2) /* * Given a complete name, return just the portion that refers to the parent. - * Can return NULL if this is a pool. + * Will return -1 if there is no parent (path is just the name of the + * pool). */ static int parent_name(const char *path, char *buf, size_t buflen) { - char *loc; + char *slashp; - if ((loc = strrchr(path, '/')) == NULL) + (void) strlcpy(buf, path, buflen); + + if ((slashp = strrchr(buf, '/')) == NULL) return (-1); - - (void) strncpy(buf, path, MIN(buflen, loc - path)); - buf[loc - path] = '\0'; + *slashp = '\0'; return (0); } @@ -3010,9 +3132,8 @@ zfs_destroy(zfs_handle_t *zhp, boolean_t defer) } struct destroydata { - char *snapname; - boolean_t gotone; - boolean_t closezhp; + nvlist_t *nvl; + const char *snapname; }; static int @@ -3021,24 +3142,19 @@ zfs_check_snap_cb(zfs_handle_t *zhp, void *arg) struct destroydata *dd = arg; zfs_handle_t *szhp; char name[ZFS_MAXNAMELEN]; - boolean_t closezhp = dd->closezhp; int rv = 0; - (void) strlcpy(name, zhp->zfs_name, sizeof (name)); - (void) strlcat(name, "@", sizeof (name)); - (void) strlcat(name, dd->snapname, sizeof (name)); + (void) snprintf(name, sizeof (name), + "%s@%s", zhp->zfs_name, dd->snapname); szhp = make_dataset_handle(zhp->zfs_hdl, name); if (szhp) { - dd->gotone = B_TRUE; + verify(nvlist_add_boolean(dd->nvl, name) == 0); zfs_close(szhp); } - dd->closezhp = B_TRUE; - if (!dd->gotone) - rv = zfs_iter_filesystems(zhp, zfs_check_snap_cb, arg); - if (closezhp) - zfs_close(zhp); + rv = zfs_iter_filesystems(zhp, zfs_check_snap_cb, dd); + zfs_close(zhp); return (rv); } @@ -3048,29 +3164,45 @@ zfs_check_snap_cb(zfs_handle_t *zhp, void *arg) int zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer) { - zfs_cmd_t zc = { 0 }; int ret; struct destroydata dd = { 0 }; dd.snapname = snapname; - (void) zfs_check_snap_cb(zhp, &dd); + verify(nvlist_alloc(&dd.nvl, NV_UNIQUE_NAME, 0) == 0); + (void) zfs_check_snap_cb(zfs_handle_dup(zhp), &dd); - if (!dd.gotone) { - return (zfs_standard_error_fmt(zhp->zfs_hdl, ENOENT, + if (nvlist_next_nvpair(dd.nvl, NULL) == NULL) { + ret = zfs_standard_error_fmt(zhp->zfs_hdl, ENOENT, dgettext(TEXT_DOMAIN, "cannot destroy '%s@%s'"), - zhp->zfs_name, snapname)); + zhp->zfs_name, snapname); + } else { + ret = zfs_destroy_snaps_nvl(zhp, dd.nvl, defer); } + nvlist_free(dd.nvl); + return (ret); +} + +/* + * Destroys all the snapshots named in the nvlist. They must be underneath + * the zhp (either snapshots of it, or snapshots of its descendants). + */ +int +zfs_destroy_snaps_nvl(zfs_handle_t *zhp, nvlist_t *snaps, boolean_t defer) +{ + int ret; + zfs_cmd_t zc = { 0 }; (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); - (void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value)); + if (zcmd_write_src_nvlist(zhp->zfs_hdl, &zc, snaps) != 0) + return (-1); zc.zc_defer_destroy = defer; - ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY_SNAPS, &zc); + ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY_SNAPS_NVL, &zc); if (ret != 0) { char errbuf[1024]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, - "cannot destroy '%s@%s'"), zc.zc_name, snapname); + "cannot destroy snapshots in %s"), zc.zc_name); switch (errno) { case EEXIST: @@ -3106,7 +3238,7 @@ zfs_clone(zfs_handle_t *zhp, const char *target, nvlist_t *props) (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot create '%s'"), target); - /* validate the target name */ + /* validate the target/clone name */ if (!zfs_validate_name(hdl, target, ZFS_TYPE_FILESYSTEM, B_TRUE)) return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); @@ -3442,42 +3574,6 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force) return (err); } -/* - * Iterate over all dependents for a given dataset. This includes both - * hierarchical dependents (children) and data dependents (snapshots and - * clones). The bulk of the processing occurs in get_dependents() in - * libzfs_graph.c. - */ -int -zfs_iter_dependents(zfs_handle_t *zhp, boolean_t allowrecursion, - zfs_iter_f func, void *data) -{ - char **dependents; - size_t count; - int i; - zfs_handle_t *child; - int ret = 0; - - if (get_dependents(zhp->zfs_hdl, allowrecursion, zhp->zfs_name, - &dependents, &count) != 0) - return (-1); - - for (i = 0; i < count; i++) { - if ((child = make_dataset_handle(zhp->zfs_hdl, - dependents[i])) == NULL) - continue; - - if ((ret = func(child, data)) != 0) - break; - } - - for (i = 0; i < count; i++) - free(dependents[i]); - free(dependents); - - return (ret); -} - /* * Renames the given dataset. */ @@ -3947,7 +4043,7 @@ zfs_userspace(zfs_handle_t *zhp, zfs_userquota_prop_t type, int error; zfs_useracct_t buf[100]; - (void) strncpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); + (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); zc.zc_objset_type = type; zc.zc_nvlist_dst = (uintptr_t)buf; diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_graph.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_graph.c deleted file mode 100644 index bc21c51ae26c..000000000000 --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_graph.c +++ /dev/null @@ -1,653 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Iterate over all children of the current object. This includes the normal - * dataset hierarchy, but also arbitrary hierarchies due to clones. We want to - * walk all datasets in the pool, and construct a directed graph of the form: - * - * home - * | - * +----+----+ - * | | - * v v ws - * bar baz | - * | | - * v v - * @yesterday ----> foo - * - * In order to construct this graph, we have to walk every dataset in the pool, - * because the clone parent is stored as a property of the child, not the - * parent. The parent only keeps track of the number of clones. - * - * In the normal case (without clones) this would be rather expensive. To avoid - * unnecessary computation, we first try a walk of the subtree hierarchy - * starting from the initial node. At each dataset, we construct a node in the - * graph and an edge leading from its parent. If we don't see any snapshots - * with a non-zero clone count, then we are finished. - * - * If we do find a cloned snapshot, then we finish the walk of the current - * subtree, but indicate that we need to do a complete walk. We then perform a - * global walk of all datasets, avoiding the subtree we already processed. - * - * At the end of this, we'll end up with a directed graph of all relevant (and - * possible some irrelevant) datasets in the system. We need to both find our - * limiting subgraph and determine a safe ordering in which to destroy the - * datasets. We do a topological ordering of our graph starting at our target - * dataset, and then walk the results in reverse. - * - * It's possible for the graph to have cycles if, for example, the user renames - * a clone to be the parent of its origin snapshot. The user can request to - * generate an error in this case, or ignore the cycle and continue. - * - * When removing datasets, we want to destroy the snapshots in chronological - * order (because this is the most efficient method). In order to accomplish - * this, we store the creation transaction group with each vertex and keep each - * vertex's edges sorted according to this value. The topological sort will - * automatically walk the snapshots in the correct order. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "libzfs_impl.h" -#include "zfs_namecheck.h" - -#define MIN_EDGECOUNT 4 - -/* - * Vertex structure. Indexed by dataset name, this structure maintains a list - * of edges to other vertices. - */ -struct zfs_edge; -typedef struct zfs_vertex { - char zv_dataset[ZFS_MAXNAMELEN]; - struct zfs_vertex *zv_next; - int zv_visited; - uint64_t zv_txg; - struct zfs_edge **zv_edges; - int zv_edgecount; - int zv_edgealloc; -} zfs_vertex_t; - -enum { - VISIT_SEEN = 1, - VISIT_SORT_PRE, - VISIT_SORT_POST -}; - -/* - * Edge structure. Simply maintains a pointer to the destination vertex. There - * is no need to store the source vertex, since we only use edges in the context - * of the source vertex. - */ -typedef struct zfs_edge { - zfs_vertex_t *ze_dest; - struct zfs_edge *ze_next; -} zfs_edge_t; - -#define ZFS_GRAPH_SIZE 1027 /* this could be dynamic some day */ - -/* - * Graph structure. Vertices are maintained in a hash indexed by dataset name. - */ -typedef struct zfs_graph { - zfs_vertex_t **zg_hash; - size_t zg_size; - size_t zg_nvertex; - const char *zg_root; - int zg_clone_count; -} zfs_graph_t; - -/* - * Allocate a new edge pointing to the target vertex. - */ -static zfs_edge_t * -zfs_edge_create(libzfs_handle_t *hdl, zfs_vertex_t *dest) -{ - zfs_edge_t *zep = zfs_alloc(hdl, sizeof (zfs_edge_t)); - - if (zep == NULL) - return (NULL); - - zep->ze_dest = dest; - - return (zep); -} - -/* - * Destroy an edge. - */ -static void -zfs_edge_destroy(zfs_edge_t *zep) -{ - free(zep); -} - -/* - * Allocate a new vertex with the given name. - */ -static zfs_vertex_t * -zfs_vertex_create(libzfs_handle_t *hdl, const char *dataset) -{ - zfs_vertex_t *zvp = zfs_alloc(hdl, sizeof (zfs_vertex_t)); - - if (zvp == NULL) - return (NULL); - - assert(strlen(dataset) < ZFS_MAXNAMELEN); - - (void) strlcpy(zvp->zv_dataset, dataset, sizeof (zvp->zv_dataset)); - - if ((zvp->zv_edges = zfs_alloc(hdl, - MIN_EDGECOUNT * sizeof (void *))) == NULL) { - free(zvp); - return (NULL); - } - - zvp->zv_edgealloc = MIN_EDGECOUNT; - - return (zvp); -} - -/* - * Destroy a vertex. Frees up any associated edges. - */ -static void -zfs_vertex_destroy(zfs_vertex_t *zvp) -{ - int i; - - for (i = 0; i < zvp->zv_edgecount; i++) - zfs_edge_destroy(zvp->zv_edges[i]); - - free(zvp->zv_edges); - free(zvp); -} - -/* - * Given a vertex, add an edge to the destination vertex. - */ -static int -zfs_vertex_add_edge(libzfs_handle_t *hdl, zfs_vertex_t *zvp, - zfs_vertex_t *dest) -{ - zfs_edge_t *zep = zfs_edge_create(hdl, dest); - - if (zep == NULL) - return (-1); - - if (zvp->zv_edgecount == zvp->zv_edgealloc) { - void *ptr; - - if ((ptr = zfs_realloc(hdl, zvp->zv_edges, - zvp->zv_edgealloc * sizeof (void *), - zvp->zv_edgealloc * 2 * sizeof (void *))) == NULL) - return (-1); - - zvp->zv_edges = ptr; - zvp->zv_edgealloc *= 2; - } - - zvp->zv_edges[zvp->zv_edgecount++] = zep; - - return (0); -} - -static int -zfs_edge_compare(const void *a, const void *b) -{ - const zfs_edge_t *ea = *((zfs_edge_t **)a); - const zfs_edge_t *eb = *((zfs_edge_t **)b); - - if (ea->ze_dest->zv_txg < eb->ze_dest->zv_txg) - return (-1); - if (ea->ze_dest->zv_txg > eb->ze_dest->zv_txg) - return (1); - return (0); -} - -/* - * Sort the given vertex edges according to the creation txg of each vertex. - */ -static void -zfs_vertex_sort_edges(zfs_vertex_t *zvp) -{ - if (zvp->zv_edgecount == 0) - return; - - qsort(zvp->zv_edges, zvp->zv_edgecount, sizeof (void *), - zfs_edge_compare); -} - -/* - * Construct a new graph object. We allow the size to be specified as a - * parameter so in the future we can size the hash according to the number of - * datasets in the pool. - */ -static zfs_graph_t * -zfs_graph_create(libzfs_handle_t *hdl, const char *dataset, size_t size) -{ - zfs_graph_t *zgp = zfs_alloc(hdl, sizeof (zfs_graph_t)); - - if (zgp == NULL) - return (NULL); - - zgp->zg_size = size; - if ((zgp->zg_hash = zfs_alloc(hdl, - size * sizeof (zfs_vertex_t *))) == NULL) { - free(zgp); - return (NULL); - } - - zgp->zg_root = dataset; - zgp->zg_clone_count = 0; - - return (zgp); -} - -/* - * Destroy a graph object. We have to iterate over all the hash chains, - * destroying each vertex in the process. - */ -static void -zfs_graph_destroy(zfs_graph_t *zgp) -{ - int i; - zfs_vertex_t *current, *next; - - for (i = 0; i < zgp->zg_size; i++) { - current = zgp->zg_hash[i]; - while (current != NULL) { - next = current->zv_next; - zfs_vertex_destroy(current); - current = next; - } - } - - free(zgp->zg_hash); - free(zgp); -} - -/* - * Graph hash function. Classic bernstein k=33 hash function, taken from - * usr/src/cmd/sgs/tools/common/strhash.c - */ -static size_t -zfs_graph_hash(zfs_graph_t *zgp, const char *str) -{ - size_t hash = 5381; - int c; - - while ((c = *str++) != 0) - hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ - - return (hash % zgp->zg_size); -} - -/* - * Given a dataset name, finds the associated vertex, creating it if necessary. - */ -static zfs_vertex_t * -zfs_graph_lookup(libzfs_handle_t *hdl, zfs_graph_t *zgp, const char *dataset, - uint64_t txg) -{ - size_t idx = zfs_graph_hash(zgp, dataset); - zfs_vertex_t *zvp; - - for (zvp = zgp->zg_hash[idx]; zvp != NULL; zvp = zvp->zv_next) { - if (strcmp(zvp->zv_dataset, dataset) == 0) { - if (zvp->zv_txg == 0) - zvp->zv_txg = txg; - return (zvp); - } - } - - if ((zvp = zfs_vertex_create(hdl, dataset)) == NULL) - return (NULL); - - zvp->zv_next = zgp->zg_hash[idx]; - zvp->zv_txg = txg; - zgp->zg_hash[idx] = zvp; - zgp->zg_nvertex++; - - return (zvp); -} - -/* - * Given two dataset names, create an edge between them. For the source vertex, - * mark 'zv_visited' to indicate that we have seen this vertex, and not simply - * created it as a destination of another edge. If 'dest' is NULL, then this - * is an individual vertex (i.e. the starting vertex), so don't add an edge. - */ -static int -zfs_graph_add(libzfs_handle_t *hdl, zfs_graph_t *zgp, const char *source, - const char *dest, uint64_t txg) -{ - zfs_vertex_t *svp, *dvp; - - if ((svp = zfs_graph_lookup(hdl, zgp, source, 0)) == NULL) - return (-1); - svp->zv_visited = VISIT_SEEN; - if (dest != NULL) { - dvp = zfs_graph_lookup(hdl, zgp, dest, txg); - if (dvp == NULL) - return (-1); - if (zfs_vertex_add_edge(hdl, svp, dvp) != 0) - return (-1); - } - - return (0); -} - -/* - * Iterate over all children of the given dataset, adding any vertices - * as necessary. Returns -1 if there was an error, or 0 otherwise. - * This is a simple recursive algorithm - the ZFS namespace typically - * is very flat. We manually invoke the necessary ioctl() calls to - * avoid the overhead and additional semantics of zfs_open(). - */ -static int -iterate_children(libzfs_handle_t *hdl, zfs_graph_t *zgp, const char *dataset) -{ - zfs_cmd_t zc = { 0 }; - zfs_vertex_t *zvp; - - /* - * Look up the source vertex, and avoid it if we've seen it before. - */ - zvp = zfs_graph_lookup(hdl, zgp, dataset, 0); - if (zvp == NULL) - return (-1); - if (zvp->zv_visited == VISIT_SEEN) - return (0); - - /* - * Iterate over all children - */ - for ((void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); - ioctl(hdl->libzfs_fd, ZFS_IOC_DATASET_LIST_NEXT, &zc) == 0; - (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name))) { - /* - * Get statistics for this dataset, to determine the type of the - * dataset and clone statistics. If this fails, the dataset has - * since been removed, and we're pretty much screwed anyway. - */ - zc.zc_objset_stats.dds_origin[0] = '\0'; - if (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0) - continue; - - if (zc.zc_objset_stats.dds_origin[0] != '\0') { - if (zfs_graph_add(hdl, zgp, - zc.zc_objset_stats.dds_origin, zc.zc_name, - zc.zc_objset_stats.dds_creation_txg) != 0) - return (-1); - /* - * Count origins only if they are contained in the graph - */ - if (isa_child_of(zc.zc_objset_stats.dds_origin, - zgp->zg_root)) - zgp->zg_clone_count--; - } - - /* - * Add an edge between the parent and the child. - */ - if (zfs_graph_add(hdl, zgp, dataset, zc.zc_name, - zc.zc_objset_stats.dds_creation_txg) != 0) - return (-1); - - /* - * Recursively visit child - */ - if (iterate_children(hdl, zgp, zc.zc_name)) - return (-1); - } - - /* - * Now iterate over all snapshots. - */ - bzero(&zc, sizeof (zc)); - - for ((void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); - ioctl(hdl->libzfs_fd, ZFS_IOC_SNAPSHOT_LIST_NEXT, &zc) == 0; - (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name))) { - - /* - * Get statistics for this dataset, to determine the type of the - * dataset and clone statistics. If this fails, the dataset has - * since been removed, and we're pretty much screwed anyway. - */ - if (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0) - continue; - - /* - * Add an edge between the parent and the child. - */ - if (zfs_graph_add(hdl, zgp, dataset, zc.zc_name, - zc.zc_objset_stats.dds_creation_txg) != 0) - return (-1); - - zgp->zg_clone_count += zc.zc_objset_stats.dds_num_clones; - } - - zvp->zv_visited = VISIT_SEEN; - - return (0); -} - -/* - * Returns false if there are no snapshots with dependent clones in this - * subtree or if all of those clones are also in this subtree. Returns - * true if there is an error or there are external dependents. - */ -static boolean_t -external_dependents(libzfs_handle_t *hdl, zfs_graph_t *zgp, const char *dataset) -{ - zfs_cmd_t zc = { 0 }; - - /* - * Check whether this dataset is a clone or has clones since - * iterate_children() only checks the children. - */ - (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); - if (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0) - return (B_TRUE); - - if (zc.zc_objset_stats.dds_origin[0] != '\0') { - if (zfs_graph_add(hdl, zgp, - zc.zc_objset_stats.dds_origin, zc.zc_name, - zc.zc_objset_stats.dds_creation_txg) != 0) - return (B_TRUE); - if (isa_child_of(zc.zc_objset_stats.dds_origin, dataset)) - zgp->zg_clone_count--; - } - - if ((zc.zc_objset_stats.dds_num_clones) || - iterate_children(hdl, zgp, dataset)) - return (B_TRUE); - - return (zgp->zg_clone_count != 0); -} - -/* - * Construct a complete graph of all necessary vertices. First, iterate over - * only our object's children. If no cloned snapshots are found, or all of - * the cloned snapshots are in this subtree then return a graph of the subtree. - * Otherwise, start at the root of the pool and iterate over all datasets. - */ -static zfs_graph_t * -construct_graph(libzfs_handle_t *hdl, const char *dataset) -{ - zfs_graph_t *zgp = zfs_graph_create(hdl, dataset, ZFS_GRAPH_SIZE); - int ret = 0; - - if (zgp == NULL) - return (zgp); - - if ((strchr(dataset, '/') == NULL) || - (external_dependents(hdl, zgp, dataset))) { - /* - * Determine pool name and try again. - */ - int len = strcspn(dataset, "/@") + 1; - char *pool = zfs_alloc(hdl, len); - - if (pool == NULL) { - zfs_graph_destroy(zgp); - return (NULL); - } - (void) strlcpy(pool, dataset, len); - - if (iterate_children(hdl, zgp, pool) == -1 || - zfs_graph_add(hdl, zgp, pool, NULL, 0) != 0) { - free(pool); - zfs_graph_destroy(zgp); - return (NULL); - } - free(pool); - } - - if (ret == -1 || zfs_graph_add(hdl, zgp, dataset, NULL, 0) != 0) { - zfs_graph_destroy(zgp); - return (NULL); - } - - return (zgp); -} - -/* - * Given a graph, do a recursive topological sort into the given array. This is - * really just a depth first search, so that the deepest nodes appear first. - * hijack the 'zv_visited' marker to avoid visiting the same vertex twice. - */ -static int -topo_sort(libzfs_handle_t *hdl, boolean_t allowrecursion, char **result, - size_t *idx, zfs_vertex_t *zgv) -{ - int i; - - if (zgv->zv_visited == VISIT_SORT_PRE && !allowrecursion) { - /* - * If we've already seen this vertex as part of our depth-first - * search, then we have a cyclic dependency, and we must return - * an error. - */ - zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, - "recursive dependency at '%s'"), - zgv->zv_dataset); - return (zfs_error(hdl, EZFS_RECURSIVE, - dgettext(TEXT_DOMAIN, - "cannot determine dependent datasets"))); - } else if (zgv->zv_visited >= VISIT_SORT_PRE) { - /* - * If we've already processed this as part of the topological - * sort, then don't bother doing so again. - */ - return (0); - } - - zgv->zv_visited = VISIT_SORT_PRE; - - /* avoid doing a search if we don't have to */ - zfs_vertex_sort_edges(zgv); - for (i = 0; i < zgv->zv_edgecount; i++) { - if (topo_sort(hdl, allowrecursion, result, idx, - zgv->zv_edges[i]->ze_dest) != 0) - return (-1); - } - - /* we may have visited this in the course of the above */ - if (zgv->zv_visited == VISIT_SORT_POST) - return (0); - - if ((result[*idx] = zfs_alloc(hdl, - strlen(zgv->zv_dataset) + 1)) == NULL) - return (-1); - - (void) strcpy(result[*idx], zgv->zv_dataset); - *idx += 1; - zgv->zv_visited = VISIT_SORT_POST; - return (0); -} - -/* - * The only public interface for this file. Do the dirty work of constructing a - * child list for the given object. Construct the graph, do the toplogical - * sort, and then return the array of strings to the caller. - * - * The 'allowrecursion' parameter controls behavior when cycles are found. If - * it is set, the the cycle is ignored and the results returned as if the cycle - * did not exist. If it is not set, then the routine will generate an error if - * a cycle is found. - */ -int -get_dependents(libzfs_handle_t *hdl, boolean_t allowrecursion, - const char *dataset, char ***result, size_t *count) -{ - zfs_graph_t *zgp; - zfs_vertex_t *zvp; - - if ((zgp = construct_graph(hdl, dataset)) == NULL) - return (-1); - - if ((*result = zfs_alloc(hdl, - zgp->zg_nvertex * sizeof (char *))) == NULL) { - zfs_graph_destroy(zgp); - return (-1); - } - - if ((zvp = zfs_graph_lookup(hdl, zgp, dataset, 0)) == NULL) { - free(*result); - zfs_graph_destroy(zgp); - return (-1); - } - - *count = 0; - if (topo_sort(hdl, allowrecursion, *result, count, zvp) != 0) { - free(*result); - zfs_graph_destroy(zgp); - return (-1); - } - - /* - * Get rid of the last entry, which is our starting vertex and not - * strictly a dependent. - */ - assert(*count > 0); - free((*result)[*count - 1]); - (*count)--; - - zfs_graph_destroy(zgp); - - return (0); -} diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h index 9cd1ed38c924..48a8edb6adbc 100644 --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h @@ -23,6 +23,7 @@ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011 Pawel Jakub Dawidek . * All rights reserved. + * Copyright (c) 2011 by Delphix. All rights reserved. */ #ifndef _LIBFS_IMPL_H @@ -116,7 +117,7 @@ struct zpool_handle { diskaddr_t zpool_start_block; }; -typedef enum { +typedef enum { PROTO_NFS = 0, PROTO_SMB = 1, PROTO_END = 2 @@ -148,6 +149,7 @@ int zpool_standard_error_fmt(libzfs_handle_t *, int, const char *, ...); int get_dependents(libzfs_handle_t *, boolean_t, const char *, char ***, size_t *); +zfs_handle_t *make_dataset_handle_zc(libzfs_handle_t *, zfs_cmd_t *); int zprop_parse_value(libzfs_handle_t *, nvpair_t *, int, zfs_type_t, diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c index cafb981d1856..6f579c5ab122 100644 --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c @@ -20,6 +20,8 @@ */ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2011 Nexenta Systems, Inc. All rights reserved. + * Copyright (c) 2011 by Delphix. All rights reserved. */ /* @@ -435,7 +437,7 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl, boolean_t active_ok) uint_t i, nspares, nl2cache; boolean_t config_seen; uint64_t best_txg; - char *name, *hostname; + char *name, *hostname, *comment; uint64_t version, guid; uint_t children = 0; nvlist_t **child = NULL; @@ -524,6 +526,7 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl, boolean_t active_ok) * version * pool guid * name + * comment (if available) * pool state * hostid (if available) * hostname (if available) @@ -545,11 +548,24 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl, boolean_t active_ok) if (nvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, name) != 0) goto nomem; + + /* + * COMMENT is optional, don't bail if it's not + * there, instead, set it to NULL. + */ + if (nvlist_lookup_string(tmp, + ZPOOL_CONFIG_COMMENT, &comment) != 0) + comment = NULL; + else if (nvlist_add_string(config, + ZPOOL_CONFIG_COMMENT, comment) != 0) + goto nomem; + verify(nvlist_lookup_uint64(tmp, ZPOOL_CONFIG_POOL_STATE, &state) == 0); if (nvlist_add_uint64(config, ZPOOL_CONFIG_POOL_STATE, state) != 0) goto nomem; + hostid = 0; if (nvlist_lookup_uint64(tmp, ZPOOL_CONFIG_HOSTID, &hostid) == 0) { diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_iter.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_iter.c new file mode 100644 index 000000000000..a3e1b9fa1b01 --- /dev/null +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_iter.c @@ -0,0 +1,462 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2010 Nexenta Systems, Inc. All rights reserved. + * Copyright (c) 2011 by Delphix. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "libzfs_impl.h" + +int +zfs_iter_clones(zfs_handle_t *zhp, zfs_iter_f func, void *data) +{ + nvlist_t *nvl = zfs_get_clones_nvl(zhp); + nvpair_t *pair; + + if (nvl == NULL) + return (0); + + for (pair = nvlist_next_nvpair(nvl, NULL); pair != NULL; + pair = nvlist_next_nvpair(nvl, pair)) { + zfs_handle_t *clone = zfs_open(zhp->zfs_hdl, nvpair_name(pair), + ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); + if (clone != NULL) { + int err = func(clone, data); + if (err != 0) + return (err); + } + } + return (0); +} + +static int +zfs_do_list_ioctl(zfs_handle_t *zhp, unsigned long arg, zfs_cmd_t *zc) +{ + int rc; + uint64_t orig_cookie; + + orig_cookie = zc->zc_cookie; +top: + (void) strlcpy(zc->zc_name, zhp->zfs_name, sizeof (zc->zc_name)); + rc = ioctl(zhp->zfs_hdl->libzfs_fd, arg, zc); + + if (rc == -1) { + switch (errno) { + case ENOMEM: + /* expand nvlist memory and try again */ + if (zcmd_expand_dst_nvlist(zhp->zfs_hdl, zc) != 0) { + zcmd_free_nvlists(zc); + return (-1); + } + zc->zc_cookie = orig_cookie; + goto top; + /* + * An errno value of ESRCH indicates normal completion. + * If ENOENT is returned, then the underlying dataset + * has been removed since we obtained the handle. + */ + case ESRCH: + case ENOENT: + rc = 1; + break; + default: + rc = zfs_standard_error(zhp->zfs_hdl, errno, + dgettext(TEXT_DOMAIN, + "cannot iterate filesystems")); + break; + } + } + return (rc); +} + +/* + * Iterate over all child filesystems + */ +int +zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data) +{ + zfs_cmd_t zc = { 0 }; + zfs_handle_t *nzhp; + int ret; + + if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM) + return (0); + + if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0) + return (-1); + + while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_DATASET_LIST_NEXT, + &zc)) == 0) { + /* + * Silently ignore errors, as the only plausible explanation is + * that the pool has since been removed. + */ + if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl, + &zc)) == NULL) { + continue; + } + + if ((ret = func(nzhp, data)) != 0) { + zcmd_free_nvlists(&zc); + return (ret); + } + } + zcmd_free_nvlists(&zc); + return ((ret < 0) ? ret : 0); +} + +/* + * Iterate over all snapshots + */ +int +zfs_iter_snapshots(zfs_handle_t *zhp, zfs_iter_f func, void *data) +{ + zfs_cmd_t zc = { 0 }; + zfs_handle_t *nzhp; + int ret; + + if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) + return (0); + + if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0) + return (-1); + while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_SNAPSHOT_LIST_NEXT, + &zc)) == 0) { + + if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl, + &zc)) == NULL) { + continue; + } + + if ((ret = func(nzhp, data)) != 0) { + zcmd_free_nvlists(&zc); + return (ret); + } + } + zcmd_free_nvlists(&zc); + return ((ret < 0) ? ret : 0); +} + +/* + * Routines for dealing with the sorted snapshot functionality + */ +typedef struct zfs_node { + zfs_handle_t *zn_handle; + avl_node_t zn_avlnode; +} zfs_node_t; + +static int +zfs_sort_snaps(zfs_handle_t *zhp, void *data) +{ + avl_tree_t *avl = data; + zfs_node_t *node; + zfs_node_t search; + + search.zn_handle = zhp; + node = avl_find(avl, &search, NULL); + if (node) { + /* + * If this snapshot was renamed while we were creating the + * AVL tree, it's possible that we already inserted it under + * its old name. Remove the old handle before adding the new + * one. + */ + zfs_close(node->zn_handle); + avl_remove(avl, node); + free(node); + } + + node = zfs_alloc(zhp->zfs_hdl, sizeof (zfs_node_t)); + node->zn_handle = zhp; + avl_add(avl, node); + + return (0); +} + +static int +zfs_snapshot_compare(const void *larg, const void *rarg) +{ + zfs_handle_t *l = ((zfs_node_t *)larg)->zn_handle; + zfs_handle_t *r = ((zfs_node_t *)rarg)->zn_handle; + uint64_t lcreate, rcreate; + + /* + * Sort them according to creation time. We use the hidden + * CREATETXG property to get an absolute ordering of snapshots. + */ + lcreate = zfs_prop_get_int(l, ZFS_PROP_CREATETXG); + rcreate = zfs_prop_get_int(r, ZFS_PROP_CREATETXG); + + if (lcreate < rcreate) + return (-1); + else if (lcreate > rcreate) + return (+1); + else + return (0); +} + +int +zfs_iter_snapshots_sorted(zfs_handle_t *zhp, zfs_iter_f callback, void *data) +{ + int ret = 0; + zfs_node_t *node; + avl_tree_t avl; + void *cookie = NULL; + + avl_create(&avl, zfs_snapshot_compare, + sizeof (zfs_node_t), offsetof(zfs_node_t, zn_avlnode)); + + ret = zfs_iter_snapshots(zhp, zfs_sort_snaps, &avl); + + for (node = avl_first(&avl); node != NULL; node = AVL_NEXT(&avl, node)) + ret |= callback(node->zn_handle, data); + + while ((node = avl_destroy_nodes(&avl, &cookie)) != NULL) + free(node); + + avl_destroy(&avl); + + return (ret); +} + +typedef struct { + char *ssa_first; + char *ssa_last; + boolean_t ssa_seenfirst; + boolean_t ssa_seenlast; + zfs_iter_f ssa_func; + void *ssa_arg; +} snapspec_arg_t; + +static int +snapspec_cb(zfs_handle_t *zhp, void *arg) { + snapspec_arg_t *ssa = arg; + char *shortsnapname; + int err = 0; + + if (ssa->ssa_seenlast) + return (0); + shortsnapname = zfs_strdup(zhp->zfs_hdl, + strchr(zfs_get_name(zhp), '@') + 1); + + if (!ssa->ssa_seenfirst && strcmp(shortsnapname, ssa->ssa_first) == 0) + ssa->ssa_seenfirst = B_TRUE; + + if (ssa->ssa_seenfirst) { + err = ssa->ssa_func(zhp, ssa->ssa_arg); + } else { + zfs_close(zhp); + } + + if (strcmp(shortsnapname, ssa->ssa_last) == 0) + ssa->ssa_seenlast = B_TRUE; + free(shortsnapname); + + return (err); +} + +/* + * spec is a string like "A,B%C,D" + * + * , where can be: + * (single snapshot) + * % (range of snapshots, inclusive) + * % (range of snapshots, starting with earliest) + * % (range of snapshots, ending with last) + * % (all snapshots) + * [,...] (comma separated list of the above) + * + * If a snapshot can not be opened, continue trying to open the others, but + * return ENOENT at the end. + */ +int +zfs_iter_snapspec(zfs_handle_t *fs_zhp, const char *spec_orig, + zfs_iter_f func, void *arg) +{ + char buf[ZFS_MAXNAMELEN]; + char *comma_separated, *cp; + int err = 0; + int ret = 0; + + (void) strlcpy(buf, spec_orig, sizeof (buf)); + cp = buf; + + while ((comma_separated = strsep(&cp, ",")) != NULL) { + char *pct = strchr(comma_separated, '%'); + if (pct != NULL) { + snapspec_arg_t ssa = { 0 }; + ssa.ssa_func = func; + ssa.ssa_arg = arg; + + if (pct == comma_separated) + ssa.ssa_seenfirst = B_TRUE; + else + ssa.ssa_first = comma_separated; + *pct = '\0'; + ssa.ssa_last = pct + 1; + + /* + * If there is a lastname specified, make sure it + * exists. + */ + if (ssa.ssa_last[0] != '\0') { + char snapname[ZFS_MAXNAMELEN]; + (void) snprintf(snapname, sizeof (snapname), + "%s@%s", zfs_get_name(fs_zhp), + ssa.ssa_last); + if (!zfs_dataset_exists(fs_zhp->zfs_hdl, + snapname, ZFS_TYPE_SNAPSHOT)) { + ret = ENOENT; + continue; + } + } + + err = zfs_iter_snapshots_sorted(fs_zhp, + snapspec_cb, &ssa); + if (ret == 0) + ret = err; + if (ret == 0 && (!ssa.ssa_seenfirst || + (ssa.ssa_last[0] != '\0' && !ssa.ssa_seenlast))) { + ret = ENOENT; + } + } else { + char snapname[ZFS_MAXNAMELEN]; + zfs_handle_t *snap_zhp; + (void) snprintf(snapname, sizeof (snapname), "%s@%s", + zfs_get_name(fs_zhp), comma_separated); + snap_zhp = make_dataset_handle(fs_zhp->zfs_hdl, + snapname); + if (snap_zhp == NULL) { + ret = ENOENT; + continue; + } + err = func(snap_zhp, arg); + if (ret == 0) + ret = err; + } + } + + return (ret); +} + +/* + * Iterate over all children, snapshots and filesystems + */ +int +zfs_iter_children(zfs_handle_t *zhp, zfs_iter_f func, void *data) +{ + int ret; + + if ((ret = zfs_iter_filesystems(zhp, func, data)) != 0) + return (ret); + + return (zfs_iter_snapshots(zhp, func, data)); +} + + +typedef struct iter_stack_frame { + struct iter_stack_frame *next; + zfs_handle_t *zhp; +} iter_stack_frame_t; + +typedef struct iter_dependents_arg { + boolean_t first; + boolean_t allowrecursion; + iter_stack_frame_t *stack; + zfs_iter_f func; + void *data; +} iter_dependents_arg_t; + +static int +iter_dependents_cb(zfs_handle_t *zhp, void *arg) +{ + iter_dependents_arg_t *ida = arg; + int err; + boolean_t first = ida->first; + ida->first = B_FALSE; + + if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) { + err = zfs_iter_clones(zhp, iter_dependents_cb, ida); + } else { + iter_stack_frame_t isf; + iter_stack_frame_t *f; + + /* + * check if there is a cycle by seeing if this fs is already + * on the stack. + */ + for (f = ida->stack; f != NULL; f = f->next) { + if (f->zhp->zfs_dmustats.dds_guid == + zhp->zfs_dmustats.dds_guid) { + if (ida->allowrecursion) { + zfs_close(zhp); + return (0); + } else { + zfs_error_aux(zhp->zfs_hdl, + dgettext(TEXT_DOMAIN, + "recursive dependency at '%s'"), + zfs_get_name(zhp)); + err = zfs_error(zhp->zfs_hdl, + EZFS_RECURSIVE, + dgettext(TEXT_DOMAIN, + "cannot determine dependent " + "datasets")); + zfs_close(zhp); + return (err); + } + } + } + + isf.zhp = zhp; + isf.next = ida->stack; + ida->stack = &isf; + err = zfs_iter_filesystems(zhp, iter_dependents_cb, ida); + if (err == 0) + err = zfs_iter_snapshots(zhp, iter_dependents_cb, ida); + ida->stack = isf.next; + } + if (!first && err == 0) + err = ida->func(zhp, ida->data); + return (err); +} + +int +zfs_iter_dependents(zfs_handle_t *zhp, boolean_t allowrecursion, + zfs_iter_f func, void *data) +{ + iter_dependents_arg_t ida; + ida.allowrecursion = allowrecursion; + ida.stack = NULL; + ida.func = func; + ida.data = data; + ida.first = B_TRUE; + return (iter_dependents_cb(zfs_handle_dup(zhp), &ida)); +} diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c index 061daab29e4f..2605768b2ac7 100644 --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c @@ -21,6 +21,8 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2011 Nexenta Systems, Inc. All rights reserved. + * Copyright (c) 2011 by Delphix. All rights reserved. */ #include @@ -261,6 +263,7 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len, case ZPOOL_PROP_ALTROOT: case ZPOOL_PROP_CACHEFILE: + case ZPOOL_PROP_COMMENT: if (zhp->zpool_props != NULL || zpool_get_all_props(zhp) == 0) { (void) strlcpy(buf, @@ -412,7 +415,7 @@ zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname, zpool_prop_t prop; char *strval; uint64_t intval; - char *slash; + char *slash, *check; struct stat64 statbuf; zpool_handle_t *zhp; nvlist_t *nvroot; @@ -573,6 +576,26 @@ zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname, *slash = '/'; break; + case ZPOOL_PROP_COMMENT: + for (check = strval; *check != '\0'; check++) { + if (!isprint(*check)) { + zfs_error_aux(hdl, + dgettext(TEXT_DOMAIN, + "comment may only have printable " + "characters")); + (void) zfs_error(hdl, EZFS_BADPROP, + errbuf); + goto error; + } + } + if (strlen(strval) > ZPROP_MAX_COMMENT) { + zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, + "comment must not exceed %d characters"), + ZPROP_MAX_COMMENT); + (void) zfs_error(hdl, EZFS_BADPROP, errbuf); + goto error; + } + break; case ZPOOL_PROP_READONLY: if (!flags.import) { zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, @@ -3010,6 +3033,26 @@ zpool_vdev_clear(zpool_handle_t *zhp, uint64_t guid) return (zpool_standard_error(hdl, errno, msg)); } +/* + * Change the GUID for a pool. + */ +int +zpool_reguid(zpool_handle_t *zhp) +{ + char msg[1024]; + libzfs_handle_t *hdl = zhp->zpool_hdl; + zfs_cmd_t zc = { 0 }; + + (void) snprintf(msg, sizeof (msg), + dgettext(TEXT_DOMAIN, "cannot reguid '%s'"), zhp->zpool_name); + + (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); + if (zfs_ioctl(hdl, ZFS_IOC_POOL_REGUID, &zc) == 0) + return (0); + + return (zpool_standard_error(hdl, errno, msg)); +} + /* * Convert from a devid string to a path. */ diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c index 9d3c9845078c..b0f034b9eafa 100644 --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c @@ -21,6 +21,7 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011 by Delphix. All rights reserved. */ #include @@ -53,7 +54,7 @@ extern void zfs_setprop_error(libzfs_handle_t *, zfs_prop_t, int, char *); /* We need to use something for ENODATA. */ #define ENODATA EIDRM -static int zfs_receive_impl(libzfs_handle_t *, const char *, recvflags_t, +static int zfs_receive_impl(libzfs_handle_t *, const char *, recvflags_t *, int, const char *, nvlist_t *, avl_tree_t *, char **, int, uint64_t *); static const zio_cksum_t zero_cksum = { 0 }; @@ -773,88 +774,6 @@ gather_nvlist(libzfs_handle_t *hdl, const char *fsname, const char *fromsnap, return (0); } -/* - * Routines for dealing with the sorted snapshot functionality - */ -typedef struct zfs_node { - zfs_handle_t *zn_handle; - avl_node_t zn_avlnode; -} zfs_node_t; - -static int -zfs_sort_snaps(zfs_handle_t *zhp, void *data) -{ - avl_tree_t *avl = data; - zfs_node_t *node; - zfs_node_t search; - - search.zn_handle = zhp; - node = avl_find(avl, &search, NULL); - if (node) { - /* - * If this snapshot was renamed while we were creating the - * AVL tree, it's possible that we already inserted it under - * its old name. Remove the old handle before adding the new - * one. - */ - zfs_close(node->zn_handle); - avl_remove(avl, node); - free(node); - } - - node = zfs_alloc(zhp->zfs_hdl, sizeof (zfs_node_t)); - node->zn_handle = zhp; - avl_add(avl, node); - - return (0); -} - -static int -zfs_snapshot_compare(const void *larg, const void *rarg) -{ - zfs_handle_t *l = ((zfs_node_t *)larg)->zn_handle; - zfs_handle_t *r = ((zfs_node_t *)rarg)->zn_handle; - uint64_t lcreate, rcreate; - - /* - * Sort them according to creation time. We use the hidden - * CREATETXG property to get an absolute ordering of snapshots. - */ - lcreate = zfs_prop_get_int(l, ZFS_PROP_CREATETXG); - rcreate = zfs_prop_get_int(r, ZFS_PROP_CREATETXG); - - if (lcreate < rcreate) - return (-1); - else if (lcreate > rcreate) - return (+1); - else - return (0); -} - -int -zfs_iter_snapshots_sorted(zfs_handle_t *zhp, zfs_iter_f callback, void *data) -{ - int ret = 0; - zfs_node_t *node; - avl_tree_t avl; - void *cookie = NULL; - - avl_create(&avl, zfs_snapshot_compare, - sizeof (zfs_node_t), offsetof(zfs_node_t, zn_avlnode)); - - ret = zfs_iter_snapshots(zhp, zfs_sort_snaps, &avl); - - for (node = avl_first(&avl); node != NULL; node = AVL_NEXT(&avl, node)) - ret |= callback(node->zn_handle, data); - - while ((node = avl_destroy_nodes(&avl, &cookie)) != NULL) - free(node); - - avl_destroy(&avl); - - return (ret); -} - /* * Routines specific to "zfs send" */ @@ -865,7 +784,7 @@ typedef struct send_dump_data { char prevsnap[ZFS_MAXNAMELEN]; uint64_t prevsnap_obj; boolean_t seenfrom, seento, replicate, doall, fromorigin; - boolean_t verbose; + boolean_t verbose, dryrun, parsable; int outfd; boolean_t err; nvlist_t *fss; @@ -875,49 +794,31 @@ typedef struct send_dump_data { nvlist_t *debugnv; char holdtag[ZFS_MAXNAMELEN]; int cleanup_fd; + uint64_t size; } send_dump_data_t; -/* - * Dumps a backup of the given snapshot (incremental from fromsnap if it's not - * NULL) to the file descriptor specified by outfd. - */ static int -dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, uint64_t fromsnap_obj, - boolean_t fromorigin, int outfd, nvlist_t *debugnv) +estimate_ioctl(zfs_handle_t *zhp, uint64_t fromsnap_obj, + boolean_t fromorigin, uint64_t *sizep) { zfs_cmd_t zc = { 0 }; libzfs_handle_t *hdl = zhp->zfs_hdl; - nvlist_t *thisdbg; assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT); assert(fromsnap_obj == 0 || !fromorigin); (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); - zc.zc_cookie = outfd; zc.zc_obj = fromorigin; zc.zc_sendobj = zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID); zc.zc_fromobj = fromsnap_obj; + zc.zc_guid = 1; /* estimate flag */ - VERIFY(0 == nvlist_alloc(&thisdbg, NV_UNIQUE_NAME, 0)); - if (fromsnap && fromsnap[0] != '\0') { - VERIFY(0 == nvlist_add_string(thisdbg, - "fromsnap", fromsnap)); - } - - if (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_SEND, &zc) != 0) { + if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SEND, &zc) != 0) { char errbuf[1024]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, - "warning: cannot send '%s'"), zhp->zfs_name); - - VERIFY(0 == nvlist_add_uint64(thisdbg, "error", errno)); - if (debugnv) { - VERIFY(0 == nvlist_add_nvlist(debugnv, - zhp->zfs_name, thisdbg)); - } - nvlist_free(thisdbg); + "warning: cannot estimate space for '%s'"), zhp->zfs_name); switch (errno) { - case EXDEV: zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "not an earlier snapshot from the same fs")); @@ -950,6 +851,86 @@ dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, uint64_t fromsnap_obj, } } + *sizep = zc.zc_objset_type; + + return (0); +} + +/* + * Dumps a backup of the given snapshot (incremental from fromsnap if it's not + * NULL) to the file descriptor specified by outfd. + */ +static int +dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, uint64_t fromsnap_obj, + boolean_t fromorigin, int outfd, nvlist_t *debugnv) +{ + zfs_cmd_t zc = { 0 }; + libzfs_handle_t *hdl = zhp->zfs_hdl; + nvlist_t *thisdbg; + + assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT); + assert(fromsnap_obj == 0 || !fromorigin); + + (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); + zc.zc_cookie = outfd; + zc.zc_obj = fromorigin; + zc.zc_sendobj = zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID); + zc.zc_fromobj = fromsnap_obj; + + VERIFY(0 == nvlist_alloc(&thisdbg, NV_UNIQUE_NAME, 0)); + if (fromsnap && fromsnap[0] != '\0') { + VERIFY(0 == nvlist_add_string(thisdbg, + "fromsnap", fromsnap)); + } + + if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SEND, &zc) != 0) { + char errbuf[1024]; + (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, + "warning: cannot send '%s'"), zhp->zfs_name); + + VERIFY(0 == nvlist_add_uint64(thisdbg, "error", errno)); + if (debugnv) { + VERIFY(0 == nvlist_add_nvlist(debugnv, + zhp->zfs_name, thisdbg)); + } + nvlist_free(thisdbg); + + switch (errno) { + case EXDEV: + zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, + "not an earlier snapshot from the same fs")); + return (zfs_error(hdl, EZFS_CROSSTARGET, errbuf)); + + case ENOENT: + if (zfs_dataset_exists(hdl, zc.zc_name, + ZFS_TYPE_SNAPSHOT)) { + zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, + "incremental source (@%s) does not exist"), + zc.zc_value); + } + return (zfs_error(hdl, EZFS_NOENT, errbuf)); + + case EDQUOT: + case EFBIG: + case EIO: + case ENOLINK: + case ENOSPC: +#ifdef sun + case ENOSTR: +#endif + case ENXIO: + case EPIPE: + case ERANGE: + case EFAULT: + case EROFS: + zfs_error_aux(hdl, strerror(errno)); + return (zfs_error(hdl, EZFS_BADBACKUP, errbuf)); + + default: + return (zfs_standard_error(hdl, errno, errbuf)); + } + } + if (debugnv) VERIFY(0 == nvlist_add_nvlist(debugnv, zhp->zfs_name, thisdbg)); nvlist_free(thisdbg); @@ -966,6 +947,9 @@ hold_for_send(zfs_handle_t *zhp, send_dump_data_t *sdd) assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT); + if (sdd->dryrun) + return (0); + /* * zfs_send() only opens a cleanup_fd for sends that need it, * e.g. replication and doall. @@ -999,7 +983,7 @@ dump_snapshot(zfs_handle_t *zhp, void *arg) send_dump_data_t *sdd = arg; char *thissnap; int err; - boolean_t isfromsnap, istosnap; + boolean_t isfromsnap, istosnap, fromorigin; boolean_t exclude = B_FALSE; thissnap = strchr(zhp->zfs_name, '@') + 1; @@ -1076,15 +1060,47 @@ dump_snapshot(zfs_handle_t *zhp, void *arg) return (err); } - /* send it */ + fromorigin = sdd->prevsnap[0] == '\0' && + (sdd->fromorigin || sdd->replicate); + if (sdd->verbose) { - (void) fprintf(stderr, "sending from @%s to %s\n", - sdd->prevsnap, zhp->zfs_name); + uint64_t size; + err = estimate_ioctl(zhp, sdd->prevsnap_obj, + fromorigin, &size); + + if (sdd->parsable) { + if (sdd->prevsnap[0] != '\0') { + (void) fprintf(stderr, "incremental\t%s\t%s", + sdd->prevsnap, zhp->zfs_name); + } else { + (void) fprintf(stderr, "full\t%s", + zhp->zfs_name); + } + } else { + (void) fprintf(stderr, dgettext(TEXT_DOMAIN, + "send from @%s to %s"), + sdd->prevsnap, zhp->zfs_name); + } + if (err == 0) { + if (sdd->parsable) { + (void) fprintf(stderr, "\t%llu\n", + (longlong_t)size); + } else { + char buf[16]; + zfs_nicenum(size, buf, sizeof (buf)); + (void) fprintf(stderr, dgettext(TEXT_DOMAIN, + " estimated size is %s\n"), buf); + } + sdd->size += size; + } else { + (void) fprintf(stderr, "\n"); + } } - err = dump_ioctl(zhp, sdd->prevsnap, sdd->prevsnap_obj, - sdd->prevsnap[0] == '\0' && (sdd->fromorigin || sdd->replicate), - sdd->outfd, sdd->debugnv); + if (!sdd->dryrun) { + err = dump_ioctl(zhp, sdd->prevsnap, sdd->prevsnap_obj, + fromorigin, sdd->outfd, sdd->debugnv); + } (void) strcpy(sdd->prevsnap, thissnap); sdd->prevsnap_obj = zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID); @@ -1103,8 +1119,8 @@ dump_filesystem(zfs_handle_t *zhp, void *arg) (void) snprintf(zc.zc_name, sizeof (zc.zc_name), "%s@%s", zhp->zfs_name, sdd->tosnap); if (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0) { - (void) fprintf(stderr, "WARNING: " - "could not send %s@%s: does not exist\n", + (void) fprintf(stderr, dgettext(TEXT_DOMAIN, + "WARNING: could not send %s@%s: does not exist\n"), zhp->zfs_name, sdd->tosnap); sdd->err = B_TRUE; return (0); @@ -1133,23 +1149,24 @@ dump_filesystem(zfs_handle_t *zhp, void *arg) rv = zfs_iter_snapshots_sorted(zhp, dump_snapshot, arg); if (!sdd->seenfrom) { - (void) fprintf(stderr, + (void) fprintf(stderr, dgettext(TEXT_DOMAIN, "WARNING: could not send %s@%s:\n" - "incremental source (%s@%s) does not exist\n", + "incremental source (%s@%s) does not exist\n"), zhp->zfs_name, sdd->tosnap, zhp->zfs_name, sdd->fromsnap); sdd->err = B_TRUE; } else if (!sdd->seento) { if (sdd->fromsnap) { - (void) fprintf(stderr, + (void) fprintf(stderr, dgettext(TEXT_DOMAIN, "WARNING: could not send %s@%s:\n" "incremental source (%s@%s) " - "is not earlier than it\n", + "is not earlier than it\n"), zhp->zfs_name, sdd->tosnap, zhp->zfs_name, sdd->fromsnap); } else { - (void) fprintf(stderr, "WARNING: " - "could not send %s@%s: does not exist\n", + (void) fprintf(stderr, dgettext(TEXT_DOMAIN, + "WARNING: " + "could not send %s@%s: does not exist\n"), zhp->zfs_name, sdd->tosnap); } sdd->err = B_TRUE; @@ -1195,11 +1212,12 @@ dump_filesystems(zfs_handle_t *rzhp, void *arg) needagain = progress = B_FALSE; for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; fspair = nvlist_next_nvpair(sdd->fss, fspair)) { - nvlist_t *fslist; + nvlist_t *fslist, *parent_nv; char *fsname; zfs_handle_t *zhp; int err; uint64_t origin_guid = 0; + uint64_t parent_guid = 0; VERIFY(nvpair_value_nvlist(fspair, &fslist) == 0); if (nvlist_lookup_boolean(fslist, "sent") == 0) @@ -1207,13 +1225,23 @@ dump_filesystems(zfs_handle_t *rzhp, void *arg) VERIFY(nvlist_lookup_string(fslist, "name", &fsname) == 0); (void) nvlist_lookup_uint64(fslist, "origin", &origin_guid); + (void) nvlist_lookup_uint64(fslist, "parentfromsnap", + &parent_guid); + + if (parent_guid != 0) { + parent_nv = fsavl_find(sdd->fsavl, parent_guid, NULL); + if (!nvlist_exists(parent_nv, "sent")) { + /* parent has not been sent; skip this one */ + needagain = B_TRUE; + continue; + } + } if (origin_guid != 0) { nvlist_t *origin_nv = fsavl_find(sdd->fsavl, origin_guid, NULL); if (origin_nv != NULL && - nvlist_lookup_boolean(origin_nv, - "sent") == ENOENT) { + !nvlist_exists(origin_nv, "sent")) { /* * origin has not been sent yet; * skip this clone. @@ -1237,6 +1265,16 @@ dump_filesystems(zfs_handle_t *rzhp, void *arg) assert(progress); goto again; } + + /* clean out the sent flags in case we reuse this fss */ + for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; + fspair = nvlist_next_nvpair(sdd->fss, fspair)) { + nvlist_t *fslist; + + VERIFY(nvpair_value_nvlist(fspair, &fslist) == 0); + (void) nvlist_remove_all(fslist, "sent"); + } + return (0); } @@ -1258,12 +1296,12 @@ dump_filesystems(zfs_handle_t *rzhp, void *arg) */ int zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, - sendflags_t flags, int outfd, snapfilter_cb_t filter_func, + sendflags_t *flags, int outfd, snapfilter_cb_t filter_func, void *cb_arg, nvlist_t **debugnvp) { char errbuf[1024]; send_dump_data_t sdd = { 0 }; - int err; + int err = 0; nvlist_t *fss = NULL; avl_tree_t *fsavl = NULL; static uint64_t holdseq; @@ -1291,12 +1329,12 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, } } - if (zfs_spa_version(zhp, &spa_version) == 0 && + if (!flags->dryrun && zfs_spa_version(zhp, &spa_version) == 0 && spa_version >= SPA_VERSION_USERREFS && - (flags.doall || flags.replicate)) + (flags->doall || flags->replicate)) holdsnaps = B_TRUE; - if (flags.dedup) { + if (flags->dedup && !flags->dryrun) { featureflags |= (DMU_BACKUP_FEATURE_DEDUP | DMU_BACKUP_FEATURE_DEDUPPROPS); if (err = pipe(pipefd)) { @@ -1316,13 +1354,13 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, } } - if (flags.replicate || flags.doall || flags.props) { + if (flags->replicate || flags->doall || flags->props) { dmu_replay_record_t drr = { 0 }; char *packbuf = NULL; size_t buflen = 0; zio_cksum_t zc = { 0 }; - if (flags.replicate || flags.props) { + if (flags->replicate || flags->props) { nvlist_t *hdrnv; VERIFY(0 == nvlist_alloc(&hdrnv, NV_UNIQUE_NAME, 0)); @@ -1331,13 +1369,13 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, "fromsnap", fromsnap)); } VERIFY(0 == nvlist_add_string(hdrnv, "tosnap", tosnap)); - if (!flags.replicate) { + if (!flags->replicate) { VERIFY(0 == nvlist_add_boolean(hdrnv, "not_recursive")); } err = gather_nvlist(zhp->zfs_hdl, zhp->zfs_name, - fromsnap, tosnap, flags.replicate, &fss, &fsavl); + fromsnap, tosnap, flags->replicate, &fss, &fsavl); if (err) goto err_out; VERIFY(0 == nvlist_add_nvlist(hdrnv, "fss", fss)); @@ -1354,33 +1392,34 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, } } - /* write first begin record */ - drr.drr_type = DRR_BEGIN; - drr.drr_u.drr_begin.drr_magic = DMU_BACKUP_MAGIC; - DMU_SET_STREAM_HDRTYPE(drr.drr_u.drr_begin.drr_versioninfo, - DMU_COMPOUNDSTREAM); - DMU_SET_FEATUREFLAGS(drr.drr_u.drr_begin.drr_versioninfo, - featureflags); - (void) snprintf(drr.drr_u.drr_begin.drr_toname, - sizeof (drr.drr_u.drr_begin.drr_toname), - "%s@%s", zhp->zfs_name, tosnap); - drr.drr_payloadlen = buflen; - err = cksum_and_write(&drr, sizeof (drr), &zc, outfd); + if (!flags->dryrun) { + /* write first begin record */ + drr.drr_type = DRR_BEGIN; + drr.drr_u.drr_begin.drr_magic = DMU_BACKUP_MAGIC; + DMU_SET_STREAM_HDRTYPE(drr.drr_u.drr_begin. + drr_versioninfo, DMU_COMPOUNDSTREAM); + DMU_SET_FEATUREFLAGS(drr.drr_u.drr_begin. + drr_versioninfo, featureflags); + (void) snprintf(drr.drr_u.drr_begin.drr_toname, + sizeof (drr.drr_u.drr_begin.drr_toname), + "%s@%s", zhp->zfs_name, tosnap); + drr.drr_payloadlen = buflen; + err = cksum_and_write(&drr, sizeof (drr), &zc, outfd); - /* write header nvlist */ - if (err != -1 && packbuf != NULL) { - err = cksum_and_write(packbuf, buflen, &zc, outfd); - } - free(packbuf); - if (err == -1) { - fsavl_destroy(fsavl); - nvlist_free(fss); - err = errno; - goto stderr_out; - } + /* write header nvlist */ + if (err != -1 && packbuf != NULL) { + err = cksum_and_write(packbuf, buflen, &zc, + outfd); + } + free(packbuf); + if (err == -1) { + fsavl_destroy(fsavl); + nvlist_free(fss); + err = errno; + goto stderr_out; + } - /* write end record */ - if (err != -1) { + /* write end record */ bzero(&drr, sizeof (drr)); drr.drr_type = DRR_END; drr.drr_u.drr_end.drr_checksum = zc; @@ -1391,22 +1430,26 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, err = errno; goto stderr_out; } + + err = 0; } } /* dump each stream */ sdd.fromsnap = fromsnap; sdd.tosnap = tosnap; - if (flags.dedup) + if (flags->dedup) sdd.outfd = pipefd[0]; else sdd.outfd = outfd; - sdd.replicate = flags.replicate; - sdd.doall = flags.doall; - sdd.fromorigin = flags.fromorigin; + sdd.replicate = flags->replicate; + sdd.doall = flags->doall; + sdd.fromorigin = flags->fromorigin; sdd.fss = fss; sdd.fsavl = fsavl; - sdd.verbose = flags.verbose; + sdd.verbose = flags->verbose; + sdd.parsable = flags->parsable; + sdd.dryrun = flags->dryrun; sdd.filter_cb = filter_func; sdd.filter_cb_arg = cb_arg; if (debugnvp) @@ -1423,11 +1466,31 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, } else { sdd.cleanup_fd = -1; } + if (flags->verbose) { + /* + * Do a verbose no-op dry run to get all the verbose output + * before generating any data. Then do a non-verbose real + * run to generate the streams. + */ + sdd.dryrun = B_TRUE; + err = dump_filesystems(zhp, &sdd); + sdd.dryrun = flags->dryrun; + sdd.verbose = B_FALSE; + if (flags->parsable) { + (void) fprintf(stderr, "size\t%llu\n", + (longlong_t)sdd.size); + } else { + char buf[16]; + zfs_nicenum(sdd.size, buf, sizeof (buf)); + (void) fprintf(stderr, dgettext(TEXT_DOMAIN, + "total estimated size is %s\n"), buf); + } + } err = dump_filesystems(zhp, &sdd); fsavl_destroy(fsavl); nvlist_free(fss); - if (flags.dedup) { + if (flags->dedup) { (void) close(pipefd[0]); (void) pthread_join(tid, NULL); } @@ -1437,7 +1500,8 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, sdd.cleanup_fd = -1; } - if (flags.replicate || flags.doall || flags.props) { + if (!flags->dryrun && (flags->replicate || flags->doall || + flags->props)) { /* * write final end record. NB: want to do this even if * there was some error, because it might not be totally @@ -1458,7 +1522,7 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, err_out: if (sdd.cleanup_fd != -1) VERIFY(0 == close(sdd.cleanup_fd)); - if (flags.dedup) { + if (flags->dedup) { (void) pthread_cancel(tid); (void) pthread_join(tid, NULL); (void) close(pipefd[0]); @@ -1529,7 +1593,7 @@ recv_read_nvlist(libzfs_handle_t *hdl, int fd, int len, nvlist_t **nvp, static int recv_rename(libzfs_handle_t *hdl, const char *name, const char *tryname, - int baselen, char *newname, recvflags_t flags) + int baselen, char *newname, recvflags_t *flags) { static int seq; zfs_cmd_t zc = { 0 }; @@ -1541,7 +1605,7 @@ recv_rename(libzfs_handle_t *hdl, const char *name, const char *tryname, if (zhp == NULL) return (-1); clp = changelist_gather(zhp, ZFS_PROP_NAME, 0, - flags.force ? MS_FORCE : 0); + flags->force ? MS_FORCE : 0); zfs_close(zhp); if (clp == NULL) return (-1); @@ -1557,7 +1621,7 @@ recv_rename(libzfs_handle_t *hdl, const char *name, const char *tryname, (void) strlcpy(zc.zc_value, tryname, sizeof (zc.zc_value)); - if (flags.verbose) { + if (flags->verbose) { (void) printf("attempting rename %s to %s\n", zc.zc_name, zc.zc_value); } @@ -1576,19 +1640,19 @@ recv_rename(libzfs_handle_t *hdl, const char *name, const char *tryname, "recv-%u-%u", getpid(), seq); (void) strlcpy(zc.zc_value, newname, sizeof (zc.zc_value)); - if (flags.verbose) { + if (flags->verbose) { (void) printf("failed - trying rename %s to %s\n", zc.zc_name, zc.zc_value); } err = ioctl(hdl->libzfs_fd, ZFS_IOC_RENAME, &zc); if (err == 0) changelist_rename(clp, name, newname); - if (err && flags.verbose) { + if (err && flags->verbose) { (void) printf("failed (%u) - " "will try again on next pass\n", errno); } err = EAGAIN; - } else if (flags.verbose) { + } else if (flags->verbose) { if (err == 0) (void) printf("success\n"); else @@ -1603,7 +1667,7 @@ recv_rename(libzfs_handle_t *hdl, const char *name, const char *tryname, static int recv_destroy(libzfs_handle_t *hdl, const char *name, int baselen, - char *newname, recvflags_t flags) + char *newname, recvflags_t *flags) { zfs_cmd_t zc = { 0 }; int err = 0; @@ -1616,7 +1680,7 @@ recv_destroy(libzfs_handle_t *hdl, const char *name, int baselen, if (zhp == NULL) return (-1); clp = changelist_gather(zhp, ZFS_PROP_NAME, 0, - flags.force ? MS_FORCE : 0); + flags->force ? MS_FORCE : 0); if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT && zfs_spa_version(zhp, &spa_version) == 0 && spa_version >= SPA_VERSION_USERREFS) @@ -1632,11 +1696,11 @@ recv_destroy(libzfs_handle_t *hdl, const char *name, int baselen, zc.zc_defer_destroy = defer; (void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name)); - if (flags.verbose) + if (flags->verbose) (void) printf("attempting destroy %s\n", zc.zc_name); err = ioctl(hdl->libzfs_fd, ZFS_IOC_DESTROY, &zc); if (err == 0) { - if (flags.verbose) + if (flags->verbose) (void) printf("success\n"); changelist_remove(clp, zc.zc_name); } @@ -1659,6 +1723,7 @@ recv_destroy(libzfs_handle_t *hdl, const char *name, int baselen, typedef struct guid_to_name_data { uint64_t guid; char *name; + char *skip; } guid_to_name_data_t; static int @@ -1667,21 +1732,35 @@ guid_to_name_cb(zfs_handle_t *zhp, void *arg) guid_to_name_data_t *gtnd = arg; int err; + if (gtnd->skip != NULL && + strcmp(zhp->zfs_name, gtnd->skip) == 0) { + return (0); + } + if (zhp->zfs_dmustats.dds_guid == gtnd->guid) { (void) strcpy(gtnd->name, zhp->zfs_name); zfs_close(zhp); return (EEXIST); } + err = zfs_iter_children(zhp, guid_to_name_cb, gtnd); zfs_close(zhp); return (err); } +/* + * Attempt to find the local dataset associated with this guid. In the case of + * multiple matches, we attempt to find the "best" match by searching + * progressively larger portions of the hierarchy. This allows one to send a + * tree of datasets individually and guarantee that we will find the source + * guid within that hierarchy, even if there are multiple matches elsewhere. + */ static int guid_to_name(libzfs_handle_t *hdl, const char *parent, uint64_t guid, char *name) { /* exhaustive search all local snapshots */ + char pname[ZFS_MAXNAMELEN]; guid_to_name_data_t gtnd; int err = 0; zfs_handle_t *zhp; @@ -1689,35 +1768,42 @@ guid_to_name(libzfs_handle_t *hdl, const char *parent, uint64_t guid, gtnd.guid = guid; gtnd.name = name; + gtnd.skip = NULL; - if (strchr(parent, '@') == NULL) { - zhp = make_dataset_handle(hdl, parent); - if (zhp != NULL) { - err = zfs_iter_children(zhp, guid_to_name_cb, >nd); - zfs_close(zhp); - if (err == EEXIST) - return (0); - } - } + (void) strlcpy(pname, parent, sizeof (pname)); - cp = strchr(parent, '/'); - if (cp) + /* + * Search progressively larger portions of the hierarchy. This will + * select the "most local" version of the origin snapshot in the case + * that there are multiple matching snapshots in the system. + */ + while ((cp = strrchr(pname, '/')) != NULL) { + + /* Chop off the last component and open the parent */ *cp = '\0'; - zhp = make_dataset_handle(hdl, parent); - if (cp) - *cp = '/'; + zhp = make_dataset_handle(hdl, pname); + + if (zhp == NULL) + continue; - if (zhp) { err = zfs_iter_children(zhp, guid_to_name_cb, >nd); zfs_close(zhp); + if (err == EEXIST) + return (0); + + /* + * Remember the dataset that we already searched, so we + * skip it next time through. + */ + gtnd.skip = pname; } - return (err == EEXIST ? 0 : ENOENT); - + return (ENOENT); } /* - * Return true if dataset guid1 is created before guid2. + * Return +1 if guid1 is before guid2, 0 if they are the same, and -1 if + * guid1 is after guid2. */ static int created_before(libzfs_handle_t *hdl, avl_tree_t *avl, @@ -1727,7 +1813,8 @@ created_before(libzfs_handle_t *hdl, avl_tree_t *avl, char *fsname, *snapname; char buf[ZFS_MAXNAMELEN]; int rv; - zfs_node_t zn1, zn2; + zfs_handle_t *guid1hdl, *guid2hdl; + uint64_t create1, create2; if (guid2 == 0) return (0); @@ -1737,30 +1824,38 @@ created_before(libzfs_handle_t *hdl, avl_tree_t *avl, nvfs = fsavl_find(avl, guid1, &snapname); VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); (void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname); - zn1.zn_handle = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); - if (zn1.zn_handle == NULL) + guid1hdl = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); + if (guid1hdl == NULL) return (-1); nvfs = fsavl_find(avl, guid2, &snapname); VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); (void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname); - zn2.zn_handle = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); - if (zn2.zn_handle == NULL) { - zfs_close(zn2.zn_handle); + guid2hdl = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); + if (guid2hdl == NULL) { + zfs_close(guid1hdl); return (-1); } - rv = (zfs_snapshot_compare(&zn1, &zn2) == -1); + create1 = zfs_prop_get_int(guid1hdl, ZFS_PROP_CREATETXG); + create2 = zfs_prop_get_int(guid2hdl, ZFS_PROP_CREATETXG); - zfs_close(zn1.zn_handle); - zfs_close(zn2.zn_handle); + if (create1 < create2) + rv = -1; + else if (create1 > create2) + rv = +1; + else + rv = 0; + + zfs_close(guid1hdl); + zfs_close(guid2hdl); return (rv); } static int recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, - recvflags_t flags, nvlist_t *stream_nv, avl_tree_t *stream_avl, + recvflags_t *flags, nvlist_t *stream_nv, avl_tree_t *stream_avl, nvlist_t *renamed) { nvlist_t *local_nv; @@ -1777,7 +1872,7 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, recursive = (nvlist_lookup_boolean(stream_nv, "not_recursive") == ENOENT); - if (flags.dryrun) + if (flags->dryrun) return (0); again: @@ -1837,7 +1932,7 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, nvlist_t *origin_nvfs; char *origin_fsname; - if (flags.verbose) + if (flags->verbose) (void) printf("promoting %s\n", fsname); origin_nvfs = fsavl_find(local_avl, originguid, @@ -1885,7 +1980,7 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, if (found == NULL) { char name[ZFS_MAXNAMELEN]; - if (!flags.force) + if (!flags->force) continue; (void) snprintf(name, sizeof (name), "%s@%s", @@ -1943,7 +2038,7 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, /* check for delete */ if (stream_nvfs == NULL) { - if (!flags.force) + if (!flags->force) continue; error = recv_destroy(hdl, fsname, strlen(tofs)+1, @@ -1956,7 +2051,7 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, } if (fromguid == 0) { - if (flags.verbose) { + if (flags->verbose) { (void) printf("local fs %s does not have " "fromsnap (%s in stream); must have " "been deleted locally; ignoring\n", @@ -1981,7 +2076,7 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, if ((stream_parent_fromsnap_guid != 0 && parent_fromsnap_guid != 0 && stream_parent_fromsnap_guid != parent_fromsnap_guid) || - ((flags.isprefix || strcmp(tofs, fsname) != 0) && + ((flags->isprefix || strcmp(tofs, fsname) != 0) && (s1 != NULL) && (s2 != NULL) && strcmp(s1, s2) != 0)) { nvlist_t *parent; char tryname[ZFS_MAXNAMELEN]; @@ -2004,7 +2099,7 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, "%s%s", pname, strrchr(stream_fsname, '/')); } else { tryname[0] = '\0'; - if (flags.verbose) { + if (flags->verbose) { (void) printf("local fs %s new parent " "not found\n", fsname); } @@ -2032,7 +2127,7 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, if (needagain && progress) { /* do another pass to fix up temporary names */ - if (flags.verbose) + if (flags->verbose) (void) printf("another pass:\n"); goto again; } @@ -2042,7 +2137,7 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, static int zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname, - recvflags_t flags, dmu_replay_record_t *drr, zio_cksum_t *zc, + recvflags_t *flags, dmu_replay_record_t *drr, zio_cksum_t *zc, char **top_zfs, int cleanup_fd, uint64_t *action_handlep) { nvlist_t *stream_nv = NULL; @@ -2071,7 +2166,7 @@ zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname, */ if (drr->drr_payloadlen != 0) { error = recv_read_nvlist(hdl, fd, drr->drr_payloadlen, - &stream_nv, flags.byteswap, zc); + &stream_nv, flags->byteswap, zc); if (error) { error = zfs_error(hdl, EZFS_BADSTREAM, errbuf); goto out; @@ -2092,9 +2187,9 @@ zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname, * Read in the end record and verify checksum. */ if (0 != (error = recv_read(hdl, fd, &drre, sizeof (drre), - flags.byteswap, NULL))) + flags->byteswap, NULL))) goto out; - if (flags.byteswap) { + if (flags->byteswap) { drre.drr_type = BSWAP_32(drre.drr_type); drre.drr_u.drr_end.drr_checksum.zc_word[0] = BSWAP_64(drre.drr_u.drr_end.drr_checksum.zc_word[0]); @@ -2135,11 +2230,11 @@ zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname, nvpair_t *pair = NULL; (void) strlcpy(tofs, destname, ZFS_MAXNAMELEN); - if (flags.isprefix) { + if (flags->isprefix) { struct drr_begin *drrb = &drr->drr_u.drr_begin; int i; - if (flags.istail) { + if (flags->istail) { cp = strrchr(drrb->drr_toname, '/'); if (cp == NULL) { (void) strlcat(tofs, "/", @@ -2157,7 +2252,7 @@ zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname, *strchr(tofs, '@') = '\0'; } - if (recursive && !flags.dryrun && !flags.nomount) { + if (recursive && !flags->dryrun && !flags->nomount) { VERIFY(0 == nvlist_alloc(&renamed, NV_UNIQUE_NAME, 0)); } @@ -2331,7 +2426,7 @@ recv_skip(libzfs_handle_t *hdl, int fd, boolean_t byteswap) */ static int zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, - recvflags_t flags, dmu_replay_record_t *drr, + recvflags_t *flags, dmu_replay_record_t *drr, dmu_replay_record_t *drr_noswap, const char *sendfs, nvlist_t *stream_nv, avl_tree_t *stream_avl, char **top_zfs, int cleanup_fd, uint64_t *action_handlep) @@ -2373,7 +2468,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, if (err) VERIFY(0 == nvlist_alloc(&props, NV_UNIQUE_NAME, 0)); - if (flags.canmountoff) { + if (flags->canmountoff) { VERIFY(0 == nvlist_add_uint64(props, zfs_prop_to_name(ZFS_PROP_CANMOUNT), 0)); } @@ -2400,7 +2495,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, * If they specified a snapshot, chop the entire name stored in * the stream. */ - if (flags.istail) { + if (flags->istail) { /* * A filesystem was specified with -e. We want to tack on only * the tail of the sent snapshot path. @@ -2426,7 +2521,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, } else { chopprefix = drrb->drr_toname + (chopprefix - sendfs); } - } else if (flags.isprefix) { + } else if (flags->isprefix) { /* * A filesystem was specified with -d. We want to tack on * everything but the first element of the sent snapshot path @@ -2480,7 +2575,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, * Determine the name of the origin snapshot, store in zc_string. */ if (drrb->drr_flags & DRR_FLAG_CLONE) { - if (guid_to_name(hdl, tosnap, + if (guid_to_name(hdl, zc.zc_value, drrb->drr_fromguid, zc.zc_string) != 0) { zcmd_free_nvlists(&zc); zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, @@ -2488,7 +2583,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, zc.zc_value); return (zfs_error(hdl, EZFS_NOENT, errbuf)); } - if (flags.verbose) + if (flags->verbose) (void) printf("found clone origin %s\n", zc.zc_string); } @@ -2511,7 +2606,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, !zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) { char suffix[ZFS_MAXNAMELEN]; (void) strcpy(suffix, strrchr(zc.zc_value, '/')); - if (guid_to_name(hdl, tosnap, parent_snapguid, + if (guid_to_name(hdl, zc.zc_name, parent_snapguid, zc.zc_value) == 0) { *strchr(zc.zc_value, '@') = '\0'; (void) strcat(zc.zc_value, suffix); @@ -2533,12 +2628,12 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, * topmost path in the stream, then if the fs does not exist we * should look no further. */ - if ((flags.isprefix || (*(chopprefix = drrb->drr_toname + + if ((flags->isprefix || (*(chopprefix = drrb->drr_toname + strlen(sendfs)) != '\0' && *chopprefix != '@')) && !zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) { char snap[ZFS_MAXNAMELEN]; (void) strcpy(snap, strchr(zc.zc_value, '@')); - if (guid_to_name(hdl, tosnap, drrb->drr_fromguid, + if (guid_to_name(hdl, zc.zc_name, drrb->drr_fromguid, zc.zc_value) == 0) { *strchr(zc.zc_value, '@') = '\0'; (void) strcat(zc.zc_value, snap); @@ -2560,7 +2655,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, * snapshots). */ if (stream_wantsnewfs) { - if (!flags.force) { + if (!flags->force) { zcmd_free_nvlists(&zc); zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "destination '%s' exists\n" @@ -2596,7 +2691,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, return (zfs_error(hdl, EZFS_EXISTS, errbuf)); } - if (!flags.dryrun && zhp->zfs_type == ZFS_TYPE_FILESYSTEM && + if (!flags->dryrun && zhp->zfs_type == ZFS_TYPE_FILESYSTEM && stream_wantsnewfs) { /* We can't do online recv in this case */ clp = changelist_gather(zhp, ZFS_PROP_NAME, 0, 0); @@ -2635,7 +2730,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, */ *cp = '\0'; - if (flags.isprefix && !flags.istail && !flags.dryrun && + if (flags->isprefix && !flags->istail && !flags->dryrun && create_parents(hdl, zc.zc_value, strlen(tosnap)) != 0) { zcmd_free_nvlists(&zc); return (zfs_error(hdl, EZFS_BADRESTORE, errbuf)); @@ -2646,18 +2741,18 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, zc.zc_begin_record = drr_noswap->drr_u.drr_begin; zc.zc_cookie = infd; - zc.zc_guid = flags.force; - if (flags.verbose) { + zc.zc_guid = flags->force; + if (flags->verbose) { (void) printf("%s %s stream of %s into %s\n", - flags.dryrun ? "would receive" : "receiving", + flags->dryrun ? "would receive" : "receiving", drrb->drr_fromguid ? "incremental" : "full", drrb->drr_toname, zc.zc_value); (void) fflush(stdout); } - if (flags.dryrun) { + if (flags->dryrun) { zcmd_free_nvlists(&zc); - return (recv_skip(hdl, infd, flags.byteswap)); + return (recv_skip(hdl, infd, flags->byteswap)); } zc.zc_nvlist_dst = (uint64_t)(uintptr_t)prop_errbuf; @@ -2738,12 +2833,12 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, nvlist_free(local_nv); if (fs != NULL) { - if (flags.verbose) { + if (flags->verbose) { (void) printf("snap %s already exists; " "ignoring\n", zc.zc_value); } err = ioctl_err = recv_skip(hdl, infd, - flags.byteswap); + flags->byteswap); } } *cp = '@'; @@ -2795,7 +2890,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, case EDQUOT: zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "destination %s space quota exceeded"), zc.zc_name); - (void) zfs_error(hdl, EZFS_BADRESTORE, errbuf); + (void) zfs_error(hdl, EZFS_NOSPC, errbuf); break; default: (void) zfs_standard_error(hdl, ioctl_errno, errbuf); @@ -2853,7 +2948,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, *action_handlep = zc.zc_action_handle; - if (flags.verbose) { + if (flags->verbose) { char buf1[64]; char buf2[64]; uint64_t bytes = zc.zc_cookie; @@ -2871,7 +2966,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, } static int -zfs_receive_impl(libzfs_handle_t *hdl, const char *tosnap, recvflags_t flags, +zfs_receive_impl(libzfs_handle_t *hdl, const char *tosnap, recvflags_t *flags, int infd, const char *sendfs, nvlist_t *stream_nv, avl_tree_t *stream_avl, char **top_zfs, int cleanup_fd, uint64_t *action_handlep) { @@ -2886,7 +2981,7 @@ zfs_receive_impl(libzfs_handle_t *hdl, const char *tosnap, recvflags_t flags, (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot receive")); - if (flags.isprefix && + if (flags->isprefix && !zfs_dataset_exists(hdl, tosnap, ZFS_TYPE_DATASET)) { zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "specified fs " "(%s) does not exist"), tosnap); @@ -2906,7 +3001,7 @@ zfs_receive_impl(libzfs_handle_t *hdl, const char *tosnap, recvflags_t flags, /* the kernel needs the non-byteswapped begin record */ drr_noswap = drr; - flags.byteswap = B_FALSE; + flags->byteswap = B_FALSE; if (drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) { /* * We computed the checksum in the wrong byteorder in @@ -2914,7 +3009,7 @@ zfs_receive_impl(libzfs_handle_t *hdl, const char *tosnap, recvflags_t flags, */ bzero(&zcksum, sizeof (zio_cksum_t)); fletcher_4_incremental_byteswap(&drr, sizeof (drr), &zcksum); - flags.byteswap = B_TRUE; + flags->byteswap = B_TRUE; drr.drr_type = BSWAP_32(drr.drr_type); drr.drr_payloadlen = BSWAP_32(drr.drr_payloadlen); @@ -2982,7 +3077,7 @@ zfs_receive_impl(libzfs_handle_t *hdl, const char *tosnap, recvflags_t flags, * (-1 will override -2). */ int -zfs_receive(libzfs_handle_t *hdl, const char *tosnap, recvflags_t flags, +zfs_receive(libzfs_handle_t *hdl, const char *tosnap, recvflags_t *flags, int infd, avl_tree_t *stream_avl) { char *top_zfs = NULL; @@ -2998,7 +3093,7 @@ zfs_receive(libzfs_handle_t *hdl, const char *tosnap, recvflags_t flags, VERIFY(0 == close(cleanup_fd)); - if (err == 0 && !flags.nomount && top_zfs) { + if (err == 0 && !flags->nomount && top_zfs) { zfs_handle_t *zhp; prop_changelist_t *clp; diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_util.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_util.c index e457a2334dce..c903696fe7d7 100644 --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_util.c +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_util.c @@ -20,6 +20,7 @@ */ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011 by Delphix. All rights reserved. */ /* @@ -351,6 +352,7 @@ zfs_standard_error_fmt(libzfs_handle_t *hdl, int error, const char *fmt, ...) switch (error) { case ENXIO: case ENODEV: + case EPIPE: zfs_verror(hdl, EZFS_IO, fmt, ap); break; @@ -1324,7 +1326,8 @@ addlist(libzfs_handle_t *hdl, char *propname, zprop_list_t **listp, * dataset property, */ if (prop == ZPROP_INVAL && (type == ZFS_TYPE_POOL || - (!zfs_prop_user(propname) && !zfs_prop_userquota(propname)))) { + (!zfs_prop_user(propname) && !zfs_prop_userquota(propname) && + !zfs_prop_written(propname)))) { zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid property '%s'"), propname); return (zfs_error(hdl, EZFS_BADPROP, diff --git a/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c b/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c index fa4fbebb45d2..105112d759d7 100644 --- a/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c +++ b/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c @@ -228,7 +228,7 @@ usage(void) "\n" " Note: if -L labelenv is specified and labelenv is not set in\n" " the environment, a default value is used.\n", - progname, progname, strlen(progname), " ", + progname, progname, (int)strlen(progname), " ", progname, progname); } diff --git a/cddl/lib/drti/Makefile b/cddl/lib/drti/Makefile index ccc9aa926283..6e3d3a61a41d 100644 --- a/cddl/lib/drti/Makefile +++ b/cddl/lib/drti/Makefile @@ -18,4 +18,4 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/compat/opensolaris \ -I${OPENSOLARIS_SYS_DISTDIR}/uts/common \ -DPIC ${PICFLAG} -.include +.include diff --git a/cddl/lib/libzfs/Makefile b/cddl/lib/libzfs/Makefile index 6f6414a62d2b..c1dac5004b8c 100644 --- a/cddl/lib/libzfs/Makefile +++ b/cddl/lib/libzfs/Makefile @@ -20,8 +20,8 @@ SRCS+= libzfs_changelist.c \ libzfs_config.c \ libzfs_dataset.c \ libzfs_diff.c \ - libzfs_graph.c \ libzfs_import.c \ + libzfs_iter.c \ libzfs_mount.c \ libzfs_pool.c \ libzfs_sendrecv.c \ diff --git a/contrib/bsnmp/snmp_mibII/mibII.c b/contrib/bsnmp/snmp_mibII/mibII.c index 9258a5d40d0b..27ebeded6a1f 100644 --- a/contrib/bsnmp/snmp_mibII/mibII.c +++ b/contrib/bsnmp/snmp_mibII/mibII.c @@ -941,7 +941,7 @@ handle_rtmsg(struct rt_msghdr *rtm) { struct sockaddr *addrs[RTAX_MAX]; struct if_msghdr *ifm; - struct ifa_msghdr *ifam; + struct ifa_msghdr ifam; struct ifma_msghdr *ifmam; #ifdef RTM_IFANNOUNCE struct if_announcemsghdr *ifan; @@ -961,17 +961,17 @@ handle_rtmsg(struct rt_msghdr *rtm) switch (rtm->rtm_type) { case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - mib_extract_addrs(ifam->ifam_addrs, (u_char *)(ifam + 1), addrs); + memcpy(&ifam, rtm, sizeof(ifam)); + mib_extract_addrs(ifam.ifam_addrs, (u_char *)(&ifam + 1), addrs); if (addrs[RTAX_IFA] == NULL || addrs[RTAX_NETMASK] == NULL) break; sa = (struct sockaddr_in *)(void *)addrs[RTAX_IFA]; if ((ifa = mib_find_ifa(sa->sin_addr)) == NULL) { /* unknown address */ - if ((ifp = mib_find_if_sys(ifam->ifam_index)) == NULL) { + if ((ifp = mib_find_if_sys(ifam.ifam_index)) == NULL) { syslog(LOG_WARNING, "RTM_NEWADDR for unknown " - "interface %u", ifam->ifam_index); + "interface %u", ifam.ifam_index); break; } if ((ifa = alloc_ifa(ifp->index, sa->sin_addr)) == NULL) @@ -988,8 +988,8 @@ handle_rtmsg(struct rt_msghdr *rtm) break; case RTM_DELADDR: - ifam = (struct ifa_msghdr *)rtm; - mib_extract_addrs(ifam->ifam_addrs, (u_char *)(ifam + 1), addrs); + memcpy(&ifam, rtm, sizeof(ifam)); + mib_extract_addrs(ifam.ifam_addrs, (u_char *)(&ifam + 1), addrs); if (addrs[RTAX_IFA] == NULL) break; diff --git a/contrib/bsnmp/snmpd/snmpmod.h b/contrib/bsnmp/snmpd/snmpmod.h index 902536650d9a..ad73566eeb2c 100644 --- a/contrib/bsnmp/snmpd/snmpmod.h +++ b/contrib/bsnmp/snmpd/snmpmod.h @@ -40,6 +40,7 @@ #define snmpmod_h_ #include +#include #include #include #include diff --git a/contrib/bzip2/bzip2recover.c b/contrib/bzip2/bzip2recover.c index f9de0496abf1..bf3bca5b2edc 100644 --- a/contrib/bzip2/bzip2recover.c +++ b/contrib/bzip2/bzip2recover.c @@ -37,7 +37,7 @@ */ #ifdef __GNUC__ typedef unsigned long long int MaybeUInt64; -# define MaybeUInt64_FMT "%Lu" +# define MaybeUInt64_FMT "%llu" #else #ifdef _MSC_VER typedef unsigned __int64 MaybeUInt64; diff --git a/contrib/compiler-rt/LICENSE.TXT b/contrib/compiler-rt/LICENSE.TXT index 2552e8c2eb66..c41925e7340f 100644 --- a/contrib/compiler-rt/LICENSE.TXT +++ b/contrib/compiler-rt/LICENSE.TXT @@ -14,7 +14,7 @@ Full text of the relevant licenses is included below. University of Illinois/NCSA Open Source License -Copyright (c) 2009-2010 by the contributors listed in CREDITS.TXT +Copyright (c) 2009-2012 by the contributors listed in CREDITS.TXT All rights reserved. @@ -55,7 +55,7 @@ SOFTWARE. ============================================================================== -Copyright (c) 2009-2010 by the contributors listed in CREDITS.TXT +Copyright (c) 2009-2012 by the contributors listed in CREDITS.TXT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -74,3 +74,25 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +============================================================================== +Copyrights and Licenses for Third Party Software Distributed with LLVM: +============================================================================== +The LLVM software contains code written by third parties. Such software will +have its own individual LICENSE.TXT file in the directory in which it appears. +This file will describe the copyrights, license, and restrictions which apply +to that code. + +The disclaimer of warranty in the University of Illinois Open Source License +applies to all code in the LLVM Distribution, and nothing in any of the +other licenses gives permission to use the names of the LLVM Team or the +University of Illinois to endorse or promote products derived from this +Software. + +The following pieces of software have additional or alternate copyrights, +licenses, and/or restrictions: + +Program Directory +------- --------- +sysinfo lib/asan/sysinfo +mach_override lib/asan/mach_override diff --git a/contrib/compiler-rt/README.txt b/contrib/compiler-rt/README.txt index cbeb10cf918e..b37c0aecdeb2 100644 --- a/contrib/compiler-rt/README.txt +++ b/contrib/compiler-rt/README.txt @@ -106,6 +106,15 @@ si_int __mulvsi3(si_int a, si_int b); // a * b di_int __mulvdi3(di_int a, di_int b); // a * b ti_int __mulvti3(ti_int a, ti_int b); // a * b + +// Integral arithmetic which returns if overflow + +si_int __mulosi4(si_int a, si_int b, int* overflow); // a * b, overflow set to one if result not in signed range +di_int __mulodi4(di_int a, di_int b, int* overflow); // a * b, overflow set to one if result not in signed range +ti_int __muloti4(ti_int a, ti_int b, int* overflow); // a * b, overflow set to + one if result not in signed range + + // Integral comparison: a < b -> 0 // a == b -> 1 // a > b -> 2 diff --git a/contrib/compiler-rt/lib/abi.h b/contrib/compiler-rt/lib/abi.h deleted file mode 100644 index 2534317ac8f6..000000000000 --- a/contrib/compiler-rt/lib/abi.h +++ /dev/null @@ -1,23 +0,0 @@ -/* ===------ abi.h - configuration header for compiler-rt -----------------=== - * - * The LLVM Compiler Infrastructure - * - * This file is dual licensed under the MIT and the University of Illinois Open - * Source Licenses. See LICENSE.TXT for details. - * - * ===----------------------------------------------------------------------=== - * - * This file is a configuration header for compiler-rt. - * This file is not part of the interface of this library. - * - * ===----------------------------------------------------------------------=== - */ - -#if __ARM_EABI__ -# define ARM_EABI_FNALIAS(aeabi_name, name) \ - void __aeabi_##aeabi_name() __attribute__((alias("__" #name))); -# define COMPILER_RT_ABI __attribute__((pcs("aapcs"))) -#else -# define ARM_EABI_FNALIAS(aeabi_name, name) -# define COMPILER_RT_ABI -#endif diff --git a/contrib/compiler-rt/lib/absvdi2.c b/contrib/compiler-rt/lib/absvdi2.c index 9c5d4a299baa..682c2355d2ac 100644 --- a/contrib/compiler-rt/lib/absvdi2.c +++ b/contrib/compiler-rt/lib/absvdi2.c @@ -11,10 +11,8 @@ * *===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: absolute value */ diff --git a/contrib/compiler-rt/lib/absvsi2.c b/contrib/compiler-rt/lib/absvsi2.c index 80a1a78984a8..4812af815982 100644 --- a/contrib/compiler-rt/lib/absvsi2.c +++ b/contrib/compiler-rt/lib/absvsi2.c @@ -11,10 +11,8 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: absolute value */ diff --git a/contrib/compiler-rt/lib/absvti2.c b/contrib/compiler-rt/lib/absvti2.c index 9e73a26b68ea..8f2bddcb3b27 100644 --- a/contrib/compiler-rt/lib/absvti2.c +++ b/contrib/compiler-rt/lib/absvti2.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: absolute value */ diff --git a/contrib/compiler-rt/lib/adddf3.c b/contrib/compiler-rt/lib/adddf3.c index 3cc997b71a3b..7eb40a15d2ae 100644 --- a/contrib/compiler-rt/lib/adddf3.c +++ b/contrib/compiler-rt/lib/adddf3.c @@ -12,8 +12,6 @@ // //===----------------------------------------------------------------------===// -#include "abi.h" - #define DOUBLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/addsf3.c b/contrib/compiler-rt/lib/addsf3.c index 20610ef31fa2..e57270a1e28d 100644 --- a/contrib/compiler-rt/lib/addsf3.c +++ b/contrib/compiler-rt/lib/addsf3.c @@ -12,8 +12,6 @@ // //===----------------------------------------------------------------------===// -#include "abi.h" - #define SINGLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/addvdi3.c b/contrib/compiler-rt/lib/addvdi3.c index 51ad397f5710..db45a27f0784 100644 --- a/contrib/compiler-rt/lib/addvdi3.c +++ b/contrib/compiler-rt/lib/addvdi3.c @@ -11,10 +11,8 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: a + b */ diff --git a/contrib/compiler-rt/lib/addvsi3.c b/contrib/compiler-rt/lib/addvsi3.c index c18f7bd45986..81f515cd7bb1 100644 --- a/contrib/compiler-rt/lib/addvsi3.c +++ b/contrib/compiler-rt/lib/addvsi3.c @@ -11,10 +11,8 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: a + b */ diff --git a/contrib/compiler-rt/lib/addvti3.c b/contrib/compiler-rt/lib/addvti3.c index ba220f548096..9105c178994e 100644 --- a/contrib/compiler-rt/lib/addvti3.c +++ b/contrib/compiler-rt/lib/addvti3.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: a + b */ diff --git a/contrib/compiler-rt/lib/apple_versioning.c b/contrib/compiler-rt/lib/apple_versioning.c deleted file mode 100644 index e838d726fbb6..000000000000 --- a/contrib/compiler-rt/lib/apple_versioning.c +++ /dev/null @@ -1,291 +0,0 @@ -/* ===-- apple_versioning.c - Adds versioning symbols for ld ---------------=== - * - * The LLVM Compiler Infrastructure - * - * This file is dual licensed under the MIT and the University of Illinois Open - * Source Licenses. See LICENSE.TXT for details. - * - * ===----------------------------------------------------------------------=== - */ - - - -#if __APPLE__ - #if __arm__ - #define NOT_HERE_BEFORE_10_6(sym) - #elif __ppc__ - #define NOT_HERE_BEFORE_10_6(sym) \ - extern const char sym##_tmp3 __asm("$ld$hide$os10.3$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp3 = 0; \ - extern const char sym##_tmp4 __asm("$ld$hide$os10.4$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp4 = 0; \ - extern const char sym##_tmp5 __asm("$ld$hide$os10.5$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp5 = 0; - #else - #define NOT_HERE_BEFORE_10_6(sym) \ - extern const char sym##_tmp4 __asm("$ld$hide$os10.4$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp4 = 0; \ - extern const char sym##_tmp5 __asm("$ld$hide$os10.5$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp5 = 0; - #endif /* __ppc__ */ - - -/* Symbols in libSystem.dylib in 10.6 and later, - * but are in libgcc_s.dylib in earlier versions - */ - -NOT_HERE_BEFORE_10_6(__absvdi2) -NOT_HERE_BEFORE_10_6(__absvsi2) -NOT_HERE_BEFORE_10_6(__absvti2) -NOT_HERE_BEFORE_10_6(__addvdi3) -NOT_HERE_BEFORE_10_6(__addvsi3) -NOT_HERE_BEFORE_10_6(__addvti3) -NOT_HERE_BEFORE_10_6(__ashldi3) -NOT_HERE_BEFORE_10_6(__ashlti3) -NOT_HERE_BEFORE_10_6(__ashrdi3) -NOT_HERE_BEFORE_10_6(__ashrti3) -NOT_HERE_BEFORE_10_6(__clear_cache) -NOT_HERE_BEFORE_10_6(__clzdi2) -NOT_HERE_BEFORE_10_6(__clzsi2) -NOT_HERE_BEFORE_10_6(__clzti2) -NOT_HERE_BEFORE_10_6(__cmpdi2) -NOT_HERE_BEFORE_10_6(__cmpti2) -NOT_HERE_BEFORE_10_6(__ctzdi2) -NOT_HERE_BEFORE_10_6(__ctzsi2) -NOT_HERE_BEFORE_10_6(__ctzti2) -NOT_HERE_BEFORE_10_6(__divdc3) -NOT_HERE_BEFORE_10_6(__divdi3) -NOT_HERE_BEFORE_10_6(__divsc3) -NOT_HERE_BEFORE_10_6(__divtc3) -NOT_HERE_BEFORE_10_6(__divti3) -NOT_HERE_BEFORE_10_6(__divxc3) -NOT_HERE_BEFORE_10_6(__enable_execute_stack) -NOT_HERE_BEFORE_10_6(__ffsdi2) -NOT_HERE_BEFORE_10_6(__ffsti2) -NOT_HERE_BEFORE_10_6(__fixdfdi) -NOT_HERE_BEFORE_10_6(__fixdfti) -NOT_HERE_BEFORE_10_6(__fixsfdi) -NOT_HERE_BEFORE_10_6(__fixsfti) -NOT_HERE_BEFORE_10_6(__fixtfdi) -NOT_HERE_BEFORE_10_6(__fixunsdfdi) -NOT_HERE_BEFORE_10_6(__fixunsdfsi) -NOT_HERE_BEFORE_10_6(__fixunsdfti) -NOT_HERE_BEFORE_10_6(__fixunssfdi) -NOT_HERE_BEFORE_10_6(__fixunssfsi) -NOT_HERE_BEFORE_10_6(__fixunssfti) -NOT_HERE_BEFORE_10_6(__fixunstfdi) -NOT_HERE_BEFORE_10_6(__fixunsxfdi) -NOT_HERE_BEFORE_10_6(__fixunsxfsi) -NOT_HERE_BEFORE_10_6(__fixunsxfti) -NOT_HERE_BEFORE_10_6(__fixxfdi) -NOT_HERE_BEFORE_10_6(__fixxfti) -NOT_HERE_BEFORE_10_6(__floatdidf) -NOT_HERE_BEFORE_10_6(__floatdisf) -NOT_HERE_BEFORE_10_6(__floatditf) -NOT_HERE_BEFORE_10_6(__floatdixf) -NOT_HERE_BEFORE_10_6(__floattidf) -NOT_HERE_BEFORE_10_6(__floattisf) -NOT_HERE_BEFORE_10_6(__floattixf) -NOT_HERE_BEFORE_10_6(__floatundidf) -NOT_HERE_BEFORE_10_6(__floatundisf) -NOT_HERE_BEFORE_10_6(__floatunditf) -NOT_HERE_BEFORE_10_6(__floatundixf) -NOT_HERE_BEFORE_10_6(__floatuntidf) -NOT_HERE_BEFORE_10_6(__floatuntisf) -NOT_HERE_BEFORE_10_6(__floatuntixf) -NOT_HERE_BEFORE_10_6(__gcc_personality_v0) -NOT_HERE_BEFORE_10_6(__lshrdi3) -NOT_HERE_BEFORE_10_6(__lshrti3) -NOT_HERE_BEFORE_10_6(__moddi3) -NOT_HERE_BEFORE_10_6(__modti3) -NOT_HERE_BEFORE_10_6(__muldc3) -NOT_HERE_BEFORE_10_6(__muldi3) -NOT_HERE_BEFORE_10_6(__mulsc3) -NOT_HERE_BEFORE_10_6(__multc3) -NOT_HERE_BEFORE_10_6(__multi3) -NOT_HERE_BEFORE_10_6(__mulvdi3) -NOT_HERE_BEFORE_10_6(__mulvsi3) -NOT_HERE_BEFORE_10_6(__mulvti3) -NOT_HERE_BEFORE_10_6(__mulxc3) -NOT_HERE_BEFORE_10_6(__negdi2) -NOT_HERE_BEFORE_10_6(__negti2) -NOT_HERE_BEFORE_10_6(__negvdi2) -NOT_HERE_BEFORE_10_6(__negvsi2) -NOT_HERE_BEFORE_10_6(__negvti2) -NOT_HERE_BEFORE_10_6(__paritydi2) -NOT_HERE_BEFORE_10_6(__paritysi2) -NOT_HERE_BEFORE_10_6(__parityti2) -NOT_HERE_BEFORE_10_6(__popcountdi2) -NOT_HERE_BEFORE_10_6(__popcountsi2) -NOT_HERE_BEFORE_10_6(__popcountti2) -NOT_HERE_BEFORE_10_6(__powidf2) -NOT_HERE_BEFORE_10_6(__powisf2) -NOT_HERE_BEFORE_10_6(__powitf2) -NOT_HERE_BEFORE_10_6(__powixf2) -NOT_HERE_BEFORE_10_6(__subvdi3) -NOT_HERE_BEFORE_10_6(__subvsi3) -NOT_HERE_BEFORE_10_6(__subvti3) -NOT_HERE_BEFORE_10_6(__ucmpdi2) -NOT_HERE_BEFORE_10_6(__ucmpti2) -NOT_HERE_BEFORE_10_6(__udivdi3) -NOT_HERE_BEFORE_10_6(__udivmoddi4) -NOT_HERE_BEFORE_10_6(__udivmodti4) -NOT_HERE_BEFORE_10_6(__udivti3) -NOT_HERE_BEFORE_10_6(__umoddi3) -NOT_HERE_BEFORE_10_6(__umodti3) - - -#if __ppc__ -NOT_HERE_BEFORE_10_6(__gcc_qadd) -NOT_HERE_BEFORE_10_6(__gcc_qdiv) -NOT_HERE_BEFORE_10_6(__gcc_qmul) -NOT_HERE_BEFORE_10_6(__gcc_qsub) -NOT_HERE_BEFORE_10_6(__trampoline_setup) -#endif /* __ppc__ */ - -#if __arm__ && __DYNAMIC__ - #define NOT_HERE_UNTIL_AFTER_4_3(sym) \ - extern const char sym##_tmp1 __asm("$ld$hide$os3.0$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp1 = 0; \ - extern const char sym##_tmp2 __asm("$ld$hide$os3.1$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp2 = 0; \ - extern const char sym##_tmp3 __asm("$ld$hide$os3.2$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp3 = 0; \ - extern const char sym##_tmp4 __asm("$ld$hide$os4.0$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp4 = 0; \ - extern const char sym##_tmp5 __asm("$ld$hide$os4.1$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp5 = 0; \ - extern const char sym##_tmp6 __asm("$ld$hide$os4.2$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp6 = 0; \ - extern const char sym##_tmp7 __asm("$ld$hide$os4.3$_" #sym ); \ - __attribute__((visibility("default"))) const char sym##_tmp7 = 0; - -NOT_HERE_UNTIL_AFTER_4_3(__absvdi2) -NOT_HERE_UNTIL_AFTER_4_3(__absvsi2) -NOT_HERE_UNTIL_AFTER_4_3(__adddf3) -NOT_HERE_UNTIL_AFTER_4_3(__adddf3vfp) -NOT_HERE_UNTIL_AFTER_4_3(__addsf3) -NOT_HERE_UNTIL_AFTER_4_3(__addsf3vfp) -NOT_HERE_UNTIL_AFTER_4_3(__addvdi3) -NOT_HERE_UNTIL_AFTER_4_3(__addvsi3) -NOT_HERE_UNTIL_AFTER_4_3(__ashldi3) -NOT_HERE_UNTIL_AFTER_4_3(__ashrdi3) -NOT_HERE_UNTIL_AFTER_4_3(__bswapdi2) -NOT_HERE_UNTIL_AFTER_4_3(__bswapsi2) -NOT_HERE_UNTIL_AFTER_4_3(__clzdi2) -NOT_HERE_UNTIL_AFTER_4_3(__clzsi2) -NOT_HERE_UNTIL_AFTER_4_3(__cmpdi2) -NOT_HERE_UNTIL_AFTER_4_3(__ctzdi2) -NOT_HERE_UNTIL_AFTER_4_3(__ctzsi2) -NOT_HERE_UNTIL_AFTER_4_3(__divdc3) -NOT_HERE_UNTIL_AFTER_4_3(__divdf3) -NOT_HERE_UNTIL_AFTER_4_3(__divdf3vfp) -NOT_HERE_UNTIL_AFTER_4_3(__divdi3) -NOT_HERE_UNTIL_AFTER_4_3(__divsc3) -NOT_HERE_UNTIL_AFTER_4_3(__divsf3) -NOT_HERE_UNTIL_AFTER_4_3(__divsf3vfp) -NOT_HERE_UNTIL_AFTER_4_3(__divsi3) -NOT_HERE_UNTIL_AFTER_4_3(__eqdf2) -NOT_HERE_UNTIL_AFTER_4_3(__eqdf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__eqsf2) -NOT_HERE_UNTIL_AFTER_4_3(__eqsf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__extendsfdf2) -NOT_HERE_UNTIL_AFTER_4_3(__extendsfdf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__ffsdi2) -NOT_HERE_UNTIL_AFTER_4_3(__fixdfdi) -NOT_HERE_UNTIL_AFTER_4_3(__fixdfsi) -NOT_HERE_UNTIL_AFTER_4_3(__fixdfsivfp) -NOT_HERE_UNTIL_AFTER_4_3(__fixsfdi) -NOT_HERE_UNTIL_AFTER_4_3(__fixsfsi) -NOT_HERE_UNTIL_AFTER_4_3(__fixsfsivfp) -NOT_HERE_UNTIL_AFTER_4_3(__fixunsdfdi) -NOT_HERE_UNTIL_AFTER_4_3(__fixunsdfsi) -NOT_HERE_UNTIL_AFTER_4_3(__fixunsdfsivfp) -NOT_HERE_UNTIL_AFTER_4_3(__fixunssfdi) -NOT_HERE_UNTIL_AFTER_4_3(__fixunssfsi) -NOT_HERE_UNTIL_AFTER_4_3(__fixunssfsivfp) -NOT_HERE_UNTIL_AFTER_4_3(__floatdidf) -NOT_HERE_UNTIL_AFTER_4_3(__floatdisf) -NOT_HERE_UNTIL_AFTER_4_3(__floatsidf) -NOT_HERE_UNTIL_AFTER_4_3(__floatsidfvfp) -NOT_HERE_UNTIL_AFTER_4_3(__floatsisf) -NOT_HERE_UNTIL_AFTER_4_3(__floatsisfvfp) -NOT_HERE_UNTIL_AFTER_4_3(__floatundidf) -NOT_HERE_UNTIL_AFTER_4_3(__floatundisf) -NOT_HERE_UNTIL_AFTER_4_3(__floatunsidf) -NOT_HERE_UNTIL_AFTER_4_3(__floatunsisf) -NOT_HERE_UNTIL_AFTER_4_3(__floatunssidfvfp) -NOT_HERE_UNTIL_AFTER_4_3(__floatunssisfvfp) -NOT_HERE_UNTIL_AFTER_4_3(__gedf2) -NOT_HERE_UNTIL_AFTER_4_3(__gedf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__gesf2) -NOT_HERE_UNTIL_AFTER_4_3(__gesf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__gtdf2) -NOT_HERE_UNTIL_AFTER_4_3(__gtdf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__gtsf2) -NOT_HERE_UNTIL_AFTER_4_3(__gtsf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__ledf2) -NOT_HERE_UNTIL_AFTER_4_3(__ledf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__lesf2) -NOT_HERE_UNTIL_AFTER_4_3(__lesf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__lshrdi3) -NOT_HERE_UNTIL_AFTER_4_3(__ltdf2) -NOT_HERE_UNTIL_AFTER_4_3(__ltdf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__ltsf2) -NOT_HERE_UNTIL_AFTER_4_3(__ltsf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__moddi3) -NOT_HERE_UNTIL_AFTER_4_3(__modsi3) -NOT_HERE_UNTIL_AFTER_4_3(__muldc3) -NOT_HERE_UNTIL_AFTER_4_3(__muldf3) -NOT_HERE_UNTIL_AFTER_4_3(__muldf3vfp) -NOT_HERE_UNTIL_AFTER_4_3(__muldi3) -NOT_HERE_UNTIL_AFTER_4_3(__mulsc3) -NOT_HERE_UNTIL_AFTER_4_3(__mulsf3) -NOT_HERE_UNTIL_AFTER_4_3(__mulsf3vfp) -NOT_HERE_UNTIL_AFTER_4_3(__mulvdi3) -NOT_HERE_UNTIL_AFTER_4_3(__mulvsi3) -NOT_HERE_UNTIL_AFTER_4_3(__nedf2) -NOT_HERE_UNTIL_AFTER_4_3(__nedf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__negdi2) -NOT_HERE_UNTIL_AFTER_4_3(__negvdi2) -NOT_HERE_UNTIL_AFTER_4_3(__negvsi2) -NOT_HERE_UNTIL_AFTER_4_3(__nesf2) -NOT_HERE_UNTIL_AFTER_4_3(__nesf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__paritydi2) -NOT_HERE_UNTIL_AFTER_4_3(__paritysi2) -NOT_HERE_UNTIL_AFTER_4_3(__popcountdi2) -NOT_HERE_UNTIL_AFTER_4_3(__popcountsi2) -NOT_HERE_UNTIL_AFTER_4_3(__powidf2) -NOT_HERE_UNTIL_AFTER_4_3(__powisf2) -NOT_HERE_UNTIL_AFTER_4_3(__subdf3) -NOT_HERE_UNTIL_AFTER_4_3(__subdf3vfp) -NOT_HERE_UNTIL_AFTER_4_3(__subsf3) -NOT_HERE_UNTIL_AFTER_4_3(__subsf3vfp) -NOT_HERE_UNTIL_AFTER_4_3(__subvdi3) -NOT_HERE_UNTIL_AFTER_4_3(__subvsi3) -NOT_HERE_UNTIL_AFTER_4_3(__truncdfsf2) -NOT_HERE_UNTIL_AFTER_4_3(__truncdfsf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__ucmpdi2) -NOT_HERE_UNTIL_AFTER_4_3(__udivdi3) -NOT_HERE_UNTIL_AFTER_4_3(__udivmoddi4) -NOT_HERE_UNTIL_AFTER_4_3(__udivsi3) -NOT_HERE_UNTIL_AFTER_4_3(__umoddi3) -NOT_HERE_UNTIL_AFTER_4_3(__umodsi3) -NOT_HERE_UNTIL_AFTER_4_3(__unorddf2) -NOT_HERE_UNTIL_AFTER_4_3(__unorddf2vfp) -NOT_HERE_UNTIL_AFTER_4_3(__unordsf2) -NOT_HERE_UNTIL_AFTER_4_3(__unordsf2vfp) - -NOT_HERE_UNTIL_AFTER_4_3(__divmodsi4) -NOT_HERE_UNTIL_AFTER_4_3(__udivmodsi4) -#endif // __arm__ && __DYNAMIC__ - - - - - -#else /* !__APPLE__ */ - -extern int avoid_empty_file; - -#endif /* !__APPLE__*/ diff --git a/contrib/compiler-rt/lib/arm/adddf3vfp.S b/contrib/compiler-rt/lib/arm/adddf3vfp.S index cced1e09a3e0..c90b0c2eabe6 100644 --- a/contrib/compiler-rt/lib/arm/adddf3vfp.S +++ b/contrib/compiler-rt/lib/arm/adddf3vfp.S @@ -15,10 +15,11 @@ // Adds two double precision floating point numbers using the Darwin // calling convention where double arguments are passsed in GPR pairs // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__adddf3vfp) - fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6 - fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7 - faddd d6, d6, d7 - fmrrd r0, r1, d6 // move result back to r0/r1 pair + vmov d6, r0, r1 // move first param from r0/r1 pair into d6 + vmov d7, r2, r3 // move second param from r2/r3 pair into d7 + vadd.f64 d6, d6, d7 + vmov r0, r1, d6 // move result back to r0/r1 pair bx lr diff --git a/contrib/compiler-rt/lib/arm/addsf3vfp.S b/contrib/compiler-rt/lib/arm/addsf3vfp.S index b747528de52b..43653d5265c0 100644 --- a/contrib/compiler-rt/lib/arm/addsf3vfp.S +++ b/contrib/compiler-rt/lib/arm/addsf3vfp.S @@ -15,10 +15,11 @@ // Adds two single precision floating point numbers using the Darwin // calling convention where single arguments are passsed in GPRs // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__addsf3vfp) - fmsr s14, r0 // move first param from r0 into float register - fmsr s15, r1 // move second param from r1 into float register - fadds s14, s14, s15 - fmrs r0, s14 // move result back to r0 + vmov s14, r0 // move first param from r0 into float register + vmov s15, r1 // move second param from r1 into float register + vadd.f32 s14, s14, s15 + vmov r0, s14 // move result back to r0 bx lr diff --git a/contrib/compiler-rt/lib/arm/divdf3vfp.S b/contrib/compiler-rt/lib/arm/divdf3vfp.S index 74ef0eabff73..52de67f7fdcd 100644 --- a/contrib/compiler-rt/lib/arm/divdf3vfp.S +++ b/contrib/compiler-rt/lib/arm/divdf3vfp.S @@ -15,10 +15,11 @@ // Divides two double precision floating point numbers using the Darwin // calling convention where double arguments are passsed in GPR pairs // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__divdf3vfp) - fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6 - fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7 - fdivd d5, d6, d7 - fmrrd r0, r1, d5 // move result back to r0/r1 pair + vmov d6, r0, r1 // move first param from r0/r1 pair into d6 + vmov d7, r2, r3 // move second param from r2/r3 pair into d7 + vdiv.f64 d5, d6, d7 + vmov r0, r1, d5 // move result back to r0/r1 pair bx lr diff --git a/contrib/compiler-rt/lib/arm/divsf3vfp.S b/contrib/compiler-rt/lib/arm/divsf3vfp.S index 9eefcf31eba8..81ba90307897 100644 --- a/contrib/compiler-rt/lib/arm/divsf3vfp.S +++ b/contrib/compiler-rt/lib/arm/divsf3vfp.S @@ -15,10 +15,11 @@ // Divides two single precision floating point numbers using the Darwin // calling convention where single arguments are passsed like 32-bit ints. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__divsf3vfp) - fmsr s14, r0 // move first param from r0 into float register - fmsr s15, r1 // move second param from r1 into float register - fdivs s13, s14, s15 - fmrs r0, s13 // move result back to r0 + vmov s14, r0 // move first param from r0 into float register + vmov s15, r1 // move second param from r1 into float register + vdiv.f32 s13, s14, s15 + vmov r0, s13 // move result back to r0 bx lr diff --git a/contrib/compiler-rt/lib/arm/eqdf2vfp.S b/contrib/compiler-rt/lib/arm/eqdf2vfp.S index 2998a76e021c..c41e55a34685 100644 --- a/contrib/compiler-rt/lib/arm/eqdf2vfp.S +++ b/contrib/compiler-rt/lib/arm/eqdf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__eqdf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr moveq r0, #1 // set result register to 1 if equal movne r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/eqsf2vfp.S b/contrib/compiler-rt/lib/arm/eqsf2vfp.S index 927566edd7af..730ef88da68c 100644 --- a/contrib/compiler-rt/lib/arm/eqsf2vfp.S +++ b/contrib/compiler-rt/lib/arm/eqsf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__eqsf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr moveq r0, #1 // set result register to 1 if equal movne r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/extendsfdf2vfp.S b/contrib/compiler-rt/lib/arm/extendsfdf2vfp.S index b1aa88e2ae97..17a146e0280a 100644 --- a/contrib/compiler-rt/lib/arm/extendsfdf2vfp.S +++ b/contrib/compiler-rt/lib/arm/extendsfdf2vfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a single precision parameter is // passed in a GPR and a double precision result is returned in R0/R1 pair. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__extendsfdf2vfp) - fmsr s15, r0 // load float register from R0 - fcvtds d7, s15 // convert single to double - fmrrd r0, r1, d7 // return result in r0/r1 pair + vmov s15, r0 // load float register from R0 + vcvt.f64.f32 d7, s15 // convert single to double + vmov r0, r1, d7 // return result in r0/r1 pair bx lr diff --git a/contrib/compiler-rt/lib/arm/fixdfsivfp.S b/contrib/compiler-rt/lib/arm/fixdfsivfp.S index 0285a17e418b..b7c3299d1c4d 100644 --- a/contrib/compiler-rt/lib/arm/fixdfsivfp.S +++ b/contrib/compiler-rt/lib/arm/fixdfsivfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a double precision parameter is // passed in GPR register pair. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__fixdfsivfp) - fmdrr d7, r0, r1 // load double register from R0/R1 - ftosizd s15, d7 // convert double to 32-bit int into s15 - fmrs r0, s15 // move s15 to result register + vmov d7, r0, r1 // load double register from R0/R1 + vcvt.s32.f64 s15, d7 // convert double to 32-bit int into s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/contrib/compiler-rt/lib/arm/fixsfsivfp.S b/contrib/compiler-rt/lib/arm/fixsfsivfp.S index d05ba740aff7..1cea6a486d6d 100644 --- a/contrib/compiler-rt/lib/arm/fixsfsivfp.S +++ b/contrib/compiler-rt/lib/arm/fixsfsivfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a single precision parameter is // passed in a GPR.. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__fixsfsivfp) - fmsr s15, r0 // load float register from R0 - ftosizs s15, s15 // convert single to 32-bit int into s15 - fmrs r0, s15 // move s15 to result register + vmov s15, r0 // load float register from R0 + vcvt.s32.f32 s15, s15 // convert single to 32-bit int into s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/contrib/compiler-rt/lib/arm/fixunsdfsivfp.S b/contrib/compiler-rt/lib/arm/fixunsdfsivfp.S index ddb703cdd608..54b03592b457 100644 --- a/contrib/compiler-rt/lib/arm/fixunsdfsivfp.S +++ b/contrib/compiler-rt/lib/arm/fixunsdfsivfp.S @@ -17,9 +17,10 @@ // Uses Darwin calling convention where a double precision parameter is // passed in GPR register pair. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__fixunsdfsivfp) - fmdrr d7, r0, r1 // load double register from R0/R1 - ftouizd s15, d7 // convert double to 32-bit int into s15 - fmrs r0, s15 // move s15 to result register + vmov d7, r0, r1 // load double register from R0/R1 + vcvt.u32.f64 s15, d7 // convert double to 32-bit int into s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/contrib/compiler-rt/lib/arm/fixunssfsivfp.S b/contrib/compiler-rt/lib/arm/fixunssfsivfp.S index afbb64f395ec..12adb529ae7a 100644 --- a/contrib/compiler-rt/lib/arm/fixunssfsivfp.S +++ b/contrib/compiler-rt/lib/arm/fixunssfsivfp.S @@ -17,9 +17,10 @@ // Uses Darwin calling convention where a single precision parameter is // passed in a GPR.. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__fixunssfsivfp) - fmsr s15, r0 // load float register from R0 - ftouizs s15, s15 // convert single to 32-bit unsigned into s15 - fmrs r0, s15 // move s15 to result register + vmov s15, r0 // load float register from R0 + vcvt.u32.f32 s15, s15 // convert single to 32-bit unsigned into s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/contrib/compiler-rt/lib/arm/floatsidfvfp.S b/contrib/compiler-rt/lib/arm/floatsidfvfp.S index fe3366a904dd..e6a1eb3e497f 100644 --- a/contrib/compiler-rt/lib/arm/floatsidfvfp.S +++ b/contrib/compiler-rt/lib/arm/floatsidfvfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a double precision result is // return in GPR register pair. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__floatsidfvfp) - fmsr s15, r0 // move int to float register s15 - fsitod d7, s15 // convert 32-bit int in s15 to double in d7 - fmrrd r0, r1, d7 // move d7 to result register pair r0/r1 + vmov s15, r0 // move int to float register s15 + vcvt.f64.s32 d7, s15 // convert 32-bit int in s15 to double in d7 + vmov r0, r1, d7 // move d7 to result register pair r0/r1 bx lr diff --git a/contrib/compiler-rt/lib/arm/floatsisfvfp.S b/contrib/compiler-rt/lib/arm/floatsisfvfp.S index 5b416100a494..0d3a24fc1ece 100644 --- a/contrib/compiler-rt/lib/arm/floatsisfvfp.S +++ b/contrib/compiler-rt/lib/arm/floatsisfvfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a single precision result is // return in a GPR.. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__floatsisfvfp) - fmsr s15, r0 // move int to float register s15 - fsitos s15, s15 // convert 32-bit int in s15 to float in s15 - fmrs r0, s15 // move s15 to result register + vmov s15, r0 // move int to float register s15 + vcvt.f32.s32 s15, s15 // convert 32-bit int in s15 to float in s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/contrib/compiler-rt/lib/arm/floatunssidfvfp.S b/contrib/compiler-rt/lib/arm/floatunssidfvfp.S index 9b22a6f760d8..770b20292fd4 100644 --- a/contrib/compiler-rt/lib/arm/floatunssidfvfp.S +++ b/contrib/compiler-rt/lib/arm/floatunssidfvfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a double precision result is // return in GPR register pair. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__floatunssidfvfp) - fmsr s15, r0 // move int to float register s15 - fuitod d7, s15 // convert 32-bit int in s15 to double in d7 - fmrrd r0, r1, d7 // move d7 to result register pair r0/r1 + vmov s15, r0 // move int to float register s15 + vcvt.f64.u32 d7, s15 // convert 32-bit int in s15 to double in d7 + vmov r0, r1, d7 // move d7 to result register pair r0/r1 bx lr diff --git a/contrib/compiler-rt/lib/arm/floatunssisfvfp.S b/contrib/compiler-rt/lib/arm/floatunssisfvfp.S index 44d5e938054a..16b3ffb104ba 100644 --- a/contrib/compiler-rt/lib/arm/floatunssisfvfp.S +++ b/contrib/compiler-rt/lib/arm/floatunssisfvfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a single precision result is // return in a GPR.. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__floatunssisfvfp) - fmsr s15, r0 // move int to float register s15 - fuitos s15, s15 // convert 32-bit int in s15 to float in s15 - fmrs r0, s15 // move s15 to result register + vmov s15, r0 // move int to float register s15 + vcvt.f32.u32 s15, s15 // convert 32-bit int in s15 to float in s15 + vmov r0, s15 // move s15 to result register bx lr diff --git a/contrib/compiler-rt/lib/arm/gedf2vfp.S b/contrib/compiler-rt/lib/arm/gedf2vfp.S index 9993f52fb49d..55603b83e306 100644 --- a/contrib/compiler-rt/lib/arm/gedf2vfp.S +++ b/contrib/compiler-rt/lib/arm/gedf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__gedf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movge r0, #1 // set result register to 1 if greater than or equal movlt r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/gesf2vfp.S b/contrib/compiler-rt/lib/arm/gesf2vfp.S index 9ce168259bbe..02da35c02e92 100644 --- a/contrib/compiler-rt/lib/arm/gesf2vfp.S +++ b/contrib/compiler-rt/lib/arm/gesf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__gesf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movge r0, #1 // set result register to 1 if greater than or equal movlt r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/gtdf2vfp.S b/contrib/compiler-rt/lib/arm/gtdf2vfp.S index 8a049c8896fe..b5b1e1482762 100644 --- a/contrib/compiler-rt/lib/arm/gtdf2vfp.S +++ b/contrib/compiler-rt/lib/arm/gtdf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__gtdf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movgt r0, #1 // set result register to 1 if equal movle r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/gtsf2vfp.S b/contrib/compiler-rt/lib/arm/gtsf2vfp.S index 1ffe1ec52acc..685a9cec96ca 100644 --- a/contrib/compiler-rt/lib/arm/gtsf2vfp.S +++ b/contrib/compiler-rt/lib/arm/gtsf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__gtsf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movgt r0, #1 // set result register to 1 if equal movle r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/ledf2vfp.S b/contrib/compiler-rt/lib/arm/ledf2vfp.S index a04d0f2a4ad3..6e140dde8764 100644 --- a/contrib/compiler-rt/lib/arm/ledf2vfp.S +++ b/contrib/compiler-rt/lib/arm/ledf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__ledf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movls r0, #1 // set result register to 1 if equal movhi r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/lesf2vfp.S b/contrib/compiler-rt/lib/arm/lesf2vfp.S index 301120047a71..7b2825097a87 100644 --- a/contrib/compiler-rt/lib/arm/lesf2vfp.S +++ b/contrib/compiler-rt/lib/arm/lesf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__lesf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movls r0, #1 // set result register to 1 if equal movhi r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/ltdf2vfp.S b/contrib/compiler-rt/lib/arm/ltdf2vfp.S index 87144a8c8152..a09e67a2f43d 100644 --- a/contrib/compiler-rt/lib/arm/ltdf2vfp.S +++ b/contrib/compiler-rt/lib/arm/ltdf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__ltdf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movmi r0, #1 // set result register to 1 if equal movpl r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/ltsf2vfp.S b/contrib/compiler-rt/lib/arm/ltsf2vfp.S index ca06ae208985..8c7f9a863f34 100644 --- a/contrib/compiler-rt/lib/arm/ltsf2vfp.S +++ b/contrib/compiler-rt/lib/arm/ltsf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__ltsf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movmi r0, #1 // set result register to 1 if equal movpl r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/muldf3vfp.S b/contrib/compiler-rt/lib/arm/muldf3vfp.S index 96bba06c118d..838581eb1097 100644 --- a/contrib/compiler-rt/lib/arm/muldf3vfp.S +++ b/contrib/compiler-rt/lib/arm/muldf3vfp.S @@ -15,10 +15,11 @@ // Multiplies two double precision floating point numbers using the Darwin // calling convention where double arguments are passsed in GPR pairs // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__muldf3vfp) - fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6 - fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7 - fmuld d6, d6, d7 - fmrrd r0, r1, d6 // move result back to r0/r1 pair + vmov d6, r0, r1 // move first param from r0/r1 pair into d6 + vmov d7, r2, r3 // move second param from r2/r3 pair into d7 + vmul.f64 d6, d6, d7 + vmov r0, r1, d6 // move result back to r0/r1 pair bx lr diff --git a/contrib/compiler-rt/lib/arm/mulsf3vfp.S b/contrib/compiler-rt/lib/arm/mulsf3vfp.S index c56991d62e70..ea25913cc49d 100644 --- a/contrib/compiler-rt/lib/arm/mulsf3vfp.S +++ b/contrib/compiler-rt/lib/arm/mulsf3vfp.S @@ -15,10 +15,11 @@ // Multiplies two single precision floating point numbers using the Darwin // calling convention where single arguments are passsed like 32-bit ints. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__mulsf3vfp) - fmsr s14, r0 // move first param from r0 into float register - fmsr s15, r1 // move second param from r1 into float register - fmuls s13, s14, s15 - fmrs r0, s13 // move result back to r0 + vmov s14, r0 // move first param from r0 into float register + vmov s15, r1 // move second param from r1 into float register + vmul.f32 s13, s14, s15 + vmov r0, s13 // move result back to r0 bx lr diff --git a/contrib/compiler-rt/lib/arm/nedf2vfp.S b/contrib/compiler-rt/lib/arm/nedf2vfp.S index a02b09cc8079..21670816c609 100644 --- a/contrib/compiler-rt/lib/arm/nedf2vfp.S +++ b/contrib/compiler-rt/lib/arm/nedf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__nedf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movne r0, #1 // set result register to 0 if unequal moveq r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/negdf2vfp.S b/contrib/compiler-rt/lib/arm/negdf2vfp.S index 100f4fd5c829..64c9b692f454 100644 --- a/contrib/compiler-rt/lib/arm/negdf2vfp.S +++ b/contrib/compiler-rt/lib/arm/negdf2vfp.S @@ -15,6 +15,7 @@ // Returns the negation a double precision floating point numbers using the // Darwin calling convention where double arguments are passsed in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__negdf2vfp) eor r1, r1, #-2147483648 // flip sign bit on double in r0/r1 pair diff --git a/contrib/compiler-rt/lib/arm/negsf2vfp.S b/contrib/compiler-rt/lib/arm/negsf2vfp.S index f96c8ad2b561..b883b733df64 100644 --- a/contrib/compiler-rt/lib/arm/negsf2vfp.S +++ b/contrib/compiler-rt/lib/arm/negsf2vfp.S @@ -15,6 +15,7 @@ // Returns the negation of a single precision floating point numbers using the // Darwin calling convention where single arguments are passsed like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__negsf2vfp) eor r0, r0, #-2147483648 // flip sign bit on float in r0 diff --git a/contrib/compiler-rt/lib/arm/nesf2vfp.S b/contrib/compiler-rt/lib/arm/nesf2vfp.S index d6205497ae63..fa7aa80e1912 100644 --- a/contrib/compiler-rt/lib/arm/nesf2vfp.S +++ b/contrib/compiler-rt/lib/arm/nesf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__nesf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movne r0, #1 // set result register to 1 if unequal moveq r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/subdf3vfp.S b/contrib/compiler-rt/lib/arm/subdf3vfp.S index ff53b3000d13..3f88baacd5bf 100644 --- a/contrib/compiler-rt/lib/arm/subdf3vfp.S +++ b/contrib/compiler-rt/lib/arm/subdf3vfp.S @@ -15,10 +15,11 @@ // Returns difference between two double precision floating point numbers using // the Darwin calling convention where double arguments are passsed in GPR pairs // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__subdf3vfp) - fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6 - fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7 - fsubd d6, d6, d7 - fmrrd r0, r1, d6 // move result back to r0/r1 pair + vmov d6, r0, r1 // move first param from r0/r1 pair into d6 + vmov d7, r2, r3 // move second param from r2/r3 pair into d7 + vsub.f64 d6, d6, d7 + vmov r0, r1, d6 // move result back to r0/r1 pair bx lr diff --git a/contrib/compiler-rt/lib/arm/subsf3vfp.S b/contrib/compiler-rt/lib/arm/subsf3vfp.S index 238f3f047450..ed02ba92167f 100644 --- a/contrib/compiler-rt/lib/arm/subsf3vfp.S +++ b/contrib/compiler-rt/lib/arm/subsf3vfp.S @@ -16,10 +16,11 @@ // using the Darwin calling convention where single arguments are passsed // like 32-bit ints. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__subsf3vfp) - fmsr s14, r0 // move first param from r0 into float register - fmsr s15, r1 // move second param from r1 into float register - fsubs s14, s14, s15 - fmrs r0, s14 // move result back to r0 + vmov s14, r0 // move first param from r0 into float register + vmov s15, r1 // move second param from r1 into float register + vsub.f32 s14, s14, s15 + vmov r0, s14 // move result back to r0 bx lr diff --git a/contrib/compiler-rt/lib/arm/truncdfsf2vfp.S b/contrib/compiler-rt/lib/arm/truncdfsf2vfp.S index 6e55c7ffb52c..371aee94b16a 100644 --- a/contrib/compiler-rt/lib/arm/truncdfsf2vfp.S +++ b/contrib/compiler-rt/lib/arm/truncdfsf2vfp.S @@ -16,9 +16,10 @@ // Uses Darwin calling convention where a double precision parameter is // passed in a R0/R1 pair and a signle precision result is returned in R0. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__truncdfsf2vfp) - fmdrr d7, r0, r1 // load double from r0/r1 pair - fcvtsd s15, d7 // convert double to single (trucate precision) - fmrs r0, s15 // return result in r0 + vmov d7, r0, r1 // load double from r0/r1 pair + vcvt.f32.f64 s15, d7 // convert double to single (trucate precision) + vmov r0, s15 // return result in r0 bx lr diff --git a/contrib/compiler-rt/lib/arm/unorddf2vfp.S b/contrib/compiler-rt/lib/arm/unorddf2vfp.S index 9b52131e4bcc..c49e55f29a4b 100644 --- a/contrib/compiler-rt/lib/arm/unorddf2vfp.S +++ b/contrib/compiler-rt/lib/arm/unorddf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where double precision arguments are passsed // like in GPR pairs. // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__unorddf2vfp) - fmdrr d6, r0, r1 // load r0/r1 pair in double register - fmdrr d7, r2, r3 // load r2/r3 pair in double register - fcmpd d6, d7 - fmstat + vmov d6, r0, r1 // load r0/r1 pair in double register + vmov d7, r2, r3 // load r2/r3 pair in double register + vcmp.f64 d6, d7 + vmrs apsr_nzcv, fpscr movvs r0, #1 // set result register to 1 if "overflow" (any NaNs) movvc r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/arm/unordsf2vfp.S b/contrib/compiler-rt/lib/arm/unordsf2vfp.S index e486533e2ad9..0ab27edf51ad 100644 --- a/contrib/compiler-rt/lib/arm/unordsf2vfp.S +++ b/contrib/compiler-rt/lib/arm/unordsf2vfp.S @@ -16,12 +16,13 @@ // Uses Darwin calling convention where single precision arguments are passsed // like 32-bit ints // + .syntax unified .align 2 DEFINE_COMPILERRT_FUNCTION(__unordsf2vfp) - fmsr s14, r0 // move from GPR 0 to float register - fmsr s15, r1 // move from GPR 1 to float register - fcmps s14, s15 - fmstat + vmov s14, r0 // move from GPR 0 to float register + vmov s15, r1 // move from GPR 1 to float register + vcmp.f32 s14, s15 + vmrs apsr_nzcv, fpscr movvs r0, #1 // set result register to 1 if "overflow" (any NaNs) movvc r0, #0 bx lr diff --git a/contrib/compiler-rt/lib/ashldi3.c b/contrib/compiler-rt/lib/ashldi3.c index adce4e2cb755..6c558fe65576 100644 --- a/contrib/compiler-rt/lib/ashldi3.c +++ b/contrib/compiler-rt/lib/ashldi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/ashrdi3.c b/contrib/compiler-rt/lib/ashrdi3.c index 03692a31d823..38ab7164527f 100644 --- a/contrib/compiler-rt/lib/ashrdi3.c +++ b/contrib/compiler-rt/lib/ashrdi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/assembly.h b/contrib/compiler-rt/lib/assembly.h index 0ce83ac294c8..83bed12335ea 100644 --- a/contrib/compiler-rt/lib/assembly.h +++ b/contrib/compiler-rt/lib/assembly.h @@ -35,15 +35,16 @@ #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) #ifdef VISIBILITY_HIDDEN -#define DEFINE_COMPILERRT_FUNCTION(name) \ - .globl SYMBOL_NAME(name) SEPARATOR \ - HIDDEN_DIRECTIVE SYMBOL_NAME(name) SEPARATOR \ - SYMBOL_NAME(name): +#define DECLARE_SYMBOL_VISIBILITY(name) \ + HIDDEN_DIRECTIVE SYMBOL_NAME(name) SEPARATOR #else +#define DECLARE_SYMBOL_VISIBILITY(name) +#endif + #define DEFINE_COMPILERRT_FUNCTION(name) \ .globl SYMBOL_NAME(name) SEPARATOR \ + DECLARE_SYMBOL_VISIBILITY(name) \ SYMBOL_NAME(name): -#endif #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \ .globl SYMBOL_NAME(name) SEPARATOR \ diff --git a/contrib/compiler-rt/lib/clear_cache.c b/contrib/compiler-rt/lib/clear_cache.c index 7b59a7f810cc..b934fd4bdf69 100644 --- a/contrib/compiler-rt/lib/clear_cache.c +++ b/contrib/compiler-rt/lib/clear_cache.c @@ -9,7 +9,6 @@ */ #include "int_lib.h" -#include #if __APPLE__ #include diff --git a/contrib/compiler-rt/lib/clzdi2.c b/contrib/compiler-rt/lib/clzdi2.c index c281945ffdff..b9e64da492bd 100644 --- a/contrib/compiler-rt/lib/clzdi2.c +++ b/contrib/compiler-rt/lib/clzdi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/clzsi2.c b/contrib/compiler-rt/lib/clzsi2.c index d0a6aeabcb32..25b8ed2c4c24 100644 --- a/contrib/compiler-rt/lib/clzsi2.c +++ b/contrib/compiler-rt/lib/clzsi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/cmpdi2.c b/contrib/compiler-rt/lib/cmpdi2.c index 999c3d2a662f..c2b1f69f4fc2 100644 --- a/contrib/compiler-rt/lib/cmpdi2.c +++ b/contrib/compiler-rt/lib/cmpdi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/ctzdi2.c b/contrib/compiler-rt/lib/ctzdi2.c index b3d37d01b0c6..db3c6fdc08f1 100644 --- a/contrib/compiler-rt/lib/ctzdi2.c +++ b/contrib/compiler-rt/lib/ctzdi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/ctzsi2.c b/contrib/compiler-rt/lib/ctzsi2.c index 2ff0e5d7655f..c69486ea445f 100644 --- a/contrib/compiler-rt/lib/ctzsi2.c +++ b/contrib/compiler-rt/lib/ctzsi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/divdc3.c b/contrib/compiler-rt/lib/divdc3.c index 5f6329856bf3..cfbc498e7b44 100644 --- a/contrib/compiler-rt/lib/divdc3.c +++ b/contrib/compiler-rt/lib/divdc3.c @@ -13,8 +13,7 @@ */ #include "int_lib.h" -#include -#include +#include "int_math.h" /* Returns: the quotient of (a + ib) / (c + id) */ @@ -22,35 +21,37 @@ double _Complex __divdc3(double __a, double __b, double __c, double __d) { int __ilogbw = 0; - double __logbw = logb(fmax(fabs(__c), fabs(__d))); - if (isfinite(__logbw)) + double __logbw = crt_logb(crt_fmax(crt_fabs(__c), crt_fabs(__d))); + if (crt_isfinite(__logbw)) { __ilogbw = (int)__logbw; - __c = scalbn(__c, -__ilogbw); - __d = scalbn(__d, -__ilogbw); + __c = crt_scalbn(__c, -__ilogbw); + __d = crt_scalbn(__d, -__ilogbw); } double __denom = __c * __c + __d * __d; double _Complex z; - __real__ z = scalbn((__a * __c + __b * __d) / __denom, -__ilogbw); - __imag__ z = scalbn((__b * __c - __a * __d) / __denom, -__ilogbw); - if (isnan(__real__ z) && isnan(__imag__ z)) + __real__ z = crt_scalbn((__a * __c + __b * __d) / __denom, -__ilogbw); + __imag__ z = crt_scalbn((__b * __c - __a * __d) / __denom, -__ilogbw); + if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) { - if ((__denom == 0.0) && (!isnan(__a) || !isnan(__b))) + if ((__denom == 0.0) && (!crt_isnan(__a) || !crt_isnan(__b))) { - __real__ z = copysign(INFINITY, __c) * __a; - __imag__ z = copysign(INFINITY, __c) * __b; + __real__ z = crt_copysign(CRT_INFINITY, __c) * __a; + __imag__ z = crt_copysign(CRT_INFINITY, __c) * __b; } - else if ((isinf(__a) || isinf(__b)) && isfinite(__c) && isfinite(__d)) + else if ((crt_isinf(__a) || crt_isinf(__b)) && + crt_isfinite(__c) && crt_isfinite(__d)) { - __a = copysign(isinf(__a) ? 1.0 : 0.0, __a); - __b = copysign(isinf(__b) ? 1.0 : 0.0, __b); - __real__ z = INFINITY * (__a * __c + __b * __d); - __imag__ z = INFINITY * (__b * __c - __a * __d); + __a = crt_copysign(crt_isinf(__a) ? 1.0 : 0.0, __a); + __b = crt_copysign(crt_isinf(__b) ? 1.0 : 0.0, __b); + __real__ z = CRT_INFINITY * (__a * __c + __b * __d); + __imag__ z = CRT_INFINITY * (__b * __c - __a * __d); } - else if (isinf(__logbw) && __logbw > 0.0 && isfinite(__a) && isfinite(__b)) + else if (crt_isinf(__logbw) && __logbw > 0.0 && + crt_isfinite(__a) && crt_isfinite(__b)) { - __c = copysign(isinf(__c) ? 1.0 : 0.0, __c); - __d = copysign(isinf(__d) ? 1.0 : 0.0, __d); + __c = crt_copysign(crt_isinf(__c) ? 1.0 : 0.0, __c); + __d = crt_copysign(crt_isinf(__d) ? 1.0 : 0.0, __d); __real__ z = 0.0 * (__a * __c + __b * __d); __imag__ z = 0.0 * (__b * __c - __a * __d); } diff --git a/contrib/compiler-rt/lib/divdf3.c b/contrib/compiler-rt/lib/divdf3.c index 925abd509e12..cc034dd7acb6 100644 --- a/contrib/compiler-rt/lib/divdf3.c +++ b/contrib/compiler-rt/lib/divdf3.c @@ -15,7 +15,6 @@ // underflow with correct rounding. // //===----------------------------------------------------------------------===// -#include "abi.h" #define DOUBLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/divdi3.c b/contrib/compiler-rt/lib/divdi3.c index d62df56f6783..2c2bcc26d581 100644 --- a/contrib/compiler-rt/lib/divdi3.c +++ b/contrib/compiler-rt/lib/divdi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/divmoddi4.c b/contrib/compiler-rt/lib/divmoddi4.c index d3ca745ac695..a2b8714b4c69 100644 --- a/contrib/compiler-rt/lib/divmoddi4.c +++ b/contrib/compiler-rt/lib/divmoddi4.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/divmodsi4.c b/contrib/compiler-rt/lib/divmodsi4.c index 4dc1978282a4..c7f7b1a7c322 100644 --- a/contrib/compiler-rt/lib/divmodsi4.c +++ b/contrib/compiler-rt/lib/divmodsi4.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/divsc3.c b/contrib/compiler-rt/lib/divsc3.c index a05f42902c0e..caa0c4075eb3 100644 --- a/contrib/compiler-rt/lib/divsc3.c +++ b/contrib/compiler-rt/lib/divsc3.c @@ -13,8 +13,7 @@ */ #include "int_lib.h" -#include -#include +#include "int_math.h" /* Returns: the quotient of (a + ib) / (c + id) */ @@ -22,35 +21,37 @@ float _Complex __divsc3(float __a, float __b, float __c, float __d) { int __ilogbw = 0; - float __logbw = logbf(fmaxf(fabsf(__c), fabsf(__d))); - if (isfinite(__logbw)) + float __logbw = crt_logbf(crt_fmaxf(crt_fabsf(__c), crt_fabsf(__d))); + if (crt_isfinite(__logbw)) { __ilogbw = (int)__logbw; - __c = scalbnf(__c, -__ilogbw); - __d = scalbnf(__d, -__ilogbw); + __c = crt_scalbnf(__c, -__ilogbw); + __d = crt_scalbnf(__d, -__ilogbw); } float __denom = __c * __c + __d * __d; float _Complex z; - __real__ z = scalbnf((__a * __c + __b * __d) / __denom, -__ilogbw); - __imag__ z = scalbnf((__b * __c - __a * __d) / __denom, -__ilogbw); - if (isnan(__real__ z) && isnan(__imag__ z)) + __real__ z = crt_scalbnf((__a * __c + __b * __d) / __denom, -__ilogbw); + __imag__ z = crt_scalbnf((__b * __c - __a * __d) / __denom, -__ilogbw); + if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) { - if ((__denom == 0) && (!isnan(__a) || !isnan(__b))) + if ((__denom == 0) && (!crt_isnan(__a) || !crt_isnan(__b))) { - __real__ z = copysignf(INFINITY, __c) * __a; - __imag__ z = copysignf(INFINITY, __c) * __b; + __real__ z = crt_copysignf(CRT_INFINITY, __c) * __a; + __imag__ z = crt_copysignf(CRT_INFINITY, __c) * __b; } - else if ((isinf(__a) || isinf(__b)) && isfinite(__c) && isfinite(__d)) + else if ((crt_isinf(__a) || crt_isinf(__b)) && + crt_isfinite(__c) && crt_isfinite(__d)) { - __a = copysignf(isinf(__a) ? 1 : 0, __a); - __b = copysignf(isinf(__b) ? 1 : 0, __b); - __real__ z = INFINITY * (__a * __c + __b * __d); - __imag__ z = INFINITY * (__b * __c - __a * __d); + __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a); + __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b); + __real__ z = CRT_INFINITY * (__a * __c + __b * __d); + __imag__ z = CRT_INFINITY * (__b * __c - __a * __d); } - else if (isinf(__logbw) && __logbw > 0 && isfinite(__a) && isfinite(__b)) + else if (crt_isinf(__logbw) && __logbw > 0 && + crt_isfinite(__a) && crt_isfinite(__b)) { - __c = copysignf(isinf(__c) ? 1 : 0, __c); - __d = copysignf(isinf(__d) ? 1 : 0, __d); + __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c); + __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d); __real__ z = 0 * (__a * __c + __b * __d); __imag__ z = 0 * (__b * __c - __a * __d); } diff --git a/contrib/compiler-rt/lib/divsf3.c b/contrib/compiler-rt/lib/divsf3.c index b73330793a08..a8230e4a0246 100644 --- a/contrib/compiler-rt/lib/divsf3.c +++ b/contrib/compiler-rt/lib/divsf3.c @@ -15,7 +15,6 @@ // underflow with correct rounding. // //===----------------------------------------------------------------------===// -#include "abi.h" #define SINGLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/divsi3.c b/contrib/compiler-rt/lib/divsi3.c index 01ef27473004..0d81cb80c37c 100644 --- a/contrib/compiler-rt/lib/divsi3.c +++ b/contrib/compiler-rt/lib/divsi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/divxc3.c b/contrib/compiler-rt/lib/divxc3.c index f054d4028392..5f240e956d84 100644 --- a/contrib/compiler-rt/lib/divxc3.c +++ b/contrib/compiler-rt/lib/divxc3.c @@ -14,8 +14,7 @@ #if !_ARCH_PPC #include "int_lib.h" -#include -#include +#include "int_math.h" /* Returns: the quotient of (a + ib) / (c + id) */ @@ -23,35 +22,37 @@ long double _Complex __divxc3(long double __a, long double __b, long double __c, long double __d) { int __ilogbw = 0; - long double __logbw = logbl(fmaxl(fabsl(__c), fabsl(__d))); - if (isfinite(__logbw)) + long double __logbw = crt_logbl(crt_fmaxl(crt_fabsl(__c), crt_fabsl(__d))); + if (crt_isfinite(__logbw)) { __ilogbw = (int)__logbw; - __c = scalbnl(__c, -__ilogbw); - __d = scalbnl(__d, -__ilogbw); + __c = crt_scalbnl(__c, -__ilogbw); + __d = crt_scalbnl(__d, -__ilogbw); } long double __denom = __c * __c + __d * __d; long double _Complex z; - __real__ z = scalbnl((__a * __c + __b * __d) / __denom, -__ilogbw); - __imag__ z = scalbnl((__b * __c - __a * __d) / __denom, -__ilogbw); - if (isnan(__real__ z) && isnan(__imag__ z)) + __real__ z = crt_scalbnl((__a * __c + __b * __d) / __denom, -__ilogbw); + __imag__ z = crt_scalbnl((__b * __c - __a * __d) / __denom, -__ilogbw); + if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) { - if ((__denom == 0) && (!isnan(__a) || !isnan(__b))) + if ((__denom == 0) && (!crt_isnan(__a) || !crt_isnan(__b))) { - __real__ z = copysignl(INFINITY, __c) * __a; - __imag__ z = copysignl(INFINITY, __c) * __b; + __real__ z = crt_copysignl(CRT_INFINITY, __c) * __a; + __imag__ z = crt_copysignl(CRT_INFINITY, __c) * __b; } - else if ((isinf(__a) || isinf(__b)) && isfinite(__c) && isfinite(__d)) + else if ((crt_isinf(__a) || crt_isinf(__b)) && + crt_isfinite(__c) && crt_isfinite(__d)) { - __a = copysignl(isinf(__a) ? 1 : 0, __a); - __b = copysignl(isinf(__b) ? 1 : 0, __b); - __real__ z = INFINITY * (__a * __c + __b * __d); - __imag__ z = INFINITY * (__b * __c - __a * __d); + __a = crt_copysignl(crt_isinf(__a) ? 1 : 0, __a); + __b = crt_copysignl(crt_isinf(__b) ? 1 : 0, __b); + __real__ z = CRT_INFINITY * (__a * __c + __b * __d); + __imag__ z = CRT_INFINITY * (__b * __c - __a * __d); } - else if (isinf(__logbw) && __logbw > 0 && isfinite(__a) && isfinite(__b)) + else if (crt_isinf(__logbw) && __logbw > 0 && + crt_isfinite(__a) && crt_isfinite(__b)) { - __c = copysignl(isinf(__c) ? 1 : 0, __c); - __d = copysignl(isinf(__d) ? 1 : 0, __d); + __c = crt_copysignl(crt_isinf(__c) ? 1 : 0, __c); + __d = crt_copysignl(crt_isinf(__d) ? 1 : 0, __d); __real__ z = 0 * (__a * __c + __b * __d); __imag__ z = 0 * (__b * __c - __a * __d); } diff --git a/contrib/compiler-rt/lib/enable_execute_stack.c b/contrib/compiler-rt/lib/enable_execute_stack.c index 7ab8e8d4155c..278ca246f537 100644 --- a/contrib/compiler-rt/lib/enable_execute_stack.c +++ b/contrib/compiler-rt/lib/enable_execute_stack.c @@ -8,7 +8,8 @@ * ===----------------------------------------------------------------------=== */ -#include +#include "int_lib.h" + #include /* #include "config.h" diff --git a/contrib/compiler-rt/lib/eprintf.c b/contrib/compiler-rt/lib/eprintf.c index 7c79174fcb57..b07d624b50f9 100644 --- a/contrib/compiler-rt/lib/eprintf.c +++ b/contrib/compiler-rt/lib/eprintf.c @@ -12,7 +12,6 @@ #include "int_lib.h" #include -#include /* diff --git a/contrib/compiler-rt/lib/extendsfdf2.c b/contrib/compiler-rt/lib/extendsfdf2.c index c0b628dffcdd..9466de780808 100644 --- a/contrib/compiler-rt/lib/extendsfdf2.c +++ b/contrib/compiler-rt/lib/extendsfdf2.c @@ -38,10 +38,7 @@ // //===----------------------------------------------------------------------===// -#include -#include - -#include "abi.h" +#include "int_lib.h" typedef float src_t; typedef uint32_t src_rep_t; diff --git a/contrib/compiler-rt/lib/ffsdi2.c b/contrib/compiler-rt/lib/ffsdi2.c index 89f1b7bf478a..a5ac9900ff10 100644 --- a/contrib/compiler-rt/lib/ffsdi2.c +++ b/contrib/compiler-rt/lib/ffsdi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/fixdfdi.c b/contrib/compiler-rt/lib/fixdfdi.c index 85a456d11229..c6732dbbb72d 100644 --- a/contrib/compiler-rt/lib/fixdfdi.c +++ b/contrib/compiler-rt/lib/fixdfdi.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/fixdfsi.c b/contrib/compiler-rt/lib/fixdfsi.c index fbcf1470b719..3d4379e8f902 100644 --- a/contrib/compiler-rt/lib/fixdfsi.c +++ b/contrib/compiler-rt/lib/fixdfsi.c @@ -12,7 +12,6 @@ // conversion is undefined for out of range values in the C standard. // //===----------------------------------------------------------------------===// -#include "abi.h" #define DOUBLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/fixsfdi.c b/contrib/compiler-rt/lib/fixsfdi.c index d80e33eb74c5..81ceab024809 100644 --- a/contrib/compiler-rt/lib/fixsfdi.c +++ b/contrib/compiler-rt/lib/fixsfdi.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/fixsfsi.c b/contrib/compiler-rt/lib/fixsfsi.c index 67749a56778d..f6de609541e0 100644 --- a/contrib/compiler-rt/lib/fixsfsi.c +++ b/contrib/compiler-rt/lib/fixsfsi.c @@ -12,7 +12,6 @@ // conversion is undefined for out of range values in the C standard. // //===----------------------------------------------------------------------===// -#include "abi.h" #define SINGLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/fixunsdfdi.c b/contrib/compiler-rt/lib/fixunsdfdi.c index d80b84a8d669..c0ff1606ab3f 100644 --- a/contrib/compiler-rt/lib/fixunsdfdi.c +++ b/contrib/compiler-rt/lib/fixunsdfdi.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/fixunsdfsi.c b/contrib/compiler-rt/lib/fixunsdfsi.c index ecdfb5d622e6..2ce4999752fa 100644 --- a/contrib/compiler-rt/lib/fixunsdfsi.c +++ b/contrib/compiler-rt/lib/fixunsdfsi.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/fixunssfdi.c b/contrib/compiler-rt/lib/fixunssfdi.c index 150642045bdc..09078db2c507 100644 --- a/contrib/compiler-rt/lib/fixunssfdi.c +++ b/contrib/compiler-rt/lib/fixunssfdi.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" /* Returns: convert a to a unsigned long long, rounding toward zero. diff --git a/contrib/compiler-rt/lib/fixunssfsi.c b/contrib/compiler-rt/lib/fixunssfsi.c index dbaa5115b2ba..d80ed1824748 100644 --- a/contrib/compiler-rt/lib/fixunssfsi.c +++ b/contrib/compiler-rt/lib/fixunssfsi.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/floatdidf.c b/contrib/compiler-rt/lib/floatdidf.c index 5ba952635030..2af9e106d935 100644 --- a/contrib/compiler-rt/lib/floatdidf.c +++ b/contrib/compiler-rt/lib/floatdidf.c @@ -11,10 +11,8 @@ * *===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: convert a to a double, rounding toward even. */ @@ -30,7 +28,6 @@ ARM_EABI_FNALIAS(l2d, floatdidf); /* Support for systems that have hardware floating-point; we'll set the inexact flag * as a side-effect of this computation. */ -#include COMPILER_RT_ABI double __floatdidf(di_int a) diff --git a/contrib/compiler-rt/lib/floatdisf.c b/contrib/compiler-rt/lib/floatdisf.c index 4dc13cab4778..660730793289 100644 --- a/contrib/compiler-rt/lib/floatdisf.c +++ b/contrib/compiler-rt/lib/floatdisf.c @@ -12,9 +12,6 @@ *===----------------------------------------------------------------------=== */ -#include "abi.h" -#include - /* Returns: convert a to a float, rounding toward even.*/ /* Assumption: float is a IEEE 32 bit floating point type diff --git a/contrib/compiler-rt/lib/floatsidf.c b/contrib/compiler-rt/lib/floatsidf.c index 72273353ac55..74cb66b2aacf 100644 --- a/contrib/compiler-rt/lib/floatsidf.c +++ b/contrib/compiler-rt/lib/floatsidf.c @@ -12,7 +12,6 @@ // mode. // //===----------------------------------------------------------------------===// -#include "abi.h" #define DOUBLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/floatsisf.c b/contrib/compiler-rt/lib/floatsisf.c index e5250ffd6021..a981391b0c0f 100644 --- a/contrib/compiler-rt/lib/floatsisf.c +++ b/contrib/compiler-rt/lib/floatsisf.c @@ -12,7 +12,6 @@ // mode. // //===----------------------------------------------------------------------===// -#include "abi.h" #define SINGLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/floattidf.c b/contrib/compiler-rt/lib/floattidf.c index f61844d5e59e..3cafea8a2e7d 100644 --- a/contrib/compiler-rt/lib/floattidf.c +++ b/contrib/compiler-rt/lib/floattidf.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: convert a to a double, rounding toward even.*/ diff --git a/contrib/compiler-rt/lib/floattisf.c b/contrib/compiler-rt/lib/floattisf.c index 7eb761d7ab2a..ab33e4aada51 100644 --- a/contrib/compiler-rt/lib/floattisf.c +++ b/contrib/compiler-rt/lib/floattisf.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: convert a to a float, rounding toward even. */ diff --git a/contrib/compiler-rt/lib/floattixf.c b/contrib/compiler-rt/lib/floattixf.c index e4bcb5ff0092..852acc707465 100644 --- a/contrib/compiler-rt/lib/floattixf.c +++ b/contrib/compiler-rt/lib/floattixf.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: convert a to a long double, rounding toward even. */ diff --git a/contrib/compiler-rt/lib/floatundidf.c b/contrib/compiler-rt/lib/floatundidf.c index e74e9d8d2fdd..67917017ec71 100644 --- a/contrib/compiler-rt/lib/floatundidf.c +++ b/contrib/compiler-rt/lib/floatundidf.c @@ -12,9 +12,6 @@ * ===----------------------------------------------------------------------=== */ -#include "abi.h" -#include - /* Returns: convert a to a double, rounding toward even. */ /* Assumption: double is a IEEE 64 bit floating point type @@ -32,7 +29,6 @@ ARM_EABI_FNALIAS(ul2d, floatundidf); * as a side-effect of this computation. */ -#include COMPILER_RT_ABI double __floatundidf(du_int a) diff --git a/contrib/compiler-rt/lib/floatundisf.c b/contrib/compiler-rt/lib/floatundisf.c index eea45a745949..1bf5fbb45436 100644 --- a/contrib/compiler-rt/lib/floatundisf.c +++ b/contrib/compiler-rt/lib/floatundisf.c @@ -12,9 +12,6 @@ *===----------------------------------------------------------------------=== */ -#include "abi.h" -#include - /* Returns: convert a to a float, rounding toward even. */ /* Assumption: float is a IEEE 32 bit floating point type diff --git a/contrib/compiler-rt/lib/floatunsidf.c b/contrib/compiler-rt/lib/floatunsidf.c index 37562996a41b..0722248ddfeb 100644 --- a/contrib/compiler-rt/lib/floatunsidf.c +++ b/contrib/compiler-rt/lib/floatunsidf.c @@ -12,7 +12,6 @@ // mode. // //===----------------------------------------------------------------------===// -#include "abi.h" #define DOUBLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/floatunsisf.c b/contrib/compiler-rt/lib/floatunsisf.c index 14ef10307f79..3dc1cd442ba5 100644 --- a/contrib/compiler-rt/lib/floatunsisf.c +++ b/contrib/compiler-rt/lib/floatunsisf.c @@ -12,7 +12,6 @@ // mode. // //===----------------------------------------------------------------------===// -#include "abi.h" #define SINGLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/floatuntidf.c b/contrib/compiler-rt/lib/floatuntidf.c index bab7483d99e0..d0889a0744f0 100644 --- a/contrib/compiler-rt/lib/floatuntidf.c +++ b/contrib/compiler-rt/lib/floatuntidf.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: convert a to a double, rounding toward even. */ diff --git a/contrib/compiler-rt/lib/floatuntisf.c b/contrib/compiler-rt/lib/floatuntisf.c index 0ab6d7e56f58..f5527583ce57 100644 --- a/contrib/compiler-rt/lib/floatuntisf.c +++ b/contrib/compiler-rt/lib/floatuntisf.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: convert a to a float, rounding toward even. */ diff --git a/contrib/compiler-rt/lib/floatuntixf.c b/contrib/compiler-rt/lib/floatuntixf.c index a84709aef60b..00c07d8ed4e6 100644 --- a/contrib/compiler-rt/lib/floatuntixf.c +++ b/contrib/compiler-rt/lib/floatuntixf.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: convert a to a long double, rounding toward even. */ diff --git a/contrib/compiler-rt/lib/fp_lib.h b/contrib/compiler-rt/lib/fp_lib.h index 6c9455ace0e6..de5f17fde191 100644 --- a/contrib/compiler-rt/lib/fp_lib.h +++ b/contrib/compiler-rt/lib/fp_lib.h @@ -24,6 +24,7 @@ #include #include #include +#include "int_lib.h" #if defined SINGLE_PRECISION diff --git a/contrib/compiler-rt/lib/gcc_personality_v0.c b/contrib/compiler-rt/lib/gcc_personality_v0.c index c840eef4842a..8a708cae5974 100644 --- a/contrib/compiler-rt/lib/gcc_personality_v0.c +++ b/contrib/compiler-rt/lib/gcc_personality_v0.c @@ -9,10 +9,6 @@ * */ -#include -#include -#include - #include "int_lib.h" /* @@ -202,7 +198,7 @@ _Unwind_Reason_Code __gcc_personality_v0(int version, _Unwind_Action actions, /* There is nothing to do if there is no LSDA for this frame. */ const uint8_t* lsda = _Unwind_GetLanguageSpecificData(context); - if ( lsda == NULL ) + if ( lsda == (uint8_t*) 0 ) return _URC_CONTINUE_UNWIND; uintptr_t pc = _Unwind_GetIP(context)-1; diff --git a/contrib/compiler-rt/lib/endianness.h b/contrib/compiler-rt/lib/int_endianness.h similarity index 90% rename from contrib/compiler-rt/lib/endianness.h rename to contrib/compiler-rt/lib/int_endianness.h index 9b7e7c1f09c4..9466ed451802 100644 --- a/contrib/compiler-rt/lib/endianness.h +++ b/contrib/compiler-rt/lib/int_endianness.h @@ -1,4 +1,4 @@ -/* ===-- endianness.h - configuration header for compiler-rt ---------------=== +/* ===-- int_endianness.h - configuration header for compiler-rt ------------=== * * The LLVM Compiler Infrastructure * @@ -13,13 +13,8 @@ * ===----------------------------------------------------------------------=== */ -#ifndef ENDIANNESS_H -#define ENDIANNESS_H - -/* - * Known limitations: - * Middle endian systems are not handled currently. - */ +#ifndef INT_ENDIANNESS_H +#define INT_ENDIANNESS_H #if defined(__SVR4) && defined(__sun) #include @@ -91,4 +86,4 @@ #error Unable to determine endian #endif /* Check we found an endianness correctly. */ -#endif /* ENDIANNESS_H */ +#endif /* INT_ENDIANNESS_H */ diff --git a/contrib/compiler-rt/lib/int_lib.h b/contrib/compiler-rt/lib/int_lib.h index e1fd6b73dc7f..a87426c513c6 100644 --- a/contrib/compiler-rt/lib/int_lib.h +++ b/contrib/compiler-rt/lib/int_lib.h @@ -16,141 +16,31 @@ #ifndef INT_LIB_H #define INT_LIB_H -/* Assumption: signed integral is 2's complement */ -/* Assumption: right shift of signed negative is arithmetic shift */ +/* Assumption: Signed integral is 2's complement. */ +/* Assumption: Right shift of signed negative is arithmetic shift. */ +/* Assumption: Endianness is little or big (not mixed). */ -#include -#include -#include "endianness.h" -#include +/* ABI macro definitions */ -/* If compiling for kernel use, call panic() instead of abort(). */ -#ifdef KERNEL_USE -extern void panic (const char *, ...); -#define compilerrt_abort() \ - panic("%s:%d: abort in %s", __FILE__, __LINE__, __FUNCTION__) +#if __ARM_EABI__ +# define ARM_EABI_FNALIAS(aeabi_name, name) \ + void __aeabi_##aeabi_name() __attribute__((alias("__" #name))); +# define COMPILER_RT_ABI __attribute__((pcs("aapcs"))) #else -#define compilerrt_abort() abort() +# define ARM_EABI_FNALIAS(aeabi_name, name) +# define COMPILER_RT_ABI #endif -#if !defined(INFINITY) && defined(HUGE_VAL) -#define INFINITY HUGE_VAL -#endif /* INFINITY */ +/* Include the standard compiler builtin headers we use functionality from. */ +#include +#include +#include +#include -typedef int si_int; -typedef unsigned su_int; +/* Include the commonly used internal type definitions. */ +#include "int_types.h" -typedef long long di_int; -typedef unsigned long long du_int; - -typedef union -{ - di_int all; - struct - { -#if _YUGA_LITTLE_ENDIAN - su_int low; - si_int high; -#else - si_int high; - su_int low; -#endif /* _YUGA_LITTLE_ENDIAN */ - }s; -} dwords; - -typedef union -{ - du_int all; - struct - { -#if _YUGA_LITTLE_ENDIAN - su_int low; - su_int high; -#else - su_int high; - su_int low; -#endif /* _YUGA_LITTLE_ENDIAN */ - }s; -} udwords; - -#if __x86_64 - -typedef int ti_int __attribute__ ((mode (TI))); -typedef unsigned tu_int __attribute__ ((mode (TI))); - -typedef union -{ - ti_int all; - struct - { -#if _YUGA_LITTLE_ENDIAN - du_int low; - di_int high; -#else - di_int high; - du_int low; -#endif /* _YUGA_LITTLE_ENDIAN */ - }s; -} twords; - -typedef union -{ - tu_int all; - struct - { -#if _YUGA_LITTLE_ENDIAN - du_int low; - du_int high; -#else - du_int high; - du_int low; -#endif /* _YUGA_LITTLE_ENDIAN */ - }s; -} utwords; - -static inline ti_int make_ti(di_int h, di_int l) { - twords r; - r.s.high = h; - r.s.low = l; - return r.all; -} - -static inline tu_int make_tu(du_int h, du_int l) { - utwords r; - r.s.high = h; - r.s.low = l; - return r.all; -} - -#endif /* __x86_64 */ - -typedef union -{ - su_int u; - float f; -} float_bits; - -typedef union -{ - udwords u; - double f; -} double_bits; - -typedef struct -{ -#if _YUGA_LITTLE_ENDIAN - udwords low; - udwords high; -#else - udwords high; - udwords low; -#endif /* _YUGA_LITTLE_ENDIAN */ -} uqwords; - -typedef union -{ - uqwords u; - long double f; -} long_double_bits; +/* Include internal utility function declarations. */ +#include "int_util.h" #endif /* INT_LIB_H */ diff --git a/contrib/compiler-rt/lib/int_math.h b/contrib/compiler-rt/lib/int_math.h new file mode 100644 index 000000000000..d6b4bdae162b --- /dev/null +++ b/contrib/compiler-rt/lib/int_math.h @@ -0,0 +1,67 @@ +/* ===-- int_math.h - internal math inlines ---------------------------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===-----------------------------------------------------------------------=== + * + * This file is not part of the interface of this library. + * + * This file defines substitutes for the libm functions used in some of the + * compiler-rt implementations, defined in such a way that there is not a direct + * dependency on libm or math.h. Instead, we use the compiler builtin versions + * where available. This reduces our dependencies on the system SDK by foisting + * the responsibility onto the compiler. + * + * ===-----------------------------------------------------------------------=== + */ + +#ifndef INT_MATH_H +#define INT_MATH_H + +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif + +#define CRT_INFINITY __builtin_huge_valf() + +#define crt_isinf(x) __builtin_isinf((x)) +#define crt_isnan(x) __builtin_isnan((x)) + +/* Define crt_isfinite in terms of the builtin if available, otherwise provide + * an alternate version in terms of our other functions. This supports some + * versions of GCC which didn't have __builtin_isfinite. + */ +#if __has_builtin(__builtin_isfinite) +# define crt_isfinite(x) __builtin_isfinite((x)) +#else +# define crt_isfinite(x) \ + __extension__(({ \ + __typeof((x)) x_ = (x); \ + !crt_isinf(x_) && !crt_isnan(x_); \ + })) +#endif + +#define crt_copysign(x, y) __builtin_copysign((x), (y)) +#define crt_copysignf(x, y) __builtin_copysignf((x), (y)) +#define crt_copysignl(x, y) __builtin_copysignl((x), (y)) + +#define crt_fabs(x) __builtin_fabs((x)) +#define crt_fabsf(x) __builtin_fabsf((x)) +#define crt_fabsl(x) __builtin_fabsl((x)) + +#define crt_fmax(x, y) __builtin_fmax((x), (y)) +#define crt_fmaxf(x, y) __builtin_fmaxf((x), (y)) +#define crt_fmaxl(x, y) __builtin_fmaxl((x), (y)) + +#define crt_logb(x) __builtin_logb((x)) +#define crt_logbf(x) __builtin_logbf((x)) +#define crt_logbl(x) __builtin_logbl((x)) + +#define crt_scalbn(x, y) __builtin_scalbn((x), (y)) +#define crt_scalbnf(x, y) __builtin_scalbnf((x), (y)) +#define crt_scalbnl(x, y) __builtin_scalbnl((x), (y)) + +#endif /* INT_MATH_H */ diff --git a/contrib/compiler-rt/lib/int_types.h b/contrib/compiler-rt/lib/int_types.h new file mode 100644 index 000000000000..fcce390f9a9b --- /dev/null +++ b/contrib/compiler-rt/lib/int_types.h @@ -0,0 +1,140 @@ +/* ===-- int_lib.h - configuration header for compiler-rt -----------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===----------------------------------------------------------------------=== + * + * This file is not part of the interface of this library. + * + * This file defines various standard types, most importantly a number of unions + * used to access parts of larger types. + * + * ===----------------------------------------------------------------------=== + */ + +#ifndef INT_TYPES_H +#define INT_TYPES_H + +#include "int_endianness.h" + +typedef int si_int; +typedef unsigned su_int; + +typedef long long di_int; +typedef unsigned long long du_int; + +typedef union +{ + di_int all; + struct + { +#if _YUGA_LITTLE_ENDIAN + su_int low; + si_int high; +#else + si_int high; + su_int low; +#endif /* _YUGA_LITTLE_ENDIAN */ + }s; +} dwords; + +typedef union +{ + du_int all; + struct + { +#if _YUGA_LITTLE_ENDIAN + su_int low; + su_int high; +#else + su_int high; + su_int low; +#endif /* _YUGA_LITTLE_ENDIAN */ + }s; +} udwords; + +#if __x86_64 + +typedef int ti_int __attribute__ ((mode (TI))); +typedef unsigned tu_int __attribute__ ((mode (TI))); + +typedef union +{ + ti_int all; + struct + { +#if _YUGA_LITTLE_ENDIAN + du_int low; + di_int high; +#else + di_int high; + du_int low; +#endif /* _YUGA_LITTLE_ENDIAN */ + }s; +} twords; + +typedef union +{ + tu_int all; + struct + { +#if _YUGA_LITTLE_ENDIAN + du_int low; + du_int high; +#else + du_int high; + du_int low; +#endif /* _YUGA_LITTLE_ENDIAN */ + }s; +} utwords; + +static inline ti_int make_ti(di_int h, di_int l) { + twords r; + r.s.high = h; + r.s.low = l; + return r.all; +} + +static inline tu_int make_tu(du_int h, du_int l) { + utwords r; + r.s.high = h; + r.s.low = l; + return r.all; +} + +#endif /* __x86_64 */ + +typedef union +{ + su_int u; + float f; +} float_bits; + +typedef union +{ + udwords u; + double f; +} double_bits; + +typedef struct +{ +#if _YUGA_LITTLE_ENDIAN + udwords low; + udwords high; +#else + udwords high; + udwords low; +#endif /* _YUGA_LITTLE_ENDIAN */ +} uqwords; + +typedef union +{ + uqwords u; + long double f; +} long_double_bits; + +#endif /* INT_TYPES_H */ + diff --git a/contrib/compiler-rt/lib/int_util.c b/contrib/compiler-rt/lib/int_util.c new file mode 100644 index 000000000000..f19476864b16 --- /dev/null +++ b/contrib/compiler-rt/lib/int_util.c @@ -0,0 +1,43 @@ +/* ===-- int_util.c - Implement internal utilities --------------------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===----------------------------------------------------------------------=== + */ + +#include "int_util.h" +#include "int_lib.h" + +/* NOTE: The definitions in this file are declared weak because we clients to be + * able to arbitrarily package individual functions into separate .a files. If + * we did not declare these weak, some link situations might end up seeing + * duplicate strong definitions of the same symbol. + * + * We can't use this solution for kernel use (which may not support weak), but + * currently expect that when built for kernel use all the functionality is + * packaged into a single library. + */ + +#ifdef KERNEL_USE + +extern void panic(const char *, ...) __attribute__((noreturn)); +__attribute__((visibility("hidden"))) +void compilerrt_abort_impl(const char *file, int line, const char *function) { + panic("%s:%d: abort in %s", file, line, function); +} + +#else + +/* Get the system definition of abort() */ +#include + +__attribute__((weak)) +__attribute__((visibility("hidden"))) +void compilerrt_abort_impl(const char *file, int line, const char *function) { + abort(); +} + +#endif diff --git a/contrib/compiler-rt/lib/int_util.h b/contrib/compiler-rt/lib/int_util.h new file mode 100644 index 000000000000..17d77223c348 --- /dev/null +++ b/contrib/compiler-rt/lib/int_util.h @@ -0,0 +1,32 @@ +/* ===-- int_util.h - internal utility functions ----------------------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===-----------------------------------------------------------------------=== + * + * This file is not part of the interface of this library. + * + * This file defines non-inline utilities which are available for use in the + * library. The function definitions themselves are all contained in int_util.c + * which will always be compiled into any compiler-rt library. + * + * ===-----------------------------------------------------------------------=== + */ + +#ifndef INT_UTIL_H +#define INT_UTIL_H + +/** \brief Trigger a program abort (or panic for kernel code). */ +#define compilerrt_abort() compilerrt_abort_impl(__FILE__, __LINE__, \ + __FUNCTION__) +void compilerrt_abort_impl(const char *file, int line, + const char *function) +#ifndef KERNEL_USE + __attribute__((weak)) +#endif + __attribute__((noreturn)) __attribute__((visibility("hidden"))); + +#endif /* INT_UTIL_H */ diff --git a/contrib/compiler-rt/lib/lshrdi3.c b/contrib/compiler-rt/lib/lshrdi3.c index 911edb191422..8af3e0c1a61b 100644 --- a/contrib/compiler-rt/lib/lshrdi3.c +++ b/contrib/compiler-rt/lib/lshrdi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/moddi3.c b/contrib/compiler-rt/lib/moddi3.c index af0a80832aef..2f3b9cc4f291 100644 --- a/contrib/compiler-rt/lib/moddi3.c +++ b/contrib/compiler-rt/lib/moddi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/modsi3.c b/contrib/compiler-rt/lib/modsi3.c index 05ce806f7105..d16213c49038 100644 --- a/contrib/compiler-rt/lib/modsi3.c +++ b/contrib/compiler-rt/lib/modsi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/muldc3.c b/contrib/compiler-rt/lib/muldc3.c index 9f9bd2aaa2bb..5f4a6d16ebf0 100644 --- a/contrib/compiler-rt/lib/muldc3.c +++ b/contrib/compiler-rt/lib/muldc3.c @@ -13,8 +13,7 @@ */ #include "int_lib.h" -#include -#include +#include "int_math.h" /* Returns: the product of a + ib and c + id */ @@ -28,46 +27,46 @@ __muldc3(double __a, double __b, double __c, double __d) double _Complex z; __real__ z = __ac - __bd; __imag__ z = __ad + __bc; - if (isnan(__real__ z) && isnan(__imag__ z)) + if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) { int __recalc = 0; - if (isinf(__a) || isinf(__b)) + if (crt_isinf(__a) || crt_isinf(__b)) { - __a = copysign(isinf(__a) ? 1 : 0, __a); - __b = copysign(isinf(__b) ? 1 : 0, __b); - if (isnan(__c)) - __c = copysign(0, __c); - if (isnan(__d)) - __d = copysign(0, __d); + __a = crt_copysign(crt_isinf(__a) ? 1 : 0, __a); + __b = crt_copysign(crt_isinf(__b) ? 1 : 0, __b); + if (crt_isnan(__c)) + __c = crt_copysign(0, __c); + if (crt_isnan(__d)) + __d = crt_copysign(0, __d); __recalc = 1; } - if (isinf(__c) || isinf(__d)) + if (crt_isinf(__c) || crt_isinf(__d)) { - __c = copysign(isinf(__c) ? 1 : 0, __c); - __d = copysign(isinf(__d) ? 1 : 0, __d); - if (isnan(__a)) - __a = copysign(0, __a); - if (isnan(__b)) - __b = copysign(0, __b); + __c = crt_copysign(crt_isinf(__c) ? 1 : 0, __c); + __d = crt_copysign(crt_isinf(__d) ? 1 : 0, __d); + if (crt_isnan(__a)) + __a = crt_copysign(0, __a); + if (crt_isnan(__b)) + __b = crt_copysign(0, __b); __recalc = 1; } - if (!__recalc && (isinf(__ac) || isinf(__bd) || - isinf(__ad) || isinf(__bc))) + if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || + crt_isinf(__ad) || crt_isinf(__bc))) { - if (isnan(__a)) - __a = copysign(0, __a); - if (isnan(__b)) - __b = copysign(0, __b); - if (isnan(__c)) - __c = copysign(0, __c); - if (isnan(__d)) - __d = copysign(0, __d); + if (crt_isnan(__a)) + __a = crt_copysign(0, __a); + if (crt_isnan(__b)) + __b = crt_copysign(0, __b); + if (crt_isnan(__c)) + __c = crt_copysign(0, __c); + if (crt_isnan(__d)) + __d = crt_copysign(0, __d); __recalc = 1; } if (__recalc) { - __real__ z = INFINITY * (__a * __c - __b * __d); - __imag__ z = INFINITY * (__a * __d + __b * __c); + __real__ z = CRT_INFINITY * (__a * __c - __b * __d); + __imag__ z = CRT_INFINITY * (__a * __d + __b * __c); } } return z; diff --git a/contrib/compiler-rt/lib/muldf3.c b/contrib/compiler-rt/lib/muldf3.c index f402cfb39d38..86d72d883e23 100644 --- a/contrib/compiler-rt/lib/muldf3.c +++ b/contrib/compiler-rt/lib/muldf3.c @@ -11,7 +11,6 @@ // with the IEEE-754 default rounding (to nearest, ties to even). // //===----------------------------------------------------------------------===// -#include "abi.h" #define DOUBLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/muldi3.c b/contrib/compiler-rt/lib/muldi3.c index e6322bf5df82..3e996302d359 100644 --- a/contrib/compiler-rt/lib/muldi3.c +++ b/contrib/compiler-rt/lib/muldi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/mulodi4.c b/contrib/compiler-rt/lib/mulodi4.c new file mode 100644 index 000000000000..0c1b5cdae768 --- /dev/null +++ b/contrib/compiler-rt/lib/mulodi4.c @@ -0,0 +1,58 @@ +/*===-- mulodi4.c - Implement __mulodi4 -----------------------------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===----------------------------------------------------------------------=== + * + * This file implements __mulodi4 for the compiler_rt library. + * + * ===----------------------------------------------------------------------=== + */ + +#include "int_lib.h" + +/* Returns: a * b */ + +/* Effects: sets *overflow to 1 if a * b overflows */ + +di_int +__mulodi4(di_int a, di_int b, int* overflow) +{ + const int N = (int)(sizeof(di_int) * CHAR_BIT); + const di_int MIN = (di_int)1 << (N-1); + const di_int MAX = ~MIN; + *overflow = 0; + di_int result = a * b; + if (a == MIN) + { + if (b != 0 && b != 1) + *overflow = 1; + return result; + } + if (b == MIN) + { + if (a != 0 && a != 1) + *overflow = 1; + return result; + } + di_int sa = a >> (N - 1); + di_int abs_a = (a ^ sa) - sa; + di_int sb = b >> (N - 1); + di_int abs_b = (b ^ sb) - sb; + if (abs_a < 2 || abs_b < 2) + return result; + if (sa == sb) + { + if (abs_a > MAX / abs_b) + *overflow = 1; + } + else + { + if (abs_a > MIN / -abs_b) + *overflow = 1; + } + return result; +} diff --git a/contrib/compiler-rt/lib/mulosi4.c b/contrib/compiler-rt/lib/mulosi4.c new file mode 100644 index 000000000000..f3398d1fc7bd --- /dev/null +++ b/contrib/compiler-rt/lib/mulosi4.c @@ -0,0 +1,58 @@ +/*===-- mulosi4.c - Implement __mulosi4 -----------------------------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===----------------------------------------------------------------------=== + * + * This file implements __mulosi4 for the compiler_rt library. + * + * ===----------------------------------------------------------------------=== + */ + +#include "int_lib.h" + +/* Returns: a * b */ + +/* Effects: sets *overflow to 1 if a * b overflows */ + +si_int +__mulosi4(si_int a, si_int b, int* overflow) +{ + const int N = (int)(sizeof(si_int) * CHAR_BIT); + const si_int MIN = (si_int)1 << (N-1); + const si_int MAX = ~MIN; + *overflow = 0; + si_int result = a * b; + if (a == MIN) + { + if (b != 0 && b != 1) + *overflow = 1; + return result; + } + if (b == MIN) + { + if (a != 0 && a != 1) + *overflow = 1; + return result; + } + si_int sa = a >> (N - 1); + si_int abs_a = (a ^ sa) - sa; + si_int sb = b >> (N - 1); + si_int abs_b = (b ^ sb) - sb; + if (abs_a < 2 || abs_b < 2) + return result; + if (sa == sb) + { + if (abs_a > MAX / abs_b) + *overflow = 1; + } + else + { + if (abs_a > MIN / -abs_b) + *overflow = 1; + } + return result; +} diff --git a/contrib/compiler-rt/lib/muloti4.c b/contrib/compiler-rt/lib/muloti4.c new file mode 100644 index 000000000000..1fcd0baf799f --- /dev/null +++ b/contrib/compiler-rt/lib/muloti4.c @@ -0,0 +1,62 @@ +/*===-- muloti4.c - Implement __muloti4 -----------------------------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===----------------------------------------------------------------------=== + * + * This file implements __muloti4 for the compiler_rt library. + * + * ===----------------------------------------------------------------------=== + */ + +#if __x86_64 + +#include "int_lib.h" + +/* Returns: a * b */ + +/* Effects: sets *overflow to 1 if a * b overflows */ + +ti_int +__muloti4(ti_int a, ti_int b, int* overflow) +{ + const int N = (int)(sizeof(ti_int) * CHAR_BIT); + const ti_int MIN = (ti_int)1 << (N-1); + const ti_int MAX = ~MIN; + *overflow = 0; + ti_int result = a * b; + if (a == MIN) + { + if (b != 0 && b != 1) + *overflow = 1; + return result; + } + if (b == MIN) + { + if (a != 0 && a != 1) + *overflow = 1; + return result; + } + ti_int sa = a >> (N - 1); + ti_int abs_a = (a ^ sa) - sa; + ti_int sb = b >> (N - 1); + ti_int abs_b = (b ^ sb) - sb; + if (abs_a < 2 || abs_b < 2) + return result; + if (sa == sb) + { + if (abs_a > MAX / abs_b) + *overflow = 1; + } + else + { + if (abs_a > MIN / -abs_b) + *overflow = 1; + } + return result; +} + +#endif diff --git a/contrib/compiler-rt/lib/mulsc3.c b/contrib/compiler-rt/lib/mulsc3.c index a878ba1f39b2..6d433fbc45f9 100644 --- a/contrib/compiler-rt/lib/mulsc3.c +++ b/contrib/compiler-rt/lib/mulsc3.c @@ -13,8 +13,7 @@ */ #include "int_lib.h" -#include -#include +#include "int_math.h" /* Returns: the product of a + ib and c + id */ @@ -28,46 +27,46 @@ __mulsc3(float __a, float __b, float __c, float __d) float _Complex z; __real__ z = __ac - __bd; __imag__ z = __ad + __bc; - if (isnan(__real__ z) && isnan(__imag__ z)) + if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) { int __recalc = 0; - if (isinf(__a) || isinf(__b)) + if (crt_isinf(__a) || crt_isinf(__b)) { - __a = copysignf(isinf(__a) ? 1 : 0, __a); - __b = copysignf(isinf(__b) ? 1 : 0, __b); - if (isnan(__c)) - __c = copysignf(0, __c); - if (isnan(__d)) - __d = copysignf(0, __d); + __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a); + __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b); + if (crt_isnan(__c)) + __c = crt_copysignf(0, __c); + if (crt_isnan(__d)) + __d = crt_copysignf(0, __d); __recalc = 1; } - if (isinf(__c) || isinf(__d)) + if (crt_isinf(__c) || crt_isinf(__d)) { - __c = copysignf(isinf(__c) ? 1 : 0, __c); - __d = copysignf(isinf(__d) ? 1 : 0, __d); - if (isnan(__a)) - __a = copysignf(0, __a); - if (isnan(__b)) - __b = copysignf(0, __b); + __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c); + __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d); + if (crt_isnan(__a)) + __a = crt_copysignf(0, __a); + if (crt_isnan(__b)) + __b = crt_copysignf(0, __b); __recalc = 1; } - if (!__recalc && (isinf(__ac) || isinf(__bd) || - isinf(__ad) || isinf(__bc))) + if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || + crt_isinf(__ad) || crt_isinf(__bc))) { - if (isnan(__a)) - __a = copysignf(0, __a); - if (isnan(__b)) - __b = copysignf(0, __b); - if (isnan(__c)) - __c = copysignf(0, __c); - if (isnan(__d)) - __d = copysignf(0, __d); + if (crt_isnan(__a)) + __a = crt_copysignf(0, __a); + if (crt_isnan(__b)) + __b = crt_copysignf(0, __b); + if (crt_isnan(__c)) + __c = crt_copysignf(0, __c); + if (crt_isnan(__d)) + __d = crt_copysignf(0, __d); __recalc = 1; } if (__recalc) { - __real__ z = INFINITY * (__a * __c - __b * __d); - __imag__ z = INFINITY * (__a * __d + __b * __c); + __real__ z = CRT_INFINITY * (__a * __c - __b * __d); + __imag__ z = CRT_INFINITY * (__a * __d + __b * __c); } } return z; diff --git a/contrib/compiler-rt/lib/mulsf3.c b/contrib/compiler-rt/lib/mulsf3.c index bf46e148167b..fce2fd4fb2a3 100644 --- a/contrib/compiler-rt/lib/mulsf3.c +++ b/contrib/compiler-rt/lib/mulsf3.c @@ -11,7 +11,6 @@ // with the IEEE-754 default rounding (to nearest, ties to even). // //===----------------------------------------------------------------------===// -#include "abi.h" #define SINGLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/mulvdi3.c b/contrib/compiler-rt/lib/mulvdi3.c index fcbb5b3f6eef..bcc8e659be48 100644 --- a/contrib/compiler-rt/lib/mulvdi3.c +++ b/contrib/compiler-rt/lib/mulvdi3.c @@ -13,7 +13,6 @@ */ #include "int_lib.h" -#include /* Returns: a * b */ diff --git a/contrib/compiler-rt/lib/mulvsi3.c b/contrib/compiler-rt/lib/mulvsi3.c index 6271cd44a3c2..d372b20175ed 100644 --- a/contrib/compiler-rt/lib/mulvsi3.c +++ b/contrib/compiler-rt/lib/mulvsi3.c @@ -13,7 +13,6 @@ */ #include "int_lib.h" -#include /* Returns: a * b */ diff --git a/contrib/compiler-rt/lib/mulvti3.c b/contrib/compiler-rt/lib/mulvti3.c index 7da9187ffc7d..ae65cf8fee19 100644 --- a/contrib/compiler-rt/lib/mulvti3.c +++ b/contrib/compiler-rt/lib/mulvti3.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: a * b */ diff --git a/contrib/compiler-rt/lib/mulxc3.c b/contrib/compiler-rt/lib/mulxc3.c index b5ae86554805..cec0573688ad 100644 --- a/contrib/compiler-rt/lib/mulxc3.c +++ b/contrib/compiler-rt/lib/mulxc3.c @@ -15,8 +15,7 @@ #if !_ARCH_PPC #include "int_lib.h" -#include -#include +#include "int_math.h" /* Returns: the product of a + ib and c + id */ @@ -30,46 +29,46 @@ __mulxc3(long double __a, long double __b, long double __c, long double __d) long double _Complex z; __real__ z = __ac - __bd; __imag__ z = __ad + __bc; - if (isnan(__real__ z) && isnan(__imag__ z)) + if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) { int __recalc = 0; - if (isinf(__a) || isinf(__b)) + if (crt_isinf(__a) || crt_isinf(__b)) { - __a = copysignl(isinf(__a) ? 1 : 0, __a); - __b = copysignl(isinf(__b) ? 1 : 0, __b); - if (isnan(__c)) - __c = copysignl(0, __c); - if (isnan(__d)) - __d = copysignl(0, __d); + __a = crt_copysignl(crt_isinf(__a) ? 1 : 0, __a); + __b = crt_copysignl(crt_isinf(__b) ? 1 : 0, __b); + if (crt_isnan(__c)) + __c = crt_copysignl(0, __c); + if (crt_isnan(__d)) + __d = crt_copysignl(0, __d); __recalc = 1; } - if (isinf(__c) || isinf(__d)) + if (crt_isinf(__c) || crt_isinf(__d)) { - __c = copysignl(isinf(__c) ? 1 : 0, __c); - __d = copysignl(isinf(__d) ? 1 : 0, __d); - if (isnan(__a)) - __a = copysignl(0, __a); - if (isnan(__b)) - __b = copysignl(0, __b); + __c = crt_copysignl(crt_isinf(__c) ? 1 : 0, __c); + __d = crt_copysignl(crt_isinf(__d) ? 1 : 0, __d); + if (crt_isnan(__a)) + __a = crt_copysignl(0, __a); + if (crt_isnan(__b)) + __b = crt_copysignl(0, __b); __recalc = 1; } - if (!__recalc && (isinf(__ac) || isinf(__bd) || - isinf(__ad) || isinf(__bc))) + if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || + crt_isinf(__ad) || crt_isinf(__bc))) { - if (isnan(__a)) - __a = copysignl(0, __a); - if (isnan(__b)) - __b = copysignl(0, __b); - if (isnan(__c)) - __c = copysignl(0, __c); - if (isnan(__d)) - __d = copysignl(0, __d); + if (crt_isnan(__a)) + __a = crt_copysignl(0, __a); + if (crt_isnan(__b)) + __b = crt_copysignl(0, __b); + if (crt_isnan(__c)) + __c = crt_copysignl(0, __c); + if (crt_isnan(__d)) + __d = crt_copysignl(0, __d); __recalc = 1; } if (__recalc) { - __real__ z = INFINITY * (__a * __c - __b * __d); - __imag__ z = INFINITY * (__a * __d + __b * __c); + __real__ z = CRT_INFINITY * (__a * __c - __b * __d); + __imag__ z = CRT_INFINITY * (__a * __d + __b * __c); } } return z; diff --git a/contrib/compiler-rt/lib/negdf2.c b/contrib/compiler-rt/lib/negdf2.c index b47f3978b41e..b11b4806c04a 100644 --- a/contrib/compiler-rt/lib/negdf2.c +++ b/contrib/compiler-rt/lib/negdf2.c @@ -10,7 +10,6 @@ // This file implements double-precision soft-float negation. // //===----------------------------------------------------------------------===// -#include "abi.h" #define DOUBLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/negsf2.c b/contrib/compiler-rt/lib/negsf2.c index 98f9fc0c0a3a..f8ef2d1da6ae 100644 --- a/contrib/compiler-rt/lib/negsf2.c +++ b/contrib/compiler-rt/lib/negsf2.c @@ -10,7 +10,6 @@ // This file implements single-precision soft-float negation. // //===----------------------------------------------------------------------===// -#include "abi.h" #define SINGLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/negvdi2.c b/contrib/compiler-rt/lib/negvdi2.c index aafaa9dc5ea3..e336ecf28f0d 100644 --- a/contrib/compiler-rt/lib/negvdi2.c +++ b/contrib/compiler-rt/lib/negvdi2.c @@ -11,10 +11,8 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: -a */ diff --git a/contrib/compiler-rt/lib/negvsi2.c b/contrib/compiler-rt/lib/negvsi2.c index 559ea18e48b4..b9e93fef06c5 100644 --- a/contrib/compiler-rt/lib/negvsi2.c +++ b/contrib/compiler-rt/lib/negvsi2.c @@ -11,10 +11,8 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: -a */ diff --git a/contrib/compiler-rt/lib/negvti2.c b/contrib/compiler-rt/lib/negvti2.c index d93130542b0c..ef766bb486b1 100644 --- a/contrib/compiler-rt/lib/negvti2.c +++ b/contrib/compiler-rt/lib/negvti2.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: -a */ diff --git a/contrib/compiler-rt/lib/paritydi2.c b/contrib/compiler-rt/lib/paritydi2.c index e7bebf68524b..2ded54c90b93 100644 --- a/contrib/compiler-rt/lib/paritydi2.c +++ b/contrib/compiler-rt/lib/paritydi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/paritysi2.c b/contrib/compiler-rt/lib/paritysi2.c index 64d509fa7954..599984663849 100644 --- a/contrib/compiler-rt/lib/paritysi2.c +++ b/contrib/compiler-rt/lib/paritysi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/popcountdi2.c b/contrib/compiler-rt/lib/popcountdi2.c index 136fc0486fd0..5e8a62f075eb 100644 --- a/contrib/compiler-rt/lib/popcountdi2.c +++ b/contrib/compiler-rt/lib/popcountdi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/popcountsi2.c b/contrib/compiler-rt/lib/popcountsi2.c index bfaa3fff2ee4..44544ff49890 100644 --- a/contrib/compiler-rt/lib/popcountsi2.c +++ b/contrib/compiler-rt/lib/popcountsi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/powidf2.c b/contrib/compiler-rt/lib/powidf2.c index 2e211eb3dcb8..ac13b172b043 100644 --- a/contrib/compiler-rt/lib/powidf2.c +++ b/contrib/compiler-rt/lib/powidf2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/powisf2.c b/contrib/compiler-rt/lib/powisf2.c index e6b43b3a3cc4..0c400ec6dd6a 100644 --- a/contrib/compiler-rt/lib/powisf2.c +++ b/contrib/compiler-rt/lib/powisf2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/ppc/DD.h b/contrib/compiler-rt/lib/ppc/DD.h index 9ecd1f50b8a9..13862dc98404 100644 --- a/contrib/compiler-rt/lib/ppc/DD.h +++ b/contrib/compiler-rt/lib/ppc/DD.h @@ -1,7 +1,7 @@ #ifndef __DD_HEADER #define __DD_HEADER -#include +#include "../int_lib.h" typedef union { long double ld; diff --git a/contrib/compiler-rt/lib/ppc/divtc3.c b/contrib/compiler-rt/lib/ppc/divtc3.c index d41f62111b3d..299128186312 100644 --- a/contrib/compiler-rt/lib/ppc/divtc3.c +++ b/contrib/compiler-rt/lib/ppc/divtc3.c @@ -3,16 +3,16 @@ */ #include "DD.h" -#include +#include "../int_math.h" -#if !defined(INFINITY) && defined(HUGE_VAL) -#define INFINITY HUGE_VAL -#endif /* INFINITY */ +#if !defined(CRT_INFINITY) && defined(HUGE_VAL) +#define CRT_INFINITY HUGE_VAL +#endif /* CRT_INFINITY */ -#define makeFinite(x) { \ - (x).s.hi = __builtin_copysign(isinf((x).s.hi) ? 1.0 : 0.0, (x).s.hi); \ - (x).s.lo = 0.0; \ - } +#define makeFinite(x) { \ + (x).s.hi = crt_copysign(crt_isinf((x).s.hi) ? 1.0 : 0.0, (x).s.hi); \ + (x).s.lo = 0.0; \ + } long double __gcc_qadd(long double, long double); long double __gcc_qsub(long double, long double); @@ -26,16 +26,16 @@ __divtc3(long double a, long double b, long double c, long double d) DD dDD = { .ld = d }; int ilogbw = 0; - const double logbw = logb(__builtin_fmax( __builtin_fabs(cDD.s.hi), __builtin_fabs(dDD.s.hi) )); + const double logbw = crt_logb(crt_fmax(crt_fabs(cDD.s.hi), crt_fabs(dDD.s.hi) )); - if (isfinite(logbw)) + if (crt_isfinite(logbw)) { ilogbw = (int)logbw; - cDD.s.hi = scalbn(cDD.s.hi, -ilogbw); - cDD.s.lo = scalbn(cDD.s.lo, -ilogbw); - dDD.s.hi = scalbn(dDD.s.hi, -ilogbw); - dDD.s.lo = scalbn(dDD.s.lo, -ilogbw); + cDD.s.hi = crt_scalbn(cDD.s.hi, -ilogbw); + cDD.s.lo = crt_scalbn(cDD.s.lo, -ilogbw); + dDD.s.hi = crt_scalbn(dDD.s.hi, -ilogbw); + dDD.s.lo = crt_scalbn(dDD.s.lo, -ilogbw); } const long double denom = __gcc_qadd(__gcc_qmul(cDD.ld, cDD.ld), __gcc_qmul(dDD.ld, dDD.ld)); @@ -45,42 +45,45 @@ __divtc3(long double a, long double b, long double c, long double d) DD real = { .ld = __gcc_qdiv(realNumerator, denom) }; DD imag = { .ld = __gcc_qdiv(imagNumerator, denom) }; - real.s.hi = scalbn(real.s.hi, -ilogbw); - real.s.lo = scalbn(real.s.lo, -ilogbw); - imag.s.hi = scalbn(imag.s.hi, -ilogbw); - imag.s.lo = scalbn(imag.s.lo, -ilogbw); + real.s.hi = crt_scalbn(real.s.hi, -ilogbw); + real.s.lo = crt_scalbn(real.s.lo, -ilogbw); + imag.s.hi = crt_scalbn(imag.s.hi, -ilogbw); + imag.s.lo = crt_scalbn(imag.s.lo, -ilogbw); - if (isnan(real.s.hi) && isnan(imag.s.hi)) + if (crt_isnan(real.s.hi) && crt_isnan(imag.s.hi)) { DD aDD = { .ld = a }; DD bDD = { .ld = b }; DD rDD = { .ld = denom }; - if ((rDD.s.hi == 0.0) && (!isnan(aDD.s.hi) || !isnan(bDD.s.hi))) + if ((rDD.s.hi == 0.0) && (!crt_isnan(aDD.s.hi) || + !crt_isnan(bDD.s.hi))) { - real.s.hi = __builtin_copysign(INFINITY,cDD.s.hi) * aDD.s.hi; + real.s.hi = crt_copysign(CRT_INFINITY,cDD.s.hi) * aDD.s.hi; real.s.lo = 0.0; - imag.s.hi = __builtin_copysign(INFINITY,cDD.s.hi) * bDD.s.hi; + imag.s.hi = crt_copysign(CRT_INFINITY,cDD.s.hi) * bDD.s.hi; imag.s.lo = 0.0; } - else if ((isinf(aDD.s.hi) || isinf(bDD.s.hi)) && isfinite(cDD.s.hi) && isfinite(dDD.s.hi)) + else if ((crt_isinf(aDD.s.hi) || crt_isinf(bDD.s.hi)) && + crt_isfinite(cDD.s.hi) && crt_isfinite(dDD.s.hi)) { makeFinite(aDD); makeFinite(bDD); - real.s.hi = INFINITY * (aDD.s.hi*cDD.s.hi + bDD.s.hi*dDD.s.hi); + real.s.hi = CRT_INFINITY * (aDD.s.hi*cDD.s.hi + bDD.s.hi*dDD.s.hi); real.s.lo = 0.0; - imag.s.hi = INFINITY * (bDD.s.hi*cDD.s.hi - aDD.s.hi*dDD.s.hi); + imag.s.hi = CRT_INFINITY * (bDD.s.hi*cDD.s.hi - aDD.s.hi*dDD.s.hi); imag.s.lo = 0.0; } - else if ((isinf(cDD.s.hi) || isinf(dDD.s.hi)) && isfinite(aDD.s.hi) && isfinite(bDD.s.hi)) + else if ((crt_isinf(cDD.s.hi) || crt_isinf(dDD.s.hi)) && + crt_isfinite(aDD.s.hi) && crt_isfinite(bDD.s.hi)) { makeFinite(cDD); makeFinite(dDD); - real.s.hi = __builtin_copysign(0.0,(aDD.s.hi*cDD.s.hi + bDD.s.hi*dDD.s.hi)); + real.s.hi = crt_copysign(0.0,(aDD.s.hi*cDD.s.hi + bDD.s.hi*dDD.s.hi)); real.s.lo = 0.0; - imag.s.hi = __builtin_copysign(0.0,(bDD.s.hi*cDD.s.hi - aDD.s.hi*dDD.s.hi)); + imag.s.hi = crt_copysign(0.0,(bDD.s.hi*cDD.s.hi - aDD.s.hi*dDD.s.hi)); imag.s.lo = 0.0; } } diff --git a/contrib/compiler-rt/lib/ppc/fixtfdi.c b/contrib/compiler-rt/lib/ppc/fixtfdi.c index fa113a037e93..56e7b3fbf3e5 100644 --- a/contrib/compiler-rt/lib/ppc/fixtfdi.c +++ b/contrib/compiler-rt/lib/ppc/fixtfdi.c @@ -7,7 +7,7 @@ */ #include "DD.h" -#include +#include "../int_math.h" uint64_t __fixtfdi(long double input) { @@ -65,7 +65,7 @@ uint64_t __fixtfdi(long double input) /* Edge cases handled here: */ /* |x| < 1, result is zero. */ - if (1.0 > __builtin_fabs(x.s.hi)) + if (1.0 > crt_fabs(x.s.hi)) return INT64_C(0); /* x very close to INT64_MIN, care must be taken to see which side we are on. */ diff --git a/contrib/compiler-rt/lib/ppc/fixunstfdi.c b/contrib/compiler-rt/lib/ppc/fixunstfdi.c index 1fb52488172c..5e6e2cedf6ac 100644 --- a/contrib/compiler-rt/lib/ppc/fixunstfdi.c +++ b/contrib/compiler-rt/lib/ppc/fixunstfdi.c @@ -6,7 +6,6 @@ /* This file implements the PowerPC 128-bit double-double -> uint64_t conversion */ #include "DD.h" -#include uint64_t __fixunstfdi(long double input) { diff --git a/contrib/compiler-rt/lib/ppc/floatditf.c b/contrib/compiler-rt/lib/ppc/floatditf.c index ed23dc84d73c..beabdd017422 100644 --- a/contrib/compiler-rt/lib/ppc/floatditf.c +++ b/contrib/compiler-rt/lib/ppc/floatditf.c @@ -6,7 +6,6 @@ /* This file implements the PowerPC long long -> long double conversion */ #include "DD.h" -#include long double __floatditf(int64_t a) { diff --git a/contrib/compiler-rt/lib/ppc/floatunditf.c b/contrib/compiler-rt/lib/ppc/floatunditf.c index 20a3b71b317c..b12e1e738fd0 100644 --- a/contrib/compiler-rt/lib/ppc/floatunditf.c +++ b/contrib/compiler-rt/lib/ppc/floatunditf.c @@ -6,7 +6,6 @@ /* This file implements the PowerPC unsigned long long -> long double conversion */ #include "DD.h" -#include long double __floatunditf(uint64_t a) { diff --git a/contrib/compiler-rt/lib/ppc/multc3.c b/contrib/compiler-rt/lib/ppc/multc3.c index 9d17a2c6bc6a..738b65a83b03 100644 --- a/contrib/compiler-rt/lib/ppc/multc3.c +++ b/contrib/compiler-rt/lib/ppc/multc3.c @@ -3,23 +3,19 @@ */ #include "DD.h" -#include +#include "../int_math.h" -#if !defined(INFINITY) && defined(HUGE_VAL) -#define INFINITY HUGE_VAL -#endif /* INFINITY */ +#define makeFinite(x) { \ + (x).s.hi = crt_copysign(crt_isinf((x).s.hi) ? 1.0 : 0.0, (x).s.hi); \ + (x).s.lo = 0.0; \ + } -#define makeFinite(x) { \ - (x).s.hi = __builtin_copysign(isinf((x).s.hi) ? 1.0 : 0.0, (x).s.hi); \ - (x).s.lo = 0.0; \ - } - -#define zeroNaN(x) { \ - if (isnan((x).s.hi)) { \ - (x).s.hi = __builtin_copysign(0.0, (x).s.hi); \ - (x).s.lo = 0.0; \ - } \ - } +#define zeroNaN(x) { \ + if (crt_isnan((x).s.hi)) { \ + (x).s.hi = crt_copysign(0.0, (x).s.hi); \ + (x).s.lo = 0.0; \ + } \ + } long double __gcc_qadd(long double, long double); long double __gcc_qsub(long double, long double); @@ -36,7 +32,7 @@ __multc3(long double a, long double b, long double c, long double d) DD real = { .ld = __gcc_qsub(ac,bd) }; DD imag = { .ld = __gcc_qadd(ad,bc) }; - if (isnan(real.s.hi) && isnan(imag.s.hi)) + if (crt_isnan(real.s.hi) && crt_isnan(imag.s.hi)) { int recalc = 0; @@ -45,7 +41,7 @@ __multc3(long double a, long double b, long double c, long double d) DD cDD = { .ld = c }; DD dDD = { .ld = d }; - if (isinf(aDD.s.hi) || isinf(bDD.s.hi)) + if (crt_isinf(aDD.s.hi) || crt_isinf(bDD.s.hi)) { makeFinite(aDD); makeFinite(bDD); @@ -54,7 +50,7 @@ __multc3(long double a, long double b, long double c, long double d) recalc = 1; } - if (isinf(cDD.s.hi) || isinf(dDD.s.hi)) + if (crt_isinf(cDD.s.hi) || crt_isinf(dDD.s.hi)) { makeFinite(cDD); makeFinite(dDD); @@ -70,7 +66,8 @@ __multc3(long double a, long double b, long double c, long double d) DD adDD = { .ld = ad }; DD bcDD = { .ld = bc }; - if (isinf(acDD.s.hi) || isinf(bdDD.s.hi) || isinf(adDD.s.hi) || isinf(bcDD.s.hi)) + if (crt_isinf(acDD.s.hi) || crt_isinf(bdDD.s.hi) || + crt_isinf(adDD.s.hi) || crt_isinf(bcDD.s.hi)) { zeroNaN(aDD); zeroNaN(bDD); @@ -82,9 +79,9 @@ __multc3(long double a, long double b, long double c, long double d) if (recalc) { - real.s.hi = INFINITY * (aDD.s.hi*cDD.s.hi - bDD.s.hi*dDD.s.hi); + real.s.hi = CRT_INFINITY * (aDD.s.hi*cDD.s.hi - bDD.s.hi*dDD.s.hi); real.s.lo = 0.0; - imag.s.hi = INFINITY * (aDD.s.hi*dDD.s.hi + bDD.s.hi*cDD.s.hi); + imag.s.hi = CRT_INFINITY * (aDD.s.hi*dDD.s.hi + bDD.s.hi*cDD.s.hi); imag.s.lo = 0.0; } } diff --git a/contrib/compiler-rt/lib/subdf3.c b/contrib/compiler-rt/lib/subdf3.c index 825e3c662973..5eb1853ef79b 100644 --- a/contrib/compiler-rt/lib/subdf3.c +++ b/contrib/compiler-rt/lib/subdf3.c @@ -11,7 +11,6 @@ // IEEE-754 default rounding (to nearest, ties to even). // //===----------------------------------------------------------------------===// -#include "abi.h" #define DOUBLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/subsf3.c b/contrib/compiler-rt/lib/subsf3.c index 625376acc376..351be0ef46a2 100644 --- a/contrib/compiler-rt/lib/subsf3.c +++ b/contrib/compiler-rt/lib/subsf3.c @@ -11,7 +11,6 @@ // IEEE-754 default rounding (to nearest, ties to even). // //===----------------------------------------------------------------------===// -#include "abi.h" #define SINGLE_PRECISION #include "fp_lib.h" diff --git a/contrib/compiler-rt/lib/subvdi3.c b/contrib/compiler-rt/lib/subvdi3.c index 36b51ad979ac..0f1f924effc7 100644 --- a/contrib/compiler-rt/lib/subvdi3.c +++ b/contrib/compiler-rt/lib/subvdi3.c @@ -11,10 +11,8 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: a - b */ diff --git a/contrib/compiler-rt/lib/subvsi3.c b/contrib/compiler-rt/lib/subvsi3.c index 03983f747e49..ec4594c9f0e9 100644 --- a/contrib/compiler-rt/lib/subvsi3.c +++ b/contrib/compiler-rt/lib/subvsi3.c @@ -11,10 +11,8 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" -#include /* Returns: a - b */ diff --git a/contrib/compiler-rt/lib/subvti3.c b/contrib/compiler-rt/lib/subvti3.c index 5d693dc9aba4..44127b73a9a9 100644 --- a/contrib/compiler-rt/lib/subvti3.c +++ b/contrib/compiler-rt/lib/subvti3.c @@ -15,7 +15,6 @@ #if __x86_64 #include "int_lib.h" -#include /* Returns: a - b */ diff --git a/contrib/compiler-rt/lib/trampoline_setup.c b/contrib/compiler-rt/lib/trampoline_setup.c index a22199e0e483..e0765b16b0b0 100644 --- a/contrib/compiler-rt/lib/trampoline_setup.c +++ b/contrib/compiler-rt/lib/trampoline_setup.c @@ -8,9 +8,6 @@ * ===----------------------------------------------------------------------=== */ -#include -#include - #include "int_lib.h" extern void __clear_cache(void* start, void* end); @@ -47,4 +44,4 @@ void __trampoline_setup(uint32_t* trampOnStack, int trampSizeAllocated, /* clear instruction cache */ __clear_cache(trampOnStack, &trampOnStack[10]); } -#endif /* __ppc__ */ +#endif /* __ppc__ && !defined(__powerpc64__) */ diff --git a/contrib/compiler-rt/lib/truncdfsf2.c b/contrib/compiler-rt/lib/truncdfsf2.c index 1dbf02f5ef63..f57af7e736dd 100644 --- a/contrib/compiler-rt/lib/truncdfsf2.c +++ b/contrib/compiler-rt/lib/truncdfsf2.c @@ -37,11 +37,7 @@ // //===----------------------------------------------------------------------===// -#include -#include -#include - -#include "abi.h" +#include "int_lib.h" typedef double src_t; typedef uint64_t src_rep_t; diff --git a/contrib/compiler-rt/lib/ucmpdi2.c b/contrib/compiler-rt/lib/ucmpdi2.c index f2d3f99f880e..3242bbf08046 100644 --- a/contrib/compiler-rt/lib/ucmpdi2.c +++ b/contrib/compiler-rt/lib/ucmpdi2.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/udivdi3.c b/contrib/compiler-rt/lib/udivdi3.c index bbd551ac7111..6c0303df3d40 100644 --- a/contrib/compiler-rt/lib/udivdi3.c +++ b/contrib/compiler-rt/lib/udivdi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/udivmoddi4.c b/contrib/compiler-rt/lib/udivmoddi4.c index c5db21cf0c89..73043d421fc3 100644 --- a/contrib/compiler-rt/lib/udivmoddi4.c +++ b/contrib/compiler-rt/lib/udivmoddi4.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" @@ -133,7 +132,7 @@ __udivmoddi4(du_int a, du_int b, du_int* rem) *rem = n.s.low & (d.s.low - 1); if (d.s.low == 1) return n.all; - unsigned sr = __builtin_ctz(d.s.low); + sr = __builtin_ctz(d.s.low); q.s.high = n.s.high >> sr; q.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr); return q.all; diff --git a/contrib/compiler-rt/lib/udivmodsi4.c b/contrib/compiler-rt/lib/udivmodsi4.c index 2a3ee27f8dcf..5b49089fccc4 100644 --- a/contrib/compiler-rt/lib/udivmodsi4.c +++ b/contrib/compiler-rt/lib/udivmodsi4.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/udivmodti4.c b/contrib/compiler-rt/lib/udivmodti4.c index d1e19edd4c3b..427861b1e3d1 100644 --- a/contrib/compiler-rt/lib/udivmodti4.c +++ b/contrib/compiler-rt/lib/udivmodti4.c @@ -132,7 +132,7 @@ __udivmodti4(tu_int a, tu_int b, tu_int* rem) *rem = n.s.low & (d.s.low - 1); if (d.s.low == 1) return n.all; - unsigned sr = __builtin_ctzll(d.s.low); + sr = __builtin_ctzll(d.s.low); q.s.high = n.s.high >> sr; q.s.low = (n.s.high << (n_udword_bits - sr)) | (n.s.low >> sr); return q.all; diff --git a/contrib/compiler-rt/lib/udivsi3.c b/contrib/compiler-rt/lib/udivsi3.c index 721ae89e4bfc..39ef48bea651 100644 --- a/contrib/compiler-rt/lib/udivsi3.c +++ b/contrib/compiler-rt/lib/udivsi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/umoddi3.c b/contrib/compiler-rt/lib/umoddi3.c index 9de1a64fdad1..3541ab6e91d8 100644 --- a/contrib/compiler-rt/lib/umoddi3.c +++ b/contrib/compiler-rt/lib/umoddi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/umodsi3.c b/contrib/compiler-rt/lib/umodsi3.c index 569b7fcb1685..aae741d896d2 100644 --- a/contrib/compiler-rt/lib/umodsi3.c +++ b/contrib/compiler-rt/lib/umodsi3.c @@ -11,7 +11,6 @@ * * ===----------------------------------------------------------------------=== */ -#include "abi.h" #include "int_lib.h" diff --git a/contrib/compiler-rt/lib/x86_64/floatdidf.c b/contrib/compiler-rt/lib/x86_64/floatdidf.c index cce3cd514a40..388404e5e089 100644 --- a/contrib/compiler-rt/lib/x86_64/floatdidf.c +++ b/contrib/compiler-rt/lib/x86_64/floatdidf.c @@ -6,7 +6,7 @@ #ifdef __x86_64__ -#include +#include "../int_lib.h" double __floatdidf(int64_t a) { diff --git a/contrib/compiler-rt/lib/x86_64/floatdisf.c b/contrib/compiler-rt/lib/x86_64/floatdisf.c index 753ba90dfb0e..96c3728e92c3 100644 --- a/contrib/compiler-rt/lib/x86_64/floatdisf.c +++ b/contrib/compiler-rt/lib/x86_64/floatdisf.c @@ -4,7 +4,7 @@ #ifdef __x86_64__ -#include +#include "../int_lib.h" float __floatdisf(int64_t a) { diff --git a/contrib/compiler-rt/lib/x86_64/floatdixf.c b/contrib/compiler-rt/lib/x86_64/floatdixf.c index 569f72774001..c01193a82b5e 100644 --- a/contrib/compiler-rt/lib/x86_64/floatdixf.c +++ b/contrib/compiler-rt/lib/x86_64/floatdixf.c @@ -6,7 +6,7 @@ #ifdef __x86_64__ -#include +#include "../int_lib.h" long double __floatdixf(int64_t a) { diff --git a/contrib/ee/ee.c b/contrib/ee/ee.c index ebc106952330..70a44076f882 100755 --- a/contrib/ee/ee.c +++ b/contrib/ee/ee.c @@ -307,7 +307,7 @@ void undel_word P_((void)); void del_line P_((void)); void undel_line P_((void)); void adv_word P_((void)); -void move_rel P_((char direction, int lines)); +void move_rel P_((int direction, int lines)); void eol P_((void)); void bol P_((void)); void adv_line P_((void)); @@ -2105,10 +2105,10 @@ char *arguments[]; else if (!strcmp("-?", buff)) { fprintf(stderr, usage0, arguments[0]); - fprintf(stderr, usage1); - fprintf(stderr, usage2); - fprintf(stderr, usage3); - fprintf(stderr, usage4); + fputs(usage1, stderr); + fputs(usage2, stderr); + fputs(usage3, stderr); + fputs(usage4, stderr); exit(1); } else if ((*buff == '+') && (start_at_line == NULL)) @@ -2939,7 +2939,7 @@ while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9))) void move_rel(direction, lines) /* move relative to current line */ -char direction; +int direction; int lines; { int i; @@ -3242,7 +3242,7 @@ char *string; /* string containing user command */ } if (shell_fork) { - printf(continue_msg); + fputs(continue_msg, stdout); fflush(stdout); while ((in = getchar()) != '\n') ; diff --git a/contrib/file/softmagic.c b/contrib/file/softmagic.c index 88f5214500db..174115ee08bd 100644 --- a/contrib/file/softmagic.c +++ b/contrib/file/softmagic.c @@ -1582,7 +1582,7 @@ mget(struct magic_set *ms, const unsigned char *s, case FILE_INDIRECT: if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 && - file_printf(ms, m->desc) == -1) + file_printf(ms, "%s", m->desc) == -1) return -1; if (nbytes < offset) return 0; diff --git a/contrib/gcc/ChangeLog.gcc43 b/contrib/gcc/ChangeLog.gcc43 index fbd462e981dc..94abc02674f2 100644 --- a/contrib/gcc/ChangeLog.gcc43 +++ b/contrib/gcc/ChangeLog.gcc43 @@ -96,6 +96,14 @@ * doc/invoke.texi: Add entry about geode processor. +2006-10-24 Richard Guenther + + PR middle-end/28796 + * builtins.c (fold_builtin_classify): Use HONOR_INFINITIES + and HONOR_NANS instead of MODE_HAS_INFINITIES and MODE_HAS_NANS + for deciding optimizations in consistency with fold-const.c + (fold_builtin_unordered_cmp): Likewise. + 2006-10-22 H.J. Lu (r117958) * config.gcc (i[34567]86-*-*): Add tmmintrin.h to extra_headers. diff --git a/contrib/gcc/builtins.c b/contrib/gcc/builtins.c index 27f19894cc7b..2359a51208fa 100644 --- a/contrib/gcc/builtins.c +++ b/contrib/gcc/builtins.c @@ -8720,7 +8720,7 @@ fold_builtin_classify (tree fndecl, tree arglist, int builtin_index) switch (builtin_index) { case BUILT_IN_ISINF: - if (!MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) + if (!HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) return omit_one_operand (type, integer_zero_node, arg); if (TREE_CODE (arg) == REAL_CST) @@ -8736,8 +8736,8 @@ fold_builtin_classify (tree fndecl, tree arglist, int builtin_index) return NULL_TREE; case BUILT_IN_FINITE: - if (!MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg))) - && !MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) + if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg))) + && !HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) return omit_one_operand (type, integer_zero_node, arg); if (TREE_CODE (arg) == REAL_CST) @@ -8750,7 +8750,7 @@ fold_builtin_classify (tree fndecl, tree arglist, int builtin_index) return NULL_TREE; case BUILT_IN_ISNAN: - if (!MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg)))) + if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg)))) return omit_one_operand (type, integer_zero_node, arg); if (TREE_CODE (arg) == REAL_CST) @@ -8833,13 +8833,13 @@ fold_builtin_unordered_cmp (tree fndecl, tree arglist, if (unordered_code == UNORDERED_EXPR) { - if (!MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg0)))) + if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))) return omit_two_operands (type, integer_zero_node, arg0, arg1); return fold_build2 (UNORDERED_EXPR, type, arg0, arg1); } - code = MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg0))) ? unordered_code - : ordered_code; + code = HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))) ? unordered_code + : ordered_code; return fold_build1 (TRUTH_NOT_EXPR, type, fold_build2 (code, type, arg0, arg1)); } diff --git a/contrib/gcclibs/libcpp/include/cpplib.h b/contrib/gcclibs/libcpp/include/cpplib.h index 5fb80d9e8209..c6a5efc5f1ce 100644 --- a/contrib/gcclibs/libcpp/include/cpplib.h +++ b/contrib/gcclibs/libcpp/include/cpplib.h @@ -555,7 +555,8 @@ enum builtin_type BT_TIME, /* `__TIME__' */ BT_STDC, /* `__STDC__' */ BT_PRAGMA, /* `_Pragma' operator */ - BT_TIMESTAMP /* `__TIMESTAMP__' */ + BT_TIMESTAMP, /* `__TIMESTAMP__' */ + BT_COUNTER /* `__COUNTER__' */ }; #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) diff --git a/contrib/gcclibs/libcpp/init.c b/contrib/gcclibs/libcpp/init.c index 4330f884be72..8280f2fe1b45 100644 --- a/contrib/gcclibs/libcpp/init.c +++ b/contrib/gcclibs/libcpp/init.c @@ -308,6 +308,7 @@ static const struct builtin builtin_array[] = B("__BASE_FILE__", BT_BASE_FILE), B("__LINE__", BT_SPECLINE), B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL), + B("__COUNTER__", BT_COUNTER), /* Keep builtins not used for -traditional-cpp at the end, and update init_builtins() if any more are added. */ B("_Pragma", BT_PRAGMA), diff --git a/contrib/gcclibs/libcpp/internal.h b/contrib/gcclibs/libcpp/internal.h index 857bfe1d8c58..addff6120f05 100644 --- a/contrib/gcclibs/libcpp/internal.h +++ b/contrib/gcclibs/libcpp/internal.h @@ -448,6 +448,8 @@ struct cpp_reader /* A saved list of the defined macros, for dependency checking of precompiled headers. */ struct cpp_savedstate *savedstate; + + unsigned int nextcounter; }; /* Character classes. Based on the more primitive macros in safe-ctype.h. diff --git a/contrib/gcclibs/libcpp/macro.c b/contrib/gcclibs/libcpp/macro.c index be50c111e32e..1eec5788f35b 100644 --- a/contrib/gcclibs/libcpp/macro.c +++ b/contrib/gcclibs/libcpp/macro.c @@ -262,6 +262,10 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) else result = pfile->time; break; + + case BT_COUNTER: + number = pfile->nextcounter++; + break; } if (result == NULL) diff --git a/contrib/gperf/AUTHORS b/contrib/gperf/AUTHORS index 3429c03166d0..184c7ce67ce3 100644 --- a/contrib/gperf/AUTHORS +++ b/contrib/gperf/AUTHORS @@ -1,2 +1,2 @@ Douglas C. Schmidt -Bruno Haible +Bruno Haible diff --git a/contrib/gperf/COPYING b/contrib/gperf/COPYING index bab08afad347..3005d950119c 100644 --- a/contrib/gperf/COPYING +++ b/contrib/gperf/COPYING @@ -2,7 +2,7 @@ Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. diff --git a/contrib/gperf/ChangeLog b/contrib/gperf/ChangeLog index 95ba1fefb2ec..42b21d7c329e 100644 --- a/contrib/gperf/ChangeLog +++ b/contrib/gperf/ChangeLog @@ -1,3 +1,1646 @@ +2007-04-30 Brendan Kehoe + + * gperf-3.0.3 released. + * src/version.cc: Bump to 3.0.3. + * tests/*.exp: Bump to 3.0.3 in header. + * doc/gperf.1: Regenerate with gperf 3.0.3. + +2007-04-06 Bruno Haible + + Improve support for mingw. + * tests/Makefile.in (check-c, check-ada, check-modula3, check-pascal, + check-lang-utf8, check-lang-ucs2): Remove '\r' from output before diff. + (POSTPROCESS_FOR_MINGW): New variable. + (check-test): Use it to postprocess output before diff. + +2007-04-04 Bruno Haible + + Support for newer GNU standards. + * doc/configure.ac (mandir): Remove assignment. + * doc/Makefile.in (datarootdir): New variable. + (docdir, dvidir, psdir, pdfdir, htmldir): Use value determined by + autoconf. + * configure.ac: Require autoconf >= 2.60. + * doc/configure.ac: Likewise. + * lib/configure.ac: Likewise. + * src/configure.ac: Likewise. + * tests/configure.ac: Likewise. + * configure: Regenerated with autoconf-2.61. + * doc/configure: Likewise. + * lib/configure: Likewise. + * src/configure: Likewise. + * tests/configure: Likewise. + * src/config.h.in: Likewise. + * src/config.h.msvc: Likewise. + * src/config.h_vms: Likewise. + +2007-04-04 Bruno Haible + + * doc/Makefile.in (MAKEINFO): Disable also the LC_MESSAGES and LC_ALL + environment variables. + +2007-04-04 Bruno Haible + + * configure.ac: Renamed from configure.in. + * doc/configure.ac: Renamed from doc/configure.in. + * lib/configure.ac: Renamed from lib/configure.in. + * src/configure.ac: Renamed from src/configure.in. + * tests/configure.ac: Renamed from tests/configure.in. + * Makefile.devel: Update. + * INSTALL: Update. + +2007-03-31 Bruno Haible + + * tests/test.c (in_word_set): New declaration. + * tests/test2.c (in_word_set): Likewise. + +2007-03-31 Bruno Haible + + * src/options.cc (Options::parse_options): Bump copyright year. + +2007-03-31 Bruno Haible + + * doc/gperf.texi: Fix typo. + +2007-03-31 Bruno Haible + + Change generated code after the meaning of __inline is changed in + GCC 4.3. + * src/output.cc (Output::output_lookup_function): Emit an inline + marker that also works with gcc-4.3 in c99 or gnu99 mode. + * tests/c-parse.exp, tests/charsets.exp, tests/chill.exp, + tests/cplusplus.exp, tests/gpc.exp, tests/incomplete.exp, + tests/java.exp, tests/languages.exp, tests/modula2.exp, + tests/objc.exp, tests/permut2.exp, tests/permut3.exp, + tests/permutc2.exp, tests/test-4.exp: Update. + Reported by Bruce Korb . + +2006-06-29 Brendan Kehoe + + * gperf-3.0.2 released. + + * doc/Makefile.in (all): No longer depend on dvi. + +2006-01-22 Brendan Kehoe + + * doc/gperf.texi: Update copyright to be 1989-2006. + (UPDATED): Change to 22 January 2006. + * doc/gperf.1 (TH): Fix date. + * configure.in: Update copyright years. + * configure: Regenerate. + * src/Makefile.in: Update copyright years. + + * doc/gperf.{dvi,ps,pdf}: Regenerated by manually invoking tex + instead of trying to use texi2dvi, whose run of etex ends up + actually always running pdfetex, thus always recreating gperf.pdf. + +2006-01-13 Brendan Kehoe + + * NEWS: Add note about #line directive fix. + * doc/gperf.1: Regenerate with Makefile.devel. + + * doc/gperf.texi (UPDATED): Correct to be today. + * doc: Regenerated by doing make in a configured tree. + Requires makeinfo, texi2dvi, texi2pdf, and texi2html. + + * configure.in: Add AC_OBJEXT and AC_EXEEXT. + * lib/Makefile.in (OBJEXT): Define for subst. + (OBJECTS): Use $(OBJEXT) instead of '.o'. + * src/Makefile.in: Make dependencies use $(OBJEXT). + (OBJEXT, EXEEXT): Define for subst. + (TARGETPROG): Add $(EXEEXT). + (OBJECTS): Use $(OBJEXT) instead of '.o'. + (clean): Remove *.$(OBJEXT) instead of *.o. + +2006-01-13 Bruno Haible + + Fix #line directives for filenames containing backslashes. + * src/output.cc (output_line_directive): New function. + (output_keyword_entry, Output::output): Use it. + Reported by Alexander . + + * src/options.cc (Options::parse_options): Update years in --version + output. + +2005-08-29 Brendan Kehoe + + * src/keyword.cc: Tweak comment to avoid nesting. + +2005-08-27 Bruno Haible + + Fix missing ranlib detection when cross-compiling. + * aclocal.m4 (CL_PROG_RANLIB): Remove macro. + * lib/configure.in: Use AC_PROG_RANLIB instead of CL_PROG_RANLIB. + +2005-07-30 Bruno Haible + + * src/version.cc: Bump version number to 3.0.2. + * doc/gperf.texi: Likewise. + * tests/c-parse.exp, tests/charsets.exp, tests/chill.exp, + tests/cplusplus.exp, tests/gpc.exp, tests/incomplete.exp, + tests/java.exp, tests/languages.exp, tests/modula2.exp, + tests/objc.exp, tests/permut2.exp, tests/permut3.exp, + tests/permutc2.exp, tests/test-4.exp: Update. + +2005-07-30 Bruno Haible + + * src/positions.h: Add forward declarations of friend classes. + Needed for compilation with g++ 4.0. + +2004-08-22 Bruno Haible + + * tests/Makefile.in (check-lang-syntax): Add test for the + --length-table-name option. + * tests/test-6.exp: Update. + +2004-08-21 Bruce Lilly + + * src/input.cc (Input::read_input): Accept length-table-name + declaration. + * src/options.h (Options::get_lengthtable_name, + Options::set_lengthtable_name): New declarations. + (Options): Add field _lengthtable_name. + * src/options.icc (Options::get_lengthtable_name): New inline method. + * src/options.cc (DEFAULT_LENGTHTABLE_NAME): New constant. + (Options::long_usage): Document --length-table-name option. + (Options::Options): Initialize _lengthtable_name field. + (Options::~Options): Update. + (Options::set_lengthtable_name): New method. + (long_options): Add option --length-table-name. + (Options::parse_options): Implement --length-table-name option. + * src/output.cc (Output::output_keylength_table, output_switch_case, + Output::output_lookup_function_body): Use option.get_lengthtable_name. + * doc/gperf.texi (Gperf Declarations): Document %define + length-table-name. + (Output Details): Document --length-table-name option. + +2003-06-12 Bruno Haible + + * gperf-3.0.1 released. + + * src/version.cc: Bump version number to 3.0.1. + * doc/gperf.texi: Likewise. + * tests/c-parse.exp, tests/charsets.exp, tests/chill.exp, + tests/cplusplus.exp, tests/gpc.exp, tests/incomplete.exp, + tests/java.exp, tests/languages.exp, tests/modula2.exp, + tests/objc.exp, tests/permut2.exp, tests/permut3.exp, + tests/permutc2.exp, tests/test-4.exp: Update. + +2003-05-31 Bruno Haible + + * doc/gperf.texi (User-supplied Struct): Mention the possibility of an + abbreviated struct declaration. + * src/input.cc (Input::read_input): Support struct declarations of the + form "struct foo;". + * tests/incomplete.gperf: New file. + * tests/incomplete.exp: New file. + * tests/Makefile.in (check-test): Check incomplete.gperf too. + Reported by Rob Leslie . + +2003-05-20 Bruno Haible + + * doc/Makefile.in (gperf.ps): Don't use $< in a target rule. + +2003-05-27 Bruno Haible + + * Makefile.vms (CC): Correct value. + (getopt.obj, getopt1.obj, getline.obj, hash.obj): Don't set + HAVE_CONFIG_H. + +2003-05-17 Bruno Haible + + * Makefile.msvc (DEBUGFLAGS): New variable. + (gperf.exe): Use it, and MFLAGS too. + +2003-05-08 Bruno Haible + + * gperf-3.0 released. + +2003-05-07 Bruno Haible + + * src/version.cc: Bump version number to 3.0. + * doc/gperf.texi: Likewise. + * tests/c-parse.exp, tests/charsets.exp, tests/chill.exp, + tests/cplusplus.exp, tests/gpc.exp, tests/java.exp, + tests/languages.exp, tests/modula2.exp, tests/objc.exp, + tests/permut2.exp, tests/permut3.exp, tests/permutc2.exp, + tests/test-4.exp: Update. + + * src/configure.in: Fix AC_INIT argument. + + * Makefile.devel (configure, lib/configure, src/configure, + tests/configure, doc/configure): Use the newest autoconf. + (src/config.h.in): Use the newest autoheader. + +2003-05-03 Bruno Haible + + * doc/gperf.texi: Use two spaces as sentence separator, as recommended + by the texinfo manual. + +2003-04-12 Bruno Haible + + * doc/configure.in (mandir): Change default value. + * doc/Makefile.in (docdir): Use datadir instead of prefix. + * Makefile.msvc (datadir): New variable. + (mandir, docdir): Use it instead of prefix. + (install, installdirs): Update. + * Makefile.vms (datadir): New variable. + (mandir, docdir): Use it instead of prefix. + (install, installdirs): Update. + +2003-04-12 Bruno Haible + + * README.vms: New file. + * Makefile.vms: New file. + * Makefile.devel (src/config.h_vms): New rule. + (all): Depend on it. + +2003-03-19 Bruno Haible + + * src/input.cc (Input::read_input): Ignore comments at the beginning + of the declarations section. + * doc/gperf.texi (Controls for GNU indent): New section. + Reported by Bruce Lilly . + +2003-03-19 Bruno Haible + + * src/output.cc (Output::output_hash_function): Avoid lint warning if + not all arguments of the hash function are used. Avoid lint warning + for fallthrough in switch. + * tests/c-parse.exp, tests/charsets.exp, tests/chill.exp, + tests/cplusplus.exp, tests/java.exp, tests/languages.exp, + tests/modula2.exp, tests/objc.exp: All /*FALLTHROUGH*/ to expected + output. + Reported by Bruce Lilly . + +2003-03-01 Bruno Haible + + * src/options.h (Options::set_initializer_suffix): New declaration. + * src/options.cc (Options::set_initializer_suffix): New method. + * src/input.cc (Input::read_input): Recognize %define + initializer-suffix. + * doc/gperf.texi (Gperf Declarations): Document %define + initializer-suffix. + * NEWS: Update. + +2003-02-26 Bruno Haible + + * Makefile.msvc: New file. + * README.woe32: New file. + * Makefile.devel (all): Depend on src/config.h.msvc. + (src/config.h.msvc): New rule. + +2003-01-07 Bruno Haible + + * src/input.h (Input::_charset_dependent): New field. + * src/input.cc (Input::read_input): Also set _charset_dependent. + * src/main.cc (main): Pass _charset_dependent from Input to Output. + * src/output.h (Output::Output): Add charset_dependent argument. + (Output::_charset_dependent): New field. + * src/output.cc (Output::Output): Add charset_dependent argument. + (Output::output): Provoke a compilation error if the execution + character set doesn't match the expectations. + * tests/c-parse.exp, tests/charsets.exp, tests/chill.exp, + tests/cplusplus.exp, tests/gpc.exp, tests/java.exp, + tests/languages.exp, tests/modula2.exp, tests/objc.exp, + tests/permut2.exp, tests/permut3.exp, tests/permutc2.exp, + tests/test-4.exp: Update. + + * src/options.cc (Options::long_usage): Change bug report address to + . + * tests/test-6.exp: Update. + + * src/output.cc (USE_DOWNCASE_TABLE): New macro. + (output_upperlower_table): New function. + (output_upperlower_strcmp, output_upperlower_strncmp, + output_upperlower_memcmp): Emit gperf_downcase array accesses. + (Output::output): Call output_upperlower_table. + * tests/permutc2.exp: Update. + + * src/keyword-list.icc (KeywordExt_List::rest): Use a portable cast. + (Only in GCC a cast of an lvalue is an lvalue.) + +2003-01-01 Bruno Haible + + * src/options.cc (Options::parse_options): Update copyright year. + + * doc/gperf.texi (@author): Add me. + + * src/options.h (NULLSTRINGS): New enum value. + (Options::get_stringpool_name, Options::set_stringpool_name): New + method declarations. + (Options::_stringpool_name): New field. + * src/options.icc (Options::get_stringpool_name): New method. + * src/options.cc (DEFAULT_STRINGPOOL_NAME): New variable. + (Options::long_usage): Document -Q and --null-strings. + (Options::Options): Initialize _stringpool_name. + (Options::~Options): Output _stringpool_name, NULLSTRINGS values too. + (Options::set_stringpool_name): New method. + (long_options): Add options --string-pool-name, --null-strings. + (Options::parse_options): Implement options -P, -Q and --null-strings. + * src/input.cc (Input::read_input): Recognize declarations %pic, + %define string-pool-name, %null-strings. + * src/output.h (Output::output_string_pool, + Output::output_lookup_pools): New method declarations. + (Output::_wordlist_eltype): New field. + * src/output.cc (Output::output_keylength_table): Trivial + simplification. + (Output::output_string_pool): New method. + (output_keyword_entry): Add stringpool_index argument. For SHAREDLIB, + use struct offsets. + (output_keyword_blank_entries): For SHAREDLIB, use -1 instead of "". + (Output::output_keyword_table): Use _wordlist_eltype instead of + _struct_tag. Compute stringpool_index for output_keyword_entry. + (Output::output_lookup_pools): New method. + (Output::output_lookup_function_body): Use _wordlist_eltype instead of + _struct_tag. For SHAREDLIB, use "+ stringpool" to convert offsets to + strings. Use "o >= 0" to test for nonempty table entry. + (Output::output_lookup_function): Call output_lookup_pools. + (Output::output): Initialize _wordlist_eltype. Call + output_lookup_pools. + * tests/jstest4.gperf: New file. + * tests/test-6.exp: Update. + * tests/Makefile.in (check-lang-syntax): Drop test of -p. Add tests of + -P and -Q. + * doc/gperf.texi (User-supplied Struct): Mention that first field has + to be of type 'int' if -P is given. + (Gperf Declarations): Document %pic, %define string-pool-name, + %null-strings. + (Output Details): Update description of option -P. Document options -Q + and --null-strings. + + * tests/Makefile.in (check-link-c, check-ada, check-pascal, + check-test): Omit option -p. + * tests/c-parse.exp: Regenerated. + * tests/chill.exp: Regenerated. + * tests/cplusplus.exp: Regenerated. + * tests/gpc.exp: Regenerated. + * tests/java.exp: Regenerated. + * tests/objc.exp: Regenerated. + * tests/test-4.exp: Regenerated. + + * src/output.cc (Output::output_lookup_function_body): Omit the + multicompare code section and its variables when it is not used. + * tests/chill.exp: Regenerated. + + * src/output.c (Output_Compare::output_firstchar_comparison): New + method. + (Output_Compare_Strcmp::output_comparison, + Output_Compare_Strncmp::output_comparison, + Output_Compare_Memcmp::output_comparison): Use it. + * tests/permutc2.exp: Update. + + * tests/smtp.gperf: New file, based on a contribution by Bruce Lilly. + * tests/Makefile.in (check-smtp): New rule. + (check): Depend on it. + (clean): Update. + +2002-12-12 Bruno Haible + + * src/search.h (Search::init_selchars_tuple, + Search::count_duplicates_tuple): Add alpha_unify argument. + (Search::count_duplicates_tuple): New method declaration. + * src/search.cc (Search::init_selchars_tuple, + Search::count_duplicates_tuple): Add alpha_unify argument. + (Search::find_positions): Update. + (Search::count_duplicates_tuple): New method. + (Search::count_duplicates_multiset): Free temp alpha_unify vector. + (Search::find_alpha_inc): Call count_duplicates_tuple. + + * src/configure.in: Add test for stack-allocated variable-size arrays. + * src/config.h.in: Regenerated. + * src/search.cc: Include config.h. + (DYNAMIC_ARRAY, FREE_DYNAMIC_ARRAY): New macros. + (Search::find_alpha_inc, Search::count_possible_collisions, + Search::find_asso_values): Use them. + * src/Makefile.in (search.o): Depend on config.h. + + * src/search.h (Search::keyword_list_length, Search::max_key_length, + Search::get_max_keysig_size, Search::prepare): Remove declarations. + (Search::prepare): Renamed from Search::preprepare. + (Search::_max_selchars_length): New field. + * src/search.cc (Search::prepare): Renamed from Search::preprepare. + (Search::prepare_asso_values): Merged with old Search::prepare. + Initialize _max_selchars_length. + (Search::keyword_list_length): Remove function. Use _list_len instead. + (Search::max_key_length): Remove function. Use _max_key_len instead. + (Search::get_max_keysig_size): Remove function. Use + _max_selchars_length instead. + (Search::count_possible_collisions, Search::find_asso_values): Update. + (Search::find_good_asso_values): Call just prepare_asso_values. + (Search::~Search): Update. + + * src/output.h (Output::output_asso_values_ref): New declaration. + * src/output.cc (char_to_index): Remove variable. + (Output::output_asso_values_ref): New function. + (Output::output_hash_function): Use it. + (Output::output): Update. + + * src/positions.h (Positions::is_useall, Positions::set_useall, + Positions::iterator, Positions::reviterator): New method declarations. + (Positions::_useall): New field. + (PositionIterator): Make constructor private. Add a constructor and a + copy constructor. + (PositionIterator::remaining): New declaration. + (PositionReverseIterator): Make constructor private. Add a constructor + and a copy constructor. + (PositionReverseIterator::remaining): New declaration. + (PositionReverseIterator::_minindex): New field. + * src/positions.icc (Positions::Positions): Initialize _useall. + (Positions::operator=): Likewise. + (Positions::is_useall, Positions::set_useall): New methods. + (Positions::sort): Do nothing if _useall is set. + (Positions::iterator, Positions::reviterator): New methods. + (PositionIterator::PositionIterator): New constructor. + (PositionIterator::remaining): New method. + (PositionReverseIterator::PositionReverseIterator): New constructor. + (PositionReverseIterator::next): Use _minindex as bound. + (PositionReverseIterator::remaining): New method. + * src/positions.cc (Positions::add, Positions::remove): Reset the + useall flag. + (Positions::print): Handle the useall case. + * src/options.h (ALLCHARS): Remove. + * src/options.cc (Options::~Options): Update. + (Options::parse_options): Use Positions::set_useall(). + * src/keyword.h (KeywordExt::init_selchars_tuple, + KeywordExt::init_selchars_multiset, KeywordExt::init_selchars_low): + Remove use_all_chars argument. + * src/keyword.cc (KeywordExt::init_selchars_low): Remove use_all_chars + argument. Tell the position iterator to stop at _allchars_length. + Remove special case code for -k'*'. + (KeywordExt::init_selchars_tuple, KeywordExt::init_selchars_multiset): + Remove use_all_chars argument. + * src/search.h (Search::init_selchars_tuple): Remove use_all_chars + argument. + (Search::init_selchars_multiset): Likewise. + * src/search.cc (Search::init_selchars_tuple): Remove use_all_chars + argument. + (Search::count_duplicates_tuple, Search::find_positions): Update. + (Search::compute_alpha_unify): Remove special case code for -k'*'. + (Search::init_selchars_multiset): Remove use_all_chars argument. + (Search::count_duplicates_multiset): Update. + (Search::find_alpha_inc): Remove special case code for -k'*'. + (Search::prepare): Update. + (Search::get_max_keysig_size): Update. + * src/output.cc (Output::output_hash_function): Remove special case + code for -k'*'. + * tests/chill.exp: Regenerated. + +2002-12-11 Bruno Haible + + Change the positions to be 0-based, instead of 1-based. + * src/positions.h (Positions::LASTCHAR): Set to -1. + (Positions::MAX_SIZE): New constant. + (Positions::pointer): Change return type. + (Positions::_positions): Change element type. + (PositionIterator::EOS, PositionReverseIterator::EOS): Set to -2. + * src/positions.icc (Positions::pointer): Change return type. + (Positions::sort): Update. + * src/positions.cc (Positions::contains, Positions::add, + Positions::remove): Update. + (Positions::print): Update. Fix off-by-one bug. + * src/options.cc (Options::~Options): Update. + (Options::parse_options): Set BAD_VALUE to -3. Update. + * src/keyword.cc (KeywordExt::init_selchars_low): Update. + * src/search.cc (Search::find_positions, Search::compute_alpha_unify, + Search::find_alpha_inc): Update. + * src/output.cc (Output::output_hash_function): Update. Don't emit + a 'case' statement right after 'default:'. + * tests/c-parse.exp: Regenerated. + * tests/charsets.exp: Regenerated. + * tests/cplusplus.exp: Regenerated. + * tests/java.exp: Regenerated. + * tests/languages.exp: Regenerated. + * tests/modula2.exp: Regenerated. + * tests/objc.exp: Regenerated. + +2002-12-10 Bruno Haible + + * src/options.h: Reorder enum values. + (Options::short_usage, Options::long_usage): Make static. + * src/options.cc (Options::short_usage); No longer print a monster + usage line. + (Options::print_options): Improve output of options like + --key-positions=1,2,$. + (Options::~Options): Update. + + * src/options.h (UPPERLOWER): New enum value. + * src/options.cc (Options::long_usage): Document option --ignore-case. + (Options::~Options): Update. + (long_options): Add option --ignore-case. + (Options::parse_options): Handle option --ignore-case. + * src/input.cc (Input::read_input): Recognize option %ignore-case. + * src/keyword.h (KeywordExt::init_selchars_tuple, + KeywordExt::init_selchars_multiset, KeywordExt::init_selchars_low): + Add alpha_unify argument. + * src/keyword.cc (KeywordExt::init_selchars_low): Add alpha_unify + argument. + (KeywordExt::init_selchars_tuple): Add alpha_unify argument. + (KeywordExt::init_selchars_multiset): Add alpha_unify argument. + * src/search.h (Search::compute_alpha_size, + Search::compute_alpha_unify): New declarations. + (Search::init_selchars_multiset): Add alpha_unify argument. + (Search::_alpha_unify): New field. + * src/search.cc (Search::compute_alpha_size, + Search::compute_alpha_unify): New functions. + (Search::init_selchars_tuple): Update. + (Search::find_positions): Temporarily set _alpha_unify. Perform a + case insensitive comparison if needed. + (Search::init_selchars_multiset): Add alpha_unify argument. + (Search::count_duplicates_multiset): Call compute_alpha_unify. + (Search::find_alpha_inc): Temporarily set _alpha_unify. At the end, + set _alpha_size and _alpha_unify. + (Search::prepare): Update. Don't compute _alpga_size here. + (Search::optimize): Propagate unified asso_values. + (Search::~Search) Delete _alpha_unify. + * src/output.cc (output_upperlower_strcmp, output_upperlower_strncmp, + output_upperlower_memcmp): New functions. + (Output_Compare_Strcmp::output_comparison, + Output_Compare_Strncmp::output_comparison, + Output_Compare_Memcmp::output_comparison): Use the case-insensitive + comparison function if --ignore-case was given. + (Output::output): Emit the auxiliary case-insensitive comparison + function if needed. + * tests/permutc2.gperf, tests/permutc2.exp: New files. + * tests/Makefile.in (check-test): Also check permutc2.gperf. + * tests/test-6.exp: Update. + * doc/gperf.texi (Gperf Declarations): Document %ignore-case. + (Input Details): Document option --ignore-case. + * NEWS: Update. + + * src/search.cc (Search::optimize): Fill unused asso_values[] entries + with a large value. + * src/output.h (Output::Output): Remove occurrences argument. + (Output::_occurrences): Remove field. + * src/output.cc (Output::Output): Remove occurrences argument. + (Output::output_hash_function): Ignore _occurrences. + * src/main.cc (main): Don't pass the _occurrences to Output. + + * src/search.cc (Search::preprepare): Exit if keywords contain + out-of-range characters. + + * src/search.cc (for): Define so as to avoid errors with old compilers. + + * src/options.h (SHAREDLIB): New enum value. + * src/options.cc (Options::short_usage): Mention option -P. + (Options::long_usage): Document option -P. + (long_options): Add option --pic. + (Options::parse_options): Handle option -P/--pic. + * src/output.cc (output_keyword_blank_entries): When SHAREDLIB is + specified, emit NULL pointers instead of "". + (Output::output_lookup_function_body): When SHAREDLIB is specified + and SWITCH and DUP and not specified, test the table entry against + NULL before the string comparison. + * tests/test-6.exp: Update. + * doc/gperf.texi (Output Details): Document option -P. + * NEWS: Update. + Suggested by Ulrich Drepper. + +2002-12-08 Bruno Haible + + * tests/permut2.gperf, tests/permut2.exp: New files. + * tests/permut3.gperf, tests/permut3.exp: New files. + * tests/charsets.gperf: New file, from Bruce Lilly. + * tests/charsets.exp: New file. + * tests/languages.gperf: New file, from Bruce Lilly. + * tests/languages.exp: New file. + * Makefile.in (check-test): Test them all. + + Completely new asso_values search algorithm. + * src/search.h (Search::compute_occurrence, Search::clear_determined, + Search::set_determined, Search::already_determined, Search::reorder): + Remove functions. + (Search::init_asso_values, Search::sort_by_occurrence, + Search::compute_occurrence, Search::sort_by_occurrence, + Search::has_collisions, Search::collision_prior_to): Remove functions. + (Search::compute_partition, Search::count_possible_collisions, + Search::unchanged_partition): New method declarations. + (Search::_determined): Remove field. + * src/search.cc (Search::prepare): Don't initialize _determined. + (Search::compute_occurrence, greater_by_occurrence, + Search::clear_determined, Search::set_determined, + Search::already_determined, Search::reorder): Remove functions. + (Search::init_asso_values, compute_disjoint_union, + Search::sort_by_occurrence, Search::compute_occurrence, + Search::sort_by_occurrence, Search::has_collisions, + Search::collision_prior_to): Remove functions. + (StackEntry): Remove class. + (EquivalenceClass, Step): New classes. + (equals, Search::compute_partition, delete_partition, + Search::count_possible_collisions, Search::unchanged_partition): New + functions. + (Search::find_asso_values): Completely rewritten. + (Search::find_good_asso_values): Don't call reorder(). + (Search::~Search): Don't free _determined. + * src/keyword.h (KeywordExt::_occurrence): Remove field. + * src/options.h (ORDER, FAST, OPT_CHOICE): Remove enum values. + (Options::_iterations): Remove field. + * src/options.icc (Options::get_iterations): Remove method. + * src/options.cc (Options::long_usage): Remove mention of -f and -o. + (Options::Options): Don't initialize _iterations. + (Options::~Options): Update. + (Options::parse_options): Do nothing for options -f, -o, -O. + * doc/gperf.texi: (Contributors): Update. + (Algorithmic Details): Remove options -f and -o. Update description + of option -s. + * tests/c-parse.exp, tests/chill.exp, tests/cplusplus.exp, + tests/gpc.exp, tests/java.exp, tests/modula2.exp, tests/objc.exp, + tests/test-4.exp): Regenerated, smaller than before. + * tests/test-6.exp: Update. + * NEWS: Update. + +2002-12-08 Bruno Haible + + * src/search.h (Search::_alpha_size): Change type to 'unsigned int'. + (Search::_asso_value_max): Likewise. + * src/search.cc (Search::prepare_asso_values): Update. + (Search::init_asso_values): Update. + (Search::~Search): Update. + * src/output.h (Output::Output): Change alpha_size type to + 'unsigned int'. + (Output::_alpha_size): Change type to 'unsigned int'. + * src/output.cc (Output::Output): Change alpha_size type to + 'unsigned int'. + (Output::output_hash_function): Update. + +2002-12-07 Bruno Haible + + * src/options.h (OPT_CHOICE): New enum value. + * src/options.cc (Options::~Options): Update. + (long_options): New option --optimized-collision-resolution. + (Options::parse_options): Accept option -O. + * src/search.h (Search::sort_by_occurrence): Change argument to + 'unsigned int'. + (Search::compute_occurrence, Search::sort_by_occurrence): New method + declarations. + * src/search.cc (Search::sort_by_occurrence): Change argument to + 'unsigned int'. + (Search::compute_occurrence, Search::sort_by_occurrence): New methods. + (Search::find_asso_values): Implement OPT_CHOICE. More debugging + output. + + * src/search.cc (Search::prepare_asso_values) [DEBUG]: Also print + the keyword list in order. + (Search::find_asso_values) [DEBUG]: Upon failure, print the union_set. + + * src/options.h (Options::get_size_multiple): Change return type to + float. + (Options::_size_multiple): Change type to float. + * src/options.icc (Options::get_size_multiple): Change return type to + float. + * src/options.cc (Options::long_usage): Update description of option + -s. + (Options::~Options): Update. + (Options::parse_options): For option -s, accept a fraction. + * src/search.cc (Search::prepare_asso_values): Use get_size_multiple + as it is. + * tests/test-6.exp: Update. + * doc/gperf.texi (Algorithmic Details): Update description of option + -s. + +2002-12-04 Bruno Haible + + Improve debugging output. + * src/hash-table.h (Hash_Table::dump): New method. + * src/hash-table.cc (Hash_Table::dump): New method, extracted from + destructor. + (Hash_Table::~Hash_Table): No longer print the contents. + * src/positions.h (PositionReverseIterator): New class. + * src/positions.icc (PositionReverseIterator::PositionReverseIterator, + PositionReverseIterator::next): New methods. + * src/search.cc (Search::find_positions): If debugging, print the + result. + (Search::find_alpha_inc): If debugging, print the result. + (Search::prepare): Explicitly dump the hash table's contents here. + + Portability fixes. + * src/positions.h (Positions::LASTCHAR, Positions::MAX_KEY_POS, + PositionIterator::EOS): Define as compile-time constants using enum. + * src/bool-array.cc (Bool_Array::~Bool_Array): Remove const qualifier + of pointer to be deleted. + * src/input.cc (Input::~Input): Likewise. + * src/keyword.cc (KeywordExt::delete_selchars): Likewise. + * src/main.cc (main): Likewise. + * src/hash-table.cc (Hash_Table::~Hash_Table): Limit scope of 'for' + variables. + * src/search.cc (Search::prepare_asso_values): Use a static_cast to + convert from time_t to long. This is possible because ISO C 99 says + time_t is a numeric type. + +2002-11-20 Bruno Haible + + * src/search.cc (Search::find_asso_values): Avoid gcc warnings about + uninitialized variables. + + Implement backtracking. + * src/search.h (Search::has_collisions): Renamed from + Search::less_collisions. Return a boolean. + * src/search.cc (Search::has_collisions): Renamed from + Search::less_collisions. Return a boolean. + (StackEntry): Remove field _collisions_so_far. + (Search::find_asso_values): Backtrack when encountering an unresolved + collision. Assume collisions_so_far is always zero. + (Search::optimize): Exit if there are accidental duplicates at the end. + * src/output.cc (Output::num_hash_values): Simply return the list + length. + (Output::output_keylength_table): Remove handling of accidental + duplicates. + (Output::output_keyword_table, Output::output_lookup_array): Likewise. + (output_switch_case, output_switches): Likewise. + * doc/gperf.texi (Algorithmic Details): Adjust description of options + -D, -f, -o, -r. + (Bugs): Remove note about missing backtracking. + (Projects): Likewise. + +2002-11-19 Bruno Haible + + Prepare for backtracking. + * src/search.h (Search::try_asso_value, Search::change_some_asso_value): + Remove declarations. + (Search::less_collisions, Search::collision_prior_to): New declarations. + (Search::_fewest_collisions, Search::_union_set, Search::_num_done): + Remove fields. + * src/search.cc (Search::prepare_asso_values): Don't initialize + _union_set. + (Search::try_asso_value, Search::change_some_asso_value): Remove + methods. + (Search::less_collisions, Search::collision_prior_to): New methods. + (StackEntry): New class. + (Search::find_asso_values): Reorganized to use pseudo-recursion. + (Search::~Search): Don't free _union_set. + + * src/search.h (Search::find_good_asso_values): New declaration. + * src/search.cc: Add comments about the basic structure of the + algorithm. + (Search::find_positions): Move the option[POSITIONS] test to here. + (Search::find_good_asso_values): New method, extracted from + Search::optimize. + (Search::optimize): Remove option[POSITIONS] test. Call + find_good_asso_values. + +2002-11-17 Bruno Haible + + * src/options.cc (Options::parse_options): Include copyright notice + and authors in --version output. + + Avoid artificial duplicates. + * src/keyword.h (KeywordExt::init_selchars_tuple): New declaration. + (KeywordExt::init_selchars_multiset): Renamed from + KeywordExt::init_selchars. + (KeywordExt::init_selchars_low): New declaration. + * src/keyword.cc (KeywordExt::init_selchars_low): Renamed from + KeywordExt::init_selchars. Add alpha_inc argument. Remove sorting. + (KeywordExt::init_selchars_tuple): New method. + (KeywordExt::init_selchars_multiset): New method, replaces + KeywordExt::init_selchars. + * src/search.h (Search::init_selchars_tuple): Renamed from + Search::init_selchars. + (Search::count_duplicates_tuple): Renamed from Search::count_duplicates. + (Search::init_selchars_multiset, Search::count_duplicates_multiset, + Search::find_alpha_inc): New declarations. + (Search::_alpha_inc): New field. + (Search::_alpha_size, Search::_occurrences, Search::_asso_values, + Search::_determined): Make non-const. + * src/search.cc (Search::Search): Don't initialize _key_positions, + _alpha_size, _occurrences, _asso_values, _determined here. + (Search::init_selchars_tuple): Renamed from Search::init_selchars. + (Search::count_duplicates_tuple): Renamed from Search::count_duplicates. + (Search::find_positions): Update. + (Search::init_selchars_multiset, Search::count_duplicates_multiset, + Search::find_alpha_inc): New methods. + (Search::prepare): Move preprepare, find_positions calls away. + Initialize _alpha_size, _occurrences, _asso_values, _determined here. + (Search::optimize): Call preprepare, find_positions here. Initialize + _key_positions here. + (Search::~Search): Deallocate _alpha_inc. + * src/output.cc (Output::Output): Add alpha_inc argument. + (Output::output_hash_function): Use _alpha_inc. + * src/output.h (Output::Output): Add alpha_inc argument. + (Output::_alpha_inc): New field. + * src/main.cc (main): Pass _alpha_inc from Search to Output. + * tests/chill.exp: Update. + * doc/gperf.texi (Algorithmic Details): Remove description of + artificial duplicates. + + * src/keyword.h (KeywordExt::_selchars): Change type to + 'const unsigned int *'. + * src/keyword.cc (sort_char_set): Change argument type to + 'unsigned int *'. + (KeywordExt::init_selchars): Update. + * src/search.h (Search::sort_by_occurrence): Change argument type to + 'unsigned int *'. + (Search::try_asso_value): Change argument type to 'unsigned int'. + (Search::_union_set): Change type to 'unsigned int *'. + * src/search.cc (Search::prepare, Search::compute_occurrence, + Search::set_determined, Search::already_determined, + Search::prepare_asso_values, Search::compute_hash): Update. + (compute_disjoint_union): Change argument types to 'unsigned int *'. + (Search::sort_by_occurrence): Likewise. + (Search::try_asso_value): Change argument type to 'unsigned int'. + (Search::change_some_asso_value, Search::~Search): Update. + * src/hash-table.cc (Hash_Table::~Hash_Table, Hash_Table::equal, + Hash_Table::insert): Update. + + * src/positions.h: New file, extracted from options.h. + * src/positions.icc: New file, extracted from options.icc. + * src/positions.cc: New file, extracted from options.cc. + * src/options.h: Include positions.h. Move classes Positions and + PositionsIterator away. + * src/options.icc: Move classes Positions and PositionsIterator away. + * src/options.cc: Move class Positions away. + * src/keyword.cc: Include positions.h instead of options.h. + * src/output.h: Include positions.h instead of options.h. + * src/search.h: Include positions.h instead of options.h. + * src/Makefile.in (OBJECTS): Add positions.o. + (POSITIONS_H): New variable. + (OPTIONS_H, SEARCH_H, OUTPUT_H, keyword.o): Use it. + (positions.o): New rule. + + * src/options.h (POSITIONS): New enum value. + (Positions::Positions): New copy constructor. + (Positions::operator=, Positions::contains, Position::add, + Positions::remove, Positions::print): New method declaration. + (Options::get_max_keysig_size): Remove method. + * src/options.icc (Positions::Positions): New copy constructor. + (Positions::operator=): New method. + (Options::get_max_keysig_size): Remove method. + * src/options.cc (Options::Options): Initialize _key_positions + trivially. + (Options::parse_options): Option -k sets POSITIONS. + (Positions::contains, Positions::add, Positions::remove, + Positions::print): New methods. + * src/hash-table.cc (Hash_Table::~Hash_Table): Compute the field + width explicitly, instead of using Options::get_max_keysig_size. + * src/keyword.h (KeywordExt::init_selchars): Add arguments + use_all_chars, positions. + (KeywordExt::delete_selchars): New declaration. + * src/keyword.cc (KeywordExt::init_selchars): Add arguments + use_all_chars, positions. Remove error message if there are no key + positions. + (KeywordExt::delete_selchars): New method. + * src/search.h: Include options.h. + (Search::preprepare, Search::init_selchars, Search::delete_selchars, + Search::count_duplicates, Search::find_positions): New declarations. + (Search::_key_positions): New field. + * src/search.cc (Search::Search): Initialize _key_positions. + (Search::preprepare, Search::init_selchars, Search::delete_selchars, + Search::count_duplicates, Search::find_positions): New functions. + (Search::prepare): Call preprepare and find_positions. Tweak error + message. + (Search::get_max_keysig_size): Use _key_positions instead of + option.get_key_positions(). + (Search::optimize): Tweak error message. + * src/output.h: Include options.h. + (Output::Output): Add Positions argument. + (Output::_key_positions): New field. + * src/output.cc (Output::Output): Add Positions argument. + (Output::output_hash_function): Omit the table if there are no + positions at all. Use _key_positions instead of + option.get_key_positions(). + (Output::output): Output the computed positions as a comment. + * src/main.cc (main): Pass the Positions from Searcher to Output. + * src/Makefile.in (SEARCH_H, OUTPUT_H): Include OPTIONS_H. + * tests/Makefile.in (check-test): Pass key positions explicitly. + * tests/gpc.exp: Update. + * tests/test-4.exp: Update. + * doc/gperf.texi (Algorithmic Details): Mention that -k is not needed + usually. + +2002-11-16 Bruno Haible + + * src/options.h (Options::get_slot_name): Renamed from + Options::get_key_name. + (Options::set, Options::set_language, Options::set_total_switches, + Options::set_function_name, Options::set_slot_name, + Options::set_class_name, Options::set_hash_name, + Options::set_wordlist_name, Options::set_delimiters): New method + declarations. + (Options::_language): New field. + (Options::_slot_name): Renamed from Options::_key_name. + * src/options.icc (Options::set): New method. + (Options::get_slot_name): Renamed from Options::get_key_name. + * src/options.cc (DEFAULT_FUNCTION_NAME): Renamed from DEFAULT_NAME. + (DEFAULT_SLOT_NAME): Renamed from DEFAULT_NAME. + (Options::Options): Initialize _language. Update. + (Options::~Options): Update. + (Options::set_language, Options::set_total_switches, + Options::set_function_name, Options::set_slot_name, + Options::set_class_name, Options::set_hash_name, + Options::set_wordlist_name, Options::set_delimiters): New methods. + (Options::parse_options): Call set_language. Update. + * src/input.cc (is_declaration, is_declaration_with_arg, + is_define_declaration): New functions. + (Input::read_input): Accept %DECL declarations. + * src/output.cc (Output::output_lookup_function_body): Update. + * doc/gperf.texi (Declarations): Add new subnodes. + (User-supplied Struct, Gperf Declarations, C Code Inclusion): New + nodes. + (Keywords, Output Format, Binary Strings, Options): Mention % + declarations as being equivalent to the command line options. + + * src/options.cc (Options::long_usage): Rename options -H, -N, -l, -G. + (long_options): Add --hash-function-name, --lookup-function-name, + --compare-lengths. + * doc/gperf.texi (Output Details): Rename options -H, -N, -l, -G. + * tests/test-6.exp: Update. + + * src/options.cc (DEFAULT_DELIMITERS): Remove newline. + * src/options.cc (Options::long_usage): Change default --delimiters. + * doc/gperf.texi (Input Details): Likewise. + * tests/test-6.exp: Update. + + * doc/gperf.texi: Move description of option -l from section + Algorithmic Details to section Output Details. + * src/options.cc (Options::long_usage): Likewise. + * tests/test-6.exp: Update. + +2002-11-12 Bruno Haible + + * src/options.h (Output::get_output_file_name): New method. + (Output::_output_file_name): New field. + * src/options.icc (Options::get_output_file_name): New method. + * src/options.cc (Options::long_usage): Document option --output-file. + (Options::Options): Initialize _output_file_name. + (long_options): Add --output-file. + (Options::parse_options): Handle it. + * src/main.cc (main): Open the output file if given by name. + * doc/gperf.texi (Output File): New section. + * tests/test-6.exp: Update. + +2002-11-10 Bruno Haible + + * src/input.cc (pretty_input_file_name): New function. + (read_input): Use it in all error and warning messages. + + * src/keyword.h (Keyword::_lineno): New field. + * src/input.h (Input::_struct_decl_lineno): New field. + * src/input.cc (Input::read_input): Set _struct_decl_lineno. Fill + each keyword's _lineno field. + * src/main.cc (main): Pass _struct_decl_lineno from Input to Output. + * src/output.h (Output::Output) Add struct_decl_lineno argument. + (Output::_struct_decl_lineno): New field. + * src/output.cc (Output::Output) Add struct_decl_lineno argument. + (output_keyword_entry): Emit #line directive before table entry. + (Output::output): Emit #line directive before _struct_decl. + + Fix memory leaks. + * src/keyword.h (empty_string): New declaration. + * src/keyword.cc (empty_string): New variable. + * src/input.h (Input::_input): Make public. + (Input::_input_end): New field. + * src/input.cc (read_input): When removing leading whitespace from + struct_decl, reallocate it. For rest, use empty_string instead of "". + Set _input_end. + (Input::~Input): Delete _struct_decl, _struct_tag, _return_type. + * src/search.cc (Search::prepare): When removing an element from + the keyword list, delete the list node. + (Search::~Search): Delete _occurrences, _asso_values. + * src/main.cc (main): Between Search::~Search and Input::~Input, + destroy the keyword list. + + Rewrite the input routines. + * src/input.h: Don't include read-line.h. + (Input): Don't inherit from class Read_Line. + (Input::read_keys, Input::strcspn, Input::set_output_types, + Input::get_array_type, Input::save_include_src, + Input::get_special_input): Remove declarations. + (Input::read_input): New declaration. + (Input::_struct_decl): Renamed from Input::_array_type. + (Input::_verbatim_declarations): Renamed from Input::_include_src. + (Input::_verbatim_code): Replaces Input::_additional_code. + * src/input.cc: Completely rewritten. + * src/output.h (Output::Output): Update the verbatim_* arguments. + (Output::_struct_decl): Renamed from Output::_array_type. + (Output::_verbatim_declarations): Renamed from Output::_include_src. + (Output::_verbatim_code): Replaces Output::_additional_code. + * src/output.cc (Output::Output): Update the verbatim_* arguments. + (Output::output): Output the verbatim_* code pieces with #line. + * src/main.cc (main): Call Input::read_input instead of + Input::read_keys. Update Output::Output arguments. + * src/read-line.h: Remove file. + * src/read-line.cc, src/read-line.icc: Remove files. + * src/Makefile.in (OBJECTS): Remove read-line.o. + (READ_LINE_H): Remove variable. + (INPUT_H): Update. + (read-line.o): Remove rule. + * doc/gperf.texi (Declarations): Correct the example. + (Keywords): Mention that lines starting with % are forbidden here. + * tests/c-parse.exp: Update. + * tests/cplusplus.exp: Update. + * tests/gpc.exp: Update. + * tests/java.exp: Update. + * tests/objc.exp: Update. + * tests/test-4.exp: Update. + + * src/options.h (Options::get_input_file_name): New declaration. + (Options::_input_file_name): New field. + * src/options.icc (Options::get_input_file_name): New method. + * src/options.cc (Options::Options): Initialize _input_file_name. + (Options::parse_options): Don't open input file, only store it in + _input_file_name. + * src/main.cc (main): Open input file here. + Print an error message upon write error on the output file. + + Upgrade to autoconf-2.52. + * configure.in: Use AC_CONFIG_SUBDIRS instead of AC_OUTPUT_SUBDIRS. + * Makefile.devel (configure, lib/configure, src/configure, + tests/configure, doc/configure): Use autoconf-2.52. + +2002-11-09 Bruno Haible + + * doc/gperf.texi: Talk about "bytes" instead of "characters". Talk + about "keywords", not "keys". Talk about "input file", not "keyfile". + (@menu): Fix a menu entry. + (Contributors): Don't mention cperf. + (Motivation): Fix an off-by-one error in the definition of "minimal". + Mention GNU Java. Recommend http URL instead of anonymous ftp. + (Search Structures): Mention GNU Java. + (Output Format): Drop reference to node 'Implementation'. + (Output Details): Talk about "slot-name" instead of "key name". + (Algorithmic Details): Talk about "selected byte positons", not + "key positions". Upper limit is now 255. Explain a third reason + why duplicates can occur. Describe negative effects of + --occurrence-sort. + (Implementation): Remove chapter. + +2002-11-07 Bruno Haible + + * src/bool-array.cc (Bool_Array::~Bool_Array): Free _storage_array. + * src/search.cc (Search::~Search): Free _union_set, _determined. + + * tests/Makefile.in (check-test): Don't redirect stderr. + +2002-11-05 Bruno Haible + + * src/keyword-list.h (mergesort_list): New declarations. + * src/keyword-list.cc (Keyword_Comparison): New type. + (merge, mergesort_list): New functions, moved here from search.cc. + * src/search.h (Search::merge, Search::merge_sort): Remove methods. + (Search::_occurrence_sort, Search::_hash_sort): Remove fields. + * src/search.cc (Search::merge, Search::merge_sort): Remove methods. + (greater_by_occurrence, less_by_hash_value): New functions. + (Search::reorder, Search::sort): Use mergesort_list. + +2002-11-04 Bruno Haible + + * src/options.h (Options::_asso_iterations): New field. + (Options::get_asso_iterations): New method declaration. + * src/options.icc (Options::get_asso_iterations): New method. + * src/options.cc (Options::short_usage): Mention j and m. + (Options::long_usage): Document option -m. + (Options::Options): Initialize _asso_iterations. + (Options::~Options): Print _asso_iterations too. + (long_options): Add --multiple-iterations. + (Options::parse_options): Handle option -m. + * src/keyword-list.h (copy_list, delete_list): New declarations. + * src/keyword-list.cc (copy_list, delete_list): New functions. + * src/search.h (Search::_initial_asso_value, Search::_jump): New fields. + * src/search.cc (Search::prepare_asso_values): Initialize + _initial_asso_value and _jump here. + (Search::init_asso_values): Use _initial_asso_value. + (Search::try_asso_value): Use _jump. + (Search::optimize): If option -m was given, iterate over different + values for _initial_asso_value and _jump. + * doc/gperf.texi (Algorithmic Details): Document option -m. + * tests/test-6.exp: Update. + +2002-11-03 Bruno Haible + + Bug fix: When option -j 0 was used without option -r, the output was + not random. + * src/search.h (Search::prepare_asso_values): New method declaration. + * src/search.cc (Search::prepare_asso_values): New method, extracted + from Search::init_asso_values. Call srand also when "-j 0" was given. + (Search::optimize): Call prepare_asso_values(). + + * src/hash-table.h (Hash_Table::_ignore_length, Hash_Table::equal): + Declare as const. + * src/hash-table.cc (Hash_Table::equal): Declare as const. + * src/input.h (Input::_factory): Declare as const. + * src/keyword-list.h (Keyword_List::first, KeywordExt_List::first): + Declare as const. + * src/keyword-list.icc (Keyword_List::first, KeywordExt_List::first): + Declare as const. + * src/output.h (Output::num_hash_values, Output::output_constants, + Output::output_hash_function, Output::output_keylength_table, + Output::output_keyword_table, Output::output_lookup_array, + Output::output_lookup_tables, Output::output_lookup_function_body, + Output::output_lookup_function, Output::_array_type, + Output::_additional_code, Output::_include_src, Output::_total_keys, + Output::_total_duplicates, Output::_max_key_len, Output::_min_key_len): + Declare as const. + * src/output.cc (Output::num_hash_values, Output::output_constants, + Output::output_hash_function, Output::output_keylength_table, + Output::output_keyword_table, Output::output_lookup_array, + Output::output_lookup_tables, Output::output_lookup_function_body, + Output::output_lookup_function): Declare as const. + * src/search.h (Search::merge, Search::merge_sort, + Search::compute_occurrence, Search::already_determined, + Search::keyword_list_length, Search::max_key_length, + Search::get_max_keysig_size, Search::compute_hash, + Search::sort_by_occurrence): Declare as const. + * src/search.cc (Search::merge, Search::merge_sort, + Search::compute_occurrence, Search::already_determined, + Search::keyword_list_length, Search::max_key_length, + Search::get_max_keysig_size, Search::compute_hash, + Search::sort_by_occurrence): Declare as const. + + * src/output.cc (Output::output): Set char_to_index to a cast in all + cases. Avoids gcc warnings on the generated code. + + * src/output.cc (Output_Enum): Prepend an underscore to field names. + (Output_Expr1): Likewise. + (Output::output_hash_function): Simplify the special case for "-k 1,$". + + * src/search.h (Search::init_asso_values, Search::find_asso_values): + New declarations. + (Search::try_asso_value): Renamed from Search::affects_prev. + (Search::change_some_asso_value): Renamed from Search::change. + (Search::set_asso_max, Search::get_asso_max): Remove methods. + (Search::_union_set): New field. + * src/search.cc (Search::init_asso_values): New method, extracted + from Search::optimize. + (Search::try_asso_value): Renamed from Search::affects_prev. Take the + iteration count as argument. + (Search::change_some_asso_value): Renamed from Search::change. Don't + make union_set static. Don't increment _fewest_collisions here. + (Search::find_asso_values): New method, extracted from + Search::optimize. + (Search::optimize); Update. + + * src/search.h (Search::compute_hash): Renamed from Search::hash. + (Search::compute_disjoint_union): Remove declaration. + (Search::sort_by_occurrence): Renamed from Search::sort_set. + * src/search.cc (Search::compute_hash): Renamed from Search::hash. + (compute_disjoint_union): Renamed from Search::compute_disjoint_union. + (Search::sort_by_occurrence): Renamed from Search::sort_set. + (Search::change): Simplify loop. + + * src/search.h (Search::clear_determined): New declaration. + * src/search.cc (Search::clear_determined): New method. + (Search::already_determined): Optimize. + (Search::reorder): Even when the next keyword after the current one + is completely determined, move all determined keywords after the + current one. + + Compute the occurrences after removal of duplicates, not before. + * src/keyword.h (KeywordExt::init_selchars): Remove occurrences + argument. + * src/keyword.cc (KeywordExt::init_selchars): Likewise. + * src/search.cc (Search::prepare): Reorder the code. Compute the + occurrences after removal of duplicates. + (Search::merge_sort): Optimize the loop. + (Search::compute_occurrence): Renamed from Search::get_occurrence. + * src/search.h (Search::compute_occurrence): Renamed from + Search::get_occurrence. + * tests/chill.exp: Regenerated. + + Bug fix: The hash table could fail to detect duplicates, between + keywords of different length, when option -n (option[NOLENGTH]) was + given. + * src/hash-table.h (Hash_Table::Hash_Table): Pass table size, not + vector and vector size as arguments. + (Hash_Table::_log_size): New field. + (Hash_Table::equal): New declaration. + * src/hash-table.cc (size_factor): New variable. + (Hash_Table::Hash_Table): Pass table size, not vector and vector size + as arguments. Allocate the vector here. + (Hash_Table::~Hash_Table): Deallocate the vector here. + (Hash_Table::equal): New function. + (Hash_Table::insert): Use it. Don't use item->_allchars_length for the + increment if _ignore_length is true. + * src/search.cc (TABLE_MULTIPLE): Remove variable. + (Search::prepare): Update. + +2002-11-02 Bruno Haible + + Provide documentation also in PDF format. + * doc/Makefile.in (pdfdir, TEXI2PDF): New variables. + (all): Depend on pdf. + (pdf, gperf.pdf): New rules. + (maintainer-clean): Remove the PDF file. + + * src/keyword-list.icc: New file, extracted from keyword-list.h. + * src/keyword-list.h: Include keyword-list.icc. Move inline methods + to there. + * src/keyword-list.cc: Include keyword-list.icc. + * src/Makefile.in (KEYWORD_LIST_H): Add keyword-list.icc. + + * lib/hashpjw.h (hashpjw): Change argument type to 'unsigned char *'. + * lib/hash.cc (hashpjw): Likewise. + * src/keyword.icc: New file. + * src/keyword.h: Include keyword.icc. + (KeywordExt::_selchars): Change type to 'unsigned char *'. + * src/keyword.cc: Include keyword.icc. + (Keyword::Keyword, KeywordExt::KeywordExt): Move to keyword.icc. + (sort_char_set): Change argument type to 'unsigned char *'. + (KeywordExt::init_selchars): Update. + * src/search.h (Search::compute_disjoint_union): Change argument types + to 'unsigned char *'. + (Search::sort_set): Likewise. + (Search::affects_prev): Change argument type to 'unsigned char'. + * src/search.cc (Search::prepare): Initialize _duplicate_link here. + (Search::get_occurrence, Search::set_determined, + Search::already_determined, Search::hash): Update. + (Search::compute_disjoint_union): Change argument types to + 'unsigned char *'. + (Search::sort_set): Likewise. + (Search::affects_prev): Change argument type to 'unsigned char'. + (Search::change): Update. + * src/Makefile.in (KEYWORD_H): Add keyword.icc. + + * src/options.cc (Options::parse_options): Fix error message. + + * src/read-line.h (Read_Line::Read_Line): Make FILE* argument + mandatory. Move body to read-line.icc. + * src/read-line.icc (Read_Line::Read_Line): New constructor. + * src/input.h (Input::Input): Add FILE* argument. + * src/input.cc (Input::Input): Likewise. + * src/main.cc (main): Pass stdin to Input constructor. + + * src/options.h (DEFAULTCHARS): Remove. + (Positions::MAX_KEY_POS): Set to 255. + (Positions::_positions): Increase array size. + (PositionIterator::EOS): Set to -1. + (PositionIterator::_index): Change type to 'unsigned int'. + * src/options.icc (Positions::Positions): Don't store + PositionIterator::EOS. + (PositionIterator::next): Produce PositionIterator::EOS here. + * src/options.cc (Options::long_usage): Use MAX_KEY_POS, not + MAX_KEY_POS-1. + (PositionStringParser): Rename field _size to _in_range. Rename + field _curr_value to _range_curr_value. Rename field _upper_bound + to _range_upper_bound. + (PositionStringParser::nextPosition): Comments. + (Options::Options): Update. + (Options::~Options): Update. + (long_options): Use NULL, not 0. + (Options::parse_options): Set BAD_VALUE to -2; -1 is now EOS. Bug fix: + Check against array overflow when more than MAX_KEY_POS positions are + given. Don't store PositionIterator::EOS. + Check against extra arguments before opening the input file. + * src/output.cc (Output::output_hash_function): Change test which + was for option[DEFAULTCHARS]. + * tests/test-6.exp: Update. + + * src/options.h (Options::get_delimiters): Renamed from + Options::get_delimiter. + * src/options.icc (Options::get_delimiters): Renamed from + Options::get_delimiter. + * src/input.cc (Input::read_keys): Update. + + Bug fix. + * src/options.cc (Options::print_options): Escape backquote inside + double-quoted strings. + + Bug fix. + * src/keyword.cc (KeywordExt::init_selchars): Avoid comparison with + uninitialized member variable. Found with 'valgrind'. + + * src/version.cc: Include version.h. + * src/Makefile.in (OBJECTS): Reorder. + (KEYWORD_H, KEYWORD_LIST_H, INPUT_H, SEARCH_H, OUTPUT_H): New + variables. + (HASH_TABLE_H): Update. + (options.o, read-line.o, keyword.o, keyword-list.o, input.o, search.o, + output.o, main.o): Update dependencies. + + * src/vectors.h: Remove file. + * src/vectors.cc: Remove file. + * src/search.h: Don't include vectors.h. + (Search): Don't inherit from Vectors. New fields _alpha_size, + _occurrences, _asso_values. + (Search::_determined, Search::get_occurrence, Search::set_determined, + Search::already_determined, Search::hash, Search::sort_set): Make + nonstatic. + * src/search.cc (Search::Search): Initialize _alpha_size, _occurrences, + _asso_values, _determined. + (Search::optimize, Search::~Search): Update. + * src/output.h: Don't include vectors.h. + (Output): Remove field _v. New fields _alpha_size, _occurrences, + _asso_values. + (Output::Output): Replace Vectors* argument with alpha_size, + occurrences, asso_values. + * src/output.cc (Output::Output): Replace Vectors* argument with + alpha_size, occurrences, asso_values. + (Output::output_hash_function): Update. + * src/main.cc (main): Don't set Vectors::ALPHA_SIZE. + Pass _alpha_size, _occurrences, _asso_values from Search to Output. + * src/keyword.h: Don't include vectors.h. + * src/Makefile.in (OBJECTS): Remove vectors.o. + (VECTORS_H): Remove variable. + (vectors.o): Remove rule. + + * src/search.h: New file, combines src/key-list.h, src/gen-perf.h. + * src/search,cc: New file, combines src/key-list.cc, src/gen-perf.cc. + * src/key-list.h: Remove file. + * src/key-list.cc: Remove file. + * src/gen-perf.h: Remove file. + * src/gen-perf.cc: Remove file. + * src/main.cc (KeywordExt_Factory): Moved here from gen-perf.cc. + (main): Inline some code from gen-perf.cc. + * src/keyword.h (KeywordExt::init_selchars): Take the occurrences + vector as argument. + * src/keyword.cc (KeywordExt::init_selchars): Take the occurrences + vector as argument. + * src/input.cc (Input::set_output_types): Initialize _array_type, + _return_type, _struct_tag. + (Input::read_keys): Initialize _additional_code. + * src/Makefile.in (OBJECTS): Add search.o. + Remove key-list.o, gen-perf.o. + (KEY_LIST_H, GEN_PERF_H): Remove variables. + (gen-perf.o, key-list.o): Remove rules. + (search.o): New rule. + + * *, */*: Update copyright notice to GPL version 2. + + * src/keyword-list.h (Keyword_List): New class. + (KeywordExt_List): Inherit from it. + * src/keyword-list.cc (Keyword_List::Keyword_List): New constructor. + (KeywordExt_List::KeywordExt_List): Update. + * src/input.h (Input::Input): Add Keyword_Factory argument. + (Input::_factory): New field. + (Input::_head): Change type to Keyword_List*. + (Input::parse_line): New declaration. + * src/input.cc (Input::Input): New constructor. + (Input::parse_line): Renamed from parse_line. Use the _factory. + (Input::read_keys): Update. + * src/key-list.cc (KeywordExt_Factory): New class. + (Key_List::read_keys): Pass a KeywordExt_Factory as Input constructor + argument. + + Avoid g++ -Wold-style-cast warnings. + * src/bool-array.icc: Use new-style casts. + * src/gen-perf.cc: Likewise. + * src/input.cc: Likewise. + * src/key-list.cc: Likewise. + * src/keyword.cc: Likewise. + * src/options.cc: Likewise. + * src/output.cc: Likewise. + * src/hash-table.cc: Likewise. Remove (char *) cast in memset argument. + + * src/keyword-list.h (KeywordExt_List): Don't inherit from KeywordExt. + (KeywordExt_List::KeywordExt_List): Take a KeywordExt* as argument. + (KeywordExt_List::_car): New field. + (KeywordExt_List::first): Use it. + * src/keyword-list.cc (KeywordExt_List::KeywordExt_List): Take a + KeywordExt* as argument. + * src/input.cc (parse_line): Create the KeywordExt separately. + + Start using bool. + * src/bool-array.h (Bool_Array::set_bit): Change return type to bool. + * src/bool-array.icc (Bool_Array::set_bit): Likewise. + * src/gen-perf.h (Gen_Perf::affects_prev): Likewise. + * src/gen-perf.cc (Gen_Perf::affects_prev): Likewise. + * src/hash-table.h (Hash_Table::_ignore_length): Change type to bool. + (Hash_Table::Hash_Table): Change 3rd argument type to bool. + * src/hash-table.cc (Hash_Table::Hash_Table): Likewise. + * src/input.h (Input::_additional_code): Change type to bool. + * src/input.cc (Input::read_keys): Update. + * src/key-list.h (Key_List::_occurrence_sort, Key_List::_hash_sort, + Key_List::_additional_code): Change type to bool. + (Key_List::_determined): Change element type to bool. + (Key_List::already_determined): Change return type to bool. + * src/key-list.cc (Key_List::_determined): Change element type to bool. + (Key_List::set_determined): Update. + (Key_List::already_determined): Change return type to bool. + (Key_List::reorder, Key_List::sort, Key_List::Key_List): Update. + * src/options.h (Positions::sort): Change return type to bool. + (Options::operator[]): Likewise. + * src/options.icc (Positions::sort): Change return type to bool. + (Options::operator[]): Likewise. + * src/output.h (Output::Output): Change 5th argument type to bool. + (Output::_additional_code): Change type to bool. + * src/output.cc (Output::Output): Change 5th argument type to bool. + +2002-10-16 Bruno Haible + + * src/*.h: Align all member names at column 24. + +2002-10-15 Bruno Haible + + * src/input.h: New file. + * src/input.cc: New file, extracted from key-list.cc. + * src/key-list.h (Key_List): Don't inherit from Read_Line. + (Key_List::get_special_input, + Key_List::save_include_src, Key_List::get_array_type, + Key_List::strcspn, Key_List::set_output_types): Remove methods. + * src/key-list.cc (Key_List::get_special_input, + Key_List::save_include_src, Key_List::get_array_type, + Key_List::strcspn, Key_List::set_output_types, parse_line): Move to + src/input.cc. + (Key_List::read_keys): Use Input::read_keys. + (Key_List::Key_List): Update. + * src/gen-perf.cc: Update. + * src/Makefile.in (OBJECTS): Add input.o. + (input.o): New rule. + +2002-10-14 Bruno Haible + + * src/options.cc: Don't include "vector.h". + (Options::parse_options): Don't initialize Vectors::ALPHA_SIZE here. + * src/vectors.cc (Vectors::ALPHA_SIZE): Don't initialize here. + * src/gen-perf.cc (Gen_Perf::Gen_Perf): Initialize Vectors::ALPHA_SIZE. + + * src/options.h (Positions): New class. + (PositionIterator): New class. + (Options::parse_options): Renamed from Options::operator(). + (Options::get_asso_max, Options::set_asso_max): Move to class Key_List. + (Options::reset, Options::get): Remove, replaced by class + PositionIterator. + (Options::get_initial_asso_value): Renamed from Options::initial_value. + (Options::key_sort): Remove, replaced by Positions::sort. + (Options): Make all fields and methods non-static. + * src/options.icc (Positions::Positions, Positions::operator[], + Positions::get_size, Positions::pointer, Positions::set_size, + Positions::sort, PositionIterator::PositionIterator, + PositionIterator::next): New methods. + (Options::get_initial_asso_value): Renamed from Options::initial_value. + (Options::get_size_multiple): New method. + (Options::get_key_positions): New method. + (Options::get_max_keysig_size): Implement using _key_positions. + * src/options.cc (Options::long_usage): Split big string into small + pieces. + (PositionStringParser): Prefix field names with _. + (Options::Options): Update. + (Options::~Options): Fix explanation of of _size_multiple. Don't print + _key_positions if it is effectively ignored. + (Options::parse_options): Renamed from Options::operator(). Update. + * src/key-list.h (Key_List): New field _size. New methods get_asso_max, + set_asso_max, get_max_keysig_size. + * src/key-list.cc (Key_List::read_keys): Don't make side effects on + options. + (Key_List::dump): Use Key_List::get_max_keysig_size() instead of + Options::get_max_keysig_size(). + (Key_List::get_max_keysig_size): New function. + * src/hash-table.cc (Hash_Table::~Hash_Table): Compute the field + width on the fly if option[ALLCHARS]. + * src/gen-perf.cc (Gen_Perf::Gen_Perf): Update, + Use Options::get_size_multiple() instead of Options::get_asso_max(). + Use Key_List::get_asso_max() instead of Options::get_asso_max(). Use + Key_List::get_max_keysig_size() instead of + Options::get_max_keysig_size(). + (Gen_Perf::affects_prev): Likewise. + (Gen_Perf::change): Likewise. + * src/keyword.cc: Update. + * src/main.cc: Update. + * src/output.cc: Update. + * tests/test-6.exp: Update. + +2002-10-13 Bruno Haible + + * src/bool-array.*: Some polishing. + + * src/options.h (Options::operator=, Options::operator!=): Remove + unused methods. + * src/options.icc (Options::operator=, Options::operator!=): Remove. + + * src/*.h: Prefix all field names with _. + * src/*.cc, src/*.icc: Update. + + * src/*: Simplify declarations of functions without arguments. + +2002-10-04 Bruno Haible + + * src/output.h: New file, extracted from key-list.h. + * src/output.cc: New file, extracted from key-list.cc. + * src/key-list.h (Key_List): Make some fields protected. Move output + routines to src/output.h. + * src/key-list.cc: Move output routines to src/output.cc. + * src/gen-perf.cc (Gen_Perf::doit_all): Use class Output. + * src/Makefile.in (OBJECTS): Add output.o. + (output.o): New rule. + +2002-10-03 Bruno Haible + + * src/iterator.h: Remove file. + * src/iterator.cc: Remove file. + * src/options.cc: (PositionStringParser): New class, taken from old + iterator.cc. + * src/Makefile.in (OBJECTS): Remove iterator.o. + (ITERATOR_H): Remove variable. + (iterator.o): Remove rule. + + * src/keyword-list.h: New file. + * src/keyword-list.cc: New file. + * src/list-node.h: Remove file. + * src/list-node.cc: Remove file. + * src/keyword.h (KeywordExt::init_selchars): New declaration. + * src/keyword.cc (sort_char_set, KeywordExt::init_selchars): New, from + old list-node.cc. + * src/gen-perf.cc: Replace List_Node by KeywordExt or KeywordExt_List, + as appropriate. + * src/hash-table.h: Likewise. + * src/key-list.h: Likewise. + * src/key-list.cc: Likewise. + * src/Makefile.in (OBJECTS): Remove list-node.o, add keyword-list.o. + (LIST_NODE_H): Remove macro. + (list-node.o): Remove rule. + (keyword-list.o): New rule. + + * src/keyword.h (KeywordExt): New class. + * src/keyword.cc (KeywordExt): New constructor. + * src/list-node.h (List_Node): Inherit from KeywordExt. + * src/list-node.cc: Update. + * src/gen-perf.cc: Update. + * src/hash-table.cc: Update. + * src/key-list.cc: Update. + (output_keyword_entry): Change argument type to KeywordExt*. + + * src/keyword.h: New file. + * src/keyword.cc: New file. + * src/list-node.h (List_Node): Extend Keyword. + * src/list-node.cc: Update. + * src/gen-perf.cc: Update. + * src/hash-table.cc: Update. + * src/key-list.cc: Update. + * src/Makefile.in (OBJECTS): Add keyword.o. + (keyword.o): New rule. + + * src/key-list.cc (Key_List::read_keys): Allocate the memory for the + hash table using 'new'. + (Key_List::output_lookup_array): Allocate the memory for the duplicates + array using 'new'. + * src/options.h (LARGE_STACK_ARRAYS): Remove definition. + * src/main.cc (main): Remove setrlimit call. + * src/configure.in: Don't test for unistd.h, sys/time.h, + sys/resource.h, getrlimit, setrlimit. + + * src/bool-array.h (Bool_Array): Make all members non-static. + Add an argument to the constructor. Remove init(), rename reset() to + clear(), rename find() to set_bit(). + * src/bool-array.icc: Move init() code into the constructor. + Rename reset() to clear(), rename find() to set_bit(). + * src/gen-perf.h (Gen_Perf): Add collision_detector member. + * src/gen-perf.cc: Update. + + * src/gen-perf.h (Gen_Perf::doit_all): Renamed from + Gen_Perf::operator (). + * src/gen-perf.cc (Gen_Perf::doit_all): Renamed from + Gen_Perf::operator (). + * src/main.cc: Update. + + * src/read-line.h (Read_Line::read_next_line): Renamed from + Read_Line::get_line. + * src/read-line.icc: Likewise. + * src/read-line.cc: Update. + * src/key-list.cc: Update. + + * lib/getline.h: New file. + * lib/getline.cc: New file. + * lib/Makefile.in (OBJECTS): Add getline.o. + (getline.o): New rule. + * src/read-line.h (Read_Line::readln_aux): Remove declaration. + * src/read-line.cc (Read_Line::readln_aux): Remove function. + * src/read-line.icc (Read_Line::get_line): Use ::get_line. + * src/options.h (LARGE_STACK): Remove macro. + + * src/bool-array.h (STORAGE_TYPE): Remove type. + Use 'unsigned int' instead of STORAGE_TYPE. + * src/bool-array.cc: Likewise. + * src/bool-array.icc: Likewise. + * src/gen-perf.cc: Likewise. + + * src/new.cc: Remove file. + * src/Makefile.in (OBJECTS): Remove new.o. + (new.o): Remove rule. + * src/configure.in: Remove test for HAVE_THROW_DECL. + * acconfig.h: Remove file. + + * src/trace.h: Remove file. + * src/trace.cc: Remove file. + * src/Makefile.in (OBJECTS): Remove trace.o. + (TRACE_H): Remove variable. + (trace.o): Remove rule. + Update all dependencies. + * src/bool-array.h, src/bool-array.cc, src/bool-array.icc: Don't use T. + * src/gen-perf.cc: Likewise. + * src/hash-table.cc: Likewise. + * src/iterator.cc: Likewise. + * src/key-list.cc: Likewise. + * src/list-node.cc: Likewise. + * src/main.cc: Likewise. + * src/new.cc: Likewise. + * src/options.h, src/options.cc, src/options.icc: Likewise. + * src/read-line.h, src/read-line.cc, src/read-line.icc: Likewise. + + * tests/Makefile.in: Use gperf option -I, to avoid gcc-3.x warnings. + * tests/test.c: Don't use gets(), to avoid warnings. + +2001-08-02 Bruno Haible + + * doc/gperf.texi: Change bug report address to . + * README: Updated. + +2000-12-18 Bruno Haible + + * src/configure.in: Add check for rand() in libm. Needed for BeOS. + * src/Makefile.in (LIBS): Use @GPERF_LIBM@ instead of hardwiring -lm. + +2000-11-20 Bruno Haible + + * doc/help2man: Update to version 1.23. + 2000-09-26 Bruno Haible * gperf-2.7.2 released. diff --git a/contrib/gperf/FREEBSD-Xlist b/contrib/gperf/FREEBSD-Xlist index 393d55c838d2..adb468037113 100644 --- a/contrib/gperf/FREEBSD-Xlist +++ b/contrib/gperf/FREEBSD-Xlist @@ -6,3 +6,7 @@ $FreeBSD$ */texinfo.tex */tests */getopt* +*/*.pdf +*/*.vms +*/*.msvc +*/*.woe32 diff --git a/contrib/gperf/INSTALL b/contrib/gperf/INSTALL index 350b32f51311..ab676eb374b3 100644 --- a/contrib/gperf/INSTALL +++ b/contrib/gperf/INSTALL @@ -19,8 +19,8 @@ diffs or instructions to the address given in the `README' so they can be considered for the next release. If at some point `config.cache' contains results you don't want to keep, you may remove or edit it. - The file `configure.in' is used to create `configure' by a program -called `autoconf'. You only need `configure.in' if you want to change + The file `configure.ac' is used to create `configure' by a program +called `autoconf'. You only need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: diff --git a/contrib/gperf/Makefile.devel b/contrib/gperf/Makefile.devel index cd6b6282acfe..566c8686c7eb 100644 --- a/contrib/gperf/Makefile.devel +++ b/contrib/gperf/Makefile.devel @@ -4,32 +4,38 @@ SHELL = /bin/sh MAKE = make -all : configures src/config.h.in doc/gperf.1 +all : configures src/config.h.in src/config.h.msvc src/config.h_vms doc/gperf.1 CONFIGURES = configure lib/configure src/configure tests/configure doc/configure configures : $(CONFIGURES) -configure : configure.in aclocal.m4 - autoconf -l . +configure : configure.ac aclocal.m4 + autoconf -I . -lib/configure : lib/configure.in aclocal.m4 - cd lib && autoconf -l .. +lib/configure : lib/configure.ac aclocal.m4 + cd lib && autoconf -I .. -src/configure : src/configure.in aclocal.m4 - cd src && autoconf -l .. +src/configure : src/configure.ac aclocal.m4 + cd src && autoconf -I .. -tests/configure : tests/configure.in aclocal.m4 - cd tests && autoconf -l .. +tests/configure : tests/configure.ac aclocal.m4 + cd tests && autoconf -I .. -doc/configure : doc/configure.in aclocal.m4 - cd doc && autoconf -l .. +doc/configure : doc/configure.ac aclocal.m4 + cd doc && autoconf -I .. check-configures : $(CONFIGURES) set -e; for f in $(CONFIGURES); do bash -x -n $$f; done -src/config.h.in : src/configure.in aclocal.m4 - cd src && autoheader -l .. +src/config.h.in : src/configure.ac aclocal.m4 + cd src && autoheader -I .. + +src/config.h.msvc : src/config.h.in + cp src/config.h.in src/config.h.msvc + +src/config.h_vms : src/config.h.in + cp src/config.h.in src/config.h_vms doc/gperf.1 : force prog=`PATH=build/src:src:$$PATH which gperf`; if test -n "$$prog"; then doc/help2man --name='generate a perfect hash function from a key set' --section=1 $$prog > doc/gperf.1; fi diff --git a/contrib/gperf/Makefile.in b/contrib/gperf/Makefile.in index 1d9336afa8a9..979156f38ea5 100644 --- a/contrib/gperf/Makefile.in +++ b/contrib/gperf/Makefile.in @@ -1,13 +1,14 @@ # Makefile for gperf -# Copyright (C) 1989, 1992, 1993, 1998 Free Software Foundation, Inc. -# written by Douglas C. Schmidt (schmidt@ics.uci.edu) +# Copyright (C) 1989, 1992, 1993, 1998, 2002 Free Software Foundation, Inc. +# Written by Douglas C. Schmidt +# and Bruno Haible . # # This file is part of GNU GPERF. # # GNU GPERF is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 1, or (at your option) +# the Free Software Foundation; either version 2, or (at your option) # any later version. # # GNU GPERF is distributed in the hope that it will be useful, @@ -16,8 +17,9 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with GNU GPERF; see the file COPYING. If not, write to -# Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# along with this program; see the file COPYING. +# If not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #### Start of system configuration section. #### diff --git a/contrib/gperf/NEWS b/contrib/gperf/NEWS index 9a2877f05384..dddf42707da7 100644 --- a/contrib/gperf/NEWS +++ b/contrib/gperf/NEWS @@ -1,3 +1,73 @@ +New in 3.0.3: + +* The generated C code is compatible with gcc-4.3.x in c99 or gnu99 mode. + +New in 3.0.2: + +* Compiles with g++-4.0.x. +* Added option --length-table-name. +* Added declaration %define length-table-name. +* Fixed #line directives for filenames containing backslashes. + +New in 3.0.1: + +* Bug fix. + +New in 3.0: + +* Added option --output that allows to specify the output file name. +* Some options have been renamed: + --hash-fn-name=NAME --> --hash-function-name=NAME + --lookup-fn-name=NAME --> --lookup-function-name=NAME + --compare-strlen --> --compare-lengths + --global --> --global-table + The older variants are still supported for backward compatibility. +* The following options can now be specified inside the input file: + %delimiters=DELIMITER-LIST + %struct-type + %ignore-case + %language=LANGUAGE-NAME + %define slot-name NAME + %define initializer-suffix INITIALIZERS + %define hash-function-name NAME + %define lookup-function-name NAME + %define class-name NAME + %7bit + %compare-lengths + %compare-strncmp + %readonly-tables + %enum + %includes + %global-table + %pic + %define string-pool-name NAME + %null-strings + %define word-array-name NAME + %switch=COUNT + %omit-struct-type +* When the option -k is not given, the default key positions are now + computed depending on the set of keywords. +* If the input file is given by name, the output file will now contain + #line directives referring to the input file. +* Some keyword sets containing permutations, like { "xy", "yx", "xz", "zx" } + or { "abc", "acb", "bca", "cab" }, are now handled by gperf without + requiring the option -D. +* The generated table is usually much smaller than it was with earlier + versions of gperf. +* Added option -m/--multiple-iterations that allows to further reduce the + size of the generated table. +* When the search for a good hash function is not immediately successful, + the table's size will grow as needed. Earlier versions of gperf bailed + out with an "Internal error, duplicate hash code value". +* The options -f/--fast and -o/--occurrence-sort have no effect any more. +* Added options -P/--pic and --null-strings that optimize the generated code + for use in shared libraries. -P/--pic does a perfect optimization but may + require some small code changes (see the documentation for details), whereas + --null-strings does only a half-hearted optimization but works without + needing any change to surrounding code. +* Added option --ignore-case that produces a case independent lookup function. +* Bug fixes. + New in 2.7.2: * Keywords may now be enclosed in double quotes; this permits the use of diff --git a/contrib/gperf/README b/contrib/gperf/README index 92ec7d20f1ff..26173bfc2467 100644 --- a/contrib/gperf/README +++ b/contrib/gperf/README @@ -22,8 +22,7 @@ this distribution follows, see the GNU standards document ftp://ftp.gnu.org/pub/gnu/standards.*, especially the 'Makefile Conventions', 'Configuration', and 'User Interfaces' sections. -Mail suggestions and bug reports to both and -. When reporting bugs, please -include in the subject line the package name and version (output of -'gperf --version') for which you found a problem. +Mail suggestions and bug reports to . When +reporting bugs, please include in the subject line the package name +and version (output of 'gperf --version') for which you found a problem. diff --git a/contrib/gperf/acconfig.h b/contrib/gperf/acconfig.h deleted file mode 100644 index cd040d450f7e..000000000000 --- a/contrib/gperf/acconfig.h +++ /dev/null @@ -1,4 +0,0 @@ - -/* Define if the C++ compiler supports "throw ()" declarations. */ -#undef HAVE_THROW_DECL - diff --git a/contrib/gperf/aclocal.m4 b/contrib/gperf/aclocal.m4 index bb22edca357d..e834c09cb477 100644 --- a/contrib/gperf/aclocal.m4 +++ b/contrib/gperf/aclocal.m4 @@ -1,7 +1,5 @@ AC_PREREQ(2.12) -AC_DEFUN(CL_PROG_RANLIB, [AC_CHECK_PROG(RANLIB, ranlib, ranlib, true)]) - AC_DEFUN(CL_PROG_INSTALL, [dnl This is mostly copied from AC_PROG_INSTALL. # Find a good install program. We prefer a C program (faster), diff --git a/contrib/gperf/configure b/contrib/gperf/configure index 77123803d955..6a82f3dcbdc8 100755 --- a/contrib/gperf/configure +++ b/contrib/gperf/configure @@ -1,26 +1,637 @@ #! /bin/sh - # Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 2.13 -# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. +# Generated by GNU Autoconf 2.61. # +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## -# Defaults: -ac_help= +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + + + +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + +if test "x$CONFIG_SHELL" = x; then + if (eval ":") 2>/dev/null; then + as_have_required=yes +else + as_have_required=no +fi + + if test $as_have_required = yes && (eval ": +(as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=\$LINENO + as_lineno_2=\$LINENO + test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" && + test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; } +") 2> /dev/null; then + : +else + as_candidate_shells= + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + case $as_dir in + /*) + for as_base in sh bash ksh sh5; do + as_candidate_shells="$as_candidate_shells $as_dir/$as_base" + done;; + esac +done +IFS=$as_save_IFS + + + for as_shell in $as_candidate_shells $SHELL; do + # Try only shells that exist, to save several forks. + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { ("$as_shell") 2> /dev/null <<\_ASEOF +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + +: +_ASEOF +}; then + CONFIG_SHELL=$as_shell + as_have_required=yes + if { "$as_shell" 2> /dev/null <<\_ASEOF +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + +: +(as_func_return () { + (exit $1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = "$1" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test $exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; } + +_ASEOF +}; then + break +fi + +fi + + done + + if test "x$CONFIG_SHELL" != x; then + for as_var in BASH_ENV ENV + do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + done + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} +fi + + + if test $as_have_required = no; then + echo This script requires a shell more modern than all the + echo shells that I found on your system. Please install a + echo modern shell, or manually run the script under such a + echo shell if you do have one. + { (exit 1); exit 1; } +fi + + +fi + +fi + + + +(eval "as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0") || { + echo No shell found that supports shell functions. + echo Please tell autoconf@gnu.org about your system, + echo including any error possibly output before this + echo message +} + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + + +exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# ac_default_prefix=/usr/local -# Any additions from configure.in: +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} + +# Identity of this package. +PACKAGE_NAME= +PACKAGE_TARNAME= +PACKAGE_VERSION= +PACKAGE_STRING= +PACKAGE_BUGREPORT= + +ac_unique_file="doc/gperf.1" +ac_subst_vars='SHELL +PATH_SEPARATOR +PACKAGE_NAME +PACKAGE_TARNAME +PACKAGE_VERSION +PACKAGE_STRING +PACKAGE_BUGREPORT +exec_prefix +prefix +program_transform_name +bindir +sbindir +libexecdir +datarootdir +datadir +sysconfdir +sharedstatedir +localstatedir +includedir +oldincludedir +docdir +infodir +htmldir +dvidir +pdfdir +psdir +libdir +localedir +mandir +DEFS +ECHO_C +ECHO_N +ECHO_T +LIBS +build_alias +host_alias +target_alias +SET_MAKE +subdirs +LIBOBJS +LTLIBOBJS' +ac_subst_files='' + ac_precious_vars='build_alias +host_alias +target_alias' +ac_subdirs_all='lib src tests doc' # Initialize some variables set by options. +ac_init_help= +ac_init_version=false # The variables have the same names as the options, with # dashes changed to underlines. -build=NONE -cache_file=./config.cache +cache_file=/dev/null exec_prefix=NONE -host=NONE no_create= -nonopt=NONE no_recursion= prefix=NONE program_prefix=NONE @@ -29,94 +640,117 @@ program_transform_name=s,x,x, silent= site= srcdir= -target=NONE verbose= x_includes=NONE x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' +datarootdir='${prefix}/share' +datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' includedir='${prefix}/include' oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -# Initialize some other variables. -subdirs= -MFLAGS= MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} -# Maximum number of lines to put in a shell here document. -ac_max_here_lines=12 +docdir='${datarootdir}/doc/${PACKAGE}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' ac_prev= +ac_dashdash= for ac_option do - # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" + eval $ac_prev=\$ac_option ac_prev= continue fi - case "$ac_option" in - -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; - *) ac_optarg= ;; + case $ac_option in + *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. - case "$ac_option" in + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir="$ac_optarg" ;; + bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) - ac_prev=build ;; + ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build="$ac_optarg" ;; + build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file="$ac_optarg" ;; + cache_file=$ac_optarg ;; - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir="$ac_optarg" ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; -disable-* | --disable-*) - ac_feature=`echo $ac_option|sed -e 's/-*disable-//'` + ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - eval "enable_${ac_feature}=no" ;; + expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + eval enable_$ac_feature=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; -enable-* | --enable-*) - ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'` + ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; - *) ac_optarg=yes ;; - esac - eval "enable_${ac_feature}='$ac_optarg'" ;; + expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + eval enable_$ac_feature=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ @@ -125,116 +759,77 @@ do -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) - exec_prefix="$ac_optarg" ;; + exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; - -help | --help | --hel | --he) - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat << EOF -Usage: configure [options] [host] -Options: [defaults in brackets after descriptions] -Configuration: - --cache-file=FILE cache test results in FILE - --help print this message - --no-create do not create output files - --quiet, --silent do not print \`checking...' messages - --version print the version of autoconf that created configure -Directory and file names: - --prefix=PREFIX install architecture-independent files in PREFIX - [$ac_default_prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [same as prefix] - --bindir=DIR user executables in DIR [EPREFIX/bin] - --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] - --libexecdir=DIR program executables in DIR [EPREFIX/libexec] - --datadir=DIR read-only architecture-independent data in DIR - [PREFIX/share] - --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] - --sharedstatedir=DIR modifiable architecture-independent data in DIR - [PREFIX/com] - --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] - --libdir=DIR object code libraries in DIR [EPREFIX/lib] - --includedir=DIR C header files in DIR [PREFIX/include] - --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] - --infodir=DIR info documentation in DIR [PREFIX/info] - --mandir=DIR man documentation in DIR [PREFIX/man] - --srcdir=DIR find the sources in DIR [configure dir or ..] - --program-prefix=PREFIX prepend PREFIX to installed program names - --program-suffix=SUFFIX append SUFFIX to installed program names - --program-transform-name=PROGRAM - run sed PROGRAM on installed program names -EOF - cat << EOF -Host type: - --build=BUILD configure for building on BUILD [BUILD=HOST] - --host=HOST configure for HOST [guessed] - --target=TARGET configure for TARGET [TARGET=HOST] -Features and packages: - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] - --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) - --x-includes=DIR X include files are in DIR - --x-libraries=DIR X library files are in DIR -EOF - if test -n "$ac_help"; then - echo "--enable and --with options recognized:$ac_help" - fi - exit 0 ;; + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; -host | --host | --hos | --ho) - ac_prev=host ;; + ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) - host="$ac_optarg" ;; + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir="$ac_optarg" ;; + includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir="$ac_optarg" ;; + infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir="$ac_optarg" ;; + libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) - libexecdir="$ac_optarg" ;; + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) + | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir="$ac_optarg" ;; + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir="$ac_optarg" ;; + mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) + | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ @@ -248,26 +843,26 @@ EOF -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir="$ac_optarg" ;; + oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix="$ac_optarg" ;; + prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix="$ac_optarg" ;; + program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix="$ac_optarg" ;; + program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ @@ -284,7 +879,17 @@ EOF | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name="$ac_optarg" ;; + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) @@ -294,7 +899,7 @@ EOF ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) - sbindir="$ac_optarg" ;; + sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ @@ -305,58 +910,53 @@ EOF | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) - sharedstatedir="$ac_optarg" ;; + sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) - site="$ac_optarg" ;; + site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir="$ac_optarg" ;; + srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir="$ac_optarg" ;; + sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target ;; + ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target="$ac_optarg" ;; + target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; - -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 2.13" - exit 0 ;; + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; -with-* | --with-*) - ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'` + ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; - *) ac_optarg=yes ;; - esac - eval "with_${ac_package}='$ac_optarg'" ;; + expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + eval with_$ac_package=\$ac_optarg ;; -without-* | --without-*) - ac_package=`echo $ac_option|sed -e 's/-*without-//'` + ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - eval "with_${ac_package}=no" ;; + expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + eval with_$ac_package=no ;; --x) # Obsolete; use --with-x. @@ -367,187 +967,683 @@ EOF ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes="$ac_optarg" ;; + x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries="$ac_optarg" ;; + x_libraries=$ac_optarg ;; - -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } + -*) { echo "$as_me: error: unrecognized option: $ac_option +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 + { (exit 1); exit 1; }; } + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + *) - if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then - echo "configure: warning: $ac_option: invalid host type" 1>&2 - fi - if test "x$nonopt" != xNONE; then - { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } - fi - nonopt="$ac_option" + # FIXME: should be removed in autoconf 3.0. + echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} ;; esac done if test -n "$ac_prev"; then - { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; } + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + { echo "$as_me: error: missing argument to $ac_option" >&2 + { (exit 1); exit 1; }; } fi -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - -# File descriptor usage: -# 0 standard input -# 1 file creation -# 2 errors and warnings -# 3 some systems may open it to /dev/tty -# 4 used on the Kubota Titan -# 6 checking for... messages and results -# 5 compiler messages saved in config.log -if test "$silent" = yes; then - exec 6>/dev/null -else - exec 6>&1 -fi -exec 5>./config.log - -echo "\ -This file contains any messages produced by compilers while -running configure, to aid debugging if configure makes a mistake. -" 1>&5 - -# Strip out --no-create and --no-recursion so they do not pile up. -# Also quote any args containing shell metacharacters. -ac_configure_args= -for ac_arg +# Be sure to have absolute directory names. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir do - case "$ac_arg" in - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) ;; - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; - *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*) - ac_configure_args="$ac_configure_args '$ac_arg'" ;; - *) ac_configure_args="$ac_configure_args $ac_arg" ;; + eval ac_val=\$$ac_var + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac + { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; } done -# NLS nuisances. -# Only set these to C if already set. These must not be set unconditionally -# because not all systems understand e.g. LANG=C (notably SCO). -# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'! -# Non-C LC_CTYPE values break the ctype check. -if test "${LANG+set}" = set; then LANG=C; export LANG; fi -if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi -if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi -if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo > confdefs.h +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + { echo "$as_me: error: Working directory cannot be determined" >&2 + { (exit 1); exit 1; }; } +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + { echo "$as_me: error: pwd does not report name of working directory" >&2 + { (exit 1); exit 1; }; } -# A filename unique to this package, relative to the directory that -# configure is in, which we can look for to find out if srcdir is correct. -ac_unique_file=doc/gperf.1 # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_prog=$0 - ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` - test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$0" || +$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$0" : 'X\(//\)[^/]' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X"$0" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then + if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; } - else - { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; } - fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 + { (exit 1); exit 1; }; } fi -srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'` +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || { echo "$as_me: error: $ac_msg" >&2 + { (exit 1); exit 1; }; } + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures this package to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF +_ACEOF fi -for ac_site_file in $CONFIG_SITE; do + +if test -n "$ac_init_help"; then + + cat <<\_ACEOF + +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +configure +generated by GNU Autoconf 2.61 + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by $as_me, which was +generated by GNU Autoconf 2.61. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + echo "PATH: $as_dir" +done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; + 2) + ac_configure_args1="$ac_configure_args1 '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + ac_configure_args="$ac_configure_args '$ac_arg'" + ;; + esac + done +done +$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } +$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + cat <<\_ASBOX +## ---------------- ## +## Cache variables. ## +## ---------------- ## +_ASBOX + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + cat <<\_ASBOX +## ----------------- ## +## Output variables. ## +## ----------------- ## +_ASBOX + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + cat <<\_ASBOX +## ------------------- ## +## File substitutions. ## +## ------------------- ## +_ASBOX + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + cat <<\_ASBOX +## ----------- ## +## confdefs.h. ## +## ----------- ## +_ASBOX + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + echo "$as_me: caught signal $ac_signal" + echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer explicitly selected file to automatically selected ones. +if test -n "$CONFIG_SITE"; then + set x "$CONFIG_SITE" +elif test "x$prefix" != xNONE; then + set x "$prefix/share/config.site" "$prefix/etc/config.site" +else + set x "$ac_default_prefix/share/config.site" \ + "$ac_default_prefix/etc/config.site" +fi +shift +for ac_site_file +do if test -r "$ac_site_file"; then - echo "loading site script $ac_site_file" + { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 +echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" fi done if test -r "$cache_file"; then - echo "loading cache $cache_file" - . $cache_file -else - echo "creating cache $cache_file" - > $cache_file -fi - -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross - -ac_exeext= -ac_objext=o -if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then - # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. - if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then - ac_n= ac_c=' -' ac_t=' ' - else - ac_n=-n ac_c= ac_t= + # Some versions of bash will fail to source /dev/null (special + # files actually), so we avoid doing that. + if test -f "$cache_file"; then + { echo "$as_me:$LINENO: loading cache $cache_file" >&5 +echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac fi else - ac_n= ac_c='\c' ac_t= + { echo "$as_me:$LINENO: creating cache $cache_file" >&5 +echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 +echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { echo "$as_me:$LINENO: former value: $ac_old_val" >&5 +echo "$as_me: former value: $ac_old_val" >&2;} + { echo "$as_me:$LINENO: current value: $ac_new_val" >&5 +echo "$as_me: current value: $ac_new_val" >&2;} + ac_cache_corrupted=: + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 +echo "$as_me: error: changes in the environment can compromise the build" >&2;} + { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 +echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} + { (exit 1); exit 1; }; } fi -echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6 -echo "configure:526: checking whether ${MAKE-make} sets \${MAKE}" >&5 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + + + + + + + + + + + + + + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +{ echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +echo $ECHO_N "checking whether ${MAKE-make} sets \$(MAKE)... $ECHO_C" >&6; } +set x ${MAKE-make}; ac_make=`echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - cat > conftestmake <<\EOF + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh all: - @echo 'ac_maketemp="${MAKE}"' -EOF + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF # GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftestmake 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make fi -rm -f conftestmake -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$ac_t""yes" 1>&6 +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } SET_MAKE= else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi + + + +ac_aux_dir=$srcdir + +subdirs="$subdirs lib src tests doc" + + extrasub="$extrasub"' /@subdir@/{ h @@ -566,349 +1662,1183 @@ p d } ' -trap '' 1 2 15 -cat > confcache <<\EOF +ac_config_files="$ac_config_files Makefile" + +cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure -# scripts and configure runs. It is not useful on other systems. -# If it contains results you don't want to keep, you may remove or edit it. +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. # -# By default, configure uses ./config.cache as the cache file, -# creating it if it does not exist already. You can give configure -# the --cache-file=FILE option to use a different cache file; that is -# what configure does when it calls configure scripts in -# subdirectories, so they share the cache. -# Giving --cache-file=/dev/null disables caching, for debugging configure. -# config.status only pays attention to the cache file if you give it the -# --recheck option to rerun configure. +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. # -EOF +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. +# So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. -(set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote substitution - # turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - -e "s/'/'\\\\''/g" \ - -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p' - ;; - esac >> confcache -if cmp -s $cache_file confcache; then - : -else - if test -w $cache_file; then - echo "updating cache $cache_file" - cat confcache > $cache_file +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + test "x$cache_file" != "x/dev/null" && + { echo "$as_me:$LINENO: updating cache $cache_file" >&5 +echo "$as_me: updating cache $cache_file" >&6;} + cat confcache >$cache_file else - echo "not updating unwritable cache $cache_file" + { echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5 +echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' -# Any assignment to VPATH causes Sun make to only execute -# the first set of double-colon rules, so remove it if not needed. -# If there is a colon in the path, we need to keep it. -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d' -fi - -trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 - # Transform confdefs.h into DEFS. # Protect against shell expansion while executing Makefile rules. # Protect against Makefile macro expansion. -cat > conftest.defs <<\EOF -s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%-D\1=\2%g -s%[ `~#$^&*(){}\\|;'"<>?]%\\&%g -s%\[%\\&%g -s%\]%\\&%g -s%\$%$$%g -EOF -DEFS=`sed -f conftest.defs confdefs.h | tr '\012' ' '` -rm -f conftest.defs +# +# If the first sed substitution is executed (which looks for macros that +# take arguments), then branch to the quote section. Otherwise, +# look for a macro that doesn't take arguments. +ac_script=' +t clear +:clear +s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g +t quote +s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g +t quote +b any +:quote +s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g +s/\[/\\&/g +s/\]/\\&/g +s/\$/$$/g +H +:any +${ + g + s/^\n// + s/\n/ /g + p +} +' +DEFS=`sed -n "$ac_script" confdefs.h` + + +ac_libobjs= +ac_ltlibobjs= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext" + ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + -# Without the "./", some shells look in PATH for config.status. : ${CONFIG_STATUS=./config.status} - -echo creating $CONFIG_STATUS -rm -f $CONFIG_STATUS -cat > $CONFIG_STATUS <&5 +echo "$as_me: creating $CONFIG_STATUS" >&6;} +cat >$CONFIG_STATUS <<_ACEOF +#! $SHELL +# Generated by $as_me. # Run this file to recreate the current configuration. -# This directory was configured as follows, -# on host `(hostname || uname -n) 2>/dev/null | sed 1q`: -# -# $0 $ac_configure_args -# # Compiler output produced by configure, useful for debugging -# configure, is in ./config.log if it exists. +# configure, is in config.log if it exists. -ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]" -for ac_option -do - case "\$ac_option" in - -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" - exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; - -version | --version | --versio | --versi | --vers | --ver | --ve | --v) - echo "$CONFIG_STATUS generated by autoconf version 2.13" - exit 0 ;; - -help | --help | --hel | --he | --h) - echo "\$ac_cs_usage"; exit 0 ;; - *) echo "\$ac_cs_usage"; exit 1 ;; - esac -done +debug=false +ac_cs_recheck=false +ac_cs_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_ACEOF -ac_given_srcdir=$srcdir +cat >>$CONFIG_STATUS <<\_ACEOF +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## -trap 'rm -fr `echo "Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 -EOF -cat >> $CONFIG_STATUS </dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac -# Protect against being on the right side of a sed subst in config.status. -sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g; - s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF -$ac_vpsub -$extrasub -s%@SHELL@%$SHELL%g -s%@CFLAGS@%$CFLAGS%g -s%@CPPFLAGS@%$CPPFLAGS%g -s%@CXXFLAGS@%$CXXFLAGS%g -s%@FFLAGS@%$FFLAGS%g -s%@DEFS@%$DEFS%g -s%@LDFLAGS@%$LDFLAGS%g -s%@LIBS@%$LIBS%g -s%@exec_prefix@%$exec_prefix%g -s%@prefix@%$prefix%g -s%@program_transform_name@%$program_transform_name%g -s%@bindir@%$bindir%g -s%@sbindir@%$sbindir%g -s%@libexecdir@%$libexecdir%g -s%@datadir@%$datadir%g -s%@sysconfdir@%$sysconfdir%g -s%@sharedstatedir@%$sharedstatedir%g -s%@localstatedir@%$localstatedir%g -s%@libdir@%$libdir%g -s%@includedir@%$includedir%g -s%@oldincludedir@%$oldincludedir%g -s%@infodir@%$infodir%g -s%@mandir@%$mandir%g -s%@SET_MAKE@%$SET_MAKE%g - -CEOF -EOF - -cat >> $CONFIG_STATUS <<\EOF - -# Split the substitutions into bite-sized pieces for seds with -# small command number limits, like on Digital OSF/1 and HP-UX. -ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script. -ac_file=1 # Number of current file. -ac_beg=1 # First line for current file. -ac_end=$ac_max_sed_cmds # Line after last line for current file. -ac_more_lines=: -ac_sed_cmds="" -while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file - else - sed "${ac_end}q" conftest.subs > conftest.s$ac_file - fi - if test ! -s conftest.s$ac_file; then - ac_more_lines=false - rm -f conftest.s$ac_file - else - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f conftest.s$ac_file" - else - ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file" - fi - ac_file=`expr $ac_file + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_cmds` - fi -done -if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat fi -EOF -cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF -for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case "$ac_file" in - *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` - ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; - *) ac_file_in="${ac_file}.in" ;; - esac - # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories. - # Remove last slash and all that follows it. Not all systems have dirname. - ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - # The file is in a subdirectory. - test ! -d "$ac_dir" && mkdir "$ac_dir" - ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`" - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' else - ac_dir_suffix= ac_dots= + PATH_SEPARATOR=: fi + rm -f conf$$.sh +fi - case "$ac_given_srcdir" in - .) srcdir=. - if test -z "$ac_dots"; then top_srcdir=. - else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;; - /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;; - *) # Relative path. - srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix" - top_srcdir="$ac_dots$ac_given_srcdir" ;; +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 + +# Save the log message, to keep $[0] and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by $as_me, which was +generated by GNU Autoconf 2.61. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF +# Files that config.status was made for. +config_files="$ac_config_files" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +ac_cs_usage="\ +\`$as_me' instantiates files from templates according to the +current configuration. + +Usage: $0 [OPTIONS] [FILE]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + +Configuration files: +$config_files + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +ac_cs_version="\\ +config.status +configured by $0, generated by GNU Autoconf 2.61, + with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" + +Copyright (C) 2006 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If no file are specified by the user, then we need to provide default +# value. By we need to know if files were specified by the user. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; esac + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + echo "$ac_cs_version"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + CONFIG_FILES="$CONFIG_FILES $ac_optarg" + ac_need_defaults=false;; + --he | --h | --help | --hel | -h ) + echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; - echo creating "$ac_file" - rm -f "$ac_file" - configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure." - case "$ac_file" in - *Makefile*) ac_comsub="1i\\ -# $configure_input" ;; - *) ac_comsub= ;; + # This is an error. + -*) { echo "$as_me: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + + *) ac_config_targets="$ac_config_targets $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +if \$ac_cs_recheck; then + echo "running CONFIG_SHELL=$SHELL $SHELL $0 "$ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6 + CONFIG_SHELL=$SHELL + export CONFIG_SHELL + exec $SHELL "$0"$ac_configure_args \$ac_configure_extra_args --no-create --no-recursion +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + + *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 +echo "$as_me: error: invalid argument: $ac_config_target" >&2;} + { (exit 1); exit 1; }; };; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= + trap 'exit_status=$? + { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status +' 0 + trap '{ (exit 1); exit 1; }' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || +{ + echo "$me: cannot create a temporary directory in ." >&2 + { (exit 1); exit 1; } +} + +# +# Set up the sed scripts for CONFIG_FILES section. +# + +# No need to generate the scripts if there are no CONFIG_FILES. +# This happens for instance when ./config.status config.h +if test -n "$CONFIG_FILES"; then + +_ACEOF + + + +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + cat >conf$$subs.sed <<_ACEOF +SHELL!$SHELL$ac_delim +PATH_SEPARATOR!$PATH_SEPARATOR$ac_delim +PACKAGE_NAME!$PACKAGE_NAME$ac_delim +PACKAGE_TARNAME!$PACKAGE_TARNAME$ac_delim +PACKAGE_VERSION!$PACKAGE_VERSION$ac_delim +PACKAGE_STRING!$PACKAGE_STRING$ac_delim +PACKAGE_BUGREPORT!$PACKAGE_BUGREPORT$ac_delim +exec_prefix!$exec_prefix$ac_delim +prefix!$prefix$ac_delim +program_transform_name!$program_transform_name$ac_delim +bindir!$bindir$ac_delim +sbindir!$sbindir$ac_delim +libexecdir!$libexecdir$ac_delim +datarootdir!$datarootdir$ac_delim +datadir!$datadir$ac_delim +sysconfdir!$sysconfdir$ac_delim +sharedstatedir!$sharedstatedir$ac_delim +localstatedir!$localstatedir$ac_delim +includedir!$includedir$ac_delim +oldincludedir!$oldincludedir$ac_delim +docdir!$docdir$ac_delim +infodir!$infodir$ac_delim +htmldir!$htmldir$ac_delim +dvidir!$dvidir$ac_delim +pdfdir!$pdfdir$ac_delim +psdir!$psdir$ac_delim +libdir!$libdir$ac_delim +localedir!$localedir$ac_delim +mandir!$mandir$ac_delim +DEFS!$DEFS$ac_delim +ECHO_C!$ECHO_C$ac_delim +ECHO_N!$ECHO_N$ac_delim +ECHO_T!$ECHO_T$ac_delim +LIBS!$LIBS$ac_delim +build_alias!$build_alias$ac_delim +host_alias!$host_alias$ac_delim +target_alias!$target_alias$ac_delim +SET_MAKE!$SET_MAKE$ac_delim +subdirs!$subdirs$ac_delim +LIBOBJS!$LIBOBJS$ac_delim +LTLIBOBJS!$LTLIBOBJS$ac_delim +_ACEOF + + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 41; then + break + elif $ac_last_try; then + { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 +echo "$as_me: error: could not make $CONFIG_STATUS" >&2;} + { (exit 1); exit 1; }; } + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed` +if test -n "$ac_eof"; then + ac_eof=`echo "$ac_eof" | sort -nru | sed 1q` + ac_eof=`expr $ac_eof + 1` +fi + +cat >>$CONFIG_STATUS <<_ACEOF +cat >"\$tmp/subs-1.sed" <<\CEOF$ac_eof +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b end +_ACEOF +sed ' +s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g +s/^/s,@/; s/!/@,|#_!!_#|/ +:n +t n +s/'"$ac_delim"'$/,g/; t +s/$/\\/; p +N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n +' >>$CONFIG_STATUS >$CONFIG_STATUS <<_ACEOF +:end +s/|#_!!_#|//g +CEOF$ac_eof +_ACEOF + + +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/ +s/:*\${srcdir}:*/:/ +s/:*@srcdir@:*/:/ +s/^\([^=]*=[ ]*\):*/\1/ +s/:*$// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF +fi # test -n "$CONFIG_FILES" + + +for ac_tag in :F $CONFIG_FILES +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) { { echo "$as_me:$LINENO: error: Invalid tag $ac_tag." >&5 +echo "$as_me: error: Invalid tag $ac_tag." >&2;} + { (exit 1); exit 1; }; };; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + { { echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5 +echo "$as_me: error: cannot find input file: $ac_f" >&2;} + { (exit 1); exit 1; }; };; + esac + ac_file_inputs="$ac_file_inputs $ac_f" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input="Generated from "`IFS=: + echo $* | sed 's|^[^:]*/||;s|:[^:]*/|, |g'`" by configure." + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + fi + + case $ac_tag in + *:-:* | *:-) cat >"$tmp/stdin";; + esac + ;; esac - ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` - sed -e "$ac_comsub -s%@configure_input@%$configure_input%g -s%@srcdir@%$srcdir%g -s%@top_srcdir@%$top_srcdir%g -" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file -fi; done -rm -f conftest.s* + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + { as_dir="$ac_dir" + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5 +echo "$as_me: error: cannot create directory $as_dir" >&2;} + { (exit 1); exit 1; }; }; } + ac_builddir=. -EOF -cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix -exit 0 -EOF + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= + +case `sed -n '/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p +' $ac_file_inputs` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF + sed "$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s&@configure_input@&$configure_input&;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +$ac_datarootdir_hack +" $ac_file_inputs | sed -f "$tmp/subs-1.sed" >$tmp/out + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && + { echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&5 +echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&2;} + + rm -f "$tmp/stdin" + case $ac_file in + -) cat "$tmp/out"; rm -f "$tmp/out";; + *) rm -f "$ac_file"; mv "$tmp/out" $ac_file;; + esac + ;; + + + + esac + +done # for ac_tag + + +{ (exit 0); exit 0; } +_ACEOF chmod +x $CONFIG_STATUS -rm -fr confdefs* $ac_clean_files -test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1 +ac_clean_files=$ac_clean_files_save +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || { (exit 1); exit 1; } +fi + +# +# CONFIG_SUBDIRS section. +# if test "$no_recursion" != yes; then # Remove --cache-file and --srcdir arguments so they do not pile up. ac_sub_configure_args= ac_prev= - for ac_arg in $ac_configure_args; do + eval "set x $ac_configure_args" + shift + for ac_arg + do if test -n "$ac_prev"; then ac_prev= continue fi - case "$ac_arg" in + case $ac_arg in -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* \ + | --c=*) + ;; + --config-cache | -C) ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) ;; - *) ac_sub_configure_args="$ac_sub_configure_args $ac_arg" ;; + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + ;; + *) + case $ac_arg in + *\'*) ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + ac_sub_configure_args="$ac_sub_configure_args '$ac_arg'" ;; esac done - for ac_config_dir in lib src tests doc; do + # Always prepend --prefix to ensure using the same prefix + # in subdir configurations. + ac_arg="--prefix=$prefix" + case $ac_arg in + *\'*) ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + ac_sub_configure_args="'$ac_arg' $ac_sub_configure_args" + + # Pass --silent + if test "$silent" = yes; then + ac_sub_configure_args="--silent $ac_sub_configure_args" + fi + + ac_popdir=`pwd` + for ac_dir in : $subdirs; do test "x$ac_dir" = x: && continue # Do not complain, so a configure script can configure whichever # parts of a large source tree are present. - if test ! -d $srcdir/$ac_config_dir; then - continue - fi + test -d "$srcdir/$ac_dir" || continue - echo configuring in $ac_config_dir + ac_msg="=== configuring in $ac_dir (`pwd`/$ac_dir)" + echo "$as_me:$LINENO: $ac_msg" >&5 + echo "$ac_msg" >&6 + { as_dir="$ac_dir" + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5 +echo "$as_me: error: cannot create directory $as_dir" >&2;} + { (exit 1); exit 1; }; }; } + ac_builddir=. - case "$srcdir" in - .) ;; - *) - if test -d ./$ac_config_dir || mkdir ./$ac_config_dir; then :; - else - { echo "configure: error: can not create `pwd`/$ac_config_dir" 1>&2; exit 1; } - fi - ;; - esac +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix - ac_popdir=`pwd` - cd $ac_config_dir +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix - # A "../" for each directory in /$ac_config_dir. - ac_dots=`echo $ac_config_dir|sed -e 's%^\./%%' -e 's%[^/]$%&/%' -e 's%[^/]*/%../%g'` - case "$srcdir" in - .) # No --srcdir option. We are building in place. - ac_sub_srcdir=$srcdir ;; - /*) # Absolute path. - ac_sub_srcdir=$srcdir/$ac_config_dir ;; - *) # Relative path. - ac_sub_srcdir=$ac_dots$srcdir/$ac_config_dir ;; - esac + cd "$ac_dir" # Check for guested configure; otherwise get Cygnus style configure. - if test -f $ac_sub_srcdir/configure; then - ac_sub_configure=$ac_sub_srcdir/configure - elif test -f $ac_sub_srcdir/configure.in; then - ac_sub_configure=$ac_configure + if test -f "$ac_srcdir/configure.gnu"; then + ac_sub_configure=$ac_srcdir/configure.gnu + elif test -f "$ac_srcdir/configure"; then + ac_sub_configure=$ac_srcdir/configure + elif test -f "$ac_srcdir/configure.in"; then + # This should be Cygnus configure. + ac_sub_configure=$ac_aux_dir/configure else - echo "configure: warning: no configuration information is in $ac_config_dir" 1>&2 + { echo "$as_me:$LINENO: WARNING: no configuration information is in $ac_dir" >&5 +echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2;} ac_sub_configure= fi # The recursion is here. if test -n "$ac_sub_configure"; then - # Make the cache file name correct relative to the subdirectory. - case "$cache_file" in - /*) ac_sub_cache_file=$cache_file ;; - *) # Relative path. - ac_sub_cache_file="$ac_dots$cache_file" ;; + case $cache_file in + [\\/]* | ?:[\\/]* ) ac_sub_cache_file=$cache_file ;; + *) # Relative name. + ac_sub_cache_file=$ac_top_build_prefix$cache_file ;; esac - echo "running ${CONFIG_SHELL-/bin/sh} $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_sub_srcdir" + { echo "$as_me:$LINENO: running $SHELL $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&5 +echo "$as_me: running $SHELL $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&6;} # The eval makes quoting arguments work. - if eval ${CONFIG_SHELL-/bin/sh} $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_sub_srcdir - then : - else - { echo "configure: error: $ac_sub_configure failed for $ac_config_dir" 1>&2; exit 1; } - fi + eval "\$SHELL \"\$ac_sub_configure\" $ac_sub_configure_args \ + --cache-file=\"\$ac_sub_cache_file\" --srcdir=\"\$ac_srcdir\"" || + { { echo "$as_me:$LINENO: error: $ac_sub_configure failed for $ac_dir" >&5 +echo "$as_me: error: $ac_sub_configure failed for $ac_dir" >&2;} + { (exit 1); exit 1; }; } fi - cd $ac_popdir + cd "$ac_popdir" done fi diff --git a/contrib/gperf/configure.in b/contrib/gperf/configure.ac similarity index 58% rename from contrib/gperf/configure.in rename to contrib/gperf/configure.ac index 5ac1499aa124..afcb112995a5 100644 --- a/contrib/gperf/configure.in +++ b/contrib/gperf/configure.ac @@ -1,13 +1,14 @@ dnl autoconf configuration for gperf -dnl Copyright (C) 1998 Free Software Foundation, Inc. -dnl written by Douglas C. Schmidt (schmidt@ics.uci.edu) +dnl Copyright (C) 1998, 2002, 2003, 2005-2007 Free Software Foundation, Inc. +dnl Written by Douglas C. Schmidt +dnl and Bruno Haible . dnl dnl This file is part of GNU GPERF. dnl dnl GNU GPERF is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by -dnl the Free Software Foundation; either version 1, or (at your option) +dnl the Free Software Foundation; either version 2, or (at your option) dnl any later version. dnl dnl GNU GPERF is distributed in the hope that it will be useful, @@ -16,12 +17,21 @@ dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the dnl GNU General Public License for more details. dnl dnl You should have received a copy of the GNU General Public License -dnl along with GNU GPERF; see the file COPYING. If not, write to the -dnl Free Software Foundation, 59 Temple Place - Suite 330, Boston, -dnl MA 02111-1307, USA. +dnl along with this program; see the file COPYING. +dnl If not, write to the Free Software Foundation, Inc., +dnl 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +AC_PREREQ([2.60]) AC_INIT(doc/gperf.1) AC_PROG_MAKE_SET +AC_OBJEXT +AC_EXEEXT + +dnl An autoconf-2.52 bug: AC_CONFIG_SUBDIRS requires AC_CONFIG_AUX_DIR_DEFAULT. +ac_aux_dir=$srcdir +AC_PROVIDE([AC_CONFIG_AUX_DIR_DEFAULT]) +AC_CONFIG_SUBDIRS(lib src tests doc) + dnl This piece of sed script replaces every line containing '@subdir@' dnl by several consecutive lines, each referencing one subdir. extrasub="$extrasub"' @@ -43,4 +53,3 @@ d } ' AC_OUTPUT(Makefile) -AC_OUTPUT_SUBDIRS(lib src tests doc) diff --git a/contrib/gperf/doc/Makefile.in b/contrib/gperf/doc/Makefile.in index 99ac03d1b68c..e68bc632ee18 100644 --- a/contrib/gperf/doc/Makefile.in +++ b/contrib/gperf/doc/Makefile.in @@ -1,12 +1,14 @@ # Makefile for gperf/doc -# Copyright (C) 1998, 2000 Free Software Foundation, Inc. +# Copyright (C) 1998, 2000, 2002-2003, 2007 Free Software Foundation, Inc. +# Written by Douglas C. Schmidt +# and Bruno Haible . # # This file is part of GNU GPERF. # # GNU GPERF is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 1, or (at your option) +# the Free Software Foundation; either version 2, or (at your option) # any later version. # # GNU GPERF is distributed in the hope that it will be useful, @@ -15,8 +17,9 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with GNU GPERF; see the file COPYING. If not, write to the Free -# Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. +# along with this program; see the file COPYING. +# If not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #### Start of system configuration section. #### @@ -27,14 +30,16 @@ srcdir = @srcdir@ prefix = @prefix@ local_prefix = /usr/local exec_prefix = @exec_prefix@ +datarootdir = @datarootdir@ datadir = @datadir@ infodir = @infodir@ mandir = @mandir@ man1dir = $(mandir)/man1 -docdir = $(prefix)/doc/@PACKAGE@ -dvidir = $(docdir) -psdir = $(docdir) -htmldir = $(docdir) +docdir = @docdir@ +dvidir = @dvidir@ +psdir = @psdir@ +pdfdir = @pdfdir@ +htmldir = @htmldir@ # Programs used by "make": RM = rm -f @@ -44,7 +49,8 @@ RM = rm -f TEX = tex TEXI2DVI = texi2dvi DVIPS = dvips -D600 -MAKEINFO = LANG= LANGUAGE= makeinfo +TEXI2PDF = texi2pdf +MAKEINFO = LANG= LC_MESSAGES= LC_ALL= LANGUAGE= makeinfo TEXI2HTML = texi2html # Programs used by "make install": @@ -59,7 +65,7 @@ SHELL = /bin/sh VPATH = $(srcdir) -all : info dvi ps html +all : info ps pdf html info : $(srcdir)/gperf.info @@ -79,7 +85,15 @@ $(srcdir)/gperf.dvi : $(srcdir)/gperf.texi $(srcdir)/gpl.texinfo ps : $(srcdir)/gperf.ps $(srcdir)/gperf.ps : $(srcdir)/gperf.dvi - $(DVIPS) -o $@ $< + $(DVIPS) -o $@ $(srcdir)/gperf.dvi + + +pdf : $(srcdir)/gperf.pdf + +$(srcdir)/gperf.pdf : $(srcdir)/gperf.texi $(srcdir)/gpl.texinfo + cd $(srcdir) && $(RM) gperf.aux gperf.toc gperf.cp gperf.fn gperf.ky gperf.pg gperf.tp gperf.vr gperf.log gperf.cps + cd $(srcdir) && $(TEXI2PDF) gperf.texi + cd $(srcdir) && $(RM) gperf.aux gperf.toc gperf.cp gperf.fn gperf.ky gperf.pg gperf.tp gperf.vr gperf.log gperf.cps html : gperf.html gperf_toc.html @@ -100,7 +114,9 @@ install : all force # $(MKINSTALLDIRS) $(DESTDIR)$(dvidir) # $(INSTALL_DATA) $(srcdir)/gperf.dvi $(DESTDIR)$(dvidir)/gperf.dvi # $(MKINSTALLDIRS) $(DESTDIR)$(psdir) -# $(INSTALL_DATA) $(srcdir)/gperf.ps $(DESTDIR)$(dvidir)/gperf.ps +# $(INSTALL_DATA) $(srcdir)/gperf.ps $(DESTDIR)$(psdir)/gperf.ps +# $(MKINSTALLDIRS) $(DESTDIR)$(pdfdir) +# $(INSTALL_DATA) $(srcdir)/gperf.pdf $(DESTDIR)$(pdfdir)/gperf.pdf $(MKINSTALLDIRS) $(DESTDIR)$(htmldir) $(INSTALL_DATA) $(srcdir)/gperf.html $(DESTDIR)$(htmldir)/gperf.html @@ -109,6 +125,7 @@ installdirs : force $(MKINSTALLDIRS) $(DESTDIR)$(man1dir) # $(MKINSTALLDIRS) $(DESTDIR)$(dvidir) # $(MKINSTALLDIRS) $(DESTDIR)$(psdir) +# $(MKINSTALLDIRS) $(DESTDIR)$(pdfdir) $(MKINSTALLDIRS) $(DESTDIR)$(htmldir) uninstall : force @@ -116,6 +133,7 @@ uninstall : force $(RM) $(DESTDIR)$(man1dir)/gperf.1 # $(RM) $(DESTDIR)$(dvidir)/gperf.dvi # $(RM) $(DESTDIR)$(psdir)/gperf.ps +# $(RM) $(DESTDIR)$(pdfdir)/gperf.pdf $(RM) $(DESTDIR)$(htmldir)/gperf.html check : all @@ -129,7 +147,7 @@ distclean : clean $(RM) config.status config.log config.cache Makefile maintainer-clean : distclean - $(RM) *.info *.dvi *.ps *.html + $(RM) *.info *.dvi *.ps *.pdf *.html force : diff --git a/contrib/gperf/doc/configure b/contrib/gperf/doc/configure index a10049f45e63..7852e793c02d 100755 --- a/contrib/gperf/doc/configure +++ b/contrib/gperf/doc/configure @@ -1,26 +1,640 @@ #! /bin/sh - # Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 2.13 -# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. +# Generated by GNU Autoconf 2.61. # +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## -# Defaults: -ac_help= +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + + + +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + +if test "x$CONFIG_SHELL" = x; then + if (eval ":") 2>/dev/null; then + as_have_required=yes +else + as_have_required=no +fi + + if test $as_have_required = yes && (eval ": +(as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=\$LINENO + as_lineno_2=\$LINENO + test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" && + test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; } +") 2> /dev/null; then + : +else + as_candidate_shells= + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + case $as_dir in + /*) + for as_base in sh bash ksh sh5; do + as_candidate_shells="$as_candidate_shells $as_dir/$as_base" + done;; + esac +done +IFS=$as_save_IFS + + + for as_shell in $as_candidate_shells $SHELL; do + # Try only shells that exist, to save several forks. + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { ("$as_shell") 2> /dev/null <<\_ASEOF +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + +: +_ASEOF +}; then + CONFIG_SHELL=$as_shell + as_have_required=yes + if { "$as_shell" 2> /dev/null <<\_ASEOF +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + +: +(as_func_return () { + (exit $1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = "$1" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test $exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; } + +_ASEOF +}; then + break +fi + +fi + + done + + if test "x$CONFIG_SHELL" != x; then + for as_var in BASH_ENV ENV + do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + done + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} +fi + + + if test $as_have_required = no; then + echo This script requires a shell more modern than all the + echo shells that I found on your system. Please install a + echo modern shell, or manually run the script under such a + echo shell if you do have one. + { (exit 1); exit 1; } +fi + + +fi + +fi + + + +(eval "as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0") || { + echo No shell found that supports shell functions. + echo Please tell autoconf@gnu.org about your system, + echo including any error possibly output before this + echo message +} + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + + +exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# ac_default_prefix=/usr/local -# Any additions from configure.in: +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} + +# Identity of this package. +PACKAGE_NAME= +PACKAGE_TARNAME= +PACKAGE_VERSION= +PACKAGE_STRING= +PACKAGE_BUGREPORT= + +ac_unique_file="gperf.1" +ac_subst_vars='SHELL +PATH_SEPARATOR +PACKAGE_NAME +PACKAGE_TARNAME +PACKAGE_VERSION +PACKAGE_STRING +PACKAGE_BUGREPORT +exec_prefix +prefix +program_transform_name +bindir +sbindir +libexecdir +datarootdir +datadir +sysconfdir +sharedstatedir +localstatedir +includedir +oldincludedir +docdir +infodir +htmldir +dvidir +pdfdir +psdir +libdir +localedir +mandir +DEFS +ECHO_C +ECHO_N +ECHO_T +LIBS +build_alias +host_alias +target_alias +PACKAGE +SET_MAKE +INSTALL +INSTALL_PROGRAM +INSTALL_DATA +LIBOBJS +LTLIBOBJS' +ac_subst_files='' + ac_precious_vars='build_alias +host_alias +target_alias' + # Initialize some variables set by options. +ac_init_help= +ac_init_version=false # The variables have the same names as the options, with # dashes changed to underlines. -build=NONE -cache_file=./config.cache +cache_file=/dev/null exec_prefix=NONE -host=NONE no_create= -nonopt=NONE no_recursion= prefix=NONE program_prefix=NONE @@ -29,94 +643,117 @@ program_transform_name=s,x,x, silent= site= srcdir= -target=NONE verbose= x_includes=NONE x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' +datarootdir='${prefix}/share' +datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' includedir='${prefix}/include' oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -# Initialize some other variables. -subdirs= -MFLAGS= MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} -# Maximum number of lines to put in a shell here document. -ac_max_here_lines=12 +docdir='${datarootdir}/doc/${PACKAGE}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' ac_prev= +ac_dashdash= for ac_option do - # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" + eval $ac_prev=\$ac_option ac_prev= continue fi - case "$ac_option" in - -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; - *) ac_optarg= ;; + case $ac_option in + *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. - case "$ac_option" in + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir="$ac_optarg" ;; + bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) - ac_prev=build ;; + ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build="$ac_optarg" ;; + build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file="$ac_optarg" ;; + cache_file=$ac_optarg ;; - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir="$ac_optarg" ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; -disable-* | --disable-*) - ac_feature=`echo $ac_option|sed -e 's/-*disable-//'` + ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - eval "enable_${ac_feature}=no" ;; + expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + eval enable_$ac_feature=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; -enable-* | --enable-*) - ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'` + ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; - *) ac_optarg=yes ;; - esac - eval "enable_${ac_feature}='$ac_optarg'" ;; + expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + eval enable_$ac_feature=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ @@ -125,116 +762,77 @@ do -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) - exec_prefix="$ac_optarg" ;; + exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; - -help | --help | --hel | --he) - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat << EOF -Usage: configure [options] [host] -Options: [defaults in brackets after descriptions] -Configuration: - --cache-file=FILE cache test results in FILE - --help print this message - --no-create do not create output files - --quiet, --silent do not print \`checking...' messages - --version print the version of autoconf that created configure -Directory and file names: - --prefix=PREFIX install architecture-independent files in PREFIX - [$ac_default_prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [same as prefix] - --bindir=DIR user executables in DIR [EPREFIX/bin] - --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] - --libexecdir=DIR program executables in DIR [EPREFIX/libexec] - --datadir=DIR read-only architecture-independent data in DIR - [PREFIX/share] - --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] - --sharedstatedir=DIR modifiable architecture-independent data in DIR - [PREFIX/com] - --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] - --libdir=DIR object code libraries in DIR [EPREFIX/lib] - --includedir=DIR C header files in DIR [PREFIX/include] - --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] - --infodir=DIR info documentation in DIR [PREFIX/info] - --mandir=DIR man documentation in DIR [PREFIX/man] - --srcdir=DIR find the sources in DIR [configure dir or ..] - --program-prefix=PREFIX prepend PREFIX to installed program names - --program-suffix=SUFFIX append SUFFIX to installed program names - --program-transform-name=PROGRAM - run sed PROGRAM on installed program names -EOF - cat << EOF -Host type: - --build=BUILD configure for building on BUILD [BUILD=HOST] - --host=HOST configure for HOST [guessed] - --target=TARGET configure for TARGET [TARGET=HOST] -Features and packages: - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] - --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) - --x-includes=DIR X include files are in DIR - --x-libraries=DIR X library files are in DIR -EOF - if test -n "$ac_help"; then - echo "--enable and --with options recognized:$ac_help" - fi - exit 0 ;; + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; -host | --host | --hos | --ho) - ac_prev=host ;; + ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) - host="$ac_optarg" ;; + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir="$ac_optarg" ;; + includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir="$ac_optarg" ;; + infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir="$ac_optarg" ;; + libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) - libexecdir="$ac_optarg" ;; + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) + | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir="$ac_optarg" ;; + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir="$ac_optarg" ;; + mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) + | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ @@ -248,26 +846,26 @@ EOF -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir="$ac_optarg" ;; + oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix="$ac_optarg" ;; + prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix="$ac_optarg" ;; + program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix="$ac_optarg" ;; + program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ @@ -284,7 +882,17 @@ EOF | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name="$ac_optarg" ;; + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) @@ -294,7 +902,7 @@ EOF ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) - sbindir="$ac_optarg" ;; + sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ @@ -305,58 +913,53 @@ EOF | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) - sharedstatedir="$ac_optarg" ;; + sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) - site="$ac_optarg" ;; + site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir="$ac_optarg" ;; + srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir="$ac_optarg" ;; + sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target ;; + ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target="$ac_optarg" ;; + target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; - -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 2.13" - exit 0 ;; + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; -with-* | --with-*) - ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'` + ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; - *) ac_optarg=yes ;; - esac - eval "with_${ac_package}='$ac_optarg'" ;; + expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + eval with_$ac_package=\$ac_optarg ;; -without-* | --without-*) - ac_package=`echo $ac_option|sed -e 's/-*without-//'` + ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - eval "with_${ac_package}=no" ;; + expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + eval with_$ac_package=no ;; --x) # Obsolete; use --with-x. @@ -367,186 +970,674 @@ EOF ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes="$ac_optarg" ;; + x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries="$ac_optarg" ;; + x_libraries=$ac_optarg ;; - -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } + -*) { echo "$as_me: error: unrecognized option: $ac_option +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 + { (exit 1); exit 1; }; } + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + *) - if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then - echo "configure: warning: $ac_option: invalid host type" 1>&2 - fi - if test "x$nonopt" != xNONE; then - { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } - fi - nonopt="$ac_option" + # FIXME: should be removed in autoconf 3.0. + echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} ;; esac done if test -n "$ac_prev"; then - { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; } + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + { echo "$as_me: error: missing argument to $ac_option" >&2 + { (exit 1); exit 1; }; } fi -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - -# File descriptor usage: -# 0 standard input -# 1 file creation -# 2 errors and warnings -# 3 some systems may open it to /dev/tty -# 4 used on the Kubota Titan -# 6 checking for... messages and results -# 5 compiler messages saved in config.log -if test "$silent" = yes; then - exec 6>/dev/null -else - exec 6>&1 -fi -exec 5>./config.log - -echo "\ -This file contains any messages produced by compilers while -running configure, to aid debugging if configure makes a mistake. -" 1>&5 - -# Strip out --no-create and --no-recursion so they do not pile up. -# Also quote any args containing shell metacharacters. -ac_configure_args= -for ac_arg +# Be sure to have absolute directory names. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir do - case "$ac_arg" in - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) ;; - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; - *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*) - ac_configure_args="$ac_configure_args '$ac_arg'" ;; - *) ac_configure_args="$ac_configure_args $ac_arg" ;; + eval ac_val=\$$ac_var + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac + { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; } done -# NLS nuisances. -# Only set these to C if already set. These must not be set unconditionally -# because not all systems understand e.g. LANG=C (notably SCO). -# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'! -# Non-C LC_CTYPE values break the ctype check. -if test "${LANG+set}" = set; then LANG=C; export LANG; fi -if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi -if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi -if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo > confdefs.h +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + { echo "$as_me: error: Working directory cannot be determined" >&2 + { (exit 1); exit 1; }; } +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + { echo "$as_me: error: pwd does not report name of working directory" >&2 + { (exit 1); exit 1; }; } -# A filename unique to this package, relative to the directory that -# configure is in, which we can look for to find out if srcdir is correct. -ac_unique_file=gperf.1 # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_prog=$0 - ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` - test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$0" || +$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$0" : 'X\(//\)[^/]' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X"$0" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then + if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; } - else - { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; } - fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 + { (exit 1); exit 1; }; } fi -srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'` +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || { echo "$as_me: error: $ac_msg" >&2 + { (exit 1); exit 1; }; } + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures this package to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF +_ACEOF fi -for ac_site_file in $CONFIG_SITE; do + +if test -n "$ac_init_help"; then + + cat <<\_ACEOF + +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +configure +generated by GNU Autoconf 2.61 + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by $as_me, which was +generated by GNU Autoconf 2.61. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + echo "PATH: $as_dir" +done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; + 2) + ac_configure_args1="$ac_configure_args1 '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + ac_configure_args="$ac_configure_args '$ac_arg'" + ;; + esac + done +done +$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } +$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + cat <<\_ASBOX +## ---------------- ## +## Cache variables. ## +## ---------------- ## +_ASBOX + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + cat <<\_ASBOX +## ----------------- ## +## Output variables. ## +## ----------------- ## +_ASBOX + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + cat <<\_ASBOX +## ------------------- ## +## File substitutions. ## +## ------------------- ## +_ASBOX + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + cat <<\_ASBOX +## ----------- ## +## confdefs.h. ## +## ----------- ## +_ASBOX + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + echo "$as_me: caught signal $ac_signal" + echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer explicitly selected file to automatically selected ones. +if test -n "$CONFIG_SITE"; then + set x "$CONFIG_SITE" +elif test "x$prefix" != xNONE; then + set x "$prefix/share/config.site" "$prefix/etc/config.site" +else + set x "$ac_default_prefix/share/config.site" \ + "$ac_default_prefix/etc/config.site" +fi +shift +for ac_site_file +do if test -r "$ac_site_file"; then - echo "loading site script $ac_site_file" + { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 +echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" fi done if test -r "$cache_file"; then - echo "loading cache $cache_file" - . $cache_file -else - echo "creating cache $cache_file" - > $cache_file -fi - -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross - -ac_exeext= -ac_objext=o -if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then - # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. - if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then - ac_n= ac_c=' -' ac_t=' ' - else - ac_n=-n ac_c= ac_t= + # Some versions of bash will fail to source /dev/null (special + # files actually), so we avoid doing that. + if test -f "$cache_file"; then + { echo "$as_me:$LINENO: loading cache $cache_file" >&5 +echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac fi else - ac_n= ac_c='\c' ac_t= + { echo "$as_me:$LINENO: creating cache $cache_file" >&5 +echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file fi +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 +echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { echo "$as_me:$LINENO: former value: $ac_old_val" >&5 +echo "$as_me: former value: $ac_old_val" >&2;} + { echo "$as_me:$LINENO: current value: $ac_new_val" >&5 +echo "$as_me: current value: $ac_new_val" >&2;} + ac_cache_corrupted=: + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 +echo "$as_me: error: changes in the environment can compromise the build" >&2;} + { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 +echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} + { (exit 1); exit 1; }; } +fi + + + + + + + + + + + + + + + + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + PACKAGE=gperf -echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6 -echo "configure:528: checking whether ${MAKE-make} sets \${MAKE}" >&5 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +{ echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +echo $ECHO_N "checking whether ${MAKE-make} sets \$(MAKE)... $ECHO_C" >&6; } +set x ${MAKE-make}; ac_make=`echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - cat > conftestmake <<\EOF + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh all: - @echo 'ac_maketemp="${MAKE}"' -EOF + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF # GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftestmake 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make fi -rm -f conftestmake -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$ac_t""yes" 1>&6 +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } SET_MAKE= else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi @@ -560,11 +1651,11 @@ fi # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. -echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:565: checking for a BSD compatible install" >&5 +{ echo "$as_me:$LINENO: checking for a BSD compatible install" >&5 +echo $ECHO_N "checking for a BSD compatible install... $ECHO_C" >&6; } if test -z "$INSTALL"; then -if eval "test \"`echo '$''{'cl_cv_path_install'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +if test "${cl_cv_path_install+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" for ac_dir in $PATH; do @@ -602,7 +1693,8 @@ else fi INSTALL="$cl_cv_path_install" fi -echo "$ac_t""$INSTALL" 1>&6 +{ echo "$as_me:$LINENO: result: $INSTALL" >&5 +echo "${ECHO_T}$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='$(INSTALL)' @@ -613,259 +1705,1006 @@ if test -z "$INSTALL_DATA"; then esac fi - trap '' 1 2 15 -cat > confcache <<\EOF + ac_config_files="$ac_config_files Makefile" + +cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure -# scripts and configure runs. It is not useful on other systems. -# If it contains results you don't want to keep, you may remove or edit it. +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. # -# By default, configure uses ./config.cache as the cache file, -# creating it if it does not exist already. You can give configure -# the --cache-file=FILE option to use a different cache file; that is -# what configure does when it calls configure scripts in -# subdirectories, so they share the cache. -# Giving --cache-file=/dev/null disables caching, for debugging configure. -# config.status only pays attention to the cache file if you give it the -# --recheck option to rerun configure. +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. # -EOF +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. +# So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. -(set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote substitution - # turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - -e "s/'/'\\\\''/g" \ - -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p' - ;; - esac >> confcache -if cmp -s $cache_file confcache; then - : -else - if test -w $cache_file; then - echo "updating cache $cache_file" - cat confcache > $cache_file +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + test "x$cache_file" != "x/dev/null" && + { echo "$as_me:$LINENO: updating cache $cache_file" >&5 +echo "$as_me: updating cache $cache_file" >&6;} + cat confcache >$cache_file else - echo "not updating unwritable cache $cache_file" + { echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5 +echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' -# Any assignment to VPATH causes Sun make to only execute -# the first set of double-colon rules, so remove it if not needed. -# If there is a colon in the path, we need to keep it. -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d' -fi - -trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 - # Transform confdefs.h into DEFS. # Protect against shell expansion while executing Makefile rules. # Protect against Makefile macro expansion. -cat > conftest.defs <<\EOF -s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%-D\1=\2%g -s%[ `~#$^&*(){}\\|;'"<>?]%\\&%g -s%\[%\\&%g -s%\]%\\&%g -s%\$%$$%g -EOF -DEFS=`sed -f conftest.defs confdefs.h | tr '\012' ' '` -rm -f conftest.defs +# +# If the first sed substitution is executed (which looks for macros that +# take arguments), then branch to the quote section. Otherwise, +# look for a macro that doesn't take arguments. +ac_script=' +t clear +:clear +s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g +t quote +s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g +t quote +b any +:quote +s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g +s/\[/\\&/g +s/\]/\\&/g +s/\$/$$/g +H +:any +${ + g + s/^\n// + s/\n/ /g + p +} +' +DEFS=`sed -n "$ac_script" confdefs.h` + + +ac_libobjs= +ac_ltlibobjs= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext" + ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + -# Without the "./", some shells look in PATH for config.status. : ${CONFIG_STATUS=./config.status} - -echo creating $CONFIG_STATUS -rm -f $CONFIG_STATUS -cat > $CONFIG_STATUS <&5 +echo "$as_me: creating $CONFIG_STATUS" >&6;} +cat >$CONFIG_STATUS <<_ACEOF +#! $SHELL +# Generated by $as_me. # Run this file to recreate the current configuration. -# This directory was configured as follows, -# on host `(hostname || uname -n) 2>/dev/null | sed 1q`: -# -# $0 $ac_configure_args -# # Compiler output produced by configure, useful for debugging -# configure, is in ./config.log if it exists. +# configure, is in config.log if it exists. -ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]" -for ac_option -do - case "\$ac_option" in - -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" - exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; - -version | --version | --versio | --versi | --vers | --ver | --ve | --v) - echo "$CONFIG_STATUS generated by autoconf version 2.13" - exit 0 ;; - -help | --help | --hel | --he | --h) - echo "\$ac_cs_usage"; exit 0 ;; - *) echo "\$ac_cs_usage"; exit 1 ;; - esac -done +debug=false +ac_cs_recheck=false +ac_cs_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_ACEOF -ac_given_srcdir=$srcdir +cat >>$CONFIG_STATUS <<\_ACEOF +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## -trap 'rm -fr `echo "Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 -EOF -cat >> $CONFIG_STATUS </dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac -# Protect against being on the right side of a sed subst in config.status. -sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g; - s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF -$ac_vpsub -$extrasub -s%@SHELL@%$SHELL%g -s%@CFLAGS@%$CFLAGS%g -s%@CPPFLAGS@%$CPPFLAGS%g -s%@CXXFLAGS@%$CXXFLAGS%g -s%@FFLAGS@%$FFLAGS%g -s%@DEFS@%$DEFS%g -s%@LDFLAGS@%$LDFLAGS%g -s%@LIBS@%$LIBS%g -s%@exec_prefix@%$exec_prefix%g -s%@prefix@%$prefix%g -s%@program_transform_name@%$program_transform_name%g -s%@bindir@%$bindir%g -s%@sbindir@%$sbindir%g -s%@libexecdir@%$libexecdir%g -s%@datadir@%$datadir%g -s%@sysconfdir@%$sysconfdir%g -s%@sharedstatedir@%$sharedstatedir%g -s%@localstatedir@%$localstatedir%g -s%@libdir@%$libdir%g -s%@includedir@%$includedir%g -s%@oldincludedir@%$oldincludedir%g -s%@infodir@%$infodir%g -s%@mandir@%$mandir%g -s%@PACKAGE@%$PACKAGE%g -s%@SET_MAKE@%$SET_MAKE%g -s%@INSTALL@%$INSTALL%g -s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g -s%@INSTALL_DATA@%$INSTALL_DATA%g - -CEOF -EOF - -cat >> $CONFIG_STATUS <<\EOF - -# Split the substitutions into bite-sized pieces for seds with -# small command number limits, like on Digital OSF/1 and HP-UX. -ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script. -ac_file=1 # Number of current file. -ac_beg=1 # First line for current file. -ac_end=$ac_max_sed_cmds # Line after last line for current file. -ac_more_lines=: -ac_sed_cmds="" -while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file - else - sed "${ac_end}q" conftest.subs > conftest.s$ac_file - fi - if test ! -s conftest.s$ac_file; then - ac_more_lines=false - rm -f conftest.s$ac_file - else - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f conftest.s$ac_file" - else - ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file" - fi - ac_file=`expr $ac_file + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_cmds` - fi -done -if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat fi -EOF -cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF -for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case "$ac_file" in - *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` - ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; - *) ac_file_in="${ac_file}.in" ;; - esac - # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories. - # Remove last slash and all that follows it. Not all systems have dirname. - ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - # The file is in a subdirectory. - test ! -d "$ac_dir" && mkdir "$ac_dir" - ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`" - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' else - ac_dir_suffix= ac_dots= + PATH_SEPARATOR=: fi + rm -f conf$$.sh +fi - case "$ac_given_srcdir" in - .) srcdir=. - if test -z "$ac_dots"; then top_srcdir=. - else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;; - /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;; - *) # Relative path. - srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix" - top_srcdir="$ac_dots$ac_given_srcdir" ;; +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 + +# Save the log message, to keep $[0] and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by $as_me, which was +generated by GNU Autoconf 2.61. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF +# Files that config.status was made for. +config_files="$ac_config_files" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +ac_cs_usage="\ +\`$as_me' instantiates files from templates according to the +current configuration. + +Usage: $0 [OPTIONS] [FILE]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + +Configuration files: +$config_files + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +ac_cs_version="\\ +config.status +configured by $0, generated by GNU Autoconf 2.61, + with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" + +Copyright (C) 2006 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If no file are specified by the user, then we need to provide default +# value. By we need to know if files were specified by the user. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; esac + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + echo "$ac_cs_version"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + CONFIG_FILES="$CONFIG_FILES $ac_optarg" + ac_need_defaults=false;; + --he | --h | --help | --hel | -h ) + echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; - echo creating "$ac_file" - rm -f "$ac_file" - configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure." - case "$ac_file" in - *Makefile*) ac_comsub="1i\\ -# $configure_input" ;; - *) ac_comsub= ;; + # This is an error. + -*) { echo "$as_me: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + + *) ac_config_targets="$ac_config_targets $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +if \$ac_cs_recheck; then + echo "running CONFIG_SHELL=$SHELL $SHELL $0 "$ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6 + CONFIG_SHELL=$SHELL + export CONFIG_SHELL + exec $SHELL "$0"$ac_configure_args \$ac_configure_extra_args --no-create --no-recursion +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + + *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 +echo "$as_me: error: invalid argument: $ac_config_target" >&2;} + { (exit 1); exit 1; }; };; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= + trap 'exit_status=$? + { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status +' 0 + trap '{ (exit 1); exit 1; }' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || +{ + echo "$me: cannot create a temporary directory in ." >&2 + { (exit 1); exit 1; } +} + +# +# Set up the sed scripts for CONFIG_FILES section. +# + +# No need to generate the scripts if there are no CONFIG_FILES. +# This happens for instance when ./config.status config.h +if test -n "$CONFIG_FILES"; then + +_ACEOF + + + +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + cat >conf$$subs.sed <<_ACEOF +SHELL!$SHELL$ac_delim +PATH_SEPARATOR!$PATH_SEPARATOR$ac_delim +PACKAGE_NAME!$PACKAGE_NAME$ac_delim +PACKAGE_TARNAME!$PACKAGE_TARNAME$ac_delim +PACKAGE_VERSION!$PACKAGE_VERSION$ac_delim +PACKAGE_STRING!$PACKAGE_STRING$ac_delim +PACKAGE_BUGREPORT!$PACKAGE_BUGREPORT$ac_delim +exec_prefix!$exec_prefix$ac_delim +prefix!$prefix$ac_delim +program_transform_name!$program_transform_name$ac_delim +bindir!$bindir$ac_delim +sbindir!$sbindir$ac_delim +libexecdir!$libexecdir$ac_delim +datarootdir!$datarootdir$ac_delim +datadir!$datadir$ac_delim +sysconfdir!$sysconfdir$ac_delim +sharedstatedir!$sharedstatedir$ac_delim +localstatedir!$localstatedir$ac_delim +includedir!$includedir$ac_delim +oldincludedir!$oldincludedir$ac_delim +docdir!$docdir$ac_delim +infodir!$infodir$ac_delim +htmldir!$htmldir$ac_delim +dvidir!$dvidir$ac_delim +pdfdir!$pdfdir$ac_delim +psdir!$psdir$ac_delim +libdir!$libdir$ac_delim +localedir!$localedir$ac_delim +mandir!$mandir$ac_delim +DEFS!$DEFS$ac_delim +ECHO_C!$ECHO_C$ac_delim +ECHO_N!$ECHO_N$ac_delim +ECHO_T!$ECHO_T$ac_delim +LIBS!$LIBS$ac_delim +build_alias!$build_alias$ac_delim +host_alias!$host_alias$ac_delim +target_alias!$target_alias$ac_delim +PACKAGE!$PACKAGE$ac_delim +SET_MAKE!$SET_MAKE$ac_delim +INSTALL!$INSTALL$ac_delim +INSTALL_PROGRAM!$INSTALL_PROGRAM$ac_delim +INSTALL_DATA!$INSTALL_DATA$ac_delim +LIBOBJS!$LIBOBJS$ac_delim +LTLIBOBJS!$LTLIBOBJS$ac_delim +_ACEOF + + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 44; then + break + elif $ac_last_try; then + { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 +echo "$as_me: error: could not make $CONFIG_STATUS" >&2;} + { (exit 1); exit 1; }; } + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed` +if test -n "$ac_eof"; then + ac_eof=`echo "$ac_eof" | sort -nru | sed 1q` + ac_eof=`expr $ac_eof + 1` +fi + +cat >>$CONFIG_STATUS <<_ACEOF +cat >"\$tmp/subs-1.sed" <<\CEOF$ac_eof +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b end +_ACEOF +sed ' +s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g +s/^/s,@/; s/!/@,|#_!!_#|/ +:n +t n +s/'"$ac_delim"'$/,g/; t +s/$/\\/; p +N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n +' >>$CONFIG_STATUS >$CONFIG_STATUS <<_ACEOF +:end +s/|#_!!_#|//g +CEOF$ac_eof +_ACEOF + + +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/ +s/:*\${srcdir}:*/:/ +s/:*@srcdir@:*/:/ +s/^\([^=]*=[ ]*\):*/\1/ +s/:*$// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF +fi # test -n "$CONFIG_FILES" + + +for ac_tag in :F $CONFIG_FILES +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) { { echo "$as_me:$LINENO: error: Invalid tag $ac_tag." >&5 +echo "$as_me: error: Invalid tag $ac_tag." >&2;} + { (exit 1); exit 1; }; };; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + { { echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5 +echo "$as_me: error: cannot find input file: $ac_f" >&2;} + { (exit 1); exit 1; }; };; + esac + ac_file_inputs="$ac_file_inputs $ac_f" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input="Generated from "`IFS=: + echo $* | sed 's|^[^:]*/||;s|:[^:]*/|, |g'`" by configure." + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + fi + + case $ac_tag in + *:-:* | *:-) cat >"$tmp/stdin";; + esac + ;; esac - ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` - sed -e "$ac_comsub -s%@configure_input@%$configure_input%g -s%@srcdir@%$srcdir%g -s%@top_srcdir@%$top_srcdir%g -" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file -fi; done -rm -f conftest.s* + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + { as_dir="$ac_dir" + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5 +echo "$as_me: error: cannot create directory $as_dir" >&2;} + { (exit 1); exit 1; }; }; } + ac_builddir=. -EOF -cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix -exit 0 -EOF + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= + +case `sed -n '/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p +' $ac_file_inputs` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF + sed "$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s&@configure_input@&$configure_input&;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +$ac_datarootdir_hack +" $ac_file_inputs | sed -f "$tmp/subs-1.sed" >$tmp/out + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && + { echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&5 +echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&2;} + + rm -f "$tmp/stdin" + case $ac_file in + -) cat "$tmp/out"; rm -f "$tmp/out";; + *) rm -f "$ac_file"; mv "$tmp/out" $ac_file;; + esac + ;; + + + + esac + +done # for ac_tag + + +{ (exit 0); exit 0; } +_ACEOF chmod +x $CONFIG_STATUS -rm -fr confdefs* $ac_clean_files -test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1 +ac_clean_files=$ac_clean_files_save + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || { (exit 1); exit 1; } +fi diff --git a/contrib/gperf/doc/configure.in b/contrib/gperf/doc/configure.ac similarity index 66% rename from contrib/gperf/doc/configure.in rename to contrib/gperf/doc/configure.ac index 944b862cf315..e6bfbfe0d01c 100644 --- a/contrib/gperf/doc/configure.in +++ b/contrib/gperf/doc/configure.ac @@ -1,13 +1,14 @@ dnl autoconf configuration for gperf/doc -dnl Copyright (C) 1998, 2000 Free Software Foundation, Inc. -dnl written by Douglas C. Schmidt (schmidt@ics.uci.edu) +dnl Copyright (C) 1998, 2000, 2002-2003, 2007 Free Software Foundation, Inc. +dnl Written by Douglas C. Schmidt +dnl and Bruno Haible . dnl dnl This file is part of GNU GPERF. dnl dnl GNU GPERF is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by -dnl the Free Software Foundation; either version 1, or (at your option) +dnl the Free Software Foundation; either version 2, or (at your option) dnl any later version. dnl dnl GNU GPERF is distributed in the hope that it will be useful, @@ -16,10 +17,11 @@ dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the dnl GNU General Public License for more details. dnl dnl You should have received a copy of the GNU General Public License -dnl along with GNU GPERF; see the file COPYING. If not, write to the -dnl Free Software Foundation, 59 Temple Place - Suite 330, Boston, -dnl MA 02111-1307, USA. +dnl along with this program; see the file COPYING. +dnl If not, write to the Free Software Foundation, Inc., +dnl 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +AC_PREREQ([2.60]) AC_INIT(gperf.1) PACKAGE=gperf AC_SUBST(PACKAGE) diff --git a/contrib/gperf/doc/gperf.1 b/contrib/gperf/doc/gperf.1 index dd425e0c7e2c..786604ef050c 100644 --- a/contrib/gperf/doc/gperf.1 +++ b/contrib/gperf/doc/gperf.1 @@ -1,21 +1,27 @@ -.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.022. -.TH GPERF "1" "September 2000" "GNU gperf 2.7.2" FSF +.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.23. +.TH GPERF "1" "May 2007" "GNU gperf 3.0.3" FSF .SH NAME gperf \- generate a perfect hash function from a key set .SH SYNOPSIS .B gperf [\fIOPTION\fR]... [\fIINPUT-FILE\fR] .SH DESCRIPTION -GNU `gperf' generates perfect hash functions. +GNU 'gperf' generates perfect hash functions. .PP If a long option shows an argument as mandatory, then it is mandatory for the equivalent short option also. +.SS "Output file location:" +.HP +\fB\-\-output\-file\fR=\fIFILE\fR Write output to specified file. +.PP +The results are written to standard output if no output file is specified +or if it is -. .SS "Input file interpretation:" .TP \fB\-e\fR, \fB\-\-delimiters\fR=\fIDELIMITER\-LIST\fR Allow user to provide a string containing delimiters used to separate keywords from their attributes. -Default is ",\en". +Default is ",". .TP \fB\-t\fR, \fB\-\-struct\-type\fR Allows the user to include a structured type @@ -23,6 +29,11 @@ declaration for generated code. Any text before %% is considered part of the type declaration. Key words and additional fields may follow this, one group of fields per line. +.TP +\fB\-\-ignore\-case\fR +Consider upper and lower case ASCII characters as +equivalent. Note that locale dependent case mappings +are ignored. .SS "Language for the output code:" .TP \fB\-L\fR, \fB\-\-language\fR=\fILANGUAGE\-NAME\fR @@ -39,21 +50,27 @@ structure. Initializers for additional components in the keyword structure. .TP -\fB\-H\fR, \fB\-\-hash\-fn\-name\fR=\fINAME\fR +\fB\-H\fR, \fB\-\-hash\-function\-name\fR=\fINAME\fR Specify name of generated hash function. Default is -`hash'. +\&'hash'. .TP -\fB\-N\fR, \fB\-\-lookup\-fn\-name\fR=\fINAME\fR +\fB\-N\fR, \fB\-\-lookup\-function\-name\fR=\fINAME\fR Specify name of generated lookup function. Default -name is `in_word_set'. +name is 'in_word_set'. .TP \fB\-Z\fR, \fB\-\-class\-name\fR=\fINAME\fR Specify name of generated C++ class. Default name is -`Perfect_Hash'. +\&'Perfect_Hash'. .TP \fB\-7\fR, \fB\-\-seven\-bit\fR Assume 7-bit characters. .TP +\fB\-l\fR, \fB\-\-compare\-lengths\fR +Compare key lengths before trying a string +comparison. This is necessary if the keywords +contain NUL bytes. It also helps cut down on the +number of string comparisons made during the lookup. +.TP \fB\-c\fR, \fB\-\-compare\-strncmp\fR Generate comparison code using strncmp rather than strcmp. @@ -70,14 +87,31 @@ lookup function rather than with defines. Include the necessary system include file at the beginning of the code. .TP -\fB\-G\fR, \fB\-\-global\fR +\fB\-G\fR, \fB\-\-global\-table\fR Generate the static table of keywords as a static global variable, rather than hiding it inside of the lookup function (which is the default behavior). .TP +\fB\-P\fR, \fB\-\-pic\fR +Optimize the generated table for inclusion in shared +libraries. This reduces the startup time of programs +using a shared library containing the generated code. +.TP +\fB\-Q\fR, \fB\-\-string\-pool\-name\fR=\fINAME\fR +Specify name of string pool generated by option \fB\-\-pic\fR. +Default name is 'stringpool'. +.TP +\fB\-\-null\-strings\fR +Use NULL strings instead of empty strings for empty +keyword table entries. +.TP \fB\-W\fR, \fB\-\-word\-array\-name\fR=\fINAME\fR Specify name of word list array. Default name is -`wordlist'. +\&'wordlist'. +.TP +\fB\-\-length\-table\-name\fR=\fINAME\fR +Specify name of length table array. Default name is +\&'lengthtable'. .TP \fB\-S\fR, \fB\-\-switch\fR=\fICOUNT\fR Causes the generated C code to use a switch @@ -99,30 +133,23 @@ defined elsewhere. .TP \fB\-k\fR, \fB\-\-key\-positions\fR=\fIKEYS\fR Select the key positions used in the hash function. -The allowable choices range between 1-126, inclusive. +The allowable choices range between 1-255, inclusive. The positions are separated by commas, ranges may be used, and key positions may occur in any order. Also, the meta-character '*' causes the generated hash function to consider ALL key positions, and $ -indicates the ``final character'' of a key, e.g., +indicates the "final character" of a key, e.g., $,1,2,4,6-10. .TP -\fB\-l\fR, \fB\-\-compare\-strlen\fR -Compare key lengths before trying a string -comparison. This helps cut down on the number of -string comparisons made during the lookup. -.TP \fB\-D\fR, \fB\-\-duplicates\fR Handle keywords that hash to duplicate values. This is useful for certain highly redundant keyword sets. .TP -\fB\-f\fR, \fB\-\-fast\fR=\fIITERATIONS\fR -Generate the gen-perf.hash function ``fast''. This -decreases gperf's running time at the cost of -minimizing generated table size. The numeric -argument represents the number of times to iterate -when resolving a collision. `0' means ``iterate by -the number of keywords''. +\fB\-m\fR, \fB\-\-multiple\-iterations\fR=\fIITERATIONS\fR +Perform multiple choices of the \fB\-i\fR and \fB\-j\fR values, +and choose the best results. This increases the +running time by a factor of ITERATIONS but does a +good job minimizing the generated table size. .TP \fB\-i\fR, \fB\-\-initial\-asso\fR=\fIN\fR Provide an initial value for the associate values @@ -130,7 +157,7 @@ array. Default is 0. Setting this value larger helps inflate the size of the final table. .TP \fB\-j\fR, \fB\-\-jump\fR=\fIJUMP\-VALUE\fR -Affects the ``jump value'', i.e., how far to advance +Affects the "jump value", i.e., how far to advance the associated character value upon collisions. Must be an odd number, default is 5. .TP @@ -138,25 +165,20 @@ be an odd number, default is 5. Do not include the length of the keyword when computing the hash function. .TP -\fB\-o\fR, \fB\-\-occurrence\-sort\fR -Reorders input keys by frequency of occurrence of -the key sets. This should decrease the search time -dramatically. -.TP \fB\-r\fR, \fB\-\-random\fR Utilizes randomness to initialize the associated values table. .TP \fB\-s\fR, \fB\-\-size\-multiple\fR=\fIN\fR Affects the size of the generated hash table. The -numeric argument N indicates ``how many times larger -or smaller'' the associated value range should be, +numeric argument N indicates "how many times larger +or smaller" the associated value range should be, in relationship to the number of keys, e.g. a value -of 3 means ``allow the maximum associated value to +of 3 means "allow the maximum associated value to be about 3 times larger than the number of input -keys.'' Conversely, a value of \fB\-3\fR means ``make the +keys". Conversely, a value of 1/3 means "make the maximum associated value about 3 times smaller than -the number of input keys. A larger table should +the number of input keys". A larger table should decrease the time required for an unsuccessful search, at the expense of extra table space. Default value is 1. @@ -171,8 +193,15 @@ Print the gperf version number. \fB\-d\fR, \fB\-\-debug\fR Enables the debugging option (produces verbose output to the standard error). +.SH AUTHOR +Written by Douglas C. Schmidt and Bruno Haible. .SH "REPORTING BUGS" -Report bugs to . +Report bugs to . +.SH COPYRIGHT +Copyright \(co 1989-1998, 2000-2004, 2006-2007 Free Software Foundation, Inc. +.br +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. .SH "SEE ALSO" The full documentation for .B gperf diff --git a/contrib/gperf/doc/gperf.texi b/contrib/gperf/doc/gperf.texi index e510ac97021f..e23f7b5329c0 100644 --- a/contrib/gperf/doc/gperf.texi +++ b/contrib/gperf/doc/gperf.texi @@ -7,9 +7,9 @@ @c some day we should @include version.texi instead of defining @c these values at hand. -@set UPDATED 26 September 2000 -@set EDITION 2.7.2 -@set VERSION 2.7.2 +@set UPDATED 31 March 2007 +@set EDITION 3.0.3 +@set VERSION 3.0.3 @c --------------------- @c remove the black boxes generated in the GPL appendix. @@ -28,7 +28,7 @@ This file documents the features of the GNU Perfect Hash Function Generator @value{VERSION}. -Copyright @copyright{} 1989-2000 Free Software Foundation, Inc. +Copyright @copyright{} 1989-2006 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are @@ -62,10 +62,11 @@ Software Foundation instead of in the original English. @subtitle The GNU Perfect Hash Function Generator @subtitle Edition @value{EDITION}, @value{UPDATED} @author Douglas C. Schmidt +@author Bruno Haible @page @vskip 0pt plus 1filll -Copyright @copyright{} 1989-2000 Free Software Foundation, Inc. +Copyright @copyright{} 1989-2007 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of @@ -98,13 +99,12 @@ bugs. * Copying:: GNU @code{gperf} General Public License says how you can copy and share @code{gperf}. * Contributors:: People who have contributed to @code{gperf}. -* Motivation:: Static search structures and GNU GPERF. +* Motivation:: The purpose of @code{gperf}. * Search Structures:: Static search structures and GNU @code{gperf} * Description:: High-level discussion of how GPERF functions. * Options:: A description of options to the program. * Bugs:: Known bugs and limitations with GPERF. * Projects:: Things still left to do. -* Implementation:: Implementation Details for GNU GPERF. * Bibliography:: Material Referenced in this Report. * Concept Index:: @@ -115,13 +115,20 @@ High-Level Description of GNU @code{gperf} * Input Format:: Input Format to @code{gperf} * Output Format:: Output Format for Generated C Code with @code{gperf} -* Binary Strings:: Use of NUL characters +* Binary Strings:: Use of NUL bytes Input Format to @code{gperf} -* Declarations:: @code{struct} Declarations and C Code Inclusion. +* Declarations:: Declarations. * Keywords:: Format for Keyword Entries. * Functions:: Including Additional C Functions. +* Controls for GNU indent:: Where to place directives for GNU @code{indent}. + +Declarations + +* User-supplied Struct:: Specifying keywords with attributes. +* Gperf Declarations:: Embedding command line options in the input. +* C Code Inclusion:: Including C declarations and definitions. Invoking @code{gperf} @@ -147,15 +154,13 @@ Invoking @code{gperf} @item @cindex Bugs The GNU @code{gperf} perfect hash function generator utility was -originally written in GNU C++ by Douglas C. Schmidt. It is now also -available in a highly-portable ``old-style'' C version. The general +written in GNU C++ by Douglas C. Schmidt. The general idea for the perfect hash function generator was inspired by Keith Bostic's algorithm written in C, and distributed to net.sources around 1984. The current program is a heavily modified, enhanced, and extended implementation of Keith's basic idea, created at the University of California, Irvine. Bugs, patches, and suggestions should be reported -to both @code{} and -@code{}. +to @code{}. @item Special thanks is extended to Michael Tiemann and Doug Lea, for @@ -166,8 +171,9 @@ In addition, Adam de Boor and Nels Olson provided many tips and insights that greatly helped improve the quality and functionality of @code{gperf}. @item -A testsuite was added by Bruno Haible. He also rewrote the output -routines for better reliability. +Bruno Haible enhanced and optimized the search algorithm. He also rewrote +the input routines and the output routines for better reliability, and +added a testsuite. @end itemize @node Motivation, Search Structures, Contributors, Top @@ -176,8 +182,8 @@ routines for better reliability. @code{gperf} is a perfect hash function generator written in C++. It transforms an @var{n} element user-specified keyword set @var{W} into a perfect hash function @var{F}. @var{F} uniquely maps keywords in -@var{W} onto the range 0..@var{k}, where @var{k} >= @var{n}. If @var{k} -= @var{n} then @var{F} is a @emph{minimal} perfect hash function. +@var{W} onto the range 0..@var{k}, where @var{k} >= @var{n-1}. If @var{k} += @var{n-1} then @var{F} is a @emph{minimal} perfect hash function. @code{gperf} generates a 0..@var{k} element static lookup table and a pair of C functions. These functions determine whether a given character string @var{s} occurs in @var{W}, using at most one probe into @@ -185,11 +191,12 @@ the lookup table. @code{gperf} currently generates the reserved keyword recognizer for lexical analyzers in several production and research compilers and -language processing tools, including GNU C, GNU C++, GNU Pascal, GNU -Modula 3, and GNU indent. Complete C++ source code for @code{gperf} is -available via anonymous ftp from @code{ftp://ftp.gnu.org/pub/gnu/gperf/}. +language processing tools, including GNU C, GNU C++, GNU Java, GNU Pascal, +GNU Modula 3, and GNU indent. Complete C++ source code for @code{gperf} is +available from @code{http://ftp.gnu.org/pub/gnu/gperf/}. A paper describing @code{gperf}'s design and implementation in greater -detail is available in the Second USENIX C++ Conference proceedings. +detail is available in the Second USENIX C++ Conference proceedings +or from @code{http://www.cs.wustl.edu/~schmidt/resume.html}. @node Search Structures, Description, Motivation, Top @chapter Static search structures and GNU @code{gperf} @@ -198,7 +205,7 @@ detail is available in the Second USENIX C++ Conference proceedings. A @dfn{static search structure} is an Abstract Data Type with certain fundamental operations, e.g., @emph{initialize}, @emph{insert}, and @emph{retrieve}. Conceptually, all insertions occur before any -retrievals. In practice, @code{gperf} generates a @code{static} array +retrievals. In practice, @code{gperf} generates a @emph{static} array containing search set keywords and any associated attributes specified by the user. Thus, there is essentially no execution-time cost for the insertions. It is a useful data structure for representing @emph{static @@ -254,8 +261,8 @@ the drudgery associated with constructing time- and space-efficient search structures by hand. It has proven a useful and practical tool for serious programming projects. Output from @code{gperf} is currently used in several production and research compilers, including GNU C, GNU -C++, GNU Pascal, and GNU Modula 3. The latter two compilers are not yet -part of the official GNU distribution. Each compiler utilizes +C++, GNU Java, GNU Pascal, and GNU Modula 3. The latter two compilers are +not yet part of the official GNU distribution. Each compiler utilizes @code{gperf} to automatically generate static search structures that efficiently identify their respective reserved keywords. @@ -265,11 +272,11 @@ efficiently identify their respective reserved keywords. @menu * Input Format:: Input Format to @code{gperf} * Output Format:: Output Format for Generated C Code with @code{gperf} -* Binary Strings:: Use of NUL characters +* Binary Strings:: Use of NUL bytes @end menu The perfect hash function generator @code{gperf} reads a set of -``keywords'' from a @dfn{keyfile} (or from the standard input by +``keywords'' from an input file (or from the standard input by default). It attempts to derive a perfect hashing function that recognizes a member of the @dfn{static keyword set} with at most a single probe into the lookup table. If @code{gperf} succeeds in @@ -288,7 +295,7 @@ statement scheme that minimizes data space storage size. Furthermore, using a C @code{switch} may actually speed up the keyword retrieval time somewhat. Actual results depend on your C compiler, of course. -In general, @code{gperf} assigns values to the characters it is using +In general, @code{gperf} assigns values to the bytes it is using for hashing until some set of values gives each keyword a unique value. A helpful heuristic is that the larger the hash value range, the easier it is for @code{gperf} to find and generate a perfect hash function. @@ -300,7 +307,7 @@ Experimentation is the key to getting the most from @code{gperf}. @cindex Declaration section @cindex Keywords section @cindex Functions section -You can control the input keyfile format by varying certain command-line +You can control the input file format by varying certain command-line arguments, in particular the @samp{-t} option. The input's appearance is similar to GNU utilities @code{flex} and @code{bison} (or UNIX utilities @code{lex} and @code{yacc}). Here's an outline of the general @@ -316,34 +323,64 @@ functions @end group @end example -@emph{Unlike} @code{flex} or @code{bison}, all sections of -@code{gperf}'s input are optional. The following sections describe the +@emph{Unlike} @code{flex} or @code{bison}, the declarations section and +the functions section are optional. The following sections describe the input format for each section. @menu -* Declarations:: @code{struct} Declarations and C Code Inclusion. +* Declarations:: Declarations. * Keywords:: Format for Keyword Entries. * Functions:: Including Additional C Functions. +* Controls for GNU indent:: Where to place directives for GNU @code{indent}. @end menu +It is possible to omit the declaration section entirely, if the @samp{-t} +option is not given. In this case the input file begins directly with the +first keyword line, e.g.: + +@example +@group +january +february +march +april +... +@end group +@end example + @node Declarations, Keywords, Input Format, Input Format -@subsection @code{struct} Declarations and C Code Inclusion +@subsection Declarations The keyword input file optionally contains a section for including -arbitrary C declarations and definitions, as well as provisions for -providing a user-supplied @code{struct}. If the @samp{-t} option +arbitrary C declarations and definitions, @code{gperf} declarations that +act like command-line options, as well as for providing a user-supplied +@code{struct}. + +@menu +* User-supplied Struct:: Specifying keywords with attributes. +* Gperf Declarations:: Embedding command line options in the input. +* C Code Inclusion:: Including C declarations and definitions. +@end menu + +@node User-supplied Struct, Gperf Declarations, Declarations, Declarations +@subsubsection User-supplied @code{struct} + +If the @samp{-t} option (or, equivalently, the @samp{%struct-type} declaration) @emph{is} enabled, you @emph{must} provide a C @code{struct} as the last -component in the declaration section from the keyfile file. The first -field in this struct must be a @code{char *} or @code{const char *} -identifier called @samp{name}, although it is possible to modify this -field's name with the @samp{-K} option described below. +component in the declaration section from the input file. The first +field in this struct must be of type @code{char *} or @code{const char *} +if the @samp{-P} option is not given, or of type @code{int} if the option +@samp{-P} (or, equivalently, the @samp{%pic} declaration) is enabled. +This first field must be called @samp{name}, although it is possible to modify +its name with the @samp{-K} option (or, equivalently, the +@samp{%define slot-name} declaration) described below. Here is a simple example, using months of the year and their attributes as input: @example @group -struct months @{ char *name; int number; int days; int leap_days; @}; +struct month @{ char *name; int number; int days; int leap_days; @}; %% january, 1, 31, 31 february, 2, 28, 29 @@ -366,6 +403,236 @@ other fields are a pair of consecutive percent signs, @samp{%%}, appearing left justified in the first column, as in the UNIX utility @code{lex}. +If the @code{struct} has already been declared in an include file, it can +be mentioned in an abbreviated form, like this: + +@example +@group +struct month; +%% +january, 1, 31, 31 +... +@end group +@end example + +@node Gperf Declarations, C Code Inclusion, User-supplied Struct, Declarations +@subsubsection Gperf Declarations + +The declaration section can contain @code{gperf} declarations. They +influence the way @code{gperf} works, like command line options do. +In fact, every such declaration is equivalent to a command line option. +There are three forms of declarations: + +@enumerate +@item +Declarations without argument, like @samp{%compare-lengths}. + +@item +Declarations with an argument, like @samp{%switch=@var{count}}. + +@item +Declarations of names of entities in the output file, like +@samp{%define lookup-function-name @var{name}}. +@end enumerate + +When a declaration is given both in the input file and as a command line +option, the command-line option's value prevails. + +The following @code{gperf} declarations are available. + +@table @samp +@item %delimiters=@var{delimiter-list} +@cindex @samp{%delimiters} +Allows you to provide a string containing delimiters used to +separate keywords from their attributes. The default is ",". This +option is essential if you want to use keywords that have embedded +commas or newlines. + +@item %struct-type +@cindex @samp{%struct-type} +Allows you to include a @code{struct} type declaration for generated +code; see above for an example. + +@item %ignore-case +@cindex @samp{%ignore-case} +Consider upper and lower case ASCII characters as equivalent. The string +comparison will use a case insignificant character comparison. Note that +locale dependent case mappings are ignored. + +@item %language=@var{language-name} +@cindex @samp{%language} +Instructs @code{gperf} to generate code in the language specified by the +option's argument. Languages handled are currently: + +@table @samp +@item KR-C +Old-style K&R C. This language is understood by old-style C compilers and +ANSI C compilers, but ANSI C compilers may flag warnings (or even errors) +because of lacking @samp{const}. + +@item C +Common C. This language is understood by ANSI C compilers, and also by +old-style C compilers, provided that you @code{#define const} to empty +for compilers which don't know about this keyword. + +@item ANSI-C +ANSI C. This language is understood by ANSI C compilers and C++ compilers. + +@item C++ +C++. This language is understood by C++ compilers. +@end table + +The default is C. + +@item %define slot-name @var{name} +@cindex @samp{%define slot-name} +This declaration is only useful when option @samp{-t} (or, equivalently, the +@samp{%struct-type} declaration) has been given. +By default, the program assumes the structure component identifier for +the keyword is @samp{name}. This option allows an arbitrary choice of +identifier for this component, although it still must occur as the first +field in your supplied @code{struct}. + +@item %define initializer-suffix @var{initializers} +@cindex @samp{%define initializer-suffix} +This declaration is only useful when option @samp{-t} (or, equivalently, the +@samp{%struct-type} declaration) has been given. +It permits to specify initializers for the structure members following +@var{slot-name} in empty hash table entries. The list of initializers +should start with a comma. By default, the emitted code will +zero-initialize structure members following @var{slot-name}. + +@item %define hash-function-name @var{name} +@cindex @samp{%define hash-function-name} +Allows you to specify the name for the generated hash function. Default +name is @samp{hash}. This option permits the use of two hash tables in +the same file. + +@item %define lookup-function-name @var{name} +@cindex @samp{%define lookup-function-name} +Allows you to specify the name for the generated lookup function. +Default name is @samp{in_word_set}. This option permits multiple +generated hash functions to be used in the same application. + +@item %define class-name @var{name} +@cindex @samp{%define class-name} +This option is only useful when option @samp{-L C++} (or, equivalently, +the @samp{%language=C++} declaration) has been given. It +allows you to specify the name of generated C++ class. Default name is +@code{Perfect_Hash}. + +@item %7bit +@cindex @samp{%7bit} +This option specifies that all strings that will be passed as arguments +to the generated hash function and the generated lookup function will +solely consist of 7-bit ASCII characters (bytes in the range 0..127). +(Note that the ANSI C functions @code{isalnum} and @code{isgraph} do +@emph{not} guarantee that a byte is in this range. Only an explicit +test like @samp{c >= 'A' && c <= 'Z'} guarantees this.) + +@item %compare-lengths +@cindex @samp{%compare-lengths} +Compare keyword lengths before trying a string comparison. This option +is mandatory for binary comparisons (@pxref{Binary Strings}). It also might +cut down on the number of string comparisons made during the lookup, since +keywords with different lengths are never compared via @code{strcmp}. +However, using @samp{%compare-lengths} might greatly increase the size of the +generated C code if the lookup table range is large (which implies that +the switch option @samp{-S} or @samp{%switch} is not enabled), since the length +table contains as many elements as there are entries in the lookup table. + +@item %compare-strncmp +@cindex @samp{%compare-strncmp} +Generates C code that uses the @code{strncmp} function to perform +string comparisons. The default action is to use @code{strcmp}. + +@item %readonly-tables +@cindex @samp{%readonly-tables} +Makes the contents of all generated lookup tables constant, i.e., +``readonly''. Many compilers can generate more efficient code for this +by putting the tables in readonly memory. + +@item %enum +@cindex @samp{%enum} +Define constant values using an enum local to the lookup function rather +than with #defines. This also means that different lookup functions can +reside in the same file. Thanks to James Clark @code{}. + +@item %includes +@cindex @samp{%includes} +Include the necessary system include file, @code{}, at the +beginning of the code. By default, this is not done; the user must +include this header file himself to allow compilation of the code. + +@item %global-table +@cindex @samp{%global-table} +Generate the static table of keywords as a static global variable, +rather than hiding it inside of the lookup function (which is the +default behavior). + +@item %pic +@cindex @samp{%pic} +Optimize the generated table for inclusion in shared libraries. This +reduces the startup time of programs using a shared library containing +the generated code. If the @samp{%struct-type} declaration (or, +equivalently, the option @samp{-t}) is also given, the first field of the +user-defined struct must be of type @samp{int}, not @samp{char *}, because +it will contain offsets into the string pool instead of actual strings. +To convert such an offset to a string, you can use the expression +@samp{stringpool + @var{o}}, where @var{o} is the offset. The string pool +name can be changed through the @samp{%define string-pool-name} declaration. + +@item %define string-pool-name @var{name} +@cindex @samp{%define string-pool-name} +Allows you to specify the name of the generated string pool created by +the declaration @samp{%pic} (or, equivalently, the option @samp{-P}). +The default name is @samp{stringpool}. This declaration permits the use of +two hash tables in the same file, with @samp{%pic} and even when the +@samp{%global-table} declaration (or, equivalently, the option @samp{-G}) +is given. + +@item %null-strings +@cindex @samp{%null-strings} +Use NULL strings instead of empty strings for empty keyword table entries. +This reduces the startup time of programs using a shared library containing +the generated code (but not as much as the declaration @samp{%pic}), at the +expense of one more test-and-branch instruction at run time. + +@item %define word-array-name @var{name} +@cindex @samp{%define word-array-name} +Allows you to specify the name for the generated array containing the +hash table. Default name is @samp{wordlist}. This option permits the +use of two hash tables in the same file, even when the option @samp{-G} +(or, equivalently, the @samp{%global-table} declaration) is given. + +@item %define length-table-name @var{name} +@cindex @samp{%define length-table-name} +Allows you to specify the name for the generated array containing the +length table. Default name is @samp{lengthtable}. This option permits the +use of two length tables in the same file, even when the option @samp{-G} +(or, equivalently, the @samp{%global-table} declaration) is given. + +@item %switch=@var{count} +@cindex @samp{%switch} +Causes the generated C code to use a @code{switch} statement scheme, +rather than an array lookup table. This can lead to a reduction in both +time and space requirements for some input files. The argument to this +option determines how many @code{switch} statements are generated. A +value of 1 generates 1 @code{switch} containing all the elements, a +value of 2 generates 2 tables with 1/2 the elements in each +@code{switch}, etc. This is useful since many C compilers cannot +correctly generate code for large @code{switch} statements. This option +was inspired in part by Keith Bostic's original C program. + +@item %omit-struct-type +@cindex @samp{%omit-struct-type} +Prevents the transfer of the type declaration to the output file. Use +this option if the type is already defined elsewhere. +@end table + +@node C Code Inclusion, , Gperf Declarations, Declarations +@subsubsection C Code Inclusion + @cindex @samp{%@{} @cindex @samp{%@}} Using a syntax similar to GNU utilities @code{flex} and @code{bison}, it @@ -380,9 +647,9 @@ feature: %@{ #include /* This section of code is inserted directly into the output. */ -int return_month_days (struct months *months, int is_leap_year); +int return_month_days (struct month *months, int is_leap_year); %@} -struct months @{ char *name; int number; int days; int leap_days; @}; +struct month @{ char *name; int number; int days; int leap_days; @}; %% january, 1, 31, 31 february, 2, 28, 29 @@ -391,32 +658,21 @@ march, 3, 31, 31 @end group @end example -It is possible to omit the declaration section entirely. In this case -the keyfile begins directly with the first keyword line, e.g.: - -@example -@group -january, 1, 31, 31 -february, 2, 28, 29 -march, 3, 31, 31 -april, 4, 30, 30 -... -@end group -@end example - @node Keywords, Functions, Declarations, Input Format @subsection Format for Keyword Entries -The second keyfile format section contains lines of keywords and any +The second input file format section contains lines of keywords and any associated attributes you might supply. A line beginning with @samp{#} in the first column is considered a comment. Everything following the -@samp{#} is ignored, up to and including the following newline. +@samp{#} is ignored, up to and including the following newline. A line +beginning with @samp{%} in the first column is an option declaration and +must not occur within the keywords section. -The first field of each non-comment line is always the key itself. It +The first field of each non-comment line is always the keyword itself. It can be given in two ways: as a simple name, i.e., without surrounding string quotation marks, or as a string enclosed in double-quotes, in C syntax, possibly with backslash escapes like @code{\"} or @code{\234} -or @code{\xa8}. In either case, it must start right at the beginning +or @code{\xa8}. In either case, it must start right at the beginning of the line, without leading whitespace. In this context, a ``field'' is considered to extend up to, but not include, the first blank, comma, or newline. Here is a simple @@ -445,11 +701,12 @@ Additional fields may optionally follow the leading keyword. Fields should be separated by commas, and terminate at the end of line. What these fields mean is entirely up to you; they are used to initialize the elements of the user-defined @code{struct} provided by you in the -declaration section. If the @samp{-t} option is @emph{not} enabled +declaration section. If the @samp{-t} option (or, equivalently, the +@samp{%struct-type} declaration) is @emph{not} enabled these fields are simply ignored. All previous examples except the last one contain keyword attributes. -@node Functions, , Keywords, Input Format +@node Functions, Controls for GNU indent, Keywords, Input Format @subsection Including Additional C Functions The optional third section also corresponds closely with conventions @@ -459,12 +716,58 @@ file, is included verbatim into the generated output file. Naturally, it is your responsibility to ensure that the code contained in this section is valid C. +@node Controls for GNU indent, , Functions, Input Format +@subsection Where to place directives for GNU @code{indent}. + +If you want to invoke GNU @code{indent} on a @code{gperf} input file, +you will see that GNU @code{indent} doesn't understand the @samp{%%}, +@samp{%@{} and @samp{%@}} directives that control @code{gperf}'s +interpretation of the input file. Therefore you have to insert some +directives for GNU @code{indent}. More precisely, assuming the most +general input file structure + +@example +@group +declarations part 1 +%@{ +verbatim code +%@} +declarations part 2 +%% +keywords +%% +functions +@end group +@end example + +@noindent +you would insert @samp{*INDENT-OFF*} and @samp{*INDENT-ON*} comments +as follows: + +@example +@group +/* *INDENT-OFF* */ +declarations part 1 +%@{ +/* *INDENT-ON* */ +verbatim code +/* *INDENT-OFF* */ +%@} +declarations part 2 +%% +keywords +%% +/* *INDENT-ON* */ +functions +@end group +@end example + @node Output Format, Binary Strings, Input Format, Description @section Output Format for Generated C Code with @code{gperf} @cindex hash table Several options control how the generated C code appears on the standard -output. Two C function are generated. They are called @code{hash} and +output. Two C functions are generated. They are called @code{hash} and @code{in_word_set}, although you may modify their names with a command-line option. Both functions require two arguments, a string, @code{char *} @var{str}, and a length parameter, @code{int} @var{len}. Their default @@ -472,26 +775,28 @@ function prototypes are as follows: @deftypefun {unsigned int} hash (const char * @var{str}, unsigned int @var{len}) By default, the generated @code{hash} function returns an integer value -created by adding @var{len} to several user-specified @var{str} key +created by adding @var{len} to several user-specified @var{str} byte positions indexed into an @dfn{associated values} table stored in a local static array. The associated values table is constructed internally by @code{gperf} and later output as a static local C array -called @samp{hash_table}; its meaning and properties are described below -(@pxref{Implementation}). The relevant key positions are specified via -the @samp{-k} option when running @code{gperf}, as detailed in the -@emph{Options} section below(@pxref{Options}). +called @samp{hash_table}. The relevant selected positions (i.e. indices +into @var{str}) are specified via the @samp{-k} option when running +@code{gperf}, as detailed in the @emph{Options} section below (@pxref{Options}). @end deftypefun @deftypefun {} in_word_set (const char * @var{str}, unsigned int @var{len}) If @var{str} is in the keyword set, returns a pointer to that -keyword. More exactly, if the option @samp{-t} was given, it returns -a pointer to the matching keyword's structure. Otherwise it returns +keyword. More exactly, if the option @samp{-t} (or, equivalently, the +@samp{%struct-type} declaration) was given, it returns +a pointer to the matching keyword's structure. Otherwise it returns @code{NULL}. @end deftypefun -If the option @samp{-c} is not used, @var{str} must be a NUL terminated -string of exactly length @var{len}. If @samp{-c} is used, @var{str} must -simply be an array of @var{len} characters and does not need to be NUL +If the option @samp{-c} (or, equivalently, the @samp{%compare-strncmp} +declaration) is not used, @var{str} must be a NUL terminated +string of exactly length @var{len}. If @samp{-c} (or, equivalently, the +@samp{%compare-strncmp} declaration) is used, @var{str} must +simply be an array of @var{len} bytes and does not need to be NUL terminated. The code generated for these two functions is affected by the following @@ -512,44 +817,50 @@ degree of optimization, this method often results in smaller and faster code. @end table -If the @samp{-t} and @samp{-S} options are omitted, the default action -is to generate a @code{char *} array containing the keys, together with -additional null strings used for padding the array. By experimenting +If the @samp{-t} and @samp{-S} options (or, equivalently, the +@samp{%struct-type} and @samp{%switch} declarations) are omitted, the default +action +is to generate a @code{char *} array containing the keywords, together with +additional empty strings used for padding the array. By experimenting with the various input and output options, and timing the resulting C code, you can determine the best option choices for different keyword set characteristics. @node Binary Strings, , Output Format, Description -@section Use of NUL characters +@section Use of NUL bytes @cindex NUL By default, the code generated by @code{gperf} operates on zero -terminated strings, the usual representation of strings in C. This means -that the keywords in the input file must not contain NUL characters, +terminated strings, the usual representation of strings in C. This means +that the keywords in the input file must not contain NUL bytes, and the @var{str} argument passed to @code{hash} or @code{in_word_set} must be NUL terminated and have exactly length @var{len}. -If option @samp{-c} is used, then the @var{str} argument does not need -to be NUL terminated. The code generated by @code{gperf} will only +If option @samp{-c} (or, equivalently, the @samp{%compare-strncmp} +declaration) is used, then the @var{str} argument does not need +to be NUL terminated. The code generated by @code{gperf} will only access the first @var{len}, not @var{len+1}, bytes starting at @var{str}. However, the keywords in the input file still must not contain NUL -characters. +bytes. -If option @samp{-l} is used, then the hash table performs binary -comparison. The keywords in the input file may contain NUL characters, +If option @samp{-l} (or, equivalently, the @samp{%compare-lengths} +declaration) is used, then the hash table performs binary +comparison. The keywords in the input file may contain NUL bytes, written in string syntax as @code{\000} or @code{\x00}, and the code -generated by @code{gperf} will treat NUL like any other character. -Also, in this case the @samp{-c} option is ignored. +generated by @code{gperf} will treat NUL like any other byte. +Also, in this case the @samp{-c} option (or, equivalently, the +@samp{%compare-strncmp} declaration) is ignored. @node Options, Bugs, Description, Top @chapter Invoking @code{gperf} There are @emph{many} options to @code{gperf}. They were added to make the program more convenient for use with real applications. ``On-line'' -help is readily available via the @samp{-h} option. Here is the +help is readily available via the @samp{--help} option. Here is the complete list of options. @menu +* Output File:: Specifying the Location of the Output File * Input Details:: Options that affect Interpretation of the Input File * Output Language:: Specifying the Language for the Output Code * Output Details:: Fine tuning Details in the Output Code @@ -557,15 +868,29 @@ complete list of options. * Verbosity:: Informative Output @end menu -@node Input Details, Output Language, Options, Options +@node Output File, Input Details, Options, Options +@section Specifying the Location of the Output File + +@table @samp +@item --output-file=@var{file} +Allows you to specify the name of the file to which the output is written to. +@end table + +The results are written to standard output if no output file is specified +or if it is @samp{-}. + +@node Input Details, Output Language, Output File, Options @section Options that affect Interpretation of the Input File +These options are also available as declarations in the input file +(@pxref{Gperf Declarations}). + @table @samp @item -e @var{keyword-delimiter-list} @itemx --delimiters=@var{keyword-delimiter-list} @cindex Delimiters -Allows the user to provide a string containing delimiters used to -separate keywords from their attributes. The default is ",\n". This +Allows you to provide a string containing delimiters used to +separate keywords from their attributes. The default is ",". This option is essential if you want to use keywords that have embedded commas or newlines. One useful trick is to use -e'TAB', where TAB is the literal tab character. @@ -578,11 +903,25 @@ part of the type declaration. Keywords and additional fields may follow this, one group of fields per line. A set of examples for generating perfect hash tables and functions for Ada, C, C++, Pascal, Modula 2, Modula 3 and JavaScript reserved words are distributed with this release. + +@item --ignore-case +Consider upper and lower case ASCII characters as equivalent. The string +comparison will use a case insignificant character comparison. Note that +locale dependent case mappings are ignored. This option is therefore not +suitable if a properly internationalized or locale aware case mapping +should be used. (For example, in a Turkish locale, the upper case equivalent +of the lowercase ASCII letter @samp{i} is the non-ASCII character +@samp{capital i with dot above}.) For this case, it is better to apply +an uppercase or lowercase conversion on the string before passing it to +the @code{gperf} generated function. @end table @node Output Language, Output Details, Input Details, Options @section Options to specify the Language for the Output Code +These options are also available as declarations in the input file +(@pxref{Gperf Declarations}). + @table @samp @item -L @var{generated-language-name} @itemx --language=@var{generated-language-name} @@ -591,41 +930,45 @@ option's argument. Languages handled are currently: @table @samp @item KR-C -Old-style K&R C. This language is understood by old-style C compilers and +Old-style K&R C. This language is understood by old-style C compilers and ANSI C compilers, but ANSI C compilers may flag warnings (or even errors) because of lacking @samp{const}. @item C -Common C. This language is understood by ANSI C compilers, and also by +Common C. This language is understood by ANSI C compilers, and also by old-style C compilers, provided that you @code{#define const} to empty for compilers which don't know about this keyword. @item ANSI-C -ANSI C. This language is understood by ANSI C compilers and C++ compilers. +ANSI C. This language is understood by ANSI C compilers and C++ compilers. @item C++ -C++. This language is understood by C++ compilers. +C++. This language is understood by C++ compilers. @end table The default is C. @item -a This option is supported for compatibility with previous releases of -@code{gperf}. It does not do anything. +@code{gperf}. It does not do anything. @item -g This option is supported for compatibility with previous releases of -@code{gperf}. It does not do anything. +@code{gperf}. It does not do anything. @end table @node Output Details, Algorithmic Details, Output Language, Options @section Options for fine tuning Details in the Output Code +Most of these options are also available as declarations in the input file +(@pxref{Gperf Declarations}). + @table @samp -@item -K @var{key-name} -@itemx --slot-name=@var{key-name} +@item -K @var{slot-name} +@itemx --slot-name=@var{slot-name} @cindex Slot name -This option is only useful when option @samp{-t} has been given. +This option is only useful when option @samp{-t} (or, equivalently, the +@samp{%struct-type} declaration) has been given. By default, the program assumes the structure component identifier for the keyword is @samp{name}. This option allows an arbitrary choice of identifier for this component, although it still must occur as the first @@ -634,29 +977,30 @@ field in your supplied @code{struct}. @item -F @var{initializers} @itemx --initializer-suffix=@var{initializers} @cindex Initializers -This option is only useful when option @samp{-t} has been given. +This option is only useful when option @samp{-t} (or, equivalently, the +@samp{%struct-type} declaration) has been given. It permits to specify initializers for the structure members following -@var{key name} in empty hash table entries. The list of initializers +@var{slot-name} in empty hash table entries. The list of initializers should start with a comma. By default, the emitted code will -zero-initialize structure members following @var{key name}. +zero-initialize structure members following @var{slot-name}. @item -H @var{hash-function-name} -@itemx --hash-fn-name=@var{hash-function-name} +@itemx --hash-function-name=@var{hash-function-name} Allows you to specify the name for the generated hash function. Default name is @samp{hash}. This option permits the use of two hash tables in the same file. @item -N @var{lookup-function-name} -@itemx --lookup-fn-name=@var{lookup-function-name} +@itemx --lookup-function-name=@var{lookup-function-name} Allows you to specify the name for the generated lookup function. -Default name is @samp{in_word_set}. This option permits completely -automatic generation of perfect hash functions, especially when multiple -generated hash functions are used in the same application. +Default name is @samp{in_word_set}. This option permits multiple +generated hash functions to be used in the same application. @item -Z @var{class-name} @itemx --class-name=@var{class-name} @cindex Class name -This option is only useful when option @samp{-L C++} has been given. It +This option is only useful when option @samp{-L C++} (or, equivalently, +the @samp{%language=C++} declaration) has been given. It allows you to specify the name of generated C++ class. Default name is @code{Perfect_Hash}. @@ -664,12 +1008,23 @@ allows you to specify the name of generated C++ class. Default name is @itemx --seven-bit This option specifies that all strings that will be passed as arguments to the generated hash function and the generated lookup function will -solely consist of 7-bit ASCII characters (characters in the range 0..127). +solely consist of 7-bit ASCII characters (bytes in the range 0..127). (Note that the ANSI C functions @code{isalnum} and @code{isgraph} do -@emph{not} guarantee that a character is in this range. Only an explicit +@emph{not} guarantee that a byte is in this range. Only an explicit test like @samp{c >= 'A' && c <= 'Z'} guarantees this.) This was the default in versions of @code{gperf} earlier than 2.7; now the default is -to assume 8-bit characters. +to support 8-bit and multibyte characters. + +@item -l +@itemx --compare-lengths +Compare keyword lengths before trying a string comparison. This option +is mandatory for binary comparisons (@pxref{Binary Strings}). It also might +cut down on the number of string comparisons made during the lookup, since +keywords with different lengths are never compared via @code{strcmp}. +However, using @samp{-l} might greatly increase the size of the +generated C code if the lookup table range is large (which implies that +the switch option @samp{-S} or @samp{%switch} is not enabled), since the length +table contains as many elements as there are entries in the lookup table. @item -c @itemx --compare-strncmp @@ -695,30 +1050,63 @@ beginning of the code. By default, this is not done; the user must include this header file himself to allow compilation of the code. @item -G -@itemx --global +@itemx --global-table Generate the static table of keywords as a static global variable, rather than hiding it inside of the lookup function (which is the default behavior). +@item -P +@itemx --pic +Optimize the generated table for inclusion in shared libraries. This +reduces the startup time of programs using a shared library containing +the generated code. If the option @samp{-t} (or, equivalently, the +@samp{%struct-type} declaration) is also given, the first field of the +user-defined struct must be of type @samp{int}, not @samp{char *}, because +it will contain offsets into the string pool instead of actual strings. +To convert such an offset to a string, you can use the expression +@samp{stringpool + @var{o}}, where @var{o} is the offset. The string pool +name can be changed through the option @samp{--string-pool-name}. + +@item -Q @var{string-pool-name} +@itemx --string-pool-name=@var{string-pool-name} +Allows you to specify the name of the generated string pool created by +option @samp{-P}. The default name is @samp{stringpool}. This option +permits the use of two hash tables in the same file, with @samp{-P} and +even when the option @samp{-G} (or, equivalently, the @samp{%global-table} +declaration) is given. + +@item --null-strings +Use NULL strings instead of empty strings for empty keyword table entries. +This reduces the startup time of programs using a shared library containing +the generated code (but not as much as option @samp{-P}), at the expense +of one more test-and-branch instruction at run time. + @item -W @var{hash-table-array-name} @itemx --word-array-name=@var{hash-table-array-name} @cindex Array name Allows you to specify the name for the generated array containing the hash table. Default name is @samp{wordlist}. This option permits the use of two hash tables in the same file, even when the option @samp{-G} -is given. +(or, equivalently, the @samp{%global-table} declaration) is given. + +@itemx --length-table-name=@var{length-table-array-name} +@cindex Array name +Allows you to specify the name for the generated array containing the +length table. Default name is @samp{lengthtable}. This option permits the +use of two length tables in the same file, even when the option @samp{-G} +(or, equivalently, the @samp{%global-table} declaration) is given. @item -S @var{total-switch-statements} @itemx --switch=@var{total-switch-statements} @cindex @code{switch} Causes the generated C code to use a @code{switch} statement scheme, rather than an array lookup table. This can lead to a reduction in both -time and space requirements for some keyfiles. The argument to this -option determines how many @code{switch} statements are generated. A +time and space requirements for some input files. The argument to this +option determines how many @code{switch} statements are generated. A value of 1 generates 1 @code{switch} containing all the elements, a value of 2 generates 2 tables with 1/2 the elements in each @code{switch}, etc. This is useful since many C compilers cannot -correctly generate code for large @code{switch} statements. This option +correctly generate code for large @code{switch} statements. This option was inspired in part by Keith Bostic's original C program. @item -T @@ -728,93 +1116,73 @@ this option if the type is already defined elsewhere. @item -p This option is supported for compatibility with previous releases of -@code{gperf}. It does not do anything. +@code{gperf}. It does not do anything. @end table @node Algorithmic Details, Verbosity, Output Details, Options @section Options for changing the Algorithms employed by @code{gperf} @table @samp -@item -k @var{keys} -@itemx --key-positions=@var{keys} -Allows selection of the character key positions used in the keywords' -hash function. The allowable choices range between 1-126, inclusive. +@item -k @var{selected-byte-positions} +@itemx --key-positions=@var{selected-byte-positions} +Allows selection of the byte positions used in the keywords' +hash function. The allowable choices range between 1-255, inclusive. The positions are separated by commas, e.g., @samp{-k 9,4,13,14}; ranges may be used, e.g., @samp{-k 2-7}; and positions may occur -in any order. Furthermore, the meta-character '*' causes the generated -hash function to consider @strong{all} character positions in each key, -whereas '$' instructs the hash function to use the ``final character'' -of a key (this is the only way to use a character position greater than -126, incidentally). +in any order. Furthermore, the wildcard '*' causes the generated +hash function to consider @strong{all} byte positions in each keyword, +whereas '$' instructs the hash function to use the ``final byte'' +of a keyword (this is the only way to use a byte position greater than +255, incidentally). For instance, the option @samp{-k 1,2,4,6-10,'$'} generates a hash function that considers positions 1,2,4,6,7,8,9,10, plus the last -character in each key (which may differ for each key, obviously). Keys -with length less than the indicated key positions work properly, since -selected key positions exceeding the key length are simply not +byte in each keyword (which may be at a different position for each +keyword, obviously). Keywords +with length less than the indicated byte positions work properly, since +selected byte positions exceeding the keyword length are simply not referenced in the hash function. -@item -l -@itemx --compare-strlen -Compare key lengths before trying a string comparison. This might cut -down on the number of string comparisons made during the lookup, since -keys with different lengths are never compared via @code{strcmp}. -However, using @samp{-l} might greatly increase the size of the -generated C code if the lookup table range is large (which implies that -the switch option @samp{-S} is not enabled), since the length table -contains as many elements as there are entries in the lookup table. -This option is mandatory for binary comparisons (@pxref{Binary Strings}). +This option is not normally needed since version 2.8 of @code{gperf}; +the default byte positions are computed depending on the keyword set, +through a search that minimizes the number of byte positions. @item -D @itemx --duplicates @cindex Duplicates -Handle keywords whose key position sets hash to duplicate values. -Duplicate hash values occur for two reasons: - -@itemize @bullet -@item -Since @code{gperf} does not backtrack it is possible for it to process -all your input keywords without finding a unique mapping for each word. -However, frequently only a very small number of duplicates occur, and -the majority of keys still require one probe into the table. - -@item -Sometimes a set of keys may have the same names, but possess different -attributes. With the -D option @code{gperf} treats all these keys as +Handle keywords whose selected byte sets hash to duplicate values. +Duplicate hash values can occur if a set of keywords has the same names, but +possesses different attributes, or if the selected byte positions are not well +chosen. With the -D option @code{gperf} treats all these keywords as part of an equivalence class and generates a perfect hash function with -multiple comparisons for duplicate keys. It is up to you to completely +multiple comparisons for duplicate keywords. It is up to you to completely disambiguate the keywords by modifying the generated C code. However, @code{gperf} helps you out by organizing the output. -@end itemize -Option @samp{-D} is extremely useful for certain large or highly -redundant keyword sets, e.g., assembler instruction opcodes. Using this option usually means that the generated hash function is no longer perfect. On the other hand, it permits @code{gperf} to work on keyword sets that it otherwise could not handle. -@item -f @var{iteration-amount} -@itemx --fast=@var{iteration-amount} -Generate the perfect hash function ``fast''. This decreases -@code{gperf}'s running time at the cost of minimizing generated -table-size. The iteration amount represents the number of times to -iterate when resolving a collision. `0' means iterate by the number of -keywords. This option is probably most useful when used in conjunction -with options @samp{-D} and/or @samp{-S} for @emph{large} keyword sets. +@item -m @var{iterations} +@itemx --multiple-iterations=@var{iterations} +Perform multiple choices of the @samp{-i} and @samp{-j} values, and +choose the best results. This increases the running time by a factor of +@var{iterations} but does a good job minimizing the generated table size. @item -i @var{initial-value} @itemx --initial-asso=@var{initial-value} Provides an initial @var{value} for the associate values array. Default is 0. Increasing the initial value helps inflate the final table size, possibly leading to more time efficient keyword lookups. Note that this -option is not particularly useful when @samp{-S} is used. Also, +option is not particularly useful when @samp{-S} (or, equivalently, +@samp{%switch}) is used. Also, @samp{-i} is overridden when the @samp{-r} option is used. @item -j @var{jump-value} @itemx --jump=@var{jump-value} @cindex Jump value Affects the ``jump value'', i.e., how far to advance the associated -character value upon collisions. @var{Jump-value} is rounded up to an +byte value upon collisions. @var{Jump-value} is rounded up to an odd number, the default is 5. If the @var{jump-value} is 0 @code{gperf} jumps by random amounts. @@ -824,60 +1192,38 @@ Instructs the generator not to include the length of a keyword when computing its hash value. This may save a few assembly instructions in the generated lookup table. -@item -o -@itemx --occurrence-sort -Reorders the keywords by sorting the keywords so that frequently -occuring key position set components appear first. A second reordering -pass follows so that keys with ``already determined values'' are placed -towards the front of the keylist. This may decrease the time required -to generate a perfect hash function for many keyword sets, and also -produce more minimal perfect hash functions. The reason for this is -that the reordering helps prune the search time by handling inevitable -collisions early in the search process. On the other hand, if the -number of keywords is @emph{very} large using @samp{-o} may -@emph{increase} @code{gperf}'s execution time, since collisions will -begin earlier and continue throughout the remainder of keyword -processing. See Cichelli's paper from the January 1980 Communications -of the ACM for details. - @item -r @itemx --random Utilizes randomness to initialize the associated values table. This frequently generates solutions faster than using deterministic initialization (which starts all associated values at 0). Furthermore, using the randomization option generally increases the size of the -table. If @code{gperf} has difficultly with a certain keyword set try using -@samp{-r} or @samp{-D}. +table. @item -s @var{size-multiple} @itemx --size-multiple=@var{size-multiple} Affects the size of the generated hash table. The numeric argument for this option indicates ``how many times larger or smaller'' the maximum -associated value range should be, in relationship to the number of keys. -If the @var{size-multiple} is negative the maximum associated value is -calculated by @emph{dividing} it into the total number of keys. For -example, a value of 3 means ``allow the maximum associated value to be -about 3 times larger than the number of input keys''. +associated value range should be, in relationship to the number of keywords. +It can be written as an integer, a floating-point number or a fraction. +For example, a value of 3 means ``allow the maximum associated value to be +about 3 times larger than the number of input keywords''. +Conversely, a value of 1/3 means ``allow the maximum associated value to +be about 3 times smaller than the number of input keywords''. Values +smaller than 1 are useful for limiting the overall size of the generated hash +table, though the option @samp{-m} is better at this purpose. -Conversely, a value of -3 means ``allow the maximum associated value to -be about 3 times smaller than the number of input keys''. Negative -values are useful for limiting the overall size of the generated hash -table, though this usually increases the number of duplicate hash -values. - -If `generate switch' option @samp{-S} is @emph{not} enabled, the maximum +If `generate switch' option @samp{-S} (or, equivalently, @samp{%switch}) is +@emph{not} enabled, the maximum associated value influences the static array table size, and a larger table should decrease the time required for an unsuccessful search, at the expense of extra table space. The default value is 1, thus the default maximum associated value about -the same size as the number of keys (for efficiency, the maximum +the same size as the number of keywords (for efficiency, the maximum associated value is always rounded up to a power of 2). The actual table size may vary somewhat, since this technique is essentially a -heuristic. In particular, setting this value too high slows down -@code{gperf}'s runtime, since it must search through a much larger range -of values. Judicious use of the @samp{-f} option helps alleviate this -overhead, however. +heuristic. @end table @node Verbosity, , Algorithmic Details, Options @@ -919,16 +1265,6 @@ work efficiently on much larger keyword sets (over 15,000 keywords). When processing large keyword sets it helps greatly to have over 8 megs of RAM. -However, since @code{gperf} does not backtrack no guaranteed solution -occurs on every run. On the other hand, it is usually easy to obtain a -solution by varying the option parameters. In particular, try the -@samp{-r} option, and also try changing the default arguments to the -@samp{-s} and @samp{-j} options. To @emph{guarantee} a solution, use -the @samp{-D} and @samp{-S} options, although the final results are not -likely to be a @emph{perfect} hash function anymore! Finally, use the -@samp{-f} option if you want @code{gperf} to generate the perfect hash -function @emph{fast}, with less emphasis on making it minimal. - @item The size of the generate static keyword array can get @emph{extremely} large if the input keyword file is large or if the keywords are quite @@ -936,19 +1272,19 @@ similar. This tends to slow down the compilation of the generated C code, and @emph{greatly} inflates the object code size. If this situation occurs, consider using the @samp{-S} option to reduce data size, potentially increasing keyword recognition time a negligible -amount. Since many C compilers cannot correctly generated code for +amount. Since many C compilers cannot correctly generate code for large switch statements it is important to qualify the @var{-S} option with an appropriate numerical argument that controls the number of switch statements generated. @item -The maximum number of key positions selected for a given key has an -arbitrary limit of 126. This restriction should be removed, and if +The maximum number of selected byte positions has an +arbitrary limit of 255. This restriction should be removed, and if anyone considers this a problem write me and let me know so I can remove the constraint. @end itemize -@node Projects, Implementation, Bugs, Top +@node Projects, Bibliography, Bugs, Top @chapter Things Still Left to Do It should be ``relatively'' easy to replace the current perfect hash @@ -957,19 +1293,11 @@ module is essential independent from other program modules. Additional worthwhile improvements include: @itemize @bullet -@item -Make the algorithm more robust. At present, the program halts with an -error diagnostic if it can't find a direct solution and the @samp{-D} -option is not enabled. A more comprehensive, albeit computationally -expensive, approach would employ backtracking or enable alternative -options and retry. It's not clear how helpful this would be, in -general, since most search sets are rather small in practice. - @item Another useful extension involves modifying the program to generate ``minimal'' perfect hash functions (under certain circumstances, the current version can be rather extravagant in the generated table size). -Again, this is mostly of theoretical interest, since a sparse table +This is mostly of theoretical interest, since a sparse table often produces faster lookups, and use of the @samp{-S} @code{switch} option can minimize the data size, at the expense of slightly longer lookups (note that the gcc compiler generally produces good code for @@ -977,42 +1305,30 @@ lookups (note that the gcc compiler generally produces good code for @item In addition to improving the algorithm, it would also be useful to -generate a C++ class or Ada package as the code output, in addition to -the current C routines. +generate an Ada package as the code output, in addition to the current +C and C++ routines. @end itemize -@node Implementation, Bibliography, Projects, Top -@chapter Implementation Details of GNU @code{gperf} - -A paper describing the high-level description of the data structures and -algorithms used to implement @code{gperf} will soon be available. This -paper is useful not only from a maintenance and enhancement perspective, -but also because they demonstrate several clever and useful programming -techniques, e.g., `Iteration Number' boolean arrays, double -hashing, a ``safe'' and efficient method for reading arbitrarily long -input from a file, and a provably optimal algorithm for simultaneously -determining both the minimum and maximum elements in a list. - @page -@node Bibliography, Concept Index, Implementation, Top +@node Bibliography, Concept Index, Projects, Top @chapter Bibliography [1] Chang, C.C.: @i{A Scheme for Constructing Ordered Minimal Perfect Hashing Functions} Information Sciences 39(1986), 187-195. - + [2] Cichelli, Richard J. @i{Author's Response to ``On Cichelli's Minimal Perfect Hash Functions Method''} Communications of the ACM, 23, 12(December 1980), 729. - + [3] Cichelli, Richard J. @i{Minimal Perfect Hash Functions Made Simple} Communications of the ACM, 23, 1(January 1980), 17-19. - + [4] Cook, C. R. and Oldehoeft, R.R. @i{A Letter Oriented Minimal Perfect Hashing Function} SIGPLAN Notices, 17, 9(September 1982), 18-27. [5] Cormack, G. V. and Horspool, R. N. S. and Kaiserwerth, M. @i{Practical Perfect Hashing} Computer Journal, 28, 1(January 1985), 54-58. - + [6] Jaeschke, G. @i{Reciprocal Hashing: A Method for Generating Minimal Perfect Hashing Functions} Communications of the ACM, 24, 12(December 1981), 829-833. @@ -1027,19 +1343,22 @@ Hash Functions} Communications of the ACM, 28, 5(December 1985), 523-532 [9] Schmidt, Douglas C. @i{GPERF: A Perfect Hash Function Generator} Second USENIX C++ Conference Proceedings, April 1990. -[10] Sebesta, R.W. and Taylor, M.A. @i{Minimal Perfect Hash Functions +[10] Schmidt, Douglas C. @i{GPERF: A Perfect Hash Function Generator} +C++ Report, SIGS 10 10 (November/December 1998). + +[11] Sebesta, R.W. and Taylor, M.A. @i{Minimal Perfect Hash Functions for Reserved Word Lists} SIGPLAN Notices, 20, 12(September 1985), 47-53. -[11] Sprugnoli, R. @i{Perfect Hashing Functions: A Single Probe +[12] Sprugnoli, R. @i{Perfect Hashing Functions: A Single Probe Retrieving Method for Static Sets} Communications of the ACM, 20 11(November 1977), 841-850. -[12] Stallman, Richard M. @i{Using and Porting GNU CC} Free Software Foundation, +[13] Stallman, Richard M. @i{Using and Porting GNU CC} Free Software Foundation, 1988. -[13] Stroustrup, Bjarne @i{The C++ Programming Language.} Addison-Wesley, 1986. +[14] Stroustrup, Bjarne @i{The C++ Programming Language.} Addison-Wesley, 1986. -[14] Tiemann, Michael D. @i{User's Guide to GNU C++} Free Software +[15] Tiemann, Michael D. @i{User's Guide to GNU C++} Free Software Foundation, 1989. @node Concept Index, , Bibliography, Top diff --git a/contrib/gperf/doc/help2man b/contrib/gperf/doc/help2man index 2c8164789aa7..5fc20dc4529f 100755 --- a/contrib/gperf/doc/help2man +++ b/contrib/gperf/doc/help2man @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Written by Brendan O'Dea # Available from ftp://ftp.gnu.org/gnu/help2man/ @@ -27,7 +27,7 @@ use Text::Tabs qw(expand); use POSIX qw(strftime setlocale LC_TIME); my $this_program = 'help2man'; -my $this_version = '1.022'; +my $this_version = '1.23'; my $version_info = < 0pt - % Only leave this space if the footline is nonempty. - % (We lessened \vsize for it in \oddfootingxxx.) - % The \baselineskip=24pt in plain's \makefootline has no effect. - \vskip 2\baselineskip - \unvbox\footlinebox - \fi - % - \ifcropmarks - \egroup % end of \vbox\bgroup - \hfil\egroup % end of (centering) \line\bgroup - \vskip\topandbottommargin plus1fill minus1fill - \boxmaxdepth = \cornerthick - \vbox to0pt{\vss - \line{% - \vbox{\moveleft\cornerthick\nsbot}% - \hfill - \vbox{\moveright\cornerthick\nsbot}% - }% - \nointerlineskip - \line{\ewbot\hfil\ewbot}% - }% - \egroup % \vbox from first cropmarks clause - \fi - }% end of \shipout\vbox - }% end of group with \turnoffactive - \advancepageno - \ifnum\outputpenalty>-20000 \else\dosupereject\fi -} - -\newinsert\margin \dimen\margin=\maxdimen - -\def\pagebody#1{\vbox to\pageheight{\boxmaxdepth=\maxdepth #1}} -{\catcode`\@ =11 -\gdef\pagecontents#1{\ifvoid\topins\else\unvbox\topins\fi -% marginal hacks, juha@viisa.uucp (Juha Takala) -\ifvoid\margin\else % marginal info is present - \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi -\dimen@=\dp#1 \unvbox#1 -\ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi -\ifr@ggedbottom \kern-\dimen@ \vfil \fi} -} - -% Here are the rules for the cropmarks. Note that they are -% offset so that the space between them is truly \outerhsize or \outervsize -% (P. A. MacKay, 12 November, 1986) -% -\def\ewtop{\vrule height\cornerthick depth0pt width\cornerlong} -\def\nstop{\vbox - {\hrule height\cornerthick depth\cornerlong width\cornerthick}} -\def\ewbot{\vrule height0pt depth\cornerthick width\cornerlong} -\def\nsbot{\vbox - {\hrule height\cornerlong depth\cornerthick width\cornerthick}} - -% Parse an argument, then pass it to #1. The argument is the rest of -% the input line (except we remove a trailing comment). #1 should be a -% macro which expects an ordinary undelimited TeX argument. -% -\def\parsearg#1{% - \let\next = #1% - \begingroup - \obeylines - \futurelet\temp\parseargx -} - -% If the next token is an obeyed space (from an @example environment or -% the like), remove it and recurse. Otherwise, we're done. -\def\parseargx{% - % \obeyedspace is defined far below, after the definition of \sepspaces. - \ifx\obeyedspace\temp - \expandafter\parseargdiscardspace - \else - \expandafter\parseargline - \fi -} - -% Remove a single space (as the delimiter token to the macro call). -{\obeyspaces % - \gdef\parseargdiscardspace {\futurelet\temp\parseargx}} - -{\obeylines % - \gdef\parseargline#1^^M{% - \endgroup % End of the group started in \parsearg. - % - % First remove any @c comment, then any @comment. - % Result of each macro is put in \toks0. - \argremovec #1\c\relax % - \expandafter\argremovecomment \the\toks0 \comment\relax % - % - % Call the caller's macro, saved as \next in \parsearg. - \expandafter\next\expandafter{\the\toks0}% - }% -} - -% Since all \c{,omment} does is throw away the argument, we can let TeX -% do that for us. The \relax here is matched by the \relax in the call -% in \parseargline; it could be more or less anything, its purpose is -% just to delimit the argument to the \c. -\def\argremovec#1\c#2\relax{\toks0 = {#1}} -\def\argremovecomment#1\comment#2\relax{\toks0 = {#1}} - -% \argremovec{,omment} might leave us with trailing spaces, though; e.g., -% @end itemize @c foo -% will have two active spaces as part of the argument with the -% `itemize'. Here we remove all active spaces from #1, and assign the -% result to \toks0. -% -% This loses if there are any *other* active characters besides spaces -% in the argument -- _ ^ +, for example -- since they get expanded. -% Fortunately, Texinfo does not define any such commands. (If it ever -% does, the catcode of the characters in questionwill have to be changed -% here.) But this means we cannot call \removeactivespaces as part of -% \argremovec{,omment}, since @c uses \parsearg, and thus the argument -% that \parsearg gets might well have any character at all in it. -% -\def\removeactivespaces#1{% - \begingroup - \ignoreactivespaces - \edef\temp{#1}% - \global\toks0 = \expandafter{\temp}% - \endgroup -} - -% Change the active space to expand to nothing. -% -\begingroup - \obeyspaces - \gdef\ignoreactivespaces{\obeyspaces\let =\empty} -\endgroup - - -\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next} - -%% These are used to keep @begin/@end levels from running away -%% Call \inENV within environments (after a \begingroup) -\newif\ifENV \ENVfalse \def\inENV{\ifENV\relax\else\ENVtrue\fi} -\def\ENVcheck{% -\ifENV\errmessage{Still within an environment; press RETURN to continue} -\endgroup\fi} % This is not perfect, but it should reduce lossage - -% @begin foo is the same as @foo, for now. -\newhelp\EMsimple{Press RETURN to continue.} - -\outer\def\begin{\parsearg\beginxxx} - -\def\beginxxx #1{% -\expandafter\ifx\csname #1\endcsname\relax -{\errhelp=\EMsimple \errmessage{Undefined command @begin #1}}\else -\csname #1\endcsname\fi} - -% @end foo executes the definition of \Efoo. -% -\def\end{\parsearg\endxxx} -\def\endxxx #1{% - \removeactivespaces{#1}% - \edef\endthing{\the\toks0}% - % - \expandafter\ifx\csname E\endthing\endcsname\relax - \expandafter\ifx\csname \endthing\endcsname\relax - % There's no \foo, i.e., no ``environment'' foo. - \errhelp = \EMsimple - \errmessage{Undefined command `@end \endthing'}% - \else - \unmatchedenderror\endthing - \fi - \else - % Everything's ok; the right environment has been started. - \csname E\endthing\endcsname - \fi -} - -% There is an environment #1, but it hasn't been started. Give an error. -% -\def\unmatchedenderror#1{% - \errhelp = \EMsimple - \errmessage{This `@end #1' doesn't have a matching `@#1'}% -} - -% Define the control sequence \E#1 to give an unmatched @end error. -% -\def\defineunmatchedend#1{% - \expandafter\def\csname E#1\endcsname{\unmatchedenderror{#1}}% -} - - -% Single-spacing is done by various environments (specifically, in -% \nonfillstart and \quotations). -\newskip\singlespaceskip \singlespaceskip = 12.5pt -\def\singlespace{% - % Why was this kern here? It messes up equalizing space above and below - % environments. --karl, 6may93 - %{\advance \baselineskip by -\singlespaceskip - %\kern \baselineskip}% - \setleading \singlespaceskip -} - -%% Simple single-character @ commands - -% @@ prints an @ -% Kludge this until the fonts are right (grr). -\def\@{{\tt\char64}} - -% This is turned off because it was never documented -% and you can use @w{...} around a quote to suppress ligatures. -%% Define @` and @' to be the same as ` and ' -%% but suppressing ligatures. -%\def\`{{`}} -%\def\'{{'}} - -% Used to generate quoted braces. -\def\mylbrace {{\tt\char123}} -\def\myrbrace {{\tt\char125}} -\let\{=\mylbrace -\let\}=\myrbrace -\begingroup - % Definitions to produce actual \{ & \} command in an index. - \catcode`\{ = 12 \catcode`\} = 12 - \catcode`\[ = 1 \catcode`\] = 2 - \catcode`\@ = 0 \catcode`\\ = 12 - @gdef@lbracecmd[\{]% - @gdef@rbracecmd[\}]% -@endgroup - -% Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent -% Others are defined by plain TeX: @` @' @" @^ @~ @= @v @H. -\let\, = \c -\let\dotaccent = \. -\def\ringaccent#1{{\accent23 #1}} -\let\tieaccent = \t -\let\ubaraccent = \b -\let\udotaccent = \d - -% Other special characters: @questiondown @exclamdown -% Plain TeX defines: @AA @AE @O @OE @L (and lowercase versions) @ss. -\def\questiondown{?`} -\def\exclamdown{!`} - -% Dotless i and dotless j, used for accents. -\def\imacro{i} -\def\jmacro{j} -\def\dotless#1{% - \def\temp{#1}% - \ifx\temp\imacro \ptexi - \else\ifx\temp\jmacro \j - \else \errmessage{@dotless can be used only with i or j}% - \fi\fi -} - -% Be sure we're in horizontal mode when doing a tie, since we make space -% equivalent to this in @example-like environments. Otherwise, a space -% at the beginning of a line will start with \penalty -- and -% since \penalty is valid in vertical mode, we'd end up putting the -% penalty on the vertical list instead of in the new paragraph. -{\catcode`@ = 11 - % Avoid using \@M directly, because that causes trouble - % if the definition is written into an index file. - \global\let\tiepenalty = \@M - \gdef\tie{\leavevmode\penalty\tiepenalty\ } -} - -% @: forces normal size whitespace following. -\def\:{\spacefactor=1000 } - -% @* forces a line break. -\def\*{\hfil\break\hbox{}\ignorespaces} - -% @. is an end-of-sentence period. -\def\.{.\spacefactor=3000 } - -% @! is an end-of-sentence bang. -\def\!{!\spacefactor=3000 } - -% @? is an end-of-sentence query. -\def\?{?\spacefactor=3000 } - -% @w prevents a word break. Without the \leavevmode, @w at the -% beginning of a paragraph, when TeX is still in vertical mode, would -% produce a whole line of output instead of starting the paragraph. -\def\w#1{\leavevmode\hbox{#1}} - -% @group ... @end group forces ... to be all on one page, by enclosing -% it in a TeX vbox. We use \vtop instead of \vbox to construct the box -% to keep its height that of a normal line. According to the rules for -% \topskip (p.114 of the TeXbook), the glue inserted is -% max (\topskip - \ht (first item), 0). If that height is large, -% therefore, no glue is inserted, and the space between the headline and -% the text is small, which looks bad. -% -\def\group{\begingroup - \ifnum\catcode13=\active \else - \errhelp = \groupinvalidhelp - \errmessage{@group invalid in context where filling is enabled}% - \fi - % - % The \vtop we start below produces a box with normal height and large - % depth; thus, TeX puts \baselineskip glue before it, and (when the - % next line of text is done) \lineskip glue after it. (See p.82 of - % the TeXbook.) Thus, space below is not quite equal to space - % above. But it's pretty close. - \def\Egroup{% - \egroup % End the \vtop. - \endgroup % End the \group. - }% - % - \vtop\bgroup - % We have to put a strut on the last line in case the @group is in - % the midst of an example, rather than completely enclosing it. - % Otherwise, the interline space between the last line of the group - % and the first line afterwards is too small. But we can't put the - % strut in \Egroup, since there it would be on a line by itself. - % Hence this just inserts a strut at the beginning of each line. - \everypar = {\strut}% - % - % Since we have a strut on every line, we don't need any of TeX's - % normal interline spacing. - \offinterlineskip - % - % OK, but now we have to do something about blank - % lines in the input in @example-like environments, which normally - % just turn into \lisppar, which will insert no space now that we've - % turned off the interline space. Simplest is to make them be an - % empty paragraph. - \ifx\par\lisppar - \edef\par{\leavevmode \par}% - % - % Reset ^^M's definition to new definition of \par. - \obeylines - \fi - % - % Do @comment since we are called inside an environment such as - % @example, where each end-of-line in the input causes an - % end-of-line in the output. We don't want the end-of-line after - % the `@group' to put extra space in the output. Since @group - % should appear on a line by itself (according to the Texinfo - % manual), we don't worry about eating any user text. - \comment -} -% -% TeX puts in an \escapechar (i.e., `@') at the beginning of the help -% message, so this ends up printing `@group can only ...'. -% -\newhelp\groupinvalidhelp{% -group can only be used in environments such as @example,^^J% -where each line of input produces a line of output.} - -% @need space-in-mils -% forces a page break if there is not space-in-mils remaining. - -\newdimen\mil \mil=0.001in - -\def\need{\parsearg\needx} - -% Old definition--didn't work. -%\def\needx #1{\par % -%% This method tries to make TeX break the page naturally -%% if the depth of the box does not fit. -%{\baselineskip=0pt% -%\vtop to #1\mil{\vfil}\kern -#1\mil\nobreak -%\prevdepth=-1000pt -%}} - -\def\needx#1{% - % Ensure vertical mode, so we don't make a big box in the middle of a - % paragraph. - \par - % - % If the @need value is less than one line space, it's useless. - \dimen0 = #1\mil - \dimen2 = \ht\strutbox - \advance\dimen2 by \dp\strutbox - \ifdim\dimen0 > \dimen2 - % - % Do a \strut just to make the height of this box be normal, so the - % normal leading is inserted relative to the preceding line. - % And a page break here is fine. - \vtop to #1\mil{\strut\vfil}% - % - % TeX does not even consider page breaks if a penalty added to the - % main vertical list is 10000 or more. But in order to see if the - % empty box we just added fits on the page, we must make it consider - % page breaks. On the other hand, we don't want to actually break the - % page after the empty box. So we use a penalty of 9999. - % - % There is an extremely small chance that TeX will actually break the - % page at this \penalty, if there are no other feasible breakpoints in - % sight. (If the user is using lots of big @group commands, which - % almost-but-not-quite fill up a page, TeX will have a hard time doing - % good page breaking, for example.) However, I could not construct an - % example where a page broke at this \penalty; if it happens in a real - % document, then we can reconsider our strategy. - \penalty9999 - % - % Back up by the size of the box, whether we did a page break or not. - \kern -#1\mil - % - % Do not allow a page break right after this kern. - \nobreak - \fi -} - -% @br forces paragraph break - -\let\br = \par - -% @dots{} output an ellipsis using the current font. -% We do .5em per period so that it has the same spacing in a typewriter -% font as three actual period characters. -% -\def\dots{% - \leavevmode - \hbox to 1.5em{% - \hskip 0pt plus 0.25fil minus 0.25fil - .\hss.\hss.% - \hskip 0pt plus 0.5fil minus 0.5fil - }% -} - -% @enddots{} is an end-of-sentence ellipsis. -% -\def\enddots{% - \leavevmode - \hbox to 2em{% - \hskip 0pt plus 0.25fil minus 0.25fil - .\hss.\hss.\hss.% - \hskip 0pt plus 0.5fil minus 0.5fil - }% - \spacefactor=3000 -} - - -% @page forces the start of a new page -% -\def\page{\par\vfill\supereject} - -% @exdent text.... -% outputs text on separate line in roman font, starting at standard page margin - -% This records the amount of indent in the innermost environment. -% That's how much \exdent should take out. -\newskip\exdentamount - -% This defn is used inside fill environments such as @defun. -\def\exdent{\parsearg\exdentyyy} -\def\exdentyyy #1{{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}} - -% This defn is used inside nofill environments such as @example. -\def\nofillexdent{\parsearg\nofillexdentyyy} -\def\nofillexdentyyy #1{{\advance \leftskip by -\exdentamount -\leftline{\hskip\leftskip{\rm#1}}}} - -% @inmargin{TEXT} puts TEXT in the margin next to the current paragraph. - -\def\inmargin#1{% -\strut\vadjust{\nobreak\kern-\strutdepth - \vtop to \strutdepth{\baselineskip\strutdepth\vss - \llap{\rightskip=\inmarginspacing \vbox{\noindent #1}}\null}}} -\newskip\inmarginspacing \inmarginspacing=1cm -\def\strutdepth{\dp\strutbox} - -%\hbox{{\rm#1}}\hfil\break}} - -% @include file insert text of that file as input. -% Allow normal characters that we make active in the argument (a file name). -\def\include{\begingroup - \catcode`\\=12 - \catcode`~=12 - \catcode`^=12 - \catcode`_=12 - \catcode`|=12 - \catcode`<=12 - \catcode`>=12 - \catcode`+=12 - \parsearg\includezzz} -% Restore active chars for included file. -\def\includezzz#1{\endgroup\begingroup - % Read the included file in a group so nested @include's work. - \def\thisfile{#1}% - \input\thisfile -\endgroup} - -\def\thisfile{} - -% @center line outputs that line, centered - -\def\center{\parsearg\centerzzz} -\def\centerzzz #1{{\advance\hsize by -\leftskip -\advance\hsize by -\rightskip -\centerline{#1}}} - -% @sp n outputs n lines of vertical space - -\def\sp{\parsearg\spxxx} -\def\spxxx #1{\vskip #1\baselineskip} - -% @comment ...line which is ignored... -% @c is the same as @comment -% @ignore ... @end ignore is another way to write a comment - -\def\comment{\begingroup \catcode`\^^M=\other% -\catcode`\@=\other \catcode`\{=\other \catcode`\}=\other% -\commentxxx} -{\catcode`\^^M=\other \gdef\commentxxx#1^^M{\endgroup}} - -\let\c=\comment - -% @paragraphindent NCHARS -% We'll use ems for NCHARS, close enough. -% We cannot implement @paragraphindent asis, though. -% -\def\asisword{asis} % no translation, these are keywords -\def\noneword{none} -% -\def\paragraphindent{\parsearg\doparagraphindent} -\def\doparagraphindent#1{% - \def\temp{#1}% - \ifx\temp\asisword - \else - \ifx\temp\noneword - \defaultparindent = 0pt - \else - \defaultparindent = #1em - \fi - \fi - \parindent = \defaultparindent -} - -% @exampleindent NCHARS -% We'll use ems for NCHARS like @paragraphindent. -% It seems @exampleindent asis isn't necessary, but -% I preserve it to make it similar to @paragraphindent. -\def\exampleindent{\parsearg\doexampleindent} -\def\doexampleindent#1{% - \def\temp{#1}% - \ifx\temp\asisword - \else - \ifx\temp\noneword - \lispnarrowing = 0pt - \else - \lispnarrowing = #1em - \fi - \fi -} - -% @asis just yields its argument. Used with @table, for example. -% -\def\asis#1{#1} - -% @math means output in math mode. -% We don't use $'s directly in the definition of \math because control -% sequences like \math are expanded when the toc file is written. Then, -% we read the toc file back, the $'s will be normal characters (as they -% should be, according to the definition of Texinfo). So we must use a -% control sequence to switch into and out of math mode. -% -% This isn't quite enough for @math to work properly in indices, but it -% seems unlikely it will ever be needed there. -% -\let\implicitmath = $ -\def\math#1{\implicitmath #1\implicitmath} - -% @bullet and @minus need the same treatment as @math, just above. -\def\bullet{\implicitmath\ptexbullet\implicitmath} -\def\minus{\implicitmath-\implicitmath} - -% @refill is a no-op. -\let\refill=\relax - -% If working on a large document in chapters, it is convenient to -% be able to disable indexing, cross-referencing, and contents, for test runs. -% This is done with @novalidate (before @setfilename). -% -\newif\iflinks \linkstrue % by default we want the aux files. -\let\novalidate = \linksfalse - -% @setfilename is done at the beginning of every texinfo file. -% So open here the files we need to have open while reading the input. -% This makes it possible to make a .fmt file for texinfo. -\def\setfilename{% - \iflinks - \readauxfile - \fi % \openindices needs to do some work in any case. - \openindices - \fixbackslash % Turn off hack to swallow `\input texinfo'. - \global\let\setfilename=\comment % Ignore extra @setfilename cmds. - % - % If texinfo.cnf is present on the system, read it. - % Useful for site-wide @afourpaper, etc. - % Just to be on the safe side, close the input stream before the \input. - \openin 1 texinfo.cnf - \ifeof1 \let\temp=\relax \else \def\temp{\input texinfo.cnf }\fi - \closein1 - \temp - % - \comment % Ignore the actual filename. -} - -% Called from \setfilename. -% -\def\openindices{% - \newindex{cp}% - \newcodeindex{fn}% - \newcodeindex{vr}% - \newcodeindex{tp}% - \newcodeindex{ky}% - \newcodeindex{pg}% -} - -% @bye. -\outer\def\bye{\pagealignmacro\tracingstats=1\ptexend} - - -\message{pdf,} -% adobe `portable' document format -\newcount\tempnum -\newcount\lnkcount -\newtoks\filename -\newcount\filenamelength -\newcount\pgn -\newtoks\toksA -\newtoks\toksB -\newtoks\toksC -\newtoks\toksD -\newbox\boxA -\newcount\countA -\newif\ifpdf -\newif\ifpdfmakepagedest - -\ifx\pdfoutput\undefined - \pdffalse - \let\pdfmkdest = \gobble - \let\pdfurl = \gobble - \let\endlink = \relax - \let\linkcolor = \relax - \let\pdfmakeoutlines = \relax -\else - \pdftrue - \pdfoutput = 1 - \input pdfcolor - \def\dopdfimage#1#2#3{% - \def\imagewidth{#2}% - \def\imageheight{#3}% - \ifnum\pdftexversion < 14 - \pdfimage - \else - \pdfximage - \fi - \ifx\empty\imagewidth\else width \imagewidth \fi - \ifx\empty\imageheight\else height \imageheight \fi - {#1.pdf}% - \ifnum\pdftexversion < 14 \else - \pdfrefximage \pdflastximage - \fi} - \def\pdfmkdest#1{\pdfdest name{#1@} xyz} - \def\pdfmkpgn#1{#1@} - \let\linkcolor = \Blue % was Cyan, but that seems light? - \def\endlink{\Black\pdfendlink} - % Adding outlines to PDF; macros for calculating structure of outlines - % come from Petr Olsak - \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0% - \else \csname#1\endcsname \fi} - \def\advancenumber#1{\tempnum=\expnumber{#1}\relax - \advance\tempnum by1 - \expandafter\xdef\csname#1\endcsname{\the\tempnum}} - \def\pdfmakeoutlines{{% - \openin 1 \jobname.toc - \ifeof 1\else\bgroup - \closein 1 - \indexnofonts - \def\tt{} - \let\_ = \normalunderscore - % Thanh's hack / proper braces in bookmarks - \edef\mylbrace{\iftrue \string{\else}\fi}\let\{=\mylbrace - \edef\myrbrace{\iffalse{\else\string}\fi}\let\}=\myrbrace - % - \def\chapentry ##1##2##3{} - \def\unnumbchapentry ##1##2{} - \def\secentry ##1##2##3##4{\advancenumber{chap##2}} - \def\unnumbsecentry ##1##2{} - \def\subsecentry ##1##2##3##4##5{\advancenumber{sec##2.##3}} - \def\unnumbsubsecentry ##1##2{} - \def\subsubsecentry ##1##2##3##4##5##6{\advancenumber{subsec##2.##3.##4}} - \def\unnumbsubsubsecentry ##1##2{} - \input \jobname.toc - \def\chapentry ##1##2##3{% - \pdfoutline goto name{\pdfmkpgn{##3}}count-\expnumber{chap##2}{##1}} - \def\unnumbchapentry ##1##2{% - \pdfoutline goto name{\pdfmkpgn{##2}}{##1}} - \def\secentry ##1##2##3##4{% - \pdfoutline goto name{\pdfmkpgn{##4}}count-\expnumber{sec##2.##3}{##1}} - \def\unnumbsecentry ##1##2{% - \pdfoutline goto name{\pdfmkpgn{##2}}{##1}} - \def\subsecentry ##1##2##3##4##5{% - \pdfoutline goto name{\pdfmkpgn{##5}}count-\expnumber{subsec##2.##3.##4}{##1}} - \def\unnumbsubsecentry ##1##2{% - \pdfoutline goto name{\pdfmkpgn{##2}}{##1}} - \def\subsubsecentry ##1##2##3##4##5##6{% - \pdfoutline goto name{\pdfmkpgn{##6}}{##1}} - \def\unnumbsubsubsecentry ##1##2{% - \pdfoutline goto name{\pdfmkpgn{##2}}{##1}} - \input \jobname.toc - \egroup\fi - }} - \def\makelinks #1,{% - \def\params{#1}\def\E{END}% - \ifx\params\E - \let\nextmakelinks=\relax - \else - \let\nextmakelinks=\makelinks - \ifnum\lnkcount>0,\fi - \picknum{#1}% - \startlink attr{/Border [0 0 0]} - goto name{\pdfmkpgn{\the\pgn}}% - \linkcolor #1% - \advance\lnkcount by 1% - \endlink - \fi - \nextmakelinks - } - \def\picknum#1{\expandafter\pn#1} - \def\pn#1{% - \def\p{#1}% - \ifx\p\lbrace - \let\nextpn=\ppn - \else - \let\nextpn=\ppnn - \def\first{#1} - \fi - \nextpn - } - \def\ppn#1{\pgn=#1\gobble} - \def\ppnn{\pgn=\first} - \def\pdfmklnk#1{\lnkcount=0\makelinks #1,END,} - \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks} - \def\skipspaces#1{\def\PP{#1}\def\D{|}% - \ifx\PP\D\let\nextsp\relax - \else\let\nextsp\skipspaces - \ifx\p\space\else\addtokens{\filename}{\PP}% - \advance\filenamelength by 1 - \fi - \fi - \nextsp} - \def\getfilename#1{\filenamelength=0\expandafter\skipspaces#1|\relax} - \ifnum\pdftexversion < 14 - \let \startlink \pdfannotlink - \else - \let \startlink \pdfstartlink - \fi - \def\pdfurl#1{% - \begingroup - \normalturnoffactive\def\@{@}% - \leavevmode\Red - \startlink attr{/Border [0 0 0]}% - user{/Subtype /Link /A << /S /URI /URI (#1) >>}% - % #1 - \endgroup} - \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}} - \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks} - \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks} - \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}} - \def\maketoks{% - \expandafter\poptoks\the\toksA|ENDTOKS| - \ifx\first0\adn0 - \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3 - \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6 - \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9 - \else - \ifnum0=\countA\else\makelink\fi - \ifx\first.\let\next=\done\else - \let\next=\maketoks - \addtokens{\toksB}{\the\toksD} - \ifx\first,\addtokens{\toksB}{\space}\fi - \fi - \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi - \next} - \def\makelink{\addtokens{\toksB}% - {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0} - \def\pdflink#1{% - \startlink attr{/Border [0 0 0]} goto name{\mkpgn{#1}} - \linkcolor #1\endlink} - \def\mkpgn#1{#1@} - \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st} -\fi % \ifx\pdfoutput - - -\message{fonts,} -% Font-change commands. - -% Texinfo sort of supports the sans serif font style, which plain TeX does not. -% So we set up a \sf analogous to plain's \rm, etc. -\newfam\sffam -\def\sf{\fam=\sffam \tensf} -\let\li = \sf % Sometimes we call it \li, not \sf. - -% We don't need math for this one. -\def\ttsl{\tenttsl} - -% Use Computer Modern fonts at \magstephalf (11pt). -\newcount\mainmagstep -\mainmagstep=\magstephalf - -% Set the font macro #1 to the font named #2, adding on the -% specified font prefix (normally `cm'). -% #3 is the font's design size, #4 is a scale factor -\def\setfont#1#2#3#4{\font#1=\fontprefix#2#3 scaled #4} - -% Use cm as the default font prefix. -% To specify the font prefix, you must define \fontprefix -% before you read in texinfo.tex. -\ifx\fontprefix\undefined -\def\fontprefix{cm} -\fi -% Support font families that don't use the same naming scheme as CM. -\def\rmshape{r} -\def\rmbshape{bx} %where the normal face is bold -\def\bfshape{b} -\def\bxshape{bx} -\def\ttshape{tt} -\def\ttbshape{tt} -\def\ttslshape{sltt} -\def\itshape{ti} -\def\itbshape{bxti} -\def\slshape{sl} -\def\slbshape{bxsl} -\def\sfshape{ss} -\def\sfbshape{ss} -\def\scshape{csc} -\def\scbshape{csc} - -\ifx\bigger\relax -\let\mainmagstep=\magstep1 -\setfont\textrm\rmshape{12}{1000} -\setfont\texttt\ttshape{12}{1000} -\else -\setfont\textrm\rmshape{10}{\mainmagstep} -\setfont\texttt\ttshape{10}{\mainmagstep} -\fi -% Instead of cmb10, you many want to use cmbx10. -% cmbx10 is a prettier font on its own, but cmb10 -% looks better when embedded in a line with cmr10. -\setfont\textbf\bfshape{10}{\mainmagstep} -\setfont\textit\itshape{10}{\mainmagstep} -\setfont\textsl\slshape{10}{\mainmagstep} -\setfont\textsf\sfshape{10}{\mainmagstep} -\setfont\textsc\scshape{10}{\mainmagstep} -\setfont\textttsl\ttslshape{10}{\mainmagstep} -\font\texti=cmmi10 scaled \mainmagstep -\font\textsy=cmsy10 scaled \mainmagstep - -% A few fonts for @defun, etc. -\setfont\defbf\bxshape{10}{\magstep1} %was 1314 -\setfont\deftt\ttshape{10}{\magstep1} -\def\df{\let\tentt=\deftt \let\tenbf = \defbf \bf} - -% Fonts for indices, footnotes, small examples (9pt). -\setfont\smallrm\rmshape{9}{1000} -\setfont\smalltt\ttshape{9}{1000} -\setfont\smallbf\bfshape{10}{900} -\setfont\smallit\itshape{9}{1000} -\setfont\smallsl\slshape{9}{1000} -\setfont\smallsf\sfshape{9}{1000} -\setfont\smallsc\scshape{10}{900} -\setfont\smallttsl\ttslshape{10}{900} -\font\smalli=cmmi9 -\font\smallsy=cmsy9 - -% Fonts for title page: -\setfont\titlerm\rmbshape{12}{\magstep3} -\setfont\titleit\itbshape{10}{\magstep4} -\setfont\titlesl\slbshape{10}{\magstep4} -\setfont\titlett\ttbshape{12}{\magstep3} -\setfont\titlettsl\ttslshape{10}{\magstep4} -\setfont\titlesf\sfbshape{17}{\magstep1} -\let\titlebf=\titlerm -\setfont\titlesc\scbshape{10}{\magstep4} -\font\titlei=cmmi12 scaled \magstep3 -\font\titlesy=cmsy10 scaled \magstep4 -\def\authorrm{\secrm} - -% Chapter (and unnumbered) fonts (17.28pt). -\setfont\chaprm\rmbshape{12}{\magstep2} -\setfont\chapit\itbshape{10}{\magstep3} -\setfont\chapsl\slbshape{10}{\magstep3} -\setfont\chaptt\ttbshape{12}{\magstep2} -\setfont\chapttsl\ttslshape{10}{\magstep3} -\setfont\chapsf\sfbshape{17}{1000} -\let\chapbf=\chaprm -\setfont\chapsc\scbshape{10}{\magstep3} -\font\chapi=cmmi12 scaled \magstep2 -\font\chapsy=cmsy10 scaled \magstep3 - -% Section fonts (14.4pt). -\setfont\secrm\rmbshape{12}{\magstep1} -\setfont\secit\itbshape{10}{\magstep2} -\setfont\secsl\slbshape{10}{\magstep2} -\setfont\sectt\ttbshape{12}{\magstep1} -\setfont\secttsl\ttslshape{10}{\magstep2} -\setfont\secsf\sfbshape{12}{\magstep1} -\let\secbf\secrm -\setfont\secsc\scbshape{10}{\magstep2} -\font\seci=cmmi12 scaled \magstep1 -\font\secsy=cmsy10 scaled \magstep2 - -% \setfont\ssecrm\bxshape{10}{\magstep1} % This size an font looked bad. -% \setfont\ssecit\itshape{10}{\magstep1} % The letters were too crowded. -% \setfont\ssecsl\slshape{10}{\magstep1} -% \setfont\ssectt\ttshape{10}{\magstep1} -% \setfont\ssecsf\sfshape{10}{\magstep1} - -%\setfont\ssecrm\bfshape{10}{1315} % Note the use of cmb rather than cmbx. -%\setfont\ssecit\itshape{10}{1315} % Also, the size is a little larger than -%\setfont\ssecsl\slshape{10}{1315} % being scaled magstep1. -%\setfont\ssectt\ttshape{10}{1315} -%\setfont\ssecsf\sfshape{10}{1315} - -%\let\ssecbf=\ssecrm - -% Subsection fonts (13.15pt). -\setfont\ssecrm\rmbshape{12}{\magstephalf} -\setfont\ssecit\itbshape{10}{1315} -\setfont\ssecsl\slbshape{10}{1315} -\setfont\ssectt\ttbshape{12}{\magstephalf} -\setfont\ssecttsl\ttslshape{10}{1315} -\setfont\ssecsf\sfbshape{12}{\magstephalf} -\let\ssecbf\ssecrm -\setfont\ssecsc\scbshape{10}{\magstep1} -\font\sseci=cmmi12 scaled \magstephalf -\font\ssecsy=cmsy10 scaled 1315 -% The smallcaps and symbol fonts should actually be scaled \magstep1.5, -% but that is not a standard magnification. - -% In order for the font changes to affect most math symbols and letters, -% we have to define the \textfont of the standard families. Since -% texinfo doesn't allow for producing subscripts and superscripts, we -% don't bother to reset \scriptfont and \scriptscriptfont (which would -% also require loading a lot more fonts). -% -\def\resetmathfonts{% - \textfont0 = \tenrm \textfont1 = \teni \textfont2 = \tensy - \textfont\itfam = \tenit \textfont\slfam = \tensl \textfont\bffam = \tenbf - \textfont\ttfam = \tentt \textfont\sffam = \tensf -} - - -% The font-changing commands redefine the meanings of \tenSTYLE, instead -% of just \STYLE. We do this so that font changes will continue to work -% in math mode, where it is the current \fam that is relevant in most -% cases, not the current font. Plain TeX does \def\bf{\fam=\bffam -% \tenbf}, for example. By redefining \tenbf, we obviate the need to -% redefine \bf itself. -\def\textfonts{% - \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl - \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc - \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy \let\tenttsl=\textttsl - \resetmathfonts} -\def\titlefonts{% - \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl - \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc - \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy - \let\tenttsl=\titlettsl - \resetmathfonts \setleading{25pt}} -\def\titlefont#1{{\titlefonts\rm #1}} -\def\chapfonts{% - \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl - \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc - \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy \let\tenttsl=\chapttsl - \resetmathfonts \setleading{19pt}} -\def\secfonts{% - \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl - \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc - \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy \let\tenttsl=\secttsl - \resetmathfonts \setleading{16pt}} -\def\subsecfonts{% - \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl - \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc - \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy \let\tenttsl=\ssecttsl - \resetmathfonts \setleading{15pt}} -\let\subsubsecfonts = \subsecfonts % Maybe make sssec fonts scaled magstephalf? -\def\smallfonts{% - \let\tenrm=\smallrm \let\tenit=\smallit \let\tensl=\smallsl - \let\tenbf=\smallbf \let\tentt=\smalltt \let\smallcaps=\smallsc - \let\tensf=\smallsf \let\teni=\smalli \let\tensy=\smallsy - \let\tenttsl=\smallttsl - \resetmathfonts \setleading{11pt}} - -% Set up the default fonts, so we can use them for creating boxes. -% -\textfonts - -% Define these so they can be easily changed for other fonts. -\def\angleleft{$\langle$} -\def\angleright{$\rangle$} - -% Count depth in font-changes, for error checks -\newcount\fontdepth \fontdepth=0 - -% Fonts for short table of contents. -\setfont\shortcontrm\rmshape{12}{1000} -\setfont\shortcontbf\bxshape{12}{1000} -\setfont\shortcontsl\slshape{12}{1000} - -%% Add scribe-like font environments, plus @l for inline lisp (usually sans -%% serif) and @ii for TeX italic - -% \smartitalic{ARG} outputs arg in italics, followed by an italic correction -% unless the following character is such as not to need one. -\def\smartitalicx{\ifx\next,\else\ifx\next-\else\ifx\next.\else\/\fi\fi\fi} -\def\smartslanted#1{{\sl #1}\futurelet\next\smartitalicx} -\def\smartitalic#1{{\it #1}\futurelet\next\smartitalicx} - -\let\i=\smartitalic -\let\var=\smartslanted -\let\dfn=\smartslanted -\let\emph=\smartitalic -\let\cite=\smartslanted - -\def\b#1{{\bf #1}} -\let\strong=\b - -% We can't just use \exhyphenpenalty, because that only has effect at -% the end of a paragraph. Restore normal hyphenation at the end of the -% group within which \nohyphenation is presumably called. -% -\def\nohyphenation{\hyphenchar\font = -1 \aftergroup\restorehyphenation} -\def\restorehyphenation{\hyphenchar\font = `- } - -\def\t#1{% - {\tt \rawbackslash \frenchspacing #1}% - \null -} -\let\ttfont=\t -\def\samp#1{`\tclose{#1}'\null} -\setfont\keyrm\rmshape{8}{1000} -\font\keysy=cmsy9 -\def\key#1{{\keyrm\textfont2=\keysy \leavevmode\hbox{% - \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{% - \vbox{\hrule\kern-0.4pt - \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}% - \kern-0.4pt\hrule}% - \kern-.06em\raise0.4pt\hbox{\angleright}}}} -% The old definition, with no lozenge: -%\def\key #1{{\ttsl \nohyphenation \uppercase{#1}}\null} -\def\ctrl #1{{\tt \rawbackslash \hat}#1} - -% @file, @option are the same as @samp. -\let\file=\samp -\let\option=\samp - -% @code is a modification of @t, -% which makes spaces the same size as normal in the surrounding text. -\def\tclose#1{% - {% - % Change normal interword space to be same as for the current font. - \spaceskip = \fontdimen2\font - % - % Switch to typewriter. - \tt - % - % But `\ ' produces the large typewriter interword space. - \def\ {{\spaceskip = 0pt{} }}% - % - % Turn off hyphenation. - \nohyphenation - % - \rawbackslash - \frenchspacing - #1% - }% - \null -} - -% We *must* turn on hyphenation at `-' and `_' in \code. -% Otherwise, it is too hard to avoid overfull hboxes -% in the Emacs manual, the Library manual, etc. - -% Unfortunately, TeX uses one parameter (\hyphenchar) to control -% both hyphenation at - and hyphenation within words. -% We must therefore turn them both off (\tclose does that) -% and arrange explicitly to hyphenate at a dash. -% -- rms. -{ - \catcode`\-=\active - \catcode`\_=\active - % - \global\def\code{\begingroup - \catcode`\-=\active \let-\codedash - \catcode`\_=\active \let_\codeunder - \codex - } - % - % If we end up with any active - characters when handling the index, - % just treat them as a normal -. - \global\def\indexbreaks{\catcode`\-=\active \let-\realdash} -} - -\def\realdash{-} -\def\codedash{-\discretionary{}{}{}} -\def\codeunder{\ifusingtt{\normalunderscore\discretionary{}{}{}}{\_}} -\def\codex #1{\tclose{#1}\endgroup} - -%\let\exp=\tclose %Was temporary - -% @kbd is like @code, except that if the argument is just one @key command, -% then @kbd has no effect. - -% @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always), -% `example' (@kbd uses ttsl only inside of @example and friends), -% or `code' (@kbd uses normal tty font always). -\def\kbdinputstyle{\parsearg\kbdinputstylexxx} -\def\kbdinputstylexxx#1{% - \def\arg{#1}% - \ifx\arg\worddistinct - \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}% - \else\ifx\arg\wordexample - \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}% - \else\ifx\arg\wordcode - \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}% - \fi\fi\fi -} -\def\worddistinct{distinct} -\def\wordexample{example} -\def\wordcode{code} - -% Default is kbdinputdistinct. (Too much of a hassle to call the macro, -% the catcodes are wrong for parsearg to work.) -\gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl} - -\def\xkey{\key} -\def\kbdfoo#1#2#3\par{\def\one{#1}\def\three{#3}\def\threex{??}% -\ifx\one\xkey\ifx\threex\three \key{#2}% -\else{\tclose{\kbdfont\look}}\fi -\else{\tclose{\kbdfont\look}}\fi} - -% For @url, @env, @command quotes seem unnecessary, so use \code. -\let\url=\code -\let\env=\code -\let\command=\code - -% @uref (abbreviation for `urlref') takes an optional (comma-separated) -% second argument specifying the text to display and an optional third -% arg as text to display instead of (rather than in addition to) the url -% itself. First (mandatory) arg is the url. Perhaps eventually put in -% a hypertex \special here. -% -\def\uref#1{\douref #1,,,\finish} -\def\douref#1,#2,#3,#4\finish{\begingroup - \unsepspaces - \pdfurl{#1}% - \setbox0 = \hbox{\ignorespaces #3}% - \ifdim\wd0 > 0pt - \unhbox0 % third arg given, show only that - \else - \setbox0 = \hbox{\ignorespaces #2}% - \ifdim\wd0 > 0pt - \ifpdf - \unhbox0 % PDF: 2nd arg given, show only it - \else - \unhbox0\ (\code{#1})% DVI: 2nd arg given, show both it and url - \fi - \else - \code{#1}% only url given, so show it - \fi - \fi - \endlink -\endgroup} - -% rms does not like angle brackets --karl, 17may97. -% So now @email is just like @uref, unless we are pdf. -% -%\def\email#1{\angleleft{\tt #1}\angleright} -\ifpdf - \def\email#1{\doemail#1,,\finish} - \def\doemail#1,#2,#3\finish{\begingroup - \unsepspaces - \pdfurl{mailto:#1}% - \setbox0 = \hbox{\ignorespaces #2}% - \ifdim\wd0>0pt\unhbox0\else\code{#1}\fi - \endlink - \endgroup} -\else - \let\email=\uref -\fi - -% Check if we are currently using a typewriter font. Since all the -% Computer Modern typewriter fonts have zero interword stretch (and -% shrink), and it is reasonable to expect all typewriter fonts to have -% this property, we can check that font parameter. -% -\def\ifmonospace{\ifdim\fontdimen3\font=0pt } - -% Typeset a dimension, e.g., `in' or `pt'. The only reason for the -% argument is to make the input look right: @dmn{pt} instead of @dmn{}pt. -% -\def\dmn#1{\thinspace #1} - -\def\kbd#1{\def\look{#1}\expandafter\kbdfoo\look??\par} - -% @l was never documented to mean ``switch to the Lisp font'', -% and it is not used as such in any manual I can find. We need it for -% Polish suppressed-l. --karl, 22sep96. -%\def\l#1{{\li #1}\null} - -% Explicit font changes: @r, @sc, undocumented @ii. -\def\r#1{{\rm #1}} % roman font -\def\sc#1{{\smallcaps#1}} % smallcaps font -\def\ii#1{{\it #1}} % italic font - -% @acronym downcases the argument and prints in smallcaps. -\def\acronym#1{{\smallcaps \lowercase{#1}}} - -% @pounds{} is a sterling sign. -\def\pounds{{\it\$}} - - -\message{page headings,} - -\newskip\titlepagetopglue \titlepagetopglue = 1.5in -\newskip\titlepagebottomglue \titlepagebottomglue = 2pc - -% First the title page. Must do @settitle before @titlepage. -\newif\ifseenauthor -\newif\iffinishedtitlepage - -% Do an implicit @contents or @shortcontents after @end titlepage if the -% user says @setcontentsaftertitlepage or @setshortcontentsaftertitlepage. -% -\newif\ifsetcontentsaftertitlepage - \let\setcontentsaftertitlepage = \setcontentsaftertitlepagetrue -\newif\ifsetshortcontentsaftertitlepage - \let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue - -\def\shorttitlepage{\parsearg\shorttitlepagezzz} -\def\shorttitlepagezzz #1{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}% - \endgroup\page\hbox{}\page} - -\def\titlepage{\begingroup \parindent=0pt \textfonts - \let\subtitlerm=\tenrm - \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}% - % - \def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines}% - % - % Leave some space at the very top of the page. - \vglue\titlepagetopglue - % - % Now you can print the title using @title. - \def\title{\parsearg\titlezzz}% - \def\titlezzz##1{\leftline{\titlefonts\rm ##1} - % print a rule at the page bottom also. - \finishedtitlepagefalse - \vskip4pt \hrule height 4pt width \hsize \vskip4pt}% - % No rule at page bottom unless we print one at the top with @title. - \finishedtitlepagetrue - % - % Now you can put text using @subtitle. - \def\subtitle{\parsearg\subtitlezzz}% - \def\subtitlezzz##1{{\subtitlefont \rightline{##1}}}% - % - % @author should come last, but may come many times. - \def\author{\parsearg\authorzzz}% - \def\authorzzz##1{\ifseenauthor\else\vskip 0pt plus 1filll\seenauthortrue\fi - {\authorfont \leftline{##1}}}% - % - % Most title ``pages'' are actually two pages long, with space - % at the top of the second. We don't want the ragged left on the second. - \let\oldpage = \page - \def\page{% - \iffinishedtitlepage\else - \finishtitlepage - \fi - \oldpage - \let\page = \oldpage - \hbox{}}% -% \def\page{\oldpage \hbox{}} -} - -\def\Etitlepage{% - \iffinishedtitlepage\else - \finishtitlepage - \fi - % It is important to do the page break before ending the group, - % because the headline and footline are only empty inside the group. - % If we use the new definition of \page, we always get a blank page - % after the title page, which we certainly don't want. - \oldpage - \endgroup - % - % If they want short, they certainly want long too. - \ifsetshortcontentsaftertitlepage - \shortcontents - \contents - \global\let\shortcontents = \relax - \global\let\contents = \relax - \fi - % - \ifsetcontentsaftertitlepage - \contents - \global\let\contents = \relax - \global\let\shortcontents = \relax - \fi - % - \ifpdf \pdfmakepagedesttrue \fi - % - \HEADINGSon -} - -\def\finishtitlepage{% - \vskip4pt \hrule height 2pt width \hsize - \vskip\titlepagebottomglue - \finishedtitlepagetrue -} - -%%% Set up page headings and footings. - -\let\thispage=\folio - -\newtoks\evenheadline % headline on even pages -\newtoks\oddheadline % headline on odd pages -\newtoks\evenfootline % footline on even pages -\newtoks\oddfootline % footline on odd pages - -% Now make Tex use those variables -\headline={{\textfonts\rm \ifodd\pageno \the\oddheadline - \else \the\evenheadline \fi}} -\footline={{\textfonts\rm \ifodd\pageno \the\oddfootline - \else \the\evenfootline \fi}\HEADINGShook} -\let\HEADINGShook=\relax - -% Commands to set those variables. -% For example, this is what @headings on does -% @evenheading @thistitle|@thispage|@thischapter -% @oddheading @thischapter|@thispage|@thistitle -% @evenfooting @thisfile|| -% @oddfooting ||@thisfile - -\def\evenheading{\parsearg\evenheadingxxx} -\def\oddheading{\parsearg\oddheadingxxx} -\def\everyheading{\parsearg\everyheadingxxx} - -\def\evenfooting{\parsearg\evenfootingxxx} -\def\oddfooting{\parsearg\oddfootingxxx} -\def\everyfooting{\parsearg\everyfootingxxx} - -{\catcode`\@=0 % - -\gdef\evenheadingxxx #1{\evenheadingyyy #1@|@|@|@|\finish} -\gdef\evenheadingyyy #1@|#2@|#3@|#4\finish{% -\global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}} - -\gdef\oddheadingxxx #1{\oddheadingyyy #1@|@|@|@|\finish} -\gdef\oddheadingyyy #1@|#2@|#3@|#4\finish{% -\global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}} - -\gdef\everyheadingxxx#1{\oddheadingxxx{#1}\evenheadingxxx{#1}}% - -\gdef\evenfootingxxx #1{\evenfootingyyy #1@|@|@|@|\finish} -\gdef\evenfootingyyy #1@|#2@|#3@|#4\finish{% -\global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}} - -\gdef\oddfootingxxx #1{\oddfootingyyy #1@|@|@|@|\finish} -\gdef\oddfootingyyy #1@|#2@|#3@|#4\finish{% - \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}% - % - % Leave some space for the footline. Hopefully ok to assume - % @evenfooting will not be used by itself. - \global\advance\pageheight by -\baselineskip - \global\advance\vsize by -\baselineskip -} - -\gdef\everyfootingxxx#1{\oddfootingxxx{#1}\evenfootingxxx{#1}} -% -}% unbind the catcode of @. - -% @headings double turns headings on for double-sided printing. -% @headings single turns headings on for single-sided printing. -% @headings off turns them off. -% @headings on same as @headings double, retained for compatibility. -% @headings after turns on double-sided headings after this page. -% @headings doubleafter turns on double-sided headings after this page. -% @headings singleafter turns on single-sided headings after this page. -% By default, they are off at the start of a document, -% and turned `on' after @end titlepage. - -\def\headings #1 {\csname HEADINGS#1\endcsname} - -\def\HEADINGSoff{ -\global\evenheadline={\hfil} \global\evenfootline={\hfil} -\global\oddheadline={\hfil} \global\oddfootline={\hfil}} -\HEADINGSoff -% When we turn headings on, set the page number to 1. -% For double-sided printing, put current file name in lower left corner, -% chapter name on inside top of right hand pages, document -% title on inside top of left hand pages, and page numbers on outside top -% edge of all pages. -\def\HEADINGSdouble{ -\global\pageno=1 -\global\evenfootline={\hfil} -\global\oddfootline={\hfil} -\global\evenheadline={\line{\folio\hfil\thistitle}} -\global\oddheadline={\line{\thischapter\hfil\folio}} -\global\let\contentsalignmacro = \chapoddpage -} -\let\contentsalignmacro = \chappager - -% For single-sided printing, chapter title goes across top left of page, -% page number on top right. -\def\HEADINGSsingle{ -\global\pageno=1 -\global\evenfootline={\hfil} -\global\oddfootline={\hfil} -\global\evenheadline={\line{\thischapter\hfil\folio}} -\global\oddheadline={\line{\thischapter\hfil\folio}} -\global\let\contentsalignmacro = \chappager -} -\def\HEADINGSon{\HEADINGSdouble} - -\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex} -\let\HEADINGSdoubleafter=\HEADINGSafter -\def\HEADINGSdoublex{% -\global\evenfootline={\hfil} -\global\oddfootline={\hfil} -\global\evenheadline={\line{\folio\hfil\thistitle}} -\global\oddheadline={\line{\thischapter\hfil\folio}} -\global\let\contentsalignmacro = \chapoddpage -} - -\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex} -\def\HEADINGSsinglex{% -\global\evenfootline={\hfil} -\global\oddfootline={\hfil} -\global\evenheadline={\line{\thischapter\hfil\folio}} -\global\oddheadline={\line{\thischapter\hfil\folio}} -\global\let\contentsalignmacro = \chappager -} - -% Subroutines used in generating headings -% This produces Day Month Year style of output. -% Only define if not already defined, in case a txi-??.tex file has set -% up a different format (e.g., txi-cs.tex does this). -\ifx\today\undefined -\def\today{% - \number\day\space - \ifcase\month - \or\putwordMJan\or\putwordMFeb\or\putwordMMar\or\putwordMApr - \or\putwordMMay\or\putwordMJun\or\putwordMJul\or\putwordMAug - \or\putwordMSep\or\putwordMOct\or\putwordMNov\or\putwordMDec - \fi - \space\number\year} -\fi - -% @settitle line... specifies the title of the document, for headings. -% It generates no output of its own. -\def\thistitle{\putwordNoTitle} -\def\settitle{\parsearg\settitlezzz} -\def\settitlezzz #1{\gdef\thistitle{#1}} - - -\message{tables,} -% Tables -- @table, @ftable, @vtable, @item(x), @kitem(x), @xitem(x). - -% default indentation of table text -\newdimen\tableindent \tableindent=.8in -% default indentation of @itemize and @enumerate text -\newdimen\itemindent \itemindent=.3in -% margin between end of table item and start of table text. -\newdimen\itemmargin \itemmargin=.1in - -% used internally for \itemindent minus \itemmargin -\newdimen\itemmax - -% Note @table, @vtable, and @vtable define @item, @itemx, etc., with -% these defs. -% They also define \itemindex -% to index the item name in whatever manner is desired (perhaps none). - -\newif\ifitemxneedsnegativevskip - -\def\itemxpar{\par\ifitemxneedsnegativevskip\nobreak\vskip-\parskip\nobreak\fi} - -\def\internalBitem{\smallbreak \parsearg\itemzzz} -\def\internalBitemx{\itemxpar \parsearg\itemzzz} - -\def\internalBxitem "#1"{\def\xitemsubtopix{#1} \smallbreak \parsearg\xitemzzz} -\def\internalBxitemx "#1"{\def\xitemsubtopix{#1} \itemxpar \parsearg\xitemzzz} - -\def\internalBkitem{\smallbreak \parsearg\kitemzzz} -\def\internalBkitemx{\itemxpar \parsearg\kitemzzz} - -\def\kitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \lastfunction}}% - \itemzzz {#1}} - -\def\xitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \xitemsubtopic}}% - \itemzzz {#1}} - -\def\itemzzz #1{\begingroup % - \advance\hsize by -\rightskip - \advance\hsize by -\tableindent - \setbox0=\hbox{\itemfont{#1}}% - \itemindex{#1}% - \nobreak % This prevents a break before @itemx. - % - % If the item text does not fit in the space we have, put it on a line - % by itself, and do not allow a page break either before or after that - % line. We do not start a paragraph here because then if the next - % command is, e.g., @kindex, the whatsit would get put into the - % horizontal list on a line by itself, resulting in extra blank space. - \ifdim \wd0>\itemmax - % - % Make this a paragraph so we get the \parskip glue and wrapping, - % but leave it ragged-right. - \begingroup - \advance\leftskip by-\tableindent - \advance\hsize by\tableindent - \advance\rightskip by0pt plus1fil - \leavevmode\unhbox0\par - \endgroup - % - % We're going to be starting a paragraph, but we don't want the - % \parskip glue -- logically it's part of the @item we just started. - \nobreak \vskip-\parskip - % - % Stop a page break at the \parskip glue coming up. Unfortunately - % we can't prevent a possible page break at the following - % \baselineskip glue. - \nobreak - \endgroup - \itemxneedsnegativevskipfalse - \else - % The item text fits into the space. Start a paragraph, so that the - % following text (if any) will end up on the same line. - \noindent - % Do this with kerns and \unhbox so that if there is a footnote in - % the item text, it can migrate to the main vertical list and - % eventually be printed. - \nobreak\kern-\tableindent - \dimen0 = \itemmax \advance\dimen0 by \itemmargin \advance\dimen0 by -\wd0 - \unhbox0 - \nobreak\kern\dimen0 - \endgroup - \itemxneedsnegativevskiptrue - \fi -} - -\def\item{\errmessage{@item while not in a table}} -\def\itemx{\errmessage{@itemx while not in a table}} -\def\kitem{\errmessage{@kitem while not in a table}} -\def\kitemx{\errmessage{@kitemx while not in a table}} -\def\xitem{\errmessage{@xitem while not in a table}} -\def\xitemx{\errmessage{@xitemx while not in a table}} - -% Contains a kludge to get @end[description] to work. -\def\description{\tablez{\dontindex}{1}{}{}{}{}} - -% @table, @ftable, @vtable. -\def\table{\begingroup\inENV\obeylines\obeyspaces\tablex} -{\obeylines\obeyspaces% -\gdef\tablex #1^^M{% -\tabley\dontindex#1 \endtabley}} - -\def\ftable{\begingroup\inENV\obeylines\obeyspaces\ftablex} -{\obeylines\obeyspaces% -\gdef\ftablex #1^^M{% -\tabley\fnitemindex#1 \endtabley -\def\Eftable{\endgraf\afterenvbreak\endgroup}% -\let\Etable=\relax}} - -\def\vtable{\begingroup\inENV\obeylines\obeyspaces\vtablex} -{\obeylines\obeyspaces% -\gdef\vtablex #1^^M{% -\tabley\vritemindex#1 \endtabley -\def\Evtable{\endgraf\afterenvbreak\endgroup}% -\let\Etable=\relax}} - -\def\dontindex #1{} -\def\fnitemindex #1{\doind {fn}{\code{#1}}}% -\def\vritemindex #1{\doind {vr}{\code{#1}}}% - -{\obeyspaces % -\gdef\tabley#1#2 #3 #4 #5 #6 #7\endtabley{\endgroup% -\tablez{#1}{#2}{#3}{#4}{#5}{#6}}} - -\def\tablez #1#2#3#4#5#6{% -\aboveenvbreak % -\begingroup % -\def\Edescription{\Etable}% Necessary kludge. -\let\itemindex=#1% -\ifnum 0#3>0 \advance \leftskip by #3\mil \fi % -\ifnum 0#4>0 \tableindent=#4\mil \fi % -\ifnum 0#5>0 \advance \rightskip by #5\mil \fi % -\def\itemfont{#2}% -\itemmax=\tableindent % -\advance \itemmax by -\itemmargin % -\advance \leftskip by \tableindent % -\exdentamount=\tableindent -\parindent = 0pt -\parskip = \smallskipamount -\ifdim \parskip=0pt \parskip=2pt \fi% -\def\Etable{\endgraf\afterenvbreak\endgroup}% -\let\item = \internalBitem % -\let\itemx = \internalBitemx % -\let\kitem = \internalBkitem % -\let\kitemx = \internalBkitemx % -\let\xitem = \internalBxitem % -\let\xitemx = \internalBxitemx % -} - -% This is the counter used by @enumerate, which is really @itemize - -\newcount \itemno - -\def\itemize{\parsearg\itemizezzz} - -\def\itemizezzz #1{% - \begingroup % ended by the @end itemize - \itemizey {#1}{\Eitemize} -} - -\def\itemizey #1#2{% -\aboveenvbreak % -\itemmax=\itemindent % -\advance \itemmax by -\itemmargin % -\advance \leftskip by \itemindent % -\exdentamount=\itemindent -\parindent = 0pt % -\parskip = \smallskipamount % -\ifdim \parskip=0pt \parskip=2pt \fi% -\def#2{\endgraf\afterenvbreak\endgroup}% -\def\itemcontents{#1}% -\let\item=\itemizeitem} - -% Set sfcode to normal for the chars that usually have another value. -% These are `.?!:;,' -\def\frenchspacing{\sfcode46=1000 \sfcode63=1000 \sfcode33=1000 - \sfcode58=1000 \sfcode59=1000 \sfcode44=1000 } - -% \splitoff TOKENS\endmark defines \first to be the first token in -% TOKENS, and \rest to be the remainder. -% -\def\splitoff#1#2\endmark{\def\first{#1}\def\rest{#2}}% - -% Allow an optional argument of an uppercase letter, lowercase letter, -% or number, to specify the first label in the enumerated list. No -% argument is the same as `1'. -% -\def\enumerate{\parsearg\enumeratezzz} -\def\enumeratezzz #1{\enumeratey #1 \endenumeratey} -\def\enumeratey #1 #2\endenumeratey{% - \begingroup % ended by the @end enumerate - % - % If we were given no argument, pretend we were given `1'. - \def\thearg{#1}% - \ifx\thearg\empty \def\thearg{1}\fi - % - % Detect if the argument is a single token. If so, it might be a - % letter. Otherwise, the only valid thing it can be is a number. - % (We will always have one token, because of the test we just made. - % This is a good thing, since \splitoff doesn't work given nothing at - % all -- the first parameter is undelimited.) - \expandafter\splitoff\thearg\endmark - \ifx\rest\empty - % Only one token in the argument. It could still be anything. - % A ``lowercase letter'' is one whose \lccode is nonzero. - % An ``uppercase letter'' is one whose \lccode is both nonzero, and - % not equal to itself. - % Otherwise, we assume it's a number. - % - % We need the \relax at the end of the \ifnum lines to stop TeX from - % continuing to look for a . - % - \ifnum\lccode\expandafter`\thearg=0\relax - \numericenumerate % a number (we hope) - \else - % It's a letter. - \ifnum\lccode\expandafter`\thearg=\expandafter`\thearg\relax - \lowercaseenumerate % lowercase letter - \else - \uppercaseenumerate % uppercase letter - \fi - \fi - \else - % Multiple tokens in the argument. We hope it's a number. - \numericenumerate - \fi -} - -% An @enumerate whose labels are integers. The starting integer is -% given in \thearg. -% -\def\numericenumerate{% - \itemno = \thearg - \startenumeration{\the\itemno}% -} - -% The starting (lowercase) letter is in \thearg. -\def\lowercaseenumerate{% - \itemno = \expandafter`\thearg - \startenumeration{% - % Be sure we're not beyond the end of the alphabet. - \ifnum\itemno=0 - \errmessage{No more lowercase letters in @enumerate; get a bigger - alphabet}% - \fi - \char\lccode\itemno - }% -} - -% The starting (uppercase) letter is in \thearg. -\def\uppercaseenumerate{% - \itemno = \expandafter`\thearg - \startenumeration{% - % Be sure we're not beyond the end of the alphabet. - \ifnum\itemno=0 - \errmessage{No more uppercase letters in @enumerate; get a bigger - alphabet} - \fi - \char\uccode\itemno - }% -} - -% Call itemizey, adding a period to the first argument and supplying the -% common last two arguments. Also subtract one from the initial value in -% \itemno, since @item increments \itemno. -% -\def\startenumeration#1{% - \advance\itemno by -1 - \itemizey{#1.}\Eenumerate\flushcr -} - -% @alphaenumerate and @capsenumerate are abbreviations for giving an arg -% to @enumerate. -% -\def\alphaenumerate{\enumerate{a}} -\def\capsenumerate{\enumerate{A}} -\def\Ealphaenumerate{\Eenumerate} -\def\Ecapsenumerate{\Eenumerate} - -% Definition of @item while inside @itemize. - -\def\itemizeitem{% -\advance\itemno by 1 -{\let\par=\endgraf \smallbreak}% -\ifhmode \errmessage{In hmode at itemizeitem}\fi -{\parskip=0in \hskip 0pt -\hbox to 0pt{\hss \itemcontents\hskip \itemmargin}% -\vadjust{\penalty 1200}}% -\flushcr} - -% @multitable macros -% Amy Hendrickson, 8/18/94, 3/6/96 -% -% @multitable ... @end multitable will make as many columns as desired. -% Contents of each column will wrap at width given in preamble. Width -% can be specified either with sample text given in a template line, -% or in percent of \hsize, the current width of text on page. - -% Table can continue over pages but will only break between lines. - -% To make preamble: -% -% Either define widths of columns in terms of percent of \hsize: -% @multitable @columnfractions .25 .3 .45 -% @item ... -% -% Numbers following @columnfractions are the percent of the total -% current hsize to be used for each column. You may use as many -% columns as desired. - - -% Or use a template: -% @multitable {Column 1 template} {Column 2 template} {Column 3 template} -% @item ... -% using the widest term desired in each column. -% -% For those who want to use more than one line's worth of words in -% the preamble, break the line within one argument and it -% will parse correctly, i.e., -% -% @multitable {Column 1 template} {Column 2 template} {Column 3 -% template} -% Not: -% @multitable {Column 1 template} {Column 2 template} -% {Column 3 template} - -% Each new table line starts with @item, each subsequent new column -% starts with @tab. Empty columns may be produced by supplying @tab's -% with nothing between them for as many times as empty columns are needed, -% ie, @tab@tab@tab will produce two empty columns. - -% @item, @tab, @multitable or @end multitable do not need to be on their -% own lines, but it will not hurt if they are. - -% Sample multitable: - -% @multitable {Column 1 template} {Column 2 template} {Column 3 template} -% @item first col stuff @tab second col stuff @tab third col -% @item -% first col stuff -% @tab -% second col stuff -% @tab -% third col -% @item first col stuff @tab second col stuff -% @tab Many paragraphs of text may be used in any column. -% -% They will wrap at the width determined by the template. -% @item@tab@tab This will be in third column. -% @end multitable - -% Default dimensions may be reset by user. -% @multitableparskip is vertical space between paragraphs in table. -% @multitableparindent is paragraph indent in table. -% @multitablecolmargin is horizontal space to be left between columns. -% @multitablelinespace is space to leave between table items, baseline -% to baseline. -% 0pt means it depends on current normal line spacing. -% -\newskip\multitableparskip -\newskip\multitableparindent -\newdimen\multitablecolspace -\newskip\multitablelinespace -\multitableparskip=0pt -\multitableparindent=6pt -\multitablecolspace=12pt -\multitablelinespace=0pt - -% Macros used to set up halign preamble: -% -\let\endsetuptable\relax -\def\xendsetuptable{\endsetuptable} -\let\columnfractions\relax -\def\xcolumnfractions{\columnfractions} -\newif\ifsetpercent - -% #1 is the part of the @columnfraction before the decimal point, which -% is presumably either 0 or the empty string (but we don't check, we -% just throw it away). #2 is the decimal part, which we use as the -% percent of \hsize for this column. -\def\pickupwholefraction#1.#2 {% - \global\advance\colcount by 1 - \expandafter\xdef\csname col\the\colcount\endcsname{.#2\hsize}% - \setuptable -} - -\newcount\colcount -\def\setuptable#1{% - \def\firstarg{#1}% - \ifx\firstarg\xendsetuptable - \let\go = \relax - \else - \ifx\firstarg\xcolumnfractions - \global\setpercenttrue - \else - \ifsetpercent - \let\go\pickupwholefraction - \else - \global\advance\colcount by 1 - \setbox0=\hbox{#1\unskip }% Add a normal word space as a separator; - % typically that is always in the input, anyway. - \expandafter\xdef\csname col\the\colcount\endcsname{\the\wd0}% - \fi - \fi - \ifx\go\pickupwholefraction - % Put the argument back for the \pickupwholefraction call, so - % we'll always have a period there to be parsed. - \def\go{\pickupwholefraction#1}% - \else - \let\go = \setuptable - \fi% - \fi - \go -} - -% This used to have \hskip1sp. But then the space in a template line is -% not enough. That is bad. So let's go back to just & until we -% encounter the problem it was intended to solve again. -% --karl, nathan@acm.org, 20apr99. -\def\tab{&} - -% @multitable ... @end multitable definitions: -% -\def\multitable{\parsearg\dotable} -\def\dotable#1{\bgroup - \vskip\parskip - \let\item\crcr - \tolerance=9500 - \hbadness=9500 - \setmultitablespacing - \parskip=\multitableparskip - \parindent=\multitableparindent - \overfullrule=0pt - \global\colcount=0 - \def\Emultitable{\global\setpercentfalse\cr\egroup\egroup}% - % - % To parse everything between @multitable and @item: - \setuptable#1 \endsetuptable - % - % \everycr will reset column counter, \colcount, at the end of - % each line. Every column entry will cause \colcount to advance by one. - % The table preamble - % looks at the current \colcount to find the correct column width. - \everycr{\noalign{% - % - % \filbreak%% keeps underfull box messages off when table breaks over pages. - % Maybe so, but it also creates really weird page breaks when the table - % breaks over pages. Wouldn't \vfil be better? Wait until the problem - % manifests itself, so it can be fixed for real --karl. - \global\colcount=0\relax}}% - % - % This preamble sets up a generic column definition, which will - % be used as many times as user calls for columns. - % \vtop will set a single line and will also let text wrap and - % continue for many paragraphs if desired. - \halign\bgroup&\global\advance\colcount by 1\relax - \multistrut\vtop{\hsize=\expandafter\csname col\the\colcount\endcsname - % - % In order to keep entries from bumping into each other - % we will add a \leftskip of \multitablecolspace to all columns after - % the first one. - % - % If a template has been used, we will add \multitablecolspace - % to the width of each template entry. - % - % If the user has set preamble in terms of percent of \hsize we will - % use that dimension as the width of the column, and the \leftskip - % will keep entries from bumping into each other. Table will start at - % left margin and final column will justify at right margin. - % - % Make sure we don't inherit \rightskip from the outer environment. - \rightskip=0pt - \ifnum\colcount=1 - % The first column will be indented with the surrounding text. - \advance\hsize by\leftskip - \else - \ifsetpercent \else - % If user has not set preamble in terms of percent of \hsize - % we will advance \hsize by \multitablecolspace. - \advance\hsize by \multitablecolspace - \fi - % In either case we will make \leftskip=\multitablecolspace: - \leftskip=\multitablecolspace - \fi - % Ignoring space at the beginning and end avoids an occasional spurious - % blank line, when TeX decides to break the line at the space before the - % box from the multistrut, so the strut ends up on a line by itself. - % For example: - % @multitable @columnfractions .11 .89 - % @item @code{#} - % @tab Legal holiday which is valid in major parts of the whole country. - % Is automatically provided with highlighting sequences respectively marking - % characters. - \noindent\ignorespaces##\unskip\multistrut}\cr -} - -\def\setmultitablespacing{% test to see if user has set \multitablelinespace. -% If so, do nothing. If not, give it an appropriate dimension based on -% current baselineskip. -\ifdim\multitablelinespace=0pt -\setbox0=\vbox{X}\global\multitablelinespace=\the\baselineskip -\global\advance\multitablelinespace by-\ht0 -%% strut to put in table in case some entry doesn't have descenders, -%% to keep lines equally spaced -\let\multistrut = \strut -\else -%% FIXME: what is \box0 supposed to be? -\gdef\multistrut{\vrule height\multitablelinespace depth\dp0 -width0pt\relax} \fi -%% Test to see if parskip is larger than space between lines of -%% table. If not, do nothing. -%% If so, set to same dimension as multitablelinespace. -\ifdim\multitableparskip>\multitablelinespace -\global\multitableparskip=\multitablelinespace -\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller - %% than skip between lines in the table. -\fi% -\ifdim\multitableparskip=0pt -\global\multitableparskip=\multitablelinespace -\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller - %% than skip between lines in the table. -\fi} - - -\message{conditionals,} -% Prevent errors for section commands. -% Used in @ignore and in failing conditionals. -\def\ignoresections{% - \let\chapter=\relax - \let\unnumbered=\relax - \let\top=\relax - \let\unnumberedsec=\relax - \let\unnumberedsection=\relax - \let\unnumberedsubsec=\relax - \let\unnumberedsubsection=\relax - \let\unnumberedsubsubsec=\relax - \let\unnumberedsubsubsection=\relax - \let\section=\relax - \let\subsec=\relax - \let\subsubsec=\relax - \let\subsection=\relax - \let\subsubsection=\relax - \let\appendix=\relax - \let\appendixsec=\relax - \let\appendixsection=\relax - \let\appendixsubsec=\relax - \let\appendixsubsection=\relax - \let\appendixsubsubsec=\relax - \let\appendixsubsubsection=\relax - \let\contents=\relax - \let\smallbook=\relax - \let\titlepage=\relax -} - -% Used in nested conditionals, where we have to parse the Texinfo source -% and so want to turn off most commands, in case they are used -% incorrectly. -% -\def\ignoremorecommands{% - \let\defcodeindex = \relax - \let\defcv = \relax - \let\deffn = \relax - \let\deffnx = \relax - \let\defindex = \relax - \let\defivar = \relax - \let\defmac = \relax - \let\defmethod = \relax - \let\defop = \relax - \let\defopt = \relax - \let\defspec = \relax - \let\deftp = \relax - \let\deftypefn = \relax - \let\deftypefun = \relax - \let\deftypeivar = \relax - \let\deftypeop = \relax - \let\deftypevar = \relax - \let\deftypevr = \relax - \let\defun = \relax - \let\defvar = \relax - \let\defvr = \relax - \let\ref = \relax - \let\xref = \relax - \let\printindex = \relax - \let\pxref = \relax - \let\settitle = \relax - \let\setchapternewpage = \relax - \let\setchapterstyle = \relax - \let\everyheading = \relax - \let\evenheading = \relax - \let\oddheading = \relax - \let\everyfooting = \relax - \let\evenfooting = \relax - \let\oddfooting = \relax - \let\headings = \relax - \let\include = \relax - \let\lowersections = \relax - \let\down = \relax - \let\raisesections = \relax - \let\up = \relax - \let\set = \relax - \let\clear = \relax - \let\item = \relax -} - -% Ignore @ignore ... @end ignore. -% -\def\ignore{\doignore{ignore}} - -% Ignore @ifinfo, @ifhtml, @ifnottex, @html, @menu, and @direntry text. -% -\def\ifinfo{\doignore{ifinfo}} -\def\ifhtml{\doignore{ifhtml}} -\def\ifnottex{\doignore{ifnottex}} -\def\html{\doignore{html}} -\def\menu{\doignore{menu}} -\def\direntry{\doignore{direntry}} - -% @dircategory CATEGORY -- specify a category of the dir file -% which this file should belong to. Ignore this in TeX. -\let\dircategory = \comment - -% Ignore text until a line `@end #1'. -% -\def\doignore#1{\begingroup - % Don't complain about control sequences we have declared \outer. - \ignoresections - % - % Define a command to swallow text until we reach `@end #1'. - % This @ is a catcode 12 token (that is the normal catcode of @ in - % this texinfo.tex file). We change the catcode of @ below to match. - \long\def\doignoretext##1@end #1{\enddoignore}% - % - % Make sure that spaces turn into tokens that match what \doignoretext wants. - \catcode32 = 10 - % - % Ignore braces, too, so mismatched braces don't cause trouble. - \catcode`\{ = 9 - \catcode`\} = 9 - % - % We must not have @c interpreted as a control sequence. - \catcode`\@ = 12 - % - % Make the letter c a comment character so that the rest of the line - % will be ignored. This way, the document can have (for example) - % @c @end ifinfo - % and the @end ifinfo will be properly ignored. - % (We've just changed @ to catcode 12.) - \catcode`\c = 14 - % - % And now expand that command. - \doignoretext -} - -% What we do to finish off ignored text. -% -\def\enddoignore{\endgroup\ignorespaces}% - -\newif\ifwarnedobs\warnedobsfalse -\def\obstexwarn{% - \ifwarnedobs\relax\else - % We need to warn folks that they may have trouble with TeX 3.0. - % This uses \immediate\write16 rather than \message to get newlines. - \immediate\write16{} - \immediate\write16{WARNING: for users of Unix TeX 3.0!} - \immediate\write16{This manual trips a bug in TeX version 3.0 (tex hangs).} - \immediate\write16{If you are running another version of TeX, relax.} - \immediate\write16{If you are running Unix TeX 3.0, kill this TeX process.} - \immediate\write16{ Then upgrade your TeX installation if you can.} - \immediate\write16{ (See ftp://ftp.gnu.org/pub/gnu/TeX.README.)} - \immediate\write16{If you are stuck with version 3.0, run the} - \immediate\write16{ script ``tex3patch'' from the Texinfo distribution} - \immediate\write16{ to use a workaround.} - \immediate\write16{} - \global\warnedobstrue - \fi -} - -% **In TeX 3.0, setting text in \nullfont hangs tex. For a -% workaround (which requires the file ``dummy.tfm'' to be installed), -% uncomment the following line: -%%%%%\font\nullfont=dummy\let\obstexwarn=\relax - -% Ignore text, except that we keep track of conditional commands for -% purposes of nesting, up to an `@end #1' command. -% -\def\nestedignore#1{% - \obstexwarn - % We must actually expand the ignored text to look for the @end - % command, so that nested ignore constructs work. Thus, we put the - % text into a \vbox and then do nothing with the result. To minimize - % the change of memory overflow, we follow the approach outlined on - % page 401 of the TeXbook: make the current font be a dummy font. - % - \setbox0 = \vbox\bgroup - % Don't complain about control sequences we have declared \outer. - \ignoresections - % - % Define `@end #1' to end the box, which will in turn undefine the - % @end command again. - \expandafter\def\csname E#1\endcsname{\egroup\ignorespaces}% - % - % We are going to be parsing Texinfo commands. Most cause no - % trouble when they are used incorrectly, but some commands do - % complicated argument parsing or otherwise get confused, so we - % undefine them. - % - % We can't do anything about stray @-signs, unfortunately; - % they'll produce `undefined control sequence' errors. - \ignoremorecommands - % - % Set the current font to be \nullfont, a TeX primitive, and define - % all the font commands to also use \nullfont. We don't use - % dummy.tfm, as suggested in the TeXbook, because not all sites - % might have that installed. Therefore, math mode will still - % produce output, but that should be an extremely small amount of - % stuff compared to the main input. - % - \nullfont - \let\tenrm=\nullfont \let\tenit=\nullfont \let\tensl=\nullfont - \let\tenbf=\nullfont \let\tentt=\nullfont \let\smallcaps=\nullfont - \let\tensf=\nullfont - % Similarly for index fonts (mostly for their use in smallexample). - \let\smallrm=\nullfont \let\smallit=\nullfont \let\smallsl=\nullfont - \let\smallbf=\nullfont \let\smalltt=\nullfont \let\smallsc=\nullfont - \let\smallsf=\nullfont - % - % Don't complain when characters are missing from the fonts. - \tracinglostchars = 0 - % - % Don't bother to do space factor calculations. - \frenchspacing - % - % Don't report underfull hboxes. - \hbadness = 10000 - % - % Do minimal line-breaking. - \pretolerance = 10000 - % - % Do not execute instructions in @tex - \def\tex{\doignore{tex}}% - % Do not execute macro definitions. - % `c' is a comment character, so the word `macro' will get cut off. - \def\macro{\doignore{ma}}% -} - -% @set VAR sets the variable VAR to an empty value. -% @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE. -% -% Since we want to separate VAR from REST-OF-LINE (which might be -% empty), we can't just use \parsearg; we have to insert a space of our -% own to delimit the rest of the line, and then take it out again if we -% didn't need it. Make sure the catcode of space is correct to avoid -% losing inside @example, for instance. -% -\def\set{\begingroup\catcode` =10 - \catcode`\-=12 \catcode`\_=12 % Allow - and _ in VAR. - \parsearg\setxxx} -\def\setxxx#1{\setyyy#1 \endsetyyy} -\def\setyyy#1 #2\endsetyyy{% - \def\temp{#2}% - \ifx\temp\empty \global\expandafter\let\csname SET#1\endcsname = \empty - \else \setzzz{#1}#2\endsetzzz % Remove the trailing space \setxxx inserted. - \fi - \endgroup -} -% Can't use \xdef to pre-expand #2 and save some time, since \temp or -% \next or other control sequences that we've defined might get us into -% an infinite loop. Consider `@set foo @cite{bar}'. -\def\setzzz#1#2 \endsetzzz{\expandafter\gdef\csname SET#1\endcsname{#2}} - -% @clear VAR clears (i.e., unsets) the variable VAR. -% -\def\clear{\parsearg\clearxxx} -\def\clearxxx#1{\global\expandafter\let\csname SET#1\endcsname=\relax} - -% @value{foo} gets the text saved in variable foo. -{ - \catcode`\_ = \active - % - % We might end up with active _ or - characters in the argument if - % we're called from @code, as @code{@value{foo-bar_}}. So \let any - % such active characters to their normal equivalents. - \gdef\value{\begingroup - \catcode`\-=12 \catcode`\_=12 - \indexbreaks \let_\normalunderscore - \valuexxx} -} -\def\valuexxx#1{\expandablevalue{#1}\endgroup} - -% We have this subroutine so that we can handle at least some @value's -% properly in indexes (we \let\value to this in \indexdummies). Ones -% whose names contain - or _ still won't work, but we can't do anything -% about that. The command has to be fully expandable, since the result -% winds up in the index file. This means that if the variable's value -% contains other Texinfo commands, it's almost certain it will fail -% (although perhaps we could fix that with sufficient work to do a -% one-level expansion on the result, instead of complete). -% -\def\expandablevalue#1{% - \expandafter\ifx\csname SET#1\endcsname\relax - {[No value for ``#1'']}% - \else - \csname SET#1\endcsname - \fi -} - -% @ifset VAR ... @end ifset reads the `...' iff VAR has been defined -% with @set. -% -\def\ifset{\parsearg\ifsetxxx} -\def\ifsetxxx #1{% - \expandafter\ifx\csname SET#1\endcsname\relax - \expandafter\ifsetfail - \else - \expandafter\ifsetsucceed - \fi -} -\def\ifsetsucceed{\conditionalsucceed{ifset}} -\def\ifsetfail{\nestedignore{ifset}} -\defineunmatchedend{ifset} - -% @ifclear VAR ... @end ifclear reads the `...' iff VAR has never been -% defined with @set, or has been undefined with @clear. -% -\def\ifclear{\parsearg\ifclearxxx} -\def\ifclearxxx #1{% - \expandafter\ifx\csname SET#1\endcsname\relax - \expandafter\ifclearsucceed - \else - \expandafter\ifclearfail - \fi -} -\def\ifclearsucceed{\conditionalsucceed{ifclear}} -\def\ifclearfail{\nestedignore{ifclear}} -\defineunmatchedend{ifclear} - -% @iftex, @ifnothtml, @ifnotinfo always succeed; we read the text -% following, through the first @end iftex (etc.). Make `@end iftex' -% (etc.) valid only after an @iftex. -% -\def\iftex{\conditionalsucceed{iftex}} -\def\ifnothtml{\conditionalsucceed{ifnothtml}} -\def\ifnotinfo{\conditionalsucceed{ifnotinfo}} -\defineunmatchedend{iftex} -\defineunmatchedend{ifnothtml} -\defineunmatchedend{ifnotinfo} - -% We can't just want to start a group at @iftex (for example) and end it -% at @end iftex, since then @set commands inside the conditional have no -% effect (they'd get reverted at the end of the group). So we must -% define \Eiftex to redefine itself to be its previous value. (We can't -% just define it to fail again with an ``unmatched end'' error, since -% the @ifset might be nested.) -% -\def\conditionalsucceed#1{% - \edef\temp{% - % Remember the current value of \E#1. - \let\nece{prevE#1} = \nece{E#1}% - % - % At the `@end #1', redefine \E#1 to be its previous value. - \def\nece{E#1}{\let\nece{E#1} = \nece{prevE#1}}% - }% - \temp -} - -% We need to expand lots of \csname's, but we don't want to expand the -% control sequences after we've constructed them. -% -\def\nece#1{\expandafter\noexpand\csname#1\endcsname} - -% @defininfoenclose. -\let\definfoenclose=\comment - - -\message{indexing,} -% Index generation facilities - -% Define \newwrite to be identical to plain tex's \newwrite -% except not \outer, so it can be used within \newindex. -{\catcode`\@=11 -\gdef\newwrite{\alloc@7\write\chardef\sixt@@n}} - -% \newindex {foo} defines an index named foo. -% It automatically defines \fooindex such that -% \fooindex ...rest of line... puts an entry in the index foo. -% It also defines \fooindfile to be the number of the output channel for -% the file that accumulates this index. The file's extension is foo. -% The name of an index should be no more than 2 characters long -% for the sake of vms. -% -\def\newindex#1{% - \iflinks - \expandafter\newwrite \csname#1indfile\endcsname - \openout \csname#1indfile\endcsname \jobname.#1 % Open the file - \fi - \expandafter\xdef\csname#1index\endcsname{% % Define @#1index - \noexpand\doindex{#1}} -} - -% @defindex foo == \newindex{foo} - -\def\defindex{\parsearg\newindex} - -% Define @defcodeindex, like @defindex except put all entries in @code. - -\def\newcodeindex#1{% - \iflinks - \expandafter\newwrite \csname#1indfile\endcsname - \openout \csname#1indfile\endcsname \jobname.#1 - \fi - \expandafter\xdef\csname#1index\endcsname{% - \noexpand\docodeindex{#1}} -} - -\def\defcodeindex{\parsearg\newcodeindex} - -% @synindex foo bar makes index foo feed into index bar. -% Do this instead of @defindex foo if you don't want it as a separate index. -% The \closeout helps reduce unnecessary open files; the limit on the -% Acorn RISC OS is a mere 16 files. -\def\synindex#1 #2 {% - \expandafter\let\expandafter\synindexfoo\expandafter=\csname#2indfile\endcsname - \expandafter\closeout\csname#1indfile\endcsname - \expandafter\let\csname#1indfile\endcsname=\synindexfoo - \expandafter\xdef\csname#1index\endcsname{% define \xxxindex - \noexpand\doindex{#2}}% -} - -% @syncodeindex foo bar similar, but put all entries made for index foo -% inside @code. -\def\syncodeindex#1 #2 {% - \expandafter\let\expandafter\synindexfoo\expandafter=\csname#2indfile\endcsname - \expandafter\closeout\csname#1indfile\endcsname - \expandafter\let\csname#1indfile\endcsname=\synindexfoo - \expandafter\xdef\csname#1index\endcsname{% define \xxxindex - \noexpand\docodeindex{#2}}% -} - -% Define \doindex, the driver for all \fooindex macros. -% Argument #1 is generated by the calling \fooindex macro, -% and it is "foo", the name of the index. - -% \doindex just uses \parsearg; it calls \doind for the actual work. -% This is because \doind is more useful to call from other macros. - -% There is also \dosubind {index}{topic}{subtopic} -% which makes an entry in a two-level index such as the operation index. - -\def\doindex#1{\edef\indexname{#1}\parsearg\singleindexer} -\def\singleindexer #1{\doind{\indexname}{#1}} - -% like the previous two, but they put @code around the argument. -\def\docodeindex#1{\edef\indexname{#1}\parsearg\singlecodeindexer} -\def\singlecodeindexer #1{\doind{\indexname}{\code{#1}}} - -\def\indexdummies{% -\def\ { }% -% Take care of the plain tex accent commands. -\def\"{\realbackslash "}% -\def\`{\realbackslash `}% -\def\'{\realbackslash '}% -\def\^{\realbackslash ^}% -\def\~{\realbackslash ~}% -\def\={\realbackslash =}% -\def\b{\realbackslash b}% -\def\c{\realbackslash c}% -\def\d{\realbackslash d}% -\def\u{\realbackslash u}% -\def\v{\realbackslash v}% -\def\H{\realbackslash H}% -% Take care of the plain tex special European modified letters. -\def\oe{\realbackslash oe}% -\def\ae{\realbackslash ae}% -\def\aa{\realbackslash aa}% -\def\OE{\realbackslash OE}% -\def\AE{\realbackslash AE}% -\def\AA{\realbackslash AA}% -\def\o{\realbackslash o}% -\def\O{\realbackslash O}% -\def\l{\realbackslash l}% -\def\L{\realbackslash L}% -\def\ss{\realbackslash ss}% -% Take care of texinfo commands likely to appear in an index entry. -% (Must be a way to avoid doing expansion at all, and thus not have to -% laboriously list every single command here.) -\def\@{@}% will be @@ when we switch to @ as escape char. -% Need these in case \tex is in effect and \{ is a \delimiter again. -% But can't use \lbracecmd and \rbracecmd because texindex assumes -% braces and backslashes are used only as delimiters. -\let\{ = \mylbrace -\let\} = \myrbrace -\def\_{{\realbackslash _}}% -\def\w{\realbackslash w }% -\def\bf{\realbackslash bf }% -%\def\rm{\realbackslash rm }% -\def\sl{\realbackslash sl }% -\def\sf{\realbackslash sf}% -\def\tt{\realbackslash tt}% -\def\gtr{\realbackslash gtr}% -\def\less{\realbackslash less}% -\def\hat{\realbackslash hat}% -\def\TeX{\realbackslash TeX}% -\def\dots{\realbackslash dots }% -\def\result{\realbackslash result}% -\def\equiv{\realbackslash equiv}% -\def\expansion{\realbackslash expansion}% -\def\print{\realbackslash print}% -\def\error{\realbackslash error}% -\def\point{\realbackslash point}% -\def\copyright{\realbackslash copyright}% -\def\tclose##1{\realbackslash tclose {##1}}% -\def\code##1{\realbackslash code {##1}}% -\def\uref##1{\realbackslash uref {##1}}% -\def\url##1{\realbackslash url {##1}}% -\def\env##1{\realbackslash env {##1}}% -\def\command##1{\realbackslash command {##1}}% -\def\option##1{\realbackslash option {##1}}% -\def\dotless##1{\realbackslash dotless {##1}}% -\def\samp##1{\realbackslash samp {##1}}% -\def\,##1{\realbackslash ,{##1}}% -\def\t##1{\realbackslash t {##1}}% -\def\r##1{\realbackslash r {##1}}% -\def\i##1{\realbackslash i {##1}}% -\def\b##1{\realbackslash b {##1}}% -\def\sc##1{\realbackslash sc {##1}}% -\def\cite##1{\realbackslash cite {##1}}% -\def\key##1{\realbackslash key {##1}}% -\def\file##1{\realbackslash file {##1}}% -\def\var##1{\realbackslash var {##1}}% -\def\kbd##1{\realbackslash kbd {##1}}% -\def\dfn##1{\realbackslash dfn {##1}}% -\def\emph##1{\realbackslash emph {##1}}% -\def\acronym##1{\realbackslash acronym {##1}}% -% -% Handle some cases of @value -- where the variable name does not -% contain - or _, and the value does not contain any -% (non-fully-expandable) commands. -\let\value = \expandablevalue -% -\unsepspaces -% Turn off macro expansion -\turnoffmacros -} - -% If an index command is used in an @example environment, any spaces -% therein should become regular spaces in the raw index file, not the -% expansion of \tie (\\leavevmode \penalty \@M \ ). -{\obeyspaces - \gdef\unsepspaces{\obeyspaces\let =\space}} - -% \indexnofonts no-ops all font-change commands. -% This is used when outputting the strings to sort the index by. -\def\indexdummyfont#1{#1} -\def\indexdummytex{TeX} -\def\indexdummydots{...} - -\def\indexnofonts{% -% Just ignore accents. -\let\,=\indexdummyfont -\let\"=\indexdummyfont -\let\`=\indexdummyfont -\let\'=\indexdummyfont -\let\^=\indexdummyfont -\let\~=\indexdummyfont -\let\==\indexdummyfont -\let\b=\indexdummyfont -\let\c=\indexdummyfont -\let\d=\indexdummyfont -\let\u=\indexdummyfont -\let\v=\indexdummyfont -\let\H=\indexdummyfont -\let\dotless=\indexdummyfont -% Take care of the plain tex special European modified letters. -\def\oe{oe}% -\def\ae{ae}% -\def\aa{aa}% -\def\OE{OE}% -\def\AE{AE}% -\def\AA{AA}% -\def\o{o}% -\def\O{O}% -\def\l{l}% -\def\L{L}% -\def\ss{ss}% -\let\w=\indexdummyfont -\let\t=\indexdummyfont -\let\r=\indexdummyfont -\let\i=\indexdummyfont -\let\b=\indexdummyfont -\let\emph=\indexdummyfont -\let\strong=\indexdummyfont -\let\cite=\indexdummyfont -\let\sc=\indexdummyfont -%Don't no-op \tt, since it isn't a user-level command -% and is used in the definitions of the active chars like <, >, |... -%\let\tt=\indexdummyfont -\let\tclose=\indexdummyfont -\let\code=\indexdummyfont -\let\url=\indexdummyfont -\let\uref=\indexdummyfont -\let\env=\indexdummyfont -\let\acronym=\indexdummyfont -\let\command=\indexdummyfont -\let\option=\indexdummyfont -\let\file=\indexdummyfont -\let\samp=\indexdummyfont -\let\kbd=\indexdummyfont -\let\key=\indexdummyfont -\let\var=\indexdummyfont -\let\TeX=\indexdummytex -\let\dots=\indexdummydots -\def\@{@}% -} - -% To define \realbackslash, we must make \ not be an escape. -% We must first make another character (@) an escape -% so we do not become unable to do a definition. - -{\catcode`\@=0 \catcode`\\=\other - @gdef@realbackslash{\}} - -\let\indexbackslash=0 %overridden during \printindex. -\let\SETmarginindex=\relax % put index entries in margin (undocumented)? - -% For \ifx comparisons. -\def\emptymacro{\empty} - -% Most index entries go through here, but \dosubind is the general case. -% -\def\doind#1#2{\dosubind{#1}{#2}\empty} - -% Workhorse for all \fooindexes. -% #1 is name of index, #2 is stuff to put there, #3 is subentry -- -% \empty if called from \doind, as we usually are. The main exception -% is with defuns, which call us directly. -% -\def\dosubind#1#2#3{% - % Put the index entry in the margin if desired. - \ifx\SETmarginindex\relax\else - \insert\margin{\hbox{\vrule height8pt depth3pt width0pt #2}}% - \fi - {% - \count255=\lastpenalty - {% - \indexdummies % Must do this here, since \bf, etc expand at this stage - \escapechar=`\\ - {% - \let\folio = 0% We will expand all macros now EXCEPT \folio. - \def\rawbackslashxx{\indexbackslash}% \indexbackslash isn't defined now - % so it will be output as is; and it will print as backslash. - % - \def\thirdarg{#3}% - % - % If third arg is present, precede it with space in sort key. - \ifx\thirdarg\emptymacro - \let\subentry = \empty - \else - \def\subentry{ #3}% - \fi - % - % First process the index entry with all font commands turned - % off to get the string to sort by. - {\indexnofonts \xdef\indexsorttmp{#2\subentry}}% - % - % Now the real index entry with the fonts. - \toks0 = {#2}% - % - % If third (subentry) arg is present, add it to the index - % string. And include a space. - \ifx\thirdarg\emptymacro \else - \toks0 = \expandafter{\the\toks0 \space #3}% - \fi - % - % Set up the complete index entry, with both the sort key - % and the original text, including any font commands. We write - % three arguments to \entry to the .?? file, texindex reduces to - % two when writing the .??s sorted result. - \edef\temp{% - \write\csname#1indfile\endcsname{% - \realbackslash entry{\indexsorttmp}{\folio}{\the\toks0}}% - }% - % - % If a skip is the last thing on the list now, preserve it - % by backing up by \lastskip, doing the \write, then inserting - % the skip again. Otherwise, the whatsit generated by the - % \write will make \lastskip zero. The result is that sequences - % like this: - % @end defun - % @tindex whatever - % @defun ... - % will have extra space inserted, because the \medbreak in the - % start of the @defun won't see the skip inserted by the @end of - % the previous defun. - % - % But don't do any of this if we're not in vertical mode. We - % don't want to do a \vskip and prematurely end a paragraph. - % - % Avoid page breaks due to these extra skips, too. - % - \iflinks - \ifvmode - \skip0 = \lastskip - \ifdim\lastskip = 0pt \else \nobreak\vskip-\lastskip \fi - \fi - % - \temp % do the write - % - % - \ifvmode \ifdim\skip0 = 0pt \else \nobreak\vskip\skip0 \fi \fi - \fi - }% - }% - \penalty\count255 - }% -} - -% The index entry written in the file actually looks like -% \entry {sortstring}{page}{topic} -% or -% \entry {sortstring}{page}{topic}{subtopic} -% The texindex program reads in these files and writes files -% containing these kinds of lines: -% \initial {c} -% before the first topic whose initial is c -% \entry {topic}{pagelist} -% for a topic that is used without subtopics -% \primary {topic} -% for the beginning of a topic that is used with subtopics -% \secondary {subtopic}{pagelist} -% for each subtopic. - -% Define the user-accessible indexing commands -% @findex, @vindex, @kindex, @cindex. - -\def\findex {\fnindex} -\def\kindex {\kyindex} -\def\cindex {\cpindex} -\def\vindex {\vrindex} -\def\tindex {\tpindex} -\def\pindex {\pgindex} - -\def\cindexsub {\begingroup\obeylines\cindexsub} -{\obeylines % -\gdef\cindexsub "#1" #2^^M{\endgroup % -\dosubind{cp}{#2}{#1}}} - -% Define the macros used in formatting output of the sorted index material. - -% @printindex causes a particular index (the ??s file) to get printed. -% It does not print any chapter heading (usually an @unnumbered). -% -\def\printindex{\parsearg\doprintindex} -\def\doprintindex#1{\begingroup - \dobreak \chapheadingskip{10000}% - % - \smallfonts \rm - \tolerance = 9500 - \indexbreaks - % - % See if the index file exists and is nonempty. - % Change catcode of @ here so that if the index file contains - % \initial {@} - % as its first line, TeX doesn't complain about mismatched braces - % (because it thinks @} is a control sequence). - \catcode`\@ = 11 - \openin 1 \jobname.#1s - \ifeof 1 - % \enddoublecolumns gets confused if there is no text in the index, - % and it loses the chapter title and the aux file entries for the - % index. The easiest way to prevent this problem is to make sure - % there is some text. - \putwordIndexNonexistent - \else - % - % If the index file exists but is empty, then \openin leaves \ifeof - % false. We have to make TeX try to read something from the file, so - % it can discover if there is anything in it. - \read 1 to \temp - \ifeof 1 - \putwordIndexIsEmpty - \else - % Index files are almost Texinfo source, but we use \ as the escape - % character. It would be better to use @, but that's too big a change - % to make right now. - \def\indexbackslash{\rawbackslashxx}% - \catcode`\\ = 0 - \escapechar = `\\ - \begindoublecolumns - \input \jobname.#1s - \enddoublecolumns - \fi - \fi - \closein 1 -\endgroup} - -% These macros are used by the sorted index file itself. -% Change them to control the appearance of the index. - -\def\initial#1{{% - % Some minor font changes for the special characters. - \let\tentt=\sectt \let\tt=\sectt \let\sf=\sectt - % - % Remove any glue we may have, we'll be inserting our own. - \removelastskip - % - % We like breaks before the index initials, so insert a bonus. - \penalty -300 - % - % Typeset the initial. Making this add up to a whole number of - % baselineskips increases the chance of the dots lining up from column - % to column. It still won't often be perfect, because of the stretch - % we need before each entry, but it's better. - % - % No shrink because it confuses \balancecolumns. - \vskip 1.67\baselineskip plus .5\baselineskip - \leftline{\secbf #1}% - \vskip .33\baselineskip plus .1\baselineskip - % - % Do our best not to break after the initial. - \nobreak -}} - -% This typesets a paragraph consisting of #1, dot leaders, and then #2 -% flush to the right margin. It is used for index and table of contents -% entries. The paragraph is indented by \leftskip. -% -\def\entry#1#2{\begingroup - % - % Start a new paragraph if necessary, so our assignments below can't - % affect previous text. - \par - % - % Do not fill out the last line with white space. - \parfillskip = 0in - % - % No extra space above this paragraph. - \parskip = 0in - % - % Do not prefer a separate line ending with a hyphen to fewer lines. - \finalhyphendemerits = 0 - % - % \hangindent is only relevant when the entry text and page number - % don't both fit on one line. In that case, bob suggests starting the - % dots pretty far over on the line. Unfortunately, a large - % indentation looks wrong when the entry text itself is broken across - % lines. So we use a small indentation and put up with long leaders. - % - % \hangafter is reset to 1 (which is the value we want) at the start - % of each paragraph, so we need not do anything with that. - \hangindent = 2em - % - % When the entry text needs to be broken, just fill out the first line - % with blank space. - \rightskip = 0pt plus1fil - % - % A bit of stretch before each entry for the benefit of balancing columns. - \vskip 0pt plus1pt - % - % Start a ``paragraph'' for the index entry so the line breaking - % parameters we've set above will have an effect. - \noindent - % - % Insert the text of the index entry. TeX will do line-breaking on it. - #1% - % The following is kludged to not output a line of dots in the index if - % there are no page numbers. The next person who breaks this will be - % cursed by a Unix daemon. - \def\tempa{{\rm }}% - \def\tempb{#2}% - \edef\tempc{\tempa}% - \edef\tempd{\tempb}% - \ifx\tempc\tempd\ \else% - % - % If we must, put the page number on a line of its own, and fill out - % this line with blank space. (The \hfil is overwhelmed with the - % fill leaders glue in \indexdotfill if the page number does fit.) - \hfil\penalty50 - \null\nobreak\indexdotfill % Have leaders before the page number. - % - % The `\ ' here is removed by the implicit \unskip that TeX does as - % part of (the primitive) \par. Without it, a spurious underfull - % \hbox ensues. - \ifpdf - \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph. - \else - \ #2% The page number ends the paragraph. - \fi - \fi% - \par -\endgroup} - -% Like \dotfill except takes at least 1 em. -\def\indexdotfill{\cleaders - \hbox{$\mathsurround=0pt \mkern1.5mu ${\it .}$ \mkern1.5mu$}\hskip 1em plus 1fill} - -\def\primary #1{\line{#1\hfil}} - -\newskip\secondaryindent \secondaryindent=0.5cm - -\def\secondary #1#2{ -{\parfillskip=0in \parskip=0in -\hangindent =1in \hangafter=1 -\noindent\hskip\secondaryindent\hbox{#1}\indexdotfill #2\par -}} - -% Define two-column mode, which we use to typeset indexes. -% Adapted from the TeXbook, page 416, which is to say, -% the manmac.tex format used to print the TeXbook itself. -\catcode`\@=11 - -\newbox\partialpage -\newdimen\doublecolumnhsize - -\def\begindoublecolumns{\begingroup % ended by \enddoublecolumns - % Grab any single-column material above us. - \output = {% - % - % Here is a possibility not foreseen in manmac: if we accumulate a - % whole lot of material, we might end up calling this \output - % routine twice in a row (see the doublecol-lose test, which is - % essentially a couple of indexes with @setchapternewpage off). In - % that case we just ship out what is in \partialpage with the normal - % output routine. Generally, \partialpage will be empty when this - % runs and this will be a no-op. See the indexspread.tex test case. - \ifvoid\partialpage \else - \onepageout{\pagecontents\partialpage}% - \fi - % - \global\setbox\partialpage = \vbox{% - % Unvbox the main output page. - \unvbox\PAGE - \kern-\topskip \kern\baselineskip - }% - }% - \eject % run that output routine to set \partialpage - % - % Use the double-column output routine for subsequent pages. - \output = {\doublecolumnout}% - % - % Change the page size parameters. We could do this once outside this - % routine, in each of @smallbook, @afourpaper, and the default 8.5x11 - % format, but then we repeat the same computation. Repeating a couple - % of assignments once per index is clearly meaningless for the - % execution time, so we may as well do it in one place. - % - % First we halve the line length, less a little for the gutter between - % the columns. We compute the gutter based on the line length, so it - % changes automatically with the paper format. The magic constant - % below is chosen so that the gutter has the same value (well, +-<1pt) - % as it did when we hard-coded it. - % - % We put the result in a separate register, \doublecolumhsize, so we - % can restore it in \pagesofar, after \hsize itself has (potentially) - % been clobbered. - % - \doublecolumnhsize = \hsize - \advance\doublecolumnhsize by -.04154\hsize - \divide\doublecolumnhsize by 2 - \hsize = \doublecolumnhsize - % - % Double the \vsize as well. (We don't need a separate register here, - % since nobody clobbers \vsize.) - \advance\vsize by -\ht\partialpage - \vsize = 2\vsize -} - -% The double-column output routine for all double-column pages except -% the last. -% -\def\doublecolumnout{% - \splittopskip=\topskip \splitmaxdepth=\maxdepth - % Get the available space for the double columns -- the normal - % (undoubled) page height minus any material left over from the - % previous page. - \dimen@ = \vsize - \divide\dimen@ by 2 - % - % box0 will be the left-hand column, box2 the right. - \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@ - \onepageout\pagesofar - \unvbox255 - \penalty\outputpenalty -} -\def\pagesofar{% - % Re-output the contents of the output page -- any previous material, - % followed by the two boxes we just split, in box0 and box2. - \unvbox\partialpage - % - \hsize = \doublecolumnhsize - \wd0=\hsize \wd2=\hsize - \hbox to\pagewidth{\box0\hfil\box2}% -} -\def\enddoublecolumns{% - \output = {% - % Split the last of the double-column material. Leave it on the - % current page, no automatic page break. - \balancecolumns - % - % If we end up splitting too much material for the current page, - % though, there will be another page break right after this \output - % invocation ends. Having called \balancecolumns once, we do not - % want to call it again. Therefore, reset \output to its normal - % definition right away. (We hope \balancecolumns will never be - % called on to balance too much material, but if it is, this makes - % the output somewhat more palatable.) - \global\output = {\onepageout{\pagecontents\PAGE}}% - }% - \eject - \endgroup % started in \begindoublecolumns - % - % \pagegoal was set to the doubled \vsize above, since we restarted - % the current page. We're now back to normal single-column - % typesetting, so reset \pagegoal to the normal \vsize (after the - % \endgroup where \vsize got restored). - \pagegoal = \vsize -} -\def\balancecolumns{% - % Called at the end of the double column material. - \setbox0 = \vbox{\unvbox255}% like \box255 but more efficient, see p.120. - \dimen@ = \ht0 - \advance\dimen@ by \topskip - \advance\dimen@ by-\baselineskip - \divide\dimen@ by 2 % target to split to - %debug\message{final 2-column material height=\the\ht0, target=\the\dimen@.}% - \splittopskip = \topskip - % Loop until we get a decent breakpoint. - {% - \vbadness = 10000 - \loop - \global\setbox3 = \copy0 - \global\setbox1 = \vsplit3 to \dimen@ - \ifdim\ht3>\dimen@ - \global\advance\dimen@ by 1pt - \repeat - }% - %debug\message{split to \the\dimen@, column heights: \the\ht1, \the\ht3.}% - \setbox0=\vbox to\dimen@{\unvbox1}% - \setbox2=\vbox to\dimen@{\unvbox3}% - % - \pagesofar -} -\catcode`\@ = \other - - -\message{sectioning,} -% Chapters, sections, etc. - -\newcount\chapno -\newcount\secno \secno=0 -\newcount\subsecno \subsecno=0 -\newcount\subsubsecno \subsubsecno=0 - -% This counter is funny since it counts through charcodes of letters A, B, ... -\newcount\appendixno \appendixno = `\@ -% \def\appendixletter{\char\the\appendixno} -% We do the following for the sake of pdftex, which needs the actual -% letter in the expansion, not just typeset. -\def\appendixletter{% - \ifnum\appendixno=`A A% - \else\ifnum\appendixno=`B B% - \else\ifnum\appendixno=`C C% - \else\ifnum\appendixno=`D D% - \else\ifnum\appendixno=`E E% - \else\ifnum\appendixno=`F F% - \else\ifnum\appendixno=`G G% - \else\ifnum\appendixno=`H H% - \else\ifnum\appendixno=`I I% - \else\ifnum\appendixno=`J J% - \else\ifnum\appendixno=`K K% - \else\ifnum\appendixno=`L L% - \else\ifnum\appendixno=`M M% - \else\ifnum\appendixno=`N N% - \else\ifnum\appendixno=`O O% - \else\ifnum\appendixno=`P P% - \else\ifnum\appendixno=`Q Q% - \else\ifnum\appendixno=`R R% - \else\ifnum\appendixno=`S S% - \else\ifnum\appendixno=`T T% - \else\ifnum\appendixno=`U U% - \else\ifnum\appendixno=`V V% - \else\ifnum\appendixno=`W W% - \else\ifnum\appendixno=`X X% - \else\ifnum\appendixno=`Y Y% - \else\ifnum\appendixno=`Z Z% - % The \the is necessary, despite appearances, because \appendixletter is - % expanded while writing the .toc file. \char\appendixno is not - % expandable, thus it is written literally, thus all appendixes come out - % with the same letter (or @) in the toc without it. - \else\char\the\appendixno - \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi - \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi} - -% Each @chapter defines this as the name of the chapter. -% page headings and footings can use it. @section does likewise. -\def\thischapter{} -\def\thissection{} - -\newcount\absseclevel % used to calculate proper heading level -\newcount\secbase\secbase=0 % @raise/lowersections modify this count - -% @raisesections: treat @section as chapter, @subsection as section, etc. -\def\raisesections{\global\advance\secbase by -1} -\let\up=\raisesections % original BFox name - -% @lowersections: treat @chapter as section, @section as subsection, etc. -\def\lowersections{\global\advance\secbase by 1} -\let\down=\lowersections % original BFox name - -% Choose a numbered-heading macro -% #1 is heading level if unmodified by @raisesections or @lowersections -% #2 is text for heading -\def\numhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1 -\ifcase\absseclevel - \chapterzzz{#2} -\or - \seczzz{#2} -\or - \numberedsubseczzz{#2} -\or - \numberedsubsubseczzz{#2} -\else - \ifnum \absseclevel<0 - \chapterzzz{#2} - \else - \numberedsubsubseczzz{#2} - \fi -\fi -} - -% like \numhead, but chooses appendix heading levels -\def\apphead#1#2{\absseclevel=\secbase\advance\absseclevel by #1 -\ifcase\absseclevel - \appendixzzz{#2} -\or - \appendixsectionzzz{#2} -\or - \appendixsubseczzz{#2} -\or - \appendixsubsubseczzz{#2} -\else - \ifnum \absseclevel<0 - \appendixzzz{#2} - \else - \appendixsubsubseczzz{#2} - \fi -\fi -} - -% like \numhead, but chooses numberless heading levels -\def\unnmhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1 -\ifcase\absseclevel - \unnumberedzzz{#2} -\or - \unnumberedseczzz{#2} -\or - \unnumberedsubseczzz{#2} -\or - \unnumberedsubsubseczzz{#2} -\else - \ifnum \absseclevel<0 - \unnumberedzzz{#2} - \else - \unnumberedsubsubseczzz{#2} - \fi -\fi -} - -% @chapter, @appendix, @unnumbered. -\def\thischaptername{No Chapter Title} -\outer\def\chapter{\parsearg\chapteryyy} -\def\chapteryyy #1{\numhead0{#1}} % normally numhead0 calls chapterzzz -\def\chapterzzz #1{% -\secno=0 \subsecno=0 \subsubsecno=0 -\global\advance \chapno by 1 \message{\putwordChapter\space \the\chapno}% -\chapmacro {#1}{\the\chapno}% -\gdef\thissection{#1}% -\gdef\thischaptername{#1}% -% We don't substitute the actual chapter name into \thischapter -% because we don't want its macros evaluated now. -\xdef\thischapter{\putwordChapter{} \the\chapno: \noexpand\thischaptername}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash chapentry{\the\toks0}% - {\the\chapno}}}% -\temp -\donoderef -\global\let\section = \numberedsec -\global\let\subsection = \numberedsubsec -\global\let\subsubsection = \numberedsubsubsec -} - -\outer\def\appendix{\parsearg\appendixyyy} -\def\appendixyyy #1{\apphead0{#1}} % normally apphead0 calls appendixzzz -\def\appendixzzz #1{% -\secno=0 \subsecno=0 \subsubsecno=0 -\global\advance \appendixno by 1 -\message{\putwordAppendix\space \appendixletter}% -\chapmacro {#1}{\putwordAppendix{} \appendixletter}% -\gdef\thissection{#1}% -\gdef\thischaptername{#1}% -\xdef\thischapter{\putwordAppendix{} \appendixletter: \noexpand\thischaptername}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash chapentry{\the\toks0}% - {\putwordAppendix{} \appendixletter}}}% -\temp -\appendixnoderef -\global\let\section = \appendixsec -\global\let\subsection = \appendixsubsec -\global\let\subsubsection = \appendixsubsubsec -} - -% @centerchap is like @unnumbered, but the heading is centered. -\outer\def\centerchap{\parsearg\centerchapyyy} -\def\centerchapyyy #1{{\let\unnumbchapmacro=\centerchapmacro \unnumberedyyy{#1}}} - -% @top is like @unnumbered. -\outer\def\top{\parsearg\unnumberedyyy} - -\outer\def\unnumbered{\parsearg\unnumberedyyy} -\def\unnumberedyyy #1{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz -\def\unnumberedzzz #1{% -\secno=0 \subsecno=0 \subsubsecno=0 -% -% This used to be simply \message{#1}, but TeX fully expands the -% argument to \message. Therefore, if #1 contained @-commands, TeX -% expanded them. For example, in `@unnumbered The @cite{Book}', TeX -% expanded @cite (which turns out to cause errors because \cite is meant -% to be executed, not expanded). -% -% Anyway, we don't want the fully-expanded definition of @cite to appear -% as a result of the \message, we just want `@cite' itself. We use -% \the to achieve this: TeX expands \the only once, -% simply yielding the contents of . (We also do this for -% the toc entries.) -\toks0 = {#1}\message{(\the\toks0)}% -% -\unnumbchapmacro {#1}% -\gdef\thischapter{#1}\gdef\thissection{#1}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash unnumbchapentry{\the\toks0}}}% -\temp -\unnumbnoderef -\global\let\section = \unnumberedsec -\global\let\subsection = \unnumberedsubsec -\global\let\subsubsection = \unnumberedsubsubsec -} - -% Sections. -\outer\def\numberedsec{\parsearg\secyyy} -\def\secyyy #1{\numhead1{#1}} % normally calls seczzz -\def\seczzz #1{% -\subsecno=0 \subsubsecno=0 \global\advance \secno by 1 % -\gdef\thissection{#1}\secheading {#1}{\the\chapno}{\the\secno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash secentry{\the\toks0}% - {\the\chapno}{\the\secno}}}% -\temp -\donoderef -\nobreak -} - -\outer\def\appendixsection{\parsearg\appendixsecyyy} -\outer\def\appendixsec{\parsearg\appendixsecyyy} -\def\appendixsecyyy #1{\apphead1{#1}} % normally calls appendixsectionzzz -\def\appendixsectionzzz #1{% -\subsecno=0 \subsubsecno=0 \global\advance \secno by 1 % -\gdef\thissection{#1}\secheading {#1}{\appendixletter}{\the\secno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash secentry{\the\toks0}% - {\appendixletter}{\the\secno}}}% -\temp -\appendixnoderef -\nobreak -} - -\outer\def\unnumberedsec{\parsearg\unnumberedsecyyy} -\def\unnumberedsecyyy #1{\unnmhead1{#1}} % normally calls unnumberedseczzz -\def\unnumberedseczzz #1{% -\plainsecheading {#1}\gdef\thissection{#1}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsecentry{\the\toks0}}}% -\temp -\unnumbnoderef -\nobreak -} - -% Subsections. -\outer\def\numberedsubsec{\parsearg\numberedsubsecyyy} -\def\numberedsubsecyyy #1{\numhead2{#1}} % normally calls numberedsubseczzz -\def\numberedsubseczzz #1{% -\gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 % -\subsecheading {#1}{\the\chapno}{\the\secno}{\the\subsecno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash subsecentry{\the\toks0}% - {\the\chapno}{\the\secno}{\the\subsecno}}}% -\temp -\donoderef -\nobreak -} - -\outer\def\appendixsubsec{\parsearg\appendixsubsecyyy} -\def\appendixsubsecyyy #1{\apphead2{#1}} % normally calls appendixsubseczzz -\def\appendixsubseczzz #1{% -\gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 % -\subsecheading {#1}{\appendixletter}{\the\secno}{\the\subsecno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash subsecentry{\the\toks0}% - {\appendixletter}{\the\secno}{\the\subsecno}}}% -\temp -\appendixnoderef -\nobreak -} - -\outer\def\unnumberedsubsec{\parsearg\unnumberedsubsecyyy} -\def\unnumberedsubsecyyy #1{\unnmhead2{#1}} %normally calls unnumberedsubseczzz -\def\unnumberedsubseczzz #1{% -\plainsubsecheading {#1}\gdef\thissection{#1}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsubsecentry% - {\the\toks0}}}% -\temp -\unnumbnoderef -\nobreak -} - -% Subsubsections. -\outer\def\numberedsubsubsec{\parsearg\numberedsubsubsecyyy} -\def\numberedsubsubsecyyy #1{\numhead3{#1}} % normally numberedsubsubseczzz -\def\numberedsubsubseczzz #1{% -\gdef\thissection{#1}\global\advance \subsubsecno by 1 % -\subsubsecheading {#1} - {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash subsubsecentry{\the\toks0}% - {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}}}% -\temp -\donoderef -\nobreak -} - -\outer\def\appendixsubsubsec{\parsearg\appendixsubsubsecyyy} -\def\appendixsubsubsecyyy #1{\apphead3{#1}} % normally appendixsubsubseczzz -\def\appendixsubsubseczzz #1{% -\gdef\thissection{#1}\global\advance \subsubsecno by 1 % -\subsubsecheading {#1} - {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash subsubsecentry{\the\toks0}% - {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}}}% -\temp -\appendixnoderef -\nobreak -} - -\outer\def\unnumberedsubsubsec{\parsearg\unnumberedsubsubsecyyy} -\def\unnumberedsubsubsecyyy #1{\unnmhead3{#1}} %normally unnumberedsubsubseczzz -\def\unnumberedsubsubseczzz #1{% -\plainsubsubsecheading {#1}\gdef\thissection{#1}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsubsubsecentry% - {\the\toks0}}}% -\temp -\unnumbnoderef -\nobreak -} - -% These are variants which are not "outer", so they can appear in @ifinfo. -% Actually, they should now be obsolete; ordinary section commands should work. -\def\infotop{\parsearg\unnumberedzzz} -\def\infounnumbered{\parsearg\unnumberedzzz} -\def\infounnumberedsec{\parsearg\unnumberedseczzz} -\def\infounnumberedsubsec{\parsearg\unnumberedsubseczzz} -\def\infounnumberedsubsubsec{\parsearg\unnumberedsubsubseczzz} - -\def\infoappendix{\parsearg\appendixzzz} -\def\infoappendixsec{\parsearg\appendixseczzz} -\def\infoappendixsubsec{\parsearg\appendixsubseczzz} -\def\infoappendixsubsubsec{\parsearg\appendixsubsubseczzz} - -\def\infochapter{\parsearg\chapterzzz} -\def\infosection{\parsearg\sectionzzz} -\def\infosubsection{\parsearg\subsectionzzz} -\def\infosubsubsection{\parsearg\subsubsectionzzz} - -% These macros control what the section commands do, according -% to what kind of chapter we are in (ordinary, appendix, or unnumbered). -% Define them by default for a numbered chapter. -\global\let\section = \numberedsec -\global\let\subsection = \numberedsubsec -\global\let\subsubsection = \numberedsubsubsec - -% Define @majorheading, @heading and @subheading - -% NOTE on use of \vbox for chapter headings, section headings, and such: -% 1) We use \vbox rather than the earlier \line to permit -% overlong headings to fold. -% 2) \hyphenpenalty is set to 10000 because hyphenation in a -% heading is obnoxious; this forbids it. -% 3) Likewise, headings look best if no \parindent is used, and -% if justification is not attempted. Hence \raggedright. - - -\def\majorheading{\parsearg\majorheadingzzz} -\def\majorheadingzzz #1{% -{\advance\chapheadingskip by 10pt \chapbreak }% -{\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 - \parindent=0pt\raggedright - \rm #1\hfill}}\bigskip \par\penalty 200} - -\def\chapheading{\parsearg\chapheadingzzz} -\def\chapheadingzzz #1{\chapbreak % -{\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 - \parindent=0pt\raggedright - \rm #1\hfill}}\bigskip \par\penalty 200} - -% @heading, @subheading, @subsubheading. -\def\heading{\parsearg\plainsecheading} -\def\subheading{\parsearg\plainsubsecheading} -\def\subsubheading{\parsearg\plainsubsubsecheading} - -% These macros generate a chapter, section, etc. heading only -% (including whitespace, linebreaking, etc. around it), -% given all the information in convenient, parsed form. - -%%% Args are the skip and penalty (usually negative) -\def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi} - -\def\setchapterstyle #1 {\csname CHAPF#1\endcsname} - -%%% Define plain chapter starts, and page on/off switching for it -% Parameter controlling skip before chapter headings (if needed) - -\newskip\chapheadingskip - -\def\chapbreak{\dobreak \chapheadingskip {-4000}} -\def\chappager{\par\vfill\supereject} -\def\chapoddpage{\chappager \ifodd\pageno \else \hbox to 0pt{} \chappager\fi} - -\def\setchapternewpage #1 {\csname CHAPPAG#1\endcsname} - -\def\CHAPPAGoff{% -\global\let\contentsalignmacro = \chappager -\global\let\pchapsepmacro=\chapbreak -\global\let\pagealignmacro=\chappager} - -\def\CHAPPAGon{% -\global\let\contentsalignmacro = \chappager -\global\let\pchapsepmacro=\chappager -\global\let\pagealignmacro=\chappager -\global\def\HEADINGSon{\HEADINGSsingle}} - -\def\CHAPPAGodd{ -\global\let\contentsalignmacro = \chapoddpage -\global\let\pchapsepmacro=\chapoddpage -\global\let\pagealignmacro=\chapoddpage -\global\def\HEADINGSon{\HEADINGSdouble}} - -\CHAPPAGon - -\def\CHAPFplain{ -\global\let\chapmacro=\chfplain -\global\let\unnumbchapmacro=\unnchfplain -\global\let\centerchapmacro=\centerchfplain} - -% Plain chapter opening. -% #1 is the text, #2 the chapter number or empty if unnumbered. -\def\chfplain#1#2{% - \pchapsepmacro - {% - \chapfonts \rm - \def\chapnum{#2}% - \setbox0 = \hbox{#2\ifx\chapnum\empty\else\enspace\fi}% - \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright - \hangindent = \wd0 \centerparametersmaybe - \unhbox0 #1\par}% - }% - \nobreak\bigskip % no page break after a chapter title - \nobreak -} - -% Plain opening for unnumbered. -\def\unnchfplain#1{\chfplain{#1}{}} - -% @centerchap -- centered and unnumbered. -\let\centerparametersmaybe = \relax -\def\centerchfplain#1{{% - \def\centerparametersmaybe{% - \advance\rightskip by 3\rightskip - \leftskip = \rightskip - \parfillskip = 0pt - }% - \chfplain{#1}{}% -}} - -\CHAPFplain % The default - -\def\unnchfopen #1{% -\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 - \parindent=0pt\raggedright - \rm #1\hfill}}\bigskip \par\nobreak -} - -\def\chfopen #1#2{\chapoddpage {\chapfonts -\vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}% -\par\penalty 5000 % -} - -\def\centerchfopen #1{% -\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 - \parindent=0pt - \hfill {\rm #1}\hfill}}\bigskip \par\nobreak -} - -\def\CHAPFopen{ -\global\let\chapmacro=\chfopen -\global\let\unnumbchapmacro=\unnchfopen -\global\let\centerchapmacro=\centerchfopen} - - -% Section titles. -\newskip\secheadingskip -\def\secheadingbreak{\dobreak \secheadingskip {-1000}} -\def\secheading#1#2#3{\sectionheading{sec}{#2.#3}{#1}} -\def\plainsecheading#1{\sectionheading{sec}{}{#1}} - -% Subsection titles. -\newskip \subsecheadingskip -\def\subsecheadingbreak{\dobreak \subsecheadingskip {-500}} -\def\subsecheading#1#2#3#4{\sectionheading{subsec}{#2.#3.#4}{#1}} -\def\plainsubsecheading#1{\sectionheading{subsec}{}{#1}} - -% Subsubsection titles. -\let\subsubsecheadingskip = \subsecheadingskip -\let\subsubsecheadingbreak = \subsecheadingbreak -\def\subsubsecheading#1#2#3#4#5{\sectionheading{subsubsec}{#2.#3.#4.#5}{#1}} -\def\plainsubsubsecheading#1{\sectionheading{subsubsec}{}{#1}} - - -% Print any size section title. -% -% #1 is the section type (sec/subsec/subsubsec), #2 is the section -% number (maybe empty), #3 the text. -\def\sectionheading#1#2#3{% - {% - \expandafter\advance\csname #1headingskip\endcsname by \parskip - \csname #1headingbreak\endcsname - }% - {% - % Switch to the right set of fonts. - \csname #1fonts\endcsname \rm - % - % Only insert the separating space if we have a section number. - \def\secnum{#2}% - \setbox0 = \hbox{#2\ifx\secnum\empty\else\enspace\fi}% - % - \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright - \hangindent = \wd0 % zero if no section number - \unhbox0 #3}% - }% - \ifdim\parskip<10pt \nobreak\kern10pt\nobreak\kern-\parskip\fi \nobreak -} - - -\message{toc,} -% Table of contents. -\newwrite\tocfile - -% Write an entry to the toc file, opening it if necessary. -% Called from @chapter, etc. We supply {\folio} at the end of the -% argument, which will end up as the last argument to the \...entry macro. -% -% We open the .toc file here instead of at @setfilename or any other -% given time so that @contents can be put in the document anywhere. -% -\newif\iftocfileopened -\def\writetocentry#1{% - \iftocfileopened\else - \immediate\openout\tocfile = \jobname.toc - \global\tocfileopenedtrue - \fi - \iflinks \write\tocfile{#1{\folio}}\fi -} - -\newskip\contentsrightmargin \contentsrightmargin=1in -\newcount\savepageno -\newcount\lastnegativepageno \lastnegativepageno = -1 - -% Finish up the main text and prepare to read what we've written -% to \tocfile. -% -\def\startcontents#1{% - % If @setchapternewpage on, and @headings double, the contents should - % start on an odd page, unlike chapters. Thus, we maintain - % \contentsalignmacro in parallel with \pagealignmacro. - % From: Torbjorn Granlund - \contentsalignmacro - \immediate\closeout\tocfile - % - % Don't need to put `Contents' or `Short Contents' in the headline. - % It is abundantly clear what they are. - \unnumbchapmacro{#1}\def\thischapter{}% - \savepageno = \pageno - \begingroup % Set up to handle contents files properly. - \catcode`\\=0 \catcode`\{=1 \catcode`\}=2 \catcode`\@=11 - % We can't do this, because then an actual ^ in a section - % title fails, e.g., @chapter ^ -- exponentiation. --karl, 9jul97. - %\catcode`\^=7 % to see ^^e4 as \"a etc. juha@piuha.ydi.vtt.fi - \raggedbottom % Worry more about breakpoints than the bottom. - \advance\hsize by -\contentsrightmargin % Don't use the full line length. - % - % Roman numerals for page numbers. - \ifnum \pageno>0 \pageno = \lastnegativepageno \fi -} - - -% Normal (long) toc. -\def\contents{% - \startcontents{\putwordTOC}% - \openin 1 \jobname.toc - \ifeof 1 \else - \closein 1 - \input \jobname.toc - \fi - \vfill \eject - \contentsalignmacro % in case @setchapternewpage odd is in effect - \pdfmakeoutlines - \endgroup - \lastnegativepageno = \pageno - \pageno = \savepageno -} - -% And just the chapters. -\def\summarycontents{% - \startcontents{\putwordShortTOC}% - % - \let\chapentry = \shortchapentry - \let\unnumbchapentry = \shortunnumberedentry - % We want a true roman here for the page numbers. - \secfonts - \let\rm=\shortcontrm \let\bf=\shortcontbf \let\sl=\shortcontsl - \rm - \hyphenpenalty = 10000 - \advance\baselineskip by 1pt % Open it up a little. - \def\secentry ##1##2##3##4{} - \def\unnumbsecentry ##1##2{} - \def\subsecentry ##1##2##3##4##5{} - \def\unnumbsubsecentry ##1##2{} - \def\subsubsecentry ##1##2##3##4##5##6{} - \def\unnumbsubsubsecentry ##1##2{} - \openin 1 \jobname.toc - \ifeof 1 \else - \closein 1 - \input \jobname.toc - \fi - \vfill \eject - \contentsalignmacro % in case @setchapternewpage odd is in effect - \endgroup - \lastnegativepageno = \pageno - \pageno = \savepageno -} -\let\shortcontents = \summarycontents - -\ifpdf - \pdfcatalog{/PageMode /UseOutlines}% -\fi - -% These macros generate individual entries in the table of contents. -% The first argument is the chapter or section name. -% The last argument is the page number. -% The arguments in between are the chapter number, section number, ... - -% Chapter-level things, for both the long and short contents. -\def\chapentry#1#2#3{\dochapentry{#2\labelspace#1}{#3}} - -% See comments in \dochapentry re vbox and related settings -\def\shortchapentry#1#2#3{% - \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#3\egroup}% -} - -% Typeset the label for a chapter or appendix for the short contents. -% The arg is, e.g. `Appendix A' for an appendix, or `3' for a chapter. -% We could simplify the code here by writing out an \appendixentry -% command in the toc file for appendices, instead of using \chapentry -% for both, but it doesn't seem worth it. -% -\newdimen\shortappendixwidth -% -\def\shortchaplabel#1{% - % Compute width of word "Appendix", may change with language. - \setbox0 = \hbox{\shortcontrm \putwordAppendix}% - \shortappendixwidth = \wd0 - % - % We typeset #1 in a box of constant width, regardless of the text of - % #1, so the chapter titles will come out aligned. - \setbox0 = \hbox{#1}% - \dimen0 = \ifdim\wd0 > \shortappendixwidth \shortappendixwidth \else 0pt \fi - % - % This space should be plenty, since a single number is .5em, and the - % widest letter (M) is 1em, at least in the Computer Modern fonts. - % (This space doesn't include the extra space that gets added after - % the label; that gets put in by \shortchapentry above.) - \advance\dimen0 by 1.1em - \hbox to \dimen0{#1\hfil}% -} - -\def\unnumbchapentry#1#2{\dochapentry{#1}{#2}} -\def\shortunnumberedentry#1#2{\tocentry{#1}{\doshortpageno\bgroup#2\egroup}} - -% Sections. -\def\secentry#1#2#3#4{\dosecentry{#2.#3\labelspace#1}{#4}} -\def\unnumbsecentry#1#2{\dosecentry{#1}{#2}} - -% Subsections. -\def\subsecentry#1#2#3#4#5{\dosubsecentry{#2.#3.#4\labelspace#1}{#5}} -\def\unnumbsubsecentry#1#2{\dosubsecentry{#1}{#2}} - -% And subsubsections. -\def\subsubsecentry#1#2#3#4#5#6{% - \dosubsubsecentry{#2.#3.#4.#5\labelspace#1}{#6}} -\def\unnumbsubsubsecentry#1#2{\dosubsubsecentry{#1}{#2}} - -% This parameter controls the indentation of the various levels. -\newdimen\tocindent \tocindent = 3pc - -% Now for the actual typesetting. In all these, #1 is the text and #2 is the -% page number. -% -% If the toc has to be broken over pages, we want it to be at chapters -% if at all possible; hence the \penalty. -\def\dochapentry#1#2{% - \penalty-300 \vskip1\baselineskip plus.33\baselineskip minus.25\baselineskip - \begingroup - \chapentryfonts - \tocentry{#1}{\dopageno\bgroup#2\egroup}% - \endgroup - \nobreak\vskip .25\baselineskip plus.1\baselineskip -} - -\def\dosecentry#1#2{\begingroup - \secentryfonts \leftskip=\tocindent - \tocentry{#1}{\dopageno\bgroup#2\egroup}% -\endgroup} - -\def\dosubsecentry#1#2{\begingroup - \subsecentryfonts \leftskip=2\tocindent - \tocentry{#1}{\dopageno\bgroup#2\egroup}% -\endgroup} - -\def\dosubsubsecentry#1#2{\begingroup - \subsubsecentryfonts \leftskip=3\tocindent - \tocentry{#1}{\dopageno\bgroup#2\egroup}% -\endgroup} - -% Final typesetting of a toc entry; we use the same \entry macro as for -% the index entries, but we want to suppress hyphenation here. (We -% can't do that in the \entry macro, since index entries might consist -% of hyphenated-identifiers-that-do-not-fit-on-a-line-and-nothing-else.) -\def\tocentry#1#2{\begingroup - \vskip 0pt plus1pt % allow a little stretch for the sake of nice page breaks - % Do not use \turnoffactive in these arguments. Since the toc is - % typeset in cmr, so characters such as _ would come out wrong; we - % have to do the usual translation tricks. - \entry{#1}{#2}% -\endgroup} - -% Space between chapter (or whatever) number and the title. -\def\labelspace{\hskip1em \relax} - -\def\dopageno#1{{\rm #1}} -\def\doshortpageno#1{{\rm #1}} - -\def\chapentryfonts{\secfonts \rm} -\def\secentryfonts{\textfonts} -\let\subsecentryfonts = \textfonts -\let\subsubsecentryfonts = \textfonts - - -\message{environments,} -% @foo ... @end foo. - -% Since these characters are used in examples, it should be an even number of -% \tt widths. Each \tt character is 1en, so two makes it 1em. -% Furthermore, these definitions must come after we define our fonts. -\newbox\dblarrowbox \newbox\longdblarrowbox -\newbox\pushcharbox \newbox\bullbox -\newbox\equivbox \newbox\errorbox - -%{\tentt -%\global\setbox\dblarrowbox = \hbox to 1em{\hfil$\Rightarrow$\hfil} -%\global\setbox\longdblarrowbox = \hbox to 1em{\hfil$\mapsto$\hfil} -%\global\setbox\pushcharbox = \hbox to 1em{\hfil$\dashv$\hfil} -%\global\setbox\equivbox = \hbox to 1em{\hfil$\ptexequiv$\hfil} -% Adapted from the manmac format (p.420 of TeXbook) -%\global\setbox\bullbox = \hbox to 1em{\kern.15em\vrule height .75ex width .85ex -% depth .1ex\hfil} -%} - -% @point{}, @result{}, @expansion{}, @print{}, @equiv{}. -\def\point{$\star$} -\def\result{\leavevmode\raise.15ex\hbox to 1em{\hfil$\Rightarrow$\hfil}} -\def\expansion{\leavevmode\raise.1ex\hbox to 1em{\hfil$\mapsto$\hfil}} -\def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}} -\def\equiv{\leavevmode\lower.1ex\hbox to 1em{\hfil$\ptexequiv$\hfil}} - -% Adapted from the TeXbook's \boxit. -{\tentt \global\dimen0 = 3em}% Width of the box. -\dimen2 = .55pt % Thickness of rules -% The text. (`r' is open on the right, `e' somewhat less so on the left.) -\setbox0 = \hbox{\kern-.75pt \tensf error\kern-1.5pt} - -\global\setbox\errorbox=\hbox to \dimen0{\hfil - \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right. - \advance\hsize by -2\dimen2 % Rules. - \vbox{ - \hrule height\dimen2 - \hbox{\vrule width\dimen2 \kern3pt % Space to left of text. - \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below. - \kern3pt\vrule width\dimen2}% Space to right. - \hrule height\dimen2} - \hfil} - -% The @error{} command. -\def\error{\leavevmode\lower.7ex\copy\errorbox} - -% @tex ... @end tex escapes into raw Tex temporarily. -% One exception: @ is still an escape character, so that @end tex works. -% But \@ or @@ will get a plain tex @ character. - -\def\tex{\begingroup - \catcode `\\=0 \catcode `\{=1 \catcode `\}=2 - \catcode `\$=3 \catcode `\&=4 \catcode `\#=6 - \catcode `\^=7 \catcode `\_=8 \catcode `\~=13 \let~=\tie - \catcode `\%=14 - \catcode 43=12 % plus - \catcode`\"=12 - \catcode`\==12 - \catcode`\|=12 - \catcode`\<=12 - \catcode`\>=12 - \escapechar=`\\ - % - \let\b=\ptexb - \let\bullet=\ptexbullet - \let\c=\ptexc - \let\,=\ptexcomma - \let\.=\ptexdot - \let\dots=\ptexdots - \let\equiv=\ptexequiv - \let\!=\ptexexclam - \let\i=\ptexi - \let\{=\ptexlbrace - \let\+=\tabalign - \let\}=\ptexrbrace - \let\*=\ptexstar - \let\t=\ptext - % - \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}% - \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}% - \def\@{@}% -\let\Etex=\endgroup} - -% Define @lisp ... @endlisp. -% @lisp does a \begingroup so it can rebind things, -% including the definition of @endlisp (which normally is erroneous). - -% Amount to narrow the margins by for @lisp. -\newskip\lispnarrowing \lispnarrowing=0.4in - -% This is the definition that ^^M gets inside @lisp, @example, and other -% such environments. \null is better than a space, since it doesn't -% have any width. -\def\lisppar{\null\endgraf} - -% Make each space character in the input produce a normal interword -% space in the output. Don't allow a line break at this space, as this -% is used only in environments like @example, where each line of input -% should produce a line of output anyway. -% -{\obeyspaces % -\gdef\sepspaces{\obeyspaces\let =\tie}} - -% Define \obeyedspace to be our active space, whatever it is. This is -% for use in \parsearg. -{\sepspaces% -\global\let\obeyedspace= } - -% This space is always present above and below environments. -\newskip\envskipamount \envskipamount = 0pt - -% Make spacing and below environment symmetrical. We use \parskip here -% to help in doing that, since in @example-like environments \parskip -% is reset to zero; thus the \afterenvbreak inserts no space -- but the -% start of the next paragraph will insert \parskip -% -\def\aboveenvbreak{{\advance\envskipamount by \parskip -\endgraf \ifdim\lastskip<\envskipamount -\removelastskip \penalty-50 \vskip\envskipamount \fi}} - -\let\afterenvbreak = \aboveenvbreak - -% \nonarrowing is a flag. If "set", @lisp etc don't narrow margins. -\let\nonarrowing=\relax - -% @cartouche ... @end cartouche: draw rectangle w/rounded corners around -% environment contents. -\font\circle=lcircle10 -\newdimen\circthick -\newdimen\cartouter\newdimen\cartinner -\newskip\normbskip\newskip\normpskip\newskip\normlskip -\circthick=\fontdimen8\circle -% -\def\ctl{{\circle\char'013\hskip -6pt}}% 6pt from pl file: 1/2charwidth -\def\ctr{{\hskip 6pt\circle\char'010}} -\def\cbl{{\circle\char'012\hskip -6pt}} -\def\cbr{{\hskip 6pt\circle\char'011}} -\def\carttop{\hbox to \cartouter{\hskip\lskip - \ctl\leaders\hrule height\circthick\hfil\ctr - \hskip\rskip}} -\def\cartbot{\hbox to \cartouter{\hskip\lskip - \cbl\leaders\hrule height\circthick\hfil\cbr - \hskip\rskip}} -% -\newskip\lskip\newskip\rskip - -\long\def\cartouche{% -\begingroup - \lskip=\leftskip \rskip=\rightskip - \leftskip=0pt\rightskip=0pt %we want these *outside*. - \cartinner=\hsize \advance\cartinner by-\lskip - \advance\cartinner by-\rskip - \cartouter=\hsize - \advance\cartouter by 18.4pt % allow for 3pt kerns on either -% side, and for 6pt waste from -% each corner char, and rule thickness - \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip - % Flag to tell @lisp, etc., not to narrow margin. - \let\nonarrowing=\comment - \vbox\bgroup - \baselineskip=0pt\parskip=0pt\lineskip=0pt - \carttop - \hbox\bgroup - \hskip\lskip - \vrule\kern3pt - \vbox\bgroup - \hsize=\cartinner - \kern3pt - \begingroup - \baselineskip=\normbskip - \lineskip=\normlskip - \parskip=\normpskip - \vskip -\parskip -\def\Ecartouche{% - \endgroup - \kern3pt - \egroup - \kern3pt\vrule - \hskip\rskip - \egroup - \cartbot - \egroup -\endgroup -}} - - -% This macro is called at the beginning of all the @example variants, -% inside a group. -\def\nonfillstart{% - \aboveenvbreak - \inENV % This group ends at the end of the body - \hfuzz = 12pt % Don't be fussy - \sepspaces % Make spaces be word-separators rather than space tokens. - \singlespace - \let\par = \lisppar % don't ignore blank lines - \obeylines % each line of input is a line of output - \parskip = 0pt - \parindent = 0pt - \emergencystretch = 0pt % don't try to avoid overfull boxes - % @cartouche defines \nonarrowing to inhibit narrowing - % at next level down. - \ifx\nonarrowing\relax - \advance \leftskip by \lispnarrowing - \exdentamount=\lispnarrowing - \let\exdent=\nofillexdent - \let\nonarrowing=\relax - \fi -} - -% Define the \E... control sequence only if we are inside the particular -% environment, so the error checking in \end will work. -% -% To end an @example-like environment, we first end the paragraph (via -% \afterenvbreak's vertical glue), and then the group. That way we keep -% the zero \parskip that the environments set -- \parskip glue will be -% inserted at the beginning of the next paragraph in the document, after -% the environment. -% -\def\nonfillfinish{\afterenvbreak\endgroup} - -% @lisp: indented, narrowed, typewriter font. -\def\lisp{\begingroup - \nonfillstart - \let\Elisp = \nonfillfinish - \tt - \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special. - \gobble % eat return -} - -% @example: Same as @lisp. -\def\example{\begingroup \def\Eexample{\nonfillfinish\endgroup}\lisp} - -% @small... is usually equivalent to the non-small (@smallbook -% redefines). We must call \example (or whatever) last in the -% definition, since it reads the return following the @example (or -% whatever) command. -% -% This actually allows (for example) @end display inside an -% @smalldisplay. Too bad, but makeinfo will catch the error anyway. -% -\def\smalldisplay{\begingroup\def\Esmalldisplay{\nonfillfinish\endgroup}\display} -\def\smallexample{\begingroup\def\Esmallexample{\nonfillfinish\endgroup}\lisp} -\def\smallformat{\begingroup\def\Esmallformat{\nonfillfinish\endgroup}\format} -\def\smalllisp{\begingroup\def\Esmalllisp{\nonfillfinish\endgroup}\lisp} - -% Real @smallexample and @smalllisp (when @smallbook): use smaller fonts. -% Originally contributed by Pavel@xerox. -\def\smalllispx{\begingroup - \def\Esmalllisp{\nonfillfinish\endgroup}% - \def\Esmallexample{\nonfillfinish\endgroup}% - \smallfonts - \lisp -} - -% @display: same as @lisp except keep current font. -% -\def\display{\begingroup - \nonfillstart - \let\Edisplay = \nonfillfinish - \gobble -} - -% @smalldisplay (when @smallbook): @display plus smaller fonts. -% -\def\smalldisplayx{\begingroup - \def\Esmalldisplay{\nonfillfinish\endgroup}% - \smallfonts \rm - \display -} - -% @format: same as @display except don't narrow margins. -% -\def\format{\begingroup - \let\nonarrowing = t - \nonfillstart - \let\Eformat = \nonfillfinish - \gobble -} - -% @smallformat (when @smallbook): @format plus smaller fonts. -% -\def\smallformatx{\begingroup - \def\Esmallformat{\nonfillfinish\endgroup}% - \smallfonts \rm - \format -} - -% @flushleft (same as @format). -% -\def\flushleft{\begingroup \def\Eflushleft{\nonfillfinish\endgroup}\format} - -% @flushright. -% -\def\flushright{\begingroup - \let\nonarrowing = t - \nonfillstart - \let\Eflushright = \nonfillfinish - \advance\leftskip by 0pt plus 1fill - \gobble -} - -% @quotation does normal linebreaking (hence we can't use \nonfillstart) -% and narrows the margins. -% -\def\quotation{% - \begingroup\inENV %This group ends at the end of the @quotation body - {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip - \singlespace - \parindent=0pt - % We have retained a nonzero parskip for the environment, since we're - % doing normal filling. So to avoid extra space below the environment... - \def\Equotation{\parskip = 0pt \nonfillfinish}% - % - % @cartouche defines \nonarrowing to inhibit narrowing at next level down. - \ifx\nonarrowing\relax - \advance\leftskip by \lispnarrowing - \advance\rightskip by \lispnarrowing - \exdentamount = \lispnarrowing - \let\nonarrowing = \relax - \fi -} - - -\message{defuns,} -% @defun etc. - -% Allow user to change definition object font (\df) internally -\def\setdeffont #1 {\csname DEF#1\endcsname} - -\newskip\defbodyindent \defbodyindent=.4in -\newskip\defargsindent \defargsindent=50pt -\newskip\deftypemargin \deftypemargin=12pt -\newskip\deflastargmargin \deflastargmargin=18pt - -\newcount\parencount -% define \functionparens, which makes ( and ) and & do special things. -% \functionparens affects the group it is contained in. -\def\activeparens{% -\catcode`\(=\active \catcode`\)=\active \catcode`\&=\active -\catcode`\[=\active \catcode`\]=\active} - -% Make control sequences which act like normal parenthesis chars. -\let\lparen = ( \let\rparen = ) - -{\activeparens % Now, smart parens don't turn on until &foo (see \amprm) - -% Be sure that we always have a definition for `(', etc. For example, -% if the fn name has parens in it, \boldbrax will not be in effect yet, -% so TeX would otherwise complain about undefined control sequence. -\global\let(=\lparen \global\let)=\rparen -\global\let[=\lbrack \global\let]=\rbrack - -\gdef\functionparens{\boldbrax\let&=\amprm\parencount=0 } -\gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb} -% This is used to turn on special parens -% but make & act ordinary (given that it's active). -\gdef\boldbraxnoamp{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb\let&=\ampnr} - -% Definitions of (, ) and & used in args for functions. -% This is the definition of ( outside of all parentheses. -\gdef\oprm#1 {{\rm\char`\(}#1 \bf \let(=\opnested - \global\advance\parencount by 1 -} -% -% This is the definition of ( when already inside a level of parens. -\gdef\opnested{\char`\(\global\advance\parencount by 1 } -% -\gdef\clrm{% Print a paren in roman if it is taking us back to depth of 0. - % also in that case restore the outer-level definition of (. - \ifnum \parencount=1 {\rm \char `\)}\sl \let(=\oprm \else \char `\) \fi - \global\advance \parencount by -1 } -% If we encounter &foo, then turn on ()-hacking afterwards -\gdef\amprm#1 {{\rm\}\let(=\oprm \let)=\clrm\ } -% -\gdef\normalparens{\boldbrax\let&=\ampnr} -} % End of definition inside \activeparens -%% These parens (in \boldbrax) actually are a little bolder than the -%% contained text. This is especially needed for [ and ] -\def\opnr{{\sf\char`\(}\global\advance\parencount by 1 } -\def\clnr{{\sf\char`\)}\global\advance\parencount by -1 } -\let\ampnr = \& -\def\lbrb{{\bf\char`\[}} -\def\rbrb{{\bf\char`\]}} - -% Active &'s sneak into the index arguments, so make sure it's defined. -{ - \catcode`& = 13 - \global\let& = \ampnr -} - -% First, defname, which formats the header line itself. -% #1 should be the function name. -% #2 should be the type of definition, such as "Function". - -\def\defname #1#2{% -% Get the values of \leftskip and \rightskip as they were -% outside the @def... -\dimen2=\leftskip -\advance\dimen2 by -\defbodyindent -\noindent -\setbox0=\hbox{\hskip \deflastargmargin{\rm #2}\hskip \deftypemargin}% -\dimen0=\hsize \advance \dimen0 by -\wd0 % compute size for first line -\dimen1=\hsize \advance \dimen1 by -\defargsindent %size for continuations -\parshape 2 0in \dimen0 \defargsindent \dimen1 -% Now output arg 2 ("Function" or some such) -% ending at \deftypemargin from the right margin, -% but stuck inside a box of width 0 so it does not interfere with linebreaking -{% Adjust \hsize to exclude the ambient margins, -% so that \rightline will obey them. -\advance \hsize by -\dimen2 -\rlap{\rightline{{\rm #2}\hskip -1.25pc }}}% -% Make all lines underfull and no complaints: -\tolerance=10000 \hbadness=10000 -\advance\leftskip by -\defbodyindent -\exdentamount=\defbodyindent -{\df #1}\enskip % Generate function name -} - -% Actually process the body of a definition -% #1 should be the terminating control sequence, such as \Edefun. -% #2 should be the "another name" control sequence, such as \defunx. -% #3 should be the control sequence that actually processes the header, -% such as \defunheader. - -\def\defparsebody #1#2#3{\begingroup\inENV% Environment for definitionbody -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2{\begingroup\obeylines\activeparens\spacesplit#3}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup % -\catcode 61=\active % 61 is `=' -\obeylines\activeparens\spacesplit#3} - -% #1 is the \E... control sequence to end the definition (which we define). -% #2 is the \...x control sequence for consecutive fns (which we define). -% #3 is the control sequence to call to resume processing. -% #4, delimited by the space, is the class name. -% -\def\defmethparsebody#1#2#3#4 {\begingroup\inENV % -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2##1 {\begingroup\obeylines\activeparens\spacesplit{#3{##1}}}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup\obeylines\activeparens\spacesplit{#3{#4}}} - -% Used for @deftypemethod and @deftypeivar. -% #1 is the \E... control sequence to end the definition (which we define). -% #2 is the \...x control sequence for consecutive fns (which we define). -% #3 is the control sequence to call to resume processing. -% #4, delimited by a space, is the class name. -% #5 is the method's return type. -% -\def\deftypemethparsebody#1#2#3#4 #5 {\begingroup\inENV - \medbreak - \def#1{\endgraf\endgroup\medbreak}% - \def#2##1 ##2 {\begingroup\obeylines\activeparens\spacesplit{#3{##1}{##2}}}% - \parindent=0in - \advance\leftskip by \defbodyindent - \exdentamount=\defbodyindent - \begingroup\obeylines\activeparens\spacesplit{#3{#4}{#5}}} - -% Used for @deftypeop. The change from \deftypemethparsebody is an -% extra argument at the beginning which is the `category', instead of it -% being the hardwired string `Method' or `Instance Variable'. We have -% to account for this both in the \...x definition and in parsing the -% input at hand. Thus also need a control sequence (passed as #5) for -% the \E... definition to assign the category name to. -% -\def\deftypeopparsebody#1#2#3#4#5 #6 {\begingroup\inENV - \medbreak - \def#1{\endgraf\endgroup\medbreak}% - \def#2##1 ##2 ##3 {% - \def#4{##1}% - \begingroup\obeylines\activeparens\spacesplit{#3{##2}{##3}}}% - \parindent=0in - \advance\leftskip by \defbodyindent - \exdentamount=\defbodyindent - \begingroup\obeylines\activeparens\spacesplit{#3{#5}{#6}}} - -\def\defopparsebody #1#2#3#4#5 {\begingroup\inENV % -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2##1 ##2 {\def#4{##1}% -\begingroup\obeylines\activeparens\spacesplit{#3{##2}}}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup\obeylines\activeparens\spacesplit{#3{#5}}} - -% These parsing functions are similar to the preceding ones -% except that they do not make parens into active characters. -% These are used for "variables" since they have no arguments. - -\def\defvarparsebody #1#2#3{\begingroup\inENV% Environment for definitionbody -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2{\begingroup\obeylines\spacesplit#3}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup % -\catcode 61=\active % -\obeylines\spacesplit#3} - -% This is used for \def{tp,vr}parsebody. It could probably be used for -% some of the others, too, with some judicious conditionals. -% -\def\parsebodycommon#1#2#3{% - \begingroup\inENV % - \medbreak % - % Define the end token that this defining construct specifies - % so that it will exit this group. - \def#1{\endgraf\endgroup\medbreak}% - \def#2##1 {\begingroup\obeylines\spacesplit{#3{##1}}}% - \parindent=0in - \advance\leftskip by \defbodyindent - \exdentamount=\defbodyindent - \begingroup\obeylines -} - -\def\defvrparsebody#1#2#3#4 {% - \parsebodycommon{#1}{#2}{#3}% - \spacesplit{#3{#4}}% -} - -% This loses on `@deftp {Data Type} {struct termios}' -- it thinks the -% type is just `struct', because we lose the braces in `{struct -% termios}' when \spacesplit reads its undelimited argument. Sigh. -% \let\deftpparsebody=\defvrparsebody -% -% So, to get around this, we put \empty in with the type name. That -% way, TeX won't find exactly `{...}' as an undelimited argument, and -% won't strip off the braces. -% -\def\deftpparsebody #1#2#3#4 {% - \parsebodycommon{#1}{#2}{#3}% - \spacesplit{\parsetpheaderline{#3{#4}}}\empty -} - -% Fine, but then we have to eventually remove the \empty *and* the -% braces (if any). That's what this does. -% -\def\removeemptybraces\empty#1\relax{#1} - -% After \spacesplit has done its work, this is called -- #1 is the final -% thing to call, #2 the type name (which starts with \empty), and #3 -% (which might be empty) the arguments. -% -\def\parsetpheaderline#1#2#3{% - #1{\removeemptybraces#2\relax}{#3}% -}% - -\def\defopvarparsebody #1#2#3#4#5 {\begingroup\inENV % -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2##1 ##2 {\def#4{##1}% -\begingroup\obeylines\spacesplit{#3{##2}}}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup\obeylines\spacesplit{#3{#5}}} - -% Split up #2 at the first space token. -% call #1 with two arguments: -% the first is all of #2 before the space token, -% the second is all of #2 after that space token. -% If #2 contains no space token, all of it is passed as the first arg -% and the second is passed as empty. - -{\obeylines -\gdef\spacesplit#1#2^^M{\endgroup\spacesplitfoo{#1}#2 \relax\spacesplitfoo}% -\long\gdef\spacesplitfoo#1#2 #3#4\spacesplitfoo{% -\ifx\relax #3% -#1{#2}{}\else #1{#2}{#3#4}\fi}} - -% So much for the things common to all kinds of definitions. - -% Define @defun. - -% First, define the processing that is wanted for arguments of \defun -% Use this to expand the args and terminate the paragraph they make up - -\def\defunargs#1{\functionparens \sl -% Expand, preventing hyphenation at `-' chars. -% Note that groups don't affect changes in \hyphenchar. -% Set the font temporarily and use \font in case \setfont made \tensl a macro. -{\tensl\hyphenchar\font=0}% -#1% -{\tensl\hyphenchar\font=45}% -\ifnum\parencount=0 \else \errmessage{Unbalanced parentheses in @def}\fi% -\interlinepenalty=10000 -\advance\rightskip by 0pt plus 1fil -\endgraf\nobreak\vskip -\parskip\nobreak -} - -\def\deftypefunargs #1{% -% Expand, preventing hyphenation at `-' chars. -% Note that groups don't affect changes in \hyphenchar. -% Use \boldbraxnoamp, not \functionparens, so that & is not special. -\boldbraxnoamp -\tclose{#1}% avoid \code because of side effects on active chars -\interlinepenalty=10000 -\advance\rightskip by 0pt plus 1fil -\endgraf\nobreak\vskip -\parskip\nobreak -} - -% Do complete processing of one @defun or @defunx line already parsed. - -% @deffn Command forward-char nchars - -\def\deffn{\defmethparsebody\Edeffn\deffnx\deffnheader} - -\def\deffnheader #1#2#3{\doind {fn}{\code{#2}}% -\begingroup\defname {#2}{#1}\defunargs{#3}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @defun == @deffn Function - -\def\defun{\defparsebody\Edefun\defunx\defunheader} - -\def\defunheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index -\begingroup\defname {#1}{\putwordDeffunc}% -\defunargs {#2}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @deftypefun int foobar (int @var{foo}, float @var{bar}) - -\def\deftypefun{\defparsebody\Edeftypefun\deftypefunx\deftypefunheader} - -% #1 is the data type. #2 is the name and args. -\def\deftypefunheader #1#2{\deftypefunheaderx{#1}#2 \relax} -% #1 is the data type, #2 the name, #3 the args. -\def\deftypefunheaderx #1#2 #3\relax{% -\doind {fn}{\code{#2}}% Make entry in function index -\begingroup\defname {\defheaderxcond#1\relax$$$#2}{\putwordDeftypefun}% -\deftypefunargs {#3}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @deftypefn {Library Function} int foobar (int @var{foo}, float @var{bar}) - -\def\deftypefn{\defmethparsebody\Edeftypefn\deftypefnx\deftypefnheader} - -% \defheaderxcond#1\relax$$$ -% puts #1 in @code, followed by a space, but does nothing if #1 is null. -\def\defheaderxcond#1#2$$${\ifx#1\relax\else\code{#1#2} \fi} - -% #1 is the classification. #2 is the data type. #3 is the name and args. -\def\deftypefnheader #1#2#3{\deftypefnheaderx{#1}{#2}#3 \relax} -% #1 is the classification, #2 the data type, #3 the name, #4 the args. -\def\deftypefnheaderx #1#2#3 #4\relax{% -\doind {fn}{\code{#3}}% Make entry in function index -\begingroup -\normalparens % notably, turn off `&' magic, which prevents -% at least some C++ text from working -\defname {\defheaderxcond#2\relax$$$#3}{#1}% -\deftypefunargs {#4}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @defmac == @deffn Macro - -\def\defmac{\defparsebody\Edefmac\defmacx\defmacheader} - -\def\defmacheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index -\begingroup\defname {#1}{\putwordDefmac}% -\defunargs {#2}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @defspec == @deffn Special Form - -\def\defspec{\defparsebody\Edefspec\defspecx\defspecheader} - -\def\defspecheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index -\begingroup\defname {#1}{\putwordDefspec}% -\defunargs {#2}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @defop CATEGORY CLASS OPERATION ARG... -% -\def\defop #1 {\def\defoptype{#1}% -\defopparsebody\Edefop\defopx\defopheader\defoptype} -% -\def\defopheader#1#2#3{% -\dosubind {fn}{\code{#2}}{\putwordon\ #1}% Make entry in function index -\begingroup\defname {#2}{\defoptype\ \putwordon\ #1}% -\defunargs {#3}\endgroup % -} - -% @deftypeop CATEGORY CLASS TYPE OPERATION ARG... -% -\def\deftypeop #1 {\def\deftypeopcategory{#1}% - \deftypeopparsebody\Edeftypeop\deftypeopx\deftypeopheader - \deftypeopcategory} -% -% #1 is the class name, #2 the data type, #3 the operation name, #4 the args. -\def\deftypeopheader#1#2#3#4{% - \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index - \begingroup - \defname{\defheaderxcond#2\relax$$$#3} - {\deftypeopcategory\ \putwordon\ \code{#1}}% - \deftypefunargs{#4}% - \endgroup -} - -% @deftypemethod CLASS TYPE METHOD ARG... -% -\def\deftypemethod{% - \deftypemethparsebody\Edeftypemethod\deftypemethodx\deftypemethodheader} -% -% #1 is the class name, #2 the data type, #3 the method name, #4 the args. -\def\deftypemethodheader#1#2#3#4{% - \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index - \begingroup - \defname{\defheaderxcond#2\relax$$$#3}{\putwordMethodon\ \code{#1}}% - \deftypefunargs{#4}% - \endgroup -} - -% @deftypeivar CLASS TYPE VARNAME -% -\def\deftypeivar{% - \deftypemethparsebody\Edeftypeivar\deftypeivarx\deftypeivarheader} -% -% #1 is the class name, #2 the data type, #3 the variable name. -\def\deftypeivarheader#1#2#3{% - \dosubind{vr}{\code{#3}}{\putwordof\ \code{#1}}% entry in variable index - \begingroup - \defname{\defheaderxcond#2\relax$$$#3} - {\putwordInstanceVariableof\ \code{#1}}% - \defvarargs{#3}% - \endgroup -} - -% @defmethod == @defop Method -% -\def\defmethod{\defmethparsebody\Edefmethod\defmethodx\defmethodheader} -% -% #1 is the class name, #2 the method name, #3 the args. -\def\defmethodheader#1#2#3{% - \dosubind{fn}{\code{#2}}{\putwordon\ \code{#1}}% entry in function index - \begingroup - \defname{#2}{\putwordMethodon\ \code{#1}}% - \defunargs{#3}% - \endgroup -} - -% @defcv {Class Option} foo-class foo-flag - -\def\defcv #1 {\def\defcvtype{#1}% -\defopvarparsebody\Edefcv\defcvx\defcvarheader\defcvtype} - -\def\defcvarheader #1#2#3{% -\dosubind {vr}{\code{#2}}{\putwordof\ #1}% Make entry in var index -\begingroup\defname {#2}{\defcvtype\ \putwordof\ #1}% -\defvarargs {#3}\endgroup % -} - -% @defivar CLASS VARNAME == @defcv {Instance Variable} CLASS VARNAME -% -\def\defivar{\defvrparsebody\Edefivar\defivarx\defivarheader} -% -\def\defivarheader#1#2#3{% - \dosubind {vr}{\code{#2}}{\putwordof\ #1}% entry in var index - \begingroup - \defname{#2}{\putwordInstanceVariableof\ #1}% - \defvarargs{#3}% - \endgroup -} - -% @defvar -% First, define the processing that is wanted for arguments of @defvar. -% This is actually simple: just print them in roman. -% This must expand the args and terminate the paragraph they make up -\def\defvarargs #1{\normalparens #1% -\interlinepenalty=10000 -\endgraf\nobreak\vskip -\parskip\nobreak} - -% @defvr Counter foo-count - -\def\defvr{\defvrparsebody\Edefvr\defvrx\defvrheader} - -\def\defvrheader #1#2#3{\doind {vr}{\code{#2}}% -\begingroup\defname {#2}{#1}\defvarargs{#3}\endgroup} - -% @defvar == @defvr Variable - -\def\defvar{\defvarparsebody\Edefvar\defvarx\defvarheader} - -\def\defvarheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index -\begingroup\defname {#1}{\putwordDefvar}% -\defvarargs {#2}\endgroup % -} - -% @defopt == @defvr {User Option} - -\def\defopt{\defvarparsebody\Edefopt\defoptx\defoptheader} - -\def\defoptheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index -\begingroup\defname {#1}{\putwordDefopt}% -\defvarargs {#2}\endgroup % -} - -% @deftypevar int foobar - -\def\deftypevar{\defvarparsebody\Edeftypevar\deftypevarx\deftypevarheader} - -% #1 is the data type. #2 is the name, perhaps followed by text that -% is actually part of the data type, which should not be put into the index. -\def\deftypevarheader #1#2{% -\dovarind#2 \relax% Make entry in variables index -\begingroup\defname {\defheaderxcond#1\relax$$$#2}{\putwordDeftypevar}% -\interlinepenalty=10000 -\endgraf\nobreak\vskip -\parskip\nobreak -\endgroup} -\def\dovarind#1 #2\relax{\doind{vr}{\code{#1}}} - -% @deftypevr {Global Flag} int enable - -\def\deftypevr{\defvrparsebody\Edeftypevr\deftypevrx\deftypevrheader} - -\def\deftypevrheader #1#2#3{\dovarind#3 \relax% -\begingroup\defname {\defheaderxcond#2\relax$$$#3}{#1} -\interlinepenalty=10000 -\endgraf\nobreak\vskip -\parskip\nobreak -\endgroup} - -% Now define @deftp -% Args are printed in bold, a slight difference from @defvar. - -\def\deftpargs #1{\bf \defvarargs{#1}} - -% @deftp Class window height width ... - -\def\deftp{\deftpparsebody\Edeftp\deftpx\deftpheader} - -\def\deftpheader #1#2#3{\doind {tp}{\code{#2}}% -\begingroup\defname {#2}{#1}\deftpargs{#3}\endgroup} - -% These definitions are used if you use @defunx (etc.) -% anywhere other than immediately after a @defun or @defunx. -% -\def\defcvx#1 {\errmessage{@defcvx in invalid context}} -\def\deffnx#1 {\errmessage{@deffnx in invalid context}} -\def\defivarx#1 {\errmessage{@defivarx in invalid context}} -\def\defmacx#1 {\errmessage{@defmacx in invalid context}} -\def\defmethodx#1 {\errmessage{@defmethodx in invalid context}} -\def\defoptx #1 {\errmessage{@defoptx in invalid context}} -\def\defopx#1 {\errmessage{@defopx in invalid context}} -\def\defspecx#1 {\errmessage{@defspecx in invalid context}} -\def\deftpx#1 {\errmessage{@deftpx in invalid context}} -\def\deftypefnx#1 {\errmessage{@deftypefnx in invalid context}} -\def\deftypefunx#1 {\errmessage{@deftypefunx in invalid context}} -\def\deftypeivarx#1 {\errmessage{@deftypeivarx in invalid context}} -\def\deftypemethodx#1 {\errmessage{@deftypemethodx in invalid context}} -\def\deftypeopx#1 {\errmessage{@deftypeopx in invalid context}} -\def\deftypevarx#1 {\errmessage{@deftypevarx in invalid context}} -\def\deftypevrx#1 {\errmessage{@deftypevrx in invalid context}} -\def\defunx#1 {\errmessage{@defunx in invalid context}} -\def\defvarx#1 {\errmessage{@defvarx in invalid context}} -\def\defvrx#1 {\errmessage{@defvrx in invalid context}} - - -\message{macros,} -% @macro. - -% To do this right we need a feature of e-TeX, \scantokens, -% which we arrange to emulate with a temporary file in ordinary TeX. -\ifx\eTeXversion\undefined - \newwrite\macscribble - \def\scanmacro#1{% - \begingroup \newlinechar`\^^M - % Undo catcode changes of \startcontents and \doprintindex - \catcode`\@=0 \catcode`\\=12 \escapechar=`\@ - % Append \endinput to make sure that TeX does not see the ending newline. - \toks0={#1\endinput}% - \immediate\openout\macscribble=\jobname.tmp - \immediate\write\macscribble{\the\toks0}% - \immediate\closeout\macscribble - \let\xeatspaces\eatspaces - \input \jobname.tmp - \endgroup -} -\else -\def\scanmacro#1{% -\begingroup \newlinechar`\^^M -% Undo catcode changes of \startcontents and \doprintindex -\catcode`\@=0 \catcode`\\=12 \escapechar=`\@ -\let\xeatspaces\eatspaces\scantokens{#1\endinput}\endgroup} -\fi - -\newcount\paramno % Count of parameters -\newtoks\macname % Macro name -\newif\ifrecursive % Is it recursive? -\def\macrolist{} % List of all defined macros in the form - % \do\macro1\do\macro2... - -% Utility routines. -% Thisdoes \let #1 = #2, except with \csnames. -\def\cslet#1#2{% -\expandafter\expandafter -\expandafter\let -\expandafter\expandafter -\csname#1\endcsname -\csname#2\endcsname} - -% Trim leading and trailing spaces off a string. -% Concepts from aro-bend problem 15 (see CTAN). -{\catcode`\@=11 -\gdef\eatspaces #1{\expandafter\trim@\expandafter{#1 }} -\gdef\trim@ #1{\trim@@ @#1 @ #1 @ @@} -\gdef\trim@@ #1@ #2@ #3@@{\trim@@@\empty #2 @} -\def\unbrace#1{#1} -\unbrace{\gdef\trim@@@ #1 } #2@{#1} -} - -% Trim a single trailing ^^M off a string. -{\catcode`\^^M=12\catcode`\Q=3% -\gdef\eatcr #1{\eatcra #1Q^^MQ}% -\gdef\eatcra#1^^MQ{\eatcrb#1Q}% -\gdef\eatcrb#1Q#2Q{#1}% -} - -% Macro bodies are absorbed as an argument in a context where -% all characters are catcode 10, 11 or 12, except \ which is active -% (as in normal texinfo). It is necessary to change the definition of \. - -% It's necessary to have hard CRs when the macro is executed. This is -% done by making ^^M (\endlinechar) catcode 12 when reading the macro -% body, and then making it the \newlinechar in \scanmacro. - -\def\macrobodyctxt{% - \catcode`\~=12 - \catcode`\^=12 - \catcode`\_=12 - \catcode`\|=12 - \catcode`\<=12 - \catcode`\>=12 - \catcode`\+=12 - \catcode`\{=12 - \catcode`\}=12 - \catcode`\@=12 - \catcode`\^^M=12 - \usembodybackslash} - -\def\macroargctxt{% - \catcode`\~=12 - \catcode`\^=12 - \catcode`\_=12 - \catcode`\|=12 - \catcode`\<=12 - \catcode`\>=12 - \catcode`\+=12 - \catcode`\@=12 - \catcode`\\=12} - -% \mbodybackslash is the definition of \ in @macro bodies. -% It maps \foo\ => \csname macarg.foo\endcsname => #N -% where N is the macro parameter number. -% We define \csname macarg.\endcsname to be \realbackslash, so -% \\ in macro replacement text gets you a backslash. - -{\catcode`@=0 @catcode`@\=@active - @gdef@usembodybackslash{@let\=@mbodybackslash} - @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname} -} -\expandafter\def\csname macarg.\endcsname{\realbackslash} - -\def\macro{\recursivefalse\parsearg\macroxxx} -\def\rmacro{\recursivetrue\parsearg\macroxxx} - -\def\macroxxx#1{% - \getargs{#1}% now \macname is the macname and \argl the arglist - \ifx\argl\empty % no arguments - \paramno=0% - \else - \expandafter\parsemargdef \argl;% - \fi - \if1\csname ismacro.\the\macname\endcsname - \message{Warning: redefining \the\macname}% - \else - \expandafter\ifx\csname \the\macname\endcsname \relax - \else \errmessage{The name \the\macname\space is reserved}\fi - \global\cslet{macsave.\the\macname}{\the\macname}% - \global\expandafter\let\csname ismacro.\the\macname\endcsname=1% - % Add the macroname to \macrolist - \toks0 = \expandafter{\macrolist\do}% - \xdef\macrolist{\the\toks0 - \expandafter\noexpand\csname\the\macname\endcsname}% - \fi - \begingroup \macrobodyctxt - \ifrecursive \expandafter\parsermacbody - \else \expandafter\parsemacbody - \fi} - -\def\unmacro{\parsearg\unmacroxxx} -\def\unmacroxxx#1{% - \if1\csname ismacro.#1\endcsname - \global\cslet{#1}{macsave.#1}% - \global\expandafter\let \csname ismacro.#1\endcsname=0% - % Remove the macro name from \macrolist - \begingroup - \edef\tempa{\expandafter\noexpand\csname#1\endcsname}% - \def\do##1{% - \def\tempb{##1}% - \ifx\tempa\tempb - % remove this - \else - \toks0 = \expandafter{\newmacrolist\do}% - \edef\newmacrolist{\the\toks0\expandafter\noexpand\tempa}% - \fi}% - \def\newmacrolist{}% - % Execute macro list to define \newmacrolist - \macrolist - \global\let\macrolist\newmacrolist - \endgroup - \else - \errmessage{Macro #1 not defined}% - \fi -} - -% This makes use of the obscure feature that if the last token of a -% is #, then the preceding argument is delimited by -% an opening brace, and that opening brace is not consumed. -\def\getargs#1{\getargsxxx#1{}} -\def\getargsxxx#1#{\getmacname #1 \relax\getmacargs} -\def\getmacname #1 #2\relax{\macname={#1}} -\def\getmacargs#1{\def\argl{#1}} - -% Parse the optional {params} list. Set up \paramno and \paramlist -% so \defmacro knows what to do. Define \macarg.blah for each blah -% in the params list, to be ##N where N is the position in that list. -% That gets used by \mbodybackslash (above). - -% We need to get `macro parameter char #' into several definitions. -% The technique used is stolen from LaTeX: let \hash be something -% unexpandable, insert that wherever you need a #, and then redefine -% it to # just before using the token list produced. -% -% The same technique is used to protect \eatspaces till just before -% the macro is used. - -\def\parsemargdef#1;{\paramno=0\def\paramlist{}% - \let\hash\relax\let\xeatspaces\relax\parsemargdefxxx#1,;,} -\def\parsemargdefxxx#1,{% - \if#1;\let\next=\relax - \else \let\next=\parsemargdefxxx - \advance\paramno by 1% - \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname - {\xeatspaces{\hash\the\paramno}}% - \edef\paramlist{\paramlist\hash\the\paramno,}% - \fi\next} - -% These two commands read recursive and nonrecursive macro bodies. -% (They're different since rec and nonrec macros end differently.) - -\long\def\parsemacbody#1@end macro% -{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}% -\long\def\parsermacbody#1@end rmacro% -{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}% - -% This defines the macro itself. There are six cases: recursive and -% nonrecursive macros of zero, one, and many arguments. -% Much magic with \expandafter here. -% \xdef is used so that macro definitions will survive the file -% they're defined in; @include reads the file inside a group. -\def\defmacro{% - \let\hash=##% convert placeholders to macro parameter chars - \ifrecursive - \ifcase\paramno - % 0 - \expandafter\xdef\csname\the\macname\endcsname{% - \noexpand\scanmacro{\temp}}% - \or % 1 - \expandafter\xdef\csname\the\macname\endcsname{% - \bgroup\noexpand\macroargctxt - \noexpand\braceorline - \expandafter\noexpand\csname\the\macname xxx\endcsname}% - \expandafter\xdef\csname\the\macname xxx\endcsname##1{% - \egroup\noexpand\scanmacro{\temp}}% - \else % many - \expandafter\xdef\csname\the\macname\endcsname{% - \bgroup\noexpand\macroargctxt - \noexpand\csname\the\macname xx\endcsname}% - \expandafter\xdef\csname\the\macname xx\endcsname##1{% - \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}% - \expandafter\expandafter - \expandafter\xdef - \expandafter\expandafter - \csname\the\macname xxx\endcsname - \paramlist{\egroup\noexpand\scanmacro{\temp}}% - \fi - \else - \ifcase\paramno - % 0 - \expandafter\xdef\csname\the\macname\endcsname{% - \noexpand\norecurse{\the\macname}% - \noexpand\scanmacro{\temp}\egroup}% - \or % 1 - \expandafter\xdef\csname\the\macname\endcsname{% - \bgroup\noexpand\macroargctxt - \noexpand\braceorline - \expandafter\noexpand\csname\the\macname xxx\endcsname}% - \expandafter\xdef\csname\the\macname xxx\endcsname##1{% - \egroup - \noexpand\norecurse{\the\macname}% - \noexpand\scanmacro{\temp}\egroup}% - \else % many - \expandafter\xdef\csname\the\macname\endcsname{% - \bgroup\noexpand\macroargctxt - \expandafter\noexpand\csname\the\macname xx\endcsname}% - \expandafter\xdef\csname\the\macname xx\endcsname##1{% - \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}% - \expandafter\expandafter - \expandafter\xdef - \expandafter\expandafter - \csname\the\macname xxx\endcsname - \paramlist{% - \egroup - \noexpand\norecurse{\the\macname}% - \noexpand\scanmacro{\temp}\egroup}% - \fi - \fi} - -\def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}} - -% \braceorline decides whether the next nonwhitespace character is a -% {. If so it reads up to the closing }, if not, it reads the whole -% line. Whatever was read is then fed to the next control sequence -% as an argument (by \parsebrace or \parsearg) -\def\braceorline#1{\let\next=#1\futurelet\nchar\braceorlinexxx} -\def\braceorlinexxx{% - \ifx\nchar\bgroup\else - \expandafter\parsearg - \fi \next} - -% We mant to disable all macros during \shipout so that they are not -% expanded by \write. -\def\turnoffmacros{\begingroup \def\do##1{\let\noexpand##1=\relax}% - \edef\next{\macrolist}\expandafter\endgroup\next} - - -% @alias. -% We need some trickery to remove the optional spaces around the equal -% sign. Just make them active and then expand them all to nothing. -\def\alias{\begingroup\obeyspaces\parsearg\aliasxxx} -\def\aliasxxx #1{\aliasyyy#1\relax} -\def\aliasyyy #1=#2\relax{\ignoreactivespaces -\edef\next{\global\let\expandafter\noexpand\csname#1\endcsname=% - \expandafter\noexpand\csname#2\endcsname}% -\expandafter\endgroup\next} - - -\message{cross references,} -% @xref etc. - -\newwrite\auxfile - -\newif\ifhavexrefs % True if xref values are known. -\newif\ifwarnedxrefs % True if we warned once that they aren't known. - -% @inforef is relatively simple. -\def\inforef #1{\inforefzzz #1,,,,**} -\def\inforefzzz #1,#2,#3,#4**{\putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}}, - node \samp{\ignorespaces#1{}}} - -% @node's job is to define \lastnode. -\def\node{\ENVcheck\parsearg\nodezzz} -\def\nodezzz#1{\nodexxx [#1,]} -\def\nodexxx[#1,#2]{\gdef\lastnode{#1}} -\let\nwnode=\node -\let\lastnode=\relax - -% The sectioning commands (@chapter, etc.) call these. -\def\donoderef{% - \ifx\lastnode\relax\else - \expandafter\expandafter\expandafter\setref{\lastnode}% - {Ysectionnumberandtype}% - \global\let\lastnode=\relax - \fi -} -\def\unnumbnoderef{% - \ifx\lastnode\relax\else - \expandafter\expandafter\expandafter\setref{\lastnode}{Ynothing}% - \global\let\lastnode=\relax - \fi -} -\def\appendixnoderef{% - \ifx\lastnode\relax\else - \expandafter\expandafter\expandafter\setref{\lastnode}% - {Yappendixletterandtype}% - \global\let\lastnode=\relax - \fi -} - - -% @anchor{NAME} -- define xref target at arbitrary point. -% -\newcount\savesfregister -\gdef\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi} -\gdef\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi} -\gdef\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces} - -% \setref{NAME}{SNT} defines a cross-reference point NAME, namely -% NAME-title, NAME-pg, and NAME-SNT. Called from \foonoderef. We have -% to set \indexdummies so commands such as @code in a section title -% aren't expanded. It would be nicer not to expand the titles in the -% first place, but there's so many layers that that is hard to do. -% -\def\setref#1#2{{% - \indexdummies - \pdfmkdest{#1}% - \dosetq{#1-title}{Ytitle}% - \dosetq{#1-pg}{Ypagenumber}% - \dosetq{#1-snt}{#2}% -}} - -% @xref, @pxref, and @ref generate cross-references. For \xrefX, #1 is -% the node name, #2 the name of the Info cross-reference, #3 the printed -% node name, #4 the name of the Info file, #5 the name of the printed -% manual. All but the node name can be omitted. -% -\def\pxref#1{\putwordsee{} \xrefX[#1,,,,,,,]} -\def\xref#1{\putwordSee{} \xrefX[#1,,,,,,,]} -\def\ref#1{\xrefX[#1,,,,,,,]} -\def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup - \unsepspaces - \def\printedmanual{\ignorespaces #5}% - \def\printednodename{\ignorespaces #3}% - \setbox1=\hbox{\printedmanual}% - \setbox0=\hbox{\printednodename}% - \ifdim \wd0 = 0pt - % No printed node name was explicitly given. - \expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax - % Use the node name inside the square brackets. - \def\printednodename{\ignorespaces #1}% - \else - % Use the actual chapter/section title appear inside - % the square brackets. Use the real section title if we have it. - \ifdim \wd1 > 0pt - % It is in another manual, so we don't have it. - \def\printednodename{\ignorespaces #1}% - \else - \ifhavexrefs - % We know the real title if we have the xref values. - \def\printednodename{\refx{#1-title}{}}% - \else - % Otherwise just copy the Info node name. - \def\printednodename{\ignorespaces #1}% - \fi% - \fi - \fi - \fi - % - % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not - % insert empty discretionaries after hyphens, which means that it will - % not find a line break at a hyphen in a node names. Since some manuals - % are best written with fairly long node names, containing hyphens, this - % is a loss. Therefore, we give the text of the node name again, so it - % is as if TeX is seeing it for the first time. - \ifpdf - \leavevmode - \getfilename{#4}% - \ifnum\filenamelength>0 - \startlink attr{/Border [0 0 0]}% - goto file{\the\filename.pdf} name{#1@}% - \else - \startlink attr{/Border [0 0 0]}% - goto name{#1@}% - \fi - \linkcolor - \fi - % - \ifdim \wd1 > 0pt - \putwordsection{} ``\printednodename'' \putwordin{} \cite{\printedmanual}% - \else - % _ (for example) has to be the character _ for the purposes of the - % control sequence corresponding to the node, but it has to expand - % into the usual \leavevmode...\vrule stuff for purposes of - % printing. So we \turnoffactive for the \refx-snt, back on for the - % printing, back off for the \refx-pg. - {\normalturnoffactive - % Only output a following space if the -snt ref is nonempty; for - % @unnumbered and @anchor, it won't be. - \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}% - \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi - }% - % [mynode], - [\printednodename],\space - % page 3 - \turnoffactive \putwordpage\tie\refx{#1-pg}{}% - \fi - \endlink -\endgroup} - -% \dosetq is the interface for calls from other macros - -% Use \normalturnoffactive so that punctuation chars such as underscore -% and backslash work in node names. (\turnoffactive doesn't do \.) -\def\dosetq#1#2{% - {\let\folio=0% - \normalturnoffactive - \edef\next{\write\auxfile{\internalsetq{#1}{#2}}}% - \iflinks - \next - \fi - }% -} - -% \internalsetq {foo}{page} expands into -% CHARACTERS 'xrdef {foo}{...expansion of \Ypage...} -% When the aux file is read, ' is the escape character - -\def\internalsetq #1#2{'xrdef {#1}{\csname #2\endcsname}} - -% Things to be expanded by \internalsetq - -\def\Ypagenumber{\folio} - -\def\Ytitle{\thissection} - -\def\Ynothing{} - -\def\Ysectionnumberandtype{% -\ifnum\secno=0 \putwordChapter\xreftie\the\chapno % -\else \ifnum \subsecno=0 \putwordSection\xreftie\the\chapno.\the\secno % -\else \ifnum \subsubsecno=0 % -\putwordSection\xreftie\the\chapno.\the\secno.\the\subsecno % -\else % -\putwordSection\xreftie\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno % -\fi \fi \fi } - -\def\Yappendixletterandtype{% -\ifnum\secno=0 \putwordAppendix\xreftie'char\the\appendixno{}% -\else \ifnum \subsecno=0 \putwordSection\xreftie'char\the\appendixno.\the\secno % -\else \ifnum \subsubsecno=0 % -\putwordSection\xreftie'char\the\appendixno.\the\secno.\the\subsecno % -\else % -\putwordSection\xreftie'char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno % -\fi \fi \fi } - -\gdef\xreftie{'tie} - -% Use TeX 3.0's \inputlineno to get the line number, for better error -% messages, but if we're using an old version of TeX, don't do anything. -% -\ifx\inputlineno\thisisundefined - \let\linenumber = \empty % Non-3.0. -\else - \def\linenumber{\the\inputlineno:\space} -\fi - -% Define \refx{NAME}{SUFFIX} to reference a cross-reference string named NAME. -% If its value is nonempty, SUFFIX is output afterward. - -\def\refx#1#2{% - \expandafter\ifx\csname X#1\endcsname\relax - % If not defined, say something at least. - \angleleft un\-de\-fined\angleright - \iflinks - \ifhavexrefs - \message{\linenumber Undefined cross reference `#1'.}% - \else - \ifwarnedxrefs\else - \global\warnedxrefstrue - \message{Cross reference values unknown; you must run TeX again.}% - \fi - \fi - \fi - \else - % It's defined, so just use it. - \csname X#1\endcsname - \fi - #2% Output the suffix in any case. -} - -% This is the macro invoked by entries in the aux file. -% -\def\xrdef#1{\begingroup - % Reenable \ as an escape while reading the second argument. - \catcode`\\ = 0 - \afterassignment\endgroup - \expandafter\gdef\csname X#1\endcsname -} - -% Read the last existing aux file, if any. No error if none exists. -\def\readauxfile{\begingroup - \catcode`\^^@=\other - \catcode`\^^A=\other - \catcode`\^^B=\other - \catcode`\^^C=\other - \catcode`\^^D=\other - \catcode`\^^E=\other - \catcode`\^^F=\other - \catcode`\^^G=\other - \catcode`\^^H=\other - \catcode`\^^K=\other - \catcode`\^^L=\other - \catcode`\^^N=\other - \catcode`\^^P=\other - \catcode`\^^Q=\other - \catcode`\^^R=\other - \catcode`\^^S=\other - \catcode`\^^T=\other - \catcode`\^^U=\other - \catcode`\^^V=\other - \catcode`\^^W=\other - \catcode`\^^X=\other - \catcode`\^^Z=\other - \catcode`\^^[=\other - \catcode`\^^\=\other - \catcode`\^^]=\other - \catcode`\^^^=\other - \catcode`\^^_=\other - \catcode`\@=\other - \catcode`\^=\other - % It was suggested to define this as 7, which would allow ^^e4 etc. - % in xref tags, i.e., node names. But since ^^e4 notation isn't - % supported in the main text, it doesn't seem desirable. Furthermore, - % that is not enough: for node names that actually contain a ^ - % character, we would end up writing a line like this: 'xrdef {'hat - % b-title}{'hat b} and \xrdef does a \csname...\endcsname on the first - % argument, and \hat is not an expandable control sequence. It could - % all be worked out, but why? Either we support ^^ or we don't. - % - % The other change necessary for this was to define \auxhat: - % \def\auxhat{\def^{'hat }}% extra space so ok if followed by letter - % and then to call \auxhat in \setq. - % - \catcode`\~=\other - \catcode`\[=\other - \catcode`\]=\other - \catcode`\"=\other - \catcode`\_=\other - \catcode`\|=\other - \catcode`\<=\other - \catcode`\>=\other - \catcode`\$=\other - \catcode`\#=\other - \catcode`\&=\other - \catcode`+=\other % avoid \+ for paranoia even though we've turned it off - % Make the characters 128-255 be printing characters - {% - \count 1=128 - \def\loop{% - \catcode\count 1=\other - \advance\count 1 by 1 - \ifnum \count 1<256 \loop \fi - }% - }% - % The aux file uses ' as the escape (for now). - % Turn off \ as an escape so we do not lose on - % entries which were dumped with control sequences in their names. - % For example, 'xrdef {$\leq $-fun}{page ...} made by @defun ^^ - % Reference to such entries still does not work the way one would wish, - % but at least they do not bomb out when the aux file is read in. - \catcode`\{=1 - \catcode`\}=2 - \catcode`\%=\other - \catcode`\'=0 - \catcode`\\=\other - % - \openin 1 \jobname.aux - \ifeof 1 \else - \closein 1 - \input \jobname.aux - \global\havexrefstrue - \global\warnedobstrue - \fi - % Open the new aux file. TeX will close it automatically at exit. - \openout\auxfile=\jobname.aux -\endgroup} - - -% Footnotes. - -\newcount \footnoteno - -% The trailing space in the following definition for supereject is -% vital for proper filling; pages come out unaligned when you do a -% pagealignmacro call if that space before the closing brace is -% removed. (Generally, numeric constants should always be followed by a -% space to prevent strange expansion errors.) -\def\supereject{\par\penalty -20000\footnoteno =0 } - -% @footnotestyle is meaningful for info output only. -\let\footnotestyle=\comment - -\let\ptexfootnote=\footnote - -{\catcode `\@=11 -% -% Auto-number footnotes. Otherwise like plain. -\gdef\footnote{% - \global\advance\footnoteno by \@ne - \edef\thisfootno{$^{\the\footnoteno}$}% - % - % In case the footnote comes at the end of a sentence, preserve the - % extra spacing after we do the footnote number. - \let\@sf\empty - \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\/\fi - % - % Remove inadvertent blank space before typesetting the footnote number. - \unskip - \thisfootno\@sf - \footnotezzz -}% - -% Don't bother with the trickery in plain.tex to not require the -% footnote text as a parameter. Our footnotes don't need to be so general. -% -% Oh yes, they do; otherwise, @ifset and anything else that uses -% \parseargline fail inside footnotes because the tokens are fixed when -% the footnote is read. --karl, 16nov96. -% -\long\gdef\footnotezzz{\insert\footins\bgroup - % We want to typeset this text as a normal paragraph, even if the - % footnote reference occurs in (for example) a display environment. - % So reset some parameters. - \interlinepenalty\interfootnotelinepenalty - \splittopskip\ht\strutbox % top baseline for broken footnotes - \splitmaxdepth\dp\strutbox - \floatingpenalty\@MM - \leftskip\z@skip - \rightskip\z@skip - \spaceskip\z@skip - \xspaceskip\z@skip - \parindent\defaultparindent - % - \smallfonts \rm - % - % Hang the footnote text off the number. - \hang - \textindent{\thisfootno}% - % - % Don't crash into the line above the footnote text. Since this - % expands into a box, it must come within the paragraph, lest it - % provide a place where TeX can split the footnote. - \footstrut - \futurelet\next\fo@t -} -\def\fo@t{\ifcat\bgroup\noexpand\next \let\next\f@@t - \else\let\next\f@t\fi \next} -\def\f@@t{\bgroup\aftergroup\@foot\let\next} -\def\f@t#1{#1\@foot} -\def\@foot{\strut\par\egroup} - -}%end \catcode `\@=11 - -% Set the baselineskip to #1, and the lineskip and strut size -% correspondingly. There is no deep meaning behind these magic numbers -% used as factors; they just match (closely enough) what Knuth defined. -% -\def\lineskipfactor{.08333} -\def\strutheightpercent{.70833} -\def\strutdepthpercent {.29167} -% -\def\setleading#1{% - \normalbaselineskip = #1\relax - \normallineskip = \lineskipfactor\normalbaselineskip - \normalbaselines - \setbox\strutbox =\hbox{% - \vrule width0pt height\strutheightpercent\baselineskip - depth \strutdepthpercent \baselineskip - }% -} - -% @| inserts a changebar to the left of the current line. It should -% surround any changed text. This approach does *not* work if the -% change spans more than two lines of output. To handle that, we would -% have adopt a much more difficult approach (putting marks into the main -% vertical list for the beginning and end of each change). -% -\def\|{% - % \vadjust can only be used in horizontal mode. - \leavevmode - % - % Append this vertical mode material after the current line in the output. - \vadjust{% - % We want to insert a rule with the height and depth of the current - % leading; that is exactly what \strutbox is supposed to record. - \vskip-\baselineskip - % - % \vadjust-items are inserted at the left edge of the type. So - % the \llap here moves out into the left-hand margin. - \llap{% - % - % For a thicker or thinner bar, change the `1pt'. - \vrule height\baselineskip width1pt - % - % This is the space between the bar and the text. - \hskip 12pt - }% - }% -} - -% For a final copy, take out the rectangles -% that mark overfull boxes (in case you have decided -% that the text looks ok even though it passes the margin). -% -\def\finalout{\overfullrule=0pt} - -% @image. We use the macros from epsf.tex to support this. -% If epsf.tex is not installed and @image is used, we complain. -% -% Check for and read epsf.tex up front. If we read it only at @image -% time, we might be inside a group, and then its definitions would get -% undone and the next image would fail. -\openin 1 = epsf.tex -\ifeof 1 \else - \closein 1 - % Do not bother showing banner with post-v2.7 epsf.tex (available in - % doc/epsf.tex until it shows up on ctan). - \def\epsfannounce{\toks0 = }% - \input epsf.tex -\fi -% -% We will only complain once about lack of epsf.tex. -\newif\ifwarnednoepsf -\newhelp\noepsfhelp{epsf.tex must be installed for images to - work. It is also included in the Texinfo distribution, or you can get - it from ftp://tug.org/tex/epsf.tex.} -% -\def\image#1{% - \ifx\epsfbox\undefined - \ifwarnednoepsf \else - \errhelp = \noepsfhelp - \errmessage{epsf.tex not found, images will be ignored}% - \global\warnednoepsftrue - \fi - \else - \imagexxx #1,,,\finish - \fi -} -% -% Arguments to @image: -% #1 is (mandatory) image filename; we tack on .eps extension. -% #2 is (optional) width, #3 is (optional) height. -% #4 is just the usual extra ignored arg for parsing this stuff. -\def\imagexxx#1,#2,#3,#4\finish{% - \ifpdf - \centerline{\dopdfimage{#1}{#2}{#3}}% - \else - % \epsfbox itself resets \epsf?size at each figure. - \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \epsfxsize=#2\relax \fi - \setbox0 = \hbox{\ignorespaces #3}\ifdim\wd0 > 0pt \epsfysize=#3\relax \fi - \begingroup - \catcode`\^^M = 5 % in case we're inside an example - % If the image is by itself, center it. - \ifvmode - \nobreak\bigskip - % Usually we'll have text after the image which will insert - % \parskip glue, so insert it here too to equalize the space - % above and below. - \nobreak\vskip\parskip - \nobreak - \centerline{\epsfbox{#1.eps}}% - \bigbreak - \else - % In the middle of a paragraph, no extra space. - \epsfbox{#1.eps}% - \fi - \endgroup - \fi -} - - -\message{localization,} -% and i18n. - -% @documentlanguage is usually given very early, just after -% @setfilename. If done too late, it may not override everything -% properly. Single argument is the language abbreviation. -% It would be nice if we could set up a hyphenation file here. -% -\def\documentlanguage{\parsearg\dodocumentlanguage} -\def\dodocumentlanguage#1{% - \tex % read txi-??.tex file in plain TeX. - % Read the file if it exists. - \openin 1 txi-#1.tex - \ifeof1 - \errhelp = \nolanghelp - \errmessage{Cannot read language file txi-#1.tex}% - \let\temp = \relax - \else - \def\temp{\input txi-#1.tex }% - \fi - \temp - \endgroup -} -\newhelp\nolanghelp{The given language definition file cannot be found or -is empty. Maybe you need to install it? In the current directory -should work if nowhere else does.} - - -% @documentencoding should change something in TeX eventually, most -% likely, but for now just recognize it. -\let\documentencoding = \comment - - -% Page size parameters. -% -\newdimen\defaultparindent \defaultparindent = 15pt - -\chapheadingskip = 15pt plus 4pt minus 2pt -\secheadingskip = 12pt plus 3pt minus 2pt -\subsecheadingskip = 9pt plus 2pt minus 2pt - -% Prevent underfull vbox error messages. -\vbadness = 10000 - -% Don't be so finicky about underfull hboxes, either. -\hbadness = 2000 - -% Following George Bush, just get rid of widows and orphans. -\widowpenalty=10000 -\clubpenalty=10000 - -% Use TeX 3.0's \emergencystretch to help line breaking, but if we're -% using an old version of TeX, don't do anything. We want the amount of -% stretch added to depend on the line length, hence the dependence on -% \hsize. We call this whenever the paper size is set. -% -\def\setemergencystretch{% - \ifx\emergencystretch\thisisundefined - % Allow us to assign to \emergencystretch anyway. - \def\emergencystretch{\dimen0}% - \else - \emergencystretch = .15\hsize - \fi -} - -% Parameters in order: 1) textheight; 2) textwidth; 3) voffset; -% 4) hoffset; 5) binding offset; 6) topskip. Then whoever calls us can -% set \parskip and call \setleading for \baselineskip. -% -\def\internalpagesizes#1#2#3#4#5#6{% - \voffset = #3\relax - \topskip = #6\relax - \splittopskip = \topskip - % - \vsize = #1\relax - \advance\vsize by \topskip - \outervsize = \vsize - \advance\outervsize by 2\topandbottommargin - \pageheight = \vsize - % - \hsize = #2\relax - \outerhsize = \hsize - \advance\outerhsize by 0.5in - \pagewidth = \hsize - % - \normaloffset = #4\relax - \bindingoffset = #5\relax - % - \parindent = \defaultparindent - \setemergencystretch -} - -% @letterpaper (the default). -\def\letterpaper{{\globaldefs = 1 - \parskip = 3pt plus 2pt minus 1pt - \setleading{13.2pt}% - % - % If page is nothing but text, make it come out even. - \internalpagesizes{46\baselineskip}{6in}{\voffset}{.25in}{\bindingoffset}{36pt}% -}} - -% Use @smallbook to reset parameters for 7x9.5 (or so) format. -\def\smallbook{{\globaldefs = 1 - \parskip = 2pt plus 1pt - \setleading{12pt}% - % - \internalpagesizes{7.5in}{5.in}{\voffset}{.25in}{\bindingoffset}{16pt}% - % - \lispnarrowing = 0.3in - \tolerance = 700 - \hfuzz = 1pt - \contentsrightmargin = 0pt - \deftypemargin = 0pt - \defbodyindent = .5cm - % - \let\smalldisplay = \smalldisplayx - \let\smallexample = \smalllispx - \let\smallformat = \smallformatx - \let\smalllisp = \smalllispx -}} - -% Use @afourpaper to print on European A4 paper. -\def\afourpaper{{\globaldefs = 1 - \setleading{12pt}% - \parskip = 3pt plus 2pt minus 1pt - % - \internalpagesizes{53\baselineskip}{160mm}{\voffset}{4mm}{\bindingoffset}{44pt}% - % - \tolerance = 700 - \hfuzz = 1pt -}} - -% A specific text layout, 24x15cm overall, intended for A4 paper. Top margin -% 29mm, hence bottom margin 28mm, nominal side margin 3cm. -\def\afourlatex{{\globaldefs = 1 - \setleading{13.6pt}% - % - \afourpaper - \internalpagesizes{237mm}{150mm}{3.6mm}{3.6mm}{3mm}{7mm}% - % - \globaldefs = 0 -}} - -% Use @afourwide to print on European A4 paper in wide format. -\def\afourwide{% - \afourpaper - \internalpagesizes{6.5in}{9.5in}{\hoffset}{\normaloffset}{\bindingoffset}{7mm}% - % - \globaldefs = 0 -} - -% @pagesizes TEXTHEIGHT[,TEXTWIDTH] -% Perhaps we should allow setting the margins, \topskip, \parskip, -% and/or leading, also. Or perhaps we should compute them somehow. -% -\def\pagesizes{\parsearg\pagesizesxxx} -\def\pagesizesxxx#1{\pagesizesyyy #1,,\finish} -\def\pagesizesyyy#1,#2,#3\finish{{% - \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi - \globaldefs = 1 - % - \parskip = 3pt plus 2pt minus 1pt - \setleading{13.2pt}% - % - \internalpagesizes{#1}{\hsize}{\voffset}{\normaloffset}{\bindingoffset}{44pt}% -}} - -% Set default to letter. -% -\letterpaper - - -\message{and turning on texinfo input format.} - -% Define macros to output various characters with catcode for normal text. -\catcode`\"=\other -\catcode`\~=\other -\catcode`\^=\other -\catcode`\_=\other -\catcode`\|=\other -\catcode`\<=\other -\catcode`\>=\other -\catcode`\+=\other -\catcode`\$=\other -\def\normaldoublequote{"} -\def\normaltilde{~} -\def\normalcaret{^} -\def\normalunderscore{_} -\def\normalverticalbar{|} -\def\normalless{<} -\def\normalgreater{>} -\def\normalplus{+} -\def\normaldollar{$} - -% This macro is used to make a character print one way in ttfont -% where it can probably just be output, and another way in other fonts, -% where something hairier probably needs to be done. -% -% #1 is what to print if we are indeed using \tt; #2 is what to print -% otherwise. Since all the Computer Modern typewriter fonts have zero -% interword stretch (and shrink), and it is reasonable to expect all -% typewriter fonts to have this, we can check that font parameter. -% -\def\ifusingtt#1#2{\ifdim \fontdimen3\font=0pt #1\else #2\fi} - -% Same as above, but check for italic font. Actually this also catches -% non-italic slanted fonts since it is impossible to distinguish them from -% italic fonts. But since this is only used by $ and it uses \sl anyway -% this is not a problem. -\def\ifusingit#1#2{\ifdim \fontdimen1\font>0pt #1\else #2\fi} - -% Turn off all special characters except @ -% (and those which the user can use as if they were ordinary). -% Most of these we simply print from the \tt font, but for some, we can -% use math or other variants that look better in normal text. - -\catcode`\"=\active -\def\activedoublequote{{\tt\char34}} -\let"=\activedoublequote -\catcode`\~=\active -\def~{{\tt\char126}} -\chardef\hat=`\^ -\catcode`\^=\active -\def^{{\tt \hat}} - -\catcode`\_=\active -\def_{\ifusingtt\normalunderscore\_} -% Subroutine for the previous macro. -\def\_{\leavevmode \kern.06em \vbox{\hrule width.3em height.1ex}} - -\catcode`\|=\active -\def|{{\tt\char124}} -\chardef \less=`\< -\catcode`\<=\active -\def<{{\tt \less}} -\chardef \gtr=`\> -\catcode`\>=\active -\def>{{\tt \gtr}} -\catcode`\+=\active -\def+{{\tt \char 43}} -\catcode`\$=\active -\def${\ifusingit{{\sl\$}}\normaldollar} -%\catcode 27=\active -%\def^^[{$\diamondsuit$} - -% Set up an active definition for =, but don't enable it most of the time. -{\catcode`\==\active -\global\def={{\tt \char 61}}} - -\catcode`+=\active -\catcode`\_=\active - -% If a .fmt file is being used, characters that might appear in a file -% name cannot be active until we have parsed the command line. -% So turn them off again, and have \everyjob (or @setfilename) turn them on. -% \otherifyactive is called near the end of this file. -\def\otherifyactive{\catcode`+=\other \catcode`\_=\other} - -\catcode`\@=0 - -% \rawbackslashxx output one backslash character in current font -\global\chardef\rawbackslashxx=`\\ -%{\catcode`\\=\other -%@gdef@rawbackslashxx{\}} - -% \rawbackslash redefines \ as input to do \rawbackslashxx. -{\catcode`\\=\active -@gdef@rawbackslash{@let\=@rawbackslashxx }} - -% \normalbackslash outputs one backslash in fixed width font. -\def\normalbackslash{{\tt\rawbackslashxx}} - -% \catcode 17=0 % Define control-q -\catcode`\\=\active - -% Used sometimes to turn off (effectively) the active characters -% even after parsing them. -@def@turnoffactive{@let"=@normaldoublequote -@let\=@realbackslash -@let~=@normaltilde -@let^=@normalcaret -@let_=@normalunderscore -@let|=@normalverticalbar -@let<=@normalless -@let>=@normalgreater -@let+=@normalplus -@let$=@normaldollar} - -@def@normalturnoffactive{@let"=@normaldoublequote -@let\=@normalbackslash -@let~=@normaltilde -@let^=@normalcaret -@let_=@normalunderscore -@let|=@normalverticalbar -@let<=@normalless -@let>=@normalgreater -@let+=@normalplus -@let$=@normaldollar} - -% Make _ and + \other characters, temporarily. -% This is canceled by @fixbackslash. -@otherifyactive - -% If a .fmt file is being used, we don't want the `\input texinfo' to show up. -% That is what \eatinput is for; after that, the `\' should revert to printing -% a backslash. -% -@gdef@eatinput input texinfo{@fixbackslash} -@global@let\ = @eatinput - -% On the other hand, perhaps the file did not have a `\input texinfo'. Then -% the first `\{ in the file would cause an error. This macro tries to fix -% that, assuming it is called before the first `\' could plausibly occur. -% Also back turn on active characters that might appear in the input -% file name, in case not using a pre-dumped format. -% -@gdef@fixbackslash{% - @ifx\@eatinput @let\ = @normalbackslash @fi - @catcode`+=@active - @catcode`@_=@active -} - -% Say @foo, not \foo, in error messages. -@escapechar = `@@ - -% These look ok in all fonts, so just make them not special. -@catcode`@& = @other -@catcode`@# = @other -@catcode`@% = @other - -@c Set initial fonts. -@textfonts -@rm - - -@c Local variables: -@c eval: (add-hook 'write-file-hooks 'time-stamp) -@c page-delimiter: "^\\\\message" -@c time-stamp-start: "def\\\\texinfoversion{" -@c time-stamp-format: "%:y-%02m-%02d.%02H" -@c time-stamp-end: "}" -@c End: diff --git a/contrib/gperf/lib/Makefile.in b/contrib/gperf/lib/Makefile.in index 3b1ee9dd3420..8412d4481c0c 100644 --- a/contrib/gperf/lib/Makefile.in +++ b/contrib/gperf/lib/Makefile.in @@ -1,13 +1,14 @@ # Makefile for gperf/lib -# Copyright (C) 1989, 1992, 1993, 1998 Free Software Foundation, Inc. -# written by Douglas C. Schmidt (schmidt@ics.uci.edu) +# Copyright (C) 1989, 1992, 1993, 1998, 2002 Free Software Foundation, Inc. +# Written by Douglas C. Schmidt +# and Bruno Haible . # # This file is part of GNU GPERF. # # GNU GPERF is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 1, or (at your option) +# the Free Software Foundation; either version 2, or (at your option) # any later version. # # GNU GPERF is distributed in the hope that it will be useful, @@ -16,8 +17,9 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with GNU GPERF; see the file COPYING. If not, write to the Free -# Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. +# along with this program; see the file COPYING. +# If not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #### Start of system configuration section. #### @@ -38,6 +40,8 @@ CPP = @CPP@ CXX = @CXX@ CXXFLAGS = @CXXFLAGS@ CXXCPP = @CXXCPP@ +# Both C and C++ compiler +OBJEXT = @OBJEXT@ # Other AR = ar AR_FLAGS = rc @@ -58,7 +62,7 @@ SHELL = /bin/sh VPATH = $(srcdir) -OBJECTS = getopt.o getopt1.o hash.o +OBJECTS = getopt.$(OBJEXT) getopt1.$(OBJEXT) getline.$(OBJEXT) hash.$(OBJEXT) CPPFLAGS = -I$(srcdir) TARGETLIB = libgp.a @@ -85,6 +89,9 @@ getopt.o : getopt.c getopt.h getopt1.o : getopt1.c getopt.h $(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/getopt1.c +getline.o : getline.cc getline.h + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/getline.cc + hash.o : hash.cc hash.h $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/hash.cc diff --git a/contrib/gperf/lib/configure b/contrib/gperf/lib/configure index 80fa25bb7f9c..46f5f720a55e 100755 --- a/contrib/gperf/lib/configure +++ b/contrib/gperf/lib/configure @@ -1,26 +1,662 @@ #! /bin/sh - # Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 2.13 -# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. +# Generated by GNU Autoconf 2.61. # +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## -# Defaults: -ac_help= +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + + + +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + +if test "x$CONFIG_SHELL" = x; then + if (eval ":") 2>/dev/null; then + as_have_required=yes +else + as_have_required=no +fi + + if test $as_have_required = yes && (eval ": +(as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=\$LINENO + as_lineno_2=\$LINENO + test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" && + test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; } +") 2> /dev/null; then + : +else + as_candidate_shells= + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + case $as_dir in + /*) + for as_base in sh bash ksh sh5; do + as_candidate_shells="$as_candidate_shells $as_dir/$as_base" + done;; + esac +done +IFS=$as_save_IFS + + + for as_shell in $as_candidate_shells $SHELL; do + # Try only shells that exist, to save several forks. + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { ("$as_shell") 2> /dev/null <<\_ASEOF +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + +: +_ASEOF +}; then + CONFIG_SHELL=$as_shell + as_have_required=yes + if { "$as_shell" 2> /dev/null <<\_ASEOF +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + +: +(as_func_return () { + (exit $1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = "$1" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test $exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; } + +_ASEOF +}; then + break +fi + +fi + + done + + if test "x$CONFIG_SHELL" != x; then + for as_var in BASH_ENV ENV + do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + done + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} +fi + + + if test $as_have_required = no; then + echo This script requires a shell more modern than all the + echo shells that I found on your system. Please install a + echo modern shell, or manually run the script under such a + echo shell if you do have one. + { (exit 1); exit 1; } +fi + + +fi + +fi + + + +(eval "as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0") || { + echo No shell found that supports shell functions. + echo Please tell autoconf@gnu.org about your system, + echo including any error possibly output before this + echo message +} + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + + +exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# ac_default_prefix=/usr/local -# Any additions from configure.in: +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} + +# Identity of this package. +PACKAGE_NAME= +PACKAGE_TARNAME= +PACKAGE_VERSION= +PACKAGE_STRING= +PACKAGE_BUGREPORT= + +ac_unique_file="hash.cc" +ac_subst_vars='SHELL +PATH_SEPARATOR +PACKAGE_NAME +PACKAGE_TARNAME +PACKAGE_VERSION +PACKAGE_STRING +PACKAGE_BUGREPORT +exec_prefix +prefix +program_transform_name +bindir +sbindir +libexecdir +datarootdir +datadir +sysconfdir +sharedstatedir +localstatedir +includedir +oldincludedir +docdir +infodir +htmldir +dvidir +pdfdir +psdir +libdir +localedir +mandir +DEFS +ECHO_C +ECHO_N +ECHO_T +LIBS +build_alias +host_alias +target_alias +SET_MAKE +CC +CFLAGS +LDFLAGS +CPPFLAGS +ac_ct_CC +EXEEXT +OBJEXT +CPP +CXX +CXXFLAGS +ac_ct_CXX +CXXCPP +RANLIB +INSTALL +INSTALL_PROGRAM +INSTALL_DATA +LIBOBJS +LTLIBOBJS' +ac_subst_files='' + ac_precious_vars='build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CPP +CXX +CXXFLAGS +CCC +CXXCPP' + # Initialize some variables set by options. +ac_init_help= +ac_init_version=false # The variables have the same names as the options, with # dashes changed to underlines. -build=NONE -cache_file=./config.cache +cache_file=/dev/null exec_prefix=NONE -host=NONE no_create= -nonopt=NONE no_recursion= prefix=NONE program_prefix=NONE @@ -29,94 +665,117 @@ program_transform_name=s,x,x, silent= site= srcdir= -target=NONE verbose= x_includes=NONE x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' +datarootdir='${prefix}/share' +datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' includedir='${prefix}/include' oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -# Initialize some other variables. -subdirs= -MFLAGS= MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} -# Maximum number of lines to put in a shell here document. -ac_max_here_lines=12 +docdir='${datarootdir}/doc/${PACKAGE}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' ac_prev= +ac_dashdash= for ac_option do - # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" + eval $ac_prev=\$ac_option ac_prev= continue fi - case "$ac_option" in - -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; - *) ac_optarg= ;; + case $ac_option in + *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. - case "$ac_option" in + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir="$ac_optarg" ;; + bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) - ac_prev=build ;; + ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build="$ac_optarg" ;; + build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file="$ac_optarg" ;; + cache_file=$ac_optarg ;; - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir="$ac_optarg" ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; -disable-* | --disable-*) - ac_feature=`echo $ac_option|sed -e 's/-*disable-//'` + ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - eval "enable_${ac_feature}=no" ;; + expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + eval enable_$ac_feature=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; -enable-* | --enable-*) - ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'` + ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; - *) ac_optarg=yes ;; - esac - eval "enable_${ac_feature}='$ac_optarg'" ;; + expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + eval enable_$ac_feature=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ @@ -125,116 +784,77 @@ do -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) - exec_prefix="$ac_optarg" ;; + exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; - -help | --help | --hel | --he) - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat << EOF -Usage: configure [options] [host] -Options: [defaults in brackets after descriptions] -Configuration: - --cache-file=FILE cache test results in FILE - --help print this message - --no-create do not create output files - --quiet, --silent do not print \`checking...' messages - --version print the version of autoconf that created configure -Directory and file names: - --prefix=PREFIX install architecture-independent files in PREFIX - [$ac_default_prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [same as prefix] - --bindir=DIR user executables in DIR [EPREFIX/bin] - --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] - --libexecdir=DIR program executables in DIR [EPREFIX/libexec] - --datadir=DIR read-only architecture-independent data in DIR - [PREFIX/share] - --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] - --sharedstatedir=DIR modifiable architecture-independent data in DIR - [PREFIX/com] - --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] - --libdir=DIR object code libraries in DIR [EPREFIX/lib] - --includedir=DIR C header files in DIR [PREFIX/include] - --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] - --infodir=DIR info documentation in DIR [PREFIX/info] - --mandir=DIR man documentation in DIR [PREFIX/man] - --srcdir=DIR find the sources in DIR [configure dir or ..] - --program-prefix=PREFIX prepend PREFIX to installed program names - --program-suffix=SUFFIX append SUFFIX to installed program names - --program-transform-name=PROGRAM - run sed PROGRAM on installed program names -EOF - cat << EOF -Host type: - --build=BUILD configure for building on BUILD [BUILD=HOST] - --host=HOST configure for HOST [guessed] - --target=TARGET configure for TARGET [TARGET=HOST] -Features and packages: - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] - --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) - --x-includes=DIR X include files are in DIR - --x-libraries=DIR X library files are in DIR -EOF - if test -n "$ac_help"; then - echo "--enable and --with options recognized:$ac_help" - fi - exit 0 ;; + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; -host | --host | --hos | --ho) - ac_prev=host ;; + ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) - host="$ac_optarg" ;; + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir="$ac_optarg" ;; + includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir="$ac_optarg" ;; + infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir="$ac_optarg" ;; + libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) - libexecdir="$ac_optarg" ;; + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) + | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir="$ac_optarg" ;; + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir="$ac_optarg" ;; + mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) + | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ @@ -248,26 +868,26 @@ EOF -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir="$ac_optarg" ;; + oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix="$ac_optarg" ;; + prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix="$ac_optarg" ;; + program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix="$ac_optarg" ;; + program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ @@ -284,7 +904,17 @@ EOF | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name="$ac_optarg" ;; + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) @@ -294,7 +924,7 @@ EOF ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) - sbindir="$ac_optarg" ;; + sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ @@ -305,58 +935,53 @@ EOF | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) - sharedstatedir="$ac_optarg" ;; + sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) - site="$ac_optarg" ;; + site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir="$ac_optarg" ;; + srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir="$ac_optarg" ;; + sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target ;; + ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target="$ac_optarg" ;; + target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; - -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 2.13" - exit 0 ;; + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; -with-* | --with-*) - ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'` + ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; - *) ac_optarg=yes ;; - esac - eval "with_${ac_package}='$ac_optarg'" ;; + expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + eval with_$ac_package=\$ac_optarg ;; -without-* | --without-*) - ac_package=`echo $ac_option|sed -e 's/-*without-//'` + ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - eval "with_${ac_package}=no" ;; + expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + eval with_$ac_package=no ;; --x) # Obsolete; use --with-x. @@ -367,395 +992,1476 @@ EOF ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes="$ac_optarg" ;; + x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries="$ac_optarg" ;; + x_libraries=$ac_optarg ;; - -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } + -*) { echo "$as_me: error: unrecognized option: $ac_option +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 + { (exit 1); exit 1; }; } + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + *) - if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then - echo "configure: warning: $ac_option: invalid host type" 1>&2 - fi - if test "x$nonopt" != xNONE; then - { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } - fi - nonopt="$ac_option" + # FIXME: should be removed in autoconf 3.0. + echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} ;; esac done if test -n "$ac_prev"; then - { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; } + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + { echo "$as_me: error: missing argument to $ac_option" >&2 + { (exit 1); exit 1; }; } fi -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - -# File descriptor usage: -# 0 standard input -# 1 file creation -# 2 errors and warnings -# 3 some systems may open it to /dev/tty -# 4 used on the Kubota Titan -# 6 checking for... messages and results -# 5 compiler messages saved in config.log -if test "$silent" = yes; then - exec 6>/dev/null -else - exec 6>&1 -fi -exec 5>./config.log - -echo "\ -This file contains any messages produced by compilers while -running configure, to aid debugging if configure makes a mistake. -" 1>&5 - -# Strip out --no-create and --no-recursion so they do not pile up. -# Also quote any args containing shell metacharacters. -ac_configure_args= -for ac_arg +# Be sure to have absolute directory names. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir do - case "$ac_arg" in - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) ;; - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; - *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*) - ac_configure_args="$ac_configure_args '$ac_arg'" ;; - *) ac_configure_args="$ac_configure_args $ac_arg" ;; + eval ac_val=\$$ac_var + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac + { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; } done -# NLS nuisances. -# Only set these to C if already set. These must not be set unconditionally -# because not all systems understand e.g. LANG=C (notably SCO). -# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'! -# Non-C LC_CTYPE values break the ctype check. -if test "${LANG+set}" = set; then LANG=C; export LANG; fi -if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi -if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi -if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo > confdefs.h +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + { echo "$as_me: error: Working directory cannot be determined" >&2 + { (exit 1); exit 1; }; } +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + { echo "$as_me: error: pwd does not report name of working directory" >&2 + { (exit 1); exit 1; }; } -# A filename unique to this package, relative to the directory that -# configure is in, which we can look for to find out if srcdir is correct. -ac_unique_file=hash.cc # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_prog=$0 - ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` - test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$0" || +$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$0" : 'X\(//\)[^/]' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X"$0" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then + if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; } - else - { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; } - fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 + { (exit 1); exit 1; }; } fi -srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'` +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || { echo "$as_me: error: $ac_msg" >&2 + { (exit 1); exit 1; }; } + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures this package to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF +_ACEOF fi -for ac_site_file in $CONFIG_SITE; do + +if test -n "$ac_init_help"; then + + cat <<\_ACEOF + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CPP C preprocessor + CXX C++ compiler command + CXXFLAGS C++ compiler flags + CXXCPP C++ preprocessor + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +configure +generated by GNU Autoconf 2.61 + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by $as_me, which was +generated by GNU Autoconf 2.61. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + echo "PATH: $as_dir" +done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; + 2) + ac_configure_args1="$ac_configure_args1 '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + ac_configure_args="$ac_configure_args '$ac_arg'" + ;; + esac + done +done +$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } +$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + cat <<\_ASBOX +## ---------------- ## +## Cache variables. ## +## ---------------- ## +_ASBOX + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + cat <<\_ASBOX +## ----------------- ## +## Output variables. ## +## ----------------- ## +_ASBOX + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + cat <<\_ASBOX +## ------------------- ## +## File substitutions. ## +## ------------------- ## +_ASBOX + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + cat <<\_ASBOX +## ----------- ## +## confdefs.h. ## +## ----------- ## +_ASBOX + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + echo "$as_me: caught signal $ac_signal" + echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer explicitly selected file to automatically selected ones. +if test -n "$CONFIG_SITE"; then + set x "$CONFIG_SITE" +elif test "x$prefix" != xNONE; then + set x "$prefix/share/config.site" "$prefix/etc/config.site" +else + set x "$ac_default_prefix/share/config.site" \ + "$ac_default_prefix/etc/config.site" +fi +shift +for ac_site_file +do if test -r "$ac_site_file"; then - echo "loading site script $ac_site_file" + { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 +echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" fi done if test -r "$cache_file"; then - echo "loading cache $cache_file" - . $cache_file -else - echo "creating cache $cache_file" - > $cache_file -fi - -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross - -ac_exeext= -ac_objext=o -if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then - # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. - if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then - ac_n= ac_c=' -' ac_t=' ' - else - ac_n=-n ac_c= ac_t= + # Some versions of bash will fail to source /dev/null (special + # files actually), so we avoid doing that. + if test -f "$cache_file"; then + { echo "$as_me:$LINENO: loading cache $cache_file" >&5 +echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac fi else - ac_n= ac_c='\c' ac_t= + { echo "$as_me:$LINENO: creating cache $cache_file" >&5 +echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 +echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { echo "$as_me:$LINENO: former value: $ac_old_val" >&5 +echo "$as_me: former value: $ac_old_val" >&2;} + { echo "$as_me:$LINENO: current value: $ac_new_val" >&5 +echo "$as_me: current value: $ac_new_val" >&2;} + ac_cache_corrupted=: + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 +echo "$as_me: error: changes in the environment can compromise the build" >&2;} + { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 +echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} + { (exit 1); exit 1; }; } fi -echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6 -echo "configure:526: checking whether ${MAKE-make} sets \${MAKE}" >&5 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + + + + + + + + + + + + + + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +{ echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +echo $ECHO_N "checking whether ${MAKE-make} sets \$(MAKE)... $ECHO_C" >&6; } +set x ${MAKE-make}; ac_make=`echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - cat > conftestmake <<\EOF + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh all: - @echo 'ac_maketemp="${MAKE}"' -EOF + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF # GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftestmake 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make fi -rm -f conftestmake -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$ac_t""yes" 1>&6 +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } SET_MAKE= else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi -# Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:555: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CC="gcc" - break - fi - done - IFS="$ac_save_ifs" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + fi fi -CC="$ac_cv_prog_CC" +CC=$ac_cv_prog_CC if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" fi if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:585: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" ac_prog_rejected=no - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue - fi - ac_cv_prog_CC="cc" - break - fi - done - IFS="$ac_save_ifs" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift - if test $# -gt 0; then + if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift - set dummy "$ac_dir/$ac_word" "$@" - shift - ac_cv_prog_CC="$@" + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi -CC="$ac_cv_prog_CC" +CC=$ac_cv_prog_CC if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } fi - if test -z "$CC"; then - case "`uname -s`" in - *win32* | *WIN32*) - # Extract the first word of "cl", so it can be a program name with args. -set dummy cl; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:636: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CC="cl" - break - fi - done - IFS="$ac_save_ifs" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + fi fi -CC="$ac_cv_prog_CC" +CC=$ac_cv_prog_CC if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } fi - ;; - esac + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 fi - test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; } +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } fi -echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:668: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross + test -n "$ac_ct_CC" && break +done -cat > conftest.$ac_ext << EOF - -#line 679 "configure" -#include "confdefs.h" - -main(){return(0);} -EOF -if { (eval echo configure:684: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - ac_cv_prog_cc_works=yes - # If we can't run a trivial program, we are probably using a cross compiler. - if (./conftest; exit) 2>/dev/null; then - ac_cv_prog_cc_cross=no + if test "x$ac_ct_CC" = x; then + CC="" else - ac_cv_prog_cc_cross=yes + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC fi -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_prog_cc_works=no fi -rm -fr conftest* -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross -echo "$ac_t""$ac_cv_prog_cc_works" 1>&6 -if test $ac_cv_prog_cc_works = no; then - { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi -echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:710: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 -echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 -cross_compiling=$ac_cv_prog_cc_cross -echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:715: checking whether we are using GNU C" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + +test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&5 +echo "$as_me: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + +# Provide some information about the compiler. +echo "$as_me:$LINENO: checking for C compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (ac_try="$ac_compiler --version >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler --version >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -v >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -v >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -V >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -V >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ echo "$as_me:$LINENO: checking for C compiler default output file name" >&5 +echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6; } +ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` +# +# List of possible output files, starting from the most likely. +# The algorithm is not robust to junk in `.', hence go to wildcards (a.*) +# only as a last resort. b.out is created by i960 compilers. +ac_files='a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out' +# +# The IRIX 6 linker writes into existing files which may not be +# executable, retaining their permissions. Remove them first so a +# subsequent execution test works. +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { (ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + else - cat > conftest.c <&5 +echo "${ECHO_T}$ac_file" >&6; } +if test -z "$ac_file"; then + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: C compiler cannot create executables +See \`config.log' for more details." >&5 +echo "$as_me: error: C compiler cannot create executables +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } +fi + +ac_exeext=$ac_cv_exeext + +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ echo "$as_me:$LINENO: checking whether the C compiler works" >&5 +echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6; } +# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 +# If not cross compiling, check that we can run a simple program. +if test "$cross_compiling" != yes; then + if { ac_try='./$ac_file' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { echo "$as_me:$LINENO: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + fi + fi +fi +{ echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + +rm -f a.out a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ echo "$as_me:$LINENO: checking whether we are cross compiling" >&5 +echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6; } +{ echo "$as_me:$LINENO: result: $cross_compiling" >&5 +echo "${ECHO_T}$cross_compiling" >&6; } + +{ echo "$as_me:$LINENO: checking for suffix of executables" >&5 +echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6; } +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest$ac_cv_exeext +{ echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5 +echo "${ECHO_T}$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +{ echo "$as_me:$LINENO: checking for suffix of object files" >&5 +echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6; } +if test "${ac_cv_objext+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_objext" >&5 +echo "${ECHO_T}$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6; } +if test "${ac_cv_c_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me #endif -EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:724: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then - ac_cv_prog_gcc=yes + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_compiler_gnu=yes else - ac_cv_prog_gcc=no -fi + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_compiler_gnu=no fi -echo "$ac_t""$ac_cv_prog_gcc" 1>&6 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu -if test $ac_cv_prog_gcc = yes; then - GCC=yes -else - GCC= fi - -ac_test_CFLAGS="${CFLAGS+set}" -ac_save_CFLAGS="$CFLAGS" -CFLAGS= -echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:743: checking whether ${CC-cc} accepts -g" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +{ echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6; } +GCC=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 +echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6; } +if test "${ac_cv_prog_cc_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - echo 'void f(){}' > conftest.c -if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then ac_cv_prog_cc_g=yes else - ac_cv_prog_cc_g=no -fi -rm -f conftest* + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + CFLAGS="" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cc_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + fi -echo "$ac_t""$ac_cv_prog_cc_g" 1>&6 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then - CFLAGS="$ac_save_CFLAGS" + CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" @@ -769,216 +2475,702 @@ else CFLAGS= fi fi +{ echo "$as_me:$LINENO: checking for $CC option to accept ISO C89" >&5 +echo $ECHO_N "checking for $CC option to accept ISO C89... $ECHO_C" >&6; } +if test "${ac_cv_prog_cc_c89+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} - echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:775: checking how to run the C preprocessor" >&5 +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cc_c89=$ac_arg +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { echo "$as_me:$LINENO: result: none needed" >&5 +echo "${ECHO_T}none needed" >&6; } ;; + xno) + { echo "$as_me:$LINENO: result: unsupported" >&5 +echo "${ECHO_T}unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { echo "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_c89" >&6; } ;; +esac + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 +echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6; } # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then -if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + if test "${ac_cv_prog_CPP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - # This must be in double quotes, not single quotes, because CPP may get - # substituted into the Makefile and "${CC-cc}" will confuse make. - CPP="${CC-cc} -E" - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:796: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` -if test -z "$ac_err"; then - : -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP="${CC-cc} -E -traditional-cpp" - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:813: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` -if test -z "$ac_err"; then - : -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP="${CC-cc} -nologo -E" - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:830: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` -if test -z "$ac_err"; then - : -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP=/lib/cpp -fi -rm -f conftest* -fi -rm -f conftest* -fi -rm -f conftest* - ac_cv_prog_CPP="$CPP" -fi - CPP="$ac_cv_prog_CPP" -else - ac_cv_prog_CPP="$CPP" -fi -echo "$ac_t""$CPP" 1>&6 - - for ac_prog in $CCC c++ g++ gcc CC cxx cc++ cl + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes do -# Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:859: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CXX'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ echo "$as_me:$LINENO: result: $CPP" >&5 +echo "${ECHO_T}$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + : +else + { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&5 +echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +if test -z "$CXX"; then + if test -n "$CCC"; then + CXX=$CCC + else + if test -n "$ac_tool_prefix"; then + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CXX+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CXX"; then ac_cv_prog_CXX="$CXX" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CXX="$ac_prog" - break - fi - done - IFS="$ac_save_ifs" -fi -fi -CXX="$ac_cv_prog_CXX" -if test -n "$CXX"; then - echo "$ac_t""$CXX" 1>&6 -else - echo "$ac_t""no" 1>&6 -fi - -test -n "$CXX" && break -done -test -n "$CXX" || CXX="gcc" - - -echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:891: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5 - -ac_ext=C -# CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CXXCPP $CPPFLAGS' -ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cxx_cross - -cat > conftest.$ac_ext << EOF - -#line 902 "configure" -#include "confdefs.h" - -int main(){return(0);} -EOF -if { (eval echo configure:907: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - ac_cv_prog_cxx_works=yes - # If we can't run a trivial program, we are probably using a cross compiler. - if (./conftest; exit) 2>/dev/null; then - ac_cv_prog_cxx_cross=no - else - ac_cv_prog_cxx_cross=yes +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 fi -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_prog_cxx_works=no -fi -rm -fr conftest* -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross +done +done +IFS=$as_save_IFS -echo "$ac_t""$ac_cv_prog_cxx_works" 1>&6 -if test $ac_cv_prog_cxx_works = no; then - { echo "configure: error: installation or configuration problem: C++ compiler cannot create executables." 1>&2; exit 1; } fi -echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:933: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5 -echo "$ac_t""$ac_cv_prog_cxx_cross" 1>&6 -cross_compiling=$ac_cv_prog_cxx_cross - -echo $ac_n "checking whether we are using GNU C++""... $ac_c" 1>&6 -echo "configure:938: checking whether we are using GNU C++" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_gxx'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +fi +CXX=$ac_cv_prog_CXX +if test -n "$CXX"; then + { echo "$as_me:$LINENO: result: $CXX" >&5 +echo "${ECHO_T}$CXX" >&6; } else - cat > conftest.C <&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$CXX" && break + done +fi +if test -z "$CXX"; then + ac_ct_CXX=$CXX + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CXX"; then + ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CXX="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CXX=$ac_cv_prog_ac_ct_CXX +if test -n "$ac_ct_CXX"; then + { echo "$as_me:$LINENO: result: $ac_ct_CXX" >&5 +echo "${ECHO_T}$ac_ct_CXX" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$ac_ct_CXX" && break +done + + if test "x$ac_ct_CXX" = x; then + CXX="g++" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CXX=$ac_ct_CXX + fi +fi + + fi +fi +# Provide some information about the compiler. +echo "$as_me:$LINENO: checking for C++ compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (ac_try="$ac_compiler --version >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler --version >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -v >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -v >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -V >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -V >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + +{ echo "$as_me:$LINENO: checking whether we are using the GNU C++ compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C++ compiler... $ECHO_C" >&6; } +if test "${ac_cv_cxx_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me #endif -EOF -if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:947: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then - ac_cv_prog_gxx=yes + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_compiler_gnu=yes else - ac_cv_prog_gxx=no -fi + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_compiler_gnu=no fi -echo "$ac_t""$ac_cv_prog_gxx" 1>&6 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_cxx_compiler_gnu=$ac_compiler_gnu -if test $ac_cv_prog_gxx = yes; then - GXX=yes -else - GXX= fi - -ac_test_CXXFLAGS="${CXXFLAGS+set}" -ac_save_CXXFLAGS="$CXXFLAGS" -CXXFLAGS= -echo $ac_n "checking whether ${CXX-g++} accepts -g""... $ac_c" 1>&6 -echo "configure:966: checking whether ${CXX-g++} accepts -g" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_cxx_g'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +{ echo "$as_me:$LINENO: result: $ac_cv_cxx_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_cxx_compiler_gnu" >&6; } +GXX=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CXXFLAGS=${CXXFLAGS+set} +ac_save_CXXFLAGS=$CXXFLAGS +{ echo "$as_me:$LINENO: checking whether $CXX accepts -g" >&5 +echo $ECHO_N "checking whether $CXX accepts -g... $ECHO_C" >&6; } +if test "${ac_cv_prog_cxx_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - echo 'void f(){}' > conftest.cc -if test -z "`${CXX-g++} -g -c conftest.cc 2>&1`"; then + ac_save_cxx_werror_flag=$ac_cxx_werror_flag + ac_cxx_werror_flag=yes + ac_cv_prog_cxx_g=no + CXXFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then ac_cv_prog_cxx_g=yes else - ac_cv_prog_cxx_g=no -fi -rm -f conftest* + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + CXXFLAGS="" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cxx_werror_flag=$ac_save_cxx_werror_flag + CXXFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cxx_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + fi -echo "$ac_t""$ac_cv_prog_cxx_g" 1>&6 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_cxx_werror_flag=$ac_save_cxx_werror_flag +fi +{ echo "$as_me:$LINENO: result: $ac_cv_prog_cxx_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cxx_g" >&6; } if test "$ac_test_CXXFLAGS" = set; then - CXXFLAGS="$ac_save_CXXFLAGS" + CXXFLAGS=$ac_save_CXXFLAGS elif test $ac_cv_prog_cxx_g = yes; then if test "$GXX" = yes; then CXXFLAGS="-g -O2" @@ -992,78 +3184,332 @@ else CXXFLAGS= fi fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu - echo $ac_n "checking how to run the C++ preprocessor""... $ac_c" 1>&6 -echo "configure:998: checking how to run the C++ preprocessor" >&5 -if test -z "$CXXCPP"; then -if eval "test \"`echo '$''{'ac_cv_prog_CXXCPP'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_ext=C -# CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. + ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' -ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cxx_cross - CXXCPP="${CXX-g++} -E" - cat > conftest.$ac_ext < -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1016: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` -if test -z "$ac_err"; then +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +{ echo "$as_me:$LINENO: checking how to run the C++ preprocessor" >&5 +echo $ECHO_N "checking how to run the C++ preprocessor... $ECHO_C" >&6; } +if test -z "$CXXCPP"; then + if test "${ac_cv_prog_CXXCPP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # Double quotes because CXXCPP needs to be expanded + for CXXCPP in "$CXX -E" "/lib/cpp" + do + ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then : else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CXXCPP=/lib/cpp -fi -rm -f conftest* - ac_cv_prog_CXXCPP="$CXXCPP" -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross -fi -fi -CXXCPP="$ac_cv_prog_CXXCPP" -echo "$ac_t""$CXXCPP" 1>&6 + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 - # Extract the first word of "ranlib", so it can be a program name with args. -set dummy ranlib; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1043: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + break +fi + + done + ac_cv_prog_CXXCPP=$CXXCPP + +fi + CXXCPP=$ac_cv_prog_CXXCPP +else + ac_cv_prog_CXXCPP=$CXXCPP +fi +{ echo "$as_me:$LINENO: result: $CXXCPP" >&5 +echo "${ECHO_T}$CXXCPP" >&6; } +ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + : +else + { { echo "$as_me:$LINENO: error: C++ preprocessor \"$CXXCPP\" fails sanity check +See \`config.log' for more details." >&5 +echo "$as_me: error: C++ preprocessor \"$CXXCPP\" fails sanity check +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_RANLIB+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_RANLIB="ranlib" - break - fi - done - IFS="$ac_save_ifs" - test -z "$ac_cv_prog_RANLIB" && ac_cv_prog_RANLIB="true" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + fi fi -RANLIB="$ac_cv_prog_RANLIB" +RANLIB=$ac_cv_prog_RANLIB if test -n "$RANLIB"; then - echo "$ac_t""$RANLIB" 1>&6 + { echo "$as_me:$LINENO: result: $RANLIB" >&5 +echo "${ECHO_T}$RANLIB" >&6; } else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5 +echo "${ECHO_T}$ac_ct_RANLIB" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" fi # Find a good install program. We prefer a C program (faster), @@ -1076,11 +3522,11 @@ fi # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. -echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:1081: checking for a BSD compatible install" >&5 +{ echo "$as_me:$LINENO: checking for a BSD compatible install" >&5 +echo $ECHO_N "checking for a BSD compatible install... $ECHO_C" >&6; } if test -z "$INSTALL"; then -if eval "test \"`echo '$''{'cl_cv_path_install'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +if test "${cl_cv_path_install+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" for ac_dir in $PATH; do @@ -1118,7 +3564,8 @@ else fi INSTALL="$cl_cv_path_install" fi -echo "$ac_t""$INSTALL" 1>&6 +{ echo "$as_me:$LINENO: result: $INSTALL" >&5 +echo "${ECHO_T}$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='$(INSTALL)' @@ -1129,263 +3576,1018 @@ if test -z "$INSTALL_DATA"; then esac fi - trap '' 1 2 15 -cat > confcache <<\EOF + ac_config_files="$ac_config_files Makefile" + +cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure -# scripts and configure runs. It is not useful on other systems. -# If it contains results you don't want to keep, you may remove or edit it. +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. # -# By default, configure uses ./config.cache as the cache file, -# creating it if it does not exist already. You can give configure -# the --cache-file=FILE option to use a different cache file; that is -# what configure does when it calls configure scripts in -# subdirectories, so they share the cache. -# Giving --cache-file=/dev/null disables caching, for debugging configure. -# config.status only pays attention to the cache file if you give it the -# --recheck option to rerun configure. +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. # -EOF +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. +# So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. -(set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote substitution - # turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - -e "s/'/'\\\\''/g" \ - -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p' - ;; - esac >> confcache -if cmp -s $cache_file confcache; then - : -else - if test -w $cache_file; then - echo "updating cache $cache_file" - cat confcache > $cache_file +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + test "x$cache_file" != "x/dev/null" && + { echo "$as_me:$LINENO: updating cache $cache_file" >&5 +echo "$as_me: updating cache $cache_file" >&6;} + cat confcache >$cache_file else - echo "not updating unwritable cache $cache_file" + { echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5 +echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' -# Any assignment to VPATH causes Sun make to only execute -# the first set of double-colon rules, so remove it if not needed. -# If there is a colon in the path, we need to keep it. -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d' -fi - -trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 - # Transform confdefs.h into DEFS. # Protect against shell expansion while executing Makefile rules. # Protect against Makefile macro expansion. -cat > conftest.defs <<\EOF -s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%-D\1=\2%g -s%[ `~#$^&*(){}\\|;'"<>?]%\\&%g -s%\[%\\&%g -s%\]%\\&%g -s%\$%$$%g -EOF -DEFS=`sed -f conftest.defs confdefs.h | tr '\012' ' '` -rm -f conftest.defs +# +# If the first sed substitution is executed (which looks for macros that +# take arguments), then branch to the quote section. Otherwise, +# look for a macro that doesn't take arguments. +ac_script=' +t clear +:clear +s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g +t quote +s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g +t quote +b any +:quote +s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g +s/\[/\\&/g +s/\]/\\&/g +s/\$/$$/g +H +:any +${ + g + s/^\n// + s/\n/ /g + p +} +' +DEFS=`sed -n "$ac_script" confdefs.h` + + +ac_libobjs= +ac_ltlibobjs= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext" + ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + -# Without the "./", some shells look in PATH for config.status. : ${CONFIG_STATUS=./config.status} - -echo creating $CONFIG_STATUS -rm -f $CONFIG_STATUS -cat > $CONFIG_STATUS <&5 +echo "$as_me: creating $CONFIG_STATUS" >&6;} +cat >$CONFIG_STATUS <<_ACEOF +#! $SHELL +# Generated by $as_me. # Run this file to recreate the current configuration. -# This directory was configured as follows, -# on host `(hostname || uname -n) 2>/dev/null | sed 1q`: -# -# $0 $ac_configure_args -# # Compiler output produced by configure, useful for debugging -# configure, is in ./config.log if it exists. +# configure, is in config.log if it exists. -ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]" -for ac_option -do - case "\$ac_option" in - -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" - exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; - -version | --version | --versio | --versi | --vers | --ver | --ve | --v) - echo "$CONFIG_STATUS generated by autoconf version 2.13" - exit 0 ;; - -help | --help | --hel | --he | --h) - echo "\$ac_cs_usage"; exit 0 ;; - *) echo "\$ac_cs_usage"; exit 1 ;; - esac -done +debug=false +ac_cs_recheck=false +ac_cs_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_ACEOF -ac_given_srcdir=$srcdir +cat >>$CONFIG_STATUS <<\_ACEOF +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## -trap 'rm -fr `echo "Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 -EOF -cat >> $CONFIG_STATUS </dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac -# Protect against being on the right side of a sed subst in config.status. -sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g; - s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF -$ac_vpsub -$extrasub -s%@SHELL@%$SHELL%g -s%@CFLAGS@%$CFLAGS%g -s%@CPPFLAGS@%$CPPFLAGS%g -s%@CXXFLAGS@%$CXXFLAGS%g -s%@FFLAGS@%$FFLAGS%g -s%@DEFS@%$DEFS%g -s%@LDFLAGS@%$LDFLAGS%g -s%@LIBS@%$LIBS%g -s%@exec_prefix@%$exec_prefix%g -s%@prefix@%$prefix%g -s%@program_transform_name@%$program_transform_name%g -s%@bindir@%$bindir%g -s%@sbindir@%$sbindir%g -s%@libexecdir@%$libexecdir%g -s%@datadir@%$datadir%g -s%@sysconfdir@%$sysconfdir%g -s%@sharedstatedir@%$sharedstatedir%g -s%@localstatedir@%$localstatedir%g -s%@libdir@%$libdir%g -s%@includedir@%$includedir%g -s%@oldincludedir@%$oldincludedir%g -s%@infodir@%$infodir%g -s%@mandir@%$mandir%g -s%@SET_MAKE@%$SET_MAKE%g -s%@CC@%$CC%g -s%@CPP@%$CPP%g -s%@CXX@%$CXX%g -s%@CXXCPP@%$CXXCPP%g -s%@RANLIB@%$RANLIB%g -s%@INSTALL@%$INSTALL%g -s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g -s%@INSTALL_DATA@%$INSTALL_DATA%g - -CEOF -EOF - -cat >> $CONFIG_STATUS <<\EOF - -# Split the substitutions into bite-sized pieces for seds with -# small command number limits, like on Digital OSF/1 and HP-UX. -ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script. -ac_file=1 # Number of current file. -ac_beg=1 # First line for current file. -ac_end=$ac_max_sed_cmds # Line after last line for current file. -ac_more_lines=: -ac_sed_cmds="" -while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file - else - sed "${ac_end}q" conftest.subs > conftest.s$ac_file - fi - if test ! -s conftest.s$ac_file; then - ac_more_lines=false - rm -f conftest.s$ac_file - else - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f conftest.s$ac_file" - else - ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file" - fi - ac_file=`expr $ac_file + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_cmds` - fi -done -if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat fi -EOF -cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF -for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case "$ac_file" in - *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` - ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; - *) ac_file_in="${ac_file}.in" ;; - esac - # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories. - # Remove last slash and all that follows it. Not all systems have dirname. - ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - # The file is in a subdirectory. - test ! -d "$ac_dir" && mkdir "$ac_dir" - ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`" - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' else - ac_dir_suffix= ac_dots= + PATH_SEPARATOR=: fi + rm -f conf$$.sh +fi - case "$ac_given_srcdir" in - .) srcdir=. - if test -z "$ac_dots"; then top_srcdir=. - else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;; - /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;; - *) # Relative path. - srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix" - top_srcdir="$ac_dots$ac_given_srcdir" ;; +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 + +# Save the log message, to keep $[0] and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by $as_me, which was +generated by GNU Autoconf 2.61. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF +# Files that config.status was made for. +config_files="$ac_config_files" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +ac_cs_usage="\ +\`$as_me' instantiates files from templates according to the +current configuration. + +Usage: $0 [OPTIONS] [FILE]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + +Configuration files: +$config_files + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +ac_cs_version="\\ +config.status +configured by $0, generated by GNU Autoconf 2.61, + with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" + +Copyright (C) 2006 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If no file are specified by the user, then we need to provide default +# value. By we need to know if files were specified by the user. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; esac + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + echo "$ac_cs_version"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + CONFIG_FILES="$CONFIG_FILES $ac_optarg" + ac_need_defaults=false;; + --he | --h | --help | --hel | -h ) + echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; - echo creating "$ac_file" - rm -f "$ac_file" - configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure." - case "$ac_file" in - *Makefile*) ac_comsub="1i\\ -# $configure_input" ;; - *) ac_comsub= ;; + # This is an error. + -*) { echo "$as_me: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + + *) ac_config_targets="$ac_config_targets $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +if \$ac_cs_recheck; then + echo "running CONFIG_SHELL=$SHELL $SHELL $0 "$ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6 + CONFIG_SHELL=$SHELL + export CONFIG_SHELL + exec $SHELL "$0"$ac_configure_args \$ac_configure_extra_args --no-create --no-recursion +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + + *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 +echo "$as_me: error: invalid argument: $ac_config_target" >&2;} + { (exit 1); exit 1; }; };; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= + trap 'exit_status=$? + { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status +' 0 + trap '{ (exit 1); exit 1; }' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || +{ + echo "$me: cannot create a temporary directory in ." >&2 + { (exit 1); exit 1; } +} + +# +# Set up the sed scripts for CONFIG_FILES section. +# + +# No need to generate the scripts if there are no CONFIG_FILES. +# This happens for instance when ./config.status config.h +if test -n "$CONFIG_FILES"; then + +_ACEOF + + + +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + cat >conf$$subs.sed <<_ACEOF +SHELL!$SHELL$ac_delim +PATH_SEPARATOR!$PATH_SEPARATOR$ac_delim +PACKAGE_NAME!$PACKAGE_NAME$ac_delim +PACKAGE_TARNAME!$PACKAGE_TARNAME$ac_delim +PACKAGE_VERSION!$PACKAGE_VERSION$ac_delim +PACKAGE_STRING!$PACKAGE_STRING$ac_delim +PACKAGE_BUGREPORT!$PACKAGE_BUGREPORT$ac_delim +exec_prefix!$exec_prefix$ac_delim +prefix!$prefix$ac_delim +program_transform_name!$program_transform_name$ac_delim +bindir!$bindir$ac_delim +sbindir!$sbindir$ac_delim +libexecdir!$libexecdir$ac_delim +datarootdir!$datarootdir$ac_delim +datadir!$datadir$ac_delim +sysconfdir!$sysconfdir$ac_delim +sharedstatedir!$sharedstatedir$ac_delim +localstatedir!$localstatedir$ac_delim +includedir!$includedir$ac_delim +oldincludedir!$oldincludedir$ac_delim +docdir!$docdir$ac_delim +infodir!$infodir$ac_delim +htmldir!$htmldir$ac_delim +dvidir!$dvidir$ac_delim +pdfdir!$pdfdir$ac_delim +psdir!$psdir$ac_delim +libdir!$libdir$ac_delim +localedir!$localedir$ac_delim +mandir!$mandir$ac_delim +DEFS!$DEFS$ac_delim +ECHO_C!$ECHO_C$ac_delim +ECHO_N!$ECHO_N$ac_delim +ECHO_T!$ECHO_T$ac_delim +LIBS!$LIBS$ac_delim +build_alias!$build_alias$ac_delim +host_alias!$host_alias$ac_delim +target_alias!$target_alias$ac_delim +SET_MAKE!$SET_MAKE$ac_delim +CC!$CC$ac_delim +CFLAGS!$CFLAGS$ac_delim +LDFLAGS!$LDFLAGS$ac_delim +CPPFLAGS!$CPPFLAGS$ac_delim +ac_ct_CC!$ac_ct_CC$ac_delim +EXEEXT!$EXEEXT$ac_delim +OBJEXT!$OBJEXT$ac_delim +CPP!$CPP$ac_delim +CXX!$CXX$ac_delim +CXXFLAGS!$CXXFLAGS$ac_delim +ac_ct_CXX!$ac_ct_CXX$ac_delim +CXXCPP!$CXXCPP$ac_delim +RANLIB!$RANLIB$ac_delim +INSTALL!$INSTALL$ac_delim +INSTALL_PROGRAM!$INSTALL_PROGRAM$ac_delim +INSTALL_DATA!$INSTALL_DATA$ac_delim +LIBOBJS!$LIBOBJS$ac_delim +LTLIBOBJS!$LTLIBOBJS$ac_delim +_ACEOF + + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 56; then + break + elif $ac_last_try; then + { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 +echo "$as_me: error: could not make $CONFIG_STATUS" >&2;} + { (exit 1); exit 1; }; } + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed` +if test -n "$ac_eof"; then + ac_eof=`echo "$ac_eof" | sort -nru | sed 1q` + ac_eof=`expr $ac_eof + 1` +fi + +cat >>$CONFIG_STATUS <<_ACEOF +cat >"\$tmp/subs-1.sed" <<\CEOF$ac_eof +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b end +_ACEOF +sed ' +s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g +s/^/s,@/; s/!/@,|#_!!_#|/ +:n +t n +s/'"$ac_delim"'$/,g/; t +s/$/\\/; p +N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n +' >>$CONFIG_STATUS >$CONFIG_STATUS <<_ACEOF +:end +s/|#_!!_#|//g +CEOF$ac_eof +_ACEOF + + +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/ +s/:*\${srcdir}:*/:/ +s/:*@srcdir@:*/:/ +s/^\([^=]*=[ ]*\):*/\1/ +s/:*$// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF +fi # test -n "$CONFIG_FILES" + + +for ac_tag in :F $CONFIG_FILES +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) { { echo "$as_me:$LINENO: error: Invalid tag $ac_tag." >&5 +echo "$as_me: error: Invalid tag $ac_tag." >&2;} + { (exit 1); exit 1; }; };; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + { { echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5 +echo "$as_me: error: cannot find input file: $ac_f" >&2;} + { (exit 1); exit 1; }; };; + esac + ac_file_inputs="$ac_file_inputs $ac_f" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input="Generated from "`IFS=: + echo $* | sed 's|^[^:]*/||;s|:[^:]*/|, |g'`" by configure." + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + fi + + case $ac_tag in + *:-:* | *:-) cat >"$tmp/stdin";; + esac + ;; esac - ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` - sed -e "$ac_comsub -s%@configure_input@%$configure_input%g -s%@srcdir@%$srcdir%g -s%@top_srcdir@%$top_srcdir%g -" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file -fi; done -rm -f conftest.s* + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + { as_dir="$ac_dir" + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5 +echo "$as_me: error: cannot create directory $as_dir" >&2;} + { (exit 1); exit 1; }; }; } + ac_builddir=. -EOF -cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix -exit 0 -EOF + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= + +case `sed -n '/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p +' $ac_file_inputs` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF + sed "$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s&@configure_input@&$configure_input&;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +$ac_datarootdir_hack +" $ac_file_inputs | sed -f "$tmp/subs-1.sed" >$tmp/out + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && + { echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&5 +echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&2;} + + rm -f "$tmp/stdin" + case $ac_file in + -) cat "$tmp/out"; rm -f "$tmp/out";; + *) rm -f "$ac_file"; mv "$tmp/out" $ac_file;; + esac + ;; + + + + esac + +done # for ac_tag + + +{ (exit 0); exit 0; } +_ACEOF chmod +x $CONFIG_STATUS -rm -fr confdefs* $ac_clean_files -test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1 +ac_clean_files=$ac_clean_files_save + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || { (exit 1); exit 1; } +fi diff --git a/contrib/gperf/lib/configure.in b/contrib/gperf/lib/configure.ac similarity index 71% rename from contrib/gperf/lib/configure.in rename to contrib/gperf/lib/configure.ac index 98266a1239f6..8db581a06ba0 100644 --- a/contrib/gperf/lib/configure.in +++ b/contrib/gperf/lib/configure.ac @@ -1,13 +1,14 @@ dnl autoconf configuration for gperf/lib -dnl Copyright (C) 1998 Free Software Foundation, Inc. -dnl written by Douglas C. Schmidt (schmidt@ics.uci.edu) +dnl Copyright (C) 1998, 2002, 2005, 2007 Free Software Foundation, Inc. +dnl Written by Douglas C. Schmidt +dnl and Bruno Haible . dnl dnl This file is part of GNU GPERF. dnl dnl GNU GPERF is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by -dnl the Free Software Foundation; either version 1, or (at your option) +dnl the Free Software Foundation; either version 2, or (at your option) dnl any later version. dnl dnl GNU GPERF is distributed in the hope that it will be useful, @@ -16,10 +17,11 @@ dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the dnl GNU General Public License for more details. dnl dnl You should have received a copy of the GNU General Public License -dnl along with GNU GPERF; see the file COPYING. If not, write to the -dnl Free Software Foundation, 59 Temple Place - Suite 330, Boston, -dnl MA 02111-1307, USA. +dnl along with this program; see the file COPYING. +dnl If not, write to the Free Software Foundation, Inc., +dnl 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +AC_PREREQ([2.60]) AC_INIT(hash.cc) AC_PROG_MAKE_SET dnl @@ -33,7 +35,7 @@ AC_PROG_CXX dnl sets variable CXX AC_PROG_CXXCPP dnl sets variable CXXCPP -CL_PROG_RANLIB +AC_PROG_RANLIB dnl sets variable RANLIB CL_PROG_INSTALL dnl sets variables INSTALL, INSTALL_DATA, INSTALL_PROGRAM diff --git a/contrib/gperf/lib/getline.cc b/contrib/gperf/lib/getline.cc new file mode 100644 index 000000000000..d3393fb0f725 --- /dev/null +++ b/contrib/gperf/lib/getline.cc @@ -0,0 +1,119 @@ +/* getline.c -- Replacement for GNU C library function getline + +Copyright (C) 1993, 1996, 2001-2002 Free Software Foundation, Inc. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +USA. */ + +/* Written by Jan Brittenson, bson@gnu.ai.mit.edu. */ + +/* Specification. */ +#include "getline.h" + +#include +#include +#include +#include + +/* Always add at least this many bytes when extending the buffer. */ +#define MIN_CHUNK 64 + +/* Reads up to (and including) a TERMINATOR from STREAM into *LINEPTR + OFFSET + (and null-terminate it). *LINEPTR is a pointer returned from new [] (or + NULL), pointing to *N characters of space. It is realloc'd as + necessary. Returns the number of characters read (not including the + null terminator), or -1 on error or immediate EOF. + NOTE: There is another getstr() function declared in . */ + +static int +getstr (char **lineptr, size_t *n, FILE *stream, char terminator, size_t offset) +{ + size_t nchars_avail; /* Allocated but unused chars in *LINEPTR. */ + char *read_pos; /* Where we're reading into *LINEPTR. */ + + if (!lineptr || !n || !stream) + return -1; + + if (!*lineptr) + { + *n = MIN_CHUNK; + *lineptr = new char[*n]; + } + + nchars_avail = *n - offset; + read_pos = *lineptr + offset; + + for (;;) + { + register int c = getc (stream); + + /* We always want at least one char left in the buffer, since we + always (unless we get an error while reading the first char) + NUL-terminate the line buffer. */ + + assert (*n - nchars_avail == (size_t) (read_pos - *lineptr)); + if (nchars_avail < 2) + { + if (*n > MIN_CHUNK) + *n *= 2; + else + *n += MIN_CHUNK; + + nchars_avail = *n + *lineptr - read_pos; + char *new_line = new char[*n]; + if (*lineptr) + { + memcpy (new_line, *lineptr, read_pos - *lineptr); + delete[] *lineptr; + } + *lineptr = new_line; + read_pos = *n - nchars_avail + *lineptr; + assert (*n - nchars_avail == (size_t) (read_pos - *lineptr)); + } + + if (c == EOF || ferror (stream)) + { + /* Return partial line, if any. */ + if (read_pos == *lineptr) + return -1; + else + break; + } + + *read_pos++ = c; + nchars_avail--; + + if (c == terminator) + /* Return the line. */ + break; + } + + /* Done - NUL terminate and return the number of chars read. */ + *read_pos = '\0'; + + return read_pos - (*lineptr + offset); +} + +int +get_line (char **lineptr, size_t *n, FILE *stream) +{ + return getstr (lineptr, n, stream, '\n', 0); +} + +int +get_delim (char **lineptr, size_t *n, int delimiter, FILE *stream) +{ + return getstr (lineptr, n, stream, delimiter, 0); +} diff --git a/contrib/gperf/lib/getline.h b/contrib/gperf/lib/getline.h new file mode 100644 index 000000000000..4456aa542fe3 --- /dev/null +++ b/contrib/gperf/lib/getline.h @@ -0,0 +1,41 @@ +/* Copyright (C) 1995, 2000-2002 Free Software Foundation, Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +USA. */ + +#ifndef GETLINE_H_ +# define GETLINE_H_ 1 + +# include +# include + +/* Like the glibc functions get_line and get_delim, except that the result + must be freed using delete[], not free(). */ + +/* Reads up to (and including) a newline from STREAM into *LINEPTR + (and null-terminate it). *LINEPTR is a pointer returned from new [] (or + NULL), pointing to *N characters of space. It is realloc'd as + necessary. Returns the number of characters read (not including the + null terminator), or -1 on error or immediate EOF. */ +extern int get_line (char **lineptr, size_t *n, FILE *stream); + +/* Reads up to (and including) a DELIMITER from STREAM into *LINEPTR + (and null-terminate it). *LINEPTR is a pointer returned from new [] (or + NULL), pointing to *N characters of space. It is realloc'd as + necessary. Returns the number of characters read (not including the + null terminator), or -1 on error or immediate EOF. */ +extern int get_delim (char **lineptr, size_t *n, int delimiter, FILE *stream); + +#endif /* not GETLINE_H_ */ diff --git a/contrib/gperf/lib/hash.cc b/contrib/gperf/lib/hash.cc index b5bb4ad66836..1795cee81c18 100644 --- a/contrib/gperf/lib/hash.cc +++ b/contrib/gperf/lib/hash.cc @@ -1,6 +1,6 @@ /* -Copyright (C) 1990, 2000 Free Software Foundation - written by Doug Lea (dl@rocky.oswego.edu) +Copyright (C) 1990, 2000, 2002 Free Software Foundation + written by Doug Lea */ #include @@ -12,14 +12,14 @@ Copyright (C) 1990, 2000 Free Software Foundation */ unsigned int -hashpjw (const char *x, unsigned int len) // From Dragon book, p436 +hashpjw (const unsigned char *x, unsigned int len) // From Dragon book, p436 { unsigned int h = 0; unsigned int g; for (; len > 0; len--) { - h = (h << 4) + (unsigned char) *x++; + h = (h << 4) + *x++; if ((g = h & 0xf0000000) != 0) h = (h ^ (g >> 24)) ^ g; } diff --git a/contrib/gperf/lib/hash.h b/contrib/gperf/lib/hash.h index 5dbc92b7a186..d202e723ad09 100644 --- a/contrib/gperf/lib/hash.h +++ b/contrib/gperf/lib/hash.h @@ -1,8 +1,8 @@ // This may look like C code, but it is really -*- C++ -*- /* -Copyright (C) 1988, 1992, 2000 Free Software Foundation - written by Doug Lea (dl@rocky.oswego.edu) +Copyright (C) 1988, 1992, 2000, 2002 Free Software Foundation + written by Doug Lea */ #ifndef _hash_h @@ -10,6 +10,6 @@ Copyright (C) 1988, 1992, 2000 Free Software Foundation /* a hash function for char[] arrays using the method described in Aho, Sethi, & Ullman, p 436. */ -extern unsigned int hashpjw (const char *string, unsigned int len); +extern unsigned int hashpjw (const unsigned char *string, unsigned int len); #endif diff --git a/contrib/gperf/src/Makefile.in b/contrib/gperf/src/Makefile.in index 60f73c735a34..19defc482c70 100644 --- a/contrib/gperf/src/Makefile.in +++ b/contrib/gperf/src/Makefile.in @@ -1,13 +1,14 @@ # Makefile for gperf/src -# Copyright (C) 1989, 1992, 1993, 1998, 2000 Free Software Foundation, Inc. -# written by Douglas C. Schmidt (schmidt@ics.uci.edu) +# Copyright (C) 1989, 1992, 1993, 1998, 2000, 2002, 2006 Free Software Foundation, Inc. +# Written by Douglas C. Schmidt +# and Bruno Haible . # # This file is part of GNU GPERF. # # GNU GPERF is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 1, or (at your option) +# the Free Software Foundation; either version 2, or (at your option) # any later version. # # GNU GPERF is distributed in the hope that it will be useful, @@ -16,8 +17,9 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with GNU GPERF; see the file COPYING. If not, write to the Free -# Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. +# along with this program; see the file COPYING. +# If not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #### Start of system configuration section. #### @@ -41,6 +43,8 @@ CXXFLAGS = @CXXFLAGS@ CXXCPP = @CXXCPP@ # Both C and C++ compiler LDFLAGS = @LDFLAGS@ +OBJEXT = @OBJEXT@ +EXEEXT = @EXEEXT@ # Other MV = mv LN = ln @@ -59,12 +63,12 @@ SHELL = /bin/sh VPATH = $(srcdir) -OBJECTS = new.o options.o iterator.o main.o gen-perf.o key-list.o list-node.o \ - hash-table.o bool-array.o read-line.o trace.o vectors.o version.o -LIBS = ../lib/libgp.a -lm +OBJECTS = version.$(OBJEXT) positions.$(OBJEXT) options.$(OBJEXT) keyword.$(OBJEXT) keyword-list.$(OBJEXT) \ + input.$(OBJEXT) bool-array.$(OBJEXT) hash-table.$(OBJEXT) search.$(OBJEXT) output.$(OBJEXT) main.$(OBJEXT) +LIBS = ../lib/libgp.a @GPERF_LIBM@ CPPFLAGS = -I. -I$(srcdir)/../lib -TARGETPROG = gperf +TARGETPROG = gperf$(EXEEXT) all : $(TARGETPROG) @@ -83,43 +87,38 @@ $(TARGETPROG): $(OBJECTS) # Dependencies. CONFIG_H = config.h VERSION_H = version.h -VECTORS_H = vectors.h -TRACE_H = trace.h -READ_LINE_H = read-line.h read-line.icc $(TRACE_H) -OPTIONS_H = options.h options.icc $(TRACE_H) -LIST_NODE_H = list-node.h $(VECTORS_H) -KEY_LIST_H = key-list.h $(LIST_NODE_H) $(VECTORS_H) $(READ_LINE_H) -ITERATOR_H = iterator.h -HASH_TABLE_H = hash-table.h $(LIST_NODE_H) -BOOL_ARRAY_H = bool-array.h bool-array.icc $(TRACE_H) $(OPTIONS_H) -GEN_PERF_H = gen-perf.h $(KEY_LIST_H) $(BOOL_ARRAY_H) +POSITIONS_H = positions.h positions.icc +OPTIONS_H = options.h options.icc $(POSITIONS_H) +KEYWORD_H = keyword.h keyword.icc +KEYWORD_LIST_H = keyword-list.h keyword-list.icc $(KEYWORD_H) +INPUT_H = input.h $(KEYWORD_LIST_H) +BOOL_ARRAY_H = bool-array.h bool-array.icc $(OPTIONS_H) +HASH_TABLE_H = hash-table.h $(KEYWORD_H) +SEARCH_H = search.h $(KEYWORD_LIST_H) $(POSITIONS_H) $(BOOL_ARRAY_H) +OUTPUT_H = output.h $(KEYWORD_LIST_H) $(POSITIONS_H) -bool-array.o : bool-array.cc $(BOOL_ARRAY_H) $(OPTIONS_H) $(TRACE_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/bool-array.cc -gen-perf.o : gen-perf.cc $(GEN_PERF_H) $(OPTIONS_H) $(TRACE_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/gen-perf.cc -hash-table.o : hash-table.cc $(HASH_TABLE_H) $(OPTIONS_H) $(TRACE_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/hash-table.cc -iterator.o : iterator.cc $(ITERATOR_H) $(TRACE_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/iterator.cc -key-list.o : key-list.cc $(KEY_LIST_H) $(OPTIONS_H) $(READ_LINE_H) $(HASH_TABLE_H) $(TRACE_H) $(VERSION_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/key-list.cc -list-node.o : list-node.cc $(LIST_NODE_H) $(OPTIONS_H) $(TRACE_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/list-node.cc -main.o : main.cc $(OPTIONS_H) $(GEN_PERF_H) $(TRACE_H) $(CONFIG_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/main.cc -new.o : new.cc $(TRACE_H) $(CONFIG_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/new.cc -options.o : options.cc $(OPTIONS_H) $(ITERATOR_H) $(TRACE_H) $(VECTORS_H) $(VERSION_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/options.cc -read-line.o : read-line.cc $(READ_LINE_H) $(OPTIONS_H) $(TRACE_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/read-line.cc -trace.o : trace.cc $(TRACE_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/trace.cc -vectors.o : vectors.cc $(VECTORS_H) - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/vectors.cc -version.o : version.cc $(VERSION_H) +version.$(OBJEXT): version.cc $(VERSION_H) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/version.cc +positions.$(OBJEXT): positions.cc $(POSITIONS_H) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/positions.cc +options.$(OBJEXT): options.cc $(OPTIONS_H) $(VERSION_H) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/options.cc +keyword.$(OBJEXT): keyword.cc $(KEYWORD_H) $(POSITIONS_H) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/keyword.cc +keyword-list.$(OBJEXT): keyword-list.cc $(KEYWORD_LIST_H) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/keyword-list.cc +input.$(OBJEXT): input.cc $(INPUT_H) $(OPTIONS_H) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/input.cc +bool-array.$(OBJEXT): bool-array.cc $(BOOL_ARRAY_H) $(OPTIONS_H) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/bool-array.cc +hash-table.$(OBJEXT): hash-table.cc $(HASH_TABLE_H) $(OPTIONS_H) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/hash-table.cc +search.$(OBJEXT): search.cc $(SEARCH_H) $(OPTIONS_H) $(HASH_TABLE_H) $(CONFIG_H) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/search.cc +output.$(OBJEXT): output.cc $(OUTPUT_H) $(OPTIONS_H) $(VERSION_H) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/output.cc +main.$(OBJEXT): main.cc $(OPTIONS_H) $(INPUT_H) $(SEARCH_H) $(OUTPUT_H) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/main.cc install : all force $(MKINSTALLDIRS) $(DESTDIR)$(bindir) @@ -136,7 +135,7 @@ check : all mostlyclean : clean clean : force - $(RM) *~ *.s *.o *.a $(TARGETPROG) core + $(RM) *~ *.s *.$(OBJEXT) *.a $(TARGETPROG) core distclean : clean $(RM) config.status config.log config.cache Makefile config.h diff --git a/contrib/gperf/src/bool-array.cc b/contrib/gperf/src/bool-array.cc index 0774b2d65265..ca3c50149afd 100644 --- a/contrib/gperf/src/bool-array.cc +++ b/contrib/gperf/src/bool-array.cc @@ -1,43 +1,41 @@ /* Fast lookup table abstraction implemented as an Iteration Number Array - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) + Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +/* Specification. */ #include "bool-array.h" #include #include #include "options.h" -#include "trace.h" -STORAGE_TYPE * Bool_Array::storage_array; -STORAGE_TYPE Bool_Array::iteration_number; -unsigned int Bool_Array::size; - -/* Prints out debugging diagnostics. */ - -Bool_Array::~Bool_Array (void) +/* Frees this object. */ +Bool_Array::~Bool_Array () { - T (Trace t ("Bool_Array::~Bool_Array");) + /* Print out debugging diagnostics. */ if (option[DEBUG]) fprintf (stderr, "\ndumping boolean array information\n" "size = %d\niteration number = %d\nend of array dump\n", - size, iteration_number); + _size, _iteration_number); + delete[] const_cast(_storage_array); } #ifndef __OPTIMIZE__ diff --git a/contrib/gperf/src/bool-array.h b/contrib/gperf/src/bool-array.h index 8330fcd22019..ddfbd869b501 100644 --- a/contrib/gperf/src/bool-array.h +++ b/contrib/gperf/src/bool-array.h @@ -2,54 +2,67 @@ /* Simple lookup table abstraction implemented as an Iteration Number Array. - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) + Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* Define and implement a simple boolean array abstraction, - uses an Iteration Numbering implementation to save on initialization time. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef bool_array_h #define bool_array_h 1 -#include "trace.h" - -#ifdef LO_CAL -/* If we are on a memory diet then we'll only make these use a limited - amount of storage space. */ -typedef unsigned short STORAGE_TYPE; -#else -typedef unsigned int STORAGE_TYPE; -#endif +/* A Bool_Array instance is a bit array of fixed size, optimized for being + filled sparsely and cleared frequently. For example, when processing + tests/chill.gperf, the array will be: + - of size 15391, + - clear will be called 3509 times, + - set_bit will be called 300394 times. + With a conventional bit array implementation, clear would be too slow. + With a tree/hash based bit array implementation, set_bit would be slower. */ class Bool_Array { -private: - static STORAGE_TYPE *storage_array; /* Initialization of the index space. */ - static STORAGE_TYPE iteration_number; /* Keep track of the current iteration. */ - static unsigned int size; /* Keep track of array size. */ - public: - Bool_Array (void); - ~Bool_Array (void); - static void init (STORAGE_TYPE *buffer, unsigned int s); - static int find (int hash_value); - static void reset (void); + /* Initializes the bit array with room for SIZE bits, numbered from + 0 to SIZE-1. */ + Bool_Array (unsigned int size); + + /* Frees this object. */ + ~Bool_Array (); + + /* Resets all bits to zero. */ + void clear (); + + /* Sets the specified bit to true. + Returns its previous value (false or true). */ + bool set_bit (unsigned int index); + +private: + /* Size of array. */ + unsigned int const _size; + + /* Current iteration number. Always nonzero. Starts out as 1, and is + incremented each time clear() is called. */ + unsigned int _iteration_number; + + /* For each index, we store in storage_array[index] the iteration_number at + the time set_bit(index) was last called. */ + unsigned int * const _storage_array; }; #ifdef __OPTIMIZE__ /* efficiency hack! */ diff --git a/contrib/gperf/src/bool-array.icc b/contrib/gperf/src/bool-array.icc index 6de6f236e712..fba4a31ace8b 100644 --- a/contrib/gperf/src/bool-array.icc +++ b/contrib/gperf/src/bool-array.icc @@ -1,84 +1,77 @@ /* Inline Functions for bool-array.{h,cc}. - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) + Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // This needs: //#include //#include //#include "options.h" -//#include "trace.h" +/* Initializes the bit array with room for SIZE bits, numbered from + 0 to SIZE-1. */ INLINE -Bool_Array::Bool_Array (void) +Bool_Array::Bool_Array (unsigned int size) + : _size (size), + _iteration_number (1), + _storage_array (new unsigned int [size]) { - T (Trace t ("Bool_Array::Bool_Array");) - storage_array = 0; - iteration_number = size = 0; -} - -INLINE void -Bool_Array::init (STORAGE_TYPE *buffer, unsigned int s) -{ - T (Trace t ("Bool_Array::init");) - size = s; - iteration_number = 1; - storage_array = buffer; - memset (storage_array, 0, s * sizeof (*storage_array)); + memset (_storage_array, 0, size * sizeof (_storage_array[0])); if (option[DEBUG]) fprintf (stderr, "\nbool array size = %d, total bytes = %d\n", - size, (unsigned int) (size * sizeof (*storage_array))); + _size, + static_cast (_size * sizeof (_storage_array[0]))); } -INLINE int -Bool_Array::find (int index) +/* Sets the specified bit to true. + Returns its previous value (false or true). */ +INLINE bool +Bool_Array::set_bit (unsigned int index) { - T (Trace t ("Bool_Array::find");) - if (storage_array[index] == iteration_number) - return 1; + if (_storage_array[index] == _iteration_number) + /* The bit was set since the last clear() call. */ + return true; else { - storage_array[index] = iteration_number; - return 0; + /* The last operation on this bit was clear(). Set it now. */ + _storage_array[index] = _iteration_number; + return false; } } +/* Resets all bits to zero. */ INLINE void -Bool_Array::reset (void) +Bool_Array::clear () { - T (Trace t ("Bool_Array::reset");) /* If we wrap around it's time to zero things out again! However, this only - occurs once about every 2^31 or 2^15 iterations, so it should probably - never happen! */ + occurs once about every 2^32 iterations, so it will not happen more + frequently than once per second. */ - if (++iteration_number == 0) + if (++_iteration_number == 0) { + _iteration_number = 1; + memset (_storage_array, 0, _size * sizeof (_storage_array[0])); if (option[DEBUG]) { - fprintf (stderr, "(re-initializing bool_array)..."); - fflush (stderr); - } - iteration_number = 1; - memset (storage_array, 0, size * sizeof (*storage_array)); - if (option[DEBUG]) - { - fprintf (stderr, "done\n"); + fprintf (stderr, "(re-initialized bool_array)\n"); fflush (stderr); } } diff --git a/contrib/gperf/src/config.h.in b/contrib/gperf/src/config.h.in index 4d3d76212d6c..1f3dc586b572 100644 --- a/contrib/gperf/src/config.h.in +++ b/contrib/gperf/src/config.h.in @@ -1,19 +1,20 @@ -/* config.h.in. Generated automatically from configure.in by autoheader. */ +/* config.h.in. Generated from configure.ac by autoheader. */ -/* Define if the C++ compiler supports "throw ()" declarations. */ -#undef HAVE_THROW_DECL +/* Define if the C++ compiler supports stack-allocated variable-size arrays. + */ +#undef HAVE_DYNAMIC_ARRAY -/* Define if you have the getrlimit function. */ -#undef HAVE_GETRLIMIT +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT -/* Define if you have the setrlimit function. */ -#undef HAVE_SETRLIMIT +/* Define to the full name of this package. */ +#undef PACKAGE_NAME -/* Define if you have the header file. */ -#undef HAVE_SYS_RESOURCE_H +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING -/* Define if you have the header file. */ -#undef HAVE_SYS_TIME_H +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME -/* Define if you have the header file. */ -#undef HAVE_UNISTD_H +/* Define to the version of this package. */ +#undef PACKAGE_VERSION diff --git a/contrib/gperf/src/config.h_vms b/contrib/gperf/src/config.h_vms new file mode 100644 index 000000000000..1f3dc586b572 --- /dev/null +++ b/contrib/gperf/src/config.h_vms @@ -0,0 +1,20 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if the C++ compiler supports stack-allocated variable-size arrays. + */ +#undef HAVE_DYNAMIC_ARRAY + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION diff --git a/contrib/gperf/src/configure b/contrib/gperf/src/configure index edd1fd7f0520..ab7048103e08 100755 --- a/contrib/gperf/src/configure +++ b/contrib/gperf/src/configure @@ -1,26 +1,662 @@ #! /bin/sh - # Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 2.13 -# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. +# Generated by GNU Autoconf 2.61. # +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## -# Defaults: -ac_help= +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + + + +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + +if test "x$CONFIG_SHELL" = x; then + if (eval ":") 2>/dev/null; then + as_have_required=yes +else + as_have_required=no +fi + + if test $as_have_required = yes && (eval ": +(as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=\$LINENO + as_lineno_2=\$LINENO + test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" && + test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; } +") 2> /dev/null; then + : +else + as_candidate_shells= + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + case $as_dir in + /*) + for as_base in sh bash ksh sh5; do + as_candidate_shells="$as_candidate_shells $as_dir/$as_base" + done;; + esac +done +IFS=$as_save_IFS + + + for as_shell in $as_candidate_shells $SHELL; do + # Try only shells that exist, to save several forks. + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { ("$as_shell") 2> /dev/null <<\_ASEOF +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + +: +_ASEOF +}; then + CONFIG_SHELL=$as_shell + as_have_required=yes + if { "$as_shell" 2> /dev/null <<\_ASEOF +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + +: +(as_func_return () { + (exit $1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = "$1" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test $exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; } + +_ASEOF +}; then + break +fi + +fi + + done + + if test "x$CONFIG_SHELL" != x; then + for as_var in BASH_ENV ENV + do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + done + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} +fi + + + if test $as_have_required = no; then + echo This script requires a shell more modern than all the + echo shells that I found on your system. Please install a + echo modern shell, or manually run the script under such a + echo shell if you do have one. + { (exit 1); exit 1; } +fi + + +fi + +fi + + + +(eval "as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0") || { + echo No shell found that supports shell functions. + echo Please tell autoconf@gnu.org about your system, + echo including any error possibly output before this + echo message +} + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + + +exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# ac_default_prefix=/usr/local -# Any additions from configure.in: +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} + +# Identity of this package. +PACKAGE_NAME= +PACKAGE_TARNAME= +PACKAGE_VERSION= +PACKAGE_STRING= +PACKAGE_BUGREPORT= + +ac_unique_file="main.cc" +ac_subst_vars='SHELL +PATH_SEPARATOR +PACKAGE_NAME +PACKAGE_TARNAME +PACKAGE_VERSION +PACKAGE_STRING +PACKAGE_BUGREPORT +exec_prefix +prefix +program_transform_name +bindir +sbindir +libexecdir +datarootdir +datadir +sysconfdir +sharedstatedir +localstatedir +includedir +oldincludedir +docdir +infodir +htmldir +dvidir +pdfdir +psdir +libdir +localedir +mandir +DEFS +ECHO_C +ECHO_N +ECHO_T +LIBS +build_alias +host_alias +target_alias +SET_MAKE +CC +CFLAGS +LDFLAGS +CPPFLAGS +ac_ct_CC +EXEEXT +OBJEXT +CPP +CXX +CXXFLAGS +ac_ct_CXX +CXXCPP +INSTALL +INSTALL_PROGRAM +INSTALL_DATA +GPERF_LIBM +LIBOBJS +LTLIBOBJS' +ac_subst_files='' + ac_precious_vars='build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CPP +CXX +CXXFLAGS +CCC +CXXCPP' + # Initialize some variables set by options. +ac_init_help= +ac_init_version=false # The variables have the same names as the options, with # dashes changed to underlines. -build=NONE -cache_file=./config.cache +cache_file=/dev/null exec_prefix=NONE -host=NONE no_create= -nonopt=NONE no_recursion= prefix=NONE program_prefix=NONE @@ -29,94 +665,117 @@ program_transform_name=s,x,x, silent= site= srcdir= -target=NONE verbose= x_includes=NONE x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' +datarootdir='${prefix}/share' +datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' includedir='${prefix}/include' oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -# Initialize some other variables. -subdirs= -MFLAGS= MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} -# Maximum number of lines to put in a shell here document. -ac_max_here_lines=12 +docdir='${datarootdir}/doc/${PACKAGE}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' ac_prev= +ac_dashdash= for ac_option do - # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" + eval $ac_prev=\$ac_option ac_prev= continue fi - case "$ac_option" in - -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; - *) ac_optarg= ;; + case $ac_option in + *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. - case "$ac_option" in + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir="$ac_optarg" ;; + bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) - ac_prev=build ;; + ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build="$ac_optarg" ;; + build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file="$ac_optarg" ;; + cache_file=$ac_optarg ;; - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir="$ac_optarg" ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; -disable-* | --disable-*) - ac_feature=`echo $ac_option|sed -e 's/-*disable-//'` + ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - eval "enable_${ac_feature}=no" ;; + expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + eval enable_$ac_feature=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; -enable-* | --enable-*) - ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'` + ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; - *) ac_optarg=yes ;; - esac - eval "enable_${ac_feature}='$ac_optarg'" ;; + expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'` + eval enable_$ac_feature=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ @@ -125,116 +784,77 @@ do -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) - exec_prefix="$ac_optarg" ;; + exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; - -help | --help | --hel | --he) - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat << EOF -Usage: configure [options] [host] -Options: [defaults in brackets after descriptions] -Configuration: - --cache-file=FILE cache test results in FILE - --help print this message - --no-create do not create output files - --quiet, --silent do not print \`checking...' messages - --version print the version of autoconf that created configure -Directory and file names: - --prefix=PREFIX install architecture-independent files in PREFIX - [$ac_default_prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [same as prefix] - --bindir=DIR user executables in DIR [EPREFIX/bin] - --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] - --libexecdir=DIR program executables in DIR [EPREFIX/libexec] - --datadir=DIR read-only architecture-independent data in DIR - [PREFIX/share] - --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] - --sharedstatedir=DIR modifiable architecture-independent data in DIR - [PREFIX/com] - --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] - --libdir=DIR object code libraries in DIR [EPREFIX/lib] - --includedir=DIR C header files in DIR [PREFIX/include] - --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] - --infodir=DIR info documentation in DIR [PREFIX/info] - --mandir=DIR man documentation in DIR [PREFIX/man] - --srcdir=DIR find the sources in DIR [configure dir or ..] - --program-prefix=PREFIX prepend PREFIX to installed program names - --program-suffix=SUFFIX append SUFFIX to installed program names - --program-transform-name=PROGRAM - run sed PROGRAM on installed program names -EOF - cat << EOF -Host type: - --build=BUILD configure for building on BUILD [BUILD=HOST] - --host=HOST configure for HOST [guessed] - --target=TARGET configure for TARGET [TARGET=HOST] -Features and packages: - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] - --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) - --x-includes=DIR X include files are in DIR - --x-libraries=DIR X library files are in DIR -EOF - if test -n "$ac_help"; then - echo "--enable and --with options recognized:$ac_help" - fi - exit 0 ;; + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; -host | --host | --hos | --ho) - ac_prev=host ;; + ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) - host="$ac_optarg" ;; + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir="$ac_optarg" ;; + includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir="$ac_optarg" ;; + infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir="$ac_optarg" ;; + libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) - libexecdir="$ac_optarg" ;; + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) + | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir="$ac_optarg" ;; + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir="$ac_optarg" ;; + mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) + | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ @@ -248,26 +868,26 @@ EOF -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir="$ac_optarg" ;; + oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix="$ac_optarg" ;; + prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix="$ac_optarg" ;; + program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix="$ac_optarg" ;; + program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ @@ -284,7 +904,17 @@ EOF | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name="$ac_optarg" ;; + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) @@ -294,7 +924,7 @@ EOF ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) - sbindir="$ac_optarg" ;; + sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ @@ -305,58 +935,53 @@ EOF | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) - sharedstatedir="$ac_optarg" ;; + sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) - site="$ac_optarg" ;; + site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir="$ac_optarg" ;; + srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir="$ac_optarg" ;; + sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target ;; + ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target="$ac_optarg" ;; + target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; - -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 2.13" - exit 0 ;; + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; -with-* | --with-*) - ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'` + ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; - *) ac_optarg=yes ;; - esac - eval "with_${ac_package}='$ac_optarg'" ;; + expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + eval with_$ac_package=\$ac_optarg ;; -without-* | --without-*) - ac_package=`echo $ac_option|sed -e 's/-*without-//'` + ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - eval "with_${ac_package}=no" ;; + expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/[-.]/_/g'` + eval with_$ac_package=no ;; --x) # Obsolete; use --with-x. @@ -367,396 +992,1478 @@ EOF ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes="$ac_optarg" ;; + x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries="$ac_optarg" ;; + x_libraries=$ac_optarg ;; - -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } + -*) { echo "$as_me: error: unrecognized option: $ac_option +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 + { (exit 1); exit 1; }; } + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + *) - if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then - echo "configure: warning: $ac_option: invalid host type" 1>&2 - fi - if test "x$nonopt" != xNONE; then - { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } - fi - nonopt="$ac_option" + # FIXME: should be removed in autoconf 3.0. + echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} ;; esac done if test -n "$ac_prev"; then - { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; } + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + { echo "$as_me: error: missing argument to $ac_option" >&2 + { (exit 1); exit 1; }; } fi -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - -# File descriptor usage: -# 0 standard input -# 1 file creation -# 2 errors and warnings -# 3 some systems may open it to /dev/tty -# 4 used on the Kubota Titan -# 6 checking for... messages and results -# 5 compiler messages saved in config.log -if test "$silent" = yes; then - exec 6>/dev/null -else - exec 6>&1 -fi -exec 5>./config.log - -echo "\ -This file contains any messages produced by compilers while -running configure, to aid debugging if configure makes a mistake. -" 1>&5 - -# Strip out --no-create and --no-recursion so they do not pile up. -# Also quote any args containing shell metacharacters. -ac_configure_args= -for ac_arg +# Be sure to have absolute directory names. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir do - case "$ac_arg" in - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) ;; - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; - *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*) - ac_configure_args="$ac_configure_args '$ac_arg'" ;; - *) ac_configure_args="$ac_configure_args $ac_arg" ;; + eval ac_val=\$$ac_var + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac + { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; } done -# NLS nuisances. -# Only set these to C if already set. These must not be set unconditionally -# because not all systems understand e.g. LANG=C (notably SCO). -# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'! -# Non-C LC_CTYPE values break the ctype check. -if test "${LANG+set}" = set; then LANG=C; export LANG; fi -if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi -if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi -if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo > confdefs.h +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + { echo "$as_me: error: Working directory cannot be determined" >&2 + { (exit 1); exit 1; }; } +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + { echo "$as_me: error: pwd does not report name of working directory" >&2 + { (exit 1); exit 1; }; } -# A filename unique to this package, relative to the directory that -# configure is in, which we can look for to find out if srcdir is correct. -ac_unique_file=gen-perf.cc # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_prog=$0 - ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` - test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$0" || +$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$0" : 'X\(//\)[^/]' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X"$0" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then + if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; } - else - { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; } - fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 + { (exit 1); exit 1; }; } fi -srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'` +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || { echo "$as_me: error: $ac_msg" >&2 + { (exit 1); exit 1; }; } + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures this package to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF +_ACEOF fi -for ac_site_file in $CONFIG_SITE; do + +if test -n "$ac_init_help"; then + + cat <<\_ACEOF + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CPP C preprocessor + CXX C++ compiler command + CXXFLAGS C++ compiler flags + CXXCPP C++ preprocessor + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +configure +generated by GNU Autoconf 2.61 + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by $as_me, which was +generated by GNU Autoconf 2.61. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + echo "PATH: $as_dir" +done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; + 2) + ac_configure_args1="$ac_configure_args1 '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + ac_configure_args="$ac_configure_args '$ac_arg'" + ;; + esac + done +done +$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } +$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + cat <<\_ASBOX +## ---------------- ## +## Cache variables. ## +## ---------------- ## +_ASBOX + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + cat <<\_ASBOX +## ----------------- ## +## Output variables. ## +## ----------------- ## +_ASBOX + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + cat <<\_ASBOX +## ------------------- ## +## File substitutions. ## +## ------------------- ## +_ASBOX + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + cat <<\_ASBOX +## ----------- ## +## confdefs.h. ## +## ----------- ## +_ASBOX + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + echo "$as_me: caught signal $ac_signal" + echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer explicitly selected file to automatically selected ones. +if test -n "$CONFIG_SITE"; then + set x "$CONFIG_SITE" +elif test "x$prefix" != xNONE; then + set x "$prefix/share/config.site" "$prefix/etc/config.site" +else + set x "$ac_default_prefix/share/config.site" \ + "$ac_default_prefix/etc/config.site" +fi +shift +for ac_site_file +do if test -r "$ac_site_file"; then - echo "loading site script $ac_site_file" + { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 +echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" fi done if test -r "$cache_file"; then - echo "loading cache $cache_file" - . $cache_file -else - echo "creating cache $cache_file" - > $cache_file -fi - -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross - -ac_exeext= -ac_objext=o -if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then - # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. - if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then - ac_n= ac_c=' -' ac_t=' ' - else - ac_n=-n ac_c= ac_t= + # Some versions of bash will fail to source /dev/null (special + # files actually), so we avoid doing that. + if test -f "$cache_file"; then + { echo "$as_me:$LINENO: loading cache $cache_file" >&5 +echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac fi else - ac_n= ac_c='\c' ac_t= + { echo "$as_me:$LINENO: creating cache $cache_file" >&5 +echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 +echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { echo "$as_me:$LINENO: former value: $ac_old_val" >&5 +echo "$as_me: former value: $ac_old_val" >&2;} + { echo "$as_me:$LINENO: current value: $ac_new_val" >&5 +echo "$as_me: current value: $ac_new_val" >&2;} + ac_cache_corrupted=: + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 +echo "$as_me: error: changes in the environment can compromise the build" >&2;} + { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 +echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} + { (exit 1); exit 1; }; } fi -echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6 -echo "configure:527: checking whether ${MAKE-make} sets \${MAKE}" >&5 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + + + + + + + + + + + + + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +ac_config_headers="$ac_config_headers config.h" + +{ echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +echo $ECHO_N "checking whether ${MAKE-make} sets \$(MAKE)... $ECHO_C" >&6; } +set x ${MAKE-make}; ac_make=`echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - cat > conftestmake <<\EOF + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh all: - @echo 'ac_maketemp="${MAKE}"' -EOF + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF # GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftestmake 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make fi -rm -f conftestmake -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$ac_t""yes" 1>&6 +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } SET_MAKE= else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi -# Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:556: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CC="gcc" - break - fi - done - IFS="$ac_save_ifs" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + fi fi -CC="$ac_cv_prog_CC" +CC=$ac_cv_prog_CC if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" fi if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:586: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" ac_prog_rejected=no - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue - fi - ac_cv_prog_CC="cc" - break - fi - done - IFS="$ac_save_ifs" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift - if test $# -gt 0; then + if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift - set dummy "$ac_dir/$ac_word" "$@" - shift - ac_cv_prog_CC="$@" + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi -CC="$ac_cv_prog_CC" +CC=$ac_cv_prog_CC if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } fi - if test -z "$CC"; then - case "`uname -s`" in - *win32* | *WIN32*) - # Extract the first word of "cl", so it can be a program name with args. -set dummy cl; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:637: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CC="cl" - break - fi - done - IFS="$ac_save_ifs" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + fi fi -CC="$ac_cv_prog_CC" +CC=$ac_cv_prog_CC if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } else - echo "$ac_t""no" 1>&6 + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } fi - ;; - esac + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 fi - test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; } +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } fi -echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:669: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross + test -n "$ac_ct_CC" && break +done -cat > conftest.$ac_ext << EOF - -#line 680 "configure" -#include "confdefs.h" - -main(){return(0);} -EOF -if { (eval echo configure:685: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - ac_cv_prog_cc_works=yes - # If we can't run a trivial program, we are probably using a cross compiler. - if (./conftest; exit) 2>/dev/null; then - ac_cv_prog_cc_cross=no + if test "x$ac_ct_CC" = x; then + CC="" else - ac_cv_prog_cc_cross=yes + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC fi -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_prog_cc_works=no fi -rm -fr conftest* -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross -echo "$ac_t""$ac_cv_prog_cc_works" 1>&6 -if test $ac_cv_prog_cc_works = no; then - { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi -echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:711: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 -echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 -cross_compiling=$ac_cv_prog_cc_cross -echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:716: checking whether we are using GNU C" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + +test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&5 +echo "$as_me: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + +# Provide some information about the compiler. +echo "$as_me:$LINENO: checking for C compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (ac_try="$ac_compiler --version >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler --version >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -v >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -v >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -V >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -V >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ echo "$as_me:$LINENO: checking for C compiler default output file name" >&5 +echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6; } +ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` +# +# List of possible output files, starting from the most likely. +# The algorithm is not robust to junk in `.', hence go to wildcards (a.*) +# only as a last resort. b.out is created by i960 compilers. +ac_files='a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out' +# +# The IRIX 6 linker writes into existing files which may not be +# executable, retaining their permissions. Remove them first so a +# subsequent execution test works. +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { (ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + else - cat > conftest.c <&5 +echo "${ECHO_T}$ac_file" >&6; } +if test -z "$ac_file"; then + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: C compiler cannot create executables +See \`config.log' for more details." >&5 +echo "$as_me: error: C compiler cannot create executables +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } +fi + +ac_exeext=$ac_cv_exeext + +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ echo "$as_me:$LINENO: checking whether the C compiler works" >&5 +echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6; } +# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 +# If not cross compiling, check that we can run a simple program. +if test "$cross_compiling" != yes; then + if { ac_try='./$ac_file' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { echo "$as_me:$LINENO: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + fi + fi +fi +{ echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + +rm -f a.out a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ echo "$as_me:$LINENO: checking whether we are cross compiling" >&5 +echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6; } +{ echo "$as_me:$LINENO: result: $cross_compiling" >&5 +echo "${ECHO_T}$cross_compiling" >&6; } + +{ echo "$as_me:$LINENO: checking for suffix of executables" >&5 +echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6; } +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest$ac_cv_exeext +{ echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5 +echo "${ECHO_T}$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +{ echo "$as_me:$LINENO: checking for suffix of object files" >&5 +echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6; } +if test "${ac_cv_objext+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_objext" >&5 +echo "${ECHO_T}$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6; } +if test "${ac_cv_c_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me #endif -EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:725: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then - ac_cv_prog_gcc=yes + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_compiler_gnu=yes else - ac_cv_prog_gcc=no -fi + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_compiler_gnu=no fi -echo "$ac_t""$ac_cv_prog_gcc" 1>&6 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu -if test $ac_cv_prog_gcc = yes; then - GCC=yes -else - GCC= fi - -ac_test_CFLAGS="${CFLAGS+set}" -ac_save_CFLAGS="$CFLAGS" -CFLAGS= -echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:744: checking whether ${CC-cc} accepts -g" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +{ echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6; } +GCC=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 +echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6; } +if test "${ac_cv_prog_cc_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - echo 'void f(){}' > conftest.c -if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then ac_cv_prog_cc_g=yes else - ac_cv_prog_cc_g=no -fi -rm -f conftest* + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + CFLAGS="" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cc_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + fi -echo "$ac_t""$ac_cv_prog_cc_g" 1>&6 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then - CFLAGS="$ac_save_CFLAGS" + CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" @@ -770,216 +2477,702 @@ else CFLAGS= fi fi +{ echo "$as_me:$LINENO: checking for $CC option to accept ISO C89" >&5 +echo $ECHO_N "checking for $CC option to accept ISO C89... $ECHO_C" >&6; } +if test "${ac_cv_prog_cc_c89+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} - echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:776: checking how to run the C preprocessor" >&5 +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cc_c89=$ac_arg +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { echo "$as_me:$LINENO: result: none needed" >&5 +echo "${ECHO_T}none needed" >&6; } ;; + xno) + { echo "$as_me:$LINENO: result: unsupported" >&5 +echo "${ECHO_T}unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { echo "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_c89" >&6; } ;; +esac + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 +echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6; } # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then -if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + if test "${ac_cv_prog_CPP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - # This must be in double quotes, not single quotes, because CPP may get - # substituted into the Makefile and "${CC-cc}" will confuse make. - CPP="${CC-cc} -E" - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:797: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` -if test -z "$ac_err"; then - : -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP="${CC-cc} -E -traditional-cpp" - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:814: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` -if test -z "$ac_err"; then - : -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP="${CC-cc} -nologo -E" - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:831: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` -if test -z "$ac_err"; then - : -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP=/lib/cpp -fi -rm -f conftest* -fi -rm -f conftest* -fi -rm -f conftest* - ac_cv_prog_CPP="$CPP" -fi - CPP="$ac_cv_prog_CPP" -else - ac_cv_prog_CPP="$CPP" -fi -echo "$ac_t""$CPP" 1>&6 - - for ac_prog in $CCC c++ g++ gcc CC cxx cc++ cl + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes do -# Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:860: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CXX'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ echo "$as_me:$LINENO: result: $CPP" >&5 +echo "${ECHO_T}$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + : +else + { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&5 +echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +if test -z "$CXX"; then + if test -n "$CCC"; then + CXX=$CCC + else + if test -n "$ac_tool_prefix"; then + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CXX+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CXX"; then ac_cv_prog_CXX="$CXX" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CXX="$ac_prog" - break - fi - done - IFS="$ac_save_ifs" -fi -fi -CXX="$ac_cv_prog_CXX" -if test -n "$CXX"; then - echo "$ac_t""$CXX" 1>&6 -else - echo "$ac_t""no" 1>&6 -fi - -test -n "$CXX" && break -done -test -n "$CXX" || CXX="gcc" - - -echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:892: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5 - -ac_ext=C -# CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CXXCPP $CPPFLAGS' -ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cxx_cross - -cat > conftest.$ac_ext << EOF - -#line 903 "configure" -#include "confdefs.h" - -int main(){return(0);} -EOF -if { (eval echo configure:908: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - ac_cv_prog_cxx_works=yes - # If we can't run a trivial program, we are probably using a cross compiler. - if (./conftest; exit) 2>/dev/null; then - ac_cv_prog_cxx_cross=no - else - ac_cv_prog_cxx_cross=yes +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 fi -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_prog_cxx_works=no -fi -rm -fr conftest* -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross +done +done +IFS=$as_save_IFS -echo "$ac_t""$ac_cv_prog_cxx_works" 1>&6 -if test $ac_cv_prog_cxx_works = no; then - { echo "configure: error: installation or configuration problem: C++ compiler cannot create executables." 1>&2; exit 1; } fi -echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:934: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5 -echo "$ac_t""$ac_cv_prog_cxx_cross" 1>&6 -cross_compiling=$ac_cv_prog_cxx_cross - -echo $ac_n "checking whether we are using GNU C++""... $ac_c" 1>&6 -echo "configure:939: checking whether we are using GNU C++" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_gxx'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +fi +CXX=$ac_cv_prog_CXX +if test -n "$CXX"; then + { echo "$as_me:$LINENO: result: $CXX" >&5 +echo "${ECHO_T}$CXX" >&6; } else - cat > conftest.C <&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$CXX" && break + done +fi +if test -z "$CXX"; then + ac_ct_CXX=$CXX + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CXX"; then + ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CXX="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CXX=$ac_cv_prog_ac_ct_CXX +if test -n "$ac_ct_CXX"; then + { echo "$as_me:$LINENO: result: $ac_ct_CXX" >&5 +echo "${ECHO_T}$ac_ct_CXX" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$ac_ct_CXX" && break +done + + if test "x$ac_ct_CXX" = x; then + CXX="g++" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CXX=$ac_ct_CXX + fi +fi + + fi +fi +# Provide some information about the compiler. +echo "$as_me:$LINENO: checking for C++ compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (ac_try="$ac_compiler --version >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler --version >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -v >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -v >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -V >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -V >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + +{ echo "$as_me:$LINENO: checking whether we are using the GNU C++ compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C++ compiler... $ECHO_C" >&6; } +if test "${ac_cv_cxx_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me #endif -EOF -if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:948: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then - ac_cv_prog_gxx=yes + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_compiler_gnu=yes else - ac_cv_prog_gxx=no -fi + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_compiler_gnu=no fi -echo "$ac_t""$ac_cv_prog_gxx" 1>&6 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_cxx_compiler_gnu=$ac_compiler_gnu -if test $ac_cv_prog_gxx = yes; then - GXX=yes -else - GXX= fi - -ac_test_CXXFLAGS="${CXXFLAGS+set}" -ac_save_CXXFLAGS="$CXXFLAGS" -CXXFLAGS= -echo $ac_n "checking whether ${CXX-g++} accepts -g""... $ac_c" 1>&6 -echo "configure:967: checking whether ${CXX-g++} accepts -g" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_cxx_g'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +{ echo "$as_me:$LINENO: result: $ac_cv_cxx_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_cxx_compiler_gnu" >&6; } +GXX=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CXXFLAGS=${CXXFLAGS+set} +ac_save_CXXFLAGS=$CXXFLAGS +{ echo "$as_me:$LINENO: checking whether $CXX accepts -g" >&5 +echo $ECHO_N "checking whether $CXX accepts -g... $ECHO_C" >&6; } +if test "${ac_cv_prog_cxx_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - echo 'void f(){}' > conftest.cc -if test -z "`${CXX-g++} -g -c conftest.cc 2>&1`"; then + ac_save_cxx_werror_flag=$ac_cxx_werror_flag + ac_cxx_werror_flag=yes + ac_cv_prog_cxx_g=no + CXXFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then ac_cv_prog_cxx_g=yes else - ac_cv_prog_cxx_g=no -fi -rm -f conftest* + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + CXXFLAGS="" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cxx_werror_flag=$ac_save_cxx_werror_flag + CXXFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_prog_cxx_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + fi -echo "$ac_t""$ac_cv_prog_cxx_g" 1>&6 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_cxx_werror_flag=$ac_save_cxx_werror_flag +fi +{ echo "$as_me:$LINENO: result: $ac_cv_prog_cxx_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cxx_g" >&6; } if test "$ac_test_CXXFLAGS" = set; then - CXXFLAGS="$ac_save_CXXFLAGS" + CXXFLAGS=$ac_save_CXXFLAGS elif test $ac_cv_prog_cxx_g = yes; then if test "$GXX" = yes; then CXXFLAGS="-g -O2" @@ -993,49 +3186,237 @@ else CXXFLAGS= fi fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu - echo $ac_n "checking how to run the C++ preprocessor""... $ac_c" 1>&6 -echo "configure:999: checking how to run the C++ preprocessor" >&5 -if test -z "$CXXCPP"; then -if eval "test \"`echo '$''{'ac_cv_prog_CXXCPP'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_ext=C -# CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. + ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' -ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cxx_cross - CXXCPP="${CXX-g++} -E" - cat > conftest.$ac_ext < -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1017: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` -if test -z "$ac_err"; then +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +{ echo "$as_me:$LINENO: checking how to run the C++ preprocessor" >&5 +echo $ECHO_N "checking how to run the C++ preprocessor... $ECHO_C" >&6; } +if test -z "$CXXCPP"; then + if test "${ac_cv_prog_CXXCPP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # Double quotes because CXXCPP needs to be expanded + for CXXCPP in "$CXX -E" "/lib/cpp" + do + ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then : else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CXXCPP=/lib/cpp + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue fi -rm -f conftest* - ac_cv_prog_CXXCPP="$CXXCPP" + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + break +fi + + done + ac_cv_prog_CXXCPP=$CXXCPP + +fi + CXXCPP=$ac_cv_prog_CXXCPP +else + ac_cv_prog_CXXCPP=$CXXCPP +fi +{ echo "$as_me:$LINENO: result: $CXXCPP" >&5 +echo "${ECHO_T}$CXXCPP" >&6; } +ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + : +else + { { echo "$as_me:$LINENO: error: C++ preprocessor \"$CXXCPP\" fails sanity check +See \`config.log' for more details." >&5 +echo "$as_me: error: C++ preprocessor \"$CXXCPP\" fails sanity check +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross -fi -fi -CXXCPP="$ac_cv_prog_CXXCPP" -echo "$ac_t""$CXXCPP" 1>&6 +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or @@ -1047,11 +3428,11 @@ echo "$ac_t""$CXXCPP" 1>&6 # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. -echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:1052: checking for a BSD compatible install" >&5 +{ echo "$as_me:$LINENO: checking for a BSD compatible install" >&5 +echo $ECHO_N "checking for a BSD compatible install... $ECHO_C" >&6; } if test -z "$INSTALL"; then -if eval "test \"`echo '$''{'cl_cv_path_install'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +if test "${cl_cv_path_install+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" for ac_dir in $PATH; do @@ -1089,7 +3470,8 @@ else fi INSTALL="$cl_cv_path_install" fi -echo "$ac_t""$INSTALL" 1>&6 +{ echo "$as_me:$LINENO: result: $INSTALL" >&5 +echo "${ECHO_T}$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='$(INSTALL)' @@ -1100,561 +3482,1244 @@ if test -z "$INSTALL_DATA"; then esac fi - echo $ac_n "checking for working throw()""... $ac_c" 1>&6 -echo "configure:1105: checking for working throw()" >&5 -if eval "test \"`echo '$''{'gp_cv_cxx_throw_decl'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - + { echo "$as_me:$LINENO: checking for stack-allocated variable-size arrays" >&5 +echo $ECHO_N "checking for stack-allocated variable-size arrays... $ECHO_C" >&6; } -ac_ext=C -# CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. +if test "${gp_cv_cxx_dynamic_array+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + + +ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' -ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cxx_cross +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu -cat > conftest.$ac_ext < -void operator delete (void* ptr) throw() {} -int main() { +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +int func (int n) { int dynamic_array[n]; } +int +main () +{ -; return 0; } -EOF -if { (eval echo configure:1127: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* - gp_cv_cxx_throw_decl=yes + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + gp_cv_cxx_dynamic_array=yes else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - gp_cv_cxx_throw_decl=no + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + gp_cv_cxx_dynamic_array=no fi -rm -f conftest* + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu fi -echo "$ac_t""$gp_cv_cxx_throw_decl" 1>&6 -if test $gp_cv_cxx_throw_decl = yes; then - cat >> confdefs.h <<\EOF -#define HAVE_THROW_DECL 1 -EOF +{ echo "$as_me:$LINENO: result: $gp_cv_cxx_dynamic_array" >&5 +echo "${ECHO_T}$gp_cv_cxx_dynamic_array" >&6; } +if test $gp_cv_cxx_dynamic_array = yes; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_DYNAMIC_ARRAY 1 +_ACEOF fi -for ac_hdr in unistd.h sys/time.h sys/resource.h -do -ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` -echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1158: checking for $ac_hdr" >&5 -if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 + +{ echo "$as_me:$LINENO: checking for rand in -lm" >&5 +echo $ECHO_N "checking for rand in -lm... $ECHO_C" >&6; } +if test "${ac_cv_lib_m_rand+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - cat > conftest.$ac_ext < -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1168: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` -if test -z "$ac_err"; then - rm -rf conftest* - eval "ac_cv_header_$ac_safe=yes" -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_header_$ac_safe=no" -fi -rm -f conftest* -fi -if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` - cat >> confdefs.h <&6 -fi -done + ac_check_lib_save_LIBS=$LIBS +LIBS="-lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ - if test $ac_cv_header_sys_resource_h = yes; then -for ac_func in getrlimit -do -echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1198: checking for $ac_func" >&5 -if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - cat > conftest.$ac_ext < -/* Override any gcc2 internal prototype to avoid an error. */ -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func(); - -int main() { - -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -$ac_func(); +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" #endif - -; return 0; } -EOF -if { (eval echo configure:1226: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_func_$ac_func=yes" +char rand (); +int +main () +{ +return rand (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + ac_cv_lib_m_rand=yes else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_func_$ac_func=no" -fi -rm -f conftest* + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_m_rand=no fi -if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` - cat >> confdefs.h <&5 +echo "${ECHO_T}$ac_cv_lib_m_rand" >&6; } +if test $ac_cv_lib_m_rand = yes; then + GPERF_LIBM="-lm" else - echo "$ac_t""no" 1>&6 -fi -done - - if test $ac_cv_func_getrlimit = yes; then -for ac_func in setrlimit -do -echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1254: checking for $ac_func" >&5 -if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - cat > conftest.$ac_ext < -/* Override any gcc2 internal prototype to avoid an error. */ -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func(); - -int main() { - -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -$ac_func(); -#endif - -; return 0; } -EOF -if { (eval echo configure:1282: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_func_$ac_func=yes" -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_func_$ac_func=no" -fi -rm -f conftest* + GPERF_LIBM="" fi -if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` - cat >> confdefs.h <&6 -fi -done - fi -fi -trap '' 1 2 15 -cat > confcache <<\EOF +ac_config_files="$ac_config_files Makefile" + +cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure -# scripts and configure runs. It is not useful on other systems. -# If it contains results you don't want to keep, you may remove or edit it. +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. # -# By default, configure uses ./config.cache as the cache file, -# creating it if it does not exist already. You can give configure -# the --cache-file=FILE option to use a different cache file; that is -# what configure does when it calls configure scripts in -# subdirectories, so they share the cache. -# Giving --cache-file=/dev/null disables caching, for debugging configure. -# config.status only pays attention to the cache file if you give it the -# --recheck option to rerun configure. +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. # -EOF +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. +# So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. -(set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote substitution - # turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - -e "s/'/'\\\\''/g" \ - -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p' - ;; - esac >> confcache -if cmp -s $cache_file confcache; then - : -else - if test -w $cache_file; then - echo "updating cache $cache_file" - cat confcache > $cache_file +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + test "x$cache_file" != "x/dev/null" && + { echo "$as_me:$LINENO: updating cache $cache_file" >&5 +echo "$as_me: updating cache $cache_file" >&6;} + cat confcache >$cache_file else - echo "not updating unwritable cache $cache_file" + { echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5 +echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' -# Any assignment to VPATH causes Sun make to only execute -# the first set of double-colon rules, so remove it if not needed. -# If there is a colon in the path, we need to keep it. -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d' -fi - -trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 - DEFS=-DHAVE_CONFIG_H -# Without the "./", some shells look in PATH for config.status. +ac_libobjs= +ac_ltlibobjs= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext" + ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + + : ${CONFIG_STATUS=./config.status} - -echo creating $CONFIG_STATUS -rm -f $CONFIG_STATUS -cat > $CONFIG_STATUS <&5 +echo "$as_me: creating $CONFIG_STATUS" >&6;} +cat >$CONFIG_STATUS <<_ACEOF +#! $SHELL +# Generated by $as_me. # Run this file to recreate the current configuration. -# This directory was configured as follows, -# on host `(hostname || uname -n) 2>/dev/null | sed 1q`: -# -# $0 $ac_configure_args -# # Compiler output produced by configure, useful for debugging -# configure, is in ./config.log if it exists. +# configure, is in config.log if it exists. -ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]" -for ac_option +debug=false +ac_cs_recheck=false +ac_cs_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in + *posix*) set -o posix ;; +esac + +fi + + + + +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH do - case "\$ac_option" in + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 + +# Save the log message, to keep $[0] and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by $as_me, which was +generated by GNU Autoconf 2.61. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF +# Files that config.status was made for. +config_files="$ac_config_files" +config_headers="$ac_config_headers" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +ac_cs_usage="\ +\`$as_me' instantiates files from templates according to the +current configuration. + +Usage: $0 [OPTIONS] [FILE]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + --header=FILE[:TEMPLATE] + instantiate the configuration header FILE + +Configuration files: +$config_files + +Configuration headers: +$config_headers + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +ac_cs_version="\\ +config.status +configured by $0, generated by GNU Autoconf 2.61, + with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" + +Copyright (C) 2006 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If no file are specified by the user, then we need to provide default +# value. By we need to know if files were specified by the user. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" - exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; - -version | --version | --versio | --versi | --vers | --ver | --ve | --v) - echo "$CONFIG_STATUS generated by autoconf version 2.13" - exit 0 ;; - -help | --help | --hel | --he | --h) - echo "\$ac_cs_usage"; exit 0 ;; - *) echo "\$ac_cs_usage"; exit 1 ;; + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + echo "$ac_cs_version"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + CONFIG_FILES="$CONFIG_FILES $ac_optarg" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg" + ac_need_defaults=false;; + --he | --h) + # Conflict between --help and --header + { echo "$as_me: error: ambiguous option: $1 +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; };; + --help | --hel | -h ) + echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) { echo "$as_me: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + + *) ac_config_targets="$ac_config_targets $1" + ac_need_defaults=false ;; + esac + shift done -ac_given_srcdir=$srcdir +ac_configure_extra_args= -trap 'rm -fr `echo "Makefile config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 -EOF -cat >> $CONFIG_STATUS < conftest.subs <<\\CEOF -$ac_vpsub -$extrasub -s%@SHELL@%$SHELL%g -s%@CFLAGS@%$CFLAGS%g -s%@CPPFLAGS@%$CPPFLAGS%g -s%@CXXFLAGS@%$CXXFLAGS%g -s%@FFLAGS@%$FFLAGS%g -s%@DEFS@%$DEFS%g -s%@LDFLAGS@%$LDFLAGS%g -s%@LIBS@%$LIBS%g -s%@exec_prefix@%$exec_prefix%g -s%@prefix@%$prefix%g -s%@program_transform_name@%$program_transform_name%g -s%@bindir@%$bindir%g -s%@sbindir@%$sbindir%g -s%@libexecdir@%$libexecdir%g -s%@datadir@%$datadir%g -s%@sysconfdir@%$sysconfdir%g -s%@sharedstatedir@%$sharedstatedir%g -s%@localstatedir@%$localstatedir%g -s%@libdir@%$libdir%g -s%@includedir@%$includedir%g -s%@oldincludedir@%$oldincludedir%g -s%@infodir@%$infodir%g -s%@mandir@%$mandir%g -s%@SET_MAKE@%$SET_MAKE%g -s%@CC@%$CC%g -s%@CPP@%$CPP%g -s%@CXX@%$CXX%g -s%@CXXCPP@%$CXXCPP%g -s%@INSTALL@%$INSTALL%g -s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g -s%@INSTALL_DATA@%$INSTALL_DATA%g - -CEOF -EOF - -cat >> $CONFIG_STATUS <<\EOF - -# Split the substitutions into bite-sized pieces for seds with -# small command number limits, like on Digital OSF/1 and HP-UX. -ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script. -ac_file=1 # Number of current file. -ac_beg=1 # First line for current file. -ac_end=$ac_max_sed_cmds # Line after last line for current file. -ac_more_lines=: -ac_sed_cmds="" -while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file - else - sed "${ac_end}q" conftest.subs > conftest.s$ac_file - fi - if test ! -s conftest.s$ac_file; then - ac_more_lines=false - rm -f conftest.s$ac_file - else - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f conftest.s$ac_file" - else - ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file" - fi - ac_file=`expr $ac_file + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_cmds` - fi -done -if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" fi -EOF -cat >> $CONFIG_STATUS <>$CONFIG_STATUS <<_ACEOF +if \$ac_cs_recheck; then + echo "running CONFIG_SHELL=$SHELL $SHELL $0 "$ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6 + CONFIG_SHELL=$SHELL + export CONFIG_SHELL + exec $SHELL "$0"$ac_configure_args \$ac_configure_extra_args --no-create --no-recursion +fi -CONFIG_FILES=\${CONFIG_FILES-"Makefile"} -EOF -cat >> $CONFIG_STATUS <<\EOF -for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case "$ac_file" in - *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` - ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; - *) ac_file_in="${ac_file}.in" ;; - esac - - # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories. - - # Remove last slash and all that follows it. Not all systems have dirname. - ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - # The file is in a subdirectory. - test ! -d "$ac_dir" && mkdir "$ac_dir" - ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`" - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` - else - ac_dir_suffix= ac_dots= - fi - - case "$ac_given_srcdir" in - .) srcdir=. - if test -z "$ac_dots"; then top_srcdir=. - else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;; - /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;; - *) # Relative path. - srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix" - top_srcdir="$ac_dots$ac_given_srcdir" ;; +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + + *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 +echo "$as_me: error: invalid argument: $ac_config_target" >&2;} + { (exit 1); exit 1; }; };; esac +done - echo creating "$ac_file" - rm -f "$ac_file" - configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure." - case "$ac_file" in - *Makefile*) ac_comsub="1i\\ -# $configure_input" ;; - *) ac_comsub= ;; - esac +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers +fi - ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` - sed -e "$ac_comsub -s%@configure_input@%$configure_input%g -s%@srcdir@%$srcdir%g -s%@top_srcdir@%$top_srcdir%g -" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file -fi; done -rm -f conftest.s* +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= + trap 'exit_status=$? + { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status +' 0 + trap '{ (exit 1); exit 1; }' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || +{ + echo "$me: cannot create a temporary directory in ." >&2 + { (exit 1); exit 1; } +} -# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where -# NAME is the cpp macro being defined and VALUE is the value it is being given. # -# ac_d sets the value in "#define NAME VALUE" lines. -ac_dA='s%^\([ ]*\)#\([ ]*define[ ][ ]*\)' -ac_dB='\([ ][ ]*\)[^ ]*%\1#\2' -ac_dC='\3' -ac_dD='%g' -# ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE". -ac_uA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_uB='\([ ]\)%\1#\2define\3' -ac_uC=' ' -ac_uD='\4%g' -# ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE". -ac_eA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_eB='$%\1#\2define\3' -ac_eC=' ' -ac_eD='%g' +# Set up the sed scripts for CONFIG_FILES section. +# -if test "${CONFIG_HEADERS+set}" != set; then -EOF -cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF +# No need to generate the scripts if there are no CONFIG_FILES. +# This happens for instance when ./config.status config.h +if test -n "$CONFIG_FILES"; then + +_ACEOF + + + +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + cat >conf$$subs.sed <<_ACEOF +SHELL!$SHELL$ac_delim +PATH_SEPARATOR!$PATH_SEPARATOR$ac_delim +PACKAGE_NAME!$PACKAGE_NAME$ac_delim +PACKAGE_TARNAME!$PACKAGE_TARNAME$ac_delim +PACKAGE_VERSION!$PACKAGE_VERSION$ac_delim +PACKAGE_STRING!$PACKAGE_STRING$ac_delim +PACKAGE_BUGREPORT!$PACKAGE_BUGREPORT$ac_delim +exec_prefix!$exec_prefix$ac_delim +prefix!$prefix$ac_delim +program_transform_name!$program_transform_name$ac_delim +bindir!$bindir$ac_delim +sbindir!$sbindir$ac_delim +libexecdir!$libexecdir$ac_delim +datarootdir!$datarootdir$ac_delim +datadir!$datadir$ac_delim +sysconfdir!$sysconfdir$ac_delim +sharedstatedir!$sharedstatedir$ac_delim +localstatedir!$localstatedir$ac_delim +includedir!$includedir$ac_delim +oldincludedir!$oldincludedir$ac_delim +docdir!$docdir$ac_delim +infodir!$infodir$ac_delim +htmldir!$htmldir$ac_delim +dvidir!$dvidir$ac_delim +pdfdir!$pdfdir$ac_delim +psdir!$psdir$ac_delim +libdir!$libdir$ac_delim +localedir!$localedir$ac_delim +mandir!$mandir$ac_delim +DEFS!$DEFS$ac_delim +ECHO_C!$ECHO_C$ac_delim +ECHO_N!$ECHO_N$ac_delim +ECHO_T!$ECHO_T$ac_delim +LIBS!$LIBS$ac_delim +build_alias!$build_alias$ac_delim +host_alias!$host_alias$ac_delim +target_alias!$target_alias$ac_delim +SET_MAKE!$SET_MAKE$ac_delim +CC!$CC$ac_delim +CFLAGS!$CFLAGS$ac_delim +LDFLAGS!$LDFLAGS$ac_delim +CPPFLAGS!$CPPFLAGS$ac_delim +ac_ct_CC!$ac_ct_CC$ac_delim +EXEEXT!$EXEEXT$ac_delim +OBJEXT!$OBJEXT$ac_delim +CPP!$CPP$ac_delim +CXX!$CXX$ac_delim +CXXFLAGS!$CXXFLAGS$ac_delim +ac_ct_CXX!$ac_ct_CXX$ac_delim +CXXCPP!$CXXCPP$ac_delim +INSTALL!$INSTALL$ac_delim +INSTALL_PROGRAM!$INSTALL_PROGRAM$ac_delim +INSTALL_DATA!$INSTALL_DATA$ac_delim +GPERF_LIBM!$GPERF_LIBM$ac_delim +LIBOBJS!$LIBOBJS$ac_delim +LTLIBOBJS!$LTLIBOBJS$ac_delim +_ACEOF + + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 56; then + break + elif $ac_last_try; then + { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 +echo "$as_me: error: could not make $CONFIG_STATUS" >&2;} + { (exit 1); exit 1; }; } + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed` +if test -n "$ac_eof"; then + ac_eof=`echo "$ac_eof" | sort -nru | sed 1q` + ac_eof=`expr $ac_eof + 1` fi -for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case "$ac_file" in - *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` - ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; - *) ac_file_in="${ac_file}.in" ;; + +cat >>$CONFIG_STATUS <<_ACEOF +cat >"\$tmp/subs-1.sed" <<\CEOF$ac_eof +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b end +_ACEOF +sed ' +s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g +s/^/s,@/; s/!/@,|#_!!_#|/ +:n +t n +s/'"$ac_delim"'$/,g/; t +s/$/\\/; p +N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n +' >>$CONFIG_STATUS >$CONFIG_STATUS <<_ACEOF +:end +s/|#_!!_#|//g +CEOF$ac_eof +_ACEOF + + +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/ +s/:*\${srcdir}:*/:/ +s/:*@srcdir@:*/:/ +s/^\([^=]*=[ ]*\):*/\1/ +s/:*$// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF +fi # test -n "$CONFIG_FILES" + + +for ac_tag in :F $CONFIG_FILES :H $CONFIG_HEADERS +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) { { echo "$as_me:$LINENO: error: Invalid tag $ac_tag." >&5 +echo "$as_me: error: Invalid tag $ac_tag." >&2;} + { (exit 1); exit 1; }; };; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + { { echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5 +echo "$as_me: error: cannot find input file: $ac_f" >&2;} + { (exit 1); exit 1; }; };; + esac + ac_file_inputs="$ac_file_inputs $ac_f" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input="Generated from "`IFS=: + echo $* | sed 's|^[^:]*/||;s|:[^:]*/|, |g'`" by configure." + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + fi + + case $ac_tag in + *:-:* | *:-) cat >"$tmp/stdin";; + esac + ;; esac - echo creating $ac_file + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + { as_dir="$ac_dir" + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5 +echo "$as_me: error: cannot create directory $as_dir" >&2;} + { (exit 1); exit 1; }; }; } + ac_builddir=. - rm -f conftest.frag conftest.in conftest.out - ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` - cat $ac_file_inputs > conftest.in +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix -EOF +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix -# Transform confdefs.h into a sed script conftest.vals that substitutes -# the proper values into config.h.in to produce config.h. And first: -# Protect against being on the right side of a sed subst in config.status. -# Protect against being in an unquoted here document in config.status. -rm -f conftest.vals -cat > conftest.hdr <<\EOF -s/[\\&%]/\\&/g -s%[\\$`]%\\&%g -s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp -s%ac_d%ac_u%gp -s%ac_u%ac_e%gp -EOF -sed -n -f conftest.hdr confdefs.h > conftest.vals -rm -f conftest.hdr -# This sed command replaces #undef with comments. This is necessary, for + case $ac_mode in + :F) + # + # CONFIG_FILE + # + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= + +case `sed -n '/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p +' $ac_file_inputs` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF + sed "$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s&@configure_input@&$configure_input&;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +$ac_datarootdir_hack +" $ac_file_inputs | sed -f "$tmp/subs-1.sed" >$tmp/out + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && + { echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&5 +echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&2;} + + rm -f "$tmp/stdin" + case $ac_file in + -) cat "$tmp/out"; rm -f "$tmp/out";; + *) rm -f "$ac_file"; mv "$tmp/out" $ac_file;; + esac + ;; + :H) + # + # CONFIG_HEADER + # +_ACEOF + +# Transform confdefs.h into a sed script `conftest.defines', that +# substitutes the proper values into config.h.in to produce config.h. +rm -f conftest.defines conftest.tail +# First, append a space to every undef/define line, to ease matching. +echo 's/$/ /' >conftest.defines +# Then, protect against being on the right side of a sed subst, or in +# an unquoted here document, in config.status. If some macros were +# called several times there might be several #defines for the same +# symbol, which is useless. But do not sort them, since the last +# AC_DEFINE must be honored. +ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* +# These sed commands are passed to sed as "A NAME B PARAMS C VALUE D", where +# NAME is the cpp macro being defined, VALUE is the value it is being given. +# PARAMS is the parameter list in the macro definition--in most cases, it's +# just an empty string. +ac_dA='s,^\\([ #]*\\)[^ ]*\\([ ]*' +ac_dB='\\)[ (].*,\\1define\\2' +ac_dC=' ' +ac_dD=' ,' + +uniq confdefs.h | + sed -n ' + t rset + :rset + s/^[ ]*#[ ]*define[ ][ ]*// + t ok + d + :ok + s/[\\&,]/\\&/g + s/^\('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/ '"$ac_dA"'\1'"$ac_dB"'\2'"${ac_dC}"'\3'"$ac_dD"'/p + s/^\('"$ac_word_re"'\)[ ]*\(.*\)/'"$ac_dA"'\1'"$ac_dB$ac_dC"'\2'"$ac_dD"'/p + ' >>conftest.defines + +# Remove the space that was appended to ease matching. +# Then replace #undef with comments. This is necessary, for # example, in the case of _POSIX_SOURCE, which is predefined and required # on some systems where configure will not decide to define it. -cat >> conftest.vals <<\EOF -s%^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*%/* & */% -EOF +# (The regexp can be short, since the line contains either #define or #undef.) +echo 's/ $// +s,^[ #]*u.*,/* & */,' >>conftest.defines -# Break up conftest.vals because some shells have a limit on -# the size of here documents, and old seds have small limits too. +# Break up conftest.defines: +ac_max_sed_lines=50 + +# First sed command is: sed -f defines.sed $ac_file_inputs >"$tmp/out1" +# Second one is: sed -f defines.sed "$tmp/out1" >"$tmp/out2" +# Third one will be: sed -f defines.sed "$tmp/out2" >"$tmp/out1" +# et cetera. +ac_in='$ac_file_inputs' +ac_out='"$tmp/out1"' +ac_nxt='"$tmp/out2"' -rm -f conftest.tail while : do - ac_lines=`grep -c . conftest.vals` - # grep -c gives empty output for an empty file on some AIX systems. - if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi - # Write a limited-size here document to conftest.frag. - echo ' cat > conftest.frag <> $CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS + # Write a here document: + cat >>$CONFIG_STATUS <<_ACEOF + # First, check the format of the line: + cat >"\$tmp/defines.sed" <<\\CEOF +/^[ ]*#[ ]*undef[ ][ ]*$ac_word_re[ ]*\$/b def +/^[ ]*#[ ]*define[ ][ ]*$ac_word_re[( ]/b def +b +:def +_ACEOF + sed ${ac_max_sed_lines}q conftest.defines >>$CONFIG_STATUS echo 'CEOF - sed -f conftest.frag conftest.in > conftest.out - rm -f conftest.in - mv conftest.out conftest.in -' >> $CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail - rm -f conftest.vals - mv conftest.tail conftest.vals + sed -f "$tmp/defines.sed"' "$ac_in >$ac_out" >>$CONFIG_STATUS + ac_in=$ac_out; ac_out=$ac_nxt; ac_nxt=$ac_in + sed 1,${ac_max_sed_lines}d conftest.defines >conftest.tail + grep . conftest.tail >/dev/null || break + rm -f conftest.defines + mv conftest.tail conftest.defines done -rm -f conftest.vals +rm -f conftest.defines conftest.tail -cat >> $CONFIG_STATUS <<\EOF - rm -f conftest.frag conftest.h - echo "/* $ac_file. Generated automatically by configure. */" > conftest.h - cat conftest.in >> conftest.h - rm -f conftest.in - if cmp -s $ac_file conftest.h 2>/dev/null; then - echo "$ac_file is unchanged" - rm -f conftest.h - else - # Remove last slash and all that follows it. Not all systems have dirname. - ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - # The file is in a subdirectory. - test ! -d "$ac_dir" && mkdir "$ac_dir" +echo "ac_result=$ac_in" >>$CONFIG_STATUS +cat >>$CONFIG_STATUS <<\_ACEOF + if test x"$ac_file" != x-; then + echo "/* $configure_input */" >"$tmp/config.h" + cat "$ac_result" >>"$tmp/config.h" + if diff $ac_file "$tmp/config.h" >/dev/null 2>&1; then + { echo "$as_me:$LINENO: $ac_file is unchanged" >&5 +echo "$as_me: $ac_file is unchanged" >&6;} + else + rm -f $ac_file + mv "$tmp/config.h" $ac_file fi - rm -f $ac_file - mv conftest.h $ac_file + else + echo "/* $configure_input */" + cat "$ac_result" fi -fi; done + rm -f "$tmp/out12" + ;; -EOF -cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF + esac -exit 0 -EOF +done # for ac_tag + + +{ (exit 0); exit 0; } +_ACEOF chmod +x $CONFIG_STATUS -rm -fr confdefs* $ac_clean_files -test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1 +ac_clean_files=$ac_clean_files_save + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || { (exit 1); exit 1; } +fi diff --git a/contrib/gperf/src/configure.in b/contrib/gperf/src/configure.ac similarity index 53% rename from contrib/gperf/src/configure.in rename to contrib/gperf/src/configure.ac index e8880d507f85..b7b91a0b191e 100644 --- a/contrib/gperf/src/configure.in +++ b/contrib/gperf/src/configure.ac @@ -1,13 +1,14 @@ dnl autoconf configuration for gperf/src -dnl Copyright (C) 1998, 2000 Free Software Foundation, Inc. -dnl written by Douglas C. Schmidt (schmidt@ics.uci.edu) +dnl Copyright (C) 1998, 2000, 2002-2003, 2007 Free Software Foundation, Inc. +dnl Written by Douglas C. Schmidt +dnl and Bruno Haible . dnl dnl This file is part of GNU GPERF. dnl dnl GNU GPERF is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by -dnl the Free Software Foundation; either version 1, or (at your option) +dnl the Free Software Foundation; either version 2, or (at your option) dnl any later version. dnl dnl GNU GPERF is distributed in the hope that it will be useful, @@ -16,11 +17,12 @@ dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the dnl GNU General Public License for more details. dnl dnl You should have received a copy of the GNU General Public License -dnl along with GNU GPERF; see the file COPYING. If not, write to the -dnl Free Software Foundation, 59 Temple Place - Suite 330, Boston, -dnl MA 02111-1307, USA. +dnl along with this program; see the file COPYING. +dnl If not, write to the Free Software Foundation, Inc., +dnl 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -AC_INIT(gen-perf.cc) +AC_PREREQ([2.60]) +AC_INIT(main.cc) AC_CONFIG_HEADER(config.h) AC_PROG_MAKE_SET dnl @@ -39,32 +41,27 @@ CL_PROG_INSTALL dnl dnl checks for compiler characteristics dnl -AC_MSG_CHECKING([for working throw()]) -AC_CACHE_VAL(gp_cv_cxx_throw_decl,[ +AC_MSG_CHECKING([for stack-allocated variable-size arrays]) +AC_CACHE_VAL(gp_cv_cxx_dynamic_array, [ AC_LANG_SAVE() AC_LANG_CPLUSPLUS() -AC_TRY_COMPILE([#include -void operator delete (void* ptr) throw() {}], [], -gp_cv_cxx_throw_decl=yes, gp_cv_cxx_throw_decl=no) +AC_TRY_COMPILE([int func (int n) { int dynamic_array[n]; }], [], +gp_cv_cxx_dynamic_array=yes, gp_cv_cxx_dynamic_array=no) AC_LANG_RESTORE() ]) -AC_MSG_RESULT([$]gp_cv_cxx_throw_decl) -if test [$]gp_cv_cxx_throw_decl = yes; then - AC_DEFINE(HAVE_THROW_DECL) +AC_MSG_RESULT($gp_cv_cxx_dynamic_array) +if test $gp_cv_cxx_dynamic_array = yes; then + AC_DEFINE(HAVE_DYNAMIC_ARRAY, 1, + [Define if the C++ compiler supports stack-allocated variable-size arrays.]) fi dnl dnl checks for functions and declarations dnl -AC_CHECK_HEADERS(unistd.h sys/time.h sys/resource.h) - dnl DEFs HAVE_UNISTD_H, HAVE_SYS_TIME_H, HAVE_SYS_RESOURCE_H -if test $ac_cv_header_sys_resource_h = yes; then -AC_CHECK_FUNCS(getrlimit) - dnl DEFS HAVE_GETRLIMIT -if test $ac_cv_func_getrlimit = yes; then -AC_CHECK_FUNCS(setrlimit) - dnl DEFS HAVE_SETRLIMIT -fi -fi +dnl +dnl checks for libraries +dnl +AC_CHECK_LIB(m, rand, GPERF_LIBM="-lm", GPERF_LIBM="") +AC_SUBST(GPERF_LIBM) dnl dnl That's it. dnl diff --git a/contrib/gperf/src/gen-perf.cc b/contrib/gperf/src/gen-perf.cc deleted file mode 100644 index 7cf9f068b9cf..000000000000 --- a/contrib/gperf/src/gen-perf.cc +++ /dev/null @@ -1,359 +0,0 @@ -/* Provides high-level routines to manipulate the keywork list - structures the code generation output. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#include -#include /* declares rand(), srand() */ -#include /* declares time() */ -#include "options.h" -#include "gen-perf.h" -#include "trace.h" - -/* Efficiently returns the least power of two greater than or equal to X! */ -#define POW(X) ((!X)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X))) - -/* Reads input keys, possibly applies the reordering heuristic, sets the - maximum associated value size (rounded up to the nearest power of 2), - may initialize the associated values array, and determines the maximum - hash table size. Note: using the random numbers is often helpful, - though not as deterministic, of course! */ - -Gen_Perf::Gen_Perf (void) -{ - T (Trace t ("Gen_Perf::Gen_Perf");) - int asso_value_max; - int non_linked_length; - - Key_List::read_keys (); - if (option[ORDER]) - reorder (); - asso_value_max = option.get_asso_max (); - non_linked_length = Key_List::keyword_list_length (); - num_done = 1; - fewest_collisions = 0; - if (asso_value_max == 0) - asso_value_max = non_linked_length; - else if (asso_value_max > 0) - asso_value_max *= non_linked_length; - else /* if (asso_value_max < 0) */ - asso_value_max = non_linked_length / -asso_value_max; - option.set_asso_max (POW (asso_value_max)); - - if (option[RANDOM]) - { - srand ((long) time (0)); - - for (int i = 0; i < ALPHA_SIZE; i++) - asso_values[i] = (rand () & asso_value_max - 1); - } - else - { - int asso_value = option.initial_value (); - - if (asso_value) /* Initialize array if user requests non-zero default. */ - for (int i = ALPHA_SIZE - 1; i >= 0; i--) - asso_values[i] = asso_value & option.get_asso_max () - 1; - } - max_hash_value = Key_List::max_key_length () + option.get_asso_max () * - option.get_max_keysig_size (); - - if (option[DEBUG]) - fprintf (stderr, "total non-linked keys = %d\nmaximum associated value is %d" - "\nmaximum size of generated hash table is %d\n", - non_linked_length, asso_value_max, max_hash_value); -} - -/* Merge two disjoint hash key multisets to form the ordered disjoint union of the sets. - (In a multiset, an element can occur multiple times.) - Precondition: both set_1 and set_2 must be ordered. Returns the length - of the combined set. */ - -inline int -Gen_Perf::compute_disjoint_union (const char *set_1, int size_1, const char *set_2, int size_2, char *set_3) -{ - T (Trace t ("Gen_Perf::compute_disjoint_union");) - char *base = set_3; - - while (size_1 > 0 && size_2 > 0) - if (*set_1 == *set_2) - set_1++, size_1--, set_2++, size_2--; - else - { - char next; - if (*set_1 < *set_2) - next = *set_1++, size_1--; - else - next = *set_2++, size_2--; - if (set_3 == base || next != set_3[-1]) - *set_3++ = next; - } - - while (size_1 > 0) - { - char next; - next = *set_1++, size_1--; - if (set_3 == base || next != set_3[-1]) - *set_3++ = next; - } - - while (size_2 > 0) - { - char next; - next = *set_2++, size_2--; - if (set_3 == base || next != set_3[-1]) - *set_3++ = next; - } - return set_3 - base; -} - -/* Sort the UNION_SET in increasing frequency of occurrence. - This speeds up later processing since we may assume the resulting - set (Set_3, in this case), is ordered. Uses insertion sort, since - the UNION_SET is typically short. */ - -inline void -Gen_Perf::sort_set (char *union_set, int len) -{ - T (Trace t ("Gen_Perf::sort_set");) - int i, j; - - for (i = 0, j = len - 1; i < j; i++) - { - int curr; - char tmp; - - for (curr = i + 1, tmp = union_set[curr]; - curr > 0 && occurrences[(unsigned char)tmp] < occurrences[(unsigned char)(union_set[curr-1])]; - curr--) - union_set[curr] = union_set[curr - 1]; - - union_set[curr] = tmp; - } -} - -/* Generate a key set's hash value. */ - -inline int -Gen_Perf::hash (List_Node *key_node) -{ - T (Trace t ("Gen_Perf::hash");) - int sum = option[NOLENGTH] ? 0 : key_node->key_length; - - const char *p = key_node->char_set; - int i = key_node->char_set_length; - for (; i > 0; p++, i--) - sum += asso_values[(unsigned char)(*p)]; - - return key_node->hash_value = sum; -} - -/* Find out how character value change affects successfully hashed items. - Returns FALSE if no other hash values are affected, else returns TRUE. - Note that because Option.Get_Asso_Max is a power of two we can guarantee - that all legal Asso_Values are visited without repetition since - Option.Get_Jump was forced to be an odd value! */ - -inline int -Gen_Perf::affects_prev (char c, List_Node *curr) -{ - T (Trace t ("Gen_Perf::affects_prev");) - int original_char = asso_values[(unsigned char)c]; - int total_iterations = !option[FAST] - ? option.get_asso_max () : option.get_iterations () ? option.get_iterations () : keyword_list_length (); - - /* Try all legal associated values. */ - - for (int i = total_iterations - 1; i >= 0; i--) - { - int collisions = 0; - - asso_values[(unsigned char)c] = - (asso_values[(unsigned char)c] + (option.get_jump () ? option.get_jump () : rand ())) - & (option.get_asso_max () - 1); - - /* Iteration Number array is a win, O(1) intialization time! */ - reset (); - - /* See how this asso_value change affects previous keywords. If - it does better than before we'll take it! */ - - for (List_Node *ptr = head; - !Bool_Array::find (hash (ptr)) || ++collisions < fewest_collisions; - ptr = ptr->next) - if (ptr == curr) - { - fewest_collisions = collisions; - if (option[DEBUG]) - fprintf (stderr, "- resolved after %d iterations", total_iterations - i); - return 0; - } - } - - /* Restore original values, no more tries. */ - asso_values[(unsigned char)c] = original_char; - /* If we're this far it's time to try the next character.... */ - return 1; -} - -/* Change a character value, try least-used characters first. */ - -void -Gen_Perf::change (List_Node *prior, List_Node *curr) -{ - T (Trace t ("Gen_Perf::change");) - static char *union_set; - int union_set_length; - - if (!union_set) - union_set = new char [2 * option.get_max_keysig_size ()]; - - if (option[DEBUG]) - { - fprintf (stderr, "collision on keyword #%d, prior = \"%.*s\", curr = \"%.*s\" hash = %d\n", - num_done, - prior->key_length, prior->key, - curr->key_length, curr->key, - curr->hash_value); - fflush (stderr); - } - union_set_length = compute_disjoint_union (prior->char_set, prior->char_set_length, curr->char_set, curr->char_set_length, union_set); - sort_set (union_set, union_set_length); - - /* Try changing some values, if change doesn't alter other values continue normal action. */ - fewest_collisions++; - - const char *p = union_set; - int i = union_set_length; - for (; i > 0; p++, i--) - if (!affects_prev (*p, curr)) - { - if (option[DEBUG]) - { - fprintf (stderr, " by changing asso_value['%c'] (char #%td) to %d\n", - *p, p - union_set + 1, asso_values[(unsigned char)(*p)]); - fflush (stderr); - } - return; /* Good, doesn't affect previous hash values, we'll take it. */ - } - - for (List_Node *ptr = head; ptr != curr; ptr = ptr->next) - hash (ptr); - - hash (curr); - - if (option[DEBUG]) - { - fprintf (stderr, "** collision not resolved after %d iterations, %d duplicates remain, continuing...\n", - !option[FAST] ? option.get_asso_max () : option.get_iterations () ? option.get_iterations () : keyword_list_length (), - fewest_collisions + total_duplicates); - fflush (stderr); - } -} - -/* Does the hard stuff.... - Initializes the Iteration Number array, and attempts to find a perfect - function that will hash all the key words without getting any - duplications. This is made much easier since we aren't attempting - to generate *minimum* functions, only perfect ones. - If we can't generate a perfect function in one pass *and* the user - hasn't enabled the DUP option, we'll inform the user to try the - randomization option, use -D, or choose alternative key positions. - The alternatives (e.g., back-tracking) are too time-consuming, i.e, - exponential in the number of keys. */ - -int -Gen_Perf::operator() (void) -{ - T (Trace t ("Gen_Perf::operator()");) -#if LARGE_STACK_ARRAYS - STORAGE_TYPE buffer[max_hash_value + 1]; -#else - // Note: we don't use new, because that invokes a custom operator new. - STORAGE_TYPE *buffer - = (STORAGE_TYPE*) malloc (sizeof(STORAGE_TYPE) * (max_hash_value + 1)); - if (buffer == NULL) - abort (); -#endif - - Bool_Array::init (buffer, max_hash_value + 1); - - List_Node *curr; - for (curr = head; curr; curr = curr->next) - { - hash (curr); - - for (List_Node *ptr = head; ptr != curr; ptr = ptr->next) - if (ptr->hash_value == curr->hash_value) - { - change (ptr, curr); - break; - } - num_done++; - } - - /* Make one final check, just to make sure nothing weird happened.... */ - - Bool_Array::reset (); - - for (curr = head; curr; curr = curr->next) - if (Bool_Array::find (hash (curr))) - if (option[DUP]) /* Keep track of this number... */ - total_duplicates++; - else /* Yow, big problems. we're outta here! */ - { - fprintf (stderr, "\nInternal error, duplicate value %d:\n" - "try options -D or -r, or use new key positions.\n\n", hash (curr)); -#if !LARGE_STACK_ARRAYS - free ((char *) buffer); -#endif - return 1; - } - - /* Sorts the key word list by hash value, and then outputs the list. - The generated hash table code is only output if the early stage of - processing turned out O.K. */ - - sort (); - output (); -#if !LARGE_STACK_ARRAYS - free ((char *) buffer); -#endif - return 0; -} - -/* Prints out some diagnostics upon completion. */ - -Gen_Perf::~Gen_Perf (void) -{ - T (Trace t ("Gen_Perf::~Gen_Perf");) - if (option[DEBUG]) - { - fprintf (stderr, "\ndumping occurrence and associated values tables\n"); - - for (int i = 0; i < ALPHA_SIZE; i++) - if (occurrences[i]) - fprintf (stderr, "asso_values[%c] = %6d, occurrences[%c] = %6d\n", - i, asso_values[i], i, occurrences[i]); - - fprintf (stderr, "end table dumping\n"); - - } -} - diff --git a/contrib/gperf/src/gen-perf.h b/contrib/gperf/src/gen-perf.h deleted file mode 100644 index 602d160131d3..000000000000 --- a/contrib/gperf/src/gen-perf.h +++ /dev/null @@ -1,50 +0,0 @@ -/* This may look like C code, but it is really -*- C++ -*- */ - -/* Provides high-level routines to manipulate the keyword list - structures the code generation output. - - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#ifndef gen_perf_h -#define gen_perf_h 1 - -#include "key-list.h" -#include "bool-array.h" - -class Gen_Perf : private Key_List, private Bool_Array -{ -private: - int max_hash_value; /* Maximum possible hash value. */ - int fewest_collisions; /* Records fewest # of collisions for asso value. */ - int num_done; /* Number of keywords processed without a collision. */ - - void change (List_Node *prior, List_Node *curr); - int affects_prev (char c, List_Node *curr); - static int hash (List_Node *key_node); - static int compute_disjoint_union (const char *set_1, int size_1, const char *set_2, int size_2, char *set_3); - static void sort_set (char *union_set, int len); - -public: - Gen_Perf (void); - ~Gen_Perf (void); - int operator () (void); -}; - -#endif diff --git a/contrib/gperf/src/hash-table.cc b/contrib/gperf/src/hash-table.cc index a147674b3074..d98d90a21109 100644 --- a/contrib/gperf/src/hash-table.cc +++ b/contrib/gperf/src/hash-table.cc @@ -1,95 +1,167 @@ /* Hash table for checking keyword links. Implemented using double hashing. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) + Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +/* Specification. */ #include "hash-table.h" #include #include /* declares memset(), strcmp() */ #include #include "options.h" -#include "trace.h" -/* The size of the hash table is always the smallest power of 2 >= the size - indicated by the user. This allows several optimizations, including - the use of double hashing and elimination of the mod instruction. - Note that the size had better be larger than the number of items - in the hash table, else there's trouble!!! Note that the memory - for the hash table is allocated *outside* the intialization routine. - This compromises information hiding somewhat, but greatly reduces - memory fragmentation, since we can now use alloca! */ +/* We use a hash table with double hashing. This is the simplest kind of + hash table, given that we always only insert and never remove entries + from the hash table. */ -Hash_Table::Hash_Table (List_Node **table_ptr, int s, int ignore_len): - table (table_ptr), size (s), collisions (0), ignore_length (ignore_len) +/* To make double hashing efficient, there need to be enough spare entries. */ +static const int size_factor = 10; + +/* We make the size of the hash table a power of 2. This allows for two + optimizations: It eliminates the modulo instruction, and allows for an + easy secondary hashing function. */ + +/* Constructor. */ +Hash_Table::Hash_Table (unsigned int size, bool ignore_length) + : _ignore_length (ignore_length), + _collisions (0) { - T (Trace t ("Hash_Table::Hash_Table");) - memset ((char *) table, 0, size * sizeof (*table)); -} + /* There need to be enough spare entries. */ + size = size * size_factor; -Hash_Table::~Hash_Table (void) -{ - T (Trace t ("Hash_Table::~Hash_Table");) - if (option[DEBUG]) + /* Find smallest power of 2 that is >= size. */ + unsigned int shift = 0; + if ((size >> 16) > 0) { - int field_width = option.get_max_keysig_size (); - - fprintf (stderr, - "\ndumping the hash table\n" - "total available table slots = %d, total bytes = %d, total collisions = %d\n" - "location, %*s, keyword\n", - size, size * (int) sizeof (*table), collisions, - field_width, "keysig"); - - for (int i = size - 1; i >= 0; i--) - if (table[i]) - fprintf (stderr, "%8d, %*.*s, %.*s\n", - i, - field_width, table[i]->char_set_length, table[i]->char_set, - table[i]->key_length, table[i]->key); - - fprintf (stderr, "\nend dumping hash table\n\n"); + size = size >> 16; + shift += 16; } + if ((size >> 8) > 0) + { + size = size >> 8; + shift += 8; + } + if ((size >> 4) > 0) + { + size = size >> 4; + shift += 4; + } + if ((size >> 2) > 0) + { + size = size >> 2; + shift += 2; + } + if ((size >> 1) > 0) + { + size = size >> 1; + shift += 1; + } + _log_size = shift; + _size = 1 << shift; + + /* Allocate table. */ + _table = new KeywordExt*[_size]; + memset (_table, 0, _size * sizeof (*_table)); } -/* If the ITEM is already in the hash table return the item found - in the table. Otherwise inserts the ITEM, and returns FALSE. - Uses double hashing. */ - -List_Node * -Hash_Table::insert (List_Node *item) +/* Destructor. */ +Hash_Table::~Hash_Table () { - T (Trace t ("Hash_Table::operator()");) - unsigned hash_val = hashpjw (item->char_set, item->char_set_length); - int probe = hash_val & (size - 1); - int increment = ((hash_val ^ item->key_length) | 1) & (size - 1); + delete[] _table; +} - while (table[probe]) +/* Print the table's contents. */ +void +Hash_Table::dump () const +{ + int field_width; + + field_width = 0; + { + for (int i = _size - 1; i >= 0; i--) + if (_table[i]) + if (field_width < _table[i]->_selchars_length) + field_width = _table[i]->_selchars_length; + } + + fprintf (stderr, + "\ndumping the hash table\n" + "total available table slots = %d, total bytes = %d, total collisions = %d\n" + "location, %*s, keyword\n", + _size, _size * static_cast(sizeof (*_table)), + _collisions, field_width, "keysig"); + + for (int i = _size - 1; i >= 0; i--) + if (_table[i]) + { + fprintf (stderr, "%8d, ", i); + if (field_width > _table[i]->_selchars_length) + fprintf (stderr, "%*s", field_width - _table[i]->_selchars_length, ""); + for (int j = 0; j < _table[i]->_selchars_length; j++) + putc (_table[i]->_selchars[j], stderr); + fprintf (stderr, ", %.*s\n", + _table[i]->_allchars_length, _table[i]->_allchars); + } + + fprintf (stderr, "\nend dumping hash table\n\n"); +} + +/* Compares two items. */ +inline bool +Hash_Table::equal (KeywordExt *item1, KeywordExt *item2) const +{ + return item1->_selchars_length == item2->_selchars_length + && memcmp (item1->_selchars, item2->_selchars, + item2->_selchars_length * sizeof (unsigned int)) + == 0 + && (_ignore_length + || item1->_allchars_length == item2->_allchars_length); +} + +/* Attempts to insert ITEM in the table. If there is already an equal + entry in it, returns it. Otherwise inserts ITEM and returns NULL. */ +KeywordExt * +Hash_Table::insert (KeywordExt *item) +{ + unsigned hash_val = + hashpjw (reinterpret_cast(item->_selchars), + item->_selchars_length * sizeof (unsigned int)); + unsigned int probe = hash_val & (_size - 1); + unsigned int increment = + (((hash_val >> _log_size) + ^ (_ignore_length ? 0 : item->_allchars_length)) + << 1) + 1; + /* Note that because _size is a power of 2 and increment is odd, + we have gcd(increment,_size) = 1, which guarantees that we'll find + an empty entry during the loop. */ + + while (_table[probe] != NULL) { - if (table[probe]->char_set_length == item->char_set_length - && memcmp (table[probe]->char_set, item->char_set, item->char_set_length) == 0 - && (ignore_length || table[probe]->key_length == item->key_length)) - return table[probe]; + if (equal (_table[probe], item)) + return _table[probe]; - collisions++; - probe = (probe + increment) & (size - 1); + _collisions++; + probe = (probe + increment) & (_size - 1); } - table[probe] = item; - return (List_Node *) 0; + _table[probe] = item; + return NULL; } diff --git a/contrib/gperf/src/hash-table.h b/contrib/gperf/src/hash-table.h index 86438d00f7d6..d6938eb4d1f0 100644 --- a/contrib/gperf/src/hash-table.h +++ b/contrib/gperf/src/hash-table.h @@ -2,42 +2,65 @@ /* Hash table used to check for duplicate keyword entries. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) + Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef hash_table_h #define hash_table_h 1 -#include "list-node.h" +#include "keyword.h" + +/* Hash table of KeywordExt* entries. + Two entries are considered equal if their _selchars are the same and + - if !ignore_length - if their _allchars_length are the same. */ class Hash_Table { -private: - List_Node **table; /* Vector of pointers to linked lists of List_Node's. */ - int size; /* Size of the vector. */ - int collisions; /* Find out how well our double hashing is working! */ - int ignore_length; - public: - Hash_Table (List_Node **t, int s, int ignore_len); - ~Hash_Table (void); - List_Node *insert (List_Node *item); + /* Constructor. + size is the maximum number of entries. + ignore_length determines a detail in the comparison function. */ + Hash_Table (unsigned int size, bool ignore_length); + /* Destructor. */ + ~Hash_Table (); + /* Attempts to insert ITEM in the table. If there is already an equal + entry in it, returns it. Otherwise inserts ITEM and returns NULL. */ + KeywordExt * insert (KeywordExt *item); + /* Print the table's contents. */ + void dump () const; + +private: + /* Vector of entries. */ + KeywordExt ** _table; + /* Size of the vector. */ + unsigned int _size; + /* log2(_size). */ + unsigned int _log_size; + /* A detail of the comparison function. */ + bool const _ignore_length; + /* Statistics: Number of collisions so far. */ + unsigned int _collisions; + + /* Compares two items. */ + bool equal (KeywordExt *item1, KeywordExt *item2) const; }; #endif diff --git a/contrib/gperf/src/input.cc b/contrib/gperf/src/input.cc new file mode 100644 index 000000000000..247b5a4df745 --- /dev/null +++ b/contrib/gperf/src/input.cc @@ -0,0 +1,1005 @@ +/* Input routines. + Copyright (C) 1989-1998, 2002-2004 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Specification. */ +#include "input.h" + +#include +#include /* declares exit() */ +#include /* declares strncpy(), strchr() */ +#include /* defines UCHAR_MAX etc. */ +#include "options.h" +#include "getline.h" + +Input::Input (FILE *stream, Keyword_Factory *keyword_factory) + : _stream (stream), _factory (keyword_factory) +{ +} + +/* Returns a pretty representation of the input file name, for error and + warning messages. */ +static const char * +pretty_input_file_name () +{ + if (option.get_input_file_name ()) + return option.get_input_file_name (); + else + return "(standard input)"; +} + +/* Returns true if the given line contains a "%DECL" declaration. */ +static bool +is_declaration (const char *line, const char *line_end, unsigned int lineno, + const char *decl) +{ + /* Skip '%'. */ + line++; + + /* Skip DECL. */ + for (const char *d = decl; *d; d++) + { + if (!(line < line_end)) + return false; + if (!(*line == *d || (*d == '-' && *line == '_'))) + return false; + line++; + } + if (line < line_end + && ((*line >= 'A' && *line <= 'Z') + || (*line >= 'a' && *line <= 'z') + || *line == '-' || *line == '_')) + return false; + + /* OK, found DECL. */ + + /* Skip whitespace. */ + while (line < line_end && (*line == ' ' || *line == '\t')) + line++; + + /* Expect end of line. */ + if (line < line_end && *line != '\n') + { + fprintf (stderr, "%s:%u: junk after declaration\n", + pretty_input_file_name (), lineno); + exit (1); + } + + return true; +} + +/* Tests if the given line contains a "%DECL=ARG" declaration. + If yes, it sets *ARGP to the argument, and returns true. + Otherwise, it returns false. */ +static bool +is_declaration_with_arg (const char *line, const char *line_end, + unsigned int lineno, + const char *decl, char **argp) +{ + /* Skip '%'. */ + line++; + + /* Skip DECL. */ + for (const char *d = decl; *d; d++) + { + if (!(line < line_end)) + return false; + if (!(*line == *d || (*d == '-' && *line == '_'))) + return false; + line++; + } + if (line < line_end + && ((*line >= 'A' && *line <= 'Z') + || (*line >= 'a' && *line <= 'z') + || *line == '-' || *line == '_')) + return false; + + /* OK, found DECL. */ + + /* Skip '='. */ + if (!(line < line_end && *line == '=')) + { + fprintf (stderr, "%s:%u: missing argument in %%%s=ARG declaration.\n", + pretty_input_file_name (), lineno, decl); + exit (1); + } + line++; + + /* The next word is the argument. */ + char *arg = new char[line_end - line + 1]; + char *p = arg; + while (line < line_end && !(*line == ' ' || *line == '\t' || *line == '\n')) + *p++ = *line++; + *p = '\0'; + + /* Skip whitespace. */ + while (line < line_end && (*line == ' ' || *line == '\t')) + line++; + + /* Expect end of line. */ + if (line < line_end && *line != '\n') + { + fprintf (stderr, "%s:%u: junk after declaration\n", + pretty_input_file_name (), lineno); + exit (1); + } + + *argp = arg; + return true; +} + +/* Tests if the given line contains a "%define DECL ARG" declaration. + If yes, it sets *ARGP to the argument, and returns true. + Otherwise, it returns false. */ +static bool +is_define_declaration (const char *line, const char *line_end, + unsigned int lineno, + const char *decl, char **argp) +{ + /* Skip '%'. */ + line++; + + /* Skip "define". */ + { + for (const char *d = "define"; *d; d++) + { + if (!(line < line_end)) + return false; + if (!(*line == *d)) + return false; + line++; + } + if (!(line < line_end && (*line == ' ' || *line == '\t'))) + return false; + } + + /* Skip whitespace. */ + while (line < line_end && (*line == ' ' || *line == '\t')) + line++; + + /* Skip DECL. */ + for (const char *d = decl; *d; d++) + { + if (!(line < line_end)) + return false; + if (!(*line == *d || (*d == '-' && *line == '_'))) + return false; + line++; + } + if (line < line_end + && ((*line >= 'A' && *line <= 'Z') + || (*line >= 'a' && *line <= 'z') + || *line == '-' || *line == '_')) + return false; + + /* OK, found DECL. */ + + /* Skip whitespace. */ + if (!(line < line_end && (*line == ' ' || *line == '\t'))) + { + fprintf (stderr, "%s:%u:" + " missing argument in %%define %s ARG declaration.\n", + pretty_input_file_name (), lineno, decl); + exit (1); + } + do + line++; + while (line < line_end && (*line == ' ' || *line == '\t')); + + /* The next word is the argument. */ + char *arg = new char[line_end - line + 1]; + char *p = arg; + while (line < line_end && !(*line == ' ' || *line == '\t' || *line == '\n')) + *p++ = *line++; + *p = '\0'; + + /* Skip whitespace. */ + while (line < line_end && (*line == ' ' || *line == '\t')) + line++; + + /* Expect end of line. */ + if (line < line_end && *line != '\n') + { + fprintf (stderr, "%s:%u: junk after declaration\n", + pretty_input_file_name (), lineno); + exit (1); + } + + *argp = arg; + return true; +} + +/* Reads the entire input file. */ +void +Input::read_input () +{ + /* The input file has the following structure: + DECLARATIONS + %% + KEYWORDS + %% + ADDITIONAL_CODE + Since the DECLARATIONS and the ADDITIONAL_CODE sections are optional, + we have to read the entire file in the case there is only one %% + separator line, in order to determine whether the structure is + DECLARATIONS + %% + KEYWORDS + or + KEYWORDS + %% + ADDITIONAL_CODE + When the option -t is given or when the first section contains + declaration lines starting with %, we go for the first interpretation, + otherwise for the second interpretation. */ + + char *input = NULL; + size_t input_size = 0; + int input_length = get_delim (&input, &input_size, EOF, _stream); + if (input_length < 0) + { + if (ferror (_stream)) + fprintf (stderr, "%s: error while reading input file\n", + pretty_input_file_name ()); + else + fprintf (stderr, "%s: The input file is empty!\n", + pretty_input_file_name ()); + exit (1); + } + + /* We use input_end as a limit, in order to cope with NUL bytes in the + input. But note that one trailing NUL byte has been added after + input_end, for convenience. */ + char *input_end = input + input_length; + + const char *declarations; + const char *declarations_end; + const char *keywords; + const char *keywords_end; + unsigned int keywords_lineno; + + /* Break up the input into the three sections. */ + { + const char *separator[2] = { NULL, NULL }; + unsigned int separator_lineno[2] = { 0, 0 }; + int separators = 0; + { + unsigned int lineno = 1; + for (const char *p = input; p < input_end; ) + { + if (p[0] == '%' && p[1] == '%') + { + separator[separators] = p; + separator_lineno[separators] = lineno; + if (++separators == 2) + break; + } + lineno++; + p = (const char *) memchr (p, '\n', input_end - p); + if (p != NULL) + p++; + else + p = input_end; + } + } + + bool has_declarations; + if (separators == 1) + { + if (option[TYPE]) + has_declarations = true; + else + { + has_declarations = false; + for (const char *p = input; p < separator[0]; ) + { + if (p[0] == '%') + { + has_declarations = true; + break; + } + p = (const char *) memchr (p, '\n', separator[0] - p); + if (p != NULL) + p++; + else + p = separator[0]; + } + } + } + else + has_declarations = (separators > 0); + + if (has_declarations) + { + declarations = input; + declarations_end = separator[0]; + /* Give a warning if the separator line is nonempty. */ + bool nonempty_line = false; + const char *p; + for (p = declarations_end + 2; p < input_end; ) + { + if (*p == '\n') + { + p++; + break; + } + if (!(*p == ' ' || *p == '\t')) + nonempty_line = true; + p++; + } + if (nonempty_line) + fprintf (stderr, "%s:%u: warning: junk after %%%% is ignored\n", + pretty_input_file_name (), separator_lineno[0]); + keywords = p; + keywords_lineno = separator_lineno[0] + 1; + } + else + { + declarations = NULL; + declarations_end = NULL; + keywords = input; + keywords_lineno = 1; + } + + if (separators > (has_declarations ? 1 : 0)) + { + keywords_end = separator[separators-1]; + _verbatim_code = separator[separators-1] + 2; + _verbatim_code_end = input_end; + _verbatim_code_lineno = separator_lineno[separators-1]; + } + else + { + keywords_end = input_end; + _verbatim_code = NULL; + _verbatim_code_end = NULL; + _verbatim_code_lineno = 0; + } + } + + /* Parse the declarations section. */ + + _verbatim_declarations = NULL; + _verbatim_declarations_end = NULL; + _verbatim_declarations_lineno = 0; + _struct_decl = NULL; + _struct_decl_lineno = 0; + _return_type = NULL; + _struct_tag = NULL; + { + unsigned int lineno = 1; + char *struct_decl = NULL; + unsigned int *struct_decl_linenos = NULL; + unsigned int struct_decl_linecount = 0; + for (const char *line = declarations; line < declarations_end; ) + { + const char *line_end; + line_end = (const char *) memchr (line, '\n', declarations_end - line); + if (line_end != NULL) + line_end++; + else + line_end = declarations_end; + + if (*line == '%') + { + if (line[1] == '{') + { + /* Handle %{. */ + if (_verbatim_declarations != NULL) + { + fprintf (stderr, "%s:%u:\n%s:%u:" + " only one %%{...%%} section is allowed\n", + pretty_input_file_name (), + _verbatim_declarations_lineno, + pretty_input_file_name (), lineno); + exit (1); + } + _verbatim_declarations = line + 2; + _verbatim_declarations_lineno = lineno; + } + else if (line[1] == '}') + { + /* Handle %}. */ + if (_verbatim_declarations == NULL) + { + fprintf (stderr, "%s:%u:" + " %%} outside of %%{...%%} section\n", + pretty_input_file_name (), lineno); + exit (1); + } + if (_verbatim_declarations_end != NULL) + { + fprintf (stderr, "%s:%u:" + " %%{...%%} section already closed\n", + pretty_input_file_name (), lineno); + exit (1); + } + _verbatim_declarations_end = line; + /* Give a warning if the rest of the line is nonempty. */ + bool nonempty_line = false; + const char *q; + for (q = line + 2; q < line_end; q++) + { + if (*q == '\n') + { + q++; + break; + } + if (!(*q == ' ' || *q == '\t')) + nonempty_line = true; + } + if (nonempty_line) + fprintf (stderr, "%s:%u:" + " warning: junk after %%} is ignored\n", + pretty_input_file_name (), lineno); + } + else if (_verbatim_declarations != NULL + && _verbatim_declarations_end == NULL) + { + fprintf (stderr, "%s:%u:" + " warning: %% directives are ignored" + " inside the %%{...%%} section\n", + pretty_input_file_name (), lineno); + } + else + { + char *arg; + + if (is_declaration_with_arg (line, line_end, lineno, + "delimiters", &arg)) + option.set_delimiters (arg); + else + + if (is_declaration (line, line_end, lineno, "struct-type")) + option.set (TYPE); + else + + if (is_declaration (line, line_end, lineno, "ignore-case")) + option.set (UPPERLOWER); + else + + if (is_declaration_with_arg (line, line_end, lineno, + "language", &arg)) + option.set_language (arg); + else + + if (is_define_declaration (line, line_end, lineno, + "slot-name", &arg)) + option.set_slot_name (arg); + else + + if (is_define_declaration (line, line_end, lineno, + "initializer-suffix", &arg)) + option.set_initializer_suffix (arg); + else + + if (is_define_declaration (line, line_end, lineno, + "hash-function-name", &arg)) + option.set_hash_name (arg); + else + + if (is_define_declaration (line, line_end, lineno, + "lookup-function-name", &arg)) + option.set_function_name (arg); + else + + if (is_define_declaration (line, line_end, lineno, + "class-name", &arg)) + option.set_class_name (arg); + else + + if (is_declaration (line, line_end, lineno, "7bit")) + option.set (SEVENBIT); + else + + if (is_declaration (line, line_end, lineno, "compare-lengths")) + option.set (LENTABLE); + else + + if (is_declaration (line, line_end, lineno, "compare-strncmp")) + option.set (COMP); + else + + if (is_declaration (line, line_end, lineno, "readonly-tables")) + option.set (CONST); + else + + if (is_declaration (line, line_end, lineno, "enum")) + option.set (ENUM); + else + + if (is_declaration (line, line_end, lineno, "includes")) + option.set (INCLUDE); + else + + if (is_declaration (line, line_end, lineno, "global-table")) + option.set (GLOBAL); + else + + if (is_declaration (line, line_end, lineno, "pic")) + option.set (SHAREDLIB); + else + + if (is_define_declaration (line, line_end, lineno, + "string-pool-name", &arg)) + option.set_stringpool_name (arg); + else + + if (is_declaration (line, line_end, lineno, "null-strings")) + option.set (NULLSTRINGS); + else + + if (is_define_declaration (line, line_end, lineno, + "word-array-name", &arg)) + option.set_wordlist_name (arg); + else + + if (is_define_declaration (line, line_end, lineno, + "length-table-name", &arg)) + option.set_lengthtable_name (arg); + else + + if (is_declaration_with_arg (line, line_end, lineno, + "switch", &arg)) + { + option.set_total_switches (atoi (arg)); + if (option.get_total_switches () <= 0) + { + fprintf (stderr, "%s:%u: number of switches %s" + " must be a positive number\n", + pretty_input_file_name (), lineno, arg); + exit (1); + } + } + else + + if (is_declaration (line, line_end, lineno, "omit-struct-type")) + option.set (NOTYPE); + else + + { + fprintf (stderr, "%s:%u: unrecognized %% directive\n", + pretty_input_file_name (), lineno); + exit (1); + } + } + } + else if (!(_verbatim_declarations != NULL + && _verbatim_declarations_end == NULL)) + { + /* Append the line to struct_decl. */ + size_t old_len = (struct_decl ? strlen (struct_decl) : 0); + size_t line_len = line_end - line; + size_t new_len = old_len + line_len + 1; + char *new_struct_decl = new char[new_len]; + if (old_len > 0) + memcpy (new_struct_decl, struct_decl, old_len); + memcpy (new_struct_decl + old_len, line, line_len); + new_struct_decl[old_len + line_len] = '\0'; + if (struct_decl) + delete[] struct_decl; + struct_decl = new_struct_decl; + /* Append the lineno to struct_decl_linenos. */ + unsigned int *new_struct_decl_linenos = + new unsigned int[struct_decl_linecount + 1]; + if (struct_decl_linecount > 0) + memcpy (new_struct_decl_linenos, struct_decl_linenos, + struct_decl_linecount * sizeof (unsigned int)); + new_struct_decl_linenos[struct_decl_linecount] = lineno; + if (struct_decl_linenos) + delete[] struct_decl_linenos; + struct_decl_linenos = new_struct_decl_linenos; + /* Increment struct_decl_linecount. */ + struct_decl_linecount++; + } + lineno++; + line = line_end; + } + if (_verbatim_declarations != NULL && _verbatim_declarations_end == NULL) + { + fprintf (stderr, "%s:%u: unterminated %%{ section\n", + pretty_input_file_name (), _verbatim_declarations_lineno); + exit (1); + } + + /* Determine _struct_decl, _return_type, _struct_tag. */ + if (option[TYPE]) + { + if (struct_decl) + { + /* Drop leading whitespace and comments. */ + { + char *p = struct_decl; + unsigned int *l = struct_decl_linenos; + for (;;) + { + if (p[0] == ' ' || p[0] == '\t') + { + p++; + continue; + } + if (p[0] == '\n') + { + l++; + p++; + continue; + } + if (p[0] == '/') + { + if (p[1] == '*') + { + /* Skip over ANSI C style comment. */ + p += 2; + while (p[0] != '\0') + { + if (p[0] == '*' && p[1] == '/') + { + p += 2; + break; + } + if (p[0] == '\n') + l++; + p++; + } + continue; + } + if (p[1] == '/') + { + /* Skip over ISO C99 or C++ style comment. */ + p += 2; + while (p[0] != '\0' && p[0] != '\n') + p++; + if (p[0] == '\n') + { + l++; + p++; + } + continue; + } + } + break; + } + if (p != struct_decl) + { + size_t len = strlen (p); + char *new_struct_decl = new char[len + 1]; + memcpy (new_struct_decl, p, len + 1); + delete[] struct_decl; + struct_decl = new_struct_decl; + } + _struct_decl_lineno = *l; + } + /* Drop trailing whitespace. */ + for (char *p = struct_decl + strlen (struct_decl); p > struct_decl;) + if (p[-1] == '\n' || p[-1] == ' ' || p[-1] == '\t') + *--p = '\0'; + else + break; + } + if (struct_decl == NULL || struct_decl[0] == '\0') + { + fprintf (stderr, "%s: missing struct declaration" + " for option --struct-type\n", + pretty_input_file_name ()); + exit (1); + } + { + /* Ensure trailing semicolon. */ + size_t old_len = strlen (struct_decl); + if (struct_decl[old_len - 1] != ';') + { + char *new_struct_decl = new char[old_len + 2]; + memcpy (new_struct_decl, struct_decl, old_len); + new_struct_decl[old_len] = ';'; + new_struct_decl[old_len + 1] = '\0'; + delete[] struct_decl; + struct_decl = new_struct_decl; + } + } + /* Set _struct_decl to the entire declaration. */ + _struct_decl = struct_decl; + /* Set _struct_tag to the naked "struct something". */ + const char *p; + for (p = struct_decl; *p && *p != '{' && *p != ';' && *p != '\n'; p++) + ; + for (; p > struct_decl;) + if (p[-1] == '\n' || p[-1] == ' ' || p[-1] == '\t') + --p; + else + break; + size_t struct_tag_length = p - struct_decl; + char *struct_tag = new char[struct_tag_length + 1]; + memcpy (struct_tag, struct_decl, struct_tag_length); + struct_tag[struct_tag_length] = '\0'; + _struct_tag = struct_tag; + /* The return type of the lookup function is "struct something *". + No "const" here, because if !option[CONST], some user code might + want to modify the structure. */ + char *return_type = new char[struct_tag_length + 3]; + memcpy (return_type, struct_decl, struct_tag_length); + return_type[struct_tag_length] = ' '; + return_type[struct_tag_length + 1] = '*'; + return_type[struct_tag_length + 2] = '\0'; + _return_type = return_type; + } + + if (struct_decl_linenos) + delete[] struct_decl_linenos; + } + + /* Parse the keywords section. */ + { + Keyword_List **list_tail = &_head; + const char *delimiters = option.get_delimiters (); + unsigned int lineno = keywords_lineno; + bool charset_dependent = false; + for (const char *line = keywords; line < keywords_end; ) + { + const char *line_end; + line_end = (const char *) memchr (line, '\n', keywords_end - line); + if (line_end != NULL) + line_end++; + else + line_end = keywords_end; + + if (line[0] == '#') + ; /* Comment line. */ + else if (line[0] == '%') + { + fprintf (stderr, "%s:%u:" + " declarations are not allowed in the keywords section.\n" + "To declare a keyword starting with %%, enclose it in" + " double-quotes.\n", + pretty_input_file_name (), lineno); + exit (1); + } + else + { + /* An input line carrying a keyword. */ + const char *keyword; + size_t keyword_length; + const char *rest; + + if (line[0] == '"') + { + /* Parse a string in ANSI C syntax. */ + char *kp = new char[line_end-line]; + keyword = kp; + const char *lp = line + 1; + + for (;;) + { + if (lp == line_end) + { + fprintf (stderr, "%s:%u: unterminated string\n", + pretty_input_file_name (), lineno); + exit (1); + } + + char c = *lp; + if (c == '\\') + { + c = *++lp; + switch (c) + { + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + { + int code = 0; + int count = 0; + while (count < 3 && *lp >= '0' && *lp <= '7') + { + code = (code << 3) + (*lp - '0'); + lp++; + count++; + } + if (code > UCHAR_MAX) + fprintf (stderr, + "%s:%u: octal escape out of range\n", + pretty_input_file_name (), lineno); + *kp = static_cast(code); + break; + } + case 'x': + { + int code = 0; + int count = 0; + lp++; + while ((*lp >= '0' && *lp <= '9') + || (*lp >= 'A' && *lp <= 'F') + || (*lp >= 'a' && *lp <= 'f')) + { + code = (code << 4) + + (*lp >= 'A' && *lp <= 'F' + ? *lp - 'A' + 10 : + *lp >= 'a' && *lp <= 'f' + ? *lp - 'a' + 10 : + *lp - '0'); + lp++; + count++; + } + if (count == 0) + fprintf (stderr, "%s:%u: hexadecimal escape" + " without any hex digits\n", + pretty_input_file_name (), lineno); + if (code > UCHAR_MAX) + fprintf (stderr, "%s:%u: hexadecimal escape" + " out of range\n", + pretty_input_file_name (), lineno); + *kp = static_cast(code); + break; + } + case '\\': case '\'': case '"': + *kp = c; + lp++; + charset_dependent = true; + break; + case 'n': + *kp = '\n'; + lp++; + charset_dependent = true; + break; + case 't': + *kp = '\t'; + lp++; + charset_dependent = true; + break; + case 'r': + *kp = '\r'; + lp++; + charset_dependent = true; + break; + case 'f': + *kp = '\f'; + lp++; + charset_dependent = true; + break; + case 'b': + *kp = '\b'; + lp++; + charset_dependent = true; + break; + case 'a': + *kp = '\a'; + lp++; + charset_dependent = true; + break; + case 'v': + *kp = '\v'; + lp++; + charset_dependent = true; + break; + default: + fprintf (stderr, "%s:%u: invalid escape sequence" + " in string\n", + pretty_input_file_name (), lineno); + exit (1); + } + } + else if (c == '"') + break; + else + { + *kp = c; + lp++; + charset_dependent = true; + } + kp++; + } + lp++; + if (lp < line_end && *lp != '\n') + { + if (strchr (delimiters, *lp) == NULL) + { + fprintf (stderr, "%s:%u: string not followed" + " by delimiter\n", + pretty_input_file_name (), lineno); + exit (1); + } + lp++; + } + keyword_length = kp - keyword; + if (option[TYPE]) + { + char *line_rest = new char[line_end - lp + 1]; + memcpy (line_rest, lp, line_end - lp); + line_rest[line_end - lp - + (line_end > lp && line_end[-1] == '\n' ? 1 : 0)] + = '\0'; + rest = line_rest; + } + else + rest = empty_string; + } + else + { + /* Not a string. Look for the delimiter. */ + const char *lp = line; + for (;;) + { + if (!(lp < line_end && *lp != '\n')) + { + keyword = line; + keyword_length = lp - line; + rest = empty_string; + break; + } + if (strchr (delimiters, *lp) != NULL) + { + keyword = line; + keyword_length = lp - line; + lp++; + if (option[TYPE]) + { + char *line_rest = new char[line_end - lp + 1]; + memcpy (line_rest, lp, line_end - lp); + line_rest[line_end - lp - + (line_end > lp && line_end[-1] == '\n' + ? 1 : 0)] + = '\0'; + rest = line_rest; + } + else + rest = empty_string; + break; + } + lp++; + } + if (keyword_length > 0) + charset_dependent = true; + } + + /* Allocate Keyword and add it to the list. */ + Keyword *new_kw = _factory->create_keyword (keyword, keyword_length, + rest); + new_kw->_lineno = lineno; + *list_tail = new Keyword_List (new_kw); + list_tail = &(*list_tail)->rest(); + } + + lineno++; + line = line_end; + } + *list_tail = NULL; + + if (_head == NULL) + { + fprintf (stderr, "%s: No keywords in input file!\n", + pretty_input_file_name ()); + exit (1); + } + + _charset_dependent = charset_dependent; + } + + /* To be freed in the destructor. */ + _input = input; + _input_end = input_end; +} + +Input::~Input () +{ + /* Free allocated memory. */ + delete[] const_cast(_return_type); + delete[] const_cast(_struct_tag); + delete[] const_cast(_struct_decl); + delete[] _input; +} diff --git a/contrib/gperf/src/input.h b/contrib/gperf/src/input.h new file mode 100644 index 000000000000..76ba01282cc4 --- /dev/null +++ b/contrib/gperf/src/input.h @@ -0,0 +1,69 @@ +/* This may look like C code, but it is really -*- C++ -*- */ + +/* Input routines. + + Copyright (C) 1989-1998, 2002-2003 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef input_h +#define input_h 1 + +#include +#include "keyword-list.h" + +class Input +{ +public: + Input (FILE *stream, Keyword_Factory *keyword_factory); + ~Input (); + void read_input (); +private: + /* Input stream. */ + FILE * _stream; + /* Creates the keywords. */ + Keyword_Factory * const _factory; +public: + /* Memory block containing the entire input. */ + char * _input; + char * _input_end; + /* The C code from the declarations section. */ + const char * _verbatim_declarations; + const char * _verbatim_declarations_end; + unsigned int _verbatim_declarations_lineno; + /* The C code from the end of the file. */ + const char * _verbatim_code; + const char * _verbatim_code_end; + unsigned int _verbatim_code_lineno; + /* Declaration of struct type for a keyword and its attributes. */ + const char * _struct_decl; + unsigned int _struct_decl_lineno; + /* Return type of the lookup function. */ + const char * _return_type; + /* Shorthand for user-defined struct tag type. */ + const char * _struct_tag; + /* List of all keywords. */ + Keyword_List * _head; + /* Whether the keyword chars would have different values in a different + character set. */ + bool _charset_dependent; +}; + +#endif diff --git a/contrib/gperf/src/iterator.cc b/contrib/gperf/src/iterator.cc deleted file mode 100644 index ca66bbb8aca4..000000000000 --- a/contrib/gperf/src/iterator.cc +++ /dev/null @@ -1,87 +0,0 @@ -/* Provides an Iterator for keyword characters. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#include "iterator.h" - -#include -#include "trace.h" - -/* Constructor for Iterator. */ - -Iterator::Iterator (const char *s, int lo, int hi, int word_end, int bad_val, int key_end) -{ - T (Trace t ("Iterator::Iterator");) - end = key_end; - error_value = bad_val; - end_word = word_end; - str = s; - hi_bound = hi; - lo_bound = lo; -} - -/* Provide an Iterator, returning the ``next'' value from - the list of valid values given in the constructor. */ - -int -Iterator::operator() (void) -{ - T (Trace t ("Iterator::operator()");) -/* Variables to record the Iterator's status when handling ranges, e.g., 3-12. */ - - static int size; - static int curr_value; - static int upper_bound; - - if (size) - { - if (++curr_value >= upper_bound) - size = 0; - return curr_value; - } - else - { - while (*str) - switch (*str) - { - default: return error_value; - case ',': str++; break; - case '$': str++; return end_word; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - for (curr_value = 0; isdigit ((unsigned char)(*str)); str++) - curr_value = curr_value * 10 + (*str - '0'); - - if (*str == '-') - { - - for (size = 1, upper_bound = 0; - isdigit ((unsigned char)(*++str)); - upper_bound = upper_bound * 10 + (*str - '0')); - - if (upper_bound <= curr_value || upper_bound > hi_bound) - return error_value; - } - return curr_value >= lo_bound && curr_value <= hi_bound - ? curr_value : error_value; - } - - return end; - } -} diff --git a/contrib/gperf/src/iterator.h b/contrib/gperf/src/iterator.h deleted file mode 100644 index d5138ab99447..000000000000 --- a/contrib/gperf/src/iterator.h +++ /dev/null @@ -1,51 +0,0 @@ -/* This may look like C code, but it is really -*- C++ -*- */ - -/* Provides an Iterator for keyword characters. - - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* Provides an Iterator that expands and decodes a control string containing digits - and ranges, returning an integer every time the generator function is called. - This is used to decode the user's key position requests. For example: - "-k 1,2,5-10,$" will return 1, 2, 5, 6, 7, 8, 9, 10, and 0 ( representing - the abstract ``last character of the key'' on successive calls to the - member function operator (). - No errors are handled in these routines, they are passed back to the - calling routines via a user-supplied Error_Value */ - -#ifndef iterator_h -#define iterator_h 1 - -class Iterator -{ -private: - const char *str; /* A pointer to the string provided by the user. */ - int end; /* Value returned after last key is processed. */ - int end_word; /* A value marking the abstract ``end of word'' ( usually '$'). */ - int error_value; /* Error value returned when input is syntactically erroneous. */ - int hi_bound; /* Greatest possible value, inclusive. */ - int lo_bound; /* Smallest possible value, inclusive. */ - -public: - Iterator (const char *s, int lo, int hi, int word_end, int bad_val, int key_end); - int operator () (void); -}; - -#endif diff --git a/contrib/gperf/src/key-list.cc b/contrib/gperf/src/key-list.cc deleted file mode 100644 index 11292bc31fab..000000000000 --- a/contrib/gperf/src/key-list.cc +++ /dev/null @@ -1,2182 +0,0 @@ -/* Routines for building, ordering, and printing the keyword list. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#include -#include /* declares strncpy(), strchr() */ -#include /* declares malloc(), free(), abs(), exit(), abort() */ -#include /* declares isprint() */ -#include /* defines assert() */ -#include /* defines SCHAR_MAX etc. */ -#include "options.h" -#include "read-line.h" -#include "hash-table.h" -#include "key-list.h" -#include "trace.h" -#include "version.h" - -/* Make the hash table 8 times larger than the number of keyword entries. */ -static const int TABLE_MULTIPLE = 10; - -/* Efficiently returns the least power of two greater than or equal to X! */ -#define POW(X) ((!X)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X))) - -int Key_List::determined[MAX_ALPHA_SIZE]; - -/* Destructor dumps diagnostics during debugging. */ - -Key_List::~Key_List (void) -{ - T (Trace t ("Key_List::~Key_List");) - if (option[DEBUG]) - { - fprintf (stderr, "\nDumping key list information:\ntotal non-static linked keywords = %d" - "\ntotal keywords = %d\ntotal duplicates = %d\nmaximum key length = %d\n", - list_len, total_keys, total_duplicates, max_key_len); - dump (); - fprintf (stderr, "End dumping list.\n\n"); - } -} - -/* Gathers the input stream into a buffer until one of two things occur: - - 1. We read a '%' followed by a '%' - 2. We read a '%' followed by a '}' - - The first symbolizes the beginning of the keyword list proper, - The second symbolizes the end of the C source code to be generated - verbatim in the output file. - - I assume that the keys are separated from the optional preceding struct - declaration by a consecutive % followed by either % or } starting in - the first column. The code below uses an expandible buffer to scan off - and return a pointer to all the code (if any) appearing before the delimiter. */ - -const char * -Key_List::get_special_input (char delimiter) -{ - T (Trace t ("Key_List::get_special_input");) - int size = 80; - char *buf = new char[size]; - int c, i; - - for (i = 0; (c = getchar ()) != EOF; i++) - { - if (c == '%') - { - if ((c = getchar ()) == delimiter) - { - - while ((c = getchar ()) != '\n') - ; /* discard newline */ - - if (i == 0) - return ""; - else - { - buf[delimiter == '%' && buf[i - 2] == ';' ? i - 2 : i - 1] = '\0'; - return buf; - } - } - else - buf[i++] = '%'; - } - else if (i >= size) /* Yikes, time to grow the buffer! */ - { - char *temp = new char[size *= 2]; - int j; - - for (j = 0; j < i; j++) - temp[j] = buf[j]; - - buf = temp; - } - buf[i] = c; - } - - return 0; /* Problem here. */ -} - -/* Stores any C text that must be included verbatim into the - generated code output. */ - -const char * -Key_List::save_include_src (void) -{ - T (Trace t ("Key_List::save_include_src");) - int c; - - if ((c = getchar ()) != '%') - ungetc (c, stdin); - else if ((c = getchar ()) != '{') - { - fprintf (stderr, "internal error, %c != '{' on line %d in file %s", c, __LINE__, __FILE__); - exit (1); - } - else - return get_special_input ('}'); - return ""; -} - -/* Determines from the input file whether the user wants to build a table - from a user-defined struct, or whether the user is content to simply - use the default array of keys. */ - -const char * -Key_List::get_array_type (void) -{ - T (Trace t ("Key_List::get_array_type");) - return get_special_input ('%'); -} - -/* strcspn - find length of initial segment of S consisting entirely - of characters not from REJECT (borrowed from Henry Spencer's - ANSI string package, when GNU libc comes out I'll replace this...). */ - -#ifndef strcspn -inline int -Key_List::strcspn (const char *s, const char *reject) -{ - T (Trace t ("Key_List::strcspn");) - const char *scan; - const char *rej_scan; - int count = 0; - - for (scan = s; *scan; scan++) - { - - for (rej_scan = reject; *rej_scan; rej_scan++) - if (*scan == *rej_scan) - return count; - - count++; - } - - return count; -} -#endif - -/* Sets up the Return_Type, the Struct_Tag type and the Array_Type - based upon various user Options. */ - -void -Key_List::set_output_types (void) -{ - T (Trace t ("Key_List::set_output_types");) - if (option[TYPE]) - { - array_type = get_array_type (); - if (!array_type) - /* Something's wrong, but we'll catch it later on, in read_keys()... */ - return; - /* Yow, we've got a user-defined type... */ - int i = strcspn (array_type, "{\n\0"); - /* Remove trailing whitespace. */ - while (i > 0 && strchr (" \t", array_type[i-1])) - i--; - int struct_tag_length = i; - - /* Set `struct_tag' to a naked "struct something". */ - char *structtag = new char[struct_tag_length + 1]; - strncpy (structtag, array_type, struct_tag_length); - structtag[struct_tag_length] = '\0'; - struct_tag = structtag; - - /* The return type of the lookup function is "struct something *". - No "const" here, because if !option[CONST], some user code might want - to modify the structure. */ - char *rettype = new char[struct_tag_length + 3]; - strncpy (rettype, array_type, struct_tag_length); - rettype[struct_tag_length] = ' '; - rettype[struct_tag_length + 1] = '*'; - rettype[struct_tag_length + 2] = '\0'; - return_type = rettype; - } -} - -/* Extracts a key from an input line and creates a new List_Node for it. */ - -static List_Node * -parse_line (const char *line, const char *delimiters) -{ - if (*line == '"') - { - /* Parse a string in ANSI C syntax. */ - char *key = new char[strlen(line)]; - char *kp = key; - const char *lp = line + 1; - - for (; *lp;) - { - char c = *lp; - - if (c == '\0') - { - fprintf (stderr, "unterminated string: %s\n", line); - exit (1); - } - else if (c == '\\') - { - c = *++lp; - switch (c) - { - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - { - int code = 0; - int count = 0; - while (count < 3 && *lp >= '0' && *lp <= '7') - { - code = (code << 3) + (*lp - '0'); - lp++; - count++; - } - if (code > UCHAR_MAX) - fprintf (stderr, "octal escape out of range: %s\n", line); - *kp = (char) code; - break; - } - case 'x': - { - int code = 0; - int count = 0; - lp++; - while ((*lp >= '0' && *lp <= '9') - || (*lp >= 'A' && *lp <= 'F') - || (*lp >= 'a' && *lp <= 'f')) - { - code = (code << 4) - + (*lp >= 'A' && *lp <= 'F' ? *lp - 'A' + 10 : - *lp >= 'a' && *lp <= 'f' ? *lp - 'a' + 10 : - *lp - '0'); - lp++; - count++; - } - if (count == 0) - fprintf (stderr, "hexadecimal escape without any hex digits: %s\n", line); - if (code > UCHAR_MAX) - fprintf (stderr, "hexadecimal escape out of range: %s\n", line); - *kp = (char) code; - break; - } - case '\\': case '\'': case '"': - *kp = c; - lp++; - break; - case 'n': - *kp = '\n'; - lp++; - break; - case 't': - *kp = '\t'; - lp++; - break; - case 'r': - *kp = '\r'; - lp++; - break; - case 'f': - *kp = '\f'; - lp++; - break; - case 'b': - *kp = '\b'; - lp++; - break; - case 'a': - *kp = '\a'; - lp++; - break; - case 'v': - *kp = '\v'; - lp++; - break; - default: - fprintf (stderr, "invalid escape sequence in string: %s\n", line); - exit (1); - } - } - else if (c == '"') - break; - else - { - *kp = c; - lp++; - } - kp++; - } - lp++; - if (*lp != '\0') - { - if (strchr (delimiters, *lp) == NULL) - { - fprintf (stderr, "string not followed by delimiter: %s\n", line); - exit (1); - } - lp++; - } - return new List_Node (key, kp - key, option[TYPE] ? lp : ""); - } - else - { - /* Not a string. Look for the delimiter. */ - int len = strcspn (line, delimiters); - const char *rest; - - if (line[len] == '\0') - rest = ""; - else - /* Skip the first delimiter. */ - rest = &line[len + 1]; - return new List_Node (line, len, option[TYPE] ? rest : ""); - } -} - -/* Reads in all keys from standard input and creates a linked list pointed - to by Head. This list is then quickly checked for ``links,'' i.e., - unhashable elements possessing identical key sets and lengths. */ - -void -Key_List::read_keys (void) -{ - T (Trace t ("Key_List::read_keys");) - char *ptr; - - include_src = save_include_src (); - set_output_types (); - - /* Oops, problem with the input file. */ - if (! (ptr = Read_Line::get_line ())) - { - fprintf (stderr, "No words in input file, did you forget to prepend %s or use -t accidentally?\n", "%%"); - exit (1); - } - - /* Read in all the keywords from the input file. */ - else - { - const char *delimiter = option.get_delimiter (); - List_Node *temp, *trail = 0; - - head = parse_line (ptr, delimiter); - - for (temp = head; - (ptr = Read_Line::get_line ()) && strcmp (ptr, "%%"); - temp = temp->next) - { - temp->next = parse_line (ptr, delimiter); - total_keys++; - } - - /* See if any additional C code is included at end of this file. */ - if (ptr) - additional_code = 1; - - /* Hash table this number of times larger than keyword number. */ - int table_size = (list_len = total_keys) * TABLE_MULTIPLE; - -#if LARGE_STACK_ARRAYS - /* By allocating the memory here we save on dynamic allocation overhead. - Table must be a power of 2 for the hash function scheme to work. */ - List_Node *table[POW (table_size)]; -#else - // Note: we don't use new, because that invokes a custom operator new. - int malloc_size = POW (table_size) * sizeof(List_Node*); - if (malloc_size == 0) malloc_size = 1; - List_Node **table = (List_Node**)malloc(malloc_size); - if (table == NULL) - abort (); -#endif - - /* Make large hash table for efficiency. */ - Hash_Table found_link (table, table_size, option[NOLENGTH]); - - /* Test whether there are any links and also set the maximum length of - an identifier in the keyword list. */ - - for (temp = head; temp; temp = temp->next) - { - List_Node *ptr = found_link.insert (temp); - - /* Check for links. We deal with these by building an equivalence class - of all duplicate values (i.e., links) so that only 1 keyword is - representative of the entire collection. This *greatly* simplifies - processing during later stages of the program. */ - - if (ptr) - { - total_duplicates++; - list_len--; - trail->next = temp->next; - temp->link = ptr->link; - ptr->link = temp; - - /* Complain if user hasn't enabled the duplicate option. */ - if (!option[DUP] || option[DEBUG]) - fprintf (stderr, "Key link: \"%.*s\" = \"%.*s\", with key set \"%.*s\".\n", - temp->key_length, temp->key, - ptr->key_length, ptr->key, - temp->char_set_length, temp->char_set); - } - else - trail = temp; - - /* Update minimum and maximum keyword length, if needed. */ - if (max_key_len < temp->key_length) - max_key_len = temp->key_length; - if (min_key_len > temp->key_length) - min_key_len = temp->key_length; - } - -#if !LARGE_STACK_ARRAYS - free ((char *) table); -#endif - - /* Exit program if links exists and option[DUP] not set, since we can't continue */ - if (total_duplicates) - { - if (option[DUP]) - fprintf (stderr, "%d input keys have identical hash values, examine output carefully...\n", - total_duplicates); - else - { - fprintf (stderr, "%d input keys have identical hash values,\ntry different key positions or use option -D.\n", - total_duplicates); - exit (1); - } - } - /* Exit program if an empty string is used as key, since the comparison - expressions don't work correctly for looking up an empty string. */ - if (min_key_len == 0) - { - fprintf (stderr, "Empty input key is not allowed.\nTo recognize an empty input key, your code should check for\nlen == 0 before calling the gperf generated lookup function.\n"); - exit (1); - } - if (option[ALLCHARS]) - option.set_keysig_size (max_key_len); - } -} - -/* Recursively merges two sorted lists together to form one sorted list. The - ordering criteria is by frequency of occurrence of elements in the key set - or by the hash value. This is a kludge, but permits nice sharing of - almost identical code without incurring the overhead of a function - call comparison. */ - -List_Node * -Key_List::merge (List_Node *list1, List_Node *list2) -{ - T (Trace t ("Key_List::merge");) - List_Node *result; - List_Node **resultp = &result; - for (;;) - { - if (!list1) - { - *resultp = list2; - break; - } - if (!list2) - { - *resultp = list1; - break; - } - if ((occurrence_sort && list1->occurrence < list2->occurrence) - || (hash_sort && list1->hash_value > list2->hash_value)) - { - *resultp = list2; - resultp = &list2->next; list2 = list1; list1 = *resultp; - } - else - { - *resultp = list1; - resultp = &list1->next; list1 = *resultp; - } - } - return result; -} - -/* Applies the merge sort algorithm to recursively sort the key list by - frequency of occurrence of elements in the key set. */ - -List_Node * -Key_List::merge_sort (List_Node *head) -{ - T (Trace t ("Key_List::merge_sort");) - if (!head || !head->next) - return head; - else - { - List_Node *middle = head; - List_Node *temp = head->next->next; - - while (temp) - { - temp = temp->next; - middle = middle->next; - if (temp) - temp = temp->next; - } - - temp = middle->next; - middle->next = 0; - return merge (merge_sort (head), merge_sort (temp)); - } -} - -/* Returns the frequency of occurrence of elements in the key set. */ - -inline int -Key_List::get_occurrence (List_Node *ptr) -{ - T (Trace t ("Key_List::get_occurrence");) - int value = 0; - - const char *p = ptr->char_set; - unsigned int i = ptr->char_set_length; - for (; i > 0; p++, i--) - value += occurrences[(unsigned char)(*p)]; - - return value; -} - -/* Enables the index location of all key set elements that are now - determined. */ - -inline void -Key_List::set_determined (List_Node *ptr) -{ - T (Trace t ("Key_List::set_determined");) - - const char *p = ptr->char_set; - unsigned int i = ptr->char_set_length; - for (; i > 0; p++, i--) - determined[(unsigned char)(*p)] = 1; -} - -/* Returns TRUE if PTR's key set is already completely determined. */ - -inline int -Key_List::already_determined (List_Node *ptr) -{ - T (Trace t ("Key_List::already_determined");) - int is_determined = 1; - - const char *p = ptr->char_set; - unsigned int i = ptr->char_set_length; - for (; is_determined && i > 0; p++, i--) - is_determined = determined[(unsigned char)(*p)]; - - return is_determined; -} - -/* Reorders the table by first sorting the list so that frequently occuring - keys appear first, and then the list is reorded so that keys whose values - are already determined will be placed towards the front of the list. This - helps prune the search time by handling inevitable collisions early in the - search process. See Cichelli's paper from Jan 1980 JACM for details.... */ - -void -Key_List::reorder (void) -{ - T (Trace t ("Key_List::reorder");) - List_Node *ptr; - for (ptr = head; ptr; ptr = ptr->next) - ptr->occurrence = get_occurrence (ptr); - - hash_sort = 0; - occurrence_sort = 1; - - for (ptr = head = merge_sort (head); ptr->next; ptr = ptr->next) - { - set_determined (ptr); - - if (already_determined (ptr->next)) - continue; - else - { - List_Node *trail_ptr = ptr->next; - List_Node *run_ptr = trail_ptr->next; - - for (; run_ptr; run_ptr = trail_ptr->next) - { - - if (already_determined (run_ptr)) - { - trail_ptr->next = run_ptr->next; - run_ptr->next = ptr->next; - ptr = ptr->next = run_ptr; - } - else - trail_ptr = run_ptr; - } - } - } -} - -/* ============================ Output routines ============================ */ - -/* The "const " qualifier. */ -static const char *const_always; - -/* The "const " qualifier, for read-only arrays. */ -static const char *const_readonly_array; - -/* The "const " qualifier, for the array type. */ -static const char *const_for_struct; - -/* Returns the smallest unsigned C type capable of holding integers up to N. */ - -static const char * -smallest_integral_type (int n) -{ - if (n <= UCHAR_MAX) return "unsigned char"; - if (n <= USHRT_MAX) return "unsigned short"; - return "unsigned int"; -} - -/* Returns the smallest signed C type capable of holding integers - from MIN to MAX. */ - -static const char * -smallest_integral_type (int min, int max) -{ - if (option[ANSIC] | option[CPLUSPLUS]) - if (min >= SCHAR_MIN && max <= SCHAR_MAX) return "signed char"; - if (min >= SHRT_MIN && max <= SHRT_MAX) return "short"; - return "int"; -} - -/* A cast from `char' to a valid array index. */ -static const char *char_to_index; - -/* ------------------------------------------------------------------------- */ - -/* Computes the maximum and minimum hash values. Since the - list is already sorted by hash value all we need to do is - find the final item! */ - -void -Key_List::compute_min_max (void) -{ - T (Trace t ("Key_List::compute_min_max");) - List_Node *temp; - for (temp = head; temp->next; temp = temp->next) - ; - - min_hash_value = head->hash_value; - max_hash_value = temp->hash_value; -} - -/* ------------------------------------------------------------------------- */ - -/* Returns the number of different hash values. */ - -int -Key_List::num_hash_values (void) -{ - T (Trace t ("Key_List::num_hash_values");) - int count = 1; - List_Node *temp; - int value; - - for (temp = head, value = temp->hash_value; temp->next; ) - { - temp = temp->next; - if (value != temp->hash_value) - { - value = temp->hash_value; - count++; - } - } - return count; -} - -/* -------------------- Output_Constants and subclasses -------------------- */ - -/* This class outputs an enumeration defining some constants. */ - -struct Output_Constants -{ - virtual void output_start () = 0; - virtual void output_item (const char *name, int value) = 0; - virtual void output_end () = 0; - Output_Constants () {} - virtual ~Output_Constants () {} -}; - -/* This class outputs an enumeration in #define syntax. */ - -struct Output_Defines : public Output_Constants -{ - virtual void output_start (); - virtual void output_item (const char *name, int value); - virtual void output_end (); - Output_Defines () {} - virtual ~Output_Defines () {} -}; - -void Output_Defines::output_start () -{ - T (Trace t ("Output_Defines::output_start");) - printf ("\n"); -} - -void Output_Defines::output_item (const char *name, int value) -{ - T (Trace t ("Output_Defines::output_item");) - printf ("#define %s %d\n", name, value); -} - -void Output_Defines::output_end () -{ - T (Trace t ("Output_Defines::output_end");) -} - -/* This class outputs an enumeration using `enum'. */ - -struct Output_Enum : public Output_Constants -{ - virtual void output_start (); - virtual void output_item (const char *name, int value); - virtual void output_end (); - Output_Enum (const char *indent) : indentation (indent) {} - virtual ~Output_Enum () {} -private: - const char *indentation; - int pending_comma; -}; - -void Output_Enum::output_start () -{ - T (Trace t ("Output_Enum::output_start");) - printf ("%senum\n" - "%s {\n", - indentation, indentation); - pending_comma = 0; -} - -void Output_Enum::output_item (const char *name, int value) -{ - T (Trace t ("Output_Enum::output_item");) - if (pending_comma) - printf (",\n"); - printf ("%s %s = %d", indentation, name, value); - pending_comma = 1; -} - -void Output_Enum::output_end () -{ - T (Trace t ("Output_Enum::output_end");) - if (pending_comma) - printf ("\n"); - printf ("%s };\n\n", indentation); -} - -/* Outputs the maximum and minimum hash values etc. */ - -void -Key_List::output_constants (struct Output_Constants& style) -{ - T (Trace t ("Key_List::output_constants");) - - style.output_start (); - style.output_item ("TOTAL_KEYWORDS", total_keys); - style.output_item ("MIN_WORD_LENGTH", min_key_len); - style.output_item ("MAX_WORD_LENGTH", max_key_len); - style.output_item ("MIN_HASH_VALUE", min_hash_value); - style.output_item ("MAX_HASH_VALUE", max_hash_value); - style.output_end (); -} - -/* ------------------------------------------------------------------------- */ - -/* Outputs a keyword, as a string: enclosed in double quotes, escaping - backslashes, double quote and unprintable characters. */ - -static void -output_string (const char *key, int len) -{ - T (Trace t ("output_string");) - - putchar ('"'); - for (; len > 0; len--) - { - unsigned char c = (unsigned char) *key++; - if (isprint (c)) - { - if (c == '"' || c == '\\') - putchar ('\\'); - putchar (c); - } - else - { - /* Use octal escapes, not hexadecimal escapes, because some old - C compilers didn't understand hexadecimal escapes, and because - hexadecimal escapes are not limited to 2 digits, thus needing - special care if the following character happens to be a digit. */ - putchar ('\\'); - putchar ('0' + ((c >> 6) & 7)); - putchar ('0' + ((c >> 3) & 7)); - putchar ('0' + (c & 7)); - } - } - putchar ('"'); -} - -/* ------------------------------------------------------------------------- */ - -/* Outputs a type and a const specifier. - The output is terminated with a space. */ - -static void -output_const_type (const char *const_string, const char *type_string) -{ - if (type_string[strlen(type_string)-1] == '*') - printf ("%s %s", type_string, const_string); - else - printf ("%s%s ", const_string, type_string); -} - -/* ----------------------- Output_Expr and subclasses ----------------------- */ - -/* This class outputs a general expression. */ - -struct Output_Expr -{ - virtual void output_expr () const = 0; - Output_Expr () {} - virtual ~Output_Expr () {} -}; - -/* This class outputs an expression formed by a single string. */ - -struct Output_Expr1 : public Output_Expr -{ - virtual void output_expr () const; - Output_Expr1 (const char *piece1) : p1 (piece1) {} - virtual ~Output_Expr1 () {} -private: - const char *p1; -}; - -void Output_Expr1::output_expr () const -{ - T (Trace t ("Output_Expr1::output_expr");) - printf ("%s", p1); -} - -#if 0 /* unused */ - -/* This class outputs an expression formed by the concatenation of two - strings. */ - -struct Output_Expr2 : public Output_Expr -{ - virtual void output_expr () const; - Output_Expr2 (const char *piece1, const char *piece2) - : p1 (piece1), p2 (piece2) {} - virtual ~Output_Expr2 () {} -private: - const char *p1; - const char *p2; -}; - -void Output_Expr2::output_expr () const -{ - T (Trace t ("Output_Expr2::output_expr");) - printf ("%s%s", p1, p2); -} - -#endif - -/* --------------------- Output_Compare and subclasses --------------------- */ - -/* This class outputs a comparison expression. */ - -struct Output_Compare -{ - virtual void output_comparison (const Output_Expr& expr1, - const Output_Expr& expr2) const = 0; - Output_Compare () {} - virtual ~Output_Compare () {} -}; - -/* This class outputs a comparison using strcmp. */ - -struct Output_Compare_Strcmp : public Output_Compare -{ - virtual void output_comparison (const Output_Expr& expr1, - const Output_Expr& expr2) const; - Output_Compare_Strcmp () {} - virtual ~Output_Compare_Strcmp () {} -}; - -void Output_Compare_Strcmp::output_comparison (const Output_Expr& expr1, - const Output_Expr& expr2) const -{ - T (Trace t ("Output_Compare_Strcmp::output_comparison");) - printf ("*"); - expr1.output_expr (); - printf (" == *"); - expr2.output_expr (); - printf (" && !strcmp ("); - expr1.output_expr (); - printf (" + 1, "); - expr2.output_expr (); - printf (" + 1)"); -} - -/* This class outputs a comparison using strncmp. - Note that the length of expr1 will be available through the local variable - `len'. */ - -struct Output_Compare_Strncmp : public Output_Compare -{ - virtual void output_comparison (const Output_Expr& expr1, - const Output_Expr& expr2) const; - Output_Compare_Strncmp () {} - virtual ~Output_Compare_Strncmp () {} -}; - -void Output_Compare_Strncmp::output_comparison (const Output_Expr& expr1, - const Output_Expr& expr2) const -{ - T (Trace t ("Output_Compare_Strncmp::output_comparison");) - printf ("*"); - expr1.output_expr (); - printf (" == *"); - expr2.output_expr (); - printf (" && !strncmp ("); - expr1.output_expr (); - printf (" + 1, "); - expr2.output_expr (); - printf (" + 1, len - 1) && "); - expr2.output_expr (); - printf ("[len] == '\\0'"); -} - -/* This class outputs a comparison using memcmp. - Note that the length of expr1 (available through the local variable `len') - must be verified to be equal to the length of expr2 prior to this - comparison. */ - -struct Output_Compare_Memcmp : public Output_Compare -{ - virtual void output_comparison (const Output_Expr& expr1, - const Output_Expr& expr2) const; - Output_Compare_Memcmp () {} - virtual ~Output_Compare_Memcmp () {} -}; - -void Output_Compare_Memcmp::output_comparison (const Output_Expr& expr1, - const Output_Expr& expr2) const -{ - T (Trace t ("Output_Compare_Memcmp::output_comparison");) - printf ("*"); - expr1.output_expr (); - printf (" == *"); - expr2.output_expr (); - printf (" && !memcmp ("); - expr1.output_expr (); - printf (" + 1, "); - expr2.output_expr (); - printf (" + 1, len - 1)"); -} - -/* ------------------------------------------------------------------------- */ - -/* Generates C code for the hash function that returns the - proper encoding for each key word. */ - -void -Key_List::output_hash_function (void) -{ - T (Trace t ("Key_List::output_hash_function");) - const int max_column = 10; - int field_width; - - /* Calculate maximum number of digits required for MAX_HASH_VALUE. */ - field_width = 2; - for (int trunc = max_hash_value; (trunc /= 10) > 0;) - field_width++; - - /* Output the function's head. */ - if (option[CPLUSPLUS]) - printf ("inline "); - else if (option[KRC] | option[C] | option[ANSIC]) - printf ("#ifdef __GNUC__\n" - "__inline\n" - "#else\n" - "#ifdef __cplusplus\n" - "inline\n" - "#endif\n" - "#endif\n"); - - if (option[KRC] | option[C] | option[ANSIC]) - printf ("static "); - printf ("unsigned int\n"); - if (option[CPLUSPLUS]) - printf ("%s::", option.get_class_name ()); - printf ("%s ", option.get_hash_name ()); - if (option[KRC] || option[C] || option [ANSIC] || option[CPLUSPLUS]) - printf (option[KRC] ? - "(str, len)\n" - " register char *str;\n" - " register unsigned int len;\n" : - option[C] ? - "(str, len)\n" - " register const char *str;\n" - " register unsigned int len;\n" : - "(register const char *str, register unsigned int len)\n"); - - /* Note that when the hash function is called, it has already been verified - that min_key_len <= len <= max_key_len. */ - - /* Output the function's body. */ - printf ("{\n"); - - /* First the asso_values array. */ - printf (" static %s%s asso_values[] =\n" - " {", - const_readonly_array, - smallest_integral_type (max_hash_value + 1)); - - for (int count = 0; count < ALPHA_SIZE; count++) - { - if (count > 0) - printf (","); - if (!(count % max_column)) - printf ("\n "); - printf ("%*d", field_width, - occurrences[count] ? asso_values[count] : max_hash_value + 1); - } - - printf ("\n" - " };\n"); - - /* Optimize special case of ``-k 1,$'' */ - if (option[DEFAULTCHARS]) - printf (" return %sasso_values[%sstr[len - 1]] + asso_values[%sstr[0]];\n", - option[NOLENGTH] ? "" : "len + ", - char_to_index, char_to_index); - else - { - int key_pos; - - option.reset (); - - /* Get first (also highest) key position. */ - key_pos = option.get (); - - if (!option[ALLCHARS] && (key_pos == WORD_END || key_pos <= min_key_len)) - { - /* We can perform additional optimizations here: - Write it out as a single expression. Note that the values - are added as `int's even though the asso_values array may - contain `unsigned char's or `unsigned short's. */ - - printf (" return %s", - option[NOLENGTH] ? "" : "len + "); - - for (; key_pos != WORD_END; ) - { - printf ("asso_values[%sstr[%d]]", char_to_index, key_pos - 1); - if ((key_pos = option.get ()) != EOS) - printf (" + "); - else - break; - } - - if (key_pos == WORD_END) - printf ("asso_values[%sstr[len - 1]]", char_to_index); - - printf (";\n"); - } - else - { - /* We've got to use the correct, but brute force, technique. */ - printf (" register int hval = %s;\n\n" - " switch (%s)\n" - " {\n" - " default:\n", - option[NOLENGTH] ? "0" : "len", - option[NOLENGTH] ? "len" : "hval"); - - /* User wants *all* characters considered in hash. */ - if (option[ALLCHARS]) - { - for (int i = max_key_len; i > 0; i--) - printf (" case %d:\n" - " hval += asso_values[%sstr[%d]];\n", - i, char_to_index, i - 1); - - printf (" break;\n" - " }\n" - " return hval;\n"); - } - else /* do the hard part... */ - { - while (key_pos != WORD_END && key_pos > max_key_len) - if ((key_pos = option.get ()) == EOS) - break; - - if (key_pos != EOS && key_pos != WORD_END) - { - int i = key_pos; - do - { - for ( ; i >= key_pos; i--) - printf (" case %d:\n", i); - - printf (" hval += asso_values[%sstr[%d]];\n", - char_to_index, key_pos - 1); - - key_pos = option.get (); - } - while (key_pos != EOS && key_pos != WORD_END); - - for ( ; i >= min_key_len; i--) - printf (" case %d:\n", i); - } - - printf (" break;\n" - " }\n" - " return hval"); - if (key_pos == WORD_END) - printf (" + asso_values[%sstr[len - 1]]", char_to_index); - printf (";\n"); - } - } - } - printf ("}\n\n"); -} - -/* ------------------------------------------------------------------------- */ - -/* Prints out a table of keyword lengths, for use with the - comparison code in generated function ``in_word_set''. */ - -void -Key_List::output_keylength_table (void) -{ - T (Trace t ("Key_List::output_keylength_table");) - const int columns = 14; - int index; - int column; - const char *indent = option[GLOBAL] ? "" : " "; - List_Node *temp; - - printf ("%sstatic %s%s lengthtable[] =\n%s {", - indent, const_readonly_array, - smallest_integral_type (max_key_len), - indent); - - /* Generate an array of lengths, similar to output_keyword_table. */ - - column = 0; - for (temp = head, index = 0; temp; temp = temp->next) - { - if (option[SWITCH] && !option[TYPE] - && !(temp->link - || (temp->next && temp->hash_value == temp->next->hash_value))) - continue; - - if (index < temp->hash_value && !option[SWITCH] && !option[DUP]) - { - /* Some blank entries. */ - for ( ; index < temp->hash_value; index++) - { - if (index > 0) - printf (","); - if ((column++ % columns) == 0) - printf ("\n%s ", indent); - printf ("%3d", 0); - } - } - - if (index > 0) - printf (","); - if ((column++ % columns) == 0) - printf("\n%s ", indent); - printf ("%3d", temp->key_length); - - /* Deal with links specially. */ - if (temp->link) // implies option[DUP] - for (List_Node *links = temp->link; links; links = links->link) - { - ++index; - printf (","); - if ((column++ % columns) == 0) - printf("\n%s ", indent); - printf ("%3d", links->key_length); - } - - index++; - } - - printf ("\n%s };\n", indent); - if (option[GLOBAL]) - printf ("\n"); -} - -/* ------------------------------------------------------------------------- */ - -static void -output_keyword_entry (List_Node *temp, const char *indent) -{ - printf ("%s ", indent); - if (option[TYPE]) - printf ("{"); - output_string (temp->key, temp->key_length); - if (option[TYPE]) - { - if (strlen (temp->rest) > 0) - printf (",%s", temp->rest); - printf ("}"); - } - if (option[DEBUG]) - printf (" /* hash value = %d, index = %d */", - temp->hash_value, temp->index); -} - -static void -output_keyword_blank_entries (int count, const char *indent) -{ - int columns; - if (option[TYPE]) - { - columns = 58 / (6 + strlen (option.get_initializer_suffix())); - if (columns == 0) - columns = 1; - } - else - { - columns = 9; - } - int column = 0; - for (int i = 0; i < count; i++) - { - if ((column % columns) == 0) - { - if (i > 0) - printf (",\n"); - printf ("%s ", indent); - } - else - { - if (i > 0) - printf (", "); - } - if (option[TYPE]) - printf ("{\"\"%s}", option.get_initializer_suffix()); - else - printf ("\"\""); - column++; - } -} - -/* Prints out the array containing the key words for the hash function. */ - -void -Key_List::output_keyword_table (void) -{ - T (Trace t ("Key_List::output_keyword_table");) - const char *indent = option[GLOBAL] ? "" : " "; - int index; - List_Node *temp; - - printf ("%sstatic ", - indent); - output_const_type (const_readonly_array, struct_tag); - printf ("%s[] =\n" - "%s {\n", - option.get_wordlist_name (), - indent); - - /* Generate an array of reserved words at appropriate locations. */ - - for (temp = head, index = 0; temp; temp = temp->next) - { - if (option[SWITCH] && !option[TYPE] - && !(temp->link - || (temp->next && temp->hash_value == temp->next->hash_value))) - continue; - - if (index > 0) - printf (",\n"); - - if (index < temp->hash_value && !option[SWITCH] && !option[DUP]) - { - /* Some blank entries. */ - output_keyword_blank_entries (temp->hash_value - index, indent); - printf (",\n"); - index = temp->hash_value; - } - - temp->index = index; - - output_keyword_entry (temp, indent); - - /* Deal with links specially. */ - if (temp->link) // implies option[DUP] - for (List_Node *links = temp->link; links; links = links->link) - { - links->index = ++index; - printf (",\n"); - output_keyword_entry (links, indent); - } - - index++; - } - if (index > 0) - printf ("\n"); - - printf ("%s };\n\n", indent); -} - -/* ------------------------------------------------------------------------- */ - -/* Generates the large, sparse table that maps hash values into - the smaller, contiguous range of the keyword table. */ - -void -Key_List::output_lookup_array (void) -{ - T (Trace t ("Key_List::output_lookup_array");) - if (option[DUP]) - { - const int DEFAULT_VALUE = -1; - - /* Because of the way output_keyword_table works, every duplicate set is - stored contiguously in the wordlist array. */ - struct duplicate_entry - { - int hash_value; /* Hash value for this particular duplicate set. */ - int index; /* Index into the main keyword storage array. */ - int count; /* Number of consecutive duplicates at this index. */ - }; - -#if LARGE_STACK_ARRAYS - duplicate_entry duplicates[total_duplicates]; - int lookup_array[max_hash_value + 1 + 2*total_duplicates]; -#else - // Note: we don't use new, because that invokes a custom operator new. - duplicate_entry *duplicates = (duplicate_entry *) - malloc (total_duplicates * sizeof(duplicate_entry) + 1); - int *lookup_array = (int *) - malloc ((max_hash_value + 1 + 2*total_duplicates) * sizeof(int)); - if (duplicates == NULL || lookup_array == NULL) - abort(); -#endif - int lookup_array_size = max_hash_value + 1; - duplicate_entry *dup_ptr = &duplicates[0]; - int *lookup_ptr = &lookup_array[max_hash_value + 1 + 2*total_duplicates]; - - while (lookup_ptr > lookup_array) - *--lookup_ptr = DEFAULT_VALUE; - - /* Now dup_ptr = &duplicates[0] and lookup_ptr = &lookup_array[0]. */ - - for (List_Node *temp = head; temp; temp = temp->next) - { - int hash_value = temp->hash_value; - lookup_array[hash_value] = temp->index; - if (option[DEBUG]) - fprintf (stderr, "keyword = %.*s, index = %d\n", - temp->key_length, temp->key, temp->index); - if (temp->link - || (temp->next && hash_value == temp->next->hash_value)) - { - /* Start a duplicate entry. */ - dup_ptr->hash_value = hash_value; - dup_ptr->index = temp->index; - dup_ptr->count = 1; - - for (;;) - { - for (List_Node *ptr = temp->link; ptr; ptr = ptr->link) - { - dup_ptr->count++; - if (option[DEBUG]) - fprintf (stderr, - "static linked keyword = %.*s, index = %d\n", - ptr->key_length, ptr->key, ptr->index); - } - - if (!(temp->next && hash_value == temp->next->hash_value)) - break; - - temp = temp->next; - - dup_ptr->count++; - if (option[DEBUG]) - fprintf (stderr, "dynamic linked keyword = %.*s, index = %d\n", - temp->key_length, temp->key, temp->index); - } - assert (dup_ptr->count >= 2); - dup_ptr++; - } - } - - while (dup_ptr > duplicates) - { - dup_ptr--; - - if (option[DEBUG]) - fprintf (stderr, - "dup_ptr[%td]: hash_value = %d, index = %d, count = %d\n", - dup_ptr - duplicates, - dup_ptr->hash_value, dup_ptr->index, dup_ptr->count); - - int i; - /* Start searching for available space towards the right part - of the lookup array. */ - for (i = dup_ptr->hash_value; i < lookup_array_size-1; i++) - if (lookup_array[i] == DEFAULT_VALUE - && lookup_array[i + 1] == DEFAULT_VALUE) - goto found_i; - /* If we didn't find it to the right look to the left instead... */ - for (i = dup_ptr->hash_value-1; i >= 0; i--) - if (lookup_array[i] == DEFAULT_VALUE - && lookup_array[i + 1] == DEFAULT_VALUE) - goto found_i; - /* Append to the end of lookup_array. */ - i = lookup_array_size; - lookup_array_size += 2; - found_i: - /* Put in an indirection from dup_ptr->hash_value to i. - At i and i+1 store dup_ptr->index and dup_ptr->count. */ - assert (lookup_array[dup_ptr->hash_value] == dup_ptr->index); - lookup_array[dup_ptr->hash_value] = - 1 - total_keys - i; - lookup_array[i] = - total_keys + dup_ptr->index; - lookup_array[i + 1] = - dup_ptr->count; - /* All these three values are <= -2, distinct from DEFAULT_VALUE. */ - } - - /* The values of the lookup array are now known. */ - - int min = INT_MAX; - int max = INT_MIN; - lookup_ptr = lookup_array + lookup_array_size; - while (lookup_ptr > lookup_array) - { - int val = *--lookup_ptr; - if (min > val) - min = val; - if (max < val) - max = val; - } - - const char *indent = option[GLOBAL] ? "" : " "; - printf ("%sstatic %s%s lookup[] =\n" - "%s {", - indent, const_readonly_array, smallest_integral_type (min, max), - indent); - - int field_width; - /* Calculate maximum number of digits required for MIN..MAX. */ - { - field_width = 2; - for (int trunc = max; (trunc /= 10) > 0;) - field_width++; - } - if (min < 0) - { - int neg_field_width = 2; - for (int trunc = -min; (trunc /= 10) > 0;) - neg_field_width++; - neg_field_width++; /* account for the minus sign */ - if (field_width < neg_field_width) - field_width = neg_field_width; - } - - const int columns = 42 / field_width; - int column; - - column = 0; - for (int i = 0; i < lookup_array_size; i++) - { - if (i > 0) - printf (","); - if ((column++ % columns) == 0) - printf("\n%s ", indent); - printf ("%*d", field_width, lookup_array[i]); - } - printf ("\n%s };\n\n", indent); - -#if !LARGE_STACK_ARRAYS - free ((char *) duplicates); - free ((char *) lookup_array); -#endif - } -} - -/* ------------------------------------------------------------------------- */ - -/* Generate all the tables needed for the lookup function. */ - -void -Key_List::output_lookup_tables (void) -{ - T (Trace t ("Key_List::output_lookup_tables");) - - if (option[SWITCH]) - { - /* Use the switch in place of lookup table. */ - if (option[LENTABLE] && (option[DUP] && total_duplicates > 0)) - output_keylength_table (); - if (option[TYPE] || (option[DUP] && total_duplicates > 0)) - output_keyword_table (); - } - else - { - /* Use the lookup table, in place of switch. */ - if (option[LENTABLE]) - output_keylength_table (); - output_keyword_table (); - output_lookup_array (); - } -} - -/* ------------------------------------------------------------------------- */ - -/* Output a single switch case (including duplicates). Advance list. */ - -static List_Node * -output_switch_case (List_Node *list, int indent, int *jumps_away) -{ - T (Trace t ("output_switch_case");) - - if (option[DEBUG]) - printf ("%*s/* hash value = %4d, keyword = \"%.*s\" */\n", - indent, "", list->hash_value, list->key_length, list->key); - - if (option[DUP] - && (list->link - || (list->next && list->hash_value == list->next->hash_value))) - { - if (option[LENTABLE]) - printf ("%*slengthptr = &lengthtable[%d];\n", - indent, "", list->index); - printf ("%*swordptr = &%s[%d];\n", - indent, "", option.get_wordlist_name (), list->index); - - int count = 0; - for (List_Node *temp = list; ; temp = temp->next) - { - for (List_Node *links = temp; links; links = links->link) - count++; - if (!(temp->next && temp->hash_value == temp->next->hash_value)) - break; - } - - printf ("%*swordendptr = wordptr + %d;\n" - "%*sgoto multicompare;\n", - indent, "", count, - indent, ""); - *jumps_away = 1; - } - else - { - if (option[LENTABLE]) - { - printf ("%*sif (len == %d)\n" - "%*s {\n", - indent, "", list->key_length, - indent, ""); - indent += 4; - } - printf ("%*sresword = ", - indent, ""); - if (option[TYPE]) - printf ("&%s[%d]", option.get_wordlist_name (), list->index); - else - output_string (list->key, list->key_length); - printf (";\n"); - printf ("%*sgoto compare;\n", - indent, ""); - if (option[LENTABLE]) - { - indent -= 4; - printf ("%*s }\n", - indent, ""); - } - else - *jumps_away = 1; - } - - while (list->next && list->hash_value == list->next->hash_value) - list = list->next; - list = list->next; - return list; -} - -/* Output a total of size cases, grouped into num_switches switch statements, - where 0 < num_switches <= size. */ - -static void -output_switches (List_Node *list, int num_switches, int size, int min_hash_value, int max_hash_value, int indent) -{ - T (Trace t ("output_switches");) - - if (option[DEBUG]) - printf ("%*s/* know %d <= key <= %d, contains %d cases */\n", - indent, "", min_hash_value, max_hash_value, size); - - if (num_switches > 1) - { - int part1 = num_switches / 2; - int part2 = num_switches - part1; - int size1 = (int)((double)size / (double)num_switches * (double)part1 + 0.5); - int size2 = size - size1; - - List_Node *temp = list; - for (int count = size1; count > 0; count--) - { - while (temp->hash_value == temp->next->hash_value) - temp = temp->next; - temp = temp->next; - } - - printf ("%*sif (key < %d)\n" - "%*s {\n", - indent, "", temp->hash_value, - indent, ""); - - output_switches (list, part1, size1, min_hash_value, temp->hash_value-1, indent+4); - - printf ("%*s }\n" - "%*selse\n" - "%*s {\n", - indent, "", indent, "", indent, ""); - - output_switches (temp, part2, size2, temp->hash_value, max_hash_value, indent+4); - - printf ("%*s }\n", - indent, ""); - } - else - { - /* Output a single switch. */ - int lowest_case_value = list->hash_value; - if (size == 1) - { - int jumps_away = 0; - assert (min_hash_value <= lowest_case_value); - assert (lowest_case_value <= max_hash_value); - if (min_hash_value == max_hash_value) - output_switch_case (list, indent, &jumps_away); - else - { - printf ("%*sif (key == %d)\n" - "%*s {\n", - indent, "", lowest_case_value, - indent, ""); - output_switch_case (list, indent+4, &jumps_away); - printf ("%*s }\n", - indent, ""); - } - } - else - { - if (lowest_case_value == 0) - printf ("%*sswitch (key)\n", indent, ""); - else - printf ("%*sswitch (key - %d)\n", indent, "", lowest_case_value); - printf ("%*s {\n", - indent, ""); - for (; size > 0; size--) - { - int jumps_away = 0; - printf ("%*s case %d:\n", - indent, "", list->hash_value - lowest_case_value); - list = output_switch_case (list, indent+6, &jumps_away); - if (!jumps_away) - printf ("%*s break;\n", - indent, ""); - } - printf ("%*s }\n", - indent, ""); - } - } -} - -/* Generates C code to perform the keyword lookup. */ - -void -Key_List::output_lookup_function_body (const Output_Compare& comparison) -{ - T (Trace t ("Key_List::output_lookup_function_body");) - - printf (" if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)\n" - " {\n" - " register int key = %s (str, len);\n\n", - option.get_hash_name ()); - - if (option[SWITCH]) - { - int switch_size = num_hash_values (); - int num_switches = option.get_total_switches (); - if (num_switches > switch_size) - num_switches = switch_size; - - printf (" if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)\n" - " {\n"); - if (option[DUP]) - { - if (option[LENTABLE]) - printf (" register %s%s *lengthptr;\n", - const_always, smallest_integral_type (max_key_len)); - printf (" register "); - output_const_type (const_readonly_array, struct_tag); - printf ("*wordptr;\n"); - printf (" register "); - output_const_type (const_readonly_array, struct_tag); - printf ("*wordendptr;\n"); - } - if (option[TYPE]) - { - printf (" register "); - output_const_type (const_readonly_array, struct_tag); - printf ("*resword;\n\n"); - } - else - printf (" register %sresword;\n\n", - struct_tag); - - output_switches (head, num_switches, switch_size, min_hash_value, max_hash_value, 10); - - if (option[DUP]) - { - int indent = 8; - printf ("%*s return 0;\n" - "%*smulticompare:\n" - "%*s while (wordptr < wordendptr)\n" - "%*s {\n", - indent, "", indent, "", indent, "", indent, ""); - if (option[LENTABLE]) - { - printf ("%*s if (len == *lengthptr)\n" - "%*s {\n", - indent, "", indent, ""); - indent += 4; - } - printf ("%*s register %schar *s = ", - indent, "", const_always); - if (option[TYPE]) - printf ("wordptr->%s", option.get_key_name ()); - else - printf ("*wordptr"); - printf (";\n\n" - "%*s if (", - indent, ""); - comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s")); - printf (")\n" - "%*s return %s;\n", - indent, "", - option[TYPE] ? "wordptr" : "s"); - if (option[LENTABLE]) - { - indent -= 4; - printf ("%*s }\n", - indent, ""); - } - if (option[LENTABLE]) - printf ("%*s lengthptr++;\n", - indent, ""); - printf ("%*s wordptr++;\n" - "%*s }\n", - indent, "", indent, ""); - } - printf (" return 0;\n" - " compare:\n"); - if (option[TYPE]) - { - printf (" {\n" - " register %schar *s = resword->%s;\n\n" - " if (", - const_always, option.get_key_name ()); - comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s")); - printf (")\n" - " return resword;\n" - " }\n"); - } - else - { - printf (" if ("); - comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("resword")); - printf (")\n" - " return resword;\n"); - } - printf (" }\n"); - } - else - { - printf (" if (key <= MAX_HASH_VALUE && key >= 0)\n"); - - if (option[DUP]) - { - int indent = 8; - printf ("%*s{\n" - "%*s register int index = lookup[key];\n\n" - "%*s if (index >= 0)\n", - indent, "", indent, "", indent, ""); - if (option[LENTABLE]) - { - printf ("%*s {\n" - "%*s if (len == lengthtable[index])\n", - indent, "", indent, ""); - indent += 4; - } - printf ("%*s {\n" - "%*s register %schar *s = %s[index]", - indent, "", - indent, "", const_always, option.get_wordlist_name ()); - if (option[TYPE]) - printf (".%s", option.get_key_name ()); - printf (";\n\n" - "%*s if (", - indent, ""); - comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s")); - printf (")\n" - "%*s return ", - indent, ""); - if (option[TYPE]) - printf ("&%s[index]", option.get_wordlist_name ()); - else - printf ("s"); - printf (";\n" - "%*s }\n", - indent, ""); - if (option[LENTABLE]) - { - indent -= 4; - printf ("%*s }\n", indent, ""); - } - if (total_duplicates > 0) - { - printf ("%*s else if (index < -TOTAL_KEYWORDS)\n" - "%*s {\n" - "%*s register int offset = - 1 - TOTAL_KEYWORDS - index;\n", - indent, "", indent, "", indent, ""); - if (option[LENTABLE]) - printf ("%*s register %s%s *lengthptr = &lengthtable[TOTAL_KEYWORDS + lookup[offset]];\n", - indent, "", const_always, smallest_integral_type (max_key_len)); - printf ("%*s register ", - indent, ""); - output_const_type (const_readonly_array, struct_tag); - printf ("*wordptr = &%s[TOTAL_KEYWORDS + lookup[offset]];\n", - option.get_wordlist_name ()); - printf ("%*s register ", - indent, ""); - output_const_type (const_readonly_array, struct_tag); - printf ("*wordendptr = wordptr + -lookup[offset + 1];\n\n"); - printf ("%*s while (wordptr < wordendptr)\n" - "%*s {\n", - indent, "", indent, ""); - if (option[LENTABLE]) - { - printf ("%*s if (len == *lengthptr)\n" - "%*s {\n", - indent, "", indent, ""); - indent += 4; - } - printf ("%*s register %schar *s = ", - indent, "", const_always); - if (option[TYPE]) - printf ("wordptr->%s", option.get_key_name ()); - else - printf ("*wordptr"); - printf (";\n\n" - "%*s if (", - indent, ""); - comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s")); - printf (")\n" - "%*s return %s;\n", - indent, "", - option[TYPE] ? "wordptr" : "s"); - if (option[LENTABLE]) - { - indent -= 4; - printf ("%*s }\n", - indent, ""); - } - if (option[LENTABLE]) - printf ("%*s lengthptr++;\n", - indent, ""); - printf ("%*s wordptr++;\n" - "%*s }\n" - "%*s }\n", - indent, "", indent, "", indent, ""); - } - printf ("%*s}\n", - indent, ""); - } - else - { - int indent = 8; - if (option[LENTABLE]) - { - printf ("%*sif (len == lengthtable[key])\n", - indent, ""); - indent += 2; - } - - printf ("%*s{\n" - "%*s register %schar *s = %s[key]", - indent, "", - indent, "", const_always, option.get_wordlist_name ()); - - if (option[TYPE]) - printf (".%s", option.get_key_name ()); - - printf (";\n\n" - "%*s if (", - indent, ""); - comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s")); - printf (")\n" - "%*s return ", - indent, ""); - if (option[TYPE]) - printf ("&%s[key]", option.get_wordlist_name ()); - else - printf ("s"); - printf (";\n" - "%*s}\n", - indent, ""); - } - } - printf (" }\n" - " return 0;\n"); -} - -/* Generates C code for the lookup function. */ - -void -Key_List::output_lookup_function (void) -{ - T (Trace t ("Key_List::output_lookup_function");) - - /* Output the function's head. */ - if (option[KRC] | option[C] | option[ANSIC]) - printf ("#ifdef __GNUC__\n" - "__inline\n" - "#endif\n"); - - printf ("%s%s\n", - const_for_struct, return_type); - if (option[CPLUSPLUS]) - printf ("%s::", option.get_class_name ()); - printf ("%s ", option.get_function_name ()); - if (option[KRC] || option[C] || option[ANSIC] || option[CPLUSPLUS]) - printf (option[KRC] ? - "(str, len)\n" - " register char *str;\n" - " register unsigned int len;\n" : - option[C] ? - "(str, len)\n" - " register const char *str;\n" - " register unsigned int len;\n" : - "(register const char *str, register unsigned int len)\n"); - - /* Output the function's body. */ - printf ("{\n"); - - if (option[ENUM] && !option[GLOBAL]) - { - Output_Enum style (" "); - output_constants (style); - } - - if (!option[GLOBAL]) - output_lookup_tables (); - - if (option[LENTABLE]) - output_lookup_function_body (Output_Compare_Memcmp ()); - else - { - if (option[COMP]) - output_lookup_function_body (Output_Compare_Strncmp ()); - else - output_lookup_function_body (Output_Compare_Strcmp ()); - } - - printf ("}\n"); -} - -/* ------------------------------------------------------------------------- */ - -/* Generates the hash function and the key word recognizer function - based upon the user's Options. */ - -void -Key_List::output (void) -{ - T (Trace t ("Key_List::output");) - - compute_min_max (); - - if (option[C] | option[ANSIC] | option[CPLUSPLUS]) - { - const_always = "const "; - const_readonly_array = (option[CONST] ? "const " : ""); - const_for_struct = ((option[CONST] && option[TYPE]) ? "const " : ""); - } - else - { - const_always = ""; - const_readonly_array = ""; - const_for_struct = ""; - } - - if (!option[TYPE]) - { - return_type = (const_always[0] ? "const char *" : "char *"); - struct_tag = (const_always[0] ? "const char *" : "char *"); - } - - char_to_index = (option[SEVENBIT] ? "" : "(unsigned char)"); - - printf ("/* "); - if (option[KRC]) - printf ("KR-C"); - else if (option[C]) - printf ("C"); - else if (option[ANSIC]) - printf ("ANSI-C"); - else if (option[CPLUSPLUS]) - printf ("C++"); - printf (" code produced by gperf version %s */\n", version_string); - Options::print_options (); - - printf ("%s\n", include_src); - - if (option[TYPE] && !option[NOTYPE]) /* Output type declaration now, reference it later on.... */ - printf ("%s;\n", array_type); - - if (option[INCLUDE]) - printf ("#include \n"); /* Declare strlen(), strcmp(), strncmp(). */ - - if (!option[ENUM]) - { - Output_Defines style; - output_constants (style); - } - else if (option[GLOBAL]) - { - Output_Enum style (""); - output_constants (style); - } - - printf ("/* maximum key range = %d, duplicates = %d */\n\n", - max_hash_value - min_hash_value + 1, total_duplicates); - - if (option[CPLUSPLUS]) - printf ("class %s\n" - "{\n" - "private:\n" - " static inline unsigned int %s (const char *str, unsigned int len);\n" - "public:\n" - " static %s%s%s (const char *str, unsigned int len);\n" - "};\n" - "\n", - option.get_class_name (), option.get_hash_name (), - const_for_struct, return_type, option.get_function_name ()); - - output_hash_function (); - - if (option[GLOBAL]) - output_lookup_tables (); - - output_lookup_function (); - - if (additional_code) - for (int c; (c = getchar ()) != EOF; putchar (c)) - ; - - fflush (stdout); -} - -/* ========================= End of Output routines ========================= */ - -/* Sorts the keys by hash value. */ - -void -Key_List::sort (void) -{ - T (Trace t ("Key_List::sort");) - hash_sort = 1; - occurrence_sort = 0; - - head = merge_sort (head); -} - -/* Dumps the key list to stderr stream. */ - -void -Key_List::dump () -{ - T (Trace t ("Key_List::dump");) - int field_width = option.get_max_keysig_size (); - - fprintf (stderr, "\nList contents are:\n(hash value, key length, index, %*s, keyword):\n", - field_width, "char_set"); - - for (List_Node *ptr = head; ptr; ptr = ptr->next) - fprintf (stderr, "%11d,%11d,%6d, %*.*s, %.*s\n", - ptr->hash_value, ptr->key_length, ptr->index, - field_width, ptr->char_set_length, ptr->char_set, - ptr->key_length, ptr->key); -} - -/* Simple-minded constructor action here... */ - -Key_List::Key_List (void) -{ - T (Trace t ("Key_List::Key_List");) - total_keys = 1; - max_key_len = INT_MIN; - min_key_len = INT_MAX; - array_type = 0; - return_type = 0; - struct_tag = 0; - head = 0; - total_duplicates = 0; - additional_code = 0; -} - -/* Returns the length of entire key list. */ - -int -Key_List::keyword_list_length (void) -{ - T (Trace t ("Key_List::keyword_list_length");) - return list_len; -} - -/* Returns length of longest key read. */ - -int -Key_List::max_key_length (void) -{ - T (Trace t ("Key_List::max_key_length");) - return max_key_len; -} - diff --git a/contrib/gperf/src/key-list.h b/contrib/gperf/src/key-list.h deleted file mode 100644 index 98b8fa5e0c84..000000000000 --- a/contrib/gperf/src/key-list.h +++ /dev/null @@ -1,96 +0,0 @@ -/* This may look like C code, but it is really -*- C++ -*- */ - -/* Data and function member declarations for the keyword list class. - - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -/* The key word list is a useful abstraction that keeps track of - various pieces of information that enable that fast generation - of the Gen_Perf.hash function. A Key_List is a singly-linked - list of List_Nodes. */ - -#ifndef key_list_h -#define key_list_h 1 - -#include "list-node.h" -#include "vectors.h" -#include "read-line.h" - -/* OSF/1 cxx needs these forward declarations. */ -struct Output_Constants; -struct Output_Compare; - -class Key_List : private Read_Line, public Vectors -{ -private: - const char *array_type; /* Pointer to the type for word list. */ - const char *return_type; /* Pointer to return type for lookup function. */ - const char *struct_tag; /* Shorthand for user-defined struct tag type. */ - const char *include_src; /* C source code to be included verbatim. */ - int max_key_len; /* Maximum length of the longest keyword. */ - int min_key_len; /* Minimum length of the shortest keyword. */ - int min_hash_value; /* Minimum hash value for all keywords. */ - int max_hash_value; /* Maximum hash value for all keywords. */ - int occurrence_sort; /* True if sorting by occurrence. */ - int hash_sort; /* True if sorting by hash value. */ - int additional_code; /* True if any additional C code is included. */ - int list_len; /* Length of head's Key_List, not counting duplicates. */ - int total_keys; /* Total number of keys, counting duplicates. */ - static int determined[MAX_ALPHA_SIZE]; /* Used in function reorder, below. */ - static int get_occurrence (List_Node *ptr); -#ifndef strcspn - static int strcspn (const char *s, const char *reject); -#endif - static int already_determined (List_Node *ptr); - static void set_determined (List_Node *ptr); - void compute_min_max (void); - int num_hash_values (void); - void output_constants (struct Output_Constants&); - void output_hash_function (void); - void output_keylength_table (void); - void output_keyword_table (void); - void output_lookup_array (void); - void output_lookup_tables (void); - void output_lookup_function_body (const struct Output_Compare&); - void output_lookup_function (void); - void set_output_types (void); - void dump (void); - const char *get_array_type (void); - const char *save_include_src (void); - const char *get_special_input (char delimiter); - List_Node *merge (List_Node *list1, List_Node *list2); - List_Node *merge_sort (List_Node *head); - -protected: - List_Node *head; /* Points to the head of the linked list. */ - int total_duplicates; /* Total number of duplicate hash values. */ - -public: - Key_List (void); - ~Key_List (void); - int keyword_list_length (void); - int max_key_length (void); - void reorder (void); - void sort (void); - void read_keys (void); - void output (void); -}; - -#endif diff --git a/contrib/gperf/src/keyword-list.cc b/contrib/gperf/src/keyword-list.cc new file mode 100644 index 000000000000..ac559f7933d2 --- /dev/null +++ b/contrib/gperf/src/keyword-list.cc @@ -0,0 +1,175 @@ +/* Keyword list. + + Copyright (C) 2002 Free Software Foundation, Inc. + Written by Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Specification. */ +#include "keyword-list.h" + +#include + +/* -------------------------- Keyword_List class --------------------------- */ + +/* Constructor. */ +Keyword_List::Keyword_List (Keyword *car) + : _cdr (NULL), _car (car) +{ +} + +/* ------------------------- KeywordExt_List class ------------------------- */ + +/* Constructor. */ +KeywordExt_List::KeywordExt_List (KeywordExt *car) + : Keyword_List (car) +{ +} + +/* ------------------------ Keyword_List functions ------------------------- */ + +/* Copies a linear list, sharing the list elements. */ +Keyword_List * +copy_list (Keyword_List *list) +{ + Keyword_List *result; + Keyword_List **lastp = &result; + while (list != NULL) + { + Keyword_List *new_cons = new Keyword_List (list->first()); + *lastp = new_cons; + lastp = &new_cons->rest(); + list = list->rest(); + } + *lastp = NULL; + return result; +} + +/* Copies a linear list, sharing the list elements. */ +KeywordExt_List * +copy_list (KeywordExt_List *list) +{ + return static_cast (copy_list (static_cast (list))); +} + +/* Deletes a linear list, keeping the list elements in memory. */ +void +delete_list (Keyword_List *list) +{ + while (list != NULL) + { + Keyword_List *rest = list->rest(); + delete list; + list = rest; + } +} + +/* Type of a comparison function. */ +typedef bool (*Keyword_Comparison) (Keyword *keyword1, Keyword *keyword2); + +/* Merges two sorted lists together to form one sorted list. */ +static Keyword_List * +merge (Keyword_List *list1, Keyword_List *list2, Keyword_Comparison less) +{ + Keyword_List *result; + Keyword_List **resultp = &result; + for (;;) + { + if (!list1) + { + *resultp = list2; + break; + } + if (!list2) + { + *resultp = list1; + break; + } + if (less (list2->first(), list1->first())) + { + *resultp = list2; + resultp = &list2->rest(); + /* We would have a stable sorting if the next line would read: + list2 = *resultp; */ + list2 = list1; list1 = *resultp; + } + else + { + *resultp = list1; + resultp = &list1->rest(); + list1 = *resultp; + } + } + return result; +} + +/* Sorts a linear list, given a comparison function. + Note: This uses a variant of mergesort that is *not* a stable sorting + algorithm. */ +Keyword_List * +mergesort_list (Keyword_List *list, Keyword_Comparison less) +{ + if (list == NULL || list->rest() == NULL) + /* List of length 0 or 1. Nothing to do. */ + return list; + else + { + /* Determine a list node in the middle. */ + Keyword_List *middle = list; + for (Keyword_List *temp = list->rest();;) + { + temp = temp->rest(); + if (temp == NULL) + break; + temp = temp->rest(); + middle = middle->rest(); + if (temp == NULL) + break; + } + + /* Cut the list into two halves. + If the list has n elements, the left half has ceiling(n/2) elements + and the right half has floor(n/2) elements. */ + Keyword_List *right_half = middle->rest(); + middle->rest() = NULL; + + /* Sort the two halves, then merge them. */ + return merge (mergesort_list (list, less), + mergesort_list (right_half, less), + less); + } +} + +KeywordExt_List * +mergesort_list (KeywordExt_List *list, + bool (*less) (KeywordExt *keyword1, KeywordExt *keyword2)) +{ + return + static_cast + (mergesort_list (static_cast (list), + reinterpret_cast (less))); +} + + +#ifndef __OPTIMIZE__ + +#define INLINE /* not inline */ +#include "keyword-list.icc" +#undef INLINE + +#endif /* not defined __OPTIMIZE__ */ diff --git a/contrib/gperf/src/keyword-list.h b/contrib/gperf/src/keyword-list.h new file mode 100644 index 000000000000..a15b3b4adf0f --- /dev/null +++ b/contrib/gperf/src/keyword-list.h @@ -0,0 +1,85 @@ +/* This may look like C code, but it is really -*- C++ -*- */ + +/* Keyword list. + + Copyright (C) 2002 Free Software Foundation, Inc. + Written by Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef keyword_list_h +#define keyword_list_h 1 + +#include "keyword.h" + +/* List node of a linear list of Keyword. */ +class Keyword_List +{ +public: + /* Constructor. */ + Keyword_List (Keyword *car); + + /* Access to first element of list. */ + Keyword * first () const; + /* Access to next element of list. */ + Keyword_List *& rest (); + +protected: + Keyword_List * _cdr; + Keyword * const _car; +}; + +/* List node of a linear list of KeywordExt. */ +class KeywordExt_List : public Keyword_List +{ +public: + /* Constructor. */ + KeywordExt_List (KeywordExt *car); + + /* Access to first element of list. */ + KeywordExt * first () const; + /* Access to next element of list. */ + KeywordExt_List *& rest (); +}; + +/* Copies a linear list, sharing the list elements. */ +extern Keyword_List * copy_list (Keyword_List *list); +extern KeywordExt_List * copy_list (KeywordExt_List *list); + +/* Deletes a linear list, keeping the list elements in memory. */ +extern void delete_list (Keyword_List *list); + +/* Sorts a linear list, given a comparison function. + Note: This uses a variant of mergesort that is *not* a stable sorting + algorithm. */ +extern Keyword_List * mergesort_list (Keyword_List *list, + bool (*less) (Keyword *keyword1, + Keyword *keyword2)); +extern KeywordExt_List * mergesort_list (KeywordExt_List *list, + bool (*less) (KeywordExt *keyword1, + KeywordExt *keyword2)); + +#ifdef __OPTIMIZE__ + +#define INLINE inline +#include "keyword-list.icc" +#undef INLINE + +#endif + +#endif diff --git a/contrib/gperf/src/keyword-list.icc b/contrib/gperf/src/keyword-list.icc new file mode 100644 index 000000000000..7fbdaacb2ccb --- /dev/null +++ b/contrib/gperf/src/keyword-list.icc @@ -0,0 +1,53 @@ +/* Inline Functions for keyword-list.{h,cc}. + + Copyright (C) 2002-2003 Free Software Foundation, Inc. + Written by Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* -------------------------- Keyword_List class --------------------------- */ + +/* Access to first element of list. */ +INLINE Keyword * +Keyword_List::first () const +{ + return _car; +} + +/* Access to next element of list. */ +INLINE Keyword_List *& +Keyword_List::rest () +{ + return _cdr; +} + +/* ------------------------- KeywordExt_List class ------------------------- */ + +/* Access to first element of list. */ +INLINE KeywordExt * +KeywordExt_List::first () const +{ + return static_cast(_car); +} + +/* Access to next element of list. */ +INLINE KeywordExt_List *& +KeywordExt_List::rest () +{ + return *reinterpret_cast(&_cdr); +} diff --git a/contrib/gperf/src/keyword.cc b/contrib/gperf/src/keyword.cc new file mode 100644 index 000000000000..ae53bcca320a --- /dev/null +++ b/contrib/gperf/src/keyword.cc @@ -0,0 +1,161 @@ +/* Keyword data. + Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Specification. */ +#include "keyword.h" + +#include +#include +#include +#include "positions.h" + + +/* --------------------------- KeywordExt class --------------------------- */ + +/* Sort a small set of 'unsigned int', base[0..len-1], in place. */ +static inline void sort_char_set (unsigned int *base, int len) +{ + /* Bubble sort is sufficient here. */ + for (int i = 1; i < len; i++) + { + int j; + unsigned int tmp; + + for (j = i, tmp = base[j]; j > 0 && tmp < base[j - 1]; j--) + base[j] = base[j - 1]; + + base[j] = tmp; + } +} + +/* Initializes selchars and selchars_length. + + General idea: + The hash function will be computed as + asso_values[allchars[key_pos[0]]] + + asso_values[allchars[key_pos[1]]] + ... + We compute selchars as the multiset + { allchars[key_pos[0]], allchars[key_pos[1]], ... } + so that the hash function becomes + asso_values[selchars[0]] + asso_values[selchars[1]] + ... + Furthermore we sort the selchars array, to ease detection of duplicates + later. + + More in detail: The arguments alpha_unify (used for case-insensitive + hash functions) and alpha_inc (used to disambiguate permutations) + apply slight modifications. The hash function will be computed as + sum (j=0,1,...: k = key_pos[j]: + asso_values[alpha_unify[allchars[k]+alpha_inc[k]]]) + + (allchars_length if !option[NOLENGTH], 0 otherwise). + We compute selchars as the multiset + { alpha_unify[allchars[k]+alpha_inc[k]] : j=0,1,..., k = key_pos[j] } + so that the hash function becomes + asso_values[selchars[0]] + asso_values[selchars[1]] + ... + + (allchars_length if !option[NOLENGTH], 0 otherwise). + */ + +unsigned int * +KeywordExt::init_selchars_low (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc) +{ + /* Iterate through the list of positions, initializing selchars + (via ptr). */ + PositionIterator iter = positions.iterator(_allchars_length); + + unsigned int *key_set = new unsigned int[iter.remaining()]; + unsigned int *ptr = key_set; + + for (int i; (i = iter.next ()) != PositionIterator::EOS; ) + { + unsigned int c; + if (i == Positions::LASTCHAR) + /* Special notation for last KEY position, i.e. '$'. */ + c = static_cast(_allchars[_allchars_length - 1]); + else if (i < _allchars_length) + { + /* Within range of KEY length, so we'll keep it. */ + c = static_cast(_allchars[i]); + if (alpha_inc) + c += alpha_inc[i]; + } + else + /* Out of range of KEY length, the iterator should not have + produced this. */ + abort (); + if (alpha_unify) + c = alpha_unify[c]; + *ptr = c; + ptr++; + } + + _selchars = key_set; + _selchars_length = ptr - key_set; + + return key_set; +} + +void +KeywordExt::init_selchars_tuple (const Positions& positions, const unsigned int *alpha_unify) +{ + init_selchars_low (positions, alpha_unify, NULL); +} + +void +KeywordExt::init_selchars_multiset (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc) +{ + unsigned int *selchars = + init_selchars_low (positions, alpha_unify, alpha_inc); + + /* Sort the selchars elements alphabetically. */ + sort_char_set (selchars, _selchars_length); +} + +/* Deletes selchars. */ +void +KeywordExt::delete_selchars () +{ + delete[] const_cast(_selchars); +} + + +/* ------------------------- Keyword_Factory class ------------------------- */ + +Keyword_Factory::Keyword_Factory () +{ +} + +Keyword_Factory::~Keyword_Factory () +{ +} + + +/* ------------------------------------------------------------------------- */ + +char empty_string[1] = ""; + + +#ifndef __OPTIMIZE__ + +#define INLINE /* not inline */ +#include "keyword.icc" +#undef INLINE + +#endif /* not defined __OPTIMIZE__ */ diff --git a/contrib/gperf/src/keyword.h b/contrib/gperf/src/keyword.h new file mode 100644 index 000000000000..88243506c2e3 --- /dev/null +++ b/contrib/gperf/src/keyword.h @@ -0,0 +1,116 @@ +/* This may look like C code, but it is really -*- C++ -*- */ + +/* Keyword data. + + Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef keyword_h +#define keyword_h 1 + +/* Class defined in "positions.h". */ +class Positions; + +/* An instance of this class is a keyword, as specified in the input file. */ + +struct Keyword +{ + /* Constructor. */ + Keyword (const char *allchars, int allchars_length, + const char *rest); + + /* Data members defined immediately by the input file. */ + /* The keyword as a string, possibly containing NUL bytes. */ + const char *const _allchars; + int const _allchars_length; + /* Additional stuff seen on the same line of the input file. */ + const char *const _rest; + /* Line number of this keyword in the input file. */ + unsigned int _lineno; +}; + +/* A keyword, in the context of a given keyposition list. */ + +struct KeywordExt : public Keyword +{ + /* Constructor. */ + KeywordExt (const char *allchars, int allchars_length, + const char *rest); + + /* Data members depending on the keyposition list. */ + /* The selected characters that participate for the hash function, + selected according to the keyposition list, as a canonically reordered + multiset. */ + const unsigned int * _selchars; + int _selchars_length; + /* Chained list of keywords having the same _selchars and + - if !option[NOLENGTH] - also the same _allchars_length. + Note that these duplicates are not members of the main keyword list. */ + KeywordExt * _duplicate_link; + + /* Methods depending on the keyposition list. */ + /* Initializes selchars and selchars_length, without reordering. */ + void init_selchars_tuple (const Positions& positions, const unsigned int *alpha_unify); + /* Initializes selchars and selchars_length, with reordering. */ + void init_selchars_multiset (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc); + /* Deletes selchars. */ + void delete_selchars (); + + /* Data members used by the algorithm. */ + int _hash_value; /* Hash value for the keyword. */ + + /* Data members used by the output routines. */ + int _final_index; + +private: + unsigned int * init_selchars_low (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc); +}; + +/* An abstract factory for creating Keyword instances. + This factory is used to make the Input class independent of the concrete + class KeywordExt. */ + +class Keyword_Factory +{ +public: + /* Constructor. */ + Keyword_Factory (); + /* Destructor. */ + virtual ~Keyword_Factory (); + + /* Creates a new Keyword. */ + virtual /*abstract*/ Keyword * + create_keyword (const char *allchars, int allchars_length, + const char *rest) = 0; +}; + +/* A statically allocated empty string. */ +extern char empty_string[1]; + +#ifdef __OPTIMIZE__ + +#define INLINE inline +#include "keyword.icc" +#undef INLINE + +#endif + +#endif diff --git a/contrib/gperf/src/keyword.icc b/contrib/gperf/src/keyword.icc new file mode 100644 index 000000000000..ba0bb56eebc1 --- /dev/null +++ b/contrib/gperf/src/keyword.icc @@ -0,0 +1,42 @@ +/* Inline Functions for keyword.{h,cc}. + + Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* ----------------------------- Keyword class ----------------------------- */ + +/* Constructor. */ +INLINE +Keyword::Keyword (const char *allchars, int allchars_length, const char *rest) + : _allchars (allchars), _allchars_length (allchars_length), _rest (rest) +{ +} + + +/* --------------------------- KeywordExt class --------------------------- */ + +/* Constructor. */ +INLINE +KeywordExt::KeywordExt (const char *allchars, int allchars_length, const char *rest) + : Keyword (allchars, allchars_length, rest), + _final_index (-1) +{ +} diff --git a/contrib/gperf/src/list-node.cc b/contrib/gperf/src/list-node.cc deleted file mode 100644 index 57a04a071fe4..000000000000 --- a/contrib/gperf/src/list-node.cc +++ /dev/null @@ -1,102 +0,0 @@ -/* Creates and initializes a new list node. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#include "list-node.h" - -#include -#include /* declares exit() */ -#include "options.h" -#include "trace.h" - -/* Sorts the key set alphabetically to speed up subsequent operations. - Uses insertion sort since the set is probably quite small. */ - -inline void -List_Node::set_sort (char *base, int len) -{ - T (Trace t ("List_Node::set_sort");) - int i, j; - - for (i = 0, j = len - 1; i < j; i++) - { - char curr, tmp; - - for (curr = i + 1, tmp = base[curr]; curr > 0 && tmp < base[curr-1]; curr--) - base[curr] = base[curr - 1]; - - base[curr] = tmp; - - } -} - -/* Initializes a List_Node. This requires obtaining memory for the CHAR_SET - initializing them using the information stored in the KEY_POSITIONS array in Options, - and checking for simple errors. It's important to note that KEY and REST are - both pointers to the different offsets into the same block of dynamic memory pointed - to by parameter K. The data member REST is used to store any additional fields - of the input file (it is set to the "" string if Option[TYPE] is not enabled). - This is useful if the user wishes to incorporate a lookup structure, - rather than just an array of keys. Finally, KEY_NUMBER contains a count - of the total number of keys seen so far. This is used to initialize - the INDEX field to some useful value. */ - -List_Node::List_Node (const char *k, int len, const char *r): - link (0), next (0), key (k), key_length (len), rest (r), index (0) -{ - T (Trace t ("List_Node::List_Node");) - char *key_set = new char[(option[ALLCHARS] ? len : option.get_max_keysig_size ())]; - char *ptr = key_set; - int i; - - if (option[ALLCHARS]) /* Use all the character positions in the KEY. */ - for (i = len; i > 0; k++, ptr++, i--) - ++occurrences[(unsigned char)(*ptr = *k)]; - else /* Only use those character positions specified by the user. */ - { - /* Iterate through the list of key_positions, initializing occurrences table - and char_set (via char * pointer ptr). */ - - for (option.reset (); (i = option.get ()) != EOS; ) - { - if (i == WORD_END) /* Special notation for last KEY position, i.e. '$'. */ - *ptr = key[len - 1]; - else if (i <= len) /* Within range of KEY length, so we'll keep it. */ - *ptr = key[i - 1]; - else /* Out of range of KEY length, so we'll just skip it. */ - continue; - ++occurrences[(unsigned char)(*ptr++)]; - } - - /* Didn't get any hits and user doesn't want to consider the - keylength, so there are essentially no usable hash positions! */ - if (ptr == char_set && option[NOLENGTH]) - { - fprintf (stderr, "Can't hash keyword %.*s with chosen key positions.\n", - key_length, key); - exit (1); - } - } - - /* Sort the KEY_SET items alphabetically. */ - set_sort (key_set, ptr - key_set); - - char_set = key_set; - char_set_length = ptr - key_set; -} diff --git a/contrib/gperf/src/list-node.h b/contrib/gperf/src/list-node.h deleted file mode 100644 index 3bd21b3359df..000000000000 --- a/contrib/gperf/src/list-node.h +++ /dev/null @@ -1,46 +0,0 @@ -/* This may look like C code, but it is really -*- C++ -*- */ - -/* Data and function members for defining values and operations of a list node. - - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#ifndef list_node_h -#define list_node_h 1 - -#include "vectors.h" - -struct List_Node : private Vectors -{ - List_Node *link; /* TRUE if key has an identical KEY_SET as another key. */ - List_Node *next; /* Points to next element on the list. */ - const char *key; /* Each keyword string stored here. */ - int key_length; /* Length of the key. */ - const char *rest; /* Additional information for building hash function. */ - const char *char_set; /* Set of characters to hash, specified by user. */ - int char_set_length; /* Length of char_set. */ - int hash_value; /* Hash value for the key. */ - int occurrence; /* A metric for frequency of key set occurrences. */ - int index; /* Position of this node relative to other nodes. */ - - List_Node (const char *key, int len, const char *rest); - static void set_sort (char *base, int len); -}; - -#endif diff --git a/contrib/gperf/src/main.cc b/contrib/gperf/src/main.cc index 03b6c7ea242b..577708b48bfd 100644 --- a/contrib/gperf/src/main.cc +++ b/contrib/gperf/src/main.cc @@ -1,76 +1,155 @@ -/* Driver program for the Gen_Perf hash function generator - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) +/* Driver program for the hash function generator + Copyright (C) 1989-1998, 2000, 2002-2003 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -/* Simple driver program for the Gen_Perf.hash function generator. - Most of the hard work is done in class Gen_Perf and its class methods. */ - -#include "config.h" -#include -#if LARGE_STACK_ARRAYS && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) -#ifdef HAVE_SYS_TIME_H -#include -#endif -#ifdef HAVE_SYS_RESOURCE_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#endif + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include +#include +#include #include "options.h" -#include "gen-perf.h" -#include "trace.h" +#include "input.h" +#include "search.h" +#include "output.h" + + +/* ------------------------------------------------------------------------- */ + +/* This Keyword factory produces KeywordExt instances. */ + +class KeywordExt_Factory : public Keyword_Factory +{ +virtual Keyword * create_keyword (const char *allchars, int allchars_length, + const char *rest); +}; + +Keyword * +KeywordExt_Factory::create_keyword (const char *allchars, int allchars_length, const char *rest) +{ + return new KeywordExt (allchars, allchars_length, rest); +} + +/* ------------------------------------------------------------------------- */ int main (int argc, char *argv[]) { - T (Trace t ("main");) + int exitcode; + + /* Set the Options. Open the input file and assign stdin to it. */ + option.parse_options (argc, argv); + + /* Open the input file. */ + if (option.get_input_file_name ()) + if (!freopen (option.get_input_file_name (), "r", stdin)) + { + fprintf (stderr, "Cannot open input file '%s'\n", + option.get_input_file_name ()); + exit (1); + } -#if LARGE_STACK_ARRAYS && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) && defined(RLIMIT_STACK) - /* Get rid of any avoidable limit on stack size. */ { - struct rlimit rlim; - if (getrlimit (RLIMIT_STACK, &rlim) == 0) - if (rlim.rlim_cur < rlim.rlim_max) - { - rlim.rlim_cur = rlim.rlim_max; - setrlimit (RLIMIT_STACK, &rlim); - } + /* Initialize the keyword list. */ + KeywordExt_Factory factory; + Input inputter (stdin, &factory); + inputter.read_input (); + /* We can cast the keyword list to KeywordExt_List* because its list + elements were created by KeywordExt_Factory. */ + KeywordExt_List* list = static_cast(inputter._head); + + { + /* Search for a good hash function. */ + Search searcher (list); + searcher.optimize (); + list = searcher._head; + + /* Open the output file. */ + if (option.get_output_file_name ()) + if (strcmp (option.get_output_file_name (), "-") != 0) + if (!freopen (option.get_output_file_name (), "w", stdout)) + { + fprintf (stderr, "Cannot open output file '%s'\n", + option.get_output_file_name ()); + exit (1); + } + + { + /* Output the hash function code. */ + Output outputter (searcher._head, + inputter._struct_decl, + inputter._struct_decl_lineno, + inputter._return_type, + inputter._struct_tag, + inputter._verbatim_declarations, + inputter._verbatim_declarations_end, + inputter._verbatim_declarations_lineno, + inputter._verbatim_code, + inputter._verbatim_code_end, + inputter._verbatim_code_lineno, + inputter._charset_dependent, + searcher._total_keys, + searcher._max_key_len, + searcher._min_key_len, + searcher._key_positions, + searcher._alpha_inc, + searcher._total_duplicates, + searcher._alpha_size, + searcher._asso_values); + outputter.output (); + + /* Check for write error on stdout. */ + exitcode = 0; + if (fflush (stdout) || ferror (stdout)) + { + fprintf (stderr, "error while writing output file\n"); + exitcode = 1; + } + + /* Here we run the Output destructor. */ + } + /* Here we run the Search destructor. */ + } + + /* Also delete the list that was allocated inside Input and reordered + inside Search. */ + for (KeywordExt_List *ptr = list; ptr; ptr = ptr->rest()) + { + KeywordExt *keyword = ptr->first(); + do + { + KeywordExt *next_keyword = keyword->_duplicate_link; + delete[] const_cast(keyword->_selchars); + if (keyword->_rest != empty_string) + delete[] const_cast(keyword->_rest); + if (!(keyword->_allchars >= inputter._input + && keyword->_allchars < inputter._input_end)) + delete[] const_cast(keyword->_allchars); + delete keyword; + keyword = next_keyword; + } + while (keyword != NULL); + } + delete_list (list); + + /* Here we run the Input destructor. */ } -#endif /* RLIMIT_STACK */ - /* Sets the Options. */ - option (argc, argv); - - /* Initializes the key word list. */ - Gen_Perf generate_table; - - /* Generates and prints the Gen_Perf hash table. */ - int status = generate_table (); - - /* Check for write error on stdout. */ - if (fflush (stdout) || ferror (stdout)) - status = 1; - - /* Don't use exit() here, it skips the destructors. */ - return status; + /* Don't use exit() here, it skips the destructors. */ + return exitcode; } diff --git a/contrib/gperf/src/new.cc b/contrib/gperf/src/new.cc deleted file mode 100644 index 8c6728ec4b2a..000000000000 --- a/contrib/gperf/src/new.cc +++ /dev/null @@ -1,87 +0,0 @@ -/* Defines a buffered memory allocation abstraction that reduces calls to - malloc. - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#include "config.h" -#include -#include /* declares malloc(), exit() */ -#include "trace.h" - -/* Determine default alignment. If your C++ compiler does not - like this then try something like #define DEFAULT_ALIGNMENT 8. */ -struct fooalign {char x; double d;}; -const int ALIGNMENT = ((char *)&((struct fooalign *) 0)->d - (char *)0); - -/* Provide an abstraction that cuts down on the number of - calls to NEW by buffering the memory pool from which - strings are allocated. */ - -void * -operator new (size_t size) -{ - T (Trace t ("operator new");) - static char *buf_start = 0; /* Large array used to reduce calls to NEW. */ - static char *buf_end = 0; /* Indicates end of BUF_START. */ - static size_t buf_size = 4096; /* Size of buffer pointed to by BUF_START. */ - char *temp; - - /* Align this on correct boundaries, just to be safe... */ - size = ((size + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT; - - /* If we are about to overflow our buffer we'll just grab another - chunk of memory. Since we never free the original memory it - doesn't matter that no one points to the beginning of that - chunk. Note we use a heuristic that grows the buffer either by - size of the request or by twice the previous size, whichever is - larger. */ - - if (buf_start + size >= buf_end) - { - buf_size *= 2; - if (buf_size < size) - buf_size = size; - if ((buf_start = (char *)malloc (buf_size)) != (char *)0) - buf_end = buf_start + buf_size; - else - { - fprintf (stderr, "Virtual memory exhausted in `operator new'\n"); - exit (1); - } - } - - temp = buf_start; - buf_start += size; - return temp; -} - -/* We need this deletion operator in order to make the linker happy. - Because `operator new' and `operator delete' always come together. */ - -void -operator delete (void *ptr) -#ifdef HAVE_THROW_DECL - throw() -#endif -{ - T (Trace t ("operator delete");) - // We cannot call free here, as it doesn't match the mallocs. - // free ((char *) ptr); - (void) ptr; -} diff --git a/contrib/gperf/src/options.cc b/contrib/gperf/src/options.cc index 77068480cf5b..a86432ea65ed 100644 --- a/contrib/gperf/src/options.cc +++ b/contrib/gperf/src/options.cc @@ -1,151 +1,192 @@ /* Handles parsing the Options provided to the user. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) + Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2007 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Specification. */ +#include "options.h" #include #include /* declares atoi(), abs(), exit() */ #include /* declares strcmp() */ +#include /* declares isdigit() */ +#include /* defines CHAR_MAX */ #include "getopt.h" -#include "options.h" -#include "iterator.h" -#include "trace.h" -#include "vectors.h" #include "version.h" -/* Global option coordinator for the entire program. */ +/* Global option coordinator for the entire program. */ Options option; -/* Records the program name. */ +/* Records the program name. */ const char *program_name; -/* Size to jump on a collision. */ +/* Size to jump on a collision. */ static const int DEFAULT_JUMP_VALUE = 5; -/* Default name for generated lookup function. */ -static const char *const DEFAULT_NAME = "in_word_set"; +/* Default name for generated lookup function. */ +static const char *const DEFAULT_FUNCTION_NAME = "in_word_set"; -/* Default name for the key component. */ -static const char *const DEFAULT_KEY = "name"; +/* Default name for the key component. */ +static const char *const DEFAULT_SLOT_NAME = "name"; -/* Default struct initializer suffix. */ +/* Default struct initializer suffix. */ static const char *const DEFAULT_INITIALIZER_SUFFIX = ""; -/* Default name for the generated class. */ +/* Default name for the generated class. */ static const char *const DEFAULT_CLASS_NAME = "Perfect_Hash"; -/* Default name for generated hash function. */ +/* Default name for generated hash function. */ static const char *const DEFAULT_HASH_NAME = "hash"; -/* Default name for generated hash table array. */ +/* Default name for generated hash table array. */ static const char *const DEFAULT_WORDLIST_NAME = "wordlist"; -/* Default delimiters that separate keywords from their attributes. */ -static const char *const DEFAULT_DELIMITERS = ",\n"; +/* Default name for generated length table array. */ +static const char *const DEFAULT_LENGTHTABLE_NAME = "lengthtable"; -int Options::option_word; -int Options::total_switches; -int Options::total_keysig_size; -int Options::size; -int Options::key_pos; -int Options::jump; -int Options::initial_asso_value; -int Options::argument_count; -int Options::iterations; -char **Options::argument_vector; -const char *Options::function_name; -const char *Options::key_name; -const char *Options::initializer_suffix; -const char *Options::class_name; -const char *Options::hash_name; -const char *Options::wordlist_name; -const char *Options::delimiters; -char Options::key_positions[MAX_KEY_POS]; +/* Default name for string pool. */ +static const char *const DEFAULT_STRINGPOOL_NAME = "stringpool"; -/* Prints program usage to given stream. */ +/* Default delimiters that separate keywords from their attributes. */ +static const char *const DEFAULT_DELIMITERS = ","; + +/* Prints program usage to given stream. */ void -Options::short_usage (FILE * strm) +Options::short_usage (FILE * stream) { - T (Trace t ("Options::short_usage");) - fprintf (strm, "Usage: %s [-cCdDef[num]FGhHiIjkKlLnNorsStTvWZ7] [input-file]\n" - "Try `%s --help' for more information.\n", - program_name, program_name); + fprintf (stream, + "Try '%s --help' for more information.\n", program_name); } void -Options::long_usage (FILE * strm) +Options::long_usage (FILE * stream) { - T (Trace t ("Options::long_usage");) - fprintf (strm, - "GNU `gperf' generates perfect hash functions.\n" - "\n" - "Usage: %s [OPTION]... [INPUT-FILE]\n" - "\n" + fprintf (stream, + "GNU 'gperf' generates perfect hash functions.\n"); + fprintf (stream, "\n"); + fprintf (stream, + "Usage: %s [OPTION]... [INPUT-FILE]\n", + program_name); + fprintf (stream, "\n"); + fprintf (stream, "If a long option shows an argument as mandatory, then it is mandatory\n" - "for the equivalent short option also.\n" - "\n" - "Input file interpretation:\n" + "for the equivalent short option also.\n"); + fprintf (stream, "\n"); + fprintf (stream, + "Output file location:\n"); + fprintf (stream, + " --output-file=FILE Write output to specified file.\n"); + fprintf (stream, + "The results are written to standard output if no output file is specified\n" + "or if it is -.\n"); + fprintf (stream, "\n"); + fprintf (stream, + "Input file interpretation:\n"); + fprintf (stream, " -e, --delimiters=DELIMITER-LIST\n" " Allow user to provide a string containing delimiters\n" " used to separate keywords from their attributes.\n" - " Default is \",\\n\".\n" + " Default is \",\".\n"); + fprintf (stream, " -t, --struct-type Allows the user to include a structured type\n" " declaration for generated code. Any text before %%%%\n" " is considered part of the type declaration. Key\n" " words and additional fields may follow this, one\n" - " group of fields per line.\n" - "\n" - "Language for the output code:\n" + " group of fields per line.\n"); + fprintf (stream, + " --ignore-case Consider upper and lower case ASCII characters as\n" + " equivalent. Note that locale dependent case mappings\n" + " are ignored.\n"); + fprintf (stream, "\n"); + fprintf (stream, + "Language for the output code:\n"); + fprintf (stream, " -L, --language=LANGUAGE-NAME\n" " Generates code in the specified language. Languages\n" " handled are currently C++, ANSI-C, C, and KR-C. The\n" - " default is C.\n" - "\n" - "Details in the output code:\n" + " default is C.\n"); + fprintf (stream, "\n"); + fprintf (stream, + "Details in the output code:\n"); + fprintf (stream, " -K, --slot-name=NAME Select name of the keyword component in the keyword\n" - " structure.\n" + " structure.\n"); + fprintf (stream, " -F, --initializer-suffix=INITIALIZERS\n" " Initializers for additional components in the keyword\n" - " structure.\n" - " -H, --hash-fn-name=NAME\n" + " structure.\n"); + fprintf (stream, + " -H, --hash-function-name=NAME\n" " Specify name of generated hash function. Default is\n" - " `hash'.\n" - " -N, --lookup-fn-name=NAME\n" + " 'hash'.\n"); + fprintf (stream, + " -N, --lookup-function-name=NAME\n" " Specify name of generated lookup function. Default\n" - " name is `in_word_set'.\n" + " name is 'in_word_set'.\n"); + fprintf (stream, " -Z, --class-name=NAME Specify name of generated C++ class. Default name is\n" - " `Perfect_Hash'.\n" - " -7, --seven-bit Assume 7-bit characters.\n" + " 'Perfect_Hash'.\n"); + fprintf (stream, + " -7, --seven-bit Assume 7-bit characters.\n"); + fprintf (stream, + " -l, --compare-lengths Compare key lengths before trying a string\n" + " comparison. This is necessary if the keywords\n" + " contain NUL bytes. It also helps cut down on the\n" + " number of string comparisons made during the lookup.\n"); + fprintf (stream, " -c, --compare-strncmp Generate comparison code using strncmp rather than\n" - " strcmp.\n" + " strcmp.\n"); + fprintf (stream, " -C, --readonly-tables Make the contents of generated lookup tables\n" - " constant, i.e., readonly.\n" + " constant, i.e., readonly.\n"); + fprintf (stream, " -E, --enum Define constant values using an enum local to the\n" - " lookup function rather than with defines.\n" + " lookup function rather than with defines.\n"); + fprintf (stream, " -I, --includes Include the necessary system include file \n" - " at the beginning of the code.\n" - " -G, --global Generate the static table of keywords as a static\n" + " at the beginning of the code.\n"); + fprintf (stream, + " -G, --global-table Generate the static table of keywords as a static\n" " global variable, rather than hiding it inside of the\n" - " lookup function (which is the default behavior).\n" + " lookup function (which is the default behavior).\n"); + fprintf (stream, + " -P, --pic Optimize the generated table for inclusion in shared\n" + " libraries. This reduces the startup time of programs\n" + " using a shared library containing the generated code.\n"); + fprintf (stream, + " -Q, --string-pool-name=NAME\n" + " Specify name of string pool generated by option --pic.\n" + " Default name is 'stringpool'.\n"); + fprintf (stream, + " --null-strings Use NULL strings instead of empty strings for empty\n" + " keyword table entries.\n"); + fprintf (stream, " -W, --word-array-name=NAME\n" " Specify name of word list array. Default name is\n" - " `wordlist'.\n" + " 'wordlist'.\n"); + fprintf (stream, + " --length-table-name=NAME\n" + " Specify name of length table array. Default name is\n" + " 'lengthtable'.\n"); + fprintf (stream, " -S, --switch=COUNT Causes the generated C code to use a switch\n" " statement scheme, rather than an array lookup table.\n" " This can lead to a reduction in both time and space\n" @@ -155,13 +196,16 @@ Options::long_usage (FILE * strm) " elements, a value of 2 generates 2 tables with 1/2\n" " the elements in each table, etc. If COUNT is very\n" " large, say 1000000, the generated C code does a\n" - " binary search.\n" + " binary search.\n"); + fprintf (stream, " -T, --omit-struct-type\n" " Prevents the transfer of the type declaration to the\n" " output file. Use this option if the type is already\n" - " defined elsewhere.\n" - "\n" - "Algorithm employed by gperf:\n" + " defined elsewhere.\n"); + fprintf (stream, "\n"); + fprintf (stream, + "Algorithm employed by gperf:\n"); + fprintf (stream, " -k, --key-positions=KEYS\n" " Select the key positions used in the hash function.\n" " The allowable choices range between 1-%d, inclusive.\n" @@ -169,79 +213,93 @@ Options::long_usage (FILE * strm) " used, and key positions may occur in any order.\n" " Also, the meta-character '*' causes the generated\n" " hash function to consider ALL key positions, and $\n" - " indicates the ``final character'' of a key, e.g.,\n" - " $,1,2,4,6-10.\n" - " -l, --compare-strlen Compare key lengths before trying a string\n" - " comparison. This helps cut down on the number of\n" - " string comparisons made during the lookup.\n" + " indicates the \"final character\" of a key, e.g.,\n" + " $,1,2,4,6-10.\n", + Positions::MAX_KEY_POS); + fprintf (stream, " -D, --duplicates Handle keywords that hash to duplicate values. This\n" - " is useful for certain highly redundant keyword sets.\n" - " -f, --fast=ITERATIONS Generate the gen-perf.hash function ``fast''. This\n" - " decreases gperf's running time at the cost of\n" - " minimizing generated table size. The numeric\n" - " argument represents the number of times to iterate\n" - " when resolving a collision. `0' means ``iterate by\n" - " the number of keywords''.\n" + " is useful for certain highly redundant keyword sets.\n"); + fprintf (stream, + " -m, --multiple-iterations=ITERATIONS\n" + " Perform multiple choices of the -i and -j values,\n" + " and choose the best results. This increases the\n" + " running time by a factor of ITERATIONS but does a\n" + " good job minimizing the generated table size.\n"); + fprintf (stream, " -i, --initial-asso=N Provide an initial value for the associate values\n" " array. Default is 0. Setting this value larger helps\n" - " inflate the size of the final table.\n" - " -j, --jump=JUMP-VALUE Affects the ``jump value'', i.e., how far to advance\n" + " inflate the size of the final table.\n"); + fprintf (stream, + " -j, --jump=JUMP-VALUE Affects the \"jump value\", i.e., how far to advance\n" " the associated character value upon collisions. Must\n" - " be an odd number, default is %d.\n" + " be an odd number, default is %d.\n", + DEFAULT_JUMP_VALUE); + fprintf (stream, " -n, --no-strlen Do not include the length of the keyword when\n" - " computing the hash function.\n" - " -o, --occurrence-sort Reorders input keys by frequency of occurrence of\n" - " the key sets. This should decrease the search time\n" - " dramatically.\n" + " computing the hash function.\n"); + fprintf (stream, " -r, --random Utilizes randomness to initialize the associated\n" - " values table.\n" + " values table.\n"); + fprintf (stream, " -s, --size-multiple=N Affects the size of the generated hash table. The\n" - " numeric argument N indicates ``how many times larger\n" - " or smaller'' the associated value range should be,\n" + " numeric argument N indicates \"how many times larger\n" + " or smaller\" the associated value range should be,\n" " in relationship to the number of keys, e.g. a value\n" - " of 3 means ``allow the maximum associated value to\n" + " of 3 means \"allow the maximum associated value to\n" " be about 3 times larger than the number of input\n" - " keys.'' Conversely, a value of -3 means ``make the\n" + " keys\". Conversely, a value of 1/3 means \"make the\n" " maximum associated value about 3 times smaller than\n" - " the number of input keys. A larger table should\n" + " the number of input keys\". A larger table should\n" " decrease the time required for an unsuccessful\n" " search, at the expense of extra table space. Default\n" - " value is 1.\n" - "\n" + " value is 1.\n"); + fprintf (stream, "\n"); + fprintf (stream, "Informative output:\n" " -h, --help Print this message.\n" " -v, --version Print the gperf version number.\n" " -d, --debug Enables the debugging option (produces verbose\n" - " output to the standard error).\n" - "\n" - "Report bugs to .\n" - , program_name, MAX_KEY_POS - 1, DEFAULT_JUMP_VALUE); + " output to the standard error).\n"); + fprintf (stream, "\n"); + fprintf (stream, + "Report bugs to .\n"); } -/* Output command-line Options. */ +/* Prints the given options. */ void -Options::print_options (void) +Options::print_options () const { - T (Trace t ("Options::print_options");) - int i; - printf ("/* Command-line: "); - for (i = 0; i < argument_count; i++) + for (int i = 0; i < _argument_count; i++) { - const char *arg = argument_vector[i]; + const char *arg = _argument_vector[i]; - /* Escape arg if it contains shell metacharacters. */ + /* Escape arg if it contains shell metacharacters. */ if (*arg == '-') { putchar (*arg); arg++; - if ((*arg >= 'A' && *arg <= 'Z') || (*arg >= 'a' && *arg <= 'z')) + if (*arg >= 'A' && *arg <= 'Z' || *arg >= 'a' && *arg <= 'z') { putchar (*arg); arg++; } + else if (*arg == '-') + { + do + { + putchar (*arg); + arg++; + } + while (*arg >= 'A' && *arg <= 'Z' || *arg >= 'a' && *arg <= 'z' || *arg == '-'); + if (*arg == '=') + { + putchar (*arg); + arg++; + } + } } if (strpbrk (arg, "\t\n !\"#$&'()*;<>?[\\]`{|}~") != NULL) { @@ -250,7 +308,7 @@ Options::print_options (void) putchar ('"'); for (; *arg; arg++) { - if (*arg == '\"' || *arg == '\\' || *arg == '$') + if (*arg == '\"' || *arg == '\\' || *arg == '$' || *arg == '`') putchar ('\\'); putchar (*arg); } @@ -277,389 +335,653 @@ Options::print_options (void) printf (" */"); } -/* Sorts the key positions *IN REVERSE ORDER!!* - This makes further routines more efficient. Especially when generating code. - Uses a simple Insertion Sort since the set is probably ordered. - Returns 1 if there are no duplicates, 0 otherwise. */ +/* ------------------------------------------------------------------------- */ -inline int -Options::key_sort (char *base, int len) +/* Parses a string denoting key positions. */ + +class PositionStringParser { - T (Trace t ("Options::key_sort");) - int i, j; +public: + /* Initializes a key position string parser for string STR. */ + PositionStringParser (const char *str, + int low_bound, int high_bound, + int end_word_marker, int error_value, int end_marker); + /* Returns the next key position from the given string. */ + int nextPosition (); +private: + /* A pointer to the string provided by the user. */ + const char * _str; + /* Smallest possible value, inclusive. */ + int const _low_bound; + /* Greatest possible value, inclusive. */ + int const _high_bound; + /* A value marking the abstract "end of word" ( usually '$'). */ + int const _end_word_marker; + /* Error value returned when input is syntactically erroneous. */ + int const _error_value; + /* Value returned after last key is processed. */ + int const _end_marker; + /* Intermediate state for producing a range of positions. */ + bool _in_range; /* True while producing a range of positions. */ + int _range_upper_bound; /* Upper bound (inclusive) of the range. */ + int _range_curr_value; /* Last value returned. */ +}; - for (i = 0, j = len - 1; i < j; i++) +/* Initializes a key position strng parser for string STR. */ +PositionStringParser::PositionStringParser (const char *str, + int low_bound, int high_bound, + int end_word_marker, int error_value, int end_marker) + : _str (str), + _low_bound (low_bound), + _high_bound (high_bound), + _end_word_marker (end_word_marker), + _error_value (error_value), + _end_marker (end_marker), + _in_range (false) +{ +} + +/* Returns the next key position from the given string. */ +int +PositionStringParser::nextPosition () +{ + if (_in_range) { - int curr, tmp; - - for (curr = i + 1,tmp = base[curr]; curr > 0 && tmp >= base[curr - 1]; curr--) - if ((base[curr] = base[curr - 1]) == tmp) /* oh no, a duplicate!!! */ - return 0; - - base[curr] = tmp; + /* We are inside a range. Return the next value from the range. */ + if (++_range_curr_value >= _range_upper_bound) + _in_range = false; + return _range_curr_value; } - - return 1; -} - -/* Sets the default Options. */ - -Options::Options (void) -{ - T (Trace t ("Options::Options");) - key_positions[0] = WORD_START; - key_positions[1] = WORD_END; - key_positions[2] = EOS; - total_keysig_size = 2; - delimiters = DEFAULT_DELIMITERS; - jump = DEFAULT_JUMP_VALUE; - option_word = DEFAULTCHARS | C; - function_name = DEFAULT_NAME; - key_name = DEFAULT_KEY; - initializer_suffix = DEFAULT_INITIALIZER_SUFFIX; - hash_name = DEFAULT_HASH_NAME; - wordlist_name = DEFAULT_WORDLIST_NAME; - class_name = DEFAULT_CLASS_NAME; - total_switches = size = 1; - initial_asso_value = iterations = 0; -} - -/* Dumps option status when debug is set. */ - -Options::~Options (void) -{ - T (Trace t ("Options::~Options");) - if (option_word & DEBUG) + else { - char *ptr; + /* Continue parsing the given string. */ + while (*_str) + switch (*_str) + { + case ',': + /* Skip the comma. */ + _str++; + break; + case '$': + /* Valid key position. */ + _str++; + return _end_word_marker; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* Valid key position. */ + { + int curr_value; + for (curr_value = 0; isdigit (static_cast(*_str)); _str++) + curr_value = curr_value * 10 + (*_str - '0'); + if (*_str == '-') + { + _str++; + /* Starting a range of key positions. */ + _in_range = true; + + for (_range_upper_bound = 0; + isdigit (static_cast(*_str)); + _str++) + _range_upper_bound = _range_upper_bound * 10 + (*_str - '0'); + + /* Verify range's upper bound. */ + if (!(_range_upper_bound > curr_value && _range_upper_bound <= _high_bound)) + return _error_value; + _range_curr_value = curr_value; + } + + /* Verify range's lower bound. */ + if (!(curr_value >= _low_bound && curr_value <= _high_bound)) + return _error_value; + return curr_value; + } + default: + /* Invalid syntax. */ + return _error_value; + } + + return _end_marker; + } +} + +/* ------------------------------------------------------------------------- */ + +/* Sets the default Options. */ + +Options::Options () + : _option_word (C), + _input_file_name (NULL), + _output_file_name (NULL), + _language (NULL), + _jump (DEFAULT_JUMP_VALUE), + _initial_asso_value (0), + _asso_iterations (0), + _total_switches (1), + _size_multiple (1), + _function_name (DEFAULT_FUNCTION_NAME), + _slot_name (DEFAULT_SLOT_NAME), + _initializer_suffix (DEFAULT_INITIALIZER_SUFFIX), + _class_name (DEFAULT_CLASS_NAME), + _hash_name (DEFAULT_HASH_NAME), + _wordlist_name (DEFAULT_WORDLIST_NAME), + _lengthtable_name (DEFAULT_LENGTHTABLE_NAME), + _stringpool_name (DEFAULT_STRINGPOOL_NAME), + _delimiters (DEFAULT_DELIMITERS), + _key_positions () +{ +} + +/* Dumps option status when debugging is enabled. */ + +Options::~Options () +{ + if (_option_word & DEBUG) + { fprintf (stderr, "\ndumping Options:" - "\nDEBUG is.......: %s" - "\nORDER is.......: %s" "\nTYPE is........: %s" - "\nRANDOM is......: %s" - "\nDEFAULTCHARS is: %s" - "\nSWITCH is......: %s" - "\nNOLENGTH is....: %s" - "\nLENTABLE is....: %s" - "\nDUP is.........: %s" - "\nFAST is........: %s" - "\nCOMP is........: %s" - "\nNOTYPE is......: %s" - "\nGLOBAL is......: %s" - "\nCONST is.......: %s" + "\nUPPERLOWER is..: %s" "\nKRC is.........: %s" "\nC is...........: %s" "\nANSIC is.......: %s" "\nCPLUSPLUS is...: %s" + "\nSEVENBIT is....: %s" + "\nLENTABLE is....: %s" + "\nCOMP is........: %s" + "\nCONST is.......: %s" "\nENUM is........: %s" "\nINCLUDE is.....: %s" - "\nSEVENBIT is....: %s" - "\niterations = %d" + "\nGLOBAL is......: %s" + "\nNULLSTRINGS is.: %s" + "\nSHAREDLIB is...: %s" + "\nSWITCH is......: %s" + "\nNOTYPE is......: %s" + "\nDUP is.........: %s" + "\nNOLENGTH is....: %s" + "\nRANDOM is......: %s" + "\nDEBUG is.......: %s" "\nlookup function name = %s" "\nhash function name = %s" "\nword list name = %s" - "\nkey name = %s" + "\nlength table name = %s" + "\nstring pool name = %s" + "\nslot name = %s" "\ninitializer suffix = %s" + "\nasso_values iterations = %d" "\njump value = %d" - "\nmax associated value = %d" + "\nhash table size multiplier = %g" "\ninitial associated value = %d" "\ndelimiters = %s" "\nnumber of switch statements = %d\n", - option_word & DEBUG ? "enabled" : "disabled", - option_word & ORDER ? "enabled" : "disabled", - option_word & TYPE ? "enabled" : "disabled", - option_word & RANDOM ? "enabled" : "disabled", - option_word & DEFAULTCHARS ? "enabled" : "disabled", - option_word & SWITCH ? "enabled" : "disabled", - option_word & NOLENGTH ? "enabled" : "disabled", - option_word & LENTABLE ? "enabled" : "disabled", - option_word & DUP ? "enabled" : "disabled", - option_word & FAST ? "enabled" : "disabled", - option_word & COMP ? "enabled" : "disabled", - option_word & NOTYPE ? "enabled" : "disabled", - option_word & GLOBAL ? "enabled" : "disabled", - option_word & CONST ? "enabled" : "disabled", - option_word & KRC ? "enabled" : "disabled", - option_word & C ? "enabled" : "disabled", - option_word & ANSIC ? "enabled" : "disabled", - option_word & CPLUSPLUS ? "enabled" : "disabled", - option_word & ENUM ? "enabled" : "disabled", - option_word & INCLUDE ? "enabled" : "disabled", - option_word & SEVENBIT ? "enabled" : "disabled", - iterations, - function_name, hash_name, wordlist_name, key_name, - initializer_suffix, jump, size - 1, initial_asso_value, - delimiters, total_switches); - if (option_word & ALLCHARS) + _option_word & TYPE ? "enabled" : "disabled", + _option_word & UPPERLOWER ? "enabled" : "disabled", + _option_word & KRC ? "enabled" : "disabled", + _option_word & C ? "enabled" : "disabled", + _option_word & ANSIC ? "enabled" : "disabled", + _option_word & CPLUSPLUS ? "enabled" : "disabled", + _option_word & SEVENBIT ? "enabled" : "disabled", + _option_word & LENTABLE ? "enabled" : "disabled", + _option_word & COMP ? "enabled" : "disabled", + _option_word & CONST ? "enabled" : "disabled", + _option_word & ENUM ? "enabled" : "disabled", + _option_word & INCLUDE ? "enabled" : "disabled", + _option_word & GLOBAL ? "enabled" : "disabled", + _option_word & NULLSTRINGS ? "enabled" : "disabled", + _option_word & SHAREDLIB ? "enabled" : "disabled", + _option_word & SWITCH ? "enabled" : "disabled", + _option_word & NOTYPE ? "enabled" : "disabled", + _option_word & DUP ? "enabled" : "disabled", + _option_word & NOLENGTH ? "enabled" : "disabled", + _option_word & RANDOM ? "enabled" : "disabled", + _option_word & DEBUG ? "enabled" : "disabled", + _function_name, _hash_name, _wordlist_name, _lengthtable_name, + _stringpool_name, _slot_name, _initializer_suffix, + _asso_iterations, _jump, _size_multiple, _initial_asso_value, + _delimiters, _total_switches); + if (_key_positions.is_useall()) fprintf (stderr, "all characters are used in the hash function\n"); + else + { + fprintf (stderr, "maximum keysig size = %d\nkey positions are: \n", + _key_positions.get_size()); - fprintf (stderr, "maximum keysig size = %d\nkey positions are: \n", - total_keysig_size); - - for (ptr = key_positions; *ptr != EOS; ptr++) - if (*ptr == WORD_END) - fprintf (stderr, "$\n"); - else - fprintf (stderr, "%d\n", *ptr); + PositionIterator iter = _key_positions.iterator(); + for (int pos; (pos = iter.next()) != PositionIterator::EOS; ) + if (pos == Positions::LASTCHAR) + fprintf (stderr, "$\n"); + else + fprintf (stderr, "%d\n", pos + 1); + } fprintf (stderr, "finished dumping Options\n"); } } -/* Parses the command line Options and sets appropriate flags in option_word. */ +/* Sets the output language, if not already set. */ +void +Options::set_language (const char *language) +{ + if (_language == NULL) + { + _language = language; + _option_word &= ~(KRC | C | ANSIC | CPLUSPLUS); + if (!strcmp (language, "KR-C")) + _option_word |= KRC; + else if (!strcmp (language, "C")) + _option_word |= C; + else if (!strcmp (language, "ANSI-C")) + _option_word |= ANSIC; + else if (!strcmp (language, "C++")) + _option_word |= CPLUSPLUS; + else + { + fprintf (stderr, "unsupported language option %s, defaulting to C\n", + language); + _option_word |= C; + } + } +} + +/* Sets the total number of switch statements, if not already set. */ +void +Options::set_total_switches (int total_switches) +{ + if (!(_option_word & SWITCH)) + { + _option_word |= SWITCH; + _total_switches = total_switches; + } +} + +/* Sets the generated function name, if not already set. */ +void +Options::set_function_name (const char *name) +{ + if (_function_name == DEFAULT_FUNCTION_NAME) + _function_name = name; +} + +/* Sets the keyword key name, if not already set. */ +void +Options::set_slot_name (const char *name) +{ + if (_slot_name == DEFAULT_SLOT_NAME) + _slot_name = name; +} + +/* Sets the struct initializer suffix, if not already set. */ +void +Options::set_initializer_suffix (const char *initializers) +{ + if (_initializer_suffix == DEFAULT_INITIALIZER_SUFFIX) + _initializer_suffix = initializers; +} + +/* Sets the generated class name, if not already set. */ +void +Options::set_class_name (const char *name) +{ + if (_class_name == DEFAULT_CLASS_NAME) + _class_name = name; +} + +/* Sets the hash function name, if not already set. */ +void +Options::set_hash_name (const char *name) +{ + if (_hash_name == DEFAULT_HASH_NAME) + _hash_name = name; +} + +/* Sets the hash table array name, if not already set. */ +void +Options::set_wordlist_name (const char *name) +{ + if (_wordlist_name == DEFAULT_WORDLIST_NAME) + _wordlist_name = name; +} + +/* Sets the length table array name, if not already set. */ +void +Options::set_lengthtable_name (const char *name) +{ + if (_lengthtable_name == DEFAULT_LENGTHTABLE_NAME) + _lengthtable_name = name; +} + +/* Sets the string pool name, if not already set. */ +void +Options::set_stringpool_name (const char *name) +{ + if (_stringpool_name == DEFAULT_STRINGPOOL_NAME) + _stringpool_name = name; +} + +/* Sets the delimiters string, if not already set. */ +void +Options::set_delimiters (const char *delimiters) +{ + if (_delimiters == DEFAULT_DELIMITERS) + _delimiters = delimiters; +} + + +/* Parses the command line Options and sets appropriate flags in option_word. */ static const struct option long_options[] = { - { "delimiters", required_argument, 0, 'e' }, - { "struct-type", no_argument, 0, 't' }, - { "language", required_argument, 0, 'L' }, - { "slot-name", required_argument, 0, 'K' }, - { "initializer-suffix", required_argument, 0, 'F' }, - { "hash-fn-name", required_argument, 0, 'H' }, - { "lookup-fn-name", required_argument, 0, 'N' }, - { "class-name", required_argument, 0, 'Z' }, - { "seven-bit", no_argument, 0, '7' }, - { "compare-strncmp", no_argument, 0, 'c' }, - { "readonly-tables", no_argument, 0, 'C' }, - { "enum", no_argument, 0, 'E' }, - { "includes", no_argument, 0, 'I' }, - { "global", no_argument, 0, 'G' }, - { "word-array-name", required_argument, 0, 'W' }, - { "switch", required_argument, 0, 'S' }, - { "omit-struct-type", no_argument, 0, 'T' }, - { "key-positions", required_argument, 0, 'k' }, - { "compare-strlen", no_argument, 0, 'l' }, - { "duplicates", no_argument, 0, 'D' }, - { "fast", required_argument, 0, 'f' }, - { "initial-asso", required_argument, 0, 'i' }, - { "jump", required_argument, 0, 'j' }, - { "no-strlen", no_argument, 0, 'n' }, - { "occurrence-sort", no_argument, 0, 'o' }, - { "random", no_argument, 0, 'r' }, - { "size-multiple", required_argument, 0, 's' }, - { "help", no_argument, 0, 'h' }, - { "version", no_argument, 0, 'v' }, - { "debug", no_argument, 0, 'd' }, - { 0, no_argument, 0, 0 } + { "output-file", required_argument, NULL, CHAR_MAX + 1 }, + { "ignore-case", no_argument, NULL, CHAR_MAX + 2 }, + { "delimiters", required_argument, NULL, 'e' }, + { "struct-type", no_argument, NULL, 't' }, + { "language", required_argument, NULL, 'L' }, + { "slot-name", required_argument, NULL, 'K' }, + { "initializer-suffix", required_argument, NULL, 'F' }, + { "hash-fn-name", required_argument, NULL, 'H' }, /* backward compatibility */ + { "hash-function-name", required_argument, NULL, 'H' }, + { "lookup-fn-name", required_argument, NULL, 'N' }, /* backward compatibility */ + { "lookup-function-name", required_argument, NULL, 'N' }, + { "class-name", required_argument, NULL, 'Z' }, + { "seven-bit", no_argument, NULL, '7' }, + { "compare-strncmp", no_argument, NULL, 'c' }, + { "readonly-tables", no_argument, NULL, 'C' }, + { "enum", no_argument, NULL, 'E' }, + { "includes", no_argument, NULL, 'I' }, + { "global-table", no_argument, NULL, 'G' }, + { "word-array-name", required_argument, NULL, 'W' }, + { "length-table-name", required_argument, NULL, CHAR_MAX + 4 }, + { "switch", required_argument, NULL, 'S' }, + { "omit-struct-type", no_argument, NULL, 'T' }, + { "key-positions", required_argument, NULL, 'k' }, + { "compare-strlen", no_argument, NULL, 'l' }, /* backward compatibility */ + { "compare-lengths", no_argument, NULL, 'l' }, + { "duplicates", no_argument, NULL, 'D' }, + { "fast", required_argument, NULL, 'f' }, + { "initial-asso", required_argument, NULL, 'i' }, + { "jump", required_argument, NULL, 'j' }, + { "multiple-iterations", required_argument, NULL, 'm' }, + { "no-strlen", no_argument, NULL, 'n' }, + { "occurrence-sort", no_argument, NULL, 'o' }, + { "optimized-collision-resolution", no_argument, NULL, 'O' }, + { "pic", no_argument, NULL, 'P' }, + { "string-pool-name", required_argument, NULL, 'Q' }, + { "null-strings", no_argument, NULL, CHAR_MAX + 3 }, + { "random", no_argument, NULL, 'r' }, + { "size-multiple", required_argument, NULL, 's' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, + { "debug", no_argument, NULL, 'd' }, + { NULL, no_argument, NULL, 0 } }; void -Options::operator() (int argc, char *argv[]) +Options::parse_options (int argc, char *argv[]) { - T (Trace t ("Options::operator()");) - int option_char; + int option_char; program_name = argv[0]; - argument_count = argc; - argument_vector = argv; + _argument_count = argc; + _argument_vector = argv; while ((option_char = - getopt_long (argument_count, argument_vector, - "adcCDe:Ef:F:gGhH:i:Ij:k:K:lL:nN:oprs:S:tTvW:Z:7", - long_options, (int *)0)) + getopt_long (_argument_count, _argument_vector, + "acCdDe:Ef:F:gGhH:i:Ij:k:K:lL:m:nN:oOpPQ:rs:S:tTvW:Z:7", + long_options, NULL)) != -1) { switch (option_char) { - case 'a': /* Generated code uses the ANSI prototype format. */ - break; /* This is now the default. */ - case 'c': /* Generate strncmp rather than strcmp. */ + case 'a': /* Generated code uses the ANSI prototype format. */ + break; /* This is now the default. */ + case 'c': /* Generate strncmp rather than strcmp. */ { - option_word |= COMP; + _option_word |= COMP; break; } - case 'C': /* Make the generated tables readonly (const). */ + case 'C': /* Make the generated tables readonly (const). */ { - option_word |= CONST; + _option_word |= CONST; break; } - case 'd': /* Enable debugging option. */ + case 'd': /* Enable debugging option. */ { - option_word |= DEBUG; + _option_word |= DEBUG; fprintf (stderr, "Starting program %s, version %s, with debugging on.\n", program_name, version_string); break; } - case 'D': /* Enable duplicate option. */ + case 'D': /* Enable duplicate option. */ { - option_word |= DUP; + _option_word |= DUP; break; } - case 'e': /* Allows user to provide keyword/attribute separator */ + case 'e': /* Specify keyword/attribute separator */ { - option.delimiters = /*getopt*/optarg; + _delimiters = /*getopt*/optarg; break; } case 'E': { - option_word |= ENUM; - break; - } - case 'f': /* Generate the hash table ``fast.'' */ - { - option_word |= FAST; - if ((iterations = atoi (/*getopt*/optarg)) < 0) - { - fprintf (stderr, "iterations value must not be negative, assuming 0\n"); - iterations = 0; - } + _option_word |= ENUM; break; } + case 'f': /* Generate the hash table "fast". */ + break; /* Not needed any more. */ case 'F': { - initializer_suffix = /*getopt*/optarg; + _initializer_suffix = /*getopt*/optarg; break; } - case 'g': /* Use the ``inline'' keyword for generated sub-routines, ifdef __GNUC__. */ - break; /* This is now the default. */ - case 'G': /* Make the keyword table a global variable. */ + case 'g': /* Use the 'inline' keyword for generated sub-routines, ifdef __GNUC__. */ + break; /* This is now the default. */ + case 'G': /* Make the keyword table a global variable. */ { - option_word |= GLOBAL; + _option_word |= GLOBAL; break; } - case 'h': /* Displays a list of helpful Options to the user. */ + case 'h': /* Displays a list of helpful Options to the user. */ { long_usage (stdout); exit (0); } - case 'H': /* Sets the name for the hash function */ + case 'H': /* Sets the name for the hash function. */ { - hash_name = /*getopt*/optarg; + _hash_name = /*getopt*/optarg; break; } - case 'i': /* Sets the initial value for the associated values array. */ + case 'i': /* Sets the initial value for the associated values array. */ { - if ((initial_asso_value = atoi (/*getopt*/optarg)) < 0) - fprintf (stderr, "Initial value %d should be non-zero, ignoring and continuing.\n", initial_asso_value); + if ((_initial_asso_value = atoi (/*getopt*/optarg)) < 0) + fprintf (stderr, "Initial value %d should be non-zero, ignoring and continuing.\n", _initial_asso_value); if (option[RANDOM]) fprintf (stderr, "warning, -r option superceeds -i, ignoring -i option and continuing\n"); break; } - case 'I': /* Enable #include statements. */ + case 'I': /* Enable #include statements. */ { - option_word |= INCLUDE; + _option_word |= INCLUDE; break; } - case 'j': /* Sets the jump value, must be odd for later algorithms. */ + case 'j': /* Sets the jump value, must be odd for later algorithms. */ { - if ((jump = atoi (/*getopt*/optarg)) < 0) + if ((_jump = atoi (/*getopt*/optarg)) < 0) { - fprintf (stderr, "Jump value %d must be a positive number.\n", jump); + fprintf (stderr, "Jump value %d must be a positive number.\n", _jump); short_usage (stderr); exit (1); } - else if (jump && ((jump % 2) == 0)) - fprintf (stderr, "Jump value %d should be odd, adding 1 and continuing...\n", jump++); + else if (_jump && ((_jump % 2) == 0)) + fprintf (stderr, "Jump value %d should be odd, adding 1 and continuing...\n", _jump++); break; } - case 'k': /* Sets key positions used for hash function. */ + case 'k': /* Sets key positions used for hash function. */ { - const int BAD_VALUE = -1; + _option_word |= POSITIONS; + const int BAD_VALUE = -3; + const int EOS = PositionIterator::EOS; int value; - Iterator expand (/*getopt*/optarg, 1, MAX_KEY_POS - 1, WORD_END, BAD_VALUE, EOS); + PositionStringParser sparser (/*getopt*/optarg, 1, Positions::MAX_KEY_POS, Positions::LASTCHAR, BAD_VALUE, EOS); if (/*getopt*/optarg [0] == '*') /* Use all the characters for hashing!!!! */ - option_word = (option_word & ~DEFAULTCHARS) | ALLCHARS; + _key_positions.set_useall(true); else { - char *key_pos; + _key_positions.set_useall(false); + int *key_positions = _key_positions.pointer(); + int *key_pos; - for (key_pos = key_positions; (value = expand ()) != EOS; key_pos++) - if (value == BAD_VALUE) - { - fprintf (stderr, "Illegal key value or range, use 1,2,3-%d,'$' or '*'.\n", - MAX_KEY_POS - 1); - short_usage (stderr); - exit (1); - } - else - *key_pos = value;; - - *key_pos = EOS; - - if (! (total_keysig_size = (key_pos - key_positions))) + for (key_pos = key_positions; (value = sparser.nextPosition()) != EOS; key_pos++) { - fprintf (stderr, "No keys selected.\n"); + if (value == BAD_VALUE) + { + fprintf (stderr, "Invalid position value or range, use 1,2,3-%d,'$' or '*'.\n", + Positions::MAX_KEY_POS); + short_usage (stderr); + exit (1); + } + if (key_pos - key_positions == Positions::MAX_SIZE) + { + /* More than Positions::MAX_SIZE key positions. + Since all key positions are in the range + 0..Positions::MAX_KEY_POS-1 or == Positions::LASTCHAR, + there must be duplicates. */ + fprintf (stderr, "Duplicate key positions selected\n"); + short_usage (stderr); + exit (1); + } + if (value != Positions::LASTCHAR) + /* We use 0-based indices in the class Positions. */ + value = value - 1; + *key_pos = value; + } + + unsigned int total_keysig_size = key_pos - key_positions; + if (total_keysig_size == 0) + { + fprintf (stderr, "No key positions selected.\n"); short_usage (stderr); exit (1); } - else if (! key_sort (key_positions, total_keysig_size)) + _key_positions.set_size (total_keysig_size); + + /* Sorts the key positions *IN REVERSE ORDER!!* + This makes further routines more efficient. Especially + when generating code. */ + if (! _key_positions.sort()) { - fprintf (stderr, "Duplicate keys selected\n"); + fprintf (stderr, "Duplicate key positions selected\n"); short_usage (stderr); exit (1); } - - if (total_keysig_size != 2 - || (key_positions[0] != 1 || key_positions[1] != WORD_END)) - option_word &= ~DEFAULTCHARS; } break; } - case 'K': /* Make this the keyname for the keyword component field. */ + case 'K': /* Make this the keyname for the keyword component field. */ { - key_name = /*getopt*/optarg; + _slot_name = /*getopt*/optarg; break; } - case 'l': /* Create length table to avoid extra string compares. */ + case 'l': /* Create length table to avoid extra string compares. */ { - option_word |= LENTABLE; + _option_word |= LENTABLE; break; } - case 'L': /* Deal with different generated languages. */ + case 'L': /* Deal with different generated languages. */ { - option_word &= ~(KRC | C | ANSIC | CPLUSPLUS); - if (!strcmp (/*getopt*/optarg, "KR-C")) - option_word |= KRC; - else if (!strcmp (/*getopt*/optarg, "C")) - option_word |= C; - else if (!strcmp (/*getopt*/optarg, "ANSI-C")) - option_word |= ANSIC; - else if (!strcmp (/*getopt*/optarg, "C++")) - option_word |= CPLUSPLUS; - else + _language = NULL; + set_language (/*getopt*/optarg); + break; + } + case 'm': /* Multiple iterations for finding good asso_values. */ + { + if ((_asso_iterations = atoi (/*getopt*/optarg)) < 0) { - fprintf (stderr, "unsupported language option %s, defaulting to C\n", /*getopt*/optarg); - option_word |= C; + fprintf (stderr, "asso_iterations value must not be negative, assuming 0\n"); + _asso_iterations = 0; } break; } - case 'n': /* Don't include the length when computing hash function. */ + case 'n': /* Don't include the length when computing hash function. */ { - option_word |= NOLENGTH; + _option_word |= NOLENGTH; break; } - case 'N': /* Make generated lookup function name be optarg */ + case 'N': /* Make generated lookup function name be optarg. */ { - function_name = /*getopt*/optarg; + _function_name = /*getopt*/optarg; break; } - case 'o': /* Order input by frequency of key set occurrence. */ + case 'o': /* Order input by frequency of key set occurrence. */ + break; /* Not needed any more. */ + case 'O': /* Optimized choice during collision resolution. */ + break; /* Not needed any more. */ + case 'p': /* Generated lookup function a pointer instead of int. */ + break; /* This is now the default. */ + case 'P': /* Optimize for position-independent code. */ { - option_word |= ORDER; + _option_word |= SHAREDLIB; break; } - case 'p': /* Generated lookup function a pointer instead of int. */ - break; /* This is now the default. */ - case 'r': /* Utilize randomness to initialize the associated values table. */ + case 'Q': /* Sets the name for the string pool. */ { - option_word |= RANDOM; - if (option.initial_asso_value != 0) - fprintf (stderr, "warning, -r option superceeds -i, disabling -i option and continuing\n"); + _stringpool_name = /*getopt*/optarg; break; } - case 's': /* Range of associated values, determines size of final table. */ + case 'r': /* Utilize randomness to initialize the associated values table. */ { - if (abs (size = atoi (/*getopt*/optarg)) > 50) - fprintf (stderr, "%d is excessive, did you really mean this?! (try `%s --help' for help)\n", size, program_name); + _option_word |= RANDOM; + if (_initial_asso_value != 0) + fprintf (stderr, "warning, -r option supersedes -i, disabling -i option and continuing\n"); break; } - case 'S': /* Generate switch statement output, rather than lookup table. */ + case 's': /* Range of associated values, determines size of final table. */ { - option_word |= SWITCH; - if ((option.total_switches = atoi (/*getopt*/optarg)) <= 0) + float numerator; + float denominator = 1; + bool invalid = false; + char *endptr; + + numerator = strtod (/*getopt*/optarg, &endptr); + if (endptr == /*getopt*/optarg) + invalid = true; + else if (*endptr != '\0') + { + if (*endptr == '/') + { + char *denomptr = endptr + 1; + denominator = strtod (denomptr, &endptr); + if (endptr == denomptr || *endptr != '\0') + invalid = true; + } + else + invalid = true; + } + if (invalid) + { + fprintf (stderr, "Invalid value for option -s.\n"); + short_usage (stderr); + exit (1); + } + _size_multiple = numerator / denominator; + /* Backward compatibility: -3 means 1/3. */ + if (_size_multiple < 0) + _size_multiple = 1 / (-_size_multiple); + /* Catch stupid users. */ + if (_size_multiple == 0) + _size_multiple = 1; + /* Warnings. */ + if (_size_multiple > 50) + fprintf (stderr, "Size multiple %g is excessive, did you really mean this?! (try '%s --help' for help)\n", _size_multiple, program_name); + else if (_size_multiple < 0.01f) + fprintf (stderr, "Size multiple %g is extremely small, did you really mean this?! (try '%s --help' for help)\n", _size_multiple, program_name); + break; + } + case 'S': /* Generate switch statement output, rather than lookup table. */ + { + _option_word |= SWITCH; + _total_switches = atoi (/*getopt*/optarg); + if (_total_switches <= 0) { fprintf (stderr, "number of switches %s must be a positive number\n", /*getopt*/optarg); short_usage (stderr); @@ -667,33 +989,59 @@ Options::operator() (int argc, char *argv[]) } break; } - case 't': /* Enable the TYPE mode, allowing arbitrary user structures. */ + case 't': /* Enable the TYPE mode, allowing arbitrary user structures. */ { - option_word |= TYPE; + _option_word |= TYPE; break; } - case 'T': /* Don't print structure definition. */ + case 'T': /* Don't print structure definition. */ { - option_word |= NOTYPE; + _option_word |= NOTYPE; break; } - case 'v': /* Print out the version and quit. */ + case 'v': /* Print out the version and quit. */ fprintf (stdout, "GNU gperf %s\n", version_string); + fprintf (stdout, "Copyright (C) %s Free Software Foundation, Inc.\n\ +This is free software; see the source for copying conditions. There is NO\n\ +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ +", + "1989-1998, 2000-2004, 2006-2007"); + fprintf (stdout, "Written by %s and %s.\n", + "Douglas C. Schmidt", "Bruno Haible"); exit (0); - case 'W': /* Sets the name for the hash table array */ + case 'W': /* Sets the name for the hash table array. */ { - wordlist_name = /*getopt*/optarg; + _wordlist_name = /*getopt*/optarg; break; } - case 'Z': /* Set the class name. */ + case 'Z': /* Set the class name. */ { - class_name = /*getopt*/optarg; + _class_name = /*getopt*/optarg; break; } - case '7': /* Assume 7-bit characters. */ + case '7': /* Assume 7-bit characters. */ { - option_word |= SEVENBIT; - Vectors::ALPHA_SIZE = 128; + _option_word |= SEVENBIT; + break; + } + case CHAR_MAX + 1: /* Set the output file name. */ + { + _output_file_name = /*getopt*/optarg; + break; + } + case CHAR_MAX + 2: /* Case insignificant. */ + { + _option_word |= UPPERLOWER; + break; + } + case CHAR_MAX + 3: /* Use NULL instead of "". */ + { + _option_word |= NULLSTRINGS; + break; + } + case CHAR_MAX + 4: /* Sets the name for the length table array. */ + { + _lengthtable_name = /*getopt*/optarg; break; } default: @@ -703,14 +1051,10 @@ Options::operator() (int argc, char *argv[]) } - if (argv[/*getopt*/optind] && ! freopen (argv[/*getopt*/optind], "r", stdin)) - { - fprintf (stderr, "Cannot open keyword file `%s'\n", argv[/*getopt*/optind]); - short_usage (stderr); - exit (1); - } + if (/*getopt*/optind < argc) + _input_file_name = argv[/*getopt*/optind++]; - if (++/*getopt*/optind < argc) + if (/*getopt*/optind < argc) { fprintf (stderr, "Extra trailing arguments to %s.\n", program_name); short_usage (stderr); @@ -718,6 +1062,8 @@ Options::operator() (int argc, char *argv[]) } } +/* ------------------------------------------------------------------------- */ + #ifndef __OPTIMIZE__ #define INLINE /* not inline */ diff --git a/contrib/gperf/src/options.h b/contrib/gperf/src/options.h index 9025c86f1732..bda7f0c8939c 100644 --- a/contrib/gperf/src/options.h +++ b/contrib/gperf/src/options.h @@ -2,154 +2,292 @@ /* Handles parsing the Options provided to the user. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) + Copyright (C) 1989-1998, 2000, 2002-2004 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* This module provides a uniform interface to the various options available - to a user of the gperf hash function generator. In addition to the - run-time options, found in the Option_Type below, there is also the - hash table Size and the Keys to be used in the hashing. - The overall design of this module was an experiment in using C++ - classes as a mechanism to enhance centralization of option and - and error handling, which tend to get out of hand in a C program. */ + to a user of the gperf hash function generator. */ #ifndef options_h #define options_h 1 #include +#include "positions.h" -/* Enumerate the potential debugging Options. */ +/* Enumeration of the possible boolean options. */ enum Option_Type { - DEBUG = 01, /* Enable debugging (prints diagnostics to stderr). */ - ORDER = 02, /* Apply ordering heuristic to speed-up search time. */ - ALLCHARS = 04, /* Use all characters in hash function. */ - TYPE = 010, /* Handle user-defined type structured keyword input. */ - RANDOM = 020, /* Randomly initialize the associated values table. */ - DEFAULTCHARS = 040, /* Make default char positions be 1,$ (end of keyword). */ - SWITCH = 0100, /* Generate switch output to save space. */ - NOLENGTH = 0200, /* Don't include keyword length in hash computations. */ - LENTABLE = 0400, /* Generate a length table for string comparison. */ - DUP = 01000, /* Handle duplicate hash values for keywords. */ - FAST = 02000, /* Generate the hash function ``fast.'' */ - NOTYPE = 04000, /* Don't include user-defined type definition in output -- it's already defined elsewhere. */ - COMP = 010000, /* Generate strncmp rather than strcmp. */ - GLOBAL = 020000, /* Make the keyword table a global variable. */ - CONST = 040000, /* Make the generated tables readonly (const). */ - KRC = 0100000, /* Generate K&R C code: no prototypes, no const. */ - C = 0200000, /* Generate C code: no prototypes, but const (user can #define it away). */ - ANSIC = 0400000, /* Generate ISO/ANSI C code: prototypes and const, but no class. */ - CPLUSPLUS = 01000000, /* Generate C++ code: prototypes, const, class, inline, enum. */ - ENUM = 02000000, /* Use enum for constants. */ - INCLUDE = 04000000, /* Generate #include statements. */ - SEVENBIT = 010000000 /* Assume 7-bit, not 8-bit, characters. */ + /* --- Input file interpretation --- */ + + /* Handle user-defined type structured keyword input. */ + TYPE = 1 << 0, + + /* Ignore case of ASCII characters. */ + UPPERLOWER = 1 << 1, + + /* --- Language for the output code --- */ + + /* Generate K&R C code: no prototypes, no const. */ + KRC = 1 << 2, + + /* Generate C code: no prototypes, but const (user can #define it away). */ + C = 1 << 3, + + /* Generate ISO/ANSI C code: prototypes and const, but no class. */ + ANSIC = 1 << 4, + + /* Generate C++ code: prototypes, const, class, inline, enum. */ + CPLUSPLUS = 1 << 5, + + /* --- Details in the output code --- */ + + /* Assume 7-bit, not 8-bit, characters. */ + SEVENBIT = 1 << 6, + + /* Generate a length table for string comparison. */ + LENTABLE = 1 << 7, + + /* Generate strncmp rather than strcmp. */ + COMP = 1 << 8, + + /* Make the generated tables readonly (const). */ + CONST = 1 << 9, + + /* Use enum for constants. */ + ENUM = 1 << 10, + + /* Generate #include statements. */ + INCLUDE = 1 << 11, + + /* Make the keyword table a global variable. */ + GLOBAL = 1 << 12, + + /* Use NULL strings instead of empty strings for empty table entries. */ + NULLSTRINGS = 1 << 13, + + /* Optimize for position-independent code. */ + SHAREDLIB = 1 << 14, + + /* Generate switch output to save space. */ + SWITCH = 1 << 15, + + /* Don't include user-defined type definition in output -- it's already + defined elsewhere. */ + NOTYPE = 1 << 16, + + /* --- Algorithm employed by gperf --- */ + + /* Use the given key positions. */ + POSITIONS = 1 << 17, + + /* Handle duplicate hash values for keywords. */ + DUP = 1 << 18, + + /* Don't include keyword length in hash computations. */ + NOLENGTH = 1 << 19, + + /* Randomly initialize the associated values table. */ + RANDOM = 1 << 20, + + /* --- Informative output --- */ + + /* Enable debugging (prints diagnostics to stderr). */ + DEBUG = 1 << 21 }; -/* Define some useful constants (these don't really belong here, but I'm - not sure where else to put them!). These should be consts, but g++ - doesn't seem to do the right thing with them at the moment... ;-( */ - -enum -{ - MAX_KEY_POS = 128 - 1, /* Max size of each word's key set. */ - WORD_START = 1, /* Signals the start of a word. */ - WORD_END = 0, /* Signals the end of a word. */ - EOS = MAX_KEY_POS /* Signals end of the key list. */ -}; - -/* Class manager for gperf program Options. */ +/* Class manager for gperf program Options. */ class Options { public: - Options (void); - ~Options (void); - int operator[] (Option_Type option); - void operator() (int argc, char *argv[]); - void operator= (enum Option_Type); - void operator!= (enum Option_Type); - static void print_options (void); - static void set_asso_max (int r); - static int get_asso_max (void); - static void reset (void); - static int get (void); - static int get_iterations (void); - static int get_max_keysig_size (void); - static void set_keysig_size (int); - static int get_jump (void); - static int initial_value (void); - static int get_total_switches (void); - static const char *get_function_name (void); - static const char *get_key_name (void); - static const char *get_initializer_suffix (void); - static const char *get_class_name (void); - static const char *get_hash_name (void); - static const char *get_wordlist_name (void); - static const char *get_delimiter (void); + /* Constructor. */ + Options (); + + /* Destructor. */ + ~Options (); + + /* Parses the options given in the command-line arguments. */ + void parse_options (int argc, char *argv[]); + + /* Prints the given options. */ + void print_options () const; + + /* Accessors. */ + + /* Tests a given boolean option. Returns true if set, false otherwise. */ + bool operator[] (Option_Type option) const; + /* Sets a given boolean option. */ + void set (Option_Type option); + + /* Returns the input file name. */ + const char * get_input_file_name () const; + + /* Returns the output file name. */ + const char * get_output_file_name () const; + + /* Sets the output language, if not already set. */ + void set_language (const char *language); + + /* Returns the jump value. */ + int get_jump () const; + + /* Returns the initial associated character value. */ + int get_initial_asso_value () const; + + /* Returns the number of iterations for finding good asso_values. */ + int get_asso_iterations () const; + + /* Returns the total number of switch statements to generate. */ + int get_total_switches () const; + /* Sets the total number of switch statements, if not already set. */ + void set_total_switches (int total_switches); + + /* Returns the factor by which to multiply the generated table's size. */ + float get_size_multiple () const; + + /* Returns the generated function name. */ + const char * get_function_name () const; + /* Sets the generated function name, if not already set. */ + void set_function_name (const char *name); + + /* Returns the keyword key name. */ + const char * get_slot_name () const; + /* Sets the keyword key name, if not already set. */ + void set_slot_name (const char *name); + + /* Returns the struct initializer suffix. */ + const char * get_initializer_suffix () const; + /* Sets the struct initializer suffix, if not already set. */ + void set_initializer_suffix (const char *initializers); + + /* Returns the generated class name. */ + const char * get_class_name () const; + /* Sets the generated class name, if not already set. */ + void set_class_name (const char *name); + + /* Returns the hash function name. */ + const char * get_hash_name () const; + /* Sets the hash function name, if not already set. */ + void set_hash_name (const char *name); + + /* Returns the hash table array name. */ + const char * get_wordlist_name () const; + /* Sets the hash table array name, if not already set. */ + void set_wordlist_name (const char *name); + + /* Returns the length table array name. */ + const char * get_lengthtable_name () const; + /* Sets the length table array name, if not already set. */ + void set_lengthtable_name (const char *name); + + /* Returns the string pool name. */ + const char * get_stringpool_name () const; + /* Sets the string pool name, if not already set. */ + void set_stringpool_name (const char *name); + + /* Returns the string used to delimit keywords from other attributes. */ + const char * get_delimiters () const; + /* Sets the delimiters string, if not already set. */ + void set_delimiters (const char *delimiters); + + /* Returns key positions. */ + const Positions& get_key_positions () const; private: - static int option_word; /* Holds the user-specified Options. */ - static int total_switches; /* Number of switch statements to generate. */ - static int total_keysig_size; /* Total number of distinct key_positions. */ - static int size; /* Range of the hash table. */ - static int key_pos; /* Tracks current key position for Iterator. */ - static int jump; /* Jump length when trying alternative values. */ - static int initial_asso_value; /* Initial value for asso_values table. */ - static int argument_count; /* Records count of command-line arguments. */ - static int iterations; /* Amount to iterate when a collision occurs. */ - static char **argument_vector; /* Stores a pointer to command-line vector. */ - static const char *function_name; /* Names used for generated lookup function. */ - static const char *key_name; /* Name used for keyword key. */ - static const char *initializer_suffix; /* Suffix for empty struct initializers. */ - static const char *class_name; /* Name used for generated C++ class. */ - static const char *hash_name; /* Name used for generated hash function. */ - static const char *wordlist_name; /* Name used for hash table array. */ - static const char *delimiters; /* Separates keywords from other attributes. */ - static char key_positions[MAX_KEY_POS]; /* Contains user-specified key choices. */ - static int key_sort (char *base, int len); /* Sorts key positions in REVERSE order. */ - static void short_usage (FILE * strm); /* Prints proper program usage. */ - static void long_usage (FILE * strm); /* Prints proper program usage. */ + /* Prints program usage to given stream. */ + static void short_usage (FILE * stream); + + /* Prints program usage to given stream. */ + static void long_usage (FILE * stream); + + /* Records count of command-line arguments. */ + int _argument_count; + + /* Stores a pointer to command-line argument vector. */ + char ** _argument_vector; + + /* Holds the boolean options. */ + int _option_word; + + /* Name of input file. */ + char * _input_file_name; + + /* Name of output file. */ + char * _output_file_name; + + /* The output language. */ + const char * _language; + + /* Jump length when trying alternative values. */ + int _jump; + + /* Initial value for asso_values table. */ + int _initial_asso_value; + + /* Number of attempts at finding good asso_values. */ + int _asso_iterations; + + /* Number of switch statements to generate. */ + int _total_switches; + + /* Factor by which to multiply the generated table's size. */ + float _size_multiple; + + /* Names used for generated lookup function. */ + const char * _function_name; + + /* Name used for keyword key. */ + const char * _slot_name; + + /* Suffix for empty struct initializers. */ + const char * _initializer_suffix; + + /* Name used for generated C++ class. */ + const char * _class_name; + + /* Name used for generated hash function. */ + const char * _hash_name; + + /* Name used for hash table array. */ + const char * _wordlist_name; + + /* Name used for length table array. */ + const char * _lengthtable_name; + + /* Name used for the string pool. */ + const char * _stringpool_name; + + /* Separates keywords from other attributes. */ + const char * _delimiters; + + /* Contains user-specified key choices. */ + Positions _key_positions; }; -/* Global option coordinator for the entire program. */ +/* Global option coordinator for the entire program. */ extern Options option; -/* Set to 1 if your want to stack-allocate some large arrays. - This requires compiler support for variable-size arrays on the stack - (not ANSI). */ -#ifndef LARGE_STACK_ARRAYS -#if defined(__GNUG__) && !defined(__STRICT_ANSI__) -#define LARGE_STACK_ARRAYS 1 -#else -#define LARGE_STACK_ARRAYS 0 -#endif -#endif - -/* Set to 1 if the stack is large enough for holding a text line. */ -#ifndef LARGE_STACK -#define LARGE_STACK 1 -#endif - #ifdef __OPTIMIZE__ -#include "trace.h" #define INLINE inline #include "options.icc" #undef INLINE diff --git a/contrib/gperf/src/options.icc b/contrib/gperf/src/options.icc index 82fe5375c23f..4188ddcbfd72 100644 --- a/contrib/gperf/src/options.icc +++ b/contrib/gperf/src/options.icc @@ -1,183 +1,157 @@ /* Inline Functions for options.{h,cc}. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) + Copyright (C) 1989-1998, 2000, 2002-2004 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -// This needs: -//#include "trace.h" +/* ----------------------------- Class Options ----------------------------- */ -/* TRUE if option enable, else FALSE. */ -INLINE int -Options::operator[] (Option_Type option) +/* Tests a given boolean option. Returns true if set, false otherwise. */ +INLINE bool +Options::operator[] (Option_Type option) const { - T (Trace t ("Options::operator[]");) - return option_word & option; + return _option_word & option; } -/* Enables option OPT. */ +/* Sets a given boolean option. */ INLINE void -Options::operator = (enum Option_Type opt) +Options::set (Option_Type option) { - T (Trace t ("Options::operator=");) - option_word |= opt; + _option_word |= option; } -/* Disables option OPT. */ -INLINE void -Options::operator != (enum Option_Type opt) -{ - T (Trace t ("Options::operator!=");) - option_word &= ~opt; -} - -/* Initializes the key Iterator. */ -INLINE void -Options::reset (void) -{ - T (Trace t ("Options::reset");) - key_pos = 0; -} - -/* Returns current key_position and advance index. */ -INLINE int -Options::get (void) -{ - T (Trace t ("Options::get");) - return key_positions[key_pos++]; -} - -/* Sets the size of the table size. */ -INLINE void -Options::set_asso_max (int r) -{ - T (Trace t ("Options::set_asso_max");) - size = r; -} - -/* Returns the size of the table size. */ -INLINE int -Options::get_asso_max (void) -{ - T (Trace t ("Options::get_asso_max");) - return size; -} - -/* Returns total distinct key positions. */ -INLINE int -Options::get_max_keysig_size (void) -{ - T (Trace t ("Options::get_max_keysig_size");) - return total_keysig_size; -} - -/* Sets total distinct key positions. */ -INLINE void -Options::set_keysig_size (int size) -{ - T (Trace t ("Options::set_keysig_size");) - total_keysig_size = size; -} - -/* Returns the jump value. */ -INLINE int -Options::get_jump (void) -{ - T (Trace t ("Options::get_jump");) - return jump; -} - -/* Returns the generated function name. */ +/* Returns the input file name. */ INLINE const char * -Options::get_function_name (void) +Options::get_input_file_name () const { - T (Trace t ("Options::get_function_name");) - return function_name; + return _input_file_name; } -/* Returns the keyword key name. */ +/* Returns the output file name. */ INLINE const char * -Options::get_key_name (void) +Options::get_output_file_name () const { - T (Trace t ("Options::get_key_name");) - return key_name; + return _output_file_name; } -/* Returns the struct initializer suffix. */ -INLINE const char * -Options::get_initializer_suffix (void) -{ - T (Trace t ("Options::get_initializer_suffix");) - return initializer_suffix; -} - -/* Returns the hash function name. */ -INLINE const char * -Options::get_hash_name (void) -{ - T (Trace t ("Options::get_hash_name");) - return hash_name; -} - -/* Returns the hash table array name. */ -INLINE const char * -Options::get_wordlist_name (void) -{ - T (Trace t ("Options::get_wordlist_name");) - return wordlist_name; -} - -/* Returns the generated class name. */ -INLINE const char * -Options::get_class_name (void) -{ - T (Trace t ("Options::get_class_name");) - return class_name; -} - -/* Returns the initial associated character value. */ +/* Returns the jump value. */ INLINE int -Options::initial_value (void) +Options::get_jump () const { - T (Trace t ("Options::initial_value");) - return initial_asso_value; + return _jump; } -/* Returns the iterations value. */ +/* Returns the initial associated character value. */ INLINE int -Options::get_iterations (void) +Options::get_initial_asso_value () const { - T (Trace t ("Options::get_iterations");) - return iterations; + return _initial_asso_value; } -/* Returns the string used to delimit keywords from other attributes. */ +/* Returns the number of iterations for finding finding good asso_values. */ +INLINE int +Options::get_asso_iterations () const +{ + return _asso_iterations; +} + +/* Returns the total number of switch statements to generate. */ +INLINE int +Options::get_total_switches () const +{ + return _total_switches; +} + +/* Returns the factor by which to multiply the generated table's size. */ +INLINE float +Options::get_size_multiple () const +{ + return _size_multiple; +} + +/* Returns the generated function name. */ INLINE const char * -Options::get_delimiter () +Options::get_function_name () const { - T (Trace t ("Options::get_delimiter");) - return delimiters; + return _function_name; } -/* Gets the total number of switch statements to generate. */ -INLINE int -Options::get_total_switches () +/* Returns the keyword key name. */ +INLINE const char * +Options::get_slot_name () const { - T (Trace t ("Options::get_total_switches");) - return total_switches; + return _slot_name; +} + +/* Returns the struct initializer suffix. */ +INLINE const char * +Options::get_initializer_suffix () const +{ + return _initializer_suffix; +} + +/* Returns the generated class name. */ +INLINE const char * +Options::get_class_name () const +{ + return _class_name; +} + +/* Returns the hash function name. */ +INLINE const char * +Options::get_hash_name () const +{ + return _hash_name; +} + +/* Returns the hash table array name. */ +INLINE const char * +Options::get_wordlist_name () const +{ + return _wordlist_name; +} + +/* Returns the length table array name. */ +INLINE const char * +Options::get_lengthtable_name () const +{ + return _lengthtable_name; +} + +/* Returns the string pool name. */ +INLINE const char * +Options::get_stringpool_name () const +{ + return _stringpool_name; +} + +/* Returns the string used to delimit keywords from other attributes. */ +INLINE const char * +Options::get_delimiters () const +{ + return _delimiters; +} + +/* Returns key positions. */ +INLINE const Positions& +Options::get_key_positions () const +{ + return _key_positions; } diff --git a/contrib/gperf/src/output.cc b/contrib/gperf/src/output.cc new file mode 100644 index 000000000000..2732057326ba --- /dev/null +++ b/contrib/gperf/src/output.cc @@ -0,0 +1,2100 @@ +/* Output routines. + Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2007 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Specification. */ +#include "output.h" + +#include +#include /* declares strncpy(), strchr() */ +#include /* declares isprint() */ +#include /* defines assert() */ +#include /* defines SCHAR_MAX etc. */ +#include "options.h" +#include "version.h" + +/* The "const " qualifier. */ +static const char *const_always; + +/* The "const " qualifier, for read-only arrays. */ +static const char *const_readonly_array; + +/* The "const " qualifier, for the array type. */ +static const char *const_for_struct; + +/* Returns the smallest unsigned C type capable of holding integers + up to N. */ + +static const char * +smallest_integral_type (int n) +{ + if (n <= UCHAR_MAX) return "unsigned char"; + if (n <= USHRT_MAX) return "unsigned short"; + return "unsigned int"; +} + +/* Returns the smallest signed C type capable of holding integers + from MIN to MAX. */ + +static const char * +smallest_integral_type (int min, int max) +{ + if (option[ANSIC] | option[CPLUSPLUS]) + if (min >= SCHAR_MIN && max <= SCHAR_MAX) return "signed char"; + if (min >= SHRT_MIN && max <= SHRT_MAX) return "short"; + return "int"; +} + +/* ------------------------------------------------------------------------- */ + +/* Constructor. + Note about the keyword list starting at head: + - The list is ordered by increasing _hash_value. This has been achieved + by Search::sort(). + - Duplicates, i.e. keywords with the same _selchars set, are chained + through the _duplicate_link pointer. Only one representative per + duplicate equivalence class remains on the linear keyword list. + - Accidental duplicates, i.e. keywords for which the _asso_values[] search + couldn't achieve different hash values, cannot occur on the linear + keyword list. Search::optimize would catch this mistake. + */ +Output::Output (KeywordExt_List *head, const char *struct_decl, + unsigned int struct_decl_lineno, const char *return_type, + const char *struct_tag, const char *verbatim_declarations, + const char *verbatim_declarations_end, + unsigned int verbatim_declarations_lineno, + const char *verbatim_code, const char *verbatim_code_end, + unsigned int verbatim_code_lineno, bool charset_dependent, + int total_keys, int max_key_len, int min_key_len, + const Positions& positions, const unsigned int *alpha_inc, + int total_duplicates, unsigned int alpha_size, + const int *asso_values) + : _head (head), _struct_decl (struct_decl), + _struct_decl_lineno (struct_decl_lineno), _return_type (return_type), + _struct_tag (struct_tag), + _verbatim_declarations (verbatim_declarations), + _verbatim_declarations_end (verbatim_declarations_end), + _verbatim_declarations_lineno (verbatim_declarations_lineno), + _verbatim_code (verbatim_code), + _verbatim_code_end (verbatim_code_end), + _verbatim_code_lineno (verbatim_code_lineno), + _charset_dependent (charset_dependent), + _total_keys (total_keys), + _max_key_len (max_key_len), _min_key_len (min_key_len), + _key_positions (positions), _alpha_inc (alpha_inc), + _total_duplicates (total_duplicates), _alpha_size (alpha_size), + _asso_values (asso_values) +{ +} + +/* ------------------------------------------------------------------------- */ + +/* Computes the minimum and maximum hash values, and stores them + in _min_hash_value and _max_hash_value. */ + +void +Output::compute_min_max () +{ + /* Since the list is already sorted by hash value all we need to do is + to look at the first and the last element of the list. */ + + _min_hash_value = _head->first()->_hash_value; + + KeywordExt_List *temp; + for (temp = _head; temp->rest(); temp = temp->rest()) + ; + _max_hash_value = temp->first()->_hash_value; +} + +/* ------------------------------------------------------------------------- */ + +/* Returns the number of different hash values. */ + +int +Output::num_hash_values () const +{ + /* Since the list is already sorted by hash value and doesn't contain + duplicates, we can simply count the number of keywords on the list. */ + int count = 0; + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + count++; + return count; +} + +/* -------------------- Output_Constants and subclasses -------------------- */ + +/* This class outputs an enumeration defining some constants. */ + +struct Output_Constants +{ + virtual void output_start () = 0; + virtual void output_item (const char *name, int value) = 0; + virtual void output_end () = 0; + Output_Constants () {} + virtual ~Output_Constants () {} +}; + +/* This class outputs an enumeration in #define syntax. */ + +struct Output_Defines : public Output_Constants +{ + virtual void output_start (); + virtual void output_item (const char *name, int value); + virtual void output_end (); + Output_Defines () {} + virtual ~Output_Defines () {} +}; + +void Output_Defines::output_start () +{ + printf ("\n"); +} + +void Output_Defines::output_item (const char *name, int value) +{ + printf ("#define %s %d\n", name, value); +} + +void Output_Defines::output_end () +{ +} + +/* This class outputs an enumeration using 'enum'. */ + +struct Output_Enum : public Output_Constants +{ + virtual void output_start (); + virtual void output_item (const char *name, int value); + virtual void output_end (); + Output_Enum (const char *indent) + : _indentation (indent) {} + virtual ~Output_Enum () {} +private: + const char *_indentation; + bool _pending_comma; +}; + +void Output_Enum::output_start () +{ + printf ("%senum\n" + "%s {\n", + _indentation, _indentation); + _pending_comma = false; +} + +void Output_Enum::output_item (const char *name, int value) +{ + if (_pending_comma) + printf (",\n"); + printf ("%s %s = %d", _indentation, name, value); + _pending_comma = true; +} + +void Output_Enum::output_end () +{ + if (_pending_comma) + printf ("\n"); + printf ("%s };\n\n", _indentation); +} + +/* Outputs the maximum and minimum hash values etc. */ + +void +Output::output_constants (struct Output_Constants& style) const +{ + style.output_start (); + style.output_item ("TOTAL_KEYWORDS", _total_keys); + style.output_item ("MIN_WORD_LENGTH", _min_key_len); + style.output_item ("MAX_WORD_LENGTH", _max_key_len); + style.output_item ("MIN_HASH_VALUE", _min_hash_value); + style.output_item ("MAX_HASH_VALUE", _max_hash_value); + style.output_end (); +} + +/* ------------------------------------------------------------------------- */ + +/* We use a downcase table because when called repeatedly, the code + gperf_downcase[c] + is faster than + if (c >= 'A' && c <= 'Z') + c += 'a' - 'A'; + */ +#define USE_DOWNCASE_TABLE 1 + +#if USE_DOWNCASE_TABLE + +/* Output gperf's ASCII-downcase table. */ + +static void +output_upperlower_table () +{ + unsigned int c; + + printf ("#ifndef GPERF_DOWNCASE\n" + "#define GPERF_DOWNCASE 1\n" + "static unsigned char gperf_downcase[256] =\n" + " {"); + for (c = 0; c < 256; c++) + { + if ((c % 15) == 0) + printf ("\n "); + printf (" %3d", c >= 'A' && c <= 'Z' ? c + 'a' - 'A' : c); + if (c < 255) + printf (","); + } + printf ("\n" + " };\n" + "#endif\n\n"); +} + +#endif + +/* Output gperf's ASCII-case insensitive strcmp replacement. */ + +static void +output_upperlower_strcmp () +{ + printf ("#ifndef GPERF_CASE_STRCMP\n" + "#define GPERF_CASE_STRCMP 1\n" + "static int\n" + "gperf_case_strcmp "); + printf (option[KRC] ? + "(s1, s2)\n" + " register char *s1;\n" + " register char *s2;\n" : + option[C] ? + "(s1, s2)\n" + " register const char *s1;\n" + " register const char *s2;\n" : + option[ANSIC] | option[CPLUSPLUS] ? + "(register const char *s1, register const char *s2)\n" : + ""); + #if USE_DOWNCASE_TABLE + printf ("{\n" + " for (;;)\n" + " {\n" + " unsigned char c1 = gperf_downcase[(unsigned char)*s1++];\n" + " unsigned char c2 = gperf_downcase[(unsigned char)*s2++];\n" + " if (c1 != 0 && c1 == c2)\n" + " continue;\n" + " return (int)c1 - (int)c2;\n" + " }\n" + "}\n"); + #else + printf ("{\n" + " for (;;)\n" + " {\n" + " unsigned char c1 = *s1++;\n" + " unsigned char c2 = *s2++;\n" + " if (c1 >= 'A' && c1 <= 'Z')\n" + " c1 += 'a' - 'A';\n" + " if (c2 >= 'A' && c2 <= 'Z')\n" + " c2 += 'a' - 'A';\n" + " if (c1 != 0 && c1 == c2)\n" + " continue;\n" + " return (int)c1 - (int)c2;\n" + " }\n" + "}\n"); + #endif + printf ("#endif\n\n"); +} + +/* Output gperf's ASCII-case insensitive strncmp replacement. */ + +static void +output_upperlower_strncmp () +{ + printf ("#ifndef GPERF_CASE_STRNCMP\n" + "#define GPERF_CASE_STRNCMP 1\n" + "static int\n" + "gperf_case_strncmp "); + printf (option[KRC] ? + "(s1, s2, n)\n" + " register char *s1;\n" + " register char *s2;\n" + " register unsigned int n;\n" : + option[C] ? + "(s1, s2, n)\n" + " register const char *s1;\n" + " register const char *s2;\n" + " register unsigned int n;\n" : + option[ANSIC] | option[CPLUSPLUS] ? + "(register const char *s1, register const char *s2, register unsigned int n)\n" : + ""); + #if USE_DOWNCASE_TABLE + printf ("{\n" + " for (; n > 0;)\n" + " {\n" + " unsigned char c1 = gperf_downcase[(unsigned char)*s1++];\n" + " unsigned char c2 = gperf_downcase[(unsigned char)*s2++];\n" + " if (c1 != 0 && c1 == c2)\n" + " {\n" + " n--;\n" + " continue;\n" + " }\n" + " return (int)c1 - (int)c2;\n" + " }\n" + " return 0;\n" + "}\n"); + #else + printf ("{\n" + " for (; n > 0;)\n" + " {\n" + " unsigned char c1 = *s1++;\n" + " unsigned char c2 = *s2++;\n" + " if (c1 >= 'A' && c1 <= 'Z')\n" + " c1 += 'a' - 'A';\n" + " if (c2 >= 'A' && c2 <= 'Z')\n" + " c2 += 'a' - 'A';\n" + " if (c1 != 0 && c1 == c2)\n" + " {\n" + " n--;\n" + " continue;\n" + " }\n" + " return (int)c1 - (int)c2;\n" + " }\n" + " return 0;\n" + "}\n"); + #endif + printf ("#endif\n\n"); +} + +/* Output gperf's ASCII-case insensitive memcmp replacement. */ + +static void +output_upperlower_memcmp () +{ + printf ("#ifndef GPERF_CASE_MEMCMP\n" + "#define GPERF_CASE_MEMCMP 1\n" + "static int\n" + "gperf_case_memcmp "); + printf (option[KRC] ? + "(s1, s2, n)\n" + " register char *s1;\n" + " register char *s2;\n" + " register unsigned int n;\n" : + option[C] ? + "(s1, s2, n)\n" + " register const char *s1;\n" + " register const char *s2;\n" + " register unsigned int n;\n" : + option[ANSIC] | option[CPLUSPLUS] ? + "(register const char *s1, register const char *s2, register unsigned int n)\n" : + ""); + #if USE_DOWNCASE_TABLE + printf ("{\n" + " for (; n > 0;)\n" + " {\n" + " unsigned char c1 = gperf_downcase[(unsigned char)*s1++];\n" + " unsigned char c2 = gperf_downcase[(unsigned char)*s2++];\n" + " if (c1 == c2)\n" + " {\n" + " n--;\n" + " continue;\n" + " }\n" + " return (int)c1 - (int)c2;\n" + " }\n" + " return 0;\n" + "}\n"); + #else + printf ("{\n" + " for (; n > 0;)\n" + " {\n" + " unsigned char c1 = *s1++;\n" + " unsigned char c2 = *s2++;\n" + " if (c1 >= 'A' && c1 <= 'Z')\n" + " c1 += 'a' - 'A';\n" + " if (c2 >= 'A' && c2 <= 'Z')\n" + " c2 += 'a' - 'A';\n" + " if (c1 == c2)\n" + " {\n" + " n--;\n" + " continue;\n" + " }\n" + " return (int)c1 - (int)c2;\n" + " }\n" + " return 0;\n" + "}\n"); + #endif + printf ("#endif\n\n"); +} + +/* ------------------------------------------------------------------------- */ + +/* Outputs a keyword, as a string: enclosed in double quotes, escaping + backslashes, double quote and unprintable characters. */ + +static void +output_string (const char *key, int len) +{ + putchar ('"'); + for (; len > 0; len--) + { + unsigned char c = static_cast(*key++); + if (isprint (c)) + { + if (c == '"' || c == '\\') + putchar ('\\'); + putchar (c); + } + else + { + /* Use octal escapes, not hexadecimal escapes, because some old + C compilers didn't understand hexadecimal escapes, and because + hexadecimal escapes are not limited to 2 digits, thus needing + special care if the following character happens to be a digit. */ + putchar ('\\'); + putchar ('0' + ((c >> 6) & 7)); + putchar ('0' + ((c >> 3) & 7)); + putchar ('0' + (c & 7)); + } + } + putchar ('"'); +} + +/* ------------------------------------------------------------------------- */ + +/* Outputs a #line directive, referring to the given line number. */ + +static void +output_line_directive (unsigned int lineno) +{ + const char *file_name = option.get_input_file_name (); + if (file_name != NULL) + { + printf ("#line %u ", lineno); + output_string (file_name, strlen (file_name)); + printf ("\n"); + } +} + +/* ------------------------------------------------------------------------- */ + +/* Outputs a type and a const specifier (i.e. "const " or ""). + The output is terminated with a space. */ + +static void +output_const_type (const char *const_string, const char *type_string) +{ + if (type_string[strlen(type_string)-1] == '*') + /* For pointer types, put the 'const' after the type. */ + printf ("%s %s", type_string, const_string); + else + /* For scalar or struct types, put the 'const' before the type. */ + printf ("%s%s ", const_string, type_string); +} + +/* ----------------------- Output_Expr and subclasses ----------------------- */ + +/* This class outputs a general expression. */ + +struct Output_Expr +{ + virtual void output_expr () const = 0; + Output_Expr () {} + virtual ~Output_Expr () {} +}; + +/* This class outputs an expression formed by a single string. */ + +struct Output_Expr1 : public Output_Expr +{ + virtual void output_expr () const; + Output_Expr1 (const char *piece1) : _p1 (piece1) {} + virtual ~Output_Expr1 () {} +private: + const char *_p1; +}; + +void Output_Expr1::output_expr () const +{ + printf ("%s", _p1); +} + +#if 0 /* unused */ + +/* This class outputs an expression formed by the concatenation of two + strings. */ + +struct Output_Expr2 : public Output_Expr +{ + virtual void output_expr () const; + Output_Expr2 (const char *piece1, const char *piece2) + : _p1 (piece1), _p2 (piece2) {} + virtual ~Output_Expr2 () {} +private: + const char *_p1; + const char *_p2; +}; + +void Output_Expr2::output_expr () const +{ + printf ("%s%s", _p1, _p2); +} + +#endif + +/* --------------------- Output_Compare and subclasses --------------------- */ + +/* This class outputs a comparison expression. */ + +struct Output_Compare +{ + /* Outputs the comparison expression. + expr1 outputs a simple expression of type 'const char *' referring to + the string being looked up. expr2 outputs a simple expression of type + 'const char *' referring to the constant string stored in the gperf + generated hash table. */ + virtual void output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const = 0; + /* Outputs the comparison expression for the first byte. + Returns true if the this comparison is complete. */ + bool output_firstchar_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const; + Output_Compare () {} + virtual ~Output_Compare () {} +}; + +bool Output_Compare::output_firstchar_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const +{ + /* First, we emit a comparison of the first byte of the two strings. + This catches most cases where the string being looked up is not in the + hash table but happens to have the same hash code as an element of the + hash table. */ + if (option[UPPERLOWER]) + { + /* Incomplete comparison, just for speedup. */ + printf ("(((unsigned char)*"); + expr1.output_expr (); + printf (" ^ (unsigned char)*"); + expr2.output_expr (); + printf (") & ~32) == 0"); + return false; + } + else + { + /* Complete comparison. */ + printf ("*"); + expr1.output_expr (); + printf (" == *"); + expr2.output_expr (); + return true; + } +} + +/* This class outputs a comparison using strcmp. */ + +struct Output_Compare_Strcmp : public Output_Compare +{ + virtual void output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const; + Output_Compare_Strcmp () {} + virtual ~Output_Compare_Strcmp () {} +}; + +void Output_Compare_Strcmp::output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const +{ + bool firstchar_done = output_firstchar_comparison (expr1, expr2); + printf (" && !"); + if (option[UPPERLOWER]) + printf ("gperf_case_"); + printf ("strcmp ("); + if (firstchar_done) + { + expr1.output_expr (); + printf (" + 1, "); + expr2.output_expr (); + printf (" + 1"); + } + else + { + expr1.output_expr (); + printf (", "); + expr2.output_expr (); + } + printf (")"); +} + +/* This class outputs a comparison using strncmp. + Note that the length of expr1 will be available through the local variable + 'len'. */ + +struct Output_Compare_Strncmp : public Output_Compare +{ + virtual void output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const; + Output_Compare_Strncmp () {} + virtual ~Output_Compare_Strncmp () {} +}; + +void Output_Compare_Strncmp::output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const +{ + bool firstchar_done = output_firstchar_comparison (expr1, expr2); + printf (" && !"); + if (option[UPPERLOWER]) + printf ("gperf_case_"); + printf ("strncmp ("); + if (firstchar_done) + { + expr1.output_expr (); + printf (" + 1, "); + expr2.output_expr (); + printf (" + 1, len - 1"); + } + else + { + expr1.output_expr (); + printf (", "); + expr2.output_expr (); + printf (", len"); + } + printf (") && "); + expr2.output_expr (); + printf ("[len] == '\\0'"); +} + +/* This class outputs a comparison using memcmp. + Note that the length of expr1 (available through the local variable 'len') + must be verified to be equal to the length of expr2 prior to this + comparison. */ + +struct Output_Compare_Memcmp : public Output_Compare +{ + virtual void output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const; + Output_Compare_Memcmp () {} + virtual ~Output_Compare_Memcmp () {} +}; + +void Output_Compare_Memcmp::output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const +{ + bool firstchar_done = output_firstchar_comparison (expr1, expr2); + printf (" && !"); + if (option[UPPERLOWER]) + printf ("gperf_case_"); + printf ("memcmp ("); + if (firstchar_done) + { + expr1.output_expr (); + printf (" + 1, "); + expr2.output_expr (); + printf (" + 1, len - 1"); + } + else + { + expr1.output_expr (); + printf (", "); + expr2.output_expr (); + printf (", len"); + } + printf (")"); +} + +/* ------------------------------------------------------------------------- */ + +/* Generates a C expression for an asso_values[] reference. */ + +void +Output::output_asso_values_ref (int pos) const +{ + printf ("asso_values["); + /* Always cast to unsigned char. This is necessary when the alpha_inc + is nonzero, and also avoids a gcc warning "subscript has type 'char'". */ + printf ("(unsigned char)"); + if (pos == Positions::LASTCHAR) + printf ("str[len - 1]"); + else + { + printf ("str[%d]", pos); + if (_alpha_inc[pos]) + printf ("+%u", _alpha_inc[pos]); + } + printf ("]"); +} + +/* Generates C code for the hash function that returns the + proper encoding for each keyword. + The hash function has the signature + unsigned int (const char *str, unsigned int len). */ + +void +Output::output_hash_function () const +{ + /* Output the function's head. */ + if (option[CPLUSPLUS]) + printf ("inline "); + else if (option[KRC] | option[C] | option[ANSIC]) + printf ("#ifdef __GNUC__\n" + "__inline\n" + "#else\n" + "#ifdef __cplusplus\n" + "inline\n" + "#endif\n" + "#endif\n"); + + if (/* The function does not use the 'str' argument? */ + _key_positions.get_size() == 0 + || /* The function uses 'str', but not the 'len' argument? */ + (option[NOLENGTH] + && _key_positions[0] < _min_key_len + && _key_positions[_key_positions.get_size() - 1] != Positions::LASTCHAR)) + /* Pacify lint. */ + printf ("/*ARGSUSED*/\n"); + + if (option[KRC] | option[C] | option[ANSIC]) + printf ("static "); + printf ("unsigned int\n"); + if (option[CPLUSPLUS]) + printf ("%s::", option.get_class_name ()); + printf ("%s ", option.get_hash_name ()); + printf (option[KRC] ? + "(str, len)\n" + " register char *str;\n" + " register unsigned int len;\n" : + option[C] ? + "(str, len)\n" + " register const char *str;\n" + " register unsigned int len;\n" : + option[ANSIC] | option[CPLUSPLUS] ? + "(register const char *str, register unsigned int len)\n" : + ""); + + /* Note that when the hash function is called, it has already been verified + that min_key_len <= len <= max_key_len. */ + + /* Output the function's body. */ + printf ("{\n"); + + /* First the asso_values array. */ + if (_key_positions.get_size() > 0) + { + printf (" static %s%s asso_values[] =\n" + " {", + const_readonly_array, + smallest_integral_type (_max_hash_value + 1)); + + const int columns = 10; + + /* Calculate maximum number of digits required for MAX_HASH_VALUE. */ + int field_width = 2; + for (int trunc = _max_hash_value; (trunc /= 10) > 0;) + field_width++; + + for (unsigned int count = 0; count < _alpha_size; count++) + { + if (count > 0) + printf (","); + if ((count % columns) == 0) + printf ("\n "); + printf ("%*d", field_width, _asso_values[count]); + } + + printf ("\n" + " };\n"); + } + + if (_key_positions.get_size() == 0) + { + /* Trivial case: No key positions at all. */ + printf (" return %s;\n", + option[NOLENGTH] ? "0" : "len"); + } + else + { + /* Iterate through the key positions. Remember that Positions::sort() + has sorted them in decreasing order, with Positions::LASTCHAR coming + last. */ + PositionIterator iter = _key_positions.iterator(_max_key_len); + int key_pos; + + /* Get the highest key position. */ + key_pos = iter.next (); + + if (key_pos == Positions::LASTCHAR || key_pos < _min_key_len) + { + /* We can perform additional optimizations here: + Write it out as a single expression. Note that the values + are added as 'int's even though the asso_values array may + contain 'unsigned char's or 'unsigned short's. */ + + printf (" return %s", + option[NOLENGTH] ? "" : "len + "); + + if (_key_positions.get_size() == 2 + && _key_positions[0] == 0 + && _key_positions[1] == Positions::LASTCHAR) + /* Optimize special case of "-k 1,$". */ + { + output_asso_values_ref (Positions::LASTCHAR); + printf (" + "); + output_asso_values_ref (0); + } + else + { + for (; key_pos != Positions::LASTCHAR; ) + { + output_asso_values_ref (key_pos); + if ((key_pos = iter.next ()) != PositionIterator::EOS) + printf (" + "); + else + break; + } + + if (key_pos == Positions::LASTCHAR) + output_asso_values_ref (Positions::LASTCHAR); + } + + printf (";\n"); + } + else + { + /* We've got to use the correct, but brute force, technique. */ + printf (" register int hval = %s;\n\n" + " switch (%s)\n" + " {\n" + " default:\n", + option[NOLENGTH] ? "0" : "len", + option[NOLENGTH] ? "len" : "hval"); + + while (key_pos != Positions::LASTCHAR && key_pos >= _max_key_len) + if ((key_pos = iter.next ()) == PositionIterator::EOS) + break; + + if (key_pos != PositionIterator::EOS && key_pos != Positions::LASTCHAR) + { + int i = key_pos; + do + { + if (i > key_pos) + printf (" /*FALLTHROUGH*/\n"); /* Pacify lint. */ + for ( ; i > key_pos; i--) + printf (" case %d:\n", i); + + printf (" hval += "); + output_asso_values_ref (key_pos); + printf (";\n"); + + key_pos = iter.next (); + } + while (key_pos != PositionIterator::EOS && key_pos != Positions::LASTCHAR); + + if (i >= _min_key_len) + printf (" /*FALLTHROUGH*/\n"); /* Pacify lint. */ + for ( ; i >= _min_key_len; i--) + printf (" case %d:\n", i); + } + + printf (" break;\n" + " }\n" + " return hval"); + if (key_pos == Positions::LASTCHAR) + { + printf (" + "); + output_asso_values_ref (Positions::LASTCHAR); + } + printf (";\n"); + } + } + printf ("}\n\n"); +} + +/* ------------------------------------------------------------------------- */ + +/* Prints out a table of keyword lengths, for use with the + comparison code in generated function 'in_word_set'. + Only called if option[LENTABLE]. */ + +void +Output::output_keylength_table () const +{ + const int columns = 14; + const char * const indent = option[GLOBAL] ? "" : " "; + + printf ("%sstatic %s%s %s[] =\n" + "%s {", + indent, const_readonly_array, + smallest_integral_type (_max_key_len), + option.get_lengthtable_name (), + indent); + + /* Generate an array of lengths, similar to output_keyword_table. */ + int index; + int column; + KeywordExt_List *temp; + + column = 0; + for (temp = _head, index = 0; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + + /* If generating a switch statement, and there is no user defined type, + we generate non-duplicates directly in the code. Only duplicates go + into the table. */ + if (option[SWITCH] && !option[TYPE] && !keyword->_duplicate_link) + continue; + + if (index < keyword->_hash_value && !option[SWITCH] && !option[DUP]) + { + /* Some blank entries. */ + for ( ; index < keyword->_hash_value; index++) + { + if (index > 0) + printf (","); + if ((column++ % columns) == 0) + printf ("\n%s ", indent); + printf ("%3d", 0); + } + } + + if (index > 0) + printf (","); + if ((column++ % columns) == 0) + printf("\n%s ", indent); + printf ("%3d", keyword->_allchars_length); + index++; + + /* Deal with duplicates specially. */ + if (keyword->_duplicate_link) // implies option[DUP] + for (KeywordExt *links = keyword->_duplicate_link; links; links = links->_duplicate_link) + { + printf (","); + if ((column++ % columns) == 0) + printf("\n%s ", indent); + printf ("%3d", links->_allchars_length); + index++; + } + } + + printf ("\n%s };\n", indent); + if (option[GLOBAL]) + printf ("\n"); +} + +/* ------------------------------------------------------------------------- */ + +/* Prints out the string pool, containing the strings of the keyword table. + Only called if option[SHAREDLIB]. */ + +void +Output::output_string_pool () const +{ + const char * const indent = option[TYPE] || option[GLOBAL] ? "" : " "; + int index; + KeywordExt_List *temp; + + printf ("%sstruct %s_t\n" + "%s {\n", + indent, option.get_stringpool_name (), indent); + for (temp = _head, index = 0; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + + /* If generating a switch statement, and there is no user defined type, + we generate non-duplicates directly in the code. Only duplicates go + into the table. */ + if (option[SWITCH] && !option[TYPE] && !keyword->_duplicate_link) + continue; + + if (!option[SWITCH] && !option[DUP]) + index = keyword->_hash_value; + + printf ("%s char %s_str%d[sizeof(", + indent, option.get_stringpool_name (), index); + output_string (keyword->_allchars, keyword->_allchars_length); + printf (")];\n"); + + /* Deal with duplicates specially. */ + if (keyword->_duplicate_link) // implies option[DUP] + for (KeywordExt *links = keyword->_duplicate_link; links; links = links->_duplicate_link) + if (!(links->_allchars_length == keyword->_allchars_length + && memcmp (links->_allchars, keyword->_allchars, + keyword->_allchars_length) == 0)) + { + index++; + printf ("%s char %s_str%d[sizeof(", + indent, option.get_stringpool_name (), index); + output_string (links->_allchars, links->_allchars_length); + printf (")];\n"); + } + + index++; + } + printf ("%s };\n", + indent); + + printf ("%sstatic %sstruct %s_t %s_contents =\n" + "%s {\n", + indent, const_readonly_array, option.get_stringpool_name (), + option.get_stringpool_name (), indent); + for (temp = _head, index = 0; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + + /* If generating a switch statement, and there is no user defined type, + we generate non-duplicates directly in the code. Only duplicates go + into the table. */ + if (option[SWITCH] && !option[TYPE] && !keyword->_duplicate_link) + continue; + + if (index > 0) + printf (",\n"); + + if (!option[SWITCH] && !option[DUP]) + index = keyword->_hash_value; + + printf ("%s ", + indent); + output_string (keyword->_allchars, keyword->_allchars_length); + + /* Deal with duplicates specially. */ + if (keyword->_duplicate_link) // implies option[DUP] + for (KeywordExt *links = keyword->_duplicate_link; links; links = links->_duplicate_link) + if (!(links->_allchars_length == keyword->_allchars_length + && memcmp (links->_allchars, keyword->_allchars, + keyword->_allchars_length) == 0)) + { + index++; + printf (",\n"); + printf ("%s ", + indent); + output_string (links->_allchars, links->_allchars_length); + } + + index++; + } + if (index > 0) + printf ("\n"); + printf ("%s };\n", + indent); + printf ("%s#define %s ((%schar *) &%s_contents)\n", + indent, option.get_stringpool_name (), const_always, + option.get_stringpool_name ()); + if (option[GLOBAL]) + printf ("\n"); +} + +/* ------------------------------------------------------------------------- */ + +static void +output_keyword_entry (KeywordExt *temp, int stringpool_index, const char *indent) +{ + if (option[TYPE]) + output_line_directive (temp->_lineno); + printf ("%s ", indent); + if (option[TYPE]) + printf ("{"); + if (option[SHAREDLIB]) + printf ("(int)(long)&((struct %s_t *)0)->%s_str%d", + option.get_stringpool_name (), option.get_stringpool_name (), + stringpool_index); + else + output_string (temp->_allchars, temp->_allchars_length); + if (option[TYPE]) + { + if (strlen (temp->_rest) > 0) + printf (",%s", temp->_rest); + printf ("}"); + } + if (option[DEBUG]) + printf (" /* hash value = %d, index = %d */", + temp->_hash_value, temp->_final_index); +} + +static void +output_keyword_blank_entries (int count, const char *indent) +{ + int columns; + if (option[TYPE]) + { + columns = 58 / (4 + (option[SHAREDLIB] ? 2 : option[NULLSTRINGS] ? 8 : 2) + + strlen (option.get_initializer_suffix())); + if (columns == 0) + columns = 1; + } + else + { + columns = (option[SHAREDLIB] ? 9 : option[NULLSTRINGS] ? 4 : 9); + } + int column = 0; + for (int i = 0; i < count; i++) + { + if ((column % columns) == 0) + { + if (i > 0) + printf (",\n"); + printf ("%s ", indent); + } + else + { + if (i > 0) + printf (", "); + } + if (option[TYPE]) + printf ("{"); + if (option[SHAREDLIB]) + printf ("-1"); + else + { + if (option[NULLSTRINGS]) + printf ("(char*)0"); + else + printf ("\"\""); + } + if (option[TYPE]) + printf ("%s}", option.get_initializer_suffix()); + column++; + } +} + +/* Prints out the array containing the keywords for the hash function. */ + +void +Output::output_keyword_table () const +{ + const char *indent = option[GLOBAL] ? "" : " "; + int index; + KeywordExt_List *temp; + + printf ("%sstatic ", + indent); + output_const_type (const_readonly_array, _wordlist_eltype); + printf ("%s[] =\n" + "%s {\n", + option.get_wordlist_name (), + indent); + + /* Generate an array of reserved words at appropriate locations. */ + + for (temp = _head, index = 0; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + + /* If generating a switch statement, and there is no user defined type, + we generate non-duplicates directly in the code. Only duplicates go + into the table. */ + if (option[SWITCH] && !option[TYPE] && !keyword->_duplicate_link) + continue; + + if (index > 0) + printf (",\n"); + + if (index < keyword->_hash_value && !option[SWITCH] && !option[DUP]) + { + /* Some blank entries. */ + output_keyword_blank_entries (keyword->_hash_value - index, indent); + printf (",\n"); + index = keyword->_hash_value; + } + + keyword->_final_index = index; + + output_keyword_entry (keyword, index, indent); + + /* Deal with duplicates specially. */ + if (keyword->_duplicate_link) // implies option[DUP] + for (KeywordExt *links = keyword->_duplicate_link; links; links = links->_duplicate_link) + { + links->_final_index = ++index; + printf (",\n"); + int stringpool_index = + (links->_allchars_length == keyword->_allchars_length + && memcmp (links->_allchars, keyword->_allchars, + keyword->_allchars_length) == 0 + ? keyword->_final_index + : links->_final_index); + output_keyword_entry (links, stringpool_index, indent); + } + + index++; + } + if (index > 0) + printf ("\n"); + + printf ("%s };\n\n", indent); +} + +/* ------------------------------------------------------------------------- */ + +/* Generates the large, sparse table that maps hash values into + the smaller, contiguous range of the keyword table. */ + +void +Output::output_lookup_array () const +{ + if (option[DUP]) + { + const int DEFAULT_VALUE = -1; + + /* Because of the way output_keyword_table works, every duplicate set is + stored contiguously in the wordlist array. */ + struct duplicate_entry + { + int hash_value; /* Hash value for this particular duplicate set. */ + int index; /* Index into the main keyword storage array. */ + int count; /* Number of consecutive duplicates at this index. */ + }; + + duplicate_entry *duplicates = new duplicate_entry[_total_duplicates]; + int *lookup_array = new int[_max_hash_value + 1 + 2*_total_duplicates]; + int lookup_array_size = _max_hash_value + 1; + duplicate_entry *dup_ptr = &duplicates[0]; + int *lookup_ptr = &lookup_array[_max_hash_value + 1 + 2*_total_duplicates]; + + while (lookup_ptr > lookup_array) + *--lookup_ptr = DEFAULT_VALUE; + + /* Now dup_ptr = &duplicates[0] and lookup_ptr = &lookup_array[0]. */ + + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + { + int hash_value = temp->first()->_hash_value; + lookup_array[hash_value] = temp->first()->_final_index; + if (option[DEBUG]) + fprintf (stderr, "keyword = %.*s, index = %d\n", + temp->first()->_allchars_length, temp->first()->_allchars, temp->first()->_final_index); + if (temp->first()->_duplicate_link) + { + /* Start a duplicate entry. */ + dup_ptr->hash_value = hash_value; + dup_ptr->index = temp->first()->_final_index; + dup_ptr->count = 1; + + for (KeywordExt *ptr = temp->first()->_duplicate_link; ptr; ptr = ptr->_duplicate_link) + { + dup_ptr->count++; + if (option[DEBUG]) + fprintf (stderr, + "static linked keyword = %.*s, index = %d\n", + ptr->_allchars_length, ptr->_allchars, ptr->_final_index); + } + assert (dup_ptr->count >= 2); + dup_ptr++; + } + } + + while (dup_ptr > duplicates) + { + dup_ptr--; + + if (option[DEBUG]) + fprintf (stderr, + "dup_ptr[%td]: hash_value = %d, index = %d, count = %d\n", + dup_ptr - duplicates, + dup_ptr->hash_value, dup_ptr->index, dup_ptr->count); + + int i; + /* Start searching for available space towards the right part + of the lookup array. */ + for (i = dup_ptr->hash_value; i < lookup_array_size-1; i++) + if (lookup_array[i] == DEFAULT_VALUE + && lookup_array[i + 1] == DEFAULT_VALUE) + goto found_i; + /* If we didn't find it to the right look to the left instead... */ + for (i = dup_ptr->hash_value-1; i >= 0; i--) + if (lookup_array[i] == DEFAULT_VALUE + && lookup_array[i + 1] == DEFAULT_VALUE) + goto found_i; + /* Append to the end of lookup_array. */ + i = lookup_array_size; + lookup_array_size += 2; + found_i: + /* Put in an indirection from dup_ptr->_hash_value to i. + At i and i+1 store dup_ptr->_final_index and dup_ptr->count. */ + assert (lookup_array[dup_ptr->hash_value] == dup_ptr->index); + lookup_array[dup_ptr->hash_value] = - 1 - _total_keys - i; + lookup_array[i] = - _total_keys + dup_ptr->index; + lookup_array[i + 1] = - dup_ptr->count; + /* All these three values are <= -2, distinct from DEFAULT_VALUE. */ + } + + /* The values of the lookup array are now known. */ + + int min = INT_MAX; + int max = INT_MIN; + lookup_ptr = lookup_array + lookup_array_size; + while (lookup_ptr > lookup_array) + { + int val = *--lookup_ptr; + if (min > val) + min = val; + if (max < val) + max = val; + } + + const char *indent = option[GLOBAL] ? "" : " "; + printf ("%sstatic %s%s lookup[] =\n" + "%s {", + indent, const_readonly_array, smallest_integral_type (min, max), + indent); + + int field_width; + /* Calculate maximum number of digits required for MIN..MAX. */ + { + field_width = 2; + for (int trunc = max; (trunc /= 10) > 0;) + field_width++; + } + if (min < 0) + { + int neg_field_width = 2; + for (int trunc = -min; (trunc /= 10) > 0;) + neg_field_width++; + neg_field_width++; /* account for the minus sign */ + if (field_width < neg_field_width) + field_width = neg_field_width; + } + + const int columns = 42 / field_width; + int column; + + column = 0; + for (int i = 0; i < lookup_array_size; i++) + { + if (i > 0) + printf (","); + if ((column++ % columns) == 0) + printf("\n%s ", indent); + printf ("%*d", field_width, lookup_array[i]); + } + printf ("\n%s };\n\n", indent); + + delete[] duplicates; + delete[] lookup_array; + } +} + +/* ------------------------------------------------------------------------- */ + +/* Generate all pools needed for the lookup function. */ + +void +Output::output_lookup_pools () const +{ + if (option[SWITCH]) + { + if (option[TYPE] || (option[DUP] && _total_duplicates > 0)) + output_string_pool (); + } + else + { + output_string_pool (); + } +} + +/* Generate all the tables needed for the lookup function. */ + +void +Output::output_lookup_tables () const +{ + if (option[SWITCH]) + { + /* Use the switch in place of lookup table. */ + if (option[LENTABLE] && (option[DUP] && _total_duplicates > 0)) + output_keylength_table (); + if (option[TYPE] || (option[DUP] && _total_duplicates > 0)) + output_keyword_table (); + } + else + { + /* Use the lookup table, in place of switch. */ + if (option[LENTABLE]) + output_keylength_table (); + output_keyword_table (); + output_lookup_array (); + } +} + +/* ------------------------------------------------------------------------- */ + +/* Output a single switch case (including duplicates). Advance list. */ + +static KeywordExt_List * +output_switch_case (KeywordExt_List *list, int indent, int *jumps_away) +{ + if (option[DEBUG]) + printf ("%*s/* hash value = %4d, keyword = \"%.*s\" */\n", + indent, "", list->first()->_hash_value, list->first()->_allchars_length, list->first()->_allchars); + + if (option[DUP] && list->first()->_duplicate_link) + { + if (option[LENTABLE]) + printf ("%*slengthptr = &%s[%d];\n", + indent, "", option.get_lengthtable_name (), list->first()->_final_index); + printf ("%*swordptr = &%s[%d];\n", + indent, "", option.get_wordlist_name (), list->first()->_final_index); + + int count = 0; + for (KeywordExt *links = list->first(); links; links = links->_duplicate_link) + count++; + + printf ("%*swordendptr = wordptr + %d;\n" + "%*sgoto multicompare;\n", + indent, "", count, + indent, ""); + *jumps_away = 1; + } + else + { + if (option[LENTABLE]) + { + printf ("%*sif (len == %d)\n" + "%*s {\n", + indent, "", list->first()->_allchars_length, + indent, ""); + indent += 4; + } + printf ("%*sresword = ", + indent, ""); + if (option[TYPE]) + printf ("&%s[%d]", option.get_wordlist_name (), list->first()->_final_index); + else + output_string (list->first()->_allchars, list->first()->_allchars_length); + printf (";\n"); + printf ("%*sgoto compare;\n", + indent, ""); + if (option[LENTABLE]) + { + indent -= 4; + printf ("%*s }\n", + indent, ""); + } + else + *jumps_away = 1; + } + + return list->rest(); +} + +/* Output a total of size cases, grouped into num_switches switch statements, + where 0 < num_switches <= size. */ + +static void +output_switches (KeywordExt_List *list, int num_switches, int size, int min_hash_value, int max_hash_value, int indent) +{ + if (option[DEBUG]) + printf ("%*s/* know %d <= key <= %d, contains %d cases */\n", + indent, "", min_hash_value, max_hash_value, size); + + if (num_switches > 1) + { + int part1 = num_switches / 2; + int part2 = num_switches - part1; + int size1 = static_cast(static_cast(size) / static_cast(num_switches) * static_cast(part1) + 0.5); + int size2 = size - size1; + + KeywordExt_List *temp = list; + for (int count = size1; count > 0; count--) + temp = temp->rest(); + + printf ("%*sif (key < %d)\n" + "%*s {\n", + indent, "", temp->first()->_hash_value, + indent, ""); + + output_switches (list, part1, size1, min_hash_value, temp->first()->_hash_value-1, indent+4); + + printf ("%*s }\n" + "%*selse\n" + "%*s {\n", + indent, "", indent, "", indent, ""); + + output_switches (temp, part2, size2, temp->first()->_hash_value, max_hash_value, indent+4); + + printf ("%*s }\n", + indent, ""); + } + else + { + /* Output a single switch. */ + int lowest_case_value = list->first()->_hash_value; + if (size == 1) + { + int jumps_away = 0; + assert (min_hash_value <= lowest_case_value); + assert (lowest_case_value <= max_hash_value); + if (min_hash_value == max_hash_value) + output_switch_case (list, indent, &jumps_away); + else + { + printf ("%*sif (key == %d)\n" + "%*s {\n", + indent, "", lowest_case_value, + indent, ""); + output_switch_case (list, indent+4, &jumps_away); + printf ("%*s }\n", + indent, ""); + } + } + else + { + if (lowest_case_value == 0) + printf ("%*sswitch (key)\n", indent, ""); + else + printf ("%*sswitch (key - %d)\n", indent, "", lowest_case_value); + printf ("%*s {\n", + indent, ""); + for (; size > 0; size--) + { + int jumps_away = 0; + printf ("%*s case %d:\n", + indent, "", list->first()->_hash_value - lowest_case_value); + list = output_switch_case (list, indent+6, &jumps_away); + if (!jumps_away) + printf ("%*s break;\n", + indent, ""); + } + printf ("%*s }\n", + indent, ""); + } + } +} + +/* Generates C code to perform the keyword lookup. */ + +void +Output::output_lookup_function_body (const Output_Compare& comparison) const +{ + printf (" if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)\n" + " {\n" + " register int key = %s (str, len);\n\n", + option.get_hash_name ()); + + if (option[SWITCH]) + { + int switch_size = num_hash_values (); + int num_switches = option.get_total_switches (); + if (num_switches > switch_size) + num_switches = switch_size; + + printf (" if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)\n" + " {\n"); + if (option[DUP] && _total_duplicates > 0) + { + if (option[LENTABLE]) + printf (" register %s%s *lengthptr;\n", + const_always, smallest_integral_type (_max_key_len)); + printf (" register "); + output_const_type (const_readonly_array, _wordlist_eltype); + printf ("*wordptr;\n"); + printf (" register "); + output_const_type (const_readonly_array, _wordlist_eltype); + printf ("*wordendptr;\n"); + } + if (option[TYPE]) + { + printf (" register "); + output_const_type (const_readonly_array, _struct_tag); + printf ("*resword;\n\n"); + } + else + printf (" register %sresword;\n\n", + _struct_tag); + + output_switches (_head, num_switches, switch_size, _min_hash_value, _max_hash_value, 10); + + printf (" return 0;\n"); + if (option[DUP] && _total_duplicates > 0) + { + int indent = 8; + printf ("%*smulticompare:\n" + "%*s while (wordptr < wordendptr)\n" + "%*s {\n", + indent, "", indent, "", indent, ""); + if (option[LENTABLE]) + { + printf ("%*s if (len == *lengthptr)\n" + "%*s {\n", + indent, "", indent, ""); + indent += 4; + } + printf ("%*s register %schar *s = ", + indent, "", const_always); + if (option[TYPE]) + printf ("wordptr->%s", option.get_slot_name ()); + else + printf ("*wordptr"); + if (option[SHAREDLIB]) + printf (" + %s", + option.get_stringpool_name ()); + printf (";\n\n" + "%*s if (", + indent, ""); + comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s")); + printf (")\n" + "%*s return %s;\n", + indent, "", + option[TYPE] ? "wordptr" : "s"); + if (option[LENTABLE]) + { + indent -= 4; + printf ("%*s }\n", + indent, ""); + } + if (option[LENTABLE]) + printf ("%*s lengthptr++;\n", + indent, ""); + printf ("%*s wordptr++;\n" + "%*s }\n" + "%*s return 0;\n", + indent, "", indent, "", indent, ""); + } + printf (" compare:\n"); + if (option[TYPE]) + { + printf (" {\n" + " register %schar *s = resword->%s", + const_always, option.get_slot_name ()); + if (option[SHAREDLIB]) + printf (" + %s", + option.get_stringpool_name ()); + printf (";\n\n" + " if ("); + comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s")); + printf (")\n" + " return resword;\n" + " }\n"); + } + else + { + printf (" if ("); + comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("resword")); + printf (")\n" + " return resword;\n"); + } + printf (" }\n"); + } + else + { + printf (" if (key <= MAX_HASH_VALUE && key >= 0)\n"); + + if (option[DUP]) + { + int indent = 8; + printf ("%*s{\n" + "%*s register int index = lookup[key];\n\n" + "%*s if (index >= 0)\n", + indent, "", indent, "", indent, ""); + if (option[LENTABLE]) + { + printf ("%*s {\n" + "%*s if (len == %s[index])\n", + indent, "", indent, "", option.get_lengthtable_name ()); + indent += 4; + } + printf ("%*s {\n" + "%*s register %schar *s = %s[index]", + indent, "", + indent, "", const_always, option.get_wordlist_name ()); + if (option[TYPE]) + printf (".%s", option.get_slot_name ()); + if (option[SHAREDLIB]) + printf (" + %s", + option.get_stringpool_name ()); + printf (";\n\n" + "%*s if (", + indent, ""); + comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s")); + printf (")\n" + "%*s return ", + indent, ""); + if (option[TYPE]) + printf ("&%s[index]", option.get_wordlist_name ()); + else + printf ("s"); + printf (";\n" + "%*s }\n", + indent, ""); + if (option[LENTABLE]) + { + indent -= 4; + printf ("%*s }\n", indent, ""); + } + if (_total_duplicates > 0) + { + printf ("%*s else if (index < -TOTAL_KEYWORDS)\n" + "%*s {\n" + "%*s register int offset = - 1 - TOTAL_KEYWORDS - index;\n", + indent, "", indent, "", indent, ""); + if (option[LENTABLE]) + printf ("%*s register %s%s *lengthptr = &%s[TOTAL_KEYWORDS + lookup[offset]];\n", + indent, "", const_always, smallest_integral_type (_max_key_len), + option.get_lengthtable_name ()); + printf ("%*s register ", + indent, ""); + output_const_type (const_readonly_array, _wordlist_eltype); + printf ("*wordptr = &%s[TOTAL_KEYWORDS + lookup[offset]];\n", + option.get_wordlist_name ()); + printf ("%*s register ", + indent, ""); + output_const_type (const_readonly_array, _wordlist_eltype); + printf ("*wordendptr = wordptr + -lookup[offset + 1];\n\n"); + printf ("%*s while (wordptr < wordendptr)\n" + "%*s {\n", + indent, "", indent, ""); + if (option[LENTABLE]) + { + printf ("%*s if (len == *lengthptr)\n" + "%*s {\n", + indent, "", indent, ""); + indent += 4; + } + printf ("%*s register %schar *s = ", + indent, "", const_always); + if (option[TYPE]) + printf ("wordptr->%s", option.get_slot_name ()); + else + printf ("*wordptr"); + if (option[SHAREDLIB]) + printf (" + %s", + option.get_stringpool_name ()); + printf (";\n\n" + "%*s if (", + indent, ""); + comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s")); + printf (")\n" + "%*s return %s;\n", + indent, "", + option[TYPE] ? "wordptr" : "s"); + if (option[LENTABLE]) + { + indent -= 4; + printf ("%*s }\n", + indent, ""); + } + if (option[LENTABLE]) + printf ("%*s lengthptr++;\n", + indent, ""); + printf ("%*s wordptr++;\n" + "%*s }\n" + "%*s }\n", + indent, "", indent, "", indent, ""); + } + printf ("%*s}\n", + indent, ""); + } + else + { + int indent = 8; + if (option[LENTABLE]) + { + printf ("%*sif (len == %s[key])\n", + indent, "", option.get_lengthtable_name ()); + indent += 2; + } + + if (option[SHAREDLIB]) + { + if (!option[LENTABLE]) + { + printf ("%*s{\n" + "%*s register int o = %s[key]", + indent, "", + indent, "", option.get_wordlist_name ()); + if (option[TYPE]) + printf (".%s", option.get_slot_name ()); + printf (";\n" + "%*s if (o >= 0)\n" + "%*s {\n", + indent, "", + indent, ""); + indent += 4; + printf ("%*s register %schar *s = o", + indent, "", const_always); + } + else + { + /* No need for the (o >= 0) test, because the + (len == lengthtable[key]) test already guarantees that + key points to nonempty table entry. */ + printf ("%*s{\n" + "%*s register %schar *s = %s[key]", + indent, "", + indent, "", const_always, + option.get_wordlist_name ()); + if (option[TYPE]) + printf (".%s", option.get_slot_name ()); + } + printf (" + %s", + option.get_stringpool_name ()); + } + else + { + printf ("%*s{\n" + "%*s register %schar *s = %s[key]", + indent, "", + indent, "", const_always, option.get_wordlist_name ()); + if (option[TYPE]) + printf (".%s", option.get_slot_name ()); + } + + printf (";\n\n" + "%*s if (", + indent, ""); + if (!option[SHAREDLIB] && option[NULLSTRINGS]) + printf ("s && "); + comparison.output_comparison (Output_Expr1 ("str"), Output_Expr1 ("s")); + printf (")\n" + "%*s return ", + indent, ""); + if (option[TYPE]) + printf ("&%s[key]", option.get_wordlist_name ()); + else + printf ("s"); + printf (";\n"); + if (option[SHAREDLIB] && !option[LENTABLE]) + { + indent -= 4; + printf ("%*s }\n", + indent, ""); + } + printf ("%*s}\n", + indent, ""); + } + } + printf (" }\n" + " return 0;\n"); +} + +/* Generates C code for the lookup function. */ + +void +Output::output_lookup_function () const +{ + /* Output the function's head. */ + if (option[KRC] | option[C] | option[ANSIC]) + /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 + inline semantics, unless -fgnu89-inline is used. It defines a macro + __GNUC_STDC_INLINE__ to indicate this situation. */ + printf ("#ifdef __GNUC__\n" + "__inline\n" + "#ifdef __GNUC_STDC_INLINE__\n" + "__attribute__ ((__gnu_inline__))\n" + "#endif\n" + "#endif\n"); + + printf ("%s%s\n", + const_for_struct, _return_type); + if (option[CPLUSPLUS]) + printf ("%s::", option.get_class_name ()); + printf ("%s ", option.get_function_name ()); + printf (option[KRC] ? + "(str, len)\n" + " register char *str;\n" + " register unsigned int len;\n" : + option[C] ? + "(str, len)\n" + " register const char *str;\n" + " register unsigned int len;\n" : + option[ANSIC] | option[CPLUSPLUS] ? + "(register const char *str, register unsigned int len)\n" : + ""); + + /* Output the function's body. */ + printf ("{\n"); + + if (option[ENUM] && !option[GLOBAL]) + { + Output_Enum style (" "); + output_constants (style); + } + + if (option[SHAREDLIB] && !(option[GLOBAL] || option[TYPE])) + output_lookup_pools (); + if (!option[GLOBAL]) + output_lookup_tables (); + + if (option[LENTABLE]) + output_lookup_function_body (Output_Compare_Memcmp ()); + else + { + if (option[COMP]) + output_lookup_function_body (Output_Compare_Strncmp ()); + else + output_lookup_function_body (Output_Compare_Strcmp ()); + } + + printf ("}\n"); +} + +/* ------------------------------------------------------------------------- */ + +/* Generates the hash function and the key word recognizer function + based upon the user's Options. */ + +void +Output::output () +{ + compute_min_max (); + + if (option[C] | option[ANSIC] | option[CPLUSPLUS]) + { + const_always = "const "; + const_readonly_array = (option[CONST] ? "const " : ""); + const_for_struct = ((option[CONST] && option[TYPE]) ? "const " : ""); + } + else + { + const_always = ""; + const_readonly_array = ""; + const_for_struct = ""; + } + + if (!option[TYPE]) + { + _return_type = (const_always[0] ? "const char *" : "char *"); + _struct_tag = (const_always[0] ? "const char *" : "char *"); + } + + _wordlist_eltype = (option[SHAREDLIB] && !option[TYPE] ? "int" : _struct_tag); + + printf ("/* "); + if (option[KRC]) + printf ("KR-C"); + else if (option[C]) + printf ("C"); + else if (option[ANSIC]) + printf ("ANSI-C"); + else if (option[CPLUSPLUS]) + printf ("C++"); + printf (" code produced by gperf version %s */\n", version_string); + option.print_options (); + printf ("\n"); + if (!option[POSITIONS]) + { + printf ("/* Computed positions: -k'"); + _key_positions.print(); + printf ("' */\n"); + } + printf ("\n"); + + if (_charset_dependent + && (_key_positions.get_size() > 0 || option[UPPERLOWER])) + { + /* The generated tables assume that the execution character set is + based on ISO-646, not EBCDIC. */ + printf ("#if !((' ' == 32) && ('!' == 33) && ('\"' == 34) && ('#' == 35) \\\n" + " && ('%%' == 37) && ('&' == 38) && ('\\'' == 39) && ('(' == 40) \\\n" + " && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \\\n" + " && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \\\n" + " && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \\\n" + " && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \\\n" + " && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \\\n" + " && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \\\n" + " && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \\\n" + " && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \\\n" + " && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \\\n" + " && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \\\n" + " && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \\\n" + " && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \\\n" + " && ('Z' == 90) && ('[' == 91) && ('\\\\' == 92) && (']' == 93) \\\n" + " && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \\\n" + " && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \\\n" + " && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \\\n" + " && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \\\n" + " && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \\\n" + " && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \\\n" + " && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \\\n" + " && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))\n" + "/* The character set is not based on ISO-646. */\n"); + printf ("%s \"gperf generated tables don't work with this execution character set. Please report a bug to .\"\n", option[KRC] || option[C] ? "error" : "#error"); + printf ("#endif\n\n"); + } + + if (_verbatim_declarations < _verbatim_declarations_end) + { + output_line_directive (_verbatim_declarations_lineno); + fwrite (_verbatim_declarations, 1, + _verbatim_declarations_end - _verbatim_declarations, stdout); + } + + if (option[TYPE] && !option[NOTYPE]) /* Output type declaration now, reference it later on.... */ + { + output_line_directive (_struct_decl_lineno); + printf ("%s\n", _struct_decl); + } + + if (option[INCLUDE]) + printf ("#include \n"); /* Declare strlen(), strcmp(), strncmp(). */ + + if (!option[ENUM]) + { + Output_Defines style; + output_constants (style); + } + else if (option[GLOBAL]) + { + Output_Enum style (""); + output_constants (style); + } + + printf ("/* maximum key range = %d, duplicates = %d */\n\n", + _max_hash_value - _min_hash_value + 1, _total_duplicates); + + if (option[UPPERLOWER]) + { + #if USE_DOWNCASE_TABLE + output_upperlower_table (); + #endif + + if (option[LENTABLE]) + output_upperlower_memcmp (); + else + { + if (option[COMP]) + output_upperlower_strncmp (); + else + output_upperlower_strcmp (); + } + } + + if (option[CPLUSPLUS]) + printf ("class %s\n" + "{\n" + "private:\n" + " static inline unsigned int %s (const char *str, unsigned int len);\n" + "public:\n" + " static %s%s%s (const char *str, unsigned int len);\n" + "};\n" + "\n", + option.get_class_name (), option.get_hash_name (), + const_for_struct, _return_type, option.get_function_name ()); + + output_hash_function (); + + if (option[SHAREDLIB] && (option[GLOBAL] || option[TYPE])) + output_lookup_pools (); + if (option[GLOBAL]) + output_lookup_tables (); + + output_lookup_function (); + + if (_verbatim_code < _verbatim_code_end) + { + output_line_directive (_verbatim_code_lineno); + fwrite (_verbatim_code, 1, _verbatim_code_end - _verbatim_code, stdout); + } + + fflush (stdout); +} diff --git a/contrib/gperf/src/output.h b/contrib/gperf/src/output.h new file mode 100644 index 000000000000..bb9345bb9db0 --- /dev/null +++ b/contrib/gperf/src/output.h @@ -0,0 +1,154 @@ +/* This may look like C code, but it is really -*- C++ -*- */ + +/* Output routines. + + Copyright (C) 1989-1998, 2000, 2002-2003 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef output_h +#define output_h 1 + +#include "keyword-list.h" +#include "positions.h" + +/* OSF/1 cxx needs these forward declarations. */ +struct Output_Constants; +struct Output_Compare; + +class Output +{ +public: + /* Constructor. */ + Output (KeywordExt_List *head, + const char *struct_decl, + unsigned int struct_decl_lineno, + const char *return_type, + const char *struct_tag, + const char *verbatim_declarations, + const char *verbatim_declarations_end, + unsigned int verbatim_declarations_lineno, + const char *verbatim_code, + const char *verbatim_code_end, + unsigned int verbatim_code_lineno, + bool charset_dependent, + int total_keys, + int max_key_len, int min_key_len, + const Positions& positions, + const unsigned int *alpha_inc, + int total_duplicates, + unsigned int alpha_size, + const int *asso_values); + + /* Generates the hash function and the key word recognizer function. */ + void output (); + +private: + + /* Computes the minimum and maximum hash values, and stores them + in _min_hash_value and _max_hash_value. */ + void compute_min_max (); + + /* Returns the number of different hash values. */ + int num_hash_values () const; + + /* Outputs the maximum and minimum hash values etc. */ + void output_constants (struct Output_Constants&) const; + + /* Generates a C expression for an asso_values[] reference. */ + void output_asso_values_ref (int pos) const; + + /* Generates C code for the hash function that returns the + proper encoding for each keyword. */ + void output_hash_function () const; + + /* Prints out a table of keyword lengths, for use with the + comparison code in generated function 'in_word_set'. */ + void output_keylength_table () const; + + /* Prints out the string pool, containing the strings of the keyword table. + */ + void output_string_pool () const; + + /* Prints out the array containing the keywords for the hash function. */ + void output_keyword_table () const; + + /* Generates the large, sparse table that maps hash values into + the smaller, contiguous range of the keyword table. */ + void output_lookup_array () const; + + /* Generate all pools needed for the lookup function. */ + void output_lookup_pools () const; + + /* Generate all the tables needed for the lookup function. */ + void output_lookup_tables () const; + + /* Generates C code to perform the keyword lookup. */ + void output_lookup_function_body (const struct Output_Compare&) const; + + /* Generates C code for the lookup function. */ + void output_lookup_function () const; + + /* Linked list of keywords. */ + KeywordExt_List * _head; + + /* Declaration of struct type for a keyword and its attributes. */ + const char * const _struct_decl; + unsigned int const _struct_decl_lineno; + /* Pointer to return type for lookup function. */ + const char * _return_type; + /* Shorthand for user-defined struct tag type. */ + const char * _struct_tag; + /* Element type of keyword array. */ + const char * _wordlist_eltype; + /* The C code from the declarations section. */ + const char * const _verbatim_declarations; + const char * const _verbatim_declarations_end; + unsigned int const _verbatim_declarations_lineno; + /* The C code from the end of the file. */ + const char * const _verbatim_code; + const char * const _verbatim_code_end; + unsigned int const _verbatim_code_lineno; + /* Whether the keyword chars would have different values in a different + character set. */ + bool _charset_dependent; + /* Total number of keys, counting duplicates. */ + int const _total_keys; + /* Maximum length of the longest keyword. */ + int const _max_key_len; + /* Minimum length of the shortest keyword. */ + int const _min_key_len; + /* Key positions. */ + Positions const _key_positions; + /* Adjustments to add to bytes add specific key positions. */ + const unsigned int * const _alpha_inc; + /* Total number of duplicate hash values. */ + int const _total_duplicates; + /* Minimum hash value for all keywords. */ + int _min_hash_value; + /* Maximum hash value for all keywords. */ + int _max_hash_value; + /* Size of alphabet. */ + unsigned int const _alpha_size; + /* Value associated with each character. */ + const int * const _asso_values; +}; + +#endif diff --git a/contrib/gperf/src/positions.cc b/contrib/gperf/src/positions.cc new file mode 100644 index 000000000000..d023fdb280f9 --- /dev/null +++ b/contrib/gperf/src/positions.cc @@ -0,0 +1,177 @@ +/* A set of byte positions. + Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Specification. */ +#include "positions.h" + +#include +#include /* declares exit() */ +#include + +/* ---------------------------- Class Positions ---------------------------- */ + +/* Set operations. Assumes the array is in reverse order. */ + +bool +Positions::contains (int pos) const +{ + unsigned int count = _size; + const int *p = _positions + _size - 1; + + for (; count > 0; p--, count--) + { + if (*p == pos) + return true; + if (*p > pos) + break; + } + return false; +} + +void +Positions::add (int pos) +{ + set_useall (false); + + unsigned int count = _size; + + if (count == MAX_SIZE) + { + fprintf (stderr, "Positions::add internal error: overflow\n"); + exit (1); + } + + int *p = _positions + _size - 1; + + for (; count > 0; p--, count--) + { + if (*p == pos) + { + fprintf (stderr, "Positions::add internal error: duplicate\n"); + exit (1); + } + if (*p > pos) + break; + p[1] = p[0]; + } + p[1] = pos; + _size++; +} + +void +Positions::remove (int pos) +{ + set_useall (false); + + unsigned int count = _size; + if (count > 0) + { + int *p = _positions + _size - 1; + + if (*p == pos) + { + _size--; + return; + } + if (*p < pos) + { + int prev = *p; + + for (;;) + { + p--; + count--; + if (count == 0) + break; + if (*p == pos) + { + *p = prev; + _size--; + return; + } + if (*p > pos) + break; + int curr = *p; + *p = prev; + prev = curr; + } + } + } + fprintf (stderr, "Positions::remove internal error: not found\n"); + exit (1); +} + +/* Output in external syntax. */ +void +Positions::print () const +{ + if (_useall) + printf ("*"); + else + { + bool first = true; + bool seen_LASTCHAR = false; + unsigned int count = _size; + const int *p = _positions + _size - 1; + + for (; count > 0; p--) + { + count--; + if (*p == LASTCHAR) + seen_LASTCHAR = true; + else + { + if (!first) + printf (","); + printf ("%d", *p + 1); + if (count > 0 && p[-1] == *p + 1) + { + printf ("-"); + do + { + p--; + count--; + } + while (count > 0 && p[-1] == *p + 1); + printf ("%d", *p + 1); + } + first = false; + } + } + if (seen_LASTCHAR) + { + if (!first) + printf (","); + printf ("$"); + } + } +} + +/* ------------------------------------------------------------------------- */ + +#ifndef __OPTIMIZE__ + +#define INLINE /* not inline */ +#include "positions.icc" +#undef INLINE + +#endif /* not defined __OPTIMIZE__ */ diff --git a/contrib/gperf/src/positions.h b/contrib/gperf/src/positions.h new file mode 100644 index 000000000000..596844f7b858 --- /dev/null +++ b/contrib/gperf/src/positions.h @@ -0,0 +1,175 @@ +/* This may look like C code, but it is really -*- C++ -*- */ + +/* A set of byte positions. + + Copyright (C) 1989-1998, 2000, 2002, 2005 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef positions_h +#define positions_h 1 + +/* Classes defined below. */ +class PositionIterator; +class PositionReverseIterator; + +/* This class denotes a set of byte positions, used to access a keyword. */ + +class Positions +{ + friend class PositionIterator; + friend class PositionReverseIterator; +public: + /* Denotes the last char of a keyword, depending on the keyword's length. */ + enum { LASTCHAR = -1 }; + + /* Maximum key position specifiable by the user, 1-based. + Note that MAX_KEY_POS-1 must fit into the element type of _positions[], + below. */ + enum { MAX_KEY_POS = 255 }; + + /* Maximum possible size. Since duplicates are eliminated and the possible + 0-based positions are -1 .. MAX_KEY_POS-1, this is: */ + enum { MAX_SIZE = MAX_KEY_POS + 1 }; + + /* Constructors. */ + Positions (); + Positions (int pos1); + Positions (int pos1, int pos2); + + /* Copy constructor. */ + Positions (const Positions& src); + + /* Assignment operator. */ + Positions& operator= (const Positions& src); + + /* Accessors. */ + bool is_useall () const; + int operator[] (unsigned int index) const; + unsigned int get_size () const; + + /* Write access. */ + void set_useall (bool useall); + int * pointer (); + void set_size (unsigned int size); + + /* Sorts the array in reverse order. + Returns true if there are no duplicates, false otherwise. */ + bool sort (); + + /* Creates an iterator, returning the positions in descending order. */ + PositionIterator iterator () const; + /* Creates an iterator, returning the positions in descending order, + that apply to strings of length <= maxlen. */ + PositionIterator iterator (int maxlen) const; + /* Creates an iterator, returning the positions in ascending order. */ + PositionReverseIterator reviterator () const; + /* Creates an iterator, returning the positions in ascending order, + that apply to strings of length <= maxlen. */ + PositionReverseIterator reviterator (int maxlen) const; + + /* Set operations. Assumes the array is in reverse order. */ + bool contains (int pos) const; + void add (int pos); + void remove (int pos); + + /* Output in external syntax. */ + void print () const; + +private: + /* The special case denoted by '*'. */ + bool _useall; + /* Number of positions. */ + unsigned int _size; + /* Array of positions. 0 for the first char, 1 for the second char etc., + LASTCHAR for the last char. */ + int _positions[MAX_SIZE]; +}; + +/* This class denotes an iterator through a set of byte positions. */ + +class PositionIterator +{ + friend class Positions; +public: + /* Copy constructor. */ + PositionIterator (const PositionIterator& src); + + /* End of iteration marker. */ + enum { EOS = -2 }; + + /* Retrieves the next position, or EOS past the end. */ + int next (); + + /* Returns the number of remaining positions, i.e. how often next() will + return a value != EOS. */ + unsigned int remaining () const; + +private: + /* Initializes an iterator through POSITIONS. */ + PositionIterator (Positions const& positions); + /* Initializes an iterator through POSITIONS, ignoring positions >= maxlen. */ + PositionIterator (Positions const& positions, int maxlen); + + const Positions& _set; + unsigned int _index; +}; + +/* This class denotes an iterator in reverse direction through a set of + byte positions. */ + +class PositionReverseIterator +{ + friend class Positions; +public: + /* Copy constructor. */ + PositionReverseIterator (const PositionReverseIterator& src); + + /* End of iteration marker. */ + enum { EOS = -2 }; + + /* Retrieves the next position, or EOS past the end. */ + int next (); + + /* Returns the number of remaining positions, i.e. how often next() will + return a value != EOS. */ + unsigned int remaining () const; + +private: + /* Initializes an iterator through POSITIONS. */ + PositionReverseIterator (Positions const& positions); + /* Initializes an iterator through POSITIONS, ignoring positions >= maxlen. */ + PositionReverseIterator (Positions const& positions, int maxlen); + + const Positions& _set; + unsigned int _index; + unsigned int _minindex; +}; + +#ifdef __OPTIMIZE__ + +#include +#define INLINE inline +#include "positions.icc" +#undef INLINE + +#endif + +#endif diff --git a/contrib/gperf/src/positions.icc b/contrib/gperf/src/positions.icc new file mode 100644 index 000000000000..c0be81b7c00c --- /dev/null +++ b/contrib/gperf/src/positions.icc @@ -0,0 +1,285 @@ +/* Inline Functions for positions.{h,cc}. + + Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +// This needs: +//#include + +/* ---------------------------- Class Positions ---------------------------- */ + +/* Constructors. */ + +INLINE +Positions::Positions () + : _useall (false), + _size (0) +{ +} + +INLINE +Positions::Positions (int pos1) + : _useall (false), + _size (1) +{ + _positions[0] = pos1; +} + +INLINE +Positions::Positions (int pos1, int pos2) + : _useall (false), + _size (2) +{ + _positions[0] = pos1; + _positions[1] = pos2; +} + +/* Copy constructor. */ + +INLINE +Positions::Positions (const Positions& src) + : _useall (src._useall), + _size (src._size) +{ + memcpy (_positions, src._positions, _size * sizeof (_positions[0])); +} + +/* Assignment operator. */ + +INLINE Positions& +Positions::operator= (const Positions& src) +{ + _useall = src._useall; + _size = src._size; + memcpy (_positions, src._positions, _size * sizeof (_positions[0])); + return *this; +} + +/* Accessors. */ + +INLINE bool +Positions::is_useall () const +{ + return _useall; +} + +INLINE int +Positions::operator[] (unsigned int index) const +{ + return _positions[index]; +} + +INLINE unsigned int +Positions::get_size () const +{ + return _size; +} + +/* Write access. */ + +INLINE void +Positions::set_useall (bool useall) +{ + _useall = useall; + if (useall) + { + /* The positions are 0, 1, ..., MAX_KEY_POS-1, in descending order. */ + _size = MAX_KEY_POS; + int *ptr = _positions; + for (int i = MAX_KEY_POS - 1; i >= 0; i--) + *ptr++ = i; + } +} + +INLINE int * +Positions::pointer () +{ + return _positions; +} + +INLINE void +Positions::set_size (unsigned int size) +{ + _size = size; +} + +/* Sorts the array in reverse order. + Returns true if there are no duplicates, false otherwise. */ +INLINE bool +Positions::sort () +{ + if (_useall) + return true; + + /* Bubble sort. */ + bool duplicate_free = true; + int *base = _positions; + unsigned int len = _size; + + for (unsigned int i = 1; i < len; i++) + { + unsigned int j; + int tmp; + + for (j = i, tmp = base[j]; j > 0 && tmp >= base[j - 1]; j--) + if ((base[j] = base[j - 1]) == tmp) /* oh no, a duplicate!!! */ + duplicate_free = false; + + base[j] = tmp; + } + + return duplicate_free; +} + +/* Creates an iterator, returning the positions in descending order. */ +INLINE PositionIterator +Positions::iterator () const +{ + return PositionIterator (*this); +} + +/* Creates an iterator, returning the positions in descending order, + that apply to strings of length <= maxlen. */ +INLINE PositionIterator +Positions::iterator (int maxlen) const +{ + return PositionIterator (*this, maxlen); +} + +/* Creates an iterator, returning the positions in ascending order. */ +INLINE PositionReverseIterator +Positions::reviterator () const +{ + return PositionReverseIterator (*this); +} + +/* Creates an iterator, returning the positions in ascending order, + that apply to strings of length <= maxlen. */ +INLINE PositionReverseIterator +Positions::reviterator (int maxlen) const +{ + return PositionReverseIterator (*this, maxlen); +} + +/* ------------------------- Class PositionIterator ------------------------ */ + +/* Initializes an iterator through POSITIONS. */ +INLINE +PositionIterator::PositionIterator (Positions const& positions) + : _set (positions), + _index (0) +{ +} + +/* Initializes an iterator through POSITIONS, ignoring positions >= maxlen. */ +INLINE +PositionIterator::PositionIterator (Positions const& positions, int maxlen) + : _set (positions) +{ + if (positions._useall) + _index = (maxlen <= Positions::MAX_KEY_POS ? Positions::MAX_KEY_POS - maxlen : 0); + else + { + unsigned int index; + for (index = 0; + index < positions._size && positions._positions[index] >= maxlen; + index++) + ; + _index = index; + } +} + +/* Retrieves the next position, or EOS past the end. */ +INLINE int +PositionIterator::next () +{ + return (_index < _set._size ? _set._positions[_index++] : EOS); +} + +/* Returns the number of remaining positions, i.e. how often next() will + return a value != EOS. */ +INLINE unsigned int +PositionIterator::remaining () const +{ + return _set._size - _index; +} + +/* Copy constructor. */ +INLINE +PositionIterator::PositionIterator (const PositionIterator& src) + : _set (src._set), + _index (src._index) +{ +} + +/* --------------------- Class PositionReverseIterator --------------------- */ + +/* Initializes an iterator through POSITIONS. */ +INLINE +PositionReverseIterator::PositionReverseIterator (Positions const& positions) + : _set (positions), + _index (_set._size), + _minindex (0) +{ +} + +/* Initializes an iterator through POSITIONS, ignoring positions >= maxlen. */ +INLINE +PositionReverseIterator::PositionReverseIterator (Positions const& positions, int maxlen) + : _set (positions), + _index (_set._size) +{ + if (positions._useall) + _minindex = (maxlen <= Positions::MAX_KEY_POS ? Positions::MAX_KEY_POS - maxlen : 0); + else + { + unsigned int index; + for (index = 0; + index < positions._size && positions._positions[index] >= maxlen; + index++) + ; + _minindex = index; + } +} + +/* Retrieves the next position, or EOS past the end. */ +INLINE int +PositionReverseIterator::next () +{ + return (_index > _minindex ? _set._positions[--_index] : EOS); +} + +/* Returns the number of remaining positions, i.e. how often next() will + return a value != EOS. */ +INLINE unsigned int +PositionReverseIterator::remaining () const +{ + return _index - _minindex; +} + +/* Copy constructor. */ +INLINE +PositionReverseIterator::PositionReverseIterator (const PositionReverseIterator& src) + : _set (src._set), + _index (src._index), + _minindex (src._minindex) +{ +} diff --git a/contrib/gperf/src/read-line.cc b/contrib/gperf/src/read-line.cc deleted file mode 100644 index 8cb0971cb6b9..000000000000 --- a/contrib/gperf/src/read-line.cc +++ /dev/null @@ -1,97 +0,0 @@ -/* Correctly reads an arbitrarily size string. - - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#include "read-line.h" - -#include -#include /* declares memcpy() */ -#include "options.h" -#include "trace.h" - -/* Recursively fills up the buffer. */ - -#define CHUNK_SIZE 4096 - -/* CHUNKS is the number of chunks (each of size CHUNK_SIZE) which have - already been read and which are temporarily stored on the stack. - This function reads the remainder of the line, allocates a buffer - for the entire line, fills the part beyond &buffer[chunks*CHUNK_SIZE], - and returns &buffer[chunks*CHUNK_SIZE]. */ - -char * -Read_Line::readln_aux (int chunks) -{ - T (Trace t ("Read_Line::readln_aux");) -#if LARGE_STACK - char buf[CHUNK_SIZE]; -#else - // Note: we don't use new, because that invokes a custom operator new. - char *buf = (char*)malloc(CHUNK_SIZE); - if (buf == NULL) - abort (); -#endif - char *bufptr = buf; - char *ptr; - int c; - - while (c = getc (fp), c != EOF && c != '\n') /* fill the current buffer */ - { - *bufptr++ = c; - if (bufptr - buf == CHUNK_SIZE) - { - if ((ptr = readln_aux (chunks + 1)) != NULL) - - /* prepend remainder to ptr buffer */ - { - ptr -= CHUNK_SIZE; - memcpy (ptr, buf, CHUNK_SIZE); - } - - goto done; - } - } - if (c == EOF && bufptr == buf && chunks == 0) - ptr = NULL; - else - { - size_t s1 = chunks * CHUNK_SIZE; - size_t s2 = bufptr - buf; - - ptr = new char[s1+s2+1]; - ptr += s1; - ptr[s2] = '\0'; - memcpy (ptr, buf, s2); - } - done: -#if !LARGE_STACK - free (buf); -#endif - - return ptr; -} - -#ifndef __OPTIMIZE__ - -#define INLINE /* not inline */ -#include "read-line.icc" -#undef INLINE - -#endif /* not defined __OPTIMIZE__ */ diff --git a/contrib/gperf/src/read-line.h b/contrib/gperf/src/read-line.h deleted file mode 100644 index b243c84749b5..000000000000 --- a/contrib/gperf/src/read-line.h +++ /dev/null @@ -1,53 +0,0 @@ -/* This may look like C code, but it is really -*- C++ -*- */ - -/* Reads arbitrarily long string from input file, returning it as a - dynamically allocated buffer. - - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -/* Returns a pointer to an arbitrary length string. Returns NULL on error or EOF - The storage for the string is dynamically allocated by new. */ - -#ifndef read_line_h -#define read_line_h 1 - -#include - -class Read_Line -{ -private: - char *readln_aux (int chunks); - FILE *fp; /* FILE pointer to the input stream. */ - -public: - Read_Line (FILE *stream = stdin) : fp (stream) {} - char *get_line (void); -}; - -#ifdef __OPTIMIZE__ - -#include "trace.h" -#define INLINE inline -#include "read-line.icc" -#undef INLINE - -#endif - -#endif diff --git a/contrib/gperf/src/read-line.icc b/contrib/gperf/src/read-line.icc deleted file mode 100644 index cdb5bf6f8c0a..000000000000 --- a/contrib/gperf/src/read-line.icc +++ /dev/null @@ -1,47 +0,0 @@ -/* Inline Functions for read-line.{h,cc}. - - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -// This needs: -//#include -//#include "trace.h" - -/* Returns the ``next'' line, ignoring comments beginning with '#'. */ -INLINE char * -Read_Line::get_line (void) -{ - T (Trace t ("Read_Line::get_line");) - int c; - - while ((c = getc (fp)) == '#') - { - while (c = getc (fp), c != EOF && c != '\n') - ; - - if (c == EOF) - return (char *)0; - } - - if (c == EOF) - return (char *)0; - - ungetc (c, stdin); - return readln_aux (0); -} diff --git a/contrib/gperf/src/search.cc b/contrib/gperf/src/search.cc new file mode 100644 index 000000000000..c2459701036d --- /dev/null +++ b/contrib/gperf/src/search.cc @@ -0,0 +1,1684 @@ +/* Search algorithm. + Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Specification. */ +#include "search.h" + +#include +#include /* declares exit(), rand(), srand() */ +#include /* declares memset(), memcmp() */ +#include /* declares time() */ +#include /* declares exp() */ +#include /* defines INT_MIN, INT_MAX, UINT_MAX */ +#include "options.h" +#include "hash-table.h" +#include "config.h" + +/* ============================== Portability ============================== */ + +/* Assume ISO C++ 'for' scoping rule. */ +#define for if (0) ; else for + +/* Dynamically allocated array with dynamic extent: + + Example: + DYNAMIC_ARRAY (my_array, int, n); + ... + FREE_DYNAMIC_ARRAY (my_array); + + Attention: depending on your implementation my_array is either the array + itself or a pointer to the array! Always use my_array only as expression! + */ +#if HAVE_DYNAMIC_ARRAY + #define DYNAMIC_ARRAY(var,eltype,size) eltype var[size] + #define FREE_DYNAMIC_ARRAY(var) +#else + #define DYNAMIC_ARRAY(var,eltype,size) eltype *var = new eltype[size] + #define FREE_DYNAMIC_ARRAY(var) delete[] var +#endif + +/* ================================ Theory ================================= */ + +/* The general form of the hash function is + + hash (keyword) = sum (asso_values[keyword[i] + alpha_inc[i]] : i in Pos) + + len (keyword) + + where Pos is a set of byte positions, + each alpha_inc[i] is a nonnegative integer, + each asso_values[c] is a nonnegative integer, + len (keyword) is the keyword's length if !option[NOLENGTH], or 0 otherwise. + + Theorem 1: If all keywords are different, there is a set Pos such that + all tuples (keyword[i] : i in Pos) are different. + + Theorem 2: If all tuples (keyword[i] : i in Pos) are different, there + are nonnegative integers alpha_inc[i] such that all multisets + {keyword[i] + alpha_inc[i] : i in Pos} are different. + + Define selchars[keyword] := {keyword[i] + alpha_inc[i] : i in Pos}. + + Theorem 3: If all multisets selchars[keyword] are different, there are + nonnegative integers asso_values[c] such that all hash values + sum (asso_values[c] : c in selchars[keyword]) are different. + + Based on these three facts, we find the hash function in three steps: + + Step 1 (Finding good byte positions): + Find a set Pos, as small as possible, such that all tuples + (keyword[i] : i in Pos) are different. + + Step 2 (Finding good alpha increments): + Find nonnegative integers alpha_inc[i], as many of them as possible being + zero, and the others being as small as possible, such that all multisets + {keyword[i] + alpha_inc[i] : i in Pos} are different. + + Step 3 (Finding good asso_values): + Find asso_values[c] such that all hash (keyword) are different. + + In other words, each step finds a projection that is injective on the + given finite set: + proj1 : String --> Map (Pos --> N) + proj2 : Map (Pos --> N) --> Map (Pos --> N) / S(Pos) + proj3 : Map (Pos --> N) / S(Pos) --> N + where + N denotes the set of nonnegative integers, + Map (A --> B) := Hom_Set (A, B) is the set of maps from A to B, and + S(Pos) is the symmetric group over Pos. + + This was the theory for option[NOLENGTH]; if !option[NOLENGTH], slight + modifications apply: + proj1 : String --> Map (Pos --> N) x N + proj2 : Map (Pos --> N) x N --> Map (Pos --> N) / S(Pos) x N + proj3 : Map (Pos --> N) / S(Pos) x N --> N + + For a case-insensitive hash function, the general form is + + hash (keyword) = + sum (asso_values[alpha_unify[keyword[i] + alpha_inc[i]]] : i in Pos) + + len (keyword) + + where alpha_unify[c] is chosen so that an upper/lower case change in + keyword[i] doesn't change alpha_unify[keyword[i] + alpha_inc[i]]. + */ + +/* ==================== Initialization and Preparation ===================== */ + +Search::Search (KeywordExt_List *list) + : _head (list) +{ +} + +void +Search::prepare () +{ + /* Compute the total number of keywords. */ + _total_keys = 0; + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + _total_keys++; + + /* Compute the minimum and maximum keyword length. */ + _max_key_len = INT_MIN; + _min_key_len = INT_MAX; + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + + if (_max_key_len < keyword->_allchars_length) + _max_key_len = keyword->_allchars_length; + if (_min_key_len > keyword->_allchars_length) + _min_key_len = keyword->_allchars_length; + } + + /* Exit program if an empty string is used as keyword, since the comparison + expressions don't work correctly for looking up an empty string. */ + if (_min_key_len == 0) + { + fprintf (stderr, "Empty input keyword is not allowed.\n" + "To recognize an empty input keyword, your code should check for\n" + "len == 0 before calling the gperf generated lookup function.\n"); + exit (1); + } + + /* Exit program if the characters in the keywords are not in the required + range. */ + if (option[SEVENBIT]) + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + + const char *k = keyword->_allchars; + for (int i = keyword->_allchars_length; i > 0; k++, i--) + if (!(static_cast(*k) < 128)) + { + fprintf (stderr, "Option --seven-bit has been specified,\n" + "but keyword \"%.*s\" contains non-ASCII characters.\n" + "Try removing option --seven-bit.\n", + keyword->_allchars_length, keyword->_allchars); + exit (1); + } + } +} + +/* ====================== Finding good byte positions ====================== */ + +/* Computes the upper bound on the indices passed to asso_values[], + assuming no alpha_increments. */ +unsigned int +Search::compute_alpha_size () const +{ + return (option[SEVENBIT] ? 128 : 256); +} + +/* Computes the unification rules between different asso_values[c], + assuming no alpha_increments. */ +unsigned int * +Search::compute_alpha_unify () const +{ + if (option[UPPERLOWER]) + { + /* Uppercase to lowercase mapping. */ + unsigned int alpha_size = compute_alpha_size(); + unsigned int *alpha_unify = new unsigned int[alpha_size]; + for (unsigned int c = 0; c < alpha_size; c++) + alpha_unify[c] = c; + for (unsigned int c = 'A'; c <= 'Z'; c++) + alpha_unify[c] = c + ('a'-'A'); + return alpha_unify; + } + else + /* Identity mapping. */ + return NULL; +} + +/* Initializes each keyword's _selchars array. */ +void +Search::init_selchars_tuple (const Positions& positions, const unsigned int *alpha_unify) const +{ + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + temp->first()->init_selchars_tuple(positions, alpha_unify); +} + +/* Deletes each keyword's _selchars array. */ +void +Search::delete_selchars () const +{ + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + temp->first()->delete_selchars(); +} + +/* Count the duplicate keywords that occur with a given set of positions. + In other words, it returns the difference + # K - # proj1 (K) + where K is the multiset of given keywords. */ +unsigned int +Search::count_duplicates_tuple (const Positions& positions, const unsigned int *alpha_unify) const +{ + /* Run through the keyword list and count the duplicates incrementally. + The result does not depend on the order of the keyword list, thanks to + the formula above. */ + init_selchars_tuple (positions, alpha_unify); + + unsigned int count = 0; + { + Hash_Table representatives (_total_keys, option[NOLENGTH]); + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + if (representatives.insert (keyword)) + count++; + } + } + + delete_selchars (); + + return count; +} + +/* Find good key positions. */ + +void +Search::find_positions () +{ + /* If the user gave the key positions, we use them. */ + if (option[POSITIONS]) + { + _key_positions = option.get_key_positions(); + return; + } + + /* Compute preliminary alpha_unify table. */ + unsigned int *alpha_unify = compute_alpha_unify (); + + /* 1. Find positions that must occur in order to distinguish duplicates. */ + Positions mandatory; + + if (!option[DUP]) + { + for (KeywordExt_List *l1 = _head; l1 && l1->rest(); l1 = l1->rest()) + { + KeywordExt *keyword1 = l1->first(); + for (KeywordExt_List *l2 = l1->rest(); l2; l2 = l2->rest()) + { + KeywordExt *keyword2 = l2->first(); + + /* If keyword1 and keyword2 have the same length and differ + in just one position, and it is not the last character, + this position is mandatory. */ + if (keyword1->_allchars_length == keyword2->_allchars_length) + { + int n = keyword1->_allchars_length; + int i; + for (i = 0; i < n - 1; i++) + { + unsigned char c1 = keyword1->_allchars[i]; + unsigned char c2 = keyword2->_allchars[i]; + if (option[UPPERLOWER]) + { + if (c1 >= 'A' && c1 <= 'Z') + c1 += 'a' - 'A'; + if (c2 >= 'A' && c2 <= 'Z') + c2 += 'a' - 'A'; + } + if (c1 != c2) + break; + } + if (i < n - 1) + { + int j; + for (j = i + 1; j < n; j++) + { + unsigned char c1 = keyword1->_allchars[j]; + unsigned char c2 = keyword2->_allchars[j]; + if (option[UPPERLOWER]) + { + if (c1 >= 'A' && c1 <= 'Z') + c1 += 'a' - 'A'; + if (c2 >= 'A' && c2 <= 'Z') + c2 += 'a' - 'A'; + } + if (c1 != c2) + break; + } + if (j >= n) + { + /* Position i is mandatory. */ + if (!mandatory.contains (i)) + mandatory.add (i); + } + } + } + } + } + } + + /* 2. Add positions, as long as this decreases the duplicates count. */ + int imax = (_max_key_len - 1 < Positions::MAX_KEY_POS - 1 + ? _max_key_len - 1 : Positions::MAX_KEY_POS - 1); + Positions current = mandatory; + unsigned int current_duplicates_count = + count_duplicates_tuple (current, alpha_unify); + for (;;) + { + Positions best; + unsigned int best_duplicates_count = UINT_MAX; + + for (int i = imax; i >= -1; i--) + if (!current.contains (i)) + { + Positions tryal = current; + tryal.add (i); + unsigned int try_duplicates_count = + count_duplicates_tuple (tryal, alpha_unify); + + /* We prefer 'try' to 'best' if it produces less duplicates, + or if it produces the same number of duplicates but with + a more efficient hash function. */ + if (try_duplicates_count < best_duplicates_count + || (try_duplicates_count == best_duplicates_count && i >= 0)) + { + best = tryal; + best_duplicates_count = try_duplicates_count; + } + } + + /* Stop adding positions when it gives no improvement. */ + if (best_duplicates_count >= current_duplicates_count) + break; + + current = best; + current_duplicates_count = best_duplicates_count; + } + + /* 3. Remove positions, as long as this doesn't increase the duplicates + count. */ + for (;;) + { + Positions best; + unsigned int best_duplicates_count = UINT_MAX; + + for (int i = imax; i >= -1; i--) + if (current.contains (i) && !mandatory.contains (i)) + { + Positions tryal = current; + tryal.remove (i); + unsigned int try_duplicates_count = + count_duplicates_tuple (tryal, alpha_unify); + + /* We prefer 'try' to 'best' if it produces less duplicates, + or if it produces the same number of duplicates but with + a more efficient hash function. */ + if (try_duplicates_count < best_duplicates_count + || (try_duplicates_count == best_duplicates_count && i == -1)) + { + best = tryal; + best_duplicates_count = try_duplicates_count; + } + } + + /* Stop removing positions when it gives no improvement. */ + if (best_duplicates_count > current_duplicates_count) + break; + + current = best; + current_duplicates_count = best_duplicates_count; + } + + /* 4. Replace two positions by one, as long as this doesn't increase the + duplicates count. */ + for (;;) + { + Positions best; + unsigned int best_duplicates_count = UINT_MAX; + + for (int i1 = imax; i1 >= -1; i1--) + if (current.contains (i1) && !mandatory.contains (i1)) + for (int i2 = imax; i2 >= -1; i2--) + if (current.contains (i2) && !mandatory.contains (i2) && i2 != i1) + for (int i3 = imax; i3 >= 0; i3--) + if (!current.contains (i3)) + { + Positions tryal = current; + tryal.remove (i1); + tryal.remove (i2); + tryal.add (i3); + unsigned int try_duplicates_count = + count_duplicates_tuple (tryal, alpha_unify); + + /* We prefer 'try' to 'best' if it produces less duplicates, + or if it produces the same number of duplicates but with + a more efficient hash function. */ + if (try_duplicates_count < best_duplicates_count + || (try_duplicates_count == best_duplicates_count + && (i1 == -1 || i2 == -1 || i3 >= 0))) + { + best = tryal; + best_duplicates_count = try_duplicates_count; + } + } + + /* Stop removing positions when it gives no improvement. */ + if (best_duplicates_count > current_duplicates_count) + break; + + current = best; + current_duplicates_count = best_duplicates_count; + } + + /* That's it. Hope it's good enough. */ + _key_positions = current; + + if (option[DEBUG]) + { + /* Print the result. */ + fprintf (stderr, "\nComputed positions: "); + PositionReverseIterator iter = _key_positions.reviterator(); + bool seen_lastchar = false; + bool first = true; + for (int i; (i = iter.next ()) != PositionReverseIterator::EOS; ) + { + if (!first) + fprintf (stderr, ", "); + if (i == Positions::LASTCHAR) + seen_lastchar = true; + else + { + fprintf (stderr, "%d", i + 1); + first = false; + } + } + if (seen_lastchar) + { + if (!first) + fprintf (stderr, ", "); + fprintf (stderr, "$"); + } + fprintf (stderr, "\n"); + } + + /* Free preliminary alpha_unify table. */ + delete[] alpha_unify; +} + +/* Count the duplicate keywords that occur with the found set of positions. + In other words, it returns the difference + # K - # proj1 (K) + where K is the multiset of given keywords. */ +unsigned int +Search::count_duplicates_tuple () const +{ + unsigned int *alpha_unify = compute_alpha_unify (); + unsigned int count = count_duplicates_tuple (_key_positions, alpha_unify); + delete[] alpha_unify; + return count; +} + +/* ===================== Finding good alpha increments ===================== */ + +/* Computes the upper bound on the indices passed to asso_values[]. */ +unsigned int +Search::compute_alpha_size (const unsigned int *alpha_inc) const +{ + unsigned int max_alpha_inc = 0; + for (int i = 0; i < _max_key_len; i++) + if (max_alpha_inc < alpha_inc[i]) + max_alpha_inc = alpha_inc[i]; + return (option[SEVENBIT] ? 128 : 256) + max_alpha_inc; +} + +/* Computes the unification rules between different asso_values[c]. */ +unsigned int * +Search::compute_alpha_unify (const Positions& positions, const unsigned int *alpha_inc) const +{ + if (option[UPPERLOWER]) + { + /* Without alpha increments, we would simply unify + 'A' -> 'a', ..., 'Z' -> 'z'. + But when a keyword contains at position i a character c, + we have the constraint + asso_values[tolower(c) + alpha_inc[i]] == + asso_values[toupper(c) + alpha_inc[i]]. + This introduces a unification + toupper(c) + alpha_inc[i] -> tolower(c) + alpha_inc[i]. + Note that this unification can extend outside the range of + ASCII letters! But still every unified character pair is at + a distance of 'a'-'A' = 32, or (after chained unification) + at a multiple of 32. So in the end the alpha_unify vector has + the form c -> c + 32 * f(c) where f(c) is a nonnegative + integer. */ + unsigned int alpha_size = compute_alpha_size (alpha_inc); + + unsigned int *alpha_unify = new unsigned int[alpha_size]; + for (unsigned int c = 0; c < alpha_size; c++) + alpha_unify[c] = c; + + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + + /* Iterate through the selected character positions. */ + PositionIterator iter = positions.iterator(keyword->_allchars_length); + + for (int i; (i = iter.next ()) != PositionIterator::EOS; ) + { + unsigned int c; + if (i == Positions::LASTCHAR) + c = static_cast(keyword->_allchars[keyword->_allchars_length - 1]); + else if (i < keyword->_allchars_length) + c = static_cast(keyword->_allchars[i]); + else + abort (); + if (c >= 'A' && c <= 'Z') + c += 'a' - 'A'; + if (c >= 'a' && c <= 'z') + { + if (i != Positions::LASTCHAR) + c += alpha_inc[i]; + /* Unify c with c - ('a'-'A'). */ + unsigned int d = alpha_unify[c]; + unsigned int b = c - ('a'-'A'); + for (int a = b; a >= 0 && alpha_unify[a] == b; a -= ('a'-'A')) + alpha_unify[a] = d; + } + } + } + return alpha_unify; + } + else + /* Identity mapping. */ + return NULL; +} + +/* Initializes each keyword's _selchars array. */ +void +Search::init_selchars_multiset (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc) const +{ + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + temp->first()->init_selchars_multiset(positions, alpha_unify, alpha_inc); +} + +/* Count the duplicate keywords that occur with the given set of positions + and a given alpha_inc[] array. + In other words, it returns the difference + # K - # proj2 (proj1 (K)) + where K is the multiset of given keywords. */ +unsigned int +Search::count_duplicates_multiset (const unsigned int *alpha_inc) const +{ + /* Run through the keyword list and count the duplicates incrementally. + The result does not depend on the order of the keyword list, thanks to + the formula above. */ + unsigned int *alpha_unify = compute_alpha_unify (_key_positions, alpha_inc); + init_selchars_multiset (_key_positions, alpha_unify, alpha_inc); + + unsigned int count = 0; + { + Hash_Table representatives (_total_keys, option[NOLENGTH]); + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + if (representatives.insert (keyword)) + count++; + } + } + + delete_selchars (); + delete[] alpha_unify; + + return count; +} + +/* Find good _alpha_inc[]. */ + +void +Search::find_alpha_inc () +{ + /* The goal is to choose _alpha_inc[] such that it doesn't introduce + artificial duplicates. + In other words, the goal is # proj2 (proj1 (K)) = # proj1 (K). */ + unsigned int duplicates_goal = count_duplicates_tuple (); + + /* Start with zero increments. This is sufficient in most cases. */ + unsigned int *current = new unsigned int [_max_key_len]; + for (int i = 0; i < _max_key_len; i++) + current[i] = 0; + unsigned int current_duplicates_count = count_duplicates_multiset (current); + + if (current_duplicates_count > duplicates_goal) + { + /* Look which _alpha_inc[i] we are free to increment. */ + unsigned int nindices; + { + nindices = 0; + PositionIterator iter = _key_positions.iterator(_max_key_len); + for (;;) + { + int key_pos = iter.next (); + if (key_pos == PositionIterator::EOS) + break; + if (key_pos != Positions::LASTCHAR) + nindices++; + } + } + + DYNAMIC_ARRAY (indices, unsigned int, nindices); + { + unsigned int j = 0; + PositionIterator iter = _key_positions.iterator(_max_key_len); + for (;;) + { + int key_pos = iter.next (); + if (key_pos == PositionIterator::EOS) + break; + if (key_pos != Positions::LASTCHAR) + indices[j++] = key_pos; + } + if (!(j == nindices)) + abort (); + } + + /* Perform several rounds of searching for a good alpha increment. + Each round reduces the number of artificial collisions by adding + an increment in a single key position. */ + DYNAMIC_ARRAY (best, unsigned int, _max_key_len); + DYNAMIC_ARRAY (tryal, unsigned int, _max_key_len); + do + { + /* An increment of 1 is not always enough. Try higher increments + also. */ + for (unsigned int inc = 1; ; inc++) + { + unsigned int best_duplicates_count = UINT_MAX; + + for (unsigned int j = 0; j < nindices; j++) + { + memcpy (tryal, current, _max_key_len * sizeof (unsigned int)); + tryal[indices[j]] += inc; + unsigned int try_duplicates_count = + count_duplicates_multiset (tryal); + + /* We prefer 'try' to 'best' if it produces less + duplicates. */ + if (try_duplicates_count < best_duplicates_count) + { + memcpy (best, tryal, _max_key_len * sizeof (unsigned int)); + best_duplicates_count = try_duplicates_count; + } + } + + /* Stop this round when we got an improvement. */ + if (best_duplicates_count < current_duplicates_count) + { + memcpy (current, best, _max_key_len * sizeof (unsigned int)); + current_duplicates_count = best_duplicates_count; + break; + } + } + } + while (current_duplicates_count > duplicates_goal); + FREE_DYNAMIC_ARRAY (tryal); + FREE_DYNAMIC_ARRAY (best); + + if (option[DEBUG]) + { + /* Print the result. */ + fprintf (stderr, "\nComputed alpha increments: "); + bool first = true; + for (unsigned int j = nindices; j-- > 0; ) + if (current[indices[j]] != 0) + { + if (!first) + fprintf (stderr, ", "); + fprintf (stderr, "%u:+%u", + indices[j] + 1, current[indices[j]]); + first = false; + } + fprintf (stderr, "\n"); + } + FREE_DYNAMIC_ARRAY (indices); + } + + _alpha_inc = current; + _alpha_size = compute_alpha_size (_alpha_inc); + _alpha_unify = compute_alpha_unify (_key_positions, _alpha_inc); +} + +/* ======================= Finding good asso_values ======================== */ + +/* Initializes the asso_values[] related parameters. */ + +void +Search::prepare_asso_values () +{ + KeywordExt_List *temp; + + /* Initialize each keyword's _selchars array. */ + init_selchars_multiset(_key_positions, _alpha_unify, _alpha_inc); + + /* Compute the maximum _selchars_length over all keywords. */ + _max_selchars_length = _key_positions.iterator(_max_key_len).remaining(); + + /* Check for duplicates, i.e. keywords with the same _selchars array + (and - if !option[NOLENGTH] - also the same length). + We deal with these by building an equivalence class, so that only + 1 keyword is representative of the entire collection. Only this + representative remains in the keyword list; the others are accessible + through the _duplicate_link chain, starting at the representative. + This *greatly* simplifies processing during later stages of the program. + Set _total_duplicates and _list_len = _total_keys - _total_duplicates. */ + { + _list_len = _total_keys; + _total_duplicates = 0; + /* Make hash table for efficiency. */ + Hash_Table representatives (_list_len, option[NOLENGTH]); + + KeywordExt_List *prev = NULL; /* list node before temp */ + for (temp = _head; temp; ) + { + KeywordExt *keyword = temp->first(); + KeywordExt *other_keyword = representatives.insert (keyword); + KeywordExt_List *garbage = NULL; + + if (other_keyword) + { + _total_duplicates++; + _list_len--; + /* Remove keyword from the main list. */ + prev->rest() = temp->rest(); + garbage = temp; + /* And insert it on other_keyword's duplicate list. */ + keyword->_duplicate_link = other_keyword->_duplicate_link; + other_keyword->_duplicate_link = keyword; + + /* Complain if user hasn't enabled the duplicate option. */ + if (!option[DUP] || option[DEBUG]) + { + fprintf (stderr, "Key link: \"%.*s\" = \"%.*s\", with key set \"", + keyword->_allchars_length, keyword->_allchars, + other_keyword->_allchars_length, other_keyword->_allchars); + for (int j = 0; j < keyword->_selchars_length; j++) + putc (keyword->_selchars[j], stderr); + fprintf (stderr, "\".\n"); + } + } + else + { + keyword->_duplicate_link = NULL; + prev = temp; + } + temp = temp->rest(); + if (garbage) + delete garbage; + } + if (option[DEBUG]) + representatives.dump(); + } + + /* Exit program if duplicates exists and option[DUP] not set, since we + don't want to continue in this case. (We don't want to turn on + option[DUP] implicitly, because the generated code is usually much + slower. */ + if (_total_duplicates) + { + if (option[DUP]) + fprintf (stderr, "%d input keys have identical hash values, examine output carefully...\n", + _total_duplicates); + else + { + fprintf (stderr, "%d input keys have identical hash values,\n", + _total_duplicates); + if (option[POSITIONS]) + fprintf (stderr, "try different key positions or use option -D.\n"); + else + fprintf (stderr, "use option -D.\n"); + exit (1); + } + } + + /* Compute the occurrences of each character in the alphabet. */ + _occurrences = new int[_alpha_size]; + memset (_occurrences, 0, _alpha_size * sizeof (_occurrences[0])); + for (temp = _head; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + const unsigned int *ptr = keyword->_selchars; + for (int count = keyword->_selchars_length; count > 0; ptr++, count--) + _occurrences[*ptr]++; + } + + /* Memory allocation. */ + _asso_values = new int[_alpha_size]; + + int non_linked_length = _list_len; + unsigned int asso_value_max; + + asso_value_max = + static_cast(non_linked_length * option.get_size_multiple()); + /* Round up to the next power of two. This makes it easy to ensure + an _asso_value[c] is >= 0 and < asso_value_max. Also, the jump value + being odd, it guarantees that Search::try_asso_value() will iterate + through different values for _asso_value[c]. */ + if (asso_value_max == 0) + asso_value_max = 1; + asso_value_max |= asso_value_max >> 1; + asso_value_max |= asso_value_max >> 2; + asso_value_max |= asso_value_max >> 4; + asso_value_max |= asso_value_max >> 8; + asso_value_max |= asso_value_max >> 16; + asso_value_max++; + _asso_value_max = asso_value_max; + + /* Given the bound for _asso_values[c], we have a bound for the possible + hash values, as computed in compute_hash(). */ + _max_hash_value = (option[NOLENGTH] ? 0 : _max_key_len) + + (_asso_value_max - 1) * _max_selchars_length; + /* Allocate a sparse bit vector for detection of collisions of hash + values. */ + _collision_detector = new Bool_Array (_max_hash_value + 1); + + if (option[DEBUG]) + { + fprintf (stderr, "total non-linked keys = %d\nmaximum associated value is %d" + "\nmaximum size of generated hash table is %d\n", + non_linked_length, asso_value_max, _max_hash_value); + + int field_width; + + field_width = 0; + { + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + if (field_width < keyword->_selchars_length) + field_width = keyword->_selchars_length; + } + } + + fprintf (stderr, "\ndumping the keyword list without duplicates\n"); + fprintf (stderr, "keyword #, %*s, keyword\n", field_width, "keysig"); + int i = 0; + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + fprintf (stderr, "%9d, ", ++i); + if (field_width > keyword->_selchars_length) + fprintf (stderr, "%*s", field_width - keyword->_selchars_length, ""); + for (int j = 0; j < keyword->_selchars_length; j++) + putc (keyword->_selchars[j], stderr); + fprintf (stderr, ", %.*s\n", + keyword->_allchars_length, keyword->_allchars); + } + fprintf (stderr, "\nend of keyword list\n\n"); + } + + if (option[RANDOM] || option.get_jump () == 0) + /* We will use rand(), so initialize the random number generator. */ + srand (static_cast(time (0))); + + _initial_asso_value = (option[RANDOM] ? -1 : option.get_initial_asso_value ()); + _jump = option.get_jump (); +} + +/* Finds some _asso_values[] that fit. */ + +/* The idea is to choose the _asso_values[] one by one, in a way that + a choice that has been made never needs to be undone later. This + means that we split the work into several steps. Each step chooses + one or more _asso_values[c]. The result of choosing one or more + _asso_values[c] is that the partitioning of the keyword set gets + broader. + Look at this partitioning: After every step, the _asso_values[] of a + certain set C of characters are undetermined. (At the beginning, C + is the set of characters c with _occurrences[c] > 0. At the end, C + is empty.) To each keyword K, we associate the multiset of _selchars + for which the _asso_values[] are undetermined: + K --> K->_selchars intersect C. + Consider two keywords equivalent if their value under this mapping is + the same. This introduces an equivalence relation on the set of + keywords. The equivalence classes partition the keyword set. (At the + beginning, the partition is the finest possible: each K is an equivalence + class by itself, because all K have a different _selchars. At the end, + all K have been merged into a single equivalence class.) + The partition before a step is always a refinement of the partition + after the step. + We choose the steps in such a way that the partition really becomes + broader at each step. (A step that only chooses an _asso_values[c] + without changing the partition is better merged with the previous step, + to avoid useless backtracking.) */ + +struct EquivalenceClass +{ + /* The keywords in this equivalence class. */ + KeywordExt_List * _keywords; + KeywordExt_List * _keywords_last; + /* The number of keywords in this equivalence class. */ + unsigned int _cardinality; + /* The undetermined selected characters for the keywords in this + equivalence class, as a canonically reordered multiset. */ + unsigned int * _undetermined_chars; + unsigned int _undetermined_chars_length; + + EquivalenceClass * _next; +}; + +struct Step +{ + /* The characters whose values are being determined in this step. */ + unsigned int _changing_count; + unsigned int * _changing; + /* Exclusive upper bound for the _asso_values[c] of this step. + A power of 2. */ + unsigned int _asso_value_max; + /* The characters whose values will be determined after this step. */ + bool * _undetermined; + /* The keyword set partition after this step. */ + EquivalenceClass * _partition; + /* The expected number of iterations in this step. */ + double _expected_lower; + double _expected_upper; + + Step * _next; +}; + +static inline bool +equals (const unsigned int *ptr1, const unsigned int *ptr2, unsigned int len) +{ + while (len > 0) + { + if (*ptr1 != *ptr2) + return false; + ptr1++; + ptr2++; + len--; + } + return true; +} + +EquivalenceClass * +Search::compute_partition (bool *undetermined) const +{ + EquivalenceClass *partition = NULL; + EquivalenceClass *partition_last = NULL; + for (KeywordExt_List *temp = _head; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + + /* Compute the undetermined characters for this keyword. */ + unsigned int *undetermined_chars = + new unsigned int[keyword->_selchars_length]; + unsigned int undetermined_chars_length = 0; + + for (int i = 0; i < keyword->_selchars_length; i++) + if (undetermined[keyword->_selchars[i]]) + undetermined_chars[undetermined_chars_length++] = keyword->_selchars[i]; + + /* Look up the equivalence class to which this keyword belongs. */ + EquivalenceClass *equclass; + for (equclass = partition; equclass; equclass = equclass->_next) + if (equclass->_undetermined_chars_length == undetermined_chars_length + && equals (equclass->_undetermined_chars, undetermined_chars, + undetermined_chars_length)) + break; + if (equclass == NULL) + { + equclass = new EquivalenceClass(); + equclass->_keywords = NULL; + equclass->_keywords_last = NULL; + equclass->_cardinality = 0; + equclass->_undetermined_chars = undetermined_chars; + equclass->_undetermined_chars_length = undetermined_chars_length; + equclass->_next = NULL; + if (partition) + partition_last->_next = equclass; + else + partition = equclass; + partition_last = equclass; + } + else + delete[] undetermined_chars; + + /* Add the keyword to the equivalence class. */ + KeywordExt_List *cons = new KeywordExt_List(keyword); + if (equclass->_keywords) + equclass->_keywords_last->rest() = cons; + else + equclass->_keywords = cons; + equclass->_keywords_last = cons; + equclass->_cardinality++; + } + + /* Free some of the allocated memory. The caller doesn't need it. */ + for (EquivalenceClass *cls = partition; cls; cls = cls->_next) + delete[] cls->_undetermined_chars; + + return partition; +} + +static void +delete_partition (EquivalenceClass *partition) +{ + while (partition != NULL) + { + EquivalenceClass *equclass = partition; + partition = equclass->_next; + delete_list (equclass->_keywords); + //delete[] equclass->_undetermined_chars; // already freed above + delete equclass; + } +} + +/* Compute the possible number of collisions when _asso_values[c] is + chosen, leading to the given partition. */ +unsigned int +Search::count_possible_collisions (EquivalenceClass *partition, unsigned int c) const +{ + /* Every equivalence class p is split according to the frequency of + occurrence of c, leading to equivalence classes p1, p2, ... + This leads to (|p|^2 - |p1|^2 - |p2|^2 - ...)/2 possible collisions. + Return the sum of this expression over all equivalence classes. */ + unsigned int sum = 0; + unsigned int m = _max_selchars_length; + DYNAMIC_ARRAY (split_cardinalities, unsigned int, m + 1); + for (EquivalenceClass *cls = partition; cls; cls = cls->_next) + { + for (unsigned int i = 0; i <= m; i++) + split_cardinalities[i] = 0; + + for (KeywordExt_List *temp = cls->_keywords; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + + unsigned int count = 0; + for (int i = 0; i < keyword->_selchars_length; i++) + if (keyword->_selchars[i] == c) + count++; + + split_cardinalities[count]++; + } + + sum += cls->_cardinality * cls->_cardinality; + for (unsigned int i = 0; i <= m; i++) + sum -= split_cardinalities[i] * split_cardinalities[i]; + } + FREE_DYNAMIC_ARRAY (split_cardinalities); + return sum; +} + +/* Test whether adding c to the undetermined characters changes the given + partition. */ +bool +Search::unchanged_partition (EquivalenceClass *partition, unsigned int c) const +{ + for (EquivalenceClass *cls = partition; cls; cls = cls->_next) + { + unsigned int first_count = UINT_MAX; + + for (KeywordExt_List *temp = cls->_keywords; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + + unsigned int count = 0; + for (int i = 0; i < keyword->_selchars_length; i++) + if (keyword->_selchars[i] == c) + count++; + + if (temp == cls->_keywords) + first_count = count; + else if (count != first_count) + /* c would split this equivalence class. */ + return false; + } + } + return true; +} + +void +Search::find_asso_values () +{ + Step *steps; + + /* Determine the steps, starting with the last one. */ + { + bool *undetermined; + bool *determined; + + steps = NULL; + + undetermined = new bool[_alpha_size]; + for (unsigned int c = 0; c < _alpha_size; c++) + undetermined[c] = false; + + determined = new bool[_alpha_size]; + for (unsigned int c = 0; c < _alpha_size; c++) + determined[c] = true; + + for (;;) + { + /* Compute the partition that needs to be refined. */ + EquivalenceClass *partition = compute_partition (undetermined); + + /* Determine the main character to be chosen in this step. + Choosing such a character c has the effect of splitting every + equivalence class (according the the frequency of occurrence of c). + We choose the c with the minimum number of possible collisions, + so that characters which lead to a large number of collisions get + handled early during the search. */ + unsigned int chosen_c; + unsigned int chosen_possible_collisions; + { + unsigned int best_c = 0; + unsigned int best_possible_collisions = UINT_MAX; + for (unsigned int c = 0; c < _alpha_size; c++) + if (_occurrences[c] > 0 && determined[c]) + { + unsigned int possible_collisions = + count_possible_collisions (partition, c); + if (possible_collisions < best_possible_collisions) + { + best_c = c; + best_possible_collisions = possible_collisions; + } + } + if (best_possible_collisions == UINT_MAX) + { + /* All c with _occurrences[c] > 0 are undetermined. We are + are the starting situation and don't need any more step. */ + delete_partition (partition); + break; + } + chosen_c = best_c; + chosen_possible_collisions = best_possible_collisions; + } + + /* We need one more step. */ + Step *step = new Step(); + + step->_undetermined = new bool[_alpha_size]; + memcpy (step->_undetermined, undetermined, _alpha_size*sizeof(bool)); + + step->_partition = partition; + + /* Now determine how the equivalence classes will be before this + step. */ + undetermined[chosen_c] = true; + partition = compute_partition (undetermined); + + /* Now determine which other characters should be determined in this + step, because they will not change the equivalence classes at + this point. It is the set of all c which, for all equivalence + classes, have the same frequency of occurrence in every keyword + of the equivalence class. */ + for (unsigned int c = 0; c < _alpha_size; c++) + if (_occurrences[c] > 0 && determined[c] + && unchanged_partition (partition, c)) + { + undetermined[c] = true; + determined[c] = false; + } + + /* main_c must be one of these. */ + if (determined[chosen_c]) + abort (); + + /* Now the set of changing characters of this step. */ + unsigned int changing_count; + + changing_count = 0; + for (unsigned int c = 0; c < _alpha_size; c++) + if (undetermined[c] && !step->_undetermined[c]) + changing_count++; + + unsigned int *changing = new unsigned int[changing_count]; + changing_count = 0; + for (unsigned int c = 0; c < _alpha_size; c++) + if (undetermined[c] && !step->_undetermined[c]) + changing[changing_count++] = c; + + step->_changing = changing; + step->_changing_count = changing_count; + + step->_asso_value_max = _asso_value_max; + + step->_expected_lower = + exp (static_cast(chosen_possible_collisions) + / static_cast(_max_hash_value)); + step->_expected_upper = + exp (static_cast(chosen_possible_collisions) + / static_cast(_asso_value_max)); + + delete_partition (partition); + + step->_next = steps; + steps = step; + } + + delete[] determined; + delete[] undetermined; + } + + if (option[DEBUG]) + { + unsigned int stepno = 0; + for (Step *step = steps; step; step = step->_next) + { + stepno++; + fprintf (stderr, "Step %u chooses _asso_values[", stepno); + for (unsigned int i = 0; i < step->_changing_count; i++) + { + if (i > 0) + fprintf (stderr, ","); + fprintf (stderr, "'%c'", step->_changing[i]); + } + fprintf (stderr, "], expected number of iterations between %g and %g.\n", + step->_expected_lower, step->_expected_upper); + fprintf (stderr, "Keyword equivalence classes:\n"); + for (EquivalenceClass *cls = step->_partition; cls; cls = cls->_next) + { + fprintf (stderr, "\n"); + for (KeywordExt_List *temp = cls->_keywords; temp; temp = temp->rest()) + { + KeywordExt *keyword = temp->first(); + fprintf (stderr, " %.*s\n", + keyword->_allchars_length, keyword->_allchars); + } + } + fprintf (stderr, "\n"); + } + } + + /* Initialize _asso_values[]. (The value given here matters only + for those c which occur in all keywords with equal multiplicity.) */ + for (unsigned int c = 0; c < _alpha_size; c++) + _asso_values[c] = 0; + + unsigned int stepno = 0; + for (Step *step = steps; step; step = step->_next) + { + stepno++; + + /* Initialize the asso_values[]. */ + unsigned int k = step->_changing_count; + for (unsigned int i = 0; i < k; i++) + { + unsigned int c = step->_changing[i]; + _asso_values[c] = + (_initial_asso_value < 0 ? rand () : _initial_asso_value) + & (step->_asso_value_max - 1); + } + + unsigned int iterations = 0; + DYNAMIC_ARRAY (iter, unsigned int, k); + for (unsigned int i = 0; i < k; i++) + iter[i] = 0; + unsigned int ii = (_jump != 0 ? k - 1 : 0); + + for (;;) + { + /* Test whether these asso_values[] lead to collisions among + the equivalence classes that should be collision-free. */ + bool has_collision = false; + for (EquivalenceClass *cls = step->_partition; cls; cls = cls->_next) + { + /* Iteration Number array is a win, O(1) initialization time! */ + _collision_detector->clear (); + + for (KeywordExt_List *ptr = cls->_keywords; ptr; ptr = ptr->rest()) + { + KeywordExt *keyword = ptr->first(); + + /* Compute the new hash code for the keyword, leaving apart + the yet undetermined asso_values[]. */ + int hashcode; + { + int sum = option[NOLENGTH] ? 0 : keyword->_allchars_length; + const unsigned int *p = keyword->_selchars; + int i = keyword->_selchars_length; + for (; i > 0; p++, i--) + if (!step->_undetermined[*p]) + sum += _asso_values[*p]; + hashcode = sum; + } + + /* See whether it collides with another keyword's hash code, + from the same equivalence class. */ + if (_collision_detector->set_bit (hashcode)) + { + has_collision = true; + break; + } + } + + /* Don't need to continue looking at the other equivalence + classes if we already have found a collision. */ + if (has_collision) + break; + } + + iterations++; + if (!has_collision) + break; + + /* Try other asso_values[]. */ + if (_jump != 0) + { + /* The way we try various values for + asso_values[step->_changing[0],...step->_changing[k-1]] + is like this: + for (bound = 0,1,...) + for (ii = 0,...,k-1) + iter[ii] := bound + iter[0..ii-1] := values <= bound + iter[ii+1..k-1] := values < bound + and + asso_values[step->_changing[i]] = + _initial_asso_value + iter[i] * _jump. + This makes it more likely to find small asso_values[]. + */ + unsigned int bound = iter[ii]; + unsigned int i = 0; + while (i < ii) + { + unsigned int c = step->_changing[i]; + iter[i]++; + _asso_values[c] = + (_asso_values[c] + _jump) & (step->_asso_value_max - 1); + if (iter[i] <= bound) + goto found_next; + _asso_values[c] = + (_asso_values[c] - iter[i] * _jump) + & (step->_asso_value_max - 1); + iter[i] = 0; + i++; + } + i = ii + 1; + while (i < k) + { + unsigned int c = step->_changing[i]; + iter[i]++; + _asso_values[c] = + (_asso_values[c] + _jump) & (step->_asso_value_max - 1); + if (iter[i] < bound) + goto found_next; + _asso_values[c] = + (_asso_values[c] - iter[i] * _jump) + & (step->_asso_value_max - 1); + iter[i] = 0; + i++; + } + /* Switch from one ii to the next. */ + { + unsigned int c = step->_changing[ii]; + _asso_values[c] = + (_asso_values[c] - bound * _jump) + & (step->_asso_value_max - 1); + iter[ii] = 0; + } + /* Here all iter[i] == 0. */ + ii++; + if (ii == k) + { + ii = 0; + bound++; + if (bound == step->_asso_value_max) + { + /* Out of search space! We can either backtrack, or + increase the available search space of this step. + It seems simpler to choose the latter solution. */ + step->_asso_value_max = 2 * step->_asso_value_max; + if (step->_asso_value_max > _asso_value_max) + { + _asso_value_max = step->_asso_value_max; + /* Reinitialize _max_hash_value. */ + _max_hash_value = + (option[NOLENGTH] ? 0 : _max_key_len) + + (_asso_value_max - 1) * _max_selchars_length; + /* Reinitialize _collision_detector. */ + delete _collision_detector; + _collision_detector = + new Bool_Array (_max_hash_value + 1); + } + } + } + { + unsigned int c = step->_changing[ii]; + iter[ii] = bound; + _asso_values[c] = + (_asso_values[c] + bound * _jump) + & (step->_asso_value_max - 1); + } + found_next: ; + } + else + { + /* Random. */ + unsigned int c = step->_changing[ii]; + _asso_values[c] = + (_asso_values[c] + rand ()) & (step->_asso_value_max - 1); + /* Next time, change the next c. */ + ii++; + if (ii == k) + ii = 0; + } + } + FREE_DYNAMIC_ARRAY (iter); + + if (option[DEBUG]) + { + fprintf (stderr, "Step %u chose _asso_values[", stepno); + for (unsigned int i = 0; i < step->_changing_count; i++) + { + if (i > 0) + fprintf (stderr, ","); + fprintf (stderr, "'%c'", step->_changing[i]); + } + fprintf (stderr, "] in %u iterations.\n", iterations); + } + } + + /* Free allocated memory. */ + while (steps != NULL) + { + Step *step = steps; + steps = step->_next; + delete[] step->_changing; + delete[] step->_undetermined; + delete_partition (step->_partition); + delete step; + } +} + +/* Computes a keyword's hash value, relative to the current _asso_values[], + and stores it in keyword->_hash_value. */ + +inline int +Search::compute_hash (KeywordExt *keyword) const +{ + int sum = option[NOLENGTH] ? 0 : keyword->_allchars_length; + + const unsigned int *p = keyword->_selchars; + int i = keyword->_selchars_length; + for (; i > 0; p++, i--) + sum += _asso_values[*p]; + + return keyword->_hash_value = sum; +} + +/* Finds good _asso_values[]. */ + +void +Search::find_good_asso_values () +{ + prepare_asso_values (); + + /* Search for good _asso_values[]. */ + int asso_iteration; + if ((asso_iteration = option.get_asso_iterations ()) == 0) + /* Try only the given _initial_asso_value and _jump. */ + find_asso_values (); + else + { + /* Try different pairs of _initial_asso_value and _jump, in the + following order: + (0, 1) + (1, 1) + (2, 1) (0, 3) + (3, 1) (1, 3) + (4, 1) (2, 3) (0, 5) + (5, 1) (3, 3) (1, 5) + ..... */ + KeywordExt_List *saved_head = _head; + int best_initial_asso_value = 0; + int best_jump = 1; + int *best_asso_values = new int[_alpha_size]; + int best_collisions = INT_MAX; + int best_max_hash_value = INT_MAX; + + _initial_asso_value = 0; _jump = 1; + for (;;) + { + /* Restore the keyword list in its original order. */ + _head = copy_list (saved_head); + /* Find good _asso_values[]. */ + find_asso_values (); + /* Test whether it is the best solution so far. */ + int collisions = 0; + int max_hash_value = INT_MIN; + _collision_detector->clear (); + for (KeywordExt_List *ptr = _head; ptr; ptr = ptr->rest()) + { + KeywordExt *keyword = ptr->first(); + int hashcode = compute_hash (keyword); + if (max_hash_value < hashcode) + max_hash_value = hashcode; + if (_collision_detector->set_bit (hashcode)) + collisions++; + } + if (collisions < best_collisions + || (collisions == best_collisions + && max_hash_value < best_max_hash_value)) + { + memcpy (best_asso_values, _asso_values, + _alpha_size * sizeof (_asso_values[0])); + best_collisions = collisions; + best_max_hash_value = max_hash_value; + } + /* Delete the copied keyword list. */ + delete_list (_head); + + if (--asso_iteration == 0) + break; + /* Prepare for next iteration. */ + if (_initial_asso_value >= 2) + _initial_asso_value -= 2, _jump += 2; + else + _initial_asso_value += _jump, _jump = 1; + } + _head = saved_head; + /* Install the best found asso_values. */ + _initial_asso_value = best_initial_asso_value; + _jump = best_jump; + memcpy (_asso_values, best_asso_values, + _alpha_size * sizeof (_asso_values[0])); + delete[] best_asso_values; + /* The keywords' _hash_value fields are recomputed below. */ + } +} + +/* ========================================================================= */ + +/* Comparison function for sorting by increasing _hash_value. */ +static bool +less_by_hash_value (KeywordExt *keyword1, KeywordExt *keyword2) +{ + return keyword1->_hash_value < keyword2->_hash_value; +} + +/* Sorts the keyword list by hash value. */ + +void +Search::sort () +{ + _head = mergesort_list (_head, less_by_hash_value); +} + +void +Search::optimize () +{ + /* Preparations. */ + prepare (); + + /* Step 1: Finding good byte positions. */ + find_positions (); + + /* Step 2: Finding good alpha increments. */ + find_alpha_inc (); + + /* Step 3: Finding good asso_values. */ + find_good_asso_values (); + + /* Make one final check, just to make sure nothing weird happened.... */ + _collision_detector->clear (); + for (KeywordExt_List *curr_ptr = _head; curr_ptr; curr_ptr = curr_ptr->rest()) + { + KeywordExt *curr = curr_ptr->first(); + unsigned int hashcode = compute_hash (curr); + if (_collision_detector->set_bit (hashcode)) + { + /* This shouldn't happen. proj1, proj2, proj3 must have been + computed to be injective on the given keyword set. */ + fprintf (stderr, + "\nInternal error, unexpected duplicate hash code\n"); + if (option[POSITIONS]) + fprintf (stderr, "try options -m or -r, or use new key positions.\n\n"); + else + fprintf (stderr, "try options -m or -r.\n\n"); + exit (1); + } + } + + /* Sorts the keyword list by hash value. */ + sort (); + + /* Set unused asso_values[c] to max_hash_value + 1. This is not absolutely + necessary, but speeds up the lookup function in many cases of lookup + failure: no string comparison is needed once the hash value of a string + is larger than the hash value of any keyword. */ + int max_hash_value; + { + KeywordExt_List *temp; + for (temp = _head; temp->rest(); temp = temp->rest()) + ; + max_hash_value = temp->first()->_hash_value; + } + for (unsigned int c = 0; c < _alpha_size; c++) + if (_occurrences[c] == 0) + _asso_values[c] = max_hash_value + 1; + + /* Propagate unified asso_values. */ + if (_alpha_unify) + for (unsigned int c = 0; c < _alpha_size; c++) + if (_alpha_unify[c] != c) + _asso_values[c] = _asso_values[_alpha_unify[c]]; +} + +/* Prints out some diagnostics upon completion. */ + +Search::~Search () +{ + delete _collision_detector; + if (option[DEBUG]) + { + fprintf (stderr, "\ndumping occurrence and associated values tables\n"); + + for (unsigned int i = 0; i < _alpha_size; i++) + if (_occurrences[i]) + fprintf (stderr, "asso_values[%c] = %6d, occurrences[%c] = %6d\n", + i, _asso_values[i], i, _occurrences[i]); + + fprintf (stderr, "end table dumping\n"); + + fprintf (stderr, "\nDumping key list information:\ntotal non-static linked keywords = %d" + "\ntotal keywords = %d\ntotal duplicates = %d\nmaximum key length = %d\n", + _list_len, _total_keys, _total_duplicates, _max_key_len); + + int field_width = _max_selchars_length; + fprintf (stderr, "\nList contents are:\n(hash value, key length, index, %*s, keyword):\n", + field_width, "selchars"); + for (KeywordExt_List *ptr = _head; ptr; ptr = ptr->rest()) + { + fprintf (stderr, "%11d,%11d,%6d, ", + ptr->first()->_hash_value, ptr->first()->_allchars_length, ptr->first()->_final_index); + if (field_width > ptr->first()->_selchars_length) + fprintf (stderr, "%*s", field_width - ptr->first()->_selchars_length, ""); + for (int j = 0; j < ptr->first()->_selchars_length; j++) + putc (ptr->first()->_selchars[j], stderr); + fprintf (stderr, ", %.*s\n", + ptr->first()->_allchars_length, ptr->first()->_allchars); + } + + fprintf (stderr, "End dumping list.\n\n"); + } + delete[] _asso_values; + delete[] _occurrences; + delete[] _alpha_unify; + delete[] _alpha_inc; +} diff --git a/contrib/gperf/src/search.h b/contrib/gperf/src/search.h new file mode 100644 index 000000000000..6b562c9a8b68 --- /dev/null +++ b/contrib/gperf/src/search.h @@ -0,0 +1,165 @@ +/* This may look like C code, but it is really -*- C++ -*- */ + +/* Search algorithm. + + Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . + + This file is part of GNU GPERF. + + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef search_h +#define search_h 1 + +#include "keyword-list.h" +#include "positions.h" +#include "bool-array.h" + +struct EquivalenceClass; + +class Search +{ +public: + Search (KeywordExt_List *list); + ~Search (); + void optimize (); +private: + void prepare (); + + /* Computes the upper bound on the indices passed to asso_values[], + assuming no alpha_increments. */ + unsigned int compute_alpha_size () const; + + /* Computes the unification rules between different asso_values[c], + assuming no alpha_increments. */ + unsigned int * compute_alpha_unify () const; + + /* Initializes each keyword's _selchars array. */ + void init_selchars_tuple (const Positions& positions, const unsigned int *alpha_unify) const; + /* Deletes each keyword's _selchars array. */ + void delete_selchars () const; + + /* Count the duplicate keywords that occur with a given set of positions. */ + unsigned int count_duplicates_tuple (const Positions& positions, const unsigned int *alpha_unify) const; + + /* Find good key positions. */ + void find_positions (); + + /* Count the duplicate keywords that occur with the found set of positions. */ + unsigned int count_duplicates_tuple () const; + + /* Computes the upper bound on the indices passed to asso_values[]. */ + unsigned int compute_alpha_size (const unsigned int *alpha_inc) const; + + /* Computes the unification rules between different asso_values[c]. */ + unsigned int * compute_alpha_unify (const Positions& positions, const unsigned int *alpha_inc) const; + + /* Initializes each keyword's _selchars array. */ + void init_selchars_multiset (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc) const; + + /* Count the duplicate keywords that occur with the given set of positions + and a given alpha_inc[] array. */ + unsigned int count_duplicates_multiset (const unsigned int *alpha_inc) const; + + /* Find good _alpha_inc[]. */ + void find_alpha_inc (); + + /* Initializes the asso_values[] related parameters. */ + void prepare_asso_values (); + + EquivalenceClass * compute_partition (bool *undetermined) const; + + unsigned int count_possible_collisions (EquivalenceClass *partition, unsigned int c) const; + + bool unchanged_partition (EquivalenceClass *partition, unsigned int c) const; + + /* Finds some _asso_values[] that fit. */ + void find_asso_values (); + + /* Computes a keyword's hash value, relative to the current _asso_values[], + and stores it in keyword->_hash_value. */ + int compute_hash (KeywordExt *keyword) const; + + /* Finds good _asso_values[]. */ + void find_good_asso_values (); + + /* Sorts the keyword list by hash value. */ + void sort (); + +public: + + /* Linked list of keywords. */ + KeywordExt_List * _head; + + /* Total number of keywords, counting duplicates. */ + int _total_keys; + + /* Maximum length of the longest keyword. */ + int _max_key_len; + + /* Minimum length of the shortest keyword. */ + int _min_key_len; + + /* User-specified or computed key positions. */ + Positions _key_positions; + + /* Adjustments to add to bytes add specific key positions. */ + unsigned int * _alpha_inc; + + /* Size of alphabet. */ + unsigned int _alpha_size; + + /* Alphabet character unification, either the identity or a mapping from + upper case characters to lower case characters (and maybe more). */ + unsigned int * _alpha_unify; + + /* Maximum _selchars_length over all keywords. */ + unsigned int _max_selchars_length; + + /* Total number of duplicates that have been moved to _duplicate_link lists + (not counting their representatives which stay on the main list). */ + int _total_duplicates; + + /* Counts occurrences of each key set character. + _occurrences[c] is the number of times that c occurs among the _selchars + of a keyword. */ + int * _occurrences; + /* Value associated with each character. */ + int * _asso_values; + +private: + + /* Length of _head list. Number of keywords, not counting duplicates. */ + int _list_len; + + /* Exclusive upper bound for every _asso_values[c]. A power of 2. */ + unsigned int _asso_value_max; + + /* Initial value for asso_values table. -1 means random. */ + int _initial_asso_value; + /* Jump length when trying alternative values. 0 means random. */ + int _jump; + + /* Maximal possible hash value. */ + int _max_hash_value; + + /* Sparse bit vector for collision detection. */ + Bool_Array * _collision_detector; +}; + +#endif diff --git a/contrib/gperf/src/trace.cc b/contrib/gperf/src/trace.cc deleted file mode 100644 index e571abae4239..000000000000 --- a/contrib/gperf/src/trace.cc +++ /dev/null @@ -1,35 +0,0 @@ -/* Tracing function calls. - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#include "trace.h" - -#include - -int Trace::nesting = 0; - -Trace::Trace (const char *n) -{ - fprintf (stderr, "%*scalling %s\n", 3 * nesting++, "", name = n); -} - -Trace::~Trace (void) -{ - fprintf (stderr, "%*sleaving %s\n", 3 * --nesting, "", name); -} diff --git a/contrib/gperf/src/trace.h b/contrib/gperf/src/trace.h deleted file mode 100644 index f16fcc5bd99e..000000000000 --- a/contrib/gperf/src/trace.h +++ /dev/null @@ -1,40 +0,0 @@ -/* Tracing function calls. - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#ifndef trace_h -#define trace_h 1 - -#ifdef TRACE -#define T(X) X -#else -#define T(X) -#endif - -class Trace -{ -private: - static int nesting; - const char *name; -public: - Trace (const char *n); - ~Trace (void); -}; - -#endif diff --git a/contrib/gperf/src/vectors.cc b/contrib/gperf/src/vectors.cc deleted file mode 100644 index 1da014d4a31a..000000000000 --- a/contrib/gperf/src/vectors.cc +++ /dev/null @@ -1,25 +0,0 @@ -/* Static class data members that are shared between several classes. - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#include "vectors.h" - -int Vectors::ALPHA_SIZE = MAX_ALPHA_SIZE; -int Vectors::occurrences[MAX_ALPHA_SIZE]; -int Vectors::asso_values[MAX_ALPHA_SIZE]; diff --git a/contrib/gperf/src/vectors.h b/contrib/gperf/src/vectors.h deleted file mode 100644 index 28a105397ebb..000000000000 --- a/contrib/gperf/src/vectors.h +++ /dev/null @@ -1,37 +0,0 @@ -/* This may look like C code, but it is really -*- C++ -*- */ - -/* Static class data members that are shared between several classes via - inheritance. - - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) - -This file is part of GNU GPERF. - -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#ifndef vectors_h -#define vectors_h 1 - -static const int MAX_ALPHA_SIZE = 256; - -struct Vectors -{ - static int ALPHA_SIZE; /* Size of alphabet. */ - static int occurrences[MAX_ALPHA_SIZE]; /* Counts occurrences of each key set character. */ - static int asso_values[MAX_ALPHA_SIZE]; /* Value associated with each character. */ -}; - -#endif diff --git a/contrib/gperf/src/version.cc b/contrib/gperf/src/version.cc index 8f07c695d537..f86ef4d455fa 100644 --- a/contrib/gperf/src/version.cc +++ b/contrib/gperf/src/version.cc @@ -1,22 +1,28 @@ /* Current program version number. - Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) + Copyright (C) 1989-1998, 2000, 2002-2003, 2005, 2007 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -const char *version_string = "2.7.2"; +/* Specification. */ +#include "version.h" + +/* Current release version. */ +const char *version_string = "3.0.3"; diff --git a/contrib/gperf/src/version.h b/contrib/gperf/src/version.h index 4ffba2ec91a1..feafbe98888a 100644 --- a/contrib/gperf/src/version.h +++ b/contrib/gperf/src/version.h @@ -1,23 +1,25 @@ /* Current program version number. - Copyright (C) 1989-1998 Free Software Foundation, Inc. - written by Douglas C. Schmidt (schmidt@ics.uci.edu) + Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc. + Written by Douglas C. Schmidt + and Bruno Haible . -This file is part of GNU GPERF. + This file is part of GNU GPERF. -GNU GPERF is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. + GNU GPERF is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GNU GPERF is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GNU GPERF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU GPERF; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Current release version. */ extern const char *version_string; diff --git a/contrib/gperf/tests/Makefile.in b/contrib/gperf/tests/Makefile.in deleted file mode 100644 index a7e3be0af6c3..000000000000 --- a/contrib/gperf/tests/Makefile.in +++ /dev/null @@ -1,232 +0,0 @@ -# Makefile for gperf/tests - -# Copyright (C) 1989, 1992, 1993, 1995, 1998 Free Software Foundation, Inc. -# written by Douglas C. Schmidt (schmidt@ics.uci.edu) -# -# This file is part of GNU GPERF. -# -# GNU GPERF is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 1, or (at your option) -# any later version. -# -# GNU GPERF is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU GPERF; see the file COPYING. If not, write to the Free -# Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. - -#### Start of system configuration section. #### - -# Directories used by "make": -srcdir = @srcdir@ - -# Programs used by "make": -# C compiler -CC = @CC@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -# C++ compiler -CXX = @CXX@ -CXXFLAGS = @CXXFLAGS@ -CXXCPP = @CXXCPP@ -# Other -MV = mv -LN = ln -RM = rm -f -@SET_MAKE@ - -#### End of system configuration section. #### - -SHELL = /bin/sh - -VPATH = $(srcdir) - -GPERF = ../src/gperf - -all : - -install : all - -installdirs : - -uninstall : - -check : check-link-c check-link-c++ check-c check-ada check-modula3 check-pascal check-test - @true - -extracheck : @CHECK_LANG_SYNTAX@ - @true - -check-link-c: force - @echo "performing some tests of the perfect hash generator" - $(CC) -c $(CFLAGS) $(srcdir)/test.c - $(GPERF) -p -c -l -S1 -o $(srcdir)/c.gperf > cinset.c - $(CC) $(CFLAGS) -o cout cinset.c test.o - -check-link-c++: force - -check-c: - @echo "testing ANSI C reserved words, all items should be found in the set" - ./cout -v < $(srcdir)/c.gperf > c.out - diff $(srcdir)/c.exp c.out - -check-ada: - $(GPERF) -k1,4,'$$' $(srcdir)/ada.gperf > adainset.c -# double '$$' is only there since make gets confused; program wants only 1 '$' - $(CC) $(CFLAGS) -o aout adainset.c test.o - @echo "testing Ada reserved words, all items should be found in the set" - ./aout -v < $(srcdir)/ada.gperf > ada-res.out - diff $(srcdir)/ada-res.exp ada-res.out - $(GPERF) -p -D -k1,'$$' -s 2 -o $(srcdir)/adadefs.gperf > preinset.c - $(CC) $(CFLAGS) -o preout preinset.c test.o - @echo "testing Ada predefined words, all items should be found in the set" - ./preout -v < $(srcdir)/adadefs.gperf > ada-pred.out - diff $(srcdir)/ada-pred.exp ada-pred.out - -check-modula3: - $(GPERF) -k1,2,'$$' -o $(srcdir)/modula3.gperf > m3inset.c - $(CC) $(CFLAGS) -o m3out m3inset.c test.o - @echo "testing Modula3 reserved words, all items should be found in the set" - ./m3out -v < $(srcdir)/modula3.gperf > modula.out - diff $(srcdir)/modula.exp modula.out - -check-pascal: - $(GPERF) -o -S2 -p < $(srcdir)/pascal.gperf > pinset.c - $(CC) $(CFLAGS) -o pout pinset.c test.o - @echo "testing Pascal reserved words, all items should be found in the set" - ./pout -v < $(srcdir)/pascal.gperf > pascal.out - diff $(srcdir)/pascal.exp pascal.out - -# these next 5 are demos that show off the generated code -check-test: - $(GPERF) -p -j1 -g -o -t -N is_reserved_word -k1,3,'$$' < $(srcdir)/c-parse.gperf > test-1.out - diff $(srcdir)/test-1.exp test-1.out - $(GPERF) -n -k1-8 -l < $(srcdir)/modula2.gperf > test-2.out - diff $(srcdir)/test-2.exp test-2.out - $(GPERF) -p -j 1 -o -a -C -g -t -k1,4,$$ < $(srcdir)/gplus.gperf > test-3.out - diff $(srcdir)/test-3.exp test-3.out - $(GPERF) -D -p -t < $(srcdir)/c-parse.gperf > test-4.out - diff $(srcdir)/test-4.exp test-4.out - $(GPERF) -g -o -j1 -t -p -N is_reserved_word < $(srcdir)/gpc.gperf > test-5.out - diff $(srcdir)/test-5.exp test-5.out -# prints out the help message - -$(GPERF) -h > test-6.out 2>&1 - diff $(srcdir)/test-6.exp test-6.out - @echo "only if, do, for, case, goto, else, while, and return should be found " - ./aout -v < $(srcdir)/c.gperf > test-7.out - diff $(srcdir)/test-7.exp test-7.out - -# The following validates valid language syntax with different parameters. -# Works only with gcc and g++, and only on platforms where "gcc -ansi" is -# usable. (There are still platforms where gcc-2.8.0's fixincludes does not -# work well enough.) - -VALIDATE = CC='$(CC)' CFLAGS='$(CFLAGS)' CXX='$(CXX)' CXXFLAGS='$(CXXFLAGS)' GPERF='$(GPERF)' ./validate - -check-lang-syntax : force - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -c - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -C - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -E - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -G - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -G -C - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -G -E - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -D - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -D -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -c - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -C - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -E - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -G - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -D - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -D -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 1000 - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -C - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -D - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -D -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 10 - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 10 -C - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 10 -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 10 -D - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 10 -D -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 1000 - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -K key_name - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -H hash_function_name - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -W word_list_name - sed -e 's,in_word_set,lookup_function_name,g' < jstest1.gperf > tmp-jstest1.gperf && \ - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 tmp-jstest1.gperf -N lookup_function_name - sed -e 's,Perfect_Hash,class_name,g' < jstest1.gperf > tmp-jstest1.gperf && \ - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 tmp-jstest1.gperf -Z class_name - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -c - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -C - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -E - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -G - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -G -C - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -G -E - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -D - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -D -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -c - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -C - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -E - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -G - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -D - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -D -l - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 1000 - sed -e 's,name,key_name,g' < jstest2.gperf > tmp-jstest2.gperf && \ - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 tmp-jstest2.gperf -t -p -K key_name - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -H hash_function_name - sed -e 's,in_word_set,lookup_function_name,g' < jstest2.gperf > tmp-jstest2.gperf && \ - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 tmp-jstest2.gperf -t -p -N lookup_function_name - sed -e 's,Perfect_Hash,class_name,g' < jstest2.gperf > tmp-jstest2.gperf && \ - $(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 tmp-jstest2.gperf -t -p -Z class_name - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -c - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -C - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -E - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -G - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -G -C - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -G -E - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -l - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -D - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -D -l - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -c - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -C - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -E - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -G - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -l - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -D - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -D -l - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 1000 - sed -e 's,name,key_name,g' < jstest3.gperf > tmp-jstest3.gperf && \ - $(VALIDATE) C,ANSI-C,C++ -k1,2 tmp-jstest3.gperf -t -p -K key_name - $(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -H hash_function_name - sed -e 's,in_word_set,lookup_function_name,g' < jstest3.gperf > tmp-jstest3.gperf && \ - $(VALIDATE) C,ANSI-C,C++ -k1,2 tmp-jstest3.gperf -t -p -N lookup_function_name - sed -e 's,Perfect_Hash,class_name,g' < jstest3.gperf > tmp-jstest3.gperf && \ - $(VALIDATE) C,ANSI-C,C++ -k1,2 tmp-jstest3.gperf -t -p -Z class_name - -mostlyclean : clean - -clean : force - $(RM) *.o core *inset.c output.* *.out aout cout m3out pout preout tmp-* valitest* - -distclean : clean - $(RM) config.status config.log config.cache Makefile - -maintainer-clean : distclean - -force : - diff --git a/contrib/gperf/tests/ada-pred.exp b/contrib/gperf/tests/ada-pred.exp deleted file mode 100644 index 33caaa32ea1f..000000000000 --- a/contrib/gperf/tests/ada-pred.exp +++ /dev/null @@ -1,54 +0,0 @@ -in word set boolean -in word set character -in word set constraint_error -in word set false -in word set float -in word set integer -in word set natural -in word set numeric_error -in word set positive -in word set program_error -in word set storage_error -in word set string -in word set tasking_error -in word set true -in word set address -in word set aft -in word set base -in word set callable -in word set constrained -in word set count -in word set delta -in word set digits -in word set emax -in word set epsilon -in word set first -in word set firstbit -in word set fore -in word set image -in word set large -in word set last -in word set lastbit -in word set length -in word set machine_emax -in word set machine_emin -in word set machine_mantissa -in word set machine_overflows -in word set machine_radix -in word set machine_rounds -in word set mantissa -in word set pos -in word set position -in word set pred -in word set range -in word set safe_emax -in word set safe_large -in word set safe_small -in word set size -in word set small -in word set storage_size -in word set succ -in word set terminated -in word set val -in word set value -in word set width diff --git a/contrib/gperf/tests/ada-res.exp b/contrib/gperf/tests/ada-res.exp deleted file mode 100644 index 8134fe861f5f..000000000000 --- a/contrib/gperf/tests/ada-res.exp +++ /dev/null @@ -1,63 +0,0 @@ -in word set else -in word set exit -in word set terminate -in word set type -in word set raise -in word set range -in word set reverse -in word set declare -in word set end -in word set record -in word set exception -in word set not -in word set then -in word set return -in word set separate -in word set select -in word set digits -in word set renames -in word set subtype -in word set elsif -in word set function -in word set for -in word set package -in word set procedure -in word set private -in word set while -in word set when -in word set new -in word set entry -in word set delay -in word set case -in word set constant -in word set at -in word set abort -in word set accept -in word set and -in word set delta -in word set access -in word set abs -in word set pragma -in word set array -in word set use -in word set out -in word set do -in word set others -in word set of -in word set or -in word set all -in word set limited -in word set loop -in word set null -in word set task -in word set in -in word set is -in word set if -in word set rem -in word set mod -in word set begin -in word set body -in word set xor -in word set goto -in word set generic -in word set with diff --git a/contrib/gperf/tests/ada.gperf b/contrib/gperf/tests/ada.gperf deleted file mode 100644 index 332bdc740ad7..000000000000 --- a/contrib/gperf/tests/ada.gperf +++ /dev/null @@ -1,63 +0,0 @@ -else -exit -terminate -type -raise -range -reverse -declare -end -record -exception -not -then -return -separate -select -digits -renames -subtype -elsif -function -for -package -procedure -private -while -when -new -entry -delay -case -constant -at -abort -accept -and -delta -access -abs -pragma -array -use -out -do -others -of -or -all -limited -loop -null -task -in -is -if -rem -mod -begin -body -xor -goto -generic -with diff --git a/contrib/gperf/tests/adadefs.gperf b/contrib/gperf/tests/adadefs.gperf deleted file mode 100644 index 875be69abc97..000000000000 --- a/contrib/gperf/tests/adadefs.gperf +++ /dev/null @@ -1,54 +0,0 @@ -boolean -character -constraint_error -false -float -integer -natural -numeric_error -positive -program_error -storage_error -string -tasking_error -true -address -aft -base -callable -constrained -count -delta -digits -emax -epsilon -first -firstbit -fore -image -large -last -lastbit -length -machine_emax -machine_emin -machine_mantissa -machine_overflows -machine_radix -machine_rounds -mantissa -pos -position -pred -range -safe_emax -safe_large -safe_small -size -small -storage_size -succ -terminated -val -value -width diff --git a/contrib/gperf/tests/c++.gperf b/contrib/gperf/tests/c++.gperf deleted file mode 100644 index 650d32d0eddd..000000000000 --- a/contrib/gperf/tests/c++.gperf +++ /dev/null @@ -1,47 +0,0 @@ -asm -auto -break -case -catch -char -class -const -continue -default -delete -do -double -else -enum -extern -float -for -friend -goto -if -inline -int -long -new -operator -overload -private -protected -public -register -return -short -signed -sizeof -static -struct -switch -template -this -typedef -union -unsigned -virtual -void -volatile -while diff --git a/contrib/gperf/tests/c-parse.gperf b/contrib/gperf/tests/c-parse.gperf deleted file mode 100644 index d11788ce9652..000000000000 --- a/contrib/gperf/tests/c-parse.gperf +++ /dev/null @@ -1,56 +0,0 @@ -%{ -/* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf */ -%} -struct resword { char *name; short token; enum rid rid; }; -%% -__alignof, ALIGNOF, NORID -__alignof__, ALIGNOF, NORID -__asm, ASM, NORID -__asm__, ASM, NORID -__attribute, ATTRIBUTE, NORID -__attribute__, ATTRIBUTE, NORID -__const, TYPE_QUAL, RID_CONST -__const__, TYPE_QUAL, RID_CONST -__inline, SCSPEC, RID_INLINE -__inline__, SCSPEC, RID_INLINE -__signed, TYPESPEC, RID_SIGNED -__signed__, TYPESPEC, RID_SIGNED -__typeof, TYPEOF, NORID -__typeof__, TYPEOF, NORID -__volatile, TYPE_QUAL, RID_VOLATILE -__volatile__, TYPE_QUAL, RID_VOLATILE -asm, ASM, NORID -auto, SCSPEC, RID_AUTO -break, BREAK, NORID -case, CASE, NORID -char, TYPESPEC, RID_CHAR -const, TYPE_QUAL, RID_CONST -continue, CONTINUE, NORID -default, DEFAULT, NORID -do, DO, NORID -double, TYPESPEC, RID_DOUBLE -else, ELSE, NORID -enum, ENUM, NORID -extern, SCSPEC, RID_EXTERN -float, TYPESPEC, RID_FLOAT -for, FOR, NORID -goto, GOTO, NORID -if, IF, NORID -inline, SCSPEC, RID_INLINE -int, TYPESPEC, RID_INT -long, TYPESPEC, RID_LONG -register, SCSPEC, RID_REGISTER -return, RETURN, NORID -short, TYPESPEC, RID_SHORT -signed, TYPESPEC, RID_SIGNED -sizeof, SIZEOF, NORID -static, SCSPEC, RID_STATIC -struct, STRUCT, NORID -switch, SWITCH, NORID -typedef, SCSPEC, RID_TYPEDEF -typeof, TYPEOF, NORID -union, UNION, NORID -unsigned, TYPESPEC, RID_UNSIGNED -void, TYPESPEC, RID_VOID -volatile, TYPE_QUAL, RID_VOLATILE -while, WHILE, NORID diff --git a/contrib/gperf/tests/c.exp b/contrib/gperf/tests/c.exp deleted file mode 100644 index 10c8b7f61164..000000000000 --- a/contrib/gperf/tests/c.exp +++ /dev/null @@ -1,32 +0,0 @@ -in word set if -in word set do -in word set int -in word set for -in word set case -in word set char -in word set auto -in word set goto -in word set else -in word set long -in word set void -in word set enum -in word set float -in word set short -in word set union -in word set break -in word set while -in word set const -in word set double -in word set static -in word set extern -in word set struct -in word set return -in word set sizeof -in word set switch -in word set signed -in word set typedef -in word set default -in word set unsigned -in word set continue -in word set register -in word set volatile diff --git a/contrib/gperf/tests/c.gperf b/contrib/gperf/tests/c.gperf deleted file mode 100644 index 8672d6c25ed3..000000000000 --- a/contrib/gperf/tests/c.gperf +++ /dev/null @@ -1,32 +0,0 @@ -if -do -int -for -case -char -auto -goto -else -long -void -enum -float -short -union -break -while -const -double -static -extern -struct -return -sizeof -switch -signed -typedef -default -unsigned -continue -register -volatile diff --git a/contrib/gperf/tests/configure b/contrib/gperf/tests/configure deleted file mode 100755 index 1c715de8662f..000000000000 --- a/contrib/gperf/tests/configure +++ /dev/null @@ -1,1214 +0,0 @@ -#! /bin/sh - -# Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 2.12 -# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. -# -# This configure script is free software; the Free Software Foundation -# gives unlimited permission to copy, distribute and modify it. - -# Defaults: -ac_help= -ac_default_prefix=/usr/local -# Any additions from configure.in: - -# Initialize some variables set by options. -# The variables have the same names as the options, with -# dashes changed to underlines. -build=NONE -cache_file=./config.cache -exec_prefix=NONE -host=NONE -no_create= -nonopt=NONE -no_recursion= -prefix=NONE -program_prefix=NONE -program_suffix=NONE -program_transform_name=s,x,x, -silent= -site= -srcdir= -target=NONE -verbose= -x_includes=NONE -x_libraries=NONE -bindir='${exec_prefix}/bin' -sbindir='${exec_prefix}/sbin' -libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' -sysconfdir='${prefix}/etc' -sharedstatedir='${prefix}/com' -localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' -includedir='${prefix}/include' -oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -# Initialize some other variables. -subdirs= -MFLAGS= MAKEFLAGS= -# Maximum number of lines to put in a shell here document. -ac_max_here_lines=12 - -ac_prev= -for ac_option -do - - # If the previous option needs an argument, assign it. - if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" - ac_prev= - continue - fi - - case "$ac_option" in - -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; - *) ac_optarg= ;; - esac - - # Accept the important Cygnus configure options, so we can diagnose typos. - - case "$ac_option" in - - -bindir | --bindir | --bindi | --bind | --bin | --bi) - ac_prev=bindir ;; - -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir="$ac_optarg" ;; - - -build | --build | --buil | --bui | --bu) - ac_prev=build ;; - -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build="$ac_optarg" ;; - - -cache-file | --cache-file | --cache-fil | --cache-fi \ - | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) - ac_prev=cache_file ;; - -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file="$ac_optarg" ;; - - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) - ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir="$ac_optarg" ;; - - -disable-* | --disable-*) - ac_feature=`echo $ac_option|sed -e 's/-*disable-//'` - # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - eval "enable_${ac_feature}=no" ;; - - -enable-* | --enable-*) - ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'` - # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; - *) ac_optarg=yes ;; - esac - eval "enable_${ac_feature}='$ac_optarg'" ;; - - -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ - | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ - | --exec | --exe | --ex) - ac_prev=exec_prefix ;; - -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ - | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ - | --exec=* | --exe=* | --ex=*) - exec_prefix="$ac_optarg" ;; - - -gas | --gas | --ga | --g) - # Obsolete; use --with-gas. - with_gas=yes ;; - - -help | --help | --hel | --he) - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat << EOF -Usage: configure [options] [host] -Options: [defaults in brackets after descriptions] -Configuration: - --cache-file=FILE cache test results in FILE - --help print this message - --no-create do not create output files - --quiet, --silent do not print \`checking...' messages - --version print the version of autoconf that created configure -Directory and file names: - --prefix=PREFIX install architecture-independent files in PREFIX - [$ac_default_prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [same as prefix] - --bindir=DIR user executables in DIR [EPREFIX/bin] - --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] - --libexecdir=DIR program executables in DIR [EPREFIX/libexec] - --datadir=DIR read-only architecture-independent data in DIR - [PREFIX/share] - --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] - --sharedstatedir=DIR modifiable architecture-independent data in DIR - [PREFIX/com] - --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] - --libdir=DIR object code libraries in DIR [EPREFIX/lib] - --includedir=DIR C header files in DIR [PREFIX/include] - --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] - --infodir=DIR info documentation in DIR [PREFIX/info] - --mandir=DIR man documentation in DIR [PREFIX/man] - --srcdir=DIR find the sources in DIR [configure dir or ..] - --program-prefix=PREFIX prepend PREFIX to installed program names - --program-suffix=SUFFIX append SUFFIX to installed program names - --program-transform-name=PROGRAM - run sed PROGRAM on installed program names -EOF - cat << EOF -Host type: - --build=BUILD configure for building on BUILD [BUILD=HOST] - --host=HOST configure for HOST [guessed] - --target=TARGET configure for TARGET [TARGET=HOST] -Features and packages: - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] - --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) - --x-includes=DIR X include files are in DIR - --x-libraries=DIR X library files are in DIR -EOF - if test -n "$ac_help"; then - echo "--enable and --with options recognized:$ac_help" - fi - exit 0 ;; - - -host | --host | --hos | --ho) - ac_prev=host ;; - -host=* | --host=* | --hos=* | --ho=*) - host="$ac_optarg" ;; - - -includedir | --includedir | --includedi | --included | --include \ - | --includ | --inclu | --incl | --inc) - ac_prev=includedir ;; - -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ - | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir="$ac_optarg" ;; - - -infodir | --infodir | --infodi | --infod | --info | --inf) - ac_prev=infodir ;; - -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir="$ac_optarg" ;; - - -libdir | --libdir | --libdi | --libd) - ac_prev=libdir ;; - -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir="$ac_optarg" ;; - - -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ - | --libexe | --libex | --libe) - ac_prev=libexecdir ;; - -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ - | --libexe=* | --libex=* | --libe=*) - libexecdir="$ac_optarg" ;; - - -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) - ac_prev=localstatedir ;; - -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir="$ac_optarg" ;; - - -mandir | --mandir | --mandi | --mand | --man | --ma | --m) - ac_prev=mandir ;; - -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir="$ac_optarg" ;; - - -nfp | --nfp | --nf) - # Obsolete; use --without-fp. - with_fp=no ;; - - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) - no_create=yes ;; - - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) - no_recursion=yes ;; - - -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ - | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ - | --oldin | --oldi | --old | --ol | --o) - ac_prev=oldincludedir ;; - -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ - | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ - | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir="$ac_optarg" ;; - - -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) - ac_prev=prefix ;; - -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix="$ac_optarg" ;; - - -program-prefix | --program-prefix | --program-prefi | --program-pref \ - | --program-pre | --program-pr | --program-p) - ac_prev=program_prefix ;; - -program-prefix=* | --program-prefix=* | --program-prefi=* \ - | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix="$ac_optarg" ;; - - -program-suffix | --program-suffix | --program-suffi | --program-suff \ - | --program-suf | --program-su | --program-s) - ac_prev=program_suffix ;; - -program-suffix=* | --program-suffix=* | --program-suffi=* \ - | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix="$ac_optarg" ;; - - -program-transform-name | --program-transform-name \ - | --program-transform-nam | --program-transform-na \ - | --program-transform-n | --program-transform- \ - | --program-transform | --program-transfor \ - | --program-transfo | --program-transf \ - | --program-trans | --program-tran \ - | --progr-tra | --program-tr | --program-t) - ac_prev=program_transform_name ;; - -program-transform-name=* | --program-transform-name=* \ - | --program-transform-nam=* | --program-transform-na=* \ - | --program-transform-n=* | --program-transform-=* \ - | --program-transform=* | --program-transfor=* \ - | --program-transfo=* | --program-transf=* \ - | --program-trans=* | --program-tran=* \ - | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name="$ac_optarg" ;; - - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - silent=yes ;; - - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) - ac_prev=sbindir ;; - -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ - | --sbi=* | --sb=*) - sbindir="$ac_optarg" ;; - - -sharedstatedir | --sharedstatedir | --sharedstatedi \ - | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ - | --sharedst | --shareds | --shared | --share | --shar \ - | --sha | --sh) - ac_prev=sharedstatedir ;; - -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ - | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ - | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ - | --sha=* | --sh=*) - sharedstatedir="$ac_optarg" ;; - - -site | --site | --sit) - ac_prev=site ;; - -site=* | --site=* | --sit=*) - site="$ac_optarg" ;; - - -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) - ac_prev=srcdir ;; - -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir="$ac_optarg" ;; - - -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ - | --syscon | --sysco | --sysc | --sys | --sy) - ac_prev=sysconfdir ;; - -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ - | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir="$ac_optarg" ;; - - -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target ;; - -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target="$ac_optarg" ;; - - -v | -verbose | --verbose | --verbos | --verbo | --verb) - verbose=yes ;; - - -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 2.12" - exit 0 ;; - - -with-* | --with-*) - ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'` - # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; - *) ac_optarg=yes ;; - esac - eval "with_${ac_package}='$ac_optarg'" ;; - - -without-* | --without-*) - ac_package=`echo $ac_option|sed -e 's/-*without-//'` - # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - eval "with_${ac_package}=no" ;; - - --x) - # Obsolete; use --with-x. - with_x=yes ;; - - -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ - | --x-incl | --x-inc | --x-in | --x-i) - ac_prev=x_includes ;; - -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ - | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes="$ac_optarg" ;; - - -x-libraries | --x-libraries | --x-librarie | --x-librari \ - | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) - ac_prev=x_libraries ;; - -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ - | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries="$ac_optarg" ;; - - -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } - ;; - - *) - if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then - echo "configure: warning: $ac_option: invalid host type" 1>&2 - fi - if test "x$nonopt" != xNONE; then - { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } - fi - nonopt="$ac_option" - ;; - - esac -done - -if test -n "$ac_prev"; then - { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; } -fi - -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - -# File descriptor usage: -# 0 standard input -# 1 file creation -# 2 errors and warnings -# 3 some systems may open it to /dev/tty -# 4 used on the Kubota Titan -# 6 checking for... messages and results -# 5 compiler messages saved in config.log -if test "$silent" = yes; then - exec 6>/dev/null -else - exec 6>&1 -fi -exec 5>./config.log - -echo "\ -This file contains any messages produced by compilers while -running configure, to aid debugging if configure makes a mistake. -" 1>&5 - -# Strip out --no-create and --no-recursion so they do not pile up. -# Also quote any args containing shell metacharacters. -ac_configure_args= -for ac_arg -do - case "$ac_arg" in - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) ;; - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; - *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*) - ac_configure_args="$ac_configure_args '$ac_arg'" ;; - *) ac_configure_args="$ac_configure_args $ac_arg" ;; - esac -done - -# NLS nuisances. -# Only set these to C if already set. These must not be set unconditionally -# because not all systems understand e.g. LANG=C (notably SCO). -# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'! -# Non-C LC_CTYPE values break the ctype check. -if test "${LANG+set}" = set; then LANG=C; export LANG; fi -if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi -if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi -if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi - -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo > confdefs.h - -# A filename unique to this package, relative to the directory that -# configure is in, which we can look for to find out if srcdir is correct. -ac_unique_file=c-parse.gperf - -# Find the source files, if location was not specified. -if test -z "$srcdir"; then - ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_prog=$0 - ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` - test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. - srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then - srcdir=.. - fi -else - ac_srcdir_defaulted=no -fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; } - else - { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; } - fi -fi -srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'` - -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi -fi -for ac_site_file in $CONFIG_SITE; do - if test -r "$ac_site_file"; then - echo "loading site script $ac_site_file" - . "$ac_site_file" - fi -done - -if test -r "$cache_file"; then - echo "loading cache $cache_file" - . $cache_file -else - echo "creating cache $cache_file" - > $cache_file -fi - -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross - -if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then - # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. - if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then - ac_n= ac_c=' -' ac_t=' ' - else - ac_n=-n ac_c= ac_t= - fi -else - ac_n= ac_c='\c' ac_t= -fi - - -echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6 -echo "configure:523: checking whether ${MAKE-make} sets \${MAKE}" >&5 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - cat > conftestmake <<\EOF -all: - @echo 'ac_maketemp="${MAKE}"' -EOF -# GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftestmake 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no -fi -rm -f conftestmake -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$ac_t""yes" 1>&6 - SET_MAKE= -else - echo "$ac_t""no" 1>&6 - SET_MAKE="MAKE=${MAKE-make}" -fi - -# Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:552: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" - for ac_dir in $PATH; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CC="gcc" - break - fi - done - IFS="$ac_save_ifs" -fi -fi -CC="$ac_cv_prog_CC" -if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 -else - echo "$ac_t""no" 1>&6 -fi - -if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:581: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" - ac_prog_rejected=no - for ac_dir in $PATH; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue - fi - ac_cv_prog_CC="cc" - break - fi - done - IFS="$ac_save_ifs" -if test $ac_prog_rejected = yes; then - # We found a bogon in the path, so make sure we never use it. - set dummy $ac_cv_prog_CC - shift - if test $# -gt 0; then - # We chose a different compiler from the bogus one. - # However, it has the same basename, so the bogon will be chosen - # first if we set CC to just the basename; use the full file name. - shift - set dummy "$ac_dir/$ac_word" "$@" - shift - ac_cv_prog_CC="$@" - fi -fi -fi -fi -CC="$ac_cv_prog_CC" -if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 -else - echo "$ac_t""no" 1>&6 -fi - - test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; } -fi - -echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:629: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 - -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross - -cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then - ac_cv_prog_cc_works=yes - # If we can't run a trivial program, we are probably using a cross compiler. - if (./conftest; exit) 2>/dev/null; then - ac_cv_prog_cc_cross=no - else - ac_cv_prog_cc_cross=yes - fi -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_prog_cc_works=no -fi -rm -fr conftest* - -echo "$ac_t""$ac_cv_prog_cc_works" 1>&6 -if test $ac_cv_prog_cc_works = no; then - { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } -fi -echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:663: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 -echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 -cross_compiling=$ac_cv_prog_cc_cross - -echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:668: checking whether we are using GNU C" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - cat > conftest.c <&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then - ac_cv_prog_gcc=yes -else - ac_cv_prog_gcc=no -fi -fi - -echo "$ac_t""$ac_cv_prog_gcc" 1>&6 - -if test $ac_cv_prog_gcc = yes; then - GCC=yes - ac_test_CFLAGS="${CFLAGS+set}" - ac_save_CFLAGS="$CFLAGS" - CFLAGS= - echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:692: checking whether ${CC-cc} accepts -g" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - echo 'void f(){}' > conftest.c -if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then - ac_cv_prog_cc_g=yes -else - ac_cv_prog_cc_g=no -fi -rm -f conftest* - -fi - -echo "$ac_t""$ac_cv_prog_cc_g" 1>&6 - if test "$ac_test_CFLAGS" = set; then - CFLAGS="$ac_save_CFLAGS" - elif test $ac_cv_prog_cc_g = yes; then - CFLAGS="-g -O2" - else - CFLAGS="-O2" - fi -else - GCC= - test "${CFLAGS+set}" = set || CFLAGS="-g" -fi - - echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:720: checking how to run the C preprocessor" >&5 -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then -if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - # This must be in double quotes, not single quotes, because CPP may get - # substituted into the Makefile and "${CC-cc}" will confuse make. - CPP="${CC-cc} -E" - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:741: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out` -if test -z "$ac_err"; then - : -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP="${CC-cc} -E -traditional-cpp" - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:758: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out` -if test -z "$ac_err"; then - : -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP=/lib/cpp -fi -rm -f conftest* -fi -rm -f conftest* - ac_cv_prog_CPP="$CPP" -fi - CPP="$ac_cv_prog_CPP" -else - ac_cv_prog_CPP="$CPP" -fi -echo "$ac_t""$CPP" 1>&6 - - for ac_prog in $CCC c++ g++ gcc CC cxx cc++ -do -# Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:785: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CXX'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - if test -n "$CXX"; then - ac_cv_prog_CXX="$CXX" # Let the user override the test. -else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" - for ac_dir in $PATH; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CXX="$ac_prog" - break - fi - done - IFS="$ac_save_ifs" -fi -fi -CXX="$ac_cv_prog_CXX" -if test -n "$CXX"; then - echo "$ac_t""$CXX" 1>&6 -else - echo "$ac_t""no" 1>&6 -fi - -test -n "$CXX" && break -done -test -n "$CXX" || CXX="gcc" - - -echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:816: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5 - -ac_ext=C -# CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CXXCPP $CPPFLAGS' -ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CXX-g++} -o conftest $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cxx_cross - -cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then - ac_cv_prog_cxx_works=yes - # If we can't run a trivial program, we are probably using a cross compiler. - if (./conftest; exit) 2>/dev/null; then - ac_cv_prog_cxx_cross=no - else - ac_cv_prog_cxx_cross=yes - fi -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_prog_cxx_works=no -fi -rm -fr conftest* -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross - -echo "$ac_t""$ac_cv_prog_cxx_works" 1>&6 -if test $ac_cv_prog_cxx_works = no; then - { echo "configure: error: installation or configuration problem: C++ compiler cannot create executables." 1>&2; exit 1; } -fi -echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:856: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5 -echo "$ac_t""$ac_cv_prog_cxx_cross" 1>&6 -cross_compiling=$ac_cv_prog_cxx_cross - -echo $ac_n "checking whether we are using GNU C++""... $ac_c" 1>&6 -echo "configure:861: checking whether we are using GNU C++" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_gxx'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - cat > conftest.C <&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then - ac_cv_prog_gxx=yes -else - ac_cv_prog_gxx=no -fi -fi - -echo "$ac_t""$ac_cv_prog_gxx" 1>&6 - -if test $ac_cv_prog_gxx = yes; then - GXX=yes - ac_test_CXXFLAGS="${CXXFLAGS+set}" - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS= - echo $ac_n "checking whether ${CXX-g++} accepts -g""... $ac_c" 1>&6 -echo "configure:885: checking whether ${CXX-g++} accepts -g" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_cxx_g'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - echo 'void f(){}' > conftest.cc -if test -z "`${CXX-g++} -g -c conftest.cc 2>&1`"; then - ac_cv_prog_cxx_g=yes -else - ac_cv_prog_cxx_g=no -fi -rm -f conftest* - -fi - -echo "$ac_t""$ac_cv_prog_cxx_g" 1>&6 - if test "$ac_test_CXXFLAGS" = set; then - CXXFLAGS="$ac_save_CXXFLAGS" - elif test $ac_cv_prog_cxx_g = yes; then - CXXFLAGS="-g -O2" - else - CXXFLAGS="-O2" - fi -else - GXX= - test "${CXXFLAGS+set}" = set || CXXFLAGS="-g" -fi - - echo $ac_n "checking how to run the C++ preprocessor""... $ac_c" 1>&6 -echo "configure:913: checking how to run the C++ preprocessor" >&5 -if test -z "$CXXCPP"; then -if eval "test \"`echo '$''{'ac_cv_prog_CXXCPP'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_ext=C -# CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CXXCPP $CPPFLAGS' -ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CXX-g++} -o conftest $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cxx_cross - CXXCPP="${CXX-g++} -E" - cat > conftest.$ac_ext < -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:931: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out` -if test -z "$ac_err"; then - : -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CXXCPP=/lib/cpp -fi -rm -f conftest* - ac_cv_prog_CXXCPP="$CXXCPP" -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross -fi -fi -CXXCPP="$ac_cv_prog_CXXCPP" -echo "$ac_t""$CXXCPP" 1>&6 - - if test $ac_cv_prog_gcc = yes -a $ac_cv_prog_gxx = yes; then - CHECK_LANG_SYNTAX='check-lang-syntax' -else - CHECK_LANG_SYNTAX='' -fi - -trap '' 1 2 15 -cat > confcache <<\EOF -# This file is a shell script that caches the results of configure -# tests run on this system so they can be shared between configure -# scripts and configure runs. It is not useful on other systems. -# If it contains results you don't want to keep, you may remove or edit it. -# -# By default, configure uses ./config.cache as the cache file, -# creating it if it does not exist already. You can give configure -# the --cache-file=FILE option to use a different cache file; that is -# what configure does when it calls configure scripts in -# subdirectories, so they share the cache. -# Giving --cache-file=/dev/null disables caching, for debugging configure. -# config.status only pays attention to the cache file if you give it the -# --recheck option to rerun configure. -# -EOF -# The following way of writing the cache mishandles newlines in values, -# but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. -# Ultrix sh set writes to stderr and can't be redirected directly, -# and sets the high bit in the cache file unless we assign to the vars. -(set) 2>&1 | - case `(ac_space=' '; set) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote substitution - # turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - -e "s/'/'\\\\''/g" \ - -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p' - ;; - esac >> confcache -if cmp -s $cache_file confcache; then - : -else - if test -w $cache_file; then - echo "updating cache $cache_file" - cat confcache > $cache_file - else - echo "not updating unwritable cache $cache_file" - fi -fi -rm -f confcache - -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - -test "x$prefix" = xNONE && prefix=$ac_default_prefix -# Let make expand exec_prefix. -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' - -# Any assignment to VPATH causes Sun make to only execute -# the first set of double-colon rules, so remove it if not needed. -# If there is a colon in the path, we need to keep it. -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d' -fi - -trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 - -# Transform confdefs.h into DEFS. -# Protect against shell expansion while executing Makefile rules. -# Protect against Makefile macro expansion. -cat > conftest.defs <<\EOF -s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%-D\1=\2%g -s%[ `~#$^&*(){}\\|;'"<>?]%\\&%g -s%\[%\\&%g -s%\]%\\&%g -s%\$%$$%g -EOF -DEFS=`sed -f conftest.defs confdefs.h | tr '\012' ' '` -rm -f conftest.defs - - -# Without the "./", some shells look in PATH for config.status. -: ${CONFIG_STATUS=./config.status} - -echo creating $CONFIG_STATUS -rm -f $CONFIG_STATUS -cat > $CONFIG_STATUS </dev/null | sed 1q`: -# -# $0 $ac_configure_args -# -# Compiler output produced by configure, useful for debugging -# configure, is in ./config.log if it exists. - -ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]" -for ac_option -do - case "\$ac_option" in - -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" - exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; - -version | --version | --versio | --versi | --vers | --ver | --ve | --v) - echo "$CONFIG_STATUS generated by autoconf version 2.12" - exit 0 ;; - -help | --help | --hel | --he | --h) - echo "\$ac_cs_usage"; exit 0 ;; - *) echo "\$ac_cs_usage"; exit 1 ;; - esac -done - -ac_given_srcdir=$srcdir - -trap 'rm -fr `echo "Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 -EOF -cat >> $CONFIG_STATUS < conftest.subs <<\\CEOF -$ac_vpsub -$extrasub -s%@CFLAGS@%$CFLAGS%g -s%@CPPFLAGS@%$CPPFLAGS%g -s%@CXXFLAGS@%$CXXFLAGS%g -s%@DEFS@%$DEFS%g -s%@LDFLAGS@%$LDFLAGS%g -s%@LIBS@%$LIBS%g -s%@exec_prefix@%$exec_prefix%g -s%@prefix@%$prefix%g -s%@program_transform_name@%$program_transform_name%g -s%@bindir@%$bindir%g -s%@sbindir@%$sbindir%g -s%@libexecdir@%$libexecdir%g -s%@datadir@%$datadir%g -s%@sysconfdir@%$sysconfdir%g -s%@sharedstatedir@%$sharedstatedir%g -s%@localstatedir@%$localstatedir%g -s%@libdir@%$libdir%g -s%@includedir@%$includedir%g -s%@oldincludedir@%$oldincludedir%g -s%@infodir@%$infodir%g -s%@mandir@%$mandir%g -s%@SET_MAKE@%$SET_MAKE%g -s%@CC@%$CC%g -s%@CPP@%$CPP%g -s%@CXX@%$CXX%g -s%@CXXCPP@%$CXXCPP%g -s%@CHECK_LANG_SYNTAX@%$CHECK_LANG_SYNTAX%g - -CEOF -EOF - -cat >> $CONFIG_STATUS <<\EOF - -# Split the substitutions into bite-sized pieces for seds with -# small command number limits, like on Digital OSF/1 and HP-UX. -ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script. -ac_file=1 # Number of current file. -ac_beg=1 # First line for current file. -ac_end=$ac_max_sed_cmds # Line after last line for current file. -ac_more_lines=: -ac_sed_cmds="" -while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file - else - sed "${ac_end}q" conftest.subs > conftest.s$ac_file - fi - if test ! -s conftest.s$ac_file; then - ac_more_lines=false - rm -f conftest.s$ac_file - else - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f conftest.s$ac_file" - else - ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file" - fi - ac_file=`expr $ac_file + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_cmds` - fi -done -if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat -fi -EOF - -cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF -for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case "$ac_file" in - *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` - ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; - *) ac_file_in="${ac_file}.in" ;; - esac - - # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories. - - # Remove last slash and all that follows it. Not all systems have dirname. - ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - # The file is in a subdirectory. - test ! -d "$ac_dir" && mkdir "$ac_dir" - ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`" - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` - else - ac_dir_suffix= ac_dots= - fi - - case "$ac_given_srcdir" in - .) srcdir=. - if test -z "$ac_dots"; then top_srcdir=. - else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;; - /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;; - *) # Relative path. - srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix" - top_srcdir="$ac_dots$ac_given_srcdir" ;; - esac - - - echo creating "$ac_file" - rm -f "$ac_file" - configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure." - case "$ac_file" in - *Makefile*) ac_comsub="1i\\ -# $configure_input" ;; - *) ac_comsub= ;; - esac - - ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` - sed -e "$ac_comsub -s%@configure_input@%$configure_input%g -s%@srcdir@%$srcdir%g -s%@top_srcdir@%$top_srcdir%g -" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file -fi; done -rm -f conftest.s* - -EOF -cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF - -exit 0 -EOF -chmod +x $CONFIG_STATUS -rm -fr confdefs* $ac_clean_files -test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1 - diff --git a/contrib/gperf/tests/configure.in b/contrib/gperf/tests/configure.in deleted file mode 100644 index a62450d903e8..000000000000 --- a/contrib/gperf/tests/configure.in +++ /dev/null @@ -1,45 +0,0 @@ -dnl autoconf configuration for gperf/tests - -dnl Copyright (C) 1998 Free Software Foundation, Inc. -dnl written by Douglas C. Schmidt (schmidt@ics.uci.edu) -dnl -dnl This file is part of GNU GPERF. -dnl -dnl GNU GPERF is free software; you can redistribute it and/or modify -dnl it under the terms of the GNU General Public License as published by -dnl the Free Software Foundation; either version 1, or (at your option) -dnl any later version. -dnl -dnl GNU GPERF is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -dnl GNU General Public License for more details. -dnl -dnl You should have received a copy of the GNU General Public License -dnl along with GNU GPERF; see the file COPYING. If not, write to the -dnl Free Software Foundation, 59 Temple Place - Suite 330, Boston, -dnl MA 02111-1307, USA. - -AC_INIT(c-parse.gperf) -AC_PROG_MAKE_SET -dnl -dnl checks for programs -dnl -AC_PROG_CC - dnl sets variable CC -AC_PROG_CPP - dnl sets variable CPP -AC_PROG_CXX - dnl sets variable CXX -AC_PROG_CXXCPP - dnl sets variable CXXCPP -if test $ac_cv_prog_gcc = yes -a $ac_cv_prog_gxx = yes; then - CHECK_LANG_SYNTAX='check-lang-syntax' -else - CHECK_LANG_SYNTAX='' -fi -AC_SUBST(CHECK_LANG_SYNTAX) -dnl -dnl That's it. -dnl -AC_OUTPUT(Makefile) diff --git a/contrib/gperf/tests/gpc.gperf b/contrib/gperf/tests/gpc.gperf deleted file mode 100644 index 8fb469e46bc6..000000000000 --- a/contrib/gperf/tests/gpc.gperf +++ /dev/null @@ -1,48 +0,0 @@ -%{ -/* ISO Pascal 7185 reserved words. - * - * For GNU Pascal compiler (GPC) by jtv@hut.fi - * - * run this through the Doug Schmidt's gperf program - * with command - * gperf -g -o -j1 -t -p -N is_reserved_word - * - */ -%} -struct resword { char *name; short token; short iclass;}; -%% -And, AND, PASCAL_ISO -Array, ARRAY, PASCAL_ISO -Begin, BEGIN_, PASCAL_ISO -Case, CASE, PASCAL_ISO -Const, CONST, PASCAL_ISO -Div, DIV, PASCAL_ISO -Do, DO, PASCAL_ISO -Downto, DOWNTO, PASCAL_ISO -Else, ELSE, PASCAL_ISO -End, END, PASCAL_ISO -File, FILE_, PASCAL_ISO -For, FOR, PASCAL_ISO -Function, FUNCTION, PASCAL_ISO -Goto, GOTO, PASCAL_ISO -If, IF, PASCAL_ISO -In, IN, PASCAL_ISO -Label, LABEL, PASCAL_ISO -Mod, MOD, PASCAL_ISO -Nil, NIL, PASCAL_ISO -Not, NOT, PASCAL_ISO -Of, OF, PASCAL_ISO -Or, OR, PASCAL_ISO -Packed, PACKED, PASCAL_ISO -Procedure, PROCEDURE, PASCAL_ISO -Program,PROGRAM,PASCAL_ISO -Record, RECORD, PASCAL_ISO -Repeat, REPEAT, PASCAL_ISO -Set, SET, PASCAL_ISO -Then, THEN, PASCAL_ISO -To, TO, PASCAL_ISO -Type, TYPE, PASCAL_ISO -Until, UNTIL, PASCAL_ISO -Var, VAR, PASCAL_ISO -While, WHILE, PASCAL_ISO -With, WITH, PASCAL_ISO diff --git a/contrib/gperf/tests/gplus.gperf b/contrib/gperf/tests/gplus.gperf deleted file mode 100644 index 4a93315be52f..000000000000 --- a/contrib/gperf/tests/gplus.gperf +++ /dev/null @@ -1,76 +0,0 @@ -%{ -/* Command-line: gperf -p -j1 -g -o -t -N is_reserved_word -k1,4,$ gplus.gperf */ -%} -struct resword { char *name; short token; enum rid rid;}; -%% -__alignof, ALIGNOF, NORID -__alignof__, ALIGNOF, NORID -__asm, ASM, NORID -__asm__, ASM, NORID -__attribute, ATTRIBUTE, NORID -__attribute__, ATTRIBUTE, NORID -__const, TYPE_QUAL, RID_CONST -__const__, TYPE_QUAL, RID_CONST -__inline, SCSPEC, RID_INLINE -__inline__, SCSPEC, RID_INLINE -__signed, TYPESPEC, RID_SIGNED -__signed__, TYPESPEC, RID_SIGNED -__typeof, TYPEOF, NORID -__typeof__, TYPEOF, NORID -__volatile, TYPE_QUAL, RID_VOLATILE -__volatile__, TYPE_QUAL, RID_VOLATILE -all, ALL, NORID /* Extension */, -except, EXCEPT, NORID /* Extension */, -exception, AGGR, RID_EXCEPTION /* Extension */, -raise, RAISE, NORID /* Extension */, -raises, RAISES, NORID /* Extension */, -reraise, RERAISE, NORID /* Extension */, -try, TRY, NORID /* Extension */, -asm, ASM, NORID, -auto, SCSPEC, RID_AUTO, -break, BREAK, NORID, -case, CASE, NORID, -catch, CATCH, NORID, -char, TYPESPEC, RID_CHAR, -class, AGGR, RID_CLASS, -const, TYPE_QUAL, RID_CONST, -continue, CONTINUE, NORID, -default, DEFAULT, NORID, -delete, DELETE, NORID, -do, DO, NORID, -double, TYPESPEC, RID_DOUBLE, -dynamic, DYNAMIC, NORID, -else, ELSE, NORID, -enum, ENUM, NORID, -extern, SCSPEC, RID_EXTERN, -float, TYPESPEC, RID_FLOAT, -for, FOR, NORID, -friend, SCSPEC, RID_FRIEND, -goto, GOTO, NORID, -if, IF, NORID, -inline, SCSPEC, RID_INLINE, -int, TYPESPEC, RID_INT, -long, TYPESPEC, RID_LONG, -new, NEW, NORID, -operator, OPERATOR, NORID, -overload, OVERLOAD, NORID, -private, PRIVATE, NORID, -protected, PROTECTED, NORID, -public, PUBLIC, NORID, -register, SCSPEC, RID_REGISTER, -return, RETURN, NORID, -short, TYPESPEC, RID_SHORT, -signed, TYPESPEC, RID_SIGNED, -sizeof, SIZEOF, NORID, -static, SCSPEC, RID_STATIC, -struct, AGGR, RID_RECORD, -switch, SWITCH, NORID, -this, THIS, NORID, -typedef, SCSPEC, RID_TYPEDEF, -typeof, TYPEOF, NORID, -union, AGGR, RID_UNION, -unsigned, TYPESPEC, RID_UNSIGNED, -virtual, SCSPEC, RID_VIRTUAL, -void, TYPESPEC, RID_VOID, -volatile, TYPE_QUAL, RID_VOLATILE, -while, WHILE, NORID, diff --git a/contrib/gperf/tests/irc.gperf b/contrib/gperf/tests/irc.gperf deleted file mode 100644 index afe53c59e7db..000000000000 --- a/contrib/gperf/tests/irc.gperf +++ /dev/null @@ -1,63 +0,0 @@ -%{ -extern int m_text(), m_private(), m_who(), m_whois(), m_user(), m_list(); -extern int m_topic(), m_invite(), m_channel(), m_version(), m_quit(); -extern int m_server(), m_kill(), m_info(), m_links(), m_summon(), m_stats(); -extern int m_users(), m_nick(), m_error(), m_help(), m_whoreply(); -extern int m_squit(), m_restart(), m_away(), m_die(), m_connect(); -extern int m_ping(), m_pong(), m_oper(), m_pass(), m_wall(), m_trace(); -extern int m_time(), m_rehash(), m_names(), m_namreply(), m_admin(); -extern int m_linreply(), m_notice(), m_lusers(), m_voice(), m_grph(); -extern int m_xtra(), m_motd(); -%} -struct Message { - char *cmd; - int (* func)(); - int count; - int parameters; -}; -%% -NICK, m_nick, 0, 1 -MSG, m_text, 0, 1 -PRIVMSG, m_private, 0, 2 -WHO, m_who, 0, 1 -WHOIS, m_whois, 0, 4 -USER, m_user, 0, 4 -SERVER, m_server, 0, 2 -LIST, m_list, 0, 1 -TOPIC, m_topic, 0, 1 -INVITE, m_invite, 0, 2 -CHANNEL, m_channel, 0, 1 -VERSION, m_version, 0, 1 -QUIT, m_quit, 0, 2 -SQUIT, m_squit, 0, 2 -KILL, m_kill, 0, 2 -INFO, m_info, 0, 1 -LINKS, m_links, 0, 1 -SUMMON, m_summon, 0, 1 -STATS, m_stats, 0, 1 -USERS, m_users, 0, 1 -RESTART, m_restart, 0, 1 -WHOREPLY,m_whoreply, 0, 7 -HELP, m_help, 0, 2 -ERROR, m_error, 0, 1 -AWAY, m_away, 0, 1 -DIE, m_die, 0, 1 -CONNECT, m_connect, 0, 3 -PING, m_ping, 0, 2 -PONG, m_pong, 0, 3 -OPER, m_oper, 0, 3 -PASS, m_pass, 0, 2 -WALL, m_wall, 0, 1 -TIME, m_time, 0, 1 -REHASH, m_rehash, 0, 1 -NAMES, m_names, 0, 1 -NAMREPLY,m_namreply, 0, 3 -ADMIN, m_admin, 0, 1 -TRACE, m_trace, 0, 1 -LINREPLY,m_linreply, 0, 2 -NOTICE, m_notice, 0, 2 -LUSERS, m_lusers, 0, 1 -VOICE, m_voice, 0, 2 -GRPH, m_grph, 0, 2 -XTRA, m_xtra, 0, 2 -MOTD, m_motd, 0, 2 diff --git a/contrib/gperf/tests/jscript.gperf b/contrib/gperf/tests/jscript.gperf deleted file mode 100644 index 6f420d8883ba..000000000000 --- a/contrib/gperf/tests/jscript.gperf +++ /dev/null @@ -1,73 +0,0 @@ -%{ -/* Command-line: gperf -k'1,2,$' -t -p -K 'name' -H 'js_kw_hash' -N 'js_kw_lookup' -a -g jscript.gperf */ -%} -struct js_keyword { - char * name; - int token; -} - -%% -# Javascript reserved words, see "keywords.html" -abstract, TK_ABSTRACT -boolean, TK_BOOLEAN -break, TK_BREAK -byte, TK_BYTE -case, TK_CASE -catch, TK_CATCH -char, TK_CHAR -class, TK_CLASS -const, TK_CONST -continue, TK_CONTINUE -default, TK_DEFAULT -do, TK_DO -double, TK_DOUBLE -else, TK_ELSE -extends, TK_EXTENDS -false, TK_FALSE -final, TK_FINAL -finally, TK_FINALLY -float, TK_FLOAT -for, TK_FOR -function, TK_FUNCTION -goto, TK_GOTO -if, TK_IF -implements, TK_IMPLEMENTS -import, TK_IMPORT -in, TK_IN -instanceof, TK_INSTANCEOF -int, TK_INT -interface, TK_INTERFACE -long, TK_LONG -native, TK_NATIVE -new, TK_NEW -null, TK_NULL -package, TK_PACKAGE -private, TK_PRIVATE -protected, TK_PROTECTED -public, TK_PUBLIC -return, TK_RETURN -short, TK_SHORT -static, TK_STATIC -super, TK_SUPER -switch, TK_SWITCH -synchronized, TK_SYNCHRONIZED -this, TK_THIS -throw, TK_THROW -throws, TK_THROWS -transient, TK_TRANSIENT -true, TK_TRUE -try, TK_TRY -var, TK_VAR -void, TK_VOID -while, TK_WHILE -with, TK_WITH -%% - -int js_keyword_lookup (register const char *str, register int len) -{ - struct js_keyword * keyword = js_kw_lookup(str,len); - if (keyword) - return keyword->token; - else - return TK_IDENT; -} diff --git a/contrib/gperf/tests/jstest1.gperf b/contrib/gperf/tests/jstest1.gperf deleted file mode 100644 index f6696b186858..000000000000 --- a/contrib/gperf/tests/jstest1.gperf +++ /dev/null @@ -1,142 +0,0 @@ -abstract -boolean -break -byte -case -catch -char -class -const -continue -default -do -double -else -extends -false -final -finally -float -for -function -goto -if -implements -import -in -instanceof -int -interface -long -native -new -null -package -private -protected -public -return -short -static -super -switch -synchronized -this -throw -throws -transient -true -try -var -void -while -with -%% -#include -#include -#if defined(__STDC__) || defined(__cplusplus) -#define CONST const -#else -#define CONST -#endif -static CONST char* testdata[] = { - "bogus", - "abstract", - "boolean", - "break", - "byte", - "case", - "catch", - "char", - "class", - "const", - "continue", - "default", - "do", - "double", - "else", - "extends", - "false", - "final", - "finally", - "float", - "for", - "function", - "goto", - "if", - "implements", - "import", - "in", - "instanceof", - "int", - "interface", - "long", - "native", - "new", - "null", - "package", - "private", - "protected", - "public", - "return", - "short", - "static", - "super", - "switch", - "synchronized", - "this", - "throw", - "throws", - "transient", - "true", - "try", - "var", - "void", - "while", - "with" -}; -int main () -{ - int i; - for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) - { -#ifdef CPLUSPLUS_TEST - CONST char * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); -#else - CONST char * resword = in_word_set(testdata[i],strlen(testdata[i])); -#endif - if (i > 0) - { - if (!resword) - exit (1); - if (strcmp(testdata[i],resword)) - exit (1); - } - else - { - if (resword) - exit (1); - } - } - return 0; -} diff --git a/contrib/gperf/tests/jstest2.gperf b/contrib/gperf/tests/jstest2.gperf deleted file mode 100644 index ee0fa7fde414..000000000000 --- a/contrib/gperf/tests/jstest2.gperf +++ /dev/null @@ -1,147 +0,0 @@ -struct js_keyword { - char * name; - int token; -} -%% -abstract, 1 -boolean, 2 -break, 3 -byte, 4 -case, 5 -catch, 6 -char, 7 -class, 8 -const, 9 -continue, 10 -default, 11 -do, 12 -double, 13 -else, 14 -extends, 15 -false, 16 -final, 17 -finally, 18 -float, 19 -for, 20 -function, 21 -goto, 22 -if, 23 -implements, 24 -import, 25 -in, 26 -instanceof, 27 -int, 28 -interface, 29 -long, 30 -native, 31 -new, 32 -null, 33 -package, 34 -private, 35 -protected, 36 -public, 37 -return, 38 -short, 39 -static, 40 -super, 41 -switch, 42 -synchronized, 43 -this, 44 -throw, 45 -throws, 46 -transient, 47 -true, 48 -try, 49 -var, 50 -void, 51 -while, 52 -with, 53 -%% -#include -#include -#if defined(__STDC__) || defined(__cplusplus) -#define CONST const -#else -#define CONST -#endif -static CONST char* testdata[] = { - "bogus", - "abstract", - "boolean", - "break", - "byte", - "case", - "catch", - "char", - "class", - "const", - "continue", - "default", - "do", - "double", - "else", - "extends", - "false", - "final", - "finally", - "float", - "for", - "function", - "goto", - "if", - "implements", - "import", - "in", - "instanceof", - "int", - "interface", - "long", - "native", - "new", - "null", - "package", - "private", - "protected", - "public", - "return", - "short", - "static", - "super", - "switch", - "synchronized", - "this", - "throw", - "throws", - "transient", - "true", - "try", - "var", - "void", - "while", - "with" -}; -int main () -{ - int i; - for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) - { -#ifdef CPLUSPLUS_TEST - CONST struct js_keyword * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); -#else - CONST struct js_keyword * resword = in_word_set(testdata[i],strlen(testdata[i])); -#endif - if (i > 0) - { - if (!resword) - exit (1); - if (strcmp(testdata[i],resword->name)) - exit (1); - } - else - { - if (resword) - exit (1); - } - } - return 0; -} diff --git a/contrib/gperf/tests/jstest3.gperf b/contrib/gperf/tests/jstest3.gperf deleted file mode 100644 index 54d37ce0e8cf..000000000000 --- a/contrib/gperf/tests/jstest3.gperf +++ /dev/null @@ -1,147 +0,0 @@ -struct js_keyword { - const char * name; - int token; -} -%% -abstract, 1 -boolean, 2 -break, 3 -byte, 4 -case, 5 -catch, 6 -char, 7 -class, 8 -const, 9 -continue, 10 -default, 11 -do, 12 -double, 13 -else, 14 -extends, 15 -false, 16 -final, 17 -finally, 18 -float, 19 -for, 20 -function, 21 -goto, 22 -if, 23 -implements, 24 -import, 25 -in, 26 -instanceof, 27 -int, 28 -interface, 29 -long, 30 -native, 31 -new, 32 -null, 33 -package, 34 -private, 35 -protected, 36 -public, 37 -return, 38 -short, 39 -static, 40 -super, 41 -switch, 42 -synchronized, 43 -this, 44 -throw, 45 -throws, 46 -transient, 47 -true, 48 -try, 49 -var, 50 -void, 51 -while, 52 -with, 53 -%% -#include -#include -#if defined(__STDC__) || defined(__cplusplus) -#define CONST const -#else -#define CONST -#endif -static CONST char* testdata[] = { - "bogus", - "abstract", - "boolean", - "break", - "byte", - "case", - "catch", - "char", - "class", - "const", - "continue", - "default", - "do", - "double", - "else", - "extends", - "false", - "final", - "finally", - "float", - "for", - "function", - "goto", - "if", - "implements", - "import", - "in", - "instanceof", - "int", - "interface", - "long", - "native", - "new", - "null", - "package", - "private", - "protected", - "public", - "return", - "short", - "static", - "super", - "switch", - "synchronized", - "this", - "throw", - "throws", - "transient", - "true", - "try", - "var", - "void", - "while", - "with" -}; -int main () -{ - int i; - for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) - { -#ifdef CPLUSPLUS_TEST - CONST struct js_keyword * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i])); -#else - CONST struct js_keyword * resword = in_word_set(testdata[i],strlen(testdata[i])); -#endif - if (i > 0) - { - if (!resword) - exit (1); - if (strcmp(testdata[i],resword->name)) - exit (1); - } - else - { - if (resword) - exit (1); - } - } - return 0; -} diff --git a/contrib/gperf/tests/makeinfo.gperf b/contrib/gperf/tests/makeinfo.gperf deleted file mode 100644 index 1488b8e38fbe..000000000000 --- a/contrib/gperf/tests/makeinfo.gperf +++ /dev/null @@ -1,116 +0,0 @@ -COMMAND; -%% -!, cm_force_sentence_end, false -', insert_self, false -*, cm_asterisk, false -., cm_force_sentence_end, false -:, cm_force_abbreviated_whitespace, false -?, cm_force_sentence_end, false -@, insert_self, false -TeX, cm_TeX, true -`, insert_self, false -appendix, cm_appendix, false -appendixsec, cm_appendixsec, false -appendixsubsec, cm_appendixsubsec, false -asis, cm_asis, true -b, cm_bold, true -br, cm_br, false -bullet, cm_bullet, true -bye, cm_bye, false -c, cm_comment, false -center, cm_center, false -chapter, cm_chapter, false -cindex, cm_cindex, false -cite, cm_cite, true -code, cm_code, true -comment, cm_comment, false -contents, do_nothing, false -copyright, cm_copyright, true -ctrl, cm_ctrl, true -defcodeindex, cm_defindex, false -defindex, cm_defindex, false -dfn, cm_dfn, true -display, cm_display, false -dots, cm_dots, true -emph, cm_emph, true -end, cm_end, false -enumerate, cm_enumerate, false -equiv, cm_equiv, true -error, cm_error, true -example, cm_example, false -exdent, cm_exdent, false -expansion, cm_expansion, true -file, cm_file, true -findex, cm_findex, false -format, cm_format, false -group, cm_group, false -i, cm_italic, true -iappendix, cm_appendix, false -iappendixsec, cm_appendixsec, false -iappendixsubsec, cm_appendixsubsec, false -ichapter, cm_chapter, false -ifinfo, cm_ifinfo, false -iftex, cm_iftex, false -ignore, cm_ignore, false -include, cm_include, false -inforef, cm_inforef, true -input, cm_include, false -isection, cm_section, false -isubsection, cm_subsection, false -isubsubsection, cm_subsubsection, false -item, cm_item, false -itemize, cm_itemize, false -itemx, cm_itemx, false -iunnumbered, cm_unnumbered, false -iunnumberedsec, cm_unnumberedsec, false -iunnumberedsubsec, cm_unnumberedsubsec, false -kbd, cm_kbd, true -key, cm_key, true -kindex, cm_kindex, false -lisp, cm_lisp, false -menu, cm_menu -minus, cm_minus, true -need, cm_need, false -node, cm_node, false -noindent, cm_noindent, false -page, do_nothing, false -pindex, cm_pindex, false -point, cm_point, true -print, cm_print, true -printindex, cm_printindex, false -pxref, cm_pxref, true -quotation, cm_quotation, false -r, cm_roman, true -ref, cm_xref, true -refill, cm_refill, false -result, cm_result, true -samp, cm_samp, true -sc, cm_sc, true -section, cm_section, false -setchapternewpage, cm_setchapternewpage, false -setfilename, cm_setfilename, false -settitle, cm_settitle, false -smallexample, cm_smallexample, false -sp, cm_sp, false -strong, cm_strong, true -subsection, cm_subsection, false -subsubsection, cm_subsubsection, false -summarycontents, do_nothing, false -syncodeindex, cm_synindex, false -synindex, cm_synindex, false -t, cm_title, true -table, cm_table, false -tex, cm_tex, false -tindex, cm_tindex, false -titlepage, cm_titlepage, false -unnumbered, cm_unnumbered, false -unnumberedsec, cm_unnumberedsec, false -unnumberedsubsec, cm_unnumberedsubsec, false -var, cm_var, true -vindex, cm_vindex, false -w, cm_w, true -xref, cm_xref, true -{, insert_self, false -}, insert_self, false -infoinclude, cm_infoinclude, false -footnote, cm_footnote, false diff --git a/contrib/gperf/tests/modula.exp b/contrib/gperf/tests/modula.exp deleted file mode 100644 index cef7d5acad8b..000000000000 --- a/contrib/gperf/tests/modula.exp +++ /dev/null @@ -1,106 +0,0 @@ -in word set AND -in word set ARRAY -in word set BEGIN -in word set BITS -in word set BY -in word set CASE -in word set CONST -in word set DIV -in word set DO -in word set ELSE -in word set ELSIF -in word set END -in word set EVAL -in word set EXCEPT -in word set EXCEPTION -in word set EXIT -in word set EXPORTS -in word set FINALLY -in word set FOR -in word set FROM -in word set IF -in word set IMPORT -in word set INTERFACE -in word set IN -in word set INLINE -in word set LOCK -in word set METHODS -in word set MOD -in word set MODULE -in word set NOT -in word set OBJECT -in word set OF -in word set OR -in word set PROCEDURE -in word set RAISES -in word set READONLY -in word set RECORD -in word set REF -in word set REPEAT -in word set RETURN -in word set SET -in word set THEN -in word set TO -in word set TRY -in word set TYPE -in word set TYPECASE -in word set UNSAFE -in word set UNTIL -in word set UNTRACED -in word set VALUE -in word set VAR -in word set WHILE -in word set WITH -in word set and -in word set array -in word set begin -in word set bits -in word set by -in word set case -in word set const -in word set div -in word set do -in word set else -in word set elsif -in word set end -in word set eval -in word set except -in word set exception -in word set exit -in word set exports -in word set finally -in word set for -in word set from -in word set if -in word set import -in word set interface -in word set in -in word set inline -in word set lock -in word set methods -in word set mod -in word set module -in word set not -in word set object -in word set of -in word set or -in word set procedure -in word set raises -in word set readonly -in word set record -in word set ref -in word set repeat -in word set return -in word set set -in word set then -in word set to -in word set try -in word set type -in word set typecase -in word set unsafe -in word set until -in word set untraced -in word set value -in word set var -in word set while -in word set with diff --git a/contrib/gperf/tests/modula2.gperf b/contrib/gperf/tests/modula2.gperf deleted file mode 100644 index 5ef9c7538354..000000000000 --- a/contrib/gperf/tests/modula2.gperf +++ /dev/null @@ -1,40 +0,0 @@ -AND -ARRAY -BEGIN -BY -CASE -CONST -DEFINITION -DIV -DO -ELSE -ELSIF -END -EXIT -EXPORT -FOR -FROM -IF -IMPLEMENTATION -IMPORT -IN -LOOP -MOD -MODULE -NOT -OF -OR -POINTER -PROCEDURE -QUALIFIED -RECORD -REPEAT -RETURN -SET -THEN -TO -TYPE -UNTIL -VAR -WHILE -WITH diff --git a/contrib/gperf/tests/modula3.gperf b/contrib/gperf/tests/modula3.gperf deleted file mode 100644 index d0243460d9ba..000000000000 --- a/contrib/gperf/tests/modula3.gperf +++ /dev/null @@ -1,106 +0,0 @@ -AND -ARRAY -BEGIN -BITS -BY -CASE -CONST -DIV -DO -ELSE -ELSIF -END -EVAL -EXCEPT -EXCEPTION -EXIT -EXPORTS -FINALLY -FOR -FROM -IF -IMPORT -INTERFACE -IN -INLINE -LOCK -METHODS -MOD -MODULE -NOT -OBJECT -OF -OR -PROCEDURE -RAISES -READONLY -RECORD -REF -REPEAT -RETURN -SET -THEN -TO -TRY -TYPE -TYPECASE -UNSAFE -UNTIL -UNTRACED -VALUE -VAR -WHILE -WITH -and -array -begin -bits -by -case -const -div -do -else -elsif -end -eval -except -exception -exit -exports -finally -for -from -if -import -interface -in -inline -lock -methods -mod -module -not -object -of -or -procedure -raises -readonly -record -ref -repeat -return -set -then -to -try -type -typecase -unsafe -until -untraced -value -var -while -with diff --git a/contrib/gperf/tests/pascal.exp b/contrib/gperf/tests/pascal.exp deleted file mode 100644 index 765e44c6a0fe..000000000000 --- a/contrib/gperf/tests/pascal.exp +++ /dev/null @@ -1,36 +0,0 @@ -in word set with -in word set array -in word set and -in word set function -in word set case -in word set var -in word set const -in word set until -in word set then -in word set set -in word set record -in word set program -in word set procedure -in word set or -in word set packed -in word set not -in word set nil -in word set label -in word set in -in word set repeat -in word set of -in word set goto -in word set forward -in word set for -in word set while -in word set file -in word set else -in word set downto -in word set do -in word set div -in word set to -in word set type -in word set end -in word set mod -in word set begin -in word set if diff --git a/contrib/gperf/tests/pascal.gperf b/contrib/gperf/tests/pascal.gperf deleted file mode 100644 index fed3fbb30eac..000000000000 --- a/contrib/gperf/tests/pascal.gperf +++ /dev/null @@ -1,36 +0,0 @@ -with -array -and -function -case -var -const -until -then -set -record -program -procedure -or -packed -not -nil -label -in -repeat -of -goto -forward -for -while -file -else -downto -do -div -to -type -end -mod -begin -if diff --git a/contrib/gperf/tests/test-1.exp b/contrib/gperf/tests/test-1.exp deleted file mode 100644 index 462fea5d0ec5..000000000000 --- a/contrib/gperf/tests/test-1.exp +++ /dev/null @@ -1,153 +0,0 @@ -/* C code produced by gperf version 2.7 */ -/* Command-line: ../src/gperf -p -j1 -g -o -t -N is_reserved_word -k1,3,$ */ -/* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf */ -struct resword { char *name; short token; enum rid rid; }; - -#define TOTAL_KEYWORDS 51 -#define MIN_WORD_LENGTH 2 -#define MAX_WORD_LENGTH 13 -#define MIN_HASH_VALUE 8 -#define MAX_HASH_VALUE 82 -/* maximum key range = 75, duplicates = 0 */ - -#ifdef __GNUC__ -__inline -#endif -static unsigned int -hash (str, len) - register const char *str; - register unsigned int len; -{ - static unsigned char asso_values[] = - { - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 0, 83, 1, 2, 34, - 19, 6, 11, 29, 0, 17, 83, 0, 23, 28, - 26, 30, 31, 83, 15, 1, 0, 28, 13, 4, - 83, 83, 5, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83 - }; - register int hval = len; - - switch (hval) - { - default: - case 3: - hval += asso_values[(unsigned char)str[2]]; - case 2: - case 1: - hval += asso_values[(unsigned char)str[0]]; - break; - } - return hval + asso_values[(unsigned char)str[len - 1]]; -} - -#ifdef __GNUC__ -__inline -#endif -struct resword * -is_reserved_word (str, len) - register const char *str; - register unsigned int len; -{ - static struct resword wordlist[] = - { - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {"__asm__", ASM, NORID}, - {""}, - {"__typeof__", TYPEOF, NORID}, - {"__signed__", TYPESPEC, RID_SIGNED}, - {"__alignof__", ALIGNOF, NORID}, - {"break", BREAK, NORID}, - {"__attribute__", ATTRIBUTE, NORID}, - {""}, {""}, - {"else", ELSE, NORID}, - {"__attribute", ATTRIBUTE, NORID}, - {"__typeof", TYPEOF, NORID}, - {"int", TYPESPEC, RID_INT}, - {"__alignof", ALIGNOF, NORID}, - {"struct", STRUCT, NORID}, - {"sizeof", SIZEOF, NORID}, - {"switch", SWITCH, NORID}, - {"__volatile__", TYPE_QUAL, RID_VOLATILE}, - {""}, - {"__inline__", SCSPEC, RID_INLINE}, - {"__signed", TYPESPEC, RID_SIGNED}, - {"__volatile", TYPE_QUAL, RID_VOLATILE}, - {"if", IF, NORID}, - {"__inline", SCSPEC, RID_INLINE}, - {"while", WHILE, NORID}, - {""}, - {"__asm", ASM, NORID}, - {"auto", SCSPEC, RID_AUTO}, - {"short", TYPESPEC, RID_SHORT}, - {"default", DEFAULT, NORID}, - {"extern", SCSPEC, RID_EXTERN}, - {""}, {""}, - {"__const", TYPE_QUAL, RID_CONST}, - {"static", SCSPEC, RID_STATIC}, - {"__const__", TYPE_QUAL, RID_CONST}, - {"for", FOR, NORID}, - {"case", CASE, NORID}, - {"float", TYPESPEC, RID_FLOAT}, - {"return", RETURN, NORID}, - {"typeof", TYPEOF, NORID}, - {"typedef", SCSPEC, RID_TYPEDEF}, - {"volatile", TYPE_QUAL, RID_VOLATILE}, - {"do", DO, NORID}, - {"inline", SCSPEC, RID_INLINE}, - {"void", TYPESPEC, RID_VOID}, - {"char", TYPESPEC, RID_CHAR}, - {"signed", TYPESPEC, RID_SIGNED}, - {"unsigned", TYPESPEC, RID_UNSIGNED}, - {""}, {""}, - {"double", TYPESPEC, RID_DOUBLE}, - {"asm", ASM, NORID}, - {""}, {""}, - {"goto", GOTO, NORID}, - {""}, - {"const", TYPE_QUAL, RID_CONST}, - {"enum", ENUM, NORID}, - {"register", SCSPEC, RID_REGISTER}, - {""}, {""}, {""}, {""}, {""}, {""}, - {"continue", CONTINUE, NORID}, - {""}, - {"union", UNION, NORID}, - {""}, {""}, {""}, {""}, {""}, - {"long", TYPESPEC, RID_LONG} - }; - - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) - { - register int key = hash (str, len); - - if (key <= MAX_HASH_VALUE && key >= 0) - { - register const char *s = wordlist[key].name; - - if (*str == *s && !strcmp (str + 1, s + 1)) - return &wordlist[key]; - } - } - return 0; -} diff --git a/contrib/gperf/tests/test-2.exp b/contrib/gperf/tests/test-2.exp deleted file mode 100644 index 3b9e7b094131..000000000000 --- a/contrib/gperf/tests/test-2.exp +++ /dev/null @@ -1,202 +0,0 @@ -/* C code produced by gperf version 2.7 */ -/* Command-line: ../src/gperf -n -k1-8 -l */ - -#define TOTAL_KEYWORDS 40 -#define MIN_WORD_LENGTH 2 -#define MAX_WORD_LENGTH 14 -#define MIN_HASH_VALUE 1 -#define MAX_HASH_VALUE 256 -/* maximum key range = 256, duplicates = 0 */ - -#ifdef __GNUC__ -__inline -#endif -static unsigned int -hash (str, len) - register const char *str; - register unsigned int len; -{ - static unsigned short asso_values[] = - { - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 25, 30, 35, 21, 0, - 30, 15, 30, 45, 257, 257, 0, 5, 45, 0, - 10, 0, 1, 20, 25, 15, 30, 40, 15, 5, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - 257, 257, 257, 257, 257, 257 - }; - register int hval = 0; - - switch (len) - { - default: - case 8: - hval += asso_values[(unsigned char)str[7]]; - case 7: - hval += asso_values[(unsigned char)str[6]]; - case 6: - hval += asso_values[(unsigned char)str[5]]; - case 5: - hval += asso_values[(unsigned char)str[4]]; - case 4: - hval += asso_values[(unsigned char)str[3]]; - case 3: - hval += asso_values[(unsigned char)str[2]]; - case 2: - hval += asso_values[(unsigned char)str[1]]; - case 1: - hval += asso_values[(unsigned char)str[0]]; - break; - } - return hval; -} - -#ifdef __GNUC__ -__inline -#endif -const char * -in_word_set (str, len) - register const char *str; - register unsigned int len; -{ - static unsigned char lengthtable[] = - { - 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 2, 3, 0, - 0, 0, 2, 3, 0, 0, 0, 2, 4, 0, 0, 0, 4, 6, - 0, 0, 0, 3, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, - 3, 5, 6, 0, 0, 6, 0, 0, 0, 0, 3, 0, 0, 0, - 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 4, 0, 0, 9, - 0, 4, 6, 6, 0, 0, 2, 3, 0, 0, 0, 5, 3, 0, - 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, - 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, - 7, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 10 - }; - static const char * wordlist[] = - { - "", - "OR", - "", "", "", "", "", "", "", "", - "LOOP", - "", "", "", "", "", "", "", "", "", - "ELSE", - "DO", - "", "", "", - "TO", - "MOD", - "", "", "", - "OF", - "FOR", - "", "", "", - "BY", - "FROM", - "", "", "", - "TYPE", - "MODULE", - "", "", "", - "SET", - "", "", "", "", "", - "EXPORT", - "", "", "", "", - "VAR", - "ARRAY", - "RECORD", - "", "", - "REPEAT", - "", "", "", "", - "END", - "", "", "", - "NOT", - "", "", "", "", - "IF", - "", "", "", "", - "CASE", - "", "", - "PROCEDURE", - "", - "EXIT", - "IMPORT", - "RETURN", - "", "", - "IN", - "AND", - "", "", "", - "ELSIF", - "DIV", - "", "", "", - "THEN", - "", "", "", "", "", "", "", "", "", - "IMPLEMENTATION", - "", "", "", "", - "WHILE", - "", "", "", "", "", "", "", "", "", - "CONST", - "POINTER", - "", "", "", - "UNTIL", - "", "", "", "", - "BEGIN", - "", "", "", "", - "WITH", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", - "", - "QUALIFIED", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", - "", "", "", "", "", - "DEFINITION" - }; - - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) - { - register int key = hash (str, len); - - if (key <= MAX_HASH_VALUE && key >= 0) - if (len == lengthtable[key]) - { - register const char *s = wordlist[key]; - - if (*str == *s && !strcmp (str + 1, s + 1)) - return s; - } - } - return 0; -} diff --git a/contrib/gperf/tests/test-3.exp b/contrib/gperf/tests/test-3.exp deleted file mode 100644 index fe0a1a6dafdf..000000000000 --- a/contrib/gperf/tests/test-3.exp +++ /dev/null @@ -1,186 +0,0 @@ -/* C code produced by gperf version 2.7 */ -/* Command-line: ../src/gperf -p -j 1 -o -a -C -g -t -k1,4,$ */ -/* Command-line: gperf -p -j1 -g -o -t -N is_reserved_word -k1,4,$ gplus.gperf */ -struct resword { char *name; short token; enum rid rid;}; - -#define TOTAL_KEYWORDS 71 -#define MIN_WORD_LENGTH 2 -#define MAX_WORD_LENGTH 13 -#define MIN_HASH_VALUE 4 -#define MAX_HASH_VALUE 147 -/* maximum key range = 144, duplicates = 0 */ - -#ifdef __GNUC__ -__inline -#endif -static unsigned int -hash (str, len) - register const char *str; - register unsigned int len; -{ - static const unsigned char asso_values[] = - { - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 0, 148, 19, 6, 27, - 37, 0, 12, 1, 15, 63, 148, 4, 0, 56, - 20, 15, 42, 148, 31, 5, 26, 39, 32, 10, - 148, 40, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, - 148, 148, 148, 148, 148, 148 - }; - register int hval = len; - - switch (hval) - { - default: - case 4: - hval += asso_values[(unsigned char)str[3]]; - case 3: - case 2: - case 1: - hval += asso_values[(unsigned char)str[0]]; - break; - } - return hval + asso_values[(unsigned char)str[len - 1]]; -} - -#ifdef __GNUC__ -__inline -#endif -const struct resword * -in_word_set (str, len) - register const char *str; - register unsigned int len; -{ - static const struct resword wordlist[] = - { - {""}, {""}, {""}, {""}, - {"else", ELSE, NORID,}, - {""}, - {"long", TYPESPEC, RID_LONG,}, - {""}, {""}, {""}, {""}, - {"__alignof__", ALIGNOF, NORID}, - {"__asm__", ASM, NORID}, - {""}, {""}, - {"while", WHILE, NORID,}, - {""}, {""}, {""}, {""}, {""}, - {"__alignof", ALIGNOF, NORID}, - {"all", ALL, NORID /* Extension */,}, - {"sizeof", SIZEOF, NORID,}, - {"__const__", TYPE_QUAL, RID_CONST}, - {"__volatile", TYPE_QUAL, RID_VOLATILE}, - {"extern", SCSPEC, RID_EXTERN,}, - {"__volatile__", TYPE_QUAL, RID_VOLATILE}, - {"__inline", SCSPEC, RID_INLINE}, - {"exception", AGGR, RID_EXCEPTION /* Extension */,}, - {"__inline__", SCSPEC, RID_INLINE}, - {"case", CASE, NORID,}, - {"except", EXCEPT, NORID /* Extension */,}, - {"new", NEW, NORID,}, - {"break", BREAK, NORID,}, - {"goto", GOTO, NORID,}, - {""}, - {"__attribute", ATTRIBUTE, NORID}, - {""}, - {"__attribute__", ATTRIBUTE, NORID}, - {"this", THIS, NORID,}, - {"raise", RAISE, NORID /* Extension */,}, - {"class", AGGR, RID_CLASS,}, - {"delete", DELETE, NORID,}, - {"typeof", TYPEOF, NORID,}, - {"typedef", SCSPEC, RID_TYPEDEF,}, - {"for", FOR, NORID,}, - {"raises", RAISES, NORID /* Extension */,}, - {"__const", TYPE_QUAL, RID_CONST}, - {"double", TYPESPEC, RID_DOUBLE,}, - {"__typeof__", TYPEOF, NORID}, - {""}, - {"switch", SWITCH, NORID,}, - {"auto", SCSPEC, RID_AUTO,}, - {"do", DO, NORID,}, - {"friend", SCSPEC, RID_FRIEND,}, - {""}, - {"reraise", RERAISE, NORID /* Extension */,}, - {""}, - {"volatile", TYPE_QUAL, RID_VOLATILE,}, - {"__typeof", TYPEOF, NORID}, - {"continue", CONTINUE, NORID,}, - {"float", TYPESPEC, RID_FLOAT,}, - {"const", TYPE_QUAL, RID_CONST,}, - {"static", SCSPEC, RID_STATIC,}, - {"virtual", SCSPEC, RID_VIRTUAL,}, - {"__asm", ASM, NORID}, - {"short", TYPESPEC, RID_SHORT,}, - {"signed", TYPESPEC, RID_SIGNED,}, - {"try", TRY, NORID /* Extension */,}, - {""}, {""}, {""}, - {"__signed__", TYPESPEC, RID_SIGNED}, - {"catch", CATCH, NORID,}, - {"public", PUBLIC, NORID,}, - {"struct", AGGR, RID_RECORD,}, - {"if", IF, NORID,}, - {"asm", ASM, NORID,}, - {"union", AGGR, RID_UNION,}, - {""}, - {"private", PRIVATE, NORID,}, - {""}, {""}, {""}, - {"operator", OPERATOR, NORID,}, - {""}, {""}, {""}, - {"default", DEFAULT, NORID,}, - {"dynamic", DYNAMIC, NORID,}, - {"overload", OVERLOAD, NORID,}, - {"int", TYPESPEC, RID_INT,}, - {"char", TYPESPEC, RID_CHAR,}, - {""}, {""}, - {"return", RETURN, NORID,}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, - {"__signed", TYPESPEC, RID_SIGNED}, - {""}, - {"void", TYPESPEC, RID_VOID,}, - {""}, {""}, {""}, - {"protected", PROTECTED, NORID,}, - {""}, - {"enum", ENUM, NORID,}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, - {"inline", SCSPEC, RID_INLINE,}, - {"register", SCSPEC, RID_REGISTER,}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, - {"unsigned", TYPESPEC, RID_UNSIGNED,} - }; - - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) - { - register int key = hash (str, len); - - if (key <= MAX_HASH_VALUE && key >= 0) - { - register const char *s = wordlist[key].name; - - if (*str == *s && !strcmp (str + 1, s + 1)) - return &wordlist[key]; - } - } - return 0; -} diff --git a/contrib/gperf/tests/test-4.exp b/contrib/gperf/tests/test-4.exp deleted file mode 100644 index b5279688714d..000000000000 --- a/contrib/gperf/tests/test-4.exp +++ /dev/null @@ -1,162 +0,0 @@ -/* C code produced by gperf version 2.7 */ -/* Command-line: ../src/gperf -D -p -t */ -/* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf */ -struct resword { char *name; short token; enum rid rid; }; - -#define TOTAL_KEYWORDS 51 -#define MIN_WORD_LENGTH 2 -#define MAX_WORD_LENGTH 13 -#define MIN_HASH_VALUE 4 -#define MAX_HASH_VALUE 82 -/* maximum key range = 79, duplicates = 2 */ - -#ifdef __GNUC__ -__inline -#endif -static unsigned int -hash (str, len) - register const char *str; - register unsigned int len; -{ - static unsigned char asso_values[] = - { - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 0, 83, 40, 20, 50, - 25, 10, 30, 0, 0, 50, 83, 0, 15, 0, - 35, 0, 83, 83, 20, 0, 10, 40, 5, 15, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83 - }; - return len + asso_values[(unsigned char)str[len - 1]] + asso_values[(unsigned char)str[0]]; -} - -#ifdef __GNUC__ -__inline -#endif -struct resword * -in_word_set (str, len) - register const char *str; - register unsigned int len; -{ - static struct resword wordlist[] = - { - {"goto", GOTO, NORID}, - {"__asm", ASM, NORID}, - {"switch", SWITCH, NORID}, - {"__asm__", ASM, NORID}, - {"__const__", TYPE_QUAL, RID_CONST}, - {"__inline__", SCSPEC, RID_INLINE}, - {"__typeof__", TYPEOF, NORID}, - {"__signed__", TYPESPEC, RID_SIGNED}, - {"__alignof__", ALIGNOF, NORID}, - {"__volatile__", TYPE_QUAL, RID_VOLATILE}, - {"__attribute__", ATTRIBUTE, NORID}, - {"enum", ENUM, NORID}, - {"short", TYPESPEC, RID_SHORT}, - {"struct", STRUCT, NORID}, - {"__const", TYPE_QUAL, RID_CONST}, - {"__inline", SCSPEC, RID_INLINE}, - {"long", TYPESPEC, RID_LONG}, - {"__volatile", TYPE_QUAL, RID_VOLATILE}, - {"__attribute", ATTRIBUTE, NORID}, - {"volatile", TYPE_QUAL, RID_VOLATILE}, - {"else", ELSE, NORID}, - {"break", BREAK, NORID}, - {"do", DO, NORID}, - {"while", WHILE, NORID}, - {"signed", TYPESPEC, RID_SIGNED}, - {"__signed", TYPESPEC, RID_SIGNED}, - {"void", TYPESPEC, RID_VOID}, - {"sizeof", SIZEOF, NORID}, - {"__typeof", TYPEOF, NORID}, - {"__alignof", ALIGNOF, NORID}, - {"double", TYPESPEC, RID_DOUBLE}, - {"default", DEFAULT, NORID}, - {"asm", ASM, NORID}, - {"auto", SCSPEC, RID_AUTO}, - {"float", TYPESPEC, RID_FLOAT}, - {"typeof", TYPEOF, NORID}, - {"typedef", SCSPEC, RID_TYPEDEF}, - {"register", SCSPEC, RID_REGISTER}, - {"extern", SCSPEC, RID_EXTERN}, - {"for", FOR, NORID}, - {"static", SCSPEC, RID_STATIC}, - {"return", RETURN, NORID}, - {"int", TYPESPEC, RID_INT}, - {"case", CASE, NORID}, - {"const", TYPE_QUAL, RID_CONST}, - {"inline", SCSPEC, RID_INLINE}, - {"continue", CONTINUE, NORID}, - {"unsigned", TYPESPEC, RID_UNSIGNED}, - {"char", TYPESPEC, RID_CHAR}, - {"union", UNION, NORID}, - {"if", IF, NORID} - }; - - static short lookup[] = - { - -1, -1, -1, -1, 0, 1, 2, 3, -1, 4, - -80, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, -1, 19, 20, 21, -1, 22, -46, -3, - 23, 24, -1, 25, 26, -1, 27, -1, 28, 29, - -1, 30, 31, 32, 33, 34, 35, 36, 37, -1, - -1, 38, -1, 39, -1, -1, 40, -1, -1, -1, - -1, 41, -1, 42, 43, 44, 45, -1, 46, -1, - -1, -1, -1, 47, 48, -1, -1, -1, -1, -1, - 49, -1, 50 - }; - - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) - { - register int key = hash (str, len); - - if (key <= MAX_HASH_VALUE && key >= 0) - { - register int index = lookup[key]; - - if (index >= 0) - { - register const char *s = wordlist[index].name; - - if (*str == *s && !strcmp (str + 1, s + 1)) - return &wordlist[index]; - } - else if (index < -TOTAL_KEYWORDS) - { - register int offset = - 1 - TOTAL_KEYWORDS - index; - register struct resword *wordptr = &wordlist[TOTAL_KEYWORDS + lookup[offset]]; - register struct resword *wordendptr = wordptr + -lookup[offset + 1]; - - while (wordptr < wordendptr) - { - register const char *s = wordptr->name; - - if (*str == *s && !strcmp (str + 1, s + 1)) - return wordptr; - wordptr++; - } - } - } - } - return 0; -} diff --git a/contrib/gperf/tests/test-5.exp b/contrib/gperf/tests/test-5.exp deleted file mode 100644 index 8f4d9ab8a62c..000000000000 --- a/contrib/gperf/tests/test-5.exp +++ /dev/null @@ -1,124 +0,0 @@ -/* C code produced by gperf version 2.7 */ -/* Command-line: ../src/gperf -g -o -j1 -t -p -N is_reserved_word */ -/* ISO Pascal 7185 reserved words. - * - * For GNU Pascal compiler (GPC) by jtv@hut.fi - * - * run this through the Doug Schmidt's gperf program - * with command - * gperf -g -o -j1 -t -p -N is_reserved_word - * - */ -struct resword { char *name; short token; short iclass;}; - -#define TOTAL_KEYWORDS 35 -#define MIN_WORD_LENGTH 2 -#define MAX_WORD_LENGTH 9 -#define MIN_HASH_VALUE 2 -#define MAX_HASH_VALUE 43 -/* maximum key range = 42, duplicates = 0 */ - -#ifdef __GNUC__ -__inline -#endif -static unsigned int -hash (str, len) - register const char *str; - register unsigned int len; -{ - static unsigned char asso_values[] = - { - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 18, 29, 14, 6, 7, - 10, 20, 44, 28, 44, 44, 28, 19, 22, 15, - 0, 44, 9, 23, 0, 23, 26, 2, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 0, 0, 13, 44, 30, 44, 44, 44, 0, 25, - 1, 0, 44, 44, 0, 44, 1, 44, 25, 44, - 44, 0, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44 - }; - return len + asso_values[(unsigned char)str[len - 1]] + asso_values[(unsigned char)str[0]]; -} - -#ifdef __GNUC__ -__inline -#endif -struct resword * -is_reserved_word (str, len) - register const char *str; - register unsigned int len; -{ - static struct resword wordlist[] = - { - {""}, {""}, - {"To", TO, PASCAL_ISO}, - {""}, - {"Type", TYPE, PASCAL_ISO}, - {"Then", THEN, PASCAL_ISO}, - {"Packed", PACKED, PASCAL_ISO}, - {"While", WHILE, PASCAL_ISO}, - {"Do", DO, PASCAL_ISO}, - {"Procedure", PROCEDURE, PASCAL_ISO}, - {"End", END, PASCAL_ISO}, - {"Else", ELSE, PASCAL_ISO}, - {"Downto", DOWNTO, PASCAL_ISO}, - {"For", FOR, PASCAL_ISO}, - {"File", FILE_, PASCAL_ISO}, - {"Record", RECORD, PASCAL_ISO}, - {"Repeat", REPEAT, PASCAL_ISO}, - {"Or", OR, PASCAL_ISO}, - {"Case", CASE, PASCAL_ISO}, - {"Function", FUNCTION, PASCAL_ISO}, - {"Const", CONST, PASCAL_ISO}, - {"And", AND, PASCAL_ISO}, - {"Mod", MOD, PASCAL_ISO}, - {"Array", ARRAY, PASCAL_ISO}, - {"Goto", GOTO, PASCAL_ISO}, - {"Nil", NIL, PASCAL_ISO}, - {"Not", NOT, PASCAL_ISO}, - {"Set", SET, PASCAL_ISO}, - {"Until", UNTIL, PASCAL_ISO}, - {"Var", VAR, PASCAL_ISO}, - {"Of", OF, PASCAL_ISO}, - {"In", IN, PASCAL_ISO}, - {"Program",PROGRAM,PASCAL_ISO}, - {"Label", LABEL, PASCAL_ISO}, - {"Div", DIV, PASCAL_ISO}, - {"Begin", BEGIN_, PASCAL_ISO}, - {"With", WITH, PASCAL_ISO}, - {""}, {""}, {""}, {""}, {""}, {""}, - {"If", IF, PASCAL_ISO} - }; - - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) - { - register int key = hash (str, len); - - if (key <= MAX_HASH_VALUE && key >= 0) - { - register const char *s = wordlist[key].name; - - if (*str == *s && !strcmp (str + 1, s + 1)) - return &wordlist[key]; - } - } - return 0; -} diff --git a/contrib/gperf/tests/test-6.exp b/contrib/gperf/tests/test-6.exp deleted file mode 100644 index 3521f13c41c4..000000000000 --- a/contrib/gperf/tests/test-6.exp +++ /dev/null @@ -1,119 +0,0 @@ -GNU `gperf' generates perfect hash functions. - -Usage: ../src/gperf [OPTION]... [INPUT-FILE] - -If a long option shows an argument as mandatory, then it is mandatory -for the equivalent short option also. - -Input file interpretation: - -e, --delimiters=DELIMITER-LIST - Allow user to provide a string containing delimiters - used to separate keywords from their attributes. - Default is ",\n". - -t, --struct-type Allows the user to include a structured type - declaration for generated code. Any text before %% - is considered part of the type declaration. Key - words and additional fields may follow this, one - group of fields per line. - -Language for the output code: - -L, --language=LANGUAGE-NAME - Generates code in the specified language. Languages - handled are currently C++, ANSI-C, C, and KR-C. The - default is C. - -Details in the output code: - -K, --slot-name=NAME Select name of the keyword component in the keyword - structure. - -H, --hash-fn-name=NAME - Specify name of generated hash function. Default is - `hash'. - -N, --lookup-fn-name=NAME - Specify name of generated lookup function. Default - name is `in_word_set'. - -Z, --class-name=NAME Specify name of generated C++ class. Default name is - `Perfect_Hash'. - -7, --seven-bit Assume 7-bit characters. - -c, --compare-strncmp Generate comparison code using strncmp rather than - strcmp. - -C, --readonly-tables Make the contents of generated lookup tables - constant, i.e., readonly. - -E, --enum Define constant values using an enum local to the - lookup function rather than with defines. - -I, --includes Include the necessary system include file - at the beginning of the code. - -G, --global Generate the static table of keywords as a static - global variable, rather than hiding it inside of the - lookup function (which is the default behavior). - -W, --word-array-name=NAME - Specify name of word list array. Default name is - `wordlist'. - -S, --switch=COUNT Causes the generated C code to use a switch - statement scheme, rather than an array lookup table. - This can lead to a reduction in both time and space - requirements for some keyfiles. The COUNT argument - determines how many switch statements are generated. - A value of 1 generates 1 switch containing all the - elements, a value of 2 generates 2 tables with 1/2 - the elements in each table, etc. If COUNT is very - large, say 1000000, the generated C code does a - binary search. - -T, --omit-struct-type - Prevents the transfer of the type declaration to the - output file. Use this option if the type is already - defined elsewhere. - -Algorithm employed by gperf: - -k, --key-positions=KEYS - Select the key positions used in the hash function. - The allowable choices range between 1-126, inclusive. - The positions are separated by commas, ranges may be - used, and key positions may occur in any order. - Also, the meta-character '*' causes the generated - hash function to consider ALL key positions, and $ - indicates the ``final character'' of a key, e.g., - $,1,2,4,6-10. - -l, --compare-strlen Compare key lengths before trying a string - comparison. This helps cut down on the number of - string comparisons made during the lookup. - -D, --duplicates Handle keywords that hash to duplicate values. This - is useful for certain highly redundant keyword sets. - -f, --fast=ITERATIONS Generate the gen-perf.hash function ``fast''. This - decreases gperf's running time at the cost of - minimizing generated table size. The numeric - argument represents the number of times to iterate - when resolving a collision. `0' means ``iterate by - the number of keywords''. - -i, --initial-asso=N Provide an initial value for the associate values - array. Default is 0. Setting this value larger helps - inflate the size of the final table. - -j, --jump=JUMP-VALUE Affects the ``jump value'', i.e., how far to advance - the associated character value upon collisions. Must - be an odd number, default is 5. - -n, --no-strlen Do not include the length of the keyword when - computing the hash function. - -o, --occurrence-sort Reorders input keys by frequency of occurrence of - the key sets. This should decrease the search time - dramatically. - -r, --random Utilizes randomness to initialize the associated - values table. - -s, --size-multiple=N Affects the size of the generated hash table. The - numeric argument N indicates ``how many times larger - or smaller'' the associated value range should be, - in relationship to the number of keys, e.g. a value - of 3 means ``allow the maximum associated value to - be about 3 times larger than the number of input - keys.'' Conversely, a value of -3 means ``make the - maximum associated value about 3 times smaller than - the number of input keys. A larger table should - decrease the time required for an unsuccessful - search, at the expense of extra table space. Default - value is 1. - -Informative output: - -h, --help Print this message. - -v, --version Print the gperf version number. - -d, --debug Enables the debugging option (produces verbose - output to the standard error). - -Report bugs to . diff --git a/contrib/gperf/tests/test-7.exp b/contrib/gperf/tests/test-7.exp deleted file mode 100644 index c5c942c10d1f..000000000000 --- a/contrib/gperf/tests/test-7.exp +++ /dev/null @@ -1,32 +0,0 @@ -in word set if -in word set do -NOT in word set int -in word set for -in word set case -NOT in word set char -NOT in word set auto -in word set goto -in word set else -NOT in word set long -NOT in word set void -NOT in word set enum -NOT in word set float -NOT in word set short -NOT in word set union -NOT in word set break -in word set while -NOT in word set const -NOT in word set double -NOT in word set static -NOT in word set extern -NOT in word set struct -in word set return -NOT in word set sizeof -NOT in word set switch -NOT in word set signed -NOT in word set typedef -NOT in word set default -NOT in word set unsigned -NOT in word set continue -NOT in word set register -NOT in word set volatile diff --git a/contrib/gperf/tests/test.c b/contrib/gperf/tests/test.c deleted file mode 100644 index 5d7815629814..000000000000 --- a/contrib/gperf/tests/test.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - Tests the generated perfect hash function. - The -v option prints diagnostics as to whether a word is in - the set or not. Without -v the program is useful for timing. -*/ - -#include - -#define MAX_LEN 80 - -int -main (argc, argv) - int argc; - char *argv[]; -{ - int verbose = argc > 1 ? 1 : 0; - char buf[MAX_LEN]; - - while (gets (buf)) - if (in_word_set (buf, strlen (buf)) && verbose) - printf ("in word set %s\n", buf); - else if (verbose) - printf ("NOT in word set %s\n", buf); - - return 0; -} diff --git a/contrib/gperf/tests/validate b/contrib/gperf/tests/validate deleted file mode 100755 index a4813ab3eec1..000000000000 --- a/contrib/gperf/tests/validate +++ /dev/null @@ -1,54 +0,0 @@ -#! /bin/sh -# Validate gperf's operation on a given input file. -# Usage: validate languages input.gperf [more gperf options] -# Uses the environment variables GPERF, CC, CFLAGS, CXX, CXXFLAGS. -# Supposes gcc and g++. - -# Exit on error -set -e - -verbose () { - echo "$@" - "$@" -} - -languages=$1 -shift - -for lang in `echo $languages | sed -e 's/,/ /g'`; do - case "$lang" in - KR-C ) - echo "${GPERF} -I -L KR-C $@ > valitest.c" - ${GPERF} -I -L KR-C "$@" > valitest.c - grep -n ' const ' valitest.c /dev/null && exit 1 - verbose ${CC} ${CFLAGS} -traditional valitest.c -o valitest - ./valitest - verbose ${CC} ${CFLAGS} -ansi -pedantic valitest.c -o valitest - ./valitest - ;; - C ) - echo "${GPERF} -I -L C $@ > valitest.c" - ${GPERF} -I -L C "$@" > valitest.c - verbose ${CC} ${CFLAGS} -traditional -Dconst= valitest.c -o valitest - ./valitest - verbose ${CC} ${CFLAGS} -ansi -pedantic -pedantic-errors valitest.c -o valitest - ./valitest - ;; - ANSI-C ) - echo "${GPERF} -I -L ANSI-C $@ > valitest.c" - ${GPERF} -I -L ANSI-C "$@" > valitest.c - verbose ${CC} ${CFLAGS} -ansi -pedantic -pedantic-errors valitest.c -o valitest - ./valitest - verbose ${CXX} ${CXXFLAGS} -ansi -pedantic -pedantic-errors valitest.c -o valitest - ./valitest - ;; - "C++" ) - echo "${GPERF} -I -L C++ $@ > valitest.c" - ${GPERF} -I -L C++ "$@" > valitest.c - verbose ${CXX} ${CXXFLAGS} -ansi -pedantic -pedantic-errors -DCPLUSPLUS_TEST valitest.c -o valitest - ./valitest - ;; - esac -done - -exit 0 diff --git a/contrib/groff/tmac/doc-common b/contrib/groff/tmac/doc-common index 20d0cab8c875..6372a23990ba 100644 --- a/contrib/groff/tmac/doc-common +++ b/contrib/groff/tmac/doc-common @@ -264,50 +264,72 @@ .ds doc-volume-as-algor algor .ds doc-volume-as-amd64 amd64 .ds doc-volume-as-amiga amiga +.ds doc-volume-as-amigappc amigappc .ds doc-volume-as-arc arc +.ds doc-volume-as-arm arm .ds doc-volume-as-arm26 arm26 .ds doc-volume-as-arm32 arm32 +.ds doc-volume-as-armish armish .ds doc-volume-as-atari atari +.ds doc-volume-as-aviion aviion +.ds doc-volume-as-beagle beagle .ds doc-volume-as-bebox bebox .ds doc-volume-as-cats cats .ds doc-volume-as-cesfic cesfic .ds doc-volume-as-cobalt cobalt .ds doc-volume-as-dreamcast dreamcast +.ds doc-volume-as-emips emips .ds doc-volume-as-evbarm evbarm .ds doc-volume-as-evbmips evbmips .ds doc-volume-as-evbppc evbppc .ds doc-volume-as-evbsh3 evbsh3 +.ds doc-volume-as-ews4800mips ews4800mips .ds doc-volume-as-hp300 hp300 .ds doc-volume-as-hp700 hp700 .ds doc-volume-as-hpcarm hpcarm .ds doc-volume-as-hpcmips hpcmips .ds doc-volume-as-hpcsh hpcsh +.ds doc-volume-as-hppa hppa +.ds doc-volume-as-hppa64 hppa64 .ds doc-volume-as-i386 i386 +.ds doc-volume-as-ia64 ia64 +.ds doc-volume-as-ibmnws ibmnws +.ds doc-volume-as-iyonix iyonix +.ds doc-volume-as-landisk landisk +.ds doc-volume-as-loongson loongson .ds doc-volume-as-luna68k luna68k +.ds doc-volume-as-luna88k luna88k .ds doc-volume-as-m68k m68k .ds doc-volume-as-mac68k mac68k .ds doc-volume-as-macppc macppc .ds doc-volume-as-mips mips +.ds doc-volume-as-mips64 mips64 .ds doc-volume-as-mipsco mipsco .ds doc-volume-as-mmeye mmeye .ds doc-volume-as-mvme68k mvme68k +.ds doc-volume-as-mvme88k mvme88k .ds doc-volume-as-mvmeppc mvmeppc .ds doc-volume-as-netwinder netwinder .ds doc-volume-as-news68k news68k .ds doc-volume-as-newsmips newsmips .ds doc-volume-as-next68k next68k .ds doc-volume-as-ofppc ofppc +.ds doc-volume-as-palm palm .ds doc-volume-as-pc532 pc532 .ds doc-volume-as-playstation2 playstation2 .ds doc-volume-as-pmax pmax .ds doc-volume-as-pmppc pmppc .ds doc-volume-as-powerpc powerpc .ds doc-volume-as-prep prep +.ds doc-volume-as-rs6000 rs6000 .ds doc-volume-as-sandpoint sandpoint .ds doc-volume-as-sbmips sbmips +.ds doc-volume-as-sgi sgi .ds doc-volume-as-sgimips sgimips .ds doc-volume-as-sh3 sh3 .ds doc-volume-as-shark shark +.ds doc-volume-as-socppc socppc +.ds doc-volume-as-solbourne solbourne .ds doc-volume-as-sparc sparc .ds doc-volume-as-sparc64 sparc64 .ds doc-volume-as-sun2 sun2 @@ -316,6 +338,8 @@ .ds doc-volume-as-vax vax .ds doc-volume-as-x68k x68k .ds doc-volume-as-x86_64 x86_64 +.ds doc-volume-as-xen xen +.ds doc-volume-as-zaurus zaurus . .de Dt . \" reset default arguments @@ -451,12 +475,16 @@ .ds doc-operating-system-NetBSD-3.0 3.0 .ds doc-operating-system-NetBSD-3.0.1 3.0.1 .ds doc-operating-system-NetBSD-3.0.2 3.0.2 +.ds doc-operating-system-NetBSD-3.0.3 3.0.3 .ds doc-operating-system-NetBSD-3.1 3.1 +.ds doc-operating-system-NetBSD-3.1.1 3.1.1 .ds doc-operating-system-NetBSD-4.0 4.0 .ds doc-operating-system-NetBSD-4.0.1 4.0.1 .ds doc-operating-system-NetBSD-5.0 5.0 .ds doc-operating-system-NetBSD-5.0.1 5.0.1 .ds doc-operating-system-NetBSD-5.0.2 5.0.2 +.ds doc-operating-system-NetBSD-5.1 5.1 +.ds doc-operating-system-NetBSD-6.0 6.0 . .ds doc-operating-system-OpenBSD-2.0 2.0 .ds doc-operating-system-OpenBSD-2.1 2.1 @@ -487,6 +515,8 @@ .ds doc-operating-system-OpenBSD-4.6 4.6 .ds doc-operating-system-OpenBSD-4.7 4.7 .ds doc-operating-system-OpenBSD-4.8 4.8 +.ds doc-operating-system-OpenBSD-4.9 4.9 +.ds doc-operating-system-OpenBSD-5.0 5.0 . .ds doc-operating-system-FreeBSD-1.0 1.0 .ds doc-operating-system-FreeBSD-1.1 1.1 @@ -544,6 +574,7 @@ .ds doc-operating-system-FreeBSD-8.0 8.0 .ds doc-operating-system-FreeBSD-8.1 8.1 .ds doc-operating-system-FreeBSD-8.2 8.2 +.ds doc-operating-system-FreeBSD-9.0 9.0 . .ds doc-operating-system-Darwin-8.0.0 8.0.0 .ds doc-operating-system-Darwin-8.1.0 8.1.0 @@ -566,7 +597,6 @@ .ds doc-operating-system-Darwin-9.6.0 9.6.0 .ds doc-operating-system-Darwin-9.7.0 9.7.0 .ds doc-operating-system-Darwin-9.8.0 9.8.0 -.ds doc-operating-system-Darwin-10.6.0 10.6.0 .ds doc-operating-system-Darwin-10.1.0 10.1.0 .ds doc-operating-system-Darwin-10.2.0 10.2.0 .ds doc-operating-system-Darwin-10.3.0 10.3.0 @@ -593,6 +623,11 @@ .ds doc-operating-system-DragonFly-2.4 2.4 .ds doc-operating-system-DragonFly-2.6 2.6 .ds doc-operating-system-DragonFly-2.8 2.8 +.ds doc-operating-system-DragonFly-2.9 2.9 +.ds doc-operating-system-DragonFly-2.9.1 2.9.1 +.ds doc-operating-system-DragonFly-2.10 2.10 +.ds doc-operating-system-DragonFly-2.10.1 2.10.1 +.ds doc-operating-system-DragonFly-2.11 2.11 . .de Os . ds doc-command-name diff --git a/contrib/groff/tmac/doc-syms b/contrib/groff/tmac/doc-syms index 0e862adb5e90..72846d406f1a 100644 --- a/contrib/groff/tmac/doc-syms +++ b/contrib/groff/tmac/doc-syms @@ -613,6 +613,8 @@ .as doc-str-St--isoC-tcor1 " (\*[Lq]\*[doc-Tn-font-size]ISO\~C\^90\*[doc-str-St], Technical Corrigendum 1\*[Rq]) .ds doc-str-St--isoC-tcor2 \*[doc-Tn-font-size]ISO/IEC\*[doc-str-St] 9899/TCOR2:1995 .as doc-str-St--isoC-tcor2 " (\*[Lq]\*[doc-Tn-font-size]ISO\~C\^90\*[doc-str-St], Technical Corrigendum 2\*[Rq]) +.ds doc-str-St--isoC-11 \*[doc-Tn-font-size]ISO/IEC\*[doc-str-St] 9899:2011 +.as doc-str-St--isoC-11 " (\*[Lq]\*[doc-Tn-font-size]ISO\~C\^11\*[doc-str-St]\*[Rq]) . .\" POSIX Part 1: System API .ds doc-str-St--p1003.1 \*[doc-Tn-font-size]\%IEEE\*[doc-str-St] Std 1003.1 @@ -754,38 +756,75 @@ .\" NS .\" NS width register `Lb' defined in doc-common . +.ds doc-str-Lb-libarchive Reading and Writing Streaming Archives Library (libarchive, \-larchive) .ds doc-str-Lb-libarm ARM Architecture Library (libarm, \-larm) .ds doc-str-Lb-libarm32 ARM32 Architecture Library (libarm32, \-larm32) +.ds doc-str-Lb-libbluetooth Bluetooth Library (libbluetooth, \-lbluetooth) .ds doc-str-Lb-libbsm Basic Security Module Library (libbsm, \-lbsm) .ds doc-str-Lb-libc Standard C\~Library (libc, \-lc) +.ds doc-str-Lb-libc_r Reentrant C\~Library (libc_r, \-lc_r) +.ds doc-str-Lb-libcalendar Calendar Arithmetic Library (libcalendar, \-lcalendar) +.ds doc-str-Lb-libcam Common Access Method User Library (libcam, \-lcam) .ds doc-str-Lb-libcdk Curses Development Kit Library (libcdk, \-lcdk) +.ds doc-str-Lb-libcipher FreeSec Crypt Library (libcipher, \-lcipher) .ds doc-str-Lb-libcompat Compatibility Library (libcompat, \-lcompat) .ds doc-str-Lb-libcrypt Crypt Library (libcrypt, \-lcrypt) .ds doc-str-Lb-libcurses Curses Library (libcurses, \-lcurses) +.ds doc-str-Lb-libdevinfo Device and Resource Information Utility Library (libdevinfo, \-ldevinfo) +.ds doc-str-Lb-libdevstat Device Statistics Library (libdevstat, \-ldevstat) +.ds doc-str-Lb-libdisk Interface to Slice and Partition Labels Library (libdisk, \-ldisk) +.ds doc-str-Lb-libdwarf DWARF Access Library (libdwarf, \-ldwarf) .ds doc-str-Lb-libedit Command Line Editor Library (libedit, \-ledit) +.ds doc-str-Lb-libelf ELF Access Library (libelf, \-lelf) .ds doc-str-Lb-libevent Event Notification Library (libevent, \-levent) +.ds doc-str-Lb-libfetch File Transfer Library for URLs (libfetch, \-lfetch) .ds doc-str-Lb-libform Curses Form Library (libform, \-lform) +.ds doc-str-Lb-libgeom Userland API Library for kernel GEOM subsystem (libgeom, \-lgeom) +.ds doc-str-Lb-libgpib General-Purpose Instrument Bus (GPIB) library (libgpib, \-lgpib) .ds doc-str-Lb-libi386 i386 Architecture Library (libi386, \-li386) .ds doc-str-Lb-libintl Internationalized Message Handling Library (libintl, \-lintl) .ds doc-str-Lb-libipsec IPsec Policy Control Library (libipsec, \-lipsec) +.ds doc-str-Lb-libipx IPX Address Conversion Support Library (libipx, \-lipx) +.ds doc-str-Lb-libiscsi iSCSI protocol library (libiscsi, \-liscsi) +.ds doc-str-Lb-libjail Jail Library (libjail, \-ljail) +.ds doc-str-Lb-libkiconv Kernel side iconv library (libkiconv, \-lkiconv) +.ds doc-str-Lb-libkse N:M Threading Library (libkse, \-lkse) .ds doc-str-Lb-libkvm Kernel Data Access Library (libkvm, \-lkvm) .ds doc-str-Lb-libm Math Library (libm, \-lm) .ds doc-str-Lb-libm68k m68k Architecture Library (libm68k, \-lm68k) .ds doc-str-Lb-libmagic Magic Number Recognition Library (libmagic, \-lmagic) +.ds doc-str-Lb-libmd Message Digest (MD4, MD5, etc.) Support Library (libmd, \-lmd) +.ds doc-str-Lb-libmemstat Kernel Memory Allocator Statistics Library (libmemstat, \-lmemstat) .ds doc-str-Lb-libmenu Curses Menu Library (libmenu, \-lmenu) +.ds doc-str-Lb-libnetgraph Netgraph User Library (libnetgraph, \-lnetgraph) +.ds doc-str-Lb-libnetpgp Netpgp signing, verification, encryption and decryption (libnetpgp, \-lnetpgp) .ds doc-str-Lb-libossaudio OSS Audio Emulation Library (libossaudio, \-lossaudio) .ds doc-str-Lb-libpam Pluggable Authentication Module Library (libpam, \-lpam) .ds doc-str-Lb-libpcap Packet Capture Library (libpcap, \-lpcap) .ds doc-str-Lb-libpci PCI Bus Access Library (libpci, \-lpci) .ds doc-str-Lb-libpmc Performance Counters Library (libpmc, \-lpmc) .ds doc-str-Lb-libposix \*[Px] \*[doc-str-Lb]Compatibility Library (libposix, \-lposix) +.ds doc-str-Lb-libprop Property Container Object Library (libprop, \-lprop) .ds doc-str-Lb-libpthread \*[Px] \*[doc-str-Lb]Threads Library (libpthread, \-lpthread) +.ds doc-str-Lb-libpuffs puffs Convenience Library (libpuffs, \-lpuffs) +.ds doc-str-Lb-librefuse File System in Userspace Convenience Library (librefuse, \-lrefuse) .ds doc-str-Lb-libresolv DNS Resolver Library (libresolv, \-lresolv) +.ds doc-str-Lb-librpcsec_gss RPC GSS-API Authentication Library (librpcsec_gss, \-lrpcsec_gss) +.ds doc-str-Lb-librpcsvc RPC Service Library (librpcsvc, \-lrpcsvc) .ds doc-str-Lb-librt \*[Px] \*[doc-str-Lb]Real-time Library (librt, \-lrt) +.ds doc-str-Lb-libsdp Bluetooth Service Discovery Protocol User Library (libsdp, \-lsdp) +.ds doc-str-Lb-libssp Buffer Overflow Protection Library (libssp, \-lssp) +.ds doc-str-Lb-libstdthreads C11 Threads Library (libstdthreads, \-lstdthreads) .ds doc-str-Lb-libSystem System Library (libSystem, \-lSystem) .ds doc-str-Lb-libtermcap Termcap Access Library (libtermcap, \-ltermcap) +.ds doc-str-Lb-libterminfo Terminal Information Library (libterminfo, \-lterminfo) +.ds doc-str-Lb-libthr 1:1 Threading Library (libthr, \-lthr) +.ds doc-str-Lb-libufs UFS File System Access Library (libufs, \-lufs) +.ds doc-str-Lb-libugidfw File System Firewall Interface Library (libugidfw, \-lugidfw) +.ds doc-str-Lb-libulog User Login Record Library (libulog, \-lulog) .ds doc-str-Lb-libusbhid USB Human Interface Devices Library (libusbhid, \-lusbhid) .ds doc-str-Lb-libutil System Utilities Library (libutil, \-lutil) +.ds doc-str-Lb-libvgl Video Graphics Library (libvgl, \-lvgl) .ds doc-str-Lb-libx86_64 x86_64 Architecture Library (libx86_64, \-lx86_64) .ds doc-str-Lb-libz Compression Library (libz, \-lz) . diff --git a/contrib/groff/tmac/doc.tmac b/contrib/groff/tmac/doc.tmac index c1c32dc21919..0bb7f3014abb 100644 --- a/contrib/groff/tmac/doc.tmac +++ b/contrib/groff/tmac/doc.tmac @@ -4268,7 +4268,7 @@ . if (\n[doc-arg-limit] > \n[doc-arg-ptr]) \{\ . nr doc-reg-Xr (\n[doc-arg-ptr] + 1) . \" modify second argument if it is a string and -. \" remove space inbetween +. \" remove space in between . if (\n[doc-type\n[doc-reg-Xr]] == 2) \{\ . ds doc-arg\n[doc-reg-Xr] \*[lp]\*[doc-arg\n[doc-reg-Xr]]\*[rp] . ds doc-space\n[doc-arg-ptr] @@ -5091,7 +5091,7 @@ . . .\" NS doc-build-func-string macro -.\" NS collect function arguments and set hard spaces inbetween +.\" NS collect function arguments and set hard spaces in between .\" NS .\" NS modifies: .\" NS doc-func-arg diff --git a/contrib/groff/tmac/groff_mdoc.man b/contrib/groff/tmac/groff_mdoc.man index 309bf1b9a8ed..305a0417df44 100644 --- a/contrib/groff/tmac/groff_mdoc.man +++ b/contrib/groff/tmac/groff_mdoc.man @@ -769,13 +769,18 @@ By default, the following architecture keywords are defined: . \# we use `No' to avoid hyphenation .Bd -ragged -offset indent -.No alpha , acorn26 , acorn32 , algor , amd64 , amiga , arc , arm26 , -.No arm32 , atari , bebox , cats , cesfic , cobalt , dreamcast , evbarm , -.No evbmips , evbppc , evbsh3 , hp300 , hp700 , hpcmips , i386 , luna68k , -.No m68k , mac68k , macppc , mips , mmeye , mvme68k , mvmeppc , netwinder , -.No news68k , newsmips , next68k , ofppc , pc532 , pmax , pmppc , powerpc , -.No prep , sandpoint , sgimips , sh3 , shark , sparc , sparc64 , sun3 , -.No tahoe , vax , x68k , x86_64 +.No acorn26 , acorn32 , algor , alpha , amd64 , amiga , amigappc , +.No arc , arm , arm26 , arm32 , armish , atari , aviion , +.No beagle , bebox , cats , cesfic , cobalt , dreamcast , +.No emips , evbarm , evbmips , evbppc , evbsh3 , ews4800mips , +.No hp300 , hp700 , hpcarm , hpcmips , hpcsh , hppa , hppa64 , +.No i386 , ia64 , ibmnws , iyonix , landisk , loongson , luna68k , luna88k , +.No m68k , mac68k , macppc , mips , mips64 , mipsco , mmeye , +.No mvme68k , mvme88k , mvmeppc , netwinder , news68k , newsmips , next68k , +.No ofppc , palm , pc532 , playstation2 , pmax , pmppc , powerpc , prep , +.No rs6000 , sandpoint , sbmips , sgi , sgimips , sh3 , shark , +.No socppc , solbourne , sparc , sparc64 , sun2 , sun3 , +.No tahoe , vax , x68k , x86_64 , xen , zaurus .Ed .Pp . @@ -864,23 +869,25 @@ the release ID. .It NetBSD 0.8, 0.8a, 0.9, 0.9a, 1.0, 1.0a, 1.1, 1.2, 1.2a, 1.2b, 1.2c, 1.2d, 1.2e, 1.3, 1.3a, 1.4, 1.4.1, 1.4.2, 1.4.3, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.6, 1.6.1, -1.6.2, 1.6.3, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.1, 3.0, 3.0.1, 3.0.2, 3.1, 4.0, -4.0.1, 5.0, 5.0.1, 5.0.2 +1.6.2, 1.6.3, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.1, 3.0, 3.0.1, 3.0.2, 3.0.3, +3.1, 3.1.1, 4.0, 4.0.1, 5.0, 5.0.1, 5.0.2, 5.1, 6.0 .It FreeBSD 1.0, 1.1, 1.1.5, 1.1.5.1, 2.0, 2.0.5, 2.1, 2.1.5, 2.1.6, 2.1.7, 2.2, 2.2.1, 2.2.2, 2.2.5, 2.2.6, 2.2.7, 2.2.8, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 4.0, 4.1, 4.1.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.6.2, 4.7, 4.8, 4.9, 4.10, 4.11, 5.0, 5.1, 5.2, 5.2.1, 5.3, 5.4, 5.5, 6.0, 6.1, 6.2, 6.3, 6.4, 7.0, 7.1, 7.2, 7.3, 8.0, -8.1 +8.1, 8.2, 9.0 .It OpenBSD 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, -3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8 +3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, +5.0 .It DragonFly 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.8, 1.8.1, 1.10, 1.12, 1.12.2, 2.0, 2.2, -2.4, 2.6, 2.8 +2.4, 2.6, 2.8, 2.9, 2.9.1, 2.10, 2.10.1, 2.11 .It Darwin 8.0.0, 8.1.0, 8.2.0, 8.3.0, 8.4.0, 8.5.0, 8.6.0, 8.7.0, 8.8.0, 8.9.0, -8.10.0, 8.11.0, 9.0.0, 9.1.0, 9.2.0, 9.3.0, 9.4.0, 9.5.0, 9.6.0 +8.10.0, 8.11.0, 9.0.0, 9.1.0, 9.2.0, 9.3.0, 9.4.0, 9.5.0, 9.6.0, 9.7.0, +9.8.0, 10.1.0, 10.2.0, 10.3.0, 10.4.0, 10.5.0, 10.6.0, 10.7.0, 11.0.0 .El .Ed .Pp @@ -1673,33 +1680,73 @@ Available arguments to and their results are: . .Pp -.Bl -tag -width ".Li libossaudio" -compact -offset indent +.Bl -tag -width ".Li librpcsec_gss" -compact -offset indent +.It Li libarchive +.Lb libarchive .It Li libarm .Lb libarm .It Li libarm32 .Lb libarm32 +.It Li libbluetooth +.Lb libbluetooth +.It Li libbsm +.Lb libbsm .It Li libc .Lb libc +.It Li libc_r +.Lb libc_r +.It Li libcalendar +.Lb libcalendar +.It Li libcam +.Lb libcam .It Li libcdk .Lb libcdk +.It Li libcipher +.Lb libcipher .It Li libcompat .Lb libcompat .It Li libcrypt .Lb libcrypt .It Li libcurses .Lb libcurses +.It Li libdevinfo +.Lb libdevinfo +.It Li libdevstat +.Lb libdevstat +.It Li libdisk +.Lb libdisk +.It Li libdwarf +.Lb libdwarf .It Li libedit .Lb libedit +.It Li libelf +.Lb libelf .It Li libevent .Lb libevent +.It Li libfetch +.Lb libfetch .It Li libform .Lb libform +.It Li libgeom +.Lb libgeom +.It Li libgpib +.Lb libgpib .It Li libi386 .Lb libi386 .It Li libintl .Lb libintl .It Li libipsec .Lb libipsec +.It Li libipx +.Lb libipx +.It Li libiscsi +.Lb libiscsi +.It Li libjail +.Lb libjail +.It Li libkiconv +.Lb libkiconv +.It Li libkse +.Lb libkse .It Li libkvm .Lb libkvm .It Li libm @@ -1708,8 +1755,16 @@ and their results are: .Lb libm68k .It Li libmagic .Lb libmagic +.It Li libmd +.Lb libmd +.It Li libmemstat +.Lb libmemstat .It Li libmenu .Lb libmenu +.It Li libnetgraph +.Lb libnetgraph +.It Li libnetpgp +.Lb libnetpgp .It Li libossaudio .Lb libossaudio .It Li libpam @@ -1722,18 +1777,48 @@ and their results are: .Lb libpmc .It Li libposix .Lb libposix +.It Li libprop +.Lb libprop .It Li libpthread .Lb libpthread +.It Li libpuffs +.Lb libpuffs +.It Li librefuse +.Lb librefuse .It Li libresolv .Lb libresolv +.It Li librpcsec_gss +.Lb librpcsec_gss +.It Li librpcsvc +.Lb librpcsvc .It Li librt .Lb librt +.It Li libsdp +.Lb libsdp +.It Li libssp +.Lb libssp +.It Li libstdthreads +.Lb libstdthreads +.It Li libSystem +.Lb libSystem .It Li libtermcap .Lb libtermcap +.It Li libterminfo +.Lb libterminfo +.It Li libthr +.Lb libthr +.It Li libufs +.Lb libufs +.It Li libugidfw +.Lb libugidfw +.It Li libulog +.Lb libulog .It Li libusbhid .Lb libusbhid .It Li libutil .Lb libutil +.It Li libvgl +.Lb libvgl .It Li libx86_64 .Lb libx86_64 .It Li libz @@ -1953,6 +2038,8 @@ are: .St -isoC-90 .It Li \-isoC\-99 .St -isoC-99 +.It Li \-isoC\-11 +.St -isoC-11 .El .Pp . diff --git a/contrib/less/command.c b/contrib/less/command.c index 41c386969eb6..def3d3679ad9 100644 --- a/contrib/less/command.c +++ b/contrib/less/command.c @@ -105,7 +105,7 @@ cmd_exec() start_mca(action, prompt, mlist, cmdflags) int action; char *prompt; - void *mlist; + void constant *mlist; int cmdflags; { mca = action; @@ -686,7 +686,7 @@ make_display() static void prompt() { - register char *p; + register char constant *p; if (ungot != NULL) { diff --git a/contrib/less/prompt.c b/contrib/less/prompt.c index daad00de2578..53e66dc4ccdb 100644 --- a/contrib/less/prompt.c +++ b/contrib/less/prompt.c @@ -394,9 +394,9 @@ protochar(c, where, iseditproto) * where to resume parsing the string. * We must keep track of nested IFs and skip them properly. */ - static char * + static char constant * skipcond(p) - register char *p; + register char constant *p; { register int iflevel; @@ -452,9 +452,9 @@ skipcond(p) /* * Decode a char that represents a position on the screen. */ - static char * + static char constant * wherechar(p, wp) - char *p; + char constant *p; int *wp; { switch (*p) @@ -478,10 +478,10 @@ wherechar(p, wp) */ public char * pr_expand(proto, maxwidth) - char *proto; + char constant *proto; int maxwidth; { - register char *p; + register char constant *p; register int c; int where; diff --git a/contrib/libarchive/COPYING b/contrib/libarchive/COPYING new file mode 100644 index 000000000000..9dbf49dbf21c --- /dev/null +++ b/contrib/libarchive/COPYING @@ -0,0 +1,60 @@ +The libarchive distribution as a whole is Copyright by Tim Kientzle +and is subject to the copyright notice reproduced at the bottom of +this file. + +Each individual file in this distribution should have a clear +copyright/licensing statement at the beginning of the file. If any do +not, please let me know and I will rectify it. The following is +intended to summarize the copyright status of the individual files; +the actual statements in the files are controlling. + +* Except as listed below, all C sources (including .c and .h files) + and documentation files are subject to the copyright notice reproduced + at the bottom of this file. + +* The following source files are also subject in whole or in part to + a 3-clause UC Regents copyright; please read the individual source + files for details: + libarchive/archive_entry.c + libarchive/archive_read_support_compression_compress.c + libarchive/archive_write_set_compression_compress.c + libarchive/mtree.5 + tar/matching.c + +* The following source files are in the public domain: + tar/getdate.c + +* The build files---including Makefiles, configure scripts, + and auxiliary scripts used as part of the compile process---have + widely varying licensing terms. Please check individual files before + distributing them to see if those restrictions apply to you. + +I intend for all new source code to use the license below and hope over +time to replace code with other licenses with new implementations that +do use the license below. The varying licensing of the build scripts +seems to be an unavoidable mess. + + +Copyright (c) 2003-2009 +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer + in this position and unchanged. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/contrib/libarchive/FREEBSD-Xlist b/contrib/libarchive/FREEBSD-Xlist new file mode 100644 index 000000000000..b87a53b0c5e1 --- /dev/null +++ b/contrib/libarchive/FREEBSD-Xlist @@ -0,0 +1,30 @@ +$FreeBSD$ +CMakeLists.txt +CTestConfig.cmake +INSTALL +Makefile.am +build +configure.ac +contrib +cpio/CMakeLists.txt +cpio/cpio_windows.c +cpio/cpio_windows.h +cpio/config_freebsd.h +cpio/test/CMakeLists.txt +doc +examples +libarchive/CMakeLists.txt +libarchive/archive_entry_copy_bhfi.c +libarchive/archive_windows.c +libarchive/archive_windows.h +libarchive/config_freebsd.h +libarchive/filter_fork_windows.c +libarchive/mtree.5 +libarchive/test/.cvsignore +libarchive/test/CMakeLists.txt +tar/CMakeLists.txt +tar/bsdtar_windows.c +tar/bsdtar_windows.h +tar/config_freebsd.h +tar/test/CMakeLists.txt +tar/test/test_windows.c diff --git a/contrib/libarchive/FREEBSD-upgrade b/contrib/libarchive/FREEBSD-upgrade new file mode 100644 index 000000000000..12890c33328f --- /dev/null +++ b/contrib/libarchive/FREEBSD-upgrade @@ -0,0 +1,24 @@ +$FreeBSD$ + +libarchive + +The source code is pulled with svn: + + svn checkout http://libarchive.googlecode.com/svn/release/2.8 + +For the contrib directory files and directories were pruned by: + +sh -c 'for F in `cat FREEBSD-Xlist | grep -v FreeBSD`; do rm -rf ./$F ; done' + +You may check if there are any new files that we don't need. + +The instructions for importing new release and merging to HEAD can be found +at FreeBSD wiki: + + http://wiki.freebsd.org/SubversionPrimer/VendorImports + +To make local changes to libarchive, simply patch and commit to the trunk +branch (aka HEAD). Never make local changes on the vendor branch. + +mm@FreeBSD.org +21-December-2011 diff --git a/contrib/libarchive/NEWS b/contrib/libarchive/NEWS new file mode 100644 index 000000000000..4a25fe37d99b --- /dev/null +++ b/contrib/libarchive/NEWS @@ -0,0 +1,550 @@ +Feb 05, 2011: Fix issue 134: Improve handling of open failures +Dec 06, 2010: Fix issue 119: Relax ISO verification +Dec 06, 2010: Fix issue 121: mtree parsing +Dec 05, 2010: Fix extraction of GNU tar 'D' directory entries +Dec 05, 2010: Be less demanding in LZMA/XZ compression tests +Jun 30, 2010: libarchive 2.8.4 released +Jun 30, 2010: Improved reliability of hash function detection +Jun 30, 2010: Fix issues on ancient FreeBSD, QNX, ancient NetBSD and Minix + +Mar 14, 2010: libarchive 2.8.3 released +Mar 14, 2010: Symlink dereference fix for Linux broke the build there; corrected. + +Mar 14, 2010: libarchive 2.8.2 released +Mar 12, 2010: Fix NULL deference for short self-extracting zip archives. +Mar 12, 2010: Don't dereference symlinks on Linux when reading ACLs. +Mar 07, 2010: Better detection of SHA2 support for old OpenSSL versions. +Mar 07, 2010: Fix parsing of input files for bsdtar -T. +Mar 07, 2010: Do not leak setup_xattr into the global namespace. + +Mar 06, 2010: libarchive 2.8.1 released +Mar 06, 2010: Fix build when an older libarchive is already installed +Mar 03, 2010: Use O_BINARY opening files in bsdtar +Mar 02, 2010: Include missing archive_crc32.h +Mar 01, 2010: Correctly include iconv.h required by libxml2. + +Feb 04, 2010: libarchive 2.8.0 released +Jan 17, 2010: Fix error handling for 'echo nonexistent | cpio -o' +Jan 17, 2010: Don't use futimes() on Cygwin + +Jan 02, 2010: libarchive 2.7.902a released (test release for 2.8) +Jan 02, 2010: Fix tar/test/test_windows on MinGW +Jan 02, 2010: Fix memory leaks in libarchive tests +Jan 01, 2010: Fix memory leak when filter startup fails + +Dec 27, 2009: libarchive 2.7.901a released (test release for 2.8) + +Aug 04, 2009: libarchive 2.7.1 released +Jul 20, 2009: Suppress bogus warning about unxz +Jul 19, 2009: Support Cygwin 1.7 +Jun 11, 2009: Support lzma/xz files compressed with larger buffer sizes. +May 24, 2009: Handle gzip files signed with OpenBSD "gzsig" program. +May 07, 2009: Avoid false failures when reading from pipe. + +Apr 16, 2009: libarchive 2.7.0 released + +Apr 10, 2009: libarchive 2.6.992a released +Apr 09, 2009: Fix SIGPIPE issue building with MSVC. +Apr 09, 2009: Fix several minor memory leaks in libarchive and libarchive_test + +Apr 08, 2009: libarchive 2.6.991a released +Apr 07, 2009: Additional tests added to bsdcpio_test + +Apr 01, 2009: libarchive 2.6.990a released +Apr 01, 2009: Use command-line gunzip, bunzip2, unxz, unlzma for + decompression if the library is built without suitable + libraries. The setup functions return ARCHIVE_WARN + in this case so clients can adapt if necessary. +Apr 01, 2009: Use getpw*_r and getgr*_r functions for thread-safety. +Mar 24, 2009: Add archive_read_next_header2(), which is up to 25% + more efficient for some clients; from Brian Harring. +Mar 22, 2009: PDF versions of manpages are now included in the distribution. +Mar, 2009: Major work to improve Cygwin build by Charles Wilson. +Feb/Mar, 2009: Major work on cmake build support, mostly by Michihiro NAKAJIMA. +Feb/Mar, 2009: Major work on Visual Studio support by Michihiro NAKAJIMA. + All tests now pass. +Feb 25, 2009: Fix Debian Bug #516577 +Feb 21, 2009: Yacc is no longer needed to build; date parser rewritten in C. +Jan/Feb, 2009: Mtree work by Michihiro. +Feb, 2009: Joliet support by Andreas Henriksson. +Jan/Feb, 2009: New options framework by Michihiro. +Feb, 2009: High-res timestamps on Tru64, AIX, and GNU Hurd, by Björn Jacke. +Jan 18, 2009: Extended attributes work on FreeBSD and Linux now with pax format. +Jan 07, 2009: New archive_read_disk_entry_from_file() knows about ACLs, + extended attributes, etc so that bsdtar and bsdcpio don't require + such system-specific knowledge. +Jan 03, 2009: Read filter system extensively refactored. In particular, + read filter pipelines are now built out automatically and individual + filters should be much easier to implement. Documentation on the + Googlecode Wiki explains how to implement new filters. +Dec 28, 2008: Many Windows/Visual Studio fixes from Michihiro NAKAJIMA. + +Dec 28, 2008: Main libarchive development moved from FreeBSD Perforce + server to Google Code. This should make it easier for more + people to participate in libarchive development. + +Dec 28, 2008: libarchive 2.6.0 released +Dec 25, 2008: libarchive 2.5.905a released +Dec 10, 2008: libarchive 2.5.904a released +Dec 04, 2008: libarchive 2.5.903a released +Nov 09, 2008: libarchive 2.5.902a released +Nov 08, 2008: libarchive 2.5.901a released +Nov 08, 2008: Start of pre-release testing for libarchive 2.6 + +Nov 07, 2008: Read filter refactor: The decompression routines just + consume and produce arbitrarily-sized blocks. The reblocking + from read_support_compression_none() has been pulled into the + read core. Also, the decompression bid now makes multiple + passes and stacks read filters. +Oct 21, 2008: bsdcpio: New command-line parser. +Oct 19, 2008: Internal read_ahead change: short reads are now an error +Oct 06, 2008: bsdtar: option parser no longer uses getopt_long(), + gives consistent option parsing on all platforms. +Sep 19, 2008: Jaakko Heinonen: shar utility built on libarchive +Sep 17, 2008: Pedro Giffuni: birthtime support +Sep 17, 2008: Miklos Vajna: lzma reader and test. Note: I still have + some concerns about the auto-detection (LZMA file format + doesn't support auto-detection well), so this is not yet + enabled under archive_read_support_compression_all(). For + now, you must call archive_read_support_compression_lzma() if + you want LZMA read support. +Sep 11, 2008: Ivailo Petrov: Many fixes to Windows build, new solution files +Jul 26, 2008: archive_entry now tracks which values have not been set. + This helps zip extraction (file size is often "unknown") and + time restores (tar usually doesn't know atime). +Jul 26, 2008: Joerg Sonnenberger: Performance improvements to shar writer +Jul 25, 2008: Joerg Sonnenberger: mtree write support + +Jul 02, 2008: libarchive 2.5.5 released + +Jul 02, 2008: libarchive 2.5.5b released +Jul 01, 2008: bsdcpio is being used by enough people, we can call it 1.0.0 now +Jun 20, 2008: bsdcpio: If a -l link fails with EXDEV, copy the file instead +Jun 19, 2008: bsdcpio: additional long options for better GNU cpio compat +Jun 15, 2008: Many small portability and bugfixes since 2.5.4b. + +May 25, 2008: libarchive 2.5.4b released +May 21, 2008: Joerg Sonnenberger: fix bsdtar hardlink handling for newc format + +May 21, 2008: More progress on Windows building. Thanks to "Scott" + for the Windows makefiles, thanks to Kees Zeelenberg for + code contributions. + +May 21, 2008: Fix a number of non-exploitable integer and buffer overflows, + thanks to David Remahl at Apple for pointing these out. + +May 21, 2008: Colin Percival: SIGINFO or SIGUSR1 to bsdtar prints progress info + +May 16, 2008: bsdtar's test harness no longer depends on file ordering. + This was causing spurious test failures on a lot of systems. + Thanks to Bernhard R. Link for the diagnosis. + +May 14, 2008: Joerg Sonnenberger: -s substitution support for bsdtar + +May 13, 2008: Joerg Sonnenberger: Many mtree improvements + +May 11, 2008: Joerg Sonnenberger: fix hardlink extraction when + hardlinks have different permissions from original file + +April 30, 2008: Primary libarchive work has been moved into the FreeBSD + project's Perforce repository: http://perforce.freebsd.org/ + The libarchive project can be browsed at + //depot/user/kientzle/libarchive-portable + Direct link: http://preview.tinyurl.com/46mdgr + +May 04, 2008: libarchive 2.5.3b released + * libarchive: Several fixes to link resolver to address bsdcpio crashes + * bsdcpio: -p hardlink handling fixes + * tar/pax: Ensure ustar dirnames end in '/'; be more careful about + measuring filenames when deciding what pathname fields to use + * libarchive: Mark which entry strings are set; be accurate about + distinguishing empty strings ("") from unset ones (NULL) + * tar: Don't crash reading entries with empty filenames + * libarchive_test, bsdtar_test, bsdcpio_test: Better detaults: + run all tests, delete temp dirs, summarize repeated failures + * -no-undefined to libtool for Cygwin + * libarchive_test: Skip large file tests on systems with 32-bit off_t + * iso9660: Don't bother trying to find the body of an empty file; + this works around strange behavior from some ISO9660 writers + * tar: allow -r -T to be used together + * tar: allow --format with -r or -u + * libarchive: Don't build archive.h + +May 04, 2008: Simplified building: archive.h is no longer constructed + This may require additional #if conditionals on some platforms. + +Mar 30, 2008: libarchive 2.5.1b released + +Mar 15, 2008: libarchive 2.5.0b released +Mar 15, 2008: bsdcpio now seems to correctly write hardlinks into newc, + ustar, and old cpio archives. Just a little more testing before + bsdcpio 1.0 becomes a reality. +Mar 15, 2008: I think the new linkify() interface is finally handling + all known hardlink strategies. +Mar 15, 2008: Mtree read fixes from Joerg Sonnenberger. +Mar 15, 2008: Many new bsdtar and bsdcpio options from Joerg Sonnenberger. +Mar 15, 2008: test harnesses no longer require uudecode; they + now have built-in decoding logic that decodes the reference + files as they are needed. + +Mar 14, 2008: libarchive 2.4.14 released; identical to 2.4.13 except for + a point fix for gname/uname mixup in pax format that was introduced + with the UTF-8 fixes. + +Feb 26, 2008: libarchive 2.4.13 released +Feb 25, 2008: Handle path, linkname, gname, or uname that can't be converted + to/from UTF-8. Implement "hdrcharset" attribute from SUS-2008. +Feb 25, 2008: Fix name clash on NetBSD. +Feb 18, 2008: Fix writing empty 'ar' archives, per Kai Wang +Feb 18, 2008: [bsdtar] Permit appending on block devices. +Feb 09, 2008: New "linkify" resolver to help with newc hardlink writing; + bsdcpio still needs to be converted to use this. +Feb 02, 2008: Windows compatibility fixes from Ivailo Petrov, Kees Zeelenberg +Jan 30, 2008: Ignore hardlink size for non-POSIX tar archives. + +Jan 22, 2008: libarchive 2.4.12 released +Jan 22, 2008: Fix bad padding when writing symlinks to newc cpio archives. +Jan 22, 2008: Verify bsdcpio_test by getting it to work against GNU cpio 2.9. + bsdcpio_test complains about missing options (-y and -z), format + of informational messages (--version, --help), and a minor formatting + issue in odc format output. After this update, bsdcpio_test uncovered + several more cosmetic issues in bsdcpio, all now fixed. +Jan 22, 2008: Experimental support for self-extracting Zip archives. +Jan 22, 2008: Extend hardlink restore strategy to work correctly with + hardlinks extracted from newc cpio files. (Which store the body + only with the last occurrence of a link.) + +Dec 30, 2007: libarchive 2.4.11 released +Dec 30, 2007: Fixed a compile error in bsdcpio on some systems. + +Dec 29, 2007: libarchive 2.4.10 released +Dec 29, 2007: bsdcpio 0.9.0 is ready for wider use. +Dec 29, 2007: Completed initial test harness for bsdcpio. + +Dec 22, 2007: libarchive 2.4.9 released +Dec 22, 2007: Implement the remaining options for bsdcpio: -a, -q, -L, -f, + pattern selection for -i and -it. + +Dec 13, 2007: libarchive 2.4.8 released +Dec 13, 2007: gzip and bzip2 compression now handle zero-byte writes correctly, + Thanks to Damien Golding for bringing this to my attention. + +Dec 12, 2007: libarchive 2.4.7 released + +Dec 10, 2007: libarchive 2.4.6 released +Dec 09, 2007: tar/test/test_copy.c verifies "tar -c | tar -x" copy pipeline +Dec 07, 2007: Fix a couple of minor memory leaks. + +Dec 04, 2007: libarchive 2.4.5 released +Dec 04, 2007: Fix cpio/test/test_write_odc by setting the umask first. + +Dec 03, 2007: libarchive 2.4.4 released +Dec 03, 2007: New configure options --disable-xattr and --disable-acl, + thanks to Samuli Suominen. + +Dec 03, 2007: libarchive 2.4.3 released +Dec 03, 2007: Thanks to Lapo Luchini for sending me a ZIP file that + libarchive couldn't handle. Fixed a bug in handling of + "length at end" flags in ZIP files. +Dec 03, 2007: Fixed bsdcpio -help, bsdtar -help tests. +Dec 02, 2007: First cut at real bsdtar test harness. + +Dec 02, 2007: libarchive 2.4.2 released + +Dec 02, 2007: libarchive 2.4.1 released +Dec 02, 2007: Minor fixes, rough cut of mdoc-to-man conversion for + man pages. + +Oct 30, 2007: libarchive 2.4.0 released +Oct 30, 2007: Minor compile fix thanks to Joerg Schilling. +Oct 30, 2007: Only run the format auction once at the beginning of the + archive. This is simpler and supports better error recovery. +Oct 29, 2007: Test support for very large entries in tar archives: + libarchive_test now exercises entries from 2GB up to 1TB. + +Oct 27, 2007: libarchive 2.3.5 released +Oct 27, 2007: Correct some unnecessary internal data copying in the + "compression none" reader and writer; this reduces user time + by up to 2/3 in some tests. (Thanks to Jan Psota for + publishing his performance test results to GNU tar's bug-tar + mailing list; those results pointed me towards this problem.) +Oct 27, 2007: Fix for skipping archive entries that are exactly + a multiple of 4G on 32-bit platforms. +Oct 25, 2007: Fix for reading very large (>8G) tar archives; this was + broken when I put in support for new GNU tar sparse formats. +Oct 20, 2007: Initial work on new pattern-matching code for cpio; I + hope this eventually replaces the code currently in bsdtar. + +Oct 08, 2007: libarchive 2.3.4 released +Oct 05, 2007: Continuing work on bsdcpio test suite. +Oct 05, 2007: New cpio.5 manpage, updates to "History" of bsdcpio.1 and + bsdtar.1 manpages. +Oct 05, 2007: Fix zip reader to immediately return EOF if you try + to read body of non-regular file. In particular, this fixes + bsdtar extraction of zip archives. + +Sep 30, 2007: libarchive 2.3.3 released +Sep 26, 2007: Rework Makefile.am so that the enable/disable options + actually do the right things. +Sep 26, 2007: cpio-odc and cpio-newc archives no longer write bodies + for non-regular files. +Sep 26, 2007: Test harness for bsdcpio is in place, needs more tests written. + This is much nicer than the ragtag collection of test scripts + that bsdtar has. + +Sep 20, 2007: libarchive 2.3.2 released +Sep 20, 2007: libarchive 2.3.1 broke bsdtar because the archive_write_data() + fix was implemented incorrectly. + +Sep 16, 2007: libarchive 2.3.1 released +Sep 16, 2007: Many fixes to bsdcpio 0.3: handle hardlinks with -p, recognize + block size on writing, fix a couple of segfaults. +Sep 16, 2007: Fixed return value from archive_write_data() when used + with archive_write_disk() to match the documentation and other + instances of this same function. +Sep 15, 2007: Add archive_entry_link_resolver, archive_entry_strmode + +Sep 11, 2007: libarchive 2.2.8 released +Sep 09, 2007: bsdcpio 0.2 supports most (not yet all) of the old POSIX spec. + +Sep 01, 2007: libarchive 2.2.7 released +Aug 31, 2007: Support for reading mtree files, including an mtree.5 manpage + (A little experimental still.) +Aug 18, 2007: Read gtar 1.17 --posix --sparse entries. +Aug 13, 2007: Refined suid/sgid restore handling; it is no longer + an error if suid/sgid bits are dropped when you request + perm restore but don't request owner restore. +Aug 06, 2007: Use --enable-bsdcpio if you want to try bsdcpio + +Aug 05, 2007: libarchive 2.2.6 released +Aug 05, 2007: New configure option --disable-bsdtar, thanks to Joerg + Sonnenberger. +Aug 05, 2007: Several bug fixes from FreeBSD CVS repo. + +Jul 13, 2007: libarchive 2.2.5 released + +Jul 12, 2007: libarchive 2.2.4 released +Jul 12, 2007: Thanks to Colin Percival's help in diagnosing and + fixing several critical security bugs. Details available at + http://security.freebsd.org/advisories/FreeBSD-SA-07:05.libarchive.asc + +May 26, 2007: libarchive 2.2.3 released +May 26, 2007: Fix memory leaks in ZIP reader and shar writer, add some + missing system headers to archive_entry.h, dead code cleanup + from Colin Percival, more tests for gzip/bzip2, fix an + EOF anomaly in bzip2 decompression. + +May 12, 2007: libarchive 2.2.2 released +May 12, 2007: Fix archive_write_disk permission restore by cloning + entry passed into write_header so that permission info is + still available at finish_entry time. (archive_read_extract() + worked okay because it held onto the passed-in entry, but + direct consumers of archive_write_disk would break). This + required fixing archive_entry_clone(), which now works and has + a reasonably complete test case. +May 10, 2007: Skeletal cpio implementation. + +May 06, 2007: libarchive 2.2.1 released +May 06, 2007: Flesh out a lot more of test_entry.c so as to catch + problems such as the device node breakage before releasing . +May 05, 2007: Fix a bad bug introduced in 2.1.9 that broke device + node entries in tar archives. +May 03, 2007: Move 'struct stat' out of archive_entry core as well. + This removes some portability headaches and fixes a bunch + of corner cases that arise when manipulating archives on + dissimilar systems. + +Apr 30, 2007: libarchive 2.1.10 released +Apr 31, 2007: Minor code cleanup. + +Apr 24, 2007: libarchive 2.1.9 released +Apr 24, 2007: Fix some recently-introduced problems with libraries + (Just let automake handle it and it all works much better.) + Finish isolating major()/minor()/makedev() in archive_entry.c. + +Apr 23, 2007: libarchive 2.1.8 released +Apr 23, 2007: Minor fixes found from building on MacOS X + +Apr 22, 2007: libarchive 2.1.7 released +Apr 22, 2007: Eliminated all uses of 'struct stat' from the + format readers/writers. This should improve portability; + 'struct stat' is now only used in archive_entry and in + code that actually touches the disk. + +Apr 17, 2007: libarchive 2.1.6 released + Libarchive now compiles and passes all tests on Interix. + +Apr 16, 2007: libarchive 2.1.5 released + +Apr 15, 2007: libarchive 2.1b2 released +Apr 15, 2007: New libarchive_internals.3 documentation of internal APIs. + Not complete, but should prove helpful. +Apr 15, 2007: Experimental "read_compress_program" and "write_compress_program" + for using libarchive with external compression. Not yet + well tested, and likely has portability issues. Feedback + appreciated. + +Apr 14, 2007: libarchive 2.0.31 released +Apr 14, 2007: More fixes for Interix, more 'ar' work + +Apr 14, 2007: libarchive 2.0.30 released +Apr 13, 2007: libarchive now enforces trailing '/' on dirs + written to tar archives + +Apr 11, 2007: libarchive 2.0.29 released +Apr 11, 2007: Make it easier to statically configure for different platforms. +Apr 11, 2007: Updated config.guess, config.sub, libtool + +Apr 06, 2007: libarchive 2.0.28 released +Apr 06, 2007: 'ar' format read/write support thanks to Kai Wang. + +Apr 01, 2007: libarchive 2.0.27 released +Mar 31, 2007: Several minor fixes from Colin Percival and Joerg Sonnenberger. + +Mar 12, 2007: libarchive 2.0.25 released +Mar 12, 2007: Fix broken --unlink flag. + +Mar 11, 2007: libarchive 2.0.24 released +Mar 10, 2007: Correct an ACL blunder that causes any ACL with an entry + that refers to a non-existent user or group to not be restored correctly. + The fix both makes the parser more tolerant (so that archives created + with the buggy ACLs can be read now) and corrects the ACL formatter. +Mar 10, 2007: More work on test portability to Linux. + +Mar 10, 2007: libarchive 2.0.22 released +Mar 10, 2007: Header cleanups; added linux/fs.h, removed + some unnecessary headers, added #include guards in bsdtar. + If you see any obvious compile failures from this, let me know. +Mar 10, 2007: Work on bsdtar test scripts: not yet robust enough + to enable as part of "make check", but getting better. +Mar 10, 2007: libarchive now returns ARCHIVE_FAILED when + a header write fails in a way that only affects this item. + Less bad than ARCHIVE_FATAL, but worse than ARCHIVE_WARN. + +Mar 07, 2007: libarchive 2.0.21 released +Mar 07, 2007: Add some ACL tests (only for the system-independent + portion of the ACL support for now). +Mar 07, 2007: tar's ability to read ACLs off disk got + turned off for FreeBSD; re-enable it. (ACL restores and + libarchive support for storing/reading ACLs from pax + archives was unaffected.) + +Mar 02, 2007: libarchive 2.0.20 released +Mar 2, 2007: It's not perfect, but it's pretty good. + Libarchive 2.0 is officially out of beta. + +Feb 28, 2007: libarchive 2.0b17 released +Feb 27, 2007: Make the GID restore checks more robust by checking + whether the current user has too few or too many privileges. + +Feb 26, 2007: libarchive 2.0b15 released +Feb 26, 2007: Don't lose symlinks when extracting from ISOs. + Thanks to Diego "Flameeyes" Pettenò for telling me about the + broken testcase on Gentoo that (finally!) led me to the cause + of this long-standing bug. + +Feb 26, 2007: libarchive 2.0b14 released +Feb 26, 2007: Fix a broken test on platforms that lack lchmod(). + +Feb 25, 2007: libarchive 2.0b13 released +Feb 25, 2007: Empty archives were being written as empty files, + without a proper end-of-archive marker. Fixed. + +Feb 23, 2007: libarchive 2.0b12 released +Feb 22, 2007: Basic security checks added: _EXTRACT_SECURE_NODOTDOT + and _EXTRACT_SECURE_SYMLINK. These checks used to be in bsdtar, + but they belong down in libarchive where they can be used by + other tools and where they can be better optimized. + +Feb 11, 2007: libarchive 2.0b11 released +Feb 10, 2007: Fixed a bunch of errors in libarchive's handling + of EXTRACT_PERM and EXTRACT_OWNER, especially relating + to SUID and SGID bits. + +Jan 31, 2007: libarchive 2.0b9 released +Jan 31, 2007: Added read support for "empty" archives as a + distinct archive format. Bsdtar uses this to handle, e.g., + "touch foo.tar; tar -rf foo.tar" + +Jan 22, 2007: libarchive 2.0b6 released +Jan 22, 2007: archive_write_disk API is now in place. It provides + a finer-grained interface than archive_read_extract. In particular, + you can use it to create objects on disk without having an archive + around (just feed it archive_entry objects describing what you + want to create), you can override the uname/gname-to-uid/gid lookups + (minitar uses this to avoid getpwXXX() and getgrXXX() bloat). + +Jan 09, 2007: libarchive 2.0a3 released +Jan 9, 2007: archive_extract is now much better; it handles the + most common cases with a minimal number of system calls. + Some features still need a lot of testing, especially corner + cases involving objects that already exist on disk. I expect + the next round of API overhaul will simplify building test cases. +Jan 9, 2007: a number of fixes thanks to Colin Percival, especially + corrections to the skip() framework and handling of large files. +Jan 9, 2007: Fixes for large ISOs. The code should correctly handle + very large ISOs with entries up to 4G. Thanks to Robert Sciuk + for pointing out these issues. + +Sep 05, 2006: libarchive 1.3.1 released +Sep 5, 2006: Bump version to 1.3 for new I/O wrappers. +Sep 4, 2006: New memory and FILE read/write wrappers. +Sep 4, 2006: libarchive test harness is now minimally functional; + it's located a few minor bugs in error-handling logic + +Aug 17, 2006: libarchive 1.2.54 released +Aug 17, 2006: Outline ABI changes for libarchive 2.0; these + are protected behind #ifdef's until I think I've found everything + that needs to change. +Aug 17, 2006: Fix error-handling in archive_read/write_close() + They weren't returning any errors before. +Aug 17, 2006: Fix recursive-add logic to not trigger if it's not set + Fixes a bug adding files when writing archive to pipe or when + using archive_write_open() directly. +Jul 2006: New "skip" handling improves performance extracting + single files from large uncompressed archives. + +Mar 21, 2006: 1.2.52 released +Mar 21, 2006: Fix -p on platforms that don't have platform-specific + extended attribute code. +Mar 20, 2006: Add NEWS file; fill in some older history from other + files. I'll try to keep this file up-to-date from now on. + +OLDER NEWS SUMMARIES + +Mar 19, 2006: libarchive 1.2.51 released +Mar 18, 2006: Many fixes to extended attribute support, including a redesign + of the storage format to simplify debugging. +Mar 12, 2006: Remove 'tp' support; it was a fun idea, but not worth + spending much time on. +Mar 11, 2006: Incorporated Jaakko Heinonen's still-experimental support + for extended attributes (Currently Linux-only.). +Mar 11, 2006: Reorganized distribution package: There is now one tar.gz + file that builds both libarchive and bsdtar. +Feb 13, 2006: Minor bug fixes: correctly read cpio device entries, write + Pax attribute entry names. +Nov 7, 2005: Experimental 'tp' format support in libarchive. Feedback + appreciated; this is not enabled by archive_read_support_format_all() + yet as I'm not quite content with the format detection heuristics. +Nov 7, 2005: Some more portability improvements thanks to Darin Broady, + minor bugfixes. +Oct 12, 2005: Use GNU libtool to build shared libraries on many systems. +Aug 9, 2005: Correctly detect that MacOS X does not have POSIX ACLs. +Apr 17, 2005: Kees Zeelenberg has ported libarchive and bsdtar to Windows: + http://gnuwin32.sourceforge.net/ +Apr 11, 2005: Extended Zip/Zip64 support thanks to Dan Nelson. -L/-h + fix from Jaakko Heinonen. +Mar 12, 2005: archive_read_extract can now handle very long + pathnames (I've tested with pathnames up to 1MB). +Mar 12, 2005: Marcus Geiger has written an article about libarchive + http://xsnil.antbear.org/2005/02/05/archive-mit-libarchive-verarbeiten/ + including examples of using it from Objective-C. His MoinX + http://moinx.antbear.org/ desktop Wiki uses + libarchive for archiving and restoring Wiki pages. +Jan 22, 2005: Preliminary ZIP extraction support, + new directory-walking code for bsdtar. +Jan 16, 2005: ISO9660 extraction code added; manpage corrections. +May 22, 2004: Many gtar-compatible long options have been added; almost + all FreeBSD ports extract correctly with bsdtar. +May 18, 2004: bsdtar can read Solaris, HP-UX, Unixware, star, gtar, + and pdtar archives. diff --git a/lib/libarchive/README b/contrib/libarchive/README similarity index 54% rename from lib/libarchive/README rename to contrib/libarchive/README index 0c4758a634c7..03e47e85497e 100644 --- a/lib/libarchive/README +++ b/contrib/libarchive/README @@ -1,21 +1,58 @@ -$FreeBSD$ +README for libarchive bundle. -libarchive: a library for reading and writing streaming archives +Questions? Issues? + * http://libarchive.googlecode.com/ is the home for ongoing + libarchive development, including issue tracker, additional + documentation, and links to the libarchive mailing lists. -This is all under a BSD license. Use, enjoy, but don't blame me if it breaks! +This distribution bundle includes the following components: + * libarchive: a library for reading and writing streaming archives + * tar: the 'bsdtar' program is a full-featured 'tar' + replacement built on libarchive + * cpio: the 'bsdcpio' program is a different interface to + essentially the same functionality + * examples: Some small example programs that you may find useful. + * examples/minitar: a compact sample demonstrating use of libarchive. + I use this for testing link pollution; it should produce a very + small executable file on most systems. + * contrib: Various items sent to me by third parties; + please contact the authors with any questions. -Documentation: +The top-level directory contains the following information files: + * NEWS - highlights of recent changes + * COPYING - what you can do with this + * INSTALL - installation instructions + * README - this file + * configure - configuration script, see INSTALL for details. + * CMakeLists.txt - input for "cmake" build tool, see INSTALL + +The following files in the top-level directory are used by the +'configure' script: + * Makefile.am, aclocal.m4, configure.ac + - used to build this distribution, only needed by maintainers + * Makefile.in, config.h.in + - templates used by configure script + +Guide to Documentation installed by this system: + * bsdtar.1 explains the use of the bsdtar program + * bsdcpio.1 explains the use of the bsdcpio program * libarchive.3 gives an overview of the library as a whole - * archive_read.3, archive_write.3, and archive_write_disk.3 provide - detailed calling sequences for the read and write APIs + * archive_read.3, archive_write.3, archive_write_disk.3, and + archive_read_disk.3 provide detailed calling sequences for the read + and write APIs * archive_entry.3 details the "struct archive_entry" utility class + * archive_internals.3 provides some insight into libarchive's + internal structure and operation. * libarchive-formats.5 documents the file formats supported by the library - * tar.5 provides some detailed information about a variety of different - "tar" formats. + * cpio.5, mtree.5, and tar.5 provide detailed information about these + popular archive formats, including hard-to-find details about + modern cpio and tar variants. +The manual pages above are provided in the 'doc' directory in +a number of different formats. -You should also read the copious comments in "archive.h" and the source -code for the sample "bsdtar" and "minitar" programs for more details. -Please let me know about any errors or omissions you find. +You should also read the copious comments in "archive.h" and the +source code for the sample programs for more details. Please let me +know about any errors or omissions you find. Currently, the library automatically detects and reads the following: * gzip compression @@ -30,6 +67,7 @@ Currently, the library automatically detects and reads the following: * POSIX pax interchange format * POSIX octet-oriented cpio * SVR4 ASCII cpio + * POSIX octet-oriented cpio * Binary cpio (big-endian or little-endian) * ISO9660 CD-ROM images (with optional Rockridge or Joliet extensions) * ZIP archives (with uncompressed or "deflate" compressed entries) @@ -52,16 +90,16 @@ The library can write: * GNU and BSD 'ar' archives * 'mtree' format -Notes: +Notes about the library architecture: + * This is a heavily stream-oriented system. There is no direct - support for in-place modification or random access and no intention - of ever adding such support. Adding such support would require - sacrificing a lot of other features, so don't bother asking. + support for in-place modification or random access. * The library is designed to be extended with new compression and archive formats. The only requirement is that the format be readable or writable as a stream and that each archive entry be - independent. + independent. There are articles on the libarchive Wiki explaining + how to extend libarchive. * On read, compression and format are always detected automatically. @@ -77,8 +115,7 @@ Notes: * On read, the library accepts whatever blocks you hand it. Your read callback is free to pass the library a byte at a time or mmap the entire archive and give it to the library at once. - On write, the library always produces correctly-blocked - output. + On write, the library always produces correctly-blocked output. * The object-style approach allows you to have multiple archive streams open at once. bsdtar uses this in its "@archive" extension. @@ -93,10 +130,8 @@ Notes: a block of data in memory and add it to a tar archive without first writing a temporary file. You can also read an entry from an archive and write the data directly to a socket. If you want - to read/write entries to disk, the archive_write_disk interface - treats a directory as if it were an archive so you can copy - from archive->disk using the same code you use for archive->archive - transfers. + to read/write entries to disk, there are convenience functions to + make this especially easy. * Note: "pax interchange format" is really an extended tar format, despite what the name says. diff --git a/usr.bin/cpio/bsdcpio.1 b/contrib/libarchive/cpio/bsdcpio.1 similarity index 100% rename from usr.bin/cpio/bsdcpio.1 rename to contrib/libarchive/cpio/bsdcpio.1 diff --git a/usr.bin/cpio/cmdline.c b/contrib/libarchive/cpio/cmdline.c similarity index 100% rename from usr.bin/cpio/cmdline.c rename to contrib/libarchive/cpio/cmdline.c diff --git a/usr.bin/cpio/cpio.c b/contrib/libarchive/cpio/cpio.c similarity index 100% rename from usr.bin/cpio/cpio.c rename to contrib/libarchive/cpio/cpio.c diff --git a/usr.bin/cpio/cpio.h b/contrib/libarchive/cpio/cpio.h similarity index 100% rename from usr.bin/cpio/cpio.h rename to contrib/libarchive/cpio/cpio.h diff --git a/usr.bin/cpio/cpio_platform.h b/contrib/libarchive/cpio/cpio_platform.h similarity index 100% rename from usr.bin/cpio/cpio_platform.h rename to contrib/libarchive/cpio/cpio_platform.h diff --git a/usr.bin/cpio/test/main.c b/contrib/libarchive/cpio/test/main.c similarity index 100% rename from usr.bin/cpio/test/main.c rename to contrib/libarchive/cpio/test/main.c diff --git a/usr.bin/cpio/test/test.h b/contrib/libarchive/cpio/test/test.h similarity index 100% rename from usr.bin/cpio/test/test.h rename to contrib/libarchive/cpio/test/test.h diff --git a/usr.bin/cpio/test/test_0.c b/contrib/libarchive/cpio/test/test_0.c similarity index 100% rename from usr.bin/cpio/test/test_0.c rename to contrib/libarchive/cpio/test/test_0.c diff --git a/usr.bin/cpio/test/test_basic.c b/contrib/libarchive/cpio/test/test_basic.c similarity index 100% rename from usr.bin/cpio/test/test_basic.c rename to contrib/libarchive/cpio/test/test_basic.c diff --git a/usr.bin/cpio/test/test_cmdline.c b/contrib/libarchive/cpio/test/test_cmdline.c similarity index 100% rename from usr.bin/cpio/test/test_cmdline.c rename to contrib/libarchive/cpio/test/test_cmdline.c diff --git a/usr.bin/cpio/test/test_format_newc.c b/contrib/libarchive/cpio/test/test_format_newc.c similarity index 100% rename from usr.bin/cpio/test/test_format_newc.c rename to contrib/libarchive/cpio/test/test_format_newc.c diff --git a/usr.bin/cpio/test/test_gcpio_compat.c b/contrib/libarchive/cpio/test/test_gcpio_compat.c similarity index 100% rename from usr.bin/cpio/test/test_gcpio_compat.c rename to contrib/libarchive/cpio/test/test_gcpio_compat.c diff --git a/usr.bin/cpio/test/test_gcpio_compat_ref.bin.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.bin.uu similarity index 100% rename from usr.bin/cpio/test/test_gcpio_compat_ref.bin.uu rename to contrib/libarchive/cpio/test/test_gcpio_compat_ref.bin.uu diff --git a/usr.bin/cpio/test/test_gcpio_compat_ref.crc.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.crc.uu similarity index 100% rename from usr.bin/cpio/test/test_gcpio_compat_ref.crc.uu rename to contrib/libarchive/cpio/test/test_gcpio_compat_ref.crc.uu diff --git a/usr.bin/cpio/test/test_gcpio_compat_ref.newc.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.newc.uu similarity index 100% rename from usr.bin/cpio/test/test_gcpio_compat_ref.newc.uu rename to contrib/libarchive/cpio/test/test_gcpio_compat_ref.newc.uu diff --git a/usr.bin/cpio/test/test_gcpio_compat_ref.ustar.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref.ustar.uu similarity index 100% rename from usr.bin/cpio/test/test_gcpio_compat_ref.ustar.uu rename to contrib/libarchive/cpio/test/test_gcpio_compat_ref.ustar.uu diff --git a/usr.bin/cpio/test/test_gcpio_compat_ref_nosym.bin.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.bin.uu similarity index 98% rename from usr.bin/cpio/test/test_gcpio_compat_ref_nosym.bin.uu rename to contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.bin.uu index 7a2a272394f3..a3e87a7167ed 100644 --- a/usr.bin/cpio/test/test_gcpio_compat_ref_nosym.bin.uu +++ b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.bin.uu @@ -1,5 +1,3 @@ -$FreeBSD$ - begin 644 test_gcpio_compat_ref_nosym.bin MQW%4`-[Z_4'H`^@#`@`VNZU*NQX$``````!D:7(`QW%4`-SZI('H`^@#`@`G MNZU*NQX%````"@!F:6QE```Q,C,T-38W.#D*QW%4`-SZI('H`^@#`@`GNZU* diff --git a/usr.bin/cpio/test/test_gcpio_compat_ref_nosym.crc.uu b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.crc.uu similarity index 98% rename from usr.bin/cpio/test/test_gcpio_compat_ref_nosym.crc.uu rename to contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.crc.uu index 0147df7355fb..38ba9fe1431d 100644 --- a/usr.bin/cpio/test/test_gcpio_compat_ref_nosym.crc.uu +++ b/contrib/libarchive/cpio/test/test_gcpio_compat_ref_nosym.crc.uu @@ -1,5 +1,3 @@ -$FreeBSD$ - begin 644 test_gcpio_compat_ref_nosym.crc M,#= 3 +#define __LA_PRINTF(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#else +#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */ +#endif + #ifdef __cplusplus extern "C" { #endif @@ -129,13 +136,13 @@ extern "C" { * (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000) * #endif */ -#define ARCHIVE_VERSION_NUMBER 2008004 +#define ARCHIVE_VERSION_NUMBER 2008005 __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_STRING "libarchive 2.8.4" +#define ARCHIVE_VERSION_STRING "libarchive 2.8.5" __LA_DECL const char * archive_version_string(void); #if ARCHIVE_VERSION_NUMBER < 3000000 @@ -717,7 +724,7 @@ __LA_DECL const char *archive_format_name(struct archive *); __LA_DECL int archive_format(struct archive *); __LA_DECL void archive_clear_error(struct archive *); __LA_DECL void archive_set_error(struct archive *, int _err, - const char *fmt, ...); + const char *fmt, ...) __LA_PRINTF(3, 4); __LA_DECL void archive_copy_error(struct archive *dest, struct archive *src); __LA_DECL int archive_file_count(struct archive *); diff --git a/lib/libarchive/archive_check_magic.c b/contrib/libarchive/libarchive/archive_check_magic.c similarity index 100% rename from lib/libarchive/archive_check_magic.c rename to contrib/libarchive/libarchive/archive_check_magic.c diff --git a/lib/libarchive/archive_crc32.h b/contrib/libarchive/libarchive/archive_crc32.h similarity index 100% rename from lib/libarchive/archive_crc32.h rename to contrib/libarchive/libarchive/archive_crc32.h diff --git a/lib/libarchive/archive_endian.h b/contrib/libarchive/libarchive/archive_endian.h similarity index 100% rename from lib/libarchive/archive_endian.h rename to contrib/libarchive/libarchive/archive_endian.h diff --git a/lib/libarchive/archive_entry.3 b/contrib/libarchive/libarchive/archive_entry.3 similarity index 100% rename from lib/libarchive/archive_entry.3 rename to contrib/libarchive/libarchive/archive_entry.3 diff --git a/lib/libarchive/archive_entry.c b/contrib/libarchive/libarchive/archive_entry.c similarity index 100% rename from lib/libarchive/archive_entry.c rename to contrib/libarchive/libarchive/archive_entry.c diff --git a/lib/libarchive/archive_entry.h b/contrib/libarchive/libarchive/archive_entry.h similarity index 100% rename from lib/libarchive/archive_entry.h rename to contrib/libarchive/libarchive/archive_entry.h diff --git a/lib/libarchive/archive_entry_copy_stat.c b/contrib/libarchive/libarchive/archive_entry_copy_stat.c similarity index 100% rename from lib/libarchive/archive_entry_copy_stat.c rename to contrib/libarchive/libarchive/archive_entry_copy_stat.c diff --git a/lib/libarchive/archive_entry_link_resolver.c b/contrib/libarchive/libarchive/archive_entry_link_resolver.c similarity index 100% rename from lib/libarchive/archive_entry_link_resolver.c rename to contrib/libarchive/libarchive/archive_entry_link_resolver.c diff --git a/lib/libarchive/archive_entry_private.h b/contrib/libarchive/libarchive/archive_entry_private.h similarity index 100% rename from lib/libarchive/archive_entry_private.h rename to contrib/libarchive/libarchive/archive_entry_private.h diff --git a/lib/libarchive/archive_entry_stat.c b/contrib/libarchive/libarchive/archive_entry_stat.c similarity index 100% rename from lib/libarchive/archive_entry_stat.c rename to contrib/libarchive/libarchive/archive_entry_stat.c diff --git a/lib/libarchive/archive_entry_strmode.c b/contrib/libarchive/libarchive/archive_entry_strmode.c similarity index 100% rename from lib/libarchive/archive_entry_strmode.c rename to contrib/libarchive/libarchive/archive_entry_strmode.c diff --git a/lib/libarchive/archive_entry_xattr.c b/contrib/libarchive/libarchive/archive_entry_xattr.c similarity index 100% rename from lib/libarchive/archive_entry_xattr.c rename to contrib/libarchive/libarchive/archive_entry_xattr.c diff --git a/lib/libarchive/archive_hash.h b/contrib/libarchive/libarchive/archive_hash.h similarity index 100% rename from lib/libarchive/archive_hash.h rename to contrib/libarchive/libarchive/archive_hash.h diff --git a/lib/libarchive/archive_platform.h b/contrib/libarchive/libarchive/archive_platform.h similarity index 100% rename from lib/libarchive/archive_platform.h rename to contrib/libarchive/libarchive/archive_platform.h diff --git a/lib/libarchive/archive_private.h b/contrib/libarchive/libarchive/archive_private.h similarity index 100% rename from lib/libarchive/archive_private.h rename to contrib/libarchive/libarchive/archive_private.h diff --git a/lib/libarchive/archive_read.3 b/contrib/libarchive/libarchive/archive_read.3 similarity index 100% rename from lib/libarchive/archive_read.3 rename to contrib/libarchive/libarchive/archive_read.3 diff --git a/lib/libarchive/archive_read.c b/contrib/libarchive/libarchive/archive_read.c similarity index 100% rename from lib/libarchive/archive_read.c rename to contrib/libarchive/libarchive/archive_read.c diff --git a/lib/libarchive/archive_read_data_into_fd.c b/contrib/libarchive/libarchive/archive_read_data_into_fd.c similarity index 100% rename from lib/libarchive/archive_read_data_into_fd.c rename to contrib/libarchive/libarchive/archive_read_data_into_fd.c diff --git a/lib/libarchive/archive_read_disk.3 b/contrib/libarchive/libarchive/archive_read_disk.3 similarity index 100% rename from lib/libarchive/archive_read_disk.3 rename to contrib/libarchive/libarchive/archive_read_disk.3 diff --git a/lib/libarchive/archive_read_disk.c b/contrib/libarchive/libarchive/archive_read_disk.c similarity index 100% rename from lib/libarchive/archive_read_disk.c rename to contrib/libarchive/libarchive/archive_read_disk.c diff --git a/lib/libarchive/archive_read_disk_entry_from_file.c b/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c similarity index 99% rename from lib/libarchive/archive_read_disk_entry_from_file.c rename to contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c index 957e4ee4da77..7ada371e3bd5 100644 --- a/lib/libarchive/archive_read_disk_entry_from_file.c +++ b/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c @@ -139,7 +139,7 @@ archive_read_disk_entry_from_file(struct archive *_a, #endif if (stat(path, &s) != 0) { archive_set_error(&a->archive, errno, - "Can't stat %s", path); + "Can't lstat %s", path); return (ARCHIVE_FAILED); } st = &s; diff --git a/lib/libarchive/archive_read_disk_private.h b/contrib/libarchive/libarchive/archive_read_disk_private.h similarity index 100% rename from lib/libarchive/archive_read_disk_private.h rename to contrib/libarchive/libarchive/archive_read_disk_private.h diff --git a/lib/libarchive/archive_read_disk_set_standard_lookup.c b/contrib/libarchive/libarchive/archive_read_disk_set_standard_lookup.c similarity index 100% rename from lib/libarchive/archive_read_disk_set_standard_lookup.c rename to contrib/libarchive/libarchive/archive_read_disk_set_standard_lookup.c diff --git a/lib/libarchive/archive_read_extract.c b/contrib/libarchive/libarchive/archive_read_extract.c similarity index 98% rename from lib/libarchive/archive_read_extract.c rename to contrib/libarchive/libarchive/archive_read_extract.c index 8ae5dec0f347..5c69f5998f58 100644 --- a/lib/libarchive/archive_read_extract.c +++ b/contrib/libarchive/libarchive/archive_read_extract.c @@ -108,7 +108,7 @@ archive_read_extract2(struct archive *_a, struct archive_entry *entry, if (r != ARCHIVE_OK) /* If _write_header failed, copy the error. */ archive_copy_error(&a->archive, ad); - else if (archive_entry_size(entry) > 0) + else if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) > 0) /* Otherwise, pour data into the entry. */ r = copy_data(_a, ad); r2 = archive_write_finish_entry(ad); diff --git a/lib/libarchive/archive_read_open_fd.c b/contrib/libarchive/libarchive/archive_read_open_fd.c similarity index 100% rename from lib/libarchive/archive_read_open_fd.c rename to contrib/libarchive/libarchive/archive_read_open_fd.c diff --git a/lib/libarchive/archive_read_open_file.c b/contrib/libarchive/libarchive/archive_read_open_file.c similarity index 100% rename from lib/libarchive/archive_read_open_file.c rename to contrib/libarchive/libarchive/archive_read_open_file.c diff --git a/lib/libarchive/archive_read_open_filename.c b/contrib/libarchive/libarchive/archive_read_open_filename.c similarity index 100% rename from lib/libarchive/archive_read_open_filename.c rename to contrib/libarchive/libarchive/archive_read_open_filename.c diff --git a/lib/libarchive/archive_read_open_memory.c b/contrib/libarchive/libarchive/archive_read_open_memory.c similarity index 100% rename from lib/libarchive/archive_read_open_memory.c rename to contrib/libarchive/libarchive/archive_read_open_memory.c diff --git a/lib/libarchive/archive_read_private.h b/contrib/libarchive/libarchive/archive_read_private.h similarity index 100% rename from lib/libarchive/archive_read_private.h rename to contrib/libarchive/libarchive/archive_read_private.h diff --git a/lib/libarchive/archive_read_support_compression_all.c b/contrib/libarchive/libarchive/archive_read_support_compression_all.c similarity index 100% rename from lib/libarchive/archive_read_support_compression_all.c rename to contrib/libarchive/libarchive/archive_read_support_compression_all.c diff --git a/lib/libarchive/archive_read_support_compression_bzip2.c b/contrib/libarchive/libarchive/archive_read_support_compression_bzip2.c similarity index 99% rename from lib/libarchive/archive_read_support_compression_bzip2.c rename to contrib/libarchive/libarchive/archive_read_support_compression_bzip2.c index fc419d4cab60..891742f653fd 100644 --- a/lib/libarchive/archive_read_support_compression_bzip2.c +++ b/contrib/libarchive/libarchive/archive_read_support_compression_bzip2.c @@ -350,4 +350,4 @@ bzip2_filter_close(struct archive_read_filter *self) return (ret); } -#endif /* HAVE_BZLIB_H */ +#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */ diff --git a/lib/libarchive/archive_read_support_compression_compress.c b/contrib/libarchive/libarchive/archive_read_support_compression_compress.c similarity index 100% rename from lib/libarchive/archive_read_support_compression_compress.c rename to contrib/libarchive/libarchive/archive_read_support_compression_compress.c diff --git a/lib/libarchive/archive_read_support_compression_gzip.c b/contrib/libarchive/libarchive/archive_read_support_compression_gzip.c similarity index 100% rename from lib/libarchive/archive_read_support_compression_gzip.c rename to contrib/libarchive/libarchive/archive_read_support_compression_gzip.c diff --git a/lib/libarchive/archive_read_support_compression_none.c b/contrib/libarchive/libarchive/archive_read_support_compression_none.c similarity index 100% rename from lib/libarchive/archive_read_support_compression_none.c rename to contrib/libarchive/libarchive/archive_read_support_compression_none.c diff --git a/lib/libarchive/archive_read_support_compression_program.c b/contrib/libarchive/libarchive/archive_read_support_compression_program.c similarity index 100% rename from lib/libarchive/archive_read_support_compression_program.c rename to contrib/libarchive/libarchive/archive_read_support_compression_program.c diff --git a/lib/libarchive/archive_read_support_compression_rpm.c b/contrib/libarchive/libarchive/archive_read_support_compression_rpm.c similarity index 99% rename from lib/libarchive/archive_read_support_compression_rpm.c rename to contrib/libarchive/libarchive/archive_read_support_compression_rpm.c index f8bd87899fb1..051baa5e1229 100644 --- a/lib/libarchive/archive_read_support_compression_rpm.c +++ b/contrib/libarchive/libarchive/archive_read_support_compression_rpm.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/lib/libarchive/archive_read_support_compression_uu.c b/contrib/libarchive/libarchive/archive_read_support_compression_uu.c similarity index 99% rename from lib/libarchive/archive_read_support_compression_uu.c rename to contrib/libarchive/libarchive/archive_read_support_compression_uu.c index cb1dae504e09..1b6a54c16326 100644 --- a/lib/libarchive/archive_read_support_compression_uu.c +++ b/contrib/libarchive/libarchive/archive_read_support_compression_uu.c @@ -488,9 +488,9 @@ uudecode_filter_read(struct archive_read_filter *self, const void **buff) switch (uudecode->state) { default: case ST_FIND_HEAD: - if (len - nl > 13 && memcmp(b, "begin ", 6) == 0) + if (len - nl >= 11 && memcmp(b, "begin ", 6) == 0) l = 6; - else if (len - nl > 18 && + else if (len - nl >= 18 && memcmp(b, "begin-base64 ", 13) == 0) l = 13; else diff --git a/lib/libarchive/archive_read_support_compression_xz.c b/contrib/libarchive/libarchive/archive_read_support_compression_xz.c similarity index 100% rename from lib/libarchive/archive_read_support_compression_xz.c rename to contrib/libarchive/libarchive/archive_read_support_compression_xz.c diff --git a/lib/libarchive/archive_read_support_format_all.c b/contrib/libarchive/libarchive/archive_read_support_format_all.c similarity index 81% rename from lib/libarchive/archive_read_support_format_all.c rename to contrib/libarchive/libarchive/archive_read_support_format_all.c index 69d16fc6a470..e57cd432acc3 100644 --- a/lib/libarchive/archive_read_support_format_all.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_all.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2011 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,5 +39,13 @@ archive_read_support_format_all(struct archive *a) archive_read_support_format_tar(a); archive_read_support_format_xar(a); archive_read_support_format_zip(a); + + /* Note: We always return ARCHIVE_OK here, even if some of the + * above return ARCHIVE_WARN. The intent here is to enable + * "as much as possible." Clients who need specific + * compression should enable those individually so they can + * verify the level of support. */ + /* Clear any warning messages set by the above functions. */ + archive_clear_error(a); return (ARCHIVE_OK); } diff --git a/lib/libarchive/archive_read_support_format_ar.c b/contrib/libarchive/libarchive/archive_read_support_format_ar.c similarity index 100% rename from lib/libarchive/archive_read_support_format_ar.c rename to contrib/libarchive/libarchive/archive_read_support_format_ar.c diff --git a/lib/libarchive/archive_read_support_format_cpio.c b/contrib/libarchive/libarchive/archive_read_support_format_cpio.c similarity index 98% rename from lib/libarchive/archive_read_support_format_cpio.c rename to contrib/libarchive/libarchive/archive_read_support_format_cpio.c index 24f3d35b30ed..87e2bf11e93d 100644 --- a/lib/libarchive/archive_read_support_format_cpio.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_cpio.c @@ -42,6 +42,10 @@ __FBSDID("$FreeBSD$"); #include "archive_private.h" #include "archive_read_private.h" +#ifdef _MSC_VER +#define __packed +#pragma pack(push, 1) +#endif struct cpio_bin_header { unsigned char c_magic[2]; unsigned char c_dev[2]; @@ -87,6 +91,11 @@ struct cpio_newc_header { char c_crc[8]; } __packed; +#ifdef _MSC_VER +#undef __packed +#pragma pack(pop) +#endif + struct links_entry { struct links_entry *next; struct links_entry *previous; @@ -264,9 +273,9 @@ archive_read_format_cpio_read_header(struct archive_read *a, /* Compare name to "TRAILER!!!" to test for end-of-archive. */ if (namelength == 11 && strcmp((const char *)h, "TRAILER!!!") == 0) { - /* TODO: Store file location of start of block. */ - archive_set_error(&a->archive, 0, NULL); - return (ARCHIVE_EOF); + /* TODO: Store file location of start of block. */ + archive_clear_error(&a->archive); + return (ARCHIVE_EOF); } /* Detect and record hardlinks to previously-extracted entries. */ diff --git a/lib/libarchive/archive_read_support_format_empty.c b/contrib/libarchive/libarchive/archive_read_support_format_empty.c similarity index 100% rename from lib/libarchive/archive_read_support_format_empty.c rename to contrib/libarchive/libarchive/archive_read_support_format_empty.c diff --git a/lib/libarchive/archive_read_support_format_iso9660.c b/contrib/libarchive/libarchive/archive_read_support_format_iso9660.c similarity index 97% rename from lib/libarchive/archive_read_support_format_iso9660.c rename to contrib/libarchive/libarchive/archive_read_support_format_iso9660.c index 021646112b3d..5c5addbbc691 100644 --- a/lib/libarchive/archive_read_support_format_iso9660.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_iso9660.c @@ -934,14 +934,14 @@ read_children(struct archive_read *a, struct file_info *parent) archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Ignoring out-of-order directory (%s) %jd > %jd", parent->name.s, - iso9660->current_position, - parent->offset); + (intmax_t)iso9660->current_position, + (intmax_t)parent->offset); return (ARCHIVE_WARN); } if (parent->offset + parent->size > iso9660->volume_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Directory is beyond end-of-media: %s", - parent->name); + parent->name.s); return (ARCHIVE_WARN); } if (iso9660->current_position < parent->offset) { @@ -1139,7 +1139,7 @@ archive_read_format_iso9660_read_header(struct archive_read *a, if (file->offset + file->size > iso9660->volume_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "File is beyond end-of-media: %s", file->name); + "File is beyond end-of-media: %s", file->name.s); iso9660->entry_bytes_remaining = 0; iso9660->entry_sparse_offset = 0; return (ARCHIVE_WARN); @@ -1198,10 +1198,10 @@ archive_read_format_iso9660_read_header(struct archive_read *a, if ((file->mode & AE_IFMT) != AE_IFDIR && file->offset < iso9660->current_position) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring out-of-order file @%x (%s) %jd < %jd", - file, + "Ignoring out-of-order file (%s) %jd < %jd", iso9660->pathname.s, - file->offset, iso9660->current_position); + (intmax_t)file->offset, + (intmax_t)iso9660->current_position); iso9660->entry_bytes_remaining = 0; iso9660->entry_sparse_offset = 0; return (ARCHIVE_WARN); @@ -1524,8 +1524,8 @@ archive_read_format_iso9660_read_data(struct archive_read *a, archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Ignoring out-of-order file (%s) %jd < %jd", iso9660->pathname.s, - iso9660->entry_content->offset, - iso9660->current_position); + (intmax_t)iso9660->entry_content->offset, + (intmax_t)iso9660->current_position); *buff = NULL; *size = 0; *offset = iso9660->entry_sparse_offset; @@ -1626,8 +1626,8 @@ parse_file_info(struct archive_read *a, struct file_info *parent, */ if (location > 0 && (location + ((fsize + iso9660->logical_block_size -1) - / iso9660->logical_block_size)) > - (unsigned int)iso9660->volume_block) { + / iso9660->logical_block_size)) + > (uint32_t)iso9660->volume_block) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Invalid location of extent of file"); return (NULL); @@ -1800,26 +1800,82 @@ parse_file_info(struct archive_read *a, struct file_info *parent, file->re = 0; parent->subdirs--; } else if (file->re) { - /* This file's parent is not rr_moved, clear invalid - * "RE" mark. */ - if (parent == NULL || parent->rr_moved == 0) - file->re = 0; - else if ((flags & 0x02) == 0) { - file->rr_moved_has_re_only = 0; - file->re = 0; + /* + * Sanity check: file's parent is rr_moved. + */ + if (parent == NULL || parent->rr_moved == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge RE"); + return (NULL); + } + /* + * Sanity check: file does not have "CL" extension. + */ + if (file->cl_offset) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge RE and CL"); + return (NULL); + } + /* + * Sanity check: The file type must be a directory. + */ + if ((flags & 0x02) == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge RE"); + return (NULL); } } else if (parent != NULL && parent->rr_moved) file->rr_moved_has_re_only = 0; else if (parent != NULL && (flags & 0x02) && (parent->re || parent->re_descendant)) file->re_descendant = 1; - if (file->cl_offset != 0) { + if (file->cl_offset) { + struct file_info *r; + + if (parent == NULL || parent->parent == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + return (NULL); + } + /* + * Sanity check: The file type must be a regular file. + */ + if ((flags & 0x02) != 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + return (NULL); + } parent->subdirs++; /* Overwrite an offset and a number of this "CL" entry * to appear before other dirs. "+1" to those is to * make sure to appear after "RE" entry which this * "CL" entry should be connected with. */ file->offset = file->number = file->cl_offset + 1; + + /* + * Sanity check: cl_offset does not point at its + * the parents or itself. + */ + for (r = parent; r; r = r->parent) { + if (r->offset == file->cl_offset) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + return (NULL); + } + } + if (file->cl_offset == file->offset || + parent->rr_moved) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + return (NULL); + } } } @@ -1923,6 +1979,13 @@ parse_rockridge(struct archive_read *a, struct file_info *file, */ break; } + if (p[0] == 'P' && p[1] == 'L') { + /* + * PL extension won't appear; + * contents are always ignored. + */ + break; + } if (p[0] == 'P' && p[1] == 'N') { if (version == 1 && data_length == 16) { file->rdev = toi(data,4); @@ -2698,6 +2761,9 @@ rede_add_entry(struct file_info *file) { struct file_info *re; + /* + * Find "RE" entry. + */ re = file->parent; while (re != NULL && !re->re) re = re->parent; diff --git a/lib/libarchive/archive_read_support_format_mtree.c b/contrib/libarchive/libarchive/archive_read_support_format_mtree.c similarity index 100% rename from lib/libarchive/archive_read_support_format_mtree.c rename to contrib/libarchive/libarchive/archive_read_support_format_mtree.c diff --git a/lib/libarchive/archive_read_support_format_raw.c b/contrib/libarchive/libarchive/archive_read_support_format_raw.c similarity index 100% rename from lib/libarchive/archive_read_support_format_raw.c rename to contrib/libarchive/libarchive/archive_read_support_format_raw.c diff --git a/lib/libarchive/archive_read_support_format_tar.c b/contrib/libarchive/libarchive/archive_read_support_format_tar.c similarity index 99% rename from lib/libarchive/archive_read_support_format_tar.c rename to contrib/libarchive/libarchive/archive_read_support_format_tar.c index 20e1293c15c6..62be309382f5 100644 --- a/lib/libarchive/archive_read_support_format_tar.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_tar.c @@ -576,7 +576,7 @@ tar_read_header(struct archive_read *a, struct tar *tar, h = __archive_read_ahead(a, 512, NULL); if (h != NULL) __archive_read_consume(a, 512); - archive_set_error(&a->archive, 0, NULL); + archive_clear_error(&a->archive); if (a->archive.archive_format_name == NULL) { a->archive.archive_format = ARCHIVE_FORMAT_TAR; a->archive.archive_format_name = "tar"; diff --git a/lib/libarchive/archive_read_support_format_xar.c b/contrib/libarchive/libarchive/archive_read_support_format_xar.c similarity index 100% rename from lib/libarchive/archive_read_support_format_xar.c rename to contrib/libarchive/libarchive/archive_read_support_format_xar.c diff --git a/lib/libarchive/archive_read_support_format_zip.c b/contrib/libarchive/libarchive/archive_read_support_format_zip.c similarity index 99% rename from lib/libarchive/archive_read_support_format_zip.c rename to contrib/libarchive/libarchive/archive_read_support_format_zip.c index 0fa1fa391d58..a02a2c290e0e 100644 --- a/lib/libarchive/archive_read_support_format_zip.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_zip.c @@ -211,7 +211,7 @@ archive_read_format_zip_bid(struct archive_read *a) /* Get 4k of data beyond where we stopped. */ buff = __archive_read_ahead(a, offset + 4096, &bytes_avail); - if (bytes_avail < offset + 1) + if (buff == NULL) break; p = (const char *)buff + offset; while (p + 9 < (const char *)buff + bytes_avail) { diff --git a/lib/libarchive/archive_string.c b/contrib/libarchive/libarchive/archive_string.c similarity index 99% rename from lib/libarchive/archive_string.c rename to contrib/libarchive/libarchive/archive_string.c index d68ad5875ae7..c67182d6f31a 100644 --- a/lib/libarchive/archive_string.c +++ b/contrib/libarchive/libarchive/archive_string.c @@ -152,7 +152,7 @@ __archive_strncat(struct archive_string *as, const void *_p, size_t n) /* Like strlen(p), except won't examine positions beyond p[n]. */ s = 0; pp = p; - while (*pp && s < n) { + while (s < n && *pp) { pp++; s++; } diff --git a/lib/libarchive/archive_string.h b/contrib/libarchive/libarchive/archive_string.h similarity index 98% rename from lib/libarchive/archive_string.h rename to contrib/libarchive/libarchive/archive_string.h index 68fbf167e734..f0655d143deb 100644 --- a/lib/libarchive/archive_string.h +++ b/contrib/libarchive/libarchive/archive_string.h @@ -44,6 +44,8 @@ #include #endif +#include "archive.h" + /* * Basic resizable/reusable string support a la Java's "StringBuffer." * @@ -134,10 +136,11 @@ void __archive_string_free(struct archive_string *); /* Like 'vsprintf', but resizes the underlying string as necessary. */ void __archive_string_vsprintf(struct archive_string *, const char *, - va_list); + va_list) __LA_PRINTF(2, 0); #define archive_string_vsprintf __archive_string_vsprintf -void __archive_string_sprintf(struct archive_string *, const char *, ...); +void __archive_string_sprintf(struct archive_string *, const char *, ...) + __LA_PRINTF(2, 3); #define archive_string_sprintf __archive_string_sprintf /* Allocates a fresh buffer and converts as (assumed to be UTF-8) into it. diff --git a/lib/libarchive/archive_string_sprintf.c b/contrib/libarchive/libarchive/archive_string_sprintf.c similarity index 100% rename from lib/libarchive/archive_string_sprintf.c rename to contrib/libarchive/libarchive/archive_string_sprintf.c diff --git a/lib/libarchive/archive_util.3 b/contrib/libarchive/libarchive/archive_util.3 similarity index 100% rename from lib/libarchive/archive_util.3 rename to contrib/libarchive/libarchive/archive_util.3 diff --git a/lib/libarchive/archive_util.c b/contrib/libarchive/libarchive/archive_util.c similarity index 99% rename from lib/libarchive/archive_util.c rename to contrib/libarchive/libarchive/archive_util.c index 4c0de025dda0..8f2b4c62c014 100644 --- a/lib/libarchive/archive_util.c +++ b/contrib/libarchive/libarchive/archive_util.c @@ -155,6 +155,7 @@ archive_clear_error(struct archive *a) { archive_string_empty(&a->error_string); a->error = NULL; + a->archive_error_number = 0; } void diff --git a/lib/libarchive/archive_virtual.c b/contrib/libarchive/libarchive/archive_virtual.c similarity index 100% rename from lib/libarchive/archive_virtual.c rename to contrib/libarchive/libarchive/archive_virtual.c diff --git a/lib/libarchive/archive_write.3 b/contrib/libarchive/libarchive/archive_write.3 similarity index 100% rename from lib/libarchive/archive_write.3 rename to contrib/libarchive/libarchive/archive_write.3 diff --git a/lib/libarchive/archive_write.c b/contrib/libarchive/libarchive/archive_write.c similarity index 100% rename from lib/libarchive/archive_write.c rename to contrib/libarchive/libarchive/archive_write.c diff --git a/lib/libarchive/archive_write_disk.3 b/contrib/libarchive/libarchive/archive_write_disk.3 similarity index 99% rename from lib/libarchive/archive_write_disk.3 rename to contrib/libarchive/libarchive/archive_write_disk.3 index 61138b80e444..bdb6ca052738 100644 --- a/lib/libarchive/archive_write_disk.3 +++ b/contrib/libarchive/libarchive/archive_write_disk.3 @@ -372,4 +372,4 @@ compact implementation when appropriate. There should be a corresponding .Nm archive_read_disk interface that walks a directory hierarchy and returns archive -entry objects. +entry objects. \ No newline at end of file diff --git a/lib/libarchive/archive_write_disk.c b/contrib/libarchive/libarchive/archive_write_disk.c similarity index 96% rename from lib/libarchive/archive_write_disk.c rename to contrib/libarchive/libarchive/archive_write_disk.c index 8a4fd0412adb..49ced58a8728 100644 --- a/lib/libarchive/archive_write_disk.c +++ b/contrib/libarchive/libarchive/archive_write_disk.c @@ -1513,6 +1513,22 @@ check_symlinks(struct archive_write_disk *a) } #if defined(_WIN32) || defined(__CYGWIN__) +static int +guidword(const char *p, int n) +{ + int i; + + for (i = 0; i < n; i++) { + if ((*p >= '0' && *p <= '9') || + (*p >= 'a' && *p <= 'f') || + (*p >= 'A' && *p <= 'F')) + p++; + else + return (-1); + } + return (0); +} + /* * 1. Convert a path separator from '\' to '/' . * We shouldn't check multi-byte character directly because some @@ -1521,26 +1537,92 @@ check_symlinks(struct archive_write_disk *a) * 2. Replace unusable characters in Windows with underscore('_'). * See also : http://msdn.microsoft.com/en-us/library/aa365247.aspx */ -static void +static int cleanup_pathname_win(struct archive_write_disk *a) { wchar_t wc; char *p; size_t alen, l; - alen = 0; - l = 0; - for (p = a->name; *p != '\0'; p++) { - ++alen; - if (*p == '\\') - l = 1; + p = a->name; + /* Skip leading "\\.\" or "\\?\" or "\\?\UNC\" or + * "\\?\Volume{GUID}\" + * (absolute path prefixes used by Windows API) */ + if ((p[0] == '\\' || p[0] == '/') && (p[1] == '\\' || p[1] == '/' ) && + (p[2] == '.' || p[2] == '?') && (p[3] == '\\' || p[3] == '/')) + { + /* A path begin with "\\?\UNC\" */ + if (p[2] == '?' && + (p[4] == 'U' || p[4] == 'u') && + (p[5] == 'N' || p[5] == 'n') && + (p[6] == 'C' || p[6] == 'c') && + (p[7] == '\\' || p[7] == '/')) + p += 8; + /* A path begin with "\\?\Volume{GUID}\" */ + else if (p[2] == '?' && + (p[4] == 'V' || p[4] == 'v') && + (p[5] == 'O' || p[5] == 'o') && + (p[6] == 'L' || p[6] == 'l') && + (p[7] == 'U' || p[7] == 'u') && + (p[8] == 'M' || p[8] == 'm') && + (p[9] == 'E' || p[9] == 'e') && + p[10] == '{') { + if (guidword(p+11, 8) == 0 && p[19] == '-' && + guidword(p+20, 4) == 0 && p[24] == '-' && + guidword(p+25, 4) == 0 && p[29] == '-' && + guidword(p+30, 4) == 0 && p[34] == '-' && + guidword(p+35, 12) == 0 && p[47] == '}' && + (p[48] == '\\' || p[48] == '/')) + p += 49; + else + p += 4; + /* A path begin with "\\.\PhysicalDriveX" */ + } else if (p[2] == '.' && + (p[4] == 'P' || p[4] == 'p') && + (p[5] == 'H' || p[5] == 'h') && + (p[6] == 'Y' || p[6] == 'y') && + (p[7] == 'S' || p[7] == 's') && + (p[8] == 'I' || p[8] == 'i') && + (p[9] == 'C' || p[9] == 'c') && + (p[9] == 'A' || p[9] == 'a') && + (p[9] == 'L' || p[9] == 'l') && + (p[9] == 'D' || p[9] == 'd') && + (p[9] == 'R' || p[9] == 'r') && + (p[9] == 'I' || p[9] == 'i') && + (p[9] == 'V' || p[9] == 'v') && + (p[9] == 'E' || p[9] == 'e') && + (p[10] >= '0' && p[10] <= '9') && + p[11] == '\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Path is a physical drive name"); + return (ARCHIVE_FAILED); + } else + p += 4; + } + + /* Skip leading drive letter from archives created + * on Windows. */ + if (((p[0] >= 'a' && p[0] <= 'z') || + (p[0] >= 'A' && p[0] <= 'Z')) && + p[1] == ':') { + if (p[2] == '\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Path is a drive name"); + return (ARCHIVE_FAILED); + } + if (p[2] == '\\' || p[2] == '/') + p += 3; + } + + for (; *p != '\0'; p++) { /* Rewrite the path name if its character is a unusable. */ if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || *p == '<' || *p == '>' || *p == '|') *p = '_'; } - if (alen == 0 || l == 0) - return; + alen = p - a->name; + if (alen == 0 || strchr(a->name, '\\') == NULL) + return (ARCHIVE_OK); /* * Convert path separator. */ @@ -1560,6 +1642,7 @@ cleanup_pathname_win(struct archive_write_disk *a) p += l; alen -= l; } + return (ARCHIVE_OK); } #endif @@ -1583,7 +1666,8 @@ cleanup_pathname(struct archive_write_disk *a) } #if defined(_WIN32) || defined(__CYGWIN__) - cleanup_pathname_win(a); + if (cleanup_pathname_win(a) != ARCHIVE_OK) + return (ARCHIVE_FAILED); #endif /* Skip leading '/'. */ if (*src == '/') @@ -1730,7 +1814,7 @@ create_dir(struct archive_write_disk *a, char *path) if (unlink(path) != 0) { archive_set_error(&a->archive, errno, "Can't create directory '%s': " - "Conflicting file cannot be removed"); + "Conflicting file cannot be removed", path); return (ARCHIVE_FAILED); } } else if (errno != ENOENT && errno != ENOTDIR) { diff --git a/lib/libarchive/archive_write_disk_private.h b/contrib/libarchive/libarchive/archive_write_disk_private.h similarity index 100% rename from lib/libarchive/archive_write_disk_private.h rename to contrib/libarchive/libarchive/archive_write_disk_private.h diff --git a/lib/libarchive/archive_write_disk_set_standard_lookup.c b/contrib/libarchive/libarchive/archive_write_disk_set_standard_lookup.c similarity index 100% rename from lib/libarchive/archive_write_disk_set_standard_lookup.c rename to contrib/libarchive/libarchive/archive_write_disk_set_standard_lookup.c diff --git a/lib/libarchive/archive_write_open_fd.c b/contrib/libarchive/libarchive/archive_write_open_fd.c similarity index 100% rename from lib/libarchive/archive_write_open_fd.c rename to contrib/libarchive/libarchive/archive_write_open_fd.c diff --git a/lib/libarchive/archive_write_open_file.c b/contrib/libarchive/libarchive/archive_write_open_file.c similarity index 100% rename from lib/libarchive/archive_write_open_file.c rename to contrib/libarchive/libarchive/archive_write_open_file.c diff --git a/lib/libarchive/archive_write_open_filename.c b/contrib/libarchive/libarchive/archive_write_open_filename.c similarity index 100% rename from lib/libarchive/archive_write_open_filename.c rename to contrib/libarchive/libarchive/archive_write_open_filename.c diff --git a/lib/libarchive/archive_write_open_memory.c b/contrib/libarchive/libarchive/archive_write_open_memory.c similarity index 100% rename from lib/libarchive/archive_write_open_memory.c rename to contrib/libarchive/libarchive/archive_write_open_memory.c diff --git a/lib/libarchive/archive_write_private.h b/contrib/libarchive/libarchive/archive_write_private.h similarity index 100% rename from lib/libarchive/archive_write_private.h rename to contrib/libarchive/libarchive/archive_write_private.h diff --git a/lib/libarchive/archive_write_set_compression_bzip2.c b/contrib/libarchive/libarchive/archive_write_set_compression_bzip2.c similarity index 100% rename from lib/libarchive/archive_write_set_compression_bzip2.c rename to contrib/libarchive/libarchive/archive_write_set_compression_bzip2.c diff --git a/lib/libarchive/archive_write_set_compression_compress.c b/contrib/libarchive/libarchive/archive_write_set_compression_compress.c similarity index 100% rename from lib/libarchive/archive_write_set_compression_compress.c rename to contrib/libarchive/libarchive/archive_write_set_compression_compress.c diff --git a/lib/libarchive/archive_write_set_compression_gzip.c b/contrib/libarchive/libarchive/archive_write_set_compression_gzip.c similarity index 100% rename from lib/libarchive/archive_write_set_compression_gzip.c rename to contrib/libarchive/libarchive/archive_write_set_compression_gzip.c diff --git a/lib/libarchive/archive_write_set_compression_none.c b/contrib/libarchive/libarchive/archive_write_set_compression_none.c similarity index 100% rename from lib/libarchive/archive_write_set_compression_none.c rename to contrib/libarchive/libarchive/archive_write_set_compression_none.c diff --git a/lib/libarchive/archive_write_set_compression_program.c b/contrib/libarchive/libarchive/archive_write_set_compression_program.c similarity index 100% rename from lib/libarchive/archive_write_set_compression_program.c rename to contrib/libarchive/libarchive/archive_write_set_compression_program.c diff --git a/lib/libarchive/archive_write_set_compression_xz.c b/contrib/libarchive/libarchive/archive_write_set_compression_xz.c similarity index 99% rename from lib/libarchive/archive_write_set_compression_xz.c rename to contrib/libarchive/libarchive/archive_write_set_compression_xz.c index d97bca7e512b..15b6cc273907 100644 --- a/lib/libarchive/archive_write_set_compression_xz.c +++ b/contrib/libarchive/libarchive/archive_write_set_compression_xz.c @@ -132,9 +132,10 @@ static int archive_compressor_xz_init_stream(struct archive_write *a, struct private_data *state) { + static const lzma_stream lzma_stream_init_data = LZMA_STREAM_INIT; int ret; - state->stream = (lzma_stream)LZMA_STREAM_INIT; + state->stream = lzma_stream_init_data; state->stream.next_out = state->compressed; state->stream.avail_out = state->compressed_buffer_size; if (a->archive.compression_code == ARCHIVE_COMPRESSION_XZ) diff --git a/lib/libarchive/archive_write_set_format.c b/contrib/libarchive/libarchive/archive_write_set_format.c similarity index 100% rename from lib/libarchive/archive_write_set_format.c rename to contrib/libarchive/libarchive/archive_write_set_format.c diff --git a/lib/libarchive/archive_write_set_format_ar.c b/contrib/libarchive/libarchive/archive_write_set_format_ar.c similarity index 99% rename from lib/libarchive/archive_write_set_format_ar.c rename to contrib/libarchive/libarchive/archive_write_set_format_ar.c index bffe07cba8f5..cb8ddaa203e7 100644 --- a/lib/libarchive/archive_write_set_format_ar.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_ar.c @@ -440,7 +440,7 @@ archive_write_ar_finish_entry(struct archive_write *a) if (ar->entry_padding != 1) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Padding wrong size: %d should be 1 or 0", - ar->entry_padding); + (int)ar->entry_padding); return (ARCHIVE_WARN); } diff --git a/lib/libarchive/archive_write_set_format_by_name.c b/contrib/libarchive/libarchive/archive_write_set_format_by_name.c similarity index 100% rename from lib/libarchive/archive_write_set_format_by_name.c rename to contrib/libarchive/libarchive/archive_write_set_format_by_name.c diff --git a/lib/libarchive/archive_write_set_format_cpio.c b/contrib/libarchive/libarchive/archive_write_set_format_cpio.c similarity index 98% rename from lib/libarchive/archive_write_set_format_cpio.c rename to contrib/libarchive/libarchive/archive_write_set_format_cpio.c index 798646a0d3bd..2df9f191c9fe 100644 --- a/lib/libarchive/archive_write_set_format_cpio.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_cpio.c @@ -62,6 +62,11 @@ struct cpio { size_t ino_list_next; }; +#ifdef _MSC_VER +#define __packed +#pragma pack(push, 1) +#endif + struct cpio_header { char c_magic[6]; char c_dev[6]; @@ -76,6 +81,11 @@ struct cpio_header { char c_filesize[11]; } __packed; +#ifdef _MSC_VER +#undef __packed +#pragma pack(pop) +#endif + /* * Set output format to 'cpio' format. */ diff --git a/lib/libarchive/archive_write_set_format_cpio_newc.c b/contrib/libarchive/libarchive/archive_write_set_format_cpio_newc.c similarity index 100% rename from lib/libarchive/archive_write_set_format_cpio_newc.c rename to contrib/libarchive/libarchive/archive_write_set_format_cpio_newc.c diff --git a/lib/libarchive/archive_write_set_format_mtree.c b/contrib/libarchive/libarchive/archive_write_set_format_mtree.c similarity index 100% rename from lib/libarchive/archive_write_set_format_mtree.c rename to contrib/libarchive/libarchive/archive_write_set_format_mtree.c diff --git a/lib/libarchive/archive_write_set_format_pax.c b/contrib/libarchive/libarchive/archive_write_set_format_pax.c similarity index 100% rename from lib/libarchive/archive_write_set_format_pax.c rename to contrib/libarchive/libarchive/archive_write_set_format_pax.c diff --git a/lib/libarchive/archive_write_set_format_shar.c b/contrib/libarchive/libarchive/archive_write_set_format_shar.c similarity index 99% rename from lib/libarchive/archive_write_set_format_shar.c rename to contrib/libarchive/libarchive/archive_write_set_format_shar.c index 6cb58e863771..bd6276846658 100644 --- a/lib/libarchive/archive_write_set_format_shar.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_shar.c @@ -537,8 +537,7 @@ archive_write_shar_finish_entry(struct archive_write *a) } if ((p = archive_entry_fflags_text(shar->entry)) != NULL) { - archive_string_sprintf(&shar->work, "chflags %s ", - p, archive_entry_pathname(shar->entry)); + archive_string_sprintf(&shar->work, "chflags %s ", p); shar_quote(&shar->work, archive_entry_pathname(shar->entry), 1); archive_strcat(&shar->work, "\n"); diff --git a/lib/libarchive/archive_write_set_format_ustar.c b/contrib/libarchive/libarchive/archive_write_set_format_ustar.c similarity index 99% rename from lib/libarchive/archive_write_set_format_ustar.c rename to contrib/libarchive/libarchive/archive_write_set_format_ustar.c index 2de0cf1db2ba..54893d487492 100644 --- a/lib/libarchive/archive_write_set_format_ustar.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_ustar.c @@ -168,7 +168,7 @@ archive_write_set_format_ustar(struct archive *_a) /* Basic internal sanity test. */ if (sizeof(template_header) != 512) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %d should be 512", sizeof(template_header)); + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %d should be 512", (int)sizeof(template_header)); return (ARCHIVE_FATAL); } diff --git a/lib/libarchive/archive_write_set_format_zip.c b/contrib/libarchive/libarchive/archive_write_set_format_zip.c similarity index 100% rename from lib/libarchive/archive_write_set_format_zip.c rename to contrib/libarchive/libarchive/archive_write_set_format_zip.c diff --git a/lib/libarchive/cpio.5 b/contrib/libarchive/libarchive/cpio.5 similarity index 100% rename from lib/libarchive/cpio.5 rename to contrib/libarchive/libarchive/cpio.5 diff --git a/lib/libarchive/filter_fork.c b/contrib/libarchive/libarchive/filter_fork.c similarity index 100% rename from lib/libarchive/filter_fork.c rename to contrib/libarchive/libarchive/filter_fork.c diff --git a/lib/libarchive/filter_fork.h b/contrib/libarchive/libarchive/filter_fork.h similarity index 100% rename from lib/libarchive/filter_fork.h rename to contrib/libarchive/libarchive/filter_fork.h diff --git a/lib/libarchive/libarchive-formats.5 b/contrib/libarchive/libarchive/libarchive-formats.5 similarity index 99% rename from lib/libarchive/libarchive-formats.5 rename to contrib/libarchive/libarchive/libarchive-formats.5 index ef4b6ca6255b..e6849b90bea5 100644 --- a/lib/libarchive/libarchive-formats.5 +++ b/contrib/libarchive/libarchive/libarchive-formats.5 @@ -65,6 +65,7 @@ Later variants have extended this by either appropriating undefined areas of the header record, extending the header to multiple records, or by storing special entries that modify the interpretation of subsequent entries. +.Pp .Bl -tag -width indent .It Cm gnutar The diff --git a/lib/libarchive/libarchive.3 b/contrib/libarchive/libarchive/libarchive.3 similarity index 99% rename from lib/libarchive/libarchive.3 rename to contrib/libarchive/libarchive/libarchive.3 index 115a79c0f16f..445d4aad34de 100644 --- a/lib/libarchive/libarchive.3 +++ b/contrib/libarchive/libarchive/libarchive.3 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 6, 2010 +.Dd July 17, 2010 .Dt LIBARCHIVE 3 .Os .Sh NAME @@ -161,7 +161,7 @@ Each archive entry consists of a header followed by a certain amount of data. You can obtain the next header with .Fn archive_read_next_header , -which returns a pointer to a +which returns a pointer to an .Tn struct archive_entry structure with information about the current archive element. If the entry is a regular file, then the header will be followed @@ -351,7 +351,7 @@ or the arbitrary key/value pairs that can appear in pax interchange format archives. .Pp Conversely, of course, not all of the information that can be -stored in a +stored in an .Tn struct archive_entry is supported by all formats. For example, cpio formats do not support nanosecond timestamps; diff --git a/lib/libarchive/libarchive_internals.3 b/contrib/libarchive/libarchive/libarchive_internals.3 similarity index 99% rename from lib/libarchive/libarchive_internals.3 rename to contrib/libarchive/libarchive/libarchive_internals.3 index 61a17c498416..64a75e81c70d 100644 --- a/lib/libarchive/libarchive_internals.3 +++ b/contrib/libarchive/libarchive/libarchive_internals.3 @@ -126,7 +126,7 @@ to read the entire file into memory at once and return the entire file to libarchive as a single block; other clients may begin asynchronous I/O operations for the next block on each request. -.Ss Decompression Layer +.Ss Decompresssion Layer The decompression layer not only handles decompression, it also buffers data so that the format handlers see a much nicer I/O model. diff --git a/lib/libarchive/tar.5 b/contrib/libarchive/libarchive/tar.5 similarity index 100% rename from lib/libarchive/tar.5 rename to contrib/libarchive/libarchive/tar.5 diff --git a/lib/libarchive/test/README b/contrib/libarchive/libarchive/test/README similarity index 100% rename from lib/libarchive/test/README rename to contrib/libarchive/libarchive/test/README diff --git a/lib/libarchive/test/main.c b/contrib/libarchive/libarchive/test/main.c similarity index 100% rename from lib/libarchive/test/main.c rename to contrib/libarchive/libarchive/test/main.c diff --git a/lib/libarchive/test/read_open_memory.c b/contrib/libarchive/libarchive/test/read_open_memory.c similarity index 100% rename from lib/libarchive/test/read_open_memory.c rename to contrib/libarchive/libarchive/test/read_open_memory.c diff --git a/lib/libarchive/test/test.h b/contrib/libarchive/libarchive/test/test.h similarity index 100% rename from lib/libarchive/test/test.h rename to contrib/libarchive/libarchive/test/test.h diff --git a/lib/libarchive/test/test_acl_basic.c b/contrib/libarchive/libarchive/test/test_acl_basic.c similarity index 100% rename from lib/libarchive/test/test_acl_basic.c rename to contrib/libarchive/libarchive/test/test_acl_basic.c diff --git a/lib/libarchive/test/test_acl_freebsd.c b/contrib/libarchive/libarchive/test/test_acl_freebsd.c similarity index 100% rename from lib/libarchive/test/test_acl_freebsd.c rename to contrib/libarchive/libarchive/test/test_acl_freebsd.c diff --git a/lib/libarchive/test/test_acl_pax.c b/contrib/libarchive/libarchive/test/test_acl_pax.c similarity index 100% rename from lib/libarchive/test/test_acl_pax.c rename to contrib/libarchive/libarchive/test/test_acl_pax.c diff --git a/lib/libarchive/test/test_archive_api_feature.c b/contrib/libarchive/libarchive/test/test_archive_api_feature.c similarity index 100% rename from lib/libarchive/test/test_archive_api_feature.c rename to contrib/libarchive/libarchive/test/test_archive_api_feature.c diff --git a/lib/libarchive/test/test_bad_fd.c b/contrib/libarchive/libarchive/test/test_bad_fd.c similarity index 100% rename from lib/libarchive/test/test_bad_fd.c rename to contrib/libarchive/libarchive/test/test_bad_fd.c diff --git a/lib/libarchive/test/test_compat_bzip2.c b/contrib/libarchive/libarchive/test/test_compat_bzip2.c similarity index 100% rename from lib/libarchive/test/test_compat_bzip2.c rename to contrib/libarchive/libarchive/test/test_compat_bzip2.c diff --git a/lib/libarchive/test/test_compat_bzip2_1.tbz.uu b/contrib/libarchive/libarchive/test/test_compat_bzip2_1.tbz.uu similarity index 100% rename from lib/libarchive/test/test_compat_bzip2_1.tbz.uu rename to contrib/libarchive/libarchive/test/test_compat_bzip2_1.tbz.uu diff --git a/lib/libarchive/test/test_compat_bzip2_2.tbz.uu b/contrib/libarchive/libarchive/test/test_compat_bzip2_2.tbz.uu similarity index 100% rename from lib/libarchive/test/test_compat_bzip2_2.tbz.uu rename to contrib/libarchive/libarchive/test/test_compat_bzip2_2.tbz.uu diff --git a/lib/libarchive/test/test_compat_cpio.c b/contrib/libarchive/libarchive/test/test_compat_cpio.c similarity index 100% rename from lib/libarchive/test/test_compat_cpio.c rename to contrib/libarchive/libarchive/test/test_compat_cpio.c diff --git a/lib/libarchive/test/test_compat_cpio_1.cpio.uu b/contrib/libarchive/libarchive/test/test_compat_cpio_1.cpio.uu similarity index 100% rename from lib/libarchive/test/test_compat_cpio_1.cpio.uu rename to contrib/libarchive/libarchive/test/test_compat_cpio_1.cpio.uu diff --git a/lib/libarchive/test/test_compat_gtar.c b/contrib/libarchive/libarchive/test/test_compat_gtar.c similarity index 100% rename from lib/libarchive/test/test_compat_gtar.c rename to contrib/libarchive/libarchive/test/test_compat_gtar.c diff --git a/lib/libarchive/test/test_compat_gtar_1.tar.uu b/contrib/libarchive/libarchive/test/test_compat_gtar_1.tar.uu similarity index 100% rename from lib/libarchive/test/test_compat_gtar_1.tar.uu rename to contrib/libarchive/libarchive/test/test_compat_gtar_1.tar.uu diff --git a/lib/libarchive/test/test_compat_gzip.c b/contrib/libarchive/libarchive/test/test_compat_gzip.c similarity index 100% rename from lib/libarchive/test/test_compat_gzip.c rename to contrib/libarchive/libarchive/test/test_compat_gzip.c diff --git a/lib/libarchive/test/test_compat_gzip_1.tgz.uu b/contrib/libarchive/libarchive/test/test_compat_gzip_1.tgz.uu similarity index 100% rename from lib/libarchive/test/test_compat_gzip_1.tgz.uu rename to contrib/libarchive/libarchive/test/test_compat_gzip_1.tgz.uu diff --git a/lib/libarchive/test/test_compat_gzip_2.tgz.uu b/contrib/libarchive/libarchive/test/test_compat_gzip_2.tgz.uu similarity index 100% rename from lib/libarchive/test/test_compat_gzip_2.tgz.uu rename to contrib/libarchive/libarchive/test/test_compat_gzip_2.tgz.uu diff --git a/lib/libarchive/test/test_compat_lzma.c b/contrib/libarchive/libarchive/test/test_compat_lzma.c similarity index 100% rename from lib/libarchive/test/test_compat_lzma.c rename to contrib/libarchive/libarchive/test/test_compat_lzma.c diff --git a/lib/libarchive/test/test_compat_lzma_1.tlz.uu b/contrib/libarchive/libarchive/test/test_compat_lzma_1.tlz.uu similarity index 100% rename from lib/libarchive/test/test_compat_lzma_1.tlz.uu rename to contrib/libarchive/libarchive/test/test_compat_lzma_1.tlz.uu diff --git a/lib/libarchive/test/test_compat_lzma_2.tlz.uu b/contrib/libarchive/libarchive/test/test_compat_lzma_2.tlz.uu similarity index 100% rename from lib/libarchive/test/test_compat_lzma_2.tlz.uu rename to contrib/libarchive/libarchive/test/test_compat_lzma_2.tlz.uu diff --git a/lib/libarchive/test/test_compat_lzma_3.tlz.uu b/contrib/libarchive/libarchive/test/test_compat_lzma_3.tlz.uu similarity index 100% rename from lib/libarchive/test/test_compat_lzma_3.tlz.uu rename to contrib/libarchive/libarchive/test/test_compat_lzma_3.tlz.uu diff --git a/lib/libarchive/test/test_compat_solaris_tar_acl.c b/contrib/libarchive/libarchive/test/test_compat_solaris_tar_acl.c similarity index 100% rename from lib/libarchive/test/test_compat_solaris_tar_acl.c rename to contrib/libarchive/libarchive/test/test_compat_solaris_tar_acl.c diff --git a/lib/libarchive/test/test_compat_solaris_tar_acl.tar.uu b/contrib/libarchive/libarchive/test/test_compat_solaris_tar_acl.tar.uu similarity index 100% rename from lib/libarchive/test/test_compat_solaris_tar_acl.tar.uu rename to contrib/libarchive/libarchive/test/test_compat_solaris_tar_acl.tar.uu diff --git a/lib/libarchive/test/test_compat_tar_hardlink.c b/contrib/libarchive/libarchive/test/test_compat_tar_hardlink.c similarity index 100% rename from lib/libarchive/test/test_compat_tar_hardlink.c rename to contrib/libarchive/libarchive/test/test_compat_tar_hardlink.c diff --git a/lib/libarchive/test/test_compat_tar_hardlink_1.tar.uu b/contrib/libarchive/libarchive/test/test_compat_tar_hardlink_1.tar.uu similarity index 100% rename from lib/libarchive/test/test_compat_tar_hardlink_1.tar.uu rename to contrib/libarchive/libarchive/test/test_compat_tar_hardlink_1.tar.uu diff --git a/lib/libarchive/test/test_compat_xz.c b/contrib/libarchive/libarchive/test/test_compat_xz.c similarity index 100% rename from lib/libarchive/test/test_compat_xz.c rename to contrib/libarchive/libarchive/test/test_compat_xz.c diff --git a/lib/libarchive/test/test_compat_xz_1.txz.uu b/contrib/libarchive/libarchive/test/test_compat_xz_1.txz.uu similarity index 100% rename from lib/libarchive/test/test_compat_xz_1.txz.uu rename to contrib/libarchive/libarchive/test/test_compat_xz_1.txz.uu diff --git a/lib/libarchive/test/test_compat_zip.c b/contrib/libarchive/libarchive/test/test_compat_zip.c similarity index 100% rename from lib/libarchive/test/test_compat_zip.c rename to contrib/libarchive/libarchive/test/test_compat_zip.c diff --git a/lib/libarchive/test/test_compat_zip_1.zip.uu b/contrib/libarchive/libarchive/test/test_compat_zip_1.zip.uu similarity index 100% rename from lib/libarchive/test/test_compat_zip_1.zip.uu rename to contrib/libarchive/libarchive/test/test_compat_zip_1.zip.uu diff --git a/lib/libarchive/test/test_compat_zip_2.zip.uu b/contrib/libarchive/libarchive/test/test_compat_zip_2.zip.uu similarity index 100% rename from lib/libarchive/test/test_compat_zip_2.zip.uu rename to contrib/libarchive/libarchive/test/test_compat_zip_2.zip.uu diff --git a/lib/libarchive/test/test_empty_write.c b/contrib/libarchive/libarchive/test/test_empty_write.c similarity index 100% rename from lib/libarchive/test/test_empty_write.c rename to contrib/libarchive/libarchive/test/test_empty_write.c diff --git a/lib/libarchive/test/test_entry.c b/contrib/libarchive/libarchive/test/test_entry.c similarity index 100% rename from lib/libarchive/test/test_entry.c rename to contrib/libarchive/libarchive/test/test_entry.c diff --git a/lib/libarchive/test/test_entry_strmode.c b/contrib/libarchive/libarchive/test/test_entry_strmode.c similarity index 100% rename from lib/libarchive/test/test_entry_strmode.c rename to contrib/libarchive/libarchive/test/test_entry_strmode.c diff --git a/lib/libarchive/test/test_extattr_freebsd.c b/contrib/libarchive/libarchive/test/test_extattr_freebsd.c similarity index 100% rename from lib/libarchive/test/test_extattr_freebsd.c rename to contrib/libarchive/libarchive/test/test_extattr_freebsd.c diff --git a/lib/libarchive/test/test_fuzz.c b/contrib/libarchive/libarchive/test/test_fuzz.c similarity index 100% rename from lib/libarchive/test/test_fuzz.c rename to contrib/libarchive/libarchive/test/test_fuzz.c diff --git a/lib/libarchive/test/test_fuzz_1.iso.Z.uu b/contrib/libarchive/libarchive/test/test_fuzz_1.iso.Z.uu similarity index 100% rename from lib/libarchive/test/test_fuzz_1.iso.Z.uu rename to contrib/libarchive/libarchive/test/test_fuzz_1.iso.Z.uu diff --git a/lib/libarchive/test/test_link_resolver.c b/contrib/libarchive/libarchive/test/test_link_resolver.c similarity index 100% rename from lib/libarchive/test/test_link_resolver.c rename to contrib/libarchive/libarchive/test/test_link_resolver.c diff --git a/lib/libarchive/test/test_open_failure.c b/contrib/libarchive/libarchive/test/test_open_failure.c similarity index 100% rename from lib/libarchive/test/test_open_failure.c rename to contrib/libarchive/libarchive/test/test_open_failure.c diff --git a/lib/libarchive/test/test_open_fd.c b/contrib/libarchive/libarchive/test/test_open_fd.c similarity index 100% rename from lib/libarchive/test/test_open_fd.c rename to contrib/libarchive/libarchive/test/test_open_fd.c diff --git a/lib/libarchive/test/test_open_file.c b/contrib/libarchive/libarchive/test/test_open_file.c similarity index 100% rename from lib/libarchive/test/test_open_file.c rename to contrib/libarchive/libarchive/test/test_open_file.c diff --git a/lib/libarchive/test/test_open_filename.c b/contrib/libarchive/libarchive/test/test_open_filename.c similarity index 100% rename from lib/libarchive/test/test_open_filename.c rename to contrib/libarchive/libarchive/test/test_open_filename.c diff --git a/lib/libarchive/test/test_pax_filename_encoding.c b/contrib/libarchive/libarchive/test/test_pax_filename_encoding.c similarity index 100% rename from lib/libarchive/test/test_pax_filename_encoding.c rename to contrib/libarchive/libarchive/test/test_pax_filename_encoding.c diff --git a/lib/libarchive/test/test_pax_filename_encoding.tar.uu b/contrib/libarchive/libarchive/test/test_pax_filename_encoding.tar.uu similarity index 100% rename from lib/libarchive/test/test_pax_filename_encoding.tar.uu rename to contrib/libarchive/libarchive/test/test_pax_filename_encoding.tar.uu diff --git a/lib/libarchive/test/test_read_compress_program.c b/contrib/libarchive/libarchive/test/test_read_compress_program.c similarity index 100% rename from lib/libarchive/test/test_read_compress_program.c rename to contrib/libarchive/libarchive/test/test_read_compress_program.c diff --git a/lib/libarchive/test/test_read_data_large.c b/contrib/libarchive/libarchive/test/test_read_data_large.c similarity index 100% rename from lib/libarchive/test/test_read_data_large.c rename to contrib/libarchive/libarchive/test/test_read_data_large.c diff --git a/lib/libarchive/test/test_read_disk.c b/contrib/libarchive/libarchive/test/test_read_disk.c similarity index 100% rename from lib/libarchive/test/test_read_disk.c rename to contrib/libarchive/libarchive/test/test_read_disk.c diff --git a/lib/libarchive/test/test_read_disk_entry_from_file.c b/contrib/libarchive/libarchive/test/test_read_disk_entry_from_file.c similarity index 100% rename from lib/libarchive/test/test_read_disk_entry_from_file.c rename to contrib/libarchive/libarchive/test/test_read_disk_entry_from_file.c diff --git a/lib/libarchive/test/test_read_extract.c b/contrib/libarchive/libarchive/test/test_read_extract.c similarity index 100% rename from lib/libarchive/test/test_read_extract.c rename to contrib/libarchive/libarchive/test/test_read_extract.c diff --git a/lib/libarchive/test/test_read_file_nonexistent.c b/contrib/libarchive/libarchive/test/test_read_file_nonexistent.c similarity index 100% rename from lib/libarchive/test/test_read_file_nonexistent.c rename to contrib/libarchive/libarchive/test/test_read_file_nonexistent.c diff --git a/lib/libarchive/test/test_read_format_ar.ar.uu b/contrib/libarchive/libarchive/test/test_read_format_ar.ar.uu similarity index 100% rename from lib/libarchive/test/test_read_format_ar.ar.uu rename to contrib/libarchive/libarchive/test/test_read_format_ar.ar.uu diff --git a/lib/libarchive/test/test_read_format_ar.c b/contrib/libarchive/libarchive/test/test_read_format_ar.c similarity index 100% rename from lib/libarchive/test/test_read_format_ar.c rename to contrib/libarchive/libarchive/test/test_read_format_ar.c diff --git a/lib/libarchive/test/test_read_format_cpio_bin.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_bin.c similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_bin.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_bin.c diff --git a/lib/libarchive/test/test_read_format_cpio_bin_Z.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_bin_Z.c similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_bin_Z.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_bin_Z.c diff --git a/lib/libarchive/test/test_read_format_cpio_bin_be.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_bin_be.c similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_bin_be.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_bin_be.c diff --git a/lib/libarchive/test/test_read_format_cpio_bin_be.cpio.uu b/contrib/libarchive/libarchive/test/test_read_format_cpio_bin_be.cpio.uu similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_bin_be.cpio.uu rename to contrib/libarchive/libarchive/test/test_read_format_cpio_bin_be.cpio.uu diff --git a/lib/libarchive/test/test_read_format_cpio_bin_bz2.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_bin_bz2.c similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_bin_bz2.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_bin_bz2.c diff --git a/lib/libarchive/test/test_read_format_cpio_bin_gz.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_bin_gz.c similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_bin_gz.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_bin_gz.c diff --git a/lib/libarchive/test/test_read_format_cpio_bin_lzma.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_bin_lzma.c similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_bin_lzma.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_bin_lzma.c diff --git a/lib/libarchive/test/test_read_format_cpio_bin_xz.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_bin_xz.c similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_bin_xz.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_bin_xz.c diff --git a/lib/libarchive/test/test_read_format_cpio_odc.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_odc.c similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_odc.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_odc.c diff --git a/lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c similarity index 99% rename from lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c index 005838d24683..3b4170cb787c 100644 --- a/lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c +++ b/contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c @@ -24,7 +24,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "test.h" -__FBSDID("$FreeBSD$"); /* Execute the following command to rebuild the data for this program: diff --git a/lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu b/contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu similarity index 99% rename from lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu rename to contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu index 3e8515079057..884ca9487cb8 100644 --- a/lib/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu +++ b/contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu @@ -1,5 +1,3 @@ -$FreeBSD$ - begin 644 test_read_format_cpio_svr4_bzip2_rpm.rpm M[:ONVP,``````7)P;7-A;7!L92TQ+C`N,"TQ```````````````````````` M```````````````````````````````````````````!``4````````````` diff --git a/lib/libarchive/test/test_read_format_cpio_svr4_gzip.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_gzip.c similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_svr4_gzip.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_gzip.c diff --git a/lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.c similarity index 99% rename from lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.c index 59e53f13bb4f..eb8a38d9df35 100644 --- a/lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.c +++ b/contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.c @@ -24,7 +24,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "test.h" -__FBSDID("$FreeBSD$"); /* Execute the following command to rebuild the data for this program: diff --git a/lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu b/contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu similarity index 99% rename from lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu rename to contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu index ac29865a696f..54d305b7742c 100644 --- a/lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu +++ b/contrib/libarchive/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu @@ -1,5 +1,3 @@ -$FreeBSD$ - begin 644 test_read_format_cpio_svr4_gzip_rpm.rpm M[:ONVP,``````7)P;7-A;7!L92TQ+C`N,"TQ```````````````````````` M```````````````````````````````````````````!``4````````````` diff --git a/lib/libarchive/test/test_read_format_cpio_svr4c_Z.c b/contrib/libarchive/libarchive/test/test_read_format_cpio_svr4c_Z.c similarity index 100% rename from lib/libarchive/test/test_read_format_cpio_svr4c_Z.c rename to contrib/libarchive/libarchive/test/test_read_format_cpio_svr4c_Z.c diff --git a/lib/libarchive/test/test_read_format_empty.c b/contrib/libarchive/libarchive/test/test_read_format_empty.c similarity index 100% rename from lib/libarchive/test/test_read_format_empty.c rename to contrib/libarchive/libarchive/test/test_read_format_empty.c diff --git a/lib/libarchive/test/test_read_format_gtar_gz.c b/contrib/libarchive/libarchive/test/test_read_format_gtar_gz.c similarity index 100% rename from lib/libarchive/test/test_read_format_gtar_gz.c rename to contrib/libarchive/libarchive/test/test_read_format_gtar_gz.c diff --git a/lib/libarchive/test/test_read_format_gtar_lzma.c b/contrib/libarchive/libarchive/test/test_read_format_gtar_lzma.c similarity index 100% rename from lib/libarchive/test/test_read_format_gtar_lzma.c rename to contrib/libarchive/libarchive/test/test_read_format_gtar_lzma.c diff --git a/lib/libarchive/test/test_read_format_gtar_sparse.c b/contrib/libarchive/libarchive/test/test_read_format_gtar_sparse.c similarity index 100% rename from lib/libarchive/test/test_read_format_gtar_sparse.c rename to contrib/libarchive/libarchive/test/test_read_format_gtar_sparse.c diff --git a/lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu b/contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu similarity index 100% rename from lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu rename to contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu diff --git a/lib/libarchive/test/test_read_format_gtar_sparse_1_17.tar.uu b/contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_17.tar.uu similarity index 100% rename from lib/libarchive/test/test_read_format_gtar_sparse_1_17.tar.uu rename to contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_17.tar.uu diff --git a/lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix00.tar.uu b/contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_17_posix00.tar.uu similarity index 100% rename from lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix00.tar.uu rename to contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_17_posix00.tar.uu diff --git a/lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix01.tar.uu b/contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_17_posix01.tar.uu similarity index 100% rename from lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix01.tar.uu rename to contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_17_posix01.tar.uu diff --git a/lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix10.tar.uu b/contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_17_posix10.tar.uu similarity index 100% rename from lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix10.tar.uu rename to contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_17_posix10.tar.uu diff --git a/lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix10_modified.tar.uu b/contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_17_posix10_modified.tar.uu similarity index 100% rename from lib/libarchive/test/test_read_format_gtar_sparse_1_17_posix10_modified.tar.uu rename to contrib/libarchive/libarchive/test/test_read_format_gtar_sparse_1_17_posix10_modified.tar.uu diff --git a/lib/libarchive/test/test_read_format_iso.iso.Z.uu b/contrib/libarchive/libarchive/test/test_read_format_iso.iso.Z.uu similarity index 100% rename from lib/libarchive/test/test_read_format_iso.iso.Z.uu rename to contrib/libarchive/libarchive/test/test_read_format_iso.iso.Z.uu diff --git a/lib/libarchive/test/test_read_format_iso_2.iso.Z.uu b/contrib/libarchive/libarchive/test/test_read_format_iso_2.iso.Z.uu similarity index 99% rename from lib/libarchive/test/test_read_format_iso_2.iso.Z.uu rename to contrib/libarchive/libarchive/test/test_read_format_iso_2.iso.Z.uu index 6851f316b38d..688ec36af14c 100644 --- a/lib/libarchive/test/test_read_format_iso_2.iso.Z.uu +++ b/contrib/libarchive/libarchive/test/test_read_format_iso_2.iso.Z.uu @@ -1,5 +1,3 @@ -$FreeBSD$ - begin 644 test_read_format_iso_2.iso.Z M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR MI,F3*%.J7,FRIinclusions; match != NULL; match = match->next){ - if (match->matches == 0 - && match_inclusion(match, pathname)) { - matching->inclusions_unmatched_count--; - match->matches++; - matched = match; - } - } - /* Exclusions take priority */ for (match = matching->exclusions; match != NULL; match = match->next){ if (match_exclusion(match, pathname)) return (1); } - /* It's not excluded and we found an inclusion above, so it's included. */ - if (matched != NULL) - return (0); - - - /* We didn't find an unmatched inclusion, check the remaining ones. */ + /* Then check for inclusions */ + matched = NULL; for (match = matching->inclusions; match != NULL; match = match->next){ - /* We looked at previously-unmatched inclusions already. */ - if (match->matches > 0 - && match_inclusion(match, pathname)) { - match->matches++; - return (0); + if (match_inclusion(match, pathname)) { + /* + * If this pattern has never been matched, + * then we're done. + */ + if (match->matches == 0) { + match->matches++; + matching->inclusions_unmatched_count--; + return (0); + } + /* + * Otherwise, remember the match but keep checking + * in case we can tick off an unmatched pattern. + */ + matched = match; } } + /* + * We didn't find a pattern that had never been matched, but + * we did find a match, so count it and exit. + */ + if (matched != NULL) { + matched->matches++; + return (0); + } /* If there were inclusions, default is to exclude. */ if (matching->inclusions != NULL) @@ -220,7 +219,11 @@ match_exclusion(struct match *match, const char *pathname) static int match_inclusion(struct match *match, const char *pathname) { +#if 0 + return (lafe_pathmatch(match->pattern, pathname, 0)); +#else return (lafe_pathmatch(match->pattern, pathname, PATHMATCH_NO_ANCHOR_END)); +#endif } void diff --git a/lib/libarchive/libarchive_fe/matching.h b/contrib/libarchive/libarchive_fe/matching.h similarity index 100% rename from lib/libarchive/libarchive_fe/matching.h rename to contrib/libarchive/libarchive_fe/matching.h diff --git a/lib/libarchive/libarchive_fe/pathmatch.c b/contrib/libarchive/libarchive_fe/pathmatch.c similarity index 100% rename from lib/libarchive/libarchive_fe/pathmatch.c rename to contrib/libarchive/libarchive_fe/pathmatch.c diff --git a/lib/libarchive/libarchive_fe/pathmatch.h b/contrib/libarchive/libarchive_fe/pathmatch.h similarity index 100% rename from lib/libarchive/libarchive_fe/pathmatch.h rename to contrib/libarchive/libarchive_fe/pathmatch.h diff --git a/usr.bin/tar/bsdtar.1 b/contrib/libarchive/tar/bsdtar.1 similarity index 100% rename from usr.bin/tar/bsdtar.1 rename to contrib/libarchive/tar/bsdtar.1 diff --git a/usr.bin/tar/bsdtar.c b/contrib/libarchive/tar/bsdtar.c similarity index 99% rename from usr.bin/tar/bsdtar.c rename to contrib/libarchive/tar/bsdtar.c index 1f250b6930a0..0e7216f080c9 100644 --- a/usr.bin/tar/bsdtar.c +++ b/contrib/libarchive/tar/bsdtar.c @@ -169,6 +169,7 @@ main(int argc, char **argv) } #endif + /* Need lafe_progname before calling lafe_warnc. */ if (*argv == NULL) lafe_progname = "bsdtar"; diff --git a/usr.bin/tar/bsdtar.h b/contrib/libarchive/tar/bsdtar.h similarity index 99% rename from usr.bin/tar/bsdtar.h rename to contrib/libarchive/tar/bsdtar.h index ede96d9fb9f3..df9e6a5096f9 100644 --- a/usr.bin/tar/bsdtar.h +++ b/contrib/libarchive/tar/bsdtar.h @@ -141,6 +141,7 @@ enum { OPTION_VERSION }; + int bsdtar_getopt(struct bsdtar *); void do_chdir(struct bsdtar *); int edit_pathname(struct bsdtar *, struct archive_entry *); diff --git a/usr.bin/tar/bsdtar_platform.h b/contrib/libarchive/tar/bsdtar_platform.h similarity index 100% rename from usr.bin/tar/bsdtar_platform.h rename to contrib/libarchive/tar/bsdtar_platform.h diff --git a/usr.bin/tar/cmdline.c b/contrib/libarchive/tar/cmdline.c similarity index 100% rename from usr.bin/tar/cmdline.c rename to contrib/libarchive/tar/cmdline.c diff --git a/usr.bin/tar/getdate.c b/contrib/libarchive/tar/getdate.c similarity index 100% rename from usr.bin/tar/getdate.c rename to contrib/libarchive/tar/getdate.c diff --git a/usr.bin/tar/read.c b/contrib/libarchive/tar/read.c similarity index 100% rename from usr.bin/tar/read.c rename to contrib/libarchive/tar/read.c diff --git a/usr.bin/tar/subst.c b/contrib/libarchive/tar/subst.c similarity index 100% rename from usr.bin/tar/subst.c rename to contrib/libarchive/tar/subst.c diff --git a/usr.bin/tar/test/main.c b/contrib/libarchive/tar/test/main.c similarity index 100% rename from usr.bin/tar/test/main.c rename to contrib/libarchive/tar/test/main.c diff --git a/usr.bin/tar/test/test.h b/contrib/libarchive/tar/test/test.h similarity index 100% rename from usr.bin/tar/test/test.h rename to contrib/libarchive/tar/test/test.h diff --git a/usr.bin/tar/test/test_0.c b/contrib/libarchive/tar/test/test_0.c similarity index 100% rename from usr.bin/tar/test/test_0.c rename to contrib/libarchive/tar/test/test_0.c diff --git a/usr.bin/tar/test/test_basic.c b/contrib/libarchive/tar/test/test_basic.c similarity index 100% rename from usr.bin/tar/test/test_basic.c rename to contrib/libarchive/tar/test/test_basic.c diff --git a/usr.bin/tar/test/test_copy.c b/contrib/libarchive/tar/test/test_copy.c similarity index 100% rename from usr.bin/tar/test/test_copy.c rename to contrib/libarchive/tar/test/test_copy.c diff --git a/usr.bin/tar/test/test_empty_mtree.c b/contrib/libarchive/tar/test/test_empty_mtree.c similarity index 100% rename from usr.bin/tar/test/test_empty_mtree.c rename to contrib/libarchive/tar/test/test_empty_mtree.c diff --git a/usr.bin/tar/test/test_getdate.c b/contrib/libarchive/tar/test/test_getdate.c similarity index 100% rename from usr.bin/tar/test/test_getdate.c rename to contrib/libarchive/tar/test/test_getdate.c diff --git a/usr.bin/tar/test/test_help.c b/contrib/libarchive/tar/test/test_help.c similarity index 100% rename from usr.bin/tar/test/test_help.c rename to contrib/libarchive/tar/test/test_help.c diff --git a/usr.bin/tar/test/test_option_T_upper.c b/contrib/libarchive/tar/test/test_option_T_upper.c similarity index 100% rename from usr.bin/tar/test/test_option_T_upper.c rename to contrib/libarchive/tar/test/test_option_T_upper.c diff --git a/usr.bin/tar/test/test_option_q.c b/contrib/libarchive/tar/test/test_option_q.c similarity index 100% rename from usr.bin/tar/test/test_option_q.c rename to contrib/libarchive/tar/test/test_option_q.c diff --git a/usr.bin/tar/test/test_option_r.c b/contrib/libarchive/tar/test/test_option_r.c similarity index 100% rename from usr.bin/tar/test/test_option_r.c rename to contrib/libarchive/tar/test/test_option_r.c diff --git a/usr.bin/tar/test/test_option_s.c b/contrib/libarchive/tar/test/test_option_s.c similarity index 98% rename from usr.bin/tar/test/test_option_s.c rename to contrib/libarchive/tar/test/test_option_s.c index 94d634514944..a2525a09ec00 100644 --- a/usr.bin/tar/test/test_option_s.c +++ b/contrib/libarchive/tar/test/test_option_s.c @@ -44,7 +44,7 @@ DEFINE_TEST(test_option_s) { struct stat st; - /* Create a sample file heirarchy. */ + /* Create a sample file hierarchy. */ assertMakeDir("in", 0755); assertMakeDir("in/d1", 0755); assertEqualInt(0, mkfile("in/d1/foo", "foo")); diff --git a/usr.bin/tar/test/test_patterns.c b/contrib/libarchive/tar/test/test_patterns.c similarity index 100% rename from usr.bin/tar/test/test_patterns.c rename to contrib/libarchive/tar/test/test_patterns.c diff --git a/usr.bin/tar/test/test_patterns_2.tar.uu b/contrib/libarchive/tar/test/test_patterns_2.tar.uu similarity index 99% rename from usr.bin/tar/test/test_patterns_2.tar.uu rename to contrib/libarchive/tar/test/test_patterns_2.tar.uu index f3a0a7507ab3..eba2daece095 100644 --- a/usr.bin/tar/test/test_patterns_2.tar.uu +++ b/contrib/libarchive/tar/test/test_patterns_2.tar.uu @@ -1,5 +1,3 @@ -$FreeBSD$ - begin 644 test_patterns_2.tar M+W1M<"]F;V\O```````````````````````````````````````````````` M```````````````````````````````````````````````````````````` diff --git a/usr.bin/tar/test/test_patterns_3.tar.uu b/contrib/libarchive/tar/test/test_patterns_3.tar.uu similarity index 99% rename from usr.bin/tar/test/test_patterns_3.tar.uu rename to contrib/libarchive/tar/test/test_patterns_3.tar.uu index 8a19f80967b0..de60b8dc8e10 100644 --- a/usr.bin/tar/test/test_patterns_3.tar.uu +++ b/contrib/libarchive/tar/test/test_patterns_3.tar.uu @@ -1,5 +1,3 @@ -$FreeBSD$ - begin 644 test_patterns_3.tar M+W1M<"]F;V\O8F%R+P`````````````````````````````````````````` M```````````````````````````````````````````````````````````` diff --git a/usr.bin/tar/test/test_patterns_4.tar.uu b/contrib/libarchive/tar/test/test_patterns_4.tar.uu similarity index 99% rename from usr.bin/tar/test/test_patterns_4.tar.uu rename to contrib/libarchive/tar/test/test_patterns_4.tar.uu index 3fc62e49dc37..240af208934d 100644 --- a/usr.bin/tar/test/test_patterns_4.tar.uu +++ b/contrib/libarchive/tar/test/test_patterns_4.tar.uu @@ -1,5 +1,3 @@ -$FreeBSD$ - begin 644 test_patterns_4.tar M+V9I;&4P,0`````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` diff --git a/usr.bin/tar/test/test_stdio.c b/contrib/libarchive/tar/test/test_stdio.c similarity index 100% rename from usr.bin/tar/test/test_stdio.c rename to contrib/libarchive/tar/test/test_stdio.c diff --git a/usr.bin/tar/test/test_strip_components.c b/contrib/libarchive/tar/test/test_strip_components.c similarity index 100% rename from usr.bin/tar/test/test_strip_components.c rename to contrib/libarchive/tar/test/test_strip_components.c diff --git a/usr.bin/tar/test/test_symlink_dir.c b/contrib/libarchive/tar/test/test_symlink_dir.c similarity index 100% rename from usr.bin/tar/test/test_symlink_dir.c rename to contrib/libarchive/tar/test/test_symlink_dir.c diff --git a/usr.bin/tar/test/test_version.c b/contrib/libarchive/tar/test/test_version.c similarity index 100% rename from usr.bin/tar/test/test_version.c rename to contrib/libarchive/tar/test/test_version.c diff --git a/usr.bin/tar/tree.c b/contrib/libarchive/tar/tree.c similarity index 55% rename from usr.bin/tar/tree.c rename to contrib/libarchive/tar/tree.c index 58e9febd3d8e..ff8e60f7e072 100644 --- a/usr.bin/tar/tree.c +++ b/contrib/libarchive/tar/tree.c @@ -18,6 +18,7 @@ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @@ -48,6 +49,9 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_STAT_H #include #endif +#ifdef HAVE_DIRECT_H +#include +#endif #ifdef HAVE_DIRENT_H #include #endif @@ -66,6 +70,9 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_UNISTD_H #include #endif +#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) +#include +#endif #include "tree.h" @@ -76,27 +83,38 @@ __FBSDID("$FreeBSD$"); */ struct tree_entry { + int depth; struct tree_entry *next; struct tree_entry *parent; char *name; size_t dirname_length; dev_t dev; ino_t ino; + int flags; + /* How to return back to the parent of a symlink. */ #ifdef HAVE_FCHDIR - int fd; + int symlink_parent_fd; #elif defined(_WIN32) && !defined(__CYGWIN__) - char *fullpath; + char *symlink_parent_path; #else #error fchdir function required. #endif - int flags; }; /* Definitions for tree_entry.flags bitmap. */ #define isDir 1 /* This entry is a regular directory. */ #define isDirLink 2 /* This entry is a symbolic link to a directory. */ -#define needsPreVisit 4 /* This entry needs to be previsited. */ -#define needsPostVisit 8 /* This entry needs to be postvisited. */ +#define needsFirstVisit 4 /* This is an initial entry. */ +#define needsDescent 8 /* This entry needs to be previsited. */ +#define needsOpen 16 /* This is a directory that needs to be opened. */ +#define needsAscent 32 /* This entry needs to be postvisited. */ + +/* + * On Windows, "first visit" is handled as a pattern to be handed to + * _findfirst(). This is consistent with Windows conventions that + * file patterns are handled within the application. On Posix, + * "first visit" is just returned to the client. + */ /* * Local data for this package. @@ -104,21 +122,28 @@ struct tree_entry { struct tree { struct tree_entry *stack; struct tree_entry *current; +#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) + HANDLE d; + BY_HANDLE_FILE_INFORMATION fileInfo; +#define INVALID_DIR_HANDLE INVALID_HANDLE_VALUE + WIN32_FIND_DATA _findData; + WIN32_FIND_DATA *findData; +#else DIR *d; -#ifdef HAVE_FCHDIR - int initialDirFd; -#elif defined(_WIN32) && !defined(__CYGWIN__) - char *initialDir; +#define INVALID_DIR_HANDLE NULL + struct dirent *de; #endif int flags; int visit_type; int tree_errno; /* Error code from last failed operation. */ + /* Dynamically-sized buffer for holding path */ char *buff; - const char *basename; size_t buff_length; - size_t path_length; - size_t dirname_length; + + const char *basename; /* Last path element */ + size_t dirname_length; /* Leading dir length */ + size_t path_length; /* Total path length */ int depth; int openCount; @@ -129,10 +154,17 @@ struct tree { }; /* Definitions for tree.flags bitmap. */ -#define needsReturn 8 /* Marks first entry as not having been returned yet. */ -#define hasStat 16 /* The st entry is set. */ -#define hasLstat 32 /* The lst entry is set. */ +#define hasStat 16 /* The st entry is valid. */ +#define hasLstat 32 /* The lst entry is valid. */ +#define hasFileInfo 64 /* The Windows fileInfo entry is valid. */ +#if defined(_WIN32) && !defined(__CYGWIN__) +static int +tree_dir_next_windows(struct tree *t, const char *pattern); +#else +static int +tree_dir_next_posix(struct tree *t); +#endif #ifdef HAVE_DIRENT_D_NAMLEN /* BSD extension; avoids need for a strlen() call. */ @@ -141,25 +173,32 @@ struct tree { #define D_NAMELEN(dp) (strlen((dp)->d_name)) #endif -#if 0 #include void tree_dump(struct tree *t, FILE *out) { + char buff[300]; struct tree_entry *te; fprintf(out, "\tdepth: %d\n", t->depth); fprintf(out, "\tbuff: %s\n", t->buff); - fprintf(out, "\tpwd: "); fflush(stdout); system("pwd"); - fprintf(out, "\taccess: %s\n", t->basename); + fprintf(out, "\tpwd: %s\n", getcwd(buff, sizeof(buff))); + fprintf(out, "\tbasename: %s\n", t->basename); fprintf(out, "\tstack:\n"); for (te = t->stack; te != NULL; te = te->next) { - fprintf(out, "\t\tte->name: %s%s%s\n", te->name, - te->flags & needsPreVisit ? "" : " *", - t->current == te ? " (current)" : ""); + fprintf(out, "\t\t%s%d:\"%s\" %s%s%s%s%s%s\n", + t->current == te ? "*" : " ", + te->depth, + te->name, + te->flags & needsFirstVisit ? "V" : "", + te->flags & needsDescent ? "D" : "", + te->flags & needsOpen ? "O" : "", + te->flags & needsAscent ? "A" : "", + te->flags & isDirLink ? "L" : "", + (t->current == te && t->d) ? "+" : "" + ); } } -#endif /* * Add a directory path to the current stack. @@ -172,24 +211,29 @@ tree_push(struct tree *t, const char *path) te = malloc(sizeof(*te)); memset(te, 0, sizeof(*te)); te->next = t->stack; + te->parent = t->current; + if (te->parent) + te->depth = te->parent->depth + 1; t->stack = te; #ifdef HAVE_FCHDIR - te->fd = -1; -#elif defined(_WIN32) && !defined(__CYGWIN__) - te->fullpath = NULL; -#endif + te->symlink_parent_fd = -1; te->name = strdup(path); - te->flags = needsPreVisit | needsPostVisit; +#elif defined(_WIN32) && !defined(__CYGWIN__) + te->symlink_parent_path = NULL; + te->name = strdup(path); +#endif + te->flags = needsDescent | needsOpen | needsAscent; te->dirname_length = t->dirname_length; } /* - * Append a name to the current path. + * Append a name to the current dir path. */ static void tree_append(struct tree *t, const char *name, size_t name_length) { char *p; + size_t size_needed; if (t->buff != NULL) t->buff[t->dirname_length] = '\0'; @@ -198,12 +242,16 @@ tree_append(struct tree *t, const char *name, size_t name_length) name_length--; /* Resize pathname buffer as needed. */ - while (name_length + 1 + t->dirname_length >= t->buff_length) { - t->buff_length *= 2; + size_needed = name_length + 1 + t->dirname_length; + if (t->buff_length < size_needed) { if (t->buff_length < 1024) t->buff_length = 1024; + while (t->buff_length < size_needed) + t->buff_length *= 2; t->buff = realloc(t->buff, t->buff_length); } + if (t->buff == NULL) + abort(); p = t->buff + t->dirname_length; t->path_length = t->dirname_length + name_length; /* Add a separating '/' if it's needed. */ @@ -211,7 +259,11 @@ tree_append(struct tree *t, const char *name, size_t name_length) *p++ = '/'; t->path_length ++; } +#if HAVE_STRNCPY_S + strncpy_s(p, t->buff_length - (p - t->buff), name, name_length); +#else strncpy(p, name, name_length); +#endif p[name_length] = '\0'; t->basename = p; } @@ -222,24 +274,55 @@ tree_append(struct tree *t, const char *name, size_t name_length) struct tree * tree_open(const char *path) { +#ifdef HAVE_FCHDIR struct tree *t; t = malloc(sizeof(*t)); memset(t, 0, sizeof(*t)); - tree_append(t, path, strlen(path)); -#ifdef HAVE_FCHDIR - t->initialDirFd = open(".", O_RDONLY); -#elif defined(_WIN32) && !defined(__CYGWIN__) - t->initialDir = getcwd(NULL, 0); -#endif - /* - * During most of the traversal, items are set up and then - * returned immediately from tree_next(). That doesn't work - * for the very first entry, so we set a flag for this special - * case. - */ - t->flags = needsReturn; + /* First item is set up a lot like a symlink traversal. */ + tree_push(t, path); + t->stack->flags = needsFirstVisit | isDirLink | needsAscent; + t->stack->symlink_parent_fd = open(".", O_RDONLY); + t->openCount++; + t->d = INVALID_DIR_HANDLE; return (t); +#elif defined(_WIN32) && !defined(__CYGWIN__) + struct tree *t; + char *cwd = _getcwd(NULL, 0); + char *pathname = strdup(path), *p, *base; + + if (pathname == NULL) + abort(); + for (p = pathname; *p != '\0'; ++p) { + if (*p == '\\') + *p = '/'; + } + base = pathname; + + t = malloc(sizeof(*t)); + memset(t, 0, sizeof(*t)); + /* First item is set up a lot like a symlink traversal. */ + /* printf("Looking for wildcard in %s\n", path); */ + /* TODO: wildcard detection here screws up on \\?\c:\ UNC names */ + if (strchr(base, '*') || strchr(base, '?')) { + // It has a wildcard in it... + // Separate the last element. + p = strrchr(base, '/'); + if (p != NULL) { + *p = '\0'; + chdir(base); + tree_append(t, base, p - base); + t->dirname_length = t->path_length; + base = p + 1; + } + } + tree_push(t, base); + free(pathname); + t->stack->flags = needsFirstVisit | isDirLink | needsAscent; + t->stack->symlink_parent_path = cwd; + t->d = INVALID_DIR_HANDLE; + return (t); +#endif } /* @@ -255,22 +338,26 @@ tree_ascend(struct tree *t) t->depth--; if (te->flags & isDirLink) { #ifdef HAVE_FCHDIR - if (fchdir(te->fd) != 0) { + if (fchdir(te->symlink_parent_fd) != 0) { t->tree_errno = errno; r = TREE_ERROR_FATAL; } - close(te->fd); + close(te->symlink_parent_fd); #elif defined(_WIN32) && !defined(__CYGWIN__) - if (chdir(te->fullpath) != 0) { + if (SetCurrentDirectory(te->symlink_parent_path) == 0) { t->tree_errno = errno; r = TREE_ERROR_FATAL; } - free(te->fullpath); - te->fullpath = NULL; + free(te->symlink_parent_path); + te->symlink_parent_path = NULL; #endif t->openCount--; } else { +#if defined(_WIN32) && !defined(__CYGWIN__) + if (SetCurrentDirectory("..") == 0) { +#else if (chdir("..") != 0) { +#endif t->tree_errno = errno; r = TREE_ERROR_FATAL; } @@ -286,16 +373,18 @@ tree_pop(struct tree *t) { struct tree_entry *te; - t->buff[t->dirname_length] = '\0'; + if (t->buff) + t->buff[t->dirname_length] = '\0'; if (t->stack == t->current && t->current != NULL) t->current = t->current->parent; te = t->stack; t->stack = te->next; t->dirname_length = te->dirname_length; - t->basename = t->buff + t->dirname_length; - /* Special case: starting dir doesn't skip leading '/'. */ - if (t->dirname_length > 0) - t->basename++; + if (t->buff) { + t->basename = t->buff + t->dirname_length; + while (t->basename[0] == '/') + t->basename++; + } free(te->name); free(te); } @@ -306,101 +395,179 @@ tree_pop(struct tree *t) int tree_next(struct tree *t) { - struct dirent *de = NULL; int r; /* If we're called again after a fatal error, that's an API * violation. Just crash now. */ if (t->visit_type == TREE_ERROR_FATAL) { - const char *msg = "Unable to continue traversing" - " directory hierarchy after a fatal error."; - write(2, msg, strlen(msg)); - *(int *)0 = 1; /* Deliberate SEGV; NULL pointer dereference. */ - exit(1); /* In case the SEGV didn't work. */ - } - - /* Handle the startup case by returning the initial entry. */ - if (t->flags & needsReturn) { - t->flags &= ~needsReturn; - return (t->visit_type = TREE_REGULAR); + fprintf(stderr, "Unable to continue traversing" + " directory hierarchy after a fatal error."); + abort(); } while (t->stack != NULL) { /* If there's an open dir, get the next entry from there. */ - while (t->d != NULL) { - de = readdir(t->d); - if (de == NULL) { - closedir(t->d); - t->d = NULL; - } else if (de->d_name[0] == '.' - && de->d_name[1] == '\0') { - /* Skip '.' */ - } else if (de->d_name[0] == '.' - && de->d_name[1] == '.' - && de->d_name[2] == '\0') { - /* Skip '..' */ - } else { - /* - * Append the path to the current path - * and return it. - */ - tree_append(t, de->d_name, D_NAMELEN(de)); - t->flags &= ~hasLstat; - t->flags &= ~hasStat; - return (t->visit_type = TREE_REGULAR); - } + if (t->d != INVALID_DIR_HANDLE) { +#if defined(_WIN32) && !defined(__CYGWIN__) + r = tree_dir_next_windows(t, NULL); +#else + r = tree_dir_next_posix(t); +#endif + if (r == 0) + continue; + return (r); } - /* If the current dir needs to be visited, set it up. */ - if (t->stack->flags & needsPreVisit) { + if (t->stack->flags & needsFirstVisit) { +#if defined(_WIN32) && !defined(__CYGWIN__) + char *d = t->stack->name; + t->stack->flags &= ~needsFirstVisit; + if (strchr(d, '*') || strchr(d, '?')) { + r = tree_dir_next_windows(t, d); + if (r == 0) + continue; + return (r); + } + // Not a pattern, handle it as-is... +#endif + /* Top stack item needs a regular visit. */ t->current = t->stack; tree_append(t, t->stack->name, strlen(t->stack->name)); - t->stack->flags &= ~needsPreVisit; + //t->dirname_length = t->path_length; + //tree_pop(t); + t->stack->flags &= ~needsFirstVisit; + return (t->visit_type = TREE_REGULAR); + } else if (t->stack->flags & needsDescent) { + /* Top stack item is dir to descend into. */ + t->current = t->stack; + tree_append(t, t->stack->name, strlen(t->stack->name)); + t->stack->flags &= ~needsDescent; /* If it is a link, set up fd for the ascent. */ if (t->stack->flags & isDirLink) { #ifdef HAVE_FCHDIR - t->stack->fd = open(".", O_RDONLY); -#elif defined(_WIN32) && !defined(__CYGWIN__) - t->stack->fullpath = getcwd(NULL, 0); -#endif + t->stack->symlink_parent_fd = open(".", O_RDONLY); t->openCount++; if (t->openCount > t->maxOpenCount) t->maxOpenCount = t->openCount; +#elif defined(_WIN32) && !defined(__CYGWIN__) + t->stack->symlink_parent_path = _getcwd(NULL, 0); +#endif } t->dirname_length = t->path_length; - if (chdir(t->stack->name) != 0) { +#if defined(_WIN32) && !defined(__CYGWIN__) + if (t->path_length == 259 || !SetCurrentDirectory(t->stack->name) != 0) +#else + if (chdir(t->stack->name) != 0) +#endif + { /* chdir() failed; return error */ tree_pop(t); t->tree_errno = errno; return (t->visit_type = TREE_ERROR_DIR); } t->depth++; - t->d = opendir("."); - if (t->d == NULL) { + return (t->visit_type = TREE_POSTDESCENT); + } else if (t->stack->flags & needsOpen) { + t->stack->flags &= ~needsOpen; +#if defined(_WIN32) && !defined(__CYGWIN__) + r = tree_dir_next_windows(t, "*"); +#else + r = tree_dir_next_posix(t); +#endif + if (r == 0) + continue; + return (r); + } else if (t->stack->flags & needsAscent) { + /* Top stack item is dir and we're done with it. */ + r = tree_ascend(t); + tree_pop(t); + t->visit_type = r != 0 ? r : TREE_POSTASCENT; + return (t->visit_type); + } else { + /* Top item on stack is dead. */ + tree_pop(t); + t->flags &= ~hasLstat; + t->flags &= ~hasStat; + } + } + return (t->visit_type = 0); +} + +#if defined(_WIN32) && !defined(__CYGWIN__) +static int +tree_dir_next_windows(struct tree *t, const char *pattern) +{ + const char *name; + size_t namelen; + int r; + + for (;;) { + if (pattern != NULL) { + t->d = FindFirstFile(pattern, &t->_findData); + if (t->d == INVALID_DIR_HANDLE) { r = tree_ascend(t); /* Undo "chdir" */ tree_pop(t); t->tree_errno = errno; t->visit_type = r != 0 ? r : TREE_ERROR_DIR; return (t->visit_type); } - t->flags &= ~hasLstat; - t->flags &= ~hasStat; - t->basename = "."; - return (t->visit_type = TREE_POSTDESCENT); + t->findData = &t->_findData; + pattern = NULL; + } else if (!FindNextFile(t->d, &t->_findData)) { + FindClose(t->d); + t->d = INVALID_DIR_HANDLE; + t->findData = NULL; + return (0); } + name = t->findData->cFileName; + namelen = strlen(name); + t->flags &= ~hasLstat; + t->flags &= ~hasStat; + if (name[0] == '.' && name[1] == '\0') + continue; + if (name[0] == '.' && name[1] == '.' && name[2] == '\0') + continue; + tree_append(t, name, namelen); + return (t->visit_type = TREE_REGULAR); + } +} +#else +static int +tree_dir_next_posix(struct tree *t) +{ + int r; + const char *name; + size_t namelen; - /* We've done everything necessary for the top stack entry. */ - if (t->stack->flags & needsPostVisit) { - r = tree_ascend(t); + if (t->d == NULL) { + if ((t->d = opendir(".")) == NULL) { + r = tree_ascend(t); /* Undo "chdir" */ tree_pop(t); - t->flags &= ~hasLstat; - t->flags &= ~hasStat; - t->visit_type = r != 0 ? r : TREE_POSTASCENT; + t->tree_errno = errno; + t->visit_type = r != 0 ? r : TREE_ERROR_DIR; return (t->visit_type); } } - return (t->visit_type = 0); + for (;;) { + t->de = readdir(t->d); + if (t->de == NULL) { + closedir(t->d); + t->d = INVALID_DIR_HANDLE; + return (0); + } + name = t->de->d_name; + namelen = D_NAMELEN(t->de); + t->flags &= ~hasLstat; + t->flags &= ~hasStat; + if (name[0] == '.' && name[1] == '\0') + continue; + if (name[0] == '.' && name[1] == '.' && name[2] == '\0') + continue; + tree_append(t, name, namelen); + return (t->visit_type = TREE_REGULAR); + } } +#endif /* * Return error code. @@ -437,25 +604,51 @@ const struct stat * tree_current_stat(struct tree *t) { if (!(t->flags & hasStat)) { - if (stat(t->basename, &t->st) != 0) + if (stat(tree_current_access_path(t), &t->st) != 0) return NULL; t->flags |= hasStat; } return (&t->st); } +#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) +const BY_HANDLE_FILE_INFORMATION * +tree_current_file_information(struct tree *t) +{ + if (!(t->flags & hasFileInfo)) { + HANDLE h = CreateFile(tree_current_access_path(t), + 0, 0, NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, + NULL); + if (h == INVALID_HANDLE_VALUE) + return NULL; + if (!GetFileInformationByHandle(h, &t->fileInfo)) { + CloseHandle(h); + return NULL; + } + CloseHandle(h); + t->flags |= hasFileInfo; + } + return (&t->fileInfo); +} +#endif /* * Get the lstat() data for the entry just returned from tree_next(). */ const struct stat * tree_current_lstat(struct tree *t) { +#if defined(_WIN32) && !defined(__CYGWIN__) + return (tree_current_stat(t)); +#else if (!(t->flags & hasLstat)) { - if (lstat(t->basename, &t->lst) != 0) + if (lstat(tree_current_access_path(t), &t->lst) != 0) return NULL; t->flags |= hasLstat; } return (&t->lst); +#endif } /* @@ -464,8 +657,14 @@ tree_current_lstat(struct tree *t) int tree_current_is_dir(struct tree *t) { +#if defined(_WIN32) && !defined(__CYGWIN__) + if (t->findData) + return (t->findData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + if (tree_current_file_information(t)) + return (t->fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + return (0); +#else const struct stat *st; - /* * If we already have lstat() info, then try some * cheap tests to determine if this is a dir. @@ -490,6 +689,7 @@ tree_current_is_dir(struct tree *t) return 0; /* Use the definitive test. Hopefully this is cached. */ return (S_ISDIR(st->st_mode)); +#endif } /* @@ -500,6 +700,11 @@ tree_current_is_dir(struct tree *t) int tree_current_is_physical_dir(struct tree *t) { +#if defined(_WIN32) && !defined(__CYGWIN__) + if (tree_current_is_physical_link(t)) + return (0); + return (tree_current_is_dir(t)); +#else const struct stat *st; /* @@ -523,6 +728,7 @@ tree_current_is_physical_dir(struct tree *t) return 0; /* Use the definitive test. Hopefully this is cached. */ return (S_ISDIR(st->st_mode)); +#endif } /* @@ -531,10 +737,21 @@ tree_current_is_physical_dir(struct tree *t) int tree_current_is_physical_link(struct tree *t) { +#if defined(_WIN32) && !defined(__CYGWIN__) +#ifndef IO_REPARSE_TAG_SYMLINK +/* Old SDKs do not provide IO_REPARSE_TAG_SYMLINK */ +#define IO_REPARSE_TAG_SYMLINK 0xA000000CL +#endif + if (t->findData) + return ((t->findData->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) + && (t->findData->dwReserved0 == IO_REPARSE_TAG_SYMLINK)); + return (0); +#else const struct stat *st = tree_current_lstat(t); if (st == NULL) return 0; return (S_ISLNK(st->st_mode)); +#endif } /* @@ -582,21 +799,23 @@ tree_close(struct tree *t) /* Release anything remaining in the stack. */ while (t->stack != NULL) tree_pop(t); - if (t->buff) - free(t->buff); - /* chdir() back to where we started. */ + free(t->buff); + /* TODO: Ensure that premature close() resets cwd */ +#if 0 #ifdef HAVE_FCHDIR if (t->initialDirFd >= 0) { - fchdir(t->initialDirFd); + int s = fchdir(t->initialDirFd); + (void)s; /* UNUSED */ close(t->initialDirFd); t->initialDirFd = -1; } #elif defined(_WIN32) && !defined(__CYGWIN__) if (t->initialDir != NULL) { - chdir(t->initialDir); + SetCurrentDir(t->initialDir); free(t->initialDir); t->initialDir = NULL; } +#endif #endif free(t); } diff --git a/usr.bin/tar/tree.h b/contrib/libarchive/tar/tree.h similarity index 100% rename from usr.bin/tar/tree.h rename to contrib/libarchive/tar/tree.h diff --git a/usr.bin/tar/util.c b/contrib/libarchive/tar/util.c similarity index 100% rename from usr.bin/tar/util.c rename to contrib/libarchive/tar/util.c diff --git a/usr.bin/tar/write.c b/contrib/libarchive/tar/write.c similarity index 99% rename from usr.bin/tar/write.c rename to contrib/libarchive/tar/write.c index a0a9b753d108..1105159d2c73 100644 --- a/usr.bin/tar/write.c +++ b/contrib/libarchive/tar/write.c @@ -592,7 +592,7 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina) struct archive_entry *in_entry; int e; - while (0 == archive_read_next_header(ina, &in_entry)) { + while (ARCHIVE_OK == (e = archive_read_next_header(ina, &in_entry))) { if (!new_enough(bsdtar, archive_entry_pathname(in_entry), archive_entry_stat(in_entry))) continue; @@ -630,8 +630,7 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina) fprintf(stderr, "\n"); } - /* Note: If we got here, we saw no write errors, so return success. */ - return (0); + return (e == ARCHIVE_EOF ? ARCHIVE_OK : e); } /* Helper function to copy data between archives. */ diff --git a/contrib/libc++/FREEBSD-upgrade b/contrib/libc++/FREEBSD-upgrade new file mode 100644 index 000000000000..5e9f60ac73fa --- /dev/null +++ b/contrib/libc++/FREEBSD-upgrade @@ -0,0 +1,8 @@ +$FreeBSD$ + +The FreeBSD copy of libc++. This contains everything from the include and +source directories upstream, with the exception of the support/win32 directory, +which is only required for building on Windows (FreeBSD is not Windows). + +To update, bring in anything new in source or include that is not +platform-dependent (unless the platform in question is FreeBSD, obviously). diff --git a/contrib/libc++/include/__bit_reference b/contrib/libc++/include/__bit_reference new file mode 100644 index 000000000000..46213332c3e8 --- /dev/null +++ b/contrib/libc++/include/__bit_reference @@ -0,0 +1,1247 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___BIT_REFERENCE +#define _LIBCPP___BIT_REFERENCE + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template class __bit_iterator; +template class __bit_const_reference; + +template +struct __has_storage_type +{ + static const bool value = false; +}; + +template ::value> +class __bit_reference +{ + typedef typename _C::__storage_type __storage_type; + typedef typename _C::__storage_pointer __storage_pointer; + + __storage_pointer __seg_; + __storage_type __mask_; + +#if defined(__clang__) + friend typename _C::__self; +#else + friend class _C::__self; +#endif + friend class __bit_const_reference<_C>; + friend class __bit_iterator<_C, false>; +public: + _LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT + {return static_cast(*__seg_ & __mask_);} + _LIBCPP_INLINE_VISIBILITY bool operator ~() const _NOEXCEPT + {return !static_cast(*this);} + + _LIBCPP_INLINE_VISIBILITY + __bit_reference& operator=(bool __x) _NOEXCEPT + { + if (__x) + *__seg_ |= __mask_; + else + *__seg_ &= ~__mask_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT + {return operator=(static_cast(__x));} + + _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {*__seg_ ^= __mask_;} + _LIBCPP_INLINE_VISIBILITY __bit_iterator<_C, false> operator&() const _NOEXCEPT + {return __bit_iterator<_C, false>(__seg_, static_cast(__ctz(__mask_)));} +private: + _LIBCPP_INLINE_VISIBILITY + __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT + : __seg_(__s), __mask_(__m) {} +}; + +template +class __bit_reference<_C, false> +{ +}; + +template +_LIBCPP_INLINE_VISIBILITY inline +void +swap(__bit_reference<_C> __x, __bit_reference<_D> __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +_LIBCPP_INLINE_VISIBILITY inline +void +swap(__bit_reference<_C> __x, bool& __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +_LIBCPP_INLINE_VISIBILITY inline +void +swap(bool& __x, __bit_reference<_C> __y) _NOEXCEPT +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template +class __bit_const_reference +{ + typedef typename _C::__storage_type __storage_type; + typedef typename _C::__const_storage_pointer __storage_pointer; + + __storage_pointer __seg_; + __storage_type __mask_; + +#if defined(__clang__) + friend typename _C::__self; +#else + friend class _C::__self; +#endif + friend class __bit_iterator<_C, true>; +public: + _LIBCPP_INLINE_VISIBILITY + __bit_const_reference(const __bit_reference<_C>& __x) _NOEXCEPT + : __seg_(__x.__seg_), __mask_(__x.__mask_) {} + + _LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT + {return static_cast(*__seg_ & __mask_);} + + _LIBCPP_INLINE_VISIBILITY __bit_iterator<_C, true> operator&() const _NOEXCEPT + {return __bit_iterator<_C, true>(__seg_, static_cast(__ctz(__mask_)));} +private: + _LIBCPP_INLINE_VISIBILITY + __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT + : __seg_(__s), __mask_(__m) {} + + __bit_const_reference& operator=(const __bit_const_reference& __x); +}; + +// find + +template +__bit_iterator<_C, false> +__find_bool_true(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast(_VSTD::__ctz(__b))); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + if (*__first.__seg_) + return _It(__first.__seg_, static_cast(_VSTD::__ctz(*__first.__seg_))); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast(_VSTD::__ctz(__b))); + } + return _It(__first.__seg_, static_cast(__n)); +} + +template +__bit_iterator<_C, false> +__find_bool_false(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = ~(*__first.__seg_ & __m); + if (__b) + return _It(__first.__seg_, static_cast(_VSTD::__ctz(__b))); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + { + __storage_type __b = ~*__first.__seg_; + if (__b) + return _It(__first.__seg_, static_cast(_VSTD::__ctz(__b))); + } + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = ~(*__first.__seg_ & __m); + if (__b) + return _It(__first.__seg_, static_cast(_VSTD::__ctz(__b))); + } + return _It(__first.__seg_, static_cast(__n)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_C, false> +find(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, const _Tp& __value_) +{ + if (static_cast(__value_)) + return __find_bool_true(__first, static_cast(__last - __first)); + return __find_bool_false(__first, static_cast(__last - __first)); +} + +// count + +template +typename __bit_iterator<_C, false>::difference_type +__count_bool_true(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage_type; + typedef typename _It::difference_type difference_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + difference_type __r = 0; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __r = _VSTD::__pop_count(*__first.__seg_ & __m); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + __r += _VSTD::__pop_count(*__first.__seg_); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __r += _VSTD::__pop_count(*__first.__seg_ & __m); + } + return __r; +} + +template +typename __bit_iterator<_C, false>::difference_type +__count_bool_false(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage_type; + typedef typename _It::difference_type difference_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + difference_type __r = 0; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __r = _VSTD::__pop_count(~(*__first.__seg_ & __m)); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + __r += _VSTD::__pop_count(~*__first.__seg_); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __r += _VSTD::__pop_count(~(*__first.__seg_ & __m)); + } + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __bit_iterator<_C, false>::difference_type +count(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, const _Tp& __value_) +{ + if (static_cast(__value_)) + return __count_bool_true(__first, static_cast(__last - __first)); + return __count_bool_false(__first, static_cast(__last - __first)); +} + +// fill_n + +template +void +__fill_n_false(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + *__first.__seg_ &= ~__m; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + __storage_type __nw = __n / __bits_per_word; + _VSTD::memset(__first.__seg_, 0, __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last partial word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__first.__seg_ &= ~__m; + } +} + +template +void +__fill_n_true(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _VSTD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + *__first.__seg_ |= __m; + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + __storage_type __nw = __n / __bits_per_word; + _VSTD::memset(__first.__seg_, -1, __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last partial word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__first.__seg_ |= __m; + } +} + +template +_LIBCPP_INLINE_VISIBILITY inline +void +fill_n(__bit_iterator<_C, false> __first, typename _C::size_type __n, bool __value_) +{ + if (__n > 0) + { + if (__value_) + __fill_n_true(__first, __n); + else + __fill_n_false(__first, __n); + } +} + +// fill + +template +inline _LIBCPP_INLINE_VISIBILITY +void +fill(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, bool __value_) +{ + _VSTD::fill_n(__first, static_cast(__last - __first), __value_); +} + +// copy + +template +__bit_iterator<_C, false> +__copy_aligned(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, + __bit_iterator<_C, false> __result) +{ + typedef __bit_iterator<_C, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + static const unsigned __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first.__ctz_; + difference_type __dn = _VSTD::min(static_cast(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + __storage_type __b = *__first.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + __storage_type __nw = __n / __bits_per_word; + _VSTD::memmove(__result.__seg_, __first.__seg_, __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + __result.__seg_ += __nw; + // do last word + if (__n > 0) + { + __first.__seg_ += __nw; + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast(__n); + } + } + return __result; +} + +template +__bit_iterator<_C, false> +__copy_unaligned(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, + __bit_iterator<_C, false> __result) +{ + typedef __bit_iterator<_C, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + static const unsigned __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first.__ctz_; + difference_type __dn = _VSTD::min(static_cast(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __first.__ctz_) + *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_); + else + *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_); + __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn); + __result.__ctz_ = static_cast(__dn); + } + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __m = ~__storage_type(0) << __result.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) + { + __storage_type __b = *__first.__seg_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << __result.__ctz_; + ++__result.__seg_; + *__result.__seg_ &= __m; + *__result.__seg_ |= __b >> __clz_r; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + __storage_type __dn = _VSTD::min(__n, static_cast(__clz_r)); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << __result.__ctz_; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> __dn; + __result.__ctz_ = static_cast(__n); + } + } + } + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_C, false> +copy(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, __bit_iterator<_C, false> __result) +{ + if (__first.__ctz_ == __result.__ctz_) + return __copy_aligned(__first, __last, __result); + return __copy_unaligned(__first, __last, __result); +} + +// copy_backward + +template +__bit_iterator<_C, false> +__copy_backward_aligned(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, + __bit_iterator<_C, false> __result) +{ + typedef __bit_iterator<_C, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + static const unsigned __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__last.__ctz_ != 0) + { + difference_type __dn = _VSTD::min(static_cast(__last.__ctz_), __n); + __n -= __dn; + unsigned __clz = __bits_per_word - __last.__ctz_; + __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz); + __storage_type __b = *__last.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + // __last.__ctz_ = 0 + } + // __last.__ctz_ == 0 || __n == 0 + // __result.__ctz_ == 0 || __n == 0 + // do middle words + __storage_type __nw = __n / __bits_per_word; + __result.__seg_ -= __nw; + __last.__seg_ -= __nw; + _VSTD::memmove(__result.__seg_, __last.__seg_, __nw * sizeof(__storage_type)); + __n -= __nw * __bits_per_word; + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) << (__bits_per_word - __n); + __storage_type __b = *--__last.__seg_ & __m; + *--__result.__seg_ &= ~__m; + *__result.__seg_ |= __b; + __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); + } + } + return __result; +} + +template +__bit_iterator<_C, false> +__copy_backward_unaligned(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, + __bit_iterator<_C, false> __result) +{ + typedef __bit_iterator<_C, _IsConst> _In; + typedef typename _In::difference_type difference_type; + typedef typename _In::__storage_type __storage_type; + static const unsigned __bits_per_word = _In::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__last.__ctz_ != 0) + { + difference_type __dn = _VSTD::min(static_cast(__last.__ctz_), __n); + __n -= __dn; + unsigned __clz_l = __bits_per_word - __last.__ctz_; + __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l); + __storage_type __b = *__last.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _VSTD::min(__dn, static_cast(__result.__ctz_)); + if (__ddn > 0) + { + __m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r); + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __last.__ctz_) + *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); + else + *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_); + __result.__ctz_ = static_cast(((-__ddn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + } + if (__dn > 0) + { + // __result.__ctz_ == 0 + --__result.__seg_; + __result.__ctz_ = static_cast(-__dn & (__bits_per_word - 1)); + __m = ~__storage_type(0) << __result.__ctz_; + *__result.__seg_ &= ~__m; + __last.__ctz_ -= __dn + __ddn; + *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); + } + // __last.__ctz_ = 0 + } + // __last.__ctz_ == 0 || __n == 0 + // __result.__ctz_ != 0 || __n == 0 + // do middle words + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __m = ~__storage_type(0) >> __clz_r; + for (; __n >= __bits_per_word; __n -= __bits_per_word) + { + __storage_type __b = *--__last.__seg_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> __clz_r; + *--__result.__seg_ &= __m; + *__result.__seg_ |= __b << __result.__ctz_; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) << (__bits_per_word - __n); + __storage_type __b = *--__last.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __dn = _VSTD::min(__n, static_cast(__result.__ctz_)); + __m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r); + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_); + __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + // __result.__ctz_ == 0 + --__result.__seg_; + __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); + __m = ~__storage_type(0) << __result.__ctz_; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn)); + } + } + } + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_C, false> +copy_backward(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, __bit_iterator<_C, false> __result) +{ + if (__last.__ctz_ == __result.__ctz_) + return __copy_backward_aligned(__first, __last, __result); + return __copy_backward_unaligned(__first, __last, __result); +} + +// move + +template +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_C, false> +move(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, __bit_iterator<_C, false> __result) +{ + return _VSTD::copy(__first, __last, __result); +} + +// move_backward + +template +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_C, false> +move_backward(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, __bit_iterator<_C, false> __result) +{ + return _VSTD::copy(__first, __last, __result); +} + +// swap_ranges + +template +__bit_iterator<__C2, false> +__swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, + __bit_iterator<__C2, false> __result) +{ + typedef __bit_iterator<__C1, false> _I1; + typedef typename _I1::difference_type difference_type; + typedef typename _I1::__storage_type __storage_type; + static const unsigned __bits_per_word = _I1::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first.__ctz_; + difference_type __dn = _VSTD::min(static_cast(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1; + *__first.__seg_ |= __b2; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_) + swap(*__first.__seg_, *__result.__seg_); + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1; + *__first.__seg_ |= __b2; + __result.__ctz_ = static_cast(__n); + } + } + return __result; +} + +template +__bit_iterator<__C2, false> +__swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, + __bit_iterator<__C2, false> __result) +{ + typedef __bit_iterator<__C1, false> _I1; + typedef typename _I1::difference_type difference_type; + typedef typename _I1::__storage_type __storage_type; + static const unsigned __bits_per_word = _I1::__bits_per_word; + difference_type __n = __last - __first; + if (__n > 0) + { + // do first word + if (__first.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first.__ctz_; + difference_type __dn = _VSTD::min(static_cast(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + if (__result.__ctz_ > __first.__ctz_) + { + unsigned __s = __result.__ctz_ - __first.__ctz_; + *__result.__seg_ |= __b1 << __s; + *__first.__seg_ |= __b2 >> __s; + } + else + { + unsigned __s = __first.__ctz_ - __result.__ctz_; + *__result.__seg_ |= __b1 >> __s; + *__first.__seg_ |= __b2 << __s; + } + __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + unsigned __s = __first.__ctz_ + __ddn; + *__result.__seg_ |= __b1 >> __s; + *__first.__seg_ |= __b2 << __s; + __result.__ctz_ = static_cast(__dn); + } + ++__first.__seg_; + // __first.__ctz_ = 0; + } + // __first.__ctz_ == 0; + // do middle words + __storage_type __m = ~__storage_type(0) << __result.__ctz_; + unsigned __clz_r = __bits_per_word - __result.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) + { + __storage_type __b1 = *__first.__seg_; + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 << __result.__ctz_; + *__first.__seg_ = __b2 >> __result.__ctz_; + ++__result.__seg_; + __b2 = *__result.__seg_ & ~__m; + *__result.__seg_ &= __m; + *__result.__seg_ |= __b1 >> __clz_r; + *__first.__seg_ |= __b2 << __clz_r; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b1 = *__first.__seg_ & __m; + *__first.__seg_ &= ~__m; + __storage_type __dn = _VSTD::min<__storage_type>(__n, __clz_r); + __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + __storage_type __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 << __result.__ctz_; + *__first.__seg_ |= __b2 >> __result.__ctz_; + __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; + __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __b2 = *__result.__seg_ & __m; + *__result.__seg_ &= ~__m; + *__result.__seg_ |= __b1 >> __dn; + *__first.__seg_ |= __b2 << __dn; + __result.__ctz_ = static_cast(__n); + } + } + } + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<__C2, false> +swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __last1, + __bit_iterator<__C2, false> __first2) +{ + if (__first1.__ctz_ == __first2.__ctz_) + return __swap_ranges_aligned(__first1, __last1, __first2); + return __swap_ranges_unaligned(__first1, __last1, __first2); +} + +// rotate + +template +struct __bit_array +{ + typedef typename _C::difference_type difference_type; + typedef typename _C::__storage_type __storage_type; + typedef typename _C::iterator iterator; + static const unsigned __bits_per_word = _C::__bits_per_word; + static const unsigned _N = 4; + + difference_type __size_; + __storage_type __word_[_N]; + + _LIBCPP_INLINE_VISIBILITY static difference_type capacity() + {return static_cast(_N * __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {} + _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(__word_, 0);} + _LIBCPP_INLINE_VISIBILITY iterator end() {return iterator(__word_ + __size_ / __bits_per_word, + static_cast(__size_ % __bits_per_word));} +}; + +template +__bit_iterator<_C, false> +rotate(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __middle, __bit_iterator<_C, false> __last) +{ + typedef __bit_iterator<_C, false> _I1; + typedef typename _I1::difference_type difference_type; + typedef typename _I1::__storage_type __storage_type; + static const unsigned __bits_per_word = _I1::__bits_per_word; + difference_type __d1 = __middle - __first; + difference_type __d2 = __last - __middle; + _I1 __r = __first + __d2; + while (__d1 != 0 && __d2 != 0) + { + if (__d1 <= __d2) + { + if (__d1 <= __bit_array<_C>::capacity()) + { + __bit_array<_C> __b(__d1); + _VSTD::copy(__first, __middle, __b.begin()); + _VSTD::copy(__b.begin(), __b.end(), _VSTD::copy(__middle, __last, __first)); + break; + } + else + { + __bit_iterator<_C, false> __mp = _VSTD::swap_ranges(__first, __middle, __middle); + __first = __middle; + __middle = __mp; + __d2 -= __d1; + } + } + else + { + if (__d2 <= __bit_array<_C>::capacity()) + { + __bit_array<_C> __b(__d2); + _VSTD::copy(__middle, __last, __b.begin()); + _VSTD::copy_backward(__b.begin(), __b.end(), _VSTD::copy_backward(__first, __middle, __last)); + break; + } + else + { + __bit_iterator<_C, false> __mp = __first + __d2; + _VSTD::swap_ranges(__first, __mp, __middle); + __first = __mp; + __d1 -= __d2; + } + } + } + return __r; +} + +// equal + +template +bool +__equal_unaligned(__bit_iterator<_C, true> __first1, __bit_iterator<_C, true> __last1, + __bit_iterator<_C, true> __first2) +{ + typedef __bit_iterator<_C, true> _It; + typedef typename _It::difference_type difference_type; + typedef typename _It::__storage_type __storage_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + difference_type __n = __last1 - __first1; + if (__n > 0) + { + // do first word + if (__first1.__ctz_ != 0) + { + unsigned __clz_f = __bits_per_word - __first1.__ctz_; + difference_type __dn = _VSTD::min(static_cast(__clz_f), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first1.__seg_ & __m; + unsigned __clz_r = __bits_per_word - __first2.__ctz_; + __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r); + __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); + if (__first2.__ctz_ > __first1.__ctz_) + if ((*__first2.__seg_ & __m) != (__b << (__first2.__ctz_ - __first1.__ctz_))) + return false; + else + if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ - __first2.__ctz_))) + return false; + __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word; + __first2.__ctz_ = static_cast((__ddn + __first2.__ctz_) % __bits_per_word); + __dn -= __ddn; + if (__dn > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __dn); + if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ + __ddn))) + return false; + __first2.__ctz_ = static_cast(__dn); + } + ++__first1.__seg_; + // __first1.__ctz_ = 0; + } + // __first1.__ctz_ == 0; + // do middle words + unsigned __clz_r = __bits_per_word - __first2.__ctz_; + __storage_type __m = ~__storage_type(0) << __first2.__ctz_; + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_) + { + __storage_type __b = *__first1.__seg_; + if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) + return false; + ++__first2.__seg_; + if ((*__first2.__seg_ & ~__m) != (__b >> __clz_r)) + return false; + } + // do last word + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first1.__seg_ & __m; + __storage_type __dn = _VSTD::min(__n, static_cast(__clz_r)); + __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); + if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) + return false; + __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word; + __first2.__ctz_ = static_cast((__dn + __first2.__ctz_) % __bits_per_word); + __n -= __dn; + if (__n > 0) + { + __m = ~__storage_type(0) >> (__bits_per_word - __n); + if ((*__first2.__seg_ & __m) != (__b >> __dn)) + return false; + } + } + } + return true; +} + +template +bool +__equal_aligned(__bit_iterator<_C, true> __first1, __bit_iterator<_C, true> __last1, + __bit_iterator<_C, true> __first2) +{ + typedef __bit_iterator<_C, true> _It; + typedef typename _It::difference_type difference_type; + typedef typename _It::__storage_type __storage_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + difference_type __n = __last1 - __first1; + if (__n > 0) + { + // do first word + if (__first1.__ctz_ != 0) + { + unsigned __clz = __bits_per_word - __first1.__ctz_; + difference_type __dn = _VSTD::min(static_cast(__clz), __n); + __n -= __dn; + __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); + if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) + return false; + ++__first2.__seg_; + ++__first1.__seg_; + // __first1.__ctz_ = 0; + // __first2.__ctz_ = 0; + } + // __first1.__ctz_ == 0; + // __first2.__ctz_ == 0; + // do middle words + for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_) + if (*__first2.__seg_ != *__first1.__seg_) + return false; + // do last word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) + return false; + } + } + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +equal(__bit_iterator<_C, _IC1> __first1, __bit_iterator<_C, _IC1> __last1, __bit_iterator<_C, _IC2> __first2) +{ + if (__first1.__ctz_ == __first2.__ctz_) + return __equal_aligned(__first1, __last1, __first2); + return __equal_unaligned(__first1, __last1, __first2); +} + +template +class __bit_iterator +{ +public: + typedef typename _C::difference_type difference_type; + typedef bool value_type; + typedef __bit_iterator pointer; + typedef typename conditional<_IsConst, __bit_const_reference<_C>, __bit_reference<_C> >::type reference; + typedef random_access_iterator_tag iterator_category; + +private: + typedef typename _C::__storage_type __storage_type; + typedef typename conditional<_IsConst, typename _C::__const_storage_pointer, + typename _C::__storage_pointer>::type __storage_pointer; + static const unsigned __bits_per_word = _C::__bits_per_word; + + __storage_pointer __seg_; + unsigned __ctz_; + +public: + _LIBCPP_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + __bit_iterator(const __bit_iterator<_C, false>& __it) _NOEXCEPT + : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT + {return reference(__seg_, __storage_type(1) << __ctz_);} + + _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator++() + { + if (__ctz_ != __bits_per_word-1) + ++__ctz_; + else + { + __ctz_ = 0; + ++__seg_; + } + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator operator++(int) + { + __bit_iterator __tmp = *this; + ++(*this); + return __tmp; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator--() + { + if (__ctz_ != 0) + --__ctz_; + else + { + __ctz_ = __bits_per_word - 1; + --__seg_; + } + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator operator--(int) + { + __bit_iterator __tmp = *this; + --(*this); + return __tmp; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator+=(difference_type __n) + { + if (__n >= 0) + __seg_ += (__n + __ctz_) / __bits_per_word; + else + __seg_ += static_cast(__n - __bits_per_word + __ctz_ + 1) + / static_cast(__bits_per_word); + __n &= (__bits_per_word - 1); + __ctz_ = static_cast((__n + __ctz_) % __bits_per_word); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator-=(difference_type __n) + { + return *this += -__n; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator operator+(difference_type __n) const + { + __bit_iterator __t(*this); + __t += __n; + return __t; + } + + _LIBCPP_INLINE_VISIBILITY __bit_iterator operator-(difference_type __n) const + { + __bit_iterator __t(*this); + __t -= __n; + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) {return __it + __n;} + + _LIBCPP_INLINE_VISIBILITY + friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y) + {return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_;} + + _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const {return *(*this + __n);} + + _LIBCPP_INLINE_VISIBILITY friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y) + {return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;} + + _LIBCPP_INLINE_VISIBILITY friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__x == __y);} + + _LIBCPP_INLINE_VISIBILITY friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y) + {return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_);} + + _LIBCPP_INLINE_VISIBILITY friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y) + {return __y < __x;} + + _LIBCPP_INLINE_VISIBILITY friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__y < __x);} + + _LIBCPP_INLINE_VISIBILITY friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y) + {return !(__x < __y);} + +private: + _LIBCPP_INLINE_VISIBILITY + __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT + : __seg_(__s), __ctz_(__ctz) {} + +#if defined(__clang__) + friend typename _C::__self; +#else + friend class _C::__self; +#endif + friend class __bit_reference<_C>; + friend class __bit_const_reference<_C>; + friend class __bit_iterator<_C, true>; + template friend struct __bit_array; + template friend void __fill_n_false(__bit_iterator<_D, false> __first, typename _D::size_type __n); + template friend void __fill_n_true(__bit_iterator<_D, false> __first, typename _D::size_type __n); + template friend __bit_iterator<_D, false> __copy_aligned(__bit_iterator<_D, _IC> __first, + __bit_iterator<_D, _IC> __last, + __bit_iterator<_D, false> __result); + template friend __bit_iterator<_D, false> __copy_unaligned(__bit_iterator<_D, _IC> __first, + __bit_iterator<_D, _IC> __last, + __bit_iterator<_D, false> __result); + template friend __bit_iterator<_D, false> copy(__bit_iterator<_D, _IC> __first, + __bit_iterator<_D, _IC> __last, + __bit_iterator<_D, false> __result); + template friend __bit_iterator<_D, false> __copy_backward_aligned(__bit_iterator<_D, _IC> __first, + __bit_iterator<_D, _IC> __last, + __bit_iterator<_D, false> __result); + template friend __bit_iterator<_D, false> __copy_backward_unaligned(__bit_iterator<_D, _IC> __first, + __bit_iterator<_D, _IC> __last, + __bit_iterator<_D, false> __result); + template friend __bit_iterator<_D, false> copy_backward(__bit_iterator<_D, _IC> __first, + __bit_iterator<_D, _IC> __last, + __bit_iterator<_D, false> __result); + template friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template friend __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>, + __bit_iterator<__C1, false>, + __bit_iterator<__C2, false>); + template friend __bit_iterator<_D, false> rotate(__bit_iterator<_D, false>, + __bit_iterator<_D, false>, + __bit_iterator<_D, false>); + template friend bool __equal_aligned(__bit_iterator<_D, true>, + __bit_iterator<_D, true>, + __bit_iterator<_D, true>); + template friend bool __equal_unaligned(__bit_iterator<_D, true>, + __bit_iterator<_D, true>, + __bit_iterator<_D, true>); + template friend bool equal(__bit_iterator<_D, _IC1>, + __bit_iterator<_D, _IC1>, + __bit_iterator<_D, _IC2>); + template friend __bit_iterator<_D, false> __find_bool_true(__bit_iterator<_D, false>, + typename _D::size_type); + template friend __bit_iterator<_D, false> __find_bool_false(__bit_iterator<_D, false>, + typename _D::size_type); +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___BIT_REFERENCE diff --git a/contrib/libc++/include/__config b/contrib/libc++/include/__config new file mode 100644 index 000000000000..0f6c77dd9817 --- /dev/null +++ b/contrib/libc++/include/__config @@ -0,0 +1,405 @@ +// -*- C++ -*- +//===--------------------------- __config ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CONFIG +#define _LIBCPP_CONFIG + +#if !_MSC_VER // explicit macro necessary because it is only defined below in this file +#pragma GCC system_header +#endif + +#define _LIBCPP_VERSION 1001 + +#define _LIBCPP_ABI_VERSION 1 + +#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y +#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) + +#define _LIBCPP_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION) + +#ifdef __LITTLE_ENDIAN__ +#if __LITTLE_ENDIAN__ +#define _LIBCPP_LITTLE_ENDIAN 1 +#define _LIBCPP_BIG_ENDIAN 0 +#endif // __LITTLE_ENDIAN__ +#endif // __LITTLE_ENDIAN__ + +#ifdef __BIG_ENDIAN__ +#if __BIG_ENDIAN__ +#define _LIBCPP_LITTLE_ENDIAN 0 +#define _LIBCPP_BIG_ENDIAN 1 +#endif // __BIG_ENDIAN__ +#endif // __BIG_ENDIAN__ + +#ifdef __FreeBSD__ +# include +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN 0 +# else // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 0 +# define _LIBCPP_BIG_ENDIAN 1 +# endif // _BYTE_ORDER == _LITTLE_ENDIAN +#endif // __FreeBSD__ + +#ifdef _WIN32 +# define _LIBCPP_LITTLE_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN 0 +// Compiler intrinsics (GCC or MSVC) +# if (defined(_MSC_VER) && _MSC_VER >= 1400) || (__GNUC__ >= 4 && __GNUC_MINOR__ > 3) +# define _LIBCP_HAS_IS_BASE_OF +# endif +#endif // _WIN32 + +#if !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN) +# include +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN 0 +# elif __BYTE_ORDER == __BIG_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 0 +# define _LIBCPP_BIG_ENDIAN 1 +# else // __BYTE_ORDER == __BIG_ENDIAN +# error unable to determine endian +# endif +#endif // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN) + +#if _WIN32 + +// only really useful for a DLL +#ifdef _LIBCPP_DLL // this should be a compiler builtin define ideally... +# ifdef cxx_EXPORTS +# define _LIBCPP_HIDDEN +# define _LIBCPP_VISIBLE __declspec(dllexport) +# else +# define _LIBCPP_HIDDEN +# define _LIBCPP_VISIBLE __declspec(dllimport) +# endif +#else +# define _LIBCPP_HIDDEN +# define _LIBCPP_VISIBLE +#endif + +#ifndef _LIBCPP_INLINE_VISIBILITY +# if _MSC_VER +# define _LIBCPP_INLINE_VISIBILITY __forceinline +# else // MinGW GCC and Clang +# define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__always_inline__)) +# endif +#endif + +#ifndef _LIBCPP_EXCEPTION_ABI +#define _LIBCPP_EXCEPTION_ABI _LIBCPP_VISIBLE +#endif + +#ifndef _LIBCPP_ALWAYS_INLINE +# if _MSC_VER +# define _LIBCPP_ALWAYS_INLINE __forceinline +# endif +#endif + +#endif // _WIN32 + +#ifndef _LIBCPP_HIDDEN +#define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden"))) +#endif + +#ifndef _LIBCPP_VISIBLE +#define _LIBCPP_VISIBLE __attribute__ ((__visibility__("default"))) +#endif + +#ifndef _LIBCPP_INLINE_VISIBILITY +#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__)) +#endif + +#ifndef _LIBCPP_EXCEPTION_ABI +#define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default"))) +#endif + +#ifndef _LIBCPP_CANTTHROW +#define _LIBCPP_CANTTHROW __attribute__ ((__nothrow__)) +#endif + +#ifndef _LIBCPP_ALWAYS_INLINE +#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__visibility__("hidden"), __always_inline__)) +#endif + +#if defined(__clang__) + +#if __has_feature(cxx_alignas) +# define _ALIGNAS(x) alignas(x) +#else +# define _ALIGNAS(x) __attribute__((__aligned__(x))) +#endif + +#if !__has_feature(cxx_alias_templates) +#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#endif + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +#ifdef __linux__ +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#else +typedef __char16_t char16_t; +typedef __char32_t char32_t; +#endif +#endif + +#if !(__has_feature(cxx_exceptions)) +#define _LIBCPP_NO_EXCEPTIONS +#endif + +#if !(__has_feature(cxx_rtti)) +#define _LIBCPP_NO_RTTI +#endif + +#if !(__has_feature(cxx_decltype)) +#define _LIBCPP_HAS_NO_DECLTYPE +#endif + +#if __has_feature(cxx_attributes) +# define _ATTRIBUTE(x) [[x]] +#else +# define _ATTRIBUTE(x) __attribute__ ((x)) +#endif + +#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + +#if !(__has_feature(cxx_deleted_functions)) +#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#endif // !(__has_feature(cxx_deleted_functions)) + +#if !(__has_feature(cxx_lambdas)) +#define _LIBCPP_HAS_NO_LAMBDAS +#endif + +#if !(__has_feature(cxx_nullptr)) +#define _LIBCPP_HAS_NO_NULLPTR +#endif + +#if !(__has_feature(cxx_rvalue_references)) +#define _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif + +#if !(__has_feature(cxx_static_assert)) +#define _LIBCPP_HAS_NO_STATIC_ASSERT +#endif + +#if !(__has_feature(cxx_auto_type)) +#define _LIBCPP_HAS_NO_AUTO_TYPE +#endif + +#if !(__has_feature(cxx_access_control_sfinae)) || !__has_feature(cxx_trailing_return) +#define _LIBCPP_HAS_NO_ADVANCED_SFINAE +#endif + +#if !(__has_feature(cxx_variadic_templates)) +#define _LIBCPP_HAS_NO_VARIADICS +#endif + +#if !(__has_feature(cxx_trailing_return)) +#define _LIBCPP_HAS_NO_TRAILING_RETURN +#endif + +#if !(__has_feature(cxx_generalized_initializers)) +#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif + +#if __has_feature(is_base_of) +# define _LIBCP_HAS_IS_BASE_OF +#endif + +// Objective-C++ features (opt-in) +#if __has_feature(objc_arc) +#define _LIBCPP_HAS_OBJC_ARC +#endif + +#if __has_feature(objc_arc_weak) +#define _LIBCPP_HAS_OBJC_ARC_WEAK +#endif + +#if !(__has_feature(cxx_constexpr)) +#define _LIBCPP_HAS_NO_CONSTEXPR +#endif + +#if (__has_feature(cxx_noexcept)) +# define _NOEXCEPT noexcept +# define _NOEXCEPT_(x) noexcept(x) +#else +# define _NOEXCEPT throw() +# define _NOEXCEPT_(x) +#endif + +#if __has_feature(underlying_type) +# define _LIBCXX_UNDERLYING_TYPE(T) __underlying_type(T) +#endif + +// Inline namespaces are available in Clang regardless of C++ dialect. +#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {inline namespace _LIBCPP_NAMESPACE { +#define _LIBCPP_END_NAMESPACE_STD } } +#define _VSTD std::_LIBCPP_NAMESPACE + +namespace std { + inline namespace _LIBCPP_NAMESPACE { + } +} + +#elif defined(__GNUC__) + +#define _ALIGNAS(x) __attribute__((__aligned__(x))) + +#define _ATTRIBUTE(x) __attribute__((x)) + +#if !__EXCEPTIONS +#define _LIBCPP_NO_EXCEPTIONS +#endif + +#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#define _LIBCPP_HAS_NO_CONSTEXPR + +#define _NOEXCEPT throw() +#define _NOEXCEPT_(x) + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ + +#define _LIBCPP_HAS_NO_ADVANCED_SFINAE +#define _LIBCPP_HAS_NO_DECLTYPE +#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#define _LIBCPP_HAS_NO_NULLPTR +#define _LIBCPP_HAS_NO_STATIC_ASSERT +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#define _LIBCPP_HAS_NO_VARIADICS +#define _LIBCPP_HAS_NO_RVALUE_REFERENCES +#define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS + +#else // __GXX_EXPERIMENTAL_CXX0X__ + +#define _LIBCPP_HAS_NO_TRAILING_RETURN +#define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS + +#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 3) +#define _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif + +#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 3) +#define _LIBCPP_HAS_NO_STATIC_ASSERT +#endif + +#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 4) +#define _LIBCPP_HAS_NO_ADVANCED_SFINAE +#define _LIBCPP_HAS_NO_DECLTYPE +#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#define _LIBCPP_HAS_NO_VARIADICS +#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 4) + +#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 6) +#define _LIBCPP_HAS_NO_NULLPTR +#endif + +#endif // __GXX_EXPERIMENTAL_CXX0X__ + +#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { namespace _LIBCPP_NAMESPACE { +#define _LIBCPP_END_NAMESPACE_STD } } +#define _VSTD std::_LIBCPP_NAMESPACE + +namespace std { +namespace _LIBCPP_NAMESPACE { +} +using namespace _LIBCPP_NAMESPACE __attribute__((__strong__)); +} + +#elif defined(_MSC_VER) + +#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +#define _LIBCPP_HAS_NO_CONSTEXPR +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#define __alignof__ __alignof +#define _ATTRIBUTE __declspec +#define _ALIGNAS(x) __declspec(align(x)) +#define _LIBCPP_HAS_NO_VARIADICS + +#define _NOEXCEPT throw() +#define _NOEXCEPT_(x) + +#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { +#define _LIBCPP_END_NAMESPACE_STD } +#define _VSTD std + +namespace std { +} + +#endif // __clang__ || __GNUC___ || _MSC_VER + +#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS +typedef unsigned short char16_t; +typedef unsigned int char32_t; +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +#ifdef _LIBCPP_HAS_NO_STATIC_ASSERT + +template struct __static_assert_test; +template <> struct __static_assert_test {}; +template struct __static_assert_check {}; +#define static_assert(__b, __m) \ + typedef __static_assert_check)> \ + _LIBCPP_CONCAT(__t, __LINE__) + +#endif // _LIBCPP_HAS_NO_STATIC_ASSERT + +#ifdef _LIBCPP_HAS_NO_DECLTYPE +#define decltype(x) __typeof__(x) +#endif + +#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#define constexpr const +#endif + +#ifndef __has_feature +#define __has_feature(__x) 0 +#endif + +#if __APPLE__ || __FreeBSD__ || _WIN32 +#define _LIBCPP_LOCALE__L_EXTENSIONS 1 +#endif +#if __FreeBSD__ +#define _DECLARE_C99_LDBL_MATH 1 +#endif + +#if __APPLE__ || __FreeBSD__ +#define _LIBCPP_HAS_DEFAULTRUNELOCALE +#endif + +#if __APPLE__ || __FreeBSD__ +#define _LIBCPP_WCTYPE_IS_MASK +#endif + +#ifdef _LIBCPP_DEBUG2 +# if _LIBCPP_DEBUG2 == 0 +# define _LIBCPP_DEBUG_LEVEL 1 +# elif _LIBCPP_DEBUG2 == 1 +# define _LIBCPP_DEBUG_LEVEL 2 +# else +# error Supported values for _LIBCPP_DEBUG2 are 0 and 1 +# endif +#endif + +#ifdef _LIBCPP_DEBUG2 +# include <__debug> +#else +# define _LIBCPP_ASSERT(x, m) ((void)0) +#endif + +#endif // _LIBCPP_CONFIG diff --git a/contrib/libc++/include/__debug b/contrib/libc++/include/__debug new file mode 100644 index 000000000000..cd3bd3a98d98 --- /dev/null +++ b/contrib/libc++/include/__debug @@ -0,0 +1,191 @@ +// -*- C++ -*- +//===--------------------------- __debug ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_DEBUG_H +#define _LIBCPP_DEBUG_H + +#if _LIBCPP_DEBUG_LEVEL >= 1 + +# include +# include +# include +# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort())) + +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 2 + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_VISIBLE __c_node; + +struct _LIBCPP_VISIBLE __i_node +{ + void* __i_; + __i_node* __next_; + __c_node* __c_; + + __i_node(const __i_node&) = delete; + __i_node& operator=(const __i_node&) = delete; + _LIBCPP_INLINE_VISIBILITY + __i_node(void* __i, __i_node* __next, __c_node* __c) + : __i_(__i), __next_(__next), __c_(__c) {} + ~__i_node(); +}; + +struct _LIBCPP_VISIBLE __c_node +{ + void* __c_; + __c_node* __next_; + __i_node** beg_; + __i_node** end_; + __i_node** cap_; + + __c_node(const __c_node&) = delete; + __c_node& operator=(const __c_node&) = delete; + _LIBCPP_INLINE_VISIBILITY + __c_node(void* __c, __c_node* __next) + : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} + virtual ~__c_node(); + + virtual bool __dereferenceable(const void*) const = 0; + virtual bool __decrementable(const void*) const = 0; + virtual bool __addable(const void*, ptrdiff_t) const = 0; + virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; + + void __add(__i_node* __i); + _LIBCPP_HIDDEN void __remove(__i_node* __i); +}; + +template +struct _C_node + : public __c_node +{ + _C_node(void* __c, __c_node* __n) + : __c_node(__c, __n) {} + + virtual bool __dereferenceable(const void*) const; + virtual bool __decrementable(const void*) const; + virtual bool __addable(const void*, ptrdiff_t) const; + virtual bool __subscriptable(const void*, ptrdiff_t) const; +}; + +template +bool +_C_node<_Cont>::__dereferenceable(const void* __i) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _C = static_cast<_Cont*>(__c_); + return _C->__dereferenceable(__j); +} + +template +bool +_C_node<_Cont>::__decrementable(const void* __i) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _C = static_cast<_Cont*>(__c_); + return _C->__decrementable(__j); +} + +template +bool +_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _C = static_cast<_Cont*>(__c_); + return _C->__addable(__j, __n); +} + +template +bool +_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const +{ + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _C = static_cast<_Cont*>(__c_); + return _C->__subscriptable(__j, __n); +} + +class _LIBCPP_VISIBLE __libcpp_db +{ + __c_node** __cbeg_; + __c_node** __cend_; + size_t __csz_; + __i_node** __ibeg_; + __i_node** __iend_; + size_t __isz_; + + __libcpp_db(); +public: + __libcpp_db(const __libcpp_db&) = delete; + __libcpp_db& operator=(const __libcpp_db&) = delete; + ~__libcpp_db(); + + class __db_c_iterator; + class __db_c_const_iterator; + class __db_i_iterator; + class __db_i_const_iterator; + + __db_c_const_iterator __c_end() const; + __db_i_const_iterator __i_end() const; + + template + _LIBCPP_INLINE_VISIBILITY + void __insert_c(_Cont* __c) + { + __c_node* __n = __insert_c(static_cast(__c)); + ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_); + } + + void __insert_i(void* __i); + __c_node* __insert_c(void* __c); + void __erase_c(void* __c); + + void __insert_ic(void* __i, const void* __c); + void __iterator_copy(void* __i, const void* __i0); + void __erase_i(void* __i); + + void* __find_c_from_i(void* __i) const; + void __invalidate_all(void* __c); + __c_node* __find_c_and_lock(void* __c) const; + __c_node* __find_c(void* __c) const; + void unlock() const; + + void swap(void* __c1, void* __c2); + + + bool __dereferenceable(const void* __i) const; + bool __decrementable(const void* __i) const; + bool __addable(const void* __i, ptrdiff_t __n) const; + bool __subscriptable(const void* __i, ptrdiff_t __n) const; + bool __comparable(const void* __i, const void* __j) const; +private: + _LIBCPP_HIDDEN + __i_node* __insert_iterator(void* __i); + _LIBCPP_HIDDEN + __i_node* __find_iterator(const void* __i) const; + + friend _LIBCPP_VISIBLE __libcpp_db* __get_db(); +}; + +_LIBCPP_VISIBLE __libcpp_db* __get_db(); +_LIBCPP_VISIBLE const __libcpp_db* __get_const_db(); + + +_LIBCPP_END_NAMESPACE_STD + +#endif + +#endif // _LIBCPP_DEBUG_H + diff --git a/contrib/libc++/include/__functional_03 b/contrib/libc++/include/__functional_03 new file mode 100644 index 000000000000..5d30ce2b7502 --- /dev/null +++ b/contrib/libc++/include/__functional_03 @@ -0,0 +1,2130 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FUNCTIONAL_03 +#define _LIBCPP_FUNCTIONAL_03 + +// manual variadic expansion for + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +template +class __mem_fn + : public __weak_result_type<_Tp> +{ +public: + // types + typedef _Tp type; +private: + type __f_; + +public: + _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} + + // invoke + + typename __invoke_return::type + operator() () + { + return __invoke(__f_); + } + + template + typename __invoke_return0::type + operator() (_A0& __a0) + { + return __invoke(__f_, __a0); + } + + template + typename __invoke_return1::type + operator() (_A0& __a0, _A1& __a1) + { + return __invoke(__f_, __a0, __a1); + } + + template + typename __invoke_return2::type + operator() (_A0& __a0, _A1& __a1, _A2& __a2) + { + return __invoke(__f_, __a0, __a1, __a2); + } +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R _T::*> +mem_fn(_R _T::* __pm) +{ + return __mem_fn<_R _T::*>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)()> +mem_fn(_R (_T::* __pm)()) +{ + return __mem_fn<_R (_T::*)()>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0)> +mem_fn(_R (_T::* __pm)(_A0)) +{ + return __mem_fn<_R (_T::*)(_A0)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0, _A1)> +mem_fn(_R (_T::* __pm)(_A0, _A1)) +{ + return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0, _A1, _A2)> +mem_fn(_R (_T::* __pm)(_A0, _A1, _A2)) +{ + return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)()> +mem_fn(_R (_T::* __pm)() const) +{ + return __mem_fn<_R (_T::*)()>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0)> +mem_fn(_R (_T::* __pm)(_A0) const) +{ + return __mem_fn<_R (_T::*)(_A0)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0, _A1)> +mem_fn(_R (_T::* __pm)(_A0, _A1) const) +{ + return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0, _A1, _A2)> +mem_fn(_R (_T::* __pm)(_A0, _A1, _A2) const) +{ + return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)()> +mem_fn(_R (_T::* __pm)() volatile) +{ + return __mem_fn<_R (_T::*)()>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0)> +mem_fn(_R (_T::* __pm)(_A0) volatile) +{ + return __mem_fn<_R (_T::*)(_A0)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0, _A1)> +mem_fn(_R (_T::* __pm)(_A0, _A1) volatile) +{ + return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0, _A1, _A2)> +mem_fn(_R (_T::* __pm)(_A0, _A1, _A2) volatile) +{ + return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)()> +mem_fn(_R (_T::* __pm)() const volatile) +{ + return __mem_fn<_R (_T::*)()>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0)> +mem_fn(_R (_T::* __pm)(_A0) const volatile) +{ + return __mem_fn<_R (_T::*)(_A0)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0, _A1)> +mem_fn(_R (_T::* __pm)(_A0, _A1) const volatile) +{ + return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_A0, _A1, _A2)> +mem_fn(_R (_T::* __pm)(_A0, _A1, _A2) const volatile) +{ + return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm); +} + +// bad_function_call + +class _LIBCPP_EXCEPTION_ABI bad_function_call + : public exception +{ +}; + +template class _LIBCPP_VISIBLE function; // undefined + +namespace __function +{ + +template +struct __maybe_derive_from_unary_function +{ +}; + +template +struct __maybe_derive_from_unary_function<_R(_A1)> + : public unary_function<_A1, _R> +{ +}; + +template +struct __maybe_derive_from_binary_function +{ +}; + +template +struct __maybe_derive_from_binary_function<_R(_A1, _A2)> + : public binary_function<_A1, _A2, _R> +{ +}; + +template class __base; + +template +class __base<_R()> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _R operator()() = 0; +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCPP_NO_RTTI +}; + +template +class __base<_R(_A0)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _R operator()(_A0) = 0; +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCPP_NO_RTTI +}; + +template +class __base<_R(_A0, _A1)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _R operator()(_A0, _A1) = 0; +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCPP_NO_RTTI +}; + +template +class __base<_R(_A0, _A1, _A2)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + __base() {} + virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _R operator()(_A0, _A1, _A2) = 0; +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const = 0; + virtual const std::type_info& target_type() const = 0; +#endif // _LIBCPP_NO_RTTI +}; + +template class __func; + +template +class __func<_F, _Alloc, _R()> + : public __base<_R()> +{ + __compressed_pair<_F, _Alloc> __f_; +public: + explicit __func(_F __f) : __f_(_VSTD::move(__f)) {} + explicit __func(_F __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} + virtual __base<_R()>* __clone() const; + virtual void __clone(__base<_R()>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _R operator()(); +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCPP_NO_RTTI +}; + +template +__base<_R()>* +__func<_F, _Alloc, _R()>::__clone() const +{ + typedef typename _Alloc::template rebind<__func>::other _A; + _A __a(__f_.second()); + typedef __allocator_destructor<_A> _D; + unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_F, _Alloc, _R()>::__clone(__base<_R()>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template +void +__func<_F, _Alloc, _R()>::destroy() +{ + __f_.~__compressed_pair<_F, _Alloc>(); +} + +template +void +__func<_F, _Alloc, _R()>::destroy_deallocate() +{ + typedef typename _Alloc::template rebind<__func>::other _A; + _A __a(__f_.second()); + __f_.~__compressed_pair<_F, _Alloc>(); + __a.deallocate(this, 1); +} + +template +_R +__func<_F, _Alloc, _R()>::operator()() +{ + return __invoke(__f_.first()); +} + +#ifndef _LIBCPP_NO_RTTI + +template +const void* +__func<_F, _Alloc, _R()>::target(const type_info& __ti) const +{ + if (__ti == typeid(_F)) + return &__f_.first(); + return (const void*)0; +} + +template +const std::type_info& +__func<_F, _Alloc, _R()>::target_type() const +{ + return typeid(_F); +} + +#endif // _LIBCPP_NO_RTTI + +template +class __func<_F, _Alloc, _R(_A0)> + : public __base<_R(_A0)> +{ + __compressed_pair<_F, _Alloc> __f_; +public: + _LIBCPP_INLINE_VISIBILITY explicit __func(_F __f) : __f_(_VSTD::move(__f)) {} + _LIBCPP_INLINE_VISIBILITY explicit __func(_F __f, _Alloc __a) + : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} + virtual __base<_R(_A0)>* __clone() const; + virtual void __clone(__base<_R(_A0)>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _R operator()(_A0); +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCPP_NO_RTTI +}; + +template +__base<_R(_A0)>* +__func<_F, _Alloc, _R(_A0)>::__clone() const +{ + typedef typename _Alloc::template rebind<__func>::other _A; + _A __a(__f_.second()); + typedef __allocator_destructor<_A> _D; + unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_F, _Alloc, _R(_A0)>::__clone(__base<_R(_A0)>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template +void +__func<_F, _Alloc, _R(_A0)>::destroy() +{ + __f_.~__compressed_pair<_F, _Alloc>(); +} + +template +void +__func<_F, _Alloc, _R(_A0)>::destroy_deallocate() +{ + typedef typename _Alloc::template rebind<__func>::other _A; + _A __a(__f_.second()); + __f_.~__compressed_pair<_F, _Alloc>(); + __a.deallocate(this, 1); +} + +template +_R +__func<_F, _Alloc, _R(_A0)>::operator()(_A0 __a0) +{ + return __invoke(__f_.first(), __a0); +} + +#ifndef _LIBCPP_NO_RTTI + +template +const void* +__func<_F, _Alloc, _R(_A0)>::target(const type_info& __ti) const +{ + if (__ti == typeid(_F)) + return &__f_.first(); + return (const void*)0; +} + +template +const std::type_info& +__func<_F, _Alloc, _R(_A0)>::target_type() const +{ + return typeid(_F); +} + +#endif // _LIBCPP_NO_RTTI + +template +class __func<_F, _Alloc, _R(_A0, _A1)> + : public __base<_R(_A0, _A1)> +{ + __compressed_pair<_F, _Alloc> __f_; +public: + _LIBCPP_INLINE_VISIBILITY explicit __func(_F __f) : __f_(_VSTD::move(__f)) {} + _LIBCPP_INLINE_VISIBILITY explicit __func(_F __f, _Alloc __a) + : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} + virtual __base<_R(_A0, _A1)>* __clone() const; + virtual void __clone(__base<_R(_A0, _A1)>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _R operator()(_A0, _A1); +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCPP_NO_RTTI +}; + +template +__base<_R(_A0, _A1)>* +__func<_F, _Alloc, _R(_A0, _A1)>::__clone() const +{ + typedef typename _Alloc::template rebind<__func>::other _A; + _A __a(__f_.second()); + typedef __allocator_destructor<_A> _D; + unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_F, _Alloc, _R(_A0, _A1)>::__clone(__base<_R(_A0, _A1)>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template +void +__func<_F, _Alloc, _R(_A0, _A1)>::destroy() +{ + __f_.~__compressed_pair<_F, _Alloc>(); +} + +template +void +__func<_F, _Alloc, _R(_A0, _A1)>::destroy_deallocate() +{ + typedef typename _Alloc::template rebind<__func>::other _A; + _A __a(__f_.second()); + __f_.~__compressed_pair<_F, _Alloc>(); + __a.deallocate(this, 1); +} + +template +_R +__func<_F, _Alloc, _R(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) +{ + return __invoke(__f_.first(), __a0, __a1); +} + +#ifndef _LIBCPP_NO_RTTI + +template +const void* +__func<_F, _Alloc, _R(_A0, _A1)>::target(const type_info& __ti) const +{ + if (__ti == typeid(_F)) + return &__f_.first(); + return (const void*)0; +} + +template +const std::type_info& +__func<_F, _Alloc, _R(_A0, _A1)>::target_type() const +{ + return typeid(_F); +} + +#endif // _LIBCPP_NO_RTTI + +template +class __func<_F, _Alloc, _R(_A0, _A1, _A2)> + : public __base<_R(_A0, _A1, _A2)> +{ + __compressed_pair<_F, _Alloc> __f_; +public: + _LIBCPP_INLINE_VISIBILITY explicit __func(_F __f) : __f_(_VSTD::move(__f)) {} + _LIBCPP_INLINE_VISIBILITY explicit __func(_F __f, _Alloc __a) + : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} + virtual __base<_R(_A0, _A1, _A2)>* __clone() const; + virtual void __clone(__base<_R(_A0, _A1, _A2)>*) const; + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _R operator()(_A0, _A1, _A2); +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const; + virtual const std::type_info& target_type() const; +#endif // _LIBCPP_NO_RTTI +}; + +template +__base<_R(_A0, _A1, _A2)>* +__func<_F, _Alloc, _R(_A0, _A1, _A2)>::__clone() const +{ + typedef typename _Alloc::template rebind<__func>::other _A; + _A __a(__f_.second()); + typedef __allocator_destructor<_A> _D; + unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_F, _Alloc, _R(_A0, _A1, _A2)>::__clone(__base<_R(_A0, _A1, _A2)>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template +void +__func<_F, _Alloc, _R(_A0, _A1, _A2)>::destroy() +{ + __f_.~__compressed_pair<_F, _Alloc>(); +} + +template +void +__func<_F, _Alloc, _R(_A0, _A1, _A2)>::destroy_deallocate() +{ + typedef typename _Alloc::template rebind<__func>::other _A; + _A __a(__f_.second()); + __f_.~__compressed_pair<_F, _Alloc>(); + __a.deallocate(this, 1); +} + +template +_R +__func<_F, _Alloc, _R(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) +{ + return __invoke(__f_.first(), __a0, __a1, __a2); +} + +#ifndef _LIBCPP_NO_RTTI + +template +const void* +__func<_F, _Alloc, _R(_A0, _A1, _A2)>::target(const type_info& __ti) const +{ + if (__ti == typeid(_F)) + return &__f_.first(); + return (const void*)0; +} + +template +const std::type_info& +__func<_F, _Alloc, _R(_A0, _A1, _A2)>::target_type() const +{ + return typeid(_F); +} + +#endif // _LIBCPP_NO_RTTI + +} // __function + +template +class _LIBCPP_VISIBLE function<_R()> +{ + typedef __function::__base<_R()> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + + template + static bool __not_null(const _F&) {return true;} + template + static bool __not_null(const function<_R()>& __p) {return __p;} +public: + typedef _R result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template + function(_F, + typename enable_if::value>::type* = 0); + + template + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc& __a, _F __f, + typename enable_if::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template + typename enable_if + < + !is_integral<_F>::value, + function& + >::type + operator=(_F); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template + _LIBCPP_INLINE_VISIBILITY + void assign(_F __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2()>&) const;// = delete; + template + bool operator!=(const function<_R2()>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _R operator()() const; + +#ifndef _LIBCPP_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template _T* target(); + template const _T* target() const; +#endif // _LIBCPP_NO_RTTI +}; + +template +function<_R()>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_R()>::function(allocator_arg_t, const _Alloc&, const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_R()>::function(_F __f, + typename enable_if::value>::type*) + : __f_(0) +{ + if (__not_null(__f)) + { + typedef __function::__func<_F, allocator<_F>, _R()> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _A; + _A __a; + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_F>(__a)); + __f_ = __hold.release(); + } + } +} + +template +template +function<_R()>::function(allocator_arg_t, const _Alloc& __a0, _F __f, + typename enable_if::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__not_null(__f)) + { + typedef __function::__func<_F, _Alloc, _R()> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<_FF> +#else + rebind_alloc<_FF>::other +#endif + _A; + _A __a(__a0); + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template +function<_R()>& +function<_R()>::operator=(const function& __f) +{ + function(__f).swap(*this); + return *this; +} + +template +function<_R()>& +function<_R()>::operator=(nullptr_t) +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + __f_ = 0; +} + +template +template +typename enable_if +< + !is_integral<_F>::value, + function<_R()>& +>::type +function<_R()>::operator=(_F __f) +{ + function(_VSTD::move(__f)).swap(*this); + return *this; +} + +template +function<_R()>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template +void +function<_R()>::swap(function& __f) +{ + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template +_R +function<_R()>::operator()() const +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__f_ == 0) + throw bad_function_call(); +#endif // _LIBCPP_NO_EXCEPTIONS + return (*__f_)(); +} + +#ifndef _LIBCPP_NO_RTTI + +template +const std::type_info& +function<_R()>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template +template +_T* +function<_R()>::target() +{ + if (__f_ == 0) + return (_T*)0; + return (_T*)__f_->target(typeid(_T)); +} + +template +template +const _T* +function<_R()>::target() const +{ + if (__f_ == 0) + return (const _T*)0; + return (const _T*)__f_->target(typeid(_T)); +} + +#endif // _LIBCPP_NO_RTTI + +template +class _LIBCPP_VISIBLE function<_R(_A0)> + : public unary_function<_A0, _R> +{ + typedef __function::__base<_R(_A0)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(const _F&) {return true;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (*__p)(_B0)) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)()) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)() const) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)() volatile) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)() const volatile) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(const function<_R(_B0)>& __p) {return __p;} +public: + typedef _R result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template + function(_F, + typename enable_if::value>::type* = 0); + + template + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc& __a, _F __f, + typename enable_if::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template + typename enable_if + < + !is_integral<_F>::value, + function& + >::type + operator=(_F); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template + _LIBCPP_INLINE_VISIBILITY + void assign(_F __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2(_B0)>&) const;// = delete; + template + bool operator!=(const function<_R2(_B0)>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _R operator()(_A0) const; + +#ifndef _LIBCPP_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template _T* target(); + template const _T* target() const; +#endif // _LIBCPP_NO_RTTI +}; + +template +function<_R(_A0)>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_R(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_R(_A0)>::function(_F __f, + typename enable_if::value>::type*) + : __f_(0) +{ + if (__not_null(__f)) + { + typedef __function::__func<_F, allocator<_F>, _R(_A0)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _A; + _A __a; + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_F>(__a)); + __f_ = __hold.release(); + } + } +} + +template +template +function<_R(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _F __f, + typename enable_if::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__not_null(__f)) + { + typedef __function::__func<_F, _Alloc, _R(_A0)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<_FF> +#else + rebind_alloc<_FF>::other +#endif + _A; + _A __a(__a0); + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template +function<_R(_A0)>& +function<_R(_A0)>::operator=(const function& __f) +{ + function(__f).swap(*this); + return *this; +} + +template +function<_R(_A0)>& +function<_R(_A0)>::operator=(nullptr_t) +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + __f_ = 0; +} + +template +template +typename enable_if +< + !is_integral<_F>::value, + function<_R(_A0)>& +>::type +function<_R(_A0)>::operator=(_F __f) +{ + function(_VSTD::move(__f)).swap(*this); + return *this; +} + +template +function<_R(_A0)>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template +void +function<_R(_A0)>::swap(function& __f) +{ + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template +_R +function<_R(_A0)>::operator()(_A0 __a0) const +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__f_ == 0) + throw bad_function_call(); +#endif // _LIBCPP_NO_EXCEPTIONS + return (*__f_)(__a0); +} + +#ifndef _LIBCPP_NO_RTTI + +template +const std::type_info& +function<_R(_A0)>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template +template +_T* +function<_R(_A0)>::target() +{ + if (__f_ == 0) + return (_T*)0; + return (_T*)__f_->target(typeid(_T)); +} + +template +template +const _T* +function<_R(_A0)>::target() const +{ + if (__f_ == 0) + return (const _T*)0; + return (const _T*)__f_->target(typeid(_T)); +} + +#endif // _LIBCPP_NO_RTTI + +template +class _LIBCPP_VISIBLE function<_R(_A0, _A1)> + : public binary_function<_A0, _A1, _R> +{ + typedef __function::__base<_R(_A0, _A1)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(const _F&) {return true;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (*__p)(_B0, _B1)) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_B1)) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_B1) const) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_B1) volatile) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_B1) const volatile) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(const function<_R(_B0, _B1)>& __p) {return __p;} +public: + typedef _R result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template + function(_F, + typename enable_if::value>::type* = 0); + + template + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc& __a, _F __f, + typename enable_if::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template + typename enable_if + < + !is_integral<_F>::value, + function& + >::type + operator=(_F); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template + _LIBCPP_INLINE_VISIBILITY + void assign(_F __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete; + template + bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _R operator()(_A0, _A1) const; + +#ifndef _LIBCPP_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template _T* target(); + template const _T* target() const; +#endif // _LIBCPP_NO_RTTI +}; + +template +function<_R(_A0, _A1)>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_R(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_R(_A0, _A1)>::function(_F __f, + typename enable_if::value>::type*) + : __f_(0) +{ + if (__not_null(__f)) + { + typedef __function::__func<_F, allocator<_F>, _R(_A0, _A1)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _A; + _A __a; + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_F>(__a)); + __f_ = __hold.release(); + } + } +} + +template +template +function<_R(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _F __f, + typename enable_if::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__not_null(__f)) + { + typedef __function::__func<_F, _Alloc, _R(_A0, _A1)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<_FF> +#else + rebind_alloc<_FF>::other +#endif + _A; + _A __a(__a0); + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template +function<_R(_A0, _A1)>& +function<_R(_A0, _A1)>::operator=(const function& __f) +{ + function(__f).swap(*this); + return *this; +} + +template +function<_R(_A0, _A1)>& +function<_R(_A0, _A1)>::operator=(nullptr_t) +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + __f_ = 0; +} + +template +template +typename enable_if +< + !is_integral<_F>::value, + function<_R(_A0, _A1)>& +>::type +function<_R(_A0, _A1)>::operator=(_F __f) +{ + function(_VSTD::move(__f)).swap(*this); + return *this; +} + +template +function<_R(_A0, _A1)>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template +void +function<_R(_A0, _A1)>::swap(function& __f) +{ + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template +_R +function<_R(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__f_ == 0) + throw bad_function_call(); +#endif // _LIBCPP_NO_EXCEPTIONS + return (*__f_)(__a0, __a1); +} + +#ifndef _LIBCPP_NO_RTTI + +template +const std::type_info& +function<_R(_A0, _A1)>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template +template +_T* +function<_R(_A0, _A1)>::target() +{ + if (__f_ == 0) + return (_T*)0; + return (_T*)__f_->target(typeid(_T)); +} + +template +template +const _T* +function<_R(_A0, _A1)>::target() const +{ + if (__f_ == 0) + return (const _T*)0; + return (const _T*)__f_->target(typeid(_T)); +} + +#endif // _LIBCPP_NO_RTTI + +template +class _LIBCPP_VISIBLE function<_R(_A0, _A1, _A2)> +{ + typedef __function::__base<_R(_A0, _A1, _A2)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(const _F&) {return true;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (*__p)(_B0, _B1, _B2)) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_B1, _B2)) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_B1, _B2) const) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_B1, _B2) volatile) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_B1, _B2) const volatile) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(const function<_R(_B0, _B1, _B2)>& __p) {return __p;} +public: + typedef _R result_type; + + // 20.7.16.2.1, construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} + _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} + function(const function&); + template + function(_F, + typename enable_if::value>::type* = 0); + + template + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) : __f_(0) {} + template + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc& __a, _F __f, + typename enable_if::value>::type* = 0); + + function& operator=(const function&); + function& operator=(nullptr_t); + template + typename enable_if + < + !is_integral<_F>::value, + function& + >::type + operator=(_F); + + ~function(); + + // 20.7.16.2.2, function modifiers: + void swap(function&); + template + _LIBCPP_INLINE_VISIBILITY + void assign(_F __f, const _Alloc& __a) + {function(allocator_arg, __a, __f).swap(*this);} + + // 20.7.16.2.3, function capacity: + _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} + +private: + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; + template + bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; +public: + // 20.7.16.2.4, function invocation: + _R operator()(_A0, _A1, _A2) const; + +#ifndef _LIBCPP_NO_RTTI + // 20.7.16.2.5, function target access: + const std::type_info& target_type() const; + template _T* target(); + template const _T* target() const; +#endif // _LIBCPP_NO_RTTI +}; + +template +function<_R(_A0, _A1, _A2)>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_R(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&, + const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_R(_A0, _A1, _A2)>::function(_F __f, + typename enable_if::value>::type*) + : __f_(0) +{ + if (__not_null(__f)) + { + typedef __function::__func<_F, allocator<_F>, _R(_A0, _A1, _A2)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef allocator<_FF> _A; + _A __a; + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(__f, allocator<_F>(__a)); + __f_ = __hold.release(); + } + } +} + +template +template +function<_R(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _F __f, + typename enable_if::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__not_null(__f)) + { + typedef __function::__func<_F, _Alloc, _R(_A0, _A1, _A2)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(__f); + } + else + { + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<_FF> +#else + rebind_alloc<_FF>::other +#endif + _A; + _A __a(__a0); + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(__f, _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template +function<_R(_A0, _A1, _A2)>& +function<_R(_A0, _A1, _A2)>::operator=(const function& __f) +{ + function(__f).swap(*this); + return *this; +} + +template +function<_R(_A0, _A1, _A2)>& +function<_R(_A0, _A1, _A2)>::operator=(nullptr_t) +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + __f_ = 0; +} + +template +template +typename enable_if +< + !is_integral<_F>::value, + function<_R(_A0, _A1, _A2)>& +>::type +function<_R(_A0, _A1, _A2)>::operator=(_F __f) +{ + function(_VSTD::move(__f)).swap(*this); + return *this; +} + +template +function<_R(_A0, _A1, _A2)>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template +void +function<_R(_A0, _A1, _A2)>::swap(function& __f) +{ + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template +_R +function<_R(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__f_ == 0) + throw bad_function_call(); +#endif // _LIBCPP_NO_EXCEPTIONS + return (*__f_)(__a0, __a1, __a2); +} + +#ifndef _LIBCPP_NO_RTTI + +template +const std::type_info& +function<_R(_A0, _A1, _A2)>::target_type() const +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template +template +_T* +function<_R(_A0, _A1, _A2)>::target() +{ + if (__f_ == 0) + return (_T*)0; + return (_T*)__f_->target(typeid(_T)); +} + +template +template +const _T* +function<_R(_A0, _A1, _A2)>::target() const +{ + if (__f_ == 0) + return (const _T*)0; + return (const _T*)__f_->target(typeid(_T)); +} + +#endif // _LIBCPP_NO_RTTI + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const function<_F>& __f, nullptr_t) {return !__f;} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(nullptr_t, const function<_F>& __f) {return !__f;} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const function<_F>& __f, nullptr_t) {return (bool)__f;} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(nullptr_t, const function<_F>& __f) {return (bool)__f;} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(function<_F>& __x, function<_F>& __y) +{return __x.swap(__y);} + +template struct __is_bind_expression : public false_type {}; +template struct _LIBCPP_VISIBLE is_bind_expression + : public __is_bind_expression::type> {}; + +template struct __is_placeholder : public integral_constant {}; +template struct _LIBCPP_VISIBLE is_placeholder + : public __is_placeholder::type> {}; + +namespace placeholders +{ + +template struct __ph {}; + +extern __ph<1> _1; +extern __ph<2> _2; +extern __ph<3> _3; +extern __ph<4> _4; +extern __ph<5> _5; +extern __ph<6> _6; +extern __ph<7> _7; +extern __ph<8> _8; +extern __ph<9> _9; +extern __ph<10> _10; + +} // placeholders + +template +struct __is_placeholder > + : public integral_constant {}; + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp& +__mu(reference_wrapper<_Tp> __t, _Uj&) +{ + return __t.get(); +} +/* +template +struct __mu_return1 {}; + +template +struct __mu_return1 +{ + typedef typename result_of<_Ti(_Uj...)>::type type; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __mu_return1::type +__mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>) +{ + __ti(_VSTD::forward::type>(get<_Indx>(__uj))...); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_bind_expression<_Ti>::value, + typename __mu_return1::value, _Ti, _Uj...>::type +>::type +__mu(_Ti& __ti, tuple<_Uj...>& __uj) +{ + typedef typename __make_tuple_indices::type __indices; + return __mu_expand(__ti, __uj, __indices()); +} + +template +struct __mu_return2 {}; + +template +struct __mu_return2 +{ + typedef typename tuple_element::value - 1, _Uj>::type type; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + 0 < is_placeholder<_Ti>::value, + typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type +>::type +__mu(_Ti&, _Uj& __uj) +{ + const size_t _Indx = is_placeholder<_Ti>::value - 1; + // compiler bug workaround + typename tuple_element<_Indx, _Uj>::type __t = get<_Indx>(__uj); + return __t; +// return _VSTD::forward::type>(get<_Indx>(__uj)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_bind_expression<_Ti>::value && + is_placeholder<_Ti>::value == 0 && + !__is_reference_wrapper<_Ti>::value, + _Ti& +>::type +__mu(_Ti& __ti, _Uj& __uj) +{ + return __ti; +} + +template +struct ____mu_return; + +template +struct ____mu_return<_Ti, true, false, tuple<_Uj...> > +{ + typedef typename result_of<_Ti(_Uj...)>::type type; +}; + +template +struct ____mu_return<_Ti, false, true, _TupleUj> +{ + typedef typename tuple_element::value - 1, + _TupleUj>::type&& type; +}; + +template +struct ____mu_return<_Ti, false, false, _TupleUj> +{ + typedef _Ti& type; +}; + +template +struct __mu_return + : public ____mu_return<_Ti, + is_bind_expression<_Ti>::value, + 0 < is_placeholder<_Ti>::value, + _TupleUj> +{ +}; + +template +struct __mu_return, _TupleUj> +{ + typedef _Ti& type; +}; + +template +struct __bind_return; + +template +struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj> +{ + typedef typename __ref_return + < + _F&, + typename __mu_return + < + _BoundArgs, + _TupleUj + >::type... + >::type type; +}; + +template +struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj> +{ + typedef typename __ref_return + < + _F&, + typename __mu_return + < + const _BoundArgs, + _TupleUj + >::type... + >::type type; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __bind_return<_F, _BoundArgs, _Args>::type +__apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, + _Args&& __args) +{ + return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...); +} + +template +class __bind +{ + _F __f_; + tuple<_BoundArgs...> __bound_args_; + + typedef typename __make_tuple_indices::type __indices; +public: + template + explicit __bind(_G&& __f, _BA&& ...__bound_args) + : __f_(_VSTD::forward<_G>(__f)), + __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} + + template + typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type + operator()(_Args&& ...__args) + { + // compiler bug workaround + return __apply_functor(__f_, __bound_args_, __indices(), + tuple<_Args&&...>(__args...)); + } + + template + typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type + operator()(_Args&& ...__args) const + { + return __apply_functor(__f_, __bound_args_, __indices(), + tuple<_Args&&...>(__args...)); + } +}; + +template +struct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {}; + +template +class __bind_r + : public __bind<_F, _BoundArgs...> +{ + typedef __bind<_F, _BoundArgs...> base; +public: + typedef _R result_type; + + template + explicit __bind_r(_G&& __f, _BA&& ...__bound_args) + : base(_VSTD::forward<_G>(__f), + _VSTD::forward<_BA>(__bound_args)...) {} + + template + result_type + operator()(_Args&& ...__args) + { + return base::operator()(_VSTD::forward<_Args>(__args)...); + } + + template + result_type + operator()(_Args&& ...__args) const + { + return base::operator()(_VSTD::forward<_Args>(__args)...); + } +}; + +template +struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {}; + +template +inline _LIBCPP_INLINE_VISIBILITY +__bind::type, typename decay<_BoundArgs>::type...> +bind(_F&& __f, _BoundArgs&&... __bound_args) +{ + typedef __bind::type, typename decay<_BoundArgs>::type...> type; + return type(_VSTD::forward<_F>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> +bind(_F&& __f, _BoundArgs&&... __bound_args) +{ + typedef __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> type; + return type(_VSTD::forward<_F>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); +} +*/ + +#endif // _LIBCPP_FUNCTIONAL_03 diff --git a/contrib/libc++/include/__functional_base b/contrib/libc++/include/__functional_base new file mode 100644 index 000000000000..8d8e4b5e6e9a --- /dev/null +++ b/contrib/libc++/include/__functional_base @@ -0,0 +1,430 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FUNCTIONAL_BASE +#define _LIBCPP_FUNCTIONAL_BASE + +#include <__config> +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct _LIBCPP_VISIBLE unary_function +{ + typedef _Arg argument_type; + typedef _Result result_type; +}; + +template +struct _LIBCPP_VISIBLE binary_function +{ + typedef _Arg1 first_argument_type; + typedef _Arg2 second_argument_type; + typedef _Result result_type; +}; + +template struct _LIBCPP_VISIBLE hash; + +template +struct __has_result_type +{ +private: + struct __two {char _; char __;}; + template static __two __test(...); + template static char __test(typename _Up::result_type* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +#ifdef _LIBCPP_HAS_NO_VARIADICS + +#include <__functional_base_03> + +#else // _LIBCPP_HAS_NO_VARIADICS + +// __weak_result_type + +template +struct __derives_from_unary_function +{ +private: + struct __two {char _; char __;}; + static __two __test(...); + template + static unary_function<_A, _R> + __test(const volatile unary_function<_A, _R>*); +public: + static const bool value = !is_same::value; + typedef decltype(__test((_Tp*)0)) type; +}; + +template +struct __derives_from_binary_function +{ +private: + struct __two {char _; char __;}; + static __two __test(...); + template + static binary_function<_A1, _A2, _R> + __test(const volatile binary_function<_A1, _A2, _R>*); +public: + static const bool value = !is_same::value; + typedef decltype(__test((_Tp*)0)) type; +}; + +template ::value> +struct __maybe_derive_from_unary_function // bool is true + : public __derives_from_unary_function<_Tp>::type +{ +}; + +template +struct __maybe_derive_from_unary_function<_Tp, false> +{ +}; + +template ::value> +struct __maybe_derive_from_binary_function // bool is true + : public __derives_from_binary_function<_Tp>::type +{ +}; + +template +struct __maybe_derive_from_binary_function<_Tp, false> +{ +}; + +template ::value> +struct __weak_result_type_imp // bool is true + : public __maybe_derive_from_unary_function<_Tp>, + public __maybe_derive_from_binary_function<_Tp> +{ + typedef typename _Tp::result_type result_type; +}; + +template +struct __weak_result_type_imp<_Tp, false> + : public __maybe_derive_from_unary_function<_Tp>, + public __maybe_derive_from_binary_function<_Tp> +{ +}; + +template +struct __weak_result_type + : public __weak_result_type_imp<_Tp> +{ +}; + +// 0 argument case + +template +struct __weak_result_type<_R ()> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (&)()> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (*)()> +{ + typedef _R result_type; +}; + +// 1 argument case + +template +struct __weak_result_type<_R (_A1)> + : public unary_function<_A1, _R> +{ +}; + +template +struct __weak_result_type<_R (&)(_A1)> + : public unary_function<_A1, _R> +{ +}; + +template +struct __weak_result_type<_R (*)(_A1)> + : public unary_function<_A1, _R> +{ +}; + +template +struct __weak_result_type<_R (_C::*)()> + : public unary_function<_C*, _R> +{ +}; + +template +struct __weak_result_type<_R (_C::*)() const> + : public unary_function +{ +}; + +template +struct __weak_result_type<_R (_C::*)() volatile> + : public unary_function +{ +}; + +template +struct __weak_result_type<_R (_C::*)() const volatile> + : public unary_function +{ +}; + +// 2 argument case + +template +struct __weak_result_type<_R (_A1, _A2)> + : public binary_function<_A1, _A2, _R> +{ +}; + +template +struct __weak_result_type<_R (*)(_A1, _A2)> + : public binary_function<_A1, _A2, _R> +{ +}; + +template +struct __weak_result_type<_R (&)(_A1, _A2)> + : public binary_function<_A1, _A2, _R> +{ +}; + +template +struct __weak_result_type<_R (_C::*)(_A1)> + : public binary_function<_C*, _A1, _R> +{ +}; + +template +struct __weak_result_type<_R (_C::*)(_A1) const> + : public binary_function +{ +}; + +template +struct __weak_result_type<_R (_C::*)(_A1) volatile> + : public binary_function +{ +}; + +template +struct __weak_result_type<_R (_C::*)(_A1) const volatile> + : public binary_function +{ +}; + +// 3 or more arguments + +template +struct __weak_result_type<_R (_A1, _A2, _A3, _A4...)> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (&)(_A1, _A2, _A3, _A4...)> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (*)(_A1, _A2, _A3, _A4...)> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...)> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...) const> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...) volatile> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...) const volatile> +{ + typedef _R result_type; +}; + +// __invoke + +// bullets 1 and 2 + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_F&& __f, _A0&& __a0, _Args&& ...__args) + -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)) +{ + return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_F&& __f, _A0&& __a0, _Args&& ...__args) + -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)) +{ + return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...); +} + +// bullets 3 and 4 + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_F&& __f, _A0&& __a0) + -> decltype(_VSTD::forward<_A0>(__a0).*__f) +{ + return _VSTD::forward<_A0>(__a0).*__f; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_F&& __f, _A0&& __a0) + -> decltype((*_VSTD::forward<_A0>(__a0)).*__f) +{ + return (*_VSTD::forward<_A0>(__a0)).*__f; +} + +// bullet 5 + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_F&& __f, _Args&& ...__args) + -> decltype(_VSTD::forward<_F>(__f)(_VSTD::forward<_Args>(__args)...)) +{ + return _VSTD::forward<_F>(__f)(_VSTD::forward<_Args>(__args)...); +} + +template +struct __invoke_return +{ + typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type; +}; + +template +class _LIBCPP_VISIBLE reference_wrapper + : public __weak_result_type<_Tp> +{ +public: + // types + typedef _Tp type; +private: + type* __f_; + +public: + // construct/copy/destroy + _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT : __f_(&__f) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + private: reference_wrapper(type&&); public: // = delete; // do not bind to temps +#endif + + // access + _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;} + _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;} + + // invoke + template + _LIBCPP_INLINE_VISIBILITY + typename __invoke_of::type + operator() (_ArgTypes&&... __args) const + { + return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...); + } +}; + +template struct ____is_reference_wrapper : public false_type {}; +template struct ____is_reference_wrapper > : public true_type {}; +template struct __is_reference_wrapper + : public ____is_reference_wrapper::type> {}; + +template +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper<_Tp> +ref(_Tp& __t) _NOEXCEPT +{ + return reference_wrapper<_Tp>(__t); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper<_Tp> +ref(reference_wrapper<_Tp> __t) _NOEXCEPT +{ + return ref(__t.get()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper +cref(const _Tp& __t) _NOEXCEPT +{ + return reference_wrapper(__t); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper +cref(reference_wrapper<_Tp> __t) _NOEXCEPT +{ + return cref(__t.get()); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS + +template void ref(const _Tp&& __t) = delete; +template void cref(const _Tp&& __t) = delete; + +#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS + +template void ref(const _Tp&& __t);// = delete; +template void cref(const _Tp&& __t);// = delete; + +#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // _LIBCPP_HAS_NO_VARIADICS + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_FUNCTIONAL_BASE diff --git a/contrib/libc++/include/__functional_base_03 b/contrib/libc++/include/__functional_base_03 new file mode 100644 index 000000000000..fabda5bc3d4b --- /dev/null +++ b/contrib/libc++/include/__functional_base_03 @@ -0,0 +1,1087 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FUNCTIONAL_BASE_03 +#define _LIBCPP_FUNCTIONAL_BASE_03 + +// manual variadic expansion for + +// __weak_result_type + +template +struct __derives_from_unary_function +{ +private: + struct __two {char _; char __;}; + static __two __test(...); + template + static unary_function<_A, _R> + __test(const volatile unary_function<_A, _R>*); +public: + static const bool value = !is_same::value; + typedef decltype(__test((_Tp*)0)) type; +}; + +template +struct __derives_from_binary_function +{ +private: + struct __two {char _; char __;}; + static __two __test(...); + template + static binary_function<_A1, _A2, _R> + __test(const volatile binary_function<_A1, _A2, _R>*); +public: + static const bool value = !is_same::value; + typedef decltype(__test((_Tp*)0)) type; +}; + +template ::value> +struct __maybe_derive_from_unary_function // bool is true + : public __derives_from_unary_function<_Tp>::type +{ +}; + +template +struct __maybe_derive_from_unary_function<_Tp, false> +{ +}; + +template ::value> +struct __maybe_derive_from_binary_function // bool is true + : public __derives_from_binary_function<_Tp>::type +{ +}; + +template +struct __maybe_derive_from_binary_function<_Tp, false> +{ +}; + +template ::value> +struct __weak_result_type_imp // bool is true + : public __maybe_derive_from_unary_function<_Tp>, + public __maybe_derive_from_binary_function<_Tp> +{ + typedef typename _Tp::result_type result_type; +}; + +template +struct __weak_result_type_imp<_Tp, false> + : public __maybe_derive_from_unary_function<_Tp>, + public __maybe_derive_from_binary_function<_Tp> +{ +}; + +template +struct __weak_result_type + : public __weak_result_type_imp::type> +{ +}; + +// 0 argument case + +template +struct __weak_result_type<_R ()> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (&)()> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (*)()> +{ + typedef _R result_type; +}; + +// 1 argument case + +template +struct __weak_result_type<_R (_A1)> + : public unary_function<_A1, _R> +{ +}; + +template +struct __weak_result_type<_R (&)(_A1)> + : public unary_function<_A1, _R> +{ +}; + +template +struct __weak_result_type<_R (*)(_A1)> + : public unary_function<_A1, _R> +{ +}; + +template +struct __weak_result_type<_R (_C::*)()> + : public unary_function<_C*, _R> +{ +}; + +template +struct __weak_result_type<_R (_C::*)() const> + : public unary_function +{ +}; + +template +struct __weak_result_type<_R (_C::*)() volatile> + : public unary_function +{ +}; + +template +struct __weak_result_type<_R (_C::*)() const volatile> + : public unary_function +{ +}; + +// 2 argument case + +template +struct __weak_result_type<_R (_A1, _A2)> + : public binary_function<_A1, _A2, _R> +{ +}; + +template +struct __weak_result_type<_R (*)(_A1, _A2)> + : public binary_function<_A1, _A2, _R> +{ +}; + +template +struct __weak_result_type<_R (&)(_A1, _A2)> + : public binary_function<_A1, _A2, _R> +{ +}; + +template +struct __weak_result_type<_R (_C::*)(_A1)> + : public binary_function<_C*, _A1, _R> +{ +}; + +template +struct __weak_result_type<_R (_C::*)(_A1) const> + : public binary_function +{ +}; + +template +struct __weak_result_type<_R (_C::*)(_A1) volatile> + : public binary_function +{ +}; + +template +struct __weak_result_type<_R (_C::*)(_A1) const volatile> + : public binary_function +{ +}; + +// 3 or more arguments + +template +struct __weak_result_type<_R (_A1, _A2, _A3)> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (&)(_A1, _A2, _A3)> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (*)(_A1, _A2, _A3)> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (_C::*)(_A1, _A2)> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (_C::*)(_A1, _A2) const> +{ + typedef _R result_type; +}; + +template +struct __weak_result_type<_R (_C::*)(_A1, _A2) volatile> +{ + typedef _R result_type; +}; + +// __invoke + +// __ref_return0 +// +// template +// struct ________ref_return0 // _HasResultType is true +// { +// typedef typename _Tp::result_type type; +// }; +// +// template +// struct ________ref_return0<_Tp, false> +// { +// typedef void type; +// }; +// +// template +// struct ____ref_return0 // _IsClass is true +// : public ________ref_return0<_Tp, __has_result_type::type>::value> +// { +// }; +// +// template +// struct ______ref_return0 // _HasResultType is true +// { +// typedef typename __callable_type<_Tp>::result_type type; +// }; +// +// template +// struct ______ref_return0<_Tp, false> // pointer to member data +// { +// typedef void type; +// }; +// +// template +// struct ____ref_return0<_Tp, false> +// : public ______ref_return0::type, +// __has_result_type<__callable_type::type> >::value> +// { +// }; +// +// template +// struct __ref_return0 +// : public ____ref_return0::type, +// is_class::type>::value> +// { +// }; +// +// __ref_return1 +// +// template +// struct ____ref_return1 // _IsClass is true +// { +// typedef typename result_of<_Tp(_A0)>::type type; +// }; +// +// template +// struct ______ref_return1 // _HasResultType is true +// { +// typedef typename __callable_type<_Tp>::result_type type; +// }; +// +// template +// struct __ref_return1_member_data1; +// +// template +// struct __ref_return1_member_data1<_R _C::*, _A0, true> +// { +// typedef typename __apply_cv<_A0, _R>::type& type; +// }; +// +// template +// struct __ref_return1_member_data1<_R _C::*, _A0, false> +// { +// static _A0 __a; +// typedef typename __apply_cv::type& type; +// }; +// +// template +// struct __ref_return1_member_data; +// +// template +// struct __ref_return1_member_data<_R _C::*, _A0> +// : public __ref_return1_member_data1<_R _C::*, _A0, +// is_same::type, +// typename remove_cv::type>::type>::value> +// { +// }; +// +// template +// struct ______ref_return1<_Tp, false, _A0> // pointer to member data +// : public __ref_return1_member_data::type, _A0> +// { +// }; +// +// template +// struct ____ref_return1<_Tp, false, _A0> +// : public ______ref_return1::type, +// __has_result_type<__callable_type::type> >::value, _A0> +// { +// }; +// +// template +// struct __ref_return1 +// : public ____ref_return1::type, +// is_class::type>::value, _A0> +// { +// }; +// +// __ref_return2 +// +// template +// struct ____ref_return2 // _IsClass is true +// { +// typedef typename result_of<_Tp(_A0, _A1)>::type type; +// }; +// +// template +// struct ______ref_return2 // _HasResultType is true +// { +// typedef typename __callable_type<_Tp>::result_type type; +// }; +// +// template +// struct ______ref_return2<_Tp, false, class _A0, class _A1> // pointer to member data +// { +// static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer" +// " to member data with too many arguments."); +// }; +// +// template +// struct ____ref_return2<_Tp, false, _A0, _A1> +// : public ______ref_return2::type, +// __has_result_type<__callable_type::type> >::value, _A0, _A1> +// { +// }; +// +// template +// struct __ref_return2 +// : public ____ref_return2::type, +// is_class::type>::value, _A0, _A1> +// { +// }; +// +// __ref_return3 +// +// template +// struct ____ref_return3 // _IsClass is true +// { +// typedef typename result_of<_Tp(_A0, _A1, _A2)>::type type; +// }; +// +// template +// struct ______ref_return3 // _HasResultType is true +// { +// typedef typename __callable_type<_Tp>::result_type type; +// }; +// +// template +// struct ______ref_return3<_Tp, false, class _A0, class _A1, class _A2> // pointer to member data +// { +// static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer" +// " to member data with too many arguments."); +// }; +// +// template +// struct ____ref_return3<_Tp, false, _A0, _A1, _A2> +// : public ______ref_return3::type, +// __has_result_type<__callable_type::type> >::value, _A0, _A1, _A2> +// { +// }; +// +// template +// struct __ref_return3 +// : public ____ref_return3::type, +// is_class::type>::value, _A0, _A1, _A2> +// { +// }; + +// first bullet + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(), _T1& __t1) +{ + return (__t1.*__f)(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0), _T1& __t1, _A0& __a0) +{ + return (__t1.*__f)(__a0); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1), _T1& __t1, _A0& __a0, _A1& __a1) +{ + return (__t1.*__f)(__a0, __a1); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1, _A2), _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return (__t1.*__f)(__a0, __a1, __a2); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)() const, _T1& __t1) +{ + return (__t1.*__f)(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0) const, _T1& __t1, _A0& __a0) +{ + return (__t1.*__f)(__a0); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1) const, _T1& __t1, _A0& __a0, _A1& __a1) +{ + return (__t1.*__f)(__a0, __a1); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1, _A2) const, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return (__t1.*__f)(__a0, __a1, __a2); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)() volatile, _T1& __t1) +{ + return (__t1.*__f)(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0) volatile, _T1& __t1, _A0& __a0) +{ + return (__t1.*__f)(__a0); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1) volatile, _T1& __t1, _A0& __a0, _A1& __a1) +{ + return (__t1.*__f)(__a0, __a1); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1, _A2) volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return (__t1.*__f)(__a0, __a1, __a2); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)() const volatile, _T1& __t1) +{ + return (__t1.*__f)(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0) const volatile, _T1& __t1, _A0& __a0) +{ + return (__t1.*__f)(__a0); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1) const volatile, _T1& __t1, _A0& __a0, _A1& __a1) +{ + return (__t1.*__f)(__a0, __a1); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1, _A2) const volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return (__t1.*__f)(__a0, __a1, __a2); +} + +// second bullet + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(), _T1 __t1) +{ + return ((*__t1).*__f)(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0), _T1 __t1, _A0& __a0) +{ + return ((*__t1).*__f)(__a0); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1), _T1 __t1, _A0& __a0, _A1& __a1) +{ + return ((*__t1).*__f)(__a0, __a1); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1, _A2), _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return ((*__t1).*__f)(__a0, __a1, __a2); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)() const, _T1 __t1) +{ + return ((*__t1).*__f)(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0) const, _T1 __t1, _A0& __a0) +{ + return ((*__t1).*__f)(__a0); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1) const, _T1 __t1, _A0& __a0, _A1& __a1) +{ + return ((*__t1).*__f)(__a0, __a1); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1, _A2) const, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return ((*__t1).*__f)(__a0, __a1, __a2); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)() volatile, _T1 __t1) +{ + return ((*__t1).*__f)(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0) volatile, _T1 __t1, _A0& __a0) +{ + return ((*__t1).*__f)(__a0); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1) volatile, _T1 __t1, _A0& __a0, _A1& __a1) +{ + return ((*__t1).*__f)(__a0, __a1); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1, _A2) volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return ((*__t1).*__f)(__a0, __a1, __a2); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)() const volatile, _T1 __t1) +{ + return ((*__t1).*__f)(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0) const volatile, _T1 __t1, _A0& __a0) +{ + return ((*__t1).*__f)(__a0); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1) const volatile, _T1 __t1, _A0& __a0, _A1& __a1) +{ + return ((*__t1).*__f)(__a0, __a1); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_base_of<_T, typename remove_reference<_T1>::type>::value, + _R +>::type +__invoke(_R (_T::*__f)(_A0, _A1, _A2) const volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return ((*__t1).*__f)(__a0, __a1, __a2); +} + +// third bullet + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_base_of<_T, typename remove_reference<_T1>::type>::value, + typename __apply_cv<_T1, _R>::type& +>::type +__invoke(_R _T::* __f, _T1& __t1) +{ + return __t1.*__f; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__invoke(_R _T::*) +{ +} + +// template +// inline _LIBCPP_INLINE_VISIBILITY +// typename enable_if +// < +// is_base_of<_T, typename remove_reference<_T1>::type>::value, +// typename __ref_return1<_R _T::*, _T1>::type +// >::type +// __invoke(_R _T::* __f, _T1& __t1) +// { +// return __t1.*__f; +// } + +// forth bullet + +template +struct __4th_helper +{ +}; + +template +struct __4th_helper<_T1, _R, true> +{ + typedef typename __apply_cv()), _R>::type type; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __4th_helper<_T1, _R, + !is_base_of<_T, + typename remove_reference<_T1>::type + >::value + >::type& +__invoke(_R _T::* __f, _T1& __t1) +{ + return (*__t1).*__f; +} + +// template +// inline _LIBCPP_INLINE_VISIBILITY +// typename enable_if +// < +// !is_base_of<_T, typename remove_reference<_T1>::type>::value, +// typename __ref_return1<_R _T::*, _T1>::type +// >::type +// __invoke(_R _T::* __f, _T1 __t1) +// { +// return (*__t1).*__f; +// } + +// fifth bullet + +template +inline _LIBCPP_INLINE_VISIBILITY +decltype(declval<_F>()()) +__invoke(_F __f) +{ + return __f(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +decltype(declval<_F>()(declval<_A0&>())) +__invoke(_F __f, _A0& __a0) +{ + return __f(__a0); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +decltype(declval<_F>()(declval<_A0&>(), declval<_A1&>())) +__invoke(_F __f, _A0& __a0, _A1& __a1) +{ + return __f(__a0, __a1); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +decltype(declval<_F>()(declval<_A0&>(), declval<_A1&>(), declval<_A2&>())) +__invoke(_F __f, _A0& __a0, _A1& __a1, _A2& __a2) +{ + return __f(__a0, __a1, __a2); +} + +// template +// inline _LIBCPP_INLINE_VISIBILITY +// _R +// __invoke(_F& __f) +// { +// return __f(); +// } +// +// template +// inline _LIBCPP_INLINE_VISIBILITY +// typename enable_if +// < +// !is_member_pointer<_F>::value, +// _R +// >::type +// __invoke(_F& __f, _A0& __a0) +// { +// return __f(__a0); +// } +// +// template +// inline _LIBCPP_INLINE_VISIBILITY +// _R +// __invoke(_F& __f, _A0& __a0, _A1& __a1) +// { +// return __f(__a0, __a1); +// } +// +// template +// inline _LIBCPP_INLINE_VISIBILITY +// _R +// __invoke(_F& __f, _A0& __a0, _A1& __a1, _A2& __a2) +// { +// return __f(__a0, __a1, __a2); +// } + +template +struct __has_type +{ +private: + struct __two {char _; char __;}; + template static __two __test(...); + template static char __test(typename _Up::type* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template >::value> +struct __invoke_return +{ + typedef typename __weak_result_type<_F>::result_type type; +}; + +template +struct __invoke_return<_F, false> +{ + typedef decltype(__invoke(_VSTD::declval<_F>())) type; +}; + +template +struct __invoke_return0 +{ + typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>())) type; +}; + +template +struct __invoke_return0<_R _T::*, _A0> +{ + typedef typename __apply_cv<_A0, _R>::type& type; +}; + +template +struct __invoke_return0<_R _T::*, _A0*> +{ + typedef typename __apply_cv<_A0, _R>::type& type; +}; + +template +struct __invoke_return1 +{ + typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(), + _VSTD::declval<_A1>())) type; +}; + +template +struct __invoke_return2 +{ + typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(), + _VSTD::declval<_A1>(), + _VSTD::declval<_A2>())) type; +}; + +template +class _LIBCPP_VISIBLE reference_wrapper + : public __weak_result_type<_Tp> +{ +public: + // types + typedef _Tp type; +private: + type* __f_; + +public: + // construct/copy/destroy + _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) : __f_(&__f) {} + + // access + _LIBCPP_INLINE_VISIBILITY operator type& () const {return *__f_;} + _LIBCPP_INLINE_VISIBILITY type& get() const {return *__f_;} + + // invoke + + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return::type + operator() () const + { + return __invoke(get()); + } + + template + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return0::type + operator() (_A0& __a0) const + { + return __invoke(get(), __a0); + } + + template + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1::type + operator() (_A0& __a0, _A1& __a1) const + { + return __invoke(get(), __a0, __a1); + } + + template + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2::type + operator() (_A0& __a0, _A1& __a1, _A2& __a2) const + { + return __invoke(get(), __a0, __a1, __a2); + } +}; + +template struct ____is_reference_wrapper : public false_type {}; +template struct ____is_reference_wrapper > : public true_type {}; +template struct __is_reference_wrapper + : public ____is_reference_wrapper::type> {}; + +template +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper<_Tp> +ref(_Tp& __t) +{ + return reference_wrapper<_Tp>(__t); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper<_Tp> +ref(reference_wrapper<_Tp> __t) +{ + return ref(__t.get()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper +cref(const _Tp& __t) +{ + return reference_wrapper(__t); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +reference_wrapper +cref(reference_wrapper<_Tp> __t) +{ + return cref(__t.get()); +} + +#endif // _LIBCPP_FUNCTIONAL_BASE_03 diff --git a/contrib/libc++/include/__hash_table b/contrib/libc++/include/__hash_table new file mode 100644 index 000000000000..4399caad658b --- /dev/null +++ b/contrib/libc++/include/__hash_table @@ -0,0 +1,1918 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP__HASH_TABLE +#define _LIBCPP__HASH_TABLE + +#include <__config> +#include +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +_LIBCPP_VISIBLE +size_t __next_prime(size_t __n); + +template +struct __hash_node_base +{ + typedef __hash_node_base __first_node; + // typedef _NodePtr pointer; + + _NodePtr __next_; + + _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {} +}; + +template +struct __hash_node + : public __hash_node_base + < + typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__hash_node<_Tp, _VoidPtr> > +#else + rebind<__hash_node<_Tp, _VoidPtr> >::other +#endif + > +{ + typedef _Tp value_type; + + size_t __hash_; + value_type __value_; +}; + +template class __hash_table; +template class __hash_const_iterator; +template class __hash_map_iterator; +template class __hash_map_const_iterator; +template + class _LIBCPP_VISIBLE unordered_map; + +template +class _LIBCPP_VISIBLE __hash_iterator +{ + typedef _NodePtr __node_pointer; + + __node_pointer __node_; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename pointer_traits<__node_pointer>::element_type::value_type value_type; + typedef typename pointer_traits<__node_pointer>::difference_type difference_type; + typedef value_type& reference; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __node_->__value_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return _VSTD::addressof(__node_->__value_);} + + _LIBCPP_INLINE_VISIBILITY + __hash_iterator& operator++() + { + __node_ = __node_->__next_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __hash_iterator operator++(int) + { + __hash_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_iterator& __x, const __hash_iterator& __y) + {return __x.__node_ == __y.__node_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y) + {return __x.__node_ != __y.__node_;} + +private: + _LIBCPP_INLINE_VISIBILITY + __hash_iterator(__node_pointer __node) _NOEXCEPT + : __node_(__node) + {} + + template friend class __hash_table; + template friend class _LIBCPP_VISIBLE __hash_const_iterator; + template friend class _LIBCPP_VISIBLE __hash_map_iterator; + template friend class _LIBCPP_VISIBLE unordered_map; + template friend class _LIBCPP_VISIBLE unordered_multimap; +}; + +template +class _LIBCPP_VISIBLE __hash_const_iterator +{ + typedef _ConstNodePtr __node_pointer; + + __node_pointer __node_; + + typedef typename remove_const< + typename pointer_traits<__node_pointer>::element_type + >::type __node; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename __node::value_type value_type; + typedef typename pointer_traits<__node_pointer>::difference_type difference_type; + typedef const value_type& reference; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__node> +#else + rebind<__node>::other +#endif + __non_const_node_pointer; + typedef __hash_iterator<__non_const_node_pointer> __non_const_iterator; + + _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT + : __node_(__x.__node_) + {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __node_->__value_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return _VSTD::addressof(__node_->__value_);} + + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator& operator++() + { + __node_ = __node_->__next_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator operator++(int) + { + __hash_const_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y) + {return __x.__node_ == __y.__node_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y) + {return __x.__node_ != __y.__node_;} + +private: + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator(__node_pointer __node) _NOEXCEPT + : __node_(__node) + {} + + template friend class __hash_table; + template friend class _LIBCPP_VISIBLE __hash_map_const_iterator; + template friend class _LIBCPP_VISIBLE unordered_map; + template friend class _LIBCPP_VISIBLE unordered_multimap; +}; + +template class _LIBCPP_VISIBLE __hash_const_local_iterator; + +template +class _LIBCPP_VISIBLE __hash_local_iterator +{ + typedef _NodePtr __node_pointer; + + __node_pointer __node_; + size_t __bucket_; + size_t __bucket_count_; + + typedef pointer_traits<__node_pointer> __pointer_traits; +public: + typedef forward_iterator_tag iterator_category; + typedef typename __pointer_traits::element_type::value_type value_type; + typedef typename __pointer_traits::difference_type difference_type; + typedef value_type& reference; + typedef typename __pointer_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __node_->__value_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return &__node_->__value_;} + + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator& operator++() + { + __node_ = __node_->__next_; + if (__node_ != nullptr && __node_->__hash_ % __bucket_count_ != __bucket_) + __node_ = nullptr; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator operator++(int) + { + __hash_local_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y) + {return __x.__node_ == __y.__node_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y) + {return __x.__node_ != __y.__node_;} + +private: + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator(__node_pointer __node, size_t __bucket, + size_t __bucket_count) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + if (__node_ != nullptr) + __node_ = __node_->__next_; + } + + template friend class __hash_table; + template friend class _LIBCPP_VISIBLE __hash_const_local_iterator; + template friend class _LIBCPP_VISIBLE __hash_map_iterator; +}; + +template +class _LIBCPP_VISIBLE __hash_const_local_iterator +{ + typedef _ConstNodePtr __node_pointer; + + __node_pointer __node_; + size_t __bucket_; + size_t __bucket_count_; + + typedef pointer_traits<__node_pointer> __pointer_traits; + typedef typename __pointer_traits::element_type __node; + typedef typename remove_const<__node>::type __non_const_node; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__non_const_node> +#else + rebind<__non_const_node>::other +#endif + __non_const_node_pointer; + typedef __hash_local_iterator<__non_const_node_pointer> + __non_const_iterator; +public: + typedef forward_iterator_tag iterator_category; + typedef typename remove_const< + typename __pointer_traits::element_type::value_type + >::type value_type; + typedef typename __pointer_traits::difference_type difference_type; + typedef const value_type& reference; + typedef typename __pointer_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT + : __node_(__x.__node_), + __bucket_(__x.__bucket_), + __bucket_count_(__x.__bucket_count_) + {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __node_->__value_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return &__node_->__value_;} + + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator& operator++() + { + __node_ = __node_->__next_; + if (__node_ != nullptr && __node_->__hash_ % __bucket_count_ != __bucket_) + __node_ = nullptr; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator operator++(int) + { + __hash_const_local_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) + {return __x.__node_ == __y.__node_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) + {return __x.__node_ != __y.__node_;} + +private: + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator(__node_pointer __node, size_t __bucket, + size_t __bucket_count) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + if (__node_ != nullptr) + __node_ = __node_->__next_; + } + + template friend class __hash_table; + template friend class _LIBCPP_VISIBLE __hash_map_const_iterator; +}; + +template +class __bucket_list_deallocator +{ + typedef _Alloc allocator_type; + typedef allocator_traits __alloc_traits; + typedef typename __alloc_traits::size_type size_type; + + __compressed_pair __data_; +public: + typedef typename __alloc_traits::pointer pointer; + + _LIBCPP_INLINE_VISIBILITY + __bucket_list_deallocator() + _NOEXCEPT_(is_nothrow_default_constructible::value) + : __data_(0) {} + + _LIBCPP_INLINE_VISIBILITY + __bucket_list_deallocator(const allocator_type& __a, size_type __size) + _NOEXCEPT_(is_nothrow_copy_constructible::value) + : __data_(__size, __a) {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + __bucket_list_deallocator(__bucket_list_deallocator&& __x) + _NOEXCEPT_(is_nothrow_move_constructible::value) + : __data_(_VSTD::move(__x.__data_)) + { + __x.size() = 0; + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + size_type& size() _NOEXCEPT {return __data_.first();} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __data_.first();} + + _LIBCPP_INLINE_VISIBILITY + allocator_type& __alloc() _NOEXCEPT {return __data_.second();} + _LIBCPP_INLINE_VISIBILITY + const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();} + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + __alloc_traits::deallocate(__alloc(), __p, size()); + } +}; + +template class __hash_map_node_destructor; + +template +class __hash_node_destructor +{ + typedef _Alloc allocator_type; + typedef allocator_traits __alloc_traits; + typedef typename __alloc_traits::value_type::value_type value_type; +public: + typedef typename __alloc_traits::pointer pointer; +private: + + allocator_type& __na_; + + __hash_node_destructor& operator=(const __hash_node_destructor&); + +public: + bool __value_constructed; + + _LIBCPP_INLINE_VISIBILITY + explicit __hash_node_destructor(allocator_type& __na, + bool __constructed = false) _NOEXCEPT + : __na_(__na), + __value_constructed(__constructed) + {} + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + if (__value_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } + + template friend class __hash_map_node_destructor; +}; + +template +class __hash_table +{ +public: + typedef _Tp value_type; + typedef _Hash hasher; + typedef _Equal key_equal; + typedef _Alloc allocator_type; + +private: + typedef allocator_traits __alloc_traits; +public: + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; +public: + // Create __node + typedef __hash_node __node; + typedef typename __node::__first_node __first_node; + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__node> +#else + rebind_alloc<__node>::other +#endif + __node_allocator; + typedef allocator_traits<__node_allocator> __node_traits; + typedef typename __node_traits::pointer __node_pointer; + typedef typename __node_traits::const_pointer __node_const_pointer; + +private: + + typedef typename __node_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__node_pointer> +#else + rebind_alloc<__node_pointer>::other +#endif + __pointer_allocator; + typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; + typedef unique_ptr<__node_pointer[], __bucket_list_deleter> __bucket_list; + typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; + typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; + + // --- Member data begin --- + __bucket_list __bucket_list_; + __compressed_pair<__first_node, __node_allocator> __p1_; + __compressed_pair __p2_; + __compressed_pair __p3_; + // --- Member data end --- + + _LIBCPP_INLINE_VISIBILITY + size_type& size() _NOEXCEPT {return __p2_.first();} +public: + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __p2_.first();} + + _LIBCPP_INLINE_VISIBILITY + hasher& hash_function() _NOEXCEPT {return __p2_.second();} + _LIBCPP_INLINE_VISIBILITY + const hasher& hash_function() const _NOEXCEPT {return __p2_.second();} + + _LIBCPP_INLINE_VISIBILITY + float& max_load_factor() _NOEXCEPT {return __p3_.first();} + _LIBCPP_INLINE_VISIBILITY + float max_load_factor() const _NOEXCEPT {return __p3_.first();} + + _LIBCPP_INLINE_VISIBILITY + key_equal& key_eq() _NOEXCEPT {return __p3_.second();} + _LIBCPP_INLINE_VISIBILITY + const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();} + + _LIBCPP_INLINE_VISIBILITY + __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();} + _LIBCPP_INLINE_VISIBILITY + const __node_allocator& __node_alloc() const _NOEXCEPT + {return __p1_.second();} + +public: + typedef __hash_iterator<__node_pointer> iterator; + typedef __hash_const_iterator<__node_const_pointer> const_iterator; + typedef __hash_local_iterator<__node_pointer> local_iterator; + typedef __hash_const_local_iterator<__node_const_pointer> const_local_iterator; + + __hash_table() + _NOEXCEPT_( + is_nothrow_default_constructible<__bucket_list>::value && + is_nothrow_default_constructible<__first_node>::value && + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value); + __hash_table(const hasher& __hf, const key_equal& __eql); + __hash_table(const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); + explicit __hash_table(const allocator_type& __a); + __hash_table(const __hash_table& __u); + __hash_table(const __hash_table& __u, const allocator_type& __a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + __hash_table(__hash_table&& __u) + _NOEXCEPT_( + is_nothrow_move_constructible<__bucket_list>::value && + is_nothrow_move_constructible<__first_node>::value && + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible::value && + is_nothrow_move_constructible::value); + __hash_table(__hash_table&& __u, const allocator_type& __a); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~__hash_table(); + + __hash_table& operator=(const __hash_table& __u); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + __hash_table& operator=(__hash_table&& __u) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value); +#endif + template + void __assign_unique(_InputIterator __first, _InputIterator __last); + template + void __assign_multi(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + { + return allocator_traits<__pointer_allocator>::max_size( + __bucket_list_.get_deleter().__alloc()); + } + + pair __node_insert_unique(__node_pointer __nd); + iterator __node_insert_multi(__node_pointer __nd); + iterator __node_insert_multi(const_iterator __p, + __node_pointer __nd); + +#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + template + pair __emplace_unique(_Args&&... __args); + template + iterator __emplace_multi(_Args&&... __args); + template + iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); +#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + + pair __insert_unique(const value_type& __x); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template + pair __insert_unique(_P&& __x); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template + iterator __insert_multi(_P&& __x); + template + iterator __insert_multi(const_iterator __p, _P&& __x); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + iterator __insert_multi(const value_type& __x); + iterator __insert_multi(const_iterator __p, const value_type& __x); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + void clear() _NOEXCEPT; + void rehash(size_type __n); + _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n) + {rehash(static_cast(ceil(__n / max_load_factor())));} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const _NOEXCEPT + { + return __bucket_list_.get_deleter().size(); + } + + iterator begin() _NOEXCEPT; + iterator end() _NOEXCEPT; + const_iterator begin() const _NOEXCEPT; + const_iterator end() const _NOEXCEPT; + + template + _LIBCPP_INLINE_VISIBILITY + size_type bucket(const _Key& __k) const + {return hash_function()(__k) % bucket_count();} + + template + iterator find(const _Key& __x); + template + const_iterator find(const _Key& __x) const; + + typedef __hash_node_destructor<__node_allocator> _D; + typedef unique_ptr<__node, _D> __node_holder; + + iterator erase(const_iterator __p); + iterator erase(const_iterator __first, const_iterator __last); + template + size_type __erase_unique(const _Key& __k); + template + size_type __erase_multi(const _Key& __k); + __node_holder remove(const_iterator __p) _NOEXCEPT; + + template + size_type __count_unique(const _Key& __k) const; + template + size_type __count_multi(const _Key& __k) const; + + template + pair + __equal_range_unique(const _Key& __k); + template + pair + __equal_range_unique(const _Key& __k) const; + + template + pair + __equal_range_multi(const _Key& __k); + template + pair + __equal_range_multi(const _Key& __k) const; + + void swap(__hash_table& __u) + _NOEXCEPT_( + (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value || + __is_nothrow_swappable<__pointer_allocator>::value) && + (!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) && + __is_nothrow_swappable::value && + __is_nothrow_swappable::value); + + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const _NOEXCEPT + {return __bucket_list_.get_deleter().__alloc().max_size();} + size_type bucket_size(size_type __n) const; + _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT + { + size_type __bc = bucket_count(); + return __bc != 0 ? (float)size() / __bc : 0.f; + } + _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT + {max_load_factor() = _VSTD::max(__mlf, load_factor());} + + _LIBCPP_INLINE_VISIBILITY local_iterator begin(size_type __n) + {return local_iterator(__bucket_list_[__n], __n, bucket_count());} + _LIBCPP_INLINE_VISIBILITY local_iterator end(size_type __n) + {return local_iterator(nullptr, __n, bucket_count());} + _LIBCPP_INLINE_VISIBILITY const_local_iterator cbegin(size_type __n) const + {return const_local_iterator(__bucket_list_[__n], __n, bucket_count());} + _LIBCPP_INLINE_VISIBILITY const_local_iterator cend(size_type __n) const + {return const_local_iterator(nullptr, __n, bucket_count());} +private: + void __rehash(size_type __n); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + template + __node_holder __construct_node(_Args&& ...__args); +#endif // _LIBCPP_HAS_NO_VARIADICS + __node_holder __construct_node(value_type&& __v, size_t __hash); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + __node_holder __construct_node(const value_type& __v); +#endif + __node_holder __construct_node(const value_type& __v, size_t __hash); + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __hash_table& __u) + {__copy_assign_alloc(__u, integral_constant());} + void __copy_assign_alloc(const __hash_table& __u, true_type); + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __hash_table& __u, false_type) {} + + void __move_assign(__hash_table& __u, false_type); + void __move_assign(__hash_table& __u, true_type) + _NOEXCEPT_( + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value); + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table& __u) + _NOEXCEPT_( + !__node_traits::propagate_on_container_move_assignment::value || + (is_nothrow_move_assignable<__pointer_allocator>::value && + is_nothrow_move_assignable<__node_allocator>::value)) + {__move_assign_alloc(__u, integral_constant());} + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table& __u, true_type) + _NOEXCEPT_( + is_nothrow_move_assignable<__pointer_allocator>::value && + is_nothrow_move_assignable<__node_allocator>::value) + { + __bucket_list_.get_deleter().__alloc() = + _VSTD::move(__u.__bucket_list_.get_deleter().__alloc()); + __node_alloc() = _VSTD::move(__u.__node_alloc()); + } + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {} + + template + _LIBCPP_INLINE_VISIBILITY + static + void + __swap_alloc(_A& __x, _A& __y) + _NOEXCEPT_( + !allocator_traits<_A>::propagate_on_container_swap::value || + __is_nothrow_swappable<_A>::value) + { + __swap_alloc(__x, __y, + integral_constant::propagate_on_container_swap::value + >()); + } + + template + _LIBCPP_INLINE_VISIBILITY + static + void + __swap_alloc(_A& __x, _A& __y, true_type) + _NOEXCEPT_(__is_nothrow_swappable<_A>::value) + { + using _VSTD::swap; + swap(__x, __y); + } + + template + _LIBCPP_INLINE_VISIBILITY + static + void + __swap_alloc(_A& __x, _A& __y, false_type) _NOEXCEPT {} + + void __deallocate(__node_pointer __np) _NOEXCEPT; + __node_pointer __detach() _NOEXCEPT; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() + _NOEXCEPT_( + is_nothrow_default_constructible<__bucket_list>::value && + is_nothrow_default_constructible<__first_node>::value && + is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value) + : __p2_(0), + __p3_(1.0f) +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, + const key_equal& __eql) + : __bucket_list_(nullptr, __bucket_list_deleter()), + __p1_(), + __p2_(0, __hf), + __p3_(1.0f, __eql) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__node_allocator(__a)), + __p2_(0, __hf), + __p3_(1.0f, __eql) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__node_allocator(__a)), + __p2_(0), + __p3_(1.0f) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) + : __bucket_list_(nullptr, + __bucket_list_deleter(allocator_traits<__pointer_allocator>:: + select_on_container_copy_construction( + __u.__bucket_list_.get_deleter().__alloc()), 0)), + __p1_(allocator_traits<__node_allocator>:: + select_on_container_copy_construction(__u.__node_alloc())), + __p2_(0, __u.hash_function()), + __p3_(__u.__p3_) +{ +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__node_allocator(__a)), + __p2_(0, __u.hash_function()), + __p3_(__u.__p3_) +{ +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) + _NOEXCEPT_( + is_nothrow_move_constructible<__bucket_list>::value && + is_nothrow_move_constructible<__first_node>::value && + is_nothrow_move_constructible::value && + is_nothrow_move_constructible::value) + : __bucket_list_(_VSTD::move(__u.__bucket_list_)), + __p1_(_VSTD::move(__u.__p1_)), + __p2_(_VSTD::move(__u.__p2_)), + __p3_(_VSTD::move(__u.__p3_)) +{ + if (size() > 0) + { + __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] = + static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + __u.__p1_.first().__next_ = nullptr; + __u.size() = 0; + } +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, + const allocator_type& __a) + : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), + __p1_(__node_allocator(__a)), + __p2_(0, _VSTD::move(__u.hash_function())), + __p3_(_VSTD::move(__u.__p3_)) +{ + if (__a == allocator_type(__u.__node_alloc())) + { + __bucket_list_.reset(__u.__bucket_list_.release()); + __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); + __u.__bucket_list_.get_deleter().size() = 0; + if (__u.size() > 0) + { + __p1_.first().__next_ = __u.__p1_.first().__next_; + __u.__p1_.first().__next_ = nullptr; + __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] = + static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + size() = __u.size(); + __u.size() = 0; + } + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() +{ + __deallocate(__p1_.first().__next_); +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc( + const __hash_table& __u, true_type) +{ + if (__node_alloc() != __u.__node_alloc()) + { + clear(); + __bucket_list_.reset(); + __bucket_list_.get_deleter().size() = 0; + } + __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc(); + __node_alloc() = __u.__node_alloc(); +} + +template +__hash_table<_Tp, _Hash, _Equal, _Alloc>& +__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u) +{ + if (this != &__u) + { + __copy_assign_alloc(__u); + hash_function() = __u.hash_function(); + key_eq() = __u.key_eq(); + max_load_factor() = __u.max_load_factor(); + __assign_multi(__u.begin(), __u.end()); + } + return *this; +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate(__node_pointer __np) + _NOEXCEPT +{ + __node_allocator& __na = __node_alloc(); + while (__np != nullptr) + { + __node_pointer __next = __np->__next_; + __node_traits::destroy(__na, _VSTD::addressof(__np->__value_)); + __node_traits::deallocate(__na, __np, 1); + __np = __next; + } +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_pointer +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT +{ + size_type __bc = bucket_count(); + for (size_type __i = 0; __i < __bc; ++__i) + __bucket_list_[__i] = nullptr; + size() = 0; + __node_pointer __cache = __p1_.first().__next_; + __p1_.first().__next_ = nullptr; + return __cache; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( + __hash_table& __u, true_type) + _NOEXCEPT_( + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value) +{ + clear(); + __bucket_list_.reset(__u.__bucket_list_.release()); + __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); + __u.__bucket_list_.get_deleter().size() = 0; + __move_assign_alloc(__u); + size() = __u.size(); + hash_function() = _VSTD::move(__u.hash_function()); + max_load_factor() = __u.max_load_factor(); + key_eq() = _VSTD::move(__u.key_eq()); + __p1_.first().__next_ = __u.__p1_.first().__next_; + if (size() > 0) + { + __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] = + static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + __u.__p1_.first().__next_ = nullptr; + __u.size() = 0; + } +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( + __hash_table& __u, false_type) +{ + if (__node_alloc() == __u.__node_alloc()) + __move_assign(__u, true_type()); + else + { + hash_function() = _VSTD::move(__u.hash_function()); + key_eq() = _VSTD::move(__u.key_eq()); + max_load_factor() = __u.max_load_factor(); + if (bucket_count() != 0) + { + __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + const_iterator __i = __u.begin(); + while (__cache != nullptr && __u.size() != 0) + { + __cache->__value_ = _VSTD::move(__u.remove(__i++)->__value_); + __node_pointer __next = __cache->__next_; + __node_insert_multi(__cache); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __deallocate(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __deallocate(__cache); + } + const_iterator __i = __u.begin(); + while (__u.size() != 0) + { + __node_holder __h = + __construct_node(_VSTD::move(__u.remove(__i++)->__value_)); + __node_insert_multi(__h.get()); + __h.release(); + } + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__hash_table<_Tp, _Hash, _Equal, _Alloc>& +__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value) +{ + __move_assign(__u, integral_constant()); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first, + _InputIterator __last) +{ + if (bucket_count() != 0) + { + __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__value_ = *__first; + __node_pointer __next = __cache->__next_; + __node_insert_unique(__cache); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __deallocate(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __deallocate(__cache); + } + for (; __first != __last; ++__first) + __insert_unique(*__first); +} + +template +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, + _InputIterator __last) +{ + if (bucket_count() != 0) + { + __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__value_ = *__first; + __node_pointer __next = __cache->__next_; + __node_insert_multi(__cache); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __deallocate(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __deallocate(__cache); + } + for (; __first != __last; ++__first) + __insert_multi(*__first); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT +{ + return iterator(__p1_.first().__next_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT +{ + return iterator(nullptr); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT +{ + return const_iterator(__p1_.first().__next_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT +{ + return const_iterator(nullptr); +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT +{ + if (size() > 0) + { + __deallocate(__p1_.first().__next_); + __p1_.first().__next_ = nullptr; + size_type __bc = bucket_count(); + for (size_type __i = 0; __i < __bc; ++__i) + __bucket_list_[__i] = nullptr; + size() = 0; + } +} + +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd) +{ + __nd->__hash_ = hash_function()(__nd->__value_); + size_type __bc = bucket_count(); + bool __inserted = false; + __node_pointer __ndptr; + size_t __chash; + if (__bc != 0) + { + __chash = __nd->__hash_ % __bc; + __ndptr = __bucket_list_[__chash]; + if (__ndptr != nullptr) + { + for (__ndptr = __ndptr->__next_; __ndptr != nullptr && + __ndptr->__hash_ % __bc == __chash; + __ndptr = __ndptr->__next_) + { + if (key_eq()(__ndptr->__value_, __nd->__value_)) + goto __done; + } + } + } + { + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_VSTD::max(2 * __bc + 1, + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + __chash = __nd->__hash_ % __bc; + } + // insert_after __bucket_list_[__chash], or __first_node if bucket is null + __node_pointer __pn = __bucket_list_[__chash]; + if (__pn == nullptr) + { + __pn = static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + __nd->__next_ = __pn->__next_; + __pn->__next_ = __nd; + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__nd->__next_ != nullptr) + __bucket_list_[__nd->__next_->__hash_ % __bc] = __nd; + } + else + { + __nd->__next_ = __pn->__next_; + __pn->__next_ = __nd; + } + __ndptr = __nd; + // increment size + ++size(); + __inserted = true; + } +__done: + return pair(iterator(__ndptr), __inserted); +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp) +{ + __cp->__hash_ = hash_function()(__cp->__value_); + size_type __bc = bucket_count(); + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_VSTD::max(2 * __bc + 1, + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + } + size_t __chash = __cp->__hash_ % __bc; + __node_pointer __pn = __bucket_list_[__chash]; + if (__pn == nullptr) + { + __pn = static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + __cp->__next_ = __pn->__next_; + __pn->__next_ = __cp; + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__cp->__next_ != nullptr) + __bucket_list_[__cp->__next_->__hash_ % __bc] = __cp; + } + else + { + for (bool __found = false; __pn->__next_ != nullptr && + __pn->__next_->__hash_ % __bc == __chash; + __pn = __pn->__next_) + { + // __found key_eq() action + // false false loop + // true true loop + // false true set __found to true + // true false break + if (__found != (__pn->__next_->__hash_ == __cp->__hash_ && + key_eq()(__pn->__next_->__value_, __cp->__value_))) + { + if (!__found) + __found = true; + else + break; + } + } + __cp->__next_ = __pn->__next_; + __pn->__next_ = __cp; + if (__cp->__next_ != nullptr) + { + size_t __nhash = __cp->__next_->__hash_ % __bc; + if (__nhash != __chash) + __bucket_list_[__nhash] = __cp; + } + } + ++size(); + return iterator(__cp); +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( + const_iterator __p, __node_pointer __cp) +{ + if (__p != end() && key_eq()(*__p, __cp->__value_)) + { + __node_pointer __np = const_cast<__node_pointer>(__p.__node_); + __cp->__hash_ = __np->__hash_; + size_type __bc = bucket_count(); + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_VSTD::max(2 * __bc + 1, + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + } + size_t __chash = __cp->__hash_ % __bc; + __node_pointer __pp = __bucket_list_[__chash]; + while (__pp->__next_ != __np) + __pp = __pp->__next_; + __cp->__next_ = __np; + __pp->__next_ = __cp; + ++size(); + return iterator(__cp); + } + return __node_insert_multi(__cp); +} + +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(const value_type& __x) +{ + size_t __hash = hash_function()(__x); + size_type __bc = bucket_count(); + bool __inserted = false; + __node_pointer __nd; + size_t __chash; + if (__bc != 0) + { + __chash = __hash % __bc; + __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + __nd->__hash_ % __bc == __chash; + __nd = __nd->__next_) + { + if (key_eq()(__nd->__value_, __x)) + goto __done; + } + } + } + { + __node_holder __h = __construct_node(__x, __hash); + if (size()+1 > __bc * max_load_factor() || __bc == 0) + { + rehash(_VSTD::max(2 * __bc + 1, + size_type(ceil(float(size() + 1) / max_load_factor())))); + __bc = bucket_count(); + __chash = __hash % __bc; + } + // insert_after __bucket_list_[__chash], or __first_node if bucket is null + __node_pointer __pn = __bucket_list_[__chash]; + if (__pn == nullptr) + { + __pn = static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + __h->__next_ = __pn->__next_; + __pn->__next_ = __h.get(); + // fix up __bucket_list_ + __bucket_list_[__chash] = __pn; + if (__h->__next_ != nullptr) + __bucket_list_[__h->__next_->__hash_ % __bc] = __h.get(); + } + else + { + __h->__next_ = __pn->__next_; + __pn->__next_ = __h.get(); + } + __nd = __h.release(); + // increment size + ++size(); + __inserted = true; + } +__done: + return pair(iterator(__nd), __inserted); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique(_Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + pair __r = __node_insert_unique(__h.get()); + if (__r.second) + __h.release(); + return __r; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + iterator __r = __node_insert_multi(__h.get()); + __h.release(); + return __r; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi( + const_iterator __p, _Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + iterator __r = __node_insert_multi(__p, __h.get()); + __h.release(); + return __r; +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template +template +pair::iterator, bool> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(_P&& __x) +{ + __node_holder __h = __construct_node(_VSTD::forward<_P>(__x)); + pair __r = __node_insert_unique(__h.get()); + if (__r.second) + __h.release(); + return __r; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(_P&& __x) +{ + __node_holder __h = __construct_node(_VSTD::forward<_P>(__x)); + iterator __r = __node_insert_multi(__h.get()); + __h.release(); + return __r; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p, + _P&& __x) +{ + __node_holder __h = __construct_node(_VSTD::forward<_P>(__x)); + iterator __r = __node_insert_multi(__p, __h.get()); + __h.release(); + return __r; +} + +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const value_type& __x) +{ + __node_holder __h = __construct_node(__x); + iterator __r = __node_insert_multi(__h.get()); + __h.release(); + return __r; +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p, + const value_type& __x) +{ + __node_holder __h = __construct_node(__x); + iterator __r = __node_insert_multi(__p, __h.get()); + __h.release(); + return __r; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n) +{ + __n = __next_prime(_VSTD::max(__n, size() > 0)); + size_type __bc = bucket_count(); + if (__n > __bc) + __rehash(__n); + else + { + __n = _VSTD::max + ( + __n, + __next_prime(size_t(ceil(float(size()) / max_load_factor()))) + ); + if (__n < __bc) + __rehash(__n); + } +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) +{ + __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); + __bucket_list_.reset(__nbc > 0 ? + __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); + __bucket_list_.get_deleter().size() = __nbc; + if (__nbc > 0) + { + for (size_type __i = 0; __i < __nbc; ++__i) + __bucket_list_[__i] = nullptr; + __node_pointer __pp(static_cast<__node_pointer>(_VSTD::addressof(__p1_.first()))); + __node_pointer __cp = __pp->__next_; + if (__cp != nullptr) + { + size_type __chash = __cp->__hash_ % __nbc; + __bucket_list_[__chash] = __pp; + size_type __phash = __chash; + for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr; + __cp = __pp->__next_) + { + __chash = __cp->__hash_ % __nbc; + if (__chash == __phash) + __pp = __cp; + else + { + if (__bucket_list_[__chash] == nullptr) + { + __bucket_list_[__chash] = __pp; + __pp = __cp; + __phash = __chash; + } + else + { + __node_pointer __np = __cp; + for (; __np->__next_ != nullptr && + key_eq()(__cp->__value_, __np->__next_->__value_); + __np = __np->__next_) + ; + __pp->__next_ = __np->__next_; + __np->__next_ = __bucket_list_[__chash]->__next_; + __bucket_list_[__chash]->__next_ = __cp; + + } + } + } + } + } +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) +{ + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + if (__bc != 0) + { + size_t __chash = __hash % __bc; + __node_pointer __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + __nd->__hash_ % __bc == __chash; + __nd = __nd->__next_) + { + if (key_eq()(__nd->__value_, __k)) + return iterator(__nd); + } + } + } + return end(); +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const +{ + size_t __hash = hash_function()(__k); + size_type __bc = bucket_count(); + if (__bc != 0) + { + size_t __chash = __hash % __bc; + __node_const_pointer __nd = __bucket_list_[__chash]; + if (__nd != nullptr) + { + for (__nd = __nd->__next_; __nd != nullptr && + __nd->__hash_ % __bc == __chash; + __nd = __nd->__next_) + { + if (key_eq()(__nd->__value_, __k)) + return const_iterator(__nd); + } + } + + } + return end(); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_Args>(__args)...); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = hash_function()(__h->__value_); + __h->__next_ = nullptr; + return __h; +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(value_type&& __v, + size_t __hash) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::move(__v)); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = __hash; + __h->__next_ = nullptr; + return _VSTD::move(__h); +} + +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const value_type& __v) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = hash_function()(__h->__value_); + __h->__next_ = nullptr; + return _VSTD::move(__h); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const value_type& __v, + size_t __hash) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v); + __h.get_deleter().__value_constructed = true; + __h->__hash_ = __hash; + __h->__next_ = nullptr; + return _VSTD::move(__h); +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) +{ + __node_pointer __np = const_cast<__node_pointer>(__p.__node_); + iterator __r(__np); + ++__r; + remove(__p); + return __r; +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator +__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, + const_iterator __last) +{ + for (const_iterator __p = __first; __first != __last; __p = __first) + { + ++__first; + erase(__p); + } + __node_pointer __np = const_cast<__node_pointer>(__last.__node_); + return iterator (__np); +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k) +{ + iterator __i = find(__k); + if (__i == end()) + return 0; + erase(__i); + return 1; +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k) +{ + size_type __r = 0; + iterator __i = find(__k); + if (__i != end()) + { + iterator __e = end(); + do + { + erase(__i++); + ++__r; + } while (__i != __e && key_eq()(*__i, __k)); + } + return __r; +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder +__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT +{ + // current node + __node_pointer __cn = const_cast<__node_pointer>(__p.__node_); + size_type __bc = bucket_count(); + size_t __chash = __cn->__hash_ % __bc; + // find previous node + __node_pointer __pn = __bucket_list_[__chash]; + for (; __pn->__next_ != __cn; __pn = __pn->__next_) + ; + // Fix up __bucket_list_ + // if __pn is not in same bucket (before begin is not in same bucket) && + // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) + if (__pn == _VSTD::addressof(__p1_.first()) || __pn->__hash_ % __bc != __chash) + { + if (__cn->__next_ == nullptr || __cn->__next_->__hash_ % __bc != __chash) + __bucket_list_[__chash] = nullptr; + } + // if __cn->__next_ is not in same bucket (nullptr is in same bucket) + if (__cn->__next_ != nullptr) + { + size_t __nhash = __cn->__next_->__hash_ % __bc; + if (__nhash != __chash) + __bucket_list_[__nhash] = __pn; + } + // remove __cn + __pn->__next_ = __cn->__next_; + __cn->__next_ = nullptr; + --size(); + return __node_holder(__cn, _D(__node_alloc(), true)); +} + +template +template +inline _LIBCPP_INLINE_VISIBILITY +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const +{ + return static_cast(find(__k) != end()); +} + +template +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const +{ + size_type __r = 0; + const_iterator __i = find(__k); + if (__i != end()) + { + const_iterator __e = end(); + do + { + ++__i; + ++__r; + } while (__i != __e && key_eq()(*__i, __k)); + } + return __r; +} + +template +template +pair::iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( + const _Key& __k) +{ + iterator __i = find(__k); + iterator __j = __i; + if (__i != end()) + ++__j; + return pair(__i, __j); +} + +template +template +pair::const_iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( + const _Key& __k) const +{ + const_iterator __i = find(__k); + const_iterator __j = __i; + if (__i != end()) + ++__j; + return pair(__i, __j); +} + +template +template +pair::iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( + const _Key& __k) +{ + iterator __i = find(__k); + iterator __j = __i; + if (__i != end()) + { + iterator __e = end(); + do + { + ++__j; + } while (__j != __e && key_eq()(*__j, __k)); + } + return pair(__i, __j); +} + +template +template +pair::const_iterator, + typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( + const _Key& __k) const +{ + const_iterator __i = find(__k); + const_iterator __j = __i; + if (__i != end()) + { + const_iterator __e = end(); + do + { + ++__j; + } while (__j != __e && key_eq()(*__j, __k)); + } + return pair(__i, __j); +} + +template +void +__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) + _NOEXCEPT_( + (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value || + __is_nothrow_swappable<__pointer_allocator>::value) && + (!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) && + __is_nothrow_swappable::value && + __is_nothrow_swappable::value) +{ + { + __node_pointer_pointer __npp = __bucket_list_.release(); + __bucket_list_.reset(__u.__bucket_list_.release()); + __u.__bucket_list_.reset(__npp); + } + _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); + __swap_alloc(__bucket_list_.get_deleter().__alloc(), + __u.__bucket_list_.get_deleter().__alloc()); + __swap_alloc(__node_alloc(), __u.__node_alloc()); + _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_); + __p2_.swap(__u.__p2_); + __p3_.swap(__u.__p3_); + if (size() > 0) + __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] = + static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + if (__u.size() > 0) + __u.__bucket_list_[__u.__p1_.first().__next_->__hash_ % __u.bucket_count()] = + static_cast<__node_pointer>(_VSTD::addressof(__u.__p1_.first())); +} + +template +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type +__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const +{ + __node_const_pointer __np = __bucket_list_[__n]; + size_type __bc = bucket_count(); + size_type __r = 0; + if (__np != nullptr) + { + for (__np = __np->__next_; __np != nullptr && + __np->__hash_ % __bc == __n; + __np = __np->__next_, ++__r) + ; + } + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x, + __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP__HASH_TABLE diff --git a/contrib/libc++/include/__locale b/contrib/libc++/include/__locale new file mode 100644 index 000000000000..28cb3ef65292 --- /dev/null +++ b/contrib/libc++/include/__locale @@ -0,0 +1,1414 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE +#define _LIBCPP___LOCALE + +#include <__config> +#include +#include +#include +#include +#include +#include +#include +#if _WIN32 +# include +#elif (__GLIBC__ || __APPLE__ || __FreeBSD__) +# include +#endif // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD_ + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +class locale; + +template bool has_facet(const locale&) _NOEXCEPT; +template const _Facet& use_facet(const locale&); + +class _LIBCPP_VISIBLE locale +{ +public: + // types: + class facet; + class id; + + typedef int category; + static const category // values assigned here are for exposition only + none = 0, + collate = LC_COLLATE_MASK, + ctype = LC_CTYPE_MASK, + monetary = LC_MONETARY_MASK, + numeric = LC_NUMERIC_MASK, + time = LC_TIME_MASK, + messages = LC_MESSAGES_MASK, + all = collate | ctype | monetary | numeric | time | messages; + + // construct/copy/destroy: + locale() _NOEXCEPT; + locale(const locale&) _NOEXCEPT; + explicit locale(const char*); + explicit locale(const string&); + locale(const locale&, const char*, category); + locale(const locale&, const string&, category); + template + _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*); + locale(const locale&, const locale&, category); + + ~locale(); + + const locale& operator=(const locale&) _NOEXCEPT; + + template locale combine(const locale&) const; + + // locale operations: + string name() const; + bool operator==(const locale&) const; + bool operator!=(const locale& __y) const {return !(*this == __y);} + template + bool operator()(const basic_string<_CharT, _Traits, _Allocator>&, + const basic_string<_CharT, _Traits, _Allocator>&) const; + + // global locale objects: + static locale global(const locale&); + static const locale& classic(); + +private: + class __imp; + __imp* __locale_; + + void __install_ctor(const locale&, facet*, long); + static locale& __global(); + bool has_facet(id&) const; + const facet* use_facet(id&) const; + + template friend bool has_facet(const locale&) _NOEXCEPT; + template friend const _Facet& use_facet(const locale&); +}; + +class _LIBCPP_VISIBLE locale::facet + : public __shared_count +{ +protected: + _LIBCPP_INLINE_VISIBILITY + explicit facet(size_t __refs = 0) + : __shared_count(static_cast(__refs)-1) {} + + virtual ~facet(); + +// facet(const facet&) = delete; // effectively done in __shared_count +// void operator=(const facet&) = delete; +private: + virtual void __on_zero_shared() _NOEXCEPT; +}; + +class _LIBCPP_VISIBLE locale::id +{ + once_flag __flag_; + int32_t __id_; + + static int32_t __next_id; +public: + _LIBCPP_INLINE_VISIBILITY id() {} +private: + void __init(); + void operator=(const id&); // = delete; + id(const id&); // = delete; +public: // only needed for tests + long __get(); + + friend class locale; + friend class locale::__imp; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +locale::locale(const locale& __other, _Facet* __f) +{ + __install_ctor(__other, __f, __f ? __f->id.__get() : 0); +} + +template +locale +locale::combine(const locale& __other) const +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (!_VSTD::has_facet<_Facet>(__other)) + throw runtime_error("locale::combine: locale missing facet"); +#endif // _LIBCPP_NO_EXCEPTIONS + return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other))); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +has_facet(const locale& __l) _NOEXCEPT +{ + return __l.has_facet(_Facet::id); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +const _Facet& +use_facet(const locale& __l) +{ + return static_cast(*__l.use_facet(_Facet::id)); +} + +// template class collate; + +template +class _LIBCPP_VISIBLE collate + : public locale::facet +{ +public: + typedef _CharT char_type; + typedef basic_string string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit collate(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_INLINE_VISIBILITY + int compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const + { + return do_compare(__lo1, __hi1, __lo2, __hi2); + } + + _LIBCPP_INLINE_VISIBILITY + string_type transform(const char_type* __lo, const char_type* __hi) const + { + return do_transform(__lo, __hi); + } + + _LIBCPP_INLINE_VISIBILITY + long hash(const char_type* __lo, const char_type* __hi) const + { + return do_hash(__lo, __hi); + } + + static locale::id id; + +protected: + ~collate(); + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const + {return string_type(__lo, __hi);} + virtual long do_hash(const char_type* __lo, const char_type* __hi) const; +}; + +template locale::id collate<_CharT>::id; + +template +collate<_CharT>::~collate() +{ +} + +template +int +collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const +{ + for (; __lo2 != __hi2; ++__lo1, ++__lo2) + { + if (__lo1 == __hi1 || *__lo1 < *__lo2) + return -1; + if (*__lo2 < *__lo1) + return 1; + } + return __lo1 != __hi1; +} + +template +long +collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const +{ + size_t __h = 0; + const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8; + const size_t __mask = size_t(0xF) << (__sr + 4); + for(const char_type* __p = __lo; __p != __hi; ++__p) + { + __h = (__h << 4) + *__p; + size_t __g = __h & __mask; + __h ^= __g | (__g >> __sr); + } + return static_cast(__h); +} + +extern template class _LIBCPP_VISIBLE collate; +extern template class _LIBCPP_VISIBLE collate; + +// template class collate_byname; + +template class _LIBCPP_VISIBLE collate_byname; + +template <> +class _LIBCPP_VISIBLE collate_byname + : public collate +{ + locale_t __l; +public: + typedef char char_type; + typedef basic_string string_type; + + explicit collate_byname(const char* __n, size_t __refs = 0); + explicit collate_byname(const string& __n, size_t __refs = 0); + +protected: + ~collate_byname(); + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; +}; + +template <> +class _LIBCPP_VISIBLE collate_byname + : public collate +{ + locale_t __l; +public: + typedef wchar_t char_type; + typedef basic_string string_type; + + explicit collate_byname(const char* __n, size_t __refs = 0); + explicit collate_byname(const string& __n, size_t __refs = 0); + +protected: + ~collate_byname(); + + virtual int do_compare(const char_type* __lo1, const char_type* __hi1, + const char_type* __lo2, const char_type* __hi2) const; + virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; +}; + +template +bool +locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, + const basic_string<_CharT, _Traits, _Allocator>& __y) const +{ + return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare( + __x.data(), __x.data() + __x.size(), + __y.data(), __y.data() + __y.size()) < 0; +} + +// template class ctype + +class _LIBCPP_VISIBLE ctype_base +{ +public: +#if __GLIBC__ + typedef unsigned short mask; + static const mask space = _ISspace; + static const mask print = _ISprint; + static const mask cntrl = _IScntrl; + static const mask upper = _ISupper; + static const mask lower = _ISlower; + static const mask alpha = _ISalpha; + static const mask digit = _ISdigit; + static const mask punct = _ISpunct; + static const mask xdigit = _ISxdigit; + static const mask blank = _ISblank; +#elif _WIN32 + typedef unsigned short mask; + static const mask space = _SPACE; + static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT; + static const mask cntrl = _CONTROL; + static const mask upper = _UPPER; + static const mask lower = _LOWER; + static const mask alpha = _ALPHA; + static const mask digit = _DIGIT; + static const mask punct = _PUNCT; + static const mask xdigit = _HEX; + static const mask blank = _BLANK; +#elif (__APPLE__ || __FreeBSD__) +#if __APPLE__ + typedef __uint32_t mask; +#elif __FreeBSD__ + typedef unsigned long mask; +#endif + static const mask space = _CTYPE_S; + static const mask print = _CTYPE_R; + static const mask cntrl = _CTYPE_C; + static const mask upper = _CTYPE_U; + static const mask lower = _CTYPE_L; + static const mask alpha = _CTYPE_A; + static const mask digit = _CTYPE_D; + static const mask punct = _CTYPE_P; + static const mask xdigit = _CTYPE_X; + static const mask blank = _CTYPE_B; +#else // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ + typedef unsigned long mask; + static const mask space = 1<<0; + static const mask print = 1<<1; + static const mask cntrl = 1<<2; + static const mask upper = 1<<3; + static const mask lower = 1<<4; + static const mask alpha = 1<<5; + static const mask digit = 1<<6; + static const mask punct = 1<<7; + static const mask xdigit = 1<<8; + static const mask blank = 1<<9; +#endif // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ + static const mask alnum = alpha | digit; + static const mask graph = alnum | punct; + + _LIBCPP_ALWAYS_INLINE ctype_base() {} +}; + +template class _LIBCPP_VISIBLE ctype; + +template <> +class _LIBCPP_VISIBLE ctype + : public locale::facet, + public ctype_base +{ +public: + typedef wchar_t char_type; + + _LIBCPP_ALWAYS_INLINE + explicit ctype(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE + bool is(mask __m, char_type __c) const + { + return do_is(__m, __c); + } + + _LIBCPP_ALWAYS_INLINE + const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const + { + return do_is(__low, __high, __vec); + } + + _LIBCPP_ALWAYS_INLINE + const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const + { + return do_scan_is(__m, __low, __high); + } + + _LIBCPP_ALWAYS_INLINE + const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const + { + return do_scan_not(__m, __low, __high); + } + + _LIBCPP_ALWAYS_INLINE + char_type toupper(char_type __c) const + { + return do_toupper(__c); + } + + _LIBCPP_ALWAYS_INLINE + const char_type* toupper(char_type* __low, const char_type* __high) const + { + return do_toupper(__low, __high); + } + + _LIBCPP_ALWAYS_INLINE + char_type tolower(char_type __c) const + { + return do_tolower(__c); + } + + _LIBCPP_ALWAYS_INLINE + const char_type* tolower(char_type* __low, const char_type* __high) const + { + return do_tolower(__low, __high); + } + + _LIBCPP_ALWAYS_INLINE + char_type widen(char __c) const + { + return do_widen(__c); + } + + _LIBCPP_ALWAYS_INLINE + const char* widen(const char* __low, const char* __high, char_type* __to) const + { + return do_widen(__low, __high, __to); + } + + _LIBCPP_ALWAYS_INLINE + char narrow(char_type __c, char __dfault) const + { + return do_narrow(__c, __dfault); + } + + _LIBCPP_ALWAYS_INLINE + const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const + { + return do_narrow(__low, __high, __dfault, __to); + } + + static locale::id id; + +protected: + ~ctype(); + virtual bool do_is(mask __m, char_type __c) const; + virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; + virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; + virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; + virtual char do_narrow(char_type, char __dfault) const; + virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; +}; + +template <> +class _LIBCPP_VISIBLE ctype + : public locale::facet, public ctype_base +{ + const mask* __tab_; + bool __del_; +public: + typedef char char_type; + + explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0); + + _LIBCPP_ALWAYS_INLINE + bool is(mask __m, char_type __c) const + { + return isascii(__c) ? __tab_[__c] & __m : false; + } + + _LIBCPP_ALWAYS_INLINE + const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const + { + for (; __low != __high; ++__low, ++__vec) + *__vec = isascii(*__low) ? __tab_[*__low] : 0; + return __low; + } + + _LIBCPP_ALWAYS_INLINE + const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const + { + for (; __low != __high; ++__low) + if (isascii(*__low) && (__tab_[*__low] & __m)) + break; + return __low; + } + + _LIBCPP_ALWAYS_INLINE + const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const + { + for (; __low != __high; ++__low) + if (!(isascii(*__low) && (__tab_[*__low] & __m))) + break; + return __low; + } + + _LIBCPP_ALWAYS_INLINE + char_type toupper(char_type __c) const + { + return do_toupper(__c); + } + + _LIBCPP_ALWAYS_INLINE + const char_type* toupper(char_type* __low, const char_type* __high) const + { + return do_toupper(__low, __high); + } + + _LIBCPP_ALWAYS_INLINE + char_type tolower(char_type __c) const + { + return do_tolower(__c); + } + + _LIBCPP_ALWAYS_INLINE + const char_type* tolower(char_type* __low, const char_type* __high) const + { + return do_tolower(__low, __high); + } + + _LIBCPP_ALWAYS_INLINE + char_type widen(char __c) const + { + return do_widen(__c); + } + + _LIBCPP_ALWAYS_INLINE + const char* widen(const char* __low, const char* __high, char_type* __to) const + { + return do_widen(__low, __high, __to); + } + + _LIBCPP_ALWAYS_INLINE + char narrow(char_type __c, char __dfault) const + { + return do_narrow(__c, __dfault); + } + + _LIBCPP_ALWAYS_INLINE + const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const + { + return do_narrow(__low, __high, __dfault, __to); + } + + static locale::id id; + +#ifdef _CACHED_RUNES + static const size_t table_size = _CACHED_RUNES; +#else + static const size_t table_size = 256; // FIXME: Don't hardcode this. +#endif + _LIBCPP_ALWAYS_INLINE const mask* table() const _NOEXCEPT {return __tab_;} + static const mask* classic_table() _NOEXCEPT; +#if defined(__GLIBC__) + static const int* __classic_upper_table() _NOEXCEPT; + static const int* __classic_lower_table() _NOEXCEPT; +#endif + +protected: + ~ctype(); + virtual char_type do_toupper(char_type __c) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type __c) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char __c) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const; + virtual char do_narrow(char_type __c, char __dfault) const; + virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const; +}; + +// template class ctype_byname; + +template class _LIBCPP_VISIBLE ctype_byname; + +template <> +class _LIBCPP_VISIBLE ctype_byname + : public ctype +{ + locale_t __l; + +public: + explicit ctype_byname(const char*, size_t = 0); + explicit ctype_byname(const string&, size_t = 0); + +protected: + ~ctype_byname(); + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; +}; + +template <> +class _LIBCPP_VISIBLE ctype_byname + : public ctype +{ + locale_t __l; + +public: + explicit ctype_byname(const char*, size_t = 0); + explicit ctype_byname(const string&, size_t = 0); + +protected: + ~ctype_byname(); + virtual bool do_is(mask __m, char_type __c) const; + virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; + virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; + virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; + virtual char_type do_toupper(char_type) const; + virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; + virtual char_type do_tolower(char_type) const; + virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; + virtual char_type do_widen(char) const; + virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; + virtual char do_narrow(char_type, char __dfault) const; + virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +isspace(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::space, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +isprint(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::print, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +iscntrl(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::cntrl, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +isupper(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::upper, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +islower(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::lower, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +isalpha(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::alpha, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +isdigit(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::digit, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +ispunct(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::punct, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +isxdigit(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::xdigit, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +isalnum(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::alnum, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +isgraph(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).is(ctype_base::graph, __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_CharT +toupper(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).toupper(__c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_CharT +tolower(_CharT __c, const locale& __loc) +{ + return use_facet >(__loc).tolower(__c); +} + +// codecvt_base + +class _LIBCPP_VISIBLE codecvt_base +{ +public: + _LIBCPP_ALWAYS_INLINE codecvt_base() {} + enum result {ok, partial, error, noconv}; +}; + +// template class codecvt; + +template class _LIBCPP_VISIBLE codecvt; + +// template <> class codecvt + +template <> +class _LIBCPP_VISIBLE codecvt + : public locale::facet, + public codecvt_base +{ +public: + typedef char intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCPP_ALWAYS_INLINE + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCPP_ALWAYS_INLINE + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCPP_ALWAYS_INLINE + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCPP_ALWAYS_INLINE + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template <> class codecvt + +template <> +class _LIBCPP_VISIBLE codecvt + : public locale::facet, + public codecvt_base +{ + locale_t __l; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + explicit codecvt(size_t __refs = 0); + + _LIBCPP_ALWAYS_INLINE + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCPP_ALWAYS_INLINE + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCPP_ALWAYS_INLINE + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCPP_ALWAYS_INLINE + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + explicit codecvt(const char*, size_t __refs = 0); + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template <> class codecvt + +template <> +class _LIBCPP_VISIBLE codecvt + : public locale::facet, + public codecvt_base +{ +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCPP_ALWAYS_INLINE + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCPP_ALWAYS_INLINE + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCPP_ALWAYS_INLINE + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCPP_ALWAYS_INLINE + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template <> class codecvt + +template <> +class _LIBCPP_VISIBLE codecvt + : public locale::facet, + public codecvt_base +{ +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit codecvt(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE + result out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + result unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const + { + return do_unshift(__st, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + result in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const + { + return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); + } + + _LIBCPP_ALWAYS_INLINE + int encoding() const _NOEXCEPT + { + return do_encoding(); + } + + _LIBCPP_ALWAYS_INLINE + bool always_noconv() const _NOEXCEPT + { + return do_always_noconv(); + } + + _LIBCPP_ALWAYS_INLINE + int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const + { + return do_length(__st, __frm, __end, __mx); + } + + _LIBCPP_ALWAYS_INLINE + int max_length() const _NOEXCEPT + { + return do_max_length(); + } + + static locale::id id; + +protected: + _LIBCPP_ALWAYS_INLINE + explicit codecvt(const char*, size_t __refs = 0) + : locale::facet(__refs) {} + + ~codecvt(); + + virtual result do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const _NOEXCEPT; + virtual bool do_always_noconv() const _NOEXCEPT; + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; + virtual int do_max_length() const _NOEXCEPT; +}; + +// template class codecvt_byname + +template +class _LIBCPP_VISIBLE codecvt_byname + : public codecvt<_InternT, _ExternT, _StateT> +{ +public: + _LIBCPP_ALWAYS_INLINE + explicit codecvt_byname(const char* __nm, size_t __refs = 0) + : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {} + _LIBCPP_ALWAYS_INLINE + explicit codecvt_byname(const string& __nm, size_t __refs = 0) + : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {} +protected: + ~codecvt_byname(); +}; + +template +codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() +{ +} + +extern template class codecvt_byname; +extern template class codecvt_byname; +extern template class codecvt_byname; +extern template class codecvt_byname; + +_LIBCPP_VISIBLE void __throw_runtime_error(const char*); + +template +struct __narrow_to_utf8 +{ + template + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const; +}; + +template <> +struct __narrow_to_utf8<8> +{ + template + _LIBCPP_ALWAYS_INLINE + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + for (; __wb < __we; ++__wb, ++__s) + *__s = *__wb; + return __s; + } +}; + +template <> +struct __narrow_to_utf8<16> + : public codecvt +{ + _LIBCPP_ALWAYS_INLINE + __narrow_to_utf8() : codecvt(1) {} + + ~__narrow_to_utf8(); + + template + _LIBCPP_ALWAYS_INLINE + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + result __r = ok; + mbstate_t __mb; + while (__wb < __we && __r != error) + { + const int __sz = 32; + char __buf[__sz]; + char* __bn; + const char16_t* __wn = (const char16_t*)__wb; + __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __wn == (const char16_t*)__wb) + __throw_runtime_error("locale not supported"); + for (const char* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = *__p; + __wb = (const _CharT*)__wn; + } + return __s; + } +}; + +template <> +struct __narrow_to_utf8<32> + : public codecvt +{ + _LIBCPP_ALWAYS_INLINE + __narrow_to_utf8() : codecvt(1) {} + + ~__narrow_to_utf8(); + + template + _LIBCPP_ALWAYS_INLINE + _OutputIterator + operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const + { + result __r = ok; + mbstate_t __mb; + while (__wb < __we && __r != error) + { + const int __sz = 32; + char __buf[__sz]; + char* __bn; + const char32_t* __wn = (const char32_t*)__wb; + __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __wn == (const char32_t*)__wb) + __throw_runtime_error("locale not supported"); + for (const char* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = *__p; + __wb = (const _CharT*)__wn; + } + return __s; + } +}; + +template +struct __widen_from_utf8 +{ + template + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const; +}; + +template <> +struct __widen_from_utf8<8> +{ + template + _LIBCPP_ALWAYS_INLINE + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + for (; __nb < __ne; ++__nb, ++__s) + *__s = *__nb; + return __s; + } +}; + +template <> +struct __widen_from_utf8<16> + : public codecvt +{ + _LIBCPP_ALWAYS_INLINE + __widen_from_utf8() : codecvt(1) {} + + ~__widen_from_utf8(); + + template + _LIBCPP_ALWAYS_INLINE + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + result __r = ok; + mbstate_t __mb; + while (__nb < __ne && __r != error) + { + const int __sz = 32; + char16_t __buf[__sz]; + char16_t* __bn; + const char* __nn = __nb; + __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __nn == __nb) + __throw_runtime_error("locale not supported"); + for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = (wchar_t)*__p; + __nb = __nn; + } + return __s; + } +}; + +template <> +struct __widen_from_utf8<32> + : public codecvt +{ + _LIBCPP_ALWAYS_INLINE + __widen_from_utf8() : codecvt(1) {} + + ~__widen_from_utf8(); + + template + _LIBCPP_ALWAYS_INLINE + _OutputIterator + operator()(_OutputIterator __s, const char* __nb, const char* __ne) const + { + result __r = ok; + mbstate_t __mb; + while (__nb < __ne && __r != error) + { + const int __sz = 32; + char32_t __buf[__sz]; + char32_t* __bn; + const char* __nn = __nb; + __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, + __buf, __buf+__sz, __bn); + if (__r == codecvt_base::error || __nn == __nb) + __throw_runtime_error("locale not supported"); + for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s) + *__s = (wchar_t)*__p; + __nb = __nn; + } + return __s; + } +}; + +// template class numpunct + +template class _LIBCPP_VISIBLE numpunct; + +template <> +class _LIBCPP_VISIBLE numpunct + : public locale::facet +{ +public: + typedef char char_type; + typedef basic_string string_type; + + explicit numpunct(size_t __refs = 0); + + _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();} + _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();} + _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();} + _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();} + _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();} + + static locale::id id; + +protected: + ~numpunct(); + virtual char_type do_decimal_point() const; + virtual char_type do_thousands_sep() const; + virtual string do_grouping() const; + virtual string_type do_truename() const; + virtual string_type do_falsename() const; + + char_type __decimal_point_; + char_type __thousands_sep_; + string __grouping_; +}; + +template <> +class _LIBCPP_VISIBLE numpunct + : public locale::facet +{ +public: + typedef wchar_t char_type; + typedef basic_string string_type; + + explicit numpunct(size_t __refs = 0); + + _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();} + _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();} + _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();} + _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();} + _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();} + + static locale::id id; + +protected: + ~numpunct(); + virtual char_type do_decimal_point() const; + virtual char_type do_thousands_sep() const; + virtual string do_grouping() const; + virtual string_type do_truename() const; + virtual string_type do_falsename() const; + + char_type __decimal_point_; + char_type __thousands_sep_; + string __grouping_; +}; + +// template class numpunct_byname + +template class _LIBCPP_VISIBLE numpunct_byname; + +template <> +class _LIBCPP_VISIBLE numpunct_byname +: public numpunct +{ +public: + typedef char char_type; + typedef basic_string string_type; + + explicit numpunct_byname(const char* __nm, size_t __refs = 0); + explicit numpunct_byname(const string& __nm, size_t __refs = 0); + +protected: + ~numpunct_byname(); + +private: + void __init(const char*); +}; + +template <> +class _LIBCPP_VISIBLE numpunct_byname +: public numpunct +{ +public: + typedef wchar_t char_type; + typedef basic_string string_type; + + explicit numpunct_byname(const char* __nm, size_t __refs = 0); + explicit numpunct_byname(const string& __nm, size_t __refs = 0); + +protected: + ~numpunct_byname(); + +private: + void __init(const char*); +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___LOCALE diff --git a/contrib/libc++/include/__mutex_base b/contrib/libc++/include/__mutex_base new file mode 100644 index 000000000000..55687659a03a --- /dev/null +++ b/contrib/libc++/include/__mutex_base @@ -0,0 +1,439 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MUTEX_BASE +#define _LIBCPP___MUTEX_BASE + +#include <__config> +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_SHARED_LOCK + +namespace ting { +template class shared_lock; +template class upgrade_lock; +} + +#endif // _LIBCPP_SHARED_LOCK + + +_LIBCPP_BEGIN_NAMESPACE_STD + +class _LIBCPP_VISIBLE mutex +{ + pthread_mutex_t __m_; + +public: + _LIBCPP_INLINE_VISIBILITY + mutex() {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;} + ~mutex(); + +private: + mutex(const mutex&);// = delete; + mutex& operator=(const mutex&);// = delete; + +public: + void lock(); + bool try_lock(); + void unlock(); + + typedef pthread_mutex_t* native_handle_type; + _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;} +}; + +struct _LIBCPP_VISIBLE defer_lock_t {}; +struct _LIBCPP_VISIBLE try_to_lock_t {}; +struct _LIBCPP_VISIBLE adopt_lock_t {}; + +//constexpr +extern const +defer_lock_t defer_lock; + +//constexpr +extern const +try_to_lock_t try_to_lock; + +//constexpr +extern const +adopt_lock_t adopt_lock; + +template +class _LIBCPP_VISIBLE lock_guard +{ +public: + typedef _Mutex mutex_type; + +private: + mutex_type& __m_; +public: + + _LIBCPP_INLINE_VISIBILITY + explicit lock_guard(mutex_type& __m) + : __m_(__m) {__m_.lock();} + _LIBCPP_INLINE_VISIBILITY + lock_guard(mutex_type& __m, adopt_lock_t) + : __m_(__m) {} + _LIBCPP_INLINE_VISIBILITY + ~lock_guard() {__m_.unlock();} + +private: + lock_guard(lock_guard const&);// = delete; + lock_guard& operator=(lock_guard const&);// = delete; +}; + +template +class _LIBCPP_VISIBLE unique_lock +{ +public: + typedef _Mutex mutex_type; + +private: + mutex_type* __m_; + bool __owns_; + +public: + _LIBCPP_INLINE_VISIBILITY + unique_lock() : __m_(nullptr), __owns_(false) {} + _LIBCPP_INLINE_VISIBILITY + explicit unique_lock(mutex_type& __m) + : __m_(&__m), __owns_(true) {__m_->lock();} + _LIBCPP_INLINE_VISIBILITY + unique_lock(mutex_type& __m, defer_lock_t) + : __m_(&__m), __owns_(false) {} + _LIBCPP_INLINE_VISIBILITY + unique_lock(mutex_type& __m, try_to_lock_t) + : __m_(&__m), __owns_(__m.try_lock()) {} + _LIBCPP_INLINE_VISIBILITY + unique_lock(mutex_type& __m, adopt_lock_t) + : __m_(&__m), __owns_(true) {} + template + _LIBCPP_INLINE_VISIBILITY + unique_lock(mutex_type& __m, const chrono::time_point<_Clock, _Duration>& __t) + : __m_(&__m), __owns_(__m.try_lock_until(__t)) {} + template + _LIBCPP_INLINE_VISIBILITY + unique_lock(mutex_type& __m, const chrono::duration<_Rep, _Period>& __d) + : __m_(&__m), __owns_(__m.try_lock_for(__d)) {} + _LIBCPP_INLINE_VISIBILITY + ~unique_lock() + { + if (__owns_) + __m_->unlock(); + } + +private: + unique_lock(unique_lock const&); // = delete; + unique_lock& operator=(unique_lock const&); // = delete; + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + unique_lock(unique_lock&& __u) + : __m_(__u.__m_), __owns_(__u.__owns_) + {__u.__m_ = nullptr; __u.__owns_ = false;} + _LIBCPP_INLINE_VISIBILITY + unique_lock& operator=(unique_lock&& __u) + { + if (__owns_) + __m_->unlock(); + __m_ = __u.__m_; + __owns_ = __u.__owns_; + __u.__m_ = nullptr; + __u.__owns_ = false; + return *this; + } + +#ifdef _LIBCPP_SHARED_LOCK + + unique_lock(ting::shared_lock&&, try_to_lock_t); + template + unique_lock(ting::shared_lock&&, + const chrono::time_point<_Clock, _Duration>&); + template + unique_lock(ting::shared_lock&&, + const chrono::duration<_Rep, _Period>&); + + explicit unique_lock(ting::upgrade_lock&&); + unique_lock(ting::upgrade_lock&&, try_to_lock_t); + template + unique_lock(ting::upgrade_lock&&, + const chrono::time_point<_Clock, _Duration>&); + template + unique_lock(ting::upgrade_lock&&, + const chrono::duration<_Rep, _Period>&); + +#endif // _LIBCPP_SHARED_LOCK + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + void lock(); + bool try_lock(); + + template + bool try_lock_for(const chrono::duration<_Rep, _Period>& __d); + template + bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t); + + void unlock(); + + _LIBCPP_INLINE_VISIBILITY + void swap(unique_lock& __u) + { + _VSTD::swap(__m_, __u.__m_); + _VSTD::swap(__owns_, __u.__owns_); + } + _LIBCPP_INLINE_VISIBILITY + mutex_type* release() + { + mutex_type* __m = __m_; + __m_ = nullptr; + __owns_ = false; + return __m; + } + + _LIBCPP_INLINE_VISIBILITY + bool owns_lock() const {return __owns_;} + _LIBCPP_INLINE_VISIBILITY +// explicit + operator bool () const {return __owns_;} + _LIBCPP_INLINE_VISIBILITY + mutex_type* mutex() const {return __m_;} +}; + +template +void +unique_lock<_Mutex>::lock() +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "unique_lock::lock: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "unique_lock::lock: already locked"); + __m_->lock(); + __owns_ = true; +} + +template +bool +unique_lock<_Mutex>::try_lock() +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "unique_lock::try_lock: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "unique_lock::try_lock: already locked"); + __owns_ = __m_->try_lock(); + return __owns_; +} + +template +template +bool +unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "unique_lock::try_lock_for: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "unique_lock::try_lock_for: already locked"); + __owns_ = __m_->try_lock_for(__d); + return __owns_; +} + +template +template +bool +unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) +{ + if (__m_ == nullptr) + __throw_system_error(EPERM, "unique_lock::try_lock_until: references null mutex"); + if (__owns_) + __throw_system_error(EDEADLK, "unique_lock::try_lock_until: already locked"); + __owns_ = __m_->try_lock_until(__t); + return __owns_; +} + +template +void +unique_lock<_Mutex>::unlock() +{ + if (!__owns_) + __throw_system_error(EPERM, "unique_lock::unlock: not locked"); + __m_->unlock(); + __owns_ = false; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) {__x.swap(__y);} + +struct _LIBCPP_VISIBLE cv_status +{ + enum _ { + no_timeout, + timeout + }; + + _ __v_; + + _LIBCPP_INLINE_VISIBILITY cv_status(_ __v) : __v_(__v) {} + _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} + +}; + +class _LIBCPP_VISIBLE condition_variable +{ + pthread_cond_t __cv_; +public: + _LIBCPP_INLINE_VISIBILITY + condition_variable() {__cv_ = (pthread_cond_t)PTHREAD_COND_INITIALIZER;} + ~condition_variable(); + +private: + condition_variable(const condition_variable&); // = delete; + condition_variable& operator=(const condition_variable&); // = delete; + +public: + void notify_one(); + void notify_all(); + + void wait(unique_lock& __lk); + template + void wait(unique_lock& __lk, _Predicate __pred); + + template + cv_status + wait_until(unique_lock& __lk, + const chrono::time_point& __t); + + template + cv_status + wait_until(unique_lock& __lk, + const chrono::time_point<_Clock, _Duration>& __t); + + template + bool + wait_until(unique_lock& __lk, + const chrono::time_point<_Clock, _Duration>& __t, + _Predicate __pred); + + template + cv_status + wait_for(unique_lock& __lk, + const chrono::duration<_Rep, _Period>& __d); + + template + bool + wait_for(unique_lock& __lk, + const chrono::duration<_Rep, _Period>& __d, + _Predicate __pred); + + typedef pthread_cond_t* native_handle_type; + _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__cv_;} + +private: + void __do_timed_wait(unique_lock& __lk, + chrono::time_point); +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + chrono::__is_duration<_To>::value, + _To +>::type +__ceil(chrono::duration<_Rep, _Period> __d) +{ + using namespace chrono; + _To __r = duration_cast<_To>(__d); + if (__r < __d) + ++__r; + return __r; +} + +template +void +condition_variable::wait(unique_lock& __lk, _Predicate __pred) +{ + while (!__pred()) + wait(__lk); +} + +template +cv_status +condition_variable::wait_until(unique_lock& __lk, + const chrono::time_point& __t) +{ + using namespace chrono; + typedef time_point __nano_sys_tmpt; + __do_timed_wait(__lk, + __nano_sys_tmpt(__ceil(__t.time_since_epoch()))); + return system_clock::now() < __t ? cv_status::no_timeout : + cv_status::timeout; +} + +template +cv_status +condition_variable::wait_until(unique_lock& __lk, + const chrono::time_point<_Clock, _Duration>& __t) +{ + using namespace chrono; + system_clock::time_point __s_now = system_clock::now(); + typename _Clock::time_point __c_now = _Clock::now(); + __do_timed_wait(__lk, __s_now + __ceil(__t - __c_now)); + return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout; +} + +template +bool +condition_variable::wait_until(unique_lock& __lk, + const chrono::time_point<_Clock, _Duration>& __t, + _Predicate __pred) +{ + while (!__pred()) + { + if (wait_until(__lk, __t) == cv_status::timeout) + return __pred(); + } + return true; +} + +template +cv_status +condition_variable::wait_for(unique_lock& __lk, + const chrono::duration<_Rep, _Period>& __d) +{ + using namespace chrono; + system_clock::time_point __s_now = system_clock::now(); + steady_clock::time_point __c_now = steady_clock::now(); + __do_timed_wait(__lk, __s_now + __ceil(__d)); + return steady_clock::now() - __c_now < __d ? cv_status::no_timeout : + cv_status::timeout; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +condition_variable::wait_for(unique_lock& __lk, + const chrono::duration<_Rep, _Period>& __d, + _Predicate __pred) +{ + return wait_until(__lk, chrono::steady_clock::now() + __d, + _VSTD::move(__pred)); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MUTEX_BASE diff --git a/contrib/libc++/include/__split_buffer b/contrib/libc++/include/__split_buffer new file mode 100644 index 000000000000..33ce42da31a4 --- /dev/null +++ b/contrib/libc++/include/__split_buffer @@ -0,0 +1,650 @@ +// -*- C++ -*- +#ifndef _LIBCPP_SPLIT_BUFFER +#define _LIBCPP_SPLIT_BUFFER + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +class __split_buffer_common +{ +protected: + void __throw_length_error() const; + void __throw_out_of_range() const; +}; + +template > +struct __split_buffer + : private __split_buffer_common +{ +private: + __split_buffer(const __split_buffer&); + __split_buffer& operator=(const __split_buffer&); +public: + typedef _Tp value_type; + typedef _Allocator allocator_type; + typedef typename remove_reference::type __alloc_rr; + typedef allocator_traits<__alloc_rr> __alloc_traits; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef pointer iterator; + typedef const_pointer const_iterator; + + pointer __first_; + pointer __begin_; + pointer __end_; + __compressed_pair __end_cap_; + + typedef typename add_lvalue_reference::type __alloc_ref; + typedef typename add_lvalue_reference::type __alloc_const_ref; + + _LIBCPP_INLINE_VISIBILITY __alloc_rr& __alloc() _NOEXCEPT {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY const __alloc_rr& __alloc() const _NOEXCEPT {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() _NOEXCEPT {return __end_cap_.first();} + _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const _NOEXCEPT {return __end_cap_.first();} + + __split_buffer() + _NOEXCEPT_(is_nothrow_default_constructible::value); + explicit __split_buffer(__alloc_rr& __a); + explicit __split_buffer(const __alloc_rr& __a); + __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a); + ~__split_buffer(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + __split_buffer(__split_buffer&& __c) + _NOEXCEPT_(is_nothrow_move_constructible::value); + __split_buffer(__split_buffer&& __c, const __alloc_rr& __a); + __split_buffer& operator=(__split_buffer&& __c) + _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value) || + !__alloc_traits::propagate_on_container_move_assignment::value); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __begin_;} + _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;} + _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __end_;} + _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __end_;} + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT + {__destruct_at_end(__begin_);} + _LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast(__end_ - __begin_);} + _LIBCPP_INLINE_VISIBILITY bool empty() const {return __end_ == __begin_;} + _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast(__end_cap() - __first_);} + _LIBCPP_INLINE_VISIBILITY size_type __front_spare() const {return static_cast(__begin_ - __first_);} + _LIBCPP_INLINE_VISIBILITY size_type __back_spare() const {return static_cast(__end_cap() - __end_);} + + _LIBCPP_INLINE_VISIBILITY reference front() {return *__begin_;} + _LIBCPP_INLINE_VISIBILITY const_reference front() const {return *__begin_;} + _LIBCPP_INLINE_VISIBILITY reference back() {return *(__end_ - 1);} + _LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(__end_ - 1);} + + void reserve(size_type __n); + void shrink_to_fit() _NOEXCEPT; + void push_front(const_reference __x); + void push_back(const_reference __x); +#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + void push_front(value_type&& __x); + void push_back(value_type&& __x); +#if !defined(_LIBCPP_HAS_NO_VARIADICS) + template + void emplace_back(_Args&&... __args); +#endif // !defined(_LIBCPP_HAS_NO_VARIADICS) +#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + + _LIBCPP_INLINE_VISIBILITY void pop_front() {__destruct_at_begin(__begin_+1);} + _LIBCPP_INLINE_VISIBILITY void pop_back() {__destruct_at_end(__end_-1);} + + void __construct_at_end(size_type __n); + void __construct_at_end(size_type __n, const_reference __x); + template + typename enable_if + < + __is_input_iterator<_InputIter>::value && + !__is_forward_iterator<_InputIter>::value, + void + >::type + __construct_at_end(_InputIter __first, _InputIter __last); + template + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + void + >::type + __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); + + _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin) + {__destruct_at_begin(__new_begin, is_trivially_destructible());} + void __destruct_at_begin(pointer __new_begin, false_type); + void __destruct_at_begin(pointer __new_begin, true_type); + + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(pointer __new_last) _NOEXCEPT + {__destruct_at_end(__new_last, is_trivially_destructible());} + void __destruct_at_end(pointer __new_last, false_type) _NOEXCEPT; + void __destruct_at_end(pointer __new_last, true_type) _NOEXCEPT; + + void swap(__split_buffer& __x) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable<__alloc_rr>::value); + + bool __invariants() const; + +private: + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__split_buffer& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable::value) + { + __alloc() = _VSTD::move(__c.__alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__split_buffer& __c, false_type) _NOEXCEPT + {} + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable<__alloc_rr>::value) + {__swap_alloc(__x, __y, integral_constant());} + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y, true_type) + _NOEXCEPT_(__is_nothrow_swappable<__alloc_rr>::value) + { + using _VSTD::swap; + swap(__x, __y); + } + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y, false_type) _NOEXCEPT + {} +}; + +template +bool +__split_buffer<_Tp, _Allocator>::__invariants() const +{ + if (__first_ == nullptr) + { + if (__begin_ != nullptr) + return false; + if (__end_ != nullptr) + return false; + if (__end_cap() != nullptr) + return false; + } + else + { + if (__begin_ < __first_) + return false; + if (__end_ < __begin_) + return false; + if (__end_cap() < __end_) + return false; + } + return true; +} + +// Default constructs __n objects starting at __end_ +// throws if construction throws +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == size() + __n +template +void +__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n) +{ + __alloc_rr& __a = this->__alloc(); + do + { + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_)); + ++this->__end_; + --__n; + } while (__n > 0); +} + +// Copy constructs __n objects starting at __end_ from __x +// throws if construction throws +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == old size() + __n +// Postcondition: [i] == __x for all i in [size() - __n, __n) +template +void +__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) +{ + __alloc_rr& __a = this->__alloc(); + do + { + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x); + ++this->__end_; + --__n; + } while (__n > 0); +} + +template +template +typename enable_if +< + __is_input_iterator<_InputIter>::value && + !__is_forward_iterator<_InputIter>::value, + void +>::type +__split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIter __last) +{ + __alloc_rr& __a = this->__alloc(); + for (; __first != __last; ++__first) + { + if (__end_ == __end_cap()) + { + size_type __old_cap = __end_cap() - __first_; + size_type __new_cap = _VSTD::max(2 * __old_cap, 8); + __split_buffer __buf(__new_cap, 0, __a); + for (pointer __p = __begin_; __p != __end_; ++__p, ++__buf.__end_) + __alloc_traits::construct(__buf.__alloc(), + _VSTD::__to_raw_pointer(__buf.__end_), _VSTD::move(*__p)); + swap(__buf); + } + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); + ++this->__end_; + } +} + +template +template +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value, + void +>::type +__split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) +{ + __alloc_rr& __a = this->__alloc(); + for (; __first != __last; ++__first) + { + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); + ++this->__end_; + } +} + +template +_LIBCPP_INLINE_VISIBILITY inline +void +__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type) +{ + while (__begin_ < __new_begin) + __alloc_traits::destroy(__alloc(), __begin_++); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +void +__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type) +{ + __begin_ = __new_begin; +} + +template +_LIBCPP_INLINE_VISIBILITY inline +void +__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT +{ + while (__new_last < __end_) + __alloc_traits::destroy(__alloc(), --__end_); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +void +__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) _NOEXCEPT +{ + __end_ = __new_last; +} + +template +__split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a) + : __end_cap_(0, __a) +{ + __first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr; + __begin_ = __end_ = __first_ + __start; + __end_cap() = __first_ + __cap; +} + +template +_LIBCPP_INLINE_VISIBILITY inline +__split_buffer<_Tp, _Allocator>::__split_buffer() + _NOEXCEPT_(is_nothrow_default_constructible::value) + : __first_(0), __begin_(0), __end_(0), __end_cap_(0) +{ +} + +template +_LIBCPP_INLINE_VISIBILITY inline +__split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a) + : __first_(0), __begin_(0), __end_(0), __end_cap_(0, __a) +{ +} + +template +_LIBCPP_INLINE_VISIBILITY inline +__split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a) + : __first_(0), __begin_(0), __end_(0), __end_cap_(0, __a) +{ +} + +template +__split_buffer<_Tp, _Allocator>::~__split_buffer() +{ + clear(); + if (__first_) + __alloc_traits::deallocate(__alloc(), __first_, capacity()); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c) + _NOEXCEPT_(is_nothrow_move_constructible::value) + : __first_(_VSTD::move(__c.__first_)), + __begin_(_VSTD::move(__c.__begin_)), + __end_(_VSTD::move(__c.__end_)), + __end_cap_(_VSTD::move(__c.__end_cap_)) +{ + __c.__first_ = nullptr; + __c.__begin_ = nullptr; + __c.__end_ = nullptr; + __c.__end_cap() = nullptr; +} + +template +__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a) + : __end_cap_(__a) +{ + if (__a == __c.__alloc()) + { + __first_ = __c.__first_; + __begin_ = __c.__begin_; + __end_ = __c.__end_; + __end_cap() = __c.__end_cap(); + __c.__first_ = nullptr; + __c.__begin_ = nullptr; + __c.__end_ = nullptr; + __c.__end_cap() = nullptr; + } + else + { + size_type __cap = __c.size(); + __first_ = __alloc_traits::allocate(__alloc(), __cap); + __begin_ = __end_ = __first_; + __end_cap() = __first_ + __cap; + typedef move_iterator _I; + __construct_at_end(_I(__c.begin()), _I(__c.end())); + } +} + +template +__split_buffer<_Tp, _Allocator>& +__split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c) + _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value) || + !__alloc_traits::propagate_on_container_move_assignment::value) +{ + clear(); + shrink_to_fit(); + __first_ = __c.__first_; + __begin_ = __c.__begin_; + __end_ = __c.__end_; + __end_cap() = __c.__end_cap(); + __move_assign_alloc(__c, + integral_constant()); + __c.__first_ = __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +__split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable<__alloc_rr>::value) +{ + _VSTD::swap(__first_, __x.__first_); + _VSTD::swap(__begin_, __x.__begin_); + _VSTD::swap(__end_, __x.__end_); + _VSTD::swap(__end_cap(), __x.__end_cap()); + __swap_alloc(__alloc(), __x.__alloc()); +} + +template +void +__split_buffer<_Tp, _Allocator>::reserve(size_type __n) +{ + if (__n < capacity()) + { + __split_buffer __t(__n, 0, __alloc()); + __t.__construct_at_end(move_iterator(__begin_), + move_iterator(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } +} + +template +void +__split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT +{ + if (capacity() > size()) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __split_buffer __t(size(), 0, __alloc()); + __t.__construct_at_end(move_iterator(__begin_), + move_iterator(__end_)); + __t.__end_ = __t.__begin_ + (__end_ - __begin_); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template +void +__split_buffer<_Tp, _Allocator>::push_front(const_reference __x) +{ + if (__begin_ == __first_) + { + if (__end_ < __end_cap()) + { + difference_type __d = __end_cap() - __end_; + __d = (__d + 1) / 2; + __begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d); + __end_ += __d; + } + else + { + size_type __c = max(2 * (__end_cap() - __first_), 1); + __split_buffer __t(__c, (__c + 3) / 4, __alloc()); + __t.__construct_at_end(move_iterator(__begin_), + move_iterator(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__begin_-1), __x); + --__begin_; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +__split_buffer<_Tp, _Allocator>::push_front(value_type&& __x) +{ + if (__begin_ == __first_) + { + if (__end_ < __end_cap()) + { + difference_type __d = __end_cap() - __end_; + __d = (__d + 1) / 2; + __begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d); + __end_ += __d; + } + else + { + size_type __c = max(2 * (__end_cap() - __first_), 1); + __split_buffer __t(__c, (__c + 3) / 4, __alloc()); + __t.__construct_at_end(move_iterator(__begin_), + move_iterator(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__begin_-1), + _VSTD::move(__x)); + --__begin_; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +_LIBCPP_INLINE_VISIBILITY inline +void +__split_buffer<_Tp, _Allocator>::push_back(const_reference __x) +{ + if (__end_ == __end_cap()) + { + if (__begin_ > __first_) + { + difference_type __d = __begin_ - __first_; + __d = (__d + 1) / 2; + __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); + __begin_ -= __d; + } + else + { + size_type __c = max(2 * (__end_cap() - __first_), 1); + __split_buffer __t(__c, __c / 4, __alloc()); + __t.__construct_at_end(move_iterator(__begin_), + move_iterator(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), __x); + ++__end_; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +__split_buffer<_Tp, _Allocator>::push_back(value_type&& __x) +{ + if (__end_ == __end_cap()) + { + if (__begin_ > __first_) + { + difference_type __d = __begin_ - __first_; + __d = (__d + 1) / 2; + __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); + __begin_ -= __d; + } + else + { + size_type __c = max(2 * (__end_cap() - __first_), 1); + __split_buffer __t(__c, __c / 4, __alloc()); + __t.__construct_at_end(move_iterator(__begin_), + move_iterator(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), + _VSTD::move(__x)); + ++__end_; +} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +void +__split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args) +{ + if (__end_ == __end_cap()) + { + if (__begin_ > __first_) + { + difference_type __d = __begin_ - __first_; + __d = (__d + 1) / 2; + __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); + __begin_ -= __d; + } + else + { + size_type __c = max(2 * (__end_cap() - __first_), 1); + __split_buffer __t(__c, __c / 4, __alloc()); + __t.__construct_at_end(move_iterator(__begin_), + move_iterator(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), + _VSTD::forward<_Args>(__args)...); + ++__end_; +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +_LIBCPP_INLINE_VISIBILITY inline +void +swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_SPLIT_BUFFER diff --git a/contrib/libc++/include/__sso_allocator b/contrib/libc++/include/__sso_allocator new file mode 100644 index 000000000000..16354d83cc5b --- /dev/null +++ b/contrib/libc++/include/__sso_allocator @@ -0,0 +1,77 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___SSO_ALLOCATOR +#define _LIBCPP___SSO_ALLOCATOR + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template class _LIBCPP_HIDDEN __sso_allocator; + +template +class _LIBCPP_HIDDEN __sso_allocator +{ +public: + typedef const void* const_pointer; + typedef void value_type; +}; + +template +class _LIBCPP_HIDDEN __sso_allocator +{ + typename aligned_storage::type buf_; + bool __allocated_; +public: + typedef size_t size_type; + typedef _Tp* pointer; + typedef _Tp value_type; + + _LIBCPP_INLINE_VISIBILITY __sso_allocator() throw() : __allocated_(false) {} + _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {} + template _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _N>&) throw() + : __allocated_(false) {} +private: + __sso_allocator& operator=(const __sso_allocator&); +public: + _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, typename __sso_allocator::const_pointer = 0) + { + if (!__allocated_ && __n <= _N) + { + __allocated_ = true; + return (pointer)&buf_; + } + return static_cast(::operator new(__n * sizeof(_Tp))); + } + _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) + { + if (__p == (pointer)&buf_) + __allocated_ = false; + else + ::operator delete(__p); + } + _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);} + + _LIBCPP_INLINE_VISIBILITY + bool operator==(__sso_allocator& __a) const {return &buf_ == &__a.buf_;} + _LIBCPP_INLINE_VISIBILITY + bool operator!=(__sso_allocator& __a) const {return &buf_ != &__a.buf_;} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___SSO_ALLOCATOR diff --git a/contrib/libc++/include/__std_stream b/contrib/libc++/include/__std_stream new file mode 100644 index 000000000000..6df6556da767 --- /dev/null +++ b/contrib/libc++/include/__std_stream @@ -0,0 +1,315 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___STD_STREAM +#define _LIBCPP___STD_STREAM + +#include <__config> +#include +#include +#include <__locale> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +static const unsigned __limit = 8; + +// __stdinbuf + +template +class _LIBCPP_HIDDEN __stdinbuf + : public basic_streambuf<_CharT, char_traits<_CharT> > +{ +public: + typedef _CharT char_type; + typedef char_traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef typename traits_type::state_type state_type; + + explicit __stdinbuf(FILE* __fp); + +protected: + virtual int_type underflow(); + virtual int_type uflow(); + virtual int_type pbackfail(int_type __c = traits_type::eof()); + virtual void imbue(const locale& __loc); + +private: + + FILE* __file_; + const codecvt* __cv_; + state_type __st_; + int __encoding_; + bool __always_noconv_; + + __stdinbuf(const __stdinbuf&); + __stdinbuf& operator=(const __stdinbuf&); + + int_type __getchar(bool __consume); +}; + +template +__stdinbuf<_CharT>::__stdinbuf(FILE* __fp) + : __file_(__fp), + __st_() +{ + imbue(this->getloc()); +} + +template +void +__stdinbuf<_CharT>::imbue(const locale& __loc) +{ + __cv_ = &use_facet >(__loc); + __encoding_ = __cv_->encoding(); + __always_noconv_ = __cv_->always_noconv(); + if (__encoding_ > __limit) + __throw_runtime_error("unsupported locale for standard input"); +} + +template +typename __stdinbuf<_CharT>::int_type +__stdinbuf<_CharT>::underflow() +{ + return __getchar(false); +} + +template +typename __stdinbuf<_CharT>::int_type +__stdinbuf<_CharT>::uflow() +{ + return __getchar(true); +} + +template +typename __stdinbuf<_CharT>::int_type +__stdinbuf<_CharT>::__getchar(bool __consume) +{ + char __extbuf[__limit]; + int __nread = _VSTD::max(1, __encoding_); + for (int __i = 0; __i < __nread; ++__i) + { + char __c = getc(__file_); + if (__c == EOF) + return traits_type::eof(); + __extbuf[__i] = static_cast(__c); + } + char_type __1buf; + if (__always_noconv_) + __1buf = static_cast(__extbuf[0]); + else + { + const char* __enxt; + char_type* __inxt; + codecvt_base::result __r; + do + { + state_type __sv_st = __st_; + __r = __cv_->in(__st_, __extbuf, __extbuf + __nread, __enxt, + &__1buf, &__1buf + 1, __inxt); + switch (__r) + { + case _VSTD::codecvt_base::ok: + break; + case codecvt_base::partial: + __st_ = __sv_st; + if (__nread == sizeof(__extbuf)) + return traits_type::eof(); + { + char __c = getc(__file_); + if (__c == EOF) + return traits_type::eof(); + __extbuf[__nread] = static_cast(__c); + } + ++__nread; + break; + case codecvt_base::error: + return traits_type::eof(); + case _VSTD::codecvt_base::noconv: + __1buf = static_cast(__extbuf[0]); + break; + } + } while (__r == _VSTD::codecvt_base::partial); + } + if (!__consume) + { + for (int __i = __nread; __i > 0;) + { + if (ungetc(__extbuf[--__i], __file_) == EOF) + return traits_type::eof(); + } + } + return traits_type::to_int_type(__1buf); +} + +template +typename __stdinbuf<_CharT>::int_type +__stdinbuf<_CharT>::pbackfail(int_type __c) +{ + if (traits_type::eq_int_type(__c, traits_type::eof())) + return __c; + char __extbuf[__limit]; + char* __enxt; + const char_type __ci = traits_type::to_char_type(__c); + const char_type* __inxt; + switch (__cv_->out(__st_, &__ci, &__ci + 1, __inxt, + __extbuf, __extbuf + sizeof(__extbuf), __enxt)) + { + case _VSTD::codecvt_base::ok: + break; + case _VSTD::codecvt_base::noconv: + __extbuf[0] = static_cast(__c); + __enxt = __extbuf + 1; + break; + case codecvt_base::partial: + case codecvt_base::error: + return traits_type::eof(); + } + while (__enxt > __extbuf) + if (ungetc(*--__enxt, __file_) == EOF) + return traits_type::eof(); + return traits_type::not_eof(__c); +} + +// __stdoutbuf + +template +class _LIBCPP_HIDDEN __stdoutbuf + : public basic_streambuf<_CharT, char_traits<_CharT> > +{ +public: + typedef _CharT char_type; + typedef char_traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef typename traits_type::state_type state_type; + + explicit __stdoutbuf(FILE* __fp); + +protected: + virtual int_type overflow (int_type __c = traits_type::eof()); + virtual int sync(); + virtual void imbue(const locale& __loc); + +private: + FILE* __file_; + const codecvt* __cv_; + state_type __st_; + bool __always_noconv_; + + __stdoutbuf(const __stdoutbuf&); + __stdoutbuf& operator=(const __stdoutbuf&); +}; + +template +__stdoutbuf<_CharT>::__stdoutbuf(FILE* __fp) + : __file_(__fp), + __cv_(&use_facet >(this->getloc())), + __st_(), + __always_noconv_(__cv_->always_noconv()) +{ +} + +template +typename __stdoutbuf<_CharT>::int_type +__stdoutbuf<_CharT>::overflow(int_type __c) +{ + char __extbuf[__limit]; + char_type __1buf; + if (!traits_type::eq_int_type(__c, traits_type::eof())) + { + this->setp(&__1buf, &__1buf+1); + *this->pptr() = traits_type::to_char_type(__c); + this->pbump(1); + if (__always_noconv_) + { + if (fwrite(this->pbase(), sizeof(char_type), 1, __file_) != 1) + return traits_type::eof(); + } + else + { + char* __extbe = __extbuf; + codecvt_base::result __r; + do + { + const char_type* __e; + __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, + __extbuf, + __extbuf + sizeof(__extbuf), + __extbe); + if (__e == this->pbase()) + return traits_type::eof(); + if (__r == codecvt_base::noconv) + { + if (fwrite(this->pbase(), 1, 1, __file_) != 1) + return traits_type::eof(); + } + else if (__r == codecvt_base::ok || __r == codecvt_base::partial) + { + size_t __nmemb = static_cast(__extbe - __extbuf); + if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb) + return traits_type::eof(); + if (__r == codecvt_base::partial) + { + this->setp((char_type*)__e, this->pptr()); + this->pbump(this->epptr() - this->pbase()); + } + } + else + return traits_type::eof(); + } while (__r == codecvt_base::partial); + } + this->setp(0, 0); + } + return traits_type::not_eof(__c); +} + +template +int +__stdoutbuf<_CharT>::sync() +{ + char __extbuf[__limit]; + codecvt_base::result __r; + do + { + char* __extbe; + __r = __cv_->unshift(__st_, __extbuf, + __extbuf + sizeof(__extbuf), + __extbe); + size_t __nmemb = static_cast(__extbe - __extbuf); + if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb) + return -1; + } while (__r == codecvt_base::partial); + if (__r == codecvt_base::error) + return -1; + if (fflush(__file_)) + return -1; + return 0; +} + +template +void +__stdoutbuf<_CharT>::imbue(const locale& __loc) +{ + sync(); + __cv_ = &use_facet >(__loc); + __always_noconv_ = __cv_->always_noconv(); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___STD_STREAM diff --git a/contrib/libc++/include/__tree b/contrib/libc++/include/__tree new file mode 100644 index 000000000000..ad5d2f4b8eaa --- /dev/null +++ b/contrib/libc++/include/__tree @@ -0,0 +1,2293 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___TREE +#define _LIBCPP___TREE + +#include <__config> +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template class __tree; +template + class _LIBCPP_VISIBLE __tree_iterator; +template + class _LIBCPP_VISIBLE __tree_const_iterator; +template + class _LIBCPP_VISIBLE map; +template + class _LIBCPP_VISIBLE multimap; +template + class _LIBCPP_VISIBLE set; +template + class _LIBCPP_VISIBLE multiset; + +/* + +_NodePtr algorithms + +The algorithms taking _NodePtr are red black tree algorithms. Those +algorithms taking a parameter named __root should assume that __root +points to a proper red black tree (unless otherwise specified). + +Each algorithm herein assumes that __root->__parent_ points to a non-null +structure which has a member __left_ which points back to __root. No other +member is read or written to at __root->__parent_. + +__root->__parent_ will be referred to below (in comments only) as end_node. +end_node->__left_ is an externably accessible lvalue for __root, and can be +changed by node insertion and removal (without explicit reference to end_node). + +All nodes (with the exception of end_node), even the node referred to as +__root, have a non-null __parent_ field. + +*/ + +// Returns: true if __x is a left child of its parent, else false +// Precondition: __x != nullptr. +template +inline _LIBCPP_INLINE_VISIBILITY +bool +__tree_is_left_child(_NodePtr __x) _NOEXCEPT +{ + return __x == __x->__parent_->__left_; +} + +// Determintes if the subtree rooted at __x is a proper red black subtree. If +// __x is a proper subtree, returns the black height (null counts as 1). If +// __x is an improper subtree, returns 0. +template +unsigned +__tree_sub_invariant(_NodePtr __x) +{ + if (__x == nullptr) + return 1; + // parent consistency checked by caller + // check __x->__left_ consistency + if (__x->__left_ != nullptr && __x->__left_->__parent_ != __x) + return 0; + // check __x->__right_ consistency + if (__x->__right_ != nullptr && __x->__right_->__parent_ != __x) + return 0; + // check __x->__left_ != __x->__right_ unless both are nullptr + if (__x->__left_ == __x->__right_ && __x->__left_ != nullptr) + return 0; + // If this is red, neither child can be red + if (!__x->__is_black_) + { + if (__x->__left_ && !__x->__left_->__is_black_) + return 0; + if (__x->__right_ && !__x->__right_->__is_black_) + return 0; + } + unsigned __h = __tree_sub_invariant(__x->__left_); + if (__h == 0) + return 0; // invalid left subtree + if (__h != __tree_sub_invariant(__x->__right_)) + return 0; // invalid or different height right subtree + return __h + __x->__is_black_; // return black height of this node +} + +// Determintes if the red black tree rooted at __root is a proper red black tree. +// __root == nullptr is a proper tree. Returns true is __root is a proper +// red black tree, else returns false. +template +bool +__tree_invariant(_NodePtr __root) +{ + if (__root == nullptr) + return true; + // check __x->__parent_ consistency + if (__root->__parent_ == nullptr) + return false; + if (!__tree_is_left_child(__root)) + return false; + // root must be black + if (!__root->__is_black_) + return false; + // do normal node checks + return __tree_sub_invariant(__root) != 0; +} + +// Returns: pointer to the left-most node under __x. +// Precondition: __x != nullptr. +template +inline _LIBCPP_INLINE_VISIBILITY +_NodePtr +__tree_min(_NodePtr __x) _NOEXCEPT +{ + while (__x->__left_ != nullptr) + __x = __x->__left_; + return __x; +} + +// Returns: pointer to the right-most node under __x. +// Precondition: __x != nullptr. +template +inline _LIBCPP_INLINE_VISIBILITY +_NodePtr +__tree_max(_NodePtr __x) _NOEXCEPT +{ + while (__x->__right_ != nullptr) + __x = __x->__right_; + return __x; +} + +// Returns: pointer to the next in-order node after __x. +// Precondition: __x != nullptr. +template +_NodePtr +__tree_next(_NodePtr __x) _NOEXCEPT +{ + if (__x->__right_ != nullptr) + return __tree_min(__x->__right_); + while (!__tree_is_left_child(__x)) + __x = __x->__parent_; + return __x->__parent_; +} + +// Returns: pointer to the previous in-order node before __x. +// Precondition: __x != nullptr. +template +_NodePtr +__tree_prev(_NodePtr __x) _NOEXCEPT +{ + if (__x->__left_ != nullptr) + return __tree_max(__x->__left_); + while (__tree_is_left_child(__x)) + __x = __x->__parent_; + return __x->__parent_; +} + +// Returns: pointer to a node which has no children +// Precondition: __x != nullptr. +template +_NodePtr +__tree_leaf(_NodePtr __x) _NOEXCEPT +{ + while (true) + { + if (__x->__left_ != nullptr) + { + __x = __x->__left_; + continue; + } + if (__x->__right_ != nullptr) + { + __x = __x->__right_; + continue; + } + break; + } + return __x; +} + +// Effects: Makes __x->__right_ the subtree root with __x as its left child +// while preserving in-order order. +// Precondition: __x->__right_ != nullptr +template +void +__tree_left_rotate(_NodePtr __x) _NOEXCEPT +{ + _NodePtr __y = __x->__right_; + __x->__right_ = __y->__left_; + if (__x->__right_ != nullptr) + __x->__right_->__parent_ = __x; + __y->__parent_ = __x->__parent_; + if (__tree_is_left_child(__x)) + __x->__parent_->__left_ = __y; + else + __x->__parent_->__right_ = __y; + __y->__left_ = __x; + __x->__parent_ = __y; +} + +// Effects: Makes __x->__left_ the subtree root with __x as its right child +// while preserving in-order order. +// Precondition: __x->__left_ != nullptr +template +void +__tree_right_rotate(_NodePtr __x) _NOEXCEPT +{ + _NodePtr __y = __x->__left_; + __x->__left_ = __y->__right_; + if (__x->__left_ != nullptr) + __x->__left_->__parent_ = __x; + __y->__parent_ = __x->__parent_; + if (__tree_is_left_child(__x)) + __x->__parent_->__left_ = __y; + else + __x->__parent_->__right_ = __y; + __y->__right_ = __x; + __x->__parent_ = __y; +} + +// Effects: Rebalances __root after attaching __x to a leaf. +// Precondition: __root != nulptr && __x != nullptr. +// __x has no children. +// __x == __root or == a direct or indirect child of __root. +// If __x were to be unlinked from __root (setting __root to +// nullptr if __root == __x), __tree_invariant(__root) == true. +// Postcondition: __tree_invariant(end_node->__left_) == true. end_node->__left_ +// may be different than the value passed in as __root. +template +void +__tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT +{ + __x->__is_black_ = __x == __root; + while (__x != __root && !__x->__parent_->__is_black_) + { + // __x->__parent_ != __root because __x->__parent_->__is_black == false + if (__tree_is_left_child(__x->__parent_)) + { + _NodePtr __y = __x->__parent_->__parent_->__right_; + if (__y != nullptr && !__y->__is_black_) + { + __x = __x->__parent_; + __x->__is_black_ = true; + __x = __x->__parent_; + __x->__is_black_ = __x == __root; + __y->__is_black_ = true; + } + else + { + if (!__tree_is_left_child(__x)) + { + __x = __x->__parent_; + __tree_left_rotate(__x); + } + __x = __x->__parent_; + __x->__is_black_ = true; + __x = __x->__parent_; + __x->__is_black_ = false; + __tree_right_rotate(__x); + break; + } + } + else + { + _NodePtr __y = __x->__parent_->__parent_->__left_; + if (__y != nullptr && !__y->__is_black_) + { + __x = __x->__parent_; + __x->__is_black_ = true; + __x = __x->__parent_; + __x->__is_black_ = __x == __root; + __y->__is_black_ = true; + } + else + { + if (__tree_is_left_child(__x)) + { + __x = __x->__parent_; + __tree_right_rotate(__x); + } + __x = __x->__parent_; + __x->__is_black_ = true; + __x = __x->__parent_; + __x->__is_black_ = false; + __tree_left_rotate(__x); + break; + } + } + } +} + +// Precondition: __root != nullptr && __z != nullptr. +// __tree_invariant(__root) == true. +// __z == __root or == a direct or indirect child of __root. +// Effects: unlinks __z from the tree rooted at __root, rebalancing as needed. +// Postcondition: __tree_invariant(end_node->__left_) == true && end_node->__left_ +// nor any of its children refer to __z. end_node->__left_ +// may be different than the value passed in as __root. +template +void +__tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEPT +{ + // __z will be removed from the tree. Client still needs to destruct/deallocate it + // __y is either __z, or if __z has two children, __tree_next(__z). + // __y will have at most one child. + // __y will be the initial hole in the tree (make the hole at a leaf) + _NodePtr __y = (__z->__left_ == nullptr || __z->__right_ == nullptr) ? + __z : __tree_next(__z); + // __x is __y's possibly null single child + _NodePtr __x = __y->__left_ != nullptr ? __y->__left_ : __y->__right_; + // __w is __x's possibly null uncle (will become __x's sibling) + _NodePtr __w = nullptr; + // link __x to __y's parent, and find __w + if (__x != nullptr) + __x->__parent_ = __y->__parent_; + if (__tree_is_left_child(__y)) + { + __y->__parent_->__left_ = __x; + if (__y != __root) + __w = __y->__parent_->__right_; + else + __root = __x; // __w == nullptr + } + else + { + __y->__parent_->__right_ = __x; + // __y can't be root if it is a right child + __w = __y->__parent_->__left_; + } + bool __removed_black = __y->__is_black_; + // If we didn't remove __z, do so now by splicing in __y for __z, + // but copy __z's color. This does not impact __x or __w. + if (__y != __z) + { + // __z->__left_ != nulptr but __z->__right_ might == __x == nullptr + __y->__parent_ = __z->__parent_; + if (__tree_is_left_child(__z)) + __y->__parent_->__left_ = __y; + else + __y->__parent_->__right_ = __y; + __y->__left_ = __z->__left_; + __y->__left_->__parent_ = __y; + __y->__right_ = __z->__right_; + if (__y->__right_ != nullptr) + __y->__right_->__parent_ = __y; + __y->__is_black_ = __z->__is_black_; + if (__root == __z) + __root = __y; + } + // There is no need to rebalance if we removed a red, or if we removed + // the last node. + if (__removed_black && __root != nullptr) + { + // Rebalance: + // __x has an implicit black color (transferred from the removed __y) + // associated with it, no matter what its color is. + // If __x is __root (in which case it can't be null), it is supposed + // to be black anyway, and if it is doubly black, then the double + // can just be ignored. + // If __x is red (in which case it can't be null), then it can absorb + // the implicit black just by setting its color to black. + // Since __y was black and only had one child (which __x points to), __x + // is either red with no children, else null, otherwise __y would have + // different black heights under left and right pointers. + // if (__x == __root || __x != nullptr && !__x->__is_black_) + if (__x != nullptr) + __x->__is_black_ = true; + else + { + // Else __x isn't root, and is "doubly black", even though it may + // be null. __w can not be null here, else the parent would + // see a black height >= 2 on the __x side and a black height + // of 1 on the __w side (__w must be a non-null black or a red + // with a non-null black child). + while (true) + { + if (!__tree_is_left_child(__w)) // if x is left child + { + if (!__w->__is_black_) + { + __w->__is_black_ = true; + __w->__parent_->__is_black_ = false; + __tree_left_rotate(__w->__parent_); + // __x is still valid + // reset __root only if necessary + if (__root == __w->__left_) + __root = __w; + // reset sibling, and it still can't be null + __w = __w->__left_->__right_; + } + // __w->__is_black_ is now true, __w may have null children + if ((__w->__left_ == nullptr || __w->__left_->__is_black_) && + (__w->__right_ == nullptr || __w->__right_->__is_black_)) + { + __w->__is_black_ = false; + __x = __w->__parent_; + // __x can no longer be null + if (__x == __root || !__x->__is_black_) + { + __x->__is_black_ = true; + break; + } + // reset sibling, and it still can't be null + __w = __tree_is_left_child(__x) ? + __x->__parent_->__right_ : + __x->__parent_->__left_; + // continue; + } + else // __w has a red child + { + if (__w->__right_ == nullptr || __w->__right_->__is_black_) + { + // __w left child is non-null and red + __w->__left_->__is_black_ = true; + __w->__is_black_ = false; + __tree_right_rotate(__w); + // __w is known not to be root, so root hasn't changed + // reset sibling, and it still can't be null + __w = __w->__parent_; + } + // __w has a right red child, left child may be null + __w->__is_black_ = __w->__parent_->__is_black_; + __w->__parent_->__is_black_ = true; + __w->__right_->__is_black_ = true; + __tree_left_rotate(__w->__parent_); + break; + } + } + else + { + if (!__w->__is_black_) + { + __w->__is_black_ = true; + __w->__parent_->__is_black_ = false; + __tree_right_rotate(__w->__parent_); + // __x is still valid + // reset __root only if necessary + if (__root == __w->__right_) + __root = __w; + // reset sibling, and it still can't be null + __w = __w->__right_->__left_; + } + // __w->__is_black_ is now true, __w may have null children + if ((__w->__left_ == nullptr || __w->__left_->__is_black_) && + (__w->__right_ == nullptr || __w->__right_->__is_black_)) + { + __w->__is_black_ = false; + __x = __w->__parent_; + // __x can no longer be null + if (!__x->__is_black_ || __x == __root) + { + __x->__is_black_ = true; + break; + } + // reset sibling, and it still can't be null + __w = __tree_is_left_child(__x) ? + __x->__parent_->__right_ : + __x->__parent_->__left_; + // continue; + } + else // __w has a red child + { + if (__w->__left_ == nullptr || __w->__left_->__is_black_) + { + // __w right child is non-null and red + __w->__right_->__is_black_ = true; + __w->__is_black_ = false; + __tree_left_rotate(__w); + // __w is known not to be root, so root hasn't changed + // reset sibling, and it still can't be null + __w = __w->__parent_; + } + // __w has a left red child, right child may be null + __w->__is_black_ = __w->__parent_->__is_black_; + __w->__parent_->__is_black_ = true; + __w->__left_->__is_black_ = true; + __tree_right_rotate(__w->__parent_); + break; + } + } + } + } + } +} + +template class __map_node_destructor; + +template +class __tree_node_destructor +{ + typedef _Allocator allocator_type; + typedef allocator_traits __alloc_traits; + typedef typename __alloc_traits::value_type::value_type value_type; +public: + typedef typename __alloc_traits::pointer pointer; +private: + + allocator_type& __na_; + + __tree_node_destructor& operator=(const __tree_node_destructor&); + +public: + bool __value_constructed; + + _LIBCPP_INLINE_VISIBILITY + explicit __tree_node_destructor(allocator_type& __na) _NOEXCEPT + : __na_(__na), + __value_constructed(false) + {} + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + if (__value_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } + + template friend class __map_node_destructor; +}; + +// node + +template +class __tree_end_node +{ +public: + typedef _Pointer pointer; + pointer __left_; + + _LIBCPP_INLINE_VISIBILITY + __tree_end_node() _NOEXCEPT : __left_() {} +}; + +template +class __tree_node_base + : public __tree_end_node + < + typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__tree_node_base<_VoidPtr> > +#else + rebind<__tree_node_base<_VoidPtr> >::other +#endif + > +{ + __tree_node_base(const __tree_node_base&); + __tree_node_base& operator=(const __tree_node_base&); +public: + typedef typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__tree_node_base> +#else + rebind<__tree_node_base>::other +#endif + pointer; + typedef typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + const_pointer; + typedef __tree_end_node base; + + pointer __right_; + pointer __parent_; + bool __is_black_; + + _LIBCPP_INLINE_VISIBILITY + __tree_node_base() _NOEXCEPT + : __right_(), __parent_(), __is_black_(false) {} +}; + +template +class __tree_node + : public __tree_node_base<_VoidPtr> +{ +public: + typedef __tree_node_base<_VoidPtr> base; + typedef _Tp value_type; + + value_type __value_; + +#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + template + _LIBCPP_INLINE_VISIBILITY + explicit __tree_node(_Args&& ...__args) + : __value_(_VSTD::forward<_Args>(__args)...) {} +#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + _LIBCPP_INLINE_VISIBILITY + explicit __tree_node(const value_type& __v) + : __value_(__v) {} +#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +}; + +template class __map_iterator; +template class __map_const_iterator; + +template +class _LIBCPP_VISIBLE __tree_iterator +{ + typedef _NodePtr __node_pointer; + typedef typename pointer_traits<__node_pointer>::element_type __node; + typedef typename __node::base __node_base; + typedef typename __node_base::pointer __node_base_pointer; + + __node_pointer __ptr_; + + typedef pointer_traits<__node_pointer> __pointer_traits; +public: + typedef bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef _DiffType difference_type; + typedef value_type& reference; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY __tree_iterator() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &__ptr_->__value_;} + + _LIBCPP_INLINE_VISIBILITY + __tree_iterator& operator++() + {__ptr_ = static_cast<__node_pointer>(__tree_next(static_cast<__node_base_pointer>(__ptr_))); + return *this;} + _LIBCPP_INLINE_VISIBILITY + __tree_iterator operator++(int) + {__tree_iterator __t(*this); ++(*this); return __t;} + + _LIBCPP_INLINE_VISIBILITY + __tree_iterator& operator--() + {__ptr_ = static_cast<__node_pointer>(__tree_prev(static_cast<__node_base_pointer>(__ptr_))); + return *this;} + _LIBCPP_INLINE_VISIBILITY + __tree_iterator operator--(int) + {__tree_iterator __t(*this); --(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __tree_iterator& __x, const __tree_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __tree_iterator& __x, const __tree_iterator& __y) + {return !(__x == __y);} + +private: + _LIBCPP_INLINE_VISIBILITY + explicit __tree_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} + template friend class __tree; + template friend class _LIBCPP_VISIBLE __tree_const_iterator; + template friend class _LIBCPP_VISIBLE __map_iterator; + template friend class _LIBCPP_VISIBLE map; + template friend class _LIBCPP_VISIBLE multimap; + template friend class _LIBCPP_VISIBLE set; + template friend class _LIBCPP_VISIBLE multiset; +}; + +template +class _LIBCPP_VISIBLE __tree_const_iterator +{ + typedef _ConstNodePtr __node_pointer; + typedef typename pointer_traits<__node_pointer>::element_type __node; + typedef const typename __node::base __node_base; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__node_base> +#else + rebind<__node_base>::other +#endif + __node_base_pointer; + + __node_pointer __ptr_; + + typedef pointer_traits<__node_pointer> __pointer_traits; +public: + typedef bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef _DiffType difference_type; + typedef const value_type& reference; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY __tree_const_iterator() {} +private: + typedef typename remove_const<__node>::type __non_const_node; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__non_const_node> +#else + rebind<__non_const_node>::other +#endif + __non_const_node_pointer; + typedef __tree_iterator + __non_const_iterator; +public: + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT + : __ptr_(__p.__ptr_) {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &__ptr_->__value_;} + + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator& operator++() + {__ptr_ = static_cast<__node_pointer>(__tree_next(static_cast<__node_base_pointer>(__ptr_))); + return *this;} + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator operator++(int) + {__tree_const_iterator __t(*this); ++(*this); return __t;} + + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator& operator--() + {__ptr_ = static_cast<__node_pointer>(__tree_prev(static_cast<__node_base_pointer>(__ptr_))); + return *this;} + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator operator--(int) + {__tree_const_iterator __t(*this); --(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y) + {return !(__x == __y);} + +private: + _LIBCPP_INLINE_VISIBILITY + explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT + : __ptr_(__p) {} + template friend class __tree; + template friend class _LIBCPP_VISIBLE map; + template friend class _LIBCPP_VISIBLE multimap; + template friend class _LIBCPP_VISIBLE set; + template friend class _LIBCPP_VISIBLE multiset; + template friend class _LIBCPP_VISIBLE __map_const_iterator; +}; + +template +class __tree +{ +public: + typedef _Tp value_type; + typedef _Compare value_compare; + typedef _Allocator allocator_type; + typedef allocator_traits __alloc_traits; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + + typedef __tree_node __node; + typedef __tree_node_base __node_base; + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__node> +#else + rebind_alloc<__node>::other +#endif + __node_allocator; + typedef allocator_traits<__node_allocator> __node_traits; + typedef typename __node_traits::pointer __node_pointer; + typedef typename __node_traits::const_pointer __node_const_pointer; + typedef typename __node_base::pointer __node_base_pointer; + typedef typename __node_base::const_pointer __node_base_const_pointer; +private: + typedef typename __node_base::base __end_node_t; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__end_node_t> +#else + rebind<__end_node_t>::other +#endif + __end_node_ptr; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + __end_node_const_ptr; + + __node_pointer __begin_node_; + __compressed_pair<__end_node_t, __node_allocator> __pair1_; + __compressed_pair __pair3_; + +public: + _LIBCPP_INLINE_VISIBILITY + __node_pointer __end_node() _NOEXCEPT + { + return static_cast<__node_pointer> + ( + pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first()) + ); + } + _LIBCPP_INLINE_VISIBILITY + __node_const_pointer __end_node() const _NOEXCEPT + { + return static_cast<__node_const_pointer> + ( + pointer_traits<__end_node_const_ptr>::pointer_to(__pair1_.first()) + ); + } + _LIBCPP_INLINE_VISIBILITY + __node_allocator& __node_alloc() _NOEXCEPT {return __pair1_.second();} +private: + _LIBCPP_INLINE_VISIBILITY + const __node_allocator& __node_alloc() const _NOEXCEPT + {return __pair1_.second();} + _LIBCPP_INLINE_VISIBILITY + __node_pointer& __begin_node() _NOEXCEPT {return __begin_node_;} + _LIBCPP_INLINE_VISIBILITY + const __node_pointer& __begin_node() const _NOEXCEPT {return __begin_node_;} +public: + _LIBCPP_INLINE_VISIBILITY + allocator_type __alloc() const _NOEXCEPT + {return allocator_type(__node_alloc());} +private: + _LIBCPP_INLINE_VISIBILITY + size_type& size() _NOEXCEPT {return __pair3_.first();} +public: + _LIBCPP_INLINE_VISIBILITY + const size_type& size() const _NOEXCEPT {return __pair3_.first();} + _LIBCPP_INLINE_VISIBILITY + value_compare& value_comp() _NOEXCEPT {return __pair3_.second();} + _LIBCPP_INLINE_VISIBILITY + const value_compare& value_comp() const _NOEXCEPT + {return __pair3_.second();} +public: + _LIBCPP_INLINE_VISIBILITY + __node_pointer __root() _NOEXCEPT + {return static_cast<__node_pointer> (__end_node()->__left_);} + _LIBCPP_INLINE_VISIBILITY + __node_const_pointer __root() const _NOEXCEPT + {return static_cast<__node_const_pointer>(__end_node()->__left_);} + + typedef __tree_iterator iterator; + typedef __tree_const_iterator const_iterator; + + explicit __tree(const value_compare& __comp) + _NOEXCEPT_( + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_copy_constructible::value); + explicit __tree(const allocator_type& __a); + __tree(const value_compare& __comp, const allocator_type& __a); + __tree(const __tree& __t); + __tree& operator=(const __tree& __t); + template + void __assign_unique(_InputIterator __first, _InputIterator __last); + template + void __assign_multi(_InputIterator __first, _InputIterator __last); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + __tree(__tree&& __t) + _NOEXCEPT_( + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible::value); + __tree(__tree&& __t, const allocator_type& __a); + __tree& operator=(__tree&& __t) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable<__node_allocator>::value); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + ~__tree(); + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return iterator(__begin_node());} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return const_iterator(__begin_node());} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return iterator(__end_node());} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return const_iterator(__end_node());} + + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + {return __node_traits::max_size(__node_alloc());} + + void clear() _NOEXCEPT; + + void swap(__tree& __t) + _NOEXCEPT_( + __is_nothrow_swappable::value && + (!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value)); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + template + pair + __emplace_unique(_Args&&... __args); + template + iterator + __emplace_multi(_Args&&... __args); + + template + iterator + __emplace_hint_unique(const_iterator __p, _Args&&... __args); + template + iterator + __emplace_hint_multi(const_iterator __p, _Args&&... __args); +#endif // _LIBCPP_HAS_NO_VARIADICS + + template + pair __insert_unique(_V&& __v); + template + iterator __insert_unique(const_iterator __p, _V&& __v); + template + iterator __insert_multi(_V&& __v); + template + iterator __insert_multi(const_iterator __p, _V&& __v); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + pair __insert_unique(const value_type& __v); + iterator __insert_unique(const_iterator __p, const value_type& __v); + iterator __insert_multi(const value_type& __v); + iterator __insert_multi(const_iterator __p, const value_type& __v); + + pair __node_insert_unique(__node_pointer __nd); + iterator __node_insert_unique(const_iterator __p, + __node_pointer __nd); + + iterator __node_insert_multi(__node_pointer __nd); + iterator __node_insert_multi(const_iterator __p, __node_pointer __nd); + + iterator erase(const_iterator __p); + iterator erase(const_iterator __f, const_iterator __l); + template + size_type __erase_unique(const _Key& __k); + template + size_type __erase_multi(const _Key& __k); + + void __insert_node_at(__node_base_pointer __parent, + __node_base_pointer& __child, + __node_base_pointer __new_node); + + template + iterator find(const _Key& __v); + template + const_iterator find(const _Key& __v) const; + + template + size_type __count_unique(const _Key& __k) const; + template + size_type __count_multi(const _Key& __k) const; + + template + _LIBCPP_INLINE_VISIBILITY + iterator lower_bound(const _Key& __v) + {return __lower_bound(__v, __root(), __end_node());} + template + iterator __lower_bound(const _Key& __v, + __node_pointer __root, + __node_pointer __result); + template + _LIBCPP_INLINE_VISIBILITY + const_iterator lower_bound(const _Key& __v) const + {return __lower_bound(__v, __root(), __end_node());} + template + const_iterator __lower_bound(const _Key& __v, + __node_const_pointer __root, + __node_const_pointer __result) const; + template + _LIBCPP_INLINE_VISIBILITY + iterator upper_bound(const _Key& __v) + {return __upper_bound(__v, __root(), __end_node());} + template + iterator __upper_bound(const _Key& __v, + __node_pointer __root, + __node_pointer __result); + template + _LIBCPP_INLINE_VISIBILITY + const_iterator upper_bound(const _Key& __v) const + {return __upper_bound(__v, __root(), __end_node());} + template + const_iterator __upper_bound(const _Key& __v, + __node_const_pointer __root, + __node_const_pointer __result) const; + template + pair + __equal_range_unique(const _Key& __k); + template + pair + __equal_range_unique(const _Key& __k) const; + + template + pair + __equal_range_multi(const _Key& __k); + template + pair + __equal_range_multi(const _Key& __k) const; + + typedef __tree_node_destructor<__node_allocator> _D; + typedef unique_ptr<__node, _D> __node_holder; + + __node_holder remove(const_iterator __p) _NOEXCEPT; +private: + typename __node_base::pointer& + __find_leaf_low(typename __node_base::pointer& __parent, const value_type& __v); + typename __node_base::pointer& + __find_leaf_high(typename __node_base::pointer& __parent, const value_type& __v); + typename __node_base::pointer& + __find_leaf(const_iterator __hint, + typename __node_base::pointer& __parent, const value_type& __v); + template + typename __node_base::pointer& + __find_equal(typename __node_base::pointer& __parent, const _Key& __v); + template + typename __node_base::pointer& + __find_equal(const_iterator __hint, typename __node_base::pointer& __parent, + const _Key& __v); + +#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + template + __node_holder __construct_node(_Args&& ...__args); +#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + __node_holder __construct_node(const value_type& __v); +#endif + + void destroy(__node_pointer __nd) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __tree& __t) + {__copy_assign_alloc(__t, integral_constant());} + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __tree& __t, true_type) + {__node_alloc() = __t.__node_alloc();} + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __tree& __t, false_type) {} + + void __move_assign(__tree& __t, false_type); + void __move_assign(__tree& __t, true_type) + _NOEXCEPT_(is_nothrow_move_assignable::value && + is_nothrow_move_assignable<__node_allocator>::value); + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__tree& __t) + _NOEXCEPT_( + !__node_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<__node_allocator>::value) + {__move_assign_alloc(__t, integral_constant());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__tree& __t, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) + {__node_alloc() = _VSTD::move(__t.__node_alloc());} + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__tree& __t, false_type) _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y) + _NOEXCEPT_( + !__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) + {__swap_alloc(__x, __y, integral_constant());} + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type) + _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value) + { + using _VSTD::swap; + swap(__x, __y); + } + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type) + _NOEXCEPT + {} + + __node_pointer __detach(); + static __node_pointer __detach(__node_pointer); +}; + +template +__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) + _NOEXCEPT_( + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_copy_constructible::value) + : __pair3_(0, __comp) +{ + __begin_node() = __end_node(); +} + +template +__tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a) + : __pair1_(__node_allocator(__a)), + __begin_node_(__node_pointer()), + __pair3_(0) +{ + __begin_node() = __end_node(); +} + +template +__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, + const allocator_type& __a) + : __pair1_(__node_allocator(__a)), + __begin_node_(__node_pointer()), + __pair3_(0, __comp) +{ + __begin_node() = __end_node(); +} + +// Precondition: size() != 0 +template +typename __tree<_Tp, _Compare, _Allocator>::__node_pointer +__tree<_Tp, _Compare, _Allocator>::__detach() +{ + __node_pointer __cache = __begin_node(); + __begin_node() = __end_node(); + __end_node()->__left_->__parent_ = nullptr; + __end_node()->__left_ = nullptr; + size() = 0; + // __cache->__left_ == nullptr + if (__cache->__right_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__right_); + // __cache->__left_ == nullptr + // __cache->__right_ == nullptr + return __cache; +} + +// Precondition: __cache != nullptr +// __cache->left_ == nullptr +// __cache->right_ == nullptr +// This is no longer a red-black tree +template +typename __tree<_Tp, _Compare, _Allocator>::__node_pointer +__tree<_Tp, _Compare, _Allocator>::__detach(__node_pointer __cache) +{ + if (__cache->__parent_ == nullptr) + return nullptr; + if (__tree_is_left_child(__cache)) + { + __cache->__parent_->__left_ = nullptr; + __cache = static_cast<__node_pointer>(__cache->__parent_); + if (__cache->__right_ == nullptr) + return __cache; + return static_cast<__node_pointer>(__tree_leaf(__cache->__right_)); + } + // __cache is right child + __cache->__parent_->__right_ = nullptr; + __cache = static_cast<__node_pointer>(__cache->__parent_); + if (__cache->__left_ == nullptr) + return __cache; + return static_cast<__node_pointer>(__tree_leaf(__cache->__left_)); +} + +template +__tree<_Tp, _Compare, _Allocator>& +__tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) +{ + if (this != &__t) + { + value_comp() = __t.value_comp(); + __copy_assign_alloc(__t); + __assign_multi(__t.begin(), __t.end()); + } + return *this; +} + +template +template +void +__tree<_Tp, _Compare, _Allocator>::__assign_unique(_InputIterator __first, _InputIterator __last) +{ + if (size() != 0) + { + __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__value_ = *__first; + __node_pointer __next = __detach(__cache); + __node_insert_unique(__cache); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + if (__cache != nullptr) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + } + } + for (; __first != __last; ++__first) + __insert_unique(*__first); +} + +template +template +void +__tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _InputIterator __last) +{ + if (size() != 0) + { + __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __cache != nullptr && __first != __last; ++__first) + { + __cache->__value_ = *__first; + __node_pointer __next = __detach(__cache); + __node_insert_multi(__cache); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + if (__cache != nullptr) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + } + } + for (; __first != __last; ++__first) + __insert_multi(*__first); +} + +template +__tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) + : __begin_node_(__node_pointer()), + __pair1_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())), + __pair3_(0, __t.value_comp()) +{ + __begin_node() = __end_node(); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) + _NOEXCEPT_( + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible::value) + : __begin_node_(_VSTD::move(__t.__begin_node_)), + __pair1_(_VSTD::move(__t.__pair1_)), + __pair3_(_VSTD::move(__t.__pair3_)) +{ + if (size() == 0) + __begin_node() = __end_node(); + else + { + __end_node()->__left_->__parent_ = __end_node(); + __t.__begin_node() = __t.__end_node(); + __t.__end_node()->__left_ = nullptr; + __t.size() = 0; + } +} + +template +__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a) + : __pair1_(__node_allocator(__a)), + __pair3_(0, _VSTD::move(__t.value_comp())) +{ + if (__a == __t.__alloc()) + { + if (__t.size() == 0) + __begin_node() = __end_node(); + else + { + __begin_node() = __t.__begin_node(); + __end_node()->__left_ = __t.__end_node()->__left_; + __end_node()->__left_->__parent_ = __end_node(); + size() = __t.size(); + __t.__begin_node() = __t.__end_node(); + __t.__end_node()->__left_ = nullptr; + __t.size() = 0; + } + } + else + { + __begin_node() = __end_node(); + } +} + +template +void +__tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) + _NOEXCEPT_(is_nothrow_move_assignable::value && + is_nothrow_move_assignable<__node_allocator>::value) +{ + destroy(static_cast<__node_pointer>(__end_node()->__left_)); + __begin_node_ = __t.__begin_node_; + __pair1_.first() = __t.__pair1_.first(); + __move_assign_alloc(__t); + __pair3_ = _VSTD::move(__t.__pair3_); + if (size() == 0) + __begin_node() = __end_node(); + else + { + __end_node()->__left_->__parent_ = __end_node(); + __t.__begin_node() = __t.__end_node(); + __t.__end_node()->__left_ = nullptr; + __t.size() = 0; + } +} + +template +void +__tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) +{ + if (__node_alloc() == __t.__node_alloc()) + __move_assign(__t, true_type()); + else + { + value_comp() = _VSTD::move(__t.value_comp()); + const_iterator __e = end(); + if (size() != 0) + { + __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + while (__cache != nullptr && __t.size() != 0) + { + __cache->__value_ = _VSTD::move(__t.remove(__t.begin())->__value_); + __node_pointer __next = __detach(__cache); + __node_insert_multi(__cache); + __cache = __next; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + if (__cache != nullptr) + { + while (__cache->__parent_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__parent_); + destroy(__cache); + } + } + while (__t.size() != 0) + __insert_multi(__e, _VSTD::move(__t.remove(__t.begin())->__value_)); + } +} + +template +__tree<_Tp, _Compare, _Allocator>& +__tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable<__node_allocator>::value) + +{ + __move_assign(__t, integral_constant()); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +__tree<_Tp, _Compare, _Allocator>::~__tree() +{ + destroy(__root()); +} + +template +void +__tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT +{ + if (__nd != nullptr) + { + destroy(static_cast<__node_pointer>(__nd->__left_)); + destroy(static_cast<__node_pointer>(__nd->__right_)); + __node_allocator& __na = __node_alloc(); + __node_traits::destroy(__na, _VSTD::addressof(__nd->__value_)); + __node_traits::deallocate(__na, __nd, 1); + } +} + +template +void +__tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) + _NOEXCEPT_( + __is_nothrow_swappable::value && + (!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value)) +{ + using _VSTD::swap; + swap(__begin_node_, __t.__begin_node_); + swap(__pair1_.first(), __t.__pair1_.first()); + __swap_alloc(__node_alloc(), __t.__node_alloc()); + __pair3_.swap(__t.__pair3_); + if (size() == 0) + __begin_node() = __end_node(); + else + __end_node()->__left_->__parent_ = __end_node(); + if (__t.size() == 0) + __t.__begin_node() = __t.__end_node(); + else + __t.__end_node()->__left_->__parent_ = __t.__end_node(); +} + +template +void +__tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT +{ + destroy(__root()); + size() = 0; + __begin_node() = __end_node(); + __end_node()->__left_ = nullptr; +} + +// Find lower_bound place to insert +// Set __parent to parent of null leaf +// Return reference to null leaf +template +typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer& +__tree<_Tp, _Compare, _Allocator>::__find_leaf_low(typename __node_base::pointer& __parent, + const value_type& __v) +{ + __node_pointer __nd = __root(); + if (__nd != nullptr) + { + while (true) + { + if (value_comp()(__nd->__value_, __v)) + { + if (__nd->__right_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__right_); + else + { + __parent = __nd; + return __parent->__right_; + } + } + else + { + if (__nd->__left_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__left_); + else + { + __parent = __nd; + return __parent->__left_; + } + } + } + } + __parent = __end_node(); + return __parent->__left_; +} + +// Find upper_bound place to insert +// Set __parent to parent of null leaf +// Return reference to null leaf +template +typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer& +__tree<_Tp, _Compare, _Allocator>::__find_leaf_high(typename __node_base::pointer& __parent, + const value_type& __v) +{ + __node_pointer __nd = __root(); + if (__nd != nullptr) + { + while (true) + { + if (value_comp()(__v, __nd->__value_)) + { + if (__nd->__left_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__left_); + else + { + __parent = __nd; + return __parent->__left_; + } + } + else + { + if (__nd->__right_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__right_); + else + { + __parent = __nd; + return __parent->__right_; + } + } + } + } + __parent = __end_node(); + return __parent->__left_; +} + +// Find leaf place to insert closest to __hint +// First check prior to __hint. +// Next check after __hint. +// Next do O(log N) search. +// Set __parent to parent of null leaf +// Return reference to null leaf +template +typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer& +__tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, + typename __node_base::pointer& __parent, + const value_type& __v) +{ + if (__hint == end() || !value_comp()(*__hint, __v)) // check before + { + // __v <= *__hint + const_iterator __prior = __hint; + if (__prior == begin() || !value_comp()(__v, *--__prior)) + { + // *prev(__hint) <= __v <= *__hint + if (__hint.__ptr_->__left_ == nullptr) + { + __parent = const_cast<__node_pointer&>(__hint.__ptr_); + return __parent->__left_; + } + else + { + __parent = const_cast<__node_pointer&>(__prior.__ptr_); + return __parent->__right_; + } + } + // __v < *prev(__hint) + return __find_leaf_high(__parent, __v); + } + // else __v > *__hint + return __find_leaf_low(__parent, __v); +} + +// Find place to insert if __v doesn't exist +// Set __parent to parent of null leaf +// Return reference to null leaf +// If __v exists, set parent to node of __v and return reference to node of __v +template +template +typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer& +__tree<_Tp, _Compare, _Allocator>::__find_equal(typename __node_base::pointer& __parent, + const _Key& __v) +{ + __node_pointer __nd = __root(); + if (__nd != nullptr) + { + while (true) + { + if (value_comp()(__v, __nd->__value_)) + { + if (__nd->__left_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__left_); + else + { + __parent = __nd; + return __parent->__left_; + } + } + else if (value_comp()(__nd->__value_, __v)) + { + if (__nd->__right_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__right_); + else + { + __parent = __nd; + return __parent->__right_; + } + } + else + { + __parent = __nd; + return __parent; + } + } + } + __parent = __end_node(); + return __parent->__left_; +} + +// Find place to insert if __v doesn't exist +// First check prior to __hint. +// Next check after __hint. +// Next do O(log N) search. +// Set __parent to parent of null leaf +// Return reference to null leaf +// If __v exists, set parent to node of __v and return reference to node of __v +template +template +typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer& +__tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, + typename __node_base::pointer& __parent, + const _Key& __v) +{ + if (__hint == end() || value_comp()(__v, *__hint)) // check before + { + // __v < *__hint + const_iterator __prior = __hint; + if (__prior == begin() || value_comp()(*--__prior, __v)) + { + // *prev(__hint) < __v < *__hint + if (__hint.__ptr_->__left_ == nullptr) + { + __parent = const_cast<__node_pointer&>(__hint.__ptr_); + return __parent->__left_; + } + else + { + __parent = const_cast<__node_pointer&>(__prior.__ptr_); + return __parent->__right_; + } + } + // __v <= *prev(__hint) + return __find_equal(__parent, __v); + } + else if (value_comp()(*__hint, __v)) // check after + { + // *__hint < __v + const_iterator __next = _VSTD::next(__hint); + if (__next == end() || value_comp()(__v, *__next)) + { + // *__hint < __v < *_VSTD::next(__hint) + if (__hint.__ptr_->__right_ == nullptr) + { + __parent = const_cast<__node_pointer&>(__hint.__ptr_); + return __parent->__right_; + } + else + { + __parent = const_cast<__node_pointer&>(__next.__ptr_); + return __parent->__left_; + } + } + // *next(__hint) <= __v + return __find_equal(__parent, __v); + } + // else __v == *__hint + __parent = const_cast<__node_pointer&>(__hint.__ptr_); + return __parent; +} + +template +void +__tree<_Tp, _Compare, _Allocator>::__insert_node_at(__node_base_pointer __parent, + __node_base_pointer& __child, + __node_base_pointer __new_node) +{ + __new_node->__left_ = nullptr; + __new_node->__right_ = nullptr; + __new_node->__parent_ = __parent; + __child = __new_node; + if (__begin_node()->__left_ != nullptr) + __begin_node() = static_cast<__node_pointer>(__begin_node()->__left_); + __tree_balance_after_insert(__end_node()->__left_, __child); + ++size(); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +typename __tree<_Tp, _Compare, _Allocator>::__node_holder +__tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&& ...__args) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_Args>(__args)...); + __h.get_deleter().__value_constructed = true; + return __h; +} + +template +template +pair::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__emplace_unique(_Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __node_base_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, __h->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + bool __inserted = false; + if (__child == nullptr) + { + __insert_node_at(__parent, __child, __h.get()); + __r = __h.release(); + __inserted = true; + } + return pair(iterator(__r), __inserted); +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique(const_iterator __p, _Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __node_base_pointer __parent; + __node_base_pointer& __child = __find_equal(__p, __parent, __h->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __insert_node_at(__parent, __child, __h.get()); + __r = __h.release(); + } + return iterator(__r); +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __node_base_pointer __parent; + __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_); + __insert_node_at(__parent, __child, __h.get()); + return iterator(static_cast<__node_pointer>(__h.release())); +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, + _Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __node_base_pointer __parent; + __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_); + __insert_node_at(__parent, __child, __h.get()); + return iterator(static_cast<__node_pointer>(__h.release())); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template +template +pair::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__insert_unique(_V&& __v) +{ + __node_holder __h = __construct_node(_VSTD::forward<_V>(__v)); + pair __r = __node_insert_unique(__h.get()); + if (__r.second) + __h.release(); + return __r; +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__insert_unique(const_iterator __p, _V&& __v) +{ + __node_holder __h = __construct_node(_VSTD::forward<_V>(__v)); + iterator __r = __node_insert_unique(__p, __h.get()); + if (__r.__ptr_ == __h.get()) + __h.release(); + return __r; +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__insert_multi(_V&& __v) +{ + __node_holder __h = __construct_node(_VSTD::forward<_V>(__v)); + __node_base_pointer __parent; + __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_); + __insert_node_at(__parent, __child, __h.get()); + return iterator(__h.release()); +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, _V&& __v) +{ + __node_holder __h = __construct_node(_VSTD::forward<_V>(__v)); + __node_base_pointer __parent; + __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_); + __insert_node_at(__parent, __child, __h.get()); + return iterator(__h.release()); +} + +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +typename __tree<_Tp, _Compare, _Allocator>::__node_holder +__tree<_Tp, _Compare, _Allocator>::__construct_node(const value_type& __v) +{ + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v); + __h.get_deleter().__value_constructed = true; + return _VSTD::move(__h); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +pair::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__insert_unique(const value_type& __v) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, __v); + __node_pointer __r = static_cast<__node_pointer>(__child); + bool __inserted = false; + if (__child == nullptr) + { + __node_holder __h = __construct_node(__v); + __insert_node_at(__parent, __child, __h.get()); + __r = __h.release(); + __inserted = true; + } + return pair(iterator(__r), __inserted); +} + +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__insert_unique(const_iterator __p, const value_type& __v) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_equal(__p, __parent, __v); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __node_holder __h = __construct_node(__v); + __insert_node_at(__parent, __child, __h.get()); + __r = __h.release(); + } + return iterator(__r); +} + +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__insert_multi(const value_type& __v) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_leaf_high(__parent, __v); + __node_holder __h = __construct_node(__v); + __insert_node_at(__parent, __child, __h.get()); + return iterator(__h.release()); +} + +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, const value_type& __v) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_leaf(__p, __parent, __v); + __node_holder __h = __construct_node(__v); + __insert_node_at(__parent, __child, __h.get()); + return iterator(__h.release()); +} + +template +pair::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__node_insert_unique(__node_pointer __nd) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, __nd->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + bool __inserted = false; + if (__child == nullptr) + { + __insert_node_at(__parent, __child, __nd); + __r = __nd; + __inserted = true; + } + return pair(iterator(__r), __inserted); +} + +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_insert_unique(const_iterator __p, + __node_pointer __nd) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_equal(__p, __parent, __nd->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __insert_node_at(__parent, __child, __nd); + __r = __nd; + } + return iterator(__r); +} + +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_leaf_high(__parent, __nd->__value_); + __insert_node_at(__parent, __child, __nd); + return iterator(__nd); +} + +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(const_iterator __p, + __node_pointer __nd) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_leaf(__p, __parent, __nd->__value_); + __insert_node_at(__parent, __child, __nd); + return iterator(__nd); +} + +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p) +{ + __node_pointer __np = const_cast<__node_pointer>(__p.__ptr_); + iterator __r(__np); + ++__r; + if (__begin_node() == __np) + __begin_node() = __r.__ptr_; + --size(); + __node_allocator& __na = __node_alloc(); + __node_traits::destroy(__na, const_cast(_VSTD::addressof(*__p))); + __tree_remove(__end_node()->__left_, + static_cast<__node_base_pointer>(__np)); + __node_traits::deallocate(__na, __np, 1); + return __r; +} + +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::erase(const_iterator __f, const_iterator __l) +{ + while (__f != __l) + __f = erase(__f); + return iterator(const_cast<__node_pointer>(__l.__ptr_)); +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__erase_unique(const _Key& __k) +{ + iterator __i = find(__k); + if (__i == end()) + return 0; + erase(__i); + return 1; +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__erase_multi(const _Key& __k) +{ + pair __p = __equal_range_multi(__k); + size_type __r = 0; + for (; __p.first != __p.second; ++__r) + __p.first = erase(__p.first); + return __r; +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) +{ + iterator __p = __lower_bound(__v, __root(), __end_node()); + if (__p != end() && !value_comp()(__v, *__p)) + return __p; + return end(); +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) const +{ + const_iterator __p = __lower_bound(__v, __root(), __end_node()); + if (__p != end() && !value_comp()(__v, *__p)) + return __p; + return end(); +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__count_unique(const _Key& __k) const +{ + __node_const_pointer __result = __end_node(); + __node_const_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = __rt; + __rt = static_cast<__node_const_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_const_pointer>(__rt->__right_); + else + return 1; + } + return 0; +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const +{ + typedef pair _P; + __node_const_pointer __result = __end_node(); + __node_const_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = __rt; + __rt = static_cast<__node_const_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_const_pointer>(__rt->__right_); + else + return _VSTD::distance( + __lower_bound(__k, static_cast<__node_const_pointer>(__rt->__left_), __rt), + __upper_bound(__k, static_cast<__node_const_pointer>(__rt->__right_), __result) + ); + } + return 0; +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, + __node_pointer __root, + __node_pointer __result) +{ + while (__root != nullptr) + { + if (!value_comp()(__root->__value_, __v)) + { + __result = __root; + __root = static_cast<__node_pointer>(__root->__left_); + } + else + __root = static_cast<__node_pointer>(__root->__right_); + } + return iterator(__result); +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, + __node_const_pointer __root, + __node_const_pointer __result) const +{ + while (__root != nullptr) + { + if (!value_comp()(__root->__value_, __v)) + { + __result = __root; + __root = static_cast<__node_const_pointer>(__root->__left_); + } + else + __root = static_cast<__node_const_pointer>(__root->__right_); + } + return const_iterator(__result); +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, + __node_pointer __root, + __node_pointer __result) +{ + while (__root != nullptr) + { + if (value_comp()(__v, __root->__value_)) + { + __result = __root; + __root = static_cast<__node_pointer>(__root->__left_); + } + else + __root = static_cast<__node_pointer>(__root->__right_); + } + return iterator(__result); +} + +template +template +typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, + __node_const_pointer __root, + __node_const_pointer __result) const +{ + while (__root != nullptr) + { + if (value_comp()(__v, __root->__value_)) + { + __result = __root; + __root = static_cast<__node_const_pointer>(__root->__left_); + } + else + __root = static_cast<__node_const_pointer>(__root->__right_); + } + return const_iterator(__result); +} + +template +template +pair::iterator, + typename __tree<_Tp, _Compare, _Allocator>::iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) +{ + typedef pair _P; + __node_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = __rt; + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _P(iterator(__rt), + iterator( + __rt->__right_ != nullptr ? + static_cast<__node_pointer>(__tree_min(__rt->__right_)) + : __result)); + } + return _P(iterator(__result), iterator(__result)); +} + +template +template +pair::const_iterator, + typename __tree<_Tp, _Compare, _Allocator>::const_iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const +{ + typedef pair _P; + __node_const_pointer __result = __end_node(); + __node_const_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = __rt; + __rt = static_cast<__node_const_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_const_pointer>(__rt->__right_); + else + return _P(const_iterator(__rt), + const_iterator( + __rt->__right_ != nullptr ? + static_cast<__node_const_pointer>(__tree_min(__rt->__right_)) + : __result)); + } + return _P(const_iterator(__result), const_iterator(__result)); +} + +template +template +pair::iterator, + typename __tree<_Tp, _Compare, _Allocator>::iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) +{ + typedef pair _P; + __node_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = __rt; + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _P(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), __rt), + __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)); + } + return _P(iterator(__result), iterator(__result)); +} + +template +template +pair::const_iterator, + typename __tree<_Tp, _Compare, _Allocator>::const_iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const +{ + typedef pair _P; + __node_const_pointer __result = __end_node(); + __node_const_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = __rt; + __rt = static_cast<__node_const_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_const_pointer>(__rt->__right_); + else + return _P(__lower_bound(__k, static_cast<__node_const_pointer>(__rt->__left_), __rt), + __upper_bound(__k, static_cast<__node_const_pointer>(__rt->__right_), __result)); + } + return _P(const_iterator(__result), const_iterator(__result)); +} + +template +typename __tree<_Tp, _Compare, _Allocator>::__node_holder +__tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT +{ + __node_pointer __np = const_cast<__node_pointer>(__p.__ptr_); + if (__begin_node() == __np) + { + if (__np->__right_ != nullptr) + __begin_node() = static_cast<__node_pointer>(__np->__right_); + else + __begin_node() = static_cast<__node_pointer>(__np->__parent_); + } + --size(); + __tree_remove(__end_node()->__left_, + static_cast<__node_base_pointer>(__np)); + return __node_holder(__np, _D(__node_alloc())); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__tree<_Tp, _Compare, _Allocator>& __x, + __tree<_Tp, _Compare, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___TREE diff --git a/contrib/libc++/include/__tuple b/contrib/libc++/include/__tuple new file mode 100644 index 000000000000..15193b4d1074 --- /dev/null +++ b/contrib/libc++/include/__tuple @@ -0,0 +1,269 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___TUPLE +#define _LIBCPP___TUPLE + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_HAS_NO_VARIADICS + +#include <__tuple_03> + +#else // _LIBCPP_HAS_NO_VARIADICS + +_LIBCPP_BEGIN_NAMESPACE_STD + +template class _LIBCPP_VISIBLE tuple_size; + +template +class _LIBCPP_VISIBLE tuple_size + : public tuple_size<_Tp> {}; + +template +class _LIBCPP_VISIBLE tuple_size + : public tuple_size<_Tp> {}; + +template +class _LIBCPP_VISIBLE tuple_size + : public tuple_size<_Tp> {}; + +template class _LIBCPP_VISIBLE tuple_element; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, const _Tp> +{ +public: + typedef typename add_const::type>::type type; +}; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, volatile _Tp> +{ +public: + typedef typename add_volatile::type>::type type; +}; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, const volatile _Tp> +{ +public: + typedef typename add_cv::type>::type type; +}; + +template class _LIBCPP_VISIBLE tuple; +template class _LIBCPP_VISIBLE pair; +template struct _LIBCPP_VISIBLE array; + +template struct __tuple_like : false_type {}; + +template struct __tuple_like : public __tuple_like<_Tp> {}; +template struct __tuple_like : public __tuple_like<_Tp> {}; +template struct __tuple_like : public __tuple_like<_Tp> {}; + +template struct __tuple_like > : true_type {}; +template struct __tuple_like > : true_type {}; +template struct __tuple_like > : true_type {}; + +template +typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(tuple<_Tp...>&) _NOEXCEPT; + +template +const typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(const tuple<_Tp...>&) _NOEXCEPT; + +template +typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(tuple<_Tp...>&&) _NOEXCEPT; + +template +typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(pair<_T1, _T2>&) _NOEXCEPT; + +template +const typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(const pair<_T1, _T2>&) _NOEXCEPT; + +template +typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(pair<_T1, _T2>&&) _NOEXCEPT; + +template +_Tp& +get(array<_Tp, _Size>&) _NOEXCEPT; + +template +const _Tp& +get(const array<_Tp, _Size>&) _NOEXCEPT; + +template +_Tp&& +get(array<_Tp, _Size>&&) _NOEXCEPT; + +// __make_tuple_indices + +template struct __tuple_indices {}; + +template +struct __make_indices_imp; + +template +struct __make_indices_imp<_Sp, __tuple_indices<_Indices...>, _Ep> +{ + typedef typename __make_indices_imp<_Sp+1, __tuple_indices<_Indices..., _Sp>, _Ep>::type type; +}; + +template +struct __make_indices_imp<_Ep, __tuple_indices<_Indices...>, _Ep> +{ + typedef __tuple_indices<_Indices...> type; +}; + +template +struct __make_tuple_indices +{ + static_assert(_Sp <= _Ep, "__make_tuple_indices input error"); + typedef typename __make_indices_imp<_Sp, __tuple_indices<>, _Ep>::type type; +}; + +// __tuple_types + +template struct __tuple_types {}; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, __tuple_types<> > +{ +public: + static_assert(_Ip == 0, "tuple_element index out of range"); + static_assert(_Ip != 0, "tuple_element index out of range"); +}; + +template +class _LIBCPP_VISIBLE tuple_element<0, __tuple_types<_Hp, _Tp...> > +{ +public: + typedef _Hp type; +}; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, __tuple_types<_Hp, _Tp...> > +{ +public: + typedef typename tuple_element<_Ip-1, __tuple_types<_Tp...> >::type type; +}; + +template +class _LIBCPP_VISIBLE tuple_size<__tuple_types<_Tp...> > + : public integral_constant +{ +}; + +template struct __tuple_like<__tuple_types<_Tp...> > : true_type {}; + +// __make_tuple_types + +// __make_tuple_types<_Tuple<_Types...>, _Ep, _Sp>::type is a +// __tuple_types<_Types...> using only those _Types in the range [_Sp, _Ep). +// _Sp defaults to 0 and _Ep defaults to tuple_size<_Tuple>. If _Tuple is a +// lvalue_reference type, then __tuple_types<_Types&...> is the result. + +template +struct __make_tuple_types_imp; + +template +struct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Sp, _Ep> +{ + typedef typename remove_reference<_Tp>::type _Tpr; + typedef typename __make_tuple_types_imp<__tuple_types<_Types..., + typename conditional::value, + typename tuple_element<_Sp, _Tpr>::type&, + typename tuple_element<_Sp, _Tpr>::type>::type>, + _Tp, _Sp+1, _Ep>::type type; +}; + +template +struct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Ep, _Ep> +{ + typedef __tuple_types<_Types...> type; +}; + +template ::type>::value, size_t _Sp = 0> +struct __make_tuple_types +{ + static_assert(_Sp <= _Ep, "__make_tuple_types input error"); + typedef typename __make_tuple_types_imp<__tuple_types<>, _Tp, _Sp, _Ep>::type type; +}; + +// __tuple_convertible + +template +struct __tuple_convertible_imp : public false_type {}; + +template +struct __tuple_convertible_imp, __tuple_types<_Up0, _Up...> > + : public integral_constant::value && + __tuple_convertible_imp, __tuple_types<_Up...> >::value> {}; + +template <> +struct __tuple_convertible_imp, __tuple_types<> > + : public true_type {}; + +template ::type>::value, + bool = __tuple_like<_Up>::value> +struct __tuple_convertible + : public false_type {}; + +template +struct __tuple_convertible<_Tp, _Up, true, true> + : public __tuple_convertible_imp::type>::value == + tuple_size<_Up>::value, + typename __make_tuple_types<_Tp>::type, typename __make_tuple_types<_Up>::type> +{}; + +// __tuple_assignable + +template +struct __tuple_assignable_imp : public false_type {}; + +template +struct __tuple_assignable_imp, __tuple_types<_Up0, _Up...> > + : public integral_constant::value && + __tuple_assignable_imp, __tuple_types<_Up...> >::value> {}; + +template <> +struct __tuple_assignable_imp, __tuple_types<> > + : public true_type {}; + +template ::type>::value, + bool = __tuple_like<_Up>::value> +struct __tuple_assignable + : public false_type {}; + +template +struct __tuple_assignable<_Tp, _Up, true, true> + : public __tuple_assignable_imp::type>::value == + tuple_size<_Up>::value, + typename __make_tuple_types<_Tp>::type, typename __make_tuple_types<_Up>::type> +{}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_HAS_NO_VARIADICS + +#endif // _LIBCPP___TUPLE diff --git a/contrib/libc++/include/__tuple_03 b/contrib/libc++/include/__tuple_03 new file mode 100644 index 000000000000..a28ac0800ae9 --- /dev/null +++ b/contrib/libc++/include/__tuple_03 @@ -0,0 +1,27 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___TUPLE_03 +#define _LIBCPP___TUPLE_03 + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template class _LIBCPP_VISIBLE tuple_size; +template class _LIBCPP_VISIBLE tuple_element; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___TUPLE_03 diff --git a/contrib/libc++/include/algorithm b/contrib/libc++/include/algorithm new file mode 100644 index 000000000000..a89b9dd65eab --- /dev/null +++ b/contrib/libc++/include/algorithm @@ -0,0 +1,5361 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ALGORITHM +#define _LIBCPP_ALGORITHM + +/* + algorithm synopsis + +#include + +namespace std +{ + +template + bool + all_of(InputIterator first, InputIterator last, Predicate pred); + +template + bool + any_of(InputIterator first, InputIterator last, Predicate pred); + +template + bool + none_of(InputIterator first, InputIterator last, Predicate pred); + +template + Function + for_each(InputIterator first, InputIterator last, Function f); + +template + InputIterator + find(InputIterator first, InputIterator last, const T& value); + +template + InputIterator + find_if(InputIterator first, InputIterator last, Predicate pred); + +template + InputIterator + find_if_not(InputIterator first, InputIterator last, Predicate pred); + +template + ForwardIterator1 + find_end(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); + +template + ForwardIterator1 + find_end(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); + +template + ForwardIterator1 + find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); + +template + ForwardIterator1 + find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); + +template + ForwardIterator + adjacent_find(ForwardIterator first, ForwardIterator last); + +template + ForwardIterator + adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); + +template + typename iterator_traits::difference_type + count(InputIterator first, InputIterator last, const T& value); + +template + typename iterator_traits::difference_type + count_if(InputIterator first, InputIterator last, Predicate pred); + +template + pair + mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); + +template + pair + mismatch(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, BinaryPredicate pred); + +template + bool + equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); + +template + bool + equal(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, BinaryPredicate pred); + +template + bool + is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2); + +template + bool + is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, BinaryPredicate pred); + +template + ForwardIterator1 + search(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); + +template + ForwardIterator1 + search(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); + +template + ForwardIterator + search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value); + +template + ForwardIterator + search_n(ForwardIterator first, ForwardIterator last, + Size count, const T& value, BinaryPredicate pred); + +template + OutputIterator + copy(InputIterator first, InputIterator last, OutputIterator result); + +template + OutputIterator + copy_if(InputIterator first, InputIterator last, + OutputIterator result, Predicate pred); + +template + OutputIterator + copy_n(InputIterator first, Size n, OutputIterator result); + +template + BidirectionalIterator2 + copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, + BidirectionalIterator2 result); + +template + ForwardIterator2 + swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); + +template + void + iter_swap(ForwardIterator1 a, ForwardIterator2 b); + +template + OutputIterator + transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op); + +template + OutputIterator + transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, + OutputIterator result, BinaryOperation binary_op); + +template + void + replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value); + +template + void + replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value); + +template + OutputIterator + replace_copy(InputIterator first, InputIterator last, OutputIterator result, + const T& old_value, const T& new_value); + +template + OutputIterator + replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value); + +template + void + fill(ForwardIterator first, ForwardIterator last, const T& value); + +template + OutputIterator + fill_n(OutputIterator first, Size n, const T& value); + +template + void + generate(ForwardIterator first, ForwardIterator last, Generator gen); + +template + OutputIterator + generate_n(OutputIterator first, Size n, Generator gen); + +template + ForwardIterator + remove(ForwardIterator first, ForwardIterator last, const T& value); + +template + ForwardIterator + remove_if(ForwardIterator first, ForwardIterator last, Predicate pred); + +template + OutputIterator + remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value); + +template + OutputIterator + remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred); + +template + ForwardIterator + unique(ForwardIterator first, ForwardIterator last); + +template + ForwardIterator + unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); + +template + OutputIterator + unique_copy(InputIterator first, InputIterator last, OutputIterator result); + +template + OutputIterator + unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred); + +template + void + reverse(BidirectionalIterator first, BidirectionalIterator last); + +template + OutputIterator + reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result); + +template + ForwardIterator + rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last); + +template + OutputIterator + rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result); + +template + void + random_shuffle(RandomAccessIterator first, RandomAccessIterator last); + +template + void + random_shuffle(RandomAccessIterator first, RandomAccessIterator last, RandomNumberGenerator& rand); + +template + void shuffle(RandomAccessIterator first, RandomAccessIterator last, + UniformRandomNumberGenerator&& g); + +template + bool + is_partitioned(InputIterator first, InputIterator last, Predicate pred); + +template + ForwardIterator + partition(ForwardIterator first, ForwardIterator last, Predicate pred); + +template + pair + partition_copy(InputIterator first, InputIterator last, + OutputIterator1 out_true, OutputIterator2 out_false, + Predicate pred); + +template + ForwardIterator + stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred); + +template + ForwardIterator + partition_point(ForwardIterator first, ForwardIterator last, Predicate pred); + +template + bool + is_sorted(ForwardIterator first, ForwardIterator last); + +template + bool + is_sorted(ForwardIterator first, ForwardIterator last, Compare comp); + +template + ForwardIterator + is_sorted_until(ForwardIterator first, ForwardIterator last); + +template + ForwardIterator + is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp); + +template + void + sort(RandomAccessIterator first, RandomAccessIterator last); + +template + void + sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + void + stable_sort(RandomAccessIterator first, RandomAccessIterator last); + +template + void + stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + void + partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last); + +template + void + partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp); + +template + RandomAccessIterator + partial_sort_copy(InputIterator first, InputIterator last, + RandomAccessIterator result_first, RandomAccessIterator result_last); + +template + RandomAccessIterator + partial_sort_copy(InputIterator first, InputIterator last, + RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp); + +template + void + nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last); + +template + void + nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp); + +template + ForwardIterator + lower_bound(ForwardIterator first, ForwardIterator last, const T& value); + +template + ForwardIterator + lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template + ForwardIterator + upper_bound(ForwardIterator first, ForwardIterator last, const T& value); + +template + ForwardIterator + upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template + pair + equal_range(ForwardIterator first, ForwardIterator last, const T& value); + +template + pair + equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template + bool + binary_search(ForwardIterator first, ForwardIterator last, const T& value); + +template + bool + binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template + OutputIterator + merge(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template + OutputIterator + merge(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template + void + inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last); + +template + void + inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp); + +template + bool + includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); + +template + bool + includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp); + +template + OutputIterator + set_union(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template + OutputIterator + set_union(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template + OutputIterator + set_intersection(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template + OutputIterator + set_intersection(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template + OutputIterator + set_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template + OutputIterator + set_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template + OutputIterator + set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template + OutputIterator + set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template + void + push_heap(RandomAccessIterator first, RandomAccessIterator last); + +template + void + push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + void + pop_heap(RandomAccessIterator first, RandomAccessIterator last); + +template + void + pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + void + make_heap(RandomAccessIterator first, RandomAccessIterator last); + +template + void + make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + void + sort_heap(RandomAccessIterator first, RandomAccessIterator last); + +template + void + sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + bool + is_heap(RandomAccessIterator first, RandomAccessiterator last); + +template + bool + is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp); + +template + RandomAccessIterator + is_heap_until(RandomAccessIterator first, RandomAccessiterator last); + +template + RandomAccessIterator + is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp); + +template + ForwardIterator + min_element(ForwardIterator first, ForwardIterator last); + +template + ForwardIterator + min_element(ForwardIterator first, ForwardIterator last, Compare comp); + +template + const T& + min(const T& a, const T& b); + +template + const T& + min(const T& a, const T& b, Compare comp); + +template + T + min(initializer_list t); + +template + T + min(initializer_list t, Compare comp); + +template + ForwardIterator + max_element(ForwardIterator first, ForwardIterator last); + +template + ForwardIterator + max_element(ForwardIterator first, ForwardIterator last, Compare comp); + +template + const T& + max(const T& a, const T& b); + +template + const T& + max(const T& a, const T& b, Compare comp); + +template + T + max(initializer_list t); + +template + T + max(initializer_list t, Compare comp); + +template + pair + minmax_element(ForwardIterator first, ForwardIterator last); + +template + pair + minmax_element(ForwardIterator first, ForwardIterator last, Compare comp); + +template + pair + minmax(const T& a, const T& b); + +template + pair + minmax(const T& a, const T& b, Compare comp); + +template + pair + minmax(initializer_list t); + +template + pair + minmax(initializer_list t, Compare comp); + +template + bool + lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); + +template + bool + lexicographical_compare(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, Compare comp); + +template + bool + next_permutation(BidirectionalIterator first, BidirectionalIterator last); + +template + bool + next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp); + +template + bool + prev_permutation(BidirectionalIterator first, BidirectionalIterator last); + +template + bool + prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp); + +} // std + +*/ + +#include <__config> +#include +#include +#include +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct __equal_to +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) const {return __x == __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T1& __y) const {return __x == __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T2& __y) const {return __x == __y;} +}; + +template +struct __equal_to<_T1, _T1> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} +}; + +template +struct __equal_to +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} +}; + +template +struct __equal_to<_T1, const _T1> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} +}; + +template +struct __less +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;} +}; + +template +struct __less<_T1, _T1> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} +}; + +template +struct __less +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} +}; + +template +struct __less<_T1, const _T1> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} +}; + +template +class __negate +{ +private: + _Predicate __p_; +public: + _LIBCPP_INLINE_VISIBILITY __negate() {} + + _LIBCPP_INLINE_VISIBILITY + explicit __negate(_Predicate __p) : __p_(__p) {} + + template + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _T1& __x) {return !__p_(__x);} + + template + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _T1& __x, const _T2& __y) {return !__p_(__x, __y);} +}; + +#ifdef _LIBCPP_DEBUG2 + +template +struct __debug_less +{ + _Compare __comp_; + __debug_less(_Compare& __c) : __comp_(__c) {} + template + bool operator()(const _Tp& __x, const _Up& __y) + { + bool __r = __comp_(__x, __y); + if (__r) + _LIBCPP_ASSERT(!__comp_(__y, __x), "Comparator does not induce a strict weak ordering"); + return __r; + } +}; + +#endif // _LIBCPP_DEBUG2 + +// Precondition: __x != 0 +inline _LIBCPP_INLINE_VISIBILITY unsigned __ctz(unsigned __x) {return __builtin_ctz (__x);} +inline _LIBCPP_INLINE_VISIBILITY unsigned long __ctz(unsigned long __x) {return __builtin_ctzl (__x);} +inline _LIBCPP_INLINE_VISIBILITY unsigned long long __ctz(unsigned long long __x) {return __builtin_ctzll(__x);} + +// Precondition: __x != 0 +inline _LIBCPP_INLINE_VISIBILITY unsigned __clz(unsigned __x) {return __builtin_clz (__x);} +inline _LIBCPP_INLINE_VISIBILITY unsigned long __clz(unsigned long __x) {return __builtin_clzl (__x);} +inline _LIBCPP_INLINE_VISIBILITY unsigned long long __clz(unsigned long long __x) {return __builtin_clzll(__x);} + +inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned __x) {return __builtin_popcount (__x);} +inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long __x) {return __builtin_popcountl (__x);} +inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long long __x) {return __builtin_popcountll(__x);} + +// all_of + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (!__pred(*__first)) + return false; + return true; +} + +// any_of + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + return true; + return false; +} + +// none_of + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + return false; + return true; +} + +// for_each + +template +inline _LIBCPP_INLINE_VISIBILITY +_Function +for_each(_InputIterator __first, _InputIterator __last, _Function __f) +{ + for (; __first != __last; ++__first) + __f(*__first); + return _VSTD::move(__f); +} + +// find + +template +inline _LIBCPP_INLINE_VISIBILITY +_InputIterator +find(_InputIterator __first, _InputIterator __last, const _Tp& __value_) +{ + for (; __first != __last; ++__first) + if (*__first == __value_) + break; + return __first; +} + +// find_if + +template +inline _LIBCPP_INLINE_VISIBILITY +_InputIterator +find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + break; + return __first; +} + +// find_if_not + +template +inline _LIBCPP_INLINE_VISIBILITY +_InputIterator +find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (!__pred(*__first)) + break; + return __first; +} + +// find_end + +template +_ForwardIterator1 +__find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, + forward_iterator_tag, forward_iterator_tag) +{ + // modeled after search algorithm + _ForwardIterator1 __r = __last1; // __last1 is the "default" answer + if (__first2 == __last2) + return __r; + while (true) + { + while (true) + { + if (__first1 == __last1) // if source exhausted return last correct answer + return __r; // (or __last1 if never found) + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } + // *__first1 matches *__first2, now match elements after here + _ForwardIterator1 __m1 = __first1; + _ForwardIterator2 __m2 = __first2; + while (true) + { + if (++__m2 == __last2) + { // Pattern exhaused, record answer and search for another one + __r = __first1; + ++__first1; + break; + } + if (++__m1 == __last1) // Source exhausted, return last answer + return __r; + if (!__pred(*__m1, *__m2)) // mismatch, restart with a new __first + { + ++__first1; + break; + } // else there is a match, check next elements + } + } +} + +template +_BidirectionalIterator1 +__find_end(_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1, + _BidirectionalIterator2 __first2, _BidirectionalIterator2 __last2, _BinaryPredicate __pred, + bidirectional_iterator_tag, bidirectional_iterator_tag) +{ + // modeled after search algorithm (in reverse) + if (__first2 == __last2) + return __last1; // Everything matches an empty sequence + _BidirectionalIterator1 __l1 = __last1; + _BidirectionalIterator2 __l2 = __last2; + --__l2; + while (true) + { + // Find last element in sequence 1 that matchs *(__last2-1), with a mininum of loop checks + while (true) + { + if (__first1 == __l1) // return __last1 if no element matches *__first2 + return __last1; + if (__pred(*--__l1, *__l2)) + break; + } + // *__l1 matches *__l2, now match elements before here + _BidirectionalIterator1 __m1 = __l1; + _BidirectionalIterator2 __m2 = __l2; + while (true) + { + if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern) + return __m1; + if (__m1 == __first1) // Otherwise if source exhaused, pattern not found + return __last1; + if (!__pred(*--__m1, *--__m2)) // if there is a mismatch, restart with a new __l1 + { + break; + } // else there is a match, check next elements + } + } +} + +template +_RandomAccessIterator1 +__find_end(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, + _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag) +{ + // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern + typename iterator_traits<_RandomAccessIterator2>::difference_type __len2 = __last2 - __first2; + if (__len2 == 0) + return __last1; + typename iterator_traits<_RandomAccessIterator1>::difference_type __len1 = __last1 - __first1; + if (__len1 < __len2) + return __last1; + const _RandomAccessIterator1 __s = __first1 + (__len2 - 1); // End of pattern match can't go before here + _RandomAccessIterator1 __l1 = __last1; + _RandomAccessIterator2 __l2 = __last2; + --__l2; + while (true) + { + while (true) + { + if (__s == __l1) + return __last1; + if (__pred(*--__l1, *__l2)) + break; + } + _RandomAccessIterator1 __m1 = __l1; + _RandomAccessIterator2 __m2 = __l2; + while (true) + { + if (__m2 == __first2) + return __m1; + // no need to check range on __m1 because __s guarantees we have enough source + if (!__pred(*--__m1, *--__m2)) + { + break; + } + } + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator1 +find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) +{ + return _VSTD::__find_end::type> + (__first1, __last1, __first2, __last2, __pred, + typename iterator_traits<_ForwardIterator1>::iterator_category(), + typename iterator_traits<_ForwardIterator2>::iterator_category()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator1 +find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2) +{ + typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::find_end(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); +} + +// find_first_of + +template +_ForwardIterator1 +find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) +{ + for (; __first1 != __last1; ++__first1) + for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) + if (__pred(*__first1, *__j)) + return __first1; + return __last1; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator1 +find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2) +{ + typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::find_first_of(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); +} + +// adjacent_find + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) +{ + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (__pred(*__first, *__i)) + return __first; + __first = __i; + } + } + return __last; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +adjacent_find(_ForwardIterator __first, _ForwardIterator __last) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type __v; + return _VSTD::adjacent_find(__first, __last, __equal_to<__v>()); +} + +// count + +template +inline _LIBCPP_INLINE_VISIBILITY +typename iterator_traits<_InputIterator>::difference_type +count(_InputIterator __first, _InputIterator __last, const _Tp& __value_) +{ + typename iterator_traits<_InputIterator>::difference_type __r(0); + for (; __first != __last; ++__first) + if (*__first == __value_) + ++__r; + return __r; +} + +// count_if + +template +inline _LIBCPP_INLINE_VISIBILITY +typename iterator_traits<_InputIterator>::difference_type +count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + typename iterator_traits<_InputIterator>::difference_type __r(0); + for (; __first != __last; ++__first) + if (__pred(*__first)) + ++__r; + return __r; +} + +// mismatch + +template +inline _LIBCPP_INLINE_VISIBILITY +pair<_InputIterator1, _InputIterator2> +mismatch(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _BinaryPredicate __pred) +{ + for (; __first1 != __last1; ++__first1, ++__first2) + if (!__pred(*__first1, *__first2)) + break; + return pair<_InputIterator1, _InputIterator2>(__first1, __first2); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +pair<_InputIterator1, _InputIterator2> +mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) +{ + typedef typename iterator_traits<_InputIterator1>::value_type __v1; + typedef typename iterator_traits<_InputIterator2>::value_type __v2; + return _VSTD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>()); +} + +// equal + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) +{ + for (; __first1 != __last1; ++__first1, ++__first2) + if (!__pred(*__first1, *__first2)) + return false; + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) +{ + typedef typename iterator_traits<_InputIterator1>::value_type __v1; + typedef typename iterator_traits<_InputIterator2>::value_type __v2; + return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>()); +} + +// is_permutation + +template +bool +is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _BinaryPredicate __pred) +{ + // shorten sequences as much as possible by lopping of any equal parts + for (; __first1 != __last1; ++__first1, ++__first2) + if (!__pred(*__first1, *__first2)) + goto __not_done; + return true; +__not_done: + // __first1 != __last1 && *__first1 != *__first2 + typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1; + _D1 __l1 = _VSTD::distance(__first1, __last1); + if (__l1 == _D1(1)) + return false; + _ForwardIterator2 __last2 = _VSTD::next(__first2, __l1); + // For each element in [f1, l1) see if there are the same number of + // equal elements in [f2, l2) + for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i) + { + // Have we already counted the number of *__i in [f1, l1)? + for (_ForwardIterator1 __j = __first1; __j != __i; ++__j) + if (__pred(*__j, *__i)) + goto __next_iter; + { + // Count number of *__i in [f2, l2) + _D1 __c2 = 0; + for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) + if (__pred(*__i, *__j)) + ++__c2; + if (__c2 == 0) + return false; + // Count number of *__i in [__i, l1) (we can start with 1) + _D1 __c1 = 1; + for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j) + if (__pred(*__i, *__j)) + ++__c1; + if (__c1 != __c2) + return false; + } +__next_iter:; + } + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2) +{ + typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>()); +} + +// search + +template +_ForwardIterator1 +__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, + forward_iterator_tag, forward_iterator_tag) +{ + if (__first2 == __last2) + return __first1; // Everything matches an empty sequence + while (true) + { + // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks + while (true) + { + if (__first1 == __last1) // return __last1 if no element matches *__first2 + return __last1; + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } + // *__first1 matches *__first2, now match elements after here + _ForwardIterator1 __m1 = __first1; + _ForwardIterator2 __m2 = __first2; + while (true) + { + if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) + return __first1; + if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found + return __last1; + if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 + { + ++__first1; + break; + } // else there is a match, check next elements + } + } +} + +template +_RandomAccessIterator1 +__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, + _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag) +{ + typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _D1; + typedef typename std::iterator_traits<_RandomAccessIterator2>::difference_type _D2; + // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern + _D2 __len2 = __last2 - __first2; + if (__len2 == 0) + return __first1; + _D1 __len1 = __last1 - __first1; + if (__len1 < __len2) + return __last1; + const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here + while (true) + { +#if !_LIBCPP_UNROLL_LOOPS + while (true) + { + if (__first1 == __s) + return __last1; + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } +#else // !_LIBCPP_UNROLL_LOOPS + for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; --__loop_unroll) + { + if (__pred(*__first1, *__first2)) + goto __phase2; + if (__pred(*++__first1, *__first2)) + goto __phase2; + if (__pred(*++__first1, *__first2)) + goto __phase2; + if (__pred(*++__first1, *__first2)) + goto __phase2; + ++__first1; + } + switch (__s - __first1) + { + case 3: + if (__pred(*__first1, *__first2)) + break; + ++__first1; + case 2: + if (__pred(*__first1, *__first2)) + break; + ++__first1; + case 1: + if (__pred(*__first1, *__first2)) + break; + case 0: + return __last1; + } + __phase2: +#endif // !_LIBCPP_UNROLL_LOOPS + _RandomAccessIterator1 __m1 = __first1; + _RandomAccessIterator2 __m2 = __first2; +#if !_LIBCPP_UNROLL_LOOPS + while (true) + { + if (++__m2 == __last2) + return __first1; + ++__m1; // no need to check range on __m1 because __s guarantees we have enough source + if (!__pred(*__m1, *__m2)) + { + ++__first1; + break; + } + } +#else // !_LIBCPP_UNROLL_LOOPS + ++__m2; + ++__m1; + for (_D2 __loop_unroll = (__last2 - __m2) / 4; __loop_unroll > 0; --__loop_unroll) + { + if (!__pred(*__m1, *__m2)) + goto __continue; + if (!__pred(*++__m1, *++__m2)) + goto __continue; + if (!__pred(*++__m1, *++__m2)) + goto __continue; + if (!__pred(*++__m1, *++__m2)) + goto __continue; + ++__m1; + ++__m2; + } + switch (__last2 - __m2) + { + case 3: + if (!__pred(*__m1, *__m2)) + break; + ++__m1; + ++__m2; + case 2: + if (!__pred(*__m1, *__m2)) + break; + ++__m1; + ++__m2; + case 1: + if (!__pred(*__m1, *__m2)) + break; + case 0: + return __first1; + } + __continue: + ++__first1; +#endif // !_LIBCPP_UNROLL_LOOPS + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator1 +search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) +{ + return _VSTD::__search::type> + (__first1, __last1, __first2, __last2, __pred, + typename std::iterator_traits<_ForwardIterator1>::iterator_category(), + typename std::iterator_traits<_ForwardIterator2>::iterator_category()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator1 +search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2) +{ + typedef typename std::iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename std::iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); +} + +// search_n + +template +_ForwardIterator +__search_n(_ForwardIterator __first, _ForwardIterator __last, + _Size __count, const _Tp& __value_, _BinaryPredicate __pred, forward_iterator_tag) +{ + if (__count <= 0) + return __first; + while (true) + { + // Find first element in sequence that matchs __value_, with a mininum of loop checks + while (true) + { + if (__first == __last) // return __last if no element matches __value_ + return __last; + if (__pred(*__first, __value_)) + break; + ++__first; + } + // *__first matches __value_, now match elements after here + _ForwardIterator __m = __first; + _Size __c(0); + while (true) + { + if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern) + return __first; + if (++__m == __last) // Otherwise if source exhaused, pattern not found + return __last; + if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first + { + __first = __m; + ++__first; + break; + } // else there is a match, check next elements + } + } +} + +template +_RandomAccessIterator +__search_n(_RandomAccessIterator __first, _RandomAccessIterator __last, + _Size __count, const _Tp& __value_, _BinaryPredicate __pred, random_access_iterator_tag) +{ + if (__count <= 0) + return __first; + _Size __len = static_cast<_Size>(__last - __first); + if (__len < __count) + return __last; + const _RandomAccessIterator __s = __last - (__count - 1); // Start of pattern match can't go beyond here + while (true) + { + // Find first element in sequence that matchs __value_, with a mininum of loop checks + while (true) + { + if (__first == __s) // return __last if no element matches __value_ + return __last; + if (__pred(*__first, __value_)) + break; + ++__first; + } + // *__first matches __value_, now match elements after here + _RandomAccessIterator __m = __first; + _Size __c(0); + while (true) + { + if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern) + return __first; + ++__m; // no need to check range on __m because __s guarantees we have enough source + if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first + { + __first = __m; + ++__first; + break; + } // else there is a match, check next elements + } + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +search_n(_ForwardIterator __first, _ForwardIterator __last, + _Size __count, const _Tp& __value_, _BinaryPredicate __pred) +{ + return _VSTD::__search_n::type> + (__first, __last, __count, __value_, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type __v; + return _VSTD::search_n(__first, __last, __count, __value_, __equal_to<__v, _Tp>()); +} + +// copy + +template +struct __libcpp_is_trivial_iterator +{ + static const bool value = is_pointer<_Iter>::value; +}; + +template +struct __libcpp_is_trivial_iterator > +{ + static const bool value = is_pointer<_Iter>::value; +}; + +template +struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > +{ + static const bool value = is_pointer<_Iter>::value; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +_Iter +__unwrap_iter(_Iter __i) +{ + return __i; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + _Tp* +>::type +__unwrap_iter(move_iterator<_Tp*> __i) +{ + return __i.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + _Tp* +>::type +__unwrap_iter(__wrap_iter<_Tp*> __i) +{ + return __i.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + for (; __first != __last; ++__first, ++__result) + *__result = *__first; + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* +>::type +__copy(_Tp* __first, _Tp* __last, _Up* __result) +{ + const size_t __n = static_cast(__last - __first); + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + return __result + __n; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + return _VSTD::__copy(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); +} + +// copy_backward + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__copy_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + while (__first != __last) + *--__result = *--__last; + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* +>::type +__copy_backward(_Tp* __first, _Tp* __last, _Up* __result) +{ + const size_t __n = static_cast(__last - __first); + __result -= __n; + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_BidirectionalIterator2 +copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, + _BidirectionalIterator2 __result) +{ + return _VSTD::__copy_backward(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); +} + +// copy_if + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +copy_if(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Predicate __pred) +{ + for (; __first != __last; ++__first) + { + if (__pred(*__first)) + { + *__result = *__first; + ++__result; + } + } + return __result; +} + +// copy_n + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_input_iterator<_InputIterator>::value && + !__is_random_access_iterator<_InputIterator>::value, + _OutputIterator +>::type +copy_n(_InputIterator __first, _Size __n, _OutputIterator __result) +{ + if (__n > 0) + { + *__result = *__first; + ++__result; + for (--__n; __n > 0; --__n) + { + ++__first; + *__result = *__first; + ++__result; + } + } + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_random_access_iterator<_InputIterator>::value, + _OutputIterator +>::type +copy_n(_InputIterator __first, _Size __n, _OutputIterator __result) +{ + return _VSTD::copy(__first, __first + __n, __result); +} + +// move + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + for (; __first != __last; ++__first, ++__result) + *__result = _VSTD::move(*__first); + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* +>::type +__move(_Tp* __first, _Tp* __last, _Up* __result) +{ + const size_t __n = static_cast(__last - __first); + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + return __result + __n; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + return _VSTD::__move(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); +} + +// move_backward + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__move_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + while (__first != __last) + *--__result = _VSTD::move(*--__last); + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* +>::type +__move_backward(_Tp* __first, _Tp* __last, _Up* __result) +{ + const size_t __n = static_cast(__last - __first); + __result -= __n; + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_BidirectionalIterator2 +move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, + _BidirectionalIterator2 __result) +{ + return _VSTD::__move_backward(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); +} + +// iter_swap + +// moved to for better swap / noexcept support + +// transform + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) +{ + for (; __first != __last; ++__first, ++__result) + *__result = __op(*__first); + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, + _OutputIterator __result, _BinaryOperation __binary_op) +{ + for (; __first1 != __last1; ++__first1, ++__first2, ++__result) + *__result = __binary_op(*__first1, *__first2); + return __result; +} + +// replace + +template +inline _LIBCPP_INLINE_VISIBILITY +void +replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value) +{ + for (; __first != __last; ++__first) + if (*__first == __old_value) + *__first = __new_value; +} + +// replace_if + +template +inline _LIBCPP_INLINE_VISIBILITY +void +replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + *__first = __new_value; +} + +// replace_copy + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, + const _Tp& __old_value, const _Tp& __new_value) +{ + for (; __first != __last; ++__first, ++__result) + if (*__first == __old_value) + *__result = __new_value; + else + *__result = *__first; + return __result; +} + +// replace_copy_if + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, + _Predicate __pred, const _Tp& __new_value) +{ + for (; __first != __last; ++__first, ++__result) + if (__pred(*__first)) + *__result = __new_value; + else + *__result = *__first; + return __result; +} + +// fill_n + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_, false_type) +{ + for (; __n > 0; ++__first, --__n) + *__first = __value_; + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_, true_type) +{ + if (__n > 0) + _VSTD::memset(__first, (unsigned char)__value_, (size_t)(__n)); + return __first + __n; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_) +{ + return _VSTD::__fill_n(__first, __n, __value_, integral_constant::value && + is_trivially_copy_assignable<_Tp>::value && + sizeof(_Tp) == 1>()); +} + +// fill + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, forward_iterator_tag) +{ + for (; __first != __last; ++__first) + *__first = __value_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag) +{ + _VSTD::fill_n(__first, __last - __first, __value_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + _VSTD::__fill(__first, __last, __value_, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +// generate + +template +inline _LIBCPP_INLINE_VISIBILITY +void +generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) +{ + for (; __first != __last; ++__first) + *__first = __gen(); +} + +// generate_n + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +generate_n(_OutputIterator __first, _Size __n, _Generator __gen) +{ + for (; __n > 0; ++__first, --__n) + *__first = __gen(); + return __first; +} + +// remove + +template +_ForwardIterator +remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + __first = _VSTD::find(__first, __last, __value_); + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (!(*__i == __value_)) + { + *__first = _VSTD::move(*__i); + ++__first; + } + } + } + return __first; +} + +// remove_if + +template +_ForwardIterator +remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) +{ + __first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type> + (__first, __last, __pred); + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (!__pred(*__i)) + { + *__first = _VSTD::move(*__i); + ++__first; + } + } + } + return __first; +} + +// remove_copy + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value_) +{ + for (; __first != __last; ++__first) + { + if (!(*__first == __value_)) + { + *__result = *__first; + ++__result; + } + } + return __result; +} + +// remove_copy_if + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) +{ + for (; __first != __last; ++__first) + { + if (!__pred(*__first)) + { + *__result = *__first; + ++__result; + } + } + return __result; +} + +// unique + +template +_ForwardIterator +unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) +{ + __first = _VSTD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type> + (__first, __last, __pred); + if (__first != __last) + { + // ... a a ? ... + // f i + _ForwardIterator __i = __first; + for (++__i; ++__i != __last;) + if (!__pred(*__first, *__i)) + *++__first = _VSTD::move(*__i); + ++__first; + } + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +unique(_ForwardIterator __first, _ForwardIterator __last) +{ + typedef typename iterator_traits<_ForwardIterator>::value_type __v; + return _VSTD::unique(__first, __last, __equal_to<__v>()); +} + +// unique_copy + +template +_OutputIterator +__unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred, + input_iterator_tag, output_iterator_tag) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __t(*__first); + *__result = __t; + ++__result; + while (++__first != __last) + { + if (!__pred(__t, *__first)) + { + __t = *__first; + *__result = __t; + ++__result; + } + } + } + return __result; +} + +template +_OutputIterator +__unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _BinaryPredicate __pred, + forward_iterator_tag, output_iterator_tag) +{ + if (__first != __last) + { + _ForwardIterator __i = __first; + *__result = *__i; + ++__result; + while (++__first != __last) + { + if (!__pred(*__i, *__first)) + { + *__result = *__first; + ++__result; + __i = __first; + } + } + } + return __result; +} + +template +_ForwardIterator +__unique_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result, _BinaryPredicate __pred, + input_iterator_tag, forward_iterator_tag) +{ + if (__first != __last) + { + *__result = *__first; + while (++__first != __last) + if (!__pred(*__result, *__first)) + *++__result = *__first; + ++__result; + } + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred) +{ + return _VSTD::__unique_copy::type> + (__first, __last, __result, __pred, + typename iterator_traits<_InputIterator>::iterator_category(), + typename iterator_traits<_OutputIterator>::iterator_category()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + typedef typename iterator_traits<_InputIterator>::value_type __v; + return _VSTD::unique_copy(__first, __last, __result, __equal_to<__v>()); +} + +// reverse + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) +{ + while (__first != __last) + { + if (__first == --__last) + break; + swap(*__first, *__last); + ++__first; + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) +{ + if (__first != __last) + for (; __first < --__last; ++__first) + swap(*__first, *__last); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) +{ + _VSTD::__reverse(__first, __last, typename iterator_traits<_BidirectionalIterator>::iterator_category()); +} + +// reverse_copy + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) +{ + for (; __first != __last; ++__result) + *__result = *--__last; + return __result; +} + +// rotate + +template +_ForwardIterator +__rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, false_type) +{ + if (__first == __middle) + return __last; + if (__middle == __last) + return __first; + _ForwardIterator __i = __middle; + while (true) + { + swap(*__first, *__i); + ++__first; + if (++__i == __last) + break; + if (__first == __middle) + __middle = __i; + } + _ForwardIterator __r = __first; + if (__first != __middle) + { + __i = __middle; + while (true) + { + swap(*__first, *__i); + ++__first; + if (++__i == __last) + { + if (__first == __middle) + break; + __i = __middle; + } + else if (__first == __middle) + __middle = __i; + } + } + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Integral +__gcd(_Integral __x, _Integral __y) +{ + do + { + _Integral __t = __x % __y; + __x = __y; + __y = __t; + } while (__y); + return __x; +} + +template +_RandomAccessIterator +__rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, true_type) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + + if (__first == __middle) + return __last; + if (__middle == __last) + return __first; + const difference_type __m1 = __middle - __first; + const difference_type __m2 = __last - __middle; + if (__m1 == __m2) + { + _VSTD::swap_ranges(__first, __middle, __middle); + return __middle; + } + const difference_type __g = __gcd(__m1, __m2); + for (_RandomAccessIterator __p = __first + __g; __p != __first;) + { + value_type __t(*--__p); + _RandomAccessIterator __p1 = __p; + _RandomAccessIterator __p2 = __p1 + __m1; + do + { + *__p1 = *__p2; + __p1 = __p2; + const difference_type __d = __last - __p2; + if (__m1 < __d) + __p2 += __m1; + else + __p2 = __first + (__m1 - __d); + } while (__p2 != __p); + *__p1 = __t; + } + return __first + __m2; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) +{ + return _VSTD::__rotate(__first, __middle, __last, + integral_constant + < + bool, + is_convertible + < + typename iterator_traits<_ForwardIterator>::iterator_category, + random_access_iterator_tag + >::value && + is_trivially_copy_assignable + < + typename iterator_traits<_ForwardIterator>::value_type + >::value + >()); +} + +// rotate_copy + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result) +{ + return _VSTD::copy(__first, __middle, _VSTD::copy(__middle, __last, __result)); +} + +// min_element + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + if (__comp(*__i, *__first)) + __first = __i; + } + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +min_element(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::min_element(__first, __last, + __less::value_type>()); +} + +// min + +template +inline _LIBCPP_INLINE_VISIBILITY +const _Tp& +min(const _Tp& __a, const _Tp& __b, _Compare __comp) +{ + return __comp(__b, __a) ? __b : __a; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +const _Tp& +min(const _Tp& __a, const _Tp& __b) +{ + return _VSTD::min(__a, __b, __less<_Tp>()); +} + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +min(initializer_list<_Tp> __t, _Compare __comp) +{ + return *_VSTD::min_element(__t.begin(), __t.end(), __comp); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +min(initializer_list<_Tp> __t) +{ + return *_VSTD::min_element(__t.begin(), __t.end()); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +// max_element + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + if (__comp(*__first, *__i)) + __first = __i; + } + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +max_element(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::max_element(__first, __last, + __less::value_type>()); +} + +// max + +template +inline _LIBCPP_INLINE_VISIBILITY +const _Tp& +max(const _Tp& __a, const _Tp& __b, _Compare __comp) +{ + return __comp(__a, __b) ? __b : __a; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +const _Tp& +max(const _Tp& __a, const _Tp& __b) +{ + return _VSTD::max(__a, __b, __less<_Tp>()); +} + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +max(initializer_list<_Tp> __t, _Compare __comp) +{ + return *_VSTD::max_element(__t.begin(), __t.end(), __comp); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +max(initializer_list<_Tp> __t) +{ + return *_VSTD::max_element(__t.begin(), __t.end()); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +// minmax_element + +template +std::pair<_ForwardIterator, _ForwardIterator> +minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + std::pair<_ForwardIterator, _ForwardIterator> __result(__first, __first); + if (__first != __last) + { + if (++__first != __last) + { + if (__comp(*__first, *__result.first)) + { + __result.second = __result.first; + __result.first = __first; + } + else + __result.second = __first; + while (++__first != __last) + { + _ForwardIterator __i = __first; + if (++__first == __last) + { + if (__comp(*__i, *__result.first)) + __result.first = __i; + else if (!__comp(*__i, *__result.second)) + __result.second = __i; + break; + } + else + { + if (__comp(*__first, *__i)) + { + if (__comp(*__first, *__result.first)) + __result.first = __first; + if (!__comp(*__i, *__result.second)) + __result.second = __i; + } + else + { + if (__comp(*__i, *__result.first)) + __result.first = __i; + if (!__comp(*__first, *__result.second)) + __result.second = __first; + } + } + } + } + } + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +std::pair<_ForwardIterator, _ForwardIterator> +minmax_element(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::minmax_element(__first, __last, __less::value_type>()); +} + +// minmax + +template +inline _LIBCPP_INLINE_VISIBILITY +pair +minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) +{ + return __comp(__b, __a) ? pair(__b, __a) : + pair(__a, __b); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +pair +minmax(const _Tp& __a, const _Tp& __b) +{ + return _VSTD::minmax(__a, __b, __less<_Tp>()); +} + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +inline _LIBCPP_INLINE_VISIBILITY +pair<_Tp, _Tp> +minmax(initializer_list<_Tp> __t) +{ + pair __p = + _VSTD::minmax_element(__t.begin(), __t.end()); + return pair<_Tp, _Tp>(*__p.first, *__p.second); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +pair<_Tp, _Tp> +minmax(initializer_list<_Tp> __t, _Compare __comp) +{ + pair __p = + _VSTD::minmax_element(__t.begin(), __t.end(), __comp); + return pair<_Tp, _Tp>(*__p.first, *__p.second); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +// random_shuffle + +// __independent_bits_engine + +template +struct __log2_imp +{ + static const size_t value = _X & ((unsigned long long)(1) << _R) ? _R + : __log2_imp<_X, _R - 1>::value; +}; + +template +struct __log2_imp<_X, 0> +{ + static const size_t value = 0; +}; + +template +struct __log2_imp<0, _R> +{ + static const size_t value = _R + 1; +}; + +template +struct __log2 +{ + static const size_t value = __log2_imp<_X, + sizeof(_UI) * __CHAR_BIT__ - 1>::value; +}; + +template +class __independent_bits_engine +{ +public: + // types + typedef _UIntType result_type; + +private: + typedef typename _Engine::result_type _Engine_result_type; + typedef typename conditional + < + sizeof(_Engine_result_type) <= sizeof(result_type), + result_type, + _Engine_result_type + >::type _Working_result_type; + + _Engine& __e_; + size_t __w_; + size_t __w0_; + size_t __n_; + size_t __n0_; + _Working_result_type __y0_; + _Working_result_type __y1_; + _Engine_result_type __mask0_; + _Engine_result_type __mask1_; + + static const _Working_result_type _R = _Engine::_Max - _Engine::_Min + + _Working_result_type(1); + static const size_t __m = __log2<_Working_result_type, _R>::value; + static const size_t _WDt = numeric_limits<_Working_result_type>::digits; + static const size_t _EDt = numeric_limits<_Engine_result_type>::digits; + +public: + // constructors and seeding functions + __independent_bits_engine(_Engine& __e, size_t __w); + + // generating functions + result_type operator()() {return __eval(integral_constant());} + +private: + result_type __eval(false_type); + result_type __eval(true_type); +}; + +template +__independent_bits_engine<_Engine, _UIntType> + ::__independent_bits_engine(_Engine& __e, size_t __w) + : __e_(__e), + __w_(__w) +{ + __n_ = __w_ / __m + (__w_ % __m != 0); + __w0_ = __w_ / __n_; + if (_R == 0) + __y0_ = _R; + else if (__w0_ < _WDt) + __y0_ = (_R >> __w0_) << __w0_; + else + __y0_ = 0; + if (_R - __y0_ > __y0_ / __n_) + { + ++__n_; + __w0_ = __w_ / __n_; + if (__w0_ < _WDt) + __y0_ = (_R >> __w0_) << __w0_; + else + __y0_ = 0; + } + __n0_ = __n_ - __w_ % __n_; + if (__w0_ < _WDt - 1) + __y1_ = (_R >> (__w0_ + 1)) << (__w0_ + 1); + else + __y1_ = 0; + __mask0_ = __w0_ > 0 ? _Engine_result_type(~0) >> (_EDt - __w0_) : + _Engine_result_type(0); + __mask1_ = __w0_ < _EDt - 1 ? + _Engine_result_type(~0) >> (_EDt - (__w0_ + 1)) : + _Engine_result_type(~0); +} + +template +inline +_UIntType +__independent_bits_engine<_Engine, _UIntType>::__eval(false_type) +{ + return static_cast(__e_() & __mask0_); +} + +template +_UIntType +__independent_bits_engine<_Engine, _UIntType>::__eval(true_type) +{ + result_type _S = 0; + for (size_t __k = 0; __k < __n0_; ++__k) + { + _Engine_result_type __u; + do + { + __u = __e_() - _Engine::min(); + } while (__u >= __y0_); + if (__w0_ < _WDt) + _S <<= __w0_; + else + _S = 0; + _S += __u & __mask0_; + } + for (size_t __k = __n0_; __k < __n_; ++__k) + { + _Engine_result_type __u; + do + { + __u = __e_() - _Engine::min(); + } while (__u >= __y1_); + if (__w0_ < _WDt - 1) + _S <<= __w0_ + 1; + else + _S = 0; + _S += __u & __mask1_; + } + return _S; +} + +// uniform_int_distribution + +template +class uniform_int_distribution +{ +public: + // types + typedef _IntType result_type; + + class param_type + { + result_type __a_; + result_type __b_; + public: + typedef uniform_int_distribution distribution_type; + + explicit param_type(result_type __a = 0, + result_type __b = numeric_limits::max()) + : __a_(__a), __b_(__b) {} + + result_type a() const {return __a_;} + result_type b() const {return __b_;} + + friend bool operator==(const param_type& __x, const param_type& __y) + {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} + friend bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions + explicit uniform_int_distribution(result_type __a = 0, + result_type __b = numeric_limits::max()) + : __p_(param_type(__a, __b)) {} + explicit uniform_int_distribution(const param_type& __p) : __p_(__p) {} + void reset() {} + + // generating functions + template result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + result_type a() const {return __p_.a();} + result_type b() const {return __p_.b();} + + param_type param() const {return __p_;} + void param(const param_type& __p) {__p_ = __p;} + + result_type min() const {return a();} + result_type max() const {return b();} + + friend bool operator==(const uniform_int_distribution& __x, + const uniform_int_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend bool operator!=(const uniform_int_distribution& __x, + const uniform_int_distribution& __y) + {return !(__x == __y);} +}; + +template +template +typename uniform_int_distribution<_IntType>::result_type +uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) +{ + typedef typename conditional::type _UIntType; + const _UIntType _R = __p.b() - __p.a() + _UIntType(1); + if (_R == 1) + return __p.a(); + const size_t _Dt = numeric_limits<_UIntType>::digits; + typedef __independent_bits_engine<_URNG, _UIntType> _Eng; + if (_R == 0) + return static_cast(_Eng(__g, _Dt)()); + size_t __w = _Dt - __clz(_R) - 1; + if ((_R & (_UIntType(~0) >> (_Dt - __w))) != 0) + ++__w; + _Eng __e(__g, __w); + _UIntType __u; + do + { + __u = __e(); + } while (__u >= _R); + return static_cast(__u + __p.a()); +} + +class __rs_default; + +__rs_default __rs_get(); + +class __rs_default +{ + static unsigned __c_; + + __rs_default(); +public: + typedef unsigned result_type; + + static const result_type _Min = 0; + static const result_type _Max = 0xFFFFFFFF; + + __rs_default(const __rs_default&); + ~__rs_default(); + + result_type operator()(); + + static const/*expr*/ result_type min() {return _Min;} + static const/*expr*/ result_type max() {return _Max;} + + friend __rs_default __rs_get(); +}; + +__rs_default __rs_get(); + +template +void +random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef uniform_int_distribution _D; + typedef typename _D::param_type _P; + difference_type __d = __last - __first; + if (__d > 1) + { + _D __uid; + __rs_default __g = __rs_get(); + for (--__last, --__d; __first < __last; ++__first, --__d) + { + difference_type __i = __uid(__g, _P(0, __d)); + if (__i != difference_type(0)) + swap(*__first, *(__first + __i)); + } + } +} + +template +void +random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _RandomNumberGenerator&& __rand) +#else + _RandomNumberGenerator& __rand) +#endif +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + difference_type __d = __last - __first; + if (__d > 1) + { + for (--__last; __first < __last; ++__first, --__d) + { + difference_type __i = __rand(__d); + swap(*__first, *(__first + __i)); + } + } +} + +template + void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _UniformRandomNumberGenerator&& __g) +#else + _UniformRandomNumberGenerator& __g) +#endif +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef uniform_int_distribution _D; + typedef typename _D::param_type _P; + difference_type __d = __last - __first; + if (__d > 1) + { + _D __uid; + for (--__last, --__d; __first < __last; ++__first, --__d) + { + difference_type __i = __uid(__g, _P(0, __d)); + if (__i != difference_type(0)) + swap(*__first, *(__first + __i)); + } + } +} + +template +bool +is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (!__pred(*__first)) + break; + for (; __first != __last; ++__first) + if (__pred(*__first)) + return false; + return true; +} + +// partition + +template +_ForwardIterator +__partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) +{ + while (true) + { + if (__first == __last) + return __first; + if (!__pred(*__first)) + break; + ++__first; + } + for (_ForwardIterator __p = __first; ++__p != __last;) + { + if (__pred(*__p)) + { + swap(*__first, *__p); + ++__first; + } + } + return __first; +} + +template +_BidirectionalIterator +__partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, + bidirectional_iterator_tag) +{ + while (true) + { + while (true) + { + if (__first == __last) + return __first; + if (!__pred(*__first)) + break; + ++__first; + } + do + { + if (__first == --__last) + return __first; + } while (!__pred(*__last)); + swap(*__first, *__last); + ++__first; + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) +{ + return _VSTD::__partition::type> + (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +// partition_copy + +template +pair<_OutputIterator1, _OutputIterator2> +partition_copy(_InputIterator __first, _InputIterator __last, + _OutputIterator1 __out_true, _OutputIterator2 __out_false, + _Predicate __pred) +{ + for (; __first != __last; ++__first) + { + if (__pred(*__first)) + { + *__out_true = *__first; + ++__out_true; + } + else + { + *__out_false = *__first; + ++__out_false; + } + } + return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false); +} + +// partition_point + +template +_ForwardIterator +partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) +{ + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + difference_type __len = _VSTD::distance(__first, __last); + while (__len != 0) + { + difference_type __l2 = __len / 2; + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__pred(*__m)) + { + __first = ++__m; + __len -= __l2 + 1; + } + else + __len = __l2; + } + return __first; +} + +// stable_partition + +template +_ForwardIterator +__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, + _Distance __len, _Pair __p, forward_iterator_tag __fit) +{ + // *__first is known to be false + // __len >= 1 + if (__len == 1) + return __first; + if (__len == 2) + { + _ForwardIterator __m = __first; + if (__pred(*++__m)) + { + swap(*__first, *__m); + return __m; + } + return __first; + } + if (__len <= __p.second) + { // The buffer is big enough to use + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; + __destruct_n __d(0); + unique_ptr __h(__p.first, __d); + // Move the falses into the temporary buffer, and the trues to the front of the line + // Update __first to always point to the end of the trues + value_type* __t = __p.first; + ::new(__t) value_type(_VSTD::move(*__first)); + __d.__incr((value_type*)0); + ++__t; + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (__pred(*__i)) + { + *__first = _VSTD::move(*__i); + ++__first; + } + else + { + ::new(__t) value_type(_VSTD::move(*__i)); + __d.__incr((value_type*)0); + ++__t; + } + } + // All trues now at start of range, all falses in buffer + // Move falses back into range, but don't mess up __first which points to first false + __i = __first; + for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i) + *__i = _VSTD::move(*__t2); + // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer + return __first; + } + // Else not enough buffer, do in place + // __len >= 3 + _ForwardIterator __m = __first; + _Distance __len2 = __len / 2; // __len2 >= 2 + _VSTD::advance(__m, __len2); + // recurse on [__first, __m), *__first know to be false + // F????????????????? + // f m l + typedef typename add_lvalue_reference<_Predicate>::type _PredRef; + _ForwardIterator __first_false = __stable_partition<_PredRef>(__first, __m, __pred, __len2, __p, __fit); + // TTTFFFFF?????????? + // f ff m l + // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true + _ForwardIterator __m1 = __m; + _ForwardIterator __second_false = __last; + _Distance __len_half = __len - __len2; + while (__pred(*__m1)) + { + if (++__m1 == __last) + goto __second_half_done; + --__len_half; + } + // TTTFFFFFTTTF?????? + // f ff m m1 l + __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __fit); +__second_half_done: + // TTTFFFFFTTTTTFFFFF + // f ff m sf l + return _VSTD::rotate(__first_false, __m, __second_false); + // TTTTTTTTFFFFFFFFFF + // | +} + +struct __return_temporary_buffer +{ + template + _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) const {_VSTD::return_temporary_buffer(__p);} +}; + +template +_ForwardIterator +__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, + forward_iterator_tag) +{ + const unsigned __alloc_limit = 3; // might want to make this a function of trivial assignment + // Either prove all true and return __first or point to first false + while (true) + { + if (__first == __last) + return __first; + if (!__pred(*__first)) + break; + ++__first; + } + // We now have a reduced range [__first, __last) + // *__first is known to be false + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; + difference_type __len = _VSTD::distance(__first, __last); + pair __p(0, 0); + unique_ptr __h; + if (__len >= __alloc_limit) + { + __p = _VSTD::get_temporary_buffer(__len); + __h.reset(__p.first); + } + return __stable_partition::type> + (__first, __last, __pred, __len, __p, forward_iterator_tag()); +} + +template +_BidirectionalIterator +__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, + _Distance __len, _Pair __p, bidirectional_iterator_tag __bit) +{ + // *__first is known to be false + // *__last is known to be true + // __len >= 2 + if (__len == 2) + { + swap(*__first, *__last); + return __last; + } + if (__len == 3) + { + _BidirectionalIterator __m = __first; + if (__pred(*++__m)) + { + swap(*__first, *__m); + swap(*__m, *__last); + return __last; + } + swap(*__m, *__last); + swap(*__first, *__m); + return __m; + } + if (__len <= __p.second) + { // The buffer is big enough to use + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + __destruct_n __d(0); + unique_ptr __h(__p.first, __d); + // Move the falses into the temporary buffer, and the trues to the front of the line + // Update __first to always point to the end of the trues + value_type* __t = __p.first; + ::new(__t) value_type(_VSTD::move(*__first)); + __d.__incr((value_type*)0); + ++__t; + _BidirectionalIterator __i = __first; + while (++__i != __last) + { + if (__pred(*__i)) + { + *__first = _VSTD::move(*__i); + ++__first; + } + else + { + ::new(__t) value_type(_VSTD::move(*__i)); + __d.__incr((value_type*)0); + ++__t; + } + } + // move *__last, known to be true + *__first = _VSTD::move(*__i); + __i = ++__first; + // All trues now at start of range, all falses in buffer + // Move falses back into range, but don't mess up __first which points to first false + for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i) + *__i = _VSTD::move(*__t2); + // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer + return __first; + } + // Else not enough buffer, do in place + // __len >= 4 + _BidirectionalIterator __m = __first; + _Distance __len2 = __len / 2; // __len2 >= 2 + _VSTD::advance(__m, __len2); + // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false + // F????????????????T + // f m l + _BidirectionalIterator __m1 = __m; + _BidirectionalIterator __first_false = __first; + _Distance __len_half = __len2; + while (!__pred(*--__m1)) + { + if (__m1 == __first) + goto __first_half_done; + --__len_half; + } + // F???TFFF?????????T + // f m1 m l + typedef typename add_lvalue_reference<_Predicate>::type _PredRef; + __first_false = __stable_partition<_PredRef>(__first, __m1, __pred, __len_half, __p, __bit); +__first_half_done: + // TTTFFFFF?????????T + // f ff m l + // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true + __m1 = __m; + _BidirectionalIterator __second_false = __last; + ++__second_false; + __len_half = __len - __len2; + while (__pred(*__m1)) + { + if (++__m1 == __last) + goto __second_half_done; + --__len_half; + } + // TTTFFFFFTTTF?????T + // f ff m m1 l + __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __bit); +__second_half_done: + // TTTFFFFFTTTTTFFFFF + // f ff m sf l + return _VSTD::rotate(__first_false, __m, __second_false); + // TTTTTTTTFFFFFFFFFF + // | +} + +template +_BidirectionalIterator +__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, + bidirectional_iterator_tag) +{ + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment + // Either prove all true and return __first or point to first false + while (true) + { + if (__first == __last) + return __first; + if (!__pred(*__first)) + break; + ++__first; + } + // __first points to first false, everything prior to __first is already set. + // Either prove [__first, __last) is all false and return __first, or point __last to last true + do + { + if (__first == --__last) + return __first; + } while (!__pred(*__last)); + // We now have a reduced range [__first, __last] + // *__first is known to be false + // *__last is known to be true + // __len >= 2 + difference_type __len = _VSTD::distance(__first, __last) + 1; + pair __p(0, 0); + unique_ptr __h; + if (__len >= __alloc_limit) + { + __p = _VSTD::get_temporary_buffer(__len); + __h.reset(__p.first); + } + return __stable_partition::type> + (__first, __last, __pred, __len, __p, bidirectional_iterator_tag()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) +{ + return __stable_partition::type> + (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +// is_sorted_until + +template +_ForwardIterator +is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (__comp(*__i, *__first)) + return __i; + __first = __i; + } + } + return __last; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::is_sorted_until(__first, __last, __less::value_type>()); +} + +// is_sorted + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + return _VSTD::is_sorted_until(__first, __last, __comp) == __last; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +is_sorted(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::is_sorted(__first, __last, __less::value_type>()); +} + +// sort + +// stable, 2-3 compares, 0-2 swaps + +template +unsigned +__sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) +{ + unsigned __r = 0; + if (!__c(*__y, *__x)) // if x <= y + { + if (!__c(*__z, *__y)) // if y <= z + return __r; // x <= y && y <= z + // x <= y && y > z + swap(*__y, *__z); // x <= z && y < z + __r = 1; + if (__c(*__y, *__x)) // if x > y + { + swap(*__x, *__y); // x < y && y <= z + __r = 2; + } + return __r; // x <= y && y < z + } + if (__c(*__z, *__y)) // x > y, if y > z + { + swap(*__x, *__z); // x < y && y < z + __r = 1; + return __r; + } + swap(*__x, *__y); // x > y && y <= z + __r = 1; // x < y && x <= z + if (__c(*__z, *__y)) // if y > z + { + swap(*__y, *__z); // x <= y && y < z + __r = 2; + } + return __r; +} // x <= y && y <= z + +// stable, 3-6 compares, 0-5 swaps + +template +unsigned +__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, + _ForwardIterator __x4, _Compare __c) +{ + unsigned __r = __sort3<_Compare>(__x1, __x2, __x3, __c); + if (__c(*__x4, *__x3)) + { + swap(*__x3, *__x4); + ++__r; + if (__c(*__x3, *__x2)) + { + swap(*__x2, *__x3); + ++__r; + if (__c(*__x2, *__x1)) + { + swap(*__x1, *__x2); + ++__r; + } + } + } + return __r; +} + +// stable, 4-10 compares, 0-9 swaps + +template +unsigned +__sort5(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, + _ForwardIterator __x4, _ForwardIterator __x5, _Compare __c) +{ + unsigned __r = __sort4<_Compare>(__x1, __x2, __x3, __x4, __c); + if (__c(*__x5, *__x4)) + { + swap(*__x4, *__x5); + ++__r; + if (__c(*__x4, *__x3)) + { + swap(*__x3, *__x4); + ++__r; + if (__c(*__x3, *__x2)) + { + swap(*__x2, *__x3); + ++__r; + if (__c(*__x2, *__x1)) + { + swap(*__x1, *__x2); + ++__r; + } + } + } + } + return __r; +} + +// Assumes size > 0 +template +void +__selection_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp) +{ + _BirdirectionalIterator __lm1 = __last; + for (--__lm1; __first != __lm1; ++__first) + { + _BirdirectionalIterator __i = _VSTD::min_element<_BirdirectionalIterator, + typename add_lvalue_reference<_Compare>::type> + (__first, __last, __comp); + if (__i != __first) + swap(*__first, *__i); + } +} + +template +void +__insertion_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp) +{ + typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type; + if (__first != __last) + { + _BirdirectionalIterator __i = __first; + for (++__i; __i != __last; ++__i) + { + _BirdirectionalIterator __j = __i; + value_type __t(_VSTD::move(*__j)); + for (_BirdirectionalIterator __k = __i; __k != __first && __comp(__t, *--__k); --__j) + *__j = _VSTD::move(*__k); + *__j = _VSTD::move(__t); + } + } +} + +template +void +__insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + _RandomAccessIterator __j = __first+2; + __sort3<_Compare>(__first, __first+1, __j, __comp); + for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i) + { + if (__comp(*__i, *__j)) + { + value_type __t(_VSTD::move(*__i)); + _RandomAccessIterator __k = __j; + __j = __i; + do + { + *__j = _VSTD::move(*__k); + __j = __k; + } while (__j != __first && __comp(__t, *--__k)); + *__j = _VSTD::move(__t); + } + __j = __i; + } +} + +template +bool +__insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + switch (__last - __first) + { + case 0: + case 1: + return true; + case 2: + if (__comp(*--__last, *__first)) + swap(*__first, *__last); + return true; + case 3: + _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp); + return true; + case 4: + _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp); + return true; + case 5: + _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp); + return true; + } + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + _RandomAccessIterator __j = __first+2; + __sort3<_Compare>(__first, __first+1, __j, __comp); + const unsigned __limit = 8; + unsigned __count = 0; + for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i) + { + if (__comp(*__i, *__j)) + { + value_type __t(_VSTD::move(*__i)); + _RandomAccessIterator __k = __j; + __j = __i; + do + { + *__j = _VSTD::move(*__k); + __j = __k; + } while (__j != __first && __comp(__t, *--__k)); + *__j = _VSTD::move(__t); + if (++__count == __limit) + return ++__i == __last; + } + __j = __i; + } + return true; +} + +template +void +__insertion_sort_move(_BirdirectionalIterator __first1, _BirdirectionalIterator __last1, + typename iterator_traits<_BirdirectionalIterator>::value_type* __first2, _Compare __comp) +{ + typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type; + if (__first1 != __last1) + { + __destruct_n __d(0); + unique_ptr __h(__first2, __d); + value_type* __last2 = __first2; + ::new(__last2) value_type(_VSTD::move(*__first1)); + __d.__incr((value_type*)0); + for (++__last2; ++__first1 != __last1; ++__last2) + { + value_type* __j2 = __last2; + value_type* __i2 = __j2; + if (__comp(*__first1, *--__i2)) + { + ::new(__j2) value_type(_VSTD::move(*__i2)); + __d.__incr((value_type*)0); + for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2) + *__j2 = _VSTD::move(*__i2); + *__j2 = _VSTD::move(*__first1); + } + else + { + ::new(__j2) value_type(_VSTD::move(*__first1)); + __d.__incr((value_type*)0); + } + } + __h.release(); + } +} + +template +void +__sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + // _Compare is known to be a reference type + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + const difference_type __limit = is_trivially_copy_constructible::value && + is_trivially_copy_assignable::value ? 30 : 6; + while (true) + { + __restart: + difference_type __len = __last - __first; + switch (__len) + { + case 0: + case 1: + return; + case 2: + if (__comp(*--__last, *__first)) + swap(*__first, *__last); + return; + case 3: + _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp); + return; + case 4: + _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp); + return; + case 5: + _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp); + return; + } + if (__len <= __limit) + { + _VSTD::__insertion_sort_3<_Compare>(__first, __last, __comp); + return; + } + // __len > 5 + _RandomAccessIterator __m = __first; + _RandomAccessIterator __lm1 = __last; + --__lm1; + unsigned __n_swaps; + { + difference_type __delta; + if (__len >= 1000) + { + __delta = __len/2; + __m += __delta; + __delta /= 2; + __n_swaps = _VSTD::__sort5<_Compare>(__first, __first + __delta, __m, __m+__delta, __lm1, __comp); + } + else + { + __delta = __len/2; + __m += __delta; + __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, __lm1, __comp); + } + } + // *__m is median + // partition [__first, __m) < *__m and *__m <= [__m, __last) + // (this inhibits tossing elements equivalent to __m around unnecessarily) + _RandomAccessIterator __i = __first; + _RandomAccessIterator __j = __lm1; + // j points beyond range to be tested, *__m is known to be <= *__lm1 + // The search going up is known to be guarded but the search coming down isn't. + // Prime the downward search with a guard. + if (!__comp(*__i, *__m)) // if *__first == *__m + { + // *__first == *__m, *__first doesn't go in first part + // manually guard downward moving __j against __i + while (true) + { + if (__i == --__j) + { + // *__first == *__m, *__m <= all other elements + // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) + ++__i; // __first + 1 + __j = __last; + if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) + { + while (true) + { + if (__i == __j) + return; // [__first, __last) all equivalent elements + if (__comp(*__first, *__i)) + { + swap(*__i, *__j); + ++__n_swaps; + ++__i; + break; + } + ++__i; + } + } + // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 + if (__i == __j) + return; + while (true) + { + while (!__comp(*__first, *__i)) + ++__i; + while (__comp(*__first, *--__j)) + ; + if (__i >= __j) + break; + swap(*__i, *__j); + ++__n_swaps; + ++__i; + } + // [__first, __i) == *__first and *__first < [__i, __last) + // The first part is sorted, sort the secod part + // _VSTD::__sort<_Compare>(__i, __last, __comp); + __first = __i; + goto __restart; + } + if (__comp(*__j, *__m)) + { + swap(*__i, *__j); + ++__n_swaps; + break; // found guard for downward moving __j, now use unguarded partition + } + } + } + // It is known that *__i < *__m + ++__i; + // j points beyond range to be tested, *__m is known to be <= *__lm1 + // if not yet partitioned... + if (__i < __j) + { + // known that *(__i - 1) < *__m + // known that __i <= __m + while (true) + { + // __m still guards upward moving __i + while (__comp(*__i, *__m)) + ++__i; + // It is now known that a guard exists for downward moving __j + while (!__comp(*--__j, *__m)) + ; + if (__i > __j) + break; + swap(*__i, *__j); + ++__n_swaps; + // It is known that __m != __j + // If __m just moved, follow it + if (__m == __i) + __m = __j; + ++__i; + } + } + // [__first, __i) < *__m and *__m <= [__i, __last) + if (__i != __m && __comp(*__m, *__i)) + { + swap(*__i, *__m); + ++__n_swaps; + } + // [__first, __i) < *__i and *__i <= [__i+1, __last) + // If we were given a perfect partition, see if insertion sort is quick... + if (__n_swaps == 0) + { + bool __fs = _VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp); + if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp)) + { + if (__fs) + return; + __last = __i; + continue; + } + else + { + if (__fs) + { + __first = ++__i; + continue; + } + } + } + // sort smaller range with recursive call and larger with tail recursion elimination + if (__i - __first < __last - __i) + { + _VSTD::__sort<_Compare>(__first, __i, __comp); + // _VSTD::__sort<_Compare>(__i+1, __last, __comp); + __first = ++__i; + } + else + { + _VSTD::__sort<_Compare>(__i+1, __last, __comp); + // _VSTD::__sort<_Compare>(__first, __i, __comp); + __last = __i; + } + } +} + +// This forwarder keeps the top call and the recursive calls using the same instantiation, forcing a reference _Compare +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __sort<_Comp_ref>(__first, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __sort<_Comp_ref>(__first, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::sort(__first, __last, __less::value_type>()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort(_Tp** __first, _Tp** __last) +{ + _VSTD::sort((size_t*)__first, (size_t*)__last, __less()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last) +{ + _VSTD::sort(__first.base(), __last.base()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last, _Compare __comp) +{ + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + _VSTD::sort<_Tp*, _Comp_ref>(__first.base(), __last.base(), __comp); +} + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4231) +#endif // _MSC_VER +extern template void __sort<__less&, char*>(char*, char*, __less&); +extern template void __sort<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&); +extern template void __sort<__less&, signed char*>(signed char*, signed char*, __less&); +extern template void __sort<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&); +extern template void __sort<__less&, short*>(short*, short*, __less&); +extern template void __sort<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&); +extern template void __sort<__less&, int*>(int*, int*, __less&); +extern template void __sort<__less&, unsigned*>(unsigned*, unsigned*, __less&); +extern template void __sort<__less&, long*>(long*, long*, __less&); +extern template void __sort<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&); +extern template void __sort<__less&, long long*>(long long*, long long*, __less&); +extern template void __sort<__less&, unsigned long long*>(unsigned long long*, unsigned long long*, __less&); +extern template void __sort<__less&, float*>(float*, float*, __less&); +extern template void __sort<__less&, double*>(double*, double*, __less&); +extern template void __sort<__less&, long double*>(long double*, long double*, __less&); + +extern template bool __insertion_sort_incomplete<__less&, char*>(char*, char*, __less&); +extern template bool __insertion_sort_incomplete<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&); +extern template bool __insertion_sort_incomplete<__less&, signed char*>(signed char*, signed char*, __less&); +extern template bool __insertion_sort_incomplete<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&); +extern template bool __insertion_sort_incomplete<__less&, short*>(short*, short*, __less&); +extern template bool __insertion_sort_incomplete<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&); +extern template bool __insertion_sort_incomplete<__less&, int*>(int*, int*, __less&); +extern template bool __insertion_sort_incomplete<__less&, unsigned*>(unsigned*, unsigned*, __less&); +extern template bool __insertion_sort_incomplete<__less&, long*>(long*, long*, __less&); +extern template bool __insertion_sort_incomplete<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&); +extern template bool __insertion_sort_incomplete<__less&, long long*>(long long*, long long*, __less&); +extern template bool __insertion_sort_incomplete<__less&, unsigned long long*>(unsigned long long*, unsigned long long*, __less&); +extern template bool __insertion_sort_incomplete<__less&, float*>(float*, float*, __less&); +extern template bool __insertion_sort_incomplete<__less&, double*>(double*, double*, __less&); +extern template bool __insertion_sort_incomplete<__less&, long double*>(long double*, long double*, __less&); + +extern template unsigned __sort5<__less&, long double*>(long double*, long double*, long double*, long double*, long double*, __less&); +#ifdef _MSC_VER +#pragma warning( pop ) +#endif _MSC_VER + +// lower_bound + +template +_ForwardIterator +__lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + difference_type __len = _VSTD::distance(__first, __last); + while (__len != 0) + { + difference_type __l2 = __len / 2; + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__comp(*__m, __value_)) + { + __first = ++__m; + __len -= __l2 + 1; + } + else + __len = __l2; + } + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __lower_bound<_Comp_ref>(__first, __last, __value_, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __lower_bound<_Comp_ref>(__first, __last, __value_, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::lower_bound(__first, __last, __value_, + __less::value_type, _Tp>()); +} + +// upper_bound + +template +_ForwardIterator +__upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + difference_type __len = _VSTD::distance(__first, __last); + while (__len != 0) + { + difference_type __l2 = __len / 2; + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__comp(__value_, *__m)) + __len = __l2; + else + { + __first = ++__m; + __len -= __l2 + 1; + } + } + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __upper_bound<_Comp_ref>(__first, __last, __value_, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __upper_bound<_Comp_ref>(__first, __last, __value_, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::upper_bound(__first, __last, __value_, + __less<_Tp, typename iterator_traits<_ForwardIterator>::value_type>()); +} + +// equal_range + +template +pair<_ForwardIterator, _ForwardIterator> +__equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + difference_type __len = _VSTD::distance(__first, __last); + while (__len != 0) + { + difference_type __l2 = __len / 2; + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__comp(*__m, __value_)) + { + __first = ++__m; + __len -= __l2 + 1; + } + else if (__comp(__value_, *__m)) + { + __last = __m; + __len = __l2; + } + else + { + _ForwardIterator __mp1 = __m; + return pair<_ForwardIterator, _ForwardIterator> + ( + __lower_bound<_Compare>(__first, __m, __value_, __comp), + __upper_bound<_Compare>(++__mp1, __last, __value_, __comp) + ); + } + } + return pair<_ForwardIterator, _ForwardIterator>(__first, __first); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +pair<_ForwardIterator, _ForwardIterator> +equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __equal_range<_Comp_ref>(__first, __last, __value_, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __equal_range<_Comp_ref>(__first, __last, __value_, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +pair<_ForwardIterator, _ForwardIterator> +equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::equal_range(__first, __last, __value_, + __less::value_type, _Tp>()); +} + +// binary_search + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +__binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ + __first = __lower_bound<_Compare>(__first, __last, __value_, __comp); + return __first != __last && !__comp(__value_, *__first); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __binary_search<_Comp_ref>(__first, __last, __value_, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __binary_search<_Comp_ref>(__first, __last, __value_, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::binary_search(__first, __last, __value_, + __less::value_type, _Tp>()); +} + +// merge + +template +_OutputIterator +__merge(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + for (; __first1 != __last1; ++__result) + { + if (__first2 == __last2) + return _VSTD::copy(__first1, __last1, __result); + if (__comp(*__first2, *__first1)) + { + *__result = *__first2; + ++__first2; + } + else + { + *__result = *__first1; + ++__first1; + } + } + return _VSTD::copy(__first2, __last2, __result); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +merge(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +merge(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + typedef typename iterator_traits<_InputIterator1>::value_type __v1; + typedef typename iterator_traits<_InputIterator2>::value_type __v2; + return merge(__first1, __last1, __first2, __last2, __result, __less<__v1, __v2>()); +} + +// inplace_merge + +template +void +__buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, + _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1, + typename iterator_traits<_BidirectionalIterator>::difference_type __len2, + typename iterator_traits<_BidirectionalIterator>::value_type* __buff) +{ + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + typedef typename iterator_traits<_BidirectionalIterator>::pointer pointer; + __destruct_n __d(0); + unique_ptr __h2(__buff, __d); + if (__len1 <= __len2) + { + value_type* __p = __buff; + for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), ++__i, ++__p) + ::new(__p) value_type(_VSTD::move(*__i)); + __merge<_Compare>(move_iterator(__buff), + move_iterator(__p), + move_iterator<_BidirectionalIterator>(__middle), + move_iterator<_BidirectionalIterator>(__last), + __first, __comp); + } + else + { + value_type* __p = __buff; + for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), ++__i, ++__p) + ::new(__p) value_type(_VSTD::move(*__i)); + typedef reverse_iterator<_BidirectionalIterator> _RBi; + typedef reverse_iterator _Rv; + __merge(move_iterator<_RBi>(_RBi(__middle)), move_iterator<_RBi>(_RBi(__first)), + move_iterator<_Rv>(_Rv(__p)), move_iterator<_Rv>(_Rv(__buff)), + _RBi(__last), __negate<_Compare>(__comp)); + } +} + +template +void +__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, + _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1, + typename iterator_traits<_BidirectionalIterator>::difference_type __len2, + typename iterator_traits<_BidirectionalIterator>::value_type* __buff, ptrdiff_t __buff_size) +{ + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + while (true) + { + // if __middle == __last, we're done + if (__len2 == 0) + return; + // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0 + for (; true; ++__first, --__len1) + { + if (__len1 == 0) + return; + if (__comp(*__middle, *__first)) + break; + } + if (__len1 <= __buff_size || __len2 <= __buff_size) + { + __buffered_inplace_merge<_Compare>(__first, __middle, __last, __comp, __len1, __len2, __buff); + return; + } + // __first < __middle < __last + // *__first > *__middle + // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that + // all elements in: + // [__first, __m1) <= [__middle, __m2) + // [__middle, __m2) < [__m1, __middle) + // [__m1, __middle) <= [__m2, __last) + // and __m1 or __m2 is in the middle of its range + _BidirectionalIterator __m1; // "median" of [__first, __middle) + _BidirectionalIterator __m2; // "median" of [__middle, __last) + difference_type __len11; // distance(__first, __m1) + difference_type __len21; // distance(__middle, __m2) + // binary search smaller range + if (__len1 < __len2) + { // __len >= 1, __len2 >= 2 + __len21 = __len2 / 2; + __m2 = __middle; + _VSTD::advance(__m2, __len21); + __m1 = __upper_bound<_Compare>(__first, __middle, *__m2, __comp); + __len11 = _VSTD::distance(__first, __m1); + } + else + { + if (__len1 == 1) + { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1 + // It is known *__first > *__middle + swap(*__first, *__middle); + return; + } + // __len1 >= 2, __len2 >= 1 + __len11 = __len1 / 2; + __m1 = __first; + _VSTD::advance(__m1, __len11); + __m2 = __lower_bound<_Compare>(__middle, __last, *__m1, __comp); + __len21 = _VSTD::distance(__middle, __m2); + } + difference_type __len12 = __len1 - __len11; // distance(__m1, __middle) + difference_type __len22 = __len2 - __len21; // distance(__m2, __last) + // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) + // swap middle two partitions + __middle = _VSTD::rotate(__m1, __middle, __m2); + // __len12 and __len21 now have swapped meanings + // merge smaller range with recurisve call and larger with tail recursion elimination + if (__len11 + __len21 < __len12 + __len22) + { + __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); +// __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); + __first = __middle; + __middle = __m2; + __len1 = __len12; + __len2 = __len22; + } + else + { + __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); +// __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); + __last = __middle; + __middle = __m1; + __len1 = __len11; + __len2 = __len21; + } + } +} + +template +struct __inplace_merge_switch +{ + static const unsigned value = is_trivially_copy_assignable<_Tp>::value; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +void +inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, + _Compare __comp) +{ + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + difference_type __len1 = _VSTD::distance(__first, __middle); + difference_type __len2 = _VSTD::distance(__middle, __last); + difference_type __buf_size = _VSTD::min(__len1, __len2); + pair __buf(0, 0); + unique_ptr __h; + if (__inplace_merge_switch::value && __buf_size > 8) + { + __buf = _VSTD::get_temporary_buffer(__buf_size); + __h.reset(__buf.first); + } +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __c, __len1, __len2, + __buf.first, __buf.second); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __comp, __len1, __len2, + __buf.first, __buf.second); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) +{ + _VSTD::inplace_merge(__first, __middle, __last, + __less::value_type>()); +} + +// stable_sort + +template +void +__merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, + typename iterator_traits<_InputIterator1>::value_type* __result, _Compare __comp) +{ + typedef typename iterator_traits<_InputIterator1>::value_type value_type; + __destruct_n __d(0); + unique_ptr __h(__result, __d); + for (; true; ++__result) + { + if (__first1 == __last1) + { + for (; __first2 != __last2; ++__first2, ++__result, __d.__incr((value_type*)0)) + ::new (__result) value_type(_VSTD::move(*__first2)); + __h.release(); + return; + } + if (__first2 == __last2) + { + for (; __first1 != __last1; ++__first1, ++__result, __d.__incr((value_type*)0)) + ::new (__result) value_type(_VSTD::move(*__first1)); + __h.release(); + return; + } + if (__comp(*__first2, *__first1)) + { + ::new (__result) value_type(_VSTD::move(*__first2)); + __d.__incr((value_type*)0); + ++__first2; + } + else + { + ::new (__result) value_type(_VSTD::move(*__first1)); + __d.__incr((value_type*)0); + ++__first1; + } + } +} + +template +void +__merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, + _OutputIterator __result, _Compare __comp) +{ + for (; __first1 != __last1; ++__result) + { + if (__first2 == __last2) + { + for (; __first1 != __last1; ++__first1, ++__result) + *__result = _VSTD::move(*__first1); + return; + } + if (__comp(*__first2, *__first1)) + { + *__result = _VSTD::move(*__first2); + ++__first2; + } + else + { + *__result = _VSTD::move(*__first1); + ++__first1; + } + } + for (; __first2 != __last2; ++__first2, ++__result) + *__result = _VSTD::move(*__first2); +} + +template +void +__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size); + +template +void +__stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __first2) +{ + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + switch (__len) + { + case 0: + return; + case 1: + ::new(__first2) value_type(_VSTD::move(*__first1)); + return; + case 2: + __destruct_n __d(0); + unique_ptr __h2(__first2, __d); + if (__comp(*--__last1, *__first1)) + { + ::new(__first2) value_type(_VSTD::move(*__last1)); + __d.__incr((value_type*)0); + ++__first2; + ::new(__first2) value_type(_VSTD::move(*__first1)); + } + else + { + ::new(__first2) value_type(_VSTD::move(*__first1)); + __d.__incr((value_type*)0); + ++__first2; + ::new(__first2) value_type(_VSTD::move(*__last1)); + } + __h2.release(); + return; + } + if (__len <= 8) + { + __insertion_sort_move<_Compare>(__first1, __last1, __first2, __comp); + return; + } + typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; + _RandomAccessIterator __m = __first1 + __l2; + __stable_sort<_Compare>(__first1, __m, __comp, __l2, __first2, __l2); + __stable_sort<_Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2); + __merge_move_construct<_Compare>(__first1, __m, __m, __last1, __first2, __comp); +} + +template +struct __stable_sort_switch +{ + static const unsigned value = 128*is_trivially_copy_assignable<_Tp>::value; +}; + +template +void +__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size) +{ + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + switch (__len) + { + case 0: + case 1: + return; + case 2: + if (__comp(*--__last, *__first)) + swap(*__first, *__last); + return; + } + if (__len <= static_cast(__stable_sort_switch::value)) + { + __insertion_sort<_Compare>(__first, __last, __comp); + return; + } + typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; + _RandomAccessIterator __m = __first + __l2; + if (__len <= __buff_size) + { + __destruct_n __d(0); + unique_ptr __h2(__buff, __d); + __stable_sort_move<_Compare>(__first, __m, __comp, __l2, __buff); + __d.__set(__l2, (value_type*)0); + __stable_sort_move<_Compare>(__m, __last, __comp, __len - __l2, __buff + __l2); + __d.__set(__len, (value_type*)0); + __merge_move_assign<_Compare>(__buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp); +// __merge<_Compare>(move_iterator(__buff), +// move_iterator(__buff + __l2), +// move_iterator<_RandomAccessIterator>(__buff + __l2), +// move_iterator<_RandomAccessIterator>(__buff + __len), +// __first, __comp); + return; + } + __stable_sort<_Compare>(__first, __m, __comp, __l2, __buff, __buff_size); + __stable_sort<_Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size); + __inplace_merge<_Compare>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + difference_type __len = __last - __first; + pair __buf(0, 0); + unique_ptr __h; + if (__len > static_cast(__stable_sort_switch::value)) + { + __buf = _VSTD::get_temporary_buffer(__len); + __h.reset(__buf.first); + } +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __stable_sort<_Comp_ref>(__first, __last, __c, __len, __buf.first, __buf.second); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __stable_sort<_Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::stable_sort(__first, __last, __less::value_type>()); +} + +// is_heap_until + +template +_RandomAccessIterator +is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename _VSTD::iterator_traits<_RandomAccessIterator>::difference_type difference_type; + difference_type __len = __last - __first; + difference_type __p = 0; + difference_type __c = 1; + _RandomAccessIterator __pp = __first; + while (__c < __len) + { + _RandomAccessIterator __cp = __first + __c; + if (__comp(*__pp, *__cp)) + return __cp; + ++__c; + ++__cp; + if (__c == __len) + return __last; + if (__comp(*__pp, *__cp)) + return __cp; + ++__p; + ++__pp; + __c = 2 * __p + 1; + } + return __last; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_RandomAccessIterator +is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + return _VSTD::is_heap_until(__first, __last, __less::value_type>()); +} + +// is_heap + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + return _VSTD::is_heap_until(__first, __last, __comp) == __last; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + return _VSTD::is_heap(__first, __last, __less::value_type>()); +} + +// push_heap + +template +void +__push_heap_front(_RandomAccessIterator __first, _RandomAccessIterator, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + if (__len > 1) + { + difference_type __p = 0; + _RandomAccessIterator __pp = __first; + difference_type __c = 2; + _RandomAccessIterator __cp = __first + __c; + if (__c == __len || __comp(*__cp, *(__cp - 1))) + { + --__c; + --__cp; + } + if (__comp(*__pp, *__cp)) + { + value_type __t(_VSTD::move(*__pp)); + do + { + *__pp = _VSTD::move(*__cp); + __pp = __cp; + __p = __c; + __c = (__p + 1) * 2; + if (__c > __len) + break; + __cp = __first + __c; + if (__c == __len || __comp(*__cp, *(__cp - 1))) + { + --__c; + --__cp; + } + } while (__comp(__t, *__cp)); + *__pp = _VSTD::move(__t); + } + } +} + +template +void +__push_heap_back(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + if (__len > 1) + { + __len = (__len - 2) / 2; + _RandomAccessIterator __ptr = __first + __len; + if (__comp(*__ptr, *--__last)) + { + value_type __t(_VSTD::move(*__last)); + do + { + *__last = _VSTD::move(*__ptr); + __last = __ptr; + if (__len == 0) + break; + __len = (__len - 1) / 2; + __ptr = __first + __len; + } while (__comp(*__ptr, __t)); + *__last = _VSTD::move(__t); + } + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __push_heap_back<_Comp_ref>(__first, __last, __c, __last - __first); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __push_heap_back<_Comp_ref>(__first, __last, __comp, __last - __first); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::push_heap(__first, __last, __less::value_type>()); +} + +// pop_heap + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len) +{ + if (__len > 1) + { + swap(*__first, *--__last); + __push_heap_front<_Compare>(__first, __last, __comp, __len-1); + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __pop_heap<_Comp_ref>(__first, __last, __c, __last - __first); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::pop_heap(__first, __last, __less::value_type>()); +} + +// make_heap + +template +void +__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + difference_type __n = __last - __first; + if (__n > 1) + { + __last = __first; + ++__last; + for (difference_type __i = 1; __i < __n;) + __push_heap_back<_Compare>(__first, ++__last, __comp, ++__i); + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __make_heap<_Comp_ref>(__first, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __make_heap<_Comp_ref>(__first, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::make_heap(__first, __last, __less::value_type>()); +} + +// sort_heap + +template +void +__sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + for (difference_type __n = __last - __first; __n > 1; --__last, --__n) + __pop_heap<_Compare>(__first, __last, __comp, __n); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __sort_heap<_Comp_ref>(__first, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __sort_heap<_Comp_ref>(__first, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::sort_heap(__first, __last, __less::value_type>()); +} + +// partial_sort + +template +void +__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, + _Compare __comp) +{ + __make_heap<_Compare>(__first, __middle, __comp); + typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first; + for (_RandomAccessIterator __i = __middle; __i != __last; ++__i) + { + if (__comp(*__i, *__first)) + { + swap(*__i, *__first); + __push_heap_front<_Compare>(__first, __middle, __comp, __len); + } + } + __sort_heap<_Compare>(__first, __middle, __comp); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, + _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __partial_sort<_Comp_ref>(__first, __middle, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __partial_sort<_Comp_ref>(__first, __middle, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) +{ + _VSTD::partial_sort(__first, __middle, __last, + __less::value_type>()); +} + +// partial_sort_copy + +template +_RandomAccessIterator +__partial_sort_copy(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) +{ + _RandomAccessIterator __r = __result_first; + if (__r != __result_last) + { + typename iterator_traits<_RandomAccessIterator>::difference_type __len = 0; + for (; __first != __last && __r != __result_last; ++__first, ++__r, ++__len) + *__r = *__first; + __make_heap<_Compare>(__result_first, __r, __comp); + for (; __first != __last; ++__first) + if (__comp(*__first, *__result_first)) + { + *__result_first = *__first; + __push_heap_front<_Compare>(__result_first, __r, __comp, __len); + } + __sort_heap<_Compare>(__result_first, __r, __comp); + } + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_RandomAccessIterator +partial_sort_copy(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_RandomAccessIterator +partial_sort_copy(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __result_first, _RandomAccessIterator __result_last) +{ + return _VSTD::partial_sort_copy(__first, __last, __result_first, __result_last, + __less::value_type>()); +} + +// nth_element + +template +void +__nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) +{ + // _Compare is known to be a reference type + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + const difference_type __limit = 7; + while (true) + { + __restart: + difference_type __len = __last - __first; + switch (__len) + { + case 0: + case 1: + return; + case 2: + if (__comp(*--__last, *__first)) + swap(*__first, *__last); + return; + case 3: + { + _RandomAccessIterator __m = __first; + _VSTD::__sort3<_Compare>(__first, ++__m, --__last, __comp); + return; + } + } + if (__len <= __limit) + { + __selection_sort<_Compare>(__first, __last, __comp); + return; + } + // __len > __limit >= 3 + _RandomAccessIterator __m = __first + __len/2; + _RandomAccessIterator __lm1 = __last; + unsigned __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, --__lm1, __comp); + // *__m is median + // partition [__first, __m) < *__m and *__m <= [__m, __last) + // (this inhibits tossing elements equivalent to __m around unnecessarily) + _RandomAccessIterator __i = __first; + _RandomAccessIterator __j = __lm1; + // j points beyond range to be tested, *__lm1 is known to be <= *__m + // The search going up is known to be guarded but the search coming down isn't. + // Prime the downward search with a guard. + if (!__comp(*__i, *__m)) // if *__first == *__m + { + // *__first == *__m, *__first doesn't go in first part + // manually guard downward moving __j against __i + while (true) + { + if (__i == --__j) + { + // *__first == *__m, *__m <= all other elements + // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) + ++__i; // __first + 1 + __j = __last; + if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) + { + while (true) + { + if (__i == __j) + return; // [__first, __last) all equivalent elements + if (__comp(*__first, *__i)) + { + swap(*__i, *__j); + ++__n_swaps; + ++__i; + break; + } + ++__i; + } + } + // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 + if (__i == __j) + return; + while (true) + { + while (!__comp(*__first, *__i)) + ++__i; + while (__comp(*__first, *--__j)) + ; + if (__i >= __j) + break; + swap(*__i, *__j); + ++__n_swaps; + ++__i; + } + // [__first, __i) == *__first and *__first < [__i, __last) + // The first part is sorted, + if (__nth < __i) + return; + // __nth_element the secod part + // __nth_element<_Compare>(__i, __nth, __last, __comp); + __first = __i; + goto __restart; + } + if (__comp(*__j, *__m)) + { + swap(*__i, *__j); + ++__n_swaps; + break; // found guard for downward moving __j, now use unguarded partition + } + } + } + ++__i; + // j points beyond range to be tested, *__lm1 is known to be <= *__m + // if not yet partitioned... + if (__i < __j) + { + // known that *(__i - 1) < *__m + while (true) + { + // __m still guards upward moving __i + while (__comp(*__i, *__m)) + ++__i; + // It is now known that a guard exists for downward moving __j + while (!__comp(*--__j, *__m)) + ; + if (__i >= __j) + break; + swap(*__i, *__j); + ++__n_swaps; + // It is known that __m != __j + // If __m just moved, follow it + if (__m == __i) + __m = __j; + ++__i; + } + } + // [__first, __i) < *__m and *__m <= [__i, __last) + if (__i != __m && __comp(*__m, *__i)) + { + swap(*__i, *__m); + ++__n_swaps; + } + // [__first, __i) < *__i and *__i <= [__i+1, __last) + if (__nth == __i) + return; + if (__n_swaps == 0) + { + // We were given a perfectly partitioned sequence. Coincidence? + if (__nth < __i) + { + // Check for [__first, __i) already sorted + __j = __m = __first; + while (++__j != __i) + { + if (__comp(*__j, *__m)) + // not yet sorted, so sort + goto not_sorted; + __m = __j; + } + // [__first, __i) sorted + return; + } + else + { + // Check for [__i, __last) already sorted + __j = __m = __i; + while (++__j != __last) + { + if (__comp(*__j, *__m)) + // not yet sorted, so sort + goto not_sorted; + __m = __j; + } + // [__i, __last) sorted + return; + } + } +not_sorted: + // __nth_element on range containing __nth + if (__nth < __i) + { + // __nth_element<_Compare>(__first, __nth, __i, __comp); + __last = __i; + } + else + { + // __nth_element<_Compare>(__i+1, __nth, __last, __comp); + __first = ++__i; + } + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __nth_element<_Comp_ref>(__first, __nth, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __nth_element<_Comp_ref>(__first, __nth, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) +{ + _VSTD::nth_element(__first, __nth, __last, __less::value_type>()); +} + +// includes + +template +bool +__includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, + _Compare __comp) +{ + for (; __first2 != __last2; ++__first1) + { + if (__first1 == __last1 || __comp(*__first2, *__first1)) + return false; + if (!__comp(*__first1, *__first2)) + ++__first2; + } + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, + _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) +{ + return _VSTD::includes(__first1, __last1, __first2, __last2, + __less::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_union + +template +_OutputIterator +__set_union(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + for (; __first1 != __last1; ++__result) + { + if (__first2 == __last2) + return _VSTD::copy(__first1, __last1, __result); + if (__comp(*__first2, *__first1)) + { + *__result = *__first2; + ++__first2; + } + else + { + *__result = *__first1; + if (!__comp(*__first1, *__first2)) + ++__first2; + ++__first1; + } + } + return _VSTD::copy(__first2, __last2, __result); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_union(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_union(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + return _VSTD::set_union(__first1, __last1, __first2, __last2, __result, + __less::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_intersection + +template +_OutputIterator +__set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + while (__first1 != __last1 && __first2 != __last2) + { + if (__comp(*__first1, *__first2)) + ++__first1; + else + { + if (!__comp(*__first2, *__first1)) + { + *__result = *__first1; + ++__result; + ++__first1; + } + ++__first2; + } + } + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + return _VSTD::set_intersection(__first1, __last1, __first2, __last2, __result, + __less::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_difference + +template +_OutputIterator +__set_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + while (__first1 != __last1) + { + if (__first2 == __last2) + return _VSTD::copy(__first1, __last1, __result); + if (__comp(*__first1, *__first2)) + { + *__result = *__first1; + ++__result; + ++__first1; + } + else + { + if (!__comp(*__first2, *__first1)) + ++__first1; + ++__first2; + } + } + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + return _VSTD::set_difference(__first1, __last1, __first2, __last2, __result, + __less::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_symmetric_difference + +template +_OutputIterator +__set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ + while (__first1 != __last1) + { + if (__first2 == __last2) + return _VSTD::copy(__first1, __last1, __result); + if (__comp(*__first1, *__first2)) + { + *__result = *__first1; + ++__result; + ++__first1; + } + else + { + if (__comp(*__first2, *__first1)) + { + *__result = *__first2; + ++__result; + } + else + ++__first1; + ++__first2; + } + } + return _VSTD::copy(__first2, __last2, __result); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + return _VSTD::set_symmetric_difference(__first1, __last1, __first2, __last2, __result, + __less::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// lexicographical_compare + +template +bool +__lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) +{ + for (; __first2 != __last2; ++__first1, ++__first2) + { + if (__first1 == __last1 || __comp(*__first1, *__first2)) + return true; + if (__comp(*__first2, *__first1)) + return false; + } + return false; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2) +{ + return _VSTD::lexicographical_compare(__first1, __last1, __first2, __last2, + __less::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// next_permutation + +template +bool +__next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) +{ + _BidirectionalIterator __i = __last; + if (__first == __last || __first == --__i) + return false; + while (true) + { + _BidirectionalIterator __ip1 = __i; + if (__comp(*--__i, *__ip1)) + { + _BidirectionalIterator __j = __last; + while (!__comp(*__i, *--__j)) + ; + swap(*__i, *__j); + _VSTD::reverse(__ip1, __last); + return true; + } + if (__i == __first) + { + _VSTD::reverse(__first, __last); + return false; + } + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __next_permutation<_Comp_ref>(__first, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __next_permutation<_Comp_ref>(__first, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) +{ + return _VSTD::next_permutation(__first, __last, + __less::value_type>()); +} + +// prev_permutation + +template +bool +__prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) +{ + _BidirectionalIterator __i = __last; + if (__first == __last || __first == --__i) + return false; + while (true) + { + _BidirectionalIterator __ip1 = __i; + if (__comp(*__ip1, *--__i)) + { + _BidirectionalIterator __j = __last; + while (!__comp(*--__j, *__i)) + ; + swap(*__i, *__j); + _VSTD::reverse(__ip1, __last); + return true; + } + if (__i == __first) + { + _VSTD::reverse(__first, __last); + return false; + } + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __prev_permutation<_Comp_ref>(__first, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __prev_permutation<_Comp_ref>(__first, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) +{ + return _VSTD::prev_permutation(__first, __last, + __less::value_type>()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + _Tp +>::type +__rotate_left(_Tp __t, _Tp __n = 1) +{ + const unsigned __bits = static_cast(sizeof(_Tp) * __CHAR_BIT__ - 1); + __n &= __bits; + return static_cast<_Tp>((__t << __n) | (static_cast::type>(__t) >> (__bits - __n))); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + _Tp +>::type +__rotate_right(_Tp __t, _Tp __n = 1) +{ + const unsigned __bits = static_cast(sizeof(_Tp) * __CHAR_BIT__ - 1); + __n &= __bits; + return static_cast<_Tp>((__t << (__bits - __n)) | (static_cast::type>(__t) >> __n)); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ALGORITHM diff --git a/contrib/libc++/include/array b/contrib/libc++/include/array new file mode 100644 index 000000000000..c11f4bd74f5f --- /dev/null +++ b/contrib/libc++/include/array @@ -0,0 +1,338 @@ +// -*- C++ -*- +//===---------------------------- array -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ARRAY +#define _LIBCPP_ARRAY + +/* + array synopsis + +namespace std +{ +template +struct array +{ + // types: + typedef T & reference; + typedef const T & const_reference; + typedef implementation defined iterator; + typedef implementation defined const_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + // No explicit construct/copy/destroy for aggregate type + void fill(const T& u); + void swap(array& a) noexcept(noexcept(swap(declval(), declval()))); + + // iterators: + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // capacity: + constexpr size_type size() const noexcept; + constexpr size_type max_size() const noexcept; + bool empty() const noexcept; + + // element access: + reference operator[](size_type n); + const_reference operator[](size_type n) const; + const_reference at(size_type n) const; + reference at(size_type n); + + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + T* data() noexcept; + const T* data() const noexcept; +}; + +template + bool operator==(const array& x, const array& y); +template + bool operator!=(const array& x, const array& y); +template + bool operator<(const array& x, const array& y); +template + bool operator>(const array& x, const array& y); +template + bool operator<=(const array& x, const array& y); +template + bool operator>=(const array& x, const array& y); + +template + void swap(array& x, array& y) noexcept(noexcept(x.swap(y))); + +template class tuple_size; +template class tuple_element; +template struct tuple_size>; +template struct tuple_element>; +template T& get(array&) noexcept; +template const T& get(const array&) noexcept; +template T&& get(array&&) noexcept; + +} // std + +*/ + +#include <__config> +#include <__tuple> +#include +#include +#include +#include +#include +#if defined(_LIBCPP_NO_EXCEPTIONS) + #include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct _LIBCPP_VISIBLE array +{ + // types: + typedef array __self; + typedef _Tp value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + value_type __elems_[_Size > 0 ? _Size : 1]; + + // No explicit construct/copy/destroy for aggregate type + _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) + {_VSTD::fill_n(__elems_, _Size, __u);} + _LIBCPP_INLINE_VISIBILITY + void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) + {_VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);} + + // iterators: + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return iterator(__elems_);} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return const_iterator(__elems_);} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return iterator(__elems_ + _Size);} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return const_iterator(__elems_ + _Size);} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT {return rend();} + + // capacity: + _LIBCPP_INLINE_VISIBILITY + /*constexpr*/ size_type size() const _NOEXCEPT {return _Size;} + _LIBCPP_INLINE_VISIBILITY + /*constexpr*/ size_type max_size() const _NOEXCEPT {return _Size;} + _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return _Size == 0;} + + // element access: + _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __elems_[__n];} + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __elems_[__n];} + reference at(size_type __n); + const_reference at(size_type __n) const; + + _LIBCPP_INLINE_VISIBILITY reference front() {return __elems_[0];} + _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __elems_[0];} + _LIBCPP_INLINE_VISIBILITY reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];} + _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];} + + _LIBCPP_INLINE_VISIBILITY + value_type* data() _NOEXCEPT {return __elems_;} + _LIBCPP_INLINE_VISIBILITY + const value_type* data() const _NOEXCEPT {return __elems_;} +}; + +template +typename array<_Tp, _Size>::reference +array<_Tp, _Size>::at(size_type __n) +{ + if (__n >= _Size) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range("array::at"); +#else + assert(!"array::at out_of_range"); +#endif + return __elems_[__n]; +} + +template +typename array<_Tp, _Size>::const_reference +array<_Tp, _Size>::at(size_type __n) const +{ + if (__n >= _Size) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range("array::at"); +#else + assert(!"array::at out_of_range"); +#endif + return __elems_[__n]; +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return _VSTD::equal(__x.__elems_, __x.__elems_ + _Size, __y.__elems_); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return !(__x == __y); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return _VSTD::lexicographical_compare(__x.__elems_, __x.__elems_ + _Size, __y.__elems_, __y.__elems_ + _Size); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return __y < __x; +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return !(__y < __x); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) +{ + return !(__x < __y); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +typename enable_if +< + __is_swappable<_Tp>::value, + void +>::type +swap(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) + _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) +{ + __x.swap(__y); +} + +template +class _LIBCPP_VISIBLE tuple_size > + : public integral_constant {}; + +template +class _LIBCPP_VISIBLE tuple_size > + : public integral_constant {}; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, array<_Tp, _Size> > +{ +public: + typedef _Tp type; +}; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, const array<_Tp, _Size> > +{ +public: + typedef const _Tp type; +}; + +template +_LIBCPP_INLINE_VISIBILITY inline +_Tp& +get(array<_Tp, _Size>& __a) _NOEXCEPT +{ + return __a[_Ip]; +} + +template +_LIBCPP_INLINE_VISIBILITY inline +const _Tp& +get(const array<_Tp, _Size>& __a) _NOEXCEPT +{ + return __a[_Ip]; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +_LIBCPP_INLINE_VISIBILITY inline +_Tp&& +get(array<_Tp, _Size>&& __a) _NOEXCEPT +{ + return _VSTD::move(__a[_Ip]); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ARRAY diff --git a/contrib/libc++/include/atomic b/contrib/libc++/include/atomic new file mode 100644 index 000000000000..244f42d0aafa --- /dev/null +++ b/contrib/libc++/include/atomic @@ -0,0 +1,1515 @@ +// -*- C++ -*- +//===--------------------------- atomic -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ATOMIC +#define _LIBCPP_ATOMIC + +/* + atomic synopsis + +namespace std +{ + +// order and consistency + +typedef enum memory_order +{ + memory_order_relaxed, + memory_order_consume, // load-consume + memory_order_acquire, // load-acquire + memory_order_release, // store-release + memory_order_acq_rel, // store-release load-acquire + memory_order_seq_cst // store-release load-acquire +} memory_order; + +template T kill_dependency(T y); + +// lock-free property + +#define ATOMIC_CHAR_LOCK_FREE unspecified +#define ATOMIC_CHAR16_T_LOCK_FREE unspecified +#define ATOMIC_CHAR32_T_LOCK_FREE unspecified +#define ATOMIC_WCHAR_T_LOCK_FREE unspecified +#define ATOMIC_SHORT_LOCK_FREE unspecified +#define ATOMIC_INT_LOCK_FREE unspecified +#define ATOMIC_LONG_LOCK_FREE unspecified +#define ATOMIC_LLONG_LOCK_FREE unspecified + +// flag type and operations + +typedef struct atomic_flag +{ + bool test_and_set(memory_order m = memory_order_seq_cst) volatile; + bool test_and_set(memory_order m = memory_order_seq_cst); + void clear(memory_order m = memory_order_seq_cst) volatile; + void clear(memory_order m = memory_order_seq_cst); + atomic_flag() = default; + atomic_flag(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) volatile = delete; +} atomic_flag; + +bool + atomic_flag_test_and_set(volatile atomic_flag* obj); + +bool + atomic_flag_test_and_set(atomic_flag* obj); + +bool + atomic_flag_test_and_set_explicit(volatile atomic_flag* obj, + memory_order m); + +bool + atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m); + +void + atomic_flag_clear(volatile atomic_flag* obj); + +void + atomic_flag_clear(atomic_flag* obj); + +void + atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m); + +void + atomic_flag_clear_explicit(atomic_flag* obj, memory_order m); + +#define ATOMIC_FLAG_INIT see below +#define ATOMIC_VAR_INIT(value) see below + +template +struct atomic +{ + bool is_lock_free() const volatile; + bool is_lock_free() const; + void store(T desr, memory_order m = memory_order_seq_cst) volatile; + void store(T desr, memory_order m = memory_order_seq_cst); + T load(memory_order m = memory_order_seq_cst) const volatile; + T load(memory_order m = memory_order_seq_cst) const; + operator T() const volatile; + operator T() const; + T exchange(T desr, memory_order m = memory_order_seq_cst) volatile; + T exchange(T desr, memory_order m = memory_order_seq_cst); + bool compare_exchange_weak(T& expc, T desr, + memory_order s, memory_order f) volatile; + bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f); + bool compare_exchange_strong(T& expc, T desr, + memory_order s, memory_order f) volatile; + bool compare_exchange_strong(T& expc, T desr, + memory_order s, memory_order f); + bool compare_exchange_weak(T& expc, T desr, + memory_order m = memory_order_seq_cst) volatile; + bool compare_exchange_weak(T& expc, T desr, + memory_order m = memory_order_seq_cst); + bool compare_exchange_strong(T& expc, T desr, + memory_order m = memory_order_seq_cst) volatile; + bool compare_exchange_strong(T& expc, T desr, + memory_order m = memory_order_seq_cst); + + atomic() = default; + constexpr atomic(T desr); + atomic(const atomic&) = delete; + atomic& operator=(const atomic&) = delete; + atomic& operator=(const atomic&) volatile = delete; + T operator=(T) volatile; + T operator=(T); +}; + +template <> +struct atomic +{ + bool is_lock_free() const volatile; + bool is_lock_free() const; + void store(integral desr, memory_order m = memory_order_seq_cst) volatile; + void store(integral desr, memory_order m = memory_order_seq_cst); + integral load(memory_order m = memory_order_seq_cst) const volatile; + integral load(memory_order m = memory_order_seq_cst) const; + operator integral() const volatile; + operator integral() const; + integral exchange(integral desr, + memory_order m = memory_order_seq_cst) volatile; + integral exchange(integral desr, memory_order m = memory_order_seq_cst); + bool compare_exchange_weak(integral& expc, integral desr, + memory_order s, memory_order f) volatile; + bool compare_exchange_weak(integral& expc, integral desr, + memory_order s, memory_order f); + bool compare_exchange_strong(integral& expc, integral desr, + memory_order s, memory_order f) volatile; + bool compare_exchange_strong(integral& expc, integral desr, + memory_order s, memory_order f); + bool compare_exchange_weak(integral& expc, integral desr, + memory_order m = memory_order_seq_cst) volatile; + bool compare_exchange_weak(integral& expc, integral desr, + memory_order m = memory_order_seq_cst); + bool compare_exchange_strong(integral& expc, integral desr, + memory_order m = memory_order_seq_cst) volatile; + bool compare_exchange_strong(integral& expc, integral desr, + memory_order m = memory_order_seq_cst); + + integral + fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile; + integral fetch_add(integral op, memory_order m = memory_order_seq_cst); + integral + fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile; + integral fetch_sub(integral op, memory_order m = memory_order_seq_cst); + integral + fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile; + integral fetch_and(integral op, memory_order m = memory_order_seq_cst); + integral + fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile; + integral fetch_or(integral op, memory_order m = memory_order_seq_cst); + integral + fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile; + integral fetch_xor(integral op, memory_order m = memory_order_seq_cst); + + atomic() = default; + constexpr atomic(integral desr); + atomic(const atomic&) = delete; + atomic& operator=(const atomic&) = delete; + atomic& operator=(const atomic&) volatile = delete; + integral operator=(integral desr) volatile; + integral operator=(integral desr); + + integral operator++(int) volatile; + integral operator++(int); + integral operator--(int) volatile; + integral operator--(int); + integral operator++() volatile; + integral operator++(); + integral operator--() volatile; + integral operator--(); + integral operator+=(integral op) volatile; + integral operator+=(integral op); + integral operator-=(integral op) volatile; + integral operator-=(integral op); + integral operator&=(integral op) volatile; + integral operator&=(integral op); + integral operator|=(integral op) volatile; + integral operator|=(integral op); + integral operator^=(integral op) volatile; + integral operator^=(integral op); +}; + +template +struct atomic +{ + bool is_lock_free() const volatile; + bool is_lock_free() const; + void store(T* desr, memory_order m = memory_order_seq_cst) volatile; + void store(T* desr, memory_order m = memory_order_seq_cst); + T* load(memory_order m = memory_order_seq_cst) const volatile; + T* load(memory_order m = memory_order_seq_cst) const; + operator T*() const volatile; + operator T*() const; + T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile; + T* exchange(T* desr, memory_order m = memory_order_seq_cst); + bool compare_exchange_weak(T*& expc, T* desr, + memory_order s, memory_order f) volatile; + bool compare_exchange_weak(T*& expc, T* desr, + memory_order s, memory_order f); + bool compare_exchange_strong(T*& expc, T* desr, + memory_order s, memory_order f) volatile; + bool compare_exchange_strong(T*& expc, T* desr, + memory_order s, memory_order f); + bool compare_exchange_weak(T*& expc, T* desr, + memory_order m = memory_order_seq_cst) volatile; + bool compare_exchange_weak(T*& expc, T* desr, + memory_order m = memory_order_seq_cst); + bool compare_exchange_strong(T*& expc, T* desr, + memory_order m = memory_order_seq_cst) volatile; + bool compare_exchange_strong(T*& expc, T* desr, + memory_order m = memory_order_seq_cst); + T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile; + T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst); + T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile; + T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst); + + atomic() = default; + constexpr atomic(T* desr); + atomic(const atomic&) = delete; + atomic& operator=(const atomic&) = delete; + atomic& operator=(const atomic&) volatile = delete; + + T* operator=(T*) volatile; + T* operator=(T*); + T* operator++(int) volatile; + T* operator++(int); + T* operator--(int) volatile; + T* operator--(int); + T* operator++() volatile; + T* operator++(); + T* operator--() volatile; + T* operator--(); + T* operator+=(ptrdiff_t op) volatile; + T* operator+=(ptrdiff_t op); + T* operator-=(ptrdiff_t op) volatile; + T* operator-=(ptrdiff_t op); +}; + + +template + bool + atomic_is_lock_free(const volatile atomic* obj); + +template + bool + atomic_is_lock_free(const atomic* obj); + +template + void + atomic_init(volatile atomic* obj, T desr); + +template + void + atomic_init(atomic* obj, T desr); + +template + void + atomic_store(volatile atomic* obj, T desr); + +template + void + atomic_store(atomic* obj, T desr); + +template + void + atomic_store_explicit(volatile atomic* obj, T desr, memory_order m); + +template + void + atomic_store_explicit(atomic* obj, T desr, memory_order m); + +template + T + atomic_load(const volatile atomic* obj); + +template + T + atomic_load(const atomic* obj); + +template + T + atomic_load_explicit(const volatile atomic* obj, memory_order m); + +template + T + atomic_load_explicit(const atomic* obj, memory_order m); + +template + T + atomic_exchange(volatile atomic* obj, T desr); + +template + T + atomic_exchange(atomic* obj, T desr); + +template + T + atomic_exchange_explicit(volatile atomic* obj, T desr, memory_order m); + +template + T + atomic_exchange_explicit(atomic* obj, T desr, memory_order m); + +template + bool + atomic_compare_exchange_weak(volatile atomic* obj, T* expc, T desr); + +template + bool + atomic_compare_exchange_weak(atomic* obj, T* expc, T desr); + +template + bool + atomic_compare_exchange_strong(volatile atomic* obj, T* expc, T desr); + +template + bool + atomic_compare_exchange_strong(atomic* obj, T* expc, T desr); + +template + bool + atomic_compare_exchange_weak_explicit(volatile atomic* obj, T* expc, + T desr, + memory_order s, memory_order f); + +template + bool + atomic_compare_exchange_weak_explicit(atomic* obj, T* expc, T desr, + memory_order s, memory_order f); + +template + bool + atomic_compare_exchange_strong_explicit(volatile atomic* obj, + T* expc, T desr, + memory_order s, memory_order f); + +template + bool + atomic_compare_exchange_strong_explicit(atomic* obj, T* expc, + T desr, + memory_order s, memory_order f); + +template + Integral + atomic_fetch_add(volatile atomic* obj, Integral op); + +template + Integral + atomic_fetch_add(atomic* obj, Integral op); + +template + Integral + atomic_fetch_add_explicit(volatile atomic* obj, Integral op, + memory_order m); +template + Integral + atomic_fetch_add_explicit(atomic* obj, Integral op, + memory_order m); +template + Integral + atomic_fetch_sub(volatile atomic* obj, Integral op); + +template + Integral + atomic_fetch_sub(atomic* obj, Integral op); + +template + Integral + atomic_fetch_sub_explicit(volatile atomic* obj, Integral op, + memory_order m); +template + Integral + atomic_fetch_sub_explicit(atomic* obj, Integral op, + memory_order m); +template + Integral + atomic_fetch_and(volatile atomic* obj, Integral op); + +template + Integral + atomic_fetch_and(atomic* obj, Integral op); + +template + Integral + atomic_fetch_and_explicit(volatile atomic* obj, Integral op, + memory_order m); +template + Integral + atomic_fetch_and_explicit(atomic* obj, Integral op, + memory_order m); +template + Integral + atomic_fetch_or(volatile atomic* obj, Integral op); + +template + Integral + atomic_fetch_or(atomic* obj, Integral op); + +template + Integral + atomic_fetch_or_explicit(volatile atomic* obj, Integral op, + memory_order m); +template + Integral + atomic_fetch_or_explicit(atomic* obj, Integral op, + memory_order m); +template + Integral + atomic_fetch_xor(volatile atomic* obj, Integral op); + +template + Integral + atomic_fetch_xor(atomic* obj, Integral op); + +template + Integral + atomic_fetch_xor_explicit(volatile atomic* obj, Integral op, + memory_order m); +template + Integral + atomic_fetch_xor_explicit(atomic* obj, Integral op, + memory_order m); + +template + T* + atomic_fetch_add(volatile atomic* obj, ptrdiff_t op); + +template + T* + atomic_fetch_add(atomic* obj, ptrdiff_t op); + +template + T* + atomic_fetch_add_explicit(volatile atomic* obj, ptrdiff_t op, + memory_order m); +template + T* + atomic_fetch_add_explicit(atomic* obj, ptrdiff_t op, memory_order m); + +template + T* + atomic_fetch_sub(volatile atomic* obj, ptrdiff_t op); + +template + T* + atomic_fetch_sub(atomic* obj, ptrdiff_t op); + +template + T* + atomic_fetch_sub_explicit(volatile atomic* obj, ptrdiff_t op, + memory_order m); +template + T* + atomic_fetch_sub_explicit(atomic* obj, ptrdiff_t op, memory_order m); + +// Atomics for standard typedef types + +typedef atomic atomic_char; +typedef atomic atomic_schar; +typedef atomic atomic_uchar; +typedef atomic atomic_short; +typedef atomic atomic_ushort; +typedef atomic atomic_int; +typedef atomic atomic_uint; +typedef atomic atomic_long; +typedef atomic atomic_ulong; +typedef atomic atomic_llong; +typedef atomic atomic_ullong; +typedef atomic atomic_char16_t; +typedef atomic atomic_char32_t; +typedef atomic atomic_wchar_t; + +typedef atomic atomic_int_least8_t; +typedef atomic atomic_uint_least8_t; +typedef atomic atomic_int_least16_t; +typedef atomic atomic_uint_least16_t; +typedef atomic atomic_int_least32_t; +typedef atomic atomic_uint_least32_t; +typedef atomic atomic_int_least64_t; +typedef atomic atomic_uint_least64_t; + +typedef atomic atomic_int_fast8_t; +typedef atomic atomic_uint_fast8_t; +typedef atomic atomic_int_fast16_t; +typedef atomic atomic_uint_fast16_t; +typedef atomic atomic_int_fast32_t; +typedef atomic atomic_uint_fast32_t; +typedef atomic atomic_int_fast64_t; +typedef atomic atomic_uint_fast64_t; + +typedef atomic atomic_intptr_t; +typedef atomic atomic_uintptr_t; +typedef atomic atomic_size_t; +typedef atomic atomic_ptrdiff_t; +typedef atomic atomic_intmax_t; +typedef atomic atomic_uintmax_t; + +// fences + +void atomic_thread_fence(memory_order m); +void atomic_signal_fence(memory_order m); + +} // std + +*/ + +#include <__config> +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !__has_feature(cxx_atomic) +#error is not implemented +#else + +typedef enum memory_order +{ + memory_order_relaxed, memory_order_consume, memory_order_acquire, + memory_order_release, memory_order_acq_rel, memory_order_seq_cst +} memory_order; + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +kill_dependency(_Tp __y) +{ + return __y; +} + +// general atomic + +template ::value && !is_same<_Tp, bool>::value> +struct __atomic_base // false +{ + _Tp __a_; + + _LIBCPP_INLINE_VISIBILITY + bool is_lock_free() const volatile + {return __atomic_is_lock_free(_Tp());} + _LIBCPP_INLINE_VISIBILITY + bool is_lock_free() const + {return __atomic_is_lock_free(_Tp());} + _LIBCPP_INLINE_VISIBILITY + void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile + {__atomic_store(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + void store(_Tp __d, memory_order __m = memory_order_seq_cst) + {__atomic_store(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp load(memory_order __m = memory_order_seq_cst) const volatile + {return __atomic_load(&__a_, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp load(memory_order __m = memory_order_seq_cst) const + {return __atomic_load(&__a_, __m);} + _LIBCPP_INLINE_VISIBILITY + operator _Tp() const volatile {return load();} + _LIBCPP_INLINE_VISIBILITY + operator _Tp() const {return load();} + _LIBCPP_INLINE_VISIBILITY + _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile + {return __atomic_exchange(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) + {return __atomic_exchange(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) volatile + {return __atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) + {return __atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) volatile + {return __atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) + {return __atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) volatile + {return __atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) + {return __atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) volatile + {return __atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) + {return __atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} + + _LIBCPP_INLINE_VISIBILITY + __atomic_base() {} // = default; + _LIBCPP_INLINE_VISIBILITY + /*constexpr*/ __atomic_base(_Tp __d) : __a_(__d) {} +#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS + __atomic_base(const __atomic_base&) = delete; + __atomic_base& operator=(const __atomic_base&) = delete; + __atomic_base& operator=(const __atomic_base&) volatile = delete; +#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +private: + __atomic_base(const __atomic_base&); + __atomic_base& operator=(const __atomic_base&); + __atomic_base& operator=(const __atomic_base&) volatile; +#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +}; + +// atomic + +template +struct __atomic_base<_Tp, true> + : public __atomic_base<_Tp, false> +{ + typedef __atomic_base<_Tp, false> __base; + _LIBCPP_INLINE_VISIBILITY + __atomic_base() {} // = default; + _LIBCPP_INLINE_VISIBILITY + /*constexpr*/ __atomic_base(_Tp __d) : __base(__d) {} + + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile + {return __atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) + {return __atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile + {return __atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) + {return __atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile + {return __atomic_fetch_and(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) + {return __atomic_fetch_and(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile + {return __atomic_fetch_or(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) + {return __atomic_fetch_or(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile + {return __atomic_fetch_xor(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) + {return __atomic_fetch_xor(&this->__a_, __op, __m);} + + _LIBCPP_INLINE_VISIBILITY + _Tp operator++(int) volatile {return fetch_add(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator++(int) {return fetch_add(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--(int) volatile {return fetch_sub(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--(int) {return fetch_sub(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator++() volatile {return fetch_add(_Tp(1)) + _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator++() {return fetch_add(_Tp(1)) + _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--() volatile {return fetch_sub(_Tp(1)) - _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--() {return fetch_sub(_Tp(1)) - _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator+=(_Tp __op) volatile {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator+=(_Tp __op) {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator-=(_Tp __op) volatile {return fetch_sub(__op) - __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator-=(_Tp __op) {return fetch_sub(__op) - __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator&=(_Tp __op) volatile {return fetch_and(__op) & __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator&=(_Tp __op) {return fetch_and(__op) & __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator|=(_Tp __op) volatile {return fetch_or(__op) | __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator|=(_Tp __op) {return fetch_or(__op) | __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator^=(_Tp __op) volatile {return fetch_xor(__op) ^ __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator^=(_Tp __op) {return fetch_xor(__op) ^ __op;} +}; + +// atomic + +template +struct atomic + : public __atomic_base<_Tp> +{ + typedef __atomic_base<_Tp> __base; + _LIBCPP_INLINE_VISIBILITY + atomic() {} // = default; + _LIBCPP_INLINE_VISIBILITY + /*constexpr*/ atomic(_Tp __d) : __base(__d) {} + + _LIBCPP_INLINE_VISIBILITY + _Tp operator=(_Tp __d) volatile + {__base::store(__d); return __d;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator=(_Tp __d) + {__base::store(__d); return __d;} +}; + +// atomic + +template +struct atomic<_Tp*> + : public __atomic_base<_Tp*> +{ + typedef __atomic_base<_Tp*> __base; + _LIBCPP_INLINE_VISIBILITY + atomic() {} // = default; + _LIBCPP_INLINE_VISIBILITY + /*constexpr*/ atomic(_Tp* __d) : __base(__d) {} + + _LIBCPP_INLINE_VISIBILITY + _Tp* operator=(_Tp* __d) volatile + {__base::store(__d); return __d;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator=(_Tp* __d) + {__base::store(__d); return __d;} + + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) + volatile + {return __atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) + {return __atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) + volatile + {return __atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) + {return __atomic_fetch_sub(&this->__a_, __op, __m);} + + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++(int) volatile {return fetch_add(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++(int) {return fetch_add(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--(int) volatile {return fetch_sub(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--(int) {return fetch_sub(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++() volatile {return fetch_add(1) + 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++() {return fetch_add(1) + 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--() volatile {return fetch_sub(1) - 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--() {return fetch_sub(1) - 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator+=(ptrdiff_t __op) volatile {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator+=(ptrdiff_t __op) {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator-=(ptrdiff_t __op) volatile {return fetch_sub(__op) - __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator-=(ptrdiff_t __op) {return fetch_sub(__op) - __op;} +}; + +// atomic_is_lock_free + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_is_lock_free(const volatile atomic<_Tp>* __o) +{ + return __o->is_lock_free(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_is_lock_free(const atomic<_Tp>* __o) +{ + return __o->is_lock_free(); +} + +// atomic_init + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_init(volatile atomic<_Tp>* __o, _Tp __d) +{ + __o->__a_ = __d; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_init(atomic<_Tp>* __o, _Tp __d) +{ + __o->__a_ = __d; +} + +// atomic_store + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_store(volatile atomic<_Tp>* __o, _Tp __d) +{ + __o->store(__d); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_store(atomic<_Tp>* __o, _Tp __d) +{ + __o->store(__d); +} + +// atomic_store_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) +{ + __o->store(__d, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) +{ + __o->store(__d, __m); +} + +// atomic_load + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load(const volatile atomic<_Tp>* __o) +{ + return __o->load(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load(const atomic<_Tp>* __o) +{ + return __o->load(); +} + +// atomic_load_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) +{ + return __o->load(__m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) +{ + return __o->load(__m); +} + +// atomic_exchange + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) +{ + return __o->exchange(__d); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange(atomic<_Tp>* __o, _Tp __d) +{ + return __o->exchange(__d); +} + +// atomic_exchange_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) +{ + return __o->exchange(__d, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) +{ + return __o->exchange(__d, __m); +} + +// atomic_compare_exchange_weak + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) +{ + return __o->compare_exchange_weak(*__e, __d); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) +{ + return __o->compare_exchange_weak(*__e, __d); +} + +// atomic_compare_exchange_strong + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) +{ + return __o->compare_exchange_strong(*__e, __d); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) +{ + return __o->compare_exchange_strong(*__e, __d); +} + +// atomic_compare_exchange_weak_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e, + _Tp __d, + memory_order __s, memory_order __f) +{ + return __o->compare_exchange_weak(*__e, __d, __s, __f); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, + memory_order __s, memory_order __f) +{ + return __o->compare_exchange_weak(*__e, __d, __s, __f); +} + +// atomic_compare_exchange_strong_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, + _Tp* __e, _Tp __d, + memory_order __s, memory_order __f) +{ + return __o->compare_exchange_strong(*__e, __d, __s, __f); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e, + _Tp __d, + memory_order __s, memory_order __f) +{ + return __o->compare_exchange_strong(*__e, __d, __s, __f); +} + +// atomic_fetch_add + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) +{ + return __o->fetch_add(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) +{ + return __o->fetch_add(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) +{ + return __o->fetch_add(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) +{ + return __o->fetch_add(__op); +} + +// atomic_fetch_add_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) +{ + return __o->fetch_add(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) +{ + return __o->fetch_add(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, + memory_order __m) +{ + return __o->fetch_add(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) +{ + return __o->fetch_add(__op, __m); +} + +// atomic_fetch_sub + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) +{ + return __o->fetch_sub(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) +{ + return __o->fetch_sub(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) +{ + return __o->fetch_sub(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) +{ + return __o->fetch_sub(__op); +} + +// atomic_fetch_sub_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) +{ + return __o->fetch_sub(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) +{ + return __o->fetch_sub(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, + memory_order __m) +{ + return __o->fetch_sub(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) +{ + return __o->fetch_sub(__op, __m); +} + +// atomic_fetch_and + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) +{ + return __o->fetch_and(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) +{ + return __o->fetch_and(__op); +} + +// atomic_fetch_and_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) +{ + return __o->fetch_and(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) +{ + return __o->fetch_and(__op, __m); +} + +// atomic_fetch_or + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) +{ + return __o->fetch_or(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) +{ + return __o->fetch_or(__op); +} + +// atomic_fetch_or_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) +{ + return __o->fetch_or(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) +{ + return __o->fetch_or(__op, __m); +} + +// atomic_fetch_xor + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) +{ + return __o->fetch_xor(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) +{ + return __o->fetch_xor(__op); +} + +// atomic_fetch_xor_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) +{ + return __o->fetch_xor(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) +{ + return __o->fetch_xor(__op, __m); +} + +// flag type and operations + +typedef struct atomic_flag +{ + bool __a_; + + _LIBCPP_INLINE_VISIBILITY + bool test_and_set(memory_order __m = memory_order_seq_cst) volatile + {return __atomic_exchange(&__a_, true, __m);} + _LIBCPP_INLINE_VISIBILITY + bool test_and_set(memory_order __m = memory_order_seq_cst) + {return __atomic_exchange(&__a_, true, __m);} + _LIBCPP_INLINE_VISIBILITY + void clear(memory_order __m = memory_order_seq_cst) volatile + {__atomic_store(&__a_, false, __m);} + _LIBCPP_INLINE_VISIBILITY + void clear(memory_order __m = memory_order_seq_cst) + {__atomic_store(&__a_, false, __m);} + + _LIBCPP_INLINE_VISIBILITY + atomic_flag() {} // = default; + _LIBCPP_INLINE_VISIBILITY + atomic_flag(bool __b) : __a_(__b) {} + +#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS + atomic_flag(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) volatile = delete; +#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +private: + atomic_flag(const atomic_flag&); + atomic_flag& operator=(const atomic_flag&); + atomic_flag& operator=(const atomic_flag&) volatile; +#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +} atomic_flag; + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set(volatile atomic_flag* __o) +{ + return __o->test_and_set(); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set(atomic_flag* __o) +{ + return __o->test_and_set(); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) +{ + return __o->test_and_set(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) +{ + return __o->test_and_set(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear(volatile atomic_flag* __o) +{ + __o->clear(); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear(atomic_flag* __o) +{ + __o->clear(); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) +{ + __o->clear(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) +{ + __o->clear(__m); +} + +// fences + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_thread_fence(memory_order __m) +{ + __atomic_thread_fence(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_signal_fence(memory_order __m) +{ + __atomic_signal_fence(__m); +} + +// Atomics for standard typedef types + +typedef atomic atomic_char; +typedef atomic atomic_schar; +typedef atomic atomic_uchar; +typedef atomic atomic_short; +typedef atomic atomic_ushort; +typedef atomic atomic_int; +typedef atomic atomic_uint; +typedef atomic atomic_long; +typedef atomic atomic_ulong; +typedef atomic atomic_llong; +typedef atomic atomic_ullong; +typedef atomic atomic_char16_t; +typedef atomic atomic_char32_t; +typedef atomic atomic_wchar_t; + +typedef atomic atomic_int_least8_t; +typedef atomic atomic_uint_least8_t; +typedef atomic atomic_int_least16_t; +typedef atomic atomic_uint_least16_t; +typedef atomic atomic_int_least32_t; +typedef atomic atomic_uint_least32_t; +typedef atomic atomic_int_least64_t; +typedef atomic atomic_uint_least64_t; + +typedef atomic atomic_int_fast8_t; +typedef atomic atomic_uint_fast8_t; +typedef atomic atomic_int_fast16_t; +typedef atomic atomic_uint_fast16_t; +typedef atomic atomic_int_fast32_t; +typedef atomic atomic_uint_fast32_t; +typedef atomic atomic_int_fast64_t; +typedef atomic atomic_uint_fast64_t; + +typedef atomic atomic_intptr_t; +typedef atomic atomic_uintptr_t; +typedef atomic atomic_size_t; +typedef atomic atomic_ptrdiff_t; +typedef atomic atomic_intmax_t; +typedef atomic atomic_uintmax_t; + +#define ATOMIC_FLAG_INIT {false} +#define ATOMIC_VAR_INIT(__v) {__v} + +// lock-free property + +#define ATOMIC_CHAR_LOCK_FREE 0 +#define ATOMIC_CHAR16_T_LOCK_FREE 0 +#define ATOMIC_CHAR32_T_LOCK_FREE 0 +#define ATOMIC_WCHAR_T_LOCK_FREE 0 +#define ATOMIC_SHORT_LOCK_FREE 0 +#define ATOMIC_INT_LOCK_FREE 0 +#define ATOMIC_LONG_LOCK_FREE 0 +#define ATOMIC_LLONG_LOCK_FREE 0 + +#endif // !__has_feature(cxx_atomic) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ATOMIC diff --git a/contrib/libc++/include/bitset b/contrib/libc++/include/bitset new file mode 100644 index 000000000000..c970f3290717 --- /dev/null +++ b/contrib/libc++/include/bitset @@ -0,0 +1,1048 @@ +// -*- C++ -*- +//===---------------------------- bitset ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_BITSET +#define _LIBCPP_BITSET + +/* + bitset synopsis + +namespace std +{ + +namespace std { + +template +class bitset +{ +public: + // bit reference: + class reference + { + friend class bitset; + reference() noexcept; + public: + ~reference() noexcept; + reference& operator=(bool x) noexcept; // for b[i] = x; + reference& operator=(const reference&) noexcept; // for b[i] = b[j]; + bool operator~() const noexcept; // flips the bit + operator bool() const noexcept; // for x = b[i]; + reference& flip() noexcept; // for b[i].flip(); + }; + + // 23.3.5.1 constructors: + constexpr bitset() noexcept; + constexpr bitset(unsigned long long val) noexcept; + template + explicit bitset(const charT* str, + typename basic_string::size_type n = basic_string::npos, + charT zero = charT('0'), charT one = charT('1')); + template + explicit bitset(const basic_string& str, + typename basic_string::size_type pos = 0, + typename basic_string::size_type n = + basic_string::npos, + charT zero = charT('0'), charT one = charT('1')); + + // 23.3.5.2 bitset operations: + bitset& operator&=(const bitset& rhs) noexcept; + bitset& operator|=(const bitset& rhs) noexcept; + bitset& operator^=(const bitset& rhs) noexcept; + bitset& operator<<=(size_t pos) noexcept; + bitset& operator>>=(size_t pos) noexcept; + bitset& set() noexcept; + bitset& set(size_t pos, bool val = true); + bitset& reset() noexcept; + bitset& reset(size_t pos); + bitset operator~() const noexcept; + bitset& flip() noexcept; + bitset& flip(size_t pos); + + // element access: + constexpr bool operator[](size_t pos) const; // for b[i]; + reference operator[](size_t pos); // for b[i]; + unsigned long to_ulong() const; + unsigned long long to_ullong() const; + template + basic_string to_string(charT zero = charT('0'), charT one = charT('1')) const; + template + basic_string > to_string(charT zero = charT('0'), charT one = charT('1')) const; + template + basic_string, allocator > to_string(charT zero = charT('0'), charT one = charT('1')) const; + basic_string, allocator > to_string(char zero = '0', char one = '1') const; + size_t count() const noexcept; + constexpr size_t size() const noexcept; + bool operator==(const bitset& rhs) const noexcept; + bool operator!=(const bitset& rhs) const noexcept; + bool test(size_t pos) const; + bool all() const noexcept; + bool any() const noexcept; + bool none() const noexcept; + bitset operator<<(size_t pos) const noexcept; + bitset operator>>(size_t pos) const noexcept; +}; + +// 23.3.5.3 bitset operators: +template +bitset operator&(const bitset&, const bitset&) noexcept; + +template +bitset operator|(const bitset&, const bitset&) noexcept; + +template +bitset operator^(const bitset&, const bitset&) noexcept; + +template +basic_istream& +operator>>(basic_istream& is, bitset& x); + +template +basic_ostream& +operator<<(basic_ostream& os, const bitset& x); + +template struct hash>; + +} // std + +*/ + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include <__config> +#include <__bit_reference> +#include +#include +#include +#include +#include +#include <__functional_base> +#if defined(_LIBCPP_NO_EXCEPTIONS) + #include +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +class __bitset; + +template +struct __has_storage_type<__bitset<_N_words, _Size> > +{ + static const bool value = true; +}; + +template +class __bitset +{ +public: + typedef ptrdiff_t difference_type; + typedef size_t size_type; +protected: + typedef __bitset __self; + typedef size_type __storage_type; + typedef __storage_type* __storage_pointer; + typedef const __storage_type* __const_storage_pointer; + static const unsigned __bits_per_word = static_cast(sizeof(__storage_type) * CHAR_BIT); + + friend class __bit_reference<__bitset>; + friend class __bit_const_reference<__bitset>; + friend class __bit_iterator<__bitset, false>; + friend class __bit_iterator<__bitset, true>; + friend class __bit_array<__bitset>; + + __storage_type __first_[_N_words]; + + typedef __bit_reference<__bitset> reference; + typedef __bit_const_reference<__bitset> const_reference; + typedef __bit_iterator<__bitset, false> iterator; + typedef __bit_iterator<__bitset, true> const_iterator; + + __bitset() _NOEXCEPT; + explicit __bitset(unsigned long long __v) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT + {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t __pos) const _NOEXCEPT + {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT + {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT + {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} + + void operator&=(const __bitset& __v) _NOEXCEPT; + void operator|=(const __bitset& __v) _NOEXCEPT; + void operator^=(const __bitset& __v) _NOEXCEPT; + + void flip() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const + {return to_ulong(integral_constant());} + _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const + {return to_ullong(integral_constant());} + + bool all() const _NOEXCEPT; + bool any() const _NOEXCEPT; + size_t __hash_code() const _NOEXCEPT; +private: + void __init(unsigned long long __v, false_type) _NOEXCEPT; + void __init(unsigned long long __v, true_type) _NOEXCEPT; + unsigned long to_ulong(false_type) const; + unsigned long to_ulong(true_type) const; + unsigned long long to_ullong(false_type) const; + unsigned long long to_ullong(true_type) const; + unsigned long long to_ullong(true_type, false_type) const; + unsigned long long to_ullong(true_type, true_type) const; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +__bitset<_N_words, _Size>::__bitset() _NOEXCEPT +{ + _VSTD::fill_n(__first_, _N_words, __storage_type(0)); +} + +template +void +__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) +{ + __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; + for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word) + __t[__i] = static_cast<__storage_type>(__v); + _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); + _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), + __storage_type(0)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) +{ + __first_[0] = __v; + _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT +{ + __init(__v, integral_constant()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT +{ + for (size_type __i = 0; __i < _N_words; ++__i) + __first_[__i] &= __v.__first_[__i]; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT +{ + for (size_type __i = 0; __i < _N_words; ++__i) + __first_[__i] |= __v.__first_[__i]; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT +{ + for (size_type __i = 0; __i < _N_words; ++__i) + __first_[__i] ^= __v.__first_[__i]; +} + +template +void +__bitset<_N_words, _Size>::flip() _NOEXCEPT +{ + // do middle whole words + size_type __n = _Size; + __storage_pointer __p = __first_; + for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) + *__p = ~*__p; + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__p & __m; + *__p &= ~__m; + *__p |= ~__b & __m; + } +} + +template +unsigned long +__bitset<_N_words, _Size>::to_ulong(false_type) const +{ + const_iterator __e = __make_iter(_Size); + const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); + if (__i != __e) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw overflow_error("bitset to_ulong overflow error"); +#else + assert(!"bitset to_ulong overflow error"); +#endif + return __first_[0]; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +unsigned long +__bitset<_N_words, _Size>::to_ulong(true_type) const +{ + return __first_[0]; +} + +template +unsigned long long +__bitset<_N_words, _Size>::to_ullong(false_type) const +{ + const_iterator __e = __make_iter(_Size); + const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); + if (__i != __e) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw overflow_error("bitset to_ullong overflow error"); +#else + assert(!"bitset to_ullong overflow error"); +#endif + return to_ullong(true_type()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +unsigned long long +__bitset<_N_words, _Size>::to_ullong(true_type) const +{ + return to_ullong(true_type(), integral_constant()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +unsigned long long +__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const +{ + return __first_[0]; +} + +template +unsigned long long +__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const +{ + unsigned long long __r = __first_[0]; + for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) + __r |= static_cast(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); + return __r; +} + +template +bool +__bitset<_N_words, _Size>::all() const _NOEXCEPT +{ + // do middle whole words + size_type __n = _Size; + __const_storage_pointer __p = __first_; + for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) + if (~*__p) + return false; + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + if (~*__p & __m) + return false; + } + return true; +} + +template +bool +__bitset<_N_words, _Size>::any() const _NOEXCEPT +{ + // do middle whole words + size_type __n = _Size; + __const_storage_pointer __p = __first_; + for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) + if (*__p) + return true; + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + if (*__p & __m) + return true; + } + return false; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +size_t +__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT +{ + size_t __h = 0; + for (size_type __i = 0; __i < _N_words; ++__i) + __h ^= __first_[__i]; + return __h; +} + +template +class __bitset<1, _Size> +{ +public: + typedef ptrdiff_t difference_type; + typedef size_t size_type; +protected: + typedef __bitset __self; + typedef size_type __storage_type; + typedef __storage_type* __storage_pointer; + typedef const __storage_type* __const_storage_pointer; + static const unsigned __bits_per_word = static_cast(sizeof(__storage_type) * CHAR_BIT); + + friend class __bit_reference<__bitset>; + friend class __bit_const_reference<__bitset>; + friend class __bit_iterator<__bitset, false>; + friend class __bit_iterator<__bitset, true>; + friend class __bit_array<__bitset>; + + __storage_type __first_; + + typedef __bit_reference<__bitset> reference; + typedef __bit_const_reference<__bitset> const_reference; + typedef __bit_iterator<__bitset, false> iterator; + typedef __bit_iterator<__bitset, true> const_iterator; + + __bitset() _NOEXCEPT; + explicit __bitset(unsigned long long __v) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT + {return reference(&__first_, __storage_type(1) << __pos);} + _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t __pos) const _NOEXCEPT + {return const_reference(&__first_, __storage_type(1) << __pos);} + _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT + {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT + {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} + + void operator&=(const __bitset& __v) _NOEXCEPT; + void operator|=(const __bitset& __v) _NOEXCEPT; + void operator^=(const __bitset& __v) _NOEXCEPT; + + void flip() _NOEXCEPT; + + unsigned long to_ulong() const; + unsigned long long to_ullong() const; + + bool all() const _NOEXCEPT; + bool any() const _NOEXCEPT; + + size_t __hash_code() const _NOEXCEPT; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +__bitset<1, _Size>::__bitset() _NOEXCEPT + : __first_(0) +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT + : __first_(static_cast<__storage_type>(__v)) +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT +{ + __first_ &= __v.__first_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT +{ + __first_ |= __v.__first_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT +{ + __first_ ^= __v.__first_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__bitset<1, _Size>::flip() _NOEXCEPT +{ + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); + __first_ = ~__first_; + __first_ &= __m; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +unsigned long +__bitset<1, _Size>::to_ulong() const +{ + return __first_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +unsigned long long +__bitset<1, _Size>::to_ullong() const +{ + return __first_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +__bitset<1, _Size>::all() const _NOEXCEPT +{ + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); + return !(~__first_ & __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +__bitset<1, _Size>::any() const _NOEXCEPT +{ + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); + return __first_ & __m; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +size_t +__bitset<1, _Size>::__hash_code() const _NOEXCEPT +{ + return __first_; +} + +template <> +class __bitset<0, 0> +{ +public: + typedef ptrdiff_t difference_type; + typedef size_t size_type; +protected: + typedef __bitset __self; + typedef size_type __storage_type; + typedef __storage_type* __storage_pointer; + typedef const __storage_type* __const_storage_pointer; + static const unsigned __bits_per_word = static_cast(sizeof(__storage_type) * CHAR_BIT); + + friend class __bit_reference<__bitset>; + friend class __bit_const_reference<__bitset>; + friend class __bit_iterator<__bitset, false>; + friend class __bit_iterator<__bitset, true>; + friend class __bit_array<__bitset>; + + typedef __bit_reference<__bitset> reference; + typedef __bit_const_reference<__bitset> const_reference; + typedef __bit_iterator<__bitset, false> iterator; + typedef __bit_iterator<__bitset, true> const_iterator; + + __bitset() _NOEXCEPT; + explicit __bitset(unsigned long long) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT + {return reference(0, 1);} + _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t) const _NOEXCEPT + {return const_reference(0, 1);} + _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT + {return iterator(0, 0);} + _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT + {return const_iterator(0, 0);} + + _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;} + _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;} + + _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;} + _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;} + + _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} +}; + +inline _LIBCPP_INLINE_VISIBILITY +__bitset<0, 0>::__bitset() _NOEXCEPT +{ +} + +inline _LIBCPP_INLINE_VISIBILITY +__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT +{ +} + +template class bitset; +template struct hash >; + +template +class _LIBCPP_VISIBLE bitset + : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> +{ + static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; + typedef __bitset<__n_words, _Size> base; + +public: + typedef typename base::reference reference; + typedef typename base::const_reference const_reference; + + // 23.3.5.1 constructors: + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY bitset() _NOEXCEPT {} + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} + template + explicit bitset(const _CharT* __str, + typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, + _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); + template + explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, + typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, + typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = + (basic_string<_CharT,_Traits,_Allocator>::npos), + _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); + + // 23.3.5.2 bitset operations: + bitset& operator&=(const bitset& __rhs) _NOEXCEPT; + bitset& operator|=(const bitset& __rhs) _NOEXCEPT; + bitset& operator^=(const bitset& __rhs) _NOEXCEPT; + bitset& operator<<=(size_t __pos) _NOEXCEPT; + bitset& operator>>=(size_t __pos) _NOEXCEPT; + bitset& set() _NOEXCEPT; + bitset& set(size_t __pos, bool __val = true); + bitset& reset() _NOEXCEPT; + bitset& reset(size_t __pos); + bitset operator~() const _NOEXCEPT; + bitset& flip() _NOEXCEPT; + bitset& flip(size_t __pos); + + // element access: + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_t __p) const {return base::__make_ref(__p);} + _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);} + unsigned long to_ulong() const; + unsigned long long to_ullong() const; + template + basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), + _CharT __one = _CharT('1')) const; + template + basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), + _CharT __one = _CharT('1')) const; + template + basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), + _CharT __one = _CharT('1')) const; + basic_string, allocator > to_string(char __zero = '0', + char __one = '1') const; + size_t count() const _NOEXCEPT; + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY size_t size() const _NOEXCEPT {return _Size;} + bool operator==(const bitset& __rhs) const _NOEXCEPT; + bool operator!=(const bitset& __rhs) const _NOEXCEPT; + bool test(size_t __pos) const; + bool all() const _NOEXCEPT; + bool any() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();} + bitset operator<<(size_t __pos) const _NOEXCEPT; + bitset operator>>(size_t __pos) const _NOEXCEPT; + +private: + + _LIBCPP_INLINE_VISIBILITY + size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} + + friend struct hash; +}; + +template +template +bitset<_Size>::bitset(const _CharT* __str, + typename basic_string<_CharT>::size_type __n, + _CharT __zero, _CharT __one) +{ + size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); + for (size_t __i = 0; __i < __rlen; ++__i) + if (__str[__i] != __zero && __str[__i] != __one) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw invalid_argument("bitset string ctor has invalid argument"); +#else + assert(!"bitset string ctor has invalid argument"); +#endif + size_t _M = _VSTD::min(__rlen, _Size); + size_t __i = 0; + for (; __i < _M; ++__i) + { + _CharT __c = __str[_M - 1 - __i]; + if (__c == __zero) + (*this)[__i] = false; + else + (*this)[__i] = true; + } + _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); +} + +template +template +bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, + typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, + typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, + _CharT __zero, _CharT __one) +{ + if (__pos > __str.size()) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range("bitset string pos out of range"); +#else + assert(!"bitset string pos out of range"); +#endif + size_t __rlen = _VSTD::min(__n, __str.size() - __pos); + for (size_t __i = __pos; __i < __pos + __rlen; ++__i) + if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw invalid_argument("bitset string ctor has invalid argument"); +#else + assert(!"bitset string ctor has invalid argument"); +#endif + size_t _M = _VSTD::min(__rlen, _Size); + size_t __i = 0; + for (; __i < _M; ++__i) + { + _CharT __c = __str[__pos + _M - 1 - __i]; + if (_Traits::eq(__c, __zero)) + (*this)[__i] = false; + else + (*this)[__i] = true; + } + _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size>& +bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT +{ + base::operator&=(__rhs); + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size>& +bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT +{ + base::operator|=(__rhs); + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size>& +bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT +{ + base::operator^=(__rhs); + return *this; +} + +template +bitset<_Size>& +bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT +{ + __pos = _VSTD::min(__pos, _Size); + _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); + _VSTD::fill_n(base::__make_iter(0), __pos, false); + return *this; +} + +template +bitset<_Size>& +bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT +{ + __pos = _VSTD::min(__pos, _Size); + _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); + _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size>& +bitset<_Size>::set() _NOEXCEPT +{ + _VSTD::fill_n(base::__make_iter(0), _Size, true); + return *this; +} + +template +bitset<_Size>& +bitset<_Size>::set(size_t __pos, bool __val) +{ + if (__pos >= _Size) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range("bitset set argument out of range"); +#else + assert(!"bitset set argument out of range"); +#endif + (*this)[__pos] = __val; + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size>& +bitset<_Size>::reset() _NOEXCEPT +{ + _VSTD::fill_n(base::__make_iter(0), _Size, false); + return *this; +} + +template +bitset<_Size>& +bitset<_Size>::reset(size_t __pos) +{ + if (__pos >= _Size) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range("bitset reset argument out of range"); +#else + assert(!"bitset reset argument out of range"); +#endif + (*this)[__pos] = false; + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size> +bitset<_Size>::operator~() const _NOEXCEPT +{ + bitset __x(*this); + __x.flip(); + return __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size>& +bitset<_Size>::flip() _NOEXCEPT +{ + base::flip(); + return *this; +} + +template +bitset<_Size>& +bitset<_Size>::flip(size_t __pos) +{ + if (__pos >= _Size) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range("bitset flip argument out of range"); +#else + assert(!"bitset flip argument out of range"); +#endif + reference r = base::__make_ref(__pos); + r = ~r; + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +unsigned long +bitset<_Size>::to_ulong() const +{ + return base::to_ulong(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +unsigned long long +bitset<_Size>::to_ullong() const +{ + return base::to_ullong(); +} + +template +template +basic_string<_CharT, _Traits, _Allocator> +bitset<_Size>::to_string(_CharT __zero, _CharT __one) const +{ + basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); + for (size_t __i = 0; __i < _Size; ++__i) + { + if ((*this)[__i]) + __r[_Size - 1 - __i] = __one; + } + return __r; +} + +template +template +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, allocator<_CharT> > +bitset<_Size>::to_string(_CharT __zero, _CharT __one) const +{ + return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); +} + +template +template +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > +bitset<_Size>::to_string(_CharT __zero, _CharT __one) const +{ + return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_string, allocator > +bitset<_Size>::to_string(char __zero, char __one) const +{ + return to_string, allocator >(__zero, __one); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +size_t +bitset<_Size>::count() const _NOEXCEPT +{ + return static_cast(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT +{ + return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT +{ + return !(*this == __rhs); +} + +template +bool +bitset<_Size>::test(size_t __pos) const +{ + if (__pos >= _Size) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range("bitset test argument out of range"); +#else + assert(!"bitset test argument out of range"); +#endif + return (*this)[__pos]; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +bitset<_Size>::all() const _NOEXCEPT +{ + return base::all(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +bitset<_Size>::any() const _NOEXCEPT +{ + return base::any(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size> +bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT +{ + bitset __r = *this; + __r <<= __pos; + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size> +bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT +{ + bitset __r = *this; + __r >>= __pos; + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size> +operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT +{ + bitset<_Size> __r = __x; + __r &= __y; + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size> +operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT +{ + bitset<_Size> __r = __x; + __r |= __y; + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bitset<_Size> +operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT +{ + bitset<_Size> __r = __x; + __r ^= __y; + return __r; +} + +template +struct _LIBCPP_VISIBLE hash > + : public unary_function, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT + {return __bs.__hash_code();} +}; + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); + +template +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_BITSET diff --git a/contrib/libc++/include/cassert b/contrib/libc++/include/cassert new file mode 100644 index 000000000000..3775990640a9 --- /dev/null +++ b/contrib/libc++/include/cassert @@ -0,0 +1,25 @@ +// -*- C++ -*- +//===-------------------------- cassert -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +/* + cassert synopsis + +Macros: + + assert + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif diff --git a/contrib/libc++/include/ccomplex b/contrib/libc++/include/ccomplex new file mode 100644 index 000000000000..6ed116445e64 --- /dev/null +++ b/contrib/libc++/include/ccomplex @@ -0,0 +1,29 @@ +// -*- C++ -*- +//===--------------------------- ccomplex ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CCOMPLEX +#define _LIBCPP_CCOMPLEX + +/* + ccomplex synopsis + +#include + +*/ + +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +// hh 080623 Created + +#endif // _LIBCPP_CCOMPLEX diff --git a/contrib/libc++/include/cctype b/contrib/libc++/include/cctype new file mode 100644 index 000000000000..e33244e7daa2 --- /dev/null +++ b/contrib/libc++/include/cctype @@ -0,0 +1,164 @@ +// -*- C++ -*- +//===---------------------------- cctype ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CCTYPE +#define _LIBCPP_CCTYPE + +/* + cctype synopsis + +namespace std +{ + +int isalnum(int c); +int isalpha(int c); +int isblank(int c); // C99 +int iscntrl(int c); +int isdigit(int c); +int isgraph(int c); +int islower(int c); +int isprint(int c); +int ispunct(int c); +int isspace(int c); +int isupper(int c); +int isxdigit(int c); +int tolower(int c); +int toupper(int c); + +} // std +*/ + +#include <__config> +#include +#if defined(_MSC_VER) +#include "support/win32/support.h" +#endif // _MSC_VER + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifdef isalnum +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isalnum(int __c) {return isalnum(__c);} +#undef isalnum +inline _LIBCPP_INLINE_VISIBILITY int isalnum(int __c) {return __libcpp_isalnum(__c);} +#else // isalnum +using ::isalnum; +#endif // isalnum + +#ifdef isalpha +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isalpha(int __c) {return isalpha(__c);} +#undef isalpha +inline _LIBCPP_INLINE_VISIBILITY int isalpha(int __c) {return __libcpp_isalpha(__c);} +#else // isalpha +using ::isalpha; +#endif // isalpha + +#ifdef isblank +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isblank(int __c) {return isblank(__c);} +#undef isblank +inline _LIBCPP_INLINE_VISIBILITY int isblank(int __c) {return __libcpp_isblank(__c);} +#else // isblank +using ::isblank; +#endif // isblank + +#ifdef iscntrl +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iscntrl(int __c) {return iscntrl(__c);} +#undef iscntrl +inline _LIBCPP_INLINE_VISIBILITY int iscntrl(int __c) {return __libcpp_iscntrl(__c);} +#else // iscntrl +using ::iscntrl; +#endif // iscntrl + +#ifdef isdigit +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isdigit(int __c) {return isdigit(__c);} +#undef isdigit +inline _LIBCPP_INLINE_VISIBILITY int isdigit(int __c) {return __libcpp_isdigit(__c);} +#else // isdigit +using ::isdigit; +#endif // isdigit + +#ifdef isgraph +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isgraph(int __c) {return isgraph(__c);} +#undef isgraph +inline _LIBCPP_INLINE_VISIBILITY int isgraph(int __c) {return __libcpp_isgraph(__c);} +#else // isgraph +using ::isgraph; +#endif // isgraph + +#ifdef islower +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_islower(int __c) {return islower(__c);} +#undef islower +inline _LIBCPP_INLINE_VISIBILITY int islower(int __c) {return __libcpp_islower(__c);} +#else // islower +using ::islower; +#endif // islower + +#ifdef isprint +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isprint(int __c) {return isprint(__c);} +#undef isprint +inline _LIBCPP_INLINE_VISIBILITY int isprint(int __c) {return __libcpp_isprint(__c);} +#else // isprint +using ::isprint; +#endif // isprint + +#ifdef ispunct +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_ispunct(int __c) {return ispunct(__c);} +#undef ispunct +inline _LIBCPP_INLINE_VISIBILITY int ispunct(int __c) {return __libcpp_ispunct(__c);} +#else // ispunct +using ::ispunct; +#endif // ispunct + +#ifdef isspace +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isspace(int __c) {return isspace(__c);} +#undef isspace +inline _LIBCPP_INLINE_VISIBILITY int isspace(int __c) {return __libcpp_isspace(__c);} +#else // isspace +using ::isspace; +#endif // isspace + +#ifdef isupper +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isupper(int __c) {return isupper(__c);} +#undef isupper +inline _LIBCPP_INLINE_VISIBILITY int isupper(int __c) {return __libcpp_isupper(__c);} +#else // isupper +using ::isupper; +#endif // isupper + +#ifdef isxdigit +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isxdigit(int __c) {return isxdigit(__c);} +#undef isxdigit +inline _LIBCPP_INLINE_VISIBILITY int isxdigit(int __c) {return __libcpp_isxdigit(__c);} +#else // isxdigit +using ::isxdigit; +#endif // isxdigit + +#ifdef tolower +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_tolower(int __c) {return tolower(__c);} +#undef tolower +inline _LIBCPP_INLINE_VISIBILITY int tolower(int __c) {return __libcpp_tolower(__c);} +#else // tolower +using ::tolower; +#endif // tolower + +#ifdef toupper +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_toupper(int __c) {return toupper(__c);} +#undef toupper +inline _LIBCPP_INLINE_VISIBILITY int toupper(int __c) {return __libcpp_toupper(__c);} +#else // toupper +using ::toupper; +#endif // toupper + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CCTYPE diff --git a/contrib/libc++/include/cerrno b/contrib/libc++/include/cerrno new file mode 100644 index 000000000000..9804e4e3dcfe --- /dev/null +++ b/contrib/libc++/include/cerrno @@ -0,0 +1,393 @@ +// -*- C++ -*- +//===-------------------------- cerrno ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CERRNO +#define _LIBCPP_CERRNO + +/* + cerrno synopsis + +Macros: + + EDOM + EILSEQ // C99 + ERANGE + errno + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE) + +#ifdef ELAST + +const int __elast1 = ELAST+1; +const int __elast2 = ELAST+2; + +#else + +const int __elast1 = 104; +const int __elast2 = 105; + +#endif + +#ifdef ENOTRECOVERABLE + +#define EOWNERDEAD __elast1 + +#ifdef ELAST +#undef ELAST +#define ELAST EOWNERDEAD +#endif + +#elif defined(EOWNERDEAD) + +#define ENOTRECOVERABLE __elast1 +#ifdef ELAST +#undef ELAST +#define ELAST ENOTRECOVERABLE +#endif + +#else // defined(EOWNERDEAD) + +#define EOWNERDEAD __elast1 +#define ENOTRECOVERABLE __elast2 +#ifdef ELAST +#undef ELAST +#define ELAST ENOTRECOVERABLE +#endif + +#endif // defined(EOWNERDEAD) + +#endif // !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE) + +// supply errno values likely to be missing, particularly on Windows + +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT 9901 +#endif + +#ifndef EADDRINUSE +#define EADDRINUSE 9902 +#endif + +#ifndef EADDRNOTAVAIL +#define EADDRNOTAVAIL 9903 +#endif + +#ifndef EISCONN +#define EISCONN 9904 +#endif + +#ifndef EBADMSG +#define EBADMSG 9905 +#endif + +#ifndef ECONNABORTED +#define ECONNABORTED 9906 +#endif + +#ifndef EALREADY +#define EALREADY 9907 +#endif + +#ifndef ECONNREFUSED +#define ECONNREFUSED 9908 +#endif + +#ifndef ECONNRESET +#define ECONNRESET 9909 +#endif + +#ifndef EDESTADDRREQ +#define EDESTADDRREQ 9910 +#endif + +#ifndef EHOSTUNREACH +#define EHOSTUNREACH 9911 +#endif + +#ifndef EIDRM +#define EIDRM 9912 +#endif + +#ifndef EMSGSIZE +#define EMSGSIZE 9913 +#endif + +#ifndef ENETDOWN +#define ENETDOWN 9914 +#endif + +#ifndef ENETRESET +#define ENETRESET 9915 +#endif + +#ifndef ENETUNREACH +#define ENETUNREACH 9916 +#endif + +#ifndef ENOBUFS +#define ENOBUFS 9917 +#endif + +#ifndef ENOLINK +#define ENOLINK 9918 +#endif + +#ifndef ENODATA +#define ENODATA 9919 +#endif + +#ifndef ENOMSG +#define ENOMSG 9920 +#endif + +#ifndef ENOPROTOOPT +#define ENOPROTOOPT 9921 +#endif + +#ifndef ENOSR +#define ENOSR 9922 +#endif + +#ifndef ENOTSOCK +#define ENOTSOCK 9923 +#endif + +#ifndef ENOSTR +#define ENOSTR 9924 +#endif + +#ifndef ENOTCONN +#define ENOTCONN 9925 +#endif + +#ifndef ENOTSUP +#define ENOTSUP 9926 +#endif + +#ifndef ECANCELED +#define ECANCELED 9927 +#endif + +#ifndef EINPROGRESS +#define EINPROGRESS 9928 +#endif + +#ifndef EOPNOTSUPP +#define EOPNOTSUPP 9929 +#endif + +#ifndef EWOULDBLOCK +#define EWOULDBLOCK 9930 +#endif + +#ifndef EOWNERDEAD +#define EOWNERDEAD 9931 +#endif + +#ifndef EPROTO +#define EPROTO 9932 +#endif + +#ifndef EPROTONOSUPPORT +#define EPROTONOSUPPORT 9933 +#endif + +#ifndef ENOTRECOVERABLE +#define ENOTRECOVERABLE 9934 +#endif + +#ifndef ETIME +#define ETIME 9935 +#endif + +#ifndef ETXTBSY +#define ETXTBSY 9936 +#endif + +#ifndef ETIMEDOUT +#define ETIMEDOUT 9938 +#endif + +#ifndef ELOOP +#define ELOOP 9939 +#endif + +#ifndef EOVERFLOW +#define EOVERFLOW 9940 +#endif + +#ifndef EPROTOTYPE +#define EPROTOTYPE 9941 +#endif + +#ifndef ENOSYS +#define ENOSYS 9942 +#endif + +#ifndef EINVAL +#define EINVAL 9943 +#endif + +#ifndef ERANGE +#define ERANGE 9944 +#endif + +#ifndef EILSEQ +#define EILSEQ 9945 +#endif + +// Windows Mobile doesn't appear to define these: + +#ifndef E2BIG +#define E2BIG 9946 +#endif + +#ifndef EDOM +#define EDOM 9947 +#endif + +#ifndef EFAULT +#define EFAULT 9948 +#endif + +#ifndef EBADF +#define EBADF 9949 +#endif + +#ifndef EPIPE +#define EPIPE 9950 +#endif + +#ifndef EXDEV +#define EXDEV 9951 +#endif + +#ifndef EBUSY +#define EBUSY 9952 +#endif + +#ifndef ENOTEMPTY +#define ENOTEMPTY 9953 +#endif + +#ifndef ENOEXEC +#define ENOEXEC 9954 +#endif + +#ifndef EEXIST +#define EEXIST 9955 +#endif + +#ifndef EFBIG +#define EFBIG 9956 +#endif + +#ifndef ENAMETOOLONG +#define ENAMETOOLONG 9957 +#endif + +#ifndef ENOTTY +#define ENOTTY 9958 +#endif + +#ifndef EINTR +#define EINTR 9959 +#endif + +#ifndef ESPIPE +#define ESPIPE 9960 +#endif + +#ifndef EIO +#define EIO 9961 +#endif + +#ifndef EISDIR +#define EISDIR 9962 +#endif + +#ifndef ECHILD +#define ECHILD 9963 +#endif + +#ifndef ENOLCK +#define ENOLCK 9964 +#endif + +#ifndef ENOSPC +#define ENOSPC 9965 +#endif + +#ifndef ENXIO +#define ENXIO 9966 +#endif + +#ifndef ENODEV +#define ENODEV 9967 +#endif + +#ifndef ENOENT +#define ENOENT 9968 +#endif + +#ifndef ESRCH +#define ESRCH 9969 +#endif + +#ifndef ENOTDIR +#define ENOTDIR 9970 +#endif + +#ifndef ENOMEM +#define ENOMEM 9971 +#endif + +#ifndef EPERM +#define EPERM 9972 +#endif + +#ifndef EACCES +#define EACCES 9973 +#endif + +#ifndef EROFS +#define EROFS 9974 +#endif + +#ifndef EDEADLK +#define EDEADLK 9975 +#endif + +#ifndef EAGAIN +#define EAGAIN 9976 +#endif + +#ifndef ENFILE +#define ENFILE 9977 +#endif + +#ifndef EMFILE +#define EMFILE 9978 +#endif + +#ifndef EMLINK +#define EMLINK 9979 +#endif + +#endif // _LIBCPP_CERRNO diff --git a/contrib/libc++/include/cfenv b/contrib/libc++/include/cfenv new file mode 100644 index 000000000000..dd7db37f8e48 --- /dev/null +++ b/contrib/libc++/include/cfenv @@ -0,0 +1,82 @@ +// -*- C++ -*- +//===---------------------------- cctype ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CFENV +#define _LIBCPP_CFENV + +/* + cfenv synopsis + +This entire header is C99 / C++0X + +Macros: + + FE_DIVBYZERO + FE_INEXACT + FE_INVALID + FE_OVERFLOW + FE_UNDERFLOW + FE_ALL_EXCEPT + FE_DOWNWARD + FE_TONEAREST + FE_TOWARDZERO + FE_UPWARD + FE_DFL_ENV + +namespace std +{ + +Types: + + fenv_t + fexcept_t + +int feclearexcept(int excepts); +int fegetexceptflag(fexcept_t* flagp, int excepts); +int feraiseexcept(int excepts); +int fesetexceptflag(const fexcept_t* flagp, int excepts); +int fetestexcept(int excepts); +int fegetround(); +int fesetround(int round); +int fegetenv(fenv_t* envp); +int feholdexcept(fenv_t* envp); +int fesetenv(const fenv_t* envp); +int feupdateenv(const fenv_t* envp); + +} // std +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::fenv_t; +using ::fexcept_t; + +using ::feclearexcept; +using ::fegetexceptflag; +using ::feraiseexcept; +using ::fesetexceptflag; +using ::fetestexcept; +using ::fegetround; +using ::fesetround; +using ::fegetenv; +using ::feholdexcept; +using ::fesetenv; +using ::feupdateenv; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CFENV diff --git a/contrib/libc++/include/cfloat b/contrib/libc++/include/cfloat new file mode 100644 index 000000000000..5fa56550fa6a --- /dev/null +++ b/contrib/libc++/include/cfloat @@ -0,0 +1,78 @@ +// -*- C++ -*- +//===--------------------------- cfloat -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CFLOAT +#define _LIBCPP_CFLOAT + +/* + cfloat synopsis + +Macros: + + FLT_ROUNDS + FLT_EVAL_METHOD // C99 + FLT_RADIX + + FLT_MANT_DIG + DBL_MANT_DIG + LDBL_MANT_DIG + + DECIMAL_DIG // C99 + + FLT_DIG + DBL_DIG + LDBL_DIG + + FLT_MIN_EXP + DBL_MIN_EXP + LDBL_MIN_EXP + + FLT_MIN_10_EXP + DBL_MIN_10_EXP + LDBL_MIN_10_EXP + + FLT_MAX_EXP + DBL_MAX_EXP + LDBL_MAX_EXP + + FLT_MAX_10_EXP + DBL_MAX_10_EXP + LDBL_MAX_10_EXP + + FLT_MAX + DBL_MAX + LDBL_MAX + + FLT_EPSILON + DBL_EPSILON + LDBL_EPSILON + + FLT_MIN + DBL_MIN + LDBL_MIN + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifndef FLT_EVAL_METHOD +#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ +#endif + +#ifndef DECIMAL_DIG +#define DECIMAL_DIG __DECIMAL_DIG__ +#endif + +#endif // _LIBCPP_CFLOAT diff --git a/contrib/libc++/include/chrono b/contrib/libc++/include/chrono new file mode 100644 index 000000000000..1c79f4bbe809 --- /dev/null +++ b/contrib/libc++/include/chrono @@ -0,0 +1,873 @@ +// -*- C++ -*- +//===---------------------------- chrono ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CHRONO +#define _LIBCPP_CHRONO + +/* + chrono synopsis + +namespace std +{ +namespace chrono +{ + +template +ToDuration +duration_cast(const duration& fd); + +template struct treat_as_floating_point : is_floating_point {}; + +template +struct duration_values +{ +public: + static Rep zero(); + static Rep max(); + static Rep min(); +}; + +// duration + +template > +class duration +{ + static_assert(!__is_duration::value, "A duration representation can not be a duration"); + static_assert(__is_ratio::value, "Second template parameter of duration must be a std::ratio"); + static_assert(Period::num > 0, "duration period must be positive"); +public: + typedef Rep rep; + typedef Period period; + + duration() = default; + template + explicit duration(const Rep2& r, + typename enable_if + < + is_convertible::value && + (treat_as_floating_point::value || + !treat_as_floating_point::value && !treat_as_floating_point::value) + >::type* = 0); + + // conversions + template + duration(const duration& d, + typename enable_if + < + treat_as_floating_point::value || + ratio_divide::type::den == 1 + >::type* = 0); + + // observer + + rep count() const; + + // arithmetic + + duration operator+() const; + duration operator-() const; + duration& operator++(); + duration operator++(int); + duration& operator--(); + duration operator--(int); + + duration& operator+=(const duration& d); + duration& operator-=(const duration& d); + + duration& operator*=(const rep& rhs); + duration& operator/=(const rep& rhs); + + // special values + + static duration zero(); + static duration min(); + static duration max(); +}; + +typedef duration nanoseconds; +typedef duration microseconds; +typedef duration milliseconds; +typedef duration seconds; +typedef duration< long, ratio< 60> > minutes; +typedef duration< long, ratio<3600> > hours; + +template +class time_point +{ +public: + typedef Clock clock; + typedef Duration duration; + typedef typename duration::rep rep; + typedef typename duration::period period; +private: + duration d_; // exposition only + +public: + time_point(); // has value "epoch" + explicit time_point(const duration& d); // same as time_point() + d + + // conversions + template + time_point(const time_point& t); + + // observer + + duration time_since_epoch() const; + + // arithmetic + + time_point& operator+=(const duration& d); + time_point& operator-=(const duration& d); + + // special values + + static constexpr time_point min(); + static constexpr time_point max(); +}; + +} // chrono + +// common_type traits +template + struct common_type, chrono::duration>; + +template + struct common_type, chrono::time_point>; + +namespace chrono { + +// duration arithmetic +template + typename common_type, duration>::type + operator+(const duration& lhs, const duration& rhs); +template + typename common_type, duration>::type + operator-(const duration& lhs, const duration& rhs); +template + duration::type, Period> + operator*(const duration& d, const Rep2& s); +template + duration::type, Period> + operator*(const Rep1& s, const duration& d); +template + duration::type, Period> + operator/(const duration& d, const Rep2& s); +template + typename common_type::type + operator/(const duration& lhs, const duration& rhs); + +// duration comparisons +template + bool operator==(const duration& lhs, const duration& rhs); +template + bool operator!=(const duration& lhs, const duration& rhs); +template + bool operator< (const duration& lhs, const duration& rhs); +template + bool operator<=(const duration& lhs, const duration& rhs); +template + bool operator> (const duration& lhs, const duration& rhs); +template + bool operator>=(const duration& lhs, const duration& rhs); + +// duration_cast +template + ToDuration duration_cast(const duration& d); + +// time_point arithmetic +template + time_point>::type> + operator+(const time_point& lhs, const duration& rhs); +template + time_point, Duration2>::type> + operator+(const duration& lhs, const time_point& rhs); +template + time_point>::type> + operator-(const time_point& lhs, const duration& rhs); +template + typename common_type::type + operator-(const time_point& lhs, const time_point& rhs); + +// time_point comparisons +template + bool operator==(const time_point& lhs, const time_point& rhs); +template + bool operator!=(const time_point& lhs, const time_point& rhs); +template + bool operator< (const time_point& lhs, const time_point& rhs); +template + bool operator<=(const time_point& lhs, const time_point& rhs); +template + bool operator> (const time_point& lhs, const time_point& rhs); +template + bool operator>=(const time_point& lhs, const time_point& rhs); + +// time_point_cast + +template + time_point time_point_cast(const time_point& t); + +// Clocks + +class system_clock +{ +public: + typedef microseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point time_point; + static const bool is_steady = false; + + static time_point now() noexcept; + static time_t to_time_t (const time_point& __t) noexcept; + static time_point from_time_t(time_t __t) noexcept; +}; + +class steady_clock +{ +public: + typedef nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point time_point; + static const bool is_steady = true; + + static time_point now() noexcept; +}; + +typedef steady_clock high_resolution_clock; + +} // chrono + +} // std +*/ + +#include <__config> +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace chrono +{ + +template > class _LIBCPP_VISIBLE duration; + +template +struct __is_duration : false_type {}; + +template +struct __is_duration > : true_type {}; + +template +struct __is_duration > : true_type {}; + +template +struct __is_duration > : true_type {}; + +template +struct __is_duration > : true_type {}; + +} // chrono + +template +struct _LIBCPP_VISIBLE common_type, + chrono::duration<_Rep2, _Period2> > +{ + typedef chrono::duration::type, + typename __ratio_gcd<_Period1, _Period2>::type> type; +}; + +namespace chrono { + +// duration_cast + +template ::type, + bool = _Period::num == 1, + bool = _Period::den == 1> +struct __duration_cast; + +template +struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> +{ + _LIBCPP_INLINE_VISIBILITY + _ToDuration operator()(const _FromDuration& __fd) const + { + return _ToDuration(static_cast(__fd.count())); + } +}; + +template +struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> +{ + _LIBCPP_INLINE_VISIBILITY + _ToDuration operator()(const _FromDuration& __fd) const + { + typedef typename common_type::type _Ct; + return _ToDuration(static_cast( + static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); + } +}; + +template +struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> +{ + _LIBCPP_INLINE_VISIBILITY + _ToDuration operator()(const _FromDuration& __fd) const + { + typedef typename common_type::type _Ct; + return _ToDuration(static_cast( + static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); + } +}; + +template +struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> +{ + _LIBCPP_INLINE_VISIBILITY + _ToDuration operator()(const _FromDuration& __fd) const + { + typedef typename common_type::type _Ct; + return _ToDuration(static_cast( + static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) + / static_cast<_Ct>(_Period::den))); + } +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +duration_cast(const duration<_Rep, _Period>& __fd) +{ + return __duration_cast, _ToDuration>()(__fd); +} + +template +struct _LIBCPP_VISIBLE treat_as_floating_point : is_floating_point<_Rep> {}; + +template +struct _LIBCPP_VISIBLE duration_values +{ +public: + _LIBCPP_INLINE_VISIBILITY static _Rep zero() {return _Rep(0);} + _LIBCPP_INLINE_VISIBILITY static _Rep max() {return numeric_limits<_Rep>::max();} + _LIBCPP_INLINE_VISIBILITY static _Rep min() {return numeric_limits<_Rep>::lowest();} +}; + +// duration + +template +class _LIBCPP_VISIBLE duration +{ + static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); + static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); + static_assert(_Period::num > 0, "duration period must be positive"); +public: + typedef _Rep rep; + typedef _Period period; +private: + rep __rep_; +public: + + _LIBCPP_INLINE_VISIBILITY duration() {} // = default; + template + _LIBCPP_INLINE_VISIBILITY + explicit duration(const _Rep2& __r, + typename enable_if + < + is_convertible<_Rep2, rep>::value && + (treat_as_floating_point::value || + !treat_as_floating_point<_Rep2>::value) + >::type* = 0) + : __rep_(__r) {} + + // conversions + template + _LIBCPP_INLINE_VISIBILITY + duration(const duration<_Rep2, _Period2>& __d, + typename enable_if + < + treat_as_floating_point::value || + (ratio_divide<_Period2, period>::type::den == 1 && + !treat_as_floating_point<_Rep2>::value) + >::type* = 0) + : __rep_(_VSTD::chrono::duration_cast(__d).count()) {} + + // observer + + _LIBCPP_INLINE_VISIBILITY rep count() const {return __rep_;} + + // arithmetic + + _LIBCPP_INLINE_VISIBILITY duration operator+() const {return *this;} + _LIBCPP_INLINE_VISIBILITY duration operator-() const {return duration(-__rep_);} + _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;} + _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);} + _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;} + _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);} + + _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} + _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} + + _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} + + // special values + + _LIBCPP_INLINE_VISIBILITY static duration zero() {return duration(duration_values::zero());} + _LIBCPP_INLINE_VISIBILITY static duration min() {return duration(duration_values::min());} + _LIBCPP_INLINE_VISIBILITY static duration max() {return duration(duration_values::max());} +}; + +typedef duration nanoseconds; +typedef duration microseconds; +typedef duration milliseconds; +typedef duration seconds; +typedef duration< long, ratio< 60> > minutes; +typedef duration< long, ratio<3600> > hours; + +// Duration == + +template +struct __duration_eq +{ + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) + { + typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; + return _Ct(__lhs).count() == _Ct(__rhs).count(); + } +}; + +template +struct __duration_eq<_LhsDuration, _LhsDuration> +{ + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) + {return __lhs.count() == __rhs.count();} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return __duration_eq, duration<_Rep2, _Period2> >()(__lhs, __rhs); +} + +// Duration != + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return !(__lhs == __rhs); +} + +// Duration < + +template +struct __duration_lt +{ + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) + { + typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; + return _Ct(__lhs).count() < _Ct(__rhs).count(); + } +}; + +template +struct __duration_lt<_LhsDuration, _LhsDuration> +{ + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) + {return __lhs.count() < __rhs.count();} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return __duration_lt, duration<_Rep2, _Period2> >()(__lhs, __rhs); +} + +// Duration > + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return __rhs < __lhs; +} + +// Duration <= + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return !(__rhs < __lhs); +} + +// Duration >= + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return !(__lhs < __rhs); +} + +// Duration + + +template +inline _LIBCPP_INLINE_VISIBILITY +typename common_type, duration<_Rep2, _Period2> >::type +operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typename common_type, duration<_Rep2, _Period2> >::type __r = __lhs; + __r += __rhs; + return __r; +} + +// Duration - + +template +inline _LIBCPP_INLINE_VISIBILITY +typename common_type, duration<_Rep2, _Period2> >::type +operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typename common_type, duration<_Rep2, _Period2> >::type __r = __lhs; + __r -= __rhs; + return __r; +} + +// Duration * + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, + duration::type, _Period> +>::type +operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) +{ + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + duration<_Cr, _Period> __r = __d; + __r *= static_cast<_Cr>(__s); + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, + duration::type, _Period> +>::type +operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) +{ + return __d * __s; +} + +// Duration / + +template ::value> +struct __duration_divide_result +{ +}; + +template ::type>::value> +struct __duration_divide_imp +{ +}; + +template +struct __duration_divide_imp, _Rep2, true> +{ + typedef duration::type, _Period> type; +}; + +template +struct __duration_divide_result, _Rep2, false> + : __duration_divide_imp, _Rep2> +{ +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __duration_divide_result, _Rep2>::type +operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) +{ + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + duration<_Cr, _Period> __r = __d; + __r /= static_cast<_Cr>(__s); + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename common_type<_Rep1, _Rep2>::type +operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typedef typename common_type, duration<_Rep2, _Period2> >::type _Ct; + return _Ct(__lhs).count() / _Ct(__rhs).count(); +} + +// Duration % + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __duration_divide_result, _Rep2>::type +operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) +{ + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + duration<_Cr, _Period> __r = __d; + __r %= static_cast<_Cr>(__s); + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename common_type, duration<_Rep2, _Period2> >::type +operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typename common_type, duration<_Rep2, _Period2> >::type __r = __lhs; + __r %= __rhs; + return __r; +} + +////////////////////////////////////////////////////////// +///////////////////// time_point ///////////////////////// +////////////////////////////////////////////////////////// + +template +class _LIBCPP_VISIBLE time_point +{ + static_assert(__is_duration<_Duration>::value, + "Second template parameter of time_point must be a std::chrono::duration"); +public: + typedef _Clock clock; + typedef _Duration duration; + typedef typename duration::rep rep; + typedef typename duration::period period; +private: + duration __d_; + +public: + _LIBCPP_INLINE_VISIBILITY time_point() : __d_(duration::zero()) {} + _LIBCPP_INLINE_VISIBILITY explicit time_point(const duration& __d) : __d_(__d) {} + + // conversions + template + _LIBCPP_INLINE_VISIBILITY + time_point(const time_point& t, + typename enable_if + < + is_convertible<_Duration2, duration>::value + >::type* = 0) + : __d_(t.time_since_epoch()) {} + + // observer + + _LIBCPP_INLINE_VISIBILITY duration time_since_epoch() const {return __d_;} + + // arithmetic + + _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d;} + _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d;} + + // special values + + _LIBCPP_INLINE_VISIBILITY static time_point min() {return time_point(duration::min());} + _LIBCPP_INLINE_VISIBILITY static time_point max() {return time_point(duration::max());} +}; + +} // chrono + +template +struct _LIBCPP_VISIBLE common_type, + chrono::time_point<_Clock, _Duration2> > +{ + typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; +}; + +namespace chrono { + +template +inline _LIBCPP_INLINE_VISIBILITY +time_point<_Clock, _ToDuration> +time_point_cast(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); +} + +// time_point == + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return __lhs.time_since_epoch() == __rhs.time_since_epoch(); +} + +// time_point != + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return !(__lhs == __rhs); +} + +// time_point < + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return __lhs.time_since_epoch() < __rhs.time_since_epoch(); +} + +// time_point > + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return __rhs < __lhs; +} + +// time_point <= + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return !(__rhs < __lhs); +} + +// time_point >= + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return !(__lhs < __rhs); +} + +// time_point operator+(time_point x, duration y); + +template +inline _LIBCPP_INLINE_VISIBILITY +time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> +operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; + _Tr __r(__lhs.time_since_epoch()); + __r += __rhs; + return __r; +} + +// time_point operator+(duration x, time_point y); + +template +inline _LIBCPP_INLINE_VISIBILITY +time_point<_Clock, typename common_type, _Duration2>::type> +operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return __rhs + __lhs; +} + +// time_point operator-(time_point x, duration y); + +template +inline _LIBCPP_INLINE_VISIBILITY +time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> +operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +{ + return __lhs + (-__rhs); +} + +// duration operator-(time_point x, time_point y); + +template +inline _LIBCPP_INLINE_VISIBILITY +typename common_type<_Duration1, _Duration2>::type +operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) +{ + return __lhs.time_since_epoch() - __rhs.time_since_epoch(); +} + +////////////////////////////////////////////////////////// +/////////////////////// clocks /////////////////////////// +////////////////////////////////////////////////////////// + +class _LIBCPP_VISIBLE system_clock +{ +public: + typedef microseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point time_point; + static const bool is_steady = false; + + static time_point now() _NOEXCEPT; + static time_t to_time_t (const time_point& __t) _NOEXCEPT; + static time_point from_time_t(time_t __t) _NOEXCEPT; +}; + +class _LIBCPP_VISIBLE steady_clock +{ +public: + typedef nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point time_point; + static const bool is_steady = true; + + static time_point now() _NOEXCEPT; +}; + +typedef steady_clock high_resolution_clock; + +} // chrono + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CHRONO diff --git a/contrib/libc++/include/cinttypes b/contrib/libc++/include/cinttypes new file mode 100644 index 000000000000..786692b8fec3 --- /dev/null +++ b/contrib/libc++/include/cinttypes @@ -0,0 +1,259 @@ +// -*- C++ -*- +//===--------------------------- cinttypes --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CINTTYPES +#define _LIBCPP_CINTTYPES + +/* + cinttypes synopsis + +This entire header is C99 / C++0X + +#include // includes + +Macros: + + PRId8 + PRId16 + PRId32 + PRId64 + + PRIdLEAST8 + PRIdLEAST16 + PRIdLEAST32 + PRIdLEAST64 + + PRIdFAST8 + PRIdFAST16 + PRIdFAST32 + PRIdFAST64 + + PRIdMAX + PRIdPTR + + PRIi8 + PRIi16 + PRIi32 + PRIi64 + + PRIiLEAST8 + PRIiLEAST16 + PRIiLEAST32 + PRIiLEAST64 + + PRIiFAST8 + PRIiFAST16 + PRIiFAST32 + PRIiFAST64 + + PRIiMAX + PRIiPTR + + PRIo8 + PRIo16 + PRIo32 + PRIo64 + + PRIoLEAST8 + PRIoLEAST16 + PRIoLEAST32 + PRIoLEAST64 + + PRIoFAST8 + PRIoFAST16 + PRIoFAST32 + PRIoFAST64 + + PRIoMAX + PRIoPTR + + PRIu8 + PRIu16 + PRIu32 + PRIu64 + + PRIuLEAST8 + PRIuLEAST16 + PRIuLEAST32 + PRIuLEAST64 + + PRIuFAST8 + PRIuFAST16 + PRIuFAST32 + PRIuFAST64 + + PRIuMAX + PRIuPTR + + PRIx8 + PRIx16 + PRIx32 + PRIx64 + + PRIxLEAST8 + PRIxLEAST16 + PRIxLEAST32 + PRIxLEAST64 + + PRIxFAST8 + PRIxFAST16 + PRIxFAST32 + PRIxFAST64 + + PRIxMAX + PRIxPTR + + PRIX8 + PRIX16 + PRIX32 + PRIX64 + + PRIXLEAST8 + PRIXLEAST16 + PRIXLEAST32 + PRIXLEAST64 + + PRIXFAST8 + PRIXFAST16 + PRIXFAST32 + PRIXFAST64 + + PRIXMAX + PRIXPTR + + SCNd8 + SCNd16 + SCNd32 + SCNd64 + + SCNdLEAST8 + SCNdLEAST16 + SCNdLEAST32 + SCNdLEAST64 + + SCNdFAST8 + SCNdFAST16 + SCNdFAST32 + SCNdFAST64 + + SCNdMAX + SCNdPTR + + SCNi8 + SCNi16 + SCNi32 + SCNi64 + + SCNiLEAST8 + SCNiLEAST16 + SCNiLEAST32 + SCNiLEAST64 + + SCNiFAST8 + SCNiFAST16 + SCNiFAST32 + SCNiFAST64 + + SCNiMAX + SCNiPTR + + SCNo8 + SCNo16 + SCNo32 + SCNo64 + + SCNoLEAST8 + SCNoLEAST16 + SCNoLEAST32 + SCNoLEAST64 + + SCNoFAST8 + SCNoFAST16 + SCNoFAST32 + SCNoFAST64 + + SCNoMAX + SCNoPTR + + SCNu8 + SCNu16 + SCNu32 + SCNu64 + + SCNuLEAST8 + SCNuLEAST16 + SCNuLEAST32 + SCNuLEAST64 + + SCNuFAST8 + SCNuFAST16 + SCNuFAST32 + SCNuFAST64 + + SCNuMAX + SCNuPTR + + SCNx8 + SCNx16 + SCNx32 + SCNx64 + + SCNxLEAST8 + SCNxLEAST16 + SCNxLEAST32 + SCNxLEAST64 + + SCNxFAST8 + SCNxFAST16 + SCNxFAST32 + SCNxFAST64 + + SCNxMAX + SCNxPTR + +namespace std +{ + +Types: + + imaxdiv_t + +intmax_t imaxabs(intmax_t j); +imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom); +intmax_t strtoimax(const char* restrict nptr, char** restrict endptr, int base); +uintmax_t strtoumax(const char* restrict nptr, char** restrict endptr, int base); +intmax_t wcstoimax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); +uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); + +} // std +*/ + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using::imaxdiv_t; + +using::imaxabs; +using::imaxdiv; +using::strtoimax; +using::strtoumax; +using::wcstoimax; +using::wcstoumax; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CINTTYPES diff --git a/contrib/libc++/include/ciso646 b/contrib/libc++/include/ciso646 new file mode 100644 index 000000000000..b2efc72a9aa1 --- /dev/null +++ b/contrib/libc++/include/ciso646 @@ -0,0 +1,25 @@ +// -*- C++ -*- +//===--------------------------- ciso646 ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CISO646 +#define _LIBCPP_CISO646 + +/* + ciso646 synopsis + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#endif // _LIBCPP_CISO646 diff --git a/contrib/libc++/include/climits b/contrib/libc++/include/climits new file mode 100644 index 000000000000..81ffecdf6eef --- /dev/null +++ b/contrib/libc++/include/climits @@ -0,0 +1,48 @@ +// -*- C++ -*- +//===--------------------------- climits ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CLIMITS +#define _LIBCPP_CLIMITS + +/* + climits synopsis + +Macros: + + CHAR_BIT + SCHAR_MIN + SCHAR_MAX + UCHAR_MAX + CHAR_MIN + CHAR_MAX + MB_LEN_MAX + SHRT_MIN + SHRT_MAX + USHRT_MAX + INT_MIN + INT_MAX + UINT_MAX + LONG_MIN + LONG_MAX + ULONG_MAX + LLONG_MIN // C99 + LLONG_MAX // C99 + ULLONG_MAX // C99 + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#endif // _LIBCPP_CLIMITS diff --git a/contrib/libc++/include/clocale b/contrib/libc++/include/clocale new file mode 100644 index 000000000000..f8b8f0dd34b6 --- /dev/null +++ b/contrib/libc++/include/clocale @@ -0,0 +1,53 @@ +// -*- C++ -*- +//===--------------------------- clocale ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CLOCALE +#define _LIBCPP_CLOCALE + +/* + clocale synopsis + +Macros: + + LC_ALL + LC_COLLATE + LC_CTYPE + LC_MONETARY + LC_NUMERIC + LC_TIME + NULL + +namespace std +{ + +struct lconv; +char* setlocale(int category, const char* locale); +lconv* localeconv(); + +} // std + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::lconv; +using ::setlocale; +using ::localeconv; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CLOCALE diff --git a/contrib/libc++/include/cmath b/contrib/libc++/include/cmath new file mode 100644 index 000000000000..ab67112ef172 --- /dev/null +++ b/contrib/libc++/include/cmath @@ -0,0 +1,1640 @@ +// -*- C++ -*- +//===---------------------------- cmath -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CMATH +#define _LIBCPP_CMATH + +/* + cmath synopsis + +Macros: + + HUGE_VAL + HUGE_VALF // C99 + HUGE_VALL // C99 + INFINITY // C99 + NAN // C99 + FP_INFINITE // C99 + FP_NAN // C99 + FP_NORMAL // C99 + FP_SUBNORMAL // C99 + FP_ZERO // C99 + FP_FAST_FMA // C99 + FP_FAST_FMAF // C99 + FP_FAST_FMAL // C99 + FP_ILOGB0 // C99 + FP_ILOGBNAN // C99 + MATH_ERRNO // C99 + MATH_ERREXCEPT // C99 + math_errhandling // C99 + +namespace std +{ + +Types: + + float_t // C99 + double_t // C99 + +// C90 + +floating_point abs(floating_point x); + +floating_point acos (arithmetic x); +float acosf(float x); +long double acosl(long double x); + +floating_point asin (arithmetic x); +float asinf(float x); +long double asinl(long double x); + +floating_point atan (arithmetic x); +float atanf(float x); +long double atanl(long double x); + +floating_point atan2 (arithmetic y, arithmetic x); +float atan2f(float y, float x); +long double atan2l(long double y, long double x); + +floating_point ceil (arithmetic x); +float ceilf(float x); +long double ceill(long double x); + +floating_point cos (arithmetic x); +float cosf(float x); +long double cosl(long double x); + +floating_point cosh (arithmetic x); +float coshf(float x); +long double coshl(long double x); + +floating_point exp (arithmetic x); +float expf(float x); +long double expl(long double x); + +floating_point fabs (arithmetic x); +float fabsf(float x); +long double fabsl(long double x); + +floating_point floor (arithmetic x); +float floorf(float x); +long double floorl(long double x); + +floating_point fmod (arithmetic x, arithmetic y); +float fmodf(float x, float y); +long double fmodl(long double x, long double y); + +floating_point frexp (arithmetic value, int* exp); +float frexpf(float value, int* exp); +long double frexpl(long double value, int* exp); + +floating_point ldexp (arithmetic value, int exp); +float ldexpf(float value, int exp); +long double ldexpl(long double value, int exp); + +floating_point log (arithmetic x); +float logf(float x); +long double logl(long double x); + +floating_point log10 (arithmetic x); +float log10f(float x); +long double log10l(long double x); + +floating_point modf (floating_point value, floating_point* iptr); +float modff(float value, float* iptr); +long double modfl(long double value, long double* iptr); + +floating_point pow (arithmetic x, arithmetic y); +float powf(float x, float y); +long double powl(long double x, long double y); + +floating_point sin (arithmetic x); +float sinf(float x); +long double sinl(long double x); + +floating_point sinh (arithmetic x); +float sinhf(float x); +long double sinhl(long double x); + +floating_point sqrt (arithmetic x); +float sqrtf(float x); +long double sqrtl(long double x); + +floating_point tan (arithmetic x); +float tanf(float x); +long double tanl(long double x); + +floating_point tanh (arithmetic x); +float tanhf(float x); +long double tanhl(long double x); + +// C99 + +bool signbit(floating_point x); + +int fpclassify(floating_point x); + +bool isfinite(floating_point x); +bool isinf(floating_point x); +bool isnan(floating_point x); +bool isnormal(floating_point x); + +bool isgreater(floating_point x, floating_point y); +bool isgreaterequal(floating_point x, floating_point y); +bool isless(floating_point x, floating_point y); +bool islessequal(floating_point x, floating_point y); +bool islessgreater(floating_point x, floating_point y); +bool isunordered(floating_point x, floating_point y); + +floating_point acosh (arithmetic x); +float acoshf(float x); +long double acoshl(long double x); + +floating_point asinh (arithmetic x); +float asinhf(float x); +long double asinhl(long double x); + +floating_point atanh (arithmetic x); +float atanhf(float x); +long double atanhl(long double x); + +floating_point cbrt (arithmetic x); +float cbrtf(float x); +long double cbrtl(long double x); + +floating_point copysign (arithmetic x, arithmetic y); +float copysignf(float x, float y); +long double copysignl(long double x, long double y); + +floating_point erf (arithmetic x); +float erff(float x); +long double erfl(long double x); + +floating_point erfc (arithmetic x); +float erfcf(float x); +long double erfcl(long double x); + +floating_point exp2 (arithmetic x); +float exp2f(float x); +long double exp2l(long double x); + +floating_point expm1 (arithmetic x); +float expm1f(float x); +long double expm1l(long double x); + +floating_point fdim (arithmetic x, arithmetic y); +float fdimf(float x, float y); +long double fdiml(long double x, long double y); + +floating_point fma (arithmetic x, arithmetic y, arithmetic z); +float fmaf(float x, float y, float z); +long double fmal(long double x, long double y, long double z); + +floating_point fmax (arithmetic x, arithmetic y); +float fmaxf(float x, float y); +long double fmaxl(long double x, long double y); + +floating_point fmin (arithmetic x, arithmetic y); +float fminf(float x, float y); +long double fminl(long double x, long double y); + +floating_point hypot (arithmetic x, arithmetic y); +float hypotf(float x, float y); +long double hypotl(long double x, long double y); + +int ilogb (arithmetic x); +int ilogbf(float x); +int ilogbl(long double x); + +floating_point lgamma (arithmetic x); +float lgammaf(float x); +long double lgammal(long double x); + +long long llrint (arithmetic x); +long long llrintf(float x); +long long llrintl(long double x); + +long long llround (arithmetic x); +long long llroundf(float x); +long long llroundl(long double x); + +floating_point log1p (arithmetic x); +float log1pf(float x); +long double log1pl(long double x); + +floating_point log2 (arithmetic x); +float log2f(float x); +long double log2l(long double x); + +floating_point logb (arithmetic x); +float logbf(float x); +long double logbl(long double x); + +long lrint (arithmetic x); +long lrintf(float x); +long lrintl(long double x); + +long lround (arithmetic x); +long lroundf(float x); +long lroundl(long double x); + +double nan (const char* str); +float nanf(const char* str); +long double nanl(const char* str); + +floating_point nearbyint (arithmetic x); +float nearbyintf(float x); +long double nearbyintl(long double x); + +floating_point nextafter (arithmetic x, arithmetic y); +float nextafterf(float x, float y); +long double nextafterl(long double x, long double y); + +floating_point nexttoward (arithmetic x, long double y); +float nexttowardf(float x, long double y); +long double nexttowardl(long double x, long double y); + +floating_point remainder (arithmetic x, arithmetic y); +float remainderf(float x, float y); +long double remainderl(long double x, long double y); + +floating_point remquo (arithmetic x, arithmetic y, int* pquo); +float remquof(float x, float y, int* pquo); +long double remquol(long double x, long double y, int* pquo); + +floating_point rint (arithmetic x); +float rintf(float x); +long double rintl(long double x); + +floating_point round (arithmetic x); +float roundf(float x); +long double roundl(long double x); + +floating_point scalbln (arithmetic x, long ex); +float scalblnf(float x, long ex); +long double scalblnl(long double x, long ex); + +floating_point scalbn (arithmetic x, int ex); +float scalbnf(float x, int ex); +long double scalbnl(long double x, int ex); + +floating_point tgamma (arithmetic x); +float tgammaf(float x); +long double tgammal(long double x); + +floating_point trunc (arithmetic x); +float truncf(float x); +long double truncl(long double x); + +} // std + +*/ + +#include <__config> +#include +#include + +#ifdef _MSC_VER +#include "support/win32/math_win32.h" +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +// signbit + +#ifdef signbit + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_signbit(_A1 __x) +{ + return signbit(__x); +} + +#undef signbit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, bool>::type +signbit(_A1 __x) +{ + return __libcpp_signbit(__x); +} + +#endif // signbit + +// fpclassify + +#ifdef fpclassify + +template +_LIBCPP_ALWAYS_INLINE +int +__libcpp_fpclassify(_A1 __x) +{ + return fpclassify(__x); +} + +#undef fpclassify + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, int>::type +fpclassify(_A1 __x) +{ + return __libcpp_fpclassify(__x); +} + +#endif // fpclassify + +// isfinite + +#ifdef isfinite + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isfinite(_A1 __x) +{ + return isfinite(__x); +} + +#undef isfinite + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, bool>::type +isfinite(_A1 __x) +{ + return __libcpp_isfinite(__x); +} + +#endif // isfinite + +// isinf + +#ifdef isinf + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isinf(_A1 __x) +{ + return isinf(__x); +} + +#undef isinf + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, bool>::type +isinf(_A1 __x) +{ + return __libcpp_isinf(__x); +} + +#endif // isinf + +// isnan + +#ifdef isnan + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isnan(_A1 __x) +{ + return isnan(__x); +} + +#undef isnan + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, bool>::type +isnan(_A1 __x) +{ + return __libcpp_isnan(__x); +} + +#endif // isnan + +// isnormal + +#ifdef isnormal + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isnormal(_A1 __x) +{ + return isnormal(__x); +} + +#undef isnormal + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, bool>::type +isnormal(_A1 __x) +{ + return __libcpp_isnormal(__x); +} + +#endif // isnormal + +// isgreater + +#ifdef isgreater + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isgreater(_A1 __x, _A2 __y) +{ + return isgreater(__x, __y); +} + +#undef isgreater + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +isgreater(_A1 __x, _A2 __y) +{ + return __libcpp_isgreater(__x, __y); +} + +#endif // isgreater + +// isgreaterequal + +#ifdef isgreaterequal + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isgreaterequal(_A1 __x, _A2 __y) +{ + return isgreaterequal(__x, __y); +} + +#undef isgreaterequal + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +isgreaterequal(_A1 __x, _A2 __y) +{ + return __libcpp_isgreaterequal(__x, __y); +} + +#endif // isgreaterequal + +// isless + +#ifdef isless + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isless(_A1 __x, _A2 __y) +{ + return isless(__x, __y); +} + +#undef isless + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +isless(_A1 __x, _A2 __y) +{ + return __libcpp_isless(__x, __y); +} + +#endif // isless + +// islessequal + +#ifdef islessequal + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_islessequal(_A1 __x, _A2 __y) +{ + return islessequal(__x, __y); +} + +#undef islessequal + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +islessequal(_A1 __x, _A2 __y) +{ + return __libcpp_islessequal(__x, __y); +} + +#endif // islessequal + +// islessgreater + +#ifdef islessgreater + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_islessgreater(_A1 __x, _A2 __y) +{ + return islessgreater(__x, __y); +} + +#undef islessgreater + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +islessgreater(_A1 __x, _A2 __y) +{ + return __libcpp_islessgreater(__x, __y); +} + +#endif // islessgreater + +// isunordered + +#ifdef isunordered + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isunordered(_A1 __x, _A2 __y) +{ + return isunordered(__x, __y); +} + +#undef isunordered + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +isunordered(_A1 __x, _A2 __y) +{ + return __libcpp_isunordered(__x, __y); +} + +#endif // isunordered + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::signbit; +using ::fpclassify; +using ::isfinite; +using ::isinf; +using ::isnan; +using ::isnormal; +using ::isgreater; +using ::isgreaterequal; +using ::isless; +using ::islessequal; +using ::islessgreater; +using ::isunordered; +using ::isunordered; + +using ::float_t; +using ::double_t; + +// abs + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, _A1>::type +abs(_A1 __x) {return fabs(__x);} + +// acos + +using ::acos; +using ::acosf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float acos(float __x) {return acosf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __x) {return acosl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +acos(_A1 __x) {return acos((double)__x);} + +// asin + +using ::asin; +using ::asinf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float asin(float __x) {return asinf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __x) {return asinl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +asin(_A1 __x) {return asin((double)__x);} + +// atan + +using ::atan; +using ::atanf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float atan(float __x) {return atanf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __x) {return atanl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +atan(_A1 __x) {return atan((double)__x);} + +// atan2 + +using ::atan2; +using ::atan2f; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float atan2(float __y, float __x) {return atan2f(__y, __x);} +inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __y, long double __x) {return atan2l(__y, __x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +atan2(_A1 __y, _A2 __x) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return atan2((__result_type)__y, (__result_type)__x); +} + +// ceil + +using ::ceil; +using ::ceilf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float ceil(float __x) {return ceilf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __x) {return ceill(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +ceil(_A1 __x) {return ceil((double)__x);} + +// cos + +using ::cos; +using ::cosf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float cos(float __x) {return cosf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __x) {return cosl(__x);} +#endif + +template +inline _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +cos(_A1 __x) {return cos((double)__x);} + +// cosh + +using ::cosh; +using ::coshf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float cosh(float __x) {return coshf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __x) {return coshl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +cosh(_A1 __x) {return cosh((double)__x);} + +// exp + +using ::exp; +using ::expf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float exp(float __x) {return expf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __x) {return expl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +exp(_A1 __x) {return exp((double)__x);} + +// fabs + +using ::fabs; +using ::fabsf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float fabs(float __x) {return fabsf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __x) {return fabsl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +fabs(_A1 __x) {return fabs((double)__x);} + +// floor + +using ::floor; +using ::floorf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float floor(float __x) {return floorf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __x) {return floorl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +floor(_A1 __x) {return floor((double)__x);} + +// fmod + +using ::fmod; +using ::fmodf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float fmod(float __x, float __y) {return fmodf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __x, long double __y) {return fmodl(__x, __y);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +fmod(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return fmod((__result_type)__x, (__result_type)__y); +} + +// frexp + +using ::frexp; +using ::frexpf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float frexp(float __x, int* __e) {return frexpf(__x, __e);} +inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __x, int* __e) {return frexpl(__x, __e);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +frexp(_A1 __x, int* __e) {return frexp((double)__x, __e);} + +// ldexp + +using ::ldexp; +using ::ldexpf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float ldexp(float __x, int __e) {return ldexpf(__x, __e);} +inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __x, int __e) {return ldexpl(__x, __e);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +ldexp(_A1 __x, int __e) {return ldexp((double)__x, __e);} + +// log + +using ::log; +using ::logf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float log(float __x) {return logf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double log(long double __x) {return logl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +log(_A1 __x) {return log((double)__x);} + +// log10 + +using ::log10; +using ::log10f; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float log10(float __x) {return log10f(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __x) {return log10l(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +log10(_A1 __x) {return log10((double)__x);} + +// modf + +using ::modf; +using ::modff; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float modf(float __x, float* __y) {return modff(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __x, long double* __y) {return modfl(__x, __y);} +#endif + +// pow + +using ::pow; +using ::powf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float pow(float __x, float __y) {return powf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __x, long double __y) {return powl(__x, __y);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +pow(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return pow((__result_type)__x, (__result_type)__y); +} + +// sin + +using ::sin; +using ::sinf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float sin(float __x) {return sinf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __x) {return sinl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +sin(_A1 __x) {return sin((double)__x);} + +// sinh + +using ::sinh; +using ::sinhf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float sinh(float __x) {return sinhf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __x) {return sinhl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +sinh(_A1 __x) {return sinh((double)__x);} + +// sqrt + +using ::sqrt; +using ::sqrtf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float sqrt(float __x) {return sqrtf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __x) {return sqrtl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +sqrt(_A1 __x) {return sqrt((double)__x);} + +// tan + +using ::tan; +using ::tanf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float tan(float __x) {return tanf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __x) {return tanl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +tan(_A1 __x) {return tan((double)__x);} + +// tanh + +using ::tanh; +using ::tanhf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float tanh(float __x) {return tanhf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __x) {return tanhl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +tanh(_A1 __x) {return tanh((double)__x);} + +// acosh + +#ifndef _MSC_VER +using ::acosh; +using ::acoshf; + +inline _LIBCPP_INLINE_VISIBILITY float acosh(float __x) {return acoshf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __x) {return acoshl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +acosh(_A1 __x) {return acosh((double)__x);} +#endif + +// asinh + +#ifndef _MSC_VER +using ::asinh; +using ::asinhf; + +inline _LIBCPP_INLINE_VISIBILITY float asinh(float __x) {return asinhf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __x) {return asinhl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +asinh(_A1 __x) {return asinh((double)__x);} +#endif + +// atanh + +#ifndef _MSC_VER +using ::atanh; +using ::atanhf; + +inline _LIBCPP_INLINE_VISIBILITY float atanh(float __x) {return atanhf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __x) {return atanhl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +atanh(_A1 __x) {return atanh((double)__x);} +#endif + +// cbrt + +#ifndef _MSC_VER +using ::cbrt; +using ::cbrtf; + +inline _LIBCPP_INLINE_VISIBILITY float cbrt(float __x) {return cbrtf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __x) {return cbrtl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +cbrt(_A1 __x) {return cbrt((double)__x);} +#endif + +// copysign + +using ::copysign; +using ::copysignf; + +inline _LIBCPP_INLINE_VISIBILITY float copysign(float __x, float __y) {return copysignf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double copysign(long double __x, long double __y) {return copysignl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +copysign(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return copysign((__result_type)__x, (__result_type)__y); +} + +#ifndef _MSC_VER + +// erf + +using ::erf; +using ::erff; + +inline _LIBCPP_INLINE_VISIBILITY float erf(float __x) {return erff(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __x) {return erfl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +erf(_A1 __x) {return erf((double)__x);} + +// erfc + +using ::erfc; +using ::erfcf; + +inline _LIBCPP_INLINE_VISIBILITY float erfc(float __x) {return erfcf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __x) {return erfcl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +erfc(_A1 __x) {return erfc((double)__x);} + +// exp2 + +using ::exp2; +using ::exp2f; + +inline _LIBCPP_INLINE_VISIBILITY float exp2(float __x) {return exp2f(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __x) {return exp2l(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +exp2(_A1 __x) {return exp2((double)__x);} + +// expm1 + +using ::expm1; +using ::expm1f; + +inline _LIBCPP_INLINE_VISIBILITY float expm1(float __x) {return expm1f(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __x) {return expm1l(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +expm1(_A1 __x) {return expm1((double)__x);} + +// fdim + +using ::fdim; +using ::fdimf; + +inline _LIBCPP_INLINE_VISIBILITY float fdim(float __x, float __y) {return fdimf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __x, long double __y) {return fdiml(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +fdim(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return fdim((__result_type)__x, (__result_type)__y); +} + +// fma + +inline _LIBCPP_INLINE_VISIBILITY float fmaf(float __x, float __y, float __z) {return (float)((double)__x*__y + __z);} +#define FP_FAST_FMAF + +using ::fma; + +inline _LIBCPP_INLINE_VISIBILITY float fma(float __x, float __y, float __z) {return fmaf(__x, __y, __z);} +inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __x, long double __y, long double __z) {return fmal(__x, __y, __z);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value && + is_arithmetic<_A3>::value, + typename __promote<_A1, _A2, _A3>::type +>::type +fma(_A1 __x, _A2 __y, _A3 __z) +{ + typedef typename __promote<_A1, _A2, _A3>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value && + is_same<_A3, __result_type>::value)), ""); + return fma((__result_type)__x, (__result_type)__y, (__result_type)__z); +} + +// fmax + +using ::fmax; +using ::fmaxf; + +inline _LIBCPP_INLINE_VISIBILITY float fmax(float __x, float __y) {return fmaxf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __x, long double __y) {return fmaxl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +fmax(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return fmax((__result_type)__x, (__result_type)__y); +} + +// fmin + +using ::fmin; +using ::fminf; + +inline _LIBCPP_INLINE_VISIBILITY float fmin(float __x, float __y) {return fminf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __x, long double __y) {return fminl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +fmin(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return fmin((__result_type)__x, (__result_type)__y); +} + +// hypot + +using ::hypot; +using ::hypotf; + +inline _LIBCPP_INLINE_VISIBILITY float hypot(float __x, float __y) {return hypotf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __x, long double __y) {return hypotl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +hypot(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return hypot((__result_type)__x, (__result_type)__y); +} + +// ilogb + +using ::ilogb; +using ::ilogbf; + +inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __x) {return ilogbf(__x);} +inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __x) {return ilogbl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, int>::type +ilogb(_A1 __x) {return ilogb((double)__x);} + +// lgamma + +using ::lgamma; +using ::lgammaf; + +inline _LIBCPP_INLINE_VISIBILITY float lgamma(float __x) {return lgammaf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __x) {return lgammal(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +lgamma(_A1 __x) {return lgamma((double)__x);} + +// llrint + +using ::llrint; +using ::llrintf; + +inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __x) {return llrintf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __x) {return llrintl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, long long>::type +llrint(_A1 __x) {return llrint((double)__x);} + +// llround + +using ::llround; +using ::llroundf; + +inline _LIBCPP_INLINE_VISIBILITY long long llround(float __x) {return llroundf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __x) {return llroundl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, long long>::type +llround(_A1 __x) {return llround((double)__x);} + +// log1p + +using ::log1p; +using ::log1pf; + +inline _LIBCPP_INLINE_VISIBILITY float log1p(float __x) {return log1pf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __x) {return log1pl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +log1p(_A1 __x) {return log1p((double)__x);} + +// log2 + +using ::log2; +using ::log2f; + +inline _LIBCPP_INLINE_VISIBILITY float log2(float __x) {return log2f(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __x) {return log2l(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +log2(_A1 __x) {return log2((double)__x);} + +// logb + +using ::logb; +using ::logbf; + +inline _LIBCPP_INLINE_VISIBILITY float logb(float __x) {return logbf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __x) {return logbl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +logb(_A1 __x) {return logb((double)__x);} + +// lrint + +using ::lrint; +using ::lrintf; + +inline _LIBCPP_INLINE_VISIBILITY long lrint(float __x) {return lrintf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __x) {return lrintl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, long>::type +lrint(_A1 __x) {return lrint((double)__x);} + +// lround + +using ::lround; +using ::lroundf; + +inline _LIBCPP_INLINE_VISIBILITY long lround(float __x) {return lroundf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long lround(long double __x) {return lroundl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, long>::type +lround(_A1 __x) {return lround((double)__x);} + +// nan + +using ::nan; +using ::nanf; + +// nearbyint + +using ::nearbyint; +using ::nearbyintf; + +inline _LIBCPP_INLINE_VISIBILITY float nearbyint(float __x) {return nearbyintf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __x) {return nearbyintl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +nearbyint(_A1 __x) {return nearbyint((double)__x);} + +// nextafter + +using ::nextafter; +using ::nextafterf; + +inline _LIBCPP_INLINE_VISIBILITY float nextafter(float __x, float __y) {return nextafterf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __x, long double __y) {return nextafterl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +nextafter(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return nextafter((__result_type)__x, (__result_type)__y); +} + +// nexttoward + +using ::nexttoward; +using ::nexttowardf; + +inline _LIBCPP_INLINE_VISIBILITY float nexttoward(float __x, long double __y) {return nexttowardf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __x, long double __y) {return nexttowardl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +nexttoward(_A1 __x, long double __y) {return nexttoward((double)__x, __y);} + +// remainder + +using ::remainder; +using ::remainderf; + +inline _LIBCPP_INLINE_VISIBILITY float remainder(float __x, float __y) {return remainderf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __x, long double __y) {return remainderl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +remainder(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return remainder((__result_type)__x, (__result_type)__y); +} + +// remquo + +using ::remquo; +using ::remquof; + +inline _LIBCPP_INLINE_VISIBILITY float remquo(float __x, float __y, int* __z) {return remquof(__x, __y, __z);} +inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __x, long double __y, int* __z) {return remquol(__x, __y, __z);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +remquo(_A1 __x, _A2 __y, int* __z) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return remquo((__result_type)__x, (__result_type)__y, __z); +} + +// rint + +using ::rint; +using ::rintf; + +inline _LIBCPP_INLINE_VISIBILITY float rint(float __x) {return rintf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __x) {return rintl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +rint(_A1 __x) {return rint((double)__x);} + +// round + +using ::round; +using ::roundf; + +inline _LIBCPP_INLINE_VISIBILITY float round(float __x) {return roundf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double round(long double __x) {return roundl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +round(_A1 __x) {return round((double)__x);} + +// scalbln + +using ::scalbln; +using ::scalblnf; + +inline _LIBCPP_INLINE_VISIBILITY float scalbln(float __x, long __y) {return scalblnf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __x, long __y) {return scalblnl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +scalbln(_A1 __x, long __y) {return scalbln((double)__x, __y);} + +// scalbn + +using ::scalbn; +using ::scalbnf; + +inline _LIBCPP_INLINE_VISIBILITY float scalbn(float __x, int __y) {return scalbnf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __x, int __y) {return scalbnl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +scalbn(_A1 __x, int __y) {return scalbn((double)__x, __y);} + +// tgamma + +using ::tgamma; +using ::tgammaf; + +inline _LIBCPP_INLINE_VISIBILITY float tgamma(float __x) {return tgammaf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __x) {return tgammal(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +tgamma(_A1 __x) {return tgamma((double)__x);} + +// trunc + +using ::trunc; +using ::truncf; + +inline _LIBCPP_INLINE_VISIBILITY float trunc(float __x) {return truncf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __x) {return truncl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +trunc(_A1 __x) {return trunc((double)__x);} + +#endif // !_MSC_VER + +using ::acosl; +using ::asinl; +using ::atanl; +using ::atan2l; +using ::ceill; +using ::cosl; +using ::coshl; +using ::expl; +using ::fabsl; +using ::floorl; +using ::fmodl; +using ::frexpl; +using ::ldexpl; +using ::logl; +using ::log10l; +using ::modfl; +using ::powl; +using ::sinl; +using ::sinhl; +using ::sqrtl; +using ::tanl; +#ifndef _MSC_VER +using ::tanhl; +using ::acoshl; +using ::asinhl; +using ::atanhl; +using ::cbrtl; +#endif !_MSC_VER +using ::copysignl; +#ifndef _MSC_VER +using ::erfl; +using ::erfcl; +using ::exp2l; +using ::expm1l; +using ::fdiml; +using ::fmal; +using ::fmaxl; +using ::fminl; +using ::hypotl; +using ::ilogbl; +using ::lgammal; +using ::llrintl; +using ::llroundl; +using ::log1pl; +using ::log2l; +using ::logbl; +using ::lrintl; +using ::lroundl; +using ::nanl; +using ::nearbyintl; +using ::nextafterl; +using ::nexttowardl; +using ::remainderl; +using ::remquol; +using ::rintl; +using ::roundl; +using ::scalblnl; +using ::scalbnl; +using ::tgammal; +using ::truncl; +#endif // !_MSC_VER + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CMATH diff --git a/contrib/libc++/include/codecvt b/contrib/libc++/include/codecvt new file mode 100644 index 000000000000..6c44e3434746 --- /dev/null +++ b/contrib/libc++/include/codecvt @@ -0,0 +1,547 @@ +// -*- C++ -*- +//===-------------------------- codecvt -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CODECVT +#define _LIBCPP_CODECVT + +/* + codecvt synopsis + +namespace std +{ + +enum codecvt_mode +{ + consume_header = 4, + generate_header = 2, + little_endian = 1 +}; + +template +class codecvt_utf8 + : public codecvt +{ + // unspecified +}; + +template +class codecvt_utf16 + : public codecvt +{ + // unspecified +}; + +template +class codecvt_utf8_utf16 + : public codecvt +{ + // unspecified +}; + +} // std + +*/ + +#include <__config> +#include <__locale> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +enum codecvt_mode +{ + consume_header = 4, + generate_header = 2, + little_endian = 1 +}; + +// codecvt_utf8 + +template class __codecvt_utf8; + +template <> +class __codecvt_utf8 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class __codecvt_utf8 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class __codecvt_utf8 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template +class _LIBCPP_VISIBLE codecvt_utf8 + : public __codecvt_utf8<_Elem> +{ +public: + _LIBCPP_ALWAYS_INLINE + explicit codecvt_utf8(size_t __refs = 0) + : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {} + + _LIBCPP_ALWAYS_INLINE + ~codecvt_utf8() {} +}; + +// codecvt_utf16 + +template class __codecvt_utf16; + +template <> +class __codecvt_utf16 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class __codecvt_utf16 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class __codecvt_utf16 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class __codecvt_utf16 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class __codecvt_utf16 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class __codecvt_utf16 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template +class _LIBCPP_VISIBLE codecvt_utf16 + : public __codecvt_utf16<_Elem, _Mode & little_endian> +{ +public: + _LIBCPP_ALWAYS_INLINE + explicit codecvt_utf16(size_t __refs = 0) + : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {} + + _LIBCPP_ALWAYS_INLINE + ~codecvt_utf16() {} +}; + +// codecvt_utf8_utf16 + +template class __codecvt_utf8_utf16; + +template <> +class __codecvt_utf8_utf16 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class __codecvt_utf8_utf16 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char32_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template <> +class __codecvt_utf8_utf16 + : public codecvt +{ + unsigned long _Maxcode_; + codecvt_mode _Mode_; +public: + typedef char16_t intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + _LIBCPP_ALWAYS_INLINE + explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode, + codecvt_mode _Mode) + : codecvt(__refs), _Maxcode_(_Maxcode), + _Mode_(_Mode) {} +protected: + virtual result + do_out(state_type& __st, + const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual result + do_in(state_type& __st, + const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, + intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; + virtual result + do_unshift(state_type& __st, + extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; + virtual int do_encoding() const throw(); + virtual bool do_always_noconv() const throw(); + virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, + size_t __mx) const; + virtual int do_max_length() const throw(); +}; + +template +class _LIBCPP_VISIBLE codecvt_utf8_utf16 + : public __codecvt_utf8_utf16<_Elem> +{ +public: + _LIBCPP_ALWAYS_INLINE + explicit codecvt_utf8_utf16(size_t __refs = 0) + : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {} + + _LIBCPP_ALWAYS_INLINE + ~codecvt_utf8_utf16() {} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CODECVT diff --git a/contrib/libc++/include/complex b/contrib/libc++/include/complex new file mode 100644 index 000000000000..e7f63eac3a1e --- /dev/null +++ b/contrib/libc++/include/complex @@ -0,0 +1,1516 @@ +// -*- C++ -*- +//===--------------------------- complex ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_COMPLEX +#define _LIBCPP_COMPLEX + +/* + complex synopsis + +namespace std +{ + +template +class complex +{ +public: + typedef T value_type; + + complex(const T& re = T(), const T& im = T()); + complex(const complex&); + template complex(const complex&); + + T real() const; + T imag() const; + + void real(T); + void imag(T); + + complex& operator= (const T&); + complex& operator+=(const T&); + complex& operator-=(const T&); + complex& operator*=(const T&); + complex& operator/=(const T&); + + complex& operator=(const complex&); + template complex& operator= (const complex&); + template complex& operator+=(const complex&); + template complex& operator-=(const complex&); + template complex& operator*=(const complex&); + template complex& operator/=(const complex&); +}; + +template<> +class complex +{ +public: + typedef float value_type; + + constexpr complex(float re = 0.0f, float im = 0.0f); + explicit constexpr complex(const complex&); + explicit constexpr complex(const complex&); + + constexpr float real() const; + void real(float); + constexpr float imag() const; + void imag(float); + + complex& operator= (float); + complex& operator+=(float); + complex& operator-=(float); + complex& operator*=(float); + complex& operator/=(float); + + complex& operator=(const complex&); + template complex& operator= (const complex&); + template complex& operator+=(const complex&); + template complex& operator-=(const complex&); + template complex& operator*=(const complex&); + template complex& operator/=(const complex&); +}; + +template<> +class complex +{ +public: + typedef double value_type; + + constexpr complex(double re = 0.0, double im = 0.0); + constexpr complex(const complex&); + explicit constexpr complex(const complex&); + + constexpr double real() const; + void real(double); + constexpr double imag() const; + void imag(double); + + complex& operator= (double); + complex& operator+=(double); + complex& operator-=(double); + complex& operator*=(double); + complex& operator/=(double); + complex& operator=(const complex&); + + template complex& operator= (const complex&); + template complex& operator+=(const complex&); + template complex& operator-=(const complex&); + template complex& operator*=(const complex&); + template complex& operator/=(const complex&); +}; + +template<> +class complex +{ +public: + typedef long double value_type; + + constexpr complex(long double re = 0.0L, long double im = 0.0L); + constexpr complex(const complex&); + constexpr complex(const complex&); + + constexpr long double real() const; + void real(long double); + constexpr long double imag() const; + void imag(long double); + + complex& operator=(const complex&); + complex& operator= (long double); + complex& operator+=(long double); + complex& operator-=(long double); + complex& operator*=(long double); + complex& operator/=(long double); + + template complex& operator= (const complex&); + template complex& operator+=(const complex&); + template complex& operator-=(const complex&); + template complex& operator*=(const complex&); + template complex& operator/=(const complex&); +}; + +// 26.3.6 operators: +template complex operator+(const complex&, const complex&); +template complex operator+(const complex&, const T&); +template complex operator+(const T&, const complex&); +template complex operator-(const complex&, const complex&); +template complex operator-(const complex&, const T&); +template complex operator-(const T&, const complex&); +template complex operator*(const complex&, const complex&); +template complex operator*(const complex&, const T&); +template complex operator*(const T&, const complex&); +template complex operator/(const complex&, const complex&); +template complex operator/(const complex&, const T&); +template complex operator/(const T&, const complex&); +template complex operator+(const complex&); +template complex operator-(const complex&); +template bool operator==(const complex&, const complex&); +template bool operator==(const complex&, const T&); +template bool operator==(const T&, const complex&); +template bool operator!=(const complex&, const complex&); +template bool operator!=(const complex&, const T&); +template bool operator!=(const T&, const complex&); + +template + basic_istream& + operator>>(basic_istream&, complex&); +template + basic_ostream& + operator<<(basic_ostream&, const complex&); + +// 26.3.7 values: + +template T real(const complex&); + long double real(long double); + double real(double); +template double real(T); + float real(float); + +template T imag(const complex&); + long double imag(long double); + double imag(double); +template double imag(T); + float imag(float); + +template T abs(const complex&); + +template T arg(const complex&); + long double arg(long double); + double arg(double); +template double arg(T); + float arg(float); + +template T norm(const complex&); + long double norm(long double); + double norm(double); +template double norm(T); + float norm(float); + +template complex conj(const complex&); + complex conj(long double); + complex conj(double); +template complex conj(T); + complex conj(float); + +template complex proj(const complex&); + complex proj(long double); + complex proj(double); +template complex proj(T); + complex proj(float); + +template complex polar(const T&, const T& = 0); + +// 26.3.8 transcendentals: +template complex acos(const complex&); +template complex asin(const complex&); +template complex atan(const complex&); +template complex acosh(const complex&); +template complex asinh(const complex&); +template complex atanh(const complex&); +template complex cos (const complex&); +template complex cosh (const complex&); +template complex exp (const complex&); +template complex log (const complex&); +template complex log10(const complex&); + +template complex pow(const complex&, const T&); +template complex pow(const complex&, const complex&); +template complex pow(const T&, const complex&); + +template complex sin (const complex&); +template complex sinh (const complex&); +template complex sqrt (const complex&); +template complex tan (const complex&); +template complex tanh (const complex&); + +template + basic_istream& + operator>>(basic_istream& is, complex& x); + +template + basic_ostream& + operator<<(basic_ostream& o, const complex& x); + +} // std + +*/ + +#include <__config> +#include +#include +#include +#include +#if defined(_LIBCPP_NO_EXCEPTIONS) + #include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template class _LIBCPP_VISIBLE complex; + +template complex<_Tp> operator*(const complex<_Tp>& __z, const complex<_Tp>& __w); +template complex<_Tp> operator/(const complex<_Tp>& __x, const complex<_Tp>& __y); + +template +class _LIBCPP_VISIBLE complex +{ +public: + typedef _Tp value_type; +private: + value_type __re_; + value_type __im_; +public: + _LIBCPP_INLINE_VISIBILITY + complex(const value_type& __re = value_type(), const value_type& __im = value_type()) + : __re_(__re), __im_(__im) {} + template _LIBCPP_INLINE_VISIBILITY + complex(const complex<_Xp>& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + + _LIBCPP_INLINE_VISIBILITY value_type real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY value_type imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (const value_type& __re) {__re_ = __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(const value_type& __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(const value_type& __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(const value_type& __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(const value_type& __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * __c; + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / __c; + return *this; + } +}; + +template<> class _LIBCPP_VISIBLE complex; +template<> class _LIBCPP_VISIBLE complex; + +template<> +class _LIBCPP_VISIBLE complex +{ + float __re_; + float __im_; +public: + typedef float value_type; + + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(float __re = 0.0f, float __im = 0.0f) + : __re_(__re), __im_(__im) {} + explicit /*constexpr*/ complex(const complex& __c); + explicit /*constexpr*/ complex(const complex& __c); + + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY float real() const {return __re_;} + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY float imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (float __re) {__re_ = __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(float __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(float __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(float __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(float __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * __c; + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / __c; + return *this; + } +}; + +template<> +class _LIBCPP_VISIBLE complex +{ + double __re_; + double __im_; +public: + typedef double value_type; + + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(double __re = 0.0, double __im = 0.0) + : __re_(__re), __im_(__im) {} + /*constexpr*/ complex(const complex& __c); + explicit /*constexpr*/ complex(const complex& __c); + + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY double real() const {return __re_;} + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY double imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (double __re) {__re_ = __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(double __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(double __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(double __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(double __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * __c; + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / __c; + return *this; + } +}; + +template<> +class _LIBCPP_VISIBLE complex +{ + long double __re_; + long double __im_; +public: + typedef long double value_type; + + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(long double __re = 0.0L, long double __im = 0.0L) + : __re_(__re), __im_(__im) {} + /*constexpr*/ complex(const complex& __c); + /*constexpr*/ complex(const complex& __c); + + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY long double real() const {return __re_;} + /*constexpr*/ _LIBCPP_INLINE_VISIBILITY long double imag() const {return __im_;} + + _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} + _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} + + _LIBCPP_INLINE_VISIBILITY complex& operator= (long double __re) {__re_ = __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator+=(long double __re) {__re_ += __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator-=(long double __re) {__re_ -= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator*=(long double __re) {__re_ *= __re; __im_ *= __re; return *this;} + _LIBCPP_INLINE_VISIBILITY complex& operator/=(long double __re) {__re_ /= __re; __im_ /= __re; return *this;} + + template _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c) + { + __re_ = __c.real(); + __im_ = __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c) + { + __re_ += __c.real(); + __im_ += __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c) + { + __re_ -= __c.real(); + __im_ -= __c.imag(); + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) + { + *this = *this * __c; + return *this; + } + template _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) + { + *this = *this / __c; + return *this; + } +}; + +//constexpr +inline _LIBCPP_INLINE_VISIBILITY +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +//constexpr +inline _LIBCPP_INLINE_VISIBILITY +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +//constexpr +inline _LIBCPP_INLINE_VISIBILITY +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +//constexpr +inline _LIBCPP_INLINE_VISIBILITY +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +//constexpr +inline _LIBCPP_INLINE_VISIBILITY +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +//constexpr +inline _LIBCPP_INLINE_VISIBILITY +complex::complex(const complex& __c) + : __re_(__c.real()), __im_(__c.imag()) {} + +// 26.3.6 operators: + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__x); + __t += __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const complex<_Tp>& __x, const _Tp& __y) +{ + complex<_Tp> __t(__x); + __t += __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__y); + __t += __x; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__x); + __t -= __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const complex<_Tp>& __x, const _Tp& __y) +{ + complex<_Tp> __t(__x); + __t -= __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(-__y); + __t += __x; + return __t; +} + +template +complex<_Tp> +operator*(const complex<_Tp>& __z, const complex<_Tp>& __w) +{ + _Tp __a = __z.real(); + _Tp __b = __z.imag(); + _Tp __c = __w.real(); + _Tp __d = __w.imag(); + _Tp __ac = __a * __c; + _Tp __bd = __b * __d; + _Tp __ad = __a * __d; + _Tp __bc = __b * __c; + _Tp __x = __ac - __bd; + _Tp __y = __ad + __bc; + if (isnan(__x) && isnan(__y)) + { + bool __recalc = false; + if (isinf(__a) || isinf(__b)) + { + __a = copysign(isinf(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(isinf(__b) ? _Tp(1) : _Tp(0), __b); + if (isnan(__c)) + __c = copysign(_Tp(0), __c); + if (isnan(__d)) + __d = copysign(_Tp(0), __d); + __recalc = true; + } + if (isinf(__c) || isinf(__d)) + { + __c = copysign(isinf(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(isinf(__d) ? _Tp(1) : _Tp(0), __d); + if (isnan(__a)) + __a = copysign(_Tp(0), __a); + if (isnan(__b)) + __b = copysign(_Tp(0), __b); + __recalc = true; + } + if (!__recalc && (isinf(__ac) || isinf(__bd) || + isinf(__ad) || isinf(__bc))) + { + if (isnan(__a)) + __a = copysign(_Tp(0), __a); + if (isnan(__b)) + __b = copysign(_Tp(0), __b); + if (isnan(__c)) + __c = copysign(_Tp(0), __c); + if (isnan(__d)) + __d = copysign(_Tp(0), __d); + __recalc = true; + } + if (__recalc) + { + __x = _Tp(INFINITY) * (__a * __c - __b * __d); + __y = _Tp(INFINITY) * (__a * __d + __b * __c); + } + } + return complex<_Tp>(__x, __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator*(const complex<_Tp>& __x, const _Tp& __y) +{ + complex<_Tp> __t(__x); + __t *= __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator*(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__y); + __t *= __x; + return __t; +} + +template +complex<_Tp> +operator/(const complex<_Tp>& __z, const complex<_Tp>& __w) +{ + int __ilogbw = 0; + _Tp __a = __z.real(); + _Tp __b = __z.imag(); + _Tp __c = __w.real(); + _Tp __d = __w.imag(); + _Tp __logbw = logb(fmax(fabs(__c), fabs(__d))); + if (isfinite(__logbw)) + { + __ilogbw = static_cast(__logbw); + __c = scalbn(__c, -__ilogbw); + __d = scalbn(__d, -__ilogbw); + } + _Tp __denom = __c * __c + __d * __d; + _Tp __x = scalbn((__a * __c + __b * __d) / __denom, -__ilogbw); + _Tp __y = scalbn((__b * __c - __a * __d) / __denom, -__ilogbw); + if (isnan(__x) && isnan(__y)) + { + if ((__denom == _Tp(0)) && (!isnan(__a) || !isnan(__b))) + { + __x = copysign(_Tp(INFINITY), __c) * __a; + __y = copysign(_Tp(INFINITY), __c) * __b; + } + else if ((isinf(__a) || isinf(__b)) && isfinite(__c) && isfinite(__d)) + { + __a = copysign(isinf(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(isinf(__b) ? _Tp(1) : _Tp(0), __b); + __x = _Tp(INFINITY) * (__a * __c + __b * __d); + __y = _Tp(INFINITY) * (__b * __c - __a * __d); + } + else if (isinf(__logbw) && __logbw > _Tp(0) && isfinite(__a) && isfinite(__b)) + { + __c = copysign(isinf(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(isinf(__d) ? _Tp(1) : _Tp(0), __d); + __x = _Tp(0) * (__a * __c + __b * __d); + __y = _Tp(0) * (__b * __c - __a * __d); + } + } + return complex<_Tp>(__x, __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator/(const complex<_Tp>& __x, const _Tp& __y) +{ + return complex<_Tp>(__x.real() / __y, __x.imag() / __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator/(const _Tp& __x, const complex<_Tp>& __y) +{ + complex<_Tp> __t(__x); + __t /= __y; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator+(const complex<_Tp>& __x) +{ + return __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +operator-(const complex<_Tp>& __x) +{ + return complex<_Tp>(-__x.real(), -__x.imag()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + return __x.real() == __y.real() && __x.imag() == __y.imag(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const complex<_Tp>& __x, const _Tp& __y) +{ + return __x.real() == __y && __x.imag() == 0; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const _Tp& __x, const complex<_Tp>& __y) +{ + return __x == __y.real() && 0 == __y.imag(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + return !(__x == __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const complex<_Tp>& __x, const _Tp& __y) +{ + return !(__x == __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const _Tp& __x, const complex<_Tp>& __y) +{ + return !(__x == __y); +} + +// 26.3.7 values: + +// real + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +real(const complex<_Tp>& __c) +{ + return __c.real(); +} + +inline _LIBCPP_INLINE_VISIBILITY +long double +real(long double __re) +{ + return __re; +} + +inline _LIBCPP_INLINE_VISIBILITY +double +real(double __re) +{ + return __re; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + double +>::type +real(_Tp __re) +{ + return __re; +} + +inline _LIBCPP_INLINE_VISIBILITY +float +real(float __re) +{ + return __re; +} + +// imag + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +imag(const complex<_Tp>& __c) +{ + return __c.imag(); +} + +inline _LIBCPP_INLINE_VISIBILITY +long double +imag(long double __re) +{ + return 0; +} + +inline _LIBCPP_INLINE_VISIBILITY +double +imag(double __re) +{ + return 0; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + double +>::type +imag(_Tp __re) +{ + return 0; +} + +inline _LIBCPP_INLINE_VISIBILITY +float +imag(float __re) +{ + return 0; +} + +// abs + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +abs(const complex<_Tp>& __c) +{ + return hypot(__c.real(), __c.imag()); +} + +// arg + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +arg(const complex<_Tp>& __c) +{ + return atan2(__c.imag(), __c.real()); +} + +inline _LIBCPP_INLINE_VISIBILITY +long double +arg(long double __re) +{ + return atan2l(0.L, __re); +} + +inline _LIBCPP_INLINE_VISIBILITY +double +arg(double __re) +{ + return atan2(0., __re); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + double +>::type +arg(_Tp __re) +{ + return atan2(0., __re); +} + +inline _LIBCPP_INLINE_VISIBILITY +float +arg(float __re) +{ + return atan2f(0.F, __re); +} + +// norm + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +norm(const complex<_Tp>& __c) +{ + if (isinf(__c.real())) + return abs(__c.real()); + if (isinf(__c.imag())) + return abs(__c.imag()); + return __c.real() * __c.real() + __c.imag() * __c.imag(); +} + +inline _LIBCPP_INLINE_VISIBILITY +long double +norm(long double __re) +{ + return __re * __re; +} + +inline _LIBCPP_INLINE_VISIBILITY +double +norm(double __re) +{ + return __re * __re; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + double +>::type +norm(_Tp __re) +{ + return (double)__re * __re; +} + +inline _LIBCPP_INLINE_VISIBILITY +float +norm(float __re) +{ + return __re * __re; +} + +// conj + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +conj(const complex<_Tp>& __c) +{ + return complex<_Tp>(__c.real(), -__c.imag()); +} + +inline _LIBCPP_INLINE_VISIBILITY +complex +conj(long double __re) +{ + return complex(__re); +} + +inline _LIBCPP_INLINE_VISIBILITY +complex +conj(double __re) +{ + return complex(__re); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + complex +>::type +conj(_Tp __re) +{ + return complex(__re); +} + +inline _LIBCPP_INLINE_VISIBILITY +complex +conj(float __re) +{ + return complex(__re); +} + +// proj + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +proj(const complex<_Tp>& __c) +{ + std::complex<_Tp> __r = __c; + if (isinf(__c.real()) || isinf(__c.imag())) + __r = complex<_Tp>(INFINITY, copysign(_Tp(0), __c.imag())); + return __r; +} + +inline _LIBCPP_INLINE_VISIBILITY +complex +proj(long double __re) +{ + if (isinf(__re)) + __re = abs(__re); + return complex(__re); +} + +inline _LIBCPP_INLINE_VISIBILITY +complex +proj(double __re) +{ + if (isinf(__re)) + __re = abs(__re); + return complex(__re); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + complex +>::type +proj(_Tp __re) +{ + return complex(__re); +} + +inline _LIBCPP_INLINE_VISIBILITY +complex +proj(float __re) +{ + if (isinf(__re)) + __re = abs(__re); + return complex(__re); +} + +// polar + +template +complex<_Tp> +polar(const _Tp& __rho, const _Tp& __theta = _Tp(0)) +{ + if (isnan(__rho) || signbit(__rho)) + return complex<_Tp>(_Tp(NAN), _Tp(NAN)); + if (isnan(__theta)) + { + if (isinf(__rho)) + return complex<_Tp>(__rho, __theta); + return complex<_Tp>(__theta, __theta); + } + if (isinf(__theta)) + { + if (isinf(__rho)) + return complex<_Tp>(__rho, _Tp(NAN)); + return complex<_Tp>(_Tp(NAN), _Tp(NAN)); + } + _Tp __x = __rho * cos(__theta); + if (isnan(__x)) + __x = 0; + _Tp __y = __rho * sin(__theta); + if (isnan(__y)) + __y = 0; + return complex<_Tp>(__x, __y); +} + +// log + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +log(const complex<_Tp>& __x) +{ + return complex<_Tp>(log(abs(__x)), arg(__x)); +} + +// log10 + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +log10(const complex<_Tp>& __x) +{ + return log(__x) / log(_Tp(10)); +} + +// sqrt + +template +complex<_Tp> +sqrt(const complex<_Tp>& __x) +{ + if (isinf(__x.imag())) + return complex<_Tp>(_Tp(INFINITY), __x.imag()); + if (isinf(__x.real())) + { + if (__x.real() > _Tp(0)) + return complex<_Tp>(__x.real(), isnan(__x.imag()) ? __x.imag() : copysign(_Tp(0), __x.imag())); + return complex<_Tp>(isnan(__x.imag()) ? __x.imag() : _Tp(0), copysign(__x.real(), __x.imag())); + } + return polar(sqrt(abs(__x)), arg(__x) / _Tp(2)); +} + +// exp + +template +complex<_Tp> +exp(const complex<_Tp>& __x) +{ + _Tp __i = __x.imag(); + if (isinf(__x.real())) + { + if (__x.real() < _Tp(0)) + { + if (!isfinite(__i)) + __i = _Tp(1); + } + else if (__i == 0 || !isfinite(__i)) + { + if (isinf(__i)) + __i = _Tp(NAN); + return complex<_Tp>(__x.real(), __i); + } + } + else if (isnan(__x.real()) && __x.imag() == 0) + return __x; + _Tp __e = exp(__x.real()); + return complex<_Tp>(__e * cos(__i), __e * sin(__i)); +} + +// pow + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +pow(const complex<_Tp>& __x, const complex<_Tp>& __y) +{ + return exp(__y * log(__x)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +complex::type> +pow(const complex<_Tp>& __x, const complex<_Up>& __y) +{ + typedef complex::type> result_type; + return _VSTD::pow(result_type(__x), result_type(__y)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_Up>::value, + complex::type> +>::type +pow(const complex<_Tp>& __x, const _Up& __y) +{ + typedef complex::type> result_type; + return _VSTD::pow(result_type(__x), result_type(__y)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_Tp>::value, + complex::type> +>::type +pow(const _Tp& __x, const complex<_Up>& __y) +{ + typedef complex::type> result_type; + return _VSTD::pow(result_type(__x), result_type(__y)); +} + +// asinh + +template +complex<_Tp> +asinh(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (isinf(__x.real())) + { + if (isnan(__x.imag())) + return __x; + if (isinf(__x.imag())) + return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); + return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag())); + } + if (isnan(__x.real())) + { + if (isinf(__x.imag())) + return complex<_Tp>(__x.imag(), __x.real()); + if (__x.imag() == 0) + return __x; + return complex<_Tp>(__x.real(), __x.real()); + } + if (isinf(__x.imag())) + return complex<_Tp>(copysign(__x.imag(), __x.real()), copysign(__pi/_Tp(2), __x.imag())); + complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) + _Tp(1))); + return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag())); +} + +// acosh + +template +complex<_Tp> +acosh(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (isinf(__x.real())) + { + if (isnan(__x.imag())) + return complex<_Tp>(abs(__x.real()), __x.imag()); + if (isinf(__x.imag())) + if (__x.real() > 0) + return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); + else + return complex<_Tp>(-__x.real(), copysign(__pi * _Tp(0.75), __x.imag())); + if (__x.real() < 0) + return complex<_Tp>(-__x.real(), copysign(__pi, __x.imag())); + return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag())); + } + if (isnan(__x.real())) + { + if (isinf(__x.imag())) + return complex<_Tp>(abs(__x.imag()), __x.real()); + return complex<_Tp>(__x.real(), __x.real()); + } + if (isinf(__x.imag())) + return complex<_Tp>(abs(__x.imag()), copysign(__pi/_Tp(2), __x.imag())); + complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) - _Tp(1))); + return complex<_Tp>(copysign(__z.real(), _Tp(0)), copysign(__z.imag(), __x.imag())); +} + +// atanh + +template +complex<_Tp> +atanh(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (isinf(__x.imag())) + { + return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag())); + } + if (isnan(__x.imag())) + { + if (isinf(__x.real()) || __x.real() == 0) + return complex<_Tp>(copysign(_Tp(0), __x.real()), __x.imag()); + return complex<_Tp>(__x.imag(), __x.imag()); + } + if (isnan(__x.real())) + { + return complex<_Tp>(__x.real(), __x.real()); + } + if (isinf(__x.real())) + { + return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag())); + } + if (abs(__x.real()) == _Tp(1) && __x.imag() == _Tp(0)) + { + return complex<_Tp>(copysign(_Tp(INFINITY), __x.real()), copysign(_Tp(0), __x.imag())); + } + complex<_Tp> __z = log((_Tp(1) + __x) / (_Tp(1) - __x)) / _Tp(2); + return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag())); +} + +// sinh + +template +complex<_Tp> +sinh(const complex<_Tp>& __x) +{ + if (isinf(__x.real()) && !isfinite(__x.imag())) + return complex<_Tp>(__x.real(), _Tp(NAN)); + if (__x.real() == 0 && !isfinite(__x.imag())) + return complex<_Tp>(__x.real(), _Tp(NAN)); + if (__x.imag() == 0 && !isfinite(__x.real())) + return __x; + return complex<_Tp>(sinh(__x.real()) * cos(__x.imag()), cosh(__x.real()) * sin(__x.imag())); +} + +// cosh + +template +complex<_Tp> +cosh(const complex<_Tp>& __x) +{ + if (isinf(__x.real()) && !isfinite(__x.imag())) + return complex<_Tp>(abs(__x.real()), _Tp(NAN)); + if (__x.real() == 0 && !isfinite(__x.imag())) + return complex<_Tp>(_Tp(NAN), __x.real()); + if (__x.real() == 0 && __x.imag() == 0) + return complex<_Tp>(_Tp(1), __x.imag()); + if (__x.imag() == 0 && !isfinite(__x.real())) + return complex<_Tp>(abs(__x.real()), __x.imag()); + return complex<_Tp>(cosh(__x.real()) * cos(__x.imag()), sinh(__x.real()) * sin(__x.imag())); +} + +// tanh + +template +complex<_Tp> +tanh(const complex<_Tp>& __x) +{ + if (isinf(__x.real())) + { + if (!isfinite(__x.imag())) + return complex<_Tp>(_Tp(1), _Tp(0)); + return complex<_Tp>(_Tp(1), copysign(_Tp(0), sin(_Tp(2) * __x.imag()))); + } + if (isnan(__x.real()) && __x.imag() == 0) + return __x; + _Tp __2r(_Tp(2) * __x.real()); + _Tp __2i(_Tp(2) * __x.imag()); + _Tp __d(cosh(__2r) + cos(__2i)); + return complex<_Tp>(sinh(__2r)/__d, sin(__2i)/__d); +} + +// asin + +template +complex<_Tp> +asin(const complex<_Tp>& __x) +{ + complex<_Tp> __z = asinh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +// acos + +template +complex<_Tp> +acos(const complex<_Tp>& __x) +{ + const _Tp __pi(atan2(+0., -0.)); + if (isinf(__x.real())) + { + if (isnan(__x.imag())) + return complex<_Tp>(__x.imag(), __x.real()); + if (isinf(__x.imag())) + { + if (__x.real() < _Tp(0)) + return complex<_Tp>(_Tp(0.75) * __pi, -__x.imag()); + return complex<_Tp>(_Tp(0.25) * __pi, -__x.imag()); + } + if (__x.real() < _Tp(0)) + return complex<_Tp>(__pi, signbit(__x.imag()) ? -__x.real() : __x.real()); + return complex<_Tp>(_Tp(0), signbit(__x.imag()) ? __x.real() : -__x.real()); + } + if (isnan(__x.real())) + { + if (isinf(__x.imag())) + return complex<_Tp>(__x.real(), -__x.imag()); + return complex<_Tp>(__x.real(), __x.real()); + } + if (isinf(__x.imag())) + return complex<_Tp>(__pi/_Tp(2), -__x.imag()); + if (__x.real() == 0) + return complex<_Tp>(__pi/_Tp(2), -__x.imag()); + complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) - _Tp(1))); + if (signbit(__x.imag())) + return complex<_Tp>(abs(__z.imag()), abs(__z.real())); + return complex<_Tp>(abs(__z.imag()), -abs(__z.real())); +} + +// atan + +template +complex<_Tp> +atan(const complex<_Tp>& __x) +{ + complex<_Tp> __z = atanh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +// sin + +template +complex<_Tp> +sin(const complex<_Tp>& __x) +{ + complex<_Tp> __z = sinh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +// cos + +template +inline _LIBCPP_INLINE_VISIBILITY +complex<_Tp> +cos(const complex<_Tp>& __x) +{ + return cosh(complex<_Tp>(-__x.imag(), __x.real())); +} + +// tan + +template +complex<_Tp> +tan(const complex<_Tp>& __x) +{ + complex<_Tp> __z = tanh(complex<_Tp>(-__x.imag(), __x.real())); + return complex<_Tp>(__z.imag(), -__z.real()); +} + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x) +{ + if (__is.good()) + { + ws(__is); + if (__is.peek() == _CharT('(')) + { + __is.get(); + _Tp __r; + __is >> __r; + if (!__is.fail()) + { + ws(__is); + _CharT __c = __is.peek(); + if (__c == _CharT(',')) + { + __is.get(); + _Tp __i; + __is >> __i; + if (!__is.fail()) + { + ws(__is); + __c = __is.peek(); + if (__c == _CharT(')')) + { + __is.get(); + __x = complex<_Tp>(__r, __i); + } + else + __is.setstate(ios_base::failbit); + } + else + __is.setstate(ios_base::failbit); + } + else if (__c == _CharT(')')) + { + __is.get(); + __x = complex<_Tp>(__r, _Tp(0)); + } + else + __is.setstate(ios_base::failbit); + } + else + __is.setstate(ios_base::failbit); + } + else + { + _Tp __r; + __is >> __r; + if (!__is.fail()) + __x = complex<_Tp>(__r, _Tp(0)); + else + __is.setstate(ios_base::failbit); + } + } + else + __is.setstate(ios_base::failbit); + return __is; +} + +template +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x) +{ + basic_ostringstream<_CharT, _Traits> __s; + __s.flags(__os.flags()); + __s.imbue(__os.getloc()); + __s.precision(__os.precision()); + __s << '(' << __x.real() << ',' << __x.imag() << ')'; + return __os << __s.str(); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_COMPLEX diff --git a/contrib/libc++/include/complex.h b/contrib/libc++/include/complex.h new file mode 100644 index 000000000000..7003d31a89cd --- /dev/null +++ b/contrib/libc++/include/complex.h @@ -0,0 +1,35 @@ +// -*- C++ -*- +//===--------------------------- complex.h --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_COMPLEX_H +#define _LIBCPP_COMPLEX_H + +/* + complex.h synopsis + +#include + +*/ + +#ifdef __cplusplus + +#include + +#else // __cplusplus + +#include_next + +#endif // __cplusplus + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#endif // _LIBCPP_COMPLEX_H diff --git a/contrib/libc++/include/condition_variable b/contrib/libc++/include/condition_variable new file mode 100644 index 000000000000..b4da556f6356 --- /dev/null +++ b/contrib/libc++/include/condition_variable @@ -0,0 +1,256 @@ +// -*- C++ -*- +//===---------------------- condition_variable ----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CONDITION_VARIABLE +#define _LIBCPP_CONDITION_VARIABLE + +/* + condition_variable synopsis + +namespace std +{ + +enum class cv_status { no_timeout, timeout }; + +class condition_variable +{ +public: + condition_variable(); + ~condition_variable(); + + condition_variable(const condition_variable&) = delete; + condition_variable& operator=(const condition_variable&) = delete; + + void notify_one(); + void notify_all(); + + void wait(unique_lock& lock); + template + void wait(unique_lock& lock, Predicate pred); + + template + cv_status + wait_until(unique_lock& lock, + const chrono::time_point& abs_time); + + template + bool + wait_until(unique_lock& lock, + const chrono::time_point& abs_time, + Predicate pred); + + template + cv_status + wait_for(unique_lock& lock, + const chrono::duration& rel_time); + + template + bool + wait_for(unique_lock& lock, + const chrono::duration& rel_time, + Predicate pred); + + typedef pthread_cond_t* native_handle_type; + native_handle_type native_handle(); +}; + +void notify_all_at_thread_exit(condition_variable& cond, unique_lock lk); + +class condition_variable_any +{ +public: + condition_variable_any(); + ~condition_variable_any(); + + condition_variable_any(const condition_variable_any&) = delete; + condition_variable_any& operator=(const condition_variable_any&) = delete; + + void notify_one(); + void notify_all(); + + template + void wait(Lock& lock); + template + void wait(Lock& lock, Predicate pred); + + template + cv_status + wait_until(Lock& lock, + const chrono::time_point& abs_time); + + template + bool + wait_until(Lock& lock, + const chrono::time_point& abs_time, + Predicate pred); + + template + cv_status + wait_for(Lock& lock, + const chrono::duration& rel_time); + + template + bool + wait_for(Lock& lock, + const chrono::duration& rel_time, + Predicate pred); +}; + +} // std + +*/ + +#include <__config> +#include <__mutex_base> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +class _LIBCPP_VISIBLE condition_variable_any +{ + condition_variable __cv_; + shared_ptr __mut_; +public: + condition_variable_any(); + + void notify_one(); + void notify_all(); + + template + void wait(_Lock& __lock); + template + void wait(_Lock& __lock, _Predicate __pred); + + template + cv_status + wait_until(_Lock& __lock, + const chrono::time_point<_Clock, _Duration>& __t); + + template + bool + wait_until(_Lock& __lock, + const chrono::time_point<_Clock, _Duration>& __t, + _Predicate __pred); + + template + cv_status + wait_for(_Lock& __lock, + const chrono::duration<_Rep, _Period>& __d); + + template + bool + wait_for(_Lock& __lock, + const chrono::duration<_Rep, _Period>& __d, + _Predicate __pred); +}; + +inline _LIBCPP_INLINE_VISIBILITY +condition_variable_any::condition_variable_any() + : __mut_(make_shared()) {} + +inline _LIBCPP_INLINE_VISIBILITY +void +condition_variable_any::notify_one() +{ + {lock_guard _(*__mut_);} + __cv_.notify_one(); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +condition_variable_any::notify_all() +{ + {lock_guard _(*__mut_);} + __cv_.notify_all(); +} + +struct __lock_external +{ + template + void operator()(_Lock* __m) {__m->lock();} +}; + +template +void +condition_variable_any::wait(_Lock& __lock) +{ + shared_ptr __mut = __mut_; + unique_lock __lk(*__mut); + __lock.unlock(); + unique_ptr<_Lock, __lock_external> __(&__lock); + lock_guard > _(__lk, adopt_lock); + __cv_.wait(__lk); +} // __mut_.unlock(), __lock.lock() + +template +inline _LIBCPP_INLINE_VISIBILITY +void +condition_variable_any::wait(_Lock& __lock, _Predicate __pred) +{ + while (!__pred()) + wait(__lock); +} + +template +cv_status +condition_variable_any::wait_until(_Lock& __lock, + const chrono::time_point<_Clock, _Duration>& __t) +{ + shared_ptr __mut = __mut_; + unique_lock __lk(*__mut); + __lock.unlock(); + unique_ptr<_Lock, __lock_external> __(&__lock); + lock_guard > _(__lk, adopt_lock); + return __cv_.wait_until(__lk, __t); +} // __mut_.unlock(), __lock.lock() + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +condition_variable_any::wait_until(_Lock& __lock, + const chrono::time_point<_Clock, _Duration>& __t, + _Predicate __pred) +{ + while (!__pred()) + if (wait_until(__lock, __t) == cv_status::timeout) + return __pred(); + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +cv_status +condition_variable_any::wait_for(_Lock& __lock, + const chrono::duration<_Rep, _Period>& __d) +{ + return wait_until(__lock, chrono::steady_clock::now() + __d); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +condition_variable_any::wait_for(_Lock& __lock, + const chrono::duration<_Rep, _Period>& __d, + _Predicate __pred) +{ + return wait_until(__lock, chrono::steady_clock::now() + __d, + _VSTD::move(__pred)); +} + +_LIBCPP_VISIBLE +void notify_all_at_thread_exit(condition_variable& cond, unique_lock lk); + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CONDITION_VARIABLE diff --git a/contrib/libc++/include/csetjmp b/contrib/libc++/include/csetjmp new file mode 100644 index 000000000000..d0b2c078967d --- /dev/null +++ b/contrib/libc++/include/csetjmp @@ -0,0 +1,52 @@ +// -*- C++ -*- +//===--------------------------- csetjmp ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSETJMP +#define _LIBCPP_CSETJMP + +/* + csetjmp synopsis + +Macros: + + setjmp + +namespace std +{ + +Types: + + jmp_buf + +void longjmp(jmp_buf env, int val); + +} // std + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifndef setjmp +#define setjmp(env) setjmp(env) +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::jmp_buf; +using ::longjmp; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSETJMP diff --git a/contrib/libc++/include/csignal b/contrib/libc++/include/csignal new file mode 100644 index 000000000000..97282661872a --- /dev/null +++ b/contrib/libc++/include/csignal @@ -0,0 +1,58 @@ +// -*- C++ -*- +//===--------------------------- csignal ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSIGNAL +#define _LIBCPP_CSIGNAL + +/* + csignal synopsis + +Macros: + + SIG_DFL + SIG_ERR + SIG_IGN + SIGABRT + SIGFPE + SIGILL + SIGINT + SIGSEGV + SIGTERM + +namespace std +{ + +Types: + + sig_atomic_t + +void (*signal(int sig, void (*func)(int)))(int); +int raise(int sig); + +} // std + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::sig_atomic_t; +using ::signal; +using ::raise; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSIGNAL diff --git a/contrib/libc++/include/cstdarg b/contrib/libc++/include/cstdarg new file mode 100644 index 000000000000..c8b6999242f7 --- /dev/null +++ b/contrib/libc++/include/cstdarg @@ -0,0 +1,48 @@ +// -*- C++ -*- +//===--------------------------- cstdarg ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDARG +#define _LIBCPP_CSTDARG + +/* + cstdarg synopsis + +Macros: + + type va_arg(va_list ap, type); + void va_copy(va_list dest, va_list src); // C99 + void va_end(va_list ap); + void va_start(va_list ap, parmN); + +namespace std +{ + +Types: + + va_list + +} // std + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::va_list; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSTDARG diff --git a/contrib/libc++/include/cstdbool b/contrib/libc++/include/cstdbool new file mode 100644 index 000000000000..2c764a61f211 --- /dev/null +++ b/contrib/libc++/include/cstdbool @@ -0,0 +1,32 @@ +// -*- C++ -*- +//===--------------------------- cstdbool ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDBOOL +#define _LIBCPP_CSTDBOOL + +/* + cstdbool synopsis + +Macros: + + __bool_true_false_are_defined + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#undef __bool_true_false_are_defined +#define __bool_true_false_are_defined 1 + +#endif // _LIBCPP_CSTDBOOL diff --git a/contrib/libc++/include/cstddef b/contrib/libc++/include/cstddef new file mode 100644 index 000000000000..48317ba0063e --- /dev/null +++ b/contrib/libc++/include/cstddef @@ -0,0 +1,102 @@ +// -*- C++ -*- +//===--------------------------- cstddef ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDDEF +#define _LIBCPP_CSTDDEF + +/* + cstddef synopsis + +Macros: + + offsetof(type,member-designator) + NULL + +namespace std +{ + +Types: + + ptrdiff_t + size_t + max_align_t + nullptr_t + +} // std + +*/ + +#include <__config> + +#ifdef __GLIBC__ +#define __need_NULL +#define __need_ptrdiff_t +#define __need_size_t +#endif // __GLIBC__ + +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::ptrdiff_t; +using ::size_t; + +typedef long double max_align_t; + +#ifdef _LIBCPP_HAS_NO_NULLPTR + +struct _LIBCPP_VISIBLE nullptr_t +{ + void* _; + + struct __nat {int __for_bool_;}; + + _LIBCPP_ALWAYS_INLINE nullptr_t(int __nat::*) {} + + _LIBCPP_ALWAYS_INLINE operator int __nat::*() const {return 0;} + + template + _LIBCPP_ALWAYS_INLINE + operator _Tp* () const {return 0;} + + template + _LIBCPP_ALWAYS_INLINE + operator _Tp _Up::* () const {return 0;} + + friend _LIBCPP_ALWAYS_INLINE bool operator==(nullptr_t, nullptr_t) {return true;} + friend _LIBCPP_ALWAYS_INLINE bool operator!=(nullptr_t, nullptr_t) {return false;} + friend _LIBCPP_ALWAYS_INLINE bool operator<(nullptr_t, nullptr_t) {return false;} + friend _LIBCPP_ALWAYS_INLINE bool operator<=(nullptr_t, nullptr_t) {return true;} + friend _LIBCPP_ALWAYS_INLINE bool operator>(nullptr_t, nullptr_t) {return false;} + friend _LIBCPP_ALWAYS_INLINE bool operator>=(nullptr_t, nullptr_t) {return true;} +}; + +inline _LIBCPP_ALWAYS_INLINE nullptr_t __get_nullptr_t() {return nullptr_t(0);} + +#define nullptr _VSTD::__get_nullptr_t() + +#endif // _LIBCPP_HAS_NO_NULLPTR + +_LIBCPP_END_NAMESPACE_STD + +#ifndef _LIBCPP_HAS_NO_NULLPTR + +namespace std +{ + typedef decltype(nullptr) nullptr_t; +} + +#endif // _LIBCPP_HAS_NO_NULLPTR + +#endif // _LIBCPP_CSTDDEF diff --git a/contrib/libc++/include/cstdint b/contrib/libc++/include/cstdint new file mode 100644 index 000000000000..7a187d3ebf28 --- /dev/null +++ b/contrib/libc++/include/cstdint @@ -0,0 +1,191 @@ +// -*- C++ -*- +//===--------------------------- cstdint ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDINT +#define _LIBCPP_CSTDINT + +/* + cstdint synopsis + +Macros: + + INT8_MIN + INT16_MIN + INT32_MIN + INT64_MIN + + INT8_MAX + INT16_MAX + INT32_MAX + INT64_MAX + + UINT8_MAX + UINT16_MAX + UINT32_MAX + UINT64_MAX + + INT_LEAST8_MIN + INT_LEAST16_MIN + INT_LEAST32_MIN + INT_LEAST64_MIN + + INT_LEAST8_MAX + INT_LEAST16_MAX + INT_LEAST32_MAX + INT_LEAST64_MAX + + UINT_LEAST8_MAX + UINT_LEAST16_MAX + UINT_LEAST32_MAX + UINT_LEAST64_MAX + + INT_FAST8_MIN + INT_FAST16_MIN + INT_FAST32_MIN + INT_FAST64_MIN + + INT_FAST8_MAX + INT_FAST16_MAX + INT_FAST32_MAX + INT_FAST64_MAX + + UINT_FAST8_MAX + UINT_FAST16_MAX + UINT_FAST32_MAX + UINT_FAST64_MAX + + INTPTR_MIN + INTPTR_MAX + UINTPTR_MAX + + INTMAX_MIN + INTMAX_MAX + + UINTMAX_MAX + + PTRDIFF_MIN + PTRDIFF_MAX + + SIG_ATOMIC_MIN + SIG_ATOMIC_MAX + + SIZE_MAX + + WCHAR_MIN + WCHAR_MAX + + WINT_MIN + WINT_MAX + + INT8_C(value) + INT16_C(value) + INT32_C(value) + INT64_C(value) + + UINT8_C(value) + UINT16_C(value) + UINT32_C(value) + UINT64_C(value) + + INTMAX_C(value) + UINTMAX_C(value) + +namespace std +{ + +Types: + + int8_t + int16_t + int32_t + int64_t + + uint8_t + uint16_t + uint32_t + uint64_t + + int_least8_t + int_least16_t + int_least32_t + int_least64_t + + uint_least8_t + uint_least16_t + uint_least32_t + uint_least64_t + + int_fast8_t + int_fast16_t + int_fast32_t + int_fast64_t + + uint_fast8_t + uint_fast16_t + uint_fast32_t + uint_fast64_t + + intptr_t + uintptr_t + + intmax_t + uintmax_t + +} // std +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using::int8_t; +using::int16_t; +using::int32_t; +using::int64_t; + +using::uint8_t; +using::uint16_t; +using::uint32_t; +using::uint64_t; + +using::int_least8_t; +using::int_least16_t; +using::int_least32_t; +using::int_least64_t; + +using::uint_least8_t; +using::uint_least16_t; +using::uint_least32_t; +using::uint_least64_t; + +using::int_fast8_t; +using::int_fast16_t; +using::int_fast32_t; +using::int_fast64_t; + +using::uint_fast8_t; +using::uint_fast16_t; +using::uint_fast32_t; +using::uint_fast64_t; + +using::intptr_t; +using::uintptr_t; + +using::intmax_t; +using::uintmax_t; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSTDINT diff --git a/contrib/libc++/include/cstdio b/contrib/libc++/include/cstdio new file mode 100644 index 000000000000..2a6ec762deae --- /dev/null +++ b/contrib/libc++/include/cstdio @@ -0,0 +1,163 @@ +// -*- C++ -*- +//===---------------------------- cstdio ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDIO +#define _LIBCPP_CSTDIO + +/* + cstdio synopsis + +Macros: + + BUFSIZ + EOF + FILENAME_MAX + FOPEN_MAX + L_tmpnam + NULL + SEEK_CUR + SEEK_END + SEEK_SET + TMP_MAX + _IOFBF + _IOLBF + _IONBF + stderr + stdin + stdout + +namespace std +{ + +Types: + +FILE +fpos_t +size_t + +int remove(const char* filename); +int rename(const char* old, const char* new); +FILE* tmpfile(void); +char* tmpnam(char* s); +int fclose(FILE* stream); +int fflush(FILE* stream); +FILE* fopen(const char* restrict filename, const char* restrict mode); +FILE* freopen(const char* restrict filename, const char * restrict mode, + FILE * restrict stream); +void setbuf(FILE* restrict stream, char* restrict buf); +int setvbuf(FILE* restrict stream, char* restrict buf, int mode, size_t size); +int fprintf(FILE* restrict stream, const char* restrict format, ...); +int fscanf(FILE* restrict stream, const char * restrict format, ...); +int printf(const char* restrict format, ...); +int scanf(const char* restrict format, ...); +int snprintf(char* restrict s, size_t n, const char* restrict format, ...); // C99 +int sprintf(char* restrict s, const char* restrict format, ...); +int sscanf(const char* restrict s, const char* restrict format, ...); +int vfprintf(FILE* restrict stream, const char* restrict format, va_list arg); +int vfscanf(FILE* restrict stream, const char* restrict format, va_list arg); // C99 +int vprintf(const char* restrict format, va_list arg); +int vscanf(const char* restrict format, va_list arg); // C99 +int vsnprintf(char* restrict s, size_t n, const char* restrict format, // C99 + va_list arg); +int vsprintf(char* restrict s, const char* restrict format, va_list arg); +int vsscanf(const char* restrict s, const char* restrict format, va_list arg); // C99 +int fgetc(FILE* stream); +char* fgets(char* restrict s, int n, FILE* restrict stream); +int fputc(int c, FILE* stream); +int fputs(const char* restrict s, FILE* restrict stream); +int getc(FILE* stream); +int getchar(void); +char* gets(char* s); +int putc(int c, FILE* stream); +int putchar(int c); +int puts(const char* s); +int ungetc(int c, FILE* stream); +size_t fread(void* restrict ptr, size_t size, size_t nmemb, + FILE* restrict stream); +size_t fwrite(const void* restrict ptr, size_t size, size_t nmemb, + FILE* restrict stream); +int fgetpos(FILE* restrict stream, fpos_t* restrict pos); +int fseek(FILE* stream, long offset, int whence); +int fsetpos(FILE*stream, const fpos_t* pos); +long ftell(FILE* stream); +void rewind(FILE* stream); +void clearerr(FILE* stream); +int feof(FILE* stream); +int ferror(FILE* stream); +void perror(const char* s); + +} // std +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::FILE; +using ::fpos_t; +using ::size_t; + +using ::remove; +using ::rename; +using ::tmpfile; +using ::tmpnam; +using ::fclose; +using ::fflush; +using ::fopen; +using ::freopen; +using ::setbuf; +using ::setvbuf; +using ::fprintf; +using ::fscanf; +using ::printf; +using ::scanf; +using ::snprintf; +using ::sprintf; +using ::sscanf; +#ifndef _MSC_VER +using ::vfprintf; +using ::vfscanf; +using ::vscanf; +using ::vsscanf; +#endif // _MSC_VER +using ::vprintf; +using ::vsnprintf; +using ::vsprintf; +using ::fgetc; +using ::fgets; +using ::fputc; +using ::fputs; +using ::getc; +using ::getchar; +using ::gets; +using ::putc; +using ::putchar; +using ::puts; +using ::ungetc; +using ::fread; +using ::fwrite; +using ::fgetpos; +using ::fseek; +using ::fsetpos; +using ::ftell; +using ::rewind; +using ::clearerr; +using ::feof; +using ::ferror; +using ::perror; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSTDIO diff --git a/contrib/libc++/include/cstdlib b/contrib/libc++/include/cstdlib new file mode 100644 index 000000000000..5d8a9d73464b --- /dev/null +++ b/contrib/libc++/include/cstdlib @@ -0,0 +1,145 @@ +// -*- C++ -*- +//===--------------------------- cstdlib ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTDLIB +#define _LIBCPP_CSTDLIB + +/* + cstdlib synopsis + +Macros: + + EXIT_FAILURE + EXIT_SUCCESS + MB_CUR_MAX + NULL + RAND_MAX + +namespace std +{ + +Types: + + size_t + div_t + ldiv_t + lldiv_t // C99 + +double atof (const char* nptr); +int atoi (const char* nptr); +long atol (const char* nptr); +long long atoll(const char* nptr); // C99 +double strtod (const char* restrict nptr, char** restrict endptr); +float strtof (const char* restrict nptr, char** restrict endptr); // C99 +long double strtold (const char* restrict nptr, char** restrict endptr); // C99 +long strtol (const char* restrict nptr, char** restrict endptr, int base); +long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99 +unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base); +unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99 +int rand(void); +void srand(unsigned int seed); +void* calloc(size_t nmemb, size_t size); +void free(void* ptr); +void* malloc(size_t size); +void* realloc(void* ptr, size_t size); +void abort(void); +int atexit(void (*func)(void)); +void exit(int status); +void _Exit(int status); +char* getenv(const char* name); +int system(const char* string); +void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)); +void qsort(void* base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)); +int abs( int j); +long abs( long j); +long long abs(long long j); // C++0X +long labs( long j); +long long llabs(long long j); // C99 +div_t div( int numer, int denom); +ldiv_t div( long numer, long denom); +lldiv_t div(long long numer, long long denom); // C++0X +ldiv_t ldiv( long numer, long denom); +lldiv_t lldiv(long long numer, long long denom); // C99 +int mblen(const char* s, size_t n); +int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n); +int wctomb(char* s, wchar_t wchar); +size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n); +size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n); + +} // std + +*/ + +#include <__config> +#include +#ifdef _MSC_VER +#include "support/win32/locale_win32.h" +#endif // _MSC_VER + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::size_t; +using ::div_t; +using ::ldiv_t; +using ::lldiv_t; +using ::atof; +using ::atoi; +using ::atol; +using ::atoll; +using ::strtod; +using ::strtof; +using ::strtold; +using ::strtol; +using ::strtoll; +using ::strtoul; +using ::strtoull; +using ::rand; +using ::srand; +using ::calloc; +using ::free; +using ::malloc; +using ::realloc; +using ::abort; +using ::atexit; +using ::exit; +using ::_Exit; +using ::getenv; +using ::system; +using ::bsearch; +using ::qsort; +using ::abs; +using ::labs; +using ::llabs; +using ::div; +using ::ldiv; +using ::lldiv; +using ::mblen; +using ::mbtowc; +using ::wctomb; +using ::mbstowcs; +using ::wcstombs; + +#ifndef _MSC_VER // MSVC already has the correct prototype in #ifdef __cplusplus +inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) {return labs(__x);} +inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) {return llabs(__x);} + +inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) {return ldiv(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) {return lldiv(__x, __y);} +#endif // _MSC_VER + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSTDLIB diff --git a/contrib/libc++/include/cstring b/contrib/libc++/include/cstring new file mode 100644 index 000000000000..dd49d802d5e0 --- /dev/null +++ b/contrib/libc++/include/cstring @@ -0,0 +1,112 @@ +// -*- C++ -*- +//===--------------------------- cstring ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CSTRING +#define _LIBCPP_CSTRING + +/* + cstring synopsis + +Macros: + + NULL + +namespace std +{ + +Types: + + size_t + +void* memcpy(void* restrict s1, const void* restrict s2, size_t n); +void* memmove(void* s1, const void* s2, size_t n); +char* strcpy (char* restrict s1, const char* restrict s2); +char* strncpy(char* restrict s1, const char* restrict s2, size_t n); +char* strcat (char* restrict s1, const char* restrict s2); +char* strncat(char* restrict s1, const char* restrict s2, size_t n); +int memcmp(const void* s1, const void* s2, size_t n); +int strcmp (const char* s1, const char* s2); +int strncmp(const char* s1, const char* s2, size_t n); +int strcoll(const char* s1, const char* s2); +size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n); +const void* memchr(const void* s, int c, size_t n); + void* memchr( void* s, int c, size_t n); +const char* strchr(const char* s, int c); + char* strchr( char* s, int c); +size_t strcspn(const char* s1, const char* s2); +const char* strpbrk(const char* s1, const char* s2); + char* strpbrk( char* s1, const char* s2); +const char* strrchr(const char* s, int c); + char* strrchr( char* s, int c); +size_t strspn(const char* s1, const char* s2); +const char* strstr(const char* s1, const char* s2); + char* strstr( char* s1, const char* s2); +char* strtok(char* restrict s1, const char* restrict s2); +void* memset(void* s, int c, size_t n); +char* strerror(int errnum); +size_t strlen(const char* s); + +} // std + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::size_t; +using ::memcpy; +using ::memmove; +using ::strcpy; +using ::strncpy; +using ::strcat; +using ::strncat; +using ::memcmp; +using ::strcmp; +using ::strncmp; +using ::strcoll; +using ::strxfrm; + +using ::memchr; + +using ::strchr; + +using ::strcspn; + +using ::strpbrk; + +using ::strrchr; + +using ::strspn; + +using ::strstr; + +// MSVC, GNU libc and its derivates already have the correct prototype in #ifdef __cplusplus +#if !defined(__GLIBC__) && !defined(_MSC_VER) +inline _LIBCPP_INLINE_VISIBILITY char* strchr( char* __s, int __c) {return ::strchr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY char* strpbrk( char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY char* strrchr( char* __s, int __c) {return ::strrchr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY void* memchr( void* __s, int __c, size_t __n) {return ::memchr(__s, __c, __n);} +inline _LIBCPP_INLINE_VISIBILITY char* strstr( char* __s1, const char* __s2) {return ::strstr(__s1, __s2);} +#endif + +using ::strtok; +using ::memset; +using ::strerror; +using ::strlen; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CSTRING diff --git a/contrib/libc++/include/ctgmath b/contrib/libc++/include/ctgmath new file mode 100644 index 000000000000..535eb7dccd15 --- /dev/null +++ b/contrib/libc++/include/ctgmath @@ -0,0 +1,29 @@ +// -*- C++ -*- +//===-------------------------- ctgmath -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CTGMATH +#define _LIBCPP_CTGMATH + +/* + ctgmath synopsis + +#include +#include + +*/ + +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#endif // _LIBCPP_CTGMATH diff --git a/contrib/libc++/include/ctime b/contrib/libc++/include/ctime new file mode 100644 index 000000000000..fc4eb26f5430 --- /dev/null +++ b/contrib/libc++/include/ctime @@ -0,0 +1,72 @@ +// -*- C++ -*- +//===---------------------------- ctime -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CTIME +#define _LIBCPP_CTIME + +/* + ctime synopsis + +Macros: + + NULL + CLOCKS_PER_SEC + +namespace std +{ + +Types: + + clock_t + size_t + time_t + tm + +clock_t clock(); +double difftime(time_t time1, time_t time0); +time_t mktime(tm* timeptr); +time_t time(time_t* timer); +char* asctime(const tm* timeptr); +char* ctime(const time_t* timer); +tm* gmtime(const time_t* timer); +tm* localtime(const time_t* timer); +size_t strftime(char* restrict s, size_t maxsize, const char* restrict format, + const tm* restrict timeptr); + +} // std + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::clock_t; +using ::size_t; +using ::time_t; +using ::tm; +using ::clock; +using ::difftime; +using ::mktime; +using ::time; +using ::asctime; +using ::ctime; +using ::gmtime; +using ::localtime; +using ::strftime; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CTIME diff --git a/contrib/libc++/include/cwchar b/contrib/libc++/include/cwchar new file mode 100644 index 000000000000..8e788fc764e1 --- /dev/null +++ b/contrib/libc++/include/cwchar @@ -0,0 +1,204 @@ +// -*- C++ -*- +//===--------------------------- cwchar -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CWCHAR +#define _LIBCPP_CWCHAR + +/* + cwchar synopsis + +Macros: + + NULL + WCHAR_MAX + WCHAR_MIN + WEOF + +namespace std +{ + +Types: + + mbstate_t + size_t + tm + wint_t + +int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...); +int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...); +int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, ...); +int swscanf(const wchar_t* restrict s, const wchar_t* restrict format, ...); +int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list arg); +int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list arg); // C99 +int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, va_list arg); +int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format, va_list arg); // C99 +int vwprintf(const wchar_t* restrict format, va_list arg); +int vwscanf(const wchar_t* restrict format, va_list arg); // C99 +int wprintf(const wchar_t* restrict format, ...); +int wscanf(const wchar_t* restrict format, ...); +wint_t fgetwc(FILE* stream); +wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream); +wint_t fputwc(wchar_t c, FILE* stream); +int fputws(const wchar_t* restrict s, FILE* restrict stream); +int fwide(FILE* stream, int mode); +wint_t getwc(FILE* stream); +wint_t getwchar(); +wint_t putwc(wchar_t c, FILE* stream); +wint_t putwchar(wchar_t c); +wint_t ungetwc(wint_t c, FILE* stream); +double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr); +float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99 +long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99 +long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); +long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99 +unsigned long wcstoul(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); +unsigned long long wcstoull(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99 +wchar_t* wcscpy(wchar_t* restrict s1, const wchar_t* restrict s2); +wchar_t* wcsncpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +wchar_t* wcscat(wchar_t* restrict s1, const wchar_t* restrict s2); +wchar_t* wcsncat(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +int wcscmp(const wchar_t* s1, const wchar_t* s2); +int wcscoll(const wchar_t* s1, const wchar_t* s2); +int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n); +size_t wcsxfrm(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +const wchar_t* wcschr(const wchar_t* s, wchar_t c); + wchar_t* wcschr( wchar_t* s, wchar_t c); +size_t wcscspn(const wchar_t* s1, const wchar_t* s2); +size_t wcslen(const wchar_t* s); +const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2); + wchar_t* wcspbrk( wchar_t* s1, const wchar_t* s2); +const wchar_t* wcsrchr(const wchar_t* s, wchar_t c); + wchar_t* wcsrchr( wchar_t* s, wchar_t c); +size_t wcsspn(const wchar_t* s1, const wchar_t* s2); +const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2); + wchar_t* wcsstr( wchar_t* s1, const wchar_t* s2); +wchar_t* wcstok(wchar_t* restrict s1, const wchar_t* restrict s2, wchar_t** restrict ptr); +const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n); + wchar_t* wmemchr( wchar_t* s, wchar_t c, size_t n); +int wmemcmp(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +wchar_t* wmemcpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); +wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n); +wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n); +size_t wcsftime(wchar_t* restrict s, size_t maxsize, const wchar_t* restrict format, + const tm* restrict timeptr); +wint_t btowc(int c); +int wctob(wint_t c); +int mbsinit(const mbstate_t* ps); +size_t mbrlen(const char* restrict s, size_t n, mbstate_t* restrict ps); +size_t mbrtowc(wchar_t* restrict pwc, const char* restrict s, size_t n, mbstate_t* restrict ps); +size_t wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps); +size_t mbsrtowcs(wchar_t* restrict dst, const char** restrict src, size_t len, + mbstate_t* restrict ps); +size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, + mbstate_t* restrict ps); + +} // std + +*/ + +#include <__config> +#include +#include +#if _WIN32 +#include // pull in *swprintf defines +#endif // _WIN32 + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::mbstate_t; +using ::size_t; +using ::tm; +using ::wint_t; +using ::FILE; +using ::fwprintf; +using ::fwscanf; +using ::swprintf; +using ::vfwprintf; +using ::vswprintf; +using ::vwprintf; +#ifndef _MSC_VER +using ::swscanf; +using ::vfwscanf; +using ::vswscanf; +using ::vwscanf; +#endif // _MSC_VER +using ::wprintf; +using ::wscanf; +using ::fgetwc; +using ::fgetws; +using ::fputwc; +using ::fputws; +using ::fwide; +using ::getwc; +using ::getwchar; +using ::putwc; +using ::putwchar; +using ::ungetwc; +using ::wcstod; +#ifndef _MSC_VER +using ::wcstof; +using ::wcstold; +#endif // _MSC_VER +using ::wcstol; +using ::wcstoll; +using ::wcstoul; +using ::wcstoull; +using ::wcscpy; +using ::wcsncpy; +using ::wcscat; +using ::wcsncat; +using ::wcscmp; +using ::wcscoll; +using ::wcsncmp; +using ::wcsxfrm; + +inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);} + +using ::wcscspn; +using ::wcslen; + +inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY wchar_t* wcspbrk( wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);} + +inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);} +inline _LIBCPP_INLINE_VISIBILITY wchar_t* wcsrchr( wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);} + +using ::wcsspn; + +inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);} +inline _LIBCPP_INLINE_VISIBILITY wchar_t* wcsstr( wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);} + +using ::wcstok; + +inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);} +inline _LIBCPP_INLINE_VISIBILITY wchar_t* wmemchr( wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);} + +using ::wmemcmp; +using ::wmemcpy; +using ::wmemmove; +using ::wmemset; +using ::wcsftime; +using ::btowc; +using ::wctob; +using ::mbsinit; +using ::mbrlen; +using ::mbrtowc; +using ::wcrtomb; +using ::mbsrtowcs; +using ::wcsrtombs; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CWCHAR diff --git a/contrib/libc++/include/cwctype b/contrib/libc++/include/cwctype new file mode 100644 index 000000000000..4f89b52db27c --- /dev/null +++ b/contrib/libc++/include/cwctype @@ -0,0 +1,213 @@ +// -*- C++ -*- +//===--------------------------- cwctype ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CWCTYPE +#define _LIBCPP_CWCTYPE + +/* + cwctype synopsis + +Macros: + + WEOF + +namespace std +{ + +Types: + + wint_t + wctrans_t + wctype_t + +int iswalnum(wint_t wc); +int iswalpha(wint_t wc); +int iswblank(wint_t wc); // C99 +int iswcntrl(wint_t wc); +int iswdigit(wint_t wc); +int iswgraph(wint_t wc); +int iswlower(wint_t wc); +int iswprint(wint_t wc); +int iswpunct(wint_t wc); +int iswspace(wint_t wc); +int iswupper(wint_t wc); +int iswxdigit(wint_t wc); +int iswctype(wint_t wc, wctype_t desc); +wctype_t wctype(const char* property); +wint_t towlower(wint_t wc); +wint_t towupper(wint_t wc); +wint_t towctrans(wint_t wc, wctrans_t desc); +wctrans_t wctrans(const char* property); + +} // std + +*/ + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ::wint_t; +using ::wctrans_t; +using ::wctype_t; + +#ifdef iswalnum +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswalnum(wint_t __wc) {return iswalnum(__wc);} +#undef iswalnum +inline _LIBCPP_INLINE_VISIBILITY int iswalnum(wint_t __wc) {return __libcpp_iswalnum(__wc);} +#else // iswalnum +using ::iswalnum; +#endif + +#ifdef iswalpha +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswalpha(wint_t __wc) {return iswalpha(__wc);} +#undef iswalpha +inline _LIBCPP_INLINE_VISIBILITY int iswalpha(wint_t __wc) {return __libcpp_iswalpha(__wc);} +#else // iswalpha +using ::iswalpha; +#endif + +#ifdef iswblank +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswblank(wint_t __wc) {return iswblank(__wc);} +#undef iswblank +inline _LIBCPP_INLINE_VISIBILITY int iswblank(wint_t __wc) {return __libcpp_iswblank(__wc);} +#else // iswblank +using ::iswblank; +#endif + +#ifdef iswcntrl +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswcntrl(wint_t __wc) {return iswcntrl(__wc);} +#undef iswcntrl +inline _LIBCPP_INLINE_VISIBILITY int iswcntrl(wint_t __wc) {return __libcpp_iswcntrl(__wc);} +#else // iswcntrl +using ::iswcntrl; +#endif + +#ifdef iswdigit +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswdigit(wint_t __wc) {return iswdigit(__wc);} +#undef iswdigit +inline _LIBCPP_INLINE_VISIBILITY int iswdigit(wint_t __wc) {return __libcpp_iswdigit(__wc);} +#else // iswdigit +using ::iswdigit; +#endif + +#ifdef iswgraph +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswgraph(wint_t __wc) {return iswgraph(__wc);} +#undef iswgraph +inline _LIBCPP_INLINE_VISIBILITY int iswgraph(wint_t __wc) {return __libcpp_iswgraph(__wc);} +#else // iswgraph +using ::iswgraph; +#endif + +#ifdef iswlower +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswlower(wint_t __wc) {return iswlower(__wc);} +#undef iswlower +inline _LIBCPP_INLINE_VISIBILITY int iswlower(wint_t __wc) {return __libcpp_iswlower(__wc);} +#else // iswlower +using ::iswlower; +#endif + +#ifdef iswprint +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswprint(wint_t __wc) {return iswprint(__wc);} +#undef iswprint +inline _LIBCPP_INLINE_VISIBILITY int iswprint(wint_t __wc) {return __libcpp_iswprint(__wc);} +#else // iswprint +using ::iswprint; +#endif + +#ifdef iswpunct +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswpunct(wint_t __wc) {return iswpunct(__wc);} +#undef iswpunct +inline _LIBCPP_INLINE_VISIBILITY int iswpunct(wint_t __wc) {return __libcpp_iswpunct(__wc);} +#else // iswpunct +using ::iswpunct; +#endif + +#ifdef iswspace +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswspace(wint_t __wc) {return iswspace(__wc);} +#undef iswspace +inline _LIBCPP_INLINE_VISIBILITY int iswspace(wint_t __wc) {return __libcpp_iswspace(__wc);} +#else // iswspace +using ::iswspace; +#endif + +#ifdef iswupper +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswupper(wint_t __wc) {return iswupper(__wc);} +#undef iswupper +inline _LIBCPP_INLINE_VISIBILITY int iswupper(wint_t __wc) {return __libcpp_iswupper(__wc);} +#else // iswupper +using ::iswupper; +#endif + +#ifdef iswxdigit +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswxdigit(wint_t __wc) {return iswxdigit(__wc);} +#undef iswxdigit +inline _LIBCPP_INLINE_VISIBILITY int iswxdigit(wint_t __wc) {return __libcpp_iswxdigit(__wc);} +#else // iswxdigit +using ::iswxdigit; +#endif + +#ifdef iswctype +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswctype(wint_t __w, wctype_t __d) {return iswctype(__w, __d);} +#undef iswctype +inline _LIBCPP_INLINE_VISIBILITY int iswctype(wint_t __w, wctype_t __d) {return __libcpp_iswctype(__w, __d);} +#else // iswctype +using ::iswctype; +#endif + +#ifdef wctype +inline _LIBCPP_INLINE_VISIBILITY wctype_t __libcpp_wctype(const char* __p) {return wctype(__p);} +#undef wctype +inline _LIBCPP_INLINE_VISIBILITY wctype_t wctype(const char* __p) {return __libcpp_wctype(__p);} +#else // wctype +using ::wctype; +#endif + +#ifdef towlower +inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towlower(wint_t __wc) {return towlower(__wc);} +#undef towlower +inline _LIBCPP_INLINE_VISIBILITY wint_t towlower(wint_t __wc) {return __libcpp_towlower(__wc);} +#else // towlower +using ::towlower; +#endif + +#ifdef towupper +inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towupper(wint_t __wc) {return towupper(__wc);} +#undef towupper +inline _LIBCPP_INLINE_VISIBILITY wint_t towupper(wint_t __wc) {return __libcpp_towupper(__wc);} +#else // towupper +using ::towupper; +#endif + +#ifdef towctrans +inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towctrans(wint_t __wc, wctype_t __d) {return towctrans(__wc, __d);} +#undef towctrans +inline _LIBCPP_INLINE_VISIBILITY wint_t towctrans(wint_t __wc, wctype_t __d) {return __libcpp_towctrans(__wc, __d);} +#else // towctrans +using ::towctrans; +#endif + +#ifdef wctrans +inline _LIBCPP_INLINE_VISIBILITY wctrans_t __libcpp_wctrans(const char* __p) {return wctrans(__p);} +#undef wctrans +inline _LIBCPP_INLINE_VISIBILITY wctrans_t wctrans(const char* __p) {return __libcpp_wctrans(__p);} +#else // wctrans +using ::wctrans; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CWCTYPE diff --git a/contrib/libc++/include/deque b/contrib/libc++/include/deque new file mode 100644 index 000000000000..ab9ba58b0286 --- /dev/null +++ b/contrib/libc++/include/deque @@ -0,0 +1,2842 @@ +// -*- C++ -*- +//===---------------------------- deque -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_DEQUE +#define _LIBCPP_DEQUE + +/* + deque synopsis + +namespace std +{ + +template > +class deque +{ +public: + // types: + typedef T value_type; + typedef Allocator allocator_type; + + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + // construct/copy/destroy: + deque() noexcept(is_nothrow_default_constructible::value); + explicit deque(const allocator_type& a); + explicit deque(size_type n); + deque(size_type n, const value_type& v); + deque(size_type n, const value_type& v, const allocator_type& a); + template + deque(InputIterator f, InputIterator l); + template + deque(InputIterator f, InputIterator l, const allocator_type& a); + deque(const deque& c); + deque(deque&& c) + noexcept(is_nothrow_move_constructible::value); + deque(initializer_list il, const Allocator& a = allocator_type()); + deque(const deque& c, const allocator_type& a); + deque(deque&& c, const allocator_type& a); + ~deque(); + + deque& operator=(const deque& c); + deque& operator=(deque&& c) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value); + deque& operator=(initializer_list il); + + template + void assign(InputIterator f, InputIterator l); + void assign(size_type n, const value_type& v); + void assign(initializer_list il); + + allocator_type get_allocator() const noexcept; + + // iterators: + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // capacity: + size_type size() const noexcept; + size_type max_size() const noexcept; + void resize(size_type n); + void resize(size_type n, const value_type& v); + void shrink_to_fit(); + bool empty() const noexcept; + + // element access: + reference operator[](size_type i); + const_reference operator[](size_type i) const; + reference at(size_type i); + const_reference at(size_type i) const; + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + // modifiers: + void push_front(const value_type& v); + void push_front(value_type&& v); + void push_back(const value_type& v); + void push_back(value_type&& v); + template void emplace_front(Args&&... args); + template void emplace_back(Args&&... args); + template iterator emplace(const_iterator p, Args&&... args); + iterator insert(const_iterator p, const value_type& v); + iterator insert(const_iterator p, value_type&& v); + iterator insert(const_iterator p, size_type n, const value_type& v); + template + iterator insert (const_iterator p, InputIterator f, InputIterator l); + iterator insert(const_iterator p, initializer_list il); + void pop_front(); + void pop_back(); + iterator erase(const_iterator p); + iterator erase(const_iterator f, const_iterator l); + void swap(deque& c) + noexcept(!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable::value); + void clear() noexcept; +}; + +template + bool operator==(const deque& x, const deque& y); +template + bool operator< (const deque& x, const deque& y); +template + bool operator!=(const deque& x, const deque& y); +template + bool operator> (const deque& x, const deque& y); +template + bool operator>=(const deque& x, const deque& y); +template + bool operator<=(const deque& x, const deque& y); + +// specialized algorithms: +template + void swap(deque& x, deque& y) + noexcept(noexcept(x.swap(y))); + +} // std + +*/ + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include <__config> +#include <__split_buffer> +#include +#include +#include +#include +#include + +_LIBCPP_BEGIN_NAMESPACE_STD + +template class __deque_base; + +template +class _LIBCPP_VISIBLE __deque_iterator; + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); + +template +_OutputIterator +copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); + +template +_OutputIterator +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); + +template +_OutputIterator +move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); + +template +_OutputIterator +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + +template +class _LIBCPP_VISIBLE __deque_iterator +{ + typedef _MapPointer __map_iterator; +public: + typedef _Pointer pointer; + typedef _DiffType difference_type; +private: + __map_iterator __m_iter_; + pointer __ptr_; + + static const difference_type __block_size = _BlockSize; +public: + typedef _ValueType value_type; + typedef random_access_iterator_tag iterator_category; + typedef _Reference reference; + + _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT {} + + template + _LIBCPP_INLINE_VISIBILITY + __deque_iterator(const __deque_iterator& __it, + typename enable_if::value>::type* = 0) _NOEXCEPT + : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;} + + _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++() + { + if (++__ptr_ - *__m_iter_ == __block_size) + { + ++__m_iter_; + __ptr_ = *__m_iter_; + } + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int) + { + __deque_iterator __tmp = *this; + ++(*this); + return __tmp; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--() + { + if (__ptr_ == *__m_iter_) + { + --__m_iter_; + __ptr_ = *__m_iter_ + __block_size; + } + --__ptr_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int) + { + __deque_iterator __tmp = *this; + --(*this); + return __tmp; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n) + { + if (__n != 0) + { + __n += __ptr_ - *__m_iter_; + if (__n > 0) + { + __m_iter_ += __n / __block_size; + __ptr_ = *__m_iter_ + __n % __block_size; + } + else // (__n < 0) + { + difference_type __z = __block_size - 1 - __n; + __m_iter_ -= __z / __block_size; + __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size); + } + } + return *this; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n) + { + return *this += -__n; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const + { + __deque_iterator __t(*this); + __t += __n; + return __t; + } + + _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const + { + __deque_iterator __t(*this); + __t -= __n; + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it) + {return __it + __n;} + + _LIBCPP_INLINE_VISIBILITY + friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y) + { + if (__x != __y) + return (__x.__m_iter_ - __y.__m_iter_) * __block_size + + (__x.__ptr_ - *__x.__m_iter_) + - (__y.__ptr_ - *__y.__m_iter_); + return 0; + } + + _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const + {return *(*this + __n);} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator==(const __deque_iterator& __x, const __deque_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) + {return !(__x == __y);} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) + {return __x.__m_iter_ < __y.__m_iter_ || + (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator>(const __deque_iterator& __x, const __deque_iterator& __y) + {return __y < __x;} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y) + {return !(__y < __x);} + + _LIBCPP_INLINE_VISIBILITY friend + bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) + {return !(__x < __y);} + +private: + _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT + : __m_iter_(__m), __ptr_(__p) {} + + template friend class __deque_base; + template friend class _LIBCPP_VISIBLE deque; + template + friend class _LIBCPP_VISIBLE __deque_iterator; + + template + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + copy(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); + + template + friend + _OutputIterator + copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + + template + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + + template + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + copy_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); + + template + friend + _OutputIterator + copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + + template + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + + template + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + move(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); + + template + friend + _OutputIterator + move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + + template + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + + template + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + move_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); + + template + friend + _OutputIterator + move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r); + + template + friend + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); +}; + +// copy + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) +{ + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + while (__f != __l) + { + pointer __rb = __r.__ptr_; + pointer __re = *__r.__m_iter_ + _B2; + difference_type __bs = __re - __rb; + difference_type __n = __l - __f; + _RAIter __m = __l; + if (__n > __bs) + { + __n = __bs; + __m = __f + __n; + } + _VSTD::copy(__f, __m, __rb); + __f = __m; + __r += __n; + } + return __r; +} + +template +_OutputIterator +copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + _B1; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + __r = _VSTD::copy(__fb, __fe, __r); + __n -= __bs; + __f += __bs; + } + return __r; +} + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + _B1; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + __r = _VSTD::copy(__fb, __fe, __r); + __n -= __bs; + __f += __bs; + } + return __r; +} + +// copy_backward + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) +{ + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + while (__f != __l) + { + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); + pointer __rb = *__rp.__m_iter_; + pointer __re = __rp.__ptr_ + 1; + difference_type __bs = __re - __rb; + difference_type __n = __l - __f; + _RAIter __m = __f; + if (__n > __bs) + { + __n = __bs; + __m = __l - __n; + } + _VSTD::copy_backward(__m, __l, __re); + __l = __m; + __r -= __n; + } + return __r; +} + +template +_OutputIterator +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + __r = _VSTD::copy_backward(__lb, __le, __r); + __n -= __bs; + __l -= __bs - 1; + } + return __r; +} + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + __r = _VSTD::copy_backward(__lb, __le, __r); + __n -= __bs; + __l -= __bs - 1; + } + return __r; +} + +// move + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) +{ + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + while (__f != __l) + { + pointer __rb = __r.__ptr_; + pointer __re = *__r.__m_iter_ + _B2; + difference_type __bs = __re - __rb; + difference_type __n = __l - __f; + _RAIter __m = __l; + if (__n > __bs) + { + __n = __bs; + __m = __f + __n; + } + _VSTD::move(__f, __m, __rb); + __f = __m; + __r += __n; + } + return __r; +} + +template +_OutputIterator +move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + _B1; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + __r = _VSTD::move(__fb, __fe, __r); + __n -= __bs; + __f += __bs; + } + return __r; +} + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + _B1; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + __r = _VSTD::move(__fb, __fe, __r); + __n -= __bs; + __f += __bs; + } + return __r; +} + +// move_backward + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move_backward(_RAIter __f, + _RAIter __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) +{ + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + while (__f != __l) + { + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); + pointer __rb = *__rp.__m_iter_; + pointer __re = __rp.__ptr_ + 1; + difference_type __bs = __re - __rb; + difference_type __n = __l - __f; + _RAIter __m = __f; + if (__n > __bs) + { + __n = __bs; + __m = __l - __n; + } + _VSTD::move_backward(__m, __l, __re); + __l = __m; + __r -= __n; + } + return __r; +} + +template +_OutputIterator +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + _OutputIterator __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + __r = _VSTD::move_backward(__lb, __le, __r); + __n -= __bs; + __l -= __bs - 1; + } + return __r; +} + +template +__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +{ + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + __r = _VSTD::move_backward(__lb, __le, __r); + __n -= __bs; + __l -= __bs - 1; + } + return __r; +} + +template +class __deque_base_common +{ +protected: + void __throw_length_error() const; + void __throw_out_of_range() const; +}; + +template +void +__deque_base_common<__b>::__throw_length_error() const +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw length_error("deque"); +#endif +} + +template +void +__deque_base_common<__b>::__throw_out_of_range() const +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range("deque"); +#endif +} + +template +class __deque_base + : protected __deque_base_common +{ + __deque_base(const __deque_base& __c); + __deque_base& operator=(const __deque_base& __c); +protected: + typedef _Tp value_type; + typedef _Allocator allocator_type; + typedef allocator_traits __alloc_traits; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + + static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16; + + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc +#else + rebind_alloc::other +#endif + __pointer_allocator; + typedef allocator_traits<__pointer_allocator> __map_traits; + typedef typename __map_traits::pointer __map_pointer; + typedef typename __map_traits::const_pointer __map_const_pointer; + typedef __split_buffer __map; + + typedef __deque_iterator iterator; + typedef __deque_iterator const_iterator; + + __map __map_; + size_type __start_; + __compressed_pair __size_; + + iterator begin() _NOEXCEPT; + const_iterator begin() const _NOEXCEPT; + iterator end() _NOEXCEPT; + const_iterator end() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();} + _LIBCPP_INLINE_VISIBILITY + const size_type& size() const _NOEXCEPT {return __size_.first();} + _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();} + _LIBCPP_INLINE_VISIBILITY + const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} + + __deque_base() + _NOEXCEPT_(is_nothrow_default_constructible::value); + explicit __deque_base(const allocator_type& __a); +public: + ~__deque_base(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + __deque_base(__deque_base&& __c) + _NOEXCEPT_(is_nothrow_move_constructible::value); + __deque_base(__deque_base&& __c, const allocator_type& __a); + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + void swap(__deque_base& __c) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable::value); +protected: + void clear() _NOEXCEPT; + + bool __invariants() const; + + _LIBCPP_INLINE_VISIBILITY + void __move_assign(__deque_base& __c) + _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value) + { + __map_ = _VSTD::move(__c.__map_); + __start_ = __c.__start_; + size() = __c.size(); + __move_assign_alloc(__c); + __c.__start_ = __c.size() = 0; + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__deque_base& __c) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable::value) + {__move_assign_alloc(__c, integral_constant());} + +private: + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__deque_base& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable::value) + { + __alloc() = _VSTD::move(__c.__alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__deque_base& __c, false_type) _NOEXCEPT + {} + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(allocator_type& __x, allocator_type& __y) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable::value) + {__swap_alloc(__x, __y, integral_constant());} + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type) + _NOEXCEPT_(__is_nothrow_swappable::value) + { + using _VSTD::swap; + swap(__x, __y); + } + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type) + _NOEXCEPT + {} +}; + +template +bool +__deque_base<_Tp, _Allocator>::__invariants() const +{ + if (!__map_.__invariants()) + return false; + if (__map_.size() >= size_type(-1) / __block_size) + return false; + for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end(); + __i != __e; ++__i) + if (*__i == nullptr) + return false; + if (__map_.size() != 0) + { + if (size() >= __map_.size() * __block_size) + return false; + if (__start_ >= __map_.size() * __block_size - size()) + return false; + } + else + { + if (size() != 0) + return false; + if (__start_ != 0) + return false; + } + return true; +} + +template +typename __deque_base<_Tp, _Allocator>::iterator +__deque_base<_Tp, _Allocator>::begin() _NOEXCEPT +{ + __map_pointer __mp = __map_.begin() + __start_ / __block_size; + return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); +} + +template +typename __deque_base<_Tp, _Allocator>::const_iterator +__deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT +{ + __map_const_pointer __mp = __map_.begin() + __start_ / __block_size; + return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); +} + +template +typename __deque_base<_Tp, _Allocator>::iterator +__deque_base<_Tp, _Allocator>::end() _NOEXCEPT +{ + size_type __p = size() + __start_; + __map_pointer __mp = __map_.begin() + __p / __block_size; + return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); +} + +template +typename __deque_base<_Tp, _Allocator>::const_iterator +__deque_base<_Tp, _Allocator>::end() const _NOEXCEPT +{ + size_type __p = size() + __start_; + __map_const_pointer __mp = __map_.begin() + __p / __block_size; + return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__deque_base<_Tp, _Allocator>::__deque_base() + _NOEXCEPT_(is_nothrow_default_constructible::value) + : __start_(0), __size_(0) {} + +template +inline _LIBCPP_INLINE_VISIBILITY +__deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a) + : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} + +template +__deque_base<_Tp, _Allocator>::~__deque_base() +{ + clear(); + typename __map::iterator __i = __map_.begin(); + typename __map::iterator __e = __map_.end(); + for (; __i != __e; ++__i) + __alloc_traits::deallocate(__alloc(), *__i, __block_size); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c) + _NOEXCEPT_(is_nothrow_move_constructible::value) + : __map_(_VSTD::move(__c.__map_)), + __start_(_VSTD::move(__c.__start_)), + __size_(_VSTD::move(__c.__size_)) +{ + __c.__start_ = 0; + __c.size() = 0; +} + +template +__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a) + : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)), + __start_(_VSTD::move(__c.__start_)), + __size_(_VSTD::move(__c.size()), __a) +{ + if (__a == __c.__alloc()) + { + __c.__start_ = 0; + __c.size() = 0; + } + else + { + __map_.clear(); + __start_ = 0; + size() = 0; + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +__deque_base<_Tp, _Allocator>::swap(__deque_base& __c) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable::value) +{ + __map_.swap(__c.__map_); + _VSTD::swap(__start_, __c.__start_); + _VSTD::swap(size(), __c.size()); + __swap_alloc(__alloc(), __c.__alloc()); +} + +template +void +__deque_base<_Tp, _Allocator>::clear() _NOEXCEPT +{ + allocator_type& __a = __alloc(); + for (iterator __i = begin(), __e = end(); __i != __e; ++__i) + __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); + size() = 0; + while (__map_.size() > 2) + { + __alloc_traits::deallocate(__a, __map_.front(), __block_size); + __map_.pop_front(); + } + switch (__map_.size()) + { + case 1: + __start_ = __block_size / 2; + break; + case 2: + __start_ = __block_size; + break; + } +} + +template > +class _LIBCPP_VISIBLE deque + : private __deque_base<_Tp, _Allocator> +{ +public: + // types: + + typedef _Tp value_type; + typedef _Allocator allocator_type; + + typedef __deque_base __base; + + typedef typename __base::__alloc_traits __alloc_traits; + typedef typename __base::reference reference; + typedef typename __base::const_reference const_reference; + typedef typename __base::iterator iterator; + typedef typename __base::const_iterator const_iterator; + typedef typename __base::size_type size_type; + typedef typename __base::difference_type difference_type; + + typedef typename __base::pointer pointer; + typedef typename __base::const_pointer const_pointer; + typedef _VSTD::reverse_iterator reverse_iterator; + typedef _VSTD::reverse_iterator const_reverse_iterator; + + // construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY + deque() + _NOEXCEPT_(is_nothrow_default_constructible::value) + {} + _LIBCPP_INLINE_VISIBILITY deque(const allocator_type& __a) : __base(__a) {} + explicit deque(size_type __n); + deque(size_type __n, const value_type& __v); + deque(size_type __n, const value_type& __v, const allocator_type& __a); + template + deque(_InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); + template + deque(_InputIter __f, _InputIter __l, const allocator_type& __a, + typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); + deque(const deque& __c); + deque(const deque& __c, const allocator_type& __a); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + deque(initializer_list __il); + deque(initializer_list __il, const allocator_type& __a); +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + deque& operator=(const deque& __c); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + deque& operator=(initializer_list __il) {assign(__il); return *this;} +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); + deque(deque&& __c, const allocator_type& __a); + deque& operator=(deque&& __c) + _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + template + void assign(_InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value && + !__is_random_access_iterator<_InputIter>::value>::type* = 0); + template + void assign(_RAIter __f, _RAIter __l, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); + void assign(size_type __n, const value_type& __v); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list __il) {assign(__il.begin(), __il.end());} +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + allocator_type get_allocator() const _NOEXCEPT; + + // iterators: + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __base::begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __base::begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __base::end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __base::end();} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT + {return reverse_iterator(__base::end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(__base::end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(__base::begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(__base::begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT + {return __base::begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT + {return __base::end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT + {return const_reverse_iterator(__base::end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT + {return const_reverse_iterator(__base::begin());} + + // capacity: + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __base::size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + {return __alloc_traits::max_size(__base::__alloc());} + void resize(size_type __n); + void resize(size_type __n, const value_type& __v); + void shrink_to_fit() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __base::size() == 0;} + + // element access: + reference operator[](size_type __i); + const_reference operator[](size_type __i) const; + reference at(size_type __i); + const_reference at(size_type __i) const; + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + // 23.2.2.3 modifiers: + void push_front(const value_type& __v); + void push_back(const value_type& __v); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + template void emplace_front(_Args&&... __args); + template void emplace_back(_Args&&... __args); + template iterator emplace(const_iterator __p, _Args&&... __args); +#endif // _LIBCPP_HAS_NO_VARIADICS + void push_front(value_type&& __v); + void push_back(value_type&& __v); + iterator insert(const_iterator __p, value_type&& __v); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + iterator insert(const_iterator __p, const value_type& __v); + iterator insert(const_iterator __p, size_type __n, const value_type& __v); + template + iterator insert (const_iterator __p, _InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value + &&!__is_bidirectional_iterator<_InputIter>::value>::type* = 0); + template + iterator insert (const_iterator __p, _BiIter __f, _BiIter __l, + typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, initializer_list __il) + {return insert(__p, __il.begin(), __il.end());} +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + void pop_front(); + void pop_back(); + iterator erase(const_iterator __p); + iterator erase(const_iterator __f, const_iterator __l); + + void swap(deque& __c) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable::value); + void clear() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + bool __invariants() const {return __base::__invariants();} +private: + _LIBCPP_INLINE_VISIBILITY + static size_type __recommend_blocks(size_type __n) + { + return __n / __base::__block_size + (__n % __base::__block_size != 0); + } + _LIBCPP_INLINE_VISIBILITY + size_type __capacity() const + { + return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1; + } + _LIBCPP_INLINE_VISIBILITY + size_type __front_spare() const + { + return __base::__start_; + } + _LIBCPP_INLINE_VISIBILITY + size_type __back_spare() const + { + return __capacity() - (__base::__start_ + __base::size()); + } + + template + void __append(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value && + !__is_forward_iterator<_InpIter>::value>::type* = 0); + template + void __append(_ForIter __f, _ForIter __l, + typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0); + void __append(size_type __n); + void __append(size_type __n, const value_type& __v); + void __erase_to_end(const_iterator __f); + void __add_front_capacity(); + void __add_front_capacity(size_type __n); + void __add_back_capacity(); + void __add_back_capacity(size_type __n); + iterator __move_and_check(iterator __f, iterator __l, iterator __r, + const_pointer& __vt); + iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r, + const_pointer& __vt); + void __move_construct_and_check(iterator __f, iterator __l, + iterator __r, const_pointer& __vt); + void __move_construct_backward_and_check(iterator __f, iterator __l, + iterator __r, const_pointer& __vt); + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const deque& __c) + {__copy_assign_alloc(__c, integral_constant());} + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const deque& __c, true_type) + { + if (__base::__alloc() != __c.__alloc()) + { + clear(); + shrink_to_fit(); + } + __base::__alloc() = __c.__alloc(); + __base::__map_.__alloc() = __c.__map_.__alloc(); + } + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const deque& __c, false_type) + {} + + void __move_assign(deque& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable::value); + void __move_assign(deque& __c, false_type); +}; + +template +deque<_Tp, _Allocator>::deque(size_type __n) +{ + if (__n > 0) + __append(__n); +} + +template +deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) +{ + if (__n > 0) + __append(__n, __v); +} + +template +deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a) + : __base(__a) +{ + if (__n > 0) + __append(__n, __v); +} + +template +template +deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value>::type*) +{ + __append(__f, __l); +} + +template +template +deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a, + typename enable_if<__is_input_iterator<_InputIter>::value>::type*) + : __base(__a) +{ + __append(__f, __l); +} + +template +deque<_Tp, _Allocator>::deque(const deque& __c) + : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc())) +{ + __append(__c.begin(), __c.end()); +} + +template +deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a) + : __base(__a) +{ + __append(__c.begin(), __c.end()); +} + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +deque<_Tp, _Allocator>::deque(initializer_list __il) +{ + __append(__il.begin(), __il.end()); +} + +template +deque<_Tp, _Allocator>::deque(initializer_list __il, const allocator_type& __a) + : __base(__a) +{ + __append(__il.begin(), __il.end()); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +deque<_Tp, _Allocator>& +deque<_Tp, _Allocator>::operator=(const deque& __c) +{ + if (this != &__c) + { + __copy_assign_alloc(__c); + assign(__c.begin(), __c.end()); + } + return *this; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +deque<_Tp, _Allocator>::deque(deque&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) + : __base(_VSTD::move(__c)) +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a) + : __base(_VSTD::move(__c), __a) +{ + if (__a != __c.__alloc()) + { + typedef move_iterator _I; + assign(_I(__c.begin()), _I(__c.end())); + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +deque<_Tp, _Allocator>& +deque<_Tp, _Allocator>::operator=(deque&& __c) + _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value) +{ + __move_assign(__c, integral_constant()); + return *this; +} + +template +void +deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type) +{ + if (__base::__alloc() != __c.__alloc()) + { + typedef move_iterator _I; + assign(_I(__c.begin()), _I(__c.end())); + } + else + __move_assign(__c, true_type()); +} + +template +void +deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable::value) +{ + clear(); + shrink_to_fit(); + __base::__move_assign(__c); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +template +void +deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value && + !__is_random_access_iterator<_InputIter>::value>::type*) +{ + iterator __i = __base::begin(); + iterator __e = __base::end(); + for (; __f != __l && __i != __e; ++__f, ++__i) + *__i = *__f; + if (__f != __l) + __append(__f, __l); + else + __erase_to_end(__i); +} + +template +template +void +deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l, + typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) +{ + if (static_cast(__l - __f) > __base::size()) + { + _RAIter __m = __f + __base::size(); + _VSTD::copy(__f, __m, __base::begin()); + __append(__m, __l); + } + else + __erase_to_end(_VSTD::copy(__f, __l, __base::begin())); +} + +template +void +deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) +{ + if (__n > __base::size()) + { + _VSTD::fill_n(__base::begin(), __base::size(), __v); + __n -= __base::size(); + __append(__n, __v); + } + else + __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Allocator +deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT +{ + return __base::__alloc(); +} + +template +void +deque<_Tp, _Allocator>::resize(size_type __n) +{ + if (__n > __base::size()) + __append(__n - __base::size()); + else if (__n < __base::size()) + __erase_to_end(__base::begin() + __n); +} + +template +void +deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v) +{ + if (__n > __base::size()) + __append(__n - __base::size(), __v); + else if (__n < __base::size()) + __erase_to_end(__base::begin() + __n); +} + +template +void +deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT +{ + allocator_type& __a = __base::__alloc(); + if (empty()) + { + while (__base::__map_.size() > 0) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } + __base::__start_ = 0; + } + else + { + if (__front_spare() >= __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); + __base::__map_.pop_front(); + __base::__start_ -= __base::__block_size; + } + if (__back_spare() >= __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } + } + __base::__map_.shrink_to_fit(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename deque<_Tp, _Allocator>::reference +deque<_Tp, _Allocator>::operator[](size_type __i) +{ + size_type __p = __base::__start_ + __i; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename deque<_Tp, _Allocator>::const_reference +deque<_Tp, _Allocator>::operator[](size_type __i) const +{ + size_type __p = __base::__start_ + __i; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename deque<_Tp, _Allocator>::reference +deque<_Tp, _Allocator>::at(size_type __i) +{ + if (__i >= __base::size()) + __base::__throw_out_of_range(); + size_type __p = __base::__start_ + __i; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename deque<_Tp, _Allocator>::const_reference +deque<_Tp, _Allocator>::at(size_type __i) const +{ + if (__i >= __base::size()) + __base::__throw_out_of_range(); + size_type __p = __base::__start_ + __i; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename deque<_Tp, _Allocator>::reference +deque<_Tp, _Allocator>::front() +{ + return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) + + __base::__start_ % __base::__block_size); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename deque<_Tp, _Allocator>::const_reference +deque<_Tp, _Allocator>::front() const +{ + return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) + + __base::__start_ % __base::__block_size); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename deque<_Tp, _Allocator>::reference +deque<_Tp, _Allocator>::back() +{ + size_type __p = __base::size() + __base::__start_ - 1; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename deque<_Tp, _Allocator>::const_reference +deque<_Tp, _Allocator>::back() const +{ + size_type __p = __base::size() + __base::__start_ - 1; + return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); +} + +template +void +deque<_Tp, _Allocator>::push_back(const value_type& __v) +{ + allocator_type& __a = __base::__alloc(); + if (__back_spare() == 0) + __add_back_capacity(); + // __back_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); + ++__base::size(); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +deque<_Tp, _Allocator>::push_back(value_type&& __v) +{ + allocator_type& __a = __base::__alloc(); + if (__back_spare() == 0) + __add_back_capacity(); + // __back_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); + ++__base::size(); +} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +void +deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) +{ + allocator_type& __a = __base::__alloc(); + if (__back_spare() == 0) + __add_back_capacity(); + // __back_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); + ++__base::size(); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +deque<_Tp, _Allocator>::push_front(const value_type& __v) +{ + allocator_type& __a = __base::__alloc(); + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); + --__base::__start_; + ++__base::size(); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +deque<_Tp, _Allocator>::push_front(value_type&& __v) +{ + allocator_type& __a = __base::__alloc(); + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); + --__base::__start_; + ++__base::size(); +} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +void +deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) +{ + allocator_type& __a = __base::__alloc(); + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); + --__base::__start_; + ++__base::size(); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) +{ + size_type __pos = __p - __base::begin(); + size_type __to_end = __base::size() - __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < __to_end) + { // insert by shifting things backward + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + if (__pos == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); + --__base::__start_; + ++__base::size(); + } + else + { + const_pointer __vt = pointer_traits::pointer_to(__v); + iterator __b = __base::begin(); + iterator __bm1 = _VSTD::prev(__b); + if (__vt == pointer_traits::pointer_to(*__b)) + __vt = pointer_traits::pointer_to(*__bm1); + __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); + --__base::__start_; + ++__base::size(); + if (__pos > 1) + __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); + *__b = *__vt; + } + } + else + { // insert by shifting things forward + if (__back_spare() == 0) + __add_back_capacity(); + // __back_capacity >= 1 + size_type __de = __base::size() - __pos; + if (__de == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); + ++__base::size(); + } + else + { + const_pointer __vt = pointer_traits::pointer_to(__v); + iterator __e = __base::end(); + iterator __em1 = _VSTD::prev(__e); + if (__vt == pointer_traits::pointer_to(*__em1)) + __vt = pointer_traits::pointer_to(*__e); + __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); + ++__base::size(); + if (__de > 1) + __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); + *--__e = *__vt; + } + } + return __base::begin() + __pos; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) +{ + size_type __pos = __p - __base::begin(); + size_type __to_end = __base::size() - __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < __to_end) + { // insert by shifting things backward + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + if (__pos == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); + --__base::__start_; + ++__base::size(); + } + else + { + iterator __b = __base::begin(); + iterator __bm1 = _VSTD::prev(__b); + __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); + --__base::__start_; + ++__base::size(); + if (__pos > 1) + __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); + *__b = _VSTD::move(__v); + } + } + else + { // insert by shifting things forward + if (__back_spare() == 0) + __add_back_capacity(); + // __back_capacity >= 1 + size_type __de = __base::size() - __pos; + if (__de == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); + ++__base::size(); + } + else + { + iterator __e = __base::end(); + iterator __em1 = _VSTD::prev(__e); + __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); + ++__base::size(); + if (__de > 1) + __e = _VSTD::move_backward(__e - __de, __em1, __e); + *--__e = _VSTD::move(__v); + } + } + return __base::begin() + __pos; +} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) +{ + size_type __pos = __p - __base::begin(); + size_type __to_end = __base::size() - __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < __to_end) + { // insert by shifting things backward + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + if (__pos == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); + --__base::__start_; + ++__base::size(); + } + else + { + iterator __b = __base::begin(); + iterator __bm1 = _VSTD::prev(__b); + __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); + --__base::__start_; + ++__base::size(); + if (__pos > 1) + __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); + *__b = value_type(_VSTD::forward<_Args>(__args)...); + } + } + else + { // insert by shifting things forward + if (__back_spare() == 0) + __add_back_capacity(); + // __back_capacity >= 1 + size_type __de = __base::size() - __pos; + if (__de == 0) + { + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); + ++__base::size(); + } + else + { + iterator __e = __base::end(); + iterator __em1 = _VSTD::prev(__e); + __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); + ++__base::size(); + if (__de > 1) + __e = _VSTD::move_backward(__e - __de, __em1, __e); + *--__e = value_type(_VSTD::forward<_Args>(__args)...); + } + } + return __base::begin() + __pos; +} + +#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) +{ + size_type __pos = __p - __base::begin(); + size_type __to_end = __base::size() - __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < __to_end) + { // insert by shifting things backward + if (__n > __front_spare()) + __add_front_capacity(__n - __front_spare()); + // __n <= __front_spare() + size_type __old_n = __n; + iterator __old_begin = __base::begin(); + iterator __i = __old_begin; + if (__n > __pos) + { + for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v); + __n = __pos; + } + if (__n > 0) + { + const_pointer __vt = pointer_traits::pointer_to(__v); + iterator __obn = __old_begin + __n; + __move_construct_backward_and_check(__old_begin, __obn, __i, __vt); + if (__n < __pos) + __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt); + _VSTD::fill_n(__old_begin, __n, *__vt); + } + } + else + { // insert by shifting things forward + size_type __back_capacity = __back_spare(); + if (__n > __back_capacity) + __add_back_capacity(__n - __back_capacity); + // __n <= __back_capacity + size_type __old_n = __n; + iterator __old_end = __base::end(); + iterator __i = __old_end; + size_type __de = __base::size() - __pos; + if (__n > __de) + { + for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); + __n = __de; + } + if (__n > 0) + { + const_pointer __vt = pointer_traits::pointer_to(__v); + iterator __oen = __old_end - __n; + __move_construct_and_check(__oen, __old_end, __i, __vt); + if (__n < __de) + __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt); + _VSTD::fill_n(__old_end - __n, __n, *__vt); + } + } + return __base::begin() + __pos; +} + +template +template +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l, + typename enable_if<__is_input_iterator<_InputIter>::value + &&!__is_bidirectional_iterator<_InputIter>::value>::type*) +{ + __split_buffer __buf(__base::__alloc()); + __buf.__construct_at_end(__f, __l); + typedef typename __split_buffer::iterator __bi; + return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end())); +} + +template +template +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, + typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*) +{ + size_type __n = _VSTD::distance(__f, __l); + size_type __pos = __p - __base::begin(); + size_type __to_end = __base::size() - __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < __to_end) + { // insert by shifting things backward + if (__n > __front_spare()) + __add_front_capacity(__n - __front_spare()); + // __n <= __front_spare() + size_type __old_n = __n; + iterator __old_begin = __base::begin(); + iterator __i = __old_begin; + _BiIter __m = __f; + if (__n > __pos) + { + __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos); + for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j); + __n = __pos; + } + if (__n > 0) + { + iterator __obn = __old_begin + __n; + for (iterator __j = __obn; __j != __old_begin;) + { + __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j)); + --__base::__start_; + ++__base::size(); + } + if (__n < __pos) + __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin); + _VSTD::copy(__m, __l, __old_begin); + } + } + else + { // insert by shifting things forward + size_type __back_capacity = __back_spare(); + if (__n > __back_capacity) + __add_back_capacity(__n - __back_capacity); + // __n <= __back_capacity + size_type __old_n = __n; + iterator __old_end = __base::end(); + iterator __i = __old_end; + _BiIter __m = __l; + size_type __de = __base::size() - __pos; + if (__n > __de) + { + __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de); + for (_BiIter __j = __m; __j != __l; ++__i, ++__j, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j); + __n = __de; + } + if (__n > 0) + { + iterator __oen = __old_end - __n; + for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j)); + if (__n < __de) + __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end); + _VSTD::copy_backward(__f, __m, __old_end); + } + } + return __base::begin() + __pos; +} + +template +template +void +deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value && + !__is_forward_iterator<_InpIter>::value>::type*) +{ + for (; __f != __l; ++__f) + push_back(*__f); +} + +template +template +void +deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l, + typename enable_if<__is_forward_iterator<_ForIter>::value>::type*) +{ + size_type __n = _VSTD::distance(__f, __l); + allocator_type& __a = __base::__alloc(); + size_type __back_capacity = __back_spare(); + if (__n > __back_capacity) + __add_back_capacity(__n - __back_capacity); + // __n <= __back_capacity + for (iterator __i = __base::end(); __f != __l; ++__i, ++__f, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f); +} + +template +void +deque<_Tp, _Allocator>::__append(size_type __n) +{ + allocator_type& __a = __base::__alloc(); + size_type __back_capacity = __back_spare(); + if (__n > __back_capacity) + __add_back_capacity(__n - __back_capacity); + // __n <= __back_capacity + for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i)); +} + +template +void +deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v) +{ + allocator_type& __a = __base::__alloc(); + size_type __back_capacity = __back_spare(); + if (__n > __back_capacity) + __add_back_capacity(__n - __back_capacity); + // __n <= __back_capacity + for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); +} + +// Create front capacity for one block of elements. +// Strong guarantee. Either do it or don't touch anything. +template +void +deque<_Tp, _Allocator>::__add_front_capacity() +{ + allocator_type& __a = __base::__alloc(); + if (__back_spare() >= __base::__block_size) + { + __base::__start_ += __base::__block_size; + pointer __pt = __base::__map_.back(); + __base::__map_.pop_back(); + __base::__map_.push_front(__pt); + } + // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer + else if (__base::__map_.size() < __base::__map_.capacity()) + { // we can put the new buffer into the map, but don't shift things around + // until all buffers are allocated. If we throw, we don't need to fix + // anything up (any added buffers are undetectible) + if (__base::__map_.__front_spare() > 0) + __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); + else + { + __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); + // Done allocating, reorder capacity + pointer __pt = __base::__map_.back(); + __base::__map_.pop_back(); + __base::__map_.push_front(__pt); + } + __base::__start_ = __base::__map_.size() == 1 ? + __base::__block_size / 2 : + __base::__start_ + __base::__block_size; + } + // Else need to allocate 1 buffer, *and* we need to reallocate __map_. + else + { + __split_buffer + __buf(max(2 * __base::__map_.capacity(), 1), + 0, __base::__map_.__alloc()); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __alloc_traits::deallocate(__a, __buf.front(), __base::__block_size); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + for (typename __base::__map_pointer __i = __base::__map_.begin(); + __i != __base::__map_.end(); ++__i) + __buf.push_back(*__i); + _VSTD::swap(__base::__map_.__first_, __buf.__first_); + _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); + _VSTD::swap(__base::__map_.__end_, __buf.__end_); + _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); + __base::__start_ = __base::__map_.size() == 1 ? + __base::__block_size / 2 : + __base::__start_ + __base::__block_size; + } +} + +// Create front capacity for __n elements. +// Strong guarantee. Either do it or don't touch anything. +template +void +deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) +{ + allocator_type& __a = __base::__alloc(); + size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); + // Number of unused blocks at back: + size_type __back_capacity = __back_spare() / __base::__block_size; + __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need + __nb -= __back_capacity; // number of blocks need to allocate + // If __nb == 0, then we have sufficient capacity. + if (__nb == 0) + { + __base::__start_ += __base::__block_size * __back_capacity; + for (; __back_capacity > 0; --__back_capacity) + { + pointer __pt = __base::__map_.back(); + __base::__map_.pop_back(); + __base::__map_.push_front(__pt); + } + } + // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers + else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) + { // we can put the new buffers into the map, but don't shift things around + // until all buffers are allocated. If we throw, we don't need to fix + // anything up (any added buffers are undetectible) + for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1)) + { + if (__base::__map_.__front_spare() == 0) + break; + __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); + } + for (; __nb > 0; --__nb, ++__back_capacity) + __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); + // Done allocating, reorder capacity + __base::__start_ += __back_capacity * __base::__block_size; + for (; __back_capacity > 0; --__back_capacity) + { + pointer __pt = __base::__map_.back(); + __base::__map_.pop_back(); + __base::__map_.push_front(__pt); + } + } + // Else need to allocate __nb buffers, *and* we need to reallocate __map_. + else + { + size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty(); + __split_buffer + __buf(max(2* __base::__map_.capacity(), + __nb + __base::__map_.size()), + 0, __base::__map_.__alloc()); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __nb > 0; --__nb) + __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (typename __base::__map_pointer __i = __buf.begin(); + __i != __buf.end(); ++__i) + __alloc_traits::deallocate(__a, *__i, __base::__block_size); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __back_capacity > 0; --__back_capacity) + { + __buf.push_back(__base::__map_.back()); + __base::__map_.pop_back(); + } + for (typename __base::__map_pointer __i = __base::__map_.begin(); + __i != __base::__map_.end(); ++__i) + __buf.push_back(*__i); + _VSTD::swap(__base::__map_.__first_, __buf.__first_); + _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); + _VSTD::swap(__base::__map_.__end_, __buf.__end_); + _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); + __base::__start_ += __ds; + } +} + +// Create back capacity for one block of elements. +// Strong guarantee. Either do it or don't touch anything. +template +void +deque<_Tp, _Allocator>::__add_back_capacity() +{ + allocator_type& __a = __base::__alloc(); + if (__front_spare() >= __base::__block_size) + { + __base::__start_ -= __base::__block_size; + pointer __pt = __base::__map_.front(); + __base::__map_.pop_front(); + __base::__map_.push_back(__pt); + } + // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers + else if (__base::__map_.size() < __base::__map_.capacity()) + { // we can put the new buffer into the map, but don't shift things around + // until it is allocated. If we throw, we don't need to fix + // anything up (any added buffers are undetectible) + if (__base::__map_.__back_spare() != 0) + __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); + else + { + __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); + // Done allocating, reorder capacity + pointer __pt = __base::__map_.front(); + __base::__map_.pop_front(); + __base::__map_.push_back(__pt); + } + } + // Else need to allocate 1 buffer, *and* we need to reallocate __map_. + else + { + __split_buffer + __buf(max(2* __base::__map_.capacity(), 1), + __base::__map_.size(), + __base::__map_.__alloc()); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __alloc_traits::deallocate(__a, __buf.back(), __base::__block_size); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + for (typename __base::__map_pointer __i = __base::__map_.end(); + __i != __base::__map_.begin();) + __buf.push_front(*--__i); + _VSTD::swap(__base::__map_.__first_, __buf.__first_); + _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); + _VSTD::swap(__base::__map_.__end_, __buf.__end_); + _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); + } +} + +// Create back capacity for __n elements. +// Strong guarantee. Either do it or don't touch anything. +template +void +deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) +{ + allocator_type& __a = __base::__alloc(); + size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); + // Number of unused blocks at front: + size_type __front_capacity = __front_spare() / __base::__block_size; + __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need + __nb -= __front_capacity; // number of blocks need to allocate + // If __nb == 0, then we have sufficient capacity. + if (__nb == 0) + { + __base::__start_ -= __base::__block_size * __front_capacity; + for (; __front_capacity > 0; --__front_capacity) + { + pointer __pt = __base::__map_.front(); + __base::__map_.pop_front(); + __base::__map_.push_back(__pt); + } + } + // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers + else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) + { // we can put the new buffers into the map, but don't shift things around + // until all buffers are allocated. If we throw, we don't need to fix + // anything up (any added buffers are undetectible) + for (; __nb > 0; --__nb) + { + if (__base::__map_.__back_spare() == 0) + break; + __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); + } + for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ += + __base::__block_size - (__base::__map_.size() == 1)) + __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); + // Done allocating, reorder capacity + __base::__start_ -= __base::__block_size * __front_capacity; + for (; __front_capacity > 0; --__front_capacity) + { + pointer __pt = __base::__map_.front(); + __base::__map_.pop_front(); + __base::__map_.push_back(__pt); + } + } + // Else need to allocate __nb buffers, *and* we need to reallocate __map_. + else + { + size_type __ds = __front_capacity * __base::__block_size; + __split_buffer + __buf(max(2* __base::__map_.capacity(), + __nb + __base::__map_.size()), + __base::__map_.size() - __front_capacity, + __base::__map_.__alloc()); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __nb > 0; --__nb) + __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + for (typename __base::__map_pointer __i = __buf.begin(); + __i != __buf.end(); ++__i) + __alloc_traits::deallocate(__a, *__i, __base::__block_size); + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + for (; __front_capacity > 0; --__front_capacity) + { + __buf.push_back(__base::__map_.front()); + __base::__map_.pop_front(); + } + for (typename __base::__map_pointer __i = __base::__map_.end(); + __i != __base::__map_.begin();) + __buf.push_front(*--__i); + _VSTD::swap(__base::__map_.__first_, __buf.__first_); + _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); + _VSTD::swap(__base::__map_.__end_, __buf.__end_); + _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); + __base::__start_ -= __ds; + } +} + +template +void +deque<_Tp, _Allocator>::pop_front() +{ + allocator_type& __a = __base::__alloc(); + __alloc_traits::destroy(__a, *(__base::__map_.begin() + + __base::__start_ / __base::__block_size) + + __base::__start_ % __base::__block_size); + --__base::size(); + if (++__base::__start_ >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); + __base::__map_.pop_front(); + __base::__start_ -= __base::__block_size; + } +} + +template +void +deque<_Tp, _Allocator>::pop_back() +{ + allocator_type& __a = __base::__alloc(); + size_type __p = __base::size() + __base::__start_ - 1; + __alloc_traits::destroy(__a, *(__base::__map_.begin() + + __p / __base::__block_size) + + __p % __base::__block_size); + --__base::size(); + if (__back_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } +} + +// move assign [__f, __l) to [__r, __r + (__l-__f)). +// If __vt points into [__f, __l), then subtract (__f - __r) from __vt. +template +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r, + const_pointer& __vt) +{ + // as if + // for (; __f != __l; ++__f, ++__r) + // *__r = _VSTD::move(*__f); + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + __base::__block_size; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + if (__fb <= __vt && __vt < __fe) + __vt = (const_iterator(__f.__m_iter_, __vt) -= __f - __r).__ptr_; + __r = _VSTD::move(__fb, __fe, __r); + __n -= __bs; + __f += __bs; + } + return __r; +} + +// move assign [__f, __l) to [__r - (__l-__f), __r) backwards. +// If __vt points into [__f, __l), then add (__r - __l) to __vt. +template +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r, + const_pointer& __vt) +{ + // as if + // while (__f != __l) + // *--__r = _VSTD::move(*--__l); + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + if (__lb <= __vt && __vt < __le) + __vt = (const_iterator(__l.__m_iter_, __vt) += __r - __l - 1).__ptr_; + __r = _VSTD::move_backward(__lb, __le, __r); + __n -= __bs; + __l -= __bs - 1; + } + return __r; +} + +// move construct [__f, __l) to [__r, __r + (__l-__f)). +// If __vt points into [__f, __l), then add (__r - __f) to __vt. +template +void +deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, + iterator __r, const_pointer& __vt) +{ + allocator_type& __a = __base::__alloc(); + // as if + // for (; __f != __l; ++__r, ++__f, ++__base::size()) + // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f)); + difference_type __n = __l - __f; + while (__n > 0) + { + pointer __fb = __f.__ptr_; + pointer __fe = *__f.__m_iter_ + __base::__block_size; + difference_type __bs = __fe - __fb; + if (__bs > __n) + { + __bs = __n; + __fe = __fb + __bs; + } + if (__fb <= __vt && __vt < __fe) + __vt = (const_iterator(__f.__m_iter_, __vt) += __r - __f).__ptr_; + for (; __fb != __fe; ++__fb, ++__r, ++__base::size()) + __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb)); + __n -= __bs; + __f += __bs; + } +} + +// move construct [__f, __l) to [__r - (__l-__f), __r) backwards. +// If __vt points into [__f, __l), then subtract (__l - __r) from __vt. +template +void +deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l, + iterator __r, const_pointer& __vt) +{ + allocator_type& __a = __base::__alloc(); + // as if + // for (iterator __j = __l; __j != __f;) + // { + // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j)); + // --__base::__start_; + // ++__base::size(); + // } + difference_type __n = __l - __f; + while (__n > 0) + { + --__l; + pointer __lb = *__l.__m_iter_; + pointer __le = __l.__ptr_ + 1; + difference_type __bs = __le - __lb; + if (__bs > __n) + { + __bs = __n; + __lb = __le - __bs; + } + if (__lb <= __vt && __vt < __le) + __vt = (const_iterator(__l.__m_iter_, __vt) -= __l - __r + 1).__ptr_; + while (__le != __lb) + { + __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le)); + --__base::__start_; + ++__base::size(); + } + __n -= __bs; + __l -= __bs - 1; + } +} + +template +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::erase(const_iterator __f) +{ + difference_type __n = 1; + iterator __b = __base::begin(); + difference_type __pos = __f - __b; + iterator __p = __b + __pos; + allocator_type& __a = __base::__alloc(); + if (__pos < (__base::size() - 1) / 2) + { // erase from front + _VSTD::move_backward(__b, __p, _VSTD::next(__p)); + __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); + --__base::size(); + ++__base::__start_; + if (__front_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); + __base::__map_.pop_front(); + __base::__start_ -= __base::__block_size; + } + } + else + { // erase from back + iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p); + __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); + --__base::size(); + if (__back_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } + } + return __base::begin() + __pos; +} + +template +typename deque<_Tp, _Allocator>::iterator +deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) +{ + difference_type __n = __l - __f; + iterator __b = __base::begin(); + difference_type __pos = __f - __b; + iterator __p = __b + __pos; + if (__n > 0) + { + allocator_type& __a = __base::__alloc(); + if (__pos < (__base::size() - __n) / 2) + { // erase from front + iterator __i = _VSTD::move_backward(__b, __p, __p + __n); + for (; __b != __i; ++__b) + __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); + __base::size() -= __n; + __base::__start_ += __n; + while (__front_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); + __base::__map_.pop_front(); + __base::__start_ -= __base::__block_size; + } + } + else + { // erase from back + iterator __i = _VSTD::move(__p + __n, __base::end(), __p); + for (iterator __e = __base::end(); __i != __e; ++__i) + __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); + __base::size() -= __n; + while (__back_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } + } + } + return __base::begin() + __pos; +} + +template +void +deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) +{ + iterator __e = __base::end(); + difference_type __n = __e - __f; + if (__n > 0) + { + allocator_type& __a = __base::__alloc(); + iterator __b = __base::begin(); + difference_type __pos = __f - __b; + for (iterator __p = __b + __pos; __p != __e; ++__p) + __alloc_traits::destroy(__a, _VSTD::addressof(*__p)); + __base::size() -= __n; + while (__back_spare() >= 2 * __base::__block_size) + { + __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); + __base::__map_.pop_back(); + } + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +deque<_Tp, _Allocator>::swap(deque& __c) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable::value) +{ + __base::swap(__c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +deque<_Tp, _Allocator>::clear() _NOEXCEPT +{ + __base::clear(); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + const typename deque<_Tp, _Allocator>::size_type __sz = __x.size(); + return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + return !(__x == __y); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + return __y < __x; +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + return !(__x < __y); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +bool +operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) +{ + return !(__y < __x); +} + +template +_LIBCPP_INLINE_VISIBILITY inline +void +swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_DEQUE diff --git a/contrib/libc++/include/exception b/contrib/libc++/include/exception new file mode 100644 index 000000000000..0a747f50fb3d --- /dev/null +++ b/contrib/libc++/include/exception @@ -0,0 +1,250 @@ +// -*- C++ -*- +//===-------------------------- exception ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXCEPTION +#define _LIBCPP_EXCEPTION + +/* + exception synopsis + +namespace std +{ + +class exception +{ +public: + exception() noexcept; + exception(const exception&) noexcept; + exception& operator=(const exception&) noexcept; + virtual ~exception() noexcept; + virtual const char* what() const noexcept; +}; + +class bad_exception + : public exception +{ +public: + bad_exception() noexcept; + bad_exception(const bad_exception&) noexcept; + bad_exception& operator=(const bad_exception&) noexcept; + virtual ~bad_exception() noexcept; + virtual const char* what() const noexcept; +}; + +typedef void (*unexpected_handler)(); +unexpected_handler set_unexpected(unexpected_handler f ) noexcept; +unexpected_handler get_unexpected() noexcept; +[[noreturn]] void unexpected(); + +typedef void (*terminate_handler)(); +terminate_handler set_terminate(terminate_handler f ) noexcept; +terminate_handler get_terminate() noexcept; +[[noreturn]] void terminate() noexcept; + +bool uncaught_exception() noexcept; + +typedef unspecified exception_ptr; + +exception_ptr current_exception() noexcept; +void rethrow_exception [[noreturn]] (exception_ptr p); +template exception_ptr make_exception_ptr(E e) noexcept; + +class nested_exception +{ +public: + nested_exception() noexcept; + nested_exception(const nested_exception&) noexcept = default; + nested_exception& operator=(const nested_exception&) noexcept = default; + virtual ~nested_exception() = default; + + // access functions + [[noreturn]] void rethrow_nested() const; + exception_ptr nested_ptr() const noexcept; +}; + +template [[noreturn]] void throw_with_nested(T&& t); +template void rethrow_if_nested(const E& e); + +} // std + +*/ + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +namespace std // purposefully not using versioning namespace +{ + +class _LIBCPP_EXCEPTION_ABI exception +{ +public: + _LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {} + virtual ~exception() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +class _LIBCPP_EXCEPTION_ABI bad_exception + : public exception +{ +public: + _LIBCPP_INLINE_VISIBILITY bad_exception() _NOEXCEPT {} + virtual ~bad_exception() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +typedef void (*unexpected_handler)(); +_LIBCPP_VISIBLE unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT; +_LIBCPP_VISIBLE unexpected_handler get_unexpected() _NOEXCEPT; +_ATTRIBUTE(noreturn) _LIBCPP_VISIBLE void unexpected(); + +typedef void (*terminate_handler)(); +_LIBCPP_VISIBLE terminate_handler set_terminate(terminate_handler) _NOEXCEPT; +_LIBCPP_VISIBLE terminate_handler get_terminate() _NOEXCEPT; +_ATTRIBUTE(noreturn) _LIBCPP_VISIBLE void terminate() _NOEXCEPT; + +_LIBCPP_VISIBLE bool uncaught_exception() _NOEXCEPT; + +class exception_ptr; + +exception_ptr current_exception() _NOEXCEPT; +_ATTRIBUTE(noreturn) void rethrow_exception(exception_ptr); + +class _LIBCPP_VISIBLE exception_ptr +{ + void* __ptr_; +public: + _LIBCPP_INLINE_VISIBILITY exception_ptr() _NOEXCEPT : __ptr_() {} + _LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {} + exception_ptr(const exception_ptr&) _NOEXCEPT; + exception_ptr& operator=(const exception_ptr&) _NOEXCEPT; + ~exception_ptr() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + // explicit + operator bool() const _NOEXCEPT {return __ptr_ != nullptr;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT + {return !(__x == __y);} + + friend exception_ptr current_exception() _NOEXCEPT; + _ATTRIBUTE(noreturn) friend void rethrow_exception(exception_ptr); +}; + +template +exception_ptr +make_exception_ptr(_E __e) _NOEXCEPT +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { + throw __e; + } + catch (...) + { + return current_exception(); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +// nested_exception + +class _LIBCPP_EXCEPTION_ABI nested_exception +{ + exception_ptr __ptr_; +public: + nested_exception() _NOEXCEPT; +// nested_exception(const nested_exception&) noexcept = default; +// nested_exception& operator=(const nested_exception&) noexcept = default; + virtual ~nested_exception() _NOEXCEPT; + + // access functions + _ATTRIBUTE(noreturn) void rethrow_nested() const; + _LIBCPP_INLINE_VISIBILITY exception_ptr nested_ptr() const _NOEXCEPT {return __ptr_;} +}; + +template +struct __nested + : public _Tp, + public nested_exception +{ + _LIBCPP_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {} +}; + +template +_ATTRIBUTE(noreturn) +void +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +throw_with_nested(_Tp&& __t, typename enable_if< + is_class::type>::value && + !is_base_of::type>::value + >::type* = 0) +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +throw_with_nested (_Tp& __t, typename enable_if< + is_class<_Tp>::value && !is_base_of::value + >::type* = 0) +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw __nested::type>(_VSTD::forward<_Tp>(__t)); +#endif +} + +template +_ATTRIBUTE(noreturn) +void +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +throw_with_nested(_Tp&& __t, typename enable_if< + !is_class::type>::value || + is_base_of::type>::value + >::type* = 0) +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +throw_with_nested (_Tp& __t, typename enable_if< + !is_class<_Tp>::value || is_base_of::value + >::type* = 0) +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw _VSTD::forward<_Tp>(__t); +#endif +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +rethrow_if_nested(const _E& __e, typename enable_if< + is_polymorphic<_E>::value + >::type* = 0) +{ + const nested_exception* __nep = dynamic_cast(&__e); + if (__nep) + __nep->rethrow_nested(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +rethrow_if_nested(const _E& __e, typename enable_if< + !is_polymorphic<_E>::value + >::type* = 0) +{ +} + +} // std + +#endif // _LIBCPP_EXCEPTION diff --git a/contrib/libc++/include/ext/__hash b/contrib/libc++/include/ext/__hash new file mode 100644 index 000000000000..8e9635d07f57 --- /dev/null +++ b/contrib/libc++/include/ext/__hash @@ -0,0 +1,46 @@ +// -*- C++ -*- +//===------------------------- hash_set ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXT_HASH +#define _LIBCPP_EXT_HASH + +#pragma GCC system_header + +#include +#include + +namespace __gnu_cxx { +using namespace std; + +template struct _LIBCPP_VISIBLE hash : public std::hash + { }; + +template <> struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const char *__c) const _NOEXCEPT + { + return __do_string_hash(__c, __c + strlen(__c)); + } +}; + +template <> struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char *__c) const _NOEXCEPT + { + return __do_string_hash(__c, __c + strlen(__c)); + } +}; +} + +#endif _LIBCPP_EXT_HASH diff --git a/contrib/libc++/include/ext/hash_map b/contrib/libc++/include/ext/hash_map new file mode 100644 index 000000000000..9e62e7a777d6 --- /dev/null +++ b/contrib/libc++/include/ext/hash_map @@ -0,0 +1,995 @@ +// -*- C++ -*- +//===-------------------------- hash_map ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_HASH_MAP +#define _LIBCPP_HASH_MAP + +/* + + hash_map synopsis + +namespace __gnu_cxx +{ + +template , class Pred = equal_to, + class Alloc = allocator>> +class hash_map +{ +public: + // types + typedef Key key_type; + typedef T mapped_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef pair value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits::pointer pointer; + typedef typename allocator_traits::const_pointer const_pointer; + typedef typename allocator_traits::size_type size_type; + typedef typename allocator_traits::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + + explicit hash_map(size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template + hash_map(InputIterator f, InputIterator l, + size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + hash_map(const hash_map&); + ~hash_map(); + hash_map& operator=(const hash_map&); + + allocator_type get_allocator() const; + + bool empty() const; + size_type size() const; + size_type max_size() const; + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + + pair insert(const value_type& obj); + template + void insert(InputIterator first, InputIterator last); + + void erase(const_iterator position); + size_type erase(const key_type& k); + void erase(const_iterator first, const_iterator last); + void clear(); + + void swap(hash_map&); + + hasher hash_funct() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair equal_range(const key_type& k); + pair equal_range(const key_type& k) const; + + mapped_type& operator[](const key_type& k); + + size_type bucket_count() const; + size_type max_bucket_count() const; + + size_type elems_in_bucket(size_type n) const; + + void resize(size_type n); +}; + +template + void swap(hash_map& x, + hash_map& y); + +template + bool + operator==(const hash_map& x, + const hash_map& y); + +template + bool + operator!=(const hash_map& x, + const hash_map& y); + +template , class Pred = equal_to, + class Alloc = allocator>> +class hash_multimap +{ +public: + // types + typedef Key key_type; + typedef T mapped_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef pair value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits::pointer pointer; + typedef typename allocator_traits::const_pointer const_pointer; + typedef typename allocator_traits::size_type size_type; + typedef typename allocator_traits::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + + explicit hash_multimap(size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template + hash_multimap(InputIterator f, InputIterator l, + size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + explicit hash_multimap(const allocator_type&); + hash_multimap(const hash_multimap&); + ~hash_multimap(); + hash_multimap& operator=(const hash_multimap&); + + allocator_type get_allocator() const; + + bool empty() const; + size_type size() const; + size_type max_size() const; + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + + iterator insert(const value_type& obj); + template + void insert(InputIterator first, InputIterator last); + + void erase(const_iterator position); + size_type erase(const key_type& k); + void erase(const_iterator first, const_iterator last); + void clear(); + + void swap(hash_multimap&); + + hasher hash_funct() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair equal_range(const key_type& k); + pair equal_range(const key_type& k) const; + + size_type bucket_count() const; + size_type max_bucket_count() const; + + size_type elems_in_bucket(size_type n) const; + + void resize(size_type n); +}; + +template + void swap(hash_multimap& x, + hash_multimap& y); + +template + bool + operator==(const hash_multimap& x, + const hash_multimap& y); + +template + bool + operator!=(const hash_multimap& x, + const hash_multimap& y); + +} // __gnu_cxx + +*/ + +#include <__config> +#include <__hash_table> +#include +#include +#include + +#if __DEPRECATED +#warning Use of the header is deprecated. Migrate to +#endif + +#pragma GCC system_header + +namespace __gnu_cxx { + +using namespace std; + +template ::value> +class __hash_map_hasher + : private _Hash +{ +public: + _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : _Hash() {} + _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : _Hash(__h) {} + _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return *this;} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const _Tp& __x) const + {return static_cast(*this)(__x.first);} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const typename _Tp::first_type& __x) const + {return static_cast(*this)(__x);} +}; + +template +class __hash_map_hasher<_Tp, _Hash, false> +{ + _Hash __hash_; +public: + _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : __hash_() {} + _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : __hash_(__h) {} + _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return __hash_;} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const _Tp& __x) const + {return __hash_(__x.first);} + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const typename _Tp::first_type& __x) const + {return __hash_(__x);} +}; + +template ::value> +class __hash_map_equal + : private _Pred +{ +public: + _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : _Pred() {} + _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : _Pred(__p) {} + _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return *this;} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return static_cast(*this)(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const + {return static_cast(*this)(__x, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const + {return static_cast(*this)(__x.first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const typename _Tp::first_type& __x, + const typename _Tp::first_type& __y) const + {return static_cast(*this)(__x, __y);} +}; + +template +class __hash_map_equal<_Tp, _Pred, false> +{ + _Pred __pred_; +public: + _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : __pred_() {} + _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : __pred_(__p) {} + _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return __pred_;} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __pred_(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const + {return __pred_(__x, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const + {return __pred_(__x.first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const typename _Tp::first_type& __x, + const typename _Tp::first_type& __y) const + {return __pred_(__x, __y);} +}; + +template +class __hash_map_node_destructor +{ + typedef _Alloc allocator_type; + typedef allocator_traits __alloc_traits; + typedef typename __alloc_traits::value_type::value_type value_type; +public: + typedef typename __alloc_traits::pointer pointer; +private: + typedef typename value_type::first_type first_type; + typedef typename value_type::second_type second_type; + + allocator_type& __na_; + + __hash_map_node_destructor& operator=(const __hash_map_node_destructor&); + +public: + bool __first_constructed; + bool __second_constructed; + + _LIBCPP_INLINE_VISIBILITY + explicit __hash_map_node_destructor(allocator_type& __na) + : __na_(__na), + __first_constructed(false), + __second_constructed(false) + {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + __hash_map_node_destructor(__hash_node_destructor&& __x) + : __na_(__x.__na_), + __first_constructed(__x.__value_constructed), + __second_constructed(__x.__value_constructed) + { + __x.__value_constructed = false; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + __hash_map_node_destructor(const __hash_node_destructor& __x) + : __na_(__x.__na_), + __first_constructed(__x.__value_constructed), + __second_constructed(__x.__value_constructed) + { + const_cast(__x.__value_constructed) = false; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) + { + if (__second_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second)); + if (__first_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } +}; + +template +class _LIBCPP_VISIBLE __hash_map_iterator +{ + _HashIterator __i_; + + typedef pointer_traits __pointer_traits; + typedef const typename _HashIterator::value_type::first_type key_type; + typedef typename _HashIterator::value_type::second_type mapped_type; +public: + typedef forward_iterator_tag iterator_category; + typedef pair value_type; + typedef typename _HashIterator::difference_type difference_type; + typedef value_type& reference; + typedef typename __pointer_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {} + + _LIBCPP_INLINE_VISIBILITY __hash_map_iterator(_HashIterator __i) : __i_(__i) {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *operator->();} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();} + + _LIBCPP_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __hash_map_iterator operator++(int) + { + __hash_map_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) + {return __x.__i_ == __y.__i_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) + {return __x.__i_ != __y.__i_;} + + template friend class _LIBCPP_VISIBLE hash_map; + template friend class _LIBCPP_VISIBLE hash_multimap; + template friend class _LIBCPP_VISIBLE __hash_const_iterator; + template friend class _LIBCPP_VISIBLE __hash_const_local_iterator; + template friend class _LIBCPP_VISIBLE __hash_map_const_iterator; +}; + +template +class _LIBCPP_VISIBLE __hash_map_const_iterator +{ + _HashIterator __i_; + + typedef pointer_traits __pointer_traits; + typedef const typename _HashIterator::value_type::first_type key_type; + typedef typename _HashIterator::value_type::second_type mapped_type; +public: + typedef forward_iterator_tag iterator_category; + typedef pair value_type; + typedef typename _HashIterator::difference_type difference_type; + typedef const value_type& reference; + typedef typename __pointer_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {} + + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {} + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator( + __hash_map_iterator __i) + : __i_(__i.__i_) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return *operator->();} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return (pointer)__i_.operator->();} + + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator& operator++() {++__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __hash_map_const_iterator operator++(int) + { + __hash_map_const_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) + {return __x.__i_ == __y.__i_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) + {return __x.__i_ != __y.__i_;} + + template friend class _LIBCPP_VISIBLE hash_map; + template friend class _LIBCPP_VISIBLE hash_multimap; + template friend class _LIBCPP_VISIBLE __hash_const_iterator; + template friend class _LIBCPP_VISIBLE __hash_const_local_iterator; +}; + +template , class _Pred = equal_to<_Key>, + class _Alloc = allocator > > +class _LIBCPP_VISIBLE hash_map +{ +public: + // types + typedef _Key key_type; + typedef _Tp mapped_type; + typedef _Tp data_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef pair value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + +private: + typedef pair __value_type; + typedef __hash_map_hasher<__value_type, hasher> __hasher; + typedef __hash_map_equal<__value_type, key_equal> __key_equal; + typedef typename allocator_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__value_type> +#else + rebind_alloc<__value_type>::other +#endif + __allocator_type; + + typedef __hash_table<__value_type, __hasher, + __key_equal, __allocator_type> __table; + + __table __table_; + + typedef typename __table::__node_pointer __node_pointer; + typedef typename __table::__node_const_pointer __node_const_pointer; + typedef typename __table::__node_traits __node_traits; + typedef typename __table::__node_allocator __node_allocator; + typedef typename __table::__node __node; + typedef __hash_map_node_destructor<__node_allocator> _D; + typedef unique_ptr<__node, _D> __node_holder; + typedef allocator_traits __alloc_traits; +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + + typedef __hash_map_iterator iterator; + typedef __hash_map_const_iterator const_iterator; + + _LIBCPP_INLINE_VISIBILITY hash_map() {__table_.rehash(193);} + explicit hash_map(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + hash_map(size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + template + hash_map(_InputIterator __first, _InputIterator __last); + template + hash_map(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template + hash_map(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + hash_map(const hash_map& __u); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const {return __table_.end();} + + _LIBCPP_INLINE_VISIBILITY + pair insert(const value_type& __x) + {return __table_.__insert_unique(__x);} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} + template + void insert(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __p) {__table_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __first, const_iterator __last) + {__table_.erase(__first.__i_, __last.__i_);} + _LIBCPP_INLINE_VISIBILITY + void clear() {__table_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(hash_map& __u) {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_funct() const + {return __table_.hash_function().hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const + {return __table_.key_eq().key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) + {return __table_.__equal_range_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) const + {return __table_.__equal_range_unique(__k);} + + mapped_type& operator[](const key_type& __k); + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type elems_in_bucket(size_type __n) const + {return __table_.bucket_size(__n);} + + _LIBCPP_INLINE_VISIBILITY + void resize(size_type __n) {__table_.rehash(__n);} + +private: + __node_holder __construct_node(const key_type& __k); +}; + +template +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + size_type __n, const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); +} + +template +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); +} + +template +template +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + _InputIterator __first, _InputIterator __last) +{ + __table_.rehash(193); + insert(__first, __last); +} + +template +template +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template +template +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( + const hash_map& __u) + : __table_(__u.__table_) +{ + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template +typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k) +{ + __node_allocator& __na = __table_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __h.get_deleter().__second_constructed = true; + return _VSTD::move(__h); +} + +template +template +inline _LIBCPP_INLINE_VISIBILITY +void +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_unique(*__first); +} + +template +_Tp& +hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) +{ + iterator __i = find(__k); + if (__i != end()) + return __i->second; + __node_holder __h = __construct_node(__k); + pair __r = __table_.__node_insert_unique(__h.get()); + __h.release(); + return __r.first->second; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + __x.swap(__y); +} + +template +bool +operator==(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); + __i != __ex; ++__i) + { + const_iterator __j = __y.find(__i->first); + if (__j == __ey || !(*__i == *__j)) + return false; + } + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +template , class _Pred = equal_to<_Key>, + class _Alloc = allocator > > +class _LIBCPP_VISIBLE hash_multimap +{ +public: + // types + typedef _Key key_type; + typedef _Tp mapped_type; + typedef _Tp data_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef pair value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + +private: + typedef pair __value_type; + typedef __hash_map_hasher<__value_type, hasher> __hasher; + typedef __hash_map_equal<__value_type, key_equal> __key_equal; + typedef typename allocator_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__value_type> +#else + rebind_alloc<__value_type>::other +#endif + __allocator_type; + + typedef __hash_table<__value_type, __hasher, + __key_equal, __allocator_type> __table; + + __table __table_; + + typedef typename __table::__node_traits __node_traits; + typedef typename __table::__node_allocator __node_allocator; + typedef typename __table::__node __node; + typedef __hash_map_node_destructor<__node_allocator> _D; + typedef unique_ptr<__node, _D> __node_holder; + typedef allocator_traits __alloc_traits; +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + + typedef __hash_map_iterator iterator; + typedef __hash_map_const_iterator const_iterator; + + _LIBCPP_INLINE_VISIBILITY + hash_multimap() {__table_.rehash(193);} + explicit hash_multimap(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + hash_multimap(size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + template + hash_multimap(_InputIterator __first, _InputIterator __last); + template + hash_multimap(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template + hash_multimap(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a); + hash_multimap(const hash_multimap& __u); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const {return __table_.end();} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator, const value_type& __x) {return insert(__x);} + template + void insert(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __p) {__table_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __first, const_iterator __last) + {__table_.erase(__first.__i_, __last.__i_);} + _LIBCPP_INLINE_VISIBILITY + void clear() {__table_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(hash_multimap& __u) {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_funct() const + {return __table_.hash_function().hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const + {return __table_.key_eq().key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) + {return __table_.__equal_range_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) const + {return __table_.__equal_range_multi(__k);} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type elems_in_bucket(size_type __n) const + {return __table_.bucket_size(__n);} + + _LIBCPP_INLINE_VISIBILITY + void resize(size_type __n) {__table_.rehash(__n);} +}; + +template +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + size_type __n, const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); +} + +template +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); +} + +template +template +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + _InputIterator __first, _InputIterator __last) +{ + __table_.rehash(193); + insert(__first, __last); +} + +template +template +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template +template +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( + const hash_multimap& __u) + : __table_(__u.__table_) +{ + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template +template +inline _LIBCPP_INLINE_VISIBILITY +void +hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_multi(*__first); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + __x.swap(__y); +} + +template +bool +operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + typedef pair _EqRng; + for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) + { + _EqRng __xeq = __x.equal_range(__i->first); + _EqRng __yeq = __y.equal_range(__i->first); + if (_VSTD::distance(__xeq.first, __xeq.second) != + _VSTD::distance(__yeq.first, __yeq.second) || + !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) + return false; + __i = __xeq.second; + } + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +} // __gnu_cxx + +#endif // _LIBCPP_HASH_MAP diff --git a/contrib/libc++/include/ext/hash_set b/contrib/libc++/include/ext/hash_set new file mode 100644 index 000000000000..14daf7bc29e4 --- /dev/null +++ b/contrib/libc++/include/ext/hash_set @@ -0,0 +1,657 @@ +// -*- C++ -*- +//===------------------------- hash_set ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_HASH_SET +#define _LIBCPP_HASH_SET + +/* + + hash_set synopsis + +namespace __gnu_cxx +{ + +template , class Pred = equal_to, + class Alloc = allocator> +class hash_set +{ +public: + // types + typedef Value key_type; + typedef key_type value_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits::pointer pointer; + typedef typename allocator_traits::const_pointer const_pointer; + typedef typename allocator_traits::size_type size_type; + typedef typename allocator_traits::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + + explicit hash_set(size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template + hash_set(InputIterator f, InputIterator l, + size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + hash_set(const hash_set&); + ~hash_set(); + hash_set& operator=(const hash_set&); + + allocator_type get_allocator() const; + + bool empty() const; + size_type size() const; + size_type max_size() const; + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + + pair insert(const value_type& obj); + template + void insert(InputIterator first, InputIterator last); + + void erase(const_iterator position); + size_type erase(const key_type& k); + void erase(const_iterator first, const_iterator last); + void clear(); + + void swap(hash_set&); + + hasher hash_funct() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair equal_range(const key_type& k); + pair equal_range(const key_type& k) const; + + size_type bucket_count() const; + size_type max_bucket_count() const; + + size_type elems_in_bucket(size_type n) const; + + void resize(size_type n); +}; + +template + void swap(hash_set& x, + hash_set& y); + +template + bool + operator==(const hash_set& x, + const hash_set& y); + +template + bool + operator!=(const hash_set& x, + const hash_set& y); + +template , class Pred = equal_to, + class Alloc = allocator> +class hash_multiset +{ +public: + // types + typedef Value key_type; + typedef key_type value_type; + typedef Hash hasher; + typedef Pred key_equal; + typedef Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits::pointer pointer; + typedef typename allocator_traits::const_pointer const_pointer; + typedef typename allocator_traits::size_type size_type; + typedef typename allocator_traits::difference_type difference_type; + + typedef /unspecified/ iterator; + typedef /unspecified/ const_iterator; + + explicit hash_multiset(size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + template + hash_multiset(InputIterator f, InputIterator l, + size_type n = 193, const hasher& hf = hasher(), + const key_equal& eql = key_equal(), + const allocator_type& a = allocator_type()); + hash_multiset(const hash_multiset&); + ~hash_multiset(); + hash_multiset& operator=(const hash_multiset&); + + allocator_type get_allocator() const; + + bool empty() const; + size_type size() const; + size_type max_size() const; + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + + iterator insert(const value_type& obj); + template + void insert(InputIterator first, InputIterator last); + + void erase(const_iterator position); + size_type erase(const key_type& k); + void erase(const_iterator first, const_iterator last); + void clear(); + + void swap(hash_multiset&); + + hasher hash_funct() const; + key_equal key_eq() const; + + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + pair equal_range(const key_type& k); + pair equal_range(const key_type& k) const; + + size_type bucket_count() const; + size_type max_bucket_count() const; + + size_type elems_in_bucket(size_type n) const; + + void resize(size_type n); +}; + +template + void swap(hash_multiset& x, + hash_multiset& y); + +template + bool + operator==(const hash_multiset& x, + const hash_multiset& y); + +template + bool + operator!=(const hash_multiset& x, + const hash_multiset& y); +} // __gnu_cxx + +*/ + +#include <__config> +#include <__hash_table> +#include +#include + +#if __DEPRECATED +#warning Use of the header is deprecated. Migrate to +#endif + +namespace __gnu_cxx { + +using namespace std; + +template , class _Pred = equal_to<_Value>, + class _Alloc = allocator<_Value> > +class _LIBCPP_VISIBLE hash_set +{ +public: + // types + typedef _Value key_type; + typedef key_type value_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + +private: + typedef __hash_table __table; + + __table __table_; + +public: + typedef typename __table::pointer pointer; + typedef typename __table::const_pointer const_pointer; + typedef typename __table::size_type size_type; + typedef typename __table::difference_type difference_type; + + typedef typename __table::const_iterator iterator; + typedef typename __table::const_iterator const_iterator; + + _LIBCPP_INLINE_VISIBILITY + hash_set() {__table_.rehash(193);} + explicit hash_set(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + hash_set(size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); + template + hash_set(_InputIterator __first, _InputIterator __last); + template + hash_set(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template + hash_set(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a); + hash_set(const hash_set& __u); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const {return __table_.end();} + + _LIBCPP_INLINE_VISIBILITY + pair insert(const value_type& __x) + {return __table_.__insert_unique(__x);} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} + template + void insert(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __p) {__table_.erase(__p);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __first, const_iterator __last) + {__table_.erase(__first, __last);} + _LIBCPP_INLINE_VISIBILITY + void clear() {__table_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(hash_set& __u) {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_funct() const {return __table_.hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const {return __table_.key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) + {return __table_.__equal_range_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) const + {return __table_.__equal_range_unique(__k);} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);} + + _LIBCPP_INLINE_VISIBILITY + void resize(size_type __n) {__table_.rehash(__n);} +}; + +template +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); +} + +template +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); +} + +template +template +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( + _InputIterator __first, _InputIterator __last) +{ + __table_.rehash(193); + insert(__first, __last); +} + +template +template +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template +template +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template +hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( + const hash_set& __u) + : __table_(__u.__table_) +{ + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template +template +inline _LIBCPP_INLINE_VISIBILITY +void +hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_unique(*__first); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(hash_set<_Value, _Hash, _Pred, _Alloc>& __x, + hash_set<_Value, _Hash, _Pred, _Alloc>& __y) +{ + __x.swap(__y); +} + +template +bool +operator==(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, + const hash_set<_Value, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename hash_set<_Value, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); + __i != __ex; ++__i) + { + const_iterator __j = __y.find(*__i); + if (__j == __ey || !(*__i == *__j)) + return false; + } + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, + const hash_set<_Value, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +template , class _Pred = equal_to<_Value>, + class _Alloc = allocator<_Value> > +class _LIBCPP_VISIBLE hash_multiset +{ +public: + // types + typedef _Value key_type; + typedef key_type value_type; + typedef _Hash hasher; + typedef _Pred key_equal; + typedef _Alloc allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + +private: + typedef __hash_table __table; + + __table __table_; + +public: + typedef typename __table::pointer pointer; + typedef typename __table::const_pointer const_pointer; + typedef typename __table::size_type size_type; + typedef typename __table::difference_type difference_type; + + typedef typename __table::const_iterator iterator; + typedef typename __table::const_iterator const_iterator; + + _LIBCPP_INLINE_VISIBILITY + hash_multiset() {__table_.rehash(193);} + explicit hash_multiset(size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + hash_multiset(size_type __n, const hasher& __hf, + const key_equal& __eql, const allocator_type& __a); + template + hash_multiset(_InputIterator __first, _InputIterator __last); + template + hash_multiset(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf = hasher(), + const key_equal& __eql = key_equal()); + template + hash_multiset(_InputIterator __first, _InputIterator __last, + size_type __n , const hasher& __hf, + const key_equal& __eql, const allocator_type& __a); + hash_multiset(const hash_multiset& __u); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const + {return allocator_type(__table_.__node_alloc());} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const {return __table_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const {return __table_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const {return __table_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() {return __table_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const {return __table_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const {return __table_.end();} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator, const value_type& __x) {return insert(__x);} + template + void insert(_InputIterator __first, _InputIterator __last); + + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __p) {__table_.erase(__p);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + void erase(const_iterator __first, const_iterator __last) + {__table_.erase(__first, __last);} + _LIBCPP_INLINE_VISIBILITY + void clear() {__table_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(hash_multiset& __u) {__table_.swap(__u.__table_);} + + _LIBCPP_INLINE_VISIBILITY + hasher hash_funct() const {return __table_.hash_function();} + _LIBCPP_INLINE_VISIBILITY + key_equal key_eq() const {return __table_.key_eq();} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __table_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) + {return __table_.__equal_range_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) const + {return __table_.__equal_range_multi(__k);} + + _LIBCPP_INLINE_VISIBILITY + size_type bucket_count() const {return __table_.bucket_count();} + _LIBCPP_INLINE_VISIBILITY + size_type max_bucket_count() const {return __table_.max_bucket_count();} + + _LIBCPP_INLINE_VISIBILITY + size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);} + + _LIBCPP_INLINE_VISIBILITY + void resize(size_type __n) {__table_.rehash(__n);} +}; + +template +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + size_type __n, const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); +} + +template +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + size_type __n, const hasher& __hf, const key_equal& __eql, + const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); +} + +template +template +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + _InputIterator __first, _InputIterator __last) +{ + __table_.rehash(193); + insert(__first, __last); +} + +template +template +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql) + : __table_(__hf, __eql) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template +template +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + _InputIterator __first, _InputIterator __last, size_type __n, + const hasher& __hf, const key_equal& __eql, const allocator_type& __a) + : __table_(__hf, __eql, __a) +{ + __table_.rehash(__n); + insert(__first, __last); +} + +template +hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( + const hash_multiset& __u) + : __table_(__u.__table_) +{ + __table_.rehash(__u.bucket_count()); + insert(__u.begin(), __u.end()); +} + +template +template +inline _LIBCPP_INLINE_VISIBILITY +void +hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, + _InputIterator __last) +{ + for (; __first != __last; ++__first) + __table_.__insert_multi(*__first); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) +{ + __x.swap(__y); +} + +template +bool +operator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) +{ + if (__x.size() != __y.size()) + return false; + typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator + const_iterator; + typedef pair _EqRng; + for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) + { + _EqRng __xeq = __x.equal_range(*__i); + _EqRng __yeq = __y.equal_range(*__i); + if (_VSTD::distance(__xeq.first, __xeq.second) != + _VSTD::distance(__yeq.first, __yeq.second) || + !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) + return false; + __i = __xeq.second; + } + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) +{ + return !(__x == __y); +} + +} // __gnu_cxx + +#endif // _LIBCPP_HASH_SET diff --git a/contrib/libc++/include/forward_list b/contrib/libc++/include/forward_list new file mode 100644 index 000000000000..61fe290d9e2f --- /dev/null +++ b/contrib/libc++/include/forward_list @@ -0,0 +1,1634 @@ +// -*- C++ -*- +//===----------------------- forward_list ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FORWARD_LIST +#define _LIBCPP_FORWARD_LIST + +/* + forward_list synopsis + +namespace std +{ + +template > +class forward_list +{ +public: + typedef T value_type; + typedef Allocator allocator_type; + + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits::pointer pointer; + typedef typename allocator_traits::const_pointer const_pointer; + typedef typename allocator_traits::size_type size_type; + typedef typename allocator_traits::difference_type difference_type; + + typedef
iterator; + typedef
const_iterator; + + forward_list() + noexcept(is_nothrow_default_constructible::value); + explicit forward_list(const allocator_type& a); + explicit forward_list(size_type n); + forward_list(size_type n, const value_type& v); + forward_list(size_type n, const value_type& v, const allocator_type& a); + template + forward_list(InputIterator first, InputIterator last); + template + forward_list(InputIterator first, InputIterator last, const allocator_type& a); + forward_list(const forward_list& x); + forward_list(const forward_list& x, const allocator_type& a); + forward_list(forward_list&& x) + noexcept(is_nothrow_move_constructible::value); + forward_list(forward_list&& x, const allocator_type& a); + forward_list(initializer_list il); + forward_list(initializer_list il, const allocator_type& a); + + ~forward_list(); + + forward_list& operator=(const forward_list& x); + forward_list& operator=(forward_list&& x) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value); + forward_list& operator=(initializer_list il); + + template + void assign(InputIterator first, InputIterator last); + void assign(size_type n, const value_type& v); + void assign(initializer_list il); + + allocator_type get_allocator() const noexcept; + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + + iterator before_begin() noexcept; + const_iterator before_begin() const noexcept; + const_iterator cbefore_begin() const noexcept; + + bool empty() const noexcept; + size_type max_size() const noexcept; + + reference front(); + const_reference front() const; + + template void emplace_front(Args&&... args); + void push_front(const value_type& v); + void push_front(value_type&& v); + + void pop_front(); + + template + iterator emplace_after(const_iterator p, Args&&... args); + iterator insert_after(const_iterator p, const value_type& v); + iterator insert_after(const_iterator p, value_type&& v); + iterator insert_after(const_iterator p, size_type n, const value_type& v); + template + iterator insert_after(const_iterator p, + InputIterator first, InputIterator last); + iterator insert_after(const_iterator p, initializer_list il); + + iterator erase_after(const_iterator p); + iterator erase_after(const_iterator first, const_iterator last); + + void swap(forward_list& x) + noexcept(!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable::value); + + void resize(size_type n); + void resize(size_type n, const value_type& v); + void clear() noexcept; + + void splice_after(const_iterator p, forward_list& x); + void splice_after(const_iterator p, forward_list&& x); + void splice_after(const_iterator p, forward_list& x, const_iterator i); + void splice_after(const_iterator p, forward_list&& x, const_iterator i); + void splice_after(const_iterator p, forward_list& x, + const_iterator first, const_iterator last); + void splice_after(const_iterator p, forward_list&& x, + const_iterator first, const_iterator last); + void remove(const value_type& v); + template void remove_if(Predicate pred); + void unique(); + template void unique(BinaryPredicate binary_pred); + void merge(forward_list& x); + void merge(forward_list&& x); + template void merge(forward_list& x, Compare comp); + template void merge(forward_list&& x, Compare comp); + void sort(); + template void sort(Compare comp); + void reverse() noexcept; +}; + +template + bool operator==(const forward_list& x, + const forward_list& y); + +template + bool operator< (const forward_list& x, + const forward_list& y); + +template + bool operator!=(const forward_list& x, + const forward_list& y); + +template + bool operator> (const forward_list& x, + const forward_list& y); + +template + bool operator>=(const forward_list& x, + const forward_list& y); + +template + bool operator<=(const forward_list& x, + const forward_list& y); + +template + void swap(forward_list& x, forward_list& y) + noexcept(noexcept(x.swap(y))); + +} // std + +*/ + +#include <__config> + +#include +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template struct __forward_list_node; + +template +struct __forward_begin_node +{ + typedef __forward_begin_node __self; + typedef _NodePtr pointer; + + pointer __next_; + + _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {} +}; + +template +struct __forward_list_node + : public __forward_begin_node + < + typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__forward_list_node<_Tp, _VoidPtr> > +#else + rebind<__forward_list_node<_Tp, _VoidPtr> >::other +#endif + > +{ + typedef _Tp value_type; + + value_type __value_; +}; + +template class forward_list; +template class __forward_list_const_iterator; + +template +class _LIBCPP_VISIBLE __forward_list_iterator +{ + typedef _NodePtr __node_pointer; + + __node_pointer __ptr_; + + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} + + template friend class forward_list; + template friend class __forward_list_const_iterator; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename pointer_traits<__node_pointer>::element_type::value_type + value_type; + typedef value_type& reference; + typedef typename pointer_traits<__node_pointer>::difference_type + difference_type; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY + __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __ptr_->__value_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return &__ptr_->__value_;} + + _LIBCPP_INLINE_VISIBILITY + __forward_list_iterator& operator++() + { + __ptr_ = __ptr_->__next_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __forward_list_iterator operator++(int) + { + __forward_list_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __forward_list_iterator& __x, + const __forward_list_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __forward_list_iterator& __x, + const __forward_list_iterator& __y) + {return !(__x == __y);} +}; + +template +class _LIBCPP_VISIBLE __forward_list_const_iterator +{ + typedef _NodeConstPtr __node_const_pointer; + + __node_const_pointer __ptr_; + + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_const_iterator(__node_const_pointer __p) _NOEXCEPT + : __ptr_(__p) {} + + typedef typename remove_const + < + typename pointer_traits<__node_const_pointer>::element_type + >::type __node; + typedef typename pointer_traits<__node_const_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__node> +#else + rebind<__node>::other +#endif + __node_pointer; + + template friend class forward_list; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename __node::value_type value_type; + typedef const value_type& reference; + typedef typename pointer_traits<__node_const_pointer>::difference_type + difference_type; + typedef typename pointer_traits<__node_const_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT + : __ptr_(__p.__ptr_) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __ptr_->__value_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return &__ptr_->__value_;} + + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator& operator++() + { + __ptr_ = __ptr_->__next_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator operator++(int) + { + __forward_list_const_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __forward_list_const_iterator& __x, + const __forward_list_const_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __forward_list_const_iterator& __x, + const __forward_list_const_iterator& __y) + {return !(__x == __y);} +}; + +template +class __forward_list_base +{ +protected: + typedef _Tp value_type; + typedef _Alloc allocator_type; + + typedef typename allocator_traits::void_pointer void_pointer; + typedef __forward_list_node __node; + typedef typename __node::__self __begin_node; + typedef typename allocator_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__node> +#else + rebind_alloc<__node>::other +#endif + __node_allocator; + typedef allocator_traits<__node_allocator> __node_traits; + typedef typename __node_traits::pointer __node_pointer; + typedef typename __node_traits::const_pointer __node_const_pointer; + + __compressed_pair<__begin_node, __node_allocator> __before_begin_; + + _LIBCPP_INLINE_VISIBILITY + __node_pointer __before_begin() _NOEXCEPT + {return pointer_traits<__node_pointer>::pointer_to( + static_cast<__node&>(__before_begin_.first()));} + _LIBCPP_INLINE_VISIBILITY + __node_const_pointer __before_begin() const _NOEXCEPT + {return pointer_traits<__node_const_pointer>::pointer_to( + static_cast(__before_begin_.first()));} + + _LIBCPP_INLINE_VISIBILITY + __node_allocator& __alloc() _NOEXCEPT + {return __before_begin_.second();} + _LIBCPP_INLINE_VISIBILITY + const __node_allocator& __alloc() const _NOEXCEPT + {return __before_begin_.second();} + + typedef __forward_list_iterator<__node_pointer> iterator; + typedef __forward_list_const_iterator<__node_const_pointer> const_iterator; + + _LIBCPP_INLINE_VISIBILITY + __forward_list_base() + _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) + : __before_begin_(__begin_node()) {} + _LIBCPP_INLINE_VISIBILITY + __forward_list_base(const allocator_type& __a) + : __before_begin_(__begin_node(), __node_allocator(__a)) {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +public: + __forward_list_base(__forward_list_base&& __x) + _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); + __forward_list_base(__forward_list_base&& __x, const allocator_type& __a); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +private: + __forward_list_base(const __forward_list_base&); + __forward_list_base& operator=(const __forward_list_base&); + +public: + ~__forward_list_base(); + +protected: + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __forward_list_base& __x) + {__copy_assign_alloc(__x, integral_constant());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__forward_list_base& __x) + _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<__node_allocator>::value) + {__move_assign_alloc(__x, integral_constant());} + +public: + void swap(__forward_list_base& __x) + _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value); +protected: + void clear() _NOEXCEPT; + +private: + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __forward_list_base&, false_type) {} + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __forward_list_base& __x, true_type) + { + if (__alloc() != __x.__alloc()) + clear(); + __alloc() = __x.__alloc(); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__forward_list_base& __x, false_type) _NOEXCEPT + {} + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__forward_list_base& __x, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) + {__alloc() = _VSTD::move(__x.__alloc());} + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y) + _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) + {__swap_alloc(__x, __y, integral_constant());} + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, + false_type) + _NOEXCEPT + {} + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, + true_type) + _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value) + { + using _VSTD::swap; + swap(__x, __y); + } +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x) + _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) + : __before_begin_(_VSTD::move(__x.__before_begin_)) +{ + __x.__before_begin()->__next_ = nullptr; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x, + const allocator_type& __a) + : __before_begin_(__begin_node(), __node_allocator(__a)) +{ + if (__alloc() == __x.__alloc()) + { + __before_begin()->__next_ = __x.__before_begin()->__next_; + __x.__before_begin()->__next_ = nullptr; + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +__forward_list_base<_Tp, _Alloc>::~__forward_list_base() +{ + clear(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x) + _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) +{ + __swap_alloc(__alloc(), __x.__alloc()); + using _VSTD::swap; + swap(__before_begin()->__next_, __x.__before_begin()->__next_); +} + +template +void +__forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT +{ + __node_allocator& __a = __alloc(); + for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;) + { + __node_pointer __next = __p->__next_; + __node_traits::destroy(__a, _VSTD::addressof(__p->__value_)); + __node_traits::deallocate(__a, __p, 1); + __p = __next; + } + __before_begin()->__next_ = nullptr; +} + +template > +class _LIBCPP_VISIBLE forward_list + : private __forward_list_base<_Tp, _Alloc> +{ + typedef __forward_list_base<_Tp, _Alloc> base; + typedef typename base::__node_allocator __node_allocator; + typedef typename base::__node __node; + typedef typename base::__node_traits __node_traits; + typedef typename base::__node_pointer __node_pointer; + +public: + typedef _Tp value_type; + typedef _Alloc allocator_type; + + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename allocator_traits::pointer pointer; + typedef typename allocator_traits::const_pointer const_pointer; + typedef typename allocator_traits::size_type size_type; + typedef typename allocator_traits::difference_type difference_type; + + typedef typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + + _LIBCPP_INLINE_VISIBILITY + forward_list() + _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) + {} // = default; + explicit forward_list(const allocator_type& __a); + explicit forward_list(size_type __n); + forward_list(size_type __n, const value_type& __v); + forward_list(size_type __n, const value_type& __v, const allocator_type& __a); + template + forward_list(_InputIterator __f, _InputIterator __l, + typename enable_if< + __is_input_iterator<_InputIterator>::value + >::type* = nullptr); + template + forward_list(_InputIterator __f, _InputIterator __l, + const allocator_type& __a, + typename enable_if< + __is_input_iterator<_InputIterator>::value + >::type* = nullptr); + forward_list(const forward_list& __x); + forward_list(const forward_list& __x, const allocator_type& __a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + forward_list(forward_list&& __x) + _NOEXCEPT_(is_nothrow_move_constructible::value) + : base(_VSTD::move(__x)) {} + forward_list(forward_list&& __x, const allocator_type& __a); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + forward_list(initializer_list __il); + forward_list(initializer_list __il, const allocator_type& __a); +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + // ~forward_list() = default; + + forward_list& operator=(const forward_list& __x); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + forward_list& operator=(forward_list&& __x) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value); +#endif +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + forward_list& operator=(initializer_list __il); +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + template + typename enable_if + < + __is_input_iterator<_InputIterator>::value, + void + >::type + assign(_InputIterator __f, _InputIterator __l); + void assign(size_type __n, const value_type& __v); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + void assign(initializer_list __il); +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT + {return allocator_type(base::__alloc());} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT + {return iterator(base::__before_begin()->__next_);} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT + {return const_iterator(base::__before_begin()->__next_);} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT + {return iterator(nullptr);} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT + {return const_iterator(nullptr);} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT + {return const_iterator(base::__before_begin()->__next_);} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT + {return const_iterator(nullptr);} + + _LIBCPP_INLINE_VISIBILITY + iterator before_begin() _NOEXCEPT + {return iterator(base::__before_begin());} + _LIBCPP_INLINE_VISIBILITY + const_iterator before_begin() const _NOEXCEPT + {return const_iterator(base::__before_begin());} + _LIBCPP_INLINE_VISIBILITY + const_iterator cbefore_begin() const _NOEXCEPT + {return const_iterator(base::__before_begin());} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT + {return base::__before_begin()->__next_ == nullptr;} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + {return numeric_limits::max();} + + _LIBCPP_INLINE_VISIBILITY + reference front() {return base::__before_begin()->__next_->__value_;} + _LIBCPP_INLINE_VISIBILITY + const_reference front() const {return base::__before_begin()->__next_->__value_;} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + template void emplace_front(_Args&&... __args); +#endif + void push_front(value_type&& __v); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + void push_front(const value_type& __v); + + void pop_front(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + template + iterator emplace_after(const_iterator __p, _Args&&... __args); +#endif // _LIBCPP_HAS_NO_VARIADICS + iterator insert_after(const_iterator __p, value_type&& __v); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + iterator insert_after(const_iterator __p, const value_type& __v); + iterator insert_after(const_iterator __p, size_type __n, const value_type& __v); + template + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_input_iterator<_InputIterator>::value, + iterator + >::type + insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + iterator insert_after(const_iterator __p, initializer_list __il) + {return insert_after(__p, __il.begin(), __il.end());} +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + iterator erase_after(const_iterator __p); + iterator erase_after(const_iterator __f, const_iterator __l); + + _LIBCPP_INLINE_VISIBILITY + void swap(forward_list& __x) + _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) + {base::swap(__x);} + + void resize(size_type __n); + void resize(size_type __n, const value_type& __v); + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {base::clear();} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void splice_after(const_iterator __p, forward_list&& __x); + _LIBCPP_INLINE_VISIBILITY + void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i); + _LIBCPP_INLINE_VISIBILITY + void splice_after(const_iterator __p, forward_list&& __x, + const_iterator __f, const_iterator __l); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + void splice_after(const_iterator __p, forward_list& __x); + void splice_after(const_iterator __p, forward_list& __x, const_iterator __i); + void splice_after(const_iterator __p, forward_list& __x, + const_iterator __f, const_iterator __l); + void remove(const value_type& __v); + template void remove_if(_Predicate __pred); + _LIBCPP_INLINE_VISIBILITY + void unique() {unique(__equal_to());} + template void unique(_BinaryPredicate __binary_pred); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void merge(forward_list&& __x) {merge(__x, __less());} + template + _LIBCPP_INLINE_VISIBILITY + void merge(forward_list&& __x, _Compare __comp) + {merge(__x, _VSTD::move(__comp));} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void merge(forward_list& __x) {merge(__x, __less());} + template void merge(forward_list& __x, _Compare __comp); + _LIBCPP_INLINE_VISIBILITY + void sort() {sort(__less());} + template void sort(_Compare __comp); + void reverse() _NOEXCEPT; + +private: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void __move_assign(forward_list& __x, true_type) + _NOEXCEPT_(is_nothrow_move_assignable::value); + void __move_assign(forward_list& __x, false_type); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + template + static + __node_pointer + __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp); + + template + static + __node_pointer + __sort(__node_pointer __f, difference_type __sz, _Compare& __comp); +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a) + : base(__a) +{ +} + +template +forward_list<_Tp, _Alloc>::forward_list(size_type __n) +{ + if (__n > 0) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(nullptr, _D(__a, 1)); + for (__node_pointer __p = base::__before_begin(); __n > 0; --__n, + __p = __p->__next_) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_)); + __h->__next_ = nullptr; + __p->__next_ = __h.release(); + } + } +} + +template +forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v) +{ + insert_after(cbefore_begin(), __n, __v); +} + +template +forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v, + const allocator_type& __a) + : base(__a) +{ + insert_after(cbefore_begin(), __n, __v); +} + +template +template +forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, + typename enable_if< + __is_input_iterator<_InputIterator>::value + >::type*) +{ + insert_after(cbefore_begin(), __f, __l); +} + +template +template +forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, + const allocator_type& __a, + typename enable_if< + __is_input_iterator<_InputIterator>::value + >::type*) + : base(__a) +{ + insert_after(cbefore_begin(), __f, __l); +} + +template +forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x) + : base(allocator_type( + __node_traits::select_on_container_copy_construction(__x.__alloc()) + ) + ) +{ + insert_after(cbefore_begin(), __x.begin(), __x.end()); +} + +template +forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x, + const allocator_type& __a) + : base(__a) +{ + insert_after(cbefore_begin(), __x.begin(), __x.end()); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x, + const allocator_type& __a) + : base(_VSTD::move(__x), __a) +{ + if (base::__alloc() != __x.__alloc()) + { + typedef move_iterator _I; + insert_after(cbefore_begin(), _I(__x.begin()), _I(__x.end())); + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +forward_list<_Tp, _Alloc>::forward_list(initializer_list __il) +{ + insert_after(cbefore_begin(), __il.begin(), __il.end()); +} + +template +forward_list<_Tp, _Alloc>::forward_list(initializer_list __il, + const allocator_type& __a) + : base(__a) +{ + insert_after(cbefore_begin(), __il.begin(), __il.end()); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +forward_list<_Tp, _Alloc>& +forward_list<_Tp, _Alloc>::operator=(const forward_list& __x) +{ + if (this != &__x) + { + base::__copy_assign_alloc(__x); + assign(__x.begin(), __x.end()); + } + return *this; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type) + _NOEXCEPT_(is_nothrow_move_assignable::value) +{ + clear(); + base::__move_assign_alloc(__x); + base::__before_begin()->__next_ = __x.__before_begin()->__next_; + __x.__before_begin()->__next_ = nullptr; +} + +template +void +forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type) +{ + if (base::__alloc() == __x.__alloc()) + __move_assign(__x, true_type()); + else + { + typedef move_iterator _I; + assign(_I(__x.begin()), _I(__x.end())); + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +forward_list<_Tp, _Alloc>& +forward_list<_Tp, _Alloc>::operator=(forward_list&& __x) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value) +{ + __move_assign(__x, integral_constant()); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +inline _LIBCPP_INLINE_VISIBILITY +forward_list<_Tp, _Alloc>& +forward_list<_Tp, _Alloc>::operator=(initializer_list __il) +{ + assign(__il.begin(), __il.end()); + return *this; +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +template +typename enable_if +< + __is_input_iterator<_InputIterator>::value, + void +>::type +forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l) +{ + iterator __i = before_begin(); + iterator __j = _VSTD::next(__i); + iterator __e = end(); + for (; __j != __e && __f != __l; ++__i, ++__j, ++__f) + *__j = *__f; + if (__j == __e) + insert_after(__i, __f, __l); + else + erase_after(__i, __e); +} + +template +void +forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v) +{ + iterator __i = before_begin(); + iterator __j = _VSTD::next(__i); + iterator __e = end(); + for (; __j != __e && __n > 0; --__n, ++__i, ++__j) + *__j = __v; + if (__j == __e) + insert_after(__i, __n, __v); + else + erase_after(__i, __e); +} + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +inline _LIBCPP_INLINE_VISIBILITY +void +forward_list<_Tp, _Alloc>::assign(initializer_list __il) +{ + assign(__il.begin(), __il.end()); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +void +forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) +{ + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), + _VSTD::forward<_Args>(__args)...); + __h->__next_ = base::__before_begin()->__next_; + base::__before_begin()->__next_ = __h.release(); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template +void +forward_list<_Tp, _Alloc>::push_front(value_type&& __v) +{ + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v)); + __h->__next_ = base::__before_begin()->__next_; + base::__before_begin()->__next_ = __h.release(); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +forward_list<_Tp, _Alloc>::push_front(const value_type& __v) +{ + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); + __h->__next_ = base::__before_begin()->__next_; + base::__before_begin()->__next_ = __h.release(); +} + +template +void +forward_list<_Tp, _Alloc>::pop_front() +{ + __node_allocator& __a = base::__alloc(); + __node_pointer __p = base::__before_begin()->__next_; + base::__before_begin()->__next_ = __p->__next_; + __node_traits::destroy(__a, _VSTD::addressof(__p->__value_)); + __node_traits::deallocate(__a, __p, 1); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args) +{ + __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), + _VSTD::forward<_Args>(__args)...); + __h->__next_ = __r->__next_; + __r->__next_ = __h.release(); + return iterator(__r->__next_); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) +{ + __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v)); + __h->__next_ = __r->__next_; + __r->__next_ = __h.release(); + return iterator(__r->__next_); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v) +{ + __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); + __h->__next_ = __r->__next_; + __r->__next_ = __h.release(); + return iterator(__r->__next_); +} + +template +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n, + const value_type& __v) +{ + __node_pointer __r = const_cast<__node_pointer>(__p.__ptr_); + if (__n > 0) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); + __node_pointer __first = __h.release(); + __node_pointer __last = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (--__n; __n != 0; --__n, __last = __last->__next_) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); + __last->__next_ = __h.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (__first != nullptr) + { + __node_pointer __next = __first->__next_; + __node_traits::destroy(__a, _VSTD::addressof(__first->__value_)); + __node_traits::deallocate(__a, __first, 1); + __first = __next; + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __last->__next_ = __r->__next_; + __r->__next_ = __first; + __r = __last; + } + return iterator(__r); +} + +template +template +typename enable_if +< + __is_input_iterator<_InputIterator>::value, + typename forward_list<_Tp, _Alloc>::iterator +>::type +forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, + _InputIterator __f, _InputIterator __l) +{ + __node_pointer __r = const_cast<__node_pointer>(__p.__ptr_); + if (__f != __l) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f); + __node_pointer __first = __h.release(); + __node_pointer __last = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (++__f; __f != __l; ++__f, __last = __last->__next_) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f); + __last->__next_ = __h.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (__first != nullptr) + { + __node_pointer __next = __first->__next_; + __node_traits::destroy(__a, _VSTD::addressof(__first->__value_)); + __node_traits::deallocate(__a, __first, 1); + __first = __next; + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __last->__next_ = __r->__next_; + __r->__next_ = __first; + __r = __last; + } + return iterator(__r); +} + +template +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::erase_after(const_iterator __f) +{ + __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_); + __node_pointer __n = __p->__next_; + __p->__next_ = __n->__next_; + __node_allocator& __a = base::__alloc(); + __node_traits::destroy(__a, _VSTD::addressof(__n->__value_)); + __node_traits::deallocate(__a, __n, 1); + return iterator(__p->__next_); +} + +template +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l) +{ + __node_pointer __e = const_cast<__node_pointer>(__l.__ptr_); + if (__f != __l) + { + __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_); + __node_pointer __n = __p->__next_; + if (__n != __e) + { + __p->__next_ = __e; + __node_allocator& __a = base::__alloc(); + do + { + __p = __n->__next_; + __node_traits::destroy(__a, _VSTD::addressof(__n->__value_)); + __node_traits::deallocate(__a, __n, 1); + __n = __p; + } while (__n != __e); + } + } + return iterator(__e); +} + +template +void +forward_list<_Tp, _Alloc>::resize(size_type __n) +{ + size_type __sz = 0; + iterator __p = before_begin(); + iterator __i = begin(); + iterator __e = end(); + for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz) + ; + if (__i != __e) + erase_after(__p, __e); + else + { + __n -= __sz; + if (__n > 0) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(nullptr, _D(__a, 1)); + for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n, + __ptr = __ptr->__next_) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_)); + __h->__next_ = nullptr; + __ptr->__next_ = __h.release(); + } + } + } +} + +template +void +forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v) +{ + size_type __sz = 0; + iterator __p = before_begin(); + iterator __i = begin(); + iterator __e = end(); + for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz) + ; + if (__i != __e) + erase_after(__p, __e); + else + { + __n -= __sz; + if (__n > 0) + { + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(nullptr, _D(__a, 1)); + for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n, + __ptr = __ptr->__next_) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); + __h->__next_ = nullptr; + __ptr->__next_ = __h.release(); + } + } + } +} + +template +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list& __x) +{ + if (!__x.empty()) + { + if (__p.__ptr_->__next_ != nullptr) + { + const_iterator __lm1 = __x.before_begin(); + while (__lm1.__ptr_->__next_ != nullptr) + ++__lm1; + const_cast<__node_pointer>(__lm1.__ptr_)->__next_ = + const_cast<__node_pointer>(__p.__ptr_)->__next_; + } + const_cast<__node_pointer>(__p.__ptr_)->__next_ = + const_cast<__node_pointer>(__x.__before_begin())->__next_; + const_cast<__node_pointer>(__x.__before_begin())->__next_ = nullptr; + } +} + +template +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list& __x, + const_iterator __i) +{ + const_iterator __lm1 = _VSTD::next(__i); + if (__p != __i && __p != __lm1) + { + const_cast<__node_pointer>(__i.__ptr_)->__next_ = + const_cast<__node_pointer>(__lm1.__ptr_)->__next_; + const_cast<__node_pointer>(__lm1.__ptr_)->__next_ = + const_cast<__node_pointer>(__p.__ptr_)->__next_; + const_cast<__node_pointer>(__p.__ptr_)->__next_ = + const_cast<__node_pointer>(__lm1.__ptr_); + } +} + +template +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list& __x, + const_iterator __f, const_iterator __l) +{ + if (__f != __l && __p != __f) + { + const_iterator __lm1 = __f; + while (__lm1.__ptr_->__next_ != __l.__ptr_) + ++__lm1; + if (__f != __lm1) + { + const_cast<__node_pointer>(__lm1.__ptr_)->__next_ = + const_cast<__node_pointer>(__p.__ptr_)->__next_; + const_cast<__node_pointer>(__p.__ptr_)->__next_ = + const_cast<__node_pointer>(__f.__ptr_)->__next_; + const_cast<__node_pointer>(__f.__ptr_)->__next_ = + const_cast<__node_pointer>(__l.__ptr_); + } + } +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list&& __x) +{ + splice_after(__p, __x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list&& __x, + const_iterator __i) +{ + splice_after(__p, __x, __i); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, + forward_list&& __x, + const_iterator __f, const_iterator __l) +{ + splice_after(__p, __x, __f, __l); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +forward_list<_Tp, _Alloc>::remove(const value_type& __v) +{ + iterator __e = end(); + for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;) + { + if (__i.__ptr_->__next_->__value_ == __v) + { + iterator __j = _VSTD::next(__i, 2); + for (; __j != __e && *__j == __v; ++__j) + ; + erase_after(__i, __j); + if (__j == __e) + break; + __i = __j; + } + else + ++__i; + } +} + +template +template +void +forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred) +{ + iterator __e = end(); + for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;) + { + if (__pred(__i.__ptr_->__next_->__value_)) + { + iterator __j = _VSTD::next(__i, 2); + for (; __j != __e && __pred(*__j); ++__j) + ; + erase_after(__i, __j); + if (__j == __e) + break; + __i = __j; + } + else + ++__i; + } +} + +template +template +void +forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred) +{ + for (iterator __i = begin(), __e = end(); __i != __e;) + { + iterator __j = _VSTD::next(__i); + for (; __j != __e && __binary_pred(*__i, *__j); ++__j) + ; + if (__i.__ptr_->__next_ != __j.__ptr_) + erase_after(__i, __j); + __i = __j; + } +} + +template +template +void +forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp) +{ + if (this != &__x) + { + base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_, + __x.__before_begin()->__next_, + __comp); + __x.__before_begin()->__next_ = nullptr; + } +} + +template +template +typename forward_list<_Tp, _Alloc>::__node_pointer +forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2, + _Compare& __comp) +{ + if (__f1 == nullptr) + return __f2; + if (__f2 == nullptr) + return __f1; + __node_pointer __r; + if (__comp(__f2->__value_, __f1->__value_)) + { + __node_pointer __t = __f2; + while (__t->__next_ != nullptr && + __comp(__t->__next_->__value_, __f1->__value_)) + __t = __t->__next_; + __r = __f2; + __f2 = __t->__next_; + __t->__next_ = __f1; + } + else + __r = __f1; + __node_pointer __p = __f1; + __f1 = __f1->__next_; + while (__f1 != nullptr && __f2 != nullptr) + { + if (__comp(__f2->__value_, __f1->__value_)) + { + __node_pointer __t = __f2; + while (__t->__next_ != nullptr && + __comp(__t->__next_->__value_, __f1->__value_)) + __t = __t->__next_; + __p->__next_ = __f2; + __f2 = __t->__next_; + __t->__next_ = __f1; + } + __p = __f1; + __f1 = __f1->__next_; + } + if (__f2 != nullptr) + __p->__next_ = __f2; + return __r; +} + +template +template +inline _LIBCPP_INLINE_VISIBILITY +void +forward_list<_Tp, _Alloc>::sort(_Compare __comp) +{ + base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_, + _VSTD::distance(begin(), end()), __comp); +} + +template +template +typename forward_list<_Tp, _Alloc>::__node_pointer +forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz, + _Compare& __comp) +{ + switch (__sz) + { + case 0: + case 1: + return __f1; + case 2: + if (__comp(__f1->__next_->__value_, __f1->__value_)) + { + __node_pointer __t = __f1->__next_; + __t->__next_ = __f1; + __f1->__next_ = nullptr; + __f1 = __t; + } + return __f1; + } + difference_type __sz1 = __sz / 2; + difference_type __sz2 = __sz - __sz1; + __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__ptr_; + __node_pointer __f2 = __t->__next_; + __t->__next_ = nullptr; + return __merge(__sort(__f1, __sz1, __comp), + __sort(__f2, __sz2, __comp), __comp); +} + +template +void +forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT +{ + __node_pointer __p = base::__before_begin()->__next_; + if (__p != nullptr) + { + __node_pointer __f = __p->__next_; + __p->__next_ = nullptr; + while (__f != nullptr) + { + __node_pointer __t = __f->__next_; + __f->__next_ = __p; + __p = __f; + __f = __t; + } + base::__before_begin()->__next_ = __p; + } +} + +template +bool operator==(const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + typedef forward_list<_Tp, _Alloc> _C; + typedef typename _C::const_iterator _I; + _I __ix = __x.begin(); + _I __ex = __x.end(); + _I __iy = __y.begin(); + _I __ey = __y.end(); + for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy) + if (!(*__ix == *__iy)) + return false; + return (__ix == __ex) == (__iy == __ey); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + return !(__x == __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool operator< (const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), + __y.begin(), __y.end()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool operator> (const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + return __y < __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool operator>=(const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + return !(__x < __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool operator<=(const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) +{ + return !(__y < __x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_FORWARD_LIST diff --git a/contrib/libc++/include/fstream b/contrib/libc++/include/fstream new file mode 100644 index 000000000000..b6a2ab0e158a --- /dev/null +++ b/contrib/libc++/include/fstream @@ -0,0 +1,1396 @@ +// -*- C++ -*- +//===------------------------- fstream ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FSTREAM +#define _LIBCPP_FSTREAM + +/* + fstream synopsis + +template > +class basic_filebuf + : public basic_streambuf +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // 27.9.1.2 Constructors/destructor: + basic_filebuf(); + basic_filebuf(basic_filebuf&& rhs); + virtual ~basic_filebuf(); + + // 27.9.1.3 Assign/swap: + basic_filebuf& operator=(basic_filebuf&& rhs); + void swap(basic_filebuf& rhs); + + // 27.9.1.4 Members: + bool is_open() const; + basic_filebuf* open(const char* s, ios_base::openmode mode); + basic_filebuf* open(const string& s, ios_base::openmode mode); + basic_filebuf* close(); + +protected: + // 27.9.1.5 Overridden virtual functions: + virtual streamsize showmanyc(); + virtual int_type underflow(); + virtual int_type uflow(); + virtual int_type pbackfail(int_type c = traits_type::eof()); + virtual int_type overflow (int_type c = traits_type::eof()); + virtual basic_streambuf* setbuf(char_type* s, streamsize n); + virtual pos_type seekoff(off_type off, ios_base::seekdir way, + ios_base::openmode which = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type sp, + ios_base::openmode which = ios_base::in | ios_base::out); + virtual int sync(); + virtual void imbue(const locale& loc); +}; + +template + void + swap(basic_filebuf& x, basic_filebuf& y); + +typedef basic_filebuf filebuf; +typedef basic_filebuf wfilebuf; + +template > +class basic_ifstream + : public basic_istream +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + basic_ifstream(); + explicit basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in); + explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in); + basic_ifstream(basic_ifstream&& rhs); + + basic_ifstream& operator=(basic_ifstream&& rhs); + void swap(basic_ifstream& rhs); + + basic_filebuf* rdbuf() const; + bool is_open() const; + void open(const char* s, ios_base::openmode mode = ios_base::in); + void open(const string& s, ios_base::openmode mode = ios_base::in); + void close(); +}; + +template + void + swap(basic_ifstream& x, basic_ifstream& y); + +typedef basic_ifstream ifstream; +typedef basic_ifstream wifstream; + +template > +class basic_ofstream + : public basic_ostream +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + basic_ofstream(); + explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out); + explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out); + basic_ofstream(basic_ofstream&& rhs); + + basic_ofstream& operator=(basic_ofstream&& rhs); + void swap(basic_ofstream& rhs); + + basic_filebuf* rdbuf() const; + bool is_open() const; + void open(const char* s, ios_base::openmode mode = ios_base::out); + void open(const string& s, ios_base::openmode mode = ios_base::out); + void close(); +}; + +template + void + swap(basic_ofstream& x, basic_ofstream& y); + +typedef basic_ofstream ofstream; +typedef basic_ofstream wofstream; + +template > +class basic_fstream + : public basic_iostream +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + basic_fstream(); + explicit basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); + explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); + basic_fstream(basic_fstream&& rhs); + + basic_fstream& operator=(basic_fstream&& rhs); + void swap(basic_fstream& rhs); + + basic_filebuf* rdbuf() const; + bool is_open() const; + void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); + void open(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); + void close(); +}; + +template + void swap(basic_fstream& x, basic_fstream& y); + +typedef basic_fstream fstream; +typedef basic_fstream wfstream; + +} // std + +*/ + +#include <__config> +#include +#include +#include <__locale> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +class _LIBCPP_VISIBLE basic_filebuf + : public basic_streambuf<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef typename traits_type::state_type state_type; + + // 27.9.1.2 Constructors/destructor: + basic_filebuf(); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + basic_filebuf(basic_filebuf&& __rhs); +#endif + virtual ~basic_filebuf(); + + // 27.9.1.3 Assign/swap: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + basic_filebuf& operator=(basic_filebuf&& __rhs); +#endif + void swap(basic_filebuf& __rhs); + + // 27.9.1.4 Members: + bool is_open() const; + basic_filebuf* open(const char* __s, ios_base::openmode __mode); + basic_filebuf* open(const string& __s, ios_base::openmode __mode); + basic_filebuf* close(); + +protected: + // 27.9.1.5 Overridden virtual functions: + virtual int_type underflow(); + virtual int_type pbackfail(int_type __c = traits_type::eof()); + virtual int_type overflow (int_type __c = traits_type::eof()); + virtual basic_streambuf* setbuf(char_type* __s, streamsize __n); + virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __wch = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type __sp, + ios_base::openmode __wch = ios_base::in | ios_base::out); + virtual int sync(); + virtual void imbue(const locale& __loc); + +private: + char* __extbuf_; + const char* __extbufnext_; + const char* __extbufend_; + char __extbuf_min_[8]; + size_t __ebs_; + char_type* __intbuf_; + size_t __ibs_; + FILE* __file_; + const codecvt* __cv_; + state_type __st_; + ios_base::openmode __om_; + ios_base::openmode __cm_; + bool __owns_eb_; + bool __owns_ib_; + bool __always_noconv_; + + bool __read_mode(); + void __write_mode(); +}; + +template +basic_filebuf<_CharT, _Traits>::basic_filebuf() + : __extbuf_(0), + __extbufnext_(0), + __extbufend_(0), + __ebs_(0), + __intbuf_(0), + __ibs_(0), + __file_(0), + __cv_(&use_facet >(this->getloc())), + __st_(), + __om_(0), + __cm_(0), + __owns_eb_(false), + __owns_ib_(false), + __always_noconv_(__cv_->always_noconv()) +{ + setbuf(0, 4096); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) + : basic_streambuf<_CharT, _Traits>(__rhs) +{ + if (__rhs.__extbuf_ == __rhs.__extbuf_min_) + { + __extbuf_ = __extbuf_min_; + __extbufnext_ = __extbuf_ + (__rhs.__extbufnext_ - __rhs.__extbuf_); + __extbufend_ = __extbuf_ + (__rhs.__extbufend_ - __rhs.__extbuf_); + } + else + { + __extbuf_ = __rhs.__extbuf_; + __extbufnext_ = __rhs.__extbufnext_; + __extbufend_ = __rhs.__extbufend_; + } + __ebs_ = __rhs.__ebs_; + __intbuf_ = __rhs.__intbuf_; + __ibs_ = __rhs.__ibs_; + __file_ = __rhs.__file_; + __cv_ = __rhs.__cv_; + __st_ = __rhs.__st_; + __om_ = __rhs.__om_; + __cm_ = __rhs.__cm_; + __owns_eb_ = __rhs.__owns_eb_; + __owns_ib_ = __rhs.__owns_ib_; + __always_noconv_ = __rhs.__always_noconv_; + if (__rhs.pbase()) + { + if (__rhs.pbase() == __rhs.__intbuf_) + this->setp(__intbuf_, __intbuf_ + (__rhs. epptr() - __rhs.pbase())); + else + this->setp((char_type*)__extbuf_, + (char_type*)__extbuf_ + (__rhs. epptr() - __rhs.pbase())); + this->pbump(__rhs. pptr() - __rhs.pbase()); + } + else if (__rhs.eback()) + { + if (__rhs.eback() == __rhs.__intbuf_) + this->setg(__intbuf_, __intbuf_ + (__rhs.gptr() - __rhs.eback()), + __intbuf_ + (__rhs.egptr() - __rhs.eback())); + else + this->setg((char_type*)__extbuf_, + (char_type*)__extbuf_ + (__rhs.gptr() - __rhs.eback()), + (char_type*)__extbuf_ + (__rhs.egptr() - __rhs.eback())); + } + __rhs.__extbuf_ = 0; + __rhs.__extbufnext_ = 0; + __rhs.__extbufend_ = 0; + __rhs.__ebs_ = 0; + __rhs.__intbuf_ = 0; + __rhs.__ibs_ = 0; + __rhs.__file_ = 0; + __rhs.__st_ = state_type(); + __rhs.__om_ = 0; + __rhs.__cm_ = 0; + __rhs.__owns_eb_ = false; + __rhs.__owns_ib_ = false; + __rhs.setg(0, 0, 0); + __rhs.setp(0, 0); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_filebuf<_CharT, _Traits>& +basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs) +{ + close(); + swap(__rhs); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +basic_filebuf<_CharT, _Traits>::~basic_filebuf() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + close(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + } +#endif // _LIBCPP_NO_EXCEPTIONS + if (__owns_eb_) + delete [] __extbuf_; + if (__owns_ib_) + delete [] __intbuf_; +} + +template +void +basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) +{ + basic_streambuf::swap(__rhs); + if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) + { + _VSTD::swap(__extbuf_, __rhs.__extbuf_); + _VSTD::swap(__extbufnext_, __rhs.__extbufnext_); + _VSTD::swap(__extbufend_, __rhs.__extbufend_); + } + else + { + ptrdiff_t __ln = __extbufnext_ - __extbuf_; + ptrdiff_t __le = __extbufend_ - __extbuf_; + ptrdiff_t __rn = __rhs.__extbufnext_ - __rhs.__extbuf_; + ptrdiff_t __re = __rhs.__extbufend_ - __rhs.__extbuf_; + if (__extbuf_ == __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) + { + __extbuf_ = __rhs.__extbuf_; + __rhs.__extbuf_ = __rhs.__extbuf_min_; + } + else if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ == __rhs.__extbuf_min_) + { + __rhs.__extbuf_ = __extbuf_; + __extbuf_ = __extbuf_min_; + } + __extbufnext_ = __extbuf_ + __rn; + __extbufend_ = __extbuf_ + __re; + __rhs.__extbufnext_ = __rhs.__extbuf_ + __ln; + __rhs.__extbufend_ = __rhs.__extbuf_ + __le; + } + _VSTD::swap(__ebs_, __rhs.__ebs_); + _VSTD::swap(__intbuf_, __rhs.__intbuf_); + _VSTD::swap(__ibs_, __rhs.__ibs_); + _VSTD::swap(__file_, __rhs.__file_); + _VSTD::swap(__cv_, __rhs.__cv_); + _VSTD::swap(__st_, __rhs.__st_); + _VSTD::swap(__om_, __rhs.__om_); + _VSTD::swap(__cm_, __rhs.__cm_); + _VSTD::swap(__owns_eb_, __rhs.__owns_eb_); + _VSTD::swap(__owns_ib_, __rhs.__owns_ib_); + _VSTD::swap(__always_noconv_, __rhs.__always_noconv_); + if (this->eback() == (char_type*)__rhs.__extbuf_min_) + { + ptrdiff_t __n = this->gptr() - this->eback(); + ptrdiff_t __e = this->egptr() - this->eback(); + this->setg((char_type*)__extbuf_min_, + (char_type*)__extbuf_min_ + __n, + (char_type*)__extbuf_min_ + __e); + } + else if (this->pbase() == (char_type*)__rhs.__extbuf_min_) + { + ptrdiff_t __n = this->pptr() - this->pbase(); + ptrdiff_t __e = this->epptr() - this->pbase(); + this->setp((char_type*)__extbuf_min_, + (char_type*)__extbuf_min_ + __e); + this->pbump(__n); + } + if (__rhs.eback() == (char_type*)__extbuf_min_) + { + ptrdiff_t __n = __rhs.gptr() - __rhs.eback(); + ptrdiff_t __e = __rhs.egptr() - __rhs.eback(); + __rhs.setg((char_type*)__rhs.__extbuf_min_, + (char_type*)__rhs.__extbuf_min_ + __n, + (char_type*)__rhs.__extbuf_min_ + __e); + } + else if (__rhs.pbase() == (char_type*)__extbuf_min_) + { + ptrdiff_t __n = __rhs.pptr() - __rhs.pbase(); + ptrdiff_t __e = __rhs.epptr() - __rhs.pbase(); + __rhs.setp((char_type*)__rhs.__extbuf_min_, + (char_type*)__rhs.__extbuf_min_ + __e); + __rhs.pbump(__n); + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_filebuf<_CharT, _Traits>& __x, basic_filebuf<_CharT, _Traits>& __y) +{ + __x.swap(__y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +basic_filebuf<_CharT, _Traits>::is_open() const +{ + return __file_ != 0; +} + +template +basic_filebuf<_CharT, _Traits>* +basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) +{ + basic_filebuf<_CharT, _Traits>* __rt = 0; + if (__file_ == 0) + { + __rt = this; + const char* __mdstr; + switch (__mode & ~ios_base::ate) + { + case ios_base::out: + case ios_base::out | ios_base::trunc: + __mdstr = "w"; + break; + case ios_base::out | ios_base::app: + case ios_base::app: + __mdstr = "a"; + break; + case ios_base::in: + __mdstr = "r"; + break; + case ios_base::in | ios_base::out: + __mdstr = "r+"; + break; + case ios_base::in | ios_base::out | ios_base::trunc: + __mdstr = "w+"; + break; + case ios_base::in | ios_base::out | ios_base::app: + case ios_base::in | ios_base::app: + __mdstr = "a+"; + break; + case ios_base::out | ios_base::binary: + case ios_base::out | ios_base::trunc | ios_base::binary: + __mdstr = "wb"; + break; + case ios_base::out | ios_base::app | ios_base::binary: + case ios_base::app | ios_base::binary: + __mdstr = "ab"; + break; + case ios_base::in | ios_base::binary: + __mdstr = "rb"; + break; + case ios_base::in | ios_base::out | ios_base::binary: + __mdstr = "r+b"; + break; + case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary: + __mdstr = "w+b"; + break; + case ios_base::in | ios_base::out | ios_base::app | ios_base::binary: + case ios_base::in | ios_base::app | ios_base::binary: + __mdstr = "a+b"; + break; + default: + __rt = 0; + break; + } + if (__rt) + { + __file_ = fopen(__s, __mdstr); + if (__file_) + { + __om_ = __mode; + if (__mode & ios_base::ate) + { + if (fseek(__file_, 0, SEEK_END)) + { + fclose(__file_); + __file_ = 0; + __rt = 0; + } + } + } + else + __rt = 0; + } + } + return __rt; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_filebuf<_CharT, _Traits>* +basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) +{ + return open(__s.c_str(), __mode); +} + +template +basic_filebuf<_CharT, _Traits>* +basic_filebuf<_CharT, _Traits>::close() +{ + basic_filebuf<_CharT, _Traits>* __rt = 0; + if (__file_) + { + __rt = this; + unique_ptr __h(__file_, fclose); + if ((__cm_ & ios_base::out) && sync()) + __rt = 0; + if (fclose(__h.release()) == 0) + __file_ = 0; + else + __rt = 0; + } + return __rt; +} + +template +typename basic_filebuf<_CharT, _Traits>::int_type +basic_filebuf<_CharT, _Traits>::underflow() +{ + if (__file_ == 0) + return traits_type::eof(); + bool __initial = __read_mode(); + char_type __1buf; + if (this->gptr() == 0) + this->setg(&__1buf, &__1buf+1, &__1buf+1); + const size_t __unget_sz = __initial ? 0 : min((this->egptr() - this->eback()) / 2, 4); + int_type __c = traits_type::eof(); + if (this->gptr() == this->egptr()) + { + memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); + if (__always_noconv_) + { + size_t __nmemb = static_cast(this->egptr() - this->eback() - __unget_sz); + __nmemb = fread(this->eback() + __unget_sz, 1, __nmemb, __file_); + if (__nmemb != 0) + { + this->setg(this->eback(), + this->eback() + __unget_sz, + this->eback() + __unget_sz + __nmemb); + __c = traits_type::to_int_type(*this->gptr()); + } + } + else + { + memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); + __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); + __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); + size_t __nmemb = _VSTD::min(static_cast(this->egptr() - this->eback() - __unget_sz), + static_cast(__extbufend_ - __extbufnext_)); + codecvt_base::result __r; + state_type __svs = __st_; + size_t __nr = fread((void*)__extbufnext_, 1, __nmemb, __file_); + if (__nr != 0) + { + __extbufend_ = __extbufnext_ + __nr; + char_type* __inext; + __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, + this->eback() + __unget_sz, + this->egptr(), __inext); + if (__r == codecvt_base::noconv) + { + this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_); + __c = traits_type::to_int_type(*this->gptr()); + } + else if (__inext != this->eback() + __unget_sz) + { + this->setg(this->eback(), this->eback() + __unget_sz, __inext); + __c = traits_type::to_int_type(*this->gptr()); + } + } + } + } + else + __c = traits_type::to_int_type(*this->gptr()); + if (this->eback() == &__1buf) + this->setg(0, 0, 0); + return __c; +} + +template +typename basic_filebuf<_CharT, _Traits>::int_type +basic_filebuf<_CharT, _Traits>::pbackfail(int_type __c) +{ + if (__file_ && this->eback() < this->gptr()) + { + if (traits_type::eq_int_type(__c, traits_type::eof())) + { + this->gbump(-1); + return traits_type::not_eof(__c); + } + if ((__om_ & ios_base::out) || + traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) + { + this->gbump(-1); + *this->gptr() = traits_type::to_char_type(__c); + return __c; + } + } + return traits_type::eof(); +} + +template +typename basic_filebuf<_CharT, _Traits>::int_type +basic_filebuf<_CharT, _Traits>::overflow(int_type __c) +{ + if (__file_ == 0) + return traits_type::eof(); + __write_mode(); + char_type __1buf; + char_type* __pb_save = this->pbase(); + char_type* __epb_save = this->epptr(); + if (!traits_type::eq_int_type(__c, traits_type::eof())) + { + if (this->pptr() == 0) + this->setp(&__1buf, &__1buf+1); + *this->pptr() = traits_type::to_char_type(__c); + this->pbump(1); + } + if (this->pptr() != this->pbase()) + { + if (__always_noconv_) + { + size_t __nmemb = static_cast(this->pptr() - this->pbase()); + if (fwrite(this->pbase(), sizeof(char_type), __nmemb, __file_) != __nmemb) + return traits_type::eof(); + } + else + { + char* __extbe = __extbuf_; + codecvt_base::result __r; + do + { + const char_type* __e; + __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, + __extbuf_, __extbuf_ + __ebs_, __extbe); + if (__e == this->pbase()) + return traits_type::eof(); + if (__r == codecvt_base::noconv) + { + size_t __nmemb = static_cast(this->pptr() - this->pbase()); + if (fwrite(this->pbase(), 1, __nmemb, __file_) != __nmemb) + return traits_type::eof(); + } + else if (__r == codecvt_base::ok || __r == codecvt_base::partial) + { + size_t __nmemb = static_cast(__extbe - __extbuf_); + if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) + return traits_type::eof(); + if (__r == codecvt_base::partial) + { + this->setp((char_type*)__e, this->pptr()); + this->pbump(this->epptr() - this->pbase()); + } + } + else + return traits_type::eof(); + } while (__r == codecvt_base::partial); + } + this->setp(__pb_save, __epb_save); + } + return traits_type::not_eof(__c); +} + +template +basic_streambuf<_CharT, _Traits>* +basic_filebuf<_CharT, _Traits>::setbuf(char_type* __s, streamsize __n) +{ + this->setg(0, 0, 0); + this->setp(0, 0); + if (__owns_eb_) + delete [] __extbuf_; + if (__owns_ib_) + delete [] __intbuf_; + __ebs_ = __n; + if (__ebs_ > sizeof(__extbuf_min_)) + { + if (__always_noconv_ && __s) + { + __extbuf_ = (char*)__s; + __owns_eb_ = false; + } + else + { + __extbuf_ = new char[__ebs_]; + __owns_eb_ = true; + } + } + else + { + __extbuf_ = __extbuf_min_; + __ebs_ = sizeof(__extbuf_min_); + __owns_eb_ = false; + } + if (!__always_noconv_) + { + __ibs_ = max(__n, sizeof(__extbuf_min_)); + if (__s && __ibs_ >= sizeof(__extbuf_min_)) + { + __intbuf_ = __s; + __owns_ib_ = false; + } + else + { + __intbuf_ = new char_type[__ibs_]; + __owns_ib_ = true; + } + } + else + { + __ibs_ = 0; + __intbuf_ = 0; + __owns_ib_ = false; + } + return this; +} + +template +typename basic_filebuf<_CharT, _Traits>::pos_type +basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode) +{ + int __width = __cv_->encoding(); + if (__file_ == 0 || (__width <= 0 && __off != 0) || sync()) + return pos_type(off_type(-1)); + // __width > 0 || __off == 0 + int __whence; + switch (__way) + { + case ios_base::beg: + __whence = SEEK_SET; + break; + case ios_base::cur: + __whence = SEEK_CUR; + break; + case ios_base::end: + __whence = SEEK_END; + break; + default: + return pos_type(off_type(-1)); + } + if (fseeko(__file_, __width > 0 ? __width * __off : 0, __whence)) + return pos_type(off_type(-1)); + pos_type __r = ftello(__file_); + __r.state(__st_); + return __r; +} + +template +typename basic_filebuf<_CharT, _Traits>::pos_type +basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) +{ + if (__file_ == 0 || sync()) + return pos_type(off_type(-1)); + if (fseeko(__file_, __sp, SEEK_SET)) + return pos_type(off_type(-1)); + return __sp; +} + +template +int +basic_filebuf<_CharT, _Traits>::sync() +{ + if (__file_ == 0) + return 0; + if (__cm_ & ios_base::out) + { + if (this->pptr() != this->pbase()) + if (overflow() == traits_type::eof()) + return -1; + codecvt_base::result __r; + do + { + char* __extbe; + __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); + size_t __nmemb = static_cast(__extbe - __extbuf_); + if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) + return -1; + } while (__r == codecvt_base::partial); + if (__r == codecvt_base::error) + return -1; + if (fflush(__file_)) + return -1; + } + else if (__cm_ & ios_base::in) + { + off_type __c; + if (__always_noconv_) + __c = this->egptr() - this->gptr(); + else + { + int __width = __cv_->encoding(); + __c = __extbufend_ - __extbufnext_; + if (__width > 0) + __c += __width * (this->egptr() - this->gptr()); + else + { + if (this->gptr() != this->egptr()) + { + reverse(this->gptr(), this->egptr()); + codecvt_base::result __r; + const char_type* __e = this->gptr(); + char* __extbe; + do + { + __r = __cv_->out(__st_, __e, this->egptr(), __e, + __extbuf_, __extbuf_ + __ebs_, __extbe); + switch (__r) + { + case codecvt_base::noconv: + __c += this->egptr() - this->gptr(); + break; + case codecvt_base::ok: + case codecvt_base::partial: + __c += __extbe - __extbuf_; + break; + default: + return -1; + } + } while (__r == codecvt_base::partial); + } + } + } + if (fseeko(__file_, -__c, SEEK_CUR)) + return -1; + this->setg(0, 0, 0); + __cm_ = 0; + } + return 0; +} + +template +void +basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc) +{ + sync(); + __cv_ = &use_facet >(__loc); + bool __old_anc = __always_noconv_; + __always_noconv_ = __cv_->always_noconv(); + if (__old_anc != __always_noconv_) + { + this->setg(0, 0, 0); + this->setp(0, 0); + // invariant, char_type is char, else we couldn't get here + if (__always_noconv_) // need to dump __intbuf_ + { + if (__owns_eb_) + delete [] __extbuf_; + __owns_eb_ = __owns_ib_; + __ebs_ = __ibs_; + __extbuf_ = (char*)__intbuf_; + __ibs_ = 0; + __intbuf_ = 0; + __owns_ib_ = false; + } + else // need to obtain an __intbuf_. + { // If __extbuf_ is user-supplied, use it, else new __intbuf_ + if (!__owns_eb_ && __extbuf_ != __extbuf_min_) + { + __ibs_ = __ebs_; + __intbuf_ = (char_type*)__extbuf_; + __owns_ib_ = false; + __extbuf_ = new char[__ebs_]; + __owns_eb_ = true; + } + else + { + __ibs_ = __ebs_; + __intbuf_ = new char_type[__ibs_]; + __owns_ib_ = true; + } + } + } +} + +template +bool +basic_filebuf<_CharT, _Traits>::__read_mode() +{ + if (!(__cm_ & ios_base::in)) + { + this->setp(0, 0); + if (__always_noconv_) + this->setg((char_type*)__extbuf_, + (char_type*)__extbuf_ + __ebs_, + (char_type*)__extbuf_ + __ebs_); + else + this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); + __cm_ = ios_base::in; + return true; + } + return false; +} + +template +void +basic_filebuf<_CharT, _Traits>::__write_mode() +{ + if (!(__cm_ & ios_base::out)) + { + this->setg(0, 0, 0); + if (__ebs_ > sizeof(__extbuf_min_)) + { + if (__always_noconv_) + this->setp((char_type*)__extbuf_, + (char_type*)__extbuf_ + (__ebs_ - 1)); + else + this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); + } + else + this->setp(0, 0); + __cm_ = ios_base::out; + } +} + +// basic_ifstream + +template +class _LIBCPP_VISIBLE basic_ifstream + : public basic_istream<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + basic_ifstream(); + explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in); + explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + basic_ifstream(basic_ifstream&& __rhs); +#endif + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + basic_ifstream& operator=(basic_ifstream&& __rhs); +#endif + void swap(basic_ifstream& __rhs); + + basic_filebuf* rdbuf() const; + bool is_open() const; + void open(const char* __s, ios_base::openmode __mode = ios_base::in); + void open(const string& __s, ios_base::openmode __mode = ios_base::in); + void close(); + +private: + basic_filebuf __sb_; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ifstream<_CharT, _Traits>::basic_ifstream() + : basic_istream(&__sb_) +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode) + : basic_istream(&__sb_) +{ + if (__sb_.open(__s, __mode | ios_base::in) == 0) + this->setstate(ios_base::failbit); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode) + : basic_istream(&__sb_) +{ + if (__sb_.open(__s, __mode | ios_base::in) == 0) + this->setstate(ios_base::failbit); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs) + : basic_istream(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) +{ + this->set_rdbuf(&__sb_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ifstream<_CharT, _Traits>& +basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs) +{ + basic_istream::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs) +{ + basic_istream::swap(__rhs); + __sb_.swap(__rhs.__sb_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_ifstream<_CharT, _Traits>& __x, basic_ifstream<_CharT, _Traits>& __y) +{ + __x.swap(__y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_filebuf<_CharT, _Traits>* +basic_ifstream<_CharT, _Traits>::rdbuf() const +{ + return const_cast*>(&__sb_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +basic_ifstream<_CharT, _Traits>::is_open() const +{ + return __sb_.is_open(); +} + +template +void +basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode | ios_base::in)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +template +void +basic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode | ios_base::in)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ifstream<_CharT, _Traits>::close() +{ + if (__sb_.close() == 0) + this->setstate(ios_base::failbit); +} + +// basic_ofstream + +template +class _LIBCPP_VISIBLE basic_ofstream + : public basic_ostream<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + basic_ofstream(); + explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out); + explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + basic_ofstream(basic_ofstream&& __rhs); +#endif + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + basic_ofstream& operator=(basic_ofstream&& __rhs); +#endif + void swap(basic_ofstream& __rhs); + + basic_filebuf* rdbuf() const; + bool is_open() const; + void open(const char* __s, ios_base::openmode __mode = ios_base::out); + void open(const string& __s, ios_base::openmode __mode = ios_base::out); + void close(); + +private: + basic_filebuf __sb_; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ofstream<_CharT, _Traits>::basic_ofstream() + : basic_ostream(&__sb_) +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode) + : basic_ostream(&__sb_) +{ + if (__sb_.open(__s, __mode | ios_base::out) == 0) + this->setstate(ios_base::failbit); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode) + : basic_ostream(&__sb_) +{ + if (__sb_.open(__s, __mode | ios_base::out) == 0) + this->setstate(ios_base::failbit); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs) + : basic_ostream(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) +{ + this->set_rdbuf(&__sb_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ofstream<_CharT, _Traits>& +basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs) +{ + basic_ostream::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs) +{ + basic_ostream::swap(__rhs); + __sb_.swap(__rhs.__sb_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_ofstream<_CharT, _Traits>& __x, basic_ofstream<_CharT, _Traits>& __y) +{ + __x.swap(__y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_filebuf<_CharT, _Traits>* +basic_ofstream<_CharT, _Traits>::rdbuf() const +{ + return const_cast*>(&__sb_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +basic_ofstream<_CharT, _Traits>::is_open() const +{ + return __sb_.is_open(); +} + +template +void +basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode | ios_base::out)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +template +void +basic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode | ios_base::out)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ofstream<_CharT, _Traits>::close() +{ + if (__sb_.close() == 0) + this->setstate(ios_base::failbit); +} + +// basic_fstream + +template +class _LIBCPP_VISIBLE basic_fstream + : public basic_iostream<_CharT, _Traits> +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + basic_fstream(); + explicit basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); + explicit basic_fstream(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + basic_fstream(basic_fstream&& __rhs); +#endif + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + basic_fstream& operator=(basic_fstream&& __rhs); +#endif + void swap(basic_fstream& __rhs); + + basic_filebuf* rdbuf() const; + bool is_open() const; + void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); + void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); + void close(); + +private: + basic_filebuf __sb_; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_fstream<_CharT, _Traits>::basic_fstream() + : basic_iostream(&__sb_) +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode) + : basic_iostream(&__sb_) +{ + if (__sb_.open(__s, __mode) == 0) + this->setstate(ios_base::failbit); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode) + : basic_iostream(&__sb_) +{ + if (__sb_.open(__s, __mode) == 0) + this->setstate(ios_base::failbit); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs) + : basic_iostream(_VSTD::move(__rhs)), + __sb_(_VSTD::move(__rhs.__sb_)) +{ + this->set_rdbuf(&__sb_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_fstream<_CharT, _Traits>& +basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs) +{ + basic_iostream::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs) +{ + basic_iostream::swap(__rhs); + __sb_.swap(__rhs.__sb_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(basic_fstream<_CharT, _Traits>& __x, basic_fstream<_CharT, _Traits>& __y) +{ + __x.swap(__y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_filebuf<_CharT, _Traits>* +basic_fstream<_CharT, _Traits>::rdbuf() const +{ + return const_cast*>(&__sb_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +basic_fstream<_CharT, _Traits>::is_open() const +{ + return __sb_.is_open(); +} + +template +void +basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +template +void +basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) +{ + if (__sb_.open(__s, __mode)) + this->clear(); + else + this->setstate(ios_base::failbit); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_fstream<_CharT, _Traits>::close() +{ + if (__sb_.close() == 0) + this->setstate(ios_base::failbit); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_FSTREAM diff --git a/contrib/libc++/include/functional b/contrib/libc++/include/functional new file mode 100644 index 000000000000..59b132c4515c --- /dev/null +++ b/contrib/libc++/include/functional @@ -0,0 +1,1999 @@ +// -*- C++ -*- +//===------------------------ functional ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FUNCTIONAL +#define _LIBCPP_FUNCTIONAL + +/* + functional synopsis + +namespace std +{ + +template +struct unary_function +{ + typedef Arg argument_type; + typedef Result result_type; +}; + +template +struct binary_function +{ + typedef Arg1 first_argument_type; + typedef Arg2 second_argument_type; + typedef Result result_type; +}; + +template +class reference_wrapper + : public unary_function // if wrapping a unary functor + : public binary_function // if wraping a binary functor +{ +public: + // types + typedef T type; + typedef see below result_type; // Not always defined + + // construct/copy/destroy + reference_wrapper(T&) noexcept; + reference_wrapper(T&&) = delete; // do not bind to temps + reference_wrapper(const reference_wrapper& x) noexcept; + + // assignment + reference_wrapper& operator=(const reference_wrapper& x) noexcept; + + // access + operator T& () const noexcept; + T& get() const noexcept; + + // invoke + template + typename result_of::type + operator() (ArgTypes&&...) const; +}; + +template reference_wrapper ref(T& t) noexcept; +template void ref(const T&& t) = delete; +template reference_wrapper ref(reference_wrappert) noexcept; + +template reference_wrapper cref(const T& t) noexcept; +template void cref(const T&& t) = delete; +template reference_wrapper cref(reference_wrapper t) noexcept; + +template +struct plus : binary_function +{ + T operator()(const T& x, const T& y) const; +}; + +template +struct minus : binary_function +{ + T operator()(const T& x, const T& y) const; +}; + +template +struct multiplies : binary_function +{ + T operator()(const T& x, const T& y) const; +}; + +template +struct divides : binary_function +{ + T operator()(const T& x, const T& y) const; +}; + +template +struct modulus : binary_function +{ + T operator()(const T& x, const T& y) const; +}; + +template +struct negate : unary_function +{ + T operator()(const T& x) const; +}; + +template +struct equal_to : binary_function +{ + bool operator()(const T& x, const T& y) const; +}; + +template +struct not_equal_to : binary_function +{ + bool operator()(const T& x, const T& y) const; +}; + +template +struct greater : binary_function +{ + bool operator()(const T& x, const T& y) const; +}; + +template +struct less : binary_function +{ + bool operator()(const T& x, const T& y) const; +}; + +template +struct greater_equal : binary_function +{ + bool operator()(const T& x, const T& y) const; +}; + +template +struct less_equal : binary_function +{ + bool operator()(const T& x, const T& y) const; +}; + +template +struct logical_and : binary_function +{ + bool operator()(const T& x, const T& y) const; +}; + +template +struct logical_or : binary_function +{ + bool operator()(const T& x, const T& y) const; +}; + +template +struct logical_not : unary_function +{ + bool operator()(const T& x) const; +}; + +template +class unary_negate + : public unary_function +{ +public: + explicit unary_negate(const Predicate& pred); + bool operator()(const typename Predicate::argument_type& x) const; +}; + +template unary_negate not1(const Predicate& pred); + +template +class binary_negate + : public binary_function +{ +public: + explicit binary_negate(const Predicate& pred); + bool operator()(const typename Predicate::first_argument_type& x, + const typename Predicate::second_argument_type& y) const; +}; + +template binary_negate not2(const Predicate& pred); + +template struct is_bind_expression; +template struct is_placeholder; + +template + unspecified bind(Fn&&, BoundArgs&&...); +template + unspecified bind(Fn&&, BoundArgs&&...); + +namespace placeholders { + // M is the implementation-defined number of placeholders + extern unspecified _1; + extern unspecified _2; + . + . + . + extern unspecified _M; +} + +template +class binder1st + : public unary_function +{ +protected: + Operation op; + typename Operation::first_argument_type value; +public: + binder1st(const Operation& x, const typename Operation::first_argument_type y); + typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; + typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; +}; + +template +binder1st bind1st(const Operation& op, const T& x); + +template +class binder2nd + : public unary_function +{ +protected: + Operation op; + typename Operation::second_argument_type value; +public: + binder2nd(const Operation& x, const typename Operation::second_argument_type y); + typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; + typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; +}; + +template +binder2nd bind2nd(const Operation& op, const T& x); + +template +class pointer_to_unary_function : public unary_function +{ +public: + explicit pointer_to_unary_function(Result (*f)(Arg)); + Result operator()(Arg x) const; +}; + +template +pointer_to_unary_function ptr_fun(Result (*f)(Arg)); + +template +class pointer_to_binary_function : public binary_function +{ +public: + explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); + Result operator()(Arg1 x, Arg2 y) const; +}; + +template +pointer_to_binary_function ptr_fun(Result (*f)(Arg1,Arg2)); + +template +class mem_fun_t : public unary_function +{ +public: + explicit mem_fun_t(S (T::*p)()); + S operator()(T* p) const; +}; + +template +class mem_fun1_t : public binary_function +{ +public: + explicit mem_fun1_t(S (T::*p)(A)); + S operator()(T* p, A x) const; +}; + +template mem_fun_t mem_fun(S (T::*f)()); +template mem_fun1_t mem_fun(S (T::*f)(A)); + +template +class mem_fun_ref_t : public unary_function +{ +public: + explicit mem_fun_ref_t(S (T::*p)()); + S operator()(T& p) const; +}; + +template +class mem_fun1_ref_t : public binary_function +{ +public: + explicit mem_fun1_ref_t(S (T::*p)(A)); + S operator()(T& p, A x) const; +}; + +template mem_fun_ref_t mem_fun_ref(S (T::*f)()); +template mem_fun1_ref_t mem_fun_ref(S (T::*f)(A)); + +template +class const_mem_fun_t : public unary_function +{ +public: + explicit const_mem_fun_t(S (T::*p)() const); + S operator()(const T* p) const; +}; + +template +class const_mem_fun1_t : public binary_function +{ +public: + explicit const_mem_fun1_t(S (T::*p)(A) const); + S operator()(const T* p, A x) const; +}; + +template const_mem_fun_t mem_fun(S (T::*f)() const); +template const_mem_fun1_t mem_fun(S (T::*f)(A) const); + +template +class const_mem_fun_ref_t : public unary_function +{ +public: + explicit const_mem_fun_ref_t(S (T::*p)() const); + S operator()(const T& p) const; +}; + +template +class const_mem_fun1_ref_t : public binary_function +{ +public: + explicit const_mem_fun1_ref_t(S (T::*p)(A) const); + S operator()(const T& p, A x) const; +}; + +template const_mem_fun_ref_t mem_fun_ref(S (T::*f)() const); +template const_mem_fun1_ref_t mem_fun_ref(S (T::*f)(A) const); + +template unspecified mem_fn(R T::*); +template unspecified mem_fn(R (T::*)(Args...)); +template unspecified mem_fn(R (T::*)(Args...) const); +template unspecified mem_fn(R (T::*)(Args...) volatile); +template unspecified mem_fn(R (T::*)(Args...) const volatile); +template unspecified mem_fn(R (T::*)(Args...) &); +template unspecified mem_fn(R (T::*)(Args...) const &); +template unspecified mem_fn(R (T::*)(Args...) volatile &); +template unspecified mem_fn(R (T::*)(Args...) const volatile &); +template unspecified mem_fn(R (T::*)(Args...) &&); +template unspecified mem_fn(R (T::*)(Args...) const &&); +template unspecified mem_fn(R (T::*)(Args...) volatile &&); +template unspecified mem_fn(R (T::*)(Args...) const volatile &&); + +class bad_function_call + : public exception +{ +}; + +template class function; // undefined + +template +class function + : public unary_function // iff sizeof...(ArgTypes) == 1 and + // ArgTypes contains T1 + : public binary_function // iff sizeof...(ArgTypes) == 2 and + // ArgTypes contains T1 and T2 +{ +public: + typedef R result_type; + + // construct/copy/destroy: + function() noexcept; + function(nullptr_t) noexcept; + function(const function&); + function(function&&) noexcept; + template + function(F); + template + function(allocator_arg_t, const Alloc&) noexcept; + template + function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; + template + function(allocator_arg_t, const Alloc&, const function&); + template + function(allocator_arg_t, const Alloc&, function&&); + template + function(allocator_arg_t, const Alloc&, F); + + function& operator=(const function&); + function& operator=(function&&) noexcept; + function& operator=(nullptr_t) noexcept; + template + function& operator=(F&&); + template + function& operator=(reference_wrapper) noexcept; + + ~function(); + + // function modifiers: + void swap(function&) noexcept; + template + void assign(F&&, const Alloc&); + + // function capacity: + explicit operator bool() const noexcept; + + // function invocation: + R operator()(ArgTypes...) const; + + // function target access: + const std::type_info& target_type() const noexcept; + template T* target() noexcept; + template const T* target() const noexcept; +}; + +// Null pointer comparisons: +template + bool operator==(const function&, nullptr_t) noexcept; + +template + bool operator==(nullptr_t, const function&) noexcept; + +template + bool operator!=(const function&, nullptr_t) noexcept; + +template + bool operator!=(nullptr_t, const function&) noexcept; + +// specialized algorithms: +template + void swap(function&, function&) noexcept; + +template struct hash; + +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; +template <> struct hash; + +template <> struct hash; +template <> struct hash; +template <> struct hash; + +template struct hash; + +} // std + +POLICY: For non-variadic implementations, the number of arguments is limited + to 3. It is hoped that the need for non-variadic implementations + will be minimal. + +*/ + +#include <__config> +#include +#include +#include +#include +#include + +#include <__functional_base> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct _LIBCPP_VISIBLE plus : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x + __y;} +}; + +template +struct _LIBCPP_VISIBLE minus : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x - __y;} +}; + +template +struct _LIBCPP_VISIBLE multiplies : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x * __y;} +}; + +template +struct _LIBCPP_VISIBLE divides : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x / __y;} +}; + +template +struct _LIBCPP_VISIBLE modulus : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x % __y;} +}; + +template +struct _LIBCPP_VISIBLE negate : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const + {return -__x;} +}; + +template +struct _LIBCPP_VISIBLE equal_to : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x == __y;} +}; + +template +struct _LIBCPP_VISIBLE not_equal_to : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x != __y;} +}; + +template +struct _LIBCPP_VISIBLE greater : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x > __y;} +}; + +template +struct _LIBCPP_VISIBLE less : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x < __y;} +}; + +template +struct _LIBCPP_VISIBLE greater_equal : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x >= __y;} +}; + +template +struct _LIBCPP_VISIBLE less_equal : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x <= __y;} +}; + +template +struct _LIBCPP_VISIBLE logical_and : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x && __y;} +}; + +template +struct _LIBCPP_VISIBLE logical_or : binary_function<_Tp, _Tp, bool> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x || __y;} +}; + +template +struct _LIBCPP_VISIBLE logical_not : unary_function<_Tp, bool> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const + {return !__x;} +}; + +template +struct _LIBCPP_VISIBLE bit_and : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x & __y;} +}; + +template +struct _LIBCPP_VISIBLE bit_or : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x | __y;} +}; + +template +struct _LIBCPP_VISIBLE bit_xor : binary_function<_Tp, _Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x ^ __y;} +}; + +template +class _LIBCPP_VISIBLE unary_negate + : public unary_function +{ + _Predicate __pred_; +public: + _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred) + : __pred_(__pred) {} + _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const + {return !__pred_(__x);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +unary_negate<_Predicate> +not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} + +template +class _LIBCPP_VISIBLE binary_negate + : public binary_function +{ + _Predicate __pred_; +public: + _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred) + : __pred_(__pred) {} + _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x, + const typename _Predicate::second_argument_type& __y) const + {return !__pred_(__x, __y);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +binary_negate<_Predicate> +not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} + +template +class _LIBCPP_VISIBLE binder1st + : public unary_function +{ +protected: + __Operation op; + typename __Operation::first_argument_type value; +public: + _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, + const typename __Operation::first_argument_type __y) + : op(__x), value(__y) {} + _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() + (typename __Operation::second_argument_type& __x) const + {return op(value, __x);} + _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() + (const typename __Operation::second_argument_type& __x) const + {return op(value, __x);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +binder1st<__Operation> +bind1st(const __Operation& __op, const _Tp& __x) + {return binder1st<__Operation>(__op, __x);} + +template +class _LIBCPP_VISIBLE binder2nd + : public unary_function +{ +protected: + __Operation op; + typename __Operation::second_argument_type value; +public: + _LIBCPP_INLINE_VISIBILITY + binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) + : op(__x), value(__y) {} + _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() + ( typename __Operation::first_argument_type& __x) const + {return op(__x, value);} + _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() + (const typename __Operation::first_argument_type& __x) const + {return op(__x, value);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +binder2nd<__Operation> +bind2nd(const __Operation& __op, const _Tp& __x) + {return binder2nd<__Operation>(__op, __x);} + +template +class _LIBCPP_VISIBLE pointer_to_unary_function + : public unary_function<_Arg, _Result> +{ + _Result (*__f_)(_Arg); +public: + _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) + : __f_(__f) {} + _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const + {return __f_(__x);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +pointer_to_unary_function<_Arg,_Result> +ptr_fun(_Result (*__f)(_Arg)) + {return pointer_to_unary_function<_Arg,_Result>(__f);} + +template +class _LIBCPP_VISIBLE pointer_to_binary_function + : public binary_function<_Arg1, _Arg2, _Result> +{ + _Result (*__f_)(_Arg1, _Arg2); +public: + _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) + : __f_(__f) {} + _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const + {return __f_(__x, __y);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +pointer_to_binary_function<_Arg1,_Arg2,_Result> +ptr_fun(_Result (*__f)(_Arg1,_Arg2)) + {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} + +template +class _LIBCPP_VISIBLE mem_fun_t : public unary_function<_Tp*, _Sp> +{ + _Sp (_Tp::*__p_)(); +public: + _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const + {return (__p->*__p_)();} +}; + +template +class _LIBCPP_VISIBLE mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap); +public: + _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const + {return (__p->*__p_)(__x);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +mem_fun_t<_Sp,_Tp> +mem_fun(_Sp (_Tp::*__f)()) + {return mem_fun_t<_Sp,_Tp>(__f);} + +template +inline _LIBCPP_INLINE_VISIBILITY +mem_fun1_t<_Sp,_Tp,_Ap> +mem_fun(_Sp (_Tp::*__f)(_Ap)) + {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} + +template +class _LIBCPP_VISIBLE mem_fun_ref_t : public unary_function<_Tp, _Sp> +{ + _Sp (_Tp::*__p_)(); +public: + _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const + {return (__p.*__p_)();} +}; + +template +class _LIBCPP_VISIBLE mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap); +public: + _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const + {return (__p.*__p_)(__x);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +mem_fun_ref_t<_Sp,_Tp> +mem_fun_ref(_Sp (_Tp::*__f)()) + {return mem_fun_ref_t<_Sp,_Tp>(__f);} + +template +inline _LIBCPP_INLINE_VISIBILITY +mem_fun1_ref_t<_Sp,_Tp,_Ap> +mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) + {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} + +template +class _LIBCPP_VISIBLE const_mem_fun_t : public unary_function +{ + _Sp (_Tp::*__p_)() const; +public: + _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const + {return (__p->*__p_)();} +}; + +template +class _LIBCPP_VISIBLE const_mem_fun1_t : public binary_function +{ + _Sp (_Tp::*__p_)(_Ap) const; +public: + _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const + {return (__p->*__p_)(__x);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +const_mem_fun_t<_Sp,_Tp> +mem_fun(_Sp (_Tp::*__f)() const) + {return const_mem_fun_t<_Sp,_Tp>(__f);} + +template +inline _LIBCPP_INLINE_VISIBILITY +const_mem_fun1_t<_Sp,_Tp,_Ap> +mem_fun(_Sp (_Tp::*__f)(_Ap) const) + {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} + +template +class _LIBCPP_VISIBLE const_mem_fun_ref_t : public unary_function<_Tp, _Sp> +{ + _Sp (_Tp::*__p_)() const; +public: + _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const + {return (__p.*__p_)();} +}; + +template +class _LIBCPP_VISIBLE const_mem_fun1_ref_t + : public binary_function<_Tp, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap) const; +public: + _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const + {return (__p.*__p_)(__x);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +const_mem_fun_ref_t<_Sp,_Tp> +mem_fun_ref(_Sp (_Tp::*__f)() const) + {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} + +template +inline _LIBCPP_INLINE_VISIBILITY +const_mem_fun1_ref_t<_Sp,_Tp,_Ap> +mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) + {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} + +#ifdef _LIBCPP_HAS_NO_VARIADICS + +#include <__functional_03> + +#else // _LIBCPP_HAS_NO_VARIADICS + +template +class __mem_fn + : public __weak_result_type<_Tp> +{ +public: + // types + typedef _Tp type; +private: + type __f_; + +public: + _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} + + // invoke + template + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return::type + operator() (_ArgTypes&&... __args) + { + return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); + } +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R _T::*> +mem_fn(_R _T::* __pm) +{ + return __mem_fn<_R _T::*>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_Args...)> +mem_fn(_R (_T::* __pm)(_Args...)) +{ + return __mem_fn<_R (_T::*)(_Args...)>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_Args...) const> +mem_fn(_R (_T::* __pm)(_Args...) const) +{ + return __mem_fn<_R (_T::*)(_Args...) const>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_Args...) volatile> +mem_fn(_R (_T::* __pm)(_Args...) volatile) +{ + return __mem_fn<_R (_T::*)(_Args...) volatile>(__pm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__mem_fn<_R (_T::*)(_Args...) const volatile> +mem_fn(_R (_T::* __pm)(_Args...) const volatile) +{ + return __mem_fn<_R (_T::*)(_Args...) const volatile>(__pm); +} + +// bad_function_call + +class _LIBCPP_EXCEPTION_ABI bad_function_call + : public exception +{ +}; + +template class _LIBCPP_VISIBLE function; // undefined + +namespace __function +{ + +template +struct __maybe_derive_from_unary_function +{ +}; + +template +struct __maybe_derive_from_unary_function<_R(_A1)> + : public unary_function<_A1, _R> +{ +}; + +template +struct __maybe_derive_from_binary_function +{ +}; + +template +struct __maybe_derive_from_binary_function<_R(_A1, _A2)> + : public binary_function<_A1, _A2, _R> +{ +}; + +template class __base; + +template +class __base<_R(_ArgTypes...)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + _LIBCPP_INLINE_VISIBILITY __base() {} + _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() _NOEXCEPT = 0; + virtual void destroy_deallocate() _NOEXCEPT = 0; + virtual _R operator()(_ArgTypes&& ...) = 0; +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const _NOEXCEPT = 0; + virtual const std::type_info& target_type() const _NOEXCEPT = 0; +#endif // _LIBCPP_NO_RTTI +}; + +template class __func; + +template +class __func<_F, _Alloc, _R(_ArgTypes...)> + : public __base<_R(_ArgTypes...)> +{ + __compressed_pair<_F, _Alloc> __f_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __func(_F __f) : __f_(_VSTD::move(__f)) {} + _LIBCPP_INLINE_VISIBILITY + explicit __func(_F __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} + virtual __base<_R(_ArgTypes...)>* __clone() const; + virtual void __clone(__base<_R(_ArgTypes...)>*) const; + virtual void destroy() _NOEXCEPT; + virtual void destroy_deallocate() _NOEXCEPT; + virtual _R operator()(_ArgTypes&& ... __arg); +#ifndef _LIBCPP_NO_RTTI + virtual const void* target(const type_info&) const _NOEXCEPT; + virtual const std::type_info& target_type() const _NOEXCEPT; +#endif // _LIBCPP_NO_RTTI +}; + +template +__base<_R(_ArgTypes...)>* +__func<_F, _Alloc, _R(_ArgTypes...)>::__clone() const +{ + typedef typename _Alloc::template rebind<__func>::other _A; + _A __a(__f_.second()); + typedef __allocator_destructor<_A> _D; + unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_F, _Alloc, _R(_ArgTypes...)>::__clone(__base<_R(_ArgTypes...)>* __p) const +{ + ::new (__p) __func(__f_.first(), __f_.second()); +} + +template +void +__func<_F, _Alloc, _R(_ArgTypes...)>::destroy() _NOEXCEPT +{ + __f_.~__compressed_pair<_F, _Alloc>(); +} + +template +void +__func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT +{ + typedef typename _Alloc::template rebind<__func>::other _A; + _A __a(__f_.second()); + __f_.~__compressed_pair<_F, _Alloc>(); + __a.deallocate(this, 1); +} + +template +_R +__func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) +{ + return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); +} + +#ifndef _LIBCPP_NO_RTTI + +template +const void* +__func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT +{ + if (__ti == typeid(_F)) + return &__f_.first(); + return (const void*)0; +} + +template +const std::type_info& +__func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const _NOEXCEPT +{ + return typeid(_F); +} + +#endif // _LIBCPP_NO_RTTI + +} // __function + +template +class _LIBCPP_VISIBLE function<_R(_ArgTypes...)> + : public __function::__maybe_derive_from_unary_function<_R(_ArgTypes...)>, + public __function::__maybe_derive_from_binary_function<_R(_ArgTypes...)> +{ + typedef __function::__base<_R(_ArgTypes...)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(const _F&) {return true;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (*__p)(_A...)) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_A...)) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_A...) const) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_A...) volatile) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(_R2 (_C::*__p)(_A...) const volatile) {return __p;} + template + _LIBCPP_INLINE_VISIBILITY + static bool __not_null(const function<_R(_A...)>& __p) {return __p;} + + template ::value> + struct __callable; + template + struct __callable<_F, true> + { + static const bool value = + is_convertible::type, + _R>::value; + }; + template + struct __callable<_F, false> + { + static const bool value = false; + }; +public: + typedef _R result_type; + + // construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY + function() _NOEXCEPT : __f_(0) {} + _LIBCPP_INLINE_VISIBILITY + function(nullptr_t) _NOEXCEPT : __f_(0) {} + function(const function&); + function(function&&) _NOEXCEPT; + template + function(_F, + typename enable_if<__callable<_F>::value>::type* = 0); + + template + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} + template + _LIBCPP_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc&, function&&); + template + function(allocator_arg_t, const _Alloc& __a, _F __f, + typename enable_if<__callable<_F>::value>::type* = 0); + + function& operator=(const function&); + function& operator=(function&&) _NOEXCEPT; + function& operator=(nullptr_t) _NOEXCEPT; + template + typename enable_if + < + __callable::type>::value, + function& + >::type + operator=(_F&&); + + ~function(); + + // function modifiers: + void swap(function&) _NOEXCEPT; + template + _LIBCPP_INLINE_VISIBILITY + void assign(_F&& __f, const _Alloc& __a) + {function(allocator_arg, __a, _VSTD::forward<_F>(__f)).swap(*this);} + + // function capacity: + _LIBCPP_INLINE_VISIBILITY + /*explicit*/ operator bool() const _NOEXCEPT {return __f_;} + + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; + template + bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; +public: + // function invocation: + _R operator()(_ArgTypes...) const; + +#ifndef _LIBCPP_NO_RTTI + // function target access: + const std::type_info& target_type() const _NOEXCEPT; + template _T* target() _NOEXCEPT; + template const _T* target() const _NOEXCEPT; +#endif // _LIBCPP_NO_RTTI +}; + +template +function<_R(_ArgTypes...)>::function(const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +template +function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, + const function& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (const __base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); +} + +template +function<_R(_ArgTypes...)>::function(function&& __f) _NOEXCEPT +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = 0; + } +} + +template +template +function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, + function&& __f) +{ + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = 0; + } +} + +template +template +function<_R(_ArgTypes...)>::function(_F __f, + typename enable_if<__callable<_F>::value>::type*) + : __f_(0) +{ + if (__not_null(__f)) + { + typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF; + if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(_VSTD::move(__f)); + } + else + { + typedef allocator<_FF> _A; + _A __a; + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_F>(__a)); + __f_ = __hold.release(); + } + } +} + +template +template +function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f, + typename enable_if<__callable<_F>::value>::type*) + : __f_(0) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + if (__not_null(__f)) + { + typedef __function::__func<_F, _Alloc, _R(_ArgTypes...)> _FF; + if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(_VSTD::move(__f)); + } + else + { + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<_FF> +#else + rebind_alloc<_FF>::other +#endif + _A; + _A __a(__a0); + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a)); + __f_ = __hold.release(); + } + } +} + +template +function<_R(_ArgTypes...)>& +function<_R(_ArgTypes...)>::operator=(const function& __f) +{ + function(__f).swap(*this); + return *this; +} + +template +function<_R(_ArgTypes...)>& +function<_R(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + __f_ = 0; + if (__f.__f_ == 0) + __f_ = 0; + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__clone(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = 0; + } +} + +template +function<_R(_ArgTypes...)>& +function<_R(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + __f_ = 0; +} + +template +template +typename enable_if +< + function<_R(_ArgTypes...)>::template __callable::type>::value, + function<_R(_ArgTypes...)>& +>::type +function<_R(_ArgTypes...)>::operator=(_F&& __f) +{ + function(_VSTD::forward<_F>(__f)).swap(*this); + return *this; +} + +template +function<_R(_ArgTypes...)>::~function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template +void +function<_R(_ArgTypes...)>::swap(function& __f) _NOEXCEPT +{ + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__clone(__t); + __f_->destroy(); + __f_ = 0; + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = 0; + __f_ = (__base*)&__buf_; + __t->__clone((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__clone((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__clone((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template +_R +function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__f_ == 0) + throw bad_function_call(); +#endif // _LIBCPP_NO_EXCEPTIONS + return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); +} + +#ifndef _LIBCPP_NO_RTTI + +template +const std::type_info& +function<_R(_ArgTypes...)>::target_type() const _NOEXCEPT +{ + if (__f_ == 0) + return typeid(void); + return __f_->target_type(); +} + +template +template +_T* +function<_R(_ArgTypes...)>::target() _NOEXCEPT +{ + if (__f_ == 0) + return (_T*)0; + return (_T*)__f_->target(typeid(_T)); +} + +template +template +const _T* +function<_R(_ArgTypes...)>::target() const _NOEXCEPT +{ + if (__f_ == 0) + return (const _T*)0; + return (const _T*)__f_->target(typeid(_T)); +} + +#endif // _LIBCPP_NO_RTTI + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y) _NOEXCEPT +{return __x.swap(__y);} + +template struct __is_bind_expression : public false_type {}; +template struct _LIBCPP_VISIBLE is_bind_expression + : public __is_bind_expression::type> {}; + +template struct __is_placeholder : public integral_constant {}; +template struct _LIBCPP_VISIBLE is_placeholder + : public __is_placeholder::type> {}; + +namespace placeholders +{ + +template struct __ph {}; + +extern __ph<1> _1; +extern __ph<2> _2; +extern __ph<3> _3; +extern __ph<4> _4; +extern __ph<5> _5; +extern __ph<6> _6; +extern __ph<7> _7; +extern __ph<8> _8; +extern __ph<9> _9; +extern __ph<10> _10; + +} // placeholders + +template +struct __is_placeholder > + : public integral_constant {}; + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp& +__mu(reference_wrapper<_Tp> __t, _Uj&) +{ + return __t.get(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __invoke_of<_Ti&, _Uj...>::type +__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) +{ + return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_bind_expression<_Ti>::value, + typename __invoke_of<_Ti&, _Uj...>::type +>::type +__mu(_Ti& __ti, tuple<_Uj...>& __uj) +{ + typedef typename __make_tuple_indices::type __indices; + return __mu_expand(__ti, __uj, __indices()); +} + +template +struct __mu_return2 {}; + +template +struct __mu_return2 +{ + typedef typename tuple_element::value - 1, _Uj>::type type; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + 0 < is_placeholder<_Ti>::value, + typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type +>::type +__mu(_Ti&, _Uj& __uj) +{ + const size_t _Indx = is_placeholder<_Ti>::value - 1; + return _VSTD::forward::type>(get<_Indx>(__uj)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + !is_bind_expression<_Ti>::value && + is_placeholder<_Ti>::value == 0 && + !__is_reference_wrapper<_Ti>::value, + _Ti& +>::type +__mu(_Ti& __ti, _Uj& __uj) +{ + return __ti; +} + +template +struct ____mu_return; + +template +struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > +{ + typedef typename __invoke_of<_Ti&, _Uj...>::type type; +}; + +template +struct ____mu_return<_Ti, false, false, true, _TupleUj> +{ + typedef typename tuple_element::value - 1, + _TupleUj>::type&& type; +}; + +template +struct ____mu_return<_Ti, true, false, false, _TupleUj> +{ + typedef typename _Ti::type& type; +}; + +template +struct ____mu_return<_Ti, false, false, false, _TupleUj> +{ + typedef _Ti& type; +}; + +template +struct __mu_return + : public ____mu_return<_Ti, + __is_reference_wrapper<_Ti>::value, + is_bind_expression<_Ti>::value, + 0 < is_placeholder<_Ti>::value, + _TupleUj> +{ +}; + +template +struct __bind_return; + +template +struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj> +{ + typedef typename __invoke_of + < + _F&, + typename __mu_return + < + _BoundArgs, + _TupleUj + >::type... + >::type type; +}; + +template +struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj> +{ + typedef typename __invoke_of + < + _F&, + typename __mu_return + < + const _BoundArgs, + _TupleUj + >::type... + >::type type; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __bind_return<_F, _BoundArgs, _Args>::type +__apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, + _Args&& __args) +{ + return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...); +} + +template +class __bind + : public __weak_result_type::type> +{ + typedef typename decay<_F>::type _Fd; + typedef tuple::type...> _Td; + _Fd __f_; + _Td __bound_args_; + + typedef typename __make_tuple_indices::type __indices; +public: +#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + + _LIBCPP_INLINE_VISIBILITY + __bind(const __bind& __b) + : __f_(__b.__f_), + __bound_args_(__b.__bound_args_) {} + + _LIBCPP_INLINE_VISIBILITY + __bind& operator=(const __bind& __b) + { + __f_ = __b.__f_; + __bound_args_ = __b.__bound_args_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __bind(__bind&& __b) + : __f_(_VSTD::move(__b.__f_)), + __bound_args_(_VSTD::move(__b.__bound_args_)) {} + + _LIBCPP_INLINE_VISIBILITY + __bind& operator=(__bind&& __b) + { + __f_ = _VSTD::move(__b.__f_); + __bound_args_ = _VSTD::move(__b.__bound_args_); + return *this; + } + +#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + + template + _LIBCPP_INLINE_VISIBILITY + explicit __bind(_G&& __f, _BA&& ...__bound_args) + : __f_(_VSTD::forward<_G>(__f)), + __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} + + template + _LIBCPP_INLINE_VISIBILITY + typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type + operator()(_Args&& ...__args) + { + return __apply_functor(__f_, __bound_args_, __indices(), + tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); + } + + template + _LIBCPP_INLINE_VISIBILITY + typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type + operator()(_Args&& ...__args) const + { + return __apply_functor(__f_, __bound_args_, __indices(), + tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); + } +}; + +template +struct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {}; + +template +class __bind_r + : public __bind<_F, _BoundArgs...> +{ + typedef __bind<_F, _BoundArgs...> base; +public: + typedef _R result_type; + +#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + + _LIBCPP_INLINE_VISIBILITY + __bind_r(const __bind_r& __b) + : base(_VSTD::forward(__b)) {} + + _LIBCPP_INLINE_VISIBILITY + __bind_r& operator=(const __bind_r& __b) + { + base::operator=(_VSTD::forward(__b)); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __bind_r(__bind_r&& __b) + : base(_VSTD::forward(__b)) {} + + _LIBCPP_INLINE_VISIBILITY + __bind_r& operator=(__bind_r&& __b) + { + base::operator=(_VSTD::forward(__b)); + return *this; + } + +#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + + template + _LIBCPP_INLINE_VISIBILITY + explicit __bind_r(_G&& __f, _BA&& ...__bound_args) + : base(_VSTD::forward<_G>(__f), + _VSTD::forward<_BA>(__bound_args)...) {} + + template + _LIBCPP_INLINE_VISIBILITY + result_type + operator()(_Args&& ...__args) + { + return base::operator()(_VSTD::forward<_Args>(__args)...); + } + + template + _LIBCPP_INLINE_VISIBILITY + result_type + operator()(_Args&& ...__args) const + { + return base::operator()(_VSTD::forward<_Args>(__args)...); + } +}; + +template +struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {}; + +template +inline _LIBCPP_INLINE_VISIBILITY +__bind<_F, _BoundArgs...> +bind(_F&& __f, _BoundArgs&&... __bound_args) +{ + typedef __bind<_F, _BoundArgs...> type; + return type(_VSTD::forward<_F>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__bind_r<_R, _F, _BoundArgs...> +bind(_F&& __f, _BoundArgs&&... __bound_args) +{ + typedef __bind_r<_R, _F, _BoundArgs...> type; + return type(_VSTD::forward<_F>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(bool __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(signed char __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast(__v);} +}; + +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast(__v);} +}; + +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(short __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(int __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(long __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast(__v);} +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(long long __v) const _NOEXCEPT + { + size_t __r = 0; + const size_t* const __p = reinterpret_cast(&__v); + for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) + __r ^= __p[__i]; + return __r; + } +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned long long __v) const _NOEXCEPT + { + size_t __r = 0; + const size_t* const __p = reinterpret_cast(&__v); + for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) + __r ^= __p[__i]; + return __r; + } +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(float __v) const _NOEXCEPT + { + if (__v == 0) + return 0; + const size_t* const __p = reinterpret_cast(&__v); + return *__p; + } +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(double __v) const _NOEXCEPT + { + if (__v == 0) + return 0; + size_t __r = 0; + const size_t* const __p = reinterpret_cast(&__v); + for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) + __r ^= __p[__i]; + return __r; + } +}; + +template <> +struct _LIBCPP_VISIBLE hash + : public unary_function +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(long double __v) const _NOEXCEPT + { + if (__v == 0) + return 0; + size_t __r = 0; + const size_t* const __p = reinterpret_cast(&__v); + for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) + __r ^= __p[__i]; + return __r; + } +}; + +// struct hash in + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_FUNCTIONAL diff --git a/contrib/libc++/include/future b/contrib/libc++/include/future new file mode 100644 index 000000000000..f6896a3a0fce --- /dev/null +++ b/contrib/libc++/include/future @@ -0,0 +1,2517 @@ +// -*- C++ -*- +//===--------------------------- future -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FUTURE +#define _LIBCPP_FUTURE + +/* + future synopsis + +namespace std +{ + +enum class future_errc +{ + broken_promise, + future_already_retrieved, + promise_already_satisfied, + no_state +}; + +enum class launch +{ + async = 1, + deferred = 2, + any = async | deferred +}; + +enum class future_status +{ + ready, + timeout, + deferred +}; + +template <> struct is_error_code_enum : public true_type { }; +error_code make_error_code(future_errc e); +error_condition make_error_condition(future_errc e); + +const error_category& future_category(); + +class future_error + : public logic_error +{ +public: + future_error(error_code ec); // exposition only + + const error_code& code() const throw(); + const char* what() const throw(); +}; + +template +class promise +{ +public: + promise(); + template + promise(allocator_arg_t, const Allocator& a); + promise(promise&& rhs); + promise(const promise& rhs) = delete; + ~promise(); + + // assignment + promise& operator=(promise&& rhs); + promise& operator=(const promise& rhs) = delete; + void swap(promise& other); + + // retrieving the result + future get_future(); + + // setting the result + void set_value(const R& r); + void set_value(R&& r); + void set_exception(exception_ptr p); + + // setting the result with deferred notification + void set_value_at_thread_exit(const R& r); + void set_value_at_thread_exit(R&& r); + void set_exception_at_thread_exit(exception_ptr p); +}; + +template +class promise +{ +public: + promise(); + template + promise(allocator_arg_t, const Allocator& a); + promise(promise&& rhs); + promise(const promise& rhs) = delete; + ~promise(); + + // assignment + promise& operator=(promise&& rhs); + promise& operator=(const promise& rhs) = delete; + void swap(promise& other); + + // retrieving the result + future get_future(); + + // setting the result + void set_value(R& r); + void set_exception(exception_ptr p); + + // setting the result with deferred notification + void set_value_at_thread_exit(R&); + void set_exception_at_thread_exit(exception_ptr p); +}; + +template <> +class promise +{ +public: + promise(); + template + promise(allocator_arg_t, const Allocator& a); + promise(promise&& rhs); + promise(const promise& rhs) = delete; + ~promise(); + + // assignment + promise& operator=(promise&& rhs); + promise& operator=(const promise& rhs) = delete; + void swap(promise& other); + + // retrieving the result + future get_future(); + + // setting the result + void set_value(); + void set_exception(exception_ptr p); + + // setting the result with deferred notification + void set_value_at_thread_exit(); + void set_exception_at_thread_exit(exception_ptr p); +}; + +template void swap(promise& x, promise& y); + +template + struct uses_allocator, Alloc> : public true_type {}; + +template +class future +{ +public: + future(); + future(future&&); + future(const future& rhs) = delete; + ~future(); + future& operator=(const future& rhs) = delete; + future& operator=(future&&); + shared_future share() &&; + + // retrieving the value + R get(); + + // functions to check state + bool valid() const; + + void wait() const; + template + future_status + wait_for(const chrono::duration& rel_time) const; + template + future_status + wait_until(const chrono::time_point& abs_time) const; +}; + +template +class future +{ +public: + future(); + future(future&&); + future(const future& rhs) = delete; + ~future(); + future& operator=(const future& rhs) = delete; + future& operator=(future&&); + shared_future share() &&; + + // retrieving the value + R& get(); + + // functions to check state + bool valid() const; + + void wait() const; + template + future_status + wait_for(const chrono::duration& rel_time) const; + template + future_status + wait_until(const chrono::time_point& abs_time) const; +}; + +template <> +class future +{ +public: + future(); + future(future&&); + future(const future& rhs) = delete; + ~future(); + future& operator=(const future& rhs) = delete; + future& operator=(future&&); + shared_future share() &&; + + // retrieving the value + void get(); + + // functions to check state + bool valid() const; + + void wait() const; + template + future_status + wait_for(const chrono::duration& rel_time) const; + template + future_status + wait_until(const chrono::time_point& abs_time) const; +}; + +template +class shared_future +{ +public: + shared_future(); + shared_future(const shared_future& rhs); + shared_future(future&&); + shared_future(shared_future&& rhs); + ~shared_future(); + shared_future& operator=(const shared_future& rhs); + shared_future& operator=(shared_future&& rhs); + + // retrieving the value + const R& get() const; + + // functions to check state + bool valid() const; + + void wait() const; + template + future_status + wait_for(const chrono::duration& rel_time) const; + template + future_status + wait_until(const chrono::time_point& abs_time) const; +}; + +template +class shared_future +{ +public: + shared_future(); + shared_future(const shared_future& rhs); + shared_future(future&&); + shared_future(shared_future&& rhs); + ~shared_future(); + shared_future& operator=(const shared_future& rhs); + shared_future& operator=(shared_future&& rhs); + + // retrieving the value + R& get() const; + + // functions to check state + bool valid() const; + + void wait() const; + template + future_status + wait_for(const chrono::duration& rel_time) const; + template + future_status + wait_until(const chrono::time_point& abs_time) const; +}; + +template <> +class shared_future +{ +public: + shared_future(); + shared_future(const shared_future& rhs); + shared_future(future&&); + shared_future(shared_future&& rhs); + ~shared_future(); + shared_future& operator=(const shared_future& rhs); + shared_future& operator=(shared_future&& rhs); + + // retrieving the value + void get() const; + + // functions to check state + bool valid() const; + + void wait() const; + template + future_status + wait_for(const chrono::duration& rel_time) const; + template + future_status + wait_until(const chrono::time_point& abs_time) const; +}; + +template + future::type> + async(F&& f, Args&&... args); + +template + future::type> + async(launch policy, F&& f, Args&&... args); + +template class packaged_task; // undefined + +template +class packaged_task +{ +public: + typedef R result_type; + + // construction and destruction + packaged_task(); + template + explicit packaged_task(F&& f); + template + explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f); + ~packaged_task(); + + // no copy + packaged_task(packaged_task&) = delete; + packaged_task& operator=(packaged_task&) = delete; + + // move support + packaged_task(packaged_task&& other); + packaged_task& operator=(packaged_task&& other); + void swap(packaged_task& other); + + bool valid() const; + + // result retrieval + future get_future(); + + // execution + void operator()(ArgTypes... ); + void make_ready_at_thread_exit(ArgTypes...); + + void reset(); +}; + +template + void swap(packaged_task&); + +template struct uses_allocator, Alloc>; + +} // std + +*/ + +#include <__config> +#include +#include +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +//enum class future_errc +struct _LIBCPP_VISIBLE future_errc +{ +enum _ { + broken_promise, + future_already_retrieved, + promise_already_satisfied, + no_state +}; + + _ __v_; + + _LIBCPP_INLINE_VISIBILITY future_errc(_ __v) : __v_(__v) {} + _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} + +}; + +template <> +struct _LIBCPP_VISIBLE is_error_code_enum : public true_type {}; + +//enum class launch +struct _LIBCPP_VISIBLE launch +{ +enum _ { + async = 1, + deferred = 2, + any = async | deferred +}; + + _ __v_; + + _LIBCPP_INLINE_VISIBILITY launch(_ __v) : __v_(__v) {} + _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} + +}; + +//enum class future_status +struct _LIBCPP_VISIBLE future_status +{ +enum _ { + ready, + timeout, + deferred +}; + + _ __v_; + + _LIBCPP_INLINE_VISIBILITY future_status(_ __v) : __v_(__v) {} + _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} + +}; + +_LIBCPP_VISIBLE +const error_category& future_category(); + +inline _LIBCPP_INLINE_VISIBILITY +error_code +make_error_code(future_errc __e) +{ + return error_code(static_cast(__e), future_category()); +} + +inline _LIBCPP_INLINE_VISIBILITY +error_condition +make_error_condition(future_errc __e) +{ + return error_condition(static_cast(__e), future_category()); +} + +class _LIBCPP_EXCEPTION_ABI future_error + : public logic_error +{ + error_code __ec_; +public: + future_error(error_code __ec); + + _LIBCPP_INLINE_VISIBILITY + const error_code& code() const throw() {return __ec_;} + + virtual ~future_error() _NOEXCEPT; +}; + +class __assoc_sub_state + : public __shared_count +{ +protected: + exception_ptr __exception_; + mutable mutex __mut_; + mutable condition_variable __cv_; + unsigned __state_; + + virtual void __on_zero_shared() _NOEXCEPT; + void __sub_wait(unique_lock& __lk); +public: + enum + { + __constructed = 1, + __future_attached = 2, + ready = 4, + deferred = 8 + }; + + _LIBCPP_INLINE_VISIBILITY + __assoc_sub_state() : __state_(0) {} + + _LIBCPP_INLINE_VISIBILITY + bool __has_value() const + {return (__state_ & __constructed) || (__exception_ != nullptr);} + + _LIBCPP_INLINE_VISIBILITY + void __set_future_attached() {__state_ |= __future_attached;} + _LIBCPP_INLINE_VISIBILITY + bool __has_future_attached() const {return __state_ & __future_attached;} + + _LIBCPP_INLINE_VISIBILITY + void __set_deferred() {__state_ |= deferred;} + + void __make_ready(); + _LIBCPP_INLINE_VISIBILITY + bool __is_ready() const {return __state_ & ready;} + + void set_value(); + void set_value_at_thread_exit(); + + void set_exception(exception_ptr __p); + void set_exception_at_thread_exit(exception_ptr __p); + + void copy(); + + void wait(); + template + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const; + template + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const; + + virtual void __execute(); +}; + +template +future_status +__assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const +{ + unique_lock __lk(__mut_); + if (__state_ & deferred) + return future_status::deferred; + while (!(__state_ & ready) && _Clock::now() < __abs_time) + __cv_.wait_until(__lk, __abs_time); + if (__state_ & ready) + return future_status::ready; + return future_status::timeout; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +future_status +__assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const +{ + return wait_until(chrono::steady_clock::now() + __rel_time); +} + +template +class __assoc_state + : public __assoc_sub_state +{ + typedef __assoc_sub_state base; + typedef typename aligned_storage::value>::type _U; +protected: + _U __value_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: + + template +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void set_value(_Arg&& __arg); +#else + void set_value(_Arg& __arg); +#endif + + template +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void set_value_at_thread_exit(_Arg&& __arg); +#else + void set_value_at_thread_exit(_Arg& __arg); +#endif + + _R move(); + typename add_lvalue_reference<_R>::type copy(); +}; + +template +void +__assoc_state<_R>::__on_zero_shared() _NOEXCEPT +{ + if (this->__state_ & base::__constructed) + reinterpret_cast<_R*>(&__value_)->~_R(); + delete this; +} + +template +template +void +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__assoc_state<_R>::set_value(_Arg&& __arg) +#else +__assoc_state<_R>::set_value(_Arg& __arg) +#endif +{ + unique_lock __lk(this->__mut_); +#ifndef _LIBCPP_NO_EXCEPTIONS + if (this->__has_value()) + throw future_error(make_error_code(future_errc::promise_already_satisfied)); +#endif + ::new(&__value_) _R(_VSTD::forward<_Arg>(__arg)); + this->__state_ |= base::__constructed | base::ready; + __lk.unlock(); + __cv_.notify_all(); +} + +template +template +void +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__assoc_state<_R>::set_value_at_thread_exit(_Arg&& __arg) +#else +__assoc_state<_R>::set_value_at_thread_exit(_Arg& __arg) +#endif +{ + unique_lock __lk(this->__mut_); +#ifndef _LIBCPP_NO_EXCEPTIONS + if (this->__has_value()) + throw future_error(make_error_code(future_errc::promise_already_satisfied)); +#endif + ::new(&__value_) _R(_VSTD::forward<_Arg>(__arg)); + this->__state_ |= base::__constructed; + __thread_local_data()->__make_ready_at_thread_exit(this); + __lk.unlock(); +} + +template +_R +__assoc_state<_R>::move() +{ + unique_lock __lk(this->__mut_); + this->__sub_wait(__lk); + if (this->__exception_ != nullptr) + rethrow_exception(this->__exception_); + return _VSTD::move(*reinterpret_cast<_R*>(&__value_)); +} + +template +typename add_lvalue_reference<_R>::type +__assoc_state<_R>::copy() +{ + unique_lock __lk(this->__mut_); + this->__sub_wait(__lk); + if (this->__exception_ != nullptr) + rethrow_exception(this->__exception_); + return *reinterpret_cast<_R*>(&__value_); +} + +template +class __assoc_state<_R&> + : public __assoc_sub_state +{ + typedef __assoc_sub_state base; + typedef _R* _U; +protected: + _U __value_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: + + void set_value(_R& __arg); + void set_value_at_thread_exit(_R& __arg); + + _R& copy(); +}; + +template +void +__assoc_state<_R&>::__on_zero_shared() _NOEXCEPT +{ + delete this; +} + +template +void +__assoc_state<_R&>::set_value(_R& __arg) +{ + unique_lock __lk(this->__mut_); +#ifndef _LIBCPP_NO_EXCEPTIONS + if (this->__has_value()) + throw future_error(make_error_code(future_errc::promise_already_satisfied)); +#endif + __value_ = &__arg; + this->__state_ |= base::__constructed | base::ready; + __lk.unlock(); + __cv_.notify_all(); +} + +template +void +__assoc_state<_R&>::set_value_at_thread_exit(_R& __arg) +{ + unique_lock __lk(this->__mut_); +#ifndef _LIBCPP_NO_EXCEPTIONS + if (this->__has_value()) + throw future_error(make_error_code(future_errc::promise_already_satisfied)); +#endif + __value_ = &__arg; + this->__state_ |= base::__constructed; + __thread_local_data()->__make_ready_at_thread_exit(this); + __lk.unlock(); +} + +template +_R& +__assoc_state<_R&>::copy() +{ + unique_lock __lk(this->__mut_); + this->__sub_wait(__lk); + if (this->__exception_ != nullptr) + rethrow_exception(this->__exception_); + return *__value_; +} + +template +class __assoc_state_alloc + : public __assoc_state<_R> +{ + typedef __assoc_state<_R> base; + _Alloc __alloc_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __assoc_state_alloc(const _Alloc& __a) + : __alloc_(__a) {} +}; + +template +void +__assoc_state_alloc<_R, _Alloc>::__on_zero_shared() _NOEXCEPT +{ + if (this->__state_ & base::__constructed) + reinterpret_cast<_R*>(&this->__value_)->~_R(); + typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_); + this->~__assoc_state_alloc(); + __a.deallocate(this, 1); +} + +template +class __assoc_state_alloc<_R&, _Alloc> + : public __assoc_state<_R&> +{ + typedef __assoc_state<_R&> base; + _Alloc __alloc_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __assoc_state_alloc(const _Alloc& __a) + : __alloc_(__a) {} +}; + +template +void +__assoc_state_alloc<_R&, _Alloc>::__on_zero_shared() _NOEXCEPT +{ + typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_); + this->~__assoc_state_alloc(); + __a.deallocate(this, 1); +} + +template +class __assoc_sub_state_alloc + : public __assoc_sub_state +{ + typedef __assoc_sub_state base; + _Alloc __alloc_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __assoc_sub_state_alloc(const _Alloc& __a) + : __alloc_(__a) {} +}; + +template +void +__assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT +{ + this->~base(); + typename _Alloc::template rebind<__assoc_sub_state_alloc>::other __a(__alloc_); + this->~__assoc_sub_state_alloc(); + __a.deallocate(this, 1); +} + +template +class __deferred_assoc_state + : public __assoc_state<_R> +{ + typedef __assoc_state<_R> base; + + _F __func_; + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + explicit __deferred_assoc_state(_F&& __f); +#endif + + virtual void __execute(); +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +__deferred_assoc_state<_R, _F>::__deferred_assoc_state(_F&& __f) + : __func_(_VSTD::forward<_F>(__f)) +{ + this->__set_deferred(); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +__deferred_assoc_state<_R, _F>::__execute() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + this->set_value(__func_()); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template +class __deferred_assoc_state + : public __assoc_sub_state +{ + typedef __assoc_sub_state base; + + _F __func_; + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + explicit __deferred_assoc_state(_F&& __f); +#endif + + virtual void __execute(); +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +__deferred_assoc_state::__deferred_assoc_state(_F&& __f) + : __func_(_VSTD::forward<_F>(__f)) +{ + this->__set_deferred(); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +__deferred_assoc_state::__execute() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __func_(); + this->set_value(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template +class __async_assoc_state + : public __assoc_state<_R> +{ + typedef __assoc_state<_R> base; + + _F __func_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + explicit __async_assoc_state(_F&& __f); +#endif + + virtual void __execute(); +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +__async_assoc_state<_R, _F>::__async_assoc_state(_F&& __f) + : __func_(_VSTD::forward<_F>(__f)) +{ +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +__async_assoc_state<_R, _F>::__execute() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + this->set_value(__func_()); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template +void +__async_assoc_state<_R, _F>::__on_zero_shared() _NOEXCEPT +{ + this->wait(); + base::__on_zero_shared(); +} + +template +class __async_assoc_state + : public __assoc_sub_state +{ + typedef __assoc_sub_state base; + + _F __func_; + + virtual void __on_zero_shared() _NOEXCEPT; +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + explicit __async_assoc_state(_F&& __f); +#endif + + virtual void __execute(); +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +__async_assoc_state::__async_assoc_state(_F&& __f) + : __func_(_VSTD::forward<_F>(__f)) +{ +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +__async_assoc_state::__execute() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __func_(); + this->set_value(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template +void +__async_assoc_state::__on_zero_shared() _NOEXCEPT +{ + this->wait(); + base::__on_zero_shared(); +} + +template class promise; +template class shared_future; + +// future + +template class future; + +template +future<_R> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__make_deferred_assoc_state(_F&& __f); +#else +__make_deferred_assoc_state(_F __f); +#endif + +template +future<_R> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__make_async_assoc_state(_F&& __f); +#else +__make_async_assoc_state(_F __f); +#endif + +template +class _LIBCPP_VISIBLE future +{ + __assoc_state<_R>* __state_; + + explicit future(__assoc_state<_R>* __state); + + template friend class promise; + template friend class shared_future; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template + friend future<_R1> __make_deferred_assoc_state(_F&& __f); + template + friend future<_R1> __make_async_assoc_state(_F&& __f); +#else + template + friend future<_R1> __make_deferred_assoc_state(_F __f); + template + friend future<_R1> __make_async_assoc_state(_F __f); +#endif + +public: + _LIBCPP_INLINE_VISIBILITY + future() : __state_(nullptr) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + future(future&& __rhs) + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + future(const future&) = delete; + future& operator=(const future&) = delete; + _LIBCPP_INLINE_VISIBILITY + future& operator=(future&& __rhs) + { + future(std::move(__rhs)).swap(*this); + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + future(const future&); + future& operator=(const future&); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~future(); + shared_future<_R> share(); + + // retrieving the value + _R get(); + + _LIBCPP_INLINE_VISIBILITY + void swap(future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template +future<_R>::future(__assoc_state<_R>* __state) + : __state_(__state) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_->__has_future_attached()) + throw future_error(make_error_code(future_errc::future_already_retrieved)); +#endif + __state_->__add_shared(); + __state_->__set_future_attached(); +} + +struct __release_shared_count +{ + void operator()(__shared_count* p) {p->__release_shared();} +}; + +template +future<_R>::~future() +{ + if (__state_) + __state_->__release_shared(); +} + +template +_R +future<_R>::get() +{ + unique_ptr<__shared_count, __release_shared_count> __(__state_); + __assoc_state<_R>* __s = __state_; + __state_ = nullptr; + return __s->move(); +} + +template +class _LIBCPP_VISIBLE future<_R&> +{ + __assoc_state<_R&>* __state_; + + explicit future(__assoc_state<_R&>* __state); + + template friend class promise; + template friend class shared_future; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template + friend future<_R1> __make_deferred_assoc_state(_F&& __f); + template + friend future<_R1> __make_async_assoc_state(_F&& __f); +#else + template + friend future<_R1> __make_deferred_assoc_state(_F __f); + template + friend future<_R1> __make_async_assoc_state(_F __f); +#endif + +public: + _LIBCPP_INLINE_VISIBILITY + future() : __state_(nullptr) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + future(future&& __rhs) + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + future(const future&) = delete; + future& operator=(const future&) = delete; + _LIBCPP_INLINE_VISIBILITY + future& operator=(future&& __rhs) + { + future(std::move(__rhs)).swap(*this); + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + future(const future&); + future& operator=(const future&); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~future(); + shared_future<_R&> share(); + + // retrieving the value + _R& get(); + + _LIBCPP_INLINE_VISIBILITY + void swap(future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template +future<_R&>::future(__assoc_state<_R&>* __state) + : __state_(__state) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_->__has_future_attached()) + throw future_error(make_error_code(future_errc::future_already_retrieved)); +#endif + __state_->__add_shared(); + __state_->__set_future_attached(); +} + +template +future<_R&>::~future() +{ + if (__state_) + __state_->__release_shared(); +} + +template +_R& +future<_R&>::get() +{ + unique_ptr<__shared_count, __release_shared_count> __(__state_); + __assoc_state<_R&>* __s = __state_; + __state_ = nullptr; + return __s->copy(); +} + +template <> +class _LIBCPP_VISIBLE future +{ + __assoc_sub_state* __state_; + + explicit future(__assoc_sub_state* __state); + + template friend class promise; + template friend class shared_future; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template + friend future<_R1> __make_deferred_assoc_state(_F&& __f); + template + friend future<_R1> __make_async_assoc_state(_F&& __f); +#else + template + friend future<_R1> __make_deferred_assoc_state(_F __f); + template + friend future<_R1> __make_async_assoc_state(_F __f); +#endif + +public: + _LIBCPP_INLINE_VISIBILITY + future() : __state_(nullptr) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + future(future&& __rhs) + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + future(const future&) = delete; + future& operator=(const future&) = delete; + _LIBCPP_INLINE_VISIBILITY + future& operator=(future&& __rhs) + { + future(std::move(__rhs)).swap(*this); + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + future(const future&); + future& operator=(const future&); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~future(); + shared_future share(); + + // retrieving the value + void get(); + + _LIBCPP_INLINE_VISIBILITY + void swap(future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(future<_R>& __x, future<_R>& __y) +{ + __x.swap(__y); +} + +// promise + +template class packaged_task; + +template +class _LIBCPP_VISIBLE promise +{ + __assoc_state<_R>* __state_; + + _LIBCPP_INLINE_VISIBILITY + explicit promise(nullptr_t) : __state_(nullptr) {} + + template friend class packaged_task; +public: + promise(); + template + promise(allocator_arg_t, const _Alloc& __a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise(promise&& __rhs) + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + promise(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~promise(); + + // assignment +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise& operator=(promise&& __rhs) + { + promise(std::move(__rhs)).swap(*this); + return *this; + } + promise& operator=(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise& operator=(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void swap(promise& __rhs) {_VSTD::swap(__state_, __rhs.__state_);} + + // retrieving the result + future<_R> get_future(); + + // setting the result + void set_value(const _R& __r); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void set_value(_R&& __r); +#endif + void set_exception(exception_ptr __p); + + // setting the result with deferred notification + void set_value_at_thread_exit(const _R& __r); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void set_value_at_thread_exit(_R&& __r); +#endif + void set_exception_at_thread_exit(exception_ptr __p); +}; + +template +promise<_R>::promise() + : __state_(new __assoc_state<_R>) +{ +} + +template +template +promise<_R>::promise(allocator_arg_t, const _Alloc& __a0) +{ + typedef typename _Alloc::template rebind<__assoc_state_alloc<_R, _Alloc> >::other _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a(__a0); + unique_ptr<__assoc_state_alloc<_R, _Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + ::new(__hold.get()) __assoc_state_alloc<_R, _Alloc>(__a0); + __state_ = __hold.release(); +} + +template +promise<_R>::~promise() +{ + if (__state_) + { + if (!__state_->__has_value() && __state_->use_count() > 1) + __state_->set_exception(make_exception_ptr( + future_error(make_error_code(future_errc::broken_promise)) + )); + __state_->__release_shared(); + } +} + +template +future<_R> +promise<_R>::get_future() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + return future<_R>(__state_); +} + +template +void +promise<_R>::set_value(const _R& __r) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + __state_->set_value(__r); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +promise<_R>::set_value(_R&& __r) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + __state_->set_value(_VSTD::move(__r)); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +promise<_R>::set_exception(exception_ptr __p) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + __state_->set_exception(__p); +} + +template +void +promise<_R>::set_value_at_thread_exit(const _R& __r) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + __state_->set_value_at_thread_exit(__r); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +promise<_R>::set_value_at_thread_exit(_R&& __r) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + __state_->set_value_at_thread_exit(_VSTD::move(__r)); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +promise<_R>::set_exception_at_thread_exit(exception_ptr __p) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + __state_->set_exception_at_thread_exit(__p); +} + +// promise + +template +class _LIBCPP_VISIBLE promise<_R&> +{ + __assoc_state<_R&>* __state_; + + _LIBCPP_INLINE_VISIBILITY + explicit promise(nullptr_t) : __state_(nullptr) {} + + template friend class packaged_task; + +public: + promise(); + template + promise(allocator_arg_t, const _Allocator& __a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise(promise&& __rhs) + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + promise(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~promise(); + + // assignment +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise& operator=(promise&& __rhs) + { + promise(std::move(__rhs)).swap(*this); + return *this; + } + promise& operator=(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise& operator=(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void swap(promise& __rhs) {_VSTD::swap(__state_, __rhs.__state_);} + + // retrieving the result + future<_R&> get_future(); + + // setting the result + void set_value(_R& __r); + void set_exception(exception_ptr __p); + + // setting the result with deferred notification + void set_value_at_thread_exit(_R&); + void set_exception_at_thread_exit(exception_ptr __p); +}; + +template +promise<_R&>::promise() + : __state_(new __assoc_state<_R&>) +{ +} + +template +template +promise<_R&>::promise(allocator_arg_t, const _Alloc& __a0) +{ + typedef typename _Alloc::template rebind<__assoc_state_alloc<_R&, _Alloc> >::other _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a(__a0); + unique_ptr<__assoc_state_alloc<_R&, _Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + ::new(__hold.get()) __assoc_state_alloc<_R&, _Alloc>(__a0); + __state_ = __hold.release(); +} + +template +promise<_R&>::~promise() +{ + if (__state_) + { + if (!__state_->__has_value() && __state_->use_count() > 1) + __state_->set_exception(make_exception_ptr( + future_error(make_error_code(future_errc::broken_promise)) + )); + __state_->__release_shared(); + } +} + +template +future<_R&> +promise<_R&>::get_future() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + return future<_R&>(__state_); +} + +template +void +promise<_R&>::set_value(_R& __r) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + __state_->set_value(__r); +} + +template +void +promise<_R&>::set_exception(exception_ptr __p) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + __state_->set_exception(__p); +} + +template +void +promise<_R&>::set_value_at_thread_exit(_R& __r) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + __state_->set_value_at_thread_exit(__r); +} + +template +void +promise<_R&>::set_exception_at_thread_exit(exception_ptr __p) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); +#endif + __state_->set_exception_at_thread_exit(__p); +} + +// promise + +template <> +class _LIBCPP_VISIBLE promise +{ + __assoc_sub_state* __state_; + + _LIBCPP_INLINE_VISIBILITY + explicit promise(nullptr_t) : __state_(nullptr) {} + + template friend class packaged_task; + +public: + promise(); + template + promise(allocator_arg_t, const _Allocator& __a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise(promise&& __rhs) + : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} + promise(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~promise(); + + // assignment +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + promise& operator=(promise&& __rhs) + { + promise(std::move(__rhs)).swap(*this); + return *this; + } + promise& operator=(const promise& __rhs) = delete; +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +private: + promise& operator=(const promise& __rhs); +public: +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void swap(promise& __rhs) {_VSTD::swap(__state_, __rhs.__state_);} + + // retrieving the result + future get_future(); + + // setting the result + void set_value(); + void set_exception(exception_ptr __p); + + // setting the result with deferred notification + void set_value_at_thread_exit(); + void set_exception_at_thread_exit(exception_ptr __p); +}; + +template +promise::promise(allocator_arg_t, const _Alloc& __a0) +{ + typedef typename _Alloc::template rebind<__assoc_sub_state_alloc<_Alloc> >::other _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a(__a0); + unique_ptr<__assoc_sub_state_alloc<_Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + ::new(__hold.get()) __assoc_sub_state_alloc<_Alloc>(__a0); + __state_ = __hold.release(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(promise<_R>& __x, promise<_R>& __y) +{ + __x.swap(__y); +} + +template + struct _LIBCPP_VISIBLE uses_allocator, _Alloc> + : public true_type {}; + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +// packaged_task + +template class __packaged_task_base; + +template +class __packaged_task_base<_R(_ArgTypes...)> +{ + __packaged_task_base(const __packaged_task_base&); + __packaged_task_base& operator=(const __packaged_task_base&); +public: + _LIBCPP_INLINE_VISIBILITY + __packaged_task_base() {} + _LIBCPP_INLINE_VISIBILITY + virtual ~__packaged_task_base() {} + virtual void __move_to(__packaged_task_base*) = 0; + virtual void destroy() = 0; + virtual void destroy_deallocate() = 0; + virtual _R operator()(_ArgTypes&& ...) = 0; +}; + +template class __packaged_task_func; + +template +class __packaged_task_func<_F, _Alloc, _R(_ArgTypes...)> + : public __packaged_task_base<_R(_ArgTypes...)> +{ + __compressed_pair<_F, _Alloc> __f_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __packaged_task_func(const _F& __f) : __f_(__f) {} + _LIBCPP_INLINE_VISIBILITY + explicit __packaged_task_func(_F&& __f) : __f_(_VSTD::move(__f)) {} + _LIBCPP_INLINE_VISIBILITY + __packaged_task_func(const _F& __f, const _Alloc& __a) + : __f_(__f, __a) {} + _LIBCPP_INLINE_VISIBILITY + __packaged_task_func(_F&& __f, const _Alloc& __a) + : __f_(_VSTD::move(__f), __a) {} + virtual void __move_to(__packaged_task_base<_R(_ArgTypes...)>*); + virtual void destroy(); + virtual void destroy_deallocate(); + virtual _R operator()(_ArgTypes&& ... __args); +}; + +template +void +__packaged_task_func<_F, _Alloc, _R(_ArgTypes...)>::__move_to( + __packaged_task_base<_R(_ArgTypes...)>* __p) +{ + ::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second())); +} + +template +void +__packaged_task_func<_F, _Alloc, _R(_ArgTypes...)>::destroy() +{ + __f_.~__compressed_pair<_F, _Alloc>(); +} + +template +void +__packaged_task_func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate() +{ + typedef typename _Alloc::template rebind<__packaged_task_func>::other _A; + _A __a(__f_.second()); + __f_.~__compressed_pair<_F, _Alloc>(); + __a.deallocate(this, 1); +} + +template +_R +__packaged_task_func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) +{ + return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); +} + +template class __packaged_task_function; + +template +class __packaged_task_function<_R(_ArgTypes...)> +{ + typedef __packaged_task_base<_R(_ArgTypes...)> __base; + aligned_storage<3*sizeof(void*)>::type __buf_; + __base* __f_; + +public: + typedef _R result_type; + + // construct/copy/destroy: + _LIBCPP_INLINE_VISIBILITY + __packaged_task_function() : __f_(nullptr) {} + template + __packaged_task_function(_F&& __f); + template + __packaged_task_function(allocator_arg_t, const _Alloc& __a, _F&& __f); + + __packaged_task_function(__packaged_task_function&&); + __packaged_task_function& operator=(__packaged_task_function&&); + + __packaged_task_function(const __packaged_task_function&) = delete; + __packaged_task_function& operator=(const __packaged_task_function&) = delete; + + ~__packaged_task_function(); + + void swap(__packaged_task_function&); + + _R operator()(_ArgTypes...) const; +}; + +template +__packaged_task_function<_R(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f) +{ + if (__f.__f_ == nullptr) + __f_ = nullptr; + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__move_to(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = nullptr; + } +} + +template +template +__packaged_task_function<_R(_ArgTypes...)>::__packaged_task_function(_F&& __f) + : __f_(nullptr) +{ + typedef typename remove_reference<_F>::type _FR; + typedef __packaged_task_func<_FR, allocator<_FR>, _R(_ArgTypes...)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(_VSTD::forward<_F>(__f)); + } + else + { + typedef allocator<_FF> _A; + _A __a; + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(_VSTD::forward<_F>(__f), allocator<_FR>(__a)); + __f_ = __hold.release(); + } +} + +template +template +__packaged_task_function<_R(_ArgTypes...)>::__packaged_task_function( + allocator_arg_t, const _Alloc& __a0, _F&& __f) + : __f_(nullptr) +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename remove_reference<_F>::type _FR; + typedef __packaged_task_func<_FR, _Alloc, _R(_ArgTypes...)> _FF; + if (sizeof(_FF) <= sizeof(__buf_)) + { + __f_ = (__base*)&__buf_; + ::new (__f_) _FF(_VSTD::forward<_F>(__f)); + } + else + { + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<_FF> +#else + rebind_alloc<_FF>::other +#endif + _A; + _A __a(__a0); + typedef __allocator_destructor<_A> _D; + unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); + ::new (__hold.get()) _FF(_VSTD::forward<_F>(__f), _Alloc(__a)); + __f_ = __hold.release(); + } +} + +template +__packaged_task_function<_R(_ArgTypes...)>& +__packaged_task_function<_R(_ArgTypes...)>::operator=(__packaged_task_function&& __f) +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + __f_ = nullptr; + if (__f.__f_ == nullptr) + __f_ = nullptr; + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f_ = (__base*)&__buf_; + __f.__f_->__move_to(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = nullptr; + } +} + +template +__packaged_task_function<_R(_ArgTypes...)>::~__packaged_task_function() +{ + if (__f_ == (__base*)&__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); +} + +template +void +__packaged_task_function<_R(_ArgTypes...)>::swap(__packaged_task_function& __f) +{ + if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __base* __t = (__base*)&__tempbuf; + __f_->__move_to(__t); + __f_->destroy(); + __f_ = nullptr; + __f.__f_->__move_to((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = nullptr; + __f_ = (__base*)&__buf_; + __t->__move_to((__base*)&__f.__buf_); + __t->destroy(); + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f_ == (__base*)&__buf_) + { + __f_->__move_to((__base*)&__f.__buf_); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = (__base*)&__f.__buf_; + } + else if (__f.__f_ == (__base*)&__f.__buf_) + { + __f.__f_->__move_to((__base*)&__buf_); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = (__base*)&__buf_; + } + else + _VSTD::swap(__f_, __f.__f_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_R +__packaged_task_function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const +{ + return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); +} + +template +class _LIBCPP_VISIBLE packaged_task<_R(_ArgTypes...)> +{ +public: + typedef _R result_type; + +private: + __packaged_task_function __f_; + promise __p_; + +public: + // construction and destruction + _LIBCPP_INLINE_VISIBILITY + packaged_task() : __p_(nullptr) {} + template + _LIBCPP_INLINE_VISIBILITY + explicit packaged_task(_F&& __f) : __f_(_VSTD::forward<_F>(__f)) {} + template + _LIBCPP_INLINE_VISIBILITY + explicit packaged_task(allocator_arg_t, const _Allocator& __a, _F&& __f) + : __f_(allocator_arg, __a, _VSTD::forward<_F>(__f)), + __p_(allocator_arg, __a) {} + // ~packaged_task() = default; + + // no copy + packaged_task(packaged_task&) = delete; + packaged_task& operator=(packaged_task&) = delete; + + // move support + _LIBCPP_INLINE_VISIBILITY + packaged_task(packaged_task&& __other) + : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {} + _LIBCPP_INLINE_VISIBILITY + packaged_task& operator=(packaged_task&& __other) + { + __f_ = _VSTD::move(__other.__f_); + __p_ = _VSTD::move(__other.__p_); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + void swap(packaged_task& __other) + { + __f_.swap(__other.__f_); + __p_.swap(__other.__p_); + } + + _LIBCPP_INLINE_VISIBILITY + bool valid() const {return __p_.__state_ != nullptr;} + + // result retrieval + _LIBCPP_INLINE_VISIBILITY + future get_future() {return __p_.get_future();} + + // execution + void operator()(_ArgTypes... __args); + void make_ready_at_thread_exit(_ArgTypes... __args); + + void reset(); +}; + +template +void +packaged_task<_R(_ArgTypes...)>::operator()(_ArgTypes... __args) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__p_.__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); + if (__p_.__state_->__has_value()) + throw future_error(make_error_code(future_errc::promise_already_satisfied)); + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __p_.set_value(__f_(_VSTD::forward<_ArgTypes>(__args)...)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __p_.set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template +void +packaged_task<_R(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__p_.__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); + if (__p_.__state_->__has_value()) + throw future_error(make_error_code(future_errc::promise_already_satisfied)); + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __p_.set_value_at_thread_exit(__f_(_VSTD::forward<_ArgTypes>(__args)...)); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __p_.set_exception_at_thread_exit(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template +void +packaged_task<_R(_ArgTypes...)>::reset() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (!valid()) + throw future_error(make_error_code(future_errc::no_state)); +#endif // _LIBCPP_NO_EXCEPTIONS + __p_ = promise(); +} + +template +class _LIBCPP_VISIBLE packaged_task +{ +public: + typedef void result_type; + +private: + __packaged_task_function __f_; + promise __p_; + +public: + // construction and destruction + _LIBCPP_INLINE_VISIBILITY + packaged_task() : __p_(nullptr) {} + template + _LIBCPP_INLINE_VISIBILITY + explicit packaged_task(_F&& __f) : __f_(_VSTD::forward<_F>(__f)) {} + template + _LIBCPP_INLINE_VISIBILITY + explicit packaged_task(allocator_arg_t, const _Allocator& __a, _F&& __f) + : __f_(allocator_arg, __a, _VSTD::forward<_F>(__f)), + __p_(allocator_arg, __a) {} + // ~packaged_task() = default; + + // no copy + packaged_task(packaged_task&) = delete; + packaged_task& operator=(packaged_task&) = delete; + + // move support + _LIBCPP_INLINE_VISIBILITY + packaged_task(packaged_task&& __other) + : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {} + _LIBCPP_INLINE_VISIBILITY + packaged_task& operator=(packaged_task&& __other) + { + __f_ = _VSTD::move(__other.__f_); + __p_ = _VSTD::move(__other.__p_); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + void swap(packaged_task& __other) + { + __f_.swap(__other.__f_); + __p_.swap(__other.__p_); + } + + _LIBCPP_INLINE_VISIBILITY + bool valid() const {return __p_.__state_ != nullptr;} + + // result retrieval + _LIBCPP_INLINE_VISIBILITY + future get_future() {return __p_.get_future();} + + // execution + void operator()(_ArgTypes... __args); + void make_ready_at_thread_exit(_ArgTypes... __args); + + void reset(); +}; + +template +void +packaged_task::operator()(_ArgTypes... __args) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__p_.__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); + if (__p_.__state_->__has_value()) + throw future_error(make_error_code(future_errc::promise_already_satisfied)); + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __f_(_VSTD::forward<_ArgTypes>(__args)...); + __p_.set_value(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __p_.set_exception(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template +void +packaged_task::make_ready_at_thread_exit(_ArgTypes... __args) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__p_.__state_ == nullptr) + throw future_error(make_error_code(future_errc::no_state)); + if (__p_.__state_->__has_value()) + throw future_error(make_error_code(future_errc::promise_already_satisfied)); + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __f_(_VSTD::forward<_ArgTypes>(__args)...); + __p_.set_value_at_thread_exit(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __p_.set_exception_at_thread_exit(current_exception()); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +template +void +packaged_task::reset() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + if (!valid()) + throw future_error(make_error_code(future_errc::no_state)); +#endif // _LIBCPP_NO_EXCEPTIONS + __p_ = promise(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) +{ + __x.swap(__y); +} + +template +struct _LIBCPP_VISIBLE uses_allocator, _Alloc> + : public true_type {}; + +template +future<_R> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__make_deferred_assoc_state(_F&& __f) +#else +__make_deferred_assoc_state(_F __f) +#endif +{ + unique_ptr<__deferred_assoc_state<_R, _F>, __release_shared_count> + __h(new __deferred_assoc_state<_R, _F>(_VSTD::forward<_F>(__f))); + return future<_R>(__h.get()); +} + +template +future<_R> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +__make_async_assoc_state(_F&& __f) +#else +__make_async_assoc_state(_F __f) +#endif +{ + unique_ptr<__async_assoc_state<_R, _F>, __release_shared_count> + __h(new __async_assoc_state<_R, _F>(_VSTD::forward<_F>(__f))); + _VSTD::thread(&__async_assoc_state<_R, _F>::__execute, __h.get()).detach(); + return future<_R>(__h.get()); +} + +template +class __async_func +{ + tuple<_F, _Args...> __f_; + +public: + typedef typename __invoke_of<_F, _Args...>::type _R; + + _LIBCPP_INLINE_VISIBILITY + explicit __async_func(_F&& __f, _Args&&... __args) + : __f_(_VSTD::move(__f), _VSTD::move(__args)...) {} + + _LIBCPP_INLINE_VISIBILITY + __async_func(__async_func&& __f) : __f_(_VSTD::move(__f.__f_)) {} + + _R operator()() + { + typedef typename __make_tuple_indices<1+sizeof...(_Args), 1>::type _Index; + return __execute(_Index()); + } +private: + template + _R + __execute(__tuple_indices<_Indices...>) + { + return __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...); + } +}; + +template +future::type, typename decay<_Args>::type...>::type> +async(launch __policy, _F&& __f, _Args&&... __args) +{ + typedef __async_func::type, typename decay<_Args>::type...> _BF; + typedef typename _BF::_R _R; + future<_R> __r; + if (__policy & launch::async) + __r = _VSTD::__make_async_assoc_state<_R>(_BF(__decay_copy(_VSTD::forward<_F>(__f)), + __decay_copy(_VSTD::forward<_Args>(__args))...)); + else if (__policy & launch::deferred) + __r = _VSTD::__make_deferred_assoc_state<_R>(_BF(__decay_copy(_VSTD::forward<_F>(__f)), + __decay_copy(_VSTD::forward<_Args>(__args))...)); + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +future::type, typename decay<_Args>::type...>::type> +async(_F&& __f, _Args&&... __args) +{ + return _VSTD::async(launch::any, _VSTD::forward<_F>(__f), + _VSTD::forward<_Args>(__args)...); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +// shared_future + +template +class _LIBCPP_VISIBLE shared_future +{ + __assoc_state<_R>* __state_; + +public: + _LIBCPP_INLINE_VISIBILITY + shared_future() : __state_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY + shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) + {if (__state_) __state_->__add_shared();} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future(future<_R>&& __f) : __state_(__f.__state_) + {__f.__state_ = nullptr;} + _LIBCPP_INLINE_VISIBILITY + shared_future(shared_future&& __rhs) : __state_(__rhs.__state_) + {__rhs.__state_ = nullptr;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~shared_future(); + shared_future& operator=(const shared_future& __rhs); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future& operator=(shared_future&& __rhs) + { + shared_future(std::move(__rhs)).swap(*this); + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + // retrieving the value + _LIBCPP_INLINE_VISIBILITY + const _R& get() const {return __state_->copy();} + + _LIBCPP_INLINE_VISIBILITY + void swap(shared_future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template +shared_future<_R>::~shared_future() +{ + if (__state_) + __state_->__release_shared(); +} + +template +shared_future<_R>& +shared_future<_R>::operator=(const shared_future& __rhs) +{ + if (__rhs.__state_) + __rhs.__state_->__add_shared(); + if (__state_) + __state_->__release_shared(); + __state_ = __rhs.__state_; + return *this; +} + +template +class _LIBCPP_VISIBLE shared_future<_R&> +{ + __assoc_state<_R&>* __state_; + +public: + _LIBCPP_INLINE_VISIBILITY + shared_future() : __state_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY + shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) + {if (__state_) __state_->__add_shared();} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future(future<_R&>&& __f) : __state_(__f.__state_) + {__f.__state_ = nullptr;} + _LIBCPP_INLINE_VISIBILITY + shared_future(shared_future&& __rhs) : __state_(__rhs.__state_) + {__rhs.__state_ = nullptr;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~shared_future(); + shared_future& operator=(const shared_future& __rhs); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future& operator=(shared_future&& __rhs) + { + shared_future(std::move(__rhs)).swap(*this); + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + // retrieving the value + _LIBCPP_INLINE_VISIBILITY + _R& get() const {return __state_->copy();} + + _LIBCPP_INLINE_VISIBILITY + void swap(shared_future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template +shared_future<_R&>::~shared_future() +{ + if (__state_) + __state_->__release_shared(); +} + +template +shared_future<_R&>& +shared_future<_R&>::operator=(const shared_future& __rhs) +{ + if (__rhs.__state_) + __rhs.__state_->__add_shared(); + if (__state_) + __state_->__release_shared(); + __state_ = __rhs.__state_; + return *this; +} + +template <> +class _LIBCPP_VISIBLE shared_future +{ + __assoc_sub_state* __state_; + +public: + _LIBCPP_INLINE_VISIBILITY + shared_future() : __state_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY + shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) + {if (__state_) __state_->__add_shared();} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future(future&& __f) : __state_(__f.__state_) + {__f.__state_ = nullptr;} + _LIBCPP_INLINE_VISIBILITY + shared_future(shared_future&& __rhs) : __state_(__rhs.__state_) + {__rhs.__state_ = nullptr;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + ~shared_future(); + shared_future& operator=(const shared_future& __rhs); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + shared_future& operator=(shared_future&& __rhs) + { + shared_future(std::move(__rhs)).swap(*this); + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + // retrieving the value + _LIBCPP_INLINE_VISIBILITY + void get() const {__state_->copy();} + + _LIBCPP_INLINE_VISIBILITY + void swap(shared_future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);} + + // functions to check state + _LIBCPP_INLINE_VISIBILITY + bool valid() const {return __state_ != nullptr;} + + _LIBCPP_INLINE_VISIBILITY + void wait() const {__state_->wait();} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const + {return __state_->wait_for(__rel_time);} + template + _LIBCPP_INLINE_VISIBILITY + future_status + wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const + {return __state_->wait_until(__abs_time);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(shared_future<_R>& __x, shared_future<_R>& __y) +{ + __x.swap(__y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +shared_future<_R> +future<_R>::share() +{ + return shared_future<_R>(_VSTD::move(*this)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +shared_future<_R&> +future<_R&>::share() +{ + return shared_future<_R&>(_VSTD::move(*this)); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +inline _LIBCPP_INLINE_VISIBILITY +shared_future +future::share() +{ + return shared_future(_VSTD::move(*this)); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_FUTURE diff --git a/contrib/libc++/include/initializer_list b/contrib/libc++/include/initializer_list new file mode 100644 index 000000000000..3263906d6374 --- /dev/null +++ b/contrib/libc++/include/initializer_list @@ -0,0 +1,105 @@ +// -*- C++ -*- +//===----------------------- initializer_list -----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_INITIALIZER_LIST +#define _LIBCPP_INITIALIZER_LIST + +/* + initializer_list synopsis + +namespace std +{ + +template +class initializer_list +{ +public: + typedef E value_type; + typedef const E& reference; + typedef const E& const_reference; + typedef size_t size_type; + + typedef const E* iterator; + typedef const E* const_iterator; + + initializer_list() noexcept; + + size_t size() const noexcept; + const E* begin() const noexcept; + const E* end() const noexcept; +}; + +template const E* begin(initializer_list il) noexcept; +template const E* end(initializer_list il) noexcept; + +} // std + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +namespace std // purposefully not versioned +{ + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +class _LIBCPP_VISIBLE initializer_list +{ + const _E* __begin_; + size_t __size_; + + _LIBCPP_ALWAYS_INLINE + initializer_list(const _E* __b, size_t __s) _NOEXCEPT + : __begin_(__b), + __size_(__s) + {} +public: + typedef _E value_type; + typedef const _E& reference; + typedef const _E& const_reference; + typedef size_t size_type; + + typedef const _E* iterator; + typedef const _E* const_iterator; + + _LIBCPP_ALWAYS_INLINE initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {} + + _LIBCPP_ALWAYS_INLINE size_t size() const _NOEXCEPT {return __size_;} + _LIBCPP_ALWAYS_INLINE const _E* begin() const _NOEXCEPT {return __begin_;} + _LIBCPP_ALWAYS_INLINE const _E* end() const _NOEXCEPT {return __begin_ + __size_;} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +const _E* +begin(initializer_list<_E> __il) _NOEXCEPT +{ + return __il.begin(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +const _E* +end(initializer_list<_E> __il) _NOEXCEPT +{ + return __il.end(); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +} // std + +#endif // _LIBCPP_INITIALIZER_LIST diff --git a/contrib/libc++/include/iomanip b/contrib/libc++/include/iomanip new file mode 100644 index 000000000000..15704046227f --- /dev/null +++ b/contrib/libc++/include/iomanip @@ -0,0 +1,504 @@ +// -*- C++ -*- +//===--------------------------- iomanip ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_IOMANIP +#define _LIBCPP_IOMANIP + +/* + iomanip synopsis + +// types T1, T2, ... are unspecified implementation types +T1 resetiosflags(ios_base::fmtflags mask); +T2 setiosflags (ios_base::fmtflags mask); +T3 setbase(int base); +template T4 setfill(charT c); +T5 setprecision(int n); +T6 setw(int n); +template T7 get_money(moneyT& mon, bool intl = false); +template T8 put_money(const moneyT& mon, bool intl = false); +template T9 get_time(struct tm* tmb, const charT* fmt); +template T10 put_time(const struct tm* tmb, const charT* fmt); + +} // std + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// resetiosflags + +class __iom_t1 +{ + ios_base::fmtflags __mask_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t1(ios_base::fmtflags __m) : __mask_(__m) {} + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t1& __x) + { + __is.unsetf(__x.__mask_); + return __is; + } + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t1& __x) + { + __os.unsetf(__x.__mask_); + return __os; + } +}; + +inline _LIBCPP_INLINE_VISIBILITY +__iom_t1 +resetiosflags(ios_base::fmtflags __mask) +{ + return __iom_t1(__mask); +} + +// setiosflags + +class __iom_t2 +{ + ios_base::fmtflags __mask_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t2(ios_base::fmtflags __m) : __mask_(__m) {} + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t2& __x) + { + __is.setf(__x.__mask_); + return __is; + } + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t2& __x) + { + __os.setf(__x.__mask_); + return __os; + } +}; + +inline _LIBCPP_INLINE_VISIBILITY +__iom_t2 +setiosflags(ios_base::fmtflags __mask) +{ + return __iom_t2(__mask); +} + +// setbase + +class __iom_t3 +{ + int __base_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t3(int __b) : __base_(__b) {} + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t3& __x) + { + __is.setf(__x.__base_ == 8 ? ios_base::oct : + __x.__base_ == 10 ? ios_base::dec : + __x.__base_ == 16 ? ios_base::hex : + ios_base::fmtflags(0), ios_base::basefield); + return __is; + } + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t3& __x) + { + __os.setf(__x.__base_ == 8 ? ios_base::oct : + __x.__base_ == 10 ? ios_base::dec : + __x.__base_ == 16 ? ios_base::hex : + ios_base::fmtflags(0), ios_base::basefield); + return __os; + } +}; + +inline _LIBCPP_INLINE_VISIBILITY +__iom_t3 +setbase(int __base) +{ + return __iom_t3(__base); +} + +// setfill + +template +class __iom_t4 +{ + _CharT __fill_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t4(_CharT __c) : __fill_(__c) {} + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t4& __x) + { + __os.fill(__x.__fill_); + return __os; + } +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +__iom_t4<_CharT> +setfill(_CharT __c) +{ + return __iom_t4<_CharT>(__c); +} + +// setprecision + +class __iom_t5 +{ + int __n_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t5(int __n) : __n_(__n) {} + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t5& __x) + { + __is.precision(__x.__n_); + return __is; + } + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t5& __x) + { + __os.precision(__x.__n_); + return __os; + } +}; + +inline _LIBCPP_INLINE_VISIBILITY +__iom_t5 +setprecision(int __n) +{ + return __iom_t5(__n); +} + +// setw + +class __iom_t6 +{ + int __n_; +public: + _LIBCPP_INLINE_VISIBILITY + explicit __iom_t6(int __n) : __n_(__n) {} + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t6& __x) + { + __is.width(__x.__n_); + return __is; + } + + template + friend + _LIBCPP_INLINE_VISIBILITY + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t6& __x) + { + __os.width(__x.__n_); + return __os; + } +}; + +inline _LIBCPP_INLINE_VISIBILITY +__iom_t6 +setw(int __n) +{ + return __iom_t6(__n); +} + +// get_money + +template class __iom_t7; + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x); + +template +class __iom_t7 +{ + _MoneyT& __mon_; + bool __intl_; +public: + _LIBCPP_INLINE_VISIBILITY + __iom_t7(_MoneyT& __mon, bool __intl) + : __mon_(__mon), __intl_(__intl) {} + + template + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_M>& __x); +}; + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_istream<_CharT, _Traits>::sentry __s(__is); + if (__s) + { + typedef istreambuf_iterator<_CharT, _Traits> _I; + typedef money_get<_CharT, _I> _F; + ios_base::iostate __err = ios_base::goodbit; + const _F& __mf = use_facet<_F>(__is.getloc()); + __mf.get(_I(__is), _I(), __x.__intl_, __is, __err, __x.__mon_); + __is.setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __is.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __is; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__iom_t7<_MoneyT> +get_money(_MoneyT& __mon, bool __intl = false) +{ + return __iom_t7<_MoneyT>(__mon, __intl); +} + +// put_money + +template class __iom_t8; + +template +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x); + +template +class __iom_t8 +{ + const _MoneyT& __mon_; + bool __intl_; +public: + _LIBCPP_INLINE_VISIBILITY + __iom_t8(const _MoneyT& __mon, bool __intl) + : __mon_(__mon), __intl_(__intl) {} + + template + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_M>& __x); +}; + +template +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_ostream<_CharT, _Traits>::sentry __s(__os); + if (__s) + { + typedef ostreambuf_iterator<_CharT, _Traits> _O; + typedef money_put<_CharT, _O> _F; + const _F& __mf = use_facet<_F>(__os.getloc()); + if (__mf.put(_O(__os), __x.__intl_, __os, __os.fill(), __x.__mon_).failed()) + __os.setstate(ios_base::badbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __os.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __os; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__iom_t8<_MoneyT> +put_money(const _MoneyT& __mon, bool __intl = false) +{ + return __iom_t8<_MoneyT>(__mon, __intl); +} + +// get_time + +template class __iom_t9; + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x); + +template +class __iom_t9 +{ + tm* __tm_; + const _CharT* __fmt_; +public: + _LIBCPP_INLINE_VISIBILITY + __iom_t9(tm* __tm, const _CharT* __fmt) + : __tm_(__tm), __fmt_(__fmt) {} + + template + friend + basic_istream<_C, _Traits>& + operator>>(basic_istream<_C, _Traits>& __is, const __iom_t9<_C>& __x); +}; + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_istream<_CharT, _Traits>::sentry __s(__is); + if (__s) + { + typedef istreambuf_iterator<_CharT, _Traits> _I; + typedef time_get<_CharT, _I> _F; + ios_base::iostate __err = ios_base::goodbit; + const _F& __tf = use_facet<_F>(__is.getloc()); + __tf.get(_I(__is), _I(), __is, __err, __x.__tm_, + __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)); + __is.setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __is.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __is; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__iom_t9<_CharT> +get_time(tm* __tm, const _CharT* __fmt) +{ + return __iom_t9<_CharT>(__tm, __fmt); +} + +// put_time + +template class __iom_t10; + +template +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x); + +template +class __iom_t10 +{ + const tm* __tm_; + const _CharT* __fmt_; +public: + _LIBCPP_INLINE_VISIBILITY + __iom_t10(const tm* __tm, const _CharT* __fmt) + : __tm_(__tm), __fmt_(__fmt) {} + + template + friend + basic_ostream<_C, _Traits>& + operator<<(basic_ostream<_C, _Traits>& __os, const __iom_t10<_C>& __x); +}; + +template +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_ostream<_CharT, _Traits>::sentry __s(__os); + if (__s) + { + typedef ostreambuf_iterator<_CharT, _Traits> _O; + typedef time_put<_CharT, _O> _F; + const _F& __tf = use_facet<_F>(__os.getloc()); + if (__tf.put(_O(__os), __os, __os.fill(), __x.__tm_, + __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)).failed()) + __os.setstate(ios_base::badbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __os.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __os; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__iom_t10<_CharT> +put_time(const tm* __tm, const _CharT* __fmt) +{ + return __iom_t10<_CharT>(__tm, __fmt); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_IOMANIP diff --git a/contrib/libc++/include/ios b/contrib/libc++/include/ios new file mode 100644 index 000000000000..7ea63a31ca71 --- /dev/null +++ b/contrib/libc++/include/ios @@ -0,0 +1,987 @@ +// -*- C++ -*- +//===---------------------------- ios -------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_IOS +#define _LIBCPP_IOS + +/* + ios synopsis + +#include + +namespace std +{ + +typedef OFF_T streamoff; +typedef SZ_T streamsize; +template class fpos; + +class ios_base +{ +public: + class failure; + + typedef T1 fmtflags; + static const fmtflags boolalpha; + static const fmtflags dec; + static const fmtflags fixed; + static const fmtflags hex; + static const fmtflags internal; + static const fmtflags left; + static const fmtflags oct; + static const fmtflags right; + static const fmtflags scientific; + static const fmtflags showbase; + static const fmtflags showpoint; + static const fmtflags showpos; + static const fmtflags skipws; + static const fmtflags unitbuf; + static const fmtflags uppercase; + static const fmtflags adjustfield; + static const fmtflags basefield; + static const fmtflags floatfield; + + typedef T2 iostate; + static const iostate badbit; + static const iostate eofbit; + static const iostate failbit; + static const iostate goodbit; + + typedef T3 openmode; + static const openmode app; + static const openmode ate; + static const openmode binary; + static const openmode in; + static const openmode out; + static const openmode trunc; + + typedef T4 seekdir; + static const seekdir beg; + static const seekdir cur; + static const seekdir end; + + class Init; + + // 27.5.2.2 fmtflags state: + fmtflags flags() const; + fmtflags flags(fmtflags fmtfl); + fmtflags setf(fmtflags fmtfl); + fmtflags setf(fmtflags fmtfl, fmtflags mask); + void unsetf(fmtflags mask); + + streamsize precision() const; + streamsize precision(streamsize prec); + streamsize width() const; + streamsize width(streamsize wide); + + // 27.5.2.3 locales: + locale imbue(const locale& loc); + locale getloc() const; + + // 27.5.2.5 storage: + static int xalloc(); + long& iword(int index); + void*& pword(int index); + + // destructor + virtual ~ios_base(); + + // 27.5.2.6 callbacks; + enum event { erase_event, imbue_event, copyfmt_event }; + typedef void (*event_callback)(event, ios_base&, int index); + void register_callback(event_callback fn, int index); + + ios_base(const ios_base&) = delete; + ios_base& operator=(const ios_base&) = delete; + + static bool sync_with_stdio(bool sync = true); + +protected: + ios_base(); +}; + +template > +class basic_ios + : public ios_base +{ +public: + // types: + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + typedef traits traits_type; + + operator unspecified-bool-type() const; + bool operator!() const; + iostate rdstate() const; + void clear(iostate state = goodbit); + void setstate(iostate state); + bool good() const; + bool eof() const; + bool fail() const; + bool bad() const; + + iostate exceptions() const; + void exceptions(iostate except); + + // 27.5.4.1 Constructor/destructor: + explicit basic_ios(basic_streambuf* sb); + virtual ~basic_ios(); + + // 27.5.4.2 Members: + basic_ostream* tie() const; + basic_ostream* tie(basic_ostream* tiestr); + + basic_streambuf* rdbuf() const; + basic_streambuf* rdbuf(basic_streambuf* sb); + + basic_ios& copyfmt(const basic_ios& rhs); + + char_type fill() const; + char_type fill(char_type ch); + + locale imbue(const locale& loc); + + char narrow(char_type c, char dfault) const; + char_type widen(char c) const; + + basic_ios(const basic_ios& ) = delete; + basic_ios& operator=(const basic_ios&) = delete; + +protected: + basic_ios(); + void init(basic_streambuf* sb); + void move(basic_ios& rhs); + void swap(basic_ios& rhs); + void set_rdbuf(basic_streambuf* sb); +}; + +// 27.5.5, manipulators: +ios_base& boolalpha (ios_base& str); +ios_base& noboolalpha(ios_base& str); +ios_base& showbase (ios_base& str); +ios_base& noshowbase (ios_base& str); +ios_base& showpoint (ios_base& str); +ios_base& noshowpoint(ios_base& str); +ios_base& showpos (ios_base& str); +ios_base& noshowpos (ios_base& str); +ios_base& skipws (ios_base& str); +ios_base& noskipws (ios_base& str); +ios_base& uppercase (ios_base& str); +ios_base& nouppercase(ios_base& str); +ios_base& unitbuf (ios_base& str); +ios_base& nounitbuf (ios_base& str); + +// 27.5.5.2 adjustfield: +ios_base& internal (ios_base& str); +ios_base& left (ios_base& str); +ios_base& right (ios_base& str); + +// 27.5.5.3 basefield: +ios_base& dec (ios_base& str); +ios_base& hex (ios_base& str); +ios_base& oct (ios_base& str); + +// 27.5.5.4 floatfield: +ios_base& fixed (ios_base& str); +ios_base& scientific (ios_base& str); +ios_base& hexfloat (ios_base& str); +ios_base& defaultfloat(ios_base& str); + +// 27.5.5.5 error reporting: +enum class io_errc +{ + stream = 1 +}; + +concept_map ErrorCodeEnum { }; +error_code make_error_code(io_errc e); +error_condition make_error_condition(io_errc e); +storage-class-specifier const error_category& iostream_category; + +} // std + +*/ + +#include <__config> +#include +#include <__locale> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +typedef ptrdiff_t streamsize; + +class _LIBCPP_VISIBLE ios_base +{ +public: + class failure; + + typedef unsigned int fmtflags; + static const fmtflags boolalpha = 0x0001; + static const fmtflags dec = 0x0002; + static const fmtflags fixed = 0x0004; + static const fmtflags hex = 0x0008; + static const fmtflags internal = 0x0010; + static const fmtflags left = 0x0020; + static const fmtflags oct = 0x0040; + static const fmtflags right = 0x0080; + static const fmtflags scientific = 0x0100; + static const fmtflags showbase = 0x0200; + static const fmtflags showpoint = 0x0400; + static const fmtflags showpos = 0x0800; + static const fmtflags skipws = 0x1000; + static const fmtflags unitbuf = 0x2000; + static const fmtflags uppercase = 0x4000; + static const fmtflags adjustfield = left | right | internal; + static const fmtflags basefield = dec | oct | hex; + static const fmtflags floatfield = scientific | fixed; + + typedef unsigned int iostate; + typedef iostate io_state; + static const iostate badbit = 0x1; + static const iostate eofbit = 0x2; + static const iostate failbit = 0x4; + static const iostate goodbit = 0x0; + + typedef unsigned int openmode; + typedef openmode open_mode; + static const openmode app = 0x01; + static const openmode ate = 0x02; + static const openmode binary = 0x04; + static const openmode in = 0x08; + static const openmode out = 0x10; + static const openmode trunc = 0x20; + + enum seekdir {beg, cur, end}; + typedef seekdir seek_dir; + + typedef _VSTD::streamoff streamoff; + typedef _VSTD::streampos streampos; + + class Init; + + // 27.5.2.2 fmtflags state: + _LIBCPP_INLINE_VISIBILITY fmtflags flags() const; + _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl); + _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl); + _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask); + _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask); + + _LIBCPP_INLINE_VISIBILITY streamsize precision() const; + _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec); + _LIBCPP_INLINE_VISIBILITY streamsize width() const; + _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide); + + // 27.5.2.3 locales: + locale imbue(const locale& __loc); + locale getloc() const; + + // 27.5.2.5 storage: + static int xalloc(); + long& iword(int __index); + void*& pword(int __index); + + // destructor + virtual ~ios_base(); + + // 27.5.2.6 callbacks; + enum event { erase_event, imbue_event, copyfmt_event }; + typedef void (*event_callback)(event, ios_base&, int __index); + void register_callback(event_callback __fn, int __index); + +private: + ios_base(const ios_base&); // = delete; + ios_base& operator=(const ios_base&); // = delete; + +public: + static bool sync_with_stdio(bool __sync = true); + + _LIBCPP_INLINE_VISIBILITY iostate rdstate() const; + void clear(iostate __state = goodbit); + _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state); + + _LIBCPP_INLINE_VISIBILITY bool good() const; + _LIBCPP_INLINE_VISIBILITY bool eof() const; + _LIBCPP_INLINE_VISIBILITY bool fail() const; + _LIBCPP_INLINE_VISIBILITY bool bad() const; + + _LIBCPP_INLINE_VISIBILITY iostate exceptions() const; + _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __except); + + void __set_badbit_and_consider_rethrow(); + void __set_failbit_and_consider_rethrow(); + +protected: + _LIBCPP_INLINE_VISIBILITY + ios_base() {// purposefully does no initialization + } + + void init(void* __sb); + _LIBCPP_ALWAYS_INLINE void* rdbuf() const {return __rdbuf_;} + + _LIBCPP_ALWAYS_INLINE + void rdbuf(void* __sb) + { + __rdbuf_ = __sb; + clear(); + } + + void __call_callbacks(event); + void copyfmt(const ios_base&); + void move(ios_base&); + void swap(ios_base&); + + _LIBCPP_ALWAYS_INLINE + void set_rdbuf(void* __sb) + { + __rdbuf_ = __sb; + } + +private: + // All data members must be scalars + fmtflags __fmtflags_; + streamsize __precision_; + streamsize __width_; + iostate __rdstate_; + iostate __exceptions_; + void* __rdbuf_; + void* __loc_; + event_callback* __fn_; + int* __index_; + size_t __event_size_; + size_t __event_cap_; + static int __xindex_; + long* __iarray_; + size_t __iarray_size_; + size_t __iarray_cap_; + void** __parray_; + size_t __parray_size_; + size_t __parray_cap_; +}; + +//enum class io_errc +struct _LIBCPP_VISIBLE io_errc +{ +enum _ { + stream = 1 +}; + _ __v_; + + _LIBCPP_ALWAYS_INLINE io_errc(_ __v) : __v_(__v) {} + _LIBCPP_ALWAYS_INLINE operator int() const {return __v_;} +}; + +template <> +struct _LIBCPP_VISIBLE is_error_code_enum : public true_type { }; +template <> +struct _LIBCPP_VISIBLE is_error_code_enum : public true_type { }; + +_LIBCPP_VISIBLE +const error_category& iostream_category(); + +inline _LIBCPP_INLINE_VISIBILITY +error_code +make_error_code(io_errc __e) +{ + return error_code(static_cast(__e), iostream_category()); +} + +inline _LIBCPP_INLINE_VISIBILITY +error_condition +make_error_condition(io_errc __e) +{ + return error_condition(static_cast(__e), iostream_category()); +} + +class _LIBCPP_EXCEPTION_ABI ios_base::failure + : public system_error +{ +public: + explicit failure(const string& __msg, const error_code& __ec = io_errc::stream); + explicit failure(const char* __msg, const error_code& __ec = io_errc::stream); + virtual ~failure() throw(); +}; + +class _LIBCPP_VISIBLE ios_base::Init +{ +public: + Init(); + ~Init(); +}; + +// fmtflags + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::fmtflags +ios_base::flags() const +{ + return __fmtflags_; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::fmtflags +ios_base::flags(fmtflags __fmtfl) +{ + fmtflags __r = __fmtflags_; + __fmtflags_ = __fmtfl; + return __r; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::fmtflags +ios_base::setf(fmtflags __fmtfl) +{ + fmtflags __r = __fmtflags_; + __fmtflags_ |= __fmtfl; + return __r; +} + +inline _LIBCPP_INLINE_VISIBILITY +void +ios_base::unsetf(fmtflags __mask) +{ + __fmtflags_ &= ~__mask; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::fmtflags +ios_base::setf(fmtflags __fmtfl, fmtflags __mask) +{ + fmtflags __r = __fmtflags_; + unsetf(__mask); + __fmtflags_ |= __fmtfl & __mask; + return __r; +} + +// precision + +inline _LIBCPP_INLINE_VISIBILITY +streamsize +ios_base::precision() const +{ + return __precision_; +} + +inline _LIBCPP_INLINE_VISIBILITY +streamsize +ios_base::precision(streamsize __prec) +{ + streamsize __r = __precision_; + __precision_ = __prec; + return __r; +} + +// width + +inline _LIBCPP_INLINE_VISIBILITY +streamsize +ios_base::width() const +{ + return __width_; +} + +inline _LIBCPP_INLINE_VISIBILITY +streamsize +ios_base::width(streamsize __wide) +{ + streamsize __r = __width_; + __width_ = __wide; + return __r; +} + +// iostate + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::iostate +ios_base::rdstate() const +{ + return __rdstate_; +} + +inline _LIBCPP_INLINE_VISIBILITY +void +ios_base::setstate(iostate __state) +{ + clear(__rdstate_ | __state); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +ios_base::good() const +{ + return __rdstate_ == 0; +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +ios_base::eof() const +{ + return __rdstate_ & eofbit; +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +ios_base::fail() const +{ + return __rdstate_ & (failbit | badbit); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +ios_base::bad() const +{ + return __rdstate_ & badbit; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base::iostate +ios_base::exceptions() const +{ + return __exceptions_; +} + +inline _LIBCPP_INLINE_VISIBILITY +void +ios_base::exceptions(iostate __except) +{ + __exceptions_ = __except; + clear(__rdstate_); +} + +template +class _LIBCPP_VISIBLE basic_ios + : public ios_base +{ +public: + // types: + typedef _CharT char_type; + typedef _Traits traits_type; + + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + _LIBCPP_ALWAYS_INLINE // explicit + operator bool() const {return !fail();} + _LIBCPP_ALWAYS_INLINE bool operator!() const {return fail();} + _LIBCPP_ALWAYS_INLINE iostate rdstate() const {return ios_base::rdstate();} + _LIBCPP_ALWAYS_INLINE void clear(iostate __state = goodbit) {ios_base::clear(__state);} + _LIBCPP_ALWAYS_INLINE void setstate(iostate __state) {ios_base::setstate(__state);} + _LIBCPP_ALWAYS_INLINE bool good() const {return ios_base::good();} + _LIBCPP_ALWAYS_INLINE bool eof() const {return ios_base::eof();} + _LIBCPP_ALWAYS_INLINE bool fail() const {return ios_base::fail();} + _LIBCPP_ALWAYS_INLINE bool bad() const {return ios_base::bad();} + + _LIBCPP_ALWAYS_INLINE iostate exceptions() const {return ios_base::exceptions();} + _LIBCPP_ALWAYS_INLINE void exceptions(iostate __except) {ios_base::exceptions(__except);} + + // 27.5.4.1 Constructor/destructor: + _LIBCPP_INLINE_VISIBILITY + explicit basic_ios(basic_streambuf* __sb); + virtual ~basic_ios(); + + // 27.5.4.2 Members: + _LIBCPP_INLINE_VISIBILITY + basic_ostream* tie() const; + _LIBCPP_INLINE_VISIBILITY + basic_ostream* tie(basic_ostream* __tiestr); + + _LIBCPP_INLINE_VISIBILITY + basic_streambuf* rdbuf() const; + _LIBCPP_INLINE_VISIBILITY + basic_streambuf* rdbuf(basic_streambuf* __sb); + + basic_ios& copyfmt(const basic_ios& __rhs); + + _LIBCPP_INLINE_VISIBILITY + char_type fill() const; + _LIBCPP_INLINE_VISIBILITY + char_type fill(char_type __ch); + + _LIBCPP_INLINE_VISIBILITY + locale imbue(const locale& __loc); + + _LIBCPP_INLINE_VISIBILITY + char narrow(char_type __c, char __dfault) const; + _LIBCPP_INLINE_VISIBILITY + char_type widen(char __c) const; + +protected: + _LIBCPP_ALWAYS_INLINE + basic_ios() {// purposefully does no initialization + } + _LIBCPP_INLINE_VISIBILITY + void init(basic_streambuf* __sb); + + _LIBCPP_INLINE_VISIBILITY + void move(basic_ios& __rhs); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_ALWAYS_INLINE + void move(basic_ios&& __rhs) {move(__rhs);} +#endif + _LIBCPP_INLINE_VISIBILITY + void swap(basic_ios& __rhs); + _LIBCPP_INLINE_VISIBILITY + void set_rdbuf(basic_streambuf* __sb); +private: + basic_ostream* __tie_; + char_type __fill_; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf* __sb) +{ + init(__sb); +} + +template +basic_ios<_CharT, _Traits>::~basic_ios() +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ios<_CharT, _Traits>::init(basic_streambuf* __sb) +{ + ios_base::init(__sb); + __tie_ = 0; + __fill_ = widen(' '); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>* +basic_ios<_CharT, _Traits>::tie() const +{ + return __tie_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>* +basic_ios<_CharT, _Traits>::tie(basic_ostream* __tiestr) +{ + basic_ostream* __r = __tie_; + __tie_ = __tiestr; + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_streambuf<_CharT, _Traits>* +basic_ios<_CharT, _Traits>::rdbuf() const +{ + return static_cast*>(ios_base::rdbuf()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_streambuf<_CharT, _Traits>* +basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf* __sb) +{ + basic_streambuf* __r = rdbuf(); + ios_base::rdbuf(__sb); + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +locale +basic_ios<_CharT, _Traits>::imbue(const locale& __loc) +{ + locale __r = getloc(); + ios_base::imbue(__loc); + if (rdbuf()) + rdbuf()->pubimbue(__loc); + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +char +basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const +{ + return use_facet >(getloc()).narrow(__c, __dfault); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_CharT +basic_ios<_CharT, _Traits>::widen(char __c) const +{ + return use_facet >(getloc()).widen(__c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_CharT +basic_ios<_CharT, _Traits>::fill() const +{ + return __fill_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_CharT +basic_ios<_CharT, _Traits>::fill(char_type __ch) +{ + char_type __r = __fill_; + __fill_ = __ch; + return __r; +} + +template +basic_ios<_CharT, _Traits>& +basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) +{ + if (this != &__rhs) + { + __call_callbacks(erase_event); + ios_base::copyfmt(__rhs); + __tie_ = __rhs.__tie_; + __fill_ = __rhs.__fill_; + __call_callbacks(copyfmt_event); + exceptions(__rhs.exceptions()); + } + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ios<_CharT, _Traits>::move(basic_ios& __rhs) +{ + ios_base::move(__rhs); + __tie_ = __rhs.__tie_; + __rhs.__tie_ = 0; + __fill_ = __rhs.__fill_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) +{ + ios_base::swap(__rhs); + _VSTD::swap(__tie_, __rhs.__tie_); + _VSTD::swap(__fill_, __rhs.__fill_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf* __sb) +{ + ios_base::set_rdbuf(__sb); +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +boolalpha(ios_base& __str) +{ + __str.setf(ios_base::boolalpha); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +noboolalpha(ios_base& __str) +{ + __str.unsetf(ios_base::boolalpha); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +showbase(ios_base& __str) +{ + __str.setf(ios_base::showbase); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +noshowbase(ios_base& __str) +{ + __str.unsetf(ios_base::showbase); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +showpoint(ios_base& __str) +{ + __str.setf(ios_base::showpoint); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +noshowpoint(ios_base& __str) +{ + __str.unsetf(ios_base::showpoint); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +showpos(ios_base& __str) +{ + __str.setf(ios_base::showpos); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +noshowpos(ios_base& __str) +{ + __str.unsetf(ios_base::showpos); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +skipws(ios_base& __str) +{ + __str.setf(ios_base::skipws); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +noskipws(ios_base& __str) +{ + __str.unsetf(ios_base::skipws); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +uppercase(ios_base& __str) +{ + __str.setf(ios_base::uppercase); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +nouppercase(ios_base& __str) +{ + __str.unsetf(ios_base::uppercase); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +unitbuf(ios_base& __str) +{ + __str.setf(ios_base::unitbuf); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +nounitbuf(ios_base& __str) +{ + __str.unsetf(ios_base::unitbuf); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +internal(ios_base& __str) +{ + __str.setf(ios_base::internal, ios_base::adjustfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +left(ios_base& __str) +{ + __str.setf(ios_base::left, ios_base::adjustfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +right(ios_base& __str) +{ + __str.setf(ios_base::right, ios_base::adjustfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +dec(ios_base& __str) +{ + __str.setf(ios_base::dec, ios_base::basefield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +hex(ios_base& __str) +{ + __str.setf(ios_base::hex, ios_base::basefield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +oct(ios_base& __str) +{ + __str.setf(ios_base::oct, ios_base::basefield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +fixed(ios_base& __str) +{ + __str.setf(ios_base::fixed, ios_base::floatfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +scientific(ios_base& __str) +{ + __str.setf(ios_base::scientific, ios_base::floatfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +hexfloat(ios_base& __str) +{ + __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield); + return __str; +} + +inline _LIBCPP_INLINE_VISIBILITY +ios_base& +defaultfloat(ios_base& __str) +{ + __str.unsetf(ios_base::floatfield); + return __str; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_IOS diff --git a/contrib/libc++/include/iosfwd b/contrib/libc++/include/iosfwd new file mode 100644 index 000000000000..7e5ac7321f54 --- /dev/null +++ b/contrib/libc++/include/iosfwd @@ -0,0 +1,194 @@ +// -*- C++ -*- +//===--------------------------- iosfwd -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_IOSFWD +#define _LIBCPP_IOSFWD + +/* + iosfwd synopsis + +namespace std +{ + +template struct char_traits; +template class allocator; + +class ios_base; +template > class basic_ios; + +template > class basic_streambuf; +template > class basic_istream; +template > class basic_ostream; +template > class basic_iostream; + +template , class Allocator = allocator > + class basic_stringbuf; +template , class Allocator = allocator > + class basic_istringstream; +template , class Allocator = allocator > + class basic_ostringstream; +template , class Allocator = allocator > + class basic_stringstream; + +template > class basic_filebuf; +template > class basic_ifstream; +template > class basic_ofstream; +template > class basic_fstream; + +template > class istreambuf_iterator; +template > class ostreambuf_iterator; + +typedef basic_ios ios; +typedef basic_ios wios; + +typedef basic_streambuf streambuf; +typedef basic_istream istream; +typedef basic_ostream ostream; +typedef basic_iostream iostream; + +typedef basic_stringbuf stringbuf; +typedef basic_istringstream istringstream; +typedef basic_ostringstream ostringstream; +typedef basic_stringstream stringstream; + +typedef basic_filebuf filebuf; +typedef basic_ifstream ifstream; +typedef basic_ofstream ofstream; +typedef basic_fstream fstream; + +typedef basic_streambuf wstreambuf; +typedef basic_istream wistream; +typedef basic_ostream wostream; +typedef basic_iostream wiostream; + +typedef basic_stringbuf wstringbuf; +typedef basic_istringstream wistringstream; +typedef basic_ostringstream wostringstream; +typedef basic_stringstream wstringstream; + +typedef basic_filebuf wfilebuf; +typedef basic_ifstream wifstream; +typedef basic_ofstream wofstream; +typedef basic_fstream wfstream; + +template class fpos; +typedef fpos::state_type> streampos; +typedef fpos::state_type> wstreampos; + +} // std + +*/ + +#include <__config> +#include // for mbstate_t + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +class ios_base; + +template struct _LIBCPP_VISIBLE char_traits; +template class _LIBCPP_VISIBLE allocator; + +template > + class _LIBCPP_VISIBLE basic_ios; + +template > + class _LIBCPP_VISIBLE basic_streambuf; +template > + class _LIBCPP_VISIBLE basic_istream; +template > + class _LIBCPP_VISIBLE basic_ostream; +template > + class _LIBCPP_VISIBLE basic_iostream; + +template , + class _Allocator = allocator<_CharT> > + class _LIBCPP_VISIBLE basic_stringbuf; +template , + class _Allocator = allocator<_CharT> > + class _LIBCPP_VISIBLE basic_istringstream; +template , + class _Allocator = allocator<_CharT> > + class _LIBCPP_VISIBLE basic_ostringstream; +template , + class _Allocator = allocator<_CharT> > + class _LIBCPP_VISIBLE basic_stringstream; + +template > + class _LIBCPP_VISIBLE basic_filebuf; +template > + class _LIBCPP_VISIBLE basic_ifstream; +template > + class _LIBCPP_VISIBLE basic_ofstream; +template > + class _LIBCPP_VISIBLE basic_fstream; + +template > + class _LIBCPP_VISIBLE istreambuf_iterator; +template > + class _LIBCPP_VISIBLE ostreambuf_iterator; + +typedef basic_ios ios; +typedef basic_ios wios; + +typedef basic_streambuf streambuf; +typedef basic_istream istream; +typedef basic_ostream ostream; +typedef basic_iostream iostream; + +typedef basic_stringbuf stringbuf; +typedef basic_istringstream istringstream; +typedef basic_ostringstream ostringstream; +typedef basic_stringstream stringstream; + +typedef basic_filebuf filebuf; +typedef basic_ifstream ifstream; +typedef basic_ofstream ofstream; +typedef basic_fstream fstream; + +typedef basic_streambuf wstreambuf; +typedef basic_istream wistream; +typedef basic_ostream wostream; +typedef basic_iostream wiostream; + +typedef basic_stringbuf wstringbuf; +typedef basic_istringstream wistringstream; +typedef basic_ostringstream wostringstream; +typedef basic_stringstream wstringstream; + +typedef basic_filebuf wfilebuf; +typedef basic_ifstream wifstream; +typedef basic_ofstream wofstream; +typedef basic_fstream wfstream; + +template class _LIBCPP_VISIBLE fpos; +typedef fpos streampos; +typedef fpos wstreampos; +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS +typedef fpos u16streampos; +typedef fpos u32streampos; +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +typedef long long streamoff; // for char_traits in + +template + class _Traits = char_traits<_CharT>, + class _Allocator = allocator<_CharT> > + class _LIBCPP_VISIBLE basic_string; +typedef basic_string, allocator > string; +typedef basic_string, allocator > wstring; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_IOSFWD diff --git a/contrib/libc++/include/iostream b/contrib/libc++/include/iostream new file mode 100644 index 000000000000..53cd146cc595 --- /dev/null +++ b/contrib/libc++/include/iostream @@ -0,0 +1,60 @@ +// -*- C++ -*- +//===--------------------------- iostream ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_IOSTREAM +#define _LIBCPP_IOSTREAM + +/* + iostream synopsis + +#include +#include +#include +#include + +namespace std { + +extern istream cin; +extern ostream cout; +extern ostream cerr; +extern ostream clog; +extern wistream wcin; +extern wostream wcout; +extern wostream wcerr; +extern wostream wclog; + +} // std + +*/ + +#include <__config> +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +extern _LIBCPP_VISIBLE istream cin; +extern _LIBCPP_VISIBLE ostream cout; +extern _LIBCPP_VISIBLE ostream cerr; +extern _LIBCPP_VISIBLE ostream clog; +extern _LIBCPP_VISIBLE wistream wcin; +extern _LIBCPP_VISIBLE wostream wcout; +extern _LIBCPP_VISIBLE wostream wcerr; +extern _LIBCPP_VISIBLE wostream wclog; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_IOSTREAM diff --git a/contrib/libc++/include/istream b/contrib/libc++/include/istream new file mode 100644 index 000000000000..24d9f3a9f63a --- /dev/null +++ b/contrib/libc++/include/istream @@ -0,0 +1,1711 @@ +// -*- C++ -*- +//===--------------------------- istream ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ISTREAM +#define _LIBCPP_ISTREAM + +/* + istream synopsis + +template > +class basic_istream + : virtual public basic_ios +{ +public: + // types (inherited from basic_ios (27.5.4)): + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // 27.7.1.1.1 Constructor/destructor: + explicit basic_istream(basic_streambuf* sb); + basic_istream(basic_istream&& rhs); + virtual ~basic_istream(); + + // 27.7.1.1.2 Assign/swap: + basic_istream& operator=(basic_istream&& rhs); + void swap(basic_istream& rhs); + + // 27.7.1.1.3 Prefix/suffix: + class sentry; + + // 27.7.1.2 Formatted input: + basic_istream& operator>>(basic_istream& (*pf)(basic_istream&)); + basic_istream& operator>>(basic_ios& + (*pf)(basic_ios&)); + basic_istream& operator>>(ios_base& (*pf)(ios_base&)); + basic_istream& operator>>(basic_streambuf* sb); + basic_istream& operator>>(bool& n); + basic_istream& operator>>(short& n); + basic_istream& operator>>(unsigned short& n); + basic_istream& operator>>(int& n); + basic_istream& operator>>(unsigned int& n); + basic_istream& operator>>(long& n); + basic_istream& operator>>(unsigned long& n); + basic_istream& operator>>(long long& n); + basic_istream& operator>>(unsigned long long& n); + basic_istream& operator>>(float& f); + basic_istream& operator>>(double& f); + basic_istream& operator>>(long double& f); + basic_istream& operator>>(void*& p); + + // 27.7.1.3 Unformatted input: + streamsize gcount() const; + int_type get(); + basic_istream& get(char_type& c); + basic_istream& get(char_type* s, streamsize n); + basic_istream& get(char_type* s, streamsize n, char_type delim); + basic_istream& get(basic_streambuf& sb); + basic_istream& get(basic_streambuf& sb, char_type delim); + + basic_istream& getline(char_type* s, streamsize n); + basic_istream& getline(char_type* s, streamsize n, char_type delim); + + basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof()); + int_type peek(); + basic_istream& read (char_type* s, streamsize n); + streamsize readsome(char_type* s, streamsize n); + + basic_istream& putback(char_type c); + basic_istream& unget(); + int sync(); + + pos_type tellg(); + basic_istream& seekg(pos_type); + basic_istream& seekg(off_type, ios_base::seekdir); +}; + +// 27.7.1.2.3 character extraction templates: +template + basic_istream& operator>>(basic_istream&, charT&); + +template + basic_istream& operator>>(basic_istream&, unsigned char&); + +template + basic_istream& operator>>(basic_istream&, signed char&); + +template + basic_istream& operator>>(basic_istream&, charT*); + +template + basic_istream& operator>>(basic_istream&, unsigned char*); + +template + basic_istream& operator>>(basic_istream&, signed char*); + +template + void + swap(basic_istream& x, basic_istream& y); + +typedef basic_istream istream; +typedef basic_istream wistream; + +template > +class basic_iostream : + public basic_istream, + public basic_ostream +{ +public: + // types: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // constructor/destructor + explicit basic_iostream(basic_streambuf* sb); + basic_iostream(basic_iostream&& rhs); + virtual ~basic_iostream(); + + // assign/swap + basic_iostream& operator=(basic_iostream&& rhs); + void swap(basic_iostream& rhs); +}; + +template + void + swap(basic_iostream& x, basic_iostream& y); + +typedef basic_iostream iostream; +typedef basic_iostream wiostream; + +template + basic_istream& + ws(basic_istream& is); + +template + basic_istream& + operator>>(basic_istream&& is, T& x); + +} // std + +*/ + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +class _LIBCPP_VISIBLE basic_istream + : virtual public basic_ios<_CharT, _Traits> +{ + streamsize __gc_; +public: + // types (inherited from basic_ios (27.5.4)): + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // 27.7.1.1.1 Constructor/destructor: + explicit basic_istream(basic_streambuf* __sb); + virtual ~basic_istream(); +protected: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + basic_istream(basic_istream&& __rhs); +#endif + + // 27.7.1.1.2 Assign/swap: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + basic_istream& operator=(basic_istream&& __rhs); +#endif + void swap(basic_istream& __rhs); +public: + + // 27.7.1.1.3 Prefix/suffix: + class sentry; + + // 27.7.1.2 Formatted input: + basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)); + basic_istream& operator>>(basic_ios& + (*__pf)(basic_ios&)); + basic_istream& operator>>(ios_base& (*__pf)(ios_base&)); + basic_istream& operator>>(basic_streambuf* __sb); + basic_istream& operator>>(bool& __n); + basic_istream& operator>>(short& __n); + basic_istream& operator>>(unsigned short& __n); + basic_istream& operator>>(int& __n); + basic_istream& operator>>(unsigned int& __n); + basic_istream& operator>>(long& __n); + basic_istream& operator>>(unsigned long& __n); + basic_istream& operator>>(long long& __n); + basic_istream& operator>>(unsigned long long& __n); + basic_istream& operator>>(float& __f); + basic_istream& operator>>(double& __f); + basic_istream& operator>>(long double& __f); + basic_istream& operator>>(void*& __p); + + // 27.7.1.3 Unformatted input: + _LIBCPP_INLINE_VISIBILITY + streamsize gcount() const {return __gc_;} + int_type get(); + basic_istream& get(char_type& __c); + basic_istream& get(char_type* __s, streamsize __n); + basic_istream& get(char_type* __s, streamsize __n, char_type __dlm); + basic_istream& get(basic_streambuf& __sb); + basic_istream& get(basic_streambuf& __sb, char_type __dlm); + + basic_istream& getline(char_type* __s, streamsize __n); + basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm); + + basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof()); + int_type peek(); + basic_istream& read (char_type* __s, streamsize __n); + streamsize readsome(char_type* __s, streamsize __n); + + basic_istream& putback(char_type __c); + basic_istream& unget(); + int sync(); + + pos_type tellg(); + basic_istream& seekg(pos_type __pos); + basic_istream& seekg(off_type __off, ios_base::seekdir __dir); +}; + +template +class _LIBCPP_VISIBLE basic_istream<_CharT, _Traits>::sentry +{ + bool __ok_; + + sentry(const sentry&); // = delete; + sentry& operator=(const sentry&); // = delete; + +public: + explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false); +// ~sentry() = default; + + _LIBCPP_INLINE_VISIBILITY + // explicit + operator bool() const {return __ok_;} +}; + +template +basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is, + bool __noskipws) + : __ok_(false) +{ + if (__is.good()) + { + if (__is.tie()) + __is.tie()->flush(); + if (!__noskipws && (__is.flags() & ios_base::skipws)) + { + typedef istreambuf_iterator<_CharT, _Traits> _I; + const ctype<_CharT>& __ct = use_facet >(__is.getloc()); + _I __i(__is); + _I __eof; + for (; __i != __eof; ++__i) + if (!__ct.is(__ct.space, *__i)) + break; + if (__i == __eof) + __is.setstate(ios_base::failbit | ios_base::eofbit); + } + __ok_ = __is.good(); + } + else + __is.setstate(ios_base::failbit); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>::basic_istream(basic_streambuf* __sb) + : __gc_(0) +{ + this->init(__sb); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) + : __gc_(__rhs.__gc_) +{ + __rhs.__gc_ = 0; + this->move(__rhs); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) +{ + swap(__rhs); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +basic_istream<_CharT, _Traits>::~basic_istream() +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_istream<_CharT, _Traits>::swap(basic_istream& __rhs) +{ + _VSTD::swap(__gc_, __rhs.__gc_); + basic_ios::swap(__rhs); +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(long& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(long long& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(float& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(double& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(long double& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(bool& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(void*& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(short& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + long __temp; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __temp); + if (__temp < numeric_limits::min()) + { + __err |= ios_base::failbit; + __n = numeric_limits::min(); + } + else if (__temp > numeric_limits::max()) + { + __err |= ios_base::failbit; + __n = numeric_limits::max(); + } + else + __n = static_cast(__temp); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(int& __n) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this); + if (__s) + { + typedef istreambuf_iterator _I; + typedef num_get _F; + ios_base::iostate __err = ios_base::goodbit; + long __temp; + use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __temp); + if (__temp < numeric_limits::min()) + { + __err |= ios_base::failbit; + __n = numeric_limits::min(); + } + else if (__temp > numeric_limits::max()) + { + __err |= ios_base::failbit; + __n = numeric_limits::max(); + } + else + __n = static_cast(__temp); + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(basic_istream& (*__pf)(basic_istream&)) +{ + return __pf(*this); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(basic_ios& + (*__pf)(basic_ios&)) +{ + __pf(*this); + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(ios_base& (*__pf)(ios_base&)) +{ + __pf(*this); + return *this; +} + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) + { + streamsize __n = __is.width(); + if (__n <= 0) + __n = numeric_limits::max() / sizeof(_CharT) - 1; + streamsize __c = 0; + const ctype<_CharT>& __ct = use_facet >(__is.getloc()); + ios_base::iostate __err = ios_base::goodbit; + while (__c < __n-1) + { + typename _Traits::int_type __i = __is.rdbuf()->sgetc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + { + __err |= ios_base::eofbit; + break; + } + _CharT __ch = _Traits::to_char_type(__i); + if (__ct.is(__ct.space, __ch)) + break; + *__s++ = __ch; + ++__c; + __is.rdbuf()->sbumpc(); + } + *__s = _CharT(); + __is.width(0); + if (__c == 0) + __err |= ios_base::failbit; + __is.setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __is.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __is; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream& +operator>>(basic_istream& __is, unsigned char* __s) +{ + return __is >> (char*)__s; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream& +operator>>(basic_istream& __is, signed char* __s) +{ + return __is >> (char*)__s; +} + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) + { + typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + __is.setstate(ios_base::eofbit | ios_base::failbit); + else + __c = _Traits::to_char_type(__i); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __is.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __is; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream& +operator>>(basic_istream& __is, unsigned char& __c) +{ + return __is >> (char&)__c; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream& +operator>>(basic_istream& __is, signed char& __c) +{ + return __is >> (char&)__c; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(basic_streambuf* __sb) +{ + __gc_ = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this, true); + if (__s) + { + if (__sb) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + ios_base::iostate __err = ios_base::goodbit; + while (true) + { + typename traits_type::int_type __i = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__i, _Traits::eof())) + { + __err |= ios_base::eofbit; + break; + } + if (traits_type::eq_int_type( + __sb->sputc(traits_type::to_char_type(__i)), + traits_type::eof())) + break; + ++__gc_; + this->rdbuf()->sbumpc(); + } + if (__gc_ == 0) + __err |= ios_base::failbit; + this->setstate(__err); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + if (__gc_ == 0) + this->__set_failbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + } + else + this->setstate(ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +typename basic_istream<_CharT, _Traits>::int_type +basic_istream<_CharT, _Traits>::get() +{ + __gc_ = 0; + int_type __r = traits_type::eof(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __s(*this, true); + if (__s) + { + __r = this->rdbuf()->sbumpc(); + if (traits_type::eq_int_type(__r, traits_type::eof())) + this->setstate(ios_base::failbit | ios_base::eofbit); + else + __gc_ = 1; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::get(char_type& __c) +{ + int_type __ch = get(); + if (__ch != traits_type::eof()) + __c = traits_type::to_char_type(__ch); + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) +{ + __gc_ = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + { + if (__n > 0) + { + ios_base::iostate __err = ios_base::goodbit; + while (__gc_ < __n-1) + { + int_type __i = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + __err |= ios_base::eofbit; + break; + } + char_type __ch = traits_type::to_char_type(__i); + if (traits_type::eq(__ch, __dlm)) + break; + *__s++ = __ch; + ++__gc_; + this->rdbuf()->sbumpc(); + } + *__s = char_type(); + if (__gc_ == 0) + __err |= ios_base::failbit; + this->setstate(__err); + } + else + this->setstate(ios_base::failbit); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n) +{ + return get(__s, __n, this->widen('\n')); +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::get(basic_streambuf& __sb, + char_type __dlm) +{ + __gc_ = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + { + ios_base::iostate __err = ios_base::goodbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + while (true) + { + typename traits_type::int_type __i = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + __err |= ios_base::eofbit; + break; + } + char_type __ch = traits_type::to_char_type(__i); + if (traits_type::eq(__ch, __dlm)) + break; + if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof())) + break; + ++__gc_; + this->rdbuf()->sbumpc(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + } +#endif // _LIBCPP_NO_EXCEPTIONS + if (__gc_ == 0) + __err |= ios_base::failbit; + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::get(basic_streambuf& __sb) +{ + return get(__sb, this->widen('\n')); +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) +{ + __gc_ = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + { + ios_base::iostate __err = ios_base::goodbit; + while (true) + { + typename traits_type::int_type __i = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + __err |= ios_base::eofbit; + break; + } + char_type __ch = traits_type::to_char_type(__i); + if (traits_type::eq(__ch, __dlm)) + { + this->rdbuf()->sbumpc(); + ++__gc_; + break; + } + if (__gc_ >= __n-1) + { + __err |= ios_base::failbit; + break; + } + *__s++ = __ch; + this->rdbuf()->sbumpc(); + ++__gc_; + } + if (__n > 0) + *__s = char_type(); + if (__gc_ == 0) + __err |= ios_base::failbit; + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n) +{ + return getline(__s, __n, this->widen('\n')); +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) +{ + __gc_ = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + { + ios_base::iostate __err = ios_base::goodbit; + if (__n == numeric_limits::max()) + { + while (true) + { + typename traits_type::int_type __i = this->rdbuf()->sbumpc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + __err |= ios_base::eofbit; + break; + } + ++__gc_; + char_type __ch = traits_type::to_char_type(__i); + if (traits_type::eq(__ch, __dlm)) + break; + } + } + else + { + while (__gc_ < __n) + { + typename traits_type::int_type __i = this->rdbuf()->sbumpc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + __err |= ios_base::eofbit; + break; + } + ++__gc_; + char_type __ch = traits_type::to_char_type(__i); + if (traits_type::eq(__ch, __dlm)) + break; + } + } + this->setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +typename basic_istream<_CharT, _Traits>::int_type +basic_istream<_CharT, _Traits>::peek() +{ + __gc_ = 0; + int_type __r = traits_type::eof(); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + __r = this->rdbuf()->sgetc(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __r; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) +{ + __gc_ = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + { + ios_base::iostate __err = ios_base::goodbit; + for (; __gc_ < __n; ++__gc_) + { + typename traits_type::int_type __i = this->rdbuf()->sbumpc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) + { + this->setstate(ios_base::failbit | ios_base::eofbit); + break; + } + *__s++ = traits_type::to_char_type(__i); + } + } + else + this->setstate(ios_base::failbit); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +streamsize +basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n) +{ + streamsize __c = this->rdbuf()->in_avail(); + switch (__c) + { + case -1: + this->setstate(ios_base::eofbit); + break; + case 0: + break; + default: + read(__s, _VSTD::min(__c, __n)); + break; + } + return __gc_; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::putback(char_type __c) +{ + __gc_ = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + { + if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof()) + this->setstate(ios_base::badbit); + } + else + this->setstate(ios_base::failbit); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::unget() +{ + __gc_ = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + { + if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof()) + this->setstate(ios_base::badbit); + } + else + this->setstate(ios_base::failbit); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +int +basic_istream<_CharT, _Traits>::sync() +{ + int __r = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + { + if (this->rdbuf() == 0) + return -1; + if (this->rdbuf()->pubsync() == -1) + { + this->setstate(ios_base::badbit); + return -1; + } + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __r; +} + +template +typename basic_istream<_CharT, _Traits>::pos_type +basic_istream<_CharT, _Traits>::tellg() +{ + pos_type __r(-1); +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __r; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::seekg(pos_type __pos) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1)) + this->setstate(ios_base::failbit); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + sentry __sen(*this, true); + if (__sen) + this->rdbuf()->pubseekoff(__off, __dir, ios_base::in); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return *this; +} + +template +basic_istream<_CharT, _Traits>& +ws(basic_istream<_CharT, _Traits>& __is) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); + if (__sen) + { + const ctype<_CharT>& __ct = use_facet >(__is.getloc()); + while (true) + { + typename _Traits::int_type __i = __is.rdbuf()->sgetc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + { + __is.setstate(ios_base::eofbit); + break; + } + if (!__ct.is(__ct.space, _Traits::to_char_type(__i))) + break; + __is.rdbuf()->sbumpc(); + } + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __is.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __is; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x) +{ + __is >> __x; + return __is; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +class _LIBCPP_VISIBLE basic_iostream + : public basic_istream<_CharT, _Traits>, + public basic_ostream<_CharT, _Traits> +{ +public: + // types: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + // constructor/destructor + explicit basic_iostream(basic_streambuf* __sb); + virtual ~basic_iostream(); +protected: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + basic_iostream(basic_iostream&& __rhs); +#endif + + // assign/swap +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + basic_iostream& operator=(basic_iostream&& __rhs); +#endif + void swap(basic_iostream& __rhs); +public: +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf* __sb) + : basic_istream<_CharT, _Traits>(__sb) +{ +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs) + : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_iostream<_CharT, _Traits>& +basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) +{ + swap(__rhs); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +basic_iostream<_CharT, _Traits>::~basic_iostream() +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +basic_iostream<_CharT, _Traits>::swap(basic_iostream& __rhs) +{ + basic_istream::swap(__rhs); +} + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + basic_string<_CharT, _Traits, _Allocator>& __str) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) + { + __str.clear(); + streamsize __n = __is.width(); + if (__n <= 0) + __n = __str.max_size(); + if (__n <= 0) + __n = numeric_limits::max(); + streamsize __c = 0; + const ctype<_CharT>& __ct = use_facet >(__is.getloc()); + ios_base::iostate __err = ios_base::goodbit; + while (__c < __n) + { + typename _Traits::int_type __i = __is.rdbuf()->sgetc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + { + __err |= ios_base::eofbit; + break; + } + _CharT __ch = _Traits::to_char_type(__i); + if (__ct.is(__ct.space, __ch)) + break; + __str.push_back(__ch); + ++__c; + __is.rdbuf()->sbumpc(); + } + __is.width(0); + if (__c == 0) + __err |= ios_base::failbit; + __is.setstate(__err); + } + else + __is.setstate(ios_base::failbit); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __is.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __is; +} + +template +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>& __is, + basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); + if (__sen) + { + __str.clear(); + ios_base::iostate __err = ios_base::goodbit; + streamsize __extr = 0; + while (true) + { + typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + { + __err |= ios_base::eofbit; + break; + } + ++__extr; + _CharT __ch = _Traits::to_char_type(__i); + if (_Traits::eq(__ch, __dlm)) + break; + __str.push_back(__ch); + if (__str.size() == __str.max_size()) + { + __err |= ios_base::failbit; + break; + } + } + if (__extr == 0) + __err |= ios_base::failbit; + __is.setstate(__err); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __is.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __is; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>& __is, + basic_string<_CharT, _Traits, _Allocator>& __str) +{ + return getline(__is, __str, __is.widen('\n')); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>&& __is, + basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) +{ + return getline(__is, __str, __dlm); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +getline(basic_istream<_CharT, _Traits>&& __is, + basic_string<_CharT, _Traits, _Allocator>& __str) +{ + return getline(__is, __str, __is.widen('\n')); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) + { + basic_string<_CharT, _Traits> __str; + const ctype<_CharT>& __ct = use_facet >(__is.getloc()); + streamsize __c = 0; + ios_base::iostate __err = ios_base::goodbit; + _CharT __zero = __ct.widen('0'); + _CharT __one = __ct.widen('1'); + while (__c < _Size) + { + typename _Traits::int_type __i = __is.rdbuf()->sgetc(); + if (_Traits::eq_int_type(__i, _Traits::eof())) + { + __err |= ios_base::eofbit; + break; + } + _CharT __ch = _Traits::to_char_type(__i); + if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one)) + break; + __str.push_back(__ch); + ++__c; + __is.rdbuf()->sbumpc(); + } + __x = bitset<_Size>(__str); + if (__c == 0) + __err |= ios_base::failbit; + __is.setstate(__err); + } + else + __is.setstate(ios_base::failbit); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __is.__set_badbit_and_consider_rethrow(); + } +#endif // _LIBCPP_NO_EXCEPTIONS + return __is; +} + +extern template class basic_istream; +extern template class basic_istream; +extern template class basic_iostream; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ISTREAM diff --git a/contrib/libc++/include/iterator b/contrib/libc++/include/iterator new file mode 100644 index 000000000000..13c2c341e238 --- /dev/null +++ b/contrib/libc++/include/iterator @@ -0,0 +1,1804 @@ +// -*- C++ -*- +//===-------------------------- iterator ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ITERATOR +#define _LIBCPP_ITERATOR + +/* + iterator synopsis + +namespace std +{ + +template +struct iterator_traits +{ + typedef typename Iterator::difference_type difference_type; + typedef typename Iterator::value_type value_type; + typedef typename Iterator::pointer pointer; + typedef typename Iterator::reference reference; + typedef typename Iterator::iterator_category iterator_category; +}; + +template +struct iterator_traits +{ + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef random_access_iterator_tag iterator_category; +}; + +template +struct iterator_traits +{ + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef const T* pointer; + typedef const T& reference; + typedef random_access_iterator_tag iterator_category; +}; + +template +struct iterator +{ + typedef T value_type; + typedef Distance difference_type; + typedef Pointer pointer; + typedef Reference reference; + typedef Category iterator_category; +}; + +struct input_iterator_tag {}; +struct output_iterator_tag {}; +struct forward_iterator_tag : public input_iterator_tag {}; +struct bidirectional_iterator_tag : public forward_iterator_tag {}; +struct random_access_iterator_tag : public bidirectional_iterator_tag {}; + +// extension: second argument not conforming to C++03 +template +void advance(InputIterator& i, + typename iterator_traits::difference_type n); + +template +typename iterator_traits::difference_type +distance(InputIterator first, InputIterator last); + +template +class reverse_iterator + : public iterator::iterator_category, + typename iterator_traits::value_type, + typename iterator_traits::difference_type, + typename iterator_traits::pointer, + typename iterator_traits::reference> +{ +protected: + Iterator current; +public: + typedef Iterator iterator_type; + typedef typename iterator_traits::difference_type difference_type; + typedef typename iterator_traits::reference reference; + typedef typename iterator_traits::pointer pointer; + + reverse_iterator(); + explicit reverse_iterator(Iterator x); + template reverse_iterator(const reverse_iterator& u); + Iterator base() const; + reference operator*() const; + pointer operator->() const; + reverse_iterator& operator++(); + reverse_iterator operator++(int); + reverse_iterator& operator--(); + reverse_iterator operator--(int); + reverse_iterator operator+ (difference_type n) const; + reverse_iterator& operator+=(difference_type n); + reverse_iterator operator- (difference_type n) const; + reverse_iterator& operator-=(difference_type n); + reference operator[](difference_type n) const; +}; + +template +bool +operator==(const reverse_iterator& x, const reverse_iterator& y); + +template +bool +operator<(const reverse_iterator& x, const reverse_iterator& y); + +template +bool +operator!=(const reverse_iterator& x, const reverse_iterator& y); + +template +bool +operator>(const reverse_iterator& x, const reverse_iterator& y); + +template +bool +operator>=(const reverse_iterator& x, const reverse_iterator& y); + +template +bool +operator<=(const reverse_iterator& x, const reverse_iterator& y); + +template +typename reverse_iterator::difference_type +operator-(const reverse_iterator& x, const reverse_iterator& y); + +template +reverse_iterator +operator+(typename reverse_iterator::difference_type n, const reverse_iterator& x); + +template +class back_insert_iterator +{ +protected: + Container* container; +public: + typedef Container container_type; + typedef void value_type; + typedef void difference_type; + typedef back_insert_iterator& reference; + typedef void pointer; + + explicit back_insert_iterator(Container& x); + back_insert_iterator& operator=(const typename Container::value_type& value); + back_insert_iterator& operator*(); + back_insert_iterator& operator++(); + back_insert_iterator operator++(int); +}; + +template back_insert_iterator back_inserter(Container& x); + +template +class front_insert_iterator +{ +protected: + Container* container; +public: + typedef Container container_type; + typedef void value_type; + typedef void difference_type; + typedef front_insert_iterator& reference; + typedef void pointer; + + explicit front_insert_iterator(Container& x); + front_insert_iterator& operator=(const typename Container::value_type& value); + front_insert_iterator& operator*(); + front_insert_iterator& operator++(); + front_insert_iterator operator++(int); +}; + +template front_insert_iterator front_inserter(Container& x); + +template +class insert_iterator +{ +protected: + Container* container; + typename Container::iterator iter; +public: + typedef Container container_type; + typedef void value_type; + typedef void difference_type; + typedef insert_iterator& reference; + typedef void pointer; + + insert_iterator(Container& x, typename Container::iterator i); + insert_iterator& operator=(const typename Container::value_type& value); + insert_iterator& operator*(); + insert_iterator& operator++(); + insert_iterator& operator++(int); +}; + +template +insert_iterator inserter(Container& x, Iterator i); + +template , class Distance = ptrdiff_t> +class istream_iterator + : public iterator +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef basic_istream istream_type; + + istream_iterator(); + istream_iterator(istream_type& s); + istream_iterator(const istream_iterator& x); + ~istream_iterator(); + + const T& operator*() const; + const T* operator->() const; + istream_iterator& operator++(); + istream_iterator operator++(int); +}; + +template +bool operator==(const istream_iterator& x, + const istream_iterator& y); +template +bool operator!=(const istream_iterator& x, + const istream_iterator& y); + +template > +class ostream_iterator + : public iterator +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef basic_ostream ostream_type; + + ostream_iterator(ostream_type& s); + ostream_iterator(ostream_type& s, const charT* delimiter); + ostream_iterator(const ostream_iterator& x); + ~ostream_iterator(); + ostream_iterator& operator=(const T& value); + + ostream_iterator& operator*(); + ostream_iterator& operator++(); + ostream_iterator& operator++(int); +}; + +template > +class istreambuf_iterator + : public iterator +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits::int_type int_type; + typedef basic_streambuf streambuf_type; + typedef basic_istream istream_type; + + istreambuf_iterator() throw(); + istreambuf_iterator(istream_type& s) throw(); + istreambuf_iterator(streambuf_type* s) throw(); + istreambuf_iterator(a-private-type) throw(); + + charT operator*() const; + pointer operator->() const; + istreambuf_iterator& operator++(); + a-private-type operator++(int); + + bool equal(const istreambuf_iterator& b) const; +}; + +template +bool operator==(const istreambuf_iterator& a, + const istreambuf_iterator& b); +template +bool operator!=(const istreambuf_iterator& a, + const istreambuf_iterator& b); + +template > +class ostreambuf_iterator + : public iterator +{ +public: + typedef charT char_type; + typedef traits traits_type; + typedef basic_streambuf streambuf_type; + typedef basic_ostream ostream_type; + + ostreambuf_iterator(ostream_type& s) throw(); + ostreambuf_iterator(streambuf_type* s) throw(); + ostreambuf_iterator& operator=(charT c); + ostreambuf_iterator& operator*(); + ostreambuf_iterator& operator++(); + ostreambuf_iterator& operator++(int); + bool failed() const throw(); +}; + +template auto begin(C& c) -> decltype(c.begin()); +template auto begin(const C& c) -> decltype(c.begin()); +template auto end(C& c) -> decltype(c.end()); +template auto end(const C& c) -> decltype(c.end()); +template T* begin(T (&array)[N]); +template T* end(T (&array)[N]); + +} // std + +*/ + +#include <__config> +#include +#include +#include +#ifdef _LIBCPP_DEBUG +#include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_VISIBLE input_iterator_tag {}; +struct _LIBCPP_VISIBLE output_iterator_tag {}; +struct _LIBCPP_VISIBLE forward_iterator_tag : public input_iterator_tag {}; +struct _LIBCPP_VISIBLE bidirectional_iterator_tag : public forward_iterator_tag {}; +struct _LIBCPP_VISIBLE random_access_iterator_tag : public bidirectional_iterator_tag {}; + +template +struct __has_iterator_category +{ +private: + struct __two {char _; char __;}; + template static __two __test(...); + template static char __test(typename _Up::iterator_category* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template struct ____iterator_traits {}; + +template +struct ____iterator_traits<_Iter, true> +{ + typedef typename _Iter::difference_type difference_type; + typedef typename _Iter::value_type value_type; + typedef typename _Iter::pointer pointer; + typedef typename _Iter::reference reference; + typedef typename _Iter::iterator_category iterator_category; +}; + +template struct __iterator_traits {}; + +template +struct __iterator_traits<_Iter, true> + : ____iterator_traits + < + _Iter, + is_convertible::value || + is_convertible::value + > +{}; + +// iterator_traits will only have the nested types if Iterator::iterator_category +// exists. Else iterator_traits will be an empty class. This is a +// conforming extension which allows some programs to compile and behave as +// the client expects instead of failing at compile time. + +template +struct _LIBCPP_VISIBLE iterator_traits + : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {}; + +template +struct _LIBCPP_VISIBLE iterator_traits<_Tp*> +{ + typedef ptrdiff_t difference_type; + typedef typename remove_const<_Tp>::type value_type; + typedef _Tp* pointer; + typedef _Tp& reference; + typedef random_access_iterator_tag iterator_category; +}; + +template >::value> +struct __has_iterator_category_convertible_to + : public integral_constant::iterator_category, _Up>::value> +{}; + +template +struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {}; + +template +struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {}; + +template +struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {}; + +template +struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {}; + +template +struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {}; + +template +struct _LIBCPP_VISIBLE iterator +{ + typedef _Tp value_type; + typedef _Distance difference_type; + typedef _Pointer pointer; + typedef _Reference reference; + typedef _Category iterator_category; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +void __advance(_InputIter& __i, + typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) +{ + for (; __n > 0; --__n) + ++__i; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void __advance(_BiDirIter& __i, + typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) +{ + if (__n >= 0) + for (; __n > 0; --__n) + ++__i; + else + for (; __n < 0; ++__n) + --__i; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void __advance(_RandIter& __i, + typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) +{ + __i += __n; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void advance(_InputIter& __i, + typename iterator_traits<_InputIter>::difference_type __n) +{ + __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename iterator_traits<_InputIter>::difference_type +__distance(_InputIter __first, _InputIter __last, input_iterator_tag) +{ + typename iterator_traits<_InputIter>::difference_type __r(0); + for (; __first != __last; ++__first) + ++__r; + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename iterator_traits<_RandIter>::difference_type +__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) +{ + return __last - __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename iterator_traits<_InputIter>::difference_type +distance(_InputIter __first, _InputIter __last) +{ + return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIter +next(_ForwardIter __x, + typename iterator_traits<_ForwardIter>::difference_type __n = 1, + typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0) +{ + _VSTD::advance(__x, __n); + return __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_BidiretionalIter +prev(_BidiretionalIter __x, + typename iterator_traits<_BidiretionalIter>::difference_type __n = 1, + typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0) +{ + _VSTD::advance(__x, -__n); + return __x; +} + +template +class _LIBCPP_VISIBLE reverse_iterator + : public iterator::iterator_category, + typename iterator_traits<_Iter>::value_type, + typename iterator_traits<_Iter>::difference_type, + typename iterator_traits<_Iter>::pointer, + typename iterator_traits<_Iter>::reference> +{ +private: + mutable _Iter __t; +protected: + _Iter current; +public: + typedef _Iter iterator_type; + typedef typename iterator_traits<_Iter>::difference_type difference_type; + typedef typename iterator_traits<_Iter>::reference reference; + typedef typename iterator_traits<_Iter>::pointer pointer; + + _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {} + _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} + template _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u) + : __t(__u.base()), current(__u.base()) {} + _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;} + _LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &(operator*());} + _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;} + _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int) + {reverse_iterator __tmp(*this); --current; return __tmp;} + _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;} + _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int) + {reverse_iterator __tmp(*this); ++current; return __tmp;} + _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const + {return reverse_iterator(current - __n);} + _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n) + {current -= __n; return *this;} + _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const + {return reverse_iterator(current + __n);} + _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n) + {current += __n; return *this;} + _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const + {return current[-__n-1];} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() == __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() > __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() != __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() < __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() <= __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __x.base() >= __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename reverse_iterator<_Iter1>::difference_type +operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +{ + return __y.base() - __x.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +reverse_iterator<_Iter> +operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) +{ + return reverse_iterator<_Iter>(__x.base() - __n); +} + +template +class _LIBCPP_VISIBLE back_insert_iterator + : public iterator&> +{ +protected: + _Container* container; +public: + typedef _Container container_type; + + _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(&__x) {} + _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_) + {container->push_back(__value_); return *this;} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_) + {container->push_back(_VSTD::move(__value_)); return *this;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +back_insert_iterator<_Container> +back_inserter(_Container& __x) +{ + return back_insert_iterator<_Container>(__x); +} + +template +class _LIBCPP_VISIBLE front_insert_iterator + : public iterator&> +{ +protected: + _Container* container; +public: + typedef _Container container_type; + + _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(&__x) {} + _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_) + {container->push_front(__value_); return *this;} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_) + {container->push_front(_VSTD::move(__value_)); return *this;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +front_insert_iterator<_Container> +front_inserter(_Container& __x) +{ + return front_insert_iterator<_Container>(__x); +} + +template +class _LIBCPP_VISIBLE insert_iterator + : public iterator&> +{ +protected: + _Container* container; + typename _Container::iterator iter; +public: + typedef _Container container_type; + + _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i) + : container(&__x), iter(__i) {} + _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_) + {iter = container->insert(iter, __value_); ++iter; return *this;} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_) + {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +insert_iterator<_Container> +inserter(_Container& __x, typename _Container::iterator __i) +{ + return insert_iterator<_Container>(__x, __i); +} + +template , class _Distance = ptrdiff_t> +class _LIBCPP_VISIBLE istream_iterator + : public iterator +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_istream<_CharT,_Traits> istream_type; +private: + istream_type* __in_stream_; + _Tp __value_; +public: + _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {} + _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s) + { + if (!(*__in_stream_ >> __value_)) + __in_stream_ = 0; + } + + _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} + _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());} + _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() + { + if (!(*__in_stream_ >> __value_)) + __in_stream_ = 0; + return *this; + } + _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) + {istream_iterator __t(*this); ++(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const istream_iterator& __x, const istream_iterator& __y) + {return __x.__in_stream_ == __y.__in_stream_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const istream_iterator& __x, const istream_iterator& __y) + {return !(__x == __y);} +}; + +template > +class _LIBCPP_VISIBLE ostream_iterator + : public iterator +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_ostream<_CharT,_Traits> ostream_type; +private: + ostream_type* __out_stream_; + const char_type* __delim_; +public: + _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) + : __out_stream_(&__s), __delim_(0) {} + _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) + : __out_stream_(&__s), __delim_(__delimiter) {} + _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) + { + *__out_stream_ << __value_; + if (__delim_) + *__out_stream_ << __delim_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} +}; + +template +class _LIBCPP_VISIBLE istreambuf_iterator + : public iterator +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename _Traits::int_type int_type; + typedef basic_streambuf<_CharT,_Traits> streambuf_type; + typedef basic_istream<_CharT,_Traits> istream_type; +private: + streambuf_type* __sbuf_; + + class __proxy + { + char_type __keep_; + streambuf_type* __sbuf_; + _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) + : __keep_(__c), __sbuf_(__s) {} + friend class istreambuf_iterator; + public: + _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;} + }; + + _LIBCPP_INLINE_VISIBILITY + void __test_for_eof() + { + if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) + __sbuf_ = 0; + } +public: + _LIBCPP_INLINE_VISIBILITY istreambuf_iterator() throw() : __sbuf_(0) {} + _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) throw() + : __sbuf_(__s.rdbuf()) {__test_for_eof();} + _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) throw() + : __sbuf_(__s) {__test_for_eof();} + _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) throw() + : __sbuf_(__p.__sbuf_) {} + + _LIBCPP_INLINE_VISIBILITY _CharT operator*() const {return __sbuf_->sgetc();} + _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;} + _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() + { + if (traits_type::eq_int_type(__sbuf_->snextc(), traits_type::eof())) + __sbuf_ = 0; + return *this; + } + _LIBCPP_INLINE_VISIBILITY __proxy operator++(int) + { + char_type __c = __sbuf_->sgetc(); + ++(*this); + return __proxy(__c, __sbuf_); + } + + _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const + {return (__sbuf_ == 0) == (__b.__sbuf_ == 0);} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, + const istreambuf_iterator<_CharT,_Traits>& __b) + {return __a.equal(__b);} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, + const istreambuf_iterator<_CharT,_Traits>& __b) + {return !__a.equal(__b);} + +template +class _LIBCPP_VISIBLE ostreambuf_iterator + : public iterator +{ +public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_streambuf<_CharT,_Traits> streambuf_type; + typedef basic_ostream<_CharT,_Traits> ostream_type; +private: + streambuf_type* __sbuf_; +public: + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) throw() + : __sbuf_(__s.rdbuf()) {} + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) throw() + : __sbuf_(__s) {} + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) + { + if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) + __sbuf_ = 0; + return *this; + } + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} + _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} + _LIBCPP_INLINE_VISIBILITY bool failed() const throw() {return __sbuf_ == 0;} +}; + +template +class _LIBCPP_VISIBLE move_iterator +{ +private: + _Iter __i; +public: + typedef _Iter iterator_type; + typedef typename iterator_traits::iterator_category iterator_category; + typedef typename iterator_traits::value_type value_type; + typedef typename iterator_traits::difference_type difference_type; + typedef typename iterator_traits::pointer pointer; +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + typedef value_type&& reference; +#else + typedef typename iterator_traits::reference reference; +#endif + + _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {} + _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {} + template _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u) + : __i(__u.base()) {} + _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;} + _LIBCPP_INLINE_VISIBILITY reference operator*() const { + return static_cast(*__i); + } + _LIBCPP_INLINE_VISIBILITY pointer operator->() const { + typename iterator_traits::reference __ref = *__i; + return &__ref; + } + _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;} + _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int) + {move_iterator __tmp(*this); ++__i; return __tmp;} + _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;} + _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int) + {move_iterator __tmp(*this); --__i; return __tmp;} + _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const + {return move_iterator(__i + __n);} + _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n) + {__i += __n; return *this;} + _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const + {return move_iterator(__i - __n);} + _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n) + {__i -= __n; return *this;} + _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const + { + return static_cast(__i[__n]); + } +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() == __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() < __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() != __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() > __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() >= __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() <= __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename move_iterator<_Iter1>::difference_type +operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +{ + return __x.base() - __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +move_iterator<_Iter> +operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) +{ + return move_iterator<_Iter>(__x.base() + __n); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +move_iterator<_Iter> +make_move_iterator(const _Iter& __i) +{ + return move_iterator<_Iter>(__i); +} + +// __wrap_iter + +template class __wrap_iter; + +template +bool +operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +bool +operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +bool +operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +bool +operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +bool +operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +bool +operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +typename __wrap_iter<_Iter1>::difference_type +operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + +template +__wrap_iter<_Iter> +operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; + +template _O copy(_I, _I, _O); +template _B2 copy_backward(_B1, _B1, _B2); +template _O move(_I, _I, _O); +template _B2 move_backward(_B1, _B1, _B2); + +template +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + _Tp* +>::type +__unwrap_iter(__wrap_iter<_Tp*>); + +template +class __wrap_iter +{ +public: + typedef _Iter iterator_type; + typedef typename iterator_traits::iterator_category iterator_category; + typedef typename iterator_traits::value_type value_type; + typedef typename iterator_traits::difference_type difference_type; + typedef typename iterator_traits::pointer pointer; + typedef typename iterator_traits::reference reference; +private: + iterator_type __i; +public: + _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_i(this); +#endif + } + template _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u, + typename enable_if::value>::type* = 0) _NOEXCEPT + : __i(__u.base()) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__iterator_copy(this, &__u); +#endif + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __wrap_iter(const __wrap_iter& __x) + : __i(__x.base()) + { + __get_db()->__iterator_copy(this, &__x); + } + _LIBCPP_INLINE_VISIBILITY + __wrap_iter& operator=(const __wrap_iter& __x) + { + if (this != &__x) + { + __get_db()->__iterator_copy(this, &__x); + __i = __x.__i; + } + return *this; + } + _LIBCPP_INLINE_VISIBILITY + ~__wrap_iter() + { + __get_db()->__erase_i(this); + } +#endif + _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable iterator"); +#endif + return *__i; + } + _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return &(operator*());} + _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable iterator"); +#endif + ++__i; + return *this; + } + _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT + {__wrap_iter __tmp(*this); ++(*this); return __tmp;} + _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), + "Attempted to decrement non-decrementable iterator"); +#endif + --__i; + return *this; + } + _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT + {__wrap_iter __tmp(*this); --(*this); return __tmp;} + _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT + {__wrap_iter __w(*this); __w += __n; return __w;} + _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), + "Attempted to add/subtract iterator outside of valid range"); +#endif + __i += __n; + return *this; + } + _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT + {return *this + (-__n);} + _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT + {*this += -__n; return *this;} + _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), + "Attempted to subscript iterator outside of valid range"); +#endif + return __i[__n]; + } + + _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;} + +private: + _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x) + { + __get_db()->__insert_ic(this, __p); + } +#endif + + template friend class __wrap_iter; + template friend class basic_string; + template friend class vector; + + template + friend + bool + operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + friend + bool + operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + friend + bool + operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + friend + bool + operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + friend + bool + operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + friend + bool + operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + friend + typename __wrap_iter<_Iter1>::difference_type + operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + + template + friend + __wrap_iter<_Iter1> + operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; + + template friend _O copy(_I, _I, _O); + template friend _B2 copy_backward(_B1, _B1, _B2); + template friend _O move(_I, _I, _O); + template friend _B2 move_backward(_B1, _B1, _B2); + + template + friend + typename enable_if + < + is_trivially_copy_assignable<_Tp>::value, + _Tp* + >::type + __unwrap_iter(__wrap_iter<_Tp*>); +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), + "Attempted to compare incomparable iterators"); +#endif + return __x.base() == __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), + "Attempted to compare incomparable iterators"); +#endif + return __x.base() < __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return !(__x == __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return __y < __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return !(__x < __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ + return !(__y < __x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __wrap_iter<_Iter1>::difference_type +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), + "Attempted to subtract incompatible iterators"); +#endif + return __x.base() - __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__wrap_iter<_Iter> +operator+(typename __wrap_iter<_Iter>::difference_type __n, + __wrap_iter<_Iter> __x) _NOEXCEPT +{ + __x += __n; + return __x; +} + +#ifdef _LIBCPP_DEBUG + +// __debug_iter + +template class __debug_iter; + +template +bool +operator==(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&); + +template +bool +operator<(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&); + +template +bool +operator!=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&); + +template +bool +operator>(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&); + +template +bool +operator>=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&); + +template +bool +operator<=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&); + +template +typename __debug_iter<_Container, _Iter1>::difference_type +operator-(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&); + +template +__debug_iter<_Container, _Iter> +operator+(typename __debug_iter<_Container, _Iter>::difference_type, const __debug_iter<_Container, _Iter>&); + +template +class __debug_iter +{ +public: + typedef _Iter iterator_type; + typedef _Container __container_type; + typedef typename iterator_traits::iterator_category iterator_category; + typedef typename iterator_traits::value_type value_type; + typedef typename iterator_traits::difference_type difference_type; + typedef typename iterator_traits::pointer pointer; + typedef typename iterator_traits::reference reference; +private: + iterator_type __i; + __debug_iter* __next; + __container_type* __cont; + +public: + _LIBCPP_INLINE_VISIBILITY __debug_iter() : __next(0), __cont(0) {} + _LIBCPP_INLINE_VISIBILITY __debug_iter(const __debug_iter& __x) + : __i(__x.base()), __next(0), __cont(0) {__set_owner(__x.__cont);} + __debug_iter& operator=(const __debug_iter& __x); + template _LIBCPP_INLINE_VISIBILITY __debug_iter(const __debug_iter<_Container, _Up>& __u, + typename enable_if::value>::type* = 0) + : __i(__u.base()), __next(0), __cont(0) {__set_owner(__u.__cont);} + _LIBCPP_INLINE_VISIBILITY ~__debug_iter() {__remove_owner();} + _LIBCPP_INLINE_VISIBILITY reference operator*() const {assert(__is_deref()); return *__i;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &(operator*());} + _LIBCPP_INLINE_VISIBILITY __debug_iter& operator++() {assert(__can_increment()); ++__i; return *this;} + _LIBCPP_INLINE_VISIBILITY __debug_iter operator++(int) + {__debug_iter __tmp(*this); operator++(); return __tmp;} + _LIBCPP_INLINE_VISIBILITY __debug_iter& operator--() {assert(__can_decrement()); --__i; return *this;} + _LIBCPP_INLINE_VISIBILITY __debug_iter operator--(int) + {__debug_iter __tmp(*this); operator--(); return __tmp;} + _LIBCPP_INLINE_VISIBILITY __debug_iter operator+ (difference_type __n) const + {__debug_iter __t(*this); __t += __n; return __t;} + __debug_iter& operator+=(difference_type __n); + _LIBCPP_INLINE_VISIBILITY __debug_iter operator- (difference_type __n) const + {__debug_iter __t(*this); __t -= __n; return __t;} + _LIBCPP_INLINE_VISIBILITY __debug_iter& operator-=(difference_type __n) + {*this += -__n; return *this;} + _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const + {return *(*this + __n);} + +private: + _LIBCPP_INLINE_VISIBILITY __debug_iter(const __container_type* __c, iterator_type __x) + : __i(__x), __next(0), __cont(0) {__set_owner(__c);} + _LIBCPP_INLINE_VISIBILITY iterator_type base() const {return __i;} + + void __set_owner(const __container_type* __c); + void __remove_owner(); + static void __remove_all(__container_type* __c); + static void swap(__container_type* __x, __container_type* __y); + + _LIBCPP_INLINE_VISIBILITY bool __is_deref() const + {return __is_deref(__is_random_access_iterator());} + bool __is_deref(false_type) const; + bool __is_deref(true_type) const; + _LIBCPP_INLINE_VISIBILITY bool __can_decrement() const + {return __can_decrement(integral_constant::value ? 2: + __is_random_access_iterator::value ? 1 : 0>());} + bool __can_decrement(integral_constant) const; + bool __can_decrement(integral_constant) const; + bool __can_decrement(integral_constant) const; + _LIBCPP_INLINE_VISIBILITY bool __can_increment() const + {return __can_increment(integral_constant::value ? 2: + __is_random_access_iterator::value ? 1 : 0>());} + bool __can_increment(integral_constant) const; + bool __can_increment(integral_constant) const; + bool __can_increment(integral_constant) const; + + _LIBCPP_INLINE_VISIBILITY bool __can_add(difference_type __n) const + {return __can_add(__n, is_pointer());} + bool __can_add(difference_type __n, false_type) const; + bool __can_add(difference_type __n, true_type) const; + + template friend class __debug_iter; + friend class _Container::__self; + + template + friend + bool + operator==(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&); + + template + friend + bool + operator<(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&); + + template + friend + bool + operator!=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&); + + template + friend + bool + operator>(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&); + + template + friend + bool + operator>=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&); + + template + friend + bool + operator<=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&); + + template + friend + typename __debug_iter<_Cp, _Iter1>::difference_type + operator-(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&); + + template + friend + __debug_iter<_Cp, _Iter1> + operator+(typename __debug_iter<_Cp, _Iter1>::difference_type, const __debug_iter<_Cp, _Iter1>&); +}; + +template +__debug_iter<_Container, _Iter>& +__debug_iter<_Container, _Iter>::operator=(const __debug_iter& __x) +{ + if (this != &__x) + { + __remove_owner(); + __i = __x.__i; + __set_owner(__x.__cont); + } + return *this; +} + +template +void +__debug_iter<_Container, _Iter>::__set_owner(const __container_type* __c) +{ + __cont = const_cast<__container_type*>(__c); + __debug_iter*& __head = __cont->__get_iterator_list(this); + __next = __head; + __head = this; +} + +template +void +__debug_iter<_Container, _Iter>::__remove_owner() +{ + if (__cont) + { + __debug_iter*& __head = __cont->__get_iterator_list(this); + if (__head == this) + __head = __next; + else + { + __debug_iter* __prev = __head; + for (__debug_iter* __p = __head->__next; __p != this; __p = __p->__next) + __prev = __p; + __prev->__next = __next; + } + __cont = 0; + } +} + +template +void +__debug_iter<_Container, _Iter>::__remove_all(__container_type* __c) +{ + __debug_iter*& __head = __c->__get_iterator_list((__debug_iter*)0); + __debug_iter* __p = __head; + __head = 0; + while (__p) + { + __p->__cont = 0; + __debug_iter* __n = __p->__next; + __p->__next = 0; + __p = __n; + } +} + +template +void +__debug_iter<_Container, _Iter>::swap(__container_type* __x, __container_type* __y) +{ + __debug_iter*& __head_x = __x->__get_iterator_list((__debug_iter*)0); + __debug_iter*& __head_y = __y->__get_iterator_list((__debug_iter*)0); + __debug_iter* __p = __head_x; + __head_x = __head_y; + __head_y = __p; + for (__p = __head_x; __p; __p = __p->__next) + __p->__cont = __x; + for (__p = __head_y; __p; __p = __p->__next) + __p->__cont = __y; +} + +template +bool +__debug_iter<_Container, _Iter>::__is_deref(false_type) const +{ + if (__cont == 0) + return false; + return __i != __cont->end().base(); +} + +template +bool +__debug_iter<_Container, _Iter>::__is_deref(true_type) const +{ + if (__cont == 0) + return false; + return __i < __cont->end().base(); +} + +template +bool +__debug_iter<_Container, _Iter>::__can_decrement(integral_constant) const +{ + if (__cont == 0) + return false; + return __i != __cont->begin().base(); +} + +template +bool +__debug_iter<_Container, _Iter>::__can_decrement(integral_constant) const +{ + if (__cont == 0) + return false; + iterator_type __b = __cont->begin().base(); + return __b < __i && __i <= __b + __cont->size(); +} + +template +bool +__debug_iter<_Container, _Iter>::__can_decrement(integral_constant) const +{ + if (__cont == 0) + return false; + iterator_type __b = __cont->begin().base(); + return __b < __i && __i <= __b + __cont->size(); +} + +template +bool +__debug_iter<_Container, _Iter>::__can_increment(integral_constant) const +{ + if (__cont == 0) + return false; + return __i != __cont->end().base(); +} + +template +bool +__debug_iter<_Container, _Iter>::__can_increment(integral_constant) const +{ + if (__cont == 0) + return false; + iterator_type __b = __cont->begin().base(); + return __b <= __i && __i < __b + __cont->size(); +} + +template +bool +__debug_iter<_Container, _Iter>::__can_increment(integral_constant) const +{ + if (__cont == 0) + return false; + iterator_type __b = __cont->begin().base(); + return __b <= __i && __i < __b + __cont->size(); +} + +template +bool +__debug_iter<_Container, _Iter>::__can_add(difference_type __n, false_type) const +{ + if (__cont == 0) + return false; + iterator_type __b = __cont->begin().base(); + iterator_type __j = __i + __n; + return __b <= __j && __j <= __b + __cont->size(); +} + +template +bool +__debug_iter<_Container, _Iter>::__can_add(difference_type __n, true_type) const +{ + if (__cont == 0) + return false; + iterator_type __b = __cont->begin().base(); + iterator_type __j = __i + __n; + return __b <= __j && __j <= __b + __cont->size(); +} + +template +__debug_iter<_Container, _Iter>& +__debug_iter<_Container, _Iter>::operator+=(difference_type __n) +{ + assert(__can_add(__n)); + __i += __n; + return *this; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y) +{ + assert(__x.__cont && __x.__cont == __y.__cont); + return __x.base() == __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y) +{ + return !(__x == __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y) +{ + assert(__x.__cont && __x.__cont == __y.__cont); + return __x.base() < __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y) +{ + return __y < __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y) +{ + return !(__x < __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y) +{ + return !(__y < __x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename __debug_iter<_Container, _Iter1>::difference_type +operator-(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y) +{ + assert(__x.__cont && __x.__cont == __y.__cont); + return __x.base() - __y.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__debug_iter<_Container, _Iter> +operator+(typename __debug_iter<_Container, _Iter>::difference_type __n, + const __debug_iter<_Container, _Iter>& __x) +{ + return __x + __n; +} + +#endif // _LIBCPP_DEBUG + +#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +begin(_C& __c) -> decltype(__c.begin()) +{ + return __c.begin(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +begin(const _C& __c) -> decltype(__c.begin()) +{ + return __c.begin(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +end(_C& __c) -> decltype(__c.end()) +{ + return __c.end(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +end(const _C& __c) -> decltype(__c.end()) +{ + return __c.end(); +} + +#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) + +template +inline _LIBCPP_INLINE_VISIBILITY +typename _C::iterator +begin(_C& __c) +{ + return __c.begin(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename _C::const_iterator +begin(const _C& __c) +{ + return __c.begin(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename _C::iterator +end(_C& __c) +{ + return __c.end(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename _C::const_iterator +end(const _C& __c) +{ + return __c.end(); +} + +#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) + +template +inline _LIBCPP_INLINE_VISIBILITY +_T* +begin(_T (&__array)[_N]) +{ + return __array; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_T* +end(_T (&__array)[_N]) +{ + return __array + _N; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ITERATOR diff --git a/contrib/libc++/include/limits b/contrib/libc++/include/limits new file mode 100644 index 000000000000..14b49b1385b3 --- /dev/null +++ b/contrib/libc++/include/limits @@ -0,0 +1,619 @@ +// -*- C++ -*- +//===---------------------------- limits ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LIMITS +#define _LIBCPP_LIMITS + +/* + limits synopsis + +namespace std +{ + +template +class numeric_limits +{ +public: + static const bool is_specialized = false; + static T min() noexcept; + static T max() noexcept; + static T lowest() noexcept; + + static const int digits = 0; + static const int digits10 = 0; + static const int max_digits10 = 0; + static const bool is_signed = false; + static const bool is_integer = false; + static const bool is_exact = false; + static const int radix = 0; + static T epsilon() noexcept; + static T round_error() noexcept; + + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const float_denorm_style has_denorm = denorm_absent; + static const bool has_denorm_loss = false; + static T infinity() noexcept; + static T quiet_NaN() noexcept; + static T signaling_NaN() noexcept; + static T denorm_min() noexcept; + + static const bool is_iec559 = false; + static const bool is_bounded = false; + static const bool is_modulo = false; + + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_toward_zero; +}; + +enum float_round_style +{ + round_indeterminate = -1, + round_toward_zero = 0, + round_to_nearest = 1, + round_toward_infinity = 2, + round_toward_neg_infinity = 3 +}; + +enum float_denorm_style +{ + denorm_indeterminate = -1, + denorm_absent = 0, + denorm_present = 1 +}; + +template<> class numeric_limits; + +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; + +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; + +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; + +} // std + +*/ + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include <__config> +#include + +#if defined(_MSC_VER) +#include "support/win32/limits_win32.h" +#endif // _MSC_VER + +_LIBCPP_BEGIN_NAMESPACE_STD + +enum float_round_style +{ + round_indeterminate = -1, + round_toward_zero = 0, + round_to_nearest = 1, + round_toward_infinity = 2, + round_toward_neg_infinity = 3 +}; + +enum float_denorm_style +{ + denorm_indeterminate = -1, + denorm_absent = 0, + denorm_present = 1 +}; + +template ::value> +class __libcpp_numeric_limits +{ +protected: + typedef _Tp type; + + static const bool is_specialized = false; + _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return type();} + + static const int digits = 0; + static const int digits10 = 0; + static const int max_digits10 = 0; + static const bool is_signed = false; + static const bool is_integer = false; + static const bool is_exact = false; + static const int radix = 0; + _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return type();} + + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const float_denorm_style has_denorm = denorm_absent; + static const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return type();} + _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return type();} + + static const bool is_iec559 = false; + static const bool is_bounded = false; + static const bool is_modulo = false; + + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_toward_zero; +}; + +template +struct __libcpp_compute_min +{ + static const _Tp value = _Tp(_Tp(1) << digits); +}; + +template +struct __libcpp_compute_min<_Tp, digits, false> +{ + static const _Tp value = _Tp(0); +}; + +template +class __libcpp_numeric_limits<_Tp, true> +{ +protected: + typedef _Tp type; + + static const bool is_specialized = true; + + static const bool is_signed = type(-1) < type(0); + static const int digits = static_cast(sizeof(type) * __CHAR_BIT__ - is_signed); + static const int digits10 = digits * 3 / 10; + static const int max_digits10 = 0; + static const type __min = __libcpp_compute_min::value; + static const type __max = is_signed ? type(type(~0) ^ __min) : type(~0); + _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __min;} + _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __max;} + _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return min();} + + static const bool is_integer = true; + static const bool is_exact = true; + static const int radix = 2; + _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return type(0);} + + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const float_denorm_style has_denorm = denorm_absent; + static const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return type(0);} + + static const bool is_iec559 = false; + static const bool is_bounded = true; + static const bool is_modulo = true; + +#if __i386__ || __x86_64__ + static const bool traps = true; +#else + static const bool traps = false; +#endif + static const bool tinyness_before = false; + static const float_round_style round_style = round_toward_zero; +}; + +template <> +class __libcpp_numeric_limits +{ +protected: + typedef bool type; + + static const bool is_specialized = true; + + static const bool is_signed = false; + static const int digits = 1; + static const int digits10 = 0; + static const int max_digits10 = 0; + static const type __min = false; + static const type __max = true; + _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __min;} + _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __max;} + _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return min();} + + static const bool is_integer = true; + static const bool is_exact = true; + static const int radix = 2; + _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return type(0);} + + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const float_denorm_style has_denorm = denorm_absent; + static const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return type(0);} + _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return type(0);} + + static const bool is_iec559 = false; + static const bool is_bounded = true; + static const bool is_modulo = false; + + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_toward_zero; +}; + +template <> +class __libcpp_numeric_limits +{ +protected: + typedef float type; + + static const bool is_specialized = true; + + static const bool is_signed = true; + static const int digits = __FLT_MANT_DIG__; + static const int digits10 = __FLT_DIG__; + static const int max_digits10 = 2+(digits * 30103)/100000; + _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __FLT_MIN__;} + _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __FLT_MAX__;} + _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return -max();} + + static const bool is_integer = false; + static const bool is_exact = false; + static const int radix = __FLT_RADIX__; + _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __FLT_EPSILON__;} + _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return 0.5F;} + + static const int min_exponent = __FLT_MIN_EXP__; + static const int min_exponent10 = __FLT_MIN_10_EXP__; + static const int max_exponent = __FLT_MAX_EXP__; + static const int max_exponent10 = __FLT_MAX_10_EXP__; + + static const bool has_infinity = true; + static const bool has_quiet_NaN = true; + static const bool has_signaling_NaN = true; + static const float_denorm_style has_denorm = denorm_present; + static const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __builtin_huge_valf();} + _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __builtin_nanf("");} + _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __builtin_nansf("");} + _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __FLT_DENORM_MIN__;} + + static const bool is_iec559 = true; + static const bool is_bounded = true; + static const bool is_modulo = false; + + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_to_nearest; +}; + +template <> +class __libcpp_numeric_limits +{ +protected: + typedef double type; + + static const bool is_specialized = true; + + static const bool is_signed = true; + static const int digits = __DBL_MANT_DIG__; + static const int digits10 = __DBL_DIG__; + static const int max_digits10 = 2+(digits * 30103)/100000; + _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __DBL_MIN__;} + _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __DBL_MAX__;} + _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return -max();} + + static const bool is_integer = false; + static const bool is_exact = false; + static const int radix = __FLT_RADIX__; + _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __DBL_EPSILON__;} + _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return 0.5;} + + static const int min_exponent = __DBL_MIN_EXP__; + static const int min_exponent10 = __DBL_MIN_10_EXP__; + static const int max_exponent = __DBL_MAX_EXP__; + static const int max_exponent10 = __DBL_MAX_10_EXP__; + + static const bool has_infinity = true; + static const bool has_quiet_NaN = true; + static const bool has_signaling_NaN = true; + static const float_denorm_style has_denorm = denorm_present; + static const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __builtin_huge_val();} + _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __builtin_nan("");} + _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __builtin_nans("");} + _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __DBL_DENORM_MIN__;} + + static const bool is_iec559 = true; + static const bool is_bounded = true; + static const bool is_modulo = false; + + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_to_nearest; +}; + +template <> +class __libcpp_numeric_limits +{ +protected: + typedef long double type; + + static const bool is_specialized = true; + + static const bool is_signed = true; + static const int digits = __LDBL_MANT_DIG__; + static const int digits10 = __LDBL_DIG__; + static const int max_digits10 = 2+(digits * 30103)/100000; + _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __LDBL_MIN__;} + _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __LDBL_MAX__;} + _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return -max();} + + static const bool is_integer = false; + static const bool is_exact = false; + static const int radix = __FLT_RADIX__; + _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __LDBL_EPSILON__;} + _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return 0.5;} + + static const int min_exponent = __LDBL_MIN_EXP__; + static const int min_exponent10 = __LDBL_MIN_10_EXP__; + static const int max_exponent = __LDBL_MAX_EXP__; + static const int max_exponent10 = __LDBL_MAX_10_EXP__; + + static const bool has_infinity = true; + static const bool has_quiet_NaN = true; + static const bool has_signaling_NaN = true; + static const float_denorm_style has_denorm = denorm_present; + static const bool has_denorm_loss = false; + _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __builtin_huge_vall();} + _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __builtin_nanl("");} + _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __builtin_nansl("");} + _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __LDBL_DENORM_MIN__;} + +#if (defined(__ppc__) || defined(__ppc64__)) + static const bool is_iec559 = false; +#else + static const bool is_iec559 = true; +#endif + static const bool is_bounded = true; + static const bool is_modulo = false; + + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_to_nearest; +}; + +template +class _LIBCPP_VISIBLE numeric_limits + : private __libcpp_numeric_limits::type> +{ + typedef __libcpp_numeric_limits::type> __base; + typedef typename __base::type type; +public: + static const bool is_specialized = __base::is_specialized; + _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __base::min();} + _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __base::max();} + _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return __base::lowest();} + + static const int digits = __base::digits; + static const int digits10 = __base::digits10; + static const int max_digits10 = __base::max_digits10; + static const bool is_signed = __base::is_signed; + static const bool is_integer = __base::is_integer; + static const bool is_exact = __base::is_exact; + static const int radix = __base::radix; + _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __base::epsilon();} + _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return __base::round_error();} + + static const int min_exponent = __base::min_exponent; + static const int min_exponent10 = __base::min_exponent10; + static const int max_exponent = __base::max_exponent; + static const int max_exponent10 = __base::max_exponent10; + + static const bool has_infinity = __base::has_infinity; + static const bool has_quiet_NaN = __base::has_quiet_NaN; + static const bool has_signaling_NaN = __base::has_signaling_NaN; + static const float_denorm_style has_denorm = __base::has_denorm; + static const bool has_denorm_loss = __base::has_denorm_loss; + _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __base::infinity();} + _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} + _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} + _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __base::denorm_min();} + + static const bool is_iec559 = __base::is_iec559; + static const bool is_bounded = __base::is_bounded; + static const bool is_modulo = __base::is_modulo; + + static const bool traps = __base::traps; + static const bool tinyness_before = __base::tinyness_before; + static const float_round_style round_style = __base::round_style; +}; + +template +class _LIBCPP_VISIBLE numeric_limits + : private numeric_limits<_Tp> +{ + typedef numeric_limits<_Tp> __base; + typedef _Tp type; +public: + static const bool is_specialized = __base::is_specialized; + _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __base::min();} + _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __base::max();} + _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return __base::lowest();} + + static const int digits = __base::digits; + static const int digits10 = __base::digits10; + static const int max_digits10 = __base::max_digits10; + static const bool is_signed = __base::is_signed; + static const bool is_integer = __base::is_integer; + static const bool is_exact = __base::is_exact; + static const int radix = __base::radix; + _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __base::epsilon();} + _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return __base::round_error();} + + static const int min_exponent = __base::min_exponent; + static const int min_exponent10 = __base::min_exponent10; + static const int max_exponent = __base::max_exponent; + static const int max_exponent10 = __base::max_exponent10; + + static const bool has_infinity = __base::has_infinity; + static const bool has_quiet_NaN = __base::has_quiet_NaN; + static const bool has_signaling_NaN = __base::has_signaling_NaN; + static const float_denorm_style has_denorm = __base::has_denorm; + static const bool has_denorm_loss = __base::has_denorm_loss; + _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __base::infinity();} + _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} + _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} + _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __base::denorm_min();} + + static const bool is_iec559 = __base::is_iec559; + static const bool is_bounded = __base::is_bounded; + static const bool is_modulo = __base::is_modulo; + + static const bool traps = __base::traps; + static const bool tinyness_before = __base::tinyness_before; + static const float_round_style round_style = __base::round_style; +}; + +template +class _LIBCPP_VISIBLE numeric_limits + : private numeric_limits<_Tp> +{ + typedef numeric_limits<_Tp> __base; + typedef _Tp type; +public: + static const bool is_specialized = __base::is_specialized; + _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __base::min();} + _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __base::max();} + _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return __base::lowest();} + + static const int digits = __base::digits; + static const int digits10 = __base::digits10; + static const int max_digits10 = __base::max_digits10; + static const bool is_signed = __base::is_signed; + static const bool is_integer = __base::is_integer; + static const bool is_exact = __base::is_exact; + static const int radix = __base::radix; + _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __base::epsilon();} + _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return __base::round_error();} + + static const int min_exponent = __base::min_exponent; + static const int min_exponent10 = __base::min_exponent10; + static const int max_exponent = __base::max_exponent; + static const int max_exponent10 = __base::max_exponent10; + + static const bool has_infinity = __base::has_infinity; + static const bool has_quiet_NaN = __base::has_quiet_NaN; + static const bool has_signaling_NaN = __base::has_signaling_NaN; + static const float_denorm_style has_denorm = __base::has_denorm; + static const bool has_denorm_loss = __base::has_denorm_loss; + _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __base::infinity();} + _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} + _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} + _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __base::denorm_min();} + + static const bool is_iec559 = __base::is_iec559; + static const bool is_bounded = __base::is_bounded; + static const bool is_modulo = __base::is_modulo; + + static const bool traps = __base::traps; + static const bool tinyness_before = __base::tinyness_before; + static const float_round_style round_style = __base::round_style; +}; + +template +class _LIBCPP_VISIBLE numeric_limits + : private numeric_limits<_Tp> +{ + typedef numeric_limits<_Tp> __base; + typedef _Tp type; +public: + static const bool is_specialized = __base::is_specialized; + _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __base::min();} + _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __base::max();} + _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return __base::lowest();} + + static const int digits = __base::digits; + static const int digits10 = __base::digits10; + static const int max_digits10 = __base::max_digits10; + static const bool is_signed = __base::is_signed; + static const bool is_integer = __base::is_integer; + static const bool is_exact = __base::is_exact; + static const int radix = __base::radix; + _LIBCPP_INLINE_VISIBILITY static type epsilon() _NOEXCEPT {return __base::epsilon();} + _LIBCPP_INLINE_VISIBILITY static type round_error() _NOEXCEPT {return __base::round_error();} + + static const int min_exponent = __base::min_exponent; + static const int min_exponent10 = __base::min_exponent10; + static const int max_exponent = __base::max_exponent; + static const int max_exponent10 = __base::max_exponent10; + + static const bool has_infinity = __base::has_infinity; + static const bool has_quiet_NaN = __base::has_quiet_NaN; + static const bool has_signaling_NaN = __base::has_signaling_NaN; + static const float_denorm_style has_denorm = __base::has_denorm; + static const bool has_denorm_loss = __base::has_denorm_loss; + _LIBCPP_INLINE_VISIBILITY static type infinity() _NOEXCEPT {return __base::infinity();} + _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();} + _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();} + _LIBCPP_INLINE_VISIBILITY static type denorm_min() _NOEXCEPT {return __base::denorm_min();} + + static const bool is_iec559 = __base::is_iec559; + static const bool is_bounded = __base::is_bounded; + static const bool is_modulo = __base::is_modulo; + + static const bool traps = __base::traps; + static const bool tinyness_before = __base::tinyness_before; + static const float_round_style round_style = __base::round_style; +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_LIMITS diff --git a/contrib/libc++/include/list b/contrib/libc++/include/list new file mode 100644 index 000000000000..345f24dbbe4d --- /dev/null +++ b/contrib/libc++/include/list @@ -0,0 +1,2273 @@ +// -*- C++ -*- +//===---------------------------- list ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LIST +#define _LIBCPP_LIST + +/* + list synopsis + +namespace std +{ + +template > +class list +{ +public: + + // types: + typedef T value_type; + typedef Alloc allocator_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef implementation-defined size_type; + typedef implementation-defined difference_type; + typedef reverse_iterator reverse_iterator; + typedef reverse_iterator const_reverse_iterator; + + list() + noexcept(is_nothrow_default_constructible::value); + explicit list(const allocator_type& a); + explicit list(size_type n); + list(size_type n, const value_type& value); + list(size_type n, const value_type& value, const allocator_type& a); + template + list(Iter first, Iter last); + template + list(Iter first, Iter last, const allocator_type& a); + list(const list& x); + list(const list&, const allocator_type& a); + list(list&& x) + noexcept(is_nothrow_move_constructible::value); + list(list&&, const allocator_type& a); + list(initializer_list); + list(initializer_list, const allocator_type& a); + + ~list(); + + list& operator=(const list& x); + list& operator=(list&& x) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value); + list& operator=(initializer_list); + template + void assign(Iter first, Iter last); + void assign(size_type n, const value_type& t); + void assign(initializer_list); + + allocator_type get_allocator() const noexcept; + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + template + void emplace_front(Args&&... args); + void pop_front(); + template + void emplace_back(Args&&... args); + void pop_back(); + void push_front(const value_type& x); + void push_front(value_type&& x); + void push_back(const value_type& x); + void push_back(value_type&& x); + template + iterator emplace(const_iterator position, Args&&... args); + iterator insert(const_iterator position, const value_type& x); + iterator insert(const_iterator position, value_type&& x); + iterator insert(const_iterator position, size_type n, const value_type& x); + template + iterator insert(const_iterator position, Iter first, Iter last); + iterator insert(const_iterator position, initializer_list il); + + iterator erase(const_iterator position); + iterator erase(const_iterator position, const_iterator last); + + void resize(size_type sz); + void resize(size_type sz, const value_type& c); + + void swap(list&) + noexcept(!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable::value); + void clear() noexcept; + + void splice(const_iterator position, list& x); + void splice(const_iterator position, list&& x); + void splice(const_iterator position, list& x, const_iterator i); + void splice(const_iterator position, list&& x, const_iterator i); + void splice(const_iterator position, list& x, const_iterator first, + const_iterator last); + void splice(const_iterator position, list&& x, const_iterator first, + const_iterator last); + + void remove(const value_type& value); + template void remove_if(Pred pred); + void unique(); + template + void unique(BinaryPredicate binary_pred); + void merge(list& x); + void merge(list&& x); + template + void merge(list& x, Compare comp); + template + void merge(list&& x, Compare comp); + void sort(); + template + void sort(Compare comp); + void reverse() noexcept; +}; + +template + bool operator==(const list& x, const list& y); +template + bool operator< (const list& x, const list& y); +template + bool operator!=(const list& x, const list& y); +template + bool operator> (const list& x, const list& y); +template + bool operator>=(const list& x, const list& y); +template + bool operator<=(const list& x, const list& y); + +template + void swap(list& x, list& y) + noexcept(noexcept(x.swap(y))); + +} // std + +*/ + +#include <__config> + +#include +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template struct __list_node; + +template +struct __list_node_base +{ + typedef typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__list_node<_Tp, _VoidPtr> > pointer; +#else + rebind<__list_node<_Tp, _VoidPtr> >::other pointer; +#endif + + pointer __prev_; + pointer __next_; + + _LIBCPP_INLINE_VISIBILITY + __list_node_base() + : __prev_(static_cast(this)), + __next_(static_cast(this)) + {} +}; + +template +struct __list_node + : public __list_node_base<_Tp, _VoidPtr> +{ + _Tp __value_; +}; + +template class list; +template class __list_imp; +template class __list_const_iterator; + +template +class _LIBCPP_VISIBLE __list_iterator +{ + typedef typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__list_node<_Tp, _VoidPtr> > __node_pointer; +#else + rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer; +#endif + + __node_pointer __ptr_; + +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + explicit __list_iterator(__node_pointer __p, const void* __c) _NOEXCEPT + : __ptr_(__p) + { + __get_db()->__insert_ic(this, __c); + } +#else + _LIBCPP_INLINE_VISIBILITY + explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} +#endif + + + + template friend class list; + template friend class __list_imp; + template friend class __list_const_iterator; +public: + typedef bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef value_type& reference; + typedef typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + typedef typename pointer_traits::difference_type difference_type; + + _LIBCPP_INLINE_VISIBILITY + __list_iterator() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_i(this); +#endif + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + __list_iterator(const __list_iterator& __p) + : __ptr_(__p.__ptr_) + { + __get_db()->__iterator_copy(this, &__p); + } + + _LIBCPP_INLINE_VISIBILITY + ~__list_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCPP_INLINE_VISIBILITY + __list_iterator& operator=(const __list_iterator& __p) + { + if (this != &__p) + { + __get_db()->__iterator_copy(this, &__p); + __ptr_ = __p.__ptr_; + } + return *this; + } + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable list::iterator"); +#endif + return __ptr_->__value_; + } + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return &(operator*());} + + _LIBCPP_INLINE_VISIBILITY + __list_iterator& operator++() + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable list::iterator"); +#endif + __ptr_ = __ptr_->__next_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;} + + _LIBCPP_INLINE_VISIBILITY + __list_iterator& operator--() + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), + "Attempted to decrement non-decrementable list::iterator"); +#endif + __ptr_ = __ptr_->__prev_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __list_iterator& __x, const __list_iterator& __y) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), + "Attempted to compare non-comparable list::iterator"); +#endif + return __x.__ptr_ == __y.__ptr_; + } + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __list_iterator& __x, const __list_iterator& __y) + {return !(__x == __y);} +}; + +template +class _LIBCPP_VISIBLE __list_const_iterator +{ + typedef typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind > __node_pointer; +#else + rebind >::other __node_pointer; +#endif + + __node_pointer __ptr_; + +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + explicit __list_const_iterator(__node_pointer __p, const void* __c) _NOEXCEPT + : __ptr_(__p) + { + __get_db()->__insert_ic(this, __c); + } +#else + _LIBCPP_INLINE_VISIBILITY + explicit __list_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} +#endif + + template friend class list; + template friend class __list_imp; +public: + typedef bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef const value_type& reference; + typedef typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + typedef typename pointer_traits::difference_type difference_type; + + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_i(this); +#endif + } + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator(__list_iterator<_Tp, _VoidPtr> __p) _NOEXCEPT + : __ptr_(__p.__ptr_) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__iterator_copy(this, &__p); +#endif + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator(const __list_const_iterator& __p) + : __ptr_(__p.__ptr_) + { + __get_db()->__iterator_copy(this, &__p); + } + + _LIBCPP_INLINE_VISIBILITY + ~__list_const_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator& operator=(const __list_const_iterator& __p) + { + if (this != &__p) + { + __get_db()->__iterator_copy(this, &__p); + __ptr_ = __p.__ptr_; + } + return *this; + } + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + reference operator*() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable list::const_iterator"); +#endif + return __ptr_->__value_; + } + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return &(operator*());} + + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator& operator++() + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable list::const_iterator"); +#endif + __ptr_ = __ptr_->__next_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;} + + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator& operator--() + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), + "Attempted to decrement non-decrementable list::const_iterator"); +#endif + __ptr_ = __ptr_->__prev_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), + "Attempted to compare non-comparable list::const_iterator"); +#endif + return __x.__ptr_ == __y.__ptr_; + } + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) + {return !(__x == __y);} +}; + +template +class __list_imp +{ + __list_imp(const __list_imp&); + __list_imp& operator=(const __list_imp&); +protected: + typedef _Tp value_type; + typedef _Alloc allocator_type; + typedef allocator_traits __alloc_traits; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::void_pointer __void_pointer; + typedef __list_iterator iterator; + typedef __list_const_iterator const_iterator; + typedef __list_node_base __node_base; + typedef __list_node __node; + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__node> +#else + rebind_alloc<__node>::other +#endif + __node_allocator; + typedef allocator_traits<__node_allocator> __node_alloc_traits; + typedef typename __node_alloc_traits::pointer __node_pointer; + typedef typename __node_alloc_traits::const_pointer __node_const_pointer; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::difference_type difference_type; + + __node_base __end_; + __compressed_pair __size_alloc_; + + _LIBCPP_INLINE_VISIBILITY + size_type& __sz() _NOEXCEPT {return __size_alloc_.first();} + _LIBCPP_INLINE_VISIBILITY + const size_type& __sz() const _NOEXCEPT + {return __size_alloc_.first();} + _LIBCPP_INLINE_VISIBILITY + __node_allocator& __node_alloc() _NOEXCEPT + {return __size_alloc_.second();} + _LIBCPP_INLINE_VISIBILITY + const __node_allocator& __node_alloc() const _NOEXCEPT + {return __size_alloc_.second();} + + static void __unlink_nodes(__node_base& __f, __node_base& __l) _NOEXCEPT; + + __list_imp() + _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value); + __list_imp(const allocator_type& __a); + ~__list_imp(); + void clear() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __sz() == 0;} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__end_.__next_, this); +#else + return iterator(__end_.__next_); +#endif + } + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(__end_.__next_, this); +#else + return const_iterator(__end_.__next_); +#endif + } + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(static_cast<__node_pointer>(&__end_), this); +#else + return iterator(static_cast<__node_pointer>(&__end_)); +#endif + } + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(static_cast<__node_const_pointer>(&__end_), this); +#else + return const_iterator(static_cast<__node_const_pointer>(&__end_)); +#endif + } + + void swap(__list_imp& __c) + _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value); + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __list_imp& __c) + {__copy_assign_alloc(__c, integral_constant());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__list_imp& __c) + _NOEXCEPT_( + !__node_alloc_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<__node_allocator>::value) + {__move_assign_alloc(__c, integral_constant());} + +private: + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y) + _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) + {__swap_alloc(__x, __y, integral_constant());} + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type) + _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value) + { + using _VSTD::swap; + swap(__x, __y); + } + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type) + _NOEXCEPT + {} + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __list_imp& __c, true_type) + { + if (__node_alloc() != __c.__node_alloc()) + clear(); + __node_alloc() = __c.__node_alloc(); + } + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __list_imp& __c, false_type) + {} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__list_imp& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) + { + __node_alloc() = _VSTD::move(__c.__node_alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__list_imp& __c, false_type) + _NOEXCEPT + {} +}; + +// Unlink nodes [__f, __l] +template +inline _LIBCPP_INLINE_VISIBILITY +void +__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_base& __f, __node_base& __l) + _NOEXCEPT +{ + __f.__prev_->__next_ = __l.__next_; + __l.__next_->__prev_ = __f.__prev_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__list_imp<_Tp, _Alloc>::__list_imp() + _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) + : __size_alloc_(0) +{ +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a) + : __size_alloc_(0, __node_allocator(__a)) +{ +} + +template +__list_imp<_Tp, _Alloc>::~__list_imp() +{ + clear(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__erase_c(this); +#endif +} + +template +void +__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT +{ + if (!empty()) + { + __node_allocator& __na = __node_alloc(); + __node_pointer __f = __end_.__next_; + __node_pointer __l = static_cast<__node_pointer>(&__end_); + __unlink_nodes(*__f, *__l->__prev_); + __sz() = 0; + while (__f != __l) + { + __node& __n = *__f; + __f = __f->__next_; + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); + __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + const_iterator* __i = static_cast((*__p)->__i_); + if (__i->__ptr_ != __l) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + } +} + +template +void +__list_imp<_Tp, _Alloc>::swap(__list_imp& __c) + _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) +{ + _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || + this->__node_alloc() == __c.__node_alloc(), + "list::swap: Either propagate_on_container_swap must be true" + " or the allocators must compare equal"); + using _VSTD::swap; + __swap_alloc(__node_alloc(), __c.__node_alloc()); + swap(__sz(), __c.__sz()); + swap(__end_, __c.__end_); + if (__sz() == 0) + __end_.__next_ = __end_.__prev_ = &static_cast<__node&>(__end_); + else + __end_.__prev_->__next_ = __end_.__next_->__prev_ + = &static_cast<__node&>(__end_); + if (__c.__sz() == 0) + __c.__end_.__next_ = __c.__end_.__prev_ + = &static_cast<__node&>(__c.__end_); + else + __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ + = &static_cast<__node&>(__c.__end_); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + std::swap(__cn1->beg_, __cn2->beg_); + std::swap(__cn1->end_, __cn2->end_); + std::swap(__cn1->cap_, __cn2->cap_); + for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;) + { + --__p; + const_iterator* __i = static_cast((*__p)->__i_); + if (__i->__ptr_ == static_cast<__node_pointer>(&__c.__end_)) + { + __cn2->__add(*__p); + if (--__cn1->end_ != __p) + memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*)); + } + else + (*__p)->__c_ = __cn1; + } + for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) + { + --__p; + const_iterator* __i = static_cast((*__p)->__i_); + if (__i->__ptr_ == static_cast<__node_pointer>(&__end_)) + { + __cn1->__add(*__p); + if (--__cn2->end_ != __p) + memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); + } + else + (*__p)->__c_ = __cn2; + } + __db->unlock(); +#endif +} + +template > +class _LIBCPP_VISIBLE list + : private __list_imp<_Tp, _Alloc> +{ + typedef __list_imp<_Tp, _Alloc> base; + typedef typename base::__node __node; + typedef typename base::__node_allocator __node_allocator; + typedef typename base::__node_pointer __node_pointer; + typedef typename base::__node_alloc_traits __node_alloc_traits; + +public: + typedef _Tp value_type; + typedef _Alloc allocator_type; + static_assert((is_same::value), + "Invalid allocator::value_type"); + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename base::pointer pointer; + typedef typename base::const_pointer const_pointer; + typedef typename base::size_type size_type; + typedef typename base::difference_type difference_type; + typedef typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + typedef _VSTD::reverse_iterator reverse_iterator; + typedef _VSTD::reverse_iterator const_reverse_iterator; + + _LIBCPP_INLINE_VISIBILITY + list() + _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + _LIBCPP_INLINE_VISIBILITY + list(const allocator_type& __a) : base(__a) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + list(size_type __n); + list(size_type __n, const value_type& __x); + list(size_type __n, const value_type& __x, const allocator_type& __a); + template + list(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); + template + list(_InpIter __f, _InpIter __l, const allocator_type& __a, + typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); + + list(const list& __c); + list(const list& __c, const allocator_type& __a); + list& operator=(const list& __c); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + list(initializer_list __il); + list(initializer_list __il, const allocator_type& __a); +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + list(list&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); + list(list&& __c, const allocator_type& __a); + list& operator=(list&& __c) + _NOEXCEPT_( + __node_alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + list& operator=(initializer_list __il) + {assign(__il.begin(), __il.end()); return *this;} +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + template + void assign(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); + void assign(size_type __n, const value_type& __x); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list __il) + {assign(__il.begin(), __il.end());} +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + allocator_type get_allocator() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return base::__sz();} + _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return base::empty();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + {return numeric_limits::max();} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return base::begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return base::begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return base::end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return base::end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return base::begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return base::end();} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT + {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + reference front() + { + _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); + return base::__end_.__next_->__value_; + } + _LIBCPP_INLINE_VISIBILITY + const_reference front() const + { + _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); + return base::__end_.__next_->__value_; + } + _LIBCPP_INLINE_VISIBILITY + reference back() + { + _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); + return base::__end_.__prev_->__value_; + } + _LIBCPP_INLINE_VISIBILITY + const_reference back() const + { + _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); + return base::__end_.__prev_->__value_; + } + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void push_front(value_type&& __x); + void push_back(value_type&& __x); +#ifndef _LIBCPP_HAS_NO_VARIADICS + template + void emplace_front(_Args&&... __args); + template + void emplace_back(_Args&&... __args); + template + iterator emplace(const_iterator __p, _Args&&... __args); +#endif // _LIBCPP_HAS_NO_VARIADICS + iterator insert(const_iterator __p, value_type&& __x); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + void push_front(const value_type& __x); + void push_back(const value_type& __x); + + iterator insert(const_iterator __p, const value_type& __x); + iterator insert(const_iterator __p, size_type __n, const value_type& __x); + template + iterator insert(const_iterator __p, _InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, initializer_list __il) + {return insert(__p, __il.begin(), __il.end());} +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + void swap(list& __c) + _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) + {base::swap(__c);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {base::clear();} + + void pop_front(); + void pop_back(); + + iterator erase(const_iterator __p); + iterator erase(const_iterator __f, const_iterator __l); + + void resize(size_type __n); + void resize(size_type __n, const value_type& __x); + + void splice(const_iterator __p, list& __c); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void splice(const_iterator __p, list&& __c) {splice(__p, __c);} +#endif + void splice(const_iterator __p, list& __c, const_iterator __i); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void splice(const_iterator __p, list&& __c, const_iterator __i) + {splice(__p, __c, __i);} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) + {splice(__p, __c, __f, __l);} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + void remove(const value_type& __x); + template void remove_if(_Pred __pred); + void unique(); + template + void unique(_BinaryPred __binary_pred); + void merge(list& __c); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void merge(list&& __c) {merge(__c);} +#endif + template + void merge(list& __c, _Comp __comp); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template + _LIBCPP_INLINE_VISIBILITY + void merge(list&& __c, _Comp __comp) {merge(__c, __comp);} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + void sort(); + template + void sort(_Comp __comp); + + void reverse() _NOEXCEPT; + + bool __invariants() const; + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const; + bool __decrementable(const const_iterator* __i) const; + bool __addable(const const_iterator* __i, ptrdiff_t __n) const; + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +private: + static void __link_nodes(__node& __p, __node& __f, __node& __l); + iterator __iterator(size_type __n); + template + static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp); + + void __move_assign(list& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value); + void __move_assign(list& __c, false_type); +}; + +// Link in nodes [__f, __l] just prior to __p +template +inline _LIBCPP_INLINE_VISIBILITY +void +list<_Tp, _Alloc>::__link_nodes(__node& __p, __node& __f, __node& __l) +{ + __p.__prev_->__next_ = &__f; + __f.__prev_ = __p.__prev_; + __p.__prev_ = &__l; + __l.__next_ = &__p; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::__iterator(size_type __n) +{ + return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n) + : _VSTD::prev(end(), base::__sz() - __n); +} + +template +list<_Tp, _Alloc>::list(size_type __n) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __n > 0; --__n) +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + emplace_back(); +#else + push_back(value_type()); +#endif +} + +template +list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __n > 0; --__n) + push_back(__x); +} + +template +list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a) + : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __n > 0; --__n) + push_back(__x); +} + +template +template +list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type*) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __f != __l; ++__f) + push_back(*__f); +} + +template +template +list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a, + typename enable_if<__is_input_iterator<_InpIter>::value>::type*) + : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (; __f != __l; ++__f) + push_back(*__f); +} + +template +list<_Tp, _Alloc>::list(const list& __c) + : base(allocator_type( + __node_alloc_traits::select_on_container_copy_construction( + __c.__node_alloc()))) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) + push_back(*__i); +} + +template +list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a) + : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) + push_back(*__i); +} + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +list<_Tp, _Alloc>::list(initializer_list __il, const allocator_type& __a) + : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (typename initializer_list::const_iterator __i = __il.begin(), + __e = __il.end(); __i != __e; ++__i) + push_back(*__i); +} + +template +list<_Tp, _Alloc>::list(initializer_list __il) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + for (typename initializer_list::const_iterator __i = __il.begin(), + __e = __il.end(); __i != __e; ++__i) + push_back(*__i); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +inline _LIBCPP_INLINE_VISIBILITY +list<_Tp, _Alloc>& +list<_Tp, _Alloc>::operator=(const list& __c) +{ + if (this != &__c) + { + base::__copy_assign_alloc(__c); + assign(__c.begin(), __c.end()); + } + return *this; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_INLINE_VISIBILITY +list<_Tp, _Alloc>::list(list&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) + : base(allocator_type(_VSTD::move(__c.__node_alloc()))) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + splice(end(), __c); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a) + : base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__a == __c.get_allocator()) + splice(end(), __c); + else + { + typedef move_iterator _I; + assign(_I(__c.begin()), _I(__c.end())); + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +list<_Tp, _Alloc>& +list<_Tp, _Alloc>::operator=(list&& __c) + _NOEXCEPT_( + __node_alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<__node_allocator>::value) +{ + __move_assign(__c, integral_constant()); + return *this; +} + +template +void +list<_Tp, _Alloc>::__move_assign(list& __c, false_type) +{ + if (base::__node_alloc() != __c.__node_alloc()) + { + typedef move_iterator _I; + assign(_I(__c.begin()), _I(__c.end())); + } + else + __move_assign(__c, true_type()); +} + +template +void +list<_Tp, _Alloc>::__move_assign(list& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) +{ + clear(); + base::__move_assign_alloc(__c); + splice(end(), __c); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +template +void +list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type*) +{ + iterator __i = begin(); + iterator __e = end(); + for (; __f != __l && __i != __e; ++__f, ++__i) + *__i = *__f; + if (__i == __e) + insert(__e, __f, __l); + else + erase(__i, __e); +} + +template +void +list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) +{ + iterator __i = begin(); + iterator __e = end(); + for (; __n > 0 && __i != __e; --__n, ++__i) + *__i = __x; + if (__i == __e) + insert(__e, __n, __x); + else + erase(__i, __e); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Alloc +list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT +{ + return allocator_type(base::__node_alloc()); +} + +template +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::insert(iterator, x) called with an iterator not" + " referring to this list"); +#endif + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __hold->__prev_ = 0; + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); + ++base::__sz(); + return iterator(__hold.release()); +} + +template +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::insert(iterator, n, x) called with an iterator not" + " referring to this list"); + iterator __r(const_cast<__node_pointer>(__p.__ptr_), this); +#else + iterator __r(const_cast<__node_pointer>(__p.__ptr_)); +#endif + if (__n > 0) + { + size_type __ds = 0; + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __hold->__prev_ = 0; + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + ++__ds; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __r = iterator(__hold.get(), this); +#else + __r = iterator(__hold.get()); +#endif + __hold.release(); + iterator __e = __r; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (--__n; __n != 0; --__n, ++__e, ++__ds) + { + __hold.reset(__node_alloc_traits::allocate(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + __e.__ptr_->__next_ = __hold.get(); + __hold->__prev_ = __e.__ptr_; + __hold.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (true) + { + __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); + __node_pointer __prev = __e.__ptr_->__prev_; + __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); + if (__prev == 0) + break; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __e = iterator(__prev, this); +#else + __e = iterator(__prev); +#endif + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_); + base::__sz() += __ds; + } + return __r; +} + +template +template +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, + typename enable_if<__is_input_iterator<_InpIter>::value>::type*) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::insert(iterator, range) called with an iterator not" + " referring to this list"); + iterator __r(const_cast<__node_pointer>(__p.__ptr_), this); +#else + iterator __r(const_cast<__node_pointer>(__p.__ptr_)); +#endif + if (__f != __l) + { + size_type __ds = 0; + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __hold->__prev_ = 0; + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); + ++__ds; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __r = iterator(__hold.get(), this); +#else + __r = iterator(__hold.get()); +#endif + __hold.release(); + iterator __e = __r; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (++__f; __f != __l; ++__f, ++__e, ++__ds) + { + __hold.reset(__node_alloc_traits::allocate(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); + __e.__ptr_->__next_ = __hold.get(); + __hold->__prev_ = __e.__ptr_; + __hold.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (true) + { + __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); + __node_pointer __prev = __e.__ptr_->__prev_; + __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); + if (__prev == 0) + break; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __e = iterator(__prev, this); +#else + __e = iterator(__prev); +#endif + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_); + base::__sz() += __ds; + } + return __r; +} + +template +void +list<_Tp, _Alloc>::push_front(const value_type& __x) +{ + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + __link_nodes(*base::__end_.__next_, *__hold, *__hold); + ++base::__sz(); + __hold.release(); +} + +template +void +list<_Tp, _Alloc>::push_back(const value_type& __x) +{ + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); + ++base::__sz(); + __hold.release(); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +list<_Tp, _Alloc>::push_front(value_type&& __x) +{ + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); + __link_nodes(*base::__end_.__next_, *__hold, *__hold); + ++base::__sz(); + __hold.release(); +} + +template +void +list<_Tp, _Alloc>::push_back(value_type&& __x) +{ + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); + __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); + ++base::__sz(); + __hold.release(); +} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +void +list<_Tp, _Alloc>::emplace_front(_Args&&... __args) +{ + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); + __link_nodes(*base::__end_.__next_, *__hold, *__hold); + ++base::__sz(); + __hold.release(); +} + +template +template +void +list<_Tp, _Alloc>::emplace_back(_Args&&... __args) +{ + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); + __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); + ++base::__sz(); + __hold.release(); +} + +template +template +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) +{ + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __hold->__prev_ = 0; + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); + __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); + ++base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__hold.release(), this); +#else + return iterator(__hold.release()); +#endif +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::insert(iterator, x) called with an iterator not" + " referring to this list"); +#endif + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __hold->__prev_ = 0; + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); + __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); + ++base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__hold.release(), this); +#else + return iterator(__hold.release()); +#endif +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +void +list<_Tp, _Alloc>::pop_front() +{ + _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); + __node_allocator& __na = base::__node_alloc(); + __node& __n = *base::__end_.__next_; + base::__unlink_nodes(__n, __n); + --base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast((*__p)->__i_); + if (__i->__ptr_ == &__n) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); + __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); +} + +template +void +list<_Tp, _Alloc>::pop_back() +{ + _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); + __node_allocator& __na = base::__node_alloc(); + __node& __n = *base::__end_.__prev_; + base::__unlink_nodes(__n, __n); + --base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast((*__p)->__i_); + if (__i->__ptr_ == &__n) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); + __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); +} + +template +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::erase(const_iterator __p) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::erase(iterator) called with an iterator not" + " referring to this list"); +#endif + __node_allocator& __na = base::__node_alloc(); + __node& __n = const_cast<__node&>(*__p.__ptr_); + __node_pointer __r = __n.__next_; + base::__unlink_nodes(__n, __n); + --base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast((*__p)->__i_); + if (__i->__ptr_ == &__n) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); + __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__r, this); +#else + return iterator(__r); +#endif +} + +template +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this, + "list::erase(iterator, iterator) called with an iterator not" + " referring to this list"); +#endif + if (__f != __l) + { + __node_allocator& __na = base::__node_alloc(); + base::__unlink_nodes(const_cast<__node&>(*__f.__ptr_), *__l.__ptr_->__prev_); + while (__f != __l) + { + __node& __n = const_cast<__node&>(*__f.__ptr_); + ++__f; + --base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast((*__p)->__i_); + if (__i->__ptr_ == &__n) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); + __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + } + } +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(const_cast<__node_pointer>(__l.__ptr_), this); +#else + return iterator(const_cast<__node_pointer>(__l.__ptr_)); +#endif +} + +template +void +list<_Tp, _Alloc>::resize(size_type __n) +{ + if (__n < base::__sz()) + erase(__iterator(__n), end()); + else if (__n > base::__sz()) + { + __n -= base::__sz(); + size_type __ds = 0; + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __hold->__prev_ = 0; + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); + ++__ds; +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator __r = iterator(__hold.release(), this); +#else + iterator __r = iterator(__hold.release()); +#endif + iterator __e = __r; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (--__n; __n != 0; --__n, ++__e, ++__ds) + { + __hold.reset(__node_alloc_traits::allocate(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); + __e.__ptr_->__next_ = __hold.get(); + __hold->__prev_ = __e.__ptr_; + __hold.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (true) + { + __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); + __node_pointer __prev = __e.__ptr_->__prev_; + __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); + if (__prev == 0) + break; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __e = iterator(__prev, this); +#else + __e = iterator(__prev); +#endif + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_); + base::__sz() += __ds; + } +} + +template +void +list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) +{ + if (__n < base::__sz()) + erase(__iterator(__n), end()); + else if (__n > base::__sz()) + { + __n -= base::__sz(); + size_type __ds = 0; + __node_allocator& __na = base::__node_alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); + __hold->__prev_ = 0; + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + ++__ds; +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator __r = iterator(__hold.release(), this); +#else + iterator __r = iterator(__hold.release()); +#endif + iterator __e = __r; +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + for (--__n; __n != 0; --__n, ++__e, ++__ds) + { + __hold.reset(__node_alloc_traits::allocate(__na, 1)); + __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); + __e.__ptr_->__next_ = __hold.get(); + __hold->__prev_ = __e.__ptr_; + __hold.release(); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + while (true) + { + __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); + __node_pointer __prev = __e.__ptr_->__prev_; + __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); + if (__prev == 0) + break; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __e = iterator(__prev, this); +#else + __e = iterator(__prev); +#endif + } + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_); + base::__sz() += __ds; + } +} + +template +void +list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) +{ + _LIBCPP_ASSERT(this != &__c, + "list::splice(iterator, list) called with this == &list"); +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::splice(iterator, list) called with an iterator not" + " referring to this list"); +#endif + if (!__c.empty()) + { + __node& __f = *__c.__end_.__next_; + __node& __l = *__c.__end_.__prev_; + base::__unlink_nodes(__f, __l); + __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __l); + base::__sz() += __c.__sz(); + __c.__sz() = 0; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) + { + --__p; + iterator* __i = static_cast((*__p)->__i_); + if (__i->__ptr_ != static_cast<__node_pointer>(&__c.__end_)) + { + __cn1->__add(*__p); + (*__p)->__c_ = __cn1; + if (--__cn2->end_ != __p) + memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); + } + } + __db->unlock(); +#endif + } +} + +template +void +list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::splice(iterator, list, iterator) called with first iterator not" + " referring to this list"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c, + "list::splice(iterator, list, iterator) called with second iterator not" + " referring to list argument"); + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i), + "list::splice(iterator, list, iterator) called with second iterator not" + " derefereceable"); +#endif + if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) + { + __node& __f = const_cast<__node&>(*__i.__ptr_); + base::__unlink_nodes(__f, __f); + __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __f); + --__c.__sz(); + ++base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) + { + --__p; + iterator* __j = static_cast((*__p)->__i_); + if (__j->__ptr_ == &__f) + { + __cn1->__add(*__p); + (*__p)->__c_ = __cn1; + if (--__cn2->end_ != __p) + memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); + } + } + __db->unlock(); +#endif + } +} + +template +void +list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::splice(iterator, list, iterator, iterator) called with first iterator not" + " referring to this list"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c, + "list::splice(iterator, list, iterator, iterator) called with second iterator not" + " referring to list argument"); + if (this == &__c) + { + for (const_iterator __i = __f; __i != __l; ++__i) + _LIBCPP_ASSERT(__i != __p, + "list::splice(iterator, list, iterator, iterator)" + " called with the first iterator within the range" + " of the second and third iterators"); + } +#endif + if (__f != __l) + { + if (this != &__c) + { + size_type __s = _VSTD::distance(__f, __l); + __c.__sz() -= __s; + base::__sz() += __s; + } + __node& __first = const_cast<__node&>(*__f.__ptr_); + --__l; + __node& __last = const_cast<__node&>(*__l.__ptr_); + base::__unlink_nodes(__first, __last); + __link_nodes(const_cast<__node&>(*__p.__ptr_), __first, __last); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) + { + --__p; + iterator* __j = static_cast((*__p)->__i_); + for (__node_pointer __k = const_cast<__node_pointer>(__f.__ptr_); + __k != __l.__ptr_; __k = __k->__next_) + { + if (__j->__ptr_ == __k) + { + __cn1->__add(*__p); + (*__p)->__c_ = __cn1; + if (--__cn2->end_ != __p) + memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); + } + } + } + __db->unlock(); +#endif + } +} + +template +void +list<_Tp, _Alloc>::remove(const value_type& __x) +{ + for (iterator __i = begin(), __e = end(); __i != __e;) + { + if (*__i == __x) + { + iterator __j = _VSTD::next(__i); + for (; __j != __e && *__j == __x; ++__j) + ; + __i = erase(__i, __j); + } + else + ++__i; + } +} + +template +template +void +list<_Tp, _Alloc>::remove_if(_Pred __pred) +{ + for (iterator __i = begin(), __e = end(); __i != __e;) + { + if (__pred(*__i)) + { + iterator __j = _VSTD::next(__i); + for (; __j != __e && __pred(*__j); ++__j) + ; + __i = erase(__i, __j); + } + else + ++__i; + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +list<_Tp, _Alloc>::unique() +{ + unique(__equal_to()); +} + +template +template +void +list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) +{ + for (iterator __i = begin(), __e = end(); __i != __e;) + { + iterator __j = _VSTD::next(__i); + for (; __j != __e && __binary_pred(*__i, *__j); ++__j) + ; + if (++__i != __j) + __i = erase(__i, __j); + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +list<_Tp, _Alloc>::merge(list& __c) +{ + merge(__c, __less()); +} + +template +template +void +list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) +{ + if (this != &__c) + { + iterator __f1 = begin(); + iterator __e1 = end(); + iterator __f2 = __c.begin(); + iterator __e2 = __c.end(); + while (__f1 != __e1 && __f2 != __e2) + { + if (__comp(*__f2, *__f1)) + { + size_type __ds = 1; + iterator __m2 = _VSTD::next(__f2); + for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds) + ; + base::__sz() += __ds; + __c.__sz() -= __ds; + __node& __f = *__f2.__ptr_; + __node& __l = *__m2.__ptr_->__prev_; + __f2 = __m2; + base::__unlink_nodes(__f, __l); + __m2 = _VSTD::next(__f1); + __link_nodes(*__f1.__ptr_, __f, __l); + __f1 = __m2; + } + else + ++__f1; + } + splice(__e1, __c); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) + { + --__p; + iterator* __i = static_cast((*__p)->__i_); + if (__i->__ptr_ != static_cast<__node_pointer>(&__c.__end_)) + { + __cn1->__add(*__p); + (*__p)->__c_ = __cn1; + if (--__cn2->end_ != __p) + memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); + } + } + __db->unlock(); +#endif + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +list<_Tp, _Alloc>::sort() +{ + sort(__less()); +} + +template +template +inline _LIBCPP_INLINE_VISIBILITY +void +list<_Tp, _Alloc>::sort(_Comp __comp) +{ + __sort(begin(), end(), base::__sz(), __comp); +} + +template +template +typename list<_Tp, _Alloc>::iterator +list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp) +{ + switch (__n) + { + case 0: + case 1: + return __f1; + case 2: + if (__comp(*--__e2, *__f1)) + { + __node& __f = *__e2.__ptr_; + base::__unlink_nodes(__f, __f); + __link_nodes(*__f1.__ptr_, __f, __f); + return __e2; + } + return __f1; + } + size_type __n2 = __n / 2; + iterator __e1 = _VSTD::next(__f1, __n2); + iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp); + iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp); + if (__comp(*__f2, *__f1)) + { + iterator __m2 = _VSTD::next(__f2); + for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) + ; + __node& __f = *__f2.__ptr_; + __node& __l = *__m2.__ptr_->__prev_; + __r = __f2; + __e1 = __f2 = __m2; + base::__unlink_nodes(__f, __l); + __m2 = _VSTD::next(__f1); + __link_nodes(*__f1.__ptr_, __f, __l); + __f1 = __m2; + } + else + ++__f1; + while (__f1 != __e1 && __f2 != __e2) + { + if (__comp(*__f2, *__f1)) + { + iterator __m2 = _VSTD::next(__f2); + for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) + ; + __node& __f = *__f2.__ptr_; + __node& __l = *__m2.__ptr_->__prev_; + if (__e1 == __f2) + __e1 = __m2; + __f2 = __m2; + base::__unlink_nodes(__f, __l); + __m2 = _VSTD::next(__f1); + __link_nodes(*__f1.__ptr_, __f, __l); + __f1 = __m2; + } + else + ++__f1; + } + return __r; +} + +template +void +list<_Tp, _Alloc>::reverse() _NOEXCEPT +{ + if (base::__sz() > 1) + { + iterator __e = end(); + for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;) + { + _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_); + __i.__ptr_ = __i.__ptr_->__prev_; + } + _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_); + } +} + +template +bool +list<_Tp, _Alloc>::__invariants() const +{ + return size() == _VSTD::distance(begin(), end()); +} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + +template +bool +list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const +{ + return __i->__ptr_ != &this->__end_; +} + +template +bool +list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const +{ + return !empty() && __i->__ptr_ != base::__end_.__next_; +} + +template +bool +list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const +{ + return false; +} + +template +bool +list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const +{ + return false; +} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return !(__x == __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return __y < __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return !(__x < __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) +{ + return !(__y < __x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_LIST diff --git a/contrib/libc++/include/locale b/contrib/libc++/include/locale new file mode 100644 index 000000000000..b2afbd40e07b --- /dev/null +++ b/contrib/libc++/include/locale @@ -0,0 +1,4485 @@ +// -*- C++ -*- +//===-------------------------- locale ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LOCALE +#define _LIBCPP_LOCALE + +/* + locale synopsis + +namespace std +{ + +class locale +{ +public: + // types: + class facet; + class id; + + typedef int category; + static const category // values assigned here are for exposition only + none = 0x000, + collate = 0x010, + ctype = 0x020, + monetary = 0x040, + numeric = 0x080, + time = 0x100, + messages = 0x200, + all = collate | ctype | monetary | numeric | time | messages; + + // construct/copy/destroy: + locale() noexcept; + locale(const locale& other) noexcept; + explicit locale(const char* std_name); + explicit locale(const string& std_name); + locale(const locale& other, const char* std_name, category); + locale(const locale& other, const string& std_name, category); + template locale(const locale& other, Facet* f); + locale(const locale& other, const locale& one, category); + + ~locale(); // not virtual + + const locale& operator=(const locale& other) noexcept; + + template locale combine(const locale& other) const; + + // locale operations: + basic_string name() const; + bool operator==(const locale& other) const; + bool operator!=(const locale& other) const; + template + bool operator()(const basic_string& s1, + const basic_string& s2) const; + + // global locale objects: + static locale global(const locale&); + static const locale& classic(); +}; + +template const Facet& use_facet(const locale&); +template bool has_facet(const locale&) noexcept; + +// 22.3.3, convenience interfaces: +template bool isspace (charT c, const locale& loc); +template bool isprint (charT c, const locale& loc); +template bool iscntrl (charT c, const locale& loc); +template bool isupper (charT c, const locale& loc); +template bool islower (charT c, const locale& loc); +template bool isalpha (charT c, const locale& loc); +template bool isdigit (charT c, const locale& loc); +template bool ispunct (charT c, const locale& loc); +template bool isxdigit(charT c, const locale& loc); +template bool isalnum (charT c, const locale& loc); +template bool isgraph (charT c, const locale& loc); +template charT toupper(charT c, const locale& loc); +template charT tolower(charT c, const locale& loc); + +template, + class Byte_alloc = allocator> +class wstring_convert +{ +public: + typedef basic_string, Byte_alloc> byte_string; + typedef basic_string, Wide_alloc> wide_string; + typedef typename Codecvt::state_type state_type; + typedef typename wide_string::traits_type::int_type int_type; + + wstring_convert(Codecvt* pcvt = new Codecvt); + wstring_convert(Codecvt* pcvt, state_type state); + wstring_convert(const byte_string& byte_err, + const wide_string& wide_err = wide_string()); + ~wstring_convert(); + + wide_string from_bytes(char byte); + wide_string from_bytes(const char* ptr); + wide_string from_bytes(const byte_string& str); + wide_string from_bytes(const char* first, const char* last); + + byte_string to_bytes(Elem wchar); + byte_string to_bytes(const Elem* wptr); + byte_string to_bytes(const wide_string& wstr); + byte_string to_bytes(const Elem* first, const Elem* last); + + size_t converted() const; + state_type state() const; +}; + +template > +class wbuffer_convert + : public basic_streambuf +{ +public: + typedef typename Tr::state_type state_type; + + wbuffer_convert(streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt, + state_type state = state_type()); + + streambuf* rdbuf() const; + streambuf* rdbuf(streambuf* bytebuf); + + state_type state() const; +}; + +// 22.4.1 and 22.4.1.3, ctype: +class ctype_base; +template class ctype; +template <> class ctype; // specialization +template class ctype_byname; +template <> class ctype_byname; // specialization + +class codecvt_base; +template class codecvt; +template class codecvt_byname; + +// 22.4.2 and 22.4.3, numeric: +template class num_get; +template class num_put; +template class numpunct; +template class numpunct_byname; + +// 22.4.4, col lation: +template class collate; +template class collate_byname; + +// 22.4.5, date and time: +class time_base; +template class time_get; +template class time_get_byname; +template class time_put; +template class time_put_byname; + +// 22.4.6, money: +class money_base; +template class money_get; +template class money_put; +template class moneypunct; +template class moneypunct_byname; + +// 22.4.7, message retrieval: +class messages_base; +template class messages; +template class messages_byname; + +} // std + +*/ + +#include <__config> +#include <__locale> +#include +#include +#include +#include +#include +#include +#if !__APPLE__ +#include +#endif +#include +#include +#if _WIN32 +#include +#else // _WIN32 +#include +#endif // !_WIN32 + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if __APPLE__ || __FreeBSD__ +# define _LIBCPP_GET_C_LOCALE 0 +#else +# define _LIBCPP_GET_C_LOCALE __cloc() + // Get the C locale object + locale_t __cloc(); +#define __cloc_defined +#endif + +typedef _VSTD::remove_pointer::type __locale_struct; +typedef _VSTD::unique_ptr<__locale_struct, decltype(&freelocale)> __locale_unique_ptr; +typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii; + +// OSX has nice foo_l() functions that let you turn off use of the global +// locale. Linux, not so much. The following functions avoid the locale when +// that's possible and otherwise do the wrong thing. FIXME. +#ifdef __linux__ + +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS +decltype(MB_CUR_MAX_L(_VSTD::declval())) +inline _LIBCPP_INLINE_VISIBILITY +__mb_cur_max_l(locale_t __l) +{ + return MB_CUR_MAX_L(__l); +} +#else // _LIBCPP_LOCALE__L_EXTENSIONS +_LIBCPP_ALWAYS_INLINE inline +decltype(MB_CUR_MAX) __mb_cur_max_l(locale_t __l) +{ + __locale_raii __current(uselocale(__l), uselocale); + return MB_CUR_MAX; +} +#endif // _LIBCPP_LOCALE__L_EXTENSIONS + +_LIBCPP_ALWAYS_INLINE inline +wint_t __btowc_l(int __c, locale_t __l) +{ +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + return btowc_l(__c, __l); +#else + __locale_raii __current(uselocale(__l), uselocale); + return btowc(__c); +#endif +} + +_LIBCPP_ALWAYS_INLINE inline +int __wctob_l(wint_t __c, locale_t __l) +{ +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + return wctob_l(__c, __l); +#else + __locale_raii __current(uselocale(__l), uselocale); + return wctob(__c); +#endif +} + +_LIBCPP_ALWAYS_INLINE inline +size_t __wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc, + size_t __len, mbstate_t *__ps, locale_t __l) +{ +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + return wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __l); +#else + __locale_raii __current(uselocale(__l), uselocale); + return wcsnrtombs(__dest, __src, __nwc, __len, __ps); +#endif +} + +_LIBCPP_ALWAYS_INLINE inline +size_t __wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l) +{ +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + return wcrtomb_l(__s, __wc, __ps, __l); +#else + __locale_raii __current(uselocale(__l), uselocale); + return wcrtomb(__s, __wc, __ps); +#endif +} + +_LIBCPP_ALWAYS_INLINE inline +size_t __mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms, + size_t __len, mbstate_t *__ps, locale_t __l) +{ +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + return mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __l); +#else + __locale_raii __current(uselocale(__l), uselocale); + return mbsnrtowcs(__dest, __src, __nms, __len, __ps); +#endif +} + +_LIBCPP_ALWAYS_INLINE inline +size_t __mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n, + mbstate_t *__ps, locale_t __l) +{ +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + return mbrtowc_l(__pwc, __s, __n, __ps, __l); +#else + __locale_raii __current(uselocale(__l), uselocale); + return mbrtowc(__pwc, __s, __n, __ps); +#endif +} + +_LIBCPP_ALWAYS_INLINE inline +int __mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l) +{ +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + return mbtowc_l(__pwc, __pmb, __max, __l); +#else + __locale_raii __current(uselocale(__l), uselocale); + return mbtowc(__pwc, __pmb, __max); +#endif +} + +_LIBCPP_ALWAYS_INLINE inline +size_t __mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l) +{ +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + return mbrlen_l(__s, __n, __ps, __l); +#else + __locale_raii __current(uselocale(__l), uselocale); + return mbrlen(__s, __n, __ps); +#endif +} + +_LIBCPP_ALWAYS_INLINE inline +lconv *__localeconv_l(locale_t __l) +{ +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + return localeconv_l(__l); +#else + __locale_raii __current(uselocale(__l), uselocale); + return localeconv(); +#endif +} + +_LIBCPP_ALWAYS_INLINE inline +size_t __mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len, + mbstate_t *__ps, locale_t __l) +{ +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + return mbsrtowcs_l(__dest, __src, __len, __ps, __l); +#else + __locale_raii __current(uselocale(__l), uselocale); + return mbsrtowcs(__dest, __src, __len, __ps); +#endif +} + +_LIBCPP_ALWAYS_INLINE inline +int __sprintf_l(char *__s, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + int __res = vsprintf_l(__s, __l, __format, __va); +#else + __locale_raii __current(uselocale(__l), uselocale); + int __res = vsprintf(__s, __format, __va); +#endif + va_end(__va); + return __res; +} + +_LIBCPP_ALWAYS_INLINE inline +int __snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + int __res = vsnprintf_l(__s, __n, __l, __format, __va); +#else + __locale_raii __current(uselocale(__l), uselocale); + int __res = vsnprintf(__s, __n, __format, __va); +#endif + va_end(__va); + return __res; +} + +_LIBCPP_ALWAYS_INLINE inline +int __asprintf_l(char **__s, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + int __res = vasprintf_l(__s, __l, __format, __va); +#else + __locale_raii __current(uselocale(__l), uselocale); + int __res = vasprintf(__s, __format, __va); +#endif + va_end(__va); + return __res; +} + +_LIBCPP_ALWAYS_INLINE inline +int __sscanf_l(const char *__s, locale_t __l, const char *__format, ...) { + va_list __va; + va_start(__va, __format); +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + int __res = vsscanf_l(__s, __l, __format, __va); +#else + __locale_raii __current(uselocale(__l), uselocale); + int __res = vsscanf(__s, __format, __va); +#endif + va_end(__va); + return __res; +} + +#endif // __linux__ + +// __scan_keyword +// Scans [__b, __e) until a match is found in the basic_strings range +// [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke). +// __b will be incremented (visibly), consuming CharT until a match is found +// or proved to not exist. A keyword may be "", in which will match anything. +// If one keyword is a prefix of another, and the next CharT in the input +// might match another keyword, the algorithm will attempt to find the longest +// matching keyword. If the longer matching keyword ends up not matching, then +// no keyword match is found. If no keyword match is found, __ke is returned +// and failbit is set in __err. +// Else an iterator pointing to the matching keyword is found. If more than +// one keyword matches, an iterator to the first matching keyword is returned. +// If on exit __b == __e, eofbit is set in __err. If __case_senstive is false, +// __ct is used to force to lower case before comparing characters. +// Examples: +// Keywords: "a", "abb" +// If the input is "a", the first keyword matches and eofbit is set. +// If the input is "abc", no match is found and "ab" are consumed. +template +_LIBCPP_HIDDEN +_ForwardIterator +__scan_keyword(_InputIterator& __b, _InputIterator __e, + _ForwardIterator __kb, _ForwardIterator __ke, + const _Ctype& __ct, ios_base::iostate& __err, + bool __case_sensitive = true) +{ + typedef typename iterator_traits<_InputIterator>::value_type _CharT; + size_t __nkw = _VSTD::distance(__kb, __ke); + const unsigned char __doesnt_match = '\0'; + const unsigned char __might_match = '\1'; + const unsigned char __does_match = '\2'; + unsigned char __statbuf[100]; + unsigned char* __status = __statbuf; + unique_ptr __stat_hold(0, free); + if (__nkw > sizeof(__statbuf)) + { + __status = (unsigned char*)malloc(__nkw); + if (__status == 0) + __throw_bad_alloc(); + __stat_hold.reset(__status); + } + size_t __n_might_match = __nkw; // At this point, any keyword might match + size_t __n_does_match = 0; // but none of them definitely do + // Initialize all statuses to __might_match, except for "" keywords are __does_match + unsigned char* __st = __status; + for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st) + { + if (!__ky->empty()) + *__st = __might_match; + else + { + *__st = __does_match; + --__n_might_match; + ++__n_does_match; + } + } + // While there might be a match, test keywords against the next CharT + for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx) + { + // Peek at the next CharT but don't consume it + _CharT __c = *__b; + if (!__case_sensitive) + __c = __ct.toupper(__c); + bool __consume = false; + // For each keyword which might match, see if the __indx character is __c + // If a match if found, consume __c + // If a match is found, and that is the last character in the keyword, + // then that keyword matches. + // If the keyword doesn't match this character, then change the keyword + // to doesn't match + __st = __status; + for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st) + { + if (*__st == __might_match) + { + _CharT __kc = (*__ky)[__indx]; + if (!__case_sensitive) + __kc = __ct.toupper(__kc); + if (__c == __kc) + { + __consume = true; + if (__ky->size() == __indx+1) + { + *__st = __does_match; + --__n_might_match; + ++__n_does_match; + } + } + else + { + *__st = __doesnt_match; + --__n_might_match; + } + } + } + // consume if we matched a character + if (__consume) + { + ++__b; + // If we consumed a character and there might be a matched keyword that + // was marked matched on a previous iteration, then such keywords + // which are now marked as not matching. + if (__n_might_match + __n_does_match > 1) + { + __st = __status; + for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st) + { + if (*__st == __does_match && __ky->size() != __indx+1) + { + *__st = __doesnt_match; + --__n_does_match; + } + } + } + } + } + // We've exited the loop because we hit eof and/or we have no more "might matches". + if (__b == __e) + __err |= ios_base::eofbit; + // Return the first matching result + for (__st = __status; __kb != __ke; ++__kb, ++__st) + if (*__st == __does_match) + break; + if (__kb == __ke) + __err |= ios_base::failbit; + return __kb; +} + +struct __num_get_base +{ + static const int __num_get_buf_sz = 40; + + static int __get_base(ios_base&); + static const char __src[33]; +}; + +void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, + ios_base::iostate& __err); + +template +struct __num_get + : protected __num_get_base +{ + static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep); + static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, + _CharT& __thousands_sep); + static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, + unsigned& __dc, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, _CharT* __atoms); + static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, + char* __a, char*& __a_end, + _CharT __decimal_point, _CharT __thousands_sep, + const string& __grouping, unsigned* __g, + unsigned*& __g_end, unsigned& __dc, _CharT* __atoms); +}; + +template +string +__num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) +{ + locale __loc = __iob.getloc(); + use_facet >(__loc).widen(__src, __src + 26, __atoms); + const numpunct<_CharT>& __np = use_facet >(__loc); + __thousands_sep = __np.thousands_sep(); + return __np.grouping(); +} + +template +string +__num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, + _CharT& __thousands_sep) +{ + locale __loc = __iob.getloc(); + use_facet >(__loc).widen(__src, __src + 32, __atoms); + const numpunct<_CharT>& __np = use_facet >(__loc); + __decimal_point = __np.decimal_point(); + __thousands_sep = __np.thousands_sep(); + return __np.grouping(); +} + +template +int +__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, + unsigned& __dc, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, _CharT* __atoms) +{ + if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) + { + *__a_end++ = __ct == __atoms[24] ? '+' : '-'; + __dc = 0; + return 0; + } + if (__ct == __thousands_sep && __grouping.size() != 0) + { + if (__g_end-__g < __num_get_buf_sz) + { + *__g_end++ = __dc; + __dc = 0; + } + return 0; + } + ptrdiff_t __f = find(__atoms, __atoms + 26, __ct) - __atoms; + if (__f >= 24) + return -1; + switch (__base) + { + case 8: + case 10: + if (__f >= __base) + return -1; + break; + case 16: + if (__f < 22) + break; + if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0') + { + __dc = 0; + *__a_end++ = __src[__f]; + return 0; + } + return -1; + } + if (__a_end-__a < __num_get_buf_sz - 1) + *__a_end++ = __src[__f]; + ++__dc; + return 0; +} + +template +int +__num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end, + _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms) +{ + if (__ct == __decimal_point) + { + if (!__in_units) + return -1; + __in_units = false; + *__a_end++ = '.'; + if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) + *__g_end++ = __dc; + return 0; + } + if (__ct == __thousands_sep && __grouping.size() != 0) + { + if (!__in_units) + return -1; + if (__g_end-__g < __num_get_buf_sz) + { + *__g_end++ = __dc; + __dc = 0; + } + return 0; + } + ptrdiff_t __f = find(__atoms, __atoms + 32, __ct) - __atoms; + if (__f >= 32) + return -1; + char __x = __src[__f]; + if (__a_end-__a < __num_get_buf_sz - 1) + *__a_end++ = __x; + if (__x == 'x' || __x == 'X') + __exp = 'P'; + else if ((__x & 0xDF) == __exp) + { + __in_units = false; + if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) + *__g_end++ = __dc; + } + if (__f >= 22) + return 0; + ++__dc; + return 0; +} + +extern template class __num_get; +extern template class __num_get; + +template > +class _LIBCPP_VISIBLE num_get + : public locale::facet, + private __num_get<_CharT> +{ +public: + typedef _CharT char_type; + typedef _InputIterator iter_type; + + _LIBCPP_ALWAYS_INLINE + explicit num_get(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, bool& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long long& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned short& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned int& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned long& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned long long& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, float& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, double& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long double& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, void*& __v) const + { + return do_get(__b, __e, __iob, __err, __v); + } + + static locale::id id; + +protected: + _LIBCPP_ALWAYS_INLINE + ~num_get() {} + + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, bool& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long long& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned short& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned int& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned long& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, unsigned long long& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, float& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, double& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, long double& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, void*& __v) const; +}; + +template +locale::id +num_get<_CharT, _InputIterator>::id; + +template +_Tp +__num_get_signed_integral(const char* __a, const char* __a_end, + ios_base::iostate& __err, int __base) +{ + if (__a != __a_end) + { + int __save_errno = errno; + errno = 0; + char *__p2; + long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); + int __current_errno = errno; + if (__current_errno == 0) + errno = __save_errno; + if (__p2 != __a_end) + { + __err = ios_base::failbit; + return 0; + } + else if (__current_errno == ERANGE || + __ll < numeric_limits<_Tp>::min() || + numeric_limits<_Tp>::max() < __ll) + { + __err = ios_base::failbit; + if (__ll > 0) + return numeric_limits<_Tp>::max(); + else + return numeric_limits<_Tp>::min(); + } + return static_cast<_Tp>(__ll); + } + __err = ios_base::failbit; + return 0; +} + +template +_Tp +__num_get_unsigned_integral(const char* __a, const char* __a_end, + ios_base::iostate& __err, int __base) +{ + if (__a != __a_end) + { + if (*__a == '-') + { + __err = ios_base::failbit; + return 0; + } + int __save_errno = errno; + errno = 0; + char *__p2; + unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); + int __current_errno = errno; + if (__current_errno == 0) + errno = __save_errno; + if (__p2 != __a_end) + { + __err = ios_base::failbit; + return 0; + } + else if (__current_errno == ERANGE || + numeric_limits<_Tp>::max() < __ll) + { + __err = ios_base::failbit; + return numeric_limits<_Tp>::max(); + } + return static_cast<_Tp>(__ll); + } + __err = ios_base::failbit; + return 0; +} + +template +_Tp +__num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) +{ + if (__a != __a_end) + { + char *__p2; + long double __ld = strtold_l(__a, &__p2, _LIBCPP_GET_C_LOCALE); + if (__p2 != __a_end) + { + __err = ios_base::failbit; + return 0; + } + return static_cast<_Tp>(__ld); + } + __err = ios_base::failbit; + return 0; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + bool& __v) const +{ + if ((__iob.flags() & ios_base::boolalpha) == 0) + { + long __lv = -1; + __b = do_get(__b, __e, __iob, __err, __lv); + switch (__lv) + { + case 0: + __v = false; + break; + case 1: + __v = true; + break; + default: + __v = true; + __err = ios_base::failbit; + break; + } + return __b; + } + const ctype<_CharT>& __ct = use_facet >(__iob.getloc()); + const numpunct<_CharT>& __np = use_facet >(__iob.getloc()); + typedef typename numpunct<_CharT>::string_type string_type; + const string_type __names[2] = {__np.truename(), __np.falsename()}; + const string_type* __i = __scan_keyword(__b, __e, __names, __names+2, + __ct, __err); + __v = __i == __names; + return __b; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + long& __v) const +{ + // Stage 1 + int __base = this->__get_base(__iob); + // Stage 2 + char_type __atoms[26]; + char_type __thousands_sep; + string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); + char __a[__num_get_base::__num_get_buf_sz] = {0}; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + for (; __b != __e; ++__b) + if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, + __thousands_sep, __grouping, __g, __g_end, + __atoms)) + break; + if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_signed_integral(__a, __a_end, __err, __base); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + long long& __v) const +{ + // Stage 1 + int __base = this->__get_base(__iob); + // Stage 2 + char_type __atoms[26]; + char_type __thousands_sep; + string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); + char __a[__num_get_base::__num_get_buf_sz] = {0}; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + for (; __b != __e; ++__b) + if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, + __thousands_sep, __grouping, __g, __g_end, + __atoms)) + break; + if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_signed_integral(__a, __a_end, __err, __base); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + unsigned short& __v) const +{ + // Stage 1 + int __base = this->__get_base(__iob); + // Stage 2 + char_type __atoms[26]; + char_type __thousands_sep; + string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); + char __a[__num_get_base::__num_get_buf_sz] = {0}; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + for (; __b != __e; ++__b) + if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, + __thousands_sep, __grouping, __g, __g_end, + __atoms)) + break; + if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_unsigned_integral(__a, __a_end, __err, __base); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + unsigned int& __v) const +{ + // Stage 1 + int __base = this->__get_base(__iob); + // Stage 2 + char_type __atoms[26]; + char_type __thousands_sep; + string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); + char __a[__num_get_base::__num_get_buf_sz] = {0}; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + for (; __b != __e; ++__b) + if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, + __thousands_sep, __grouping, __g, __g_end, + __atoms)) + break; + if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_unsigned_integral(__a, __a_end, __err, __base); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + unsigned long& __v) const +{ + // Stage 1 + int __base = this->__get_base(__iob); + // Stage 2 + char_type __atoms[26]; + char_type __thousands_sep; + string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); + char __a[__num_get_base::__num_get_buf_sz] = {0}; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + for (; __b != __e; ++__b) + if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, + __thousands_sep, __grouping, __g, __g_end, + __atoms)) + break; + if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_unsigned_integral(__a, __a_end, __err, __base); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + unsigned long long& __v) const +{ + // Stage 1 + int __base = this->__get_base(__iob); + // Stage 2 + char_type __atoms[26]; + char_type __thousands_sep; + string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); + char __a[__num_get_base::__num_get_buf_sz] = {0}; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + for (; __b != __e; ++__b) + if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, + __thousands_sep, __grouping, __g, __g_end, + __atoms)) + break; + if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_unsigned_integral(__a, __a_end, __err, __base); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + float& __v) const +{ + // Stage 1, nothing to do + // Stage 2 + char_type __atoms[32]; + char_type __decimal_point; + char_type __thousands_sep; + string __grouping = this->__stage2_float_prep(__iob, __atoms, + __decimal_point, + __thousands_sep); + char __a[__num_get_base::__num_get_buf_sz] = {0}; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + bool __in_units = true; + char __exp = 'E'; + for (; __b != __e; ++__b) + if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, + __decimal_point, __thousands_sep, + __grouping, __g, __g_end, + __dc, __atoms)) + break; + if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_float(__a, __a_end, __err); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + double& __v) const +{ + // Stage 1, nothing to do + // Stage 2 + char_type __atoms[32]; + char_type __decimal_point; + char_type __thousands_sep; + string __grouping = this->__stage2_float_prep(__iob, __atoms, + __decimal_point, + __thousands_sep); + char __a[__num_get_base::__num_get_buf_sz] = {0}; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + bool __in_units = true; + char __exp = 'E'; + for (; __b != __e; ++__b) + if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, + __decimal_point, __thousands_sep, + __grouping, __g, __g_end, + __dc, __atoms)) + break; + if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_float(__a, __a_end, __err); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + long double& __v) const +{ + // Stage 1, nothing to do + // Stage 2 + char_type __atoms[32]; + char_type __decimal_point; + char_type __thousands_sep; + string __grouping = this->__stage2_float_prep(__iob, __atoms, + __decimal_point, + __thousands_sep); + char __a[__num_get_base::__num_get_buf_sz] = {0}; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + bool __in_units = true; + char __exp = 'E'; + for (; __b != __e; ++__b) + if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, + __decimal_point, __thousands_sep, + __grouping, __g, __g_end, + __dc, __atoms)) + break; + if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) + *__g_end++ = __dc; + // Stage 3 + __v = __num_get_float(__a, __a_end, __err); + // Digit grouping checked + __check_grouping(__grouping, __g, __g_end, __err); + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + void*& __v) const +{ + // Stage 1 + int __base = 16; + // Stage 2 + char_type __atoms[26]; + char_type __thousands_sep; + string __grouping; + use_facet >(__iob.getloc()).widen(__num_get_base::__src, + __num_get_base::__src + 26, __atoms); + char __a[__num_get_base::__num_get_buf_sz] = {0}; + char* __a_end = __a; + unsigned __g[__num_get_base::__num_get_buf_sz]; + unsigned* __g_end = __g; + unsigned __dc = 0; + for (; __b != __e; ++__b) + if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, + __thousands_sep, __grouping, + __g, __g_end, __atoms)) + break; + // Stage 3 + __a[sizeof(__a)-1] = 0; +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + if (sscanf_l(__a, _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1) +#else + if (__sscanf_l(__a, __cloc(), "%p", &__v) != 1) +#endif + __err = ios_base::failbit; + // EOF checked + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +extern template class num_get; +extern template class num_get; + +struct __num_put_base +{ +protected: + static void __format_int(char* __fmt, const char* __len, bool __signd, + ios_base::fmtflags __flags); + static bool __format_float(char* __fmt, const char* __len, + ios_base::fmtflags __flags); + static char* __identify_padding(char* __nb, char* __ne, + const ios_base& __iob); +}; + +template +struct __num_put + : protected __num_put_base +{ + static void __widen_and_group_int(char* __nb, char* __np, char* __ne, + _CharT* __ob, _CharT*& __op, _CharT*& __oe, + const locale& __loc); + static void __widen_and_group_float(char* __nb, char* __np, char* __ne, + _CharT* __ob, _CharT*& __op, _CharT*& __oe, + const locale& __loc); +}; + +template +void +__num_put<_CharT>::__widen_and_group_int(char* __nb, char* __np, char* __ne, + _CharT* __ob, _CharT*& __op, _CharT*& __oe, + const locale& __loc) +{ + const ctype<_CharT>& __ct = use_facet > (__loc); + const numpunct<_CharT>& __npt = use_facet >(__loc); + string __grouping = __npt.grouping(); + if (__grouping.empty()) + { + __ct.widen(__nb, __ne, __ob); + __oe = __ob + (__ne - __nb); + } + else + { + __oe = __ob; + char* __nf = __nb; + if (*__nf == '-' || *__nf == '+') + *__oe++ = __ct.widen(*__nf++); + if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || + __nf[1] == 'X')) + { + *__oe++ = __ct.widen(*__nf++); + *__oe++ = __ct.widen(*__nf++); + } + reverse(__nf, __ne); + _CharT __thousands_sep = __npt.thousands_sep(); + unsigned __dc = 0; + unsigned __dg = 0; + for (char* __p = __nf; __p < __ne; ++__p) + { + if (static_cast(__grouping[__dg]) > 0 && + __dc == static_cast(__grouping[__dg])) + { + *__oe++ = __thousands_sep; + __dc = 0; + if (__dg < __grouping.size()-1) + ++__dg; + } + *__oe++ = __ct.widen(*__p); + ++__dc; + } + reverse(__ob + (__nf - __nb), __oe); + } + if (__np == __ne) + __op = __oe; + else + __op = __ob + (__np - __nb); +} + +template +void +__num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne, + _CharT* __ob, _CharT*& __op, _CharT*& __oe, + const locale& __loc) +{ + const ctype<_CharT>& __ct = use_facet > (__loc); + const numpunct<_CharT>& __npt = use_facet >(__loc); + string __grouping = __npt.grouping(); + __oe = __ob; + char* __nf = __nb; + if (*__nf == '-' || *__nf == '+') + *__oe++ = __ct.widen(*__nf++); + char* __ns; + if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || + __nf[1] == 'X')) + { + *__oe++ = __ct.widen(*__nf++); + *__oe++ = __ct.widen(*__nf++); + for (__ns = __nf; __ns < __ne; ++__ns) + if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) + break; + } + else + { + for (__ns = __nf; __ns < __ne; ++__ns) + if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) + break; + } + if (__grouping.empty()) + { + __ct.widen(__nf, __ns, __oe); + __oe += __ns - __nf; + } + else + { + reverse(__nf, __ns); + _CharT __thousands_sep = __npt.thousands_sep(); + unsigned __dc = 0; + unsigned __dg = 0; + for (char* __p = __nf; __p < __ns; ++__p) + { + if (__grouping[__dg] > 0 && __dc == static_cast(__grouping[__dg])) + { + *__oe++ = __thousands_sep; + __dc = 0; + if (__dg < __grouping.size()-1) + ++__dg; + } + *__oe++ = __ct.widen(*__p); + ++__dc; + } + reverse(__ob + (__nf - __nb), __oe); + } + for (__nf = __ns; __nf < __ne; ++__nf) + { + if (*__nf == '.') + { + *__oe++ = __npt.decimal_point(); + ++__nf; + break; + } + else + *__oe++ = __ct.widen(*__nf); + } + __ct.widen(__nf, __ne, __oe); + __oe += __ne - __nf; + if (__np == __ne) + __op = __oe; + else + __op = __ob + (__np - __nb); +} + +extern template class __num_put; +extern template class __num_put; + +template > +class _LIBCPP_VISIBLE num_put + : public locale::facet, + private __num_put<_CharT> +{ +public: + typedef _CharT char_type; + typedef _OutputIterator iter_type; + + _LIBCPP_ALWAYS_INLINE + explicit num_put(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + bool __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + long __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + long long __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + unsigned long __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + unsigned long long __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + double __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + long double __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + const void* __v) const + { + return do_put(__s, __iob, __fl, __v); + } + + static locale::id id; + +protected: + _LIBCPP_ALWAYS_INLINE + ~num_put() {} + + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + bool __v) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + long __v) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + long long __v) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + unsigned long) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + unsigned long long) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + double __v) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + long double __v) const; + virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, + const void* __v) const; +}; + +template +locale::id +num_put<_CharT, _OutputIterator>::id; + +template +_LIBCPP_HIDDEN +_OutputIterator +__pad_and_output(_OutputIterator __s, + const _CharT* __ob, const _CharT* __op, const _CharT* __oe, + ios_base& __iob, _CharT __fl) +{ + streamsize __sz = __oe - __ob; + streamsize __ns = __iob.width(); + if (__ns > __sz) + __ns -= __sz; + else + __ns = 0; + for (;__ob < __op; ++__ob, ++__s) + *__s = *__ob; + for (; __ns; --__ns, ++__s) + *__s = __fl; + for (; __ob < __oe; ++__ob, ++__s) + *__s = *__ob; + __iob.width(0); + return __s; +} + +template +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, bool __v) const +{ + if ((__iob.flags() & ios_base::boolalpha) == 0) + return do_put(__s, __iob, __fl, (unsigned long)__v); + const numpunct& __np = use_facet >(__iob.getloc()); + typedef typename numpunct::string_type string_type; + string_type __nm = __v ? __np.truename() : __np.falsename(); + for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s) + *__s = *__i; + return __s; +} + +template +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, long __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[6] = {'%', 0}; + const char* __len = "l"; + this->__format_int(__fmt+1, __len, true, __iob.flags()); + const unsigned __nbuf = (numeric_limits::digits / 3) + + ((numeric_limits::digits % 3) != 0) + + 1; + char __nar[__nbuf]; +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); +#else + int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); +#endif + char* __ne = __nar + __nc; + char* __np = this->__identify_padding(__nar, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); +} + +template +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, long long __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[8] = {'%', 0}; + const char* __len = "ll"; + this->__format_int(__fmt+1, __len, true, __iob.flags()); + const unsigned __nbuf = (numeric_limits::digits / 3) + + ((numeric_limits::digits % 3) != 0) + + 1; + char __nar[__nbuf]; +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); +#else + int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); +#endif + char* __ne = __nar + __nc; + char* __np = this->__identify_padding(__nar, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); +} + +template +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, unsigned long __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[6] = {'%', 0}; + const char* __len = "l"; + this->__format_int(__fmt+1, __len, false, __iob.flags()); + const unsigned __nbuf = (numeric_limits::digits / 3) + + ((numeric_limits::digits % 3) != 0) + + 1; + char __nar[__nbuf]; +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); +#else + int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); +#endif + char* __ne = __nar + __nc; + char* __np = this->__identify_padding(__nar, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); +} + +template +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, unsigned long long __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[8] = {'%', 0}; + const char* __len = "ll"; + this->__format_int(__fmt+1, __len, false, __iob.flags()); + const unsigned __nbuf = (numeric_limits::digits / 3) + + ((numeric_limits::digits % 3) != 0) + + 1; + char __nar[__nbuf]; +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); +#else + int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); +#endif + char* __ne = __nar + __nc; + char* __np = this->__identify_padding(__nar, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); +} + +template +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, double __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[8] = {'%', 0}; + const char* __len = ""; + bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags()); + const unsigned __nbuf = 30; + char __nar[__nbuf]; + char* __nb = __nar; + int __nc; + if (__specify_precision) +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, + (int)__iob.precision(), __v); +#else + __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt, + (int)__iob.precision(), __v); +#endif + else +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); +#else + __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt, __v); +#endif + unique_ptr __nbh(0, free); + if (__nc > static_cast(__nbuf-1)) + { + if (__specify_precision) +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); +#else + __nc = __asprintf_l(&__nb, __cloc(), __fmt, + (int)__iob.precision(), __v); +#endif + else +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); +#else + __nc = __asprintf_l(&__nb, __cloc(), __fmt, (int)__iob.precision(), __v); +#endif + if (__nb == 0) + __throw_bad_alloc(); + __nbh.reset(__nb); + } + char* __ne = __nb + __nc; + char* __np = this->__identify_padding(__nb, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __ob = __o; + unique_ptr __obh(0, free); + if (__nb != __nar) + { + __ob = (char_type*)malloc((2*__nc)*sizeof(char_type)); + if (__ob == 0) + __throw_bad_alloc(); + __obh.reset(__ob); + } + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl); + return __s; +} + +template +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, long double __v) const +{ + // Stage 1 - Get number in narrow char + char __fmt[8] = {'%', 0}; + const char* __len = "L"; + bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags()); + const unsigned __nbuf = 30; + char __nar[__nbuf]; + char* __nb = __nar; + int __nc; + if (__specify_precision) +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, + (int)__iob.precision(), __v); +#else + __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt, + (int)__iob.precision(), __v); +#endif + else +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); +#else + __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt, __v); +#endif + unique_ptr __nbh(0, free); + if (__nc > static_cast(__nbuf-1)) + { + if (__specify_precision) +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); +#else + __nc = __asprintf_l(&__nb, __cloc(), __fmt, + (int)__iob.precision(), __v); +#endif + else +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); +#else + __nc = __asprintf_l(&__nb, __cloc(), __fmt, __v); +#endif + if (__nb == 0) + __throw_bad_alloc(); + __nbh.reset(__nb); + } + char* __ne = __nb + __nc; + char* __np = this->__identify_padding(__nb, __ne, __iob); + // Stage 2 - Widen __nar while adding thousands separators + char_type __o[2*(__nbuf-1) - 1]; + char_type* __ob = __o; + unique_ptr __obh(0, free); + if (__nb != __nar) + { + __ob = (char_type*)malloc((2*__nc)*sizeof(char_type)); + if (__ob == 0) + __throw_bad_alloc(); + __obh.reset(__ob); + } + char_type* __op; // pad here + char_type* __oe; // end of output + this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); + // [__o, __oe) contains thousands_sep'd wide number + // Stage 3 & 4 + __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl); + return __s; +} + +template +_OutputIterator +num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type __fl, const void* __v) const +{ + // Stage 1 - Get pointer in narrow char + char __fmt[6] = "%p"; + const unsigned __nbuf = 20; + char __nar[__nbuf]; +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); +#else + int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); +#endif + char* __ne = __nar + __nc; + char* __np = this->__identify_padding(__nar, __ne, __iob); + // Stage 2 - Widen __nar + char_type __o[2*(__nbuf-1) - 1]; + char_type* __op; // pad here + char_type* __oe; // end of output + const ctype& __ct = use_facet >(__iob.getloc()); + __ct.widen(__nar, __ne, __o); + __oe = __o + (__ne - __nar); + if (__np == __ne) + __op = __oe; + else + __op = __o + (__np - __nar); + // [__o, __oe) contains wide number + // Stage 3 & 4 + return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); +} + +extern template class num_put; +extern template class num_put; + +template +_LIBCPP_HIDDEN +int +__get_up_to_n_digits(_InputIterator& __b, _InputIterator __e, + ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n) +{ + // Precondition: __n >= 1 + if (__b == __e) + { + __err |= ios_base::eofbit | ios_base::failbit; + return 0; + } + // get first digit + _CharT __c = *__b; + if (!__ct.is(ctype_base::digit, __c)) + { + __err |= ios_base::failbit; + return 0; + } + int __r = __ct.narrow(__c, 0) - '0'; + for (++__b, --__n; __b != __e && __n > 0; ++__b, --__n) + { + // get next digit + __c = *__b; + if (!__ct.is(ctype_base::digit, __c)) + return __r; + __r = __r * 10 + __ct.narrow(__c, 0) - '0'; + } + if (__b == __e) + __err |= ios_base::eofbit; + return __r; +} + +class _LIBCPP_VISIBLE time_base +{ +public: + enum dateorder {no_order, dmy, mdy, ymd, ydm}; +}; + +template +class __time_get_c_storage // purposefully not decorated +{ +protected: + typedef basic_string<_CharT> string_type; + + virtual const string_type* __weeks() const; + virtual const string_type* __months() const; + virtual const string_type* __am_pm() const; + virtual const string_type& __c() const; + virtual const string_type& __r() const; + virtual const string_type& __x() const; + virtual const string_type& __X() const; +}; + +template > +class _LIBCPP_VISIBLE time_get + : public locale::facet, + public time_base, + private __time_get_c_storage<_CharT> +{ +public: + typedef _CharT char_type; + typedef _InputIterator iter_type; + typedef time_base::dateorder dateorder; + typedef basic_string string_type; + + _LIBCPP_ALWAYS_INLINE + explicit time_get(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE + dateorder date_order() const + { + return this->do_date_order(); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get_time(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const + { + return do_get_time(__b, __e, __iob, __err, __tm); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get_date(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const + { + return do_get_date(__b, __e, __iob, __err, __tm); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get_weekday(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const + { + return do_get_weekday(__b, __e, __iob, __err, __tm); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get_monthname(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const + { + return do_get_monthname(__b, __e, __iob, __err, __tm); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get_year(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const + { + return do_get_year(__b, __e, __iob, __err, __tm); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm *__tm, + char __fmt, char __mod = 0) const + { + return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod); + } + + iter_type get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm, + const char_type* __fmtb, const char_type* __fmte) const; + + static locale::id id; + +protected: + _LIBCPP_ALWAYS_INLINE + ~time_get() {} + + virtual dateorder do_date_order() const; + virtual iter_type do_get_time(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const; + virtual iter_type do_get_date(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const; + virtual iter_type do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const; + virtual iter_type do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const; + virtual iter_type do_get_year(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm) const; + virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, tm* __tm, + char __fmt, char __mod) const; +private: + void __get_white_space(iter_type& __b, iter_type __e, + ios_base::iostate& __err, const ctype& __ct) const; + void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, + const ctype& __ct) const; + + void __get_weekdayname(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_monthname(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_day(int& __d, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_month(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_year(int& __y, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_year4(int& __y, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_hour(int& __d, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_12_hour(int& __h, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_am_pm(int& __h, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_minute(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_second(int& __s, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_weekday(int& __w, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; + void __get_day_year_num(int& __w, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const; +}; + +template +locale::id +time_get<_CharT, _InputIterator>::id; + +// time_get primatives + +template +void +time_get<_CharT, _InputIterator>::__get_weekdayname(int& __w, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + // Note: ignoring case comes from the POSIX strptime spec + const string_type* __wk = this->__weeks(); + int __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk; + if (__i < 14) + __w = __i % 7; +} + +template +void +time_get<_CharT, _InputIterator>::__get_monthname(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + // Note: ignoring case comes from the POSIX strptime spec + const string_type* __month = this->__months(); + int __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month; + if (__i < 24) + __m = __i % 12; +} + +template +void +time_get<_CharT, _InputIterator>::__get_day(int& __d, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); + if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31) + __d = __t; + else + __err |= ios_base::failbit; +} + +template +void +time_get<_CharT, _InputIterator>::__get_month(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1; + if (!(__err & ios_base::failbit) && __t <= 11) + __m = __t; + else + __err |= ios_base::failbit; +} + +template +void +time_get<_CharT, _InputIterator>::__get_year(int& __y, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4); + if (!(__err & ios_base::failbit)) + { + if (__t < 69) + __t += 2000; + else if (69 <= __t && __t <= 99) + __t += 1900; + __y = __t - 1900; + } +} + +template +void +time_get<_CharT, _InputIterator>::__get_year4(int& __y, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4); + if (!(__err & ios_base::failbit)) + __y = __t - 1900; +} + +template +void +time_get<_CharT, _InputIterator>::__get_hour(int& __h, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); + if (!(__err & ios_base::failbit) && __t <= 23) + __h = __t; + else + __err |= ios_base::failbit; +} + +template +void +time_get<_CharT, _InputIterator>::__get_12_hour(int& __h, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); + if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12) + __h = __t; + else + __err |= ios_base::failbit; +} + +template +void +time_get<_CharT, _InputIterator>::__get_minute(int& __m, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); + if (!(__err & ios_base::failbit) && __t <= 59) + __m = __t; + else + __err |= ios_base::failbit; +} + +template +void +time_get<_CharT, _InputIterator>::__get_second(int& __s, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); + if (!(__err & ios_base::failbit) && __t <= 60) + __s = __t; + else + __err |= ios_base::failbit; +} + +template +void +time_get<_CharT, _InputIterator>::__get_weekday(int& __w, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 1); + if (!(__err & ios_base::failbit) && __t <= 6) + __w = __t; + else + __err |= ios_base::failbit; +} + +template +void +time_get<_CharT, _InputIterator>::__get_day_year_num(int& __d, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 3); + if (!(__err & ios_base::failbit) && __t <= 365) + __d = __t; + else + __err |= ios_base::failbit; +} + +template +void +time_get<_CharT, _InputIterator>::__get_white_space(iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) + ; + if (__b == __e) + __err |= ios_base::eofbit; +} + +template +void +time_get<_CharT, _InputIterator>::__get_am_pm(int& __h, + iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + const string_type* __ap = this->__am_pm(); + if (__ap[0].size() + __ap[1].size() == 0) + { + __err |= ios_base::failbit; + return; + } + int __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap; + if (__i == 0 && __h == 12) + __h = 0; + else if (__i == 1 && __h < 12) + __h += 12; +} + +template +void +time_get<_CharT, _InputIterator>::__get_percent(iter_type& __b, iter_type __e, + ios_base::iostate& __err, + const ctype& __ct) const +{ + if (__b == __e) + { + __err |= ios_base::eofbit | ios_base::failbit; + return; + } + if (__ct.narrow(*__b, 0) != '%') + __err |= ios_base::failbit; + else if(++__b == __e) + __err |= ios_base::eofbit; +} + +// time_get end primatives + +template +_InputIterator +time_get<_CharT, _InputIterator>::get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, tm* __tm, + const char_type* __fmtb, const char_type* __fmte) const +{ + const ctype& __ct = use_facet >(__iob.getloc()); + __err = ios_base::goodbit; + while (__fmtb != __fmte && __err == ios_base::goodbit) + { + if (__b == __e) + { + __err = ios_base::failbit; + break; + } + if (__ct.narrow(*__fmtb, 0) == '%') + { + if (++__fmtb == __fmte) + { + __err = ios_base::failbit; + break; + } + char __cmd = __ct.narrow(*__fmtb, 0); + char __opt = '\0'; + if (__cmd == 'E' || __cmd == '0') + { + if (++__fmtb == __fmte) + { + __err = ios_base::failbit; + break; + } + __opt = __cmd; + __cmd = __ct.narrow(*__fmtb, 0); + } + __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt); + ++__fmtb; + } + else if (__ct.is(ctype_base::space, *__fmtb)) + { + for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb) + ; + for ( ; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) + ; + } + else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb)) + { + ++__b; + ++__fmtb; + } + else + __err = ios_base::failbit; + } + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +typename time_get<_CharT, _InputIterator>::dateorder +time_get<_CharT, _InputIterator>::do_date_order() const +{ + return mdy; +} + +template +_InputIterator +time_get<_CharT, _InputIterator>::do_get_time(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + tm* __tm) const +{ + const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; + return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0])); +} + +template +_InputIterator +time_get<_CharT, _InputIterator>::do_get_date(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + tm* __tm) const +{ + const ctype& __ct = use_facet >(__iob.getloc()); + const string_type& __fmt = this->__x(); + return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size()); +} + +template +_InputIterator +time_get<_CharT, _InputIterator>::do_get_weekday(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + tm* __tm) const +{ + const ctype& __ct = use_facet >(__iob.getloc()); + __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct); + return __b; +} + +template +_InputIterator +time_get<_CharT, _InputIterator>::do_get_monthname(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + tm* __tm) const +{ + const ctype& __ct = use_facet >(__iob.getloc()); + __get_monthname(__tm->tm_mon, __b, __e, __err, __ct); + return __b; +} + +template +_InputIterator +time_get<_CharT, _InputIterator>::do_get_year(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + tm* __tm) const +{ + const ctype& __ct = use_facet >(__iob.getloc()); + __get_year(__tm->tm_year, __b, __e, __err, __ct); + return __b; +} + +template +_InputIterator +time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, tm* __tm, + char __fmt, char) const +{ + __err = ios_base::goodbit; + const ctype& __ct = use_facet >(__iob.getloc()); + switch (__fmt) + { + case 'a': + case 'A': + __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct); + break; + case 'b': + case 'B': + case 'h': + __get_monthname(__tm->tm_mon, __b, __e, __err, __ct); + break; + case 'c': + { + const string_type& __fmt = this->__c(); + __b = get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size()); + } + break; + case 'd': + case 'e': + __get_day(__tm->tm_mday, __b, __e, __err, __ct); + break; + case 'D': + { + const char_type __fmt[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'}; + __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0])); + } + break; + case 'F': + { + const char_type __fmt[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'}; + __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0])); + } + break; + case 'H': + __get_hour(__tm->tm_hour, __b, __e, __err, __ct); + break; + case 'I': + __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct); + break; + case 'j': + __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct); + break; + case 'm': + __get_month(__tm->tm_mon, __b, __e, __err, __ct); + break; + case 'M': + __get_minute(__tm->tm_min, __b, __e, __err, __ct); + break; + case 'n': + case 't': + __get_white_space(__b, __e, __err, __ct); + break; + case 'p': + __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct); + break; + case 'r': + { + const char_type __fmt[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'}; + __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0])); + } + break; + case 'R': + { + const char_type __fmt[] = {'%', 'H', ':', '%', 'M'}; + __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0])); + } + break; + case 'S': + __get_second(__tm->tm_sec, __b, __e, __err, __ct); + break; + case 'T': + { + const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; + __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0])); + } + break; + case 'w': + __get_weekday(__tm->tm_wday, __b, __e, __err, __ct); + break; + case 'x': + return do_get_date(__b, __e, __iob, __err, __tm); + case 'X': + { + const string_type& __fmt = this->__X(); + __b = get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size()); + } + break; + case 'y': + __get_year(__tm->tm_year, __b, __e, __err, __ct); + break; + case 'Y': + __get_year4(__tm->tm_year, __b, __e, __err, __ct); + break; + case '%': + __get_percent(__b, __e, __err, __ct); + break; + default: + __err |= ios_base::failbit; + } + return __b; +} + +extern template class time_get; +extern template class time_get; + +class __time_get +{ +protected: + locale_t __loc_; + + __time_get(const char* __nm); + __time_get(const string& __nm); + ~__time_get(); +}; + +template +class __time_get_storage + : public __time_get +{ +protected: + typedef basic_string<_CharT> string_type; + + string_type __weeks_[14]; + string_type __months_[24]; + string_type __am_pm_[2]; + string_type __c_; + string_type __r_; + string_type __x_; + string_type __X_; + + explicit __time_get_storage(const char* __nm); + explicit __time_get_storage(const string& __nm); + + _LIBCPP_ALWAYS_INLINE ~__time_get_storage() {} + + time_base::dateorder __do_date_order() const; + +private: + void init(const ctype<_CharT>&); + string_type __analyze(char __fmt, const ctype<_CharT>&); +}; + +template > +class _LIBCPP_VISIBLE time_get_byname + : public time_get<_CharT, _InputIterator>, + private __time_get_storage<_CharT> +{ +public: + typedef time_base::dateorder dateorder; + typedef _InputIterator iter_type; + typedef _CharT char_type; + typedef basic_string string_type; + + _LIBCPP_INLINE_VISIBILITY + explicit time_get_byname(const char* __nm, size_t __refs = 0) + : time_get<_CharT, _InputIterator>(__refs), + __time_get_storage<_CharT>(__nm) {} + _LIBCPP_INLINE_VISIBILITY + explicit time_get_byname(const string& __nm, size_t __refs = 0) + : time_get<_CharT, _InputIterator>(__refs), + __time_get_storage<_CharT>(__nm) {} + +protected: + _LIBCPP_INLINE_VISIBILITY + ~time_get_byname() {} + + _LIBCPP_INLINE_VISIBILITY + virtual dateorder do_date_order() const {return this->__do_date_order();} +private: + _LIBCPP_INLINE_VISIBILITY + virtual const string_type* __weeks() const {return this->__weeks_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type* __months() const {return this->__months_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type* __am_pm() const {return this->__am_pm_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type& __c() const {return this->__c_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type& __r() const {return this->__r_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type& __x() const {return this->__x_;} + _LIBCPP_INLINE_VISIBILITY + virtual const string_type& __X() const {return this->__X_;} +}; + +extern template class time_get_byname; +extern template class time_get_byname; + +class __time_put +{ + locale_t __loc_; +protected: + _LIBCPP_ALWAYS_INLINE __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {} + __time_put(const char* __nm); + __time_put(const string& __nm); + ~__time_put(); + void __do_put(char* __nb, char*& __ne, const tm* __tm, + char __fmt, char __mod) const; + void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, + char __fmt, char __mod) const; +}; + +template > +class _LIBCPP_VISIBLE time_put + : public locale::facet, + private __time_put +{ +public: + typedef _CharT char_type; + typedef _OutputIterator iter_type; + + _LIBCPP_ALWAYS_INLINE + explicit time_put(size_t __refs = 0) + : locale::facet(__refs) {} + + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, + const char_type* __pb, const char_type* __pe) const; + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, ios_base& __iob, char_type __fl, + const tm* __tm, char __fmt, char __mod = 0) const + { + return do_put(__s, __iob, __fl, __tm, __fmt, __mod); + } + + static locale::id id; + +protected: + _LIBCPP_ALWAYS_INLINE + ~time_put() {} + virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm, + char __fmt, char __mod) const; + + _LIBCPP_ALWAYS_INLINE + explicit time_put(const char* __nm, size_t __refs) + : locale::facet(__refs), + __time_put(__nm) {} + _LIBCPP_ALWAYS_INLINE + explicit time_put(const string& __nm, size_t __refs) + : locale::facet(__refs), + __time_put(__nm) {} +}; + +template +locale::id +time_put<_CharT, _OutputIterator>::id; + +template +_OutputIterator +time_put<_CharT, _OutputIterator>::put(iter_type __s, ios_base& __iob, + char_type __fl, const tm* __tm, + const char_type* __pb, + const char_type* __pe) const +{ + const ctype& __ct = use_facet >(__iob.getloc()); + for (; __pb != __pe; ++__pb) + { + if (__ct.narrow(*__pb, 0) == '%') + { + if (++__pb == __pe) + { + *__s++ = __pb[-1]; + break; + } + char __mod = 0; + char __fmt = __ct.narrow(*__pb, 0); + if (__fmt == 'E' || __fmt == 'O') + { + if (++__pb == __pe) + { + *__s++ = __pb[-2]; + *__s++ = __pb[-1]; + break; + } + __mod = __fmt; + __fmt = __ct.narrow(*__pb, 0); + } + __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod); + } + else + *__s++ = *__pb; + } + return __s; +} + +template +_OutputIterator +time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + char_type, const tm* __tm, + char __fmt, char __mod) const +{ + char_type __nar[100]; + char_type* __nb = __nar; + char_type* __ne = __nb + 100; + __do_put(__nb, __ne, __tm, __fmt, __mod); + return _VSTD::copy(__nb, __ne, __s); +} + +extern template class time_put; +extern template class time_put; + +template > +class _LIBCPP_VISIBLE time_put_byname + : public time_put<_CharT, _OutputIterator> +{ +public: + _LIBCPP_ALWAYS_INLINE + explicit time_put_byname(const char* __nm, size_t __refs = 0) + : time_put<_CharT, _OutputIterator>(__nm, __refs) {} + + _LIBCPP_ALWAYS_INLINE + explicit time_put_byname(const string& __nm, size_t __refs = 0) + : time_put<_CharT, _OutputIterator>(__nm, __refs) {} + +protected: + _LIBCPP_ALWAYS_INLINE + ~time_put_byname() {} +}; + +extern template class time_put_byname; +extern template class time_put_byname; + +// money_base + +class _LIBCPP_VISIBLE money_base +{ +public: + enum part {none, space, symbol, sign, value}; + struct pattern {char field[4];}; + + _LIBCPP_ALWAYS_INLINE money_base() {} +}; + +// moneypunct + +template +class _LIBCPP_VISIBLE moneypunct + : public locale::facet, + public money_base +{ +public: + typedef _CharT char_type; + typedef basic_string string_type; + + _LIBCPP_ALWAYS_INLINE + explicit moneypunct(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();} + _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();} + _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();} + _LIBCPP_ALWAYS_INLINE string_type curr_symbol() const {return do_curr_symbol();} + _LIBCPP_ALWAYS_INLINE string_type positive_sign() const {return do_positive_sign();} + _LIBCPP_ALWAYS_INLINE string_type negative_sign() const {return do_negative_sign();} + _LIBCPP_ALWAYS_INLINE int frac_digits() const {return do_frac_digits();} + _LIBCPP_ALWAYS_INLINE pattern pos_format() const {return do_pos_format();} + _LIBCPP_ALWAYS_INLINE pattern neg_format() const {return do_neg_format();} + + static locale::id id; + static const bool intl = _International; + +protected: + _LIBCPP_ALWAYS_INLINE + ~moneypunct() {} + + virtual char_type do_decimal_point() const {return numeric_limits::max();} + virtual char_type do_thousands_sep() const {return numeric_limits::max();} + virtual string do_grouping() const {return string();} + virtual string_type do_curr_symbol() const {return string_type();} + virtual string_type do_positive_sign() const {return string_type();} + virtual string_type do_negative_sign() const {return string_type(1, '-');} + virtual int do_frac_digits() const {return 0;} + virtual pattern do_pos_format() const + {pattern __p = {symbol, sign, none, value}; return __p;} + virtual pattern do_neg_format() const + {pattern __p = {symbol, sign, none, value}; return __p;} +}; + +template +locale::id +moneypunct<_CharT, _International>::id; + +extern template class moneypunct; +extern template class moneypunct; +extern template class moneypunct; +extern template class moneypunct; + +// moneypunct_byname + +template +class _LIBCPP_VISIBLE moneypunct_byname + : public moneypunct<_CharT, _International> +{ +public: + typedef money_base::pattern pattern; + typedef _CharT char_type; + typedef basic_string string_type; + + _LIBCPP_ALWAYS_INLINE + explicit moneypunct_byname(const char* __nm, size_t __refs = 0) + : moneypunct<_CharT, _International>(__refs) {init(__nm);} + + _LIBCPP_ALWAYS_INLINE + explicit moneypunct_byname(const string& __nm, size_t __refs = 0) + : moneypunct<_CharT, _International>(__refs) {init(__nm.c_str());} + +protected: + _LIBCPP_ALWAYS_INLINE + ~moneypunct_byname() {} + + virtual char_type do_decimal_point() const {return __decimal_point_;} + virtual char_type do_thousands_sep() const {return __thousands_sep_;} + virtual string do_grouping() const {return __grouping_;} + virtual string_type do_curr_symbol() const {return __curr_symbol_;} + virtual string_type do_positive_sign() const {return __positive_sign_;} + virtual string_type do_negative_sign() const {return __negative_sign_;} + virtual int do_frac_digits() const {return __frac_digits_;} + virtual pattern do_pos_format() const {return __pos_format_;} + virtual pattern do_neg_format() const {return __neg_format_;} + +private: + char_type __decimal_point_; + char_type __thousands_sep_; + string __grouping_; + string_type __curr_symbol_; + string_type __positive_sign_; + string_type __negative_sign_; + int __frac_digits_; + pattern __pos_format_; + pattern __neg_format_; + + void init(const char*); +}; + +template<> void moneypunct_byname::init(const char*); +template<> void moneypunct_byname::init(const char*); +template<> void moneypunct_byname::init(const char*); +template<> void moneypunct_byname::init(const char*); + +extern template class moneypunct_byname; +extern template class moneypunct_byname; +extern template class moneypunct_byname; +extern template class moneypunct_byname; + +// money_get + +template +class __money_get +{ +protected: + typedef _CharT char_type; + typedef basic_string string_type; + + _LIBCPP_ALWAYS_INLINE __money_get() {} + + static void __gather_info(bool __intl, const locale& __loc, + money_base::pattern& __pat, char_type& __dp, + char_type& __ts, string& __grp, + string_type& __sym, string_type& __psn, + string_type& __nsn, int& __fd); +}; + +template +void +__money_get<_CharT>::__gather_info(bool __intl, const locale& __loc, + money_base::pattern& __pat, char_type& __dp, + char_type& __ts, string& __grp, + string_type& __sym, string_type& __psn, + string_type& __nsn, int& __fd) +{ + if (__intl) + { + const moneypunct& __mp = + use_facet >(__loc); + __pat = __mp.neg_format(); + __nsn = __mp.negative_sign(); + __psn = __mp.positive_sign(); + __dp = __mp.decimal_point(); + __ts = __mp.thousands_sep(); + __grp = __mp.grouping(); + __sym = __mp.curr_symbol(); + __fd = __mp.frac_digits(); + } + else + { + const moneypunct& __mp = + use_facet >(__loc); + __pat = __mp.neg_format(); + __nsn = __mp.negative_sign(); + __psn = __mp.positive_sign(); + __dp = __mp.decimal_point(); + __ts = __mp.thousands_sep(); + __grp = __mp.grouping(); + __sym = __mp.curr_symbol(); + __fd = __mp.frac_digits(); + } +} + +extern template class __money_get; +extern template class __money_get; + +template > +class _LIBCPP_VISIBLE money_get + : public locale::facet, + private __money_get<_CharT> +{ +public: + typedef _CharT char_type; + typedef _InputIterator iter_type; + typedef basic_string string_type; + + _LIBCPP_ALWAYS_INLINE + explicit money_get(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, + ios_base::iostate& __err, long double& __v) const + { + return do_get(__b, __e, __intl, __iob, __err, __v); + } + + _LIBCPP_ALWAYS_INLINE + iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, + ios_base::iostate& __err, string_type& __v) const + { + return do_get(__b, __e, __intl, __iob, __err, __v); + } + + static locale::id id; + +protected: + + _LIBCPP_ALWAYS_INLINE + ~money_get() {} + + virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl, + ios_base& __iob, ios_base::iostate& __err, + long double& __v) const; + virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl, + ios_base& __iob, ios_base::iostate& __err, + string_type& __v) const; + +private: + static bool __do_get(iter_type& __b, iter_type __e, + bool __intl, const locale& __loc, + ios_base::fmtflags __flags, ios_base::iostate& __err, + bool& __neg, const ctype& __ct, + unique_ptr& __wb, + char_type*& __wn, char_type* __we); +}; + +template +locale::id +money_get<_CharT, _InputIterator>::id; + +void __do_nothing(void*); + +template +_LIBCPP_HIDDEN +void +__double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e) +{ + bool __owns = __b.get_deleter() != __do_nothing; + size_t __cur_cap = (__e-__b.get()) * sizeof(_Tp); + size_t __new_cap = __cur_cap < numeric_limits::max() / 2 ? + 2 * __cur_cap : numeric_limits::max(); + size_t __n_off = __n - __b.get(); + _Tp* __t = (_Tp*)realloc(__owns ? __b.get() : 0, __new_cap); + if (__t == 0) + __throw_bad_alloc(); + if (__owns) + __b.release(); + __b = unique_ptr<_Tp, void(*)(void*)>(__t, free); + __new_cap /= sizeof(_Tp); + __n = __b.get() + __n_off; + __e = __b.get() + __new_cap; +} + +// true == success +template +bool +money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e, + bool __intl, const locale& __loc, + ios_base::fmtflags __flags, + ios_base::iostate& __err, + bool& __neg, + const ctype& __ct, + unique_ptr& __wb, + char_type*& __wn, char_type* __we) +{ + const unsigned __bz = 100; + unsigned __gbuf[__bz]; + unique_ptr __gb(__gbuf, __do_nothing); + unsigned* __gn = __gb.get(); + unsigned* __ge = __gn + __bz; + money_base::pattern __pat; + char_type __dp; + char_type __ts; + string __grp; + string_type __sym; + string_type __psn; + string_type __nsn; + int __fd; + __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp, + __sym, __psn, __nsn, __fd); + const string_type* __trailing_sign = 0; + __wn = __wb.get(); + for (unsigned __p = 0; __p < 4 && __b != __e; ++__p) + { + switch (__pat.field[__p]) + { + case money_base::space: + if (__p != 3) + { + if (__ct.is(ctype_base::space, *__b)) + ++__b; + else + { + __err |= ios_base::failbit; + return false; + } + } + // drop through + case money_base::none: + if (__p != 3) + { + while (__b != __e && __ct.is(ctype_base::space, *__b)) + ++__b; + } + break; + case money_base::sign: + if (__psn.size() + __nsn.size() > 0) + { + if (__psn.size() == 0 || __nsn.size() == 0) + { // sign is optional + if (__psn.size() > 0) + { // __nsn.size() == 0 + if (*__b == __psn[0]) + { + ++__b; + if (__psn.size() > 1) + __trailing_sign = &__psn; + } + else + __neg = true; + } + else if (*__b == __nsn[0]) // __nsn.size() > 0 && __psn.size() == 0 + { + ++__b; + __neg = true; + if (__nsn.size() > 1) + __trailing_sign = &__nsn; + } + } + else // sign is required + { + if (*__b == __psn[0]) + { + ++__b; + if (__psn.size() > 1) + __trailing_sign = &__psn; + } + else if (*__b == __nsn[0]) + { + ++__b; + __neg = true; + if (__nsn.size() > 1) + __trailing_sign = &__nsn; + } + else + { + __err |= ios_base::failbit; + return false; + } + } + } + break; + case money_base::symbol: + { + bool __more_needed = __trailing_sign || + (__p < 2) || + (__p == 2 && __pat.field[3] != static_cast(money_base::none)); + bool __sb = __flags & ios_base::showbase; + if (__sb || __more_needed) + { + ios_base::iostate __et = ios_base::goodbit; + string_type* __k = __scan_keyword(__b, __e, &__sym, &__sym+1, + __ct, __et); + if (__sb && __k != &__sym) + { + __err |= ios_base::failbit; + return false; + } + } + } + break; + case money_base::value: + { + unsigned __ng = 0; + for (; __b != __e; ++__b) + { + char_type __c = *__b; + if (__ct.is(ctype_base::digit, __c)) + { + if (__wn == __we) + __double_or_nothing(__wb, __wn, __we); + *__wn++ = __c; + ++__ng; + } + else if (__grp.size() > 0 && __ng > 0 && __c == __ts) + { + if (__gn == __ge) + __double_or_nothing(__gb, __gn, __ge); + *__gn++ = __ng; + __ng = 0; + } + else + break; + } + if (__gb.get() != __gn && __ng > 0) + { + if (__gn == __ge) + __double_or_nothing(__gb, __gn, __ge); + *__gn++ = __ng; + } + if (__fd > 0) + { + if (__b == __e || *__b != __dp) + { + __err |= ios_base::failbit; + return false; + } + for (++__b; __fd > 0; --__fd, ++__b) + { + if (__b == __e || !__ct.is(ctype_base::digit, *__b)) + { + __err |= ios_base::failbit; + return false; + } + if (__wn == __we) + __double_or_nothing(__wb, __wn, __we); + *__wn++ = *__b; + } + } + if (__wn == __wb.get()) + { + __err |= ios_base::failbit; + return false; + } + } + break; + } + } + if (__trailing_sign) + { + for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b) + { + if (__b == __e || *__b != (*__trailing_sign)[__i]) + { + __err |= ios_base::failbit; + return false; + } + } + } + if (__gb.get() != __gn) + { + ios_base::iostate __et = ios_base::goodbit; + __check_grouping(__grp, __gb.get(), __gn, __et); + if (__et) + { + __err |= ios_base::failbit; + return false; + } + } + return true; +} + +template +_InputIterator +money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + bool __intl, ios_base& __iob, + ios_base::iostate& __err, + long double& __v) const +{ + const unsigned __bz = 100; + char_type __wbuf[__bz]; + unique_ptr __wb(__wbuf, __do_nothing); + char_type* __wn; + char_type* __we = __wbuf + __bz; + locale __loc = __iob.getloc(); + const ctype& __ct = use_facet >(__loc); + bool __neg = false; + if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, + __wb, __wn, __we)) + { + const char __src[] = "0123456789"; + char_type __atoms[sizeof(__src)-1]; + __ct.widen(__src, __src + (sizeof(__src)-1), __atoms); + char __nbuf[__bz]; + char* __nc = __nbuf; + unique_ptr __h(0, free); + if (__wn - __wb.get() > __bz-2) + { + __h.reset((char*)malloc(__wn - __wb.get() + 2)); + if (__h.get() == 0) + __throw_bad_alloc(); + __nc = __h.get(); + } + if (__neg) + *__nc++ = '-'; + for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc) + *__nc = __src[find(__atoms, __atoms+sizeof(__atoms), *__w) - __atoms]; + *__nc = char(); + if (sscanf(__nbuf, "%Lf", &__v) != 1) + __throw_runtime_error("money_get error"); + } + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +template +_InputIterator +money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + bool __intl, ios_base& __iob, + ios_base::iostate& __err, + string_type& __v) const +{ + const unsigned __bz = 100; + char_type __wbuf[__bz]; + unique_ptr __wb(__wbuf, __do_nothing); + char_type* __wn; + char_type* __we = __wbuf + __bz; + locale __loc = __iob.getloc(); + const ctype& __ct = use_facet >(__loc); + bool __neg = false; + if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, + __wb, __wn, __we)) + { + __v.clear(); + if (__neg) + __v.push_back(__ct.widen('-')); + char_type __z = __ct.widen('0'); + char_type* __w; + for (__w = __wb.get(); __w < __wn-1; ++__w) + if (*__w != __z) + break; + __v.append(__w, __wn); + } + if (__b == __e) + __err |= ios_base::eofbit; + return __b; +} + +extern template class money_get; +extern template class money_get; + +// money_put + +template +class __money_put +{ +protected: + typedef _CharT char_type; + typedef basic_string string_type; + + _LIBCPP_ALWAYS_INLINE __money_put() {} + + static void __gather_info(bool __intl, bool __neg, const locale& __loc, + money_base::pattern& __pat, char_type& __dp, + char_type& __ts, string& __grp, + string_type& __sym, string_type& __sn, + int& __fd); + static void __format(char_type* __mb, char_type*& __mi, char_type*& __me, + ios_base::fmtflags __flags, + const char_type* __db, const char_type* __de, + const ctype& __ct, bool __neg, + const money_base::pattern& __pat, char_type __dp, + char_type __ts, const string& __grp, + const string_type& __sym, const string_type& __sn, + int __fd); +}; + +template +void +__money_put<_CharT>::__gather_info(bool __intl, bool __neg, const locale& __loc, + money_base::pattern& __pat, char_type& __dp, + char_type& __ts, string& __grp, + string_type& __sym, string_type& __sn, + int& __fd) +{ + if (__intl) + { + const moneypunct& __mp = + use_facet >(__loc); + if (__neg) + { + __pat = __mp.neg_format(); + __sn = __mp.negative_sign(); + } + else + { + __pat = __mp.pos_format(); + __sn = __mp.positive_sign(); + } + __dp = __mp.decimal_point(); + __ts = __mp.thousands_sep(); + __grp = __mp.grouping(); + __sym = __mp.curr_symbol(); + __fd = __mp.frac_digits(); + } + else + { + const moneypunct& __mp = + use_facet >(__loc); + if (__neg) + { + __pat = __mp.neg_format(); + __sn = __mp.negative_sign(); + } + else + { + __pat = __mp.pos_format(); + __sn = __mp.positive_sign(); + } + __dp = __mp.decimal_point(); + __ts = __mp.thousands_sep(); + __grp = __mp.grouping(); + __sym = __mp.curr_symbol(); + __fd = __mp.frac_digits(); + } +} + +template +void +__money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __me, + ios_base::fmtflags __flags, + const char_type* __db, const char_type* __de, + const ctype& __ct, bool __neg, + const money_base::pattern& __pat, char_type __dp, + char_type __ts, const string& __grp, + const string_type& __sym, const string_type& __sn, + int __fd) +{ + __me = __mb; + for (unsigned __p = 0; __p < 4; ++__p) + { + switch (__pat.field[__p]) + { + case money_base::none: + __mi = __me; + break; + case money_base::space: + __mi = __me; + *__me++ = __ct.widen(' '); + break; + case money_base::sign: + if (!__sn.empty()) + *__me++ = __sn[0]; + break; + case money_base::symbol: + if (!__sym.empty() && (__flags & ios_base::showbase)) + __me = _VSTD::copy(__sym.begin(), __sym.end(), __me); + break; + case money_base::value: + { + // remember start of value so we can reverse it + char_type* __t = __me; + // find beginning of digits + if (__neg) + ++__db; + // find end of digits + const char_type* __d; + for (__d = __db; __d < __de; ++__d) + if (!__ct.is(ctype_base::digit, *__d)) + break; + // print fractional part + if (__fd > 0) + { + int __f; + for (__f = __fd; __d > __db && __f > 0; --__f) + *__me++ = *--__d; + char_type __z = __f > 0 ? __ct.widen('0') : char_type(); + for (; __f > 0; --__f) + *__me++ = __z; + *__me++ = __dp; + } + // print units part + if (__d == __db) + { + *__me++ = __ct.widen('0'); + } + else + { + unsigned __ng = 0; + unsigned __ig = 0; + unsigned __gl = __grp.empty() ? numeric_limits::max() + : static_cast(__grp[__ig]); + while (__d != __db) + { + if (__ng == __gl) + { + *__me++ = __ts; + __ng = 0; + if (++__ig < __grp.size()) + __gl = __grp[__ig] == numeric_limits::max() ? + numeric_limits::max() : + static_cast(__grp[__ig]); + } + *__me++ = *--__d; + ++__ng; + } + } + // reverse it + reverse(__t, __me); + } + break; + } + } + // print rest of sign, if any + if (__sn.size() > 1) + __me = _VSTD::copy(__sn.begin()+1, __sn.end(), __me); + // set alignment + if ((__flags & ios_base::adjustfield) == ios_base::left) + __mi = __me; + else if ((__flags & ios_base::adjustfield) != ios_base::internal) + __mi = __mb; +} + +extern template class __money_put; +extern template class __money_put; + +template > +class _LIBCPP_VISIBLE money_put + : public locale::facet, + private __money_put<_CharT> +{ +public: + typedef _CharT char_type; + typedef _OutputIterator iter_type; + typedef basic_string string_type; + + _LIBCPP_ALWAYS_INLINE + explicit money_put(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, + long double __units) const + { + return do_put(__s, __intl, __iob, __fl, __units); + } + + _LIBCPP_ALWAYS_INLINE + iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, + const string_type& __digits) const + { + return do_put(__s, __intl, __iob, __fl, __digits); + } + + static locale::id id; + +protected: + _LIBCPP_ALWAYS_INLINE + ~money_put() {} + + virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, + char_type __fl, long double __units) const; + virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, + char_type __fl, const string_type& __digits) const; +}; + +template +locale::id +money_put<_CharT, _OutputIterator>::id; + +template +_OutputIterator +money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, + ios_base& __iob, char_type __fl, + long double __units) const +{ + // convert to char + const size_t __bs = 100; + char __buf[__bs]; + char* __bb = __buf; + char_type __digits[__bs]; + char_type* __db = __digits; + size_t __n = snprintf(__bb, __bs, "%.0Lf", __units); + unique_ptr __hn(0, free); + unique_ptr __hd(0, free); + // secure memory for digit storage + if (__n > __bs-1) + { +#ifdef _LIBCPP_LOCALE__L_EXTENSIONS + __n = asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units); +#else + __n = __asprintf_l(&__bb, __cloc(), "%.0Lf", __units); +#endif + if (__bb == 0) + __throw_bad_alloc(); + __hn.reset(__bb); + __hd.reset((char_type*)malloc(__n * sizeof(char_type))); + if (__hd == 0) + __throw_bad_alloc(); + __db = __hd.get(); + } + // gather info + locale __loc = __iob.getloc(); + const ctype& __ct = use_facet >(__loc); + __ct.widen(__bb, __bb + __n, __db); + bool __neg = __n > 0 && __bb[0] == '-'; + money_base::pattern __pat; + char_type __dp; + char_type __ts; + string __grp; + string_type __sym; + string_type __sn; + int __fd; + this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); + // secure memory for formatting + char_type __mbuf[__bs]; + char_type* __mb = __mbuf; + unique_ptr __hw(0, free); + size_t __exn = static_cast(__n) > __fd ? + (__n - __fd) * 2 + __sn.size() + __sym.size() + __fd + 1 + : __sn.size() + __sym.size() + __fd + 2; + if (__exn > __bs) + { + __hw.reset((char_type*)malloc(__exn * sizeof(char_type))); + __mb = __hw.get(); + if (__mb == 0) + __throw_bad_alloc(); + } + // format + char_type* __mi; + char_type* __me; + this->__format(__mb, __mi, __me, __iob.flags(), + __db, __db + __n, __ct, + __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); + return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); +} + +template +_OutputIterator +money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, + ios_base& __iob, char_type __fl, + const string_type& __digits) const +{ + // gather info + locale __loc = __iob.getloc(); + const ctype& __ct = use_facet >(__loc); + bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-'); + money_base::pattern __pat; + char_type __dp; + char_type __ts; + string __grp; + string_type __sym; + string_type __sn; + int __fd; + this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); + // secure memory for formatting + char_type __mbuf[100]; + char_type* __mb = __mbuf; + unique_ptr __h(0, free); + size_t __exn = __digits.size() > __fd ? + (__digits.size() - __fd) * 2 + __sn.size() + __sym.size() + __fd + 1 + : __sn.size() + __sym.size() + __fd + 2; + if (__exn > 100) + { + __h.reset((char_type*)malloc(__exn * sizeof(char_type))); + __mb = __h.get(); + if (__mb == 0) + __throw_bad_alloc(); + } + // format + char_type* __mi; + char_type* __me; + this->__format(__mb, __mi, __me, __iob.flags(), + __digits.data(), __digits.data() + __digits.size(), __ct, + __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); + return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); +} + +extern template class money_put; +extern template class money_put; + +// messages + +class _LIBCPP_VISIBLE messages_base +{ +public: + typedef ptrdiff_t catalog; + + _LIBCPP_ALWAYS_INLINE messages_base() {} +}; + +template +class _LIBCPP_VISIBLE messages + : public locale::facet, + public messages_base +{ +public: + typedef _CharT char_type; + typedef basic_string<_CharT> string_type; + + _LIBCPP_ALWAYS_INLINE + explicit messages(size_t __refs = 0) + : locale::facet(__refs) {} + + _LIBCPP_ALWAYS_INLINE + catalog open(const basic_string& __nm, const locale& __loc) const + { + return do_open(__nm, __loc); + } + + _LIBCPP_ALWAYS_INLINE + string_type get(catalog __c, int __set, int __msgid, + const string_type& __dflt) const + { + return do_get(__c, __set, __msgid, __dflt); + } + + _LIBCPP_ALWAYS_INLINE + void close(catalog __c) const + { + do_close(__c); + } + + static locale::id id; + +protected: + _LIBCPP_ALWAYS_INLINE + ~messages() {} + + virtual catalog do_open(const basic_string&, const locale&) const; + virtual string_type do_get(catalog, int __set, int __msgid, + const string_type& __dflt) const; + virtual void do_close(catalog) const; +}; + +template +locale::id +messages<_CharT>::id; + +template +typename messages<_CharT>::catalog +messages<_CharT>::do_open(const basic_string& __nm, const locale&) const +{ +#if _WIN32 + return -1; +#else // _WIN32 + catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE); + if (__cat != -1) + __cat = static_cast((static_cast(__cat) >> 1)); + return __cat; +#endif // _WIN32 +} + +template +typename messages<_CharT>::string_type +messages<_CharT>::do_get(catalog __c, int __set, int __msgid, + const string_type& __dflt) const +{ +#if _WIN32 + return __dflt; +#else // _WIN32 + string __ndflt; + __narrow_to_utf8()(back_inserter(__ndflt), + __dflt.c_str(), + __dflt.c_str() + __dflt.size()); + if (__c != -1) + __c <<= 1; + nl_catd __cat = (nl_catd)__c; + char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str()); + string_type __w; + __widen_from_utf8()(back_inserter(__w), + __n, __n + strlen(__n)); + return __w; +#endif // _WIN32 +} + +template +void +messages<_CharT>::do_close(catalog __c) const +{ +#if !_WIN32 + if (__c != -1) + __c <<= 1; + nl_catd __cat = (nl_catd)__c; + catclose(__cat); +#endif // !_WIN32 +} + +extern template class messages; +extern template class messages; + +template +class _LIBCPP_VISIBLE messages_byname + : public messages<_CharT> +{ +public: + typedef messages_base::catalog catalog; + typedef basic_string<_CharT> string_type; + + _LIBCPP_ALWAYS_INLINE + explicit messages_byname(const char*, size_t __refs = 0) + : messages<_CharT>(__refs) {} + + _LIBCPP_ALWAYS_INLINE + explicit messages_byname(const string&, size_t __refs = 0) + : messages<_CharT>(__refs) {} + +protected: + _LIBCPP_ALWAYS_INLINE + ~messages_byname() {} +}; + +extern template class messages_byname; +extern template class messages_byname; + +template, + class _Byte_alloc = allocator > +class _LIBCPP_VISIBLE wstring_convert +{ +public: + typedef basic_string, _Byte_alloc> byte_string; + typedef basic_string<_Elem, char_traits<_Elem>, _Wide_alloc> wide_string; + typedef typename _Codecvt::state_type state_type; + typedef typename wide_string::traits_type::int_type int_type; + +private: + byte_string __byte_err_string_; + wide_string __wide_err_string_; + _Codecvt* __cvtptr_; + state_type __cvtstate_; + size_t __cvtcount_; + + wstring_convert(const wstring_convert& __wc); + wstring_convert& operator=(const wstring_convert& __wc); +public: + wstring_convert(_Codecvt* __pcvt = new _Codecvt); + wstring_convert(_Codecvt* __pcvt, state_type __state); + wstring_convert(const byte_string& __byte_err, + const wide_string& __wide_err = wide_string()); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + wstring_convert(wstring_convert&& __wc); +#endif + ~wstring_convert(); + + _LIBCPP_ALWAYS_INLINE + wide_string from_bytes(char __byte) + {return from_bytes(&__byte, &__byte+1);} + _LIBCPP_ALWAYS_INLINE + wide_string from_bytes(const char* __ptr) + {return from_bytes(__ptr, __ptr + char_traits::length(__ptr));} + _LIBCPP_ALWAYS_INLINE + wide_string from_bytes(const byte_string& __str) + {return from_bytes(__str.data(), __str.data() + __str.size());} + wide_string from_bytes(const char* __first, const char* __last); + + _LIBCPP_ALWAYS_INLINE + byte_string to_bytes(_Elem __wchar) + {return to_bytes(&__wchar, &__wchar+1);} + _LIBCPP_ALWAYS_INLINE + byte_string to_bytes(const _Elem* __wptr) + {return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));} + _LIBCPP_ALWAYS_INLINE + byte_string to_bytes(const wide_string& __wstr) + {return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());} + byte_string to_bytes(const _Elem* __first, const _Elem* __last); + + _LIBCPP_ALWAYS_INLINE + size_t converted() const {return __cvtcount_;} + _LIBCPP_ALWAYS_INLINE + state_type state() const {return __cvtstate_;} +}; + +template +inline _LIBCPP_ALWAYS_INLINE +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + wstring_convert(_Codecvt* __pcvt) + : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) +{ +} + +template +inline _LIBCPP_ALWAYS_INLINE +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + wstring_convert(_Codecvt* __pcvt, state_type __state) + : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) +{ +} + +template +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err) + : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), + __cvtstate_(), __cvtcount_(0) +{ + __cvtptr_ = new _Codecvt; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +inline _LIBCPP_ALWAYS_INLINE +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + wstring_convert(wstring_convert&& __wc) + : __byte_err_string_(_VSTD::move(__wc.__byte_err_string_)), + __wide_err_string_(_VSTD::move(__wc.__wide_err_string_)), + __cvtptr_(__wc.__cvtptr_), + __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtstate_) +{ + __wc.__cvtptr_ = nullptr; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::~wstring_convert() +{ + delete __cvtptr_; +} + +template +typename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::wide_string +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + from_bytes(const char* __frm, const char* __frm_end) +{ + __cvtcount_ = 0; + if (__cvtptr_ != nullptr) + { + wide_string __ws(2*(__frm_end - __frm), _Elem()); + __ws.resize(__ws.capacity()); + codecvt_base::result __r = codecvt_base::ok; + state_type __st = __cvtstate_; + if (__frm != __frm_end) + { + _Elem* __to = &__ws[0]; + _Elem* __to_end = __to + __ws.size(); + const char* __frm_nxt; + do + { + _Elem* __to_nxt; + __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, + __to, __to_end, __to_nxt); + __cvtcount_ += __frm_nxt - __frm; + if (__frm_nxt == __frm) + { + __r = codecvt_base::error; + } + else if (__r == codecvt_base::noconv) + { + __ws.resize(__to - &__ws[0]); + // This only gets executed if _Elem is char + __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end); + __frm = __frm_nxt; + __r = codecvt_base::ok; + } + else if (__r == codecvt_base::ok) + { + __ws.resize(__to_nxt - &__ws[0]); + __frm = __frm_nxt; + } + else if (__r == codecvt_base::partial) + { + ptrdiff_t __s = __to_nxt - &__ws[0]; + __ws.resize(2 * __s); + __to = &__ws[0] + __s; + __to_end = &__ws[0] + __ws.size(); + __frm = __frm_nxt; + } + } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); + } + if (__r == codecvt_base::ok) + return __ws; + } +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__wide_err_string_.empty()) + throw range_error("wstring_convert: from_bytes error"); +#endif // _LIBCPP_NO_EXCEPTIONS + return __wide_err_string_; +} + +template +typename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::byte_string +wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: + to_bytes(const _Elem* __frm, const _Elem* __frm_end) +{ + __cvtcount_ = 0; + if (__cvtptr_ != nullptr) + { + byte_string __bs(2*(__frm_end - __frm), char()); + __bs.resize(__bs.capacity()); + codecvt_base::result __r = codecvt_base::ok; + state_type __st = __cvtstate_; + if (__frm != __frm_end) + { + char* __to = &__bs[0]; + char* __to_end = __to + __bs.size(); + const _Elem* __frm_nxt; + do + { + char* __to_nxt; + __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, + __to, __to_end, __to_nxt); + __cvtcount_ += __frm_nxt - __frm; + if (__frm_nxt == __frm) + { + __r = codecvt_base::error; + } + else if (__r == codecvt_base::noconv) + { + __bs.resize(__to - &__bs[0]); + // This only gets executed if _Elem is char + __bs.append((const char*)__frm, (const char*)__frm_end); + __frm = __frm_nxt; + __r = codecvt_base::ok; + } + else if (__r == codecvt_base::ok) + { + __bs.resize(__to_nxt - &__bs[0]); + __frm = __frm_nxt; + } + else if (__r == codecvt_base::partial) + { + ptrdiff_t __s = __to_nxt - &__bs[0]; + __bs.resize(2 * __s); + __to = &__bs[0] + __s; + __to_end = &__bs[0] + __bs.size(); + __frm = __frm_nxt; + } + } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); + } + if (__r == codecvt_base::ok) + { + size_t __s = __bs.size(); + __bs.resize(__bs.capacity()); + char* __to = &__bs[0] + __s; + char* __to_end = __to + __bs.size(); + do + { + char* __to_nxt; + __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt); + if (__r == codecvt_base::noconv) + { + __bs.resize(__to - &__bs[0]); + __r = codecvt_base::ok; + } + else if (__r == codecvt_base::ok) + { + __bs.resize(__to_nxt - &__bs[0]); + } + else if (__r == codecvt_base::partial) + { + ptrdiff_t __s = __to_nxt - &__bs[0]; + __bs.resize(2 * __s); + __to = &__bs[0] + __s; + __to_end = &__bs[0] + __bs.size(); + } + } while (__r == codecvt_base::partial); + if (__r == codecvt_base::ok) + return __bs; + } + } +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__byte_err_string_.empty()) + throw range_error("wstring_convert: to_bytes error"); +#endif // _LIBCPP_NO_EXCEPTIONS + return __byte_err_string_; +} + +template > +class _LIBCPP_VISIBLE wbuffer_convert + : public basic_streambuf<_Elem, _Tr> +{ +public: + // types: + typedef _Elem char_type; + typedef _Tr traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef typename _Codecvt::state_type state_type; + +private: + char* __extbuf_; + const char* __extbufnext_; + const char* __extbufend_; + char __extbuf_min_[8]; + size_t __ebs_; + char_type* __intbuf_; + size_t __ibs_; + streambuf* __bufptr_; + _Codecvt* __cv_; + state_type __st_; + ios_base::openmode __cm_; + bool __owns_eb_; + bool __owns_ib_; + bool __always_noconv_; + + wbuffer_convert(const wbuffer_convert&); + wbuffer_convert& operator=(const wbuffer_convert&); +public: + wbuffer_convert(streambuf* __bytebuf = 0, _Codecvt* __pcvt = new _Codecvt, + state_type __state = state_type()); + ~wbuffer_convert(); + + _LIBCPP_INLINE_VISIBILITY + streambuf* rdbuf() const {return __bufptr_;} + _LIBCPP_INLINE_VISIBILITY + streambuf* rdbuf(streambuf* __bytebuf) + { + streambuf* __r = __bufptr_; + __bufptr_ = __bytebuf; + return __r; + } + + _LIBCPP_INLINE_VISIBILITY + state_type state() const {return __st_;} + +protected: + virtual int_type underflow(); + virtual int_type pbackfail(int_type __c = traits_type::eof()); + virtual int_type overflow (int_type __c = traits_type::eof()); + virtual basic_streambuf* setbuf(char_type* __s, + streamsize __n); + virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __wch = ios_base::in | ios_base::out); + virtual pos_type seekpos(pos_type __sp, + ios_base::openmode __wch = ios_base::in | ios_base::out); + virtual int sync(); + +private: + bool __read_mode(); + void __write_mode(); + wbuffer_convert* __close(); +}; + +template +wbuffer_convert<_Codecvt, _Elem, _Tr>:: + wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state) + : __extbuf_(0), + __extbufnext_(0), + __extbufend_(0), + __ebs_(0), + __intbuf_(0), + __ibs_(0), + __bufptr_(__bytebuf), + __cv_(__pcvt), + __st_(__state), + __cm_(0), + __owns_eb_(false), + __owns_ib_(false), + __always_noconv_(__cv_ ? __cv_->always_noconv() : false) +{ + setbuf(0, 4096); +} + +template +wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() +{ + __close(); + delete __cv_; + if (__owns_eb_) + delete [] __extbuf_; + if (__owns_ib_) + delete [] __intbuf_; +} + +template +typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type +wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() +{ + if (__cv_ == 0 || __bufptr_ == 0) + return traits_type::eof(); + bool __initial = __read_mode(); + char_type __1buf; + if (this->gptr() == 0) + this->setg(&__1buf, &__1buf+1, &__1buf+1); + const size_t __unget_sz = __initial ? 0 : min((this->egptr() - this->eback()) / 2, 4); + int_type __c = traits_type::eof(); + if (this->gptr() == this->egptr()) + { + memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); + if (__always_noconv_) + { + streamsize __nmemb = static_cast(this->egptr() - this->eback() - __unget_sz); + __nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb); + if (__nmemb != 0) + { + this->setg(this->eback(), + this->eback() + __unget_sz, + this->eback() + __unget_sz + __nmemb); + __c = *this->gptr(); + } + } + else + { + memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); + __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); + __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); + streamsize __nmemb = _VSTD::min(static_cast(this->egptr() - this->eback() - __unget_sz), + static_cast(__extbufend_ - __extbufnext_)); + codecvt_base::result __r; + state_type __svs = __st_; + streamsize __nr = __bufptr_->sgetn(const_cast(__extbufnext_), __nmemb); + if (__nr != 0) + { + __extbufend_ = __extbufnext_ + __nr; + char_type* __inext; + __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, + this->eback() + __unget_sz, + this->egptr(), __inext); + if (__r == codecvt_base::noconv) + { + this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_); + __c = *this->gptr(); + } + else if (__inext != this->eback() + __unget_sz) + { + this->setg(this->eback(), this->eback() + __unget_sz, __inext); + __c = *this->gptr(); + } + } + } + } + else + __c = *this->gptr(); + if (this->eback() == &__1buf) + this->setg(0, 0, 0); + return __c; +} + +template +typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type +wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) +{ + if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr()) + { + if (traits_type::eq_int_type(__c, traits_type::eof())) + { + this->gbump(-1); + return traits_type::not_eof(__c); + } + if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) + { + this->gbump(-1); + *this->gptr() = traits_type::to_char_type(__c); + return __c; + } + } + return traits_type::eof(); +} + +template +typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type +wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) +{ + if (__cv_ == 0 || __bufptr_ == 0) + return traits_type::eof(); + __write_mode(); + char_type __1buf; + char_type* __pb_save = this->pbase(); + char_type* __epb_save = this->epptr(); + if (!traits_type::eq_int_type(__c, traits_type::eof())) + { + if (this->pptr() == 0) + this->setp(&__1buf, &__1buf+1); + *this->pptr() = traits_type::to_char_type(__c); + this->pbump(1); + } + if (this->pptr() != this->pbase()) + { + if (__always_noconv_) + { + streamsize __nmemb = static_cast(this->pptr() - this->pbase()); + if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb) + return traits_type::eof(); + } + else + { + char* __extbe = __extbuf_; + codecvt_base::result __r; + do + { + const char_type* __e; + __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, + __extbuf_, __extbuf_ + __ebs_, __extbe); + if (__e == this->pbase()) + return traits_type::eof(); + if (__r == codecvt_base::noconv) + { + streamsize __nmemb = static_cast(this->pptr() - this->pbase()); + if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb) + return traits_type::eof(); + } + else if (__r == codecvt_base::ok || __r == codecvt_base::partial) + { + streamsize __nmemb = static_cast(__extbe - __extbuf_); + if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb) + return traits_type::eof(); + if (__r == codecvt_base::partial) + { + this->setp((char_type*)__e, this->pptr()); + this->pbump(this->epptr() - this->pbase()); + } + } + else + return traits_type::eof(); + } while (__r == codecvt_base::partial); + } + this->setp(__pb_save, __epb_save); + } + return traits_type::not_eof(__c); +} + +template +basic_streambuf<_Elem, _Tr>* +wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n) +{ + this->setg(0, 0, 0); + this->setp(0, 0); + if (__owns_eb_) + delete [] __extbuf_; + if (__owns_ib_) + delete [] __intbuf_; + __ebs_ = __n; + if (__ebs_ > sizeof(__extbuf_min_)) + { + if (__always_noconv_ && __s) + { + __extbuf_ = (char*)__s; + __owns_eb_ = false; + } + else + { + __extbuf_ = new char[__ebs_]; + __owns_eb_ = true; + } + } + else + { + __extbuf_ = __extbuf_min_; + __ebs_ = sizeof(__extbuf_min_); + __owns_eb_ = false; + } + if (!__always_noconv_) + { + __ibs_ = max(__n, sizeof(__extbuf_min_)); + if (__s && __ibs_ >= sizeof(__extbuf_min_)) + { + __intbuf_ = __s; + __owns_ib_ = false; + } + else + { + __intbuf_ = new char_type[__ibs_]; + __owns_ib_ = true; + } + } + else + { + __ibs_ = 0; + __intbuf_ = 0; + __owns_ib_ = false; + } + return this; +} + +template +typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type +wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __om) +{ + int __width = __cv_->encoding(); + if (__cv_ == 0 || __bufptr_ == 0 || (__width <= 0 && __off != 0) || sync()) + return pos_type(off_type(-1)); + // __width > 0 || __off == 0 + switch (__way) + { + case ios_base::beg: + break; + case ios_base::cur: + break; + case ios_base::end: + break; + default: + return pos_type(off_type(-1)); + } + pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om); + __r.state(__st_); + return __r; +} + +template +typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type +wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch) +{ + if (__cv_ == 0 || __bufptr_ == 0 || sync()) + return pos_type(off_type(-1)); + if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1))) + return pos_type(off_type(-1)); + return __sp; +} + +template +int +wbuffer_convert<_Codecvt, _Elem, _Tr>::sync() +{ + if (__cv_ == 0 || __bufptr_ == 0) + return 0; + if (__cm_ & ios_base::out) + { + if (this->pptr() != this->pbase()) + if (overflow() == traits_type::eof()) + return -1; + codecvt_base::result __r; + do + { + char* __extbe; + __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); + streamsize __nmemb = static_cast(__extbe - __extbuf_); + if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb) + return -1; + } while (__r == codecvt_base::partial); + if (__r == codecvt_base::error) + return -1; + if (__bufptr_->pubsync()) + return -1; + } + else if (__cm_ & ios_base::in) + { + off_type __c; + if (__always_noconv_) + __c = this->egptr() - this->gptr(); + else + { + int __width = __cv_->encoding(); + __c = __extbufend_ - __extbufnext_; + if (__width > 0) + __c += __width * (this->egptr() - this->gptr()); + else + { + if (this->gptr() != this->egptr()) + { + reverse(this->gptr(), this->egptr()); + codecvt_base::result __r; + const char_type* __e = this->gptr(); + char* __extbe; + do + { + __r = __cv_->out(__st_, __e, this->egptr(), __e, + __extbuf_, __extbuf_ + __ebs_, __extbe); + switch (__r) + { + case codecvt_base::noconv: + __c += this->egptr() - this->gptr(); + break; + case codecvt_base::ok: + case codecvt_base::partial: + __c += __extbe - __extbuf_; + break; + default: + return -1; + } + } while (__r == codecvt_base::partial); + } + } + } + if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1))) + return -1; + this->setg(0, 0, 0); + __cm_ = 0; + } + return 0; +} + +template +bool +wbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode() +{ + if (!(__cm_ & ios_base::in)) + { + this->setp(0, 0); + if (__always_noconv_) + this->setg((char_type*)__extbuf_, + (char_type*)__extbuf_ + __ebs_, + (char_type*)__extbuf_ + __ebs_); + else + this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); + __cm_ = ios_base::in; + return true; + } + return false; +} + +template +void +wbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode() +{ + if (!(__cm_ & ios_base::out)) + { + this->setg(0, 0, 0); + if (__ebs_ > sizeof(__extbuf_min_)) + { + if (__always_noconv_) + this->setp((char_type*)__extbuf_, + (char_type*)__extbuf_ + (__ebs_ - 1)); + else + this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); + } + else + this->setp(0, 0); + __cm_ = ios_base::out; + } +} + +template +wbuffer_convert<_Codecvt, _Elem, _Tr>* +wbuffer_convert<_Codecvt, _Elem, _Tr>::__close() +{ + wbuffer_convert* __rt = 0; + if (__cv_ != 0 && __bufptr_ != 0) + { + __rt = this; + if ((__cm_ & ios_base::out) && sync()) + __rt = 0; + } + return __rt; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_LOCALE diff --git a/contrib/libc++/include/map b/contrib/libc++/include/map new file mode 100644 index 000000000000..8bb75550dbaa --- /dev/null +++ b/contrib/libc++/include/map @@ -0,0 +1,1931 @@ +// -*- C++ -*- +//===----------------------------- map ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_MAP +#define _LIBCPP_MAP + +/* + + map synopsis + +namespace std +{ + +template , + class Allocator = allocator>> +class map +{ +public: + // types: + typedef Key key_type; + typedef T mapped_type; + typedef pair value_type; + typedef Compare key_compare; + typedef Allocator allocator_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + class value_compare + : public binary_function + { + friend class map; + protected: + key_compare comp; + + value_compare(key_compare c); + public: + bool operator()(const value_type& x, const value_type& y) const; + }; + + // construct/copy/destroy: + map() + noexcept( + is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value && + is_nothrow_copy_constructible::value); + explicit map(const key_compare& comp); + map(const key_compare& comp, const allocator_type& a); + template + map(InputIterator first, InputIterator last, + const key_compare& comp = key_compare()); + template + map(InputIterator first, InputIterator last, + const key_compare& comp, const allocator_type& a); + map(const map& m); + map(map&& m) + noexcept( + is_nothrow_move_constructible::value && + is_nothrow_move_constructible::value); + explicit map(const allocator_type& a); + map(const map& m, const allocator_type& a); + map(map&& m, const allocator_type& a); + map(initializer_list il, const key_compare& comp = key_compare()); + map(initializer_list il, const key_compare& comp, const allocator_type& a); + ~map(); + + map& operator=(const map& m); + map& operator=(map&& m) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value); + map& operator=(initializer_list il); + + // iterators: + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // capacity: + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + // element access: + mapped_type& operator[](const key_type& k); + mapped_type& operator[](key_type&& k); + + mapped_type& at(const key_type& k); + const mapped_type& at(const key_type& k) const; + + // modifiers: + template + pair emplace(Args&&... args); + template + iterator emplace_hint(const_iterator position, Args&&... args); + pair insert(const value_type& v); + template + pair insert(P&& p); + iterator insert(const_iterator position, const value_type& v); + template + iterator insert(const_iterator position, P&& p); + template + void insert(InputIterator first, InputIterator last); + void insert(initializer_list il); + + iterator erase(const_iterator position); + size_type erase(const key_type& k); + iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + + void swap(map& m) + noexcept( + __is_nothrow_swappable::value && + (!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable::value)); + + // observers: + allocator_type get_allocator() const noexcept; + key_compare key_comp() const; + value_compare value_comp() const; + + // map operations: + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + iterator lower_bound(const key_type& k); + const_iterator lower_bound(const key_type& k) const; + iterator upper_bound(const key_type& k); + const_iterator upper_bound(const key_type& k) const; + pair equal_range(const key_type& k); + pair equal_range(const key_type& k) const; +}; + +template +bool +operator==(const map& x, + const map& y); + +template +bool +operator< (const map& x, + const map& y); + +template +bool +operator!=(const map& x, + const map& y); + +template +bool +operator> (const map& x, + const map& y); + +template +bool +operator>=(const map& x, + const map& y); + +template +bool +operator<=(const map& x, + const map& y); + +// specialized algorithms: +template +void +swap(map& x, map& y) + noexcept(noexcept(x.swap(y))); + +template , + class Allocator = allocator>> +class multimap +{ +public: + // types: + typedef Key key_type; + typedef T mapped_type; + typedef pair value_type; + typedef Compare key_compare; + typedef Allocator allocator_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + class value_compare + : public binary_function + { + friend class multimap; + protected: + key_compare comp; + value_compare(key_compare c); + public: + bool operator()(const value_type& x, const value_type& y) const; + }; + + // construct/copy/destroy: + multimap() + noexcept( + is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value && + is_nothrow_copy_constructible::value); + explicit multimap(const key_compare& comp); + multimap(const key_compare& comp, const allocator_type& a); + template + multimap(InputIterator first, InputIterator last, const key_compare& comp); + template + multimap(InputIterator first, InputIterator last, const key_compare& comp, + const allocator_type& a); + multimap(const multimap& m); + multimap(multimap&& m) + noexcept( + is_nothrow_move_constructible::value && + is_nothrow_move_constructible::value); + explicit multimap(const allocator_type& a); + multimap(const multimap& m, const allocator_type& a); + multimap(multimap&& m, const allocator_type& a); + multimap(initializer_list il, const key_compare& comp = key_compare()); + multimap(initializer_list il, const key_compare& comp, + const allocator_type& a); + ~multimap(); + + multimap& operator=(const multimap& m); + multimap& operator=(multimap&& m) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value); + multimap& operator=(initializer_list il); + + // iterators: + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // capacity: + bool empty() const noexcept; + size_type size() const noexcept; + size_type max_size() const noexcept; + + // modifiers: + template + iterator emplace(Args&&... args); + template + iterator emplace_hint(const_iterator position, Args&&... args); + iterator insert(const value_type& v); + template + iterator insert(P&& p); + iterator insert(const_iterator position, const value_type& v); + template + iterator insert(const_iterator position, P&& p); + template + void insert(InputIterator first, InputIterator last); + void insert(initializer_list il); + + iterator erase(const_iterator position); + size_type erase(const key_type& k); + iterator erase(const_iterator first, const_iterator last); + void clear() noexcept; + + void swap(multimap& m) + noexcept( + __is_nothrow_swappable::value && + (!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable::value)); + + // observers: + allocator_type get_allocator() const noexcept; + key_compare key_comp() const; + value_compare value_comp() const; + + // map operations: + iterator find(const key_type& k); + const_iterator find(const key_type& k) const; + size_type count(const key_type& k) const; + iterator lower_bound(const key_type& k); + const_iterator lower_bound(const key_type& k) const; + iterator upper_bound(const key_type& k); + const_iterator upper_bound(const key_type& k) const; + pair equal_range(const key_type& k); + pair equal_range(const key_type& k) const; +}; + +template +bool +operator==(const multimap& x, + const multimap& y); + +template +bool +operator< (const multimap& x, + const multimap& y); + +template +bool +operator!=(const multimap& x, + const multimap& y); + +template +bool +operator> (const multimap& x, + const multimap& y); + +template +bool +operator>=(const multimap& x, + const multimap& y); + +template +bool +operator<=(const multimap& x, + const multimap& y); + +// specialized algorithms: +template +void +swap(multimap& x, + multimap& y) + noexcept(noexcept(x.swap(y))); + +} // std + +*/ + +#include <__config> +#include <__tree> +#include +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template ::value> +class __map_value_compare + : private _Compare +{ + typedef pair::type, _Tp> _P; + typedef pair _CP; +public: + _LIBCPP_INLINE_VISIBILITY + __map_value_compare() + _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) + : _Compare() {} + _LIBCPP_INLINE_VISIBILITY + __map_value_compare(_Compare c) + _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) + : _Compare(c) {} + _LIBCPP_INLINE_VISIBILITY + const _Compare& key_comp() const _NOEXCEPT {return *this;} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _CP& __x, const _CP& __y) const + {return static_cast(*this)(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _CP& __x, const _P& __y) const + {return static_cast(*this)(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _CP& __x, const _Key& __y) const + {return static_cast(*this)(__x.first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _P& __x, const _CP& __y) const + {return static_cast(*this)(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _P& __x, const _P& __y) const + {return static_cast(*this)(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _P& __x, const _Key& __y) const + {return static_cast(*this)(__x.first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Key& __x, const _CP& __y) const + {return static_cast(*this)(__x, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Key& __x, const _P& __y) const + {return static_cast(*this)(__x, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Key& __x, const _Key& __y) const + {return static_cast(*this)(__x, __y);} +}; + +template +class __map_value_compare<_Key, _Tp, _Compare, false> +{ + _Compare comp; + + typedef pair::type, _Tp> _P; + typedef pair _CP; + +public: + _LIBCPP_INLINE_VISIBILITY + __map_value_compare() + _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) + : comp() {} + _LIBCPP_INLINE_VISIBILITY + __map_value_compare(_Compare c) + _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) + : comp(c) {} + _LIBCPP_INLINE_VISIBILITY + const _Compare& key_comp() const _NOEXCEPT {return comp;} + + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _CP& __x, const _CP& __y) const + {return comp(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _CP& __x, const _P& __y) const + {return comp(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _CP& __x, const _Key& __y) const + {return comp(__x.first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _P& __x, const _CP& __y) const + {return comp(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _P& __x, const _P& __y) const + {return comp(__x.first, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _P& __x, const _Key& __y) const + {return comp(__x.first, __y);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Key& __x, const _CP& __y) const + {return comp(__x, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Key& __x, const _P& __y) const + {return comp(__x, __y.first);} + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _Key& __x, const _Key& __y) const + {return comp(__x, __y);} +}; + +template +class __map_node_destructor +{ + typedef _Allocator allocator_type; + typedef allocator_traits __alloc_traits; + typedef typename __alloc_traits::value_type::value_type value_type; +public: + typedef typename __alloc_traits::pointer pointer; +private: + typedef typename value_type::first_type first_type; + typedef typename value_type::second_type second_type; + + allocator_type& __na_; + + __map_node_destructor& operator=(const __map_node_destructor&); + +public: + bool __first_constructed; + bool __second_constructed; + + _LIBCPP_INLINE_VISIBILITY + explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT + : __na_(__na), + __first_constructed(false), + __second_constructed(false) + {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + __map_node_destructor(__tree_node_destructor&& __x) _NOEXCEPT + : __na_(__x.__na_), + __first_constructed(__x.__value_constructed), + __second_constructed(__x.__value_constructed) + { + __x.__value_constructed = false; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + if (__second_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second)); + if (__first_constructed) + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } +}; + +template + class map; +template + class multimap; +template class __map_const_iterator; + +template +class _LIBCPP_VISIBLE __map_iterator +{ + _TreeIterator __i_; + + typedef typename _TreeIterator::__pointer_traits __pointer_traits; + typedef const typename _TreeIterator::value_type::first_type __key_type; + typedef typename _TreeIterator::value_type::second_type __mapped_type; +public: + typedef bidirectional_iterator_tag iterator_category; + typedef pair<__key_type, __mapped_type> value_type; + typedef typename _TreeIterator::difference_type difference_type; + typedef value_type& reference; + typedef typename __pointer_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY + __map_iterator() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return *operator->();} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return (pointer)__i_.operator->();} + + _LIBCPP_INLINE_VISIBILITY + __map_iterator& operator++() {++__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __map_iterator operator++(int) + { + __map_iterator __t(*this); + ++(*this); + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + __map_iterator& operator--() {--__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __map_iterator operator--(int) + { + __map_iterator __t(*this); + --(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __map_iterator& __x, const __map_iterator& __y) + {return __x.__i_ == __y.__i_;} + friend + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __map_iterator& __x, const __map_iterator& __y) + {return __x.__i_ != __y.__i_;} + + template friend class _LIBCPP_VISIBLE map; + template friend class _LIBCPP_VISIBLE multimap; + template friend class _LIBCPP_VISIBLE __map_const_iterator; +}; + +template +class _LIBCPP_VISIBLE __map_const_iterator +{ + _TreeIterator __i_; + + typedef typename _TreeIterator::__pointer_traits __pointer_traits; + typedef const typename _TreeIterator::value_type::first_type __key_type; + typedef typename _TreeIterator::value_type::second_type __mapped_type; +public: + typedef bidirectional_iterator_tag iterator_category; + typedef pair<__key_type, __mapped_type> value_type; + typedef typename _TreeIterator::difference_type difference_type; + typedef const value_type& reference; + typedef typename __pointer_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind +#else + rebind::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator() _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator( + __map_iterator __i) + _NOEXCEPT + : __i_(__i.__i_) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return *operator->();} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return (pointer)__i_.operator->();} + + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator& operator++() {++__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator operator++(int) + { + __map_const_iterator __t(*this); + ++(*this); + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator& operator--() {--__i_; return *this;} + _LIBCPP_INLINE_VISIBILITY + __map_const_iterator operator--(int) + { + __map_const_iterator __t(*this); + --(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) + {return __x.__i_ == __y.__i_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) + {return __x.__i_ != __y.__i_;} + + template friend class _LIBCPP_VISIBLE map; + template friend class _LIBCPP_VISIBLE multimap; + template friend class _LIBCPP_VISIBLE __tree_const_iterator; +}; + +template , + class _Allocator = allocator > > +class _LIBCPP_VISIBLE map +{ +public: + // types: + typedef _Key key_type; + typedef _Tp mapped_type; + typedef pair value_type; + typedef _Compare key_compare; + typedef _Allocator allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + + class _LIBCPP_VISIBLE value_compare + : public binary_function + { + friend class map; + protected: + key_compare comp; + + _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {} + public: + _LIBCPP_INLINE_VISIBILITY + bool operator()(const value_type& __x, const value_type& __y) const + {return comp(__x.first, __y.first);} + }; + +private: + typedef pair __value_type; + typedef __map_value_compare __vc; + typedef typename allocator_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__value_type> +#else + rebind_alloc<__value_type>::other +#endif + __allocator_type; + typedef __tree<__value_type, __vc, __allocator_type> __base; + typedef typename __base::__node_traits __node_traits; + typedef allocator_traits __alloc_traits; + + __base __tree_; + +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef __map_iterator iterator; + typedef __map_const_iterator const_iterator; + typedef _VSTD::reverse_iterator reverse_iterator; + typedef _VSTD::reverse_iterator const_reverse_iterator; + + _LIBCPP_INLINE_VISIBILITY + explicit map(const key_compare& __comp = key_compare()) + _NOEXCEPT_( + is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value && + is_nothrow_copy_constructible::value) + : __tree_(__vc(__comp)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit map(const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), __a) {} + + template + _LIBCPP_INLINE_VISIBILITY + map(_InputIterator __f, _InputIterator __l, + const key_compare& __comp = key_compare()) + : __tree_(__vc(__comp)) + { + insert(__f, __l); + } + + template + _LIBCPP_INLINE_VISIBILITY + map(_InputIterator __f, _InputIterator __l, + const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), __a) + { + insert(__f, __l); + } + + _LIBCPP_INLINE_VISIBILITY + map(const map& __m) + : __tree_(__m.__tree_) + { + insert(__m.begin(), __m.end()); + } + + _LIBCPP_INLINE_VISIBILITY + map& operator=(const map& __m) + { + __tree_ = __m.__tree_; + return *this; + } + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + map(map&& __m) + _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) + : __tree_(_VSTD::move(__m.__tree_)) + { + } + + map(map&& __m, const allocator_type& __a); + + _LIBCPP_INLINE_VISIBILITY + map& operator=(map&& __m) + _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) + { + __tree_ = _VSTD::move(__m.__tree_); + return *this; + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + map(initializer_list __il, const key_compare& __comp = key_compare()) + : __tree_(__vc(__comp)) + { + insert(__il.begin(), __il.end()); + } + + _LIBCPP_INLINE_VISIBILITY + map(initializer_list __il, const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), __a) + { + insert(__il.begin(), __il.end()); + } + + _LIBCPP_INLINE_VISIBILITY + map& operator=(initializer_list __il) + { + __tree_.__assign_unique(__il.begin(), __il.end()); + return *this; + } + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + explicit map(const allocator_type& __a) + : __tree_(__a) + { + } + + _LIBCPP_INLINE_VISIBILITY + map(const map& __m, const allocator_type& __a) + : __tree_(__m.__tree_.value_comp(), __a) + { + insert(__m.begin(), __m.end()); + } + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __tree_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __tree_.end();} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT {return rend();} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __tree_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __tree_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __tree_.max_size();} + + mapped_type& operator[](const key_type& __k); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + mapped_type& operator[](key_type&& __k); +#endif + + mapped_type& at(const key_type& __k); + const mapped_type& at(const key_type& __k) const; + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();} + _LIBCPP_INLINE_VISIBILITY + key_compare key_comp() const {return __tree_.value_comp().key_comp();} + _LIBCPP_INLINE_VISIBILITY + value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + pair + emplace() {return __tree_.__emplace_unique();} + + template ::value>::type> + _LIBCPP_INLINE_VISIBILITY + pair + emplace(_A0&& __a0) + {return __tree_.__emplace_unique(_VSTD::forward<_A0>(__a0));} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + + template ::value>::type> + pair + emplace(_A0&& __a0, _Args&& ...__args); + +#endif // _LIBCPP_HAS_NO_VARIADICS + + _LIBCPP_INLINE_VISIBILITY + iterator + emplace_hint(const_iterator __p) + {return __tree_.__emplace_hint_unique(__p.__i_);} + + template ::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator + emplace_hint(const_iterator __p, _A0&& __a0) + {return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_A0>(__a0));} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + + template ::value>::type> + iterator + emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args); + +#endif // _LIBCPP_HAS_NO_VARIADICS + + template ::value>::type> + _LIBCPP_INLINE_VISIBILITY + pair insert(_P&& __p) + {return __tree_.__insert_unique(_VSTD::forward<_P>(__p));} + + template ::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __pos, _P&& __p) + {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_P>(__p));} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + pair + insert(const value_type& __v) {return __tree_.__insert_unique(__v);} + + _LIBCPP_INLINE_VISIBILITY + iterator + insert(const_iterator __p, const value_type& __v) + {return __tree_.__insert_unique(__p.__i_, __v);} + + template + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __f, _InputIterator __l) + { + for (const_iterator __e = cend(); __f != __l; ++__f) + insert(__e.__i_, *__f); + } + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list __il) + {insert(__il.begin(), __il.end());} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) + {return __tree_.__erase_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __f, const_iterator __l) + {return __tree_.erase(__f.__i_, __l.__i_);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__tree_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(map& __m) + _NOEXCEPT_(__is_nothrow_swappable<__base>::value) + {__tree_.swap(__m.__tree_);} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __tree_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __tree_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const + {return __tree_.__count_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator lower_bound(const key_type& __k) + {return __tree_.lower_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator lower_bound(const key_type& __k) const + {return __tree_.lower_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator upper_bound(const key_type& __k) + {return __tree_.upper_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator upper_bound(const key_type& __k) const + {return __tree_.upper_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) + {return __tree_.__equal_range_unique(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) const + {return __tree_.__equal_range_unique(__k);} + +private: + typedef typename __base::__node __node; + typedef typename __base::__node_allocator __node_allocator; + typedef typename __base::__node_pointer __node_pointer; + typedef typename __base::__node_const_pointer __node_const_pointer; + typedef typename __base::__node_base_pointer __node_base_pointer; + typedef typename __base::__node_base_const_pointer __node_base_const_pointer; + typedef __map_node_destructor<__node_allocator> _D; + typedef unique_ptr<__node, _D> __node_holder; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + __node_holder __construct_node(); + template ::value>::type> + __node_holder __construct_node(_A0&& __a0); +#ifndef _LIBCPP_HAS_NO_VARIADICS + template ::value>::type> + __node_holder __construct_node(_A0&& __a0, _Args&& ...__args); +#endif // _LIBCPP_HAS_NO_VARIADICS +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + __node_holder __construct_node(const key_type& __k); +#endif + + __node_base_pointer& + __find_equal_key(__node_base_pointer& __parent, const key_type& __k); + __node_base_pointer& + __find_equal_key(const_iterator __hint, + __node_base_pointer& __parent, const key_type& __k); + __node_base_const_pointer + __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const; +}; + +// Find place to insert if __k doesn't exist +// Set __parent to parent of null leaf +// Return reference to null leaf +// If __k exists, set parent to node of __k and return reference to node of __k +template +typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer& +map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent, + const key_type& __k) +{ + __node_pointer __nd = __tree_.__root(); + if (__nd != nullptr) + { + while (true) + { + if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first)) + { + if (__nd->__left_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__left_); + else + { + __parent = __nd; + return __parent->__left_; + } + } + else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k)) + { + if (__nd->__right_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__right_); + else + { + __parent = __nd; + return __parent->__right_; + } + } + else + { + __parent = __nd; + return __parent; + } + } + } + __parent = __tree_.__end_node(); + return __parent->__left_; +} + +// Find place to insert if __k doesn't exist +// First check prior to __hint. +// Next check after __hint. +// Next do O(log N) search. +// Set __parent to parent of null leaf +// Return reference to null leaf +// If __k exists, set parent to node of __k and return reference to node of __k +template +typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer& +map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(const_iterator __hint, + __node_base_pointer& __parent, + const key_type& __k) +{ + if (__hint == end() || __tree_.value_comp().key_comp()(__k, __hint->first)) // check before + { + // __k < *__hint + const_iterator __prior = __hint; + if (__prior == begin() || __tree_.value_comp().key_comp()((--__prior)->first, __k)) + { + // *prev(__hint) < __k < *__hint + if (__hint.__ptr_->__left_ == nullptr) + { + __parent = const_cast<__node_pointer&>(__hint.__ptr_); + return __parent->__left_; + } + else + { + __parent = const_cast<__node_pointer&>(__prior.__ptr_); + return __parent->__right_; + } + } + // __k <= *prev(__hint) + return __find_equal_key(__parent, __k); + } + else if (__tree_.value_comp().key_comp()(__hint->first, __k)) // check after + { + // *__hint < __k + const_iterator __next = _VSTD::next(__hint); + if (__next == end() || __tree_.value_comp().key_comp()(__k, __next->first)) + { + // *__hint < __k < *next(__hint) + if (__hint.__ptr_->__right_ == nullptr) + { + __parent = const_cast<__node_pointer&>(__hint.__ptr_); + return __parent->__right_; + } + else + { + __parent = const_cast<__node_pointer&>(__next.__ptr_); + return __parent->__left_; + } + } + // *next(__hint) <= __k + return __find_equal_key(__parent, __k); + } + // else __k == *__hint + __parent = const_cast<__node_pointer&>(__hint.__ptr_); + return __parent; +} + +// Find __k +// Set __parent to parent of null leaf and +// return reference to null leaf iv __k does not exist. +// If __k exists, set parent to node of __k and return reference to node of __k +template +typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer +map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent, + const key_type& __k) const +{ + __node_const_pointer __nd = __tree_.__root(); + if (__nd != nullptr) + { + while (true) + { + if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first)) + { + if (__nd->__left_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__left_); + else + { + __parent = __nd; + return const_cast(__parent->__left_); + } + } + else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k)) + { + if (__nd->__right_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__right_); + else + { + __parent = __nd; + return const_cast(__parent->__right_); + } + } + else + { + __parent = __nd; + return __parent; + } + } + } + __parent = __tree_.__end_node(); + return const_cast(__parent->__left_); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a) + : __tree_(_VSTD::move(__m.__tree_), __a) +{ + if (__a != __m.get_allocator()) + { + const_iterator __e = cend(); + while (!__m.empty()) + __tree_.__insert_unique(__e.__i_, + _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_)); + } +} + +template +typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder +map<_Key, _Tp, _Compare, _Allocator>::__construct_node() +{ + __node_allocator& __na = __tree_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first)); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __h.get_deleter().__second_constructed = true; + return __h; +} + +template +template +typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder +map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) +{ + __node_allocator& __na = __tree_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0)); + __h.get_deleter().__first_constructed = true; + __h.get_deleter().__second_constructed = true; + return __h; +} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template +typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder +map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args) +{ + __node_allocator& __na = __tree_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0)); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second), _VSTD::forward<_Args>(__args)...); + __h.get_deleter().__second_constructed = true; + return __h; +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder +map<_Key, _Tp, _Compare, _Allocator>::__construct_node(const key_type& __k) +{ + __node_allocator& __na = __tree_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __h.get_deleter().__second_constructed = true; + return _VSTD::move(__h); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +_Tp& +map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_equal_key(__parent, __k); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __node_holder __h = __construct_node(__k); + __tree_.__insert_node_at(__parent, __child, __h.get()); + __r = __h.release(); + } + return __r->__value_.second; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +_Tp& +map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_equal_key(__parent, __k); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __node_holder __h = __construct_node(_VSTD::move(__k)); + __tree_.__insert_node_at(__parent, __child, __h.get()); + __r = __h.release(); + } + return __r->__value_.second; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +_Tp& +map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) +{ + __node_base_pointer __parent; + __node_base_pointer& __child = __find_equal_key(__parent, __k); +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__child == nullptr) + throw out_of_range("map::at: key not found"); +#endif // _LIBCPP_NO_EXCEPTIONS + return static_cast<__node_pointer>(__child)->__value_.second; +} + +template +const _Tp& +map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const +{ + __node_base_const_pointer __parent; + __node_base_const_pointer __child = __find_equal_key(__parent, __k); +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__child == nullptr) + throw out_of_range("map::at: key not found"); +#endif // _LIBCPP_NO_EXCEPTIONS + return static_cast<__node_const_pointer>(__child)->__value_.second; +} + +#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + +template +template ::value>::type + > +pair::iterator, bool> +map<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), + _VSTD::forward<_Args>(__args)...); + pair __r = __tree_.__node_insert_unique(__h.get()); + if (__r.second) + __h.release(); + return __r; +} + +template +template ::value>::type + > +typename map<_Key, _Tp, _Compare, _Allocator>::iterator +map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p, + _A0&& __a0, _Args&& ...__args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), + _VSTD::forward<_Args>(__args)...); + iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get()); + if (__r.__i_.__ptr_ == __h.get()) + __h.release(); + return __r; +} + +#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__x == __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return __y < __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__x < __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__y < __x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(map<_Key, _Tp, _Compare, _Allocator>& __x, + map<_Key, _Tp, _Compare, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +template , + class _Allocator = allocator > > +class _LIBCPP_VISIBLE multimap +{ +public: + // types: + typedef _Key key_type; + typedef _Tp mapped_type; + typedef pair value_type; + typedef _Compare key_compare; + typedef _Allocator allocator_type; + typedef value_type& reference; + typedef const value_type& const_reference; + + class _LIBCPP_VISIBLE value_compare + : public binary_function + { + friend class multimap; + protected: + key_compare comp; + + _LIBCPP_INLINE_VISIBILITY + value_compare(key_compare c) : comp(c) {} + public: + _LIBCPP_INLINE_VISIBILITY + bool operator()(const value_type& __x, const value_type& __y) const + {return comp(__x.first, __y.first);} + }; + +private: + typedef pair __value_type; + typedef __map_value_compare __vc; + typedef typename allocator_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__value_type> +#else + rebind_alloc<__value_type>::other +#endif + __allocator_type; + typedef __tree<__value_type, __vc, __allocator_type> __base; + typedef typename __base::__node_traits __node_traits; + typedef allocator_traits __alloc_traits; + + __base __tree_; + +public: + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef __map_iterator iterator; + typedef __map_const_iterator const_iterator; + typedef _VSTD::reverse_iterator reverse_iterator; + typedef _VSTD::reverse_iterator const_reverse_iterator; + + _LIBCPP_INLINE_VISIBILITY + explicit multimap(const key_compare& __comp = key_compare()) + _NOEXCEPT_( + is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value && + is_nothrow_copy_constructible::value) + : __tree_(__vc(__comp)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit multimap(const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), __a) {} + + template + _LIBCPP_INLINE_VISIBILITY + multimap(_InputIterator __f, _InputIterator __l, + const key_compare& __comp = key_compare()) + : __tree_(__vc(__comp)) + { + insert(__f, __l); + } + + template + _LIBCPP_INLINE_VISIBILITY + multimap(_InputIterator __f, _InputIterator __l, + const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), __a) + { + insert(__f, __l); + } + + _LIBCPP_INLINE_VISIBILITY + multimap(const multimap& __m) + : __tree_(__m.__tree_.value_comp(), + __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc())) + { + insert(__m.begin(), __m.end()); + } + + _LIBCPP_INLINE_VISIBILITY + multimap& operator=(const multimap& __m) + { + __tree_ = __m.__tree_; + return *this; + } + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + multimap(multimap&& __m) + _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) + : __tree_(_VSTD::move(__m.__tree_)) + { + } + + multimap(multimap&& __m, const allocator_type& __a); + + _LIBCPP_INLINE_VISIBILITY + multimap& operator=(multimap&& __m) + _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) + { + __tree_ = _VSTD::move(__m.__tree_); + return *this; + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + multimap(initializer_list __il, const key_compare& __comp = key_compare()) + : __tree_(__vc(__comp)) + { + insert(__il.begin(), __il.end()); + } + + _LIBCPP_INLINE_VISIBILITY + multimap(initializer_list __il, const key_compare& __comp, const allocator_type& __a) + : __tree_(__vc(__comp), __a) + { + insert(__il.begin(), __il.end()); + } + + _LIBCPP_INLINE_VISIBILITY + multimap& operator=(initializer_list __il) + { + __tree_.__assign_multi(__il.begin(), __il.end()); + return *this; + } + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + explicit multimap(const allocator_type& __a) + : __tree_(__a) + { + } + + _LIBCPP_INLINE_VISIBILITY + multimap(const multimap& __m, const allocator_type& __a) + : __tree_(__m.__tree_.value_comp(), __a) + { + insert(__m.begin(), __m.end()); + } + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return __tree_.begin();} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return __tree_.end();} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return __tree_.end();} + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT {return rend();} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return __tree_.size() == 0;} + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT {return __tree_.size();} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT {return __tree_.max_size();} + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();} + _LIBCPP_INLINE_VISIBILITY + key_compare key_comp() const {return __tree_.value_comp().key_comp();} + _LIBCPP_INLINE_VISIBILITY + value_compare value_comp() const + {return value_compare(__tree_.value_comp().key_comp());} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + iterator emplace() {return __tree_.__emplace_multi();} + + template ::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator + emplace(_A0&& __a0) + {return __tree_.__emplace_multi(_VSTD::forward<_A0>(__a0));} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + + template ::value>::type> + iterator + emplace(_A0&& __a0, _Args&& ...__args); + +#endif // _LIBCPP_HAS_NO_VARIADICS + + _LIBCPP_INLINE_VISIBILITY + iterator emplace_hint(const_iterator __p) + {return __tree_.__emplace_hint_multi(__p.__i_);} + + template ::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator + emplace_hint(const_iterator __p, _A0&& __a0) + {return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_A0>(__a0));} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + + template ::value>::type> + iterator + emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args); + +#endif // _LIBCPP_HAS_NO_VARIADICS + + template ::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator insert(_P&& __p) + {return __tree_.__insert_multi(_VSTD::forward<_P>(__p));} + + template ::value>::type> + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __pos, _P&& __p) + {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_P>(__p));} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, const value_type& __v) + {return __tree_.__insert_multi(__p.__i_, __v);} + + template + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __f, _InputIterator __l) + { + for (const_iterator __e = cend(); __f != __l; ++__f) + __tree_.__insert_multi(__e.__i_, *__f); + } + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list __il) + {insert(__il.begin(), __il.end());} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY + size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator erase(const_iterator __f, const_iterator __l) + {return __tree_.erase(__f.__i_, __l.__i_);} + _LIBCPP_INLINE_VISIBILITY + void clear() {__tree_.clear();} + + _LIBCPP_INLINE_VISIBILITY + void swap(multimap& __m) + _NOEXCEPT_(__is_nothrow_swappable<__base>::value) + {__tree_.swap(__m.__tree_);} + + _LIBCPP_INLINE_VISIBILITY + iterator find(const key_type& __k) {return __tree_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator find(const key_type& __k) const {return __tree_.find(__k);} + _LIBCPP_INLINE_VISIBILITY + size_type count(const key_type& __k) const + {return __tree_.__count_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator lower_bound(const key_type& __k) + {return __tree_.lower_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator lower_bound(const key_type& __k) const + {return __tree_.lower_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + iterator upper_bound(const key_type& __k) + {return __tree_.upper_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + const_iterator upper_bound(const key_type& __k) const + {return __tree_.upper_bound(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) + {return __tree_.__equal_range_multi(__k);} + _LIBCPP_INLINE_VISIBILITY + pair equal_range(const key_type& __k) const + {return __tree_.__equal_range_multi(__k);} + +private: + typedef typename __base::__node __node; + typedef typename __base::__node_allocator __node_allocator; + typedef typename __base::__node_pointer __node_pointer; + typedef typename __base::__node_const_pointer __node_const_pointer; + typedef __map_node_destructor<__node_allocator> _D; + typedef unique_ptr<__node, _D> __node_holder; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + __node_holder __construct_node(); + template ::value>::type> + __node_holder __construct_node(_A0&& __a0); +#ifndef _LIBCPP_HAS_NO_VARIADICS + template ::value>::type> + __node_holder __construct_node(_A0&& __a0, _Args&& ...__args); +#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a) + : __tree_(_VSTD::move(__m.__tree_), __a) +{ + if (__a != __m.get_allocator()) + { + const_iterator __e = cend(); + while (!__m.empty()) + __tree_.__insert_multi(__e.__i_, + _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_)); + } +} + +template +typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder +multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node() +{ + __node_allocator& __na = __tree_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first)); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __h.get_deleter().__second_constructed = true; + return __h; +} + +template +template ::value>::type + > +typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder +multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) +{ + __node_allocator& __na = __tree_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0)); + __h.get_deleter().__first_constructed = true; + __h.get_deleter().__second_constructed = true; + return __h; +} + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template +template ::value>::type + > +typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder +multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args) +{ + __node_allocator& __na = __tree_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0)); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second), _VSTD::forward<_Args>(__args)...); + __h.get_deleter().__second_constructed = true; + return __h; +} + +#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + +template +template ::value>::type + > +typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator +multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), + _VSTD::forward<_Args>(__args)...); + iterator __r = __tree_.__node_insert_multi(__h.get()); + __h.release(); + return __r; +} + +template +template ::value>::type + > +typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator +multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p, + _A0&& __a0, + _Args&& ...__args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), + _VSTD::forward<_Args>(__args)...); + iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get()); + __h.release(); + return __r; +} + +#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__x == __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return __y < __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__x < __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return !(__y < __x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x, + multimap<_Key, _Tp, _Compare, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_MAP diff --git a/contrib/libc++/include/memory b/contrib/libc++/include/memory new file mode 100644 index 000000000000..878dda8730d9 --- /dev/null +++ b/contrib/libc++/include/memory @@ -0,0 +1,4193 @@ +// -*- C++ -*- +//===-------------------------- memory ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_MEMORY +#define _LIBCPP_MEMORY + +/* + memory synopsis + +namespace std +{ + +struct allocator_arg_t { }; +constexpr allocator_arg_t allocator_arg = allocator_arg_t(); + +template struct uses_allocator; + +template +struct pointer_traits +{ + typedef Ptr pointer; + typedef
element_type; + typedef
difference_type; + + template using rebind =
; + + static pointer pointer_to(
); +}; + +template +struct pointer_traits +{ + typedef T* pointer; + typedef T element_type; + typedef ptrdiff_t difference_type; + + template using rebind = U*; + + static pointer pointer_to(
) noexcept; +}; + +template +struct allocator_traits +{ + typedef Alloc allocator_type; + typedef typename allocator_type::value_type + value_type; + + typedef Alloc::pointer | value_type* pointer; + typedef Alloc::const_pointer + | pointer_traits::rebind + const_pointer; + typedef Alloc::void_pointer + | pointer_traits::rebind + void_pointer; + typedef Alloc::const_void_pointer + | pointer_traits::rebind + const_void_pointer; + typedef Alloc::difference_type + | pointer_traits::difference_type + difference_type; + typedef Alloc::size_type + | make_unsigned::type + size_type; + typedef Alloc::propagate_on_container_copy_assignment + | false_type propagate_on_container_copy_assignment; + typedef Alloc::propagate_on_container_move_assignment + | false_type propagate_on_container_move_assignment; + typedef Alloc::propagate_on_container_swap + | false_type propagate_on_container_swap; + + template using rebind_alloc = Alloc::rebind::other | Alloc; + template using rebind_traits = allocator_traits>; + + static pointer allocate(allocator_type& a, size_type n); + static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); + + static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; + + template + static void construct(allocator_type& a, T* p, Args&&... args); + + template + static void destroy(allocator_type& a, T* p); + + static size_type max_size(const allocator_type& a); + + static allocator_type + select_on_container_copy_construction(const allocator_type& a); +}; + +template <> +class allocator +{ +public: + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + + template struct rebind {typedef allocator<_Up> other;}; +}; + +template +class allocator +{ +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef typename add_lvalue_reference::type reference; + typedef typename add_lvalue_reference::type const_reference; + typedef T value_type; + + template struct rebind {typedef allocator other;}; + + allocator() noexcept; + allocator(const allocator&) noexcept; + template allocator(const allocator&) noexcept; + ~allocator(); + pointer address(reference x) const noexcept; + const_pointer address(const_reference x) const noexcept; + pointer allocate(size_type, allocator::const_pointer hint = 0); + void deallocate(pointer p, size_type n) noexcept; + size_type max_size() const noexcept; + template + void construct(U* p, Args&&... args); + template + void destroy(U* p); +}; + +template +bool operator==(const allocator&, const allocator&) noexcept; + +template +bool operator!=(const allocator&, const allocator&) noexcept; + +template +class raw_storage_iterator + : public iterator // purposefully not C++03 +{ +public: + explicit raw_storage_iterator(OutputIterator x); + raw_storage_iterator& operator*(); + raw_storage_iterator& operator=(const T& element); + raw_storage_iterator& operator++(); + raw_storage_iterator operator++(int); +}; + +template pair get_temporary_buffer(ptrdiff_t n) noexcept; +template void return_temporary_buffer(T* p) noexcept; + +template T* addressof(T& r) noexcept; + +template +ForwardIterator +uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); + +template +ForwardIterator +uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); + +template +void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); + +template +ForwardIterator +uninitialized_fill_n(ForwardIterator first, Size n, const T& x); + +template struct auto_ptr_ref {}; + +template +class auto_ptr +{ +public: + typedef X element_type; + + explicit auto_ptr(X* p =0) throw(); + auto_ptr(auto_ptr&) throw(); + template auto_ptr(auto_ptr&) throw(); + auto_ptr& operator=(auto_ptr&) throw(); + template auto_ptr& operator=(auto_ptr&) throw(); + auto_ptr& operator=(auto_ptr_ref r) throw(); + ~auto_ptr() throw(); + + typename add_lvalue_reference::type operator*() const throw(); + X* operator->() const throw(); + X* get() const throw(); + X* release() throw(); + void reset(X* p =0) throw(); + + auto_ptr(auto_ptr_ref) throw(); + template operator auto_ptr_ref() throw(); + template operator auto_ptr() throw(); +}; + +template +struct default_delete +{ + constexpr default_delete() noexcept = default; + template default_delete(const default_delete&) noexcept; + + void operator()(T*) const noexcept; +}; + +template +struct default_delete +{ + constexpr default_delete() noexcept = default; + void operator()(T*) const noexcept; + template void operator()(U*) const = delete; +}; + +template > +class unique_ptr +{ +public: + typedef see below pointer; + typedef T element_type; + typedef D deleter_type; + + // constructors + constexpr unique_ptr() noexcept; + explicit unique_ptr(pointer p) noexcept; + unique_ptr(pointer p, see below d1) noexcept; + unique_ptr(pointer p, see below d2) noexcept; + unique_ptr(unique_ptr&& u) noexcept; + unique_ptr(nullptr_t) noexcept : unique_ptr() { } + template + unique_ptr(unique_ptr&& u) noexcept; + template + unique_ptr(auto_ptr&& u) noexcept; + + // destructor + ~unique_ptr(); + + // assignment + unique_ptr& operator=(unique_ptr&& u) noexcept; + template unique_ptr& operator=(unique_ptr&& u) noexcept; + unique_ptr& operator=(nullptr_t) noexcept; + + // observers + typename add_lvalue_reference::type operator*() const; + pointer operator->() const noexcept; + pointer get() const noexcept; + deleter_type& get_deleter() noexcept; + const deleter_type& get_deleter() const noexcept; + explicit operator bool() const noexcept; + + // modifiers + pointer release() noexcept; + void reset(pointer p = pointer()) noexcept; + void swap(unique_ptr& u) noexcept; +}; + +template +class unique_ptr +{ +public: + typedef implementation-defined pointer; + typedef T element_type; + typedef D deleter_type; + + // constructors + constexpr unique_ptr() noexcept; + explicit unique_ptr(pointer p) noexcept; + unique_ptr(pointer p, see below d) noexcept; + unique_ptr(pointer p, see below d) noexcept; + unique_ptr(unique_ptr&& u) noexcept; + unique_ptr(nullptr_t) noexcept : unique_ptr() { } + + // destructor + ~unique_ptr(); + + // assignment + unique_ptr& operator=(unique_ptr&& u) noexcept; + unique_ptr& operator=(nullptr_t) noexcept; + + // observers + T& operator[](size_t i) const; + pointer get() const noexcept; + deleter_type& get_deleter() noexcept; + const deleter_type& get_deleter() const noexcept; + explicit operator bool() const noexcept; + + // modifiers + pointer release() noexcept; + void reset(pointer p = pointer()) noexcept; + void reset(nullptr_t) noexcept; + template void reset(U) = delete; + void swap(unique_ptr& u) noexcept; +}; + +template + void swap(unique_ptr& x, unique_ptr& y) noexcept; + +template + bool operator==(const unique_ptr& x, const unique_ptr& y); +template + bool operator!=(const unique_ptr& x, const unique_ptr& y); +template + bool operator<(const unique_ptr& x, const unique_ptr& y); +template + bool operator<=(const unique_ptr& x, const unique_ptr& y); +template + bool operator>(const unique_ptr& x, const unique_ptr& y); +template + bool operator>=(const unique_ptr& x, const unique_ptr& y); + +template + bool operator==(const unique_ptr& x, nullptr_t) noexcept; +template + bool operator==(nullptr_t, const unique_ptr& y) noexcept; +template + bool operator!=(const unique_ptr& x, nullptr_t) noexcept; +template + bool operator!=(nullptr_t, const unique_ptr& y) noexcept; + +template + bool operator<(const unique_ptr& x, nullptr_t); +template + bool operator<(nullptr_t, const unique_ptr& y); +template + bool operator<=(const unique_ptr& x, nullptr_t); +template + bool operator<=(nullptr_t, const unique_ptr& y); +template + bool operator>(const unique_ptr& x, nullptr_t); +template + bool operator>(nullptr_t, const unique_ptr& y); +template + bool operator>=(const unique_ptr& x, nullptr_t); +template + bool operator>=(nullptr_t, const unique_ptr& y); + +class bad_weak_ptr + : public std::exception +{ + bad_weak_ptr() noexcept; +}; + +template +class shared_ptr +{ +public: + typedef T element_type; + + // constructors: + constexpr shared_ptr() noexcept; + template explicit shared_ptr(Y* p); + template shared_ptr(Y* p, D d); + template shared_ptr(Y* p, D d, A a); + template shared_ptr(nullptr_t p, D d); + template shared_ptr(nullptr_t p, D d, A a); + template shared_ptr(const shared_ptr& r, T *p) noexcept; + shared_ptr(const shared_ptr& r) noexcept; + template shared_ptr(const shared_ptr& r) noexcept; + shared_ptr(shared_ptr&& r) noexcept; + template shared_ptr(shared_ptr&& r) noexcept; + template explicit shared_ptr(const weak_ptr& r); + template shared_ptr(auto_ptr&& r); + template shared_ptr(unique_ptr&& r); + shared_ptr(nullptr_t) : shared_ptr() { } + + // destructor: + ~shared_ptr(); + + // assignment: + shared_ptr& operator=(const shared_ptr& r) noexcept; + template shared_ptr& operator=(const shared_ptr& r) noexcept; + shared_ptr& operator=(shared_ptr&& r) noexcept; + template shared_ptr& operator=(shared_ptr&& r); + template shared_ptr& operator=(auto_ptr&& r); + template shared_ptr& operator=(unique_ptr&& r); + + // modifiers: + void swap(shared_ptr& r) noexcept; + void reset() noexcept; + template void reset(Y* p); + template void reset(Y* p, D d); + template void reset(Y* p, D d, A a); + + // observers: + T* get() const noexcept; + T& operator*() const noexcept; + T* operator->() const noexcept; + long use_count() const noexcept; + bool unique() const noexcept; + explicit operator bool() const noexcept; + template bool owner_before(shared_ptr const& b) const; + template bool owner_before(weak_ptr const& b) const; +}; + +// shared_ptr comparisons: +template + bool operator==(shared_ptr const& a, shared_ptr const& b) noexcept; +template + bool operator!=(shared_ptr const& a, shared_ptr const& b) noexcept; +template + bool operator<(shared_ptr const& a, shared_ptr const& b) noexcept; +template + bool operator>(shared_ptr const& a, shared_ptr const& b) noexcept; +template + bool operator<=(shared_ptr const& a, shared_ptr const& b) noexcept; +template + bool operator>=(shared_ptr const& a, shared_ptr const& b) noexcept; + +template + bool operator==(const shared_ptr& x, nullptr_t) noexcept; +template + bool operator==(nullptr_t, const shared_ptr& y) noexcept; +template + bool operator!=(const shared_ptr& x, nullptr_t) noexcept; +template + bool operator!=(nullptr_t, const shared_ptr& y) noexcept; +template + bool operator<(const shared_ptr& x, nullptr_t) noexcept; +template +bool operator<(nullptr_t, const shared_ptr& y) noexcept; +template + bool operator<=(const shared_ptr& x, nullptr_t) noexcept; +template + bool operator<=(nullptr_t, const shared_ptr& y) noexcept; +template + bool operator>(const shared_ptr& x, nullptr_t) noexcept; +template + bool operator>(nullptr_t, const shared_ptr& y) noexcept; +template + bool operator>=(const shared_ptr& x, nullptr_t) noexcept; +template + bool operator>=(nullptr_t, const shared_ptr& y) noexcept; + +// shared_ptr specialized algorithms: +template void swap(shared_ptr& a, shared_ptr& b) noexcept; + +// shared_ptr casts: +template + shared_ptr static_pointer_cast(shared_ptr const& r) noexcept; +template + shared_ptr dynamic_pointer_cast(shared_ptr const& r) noexcept; +template + shared_ptr const_pointer_cast(shared_ptr const& r) noexcept; + +// shared_ptr I/O: +template + basic_ostream& operator<< (basic_ostream& os, shared_ptr const& p); + +// shared_ptr get_deleter: +template D* get_deleter(shared_ptr const& p) noexcept; + +template + shared_ptr make_shared(Args&&... args); +template + shared_ptr allocate_shared(const A& a, Args&&... args); + +template +class weak_ptr +{ +public: + typedef T element_type; + + // constructors + constexpr weak_ptr() noexcept; + template weak_ptr(shared_ptr const& r) noexcept; + weak_ptr(weak_ptr const& r) noexcept; + template weak_ptr(weak_ptr const& r) noexcept; + + // destructor + ~weak_ptr(); + + // assignment + weak_ptr& operator=(weak_ptr const& r) noexcept; + template weak_ptr& operator=(weak_ptr const& r) noexcept; + template weak_ptr& operator=(shared_ptr const& r) noexcept; + + // modifiers + void swap(weak_ptr& r) noexcept; + void reset() noexcept; + + // observers + long use_count() const noexcept; + bool expired() const noexcept; + shared_ptr lock() const noexcept; + template bool owner_before(shared_ptr const& b); + template bool owner_before(weak_ptr const& b); +}; + +// weak_ptr specialized algorithms: +template void swap(weak_ptr& a, weak_ptr& b) noexcept; + +// class owner_less: +template struct owner_less; + +template +struct owner_less> + : binary_function, shared_ptr, bool> +{ + typedef bool result_type; + bool operator()(shared_ptr const&, shared_ptr const&) const; + bool operator()(shared_ptr const&, weak_ptr const&) const; + bool operator()(weak_ptr const&, shared_ptr const&) const; +}; + +template +struct owner_less> + : binary_function, weak_ptr, bool> +{ + typedef bool result_type; + bool operator()(weak_ptr const&, weak_ptr const&) const; + bool operator()(shared_ptr const&, weak_ptr const&) const; + bool operator()(weak_ptr const&, shared_ptr const&) const; +}; + +template +class enable_shared_from_this +{ +protected: + constexpr enable_shared_from_this() noexcept; + enable_shared_from_this(enable_shared_from_this const&) noexcept; + enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept; + ~enable_shared_from_this(); +public: + shared_ptr shared_from_this(); + shared_ptr shared_from_this() const; +}; + +template + bool atomic_is_lock_free(const shared_ptr* p); +template + shared_ptr atomic_load(const shared_ptr* p); +template + shared_ptr atomic_load_explicit(const shared_ptr* p, memory_order mo); +template + void atomic_store(shared_ptr* p, shared_ptr r); +template + void atomic_store_explicit(shared_ptr* p, shared_ptr r, memory_order mo); +template + shared_ptr atomic_exchange(shared_ptr* p, shared_ptr r); +template + shared_ptr + atomic_exchange_explicit(shared_ptr* p, shared_ptr r, memory_order mo); +template + bool + atomic_compare_exchange_weak(shared_ptr* p, shared_ptr* v, shared_ptr w); +template + bool + atomic_compare_exchange_strong( shared_ptr* p, shared_ptr* v, shared_ptr w); +template + bool + atomic_compare_exchange_weak_explicit(shared_ptr* p, shared_ptr* v, + shared_ptr w, memory_order success, + memory_order failure); +template + bool + atomic_compare_exchange_strong_explicit(shared_ptr* p, shared_ptr* v, + shared_ptr w, memory_order success, + memory_order failure); +// Hash support +template struct hash; +template struct hash >; +template struct hash >; + +// Pointer safety +enum class pointer_safety { relaxed, preferred, strict }; +void declare_reachable(void *p); +template T *undeclare_reachable(T *p); +void declare_no_pointers(char *p, size_t n); +void undeclare_no_pointers(char *p, size_t n); +pointer_safety get_pointer_safety() noexcept; + +void* align(size_t alignment, size_t size, void*& ptr, size_t& space); + +} // std + +*/ + +#include <__config> +#include +#include +#include +#include +#include +#include +#include +#include +#include <__functional_base> +#include +#if defined(_LIBCPP_NO_EXCEPTIONS) + #include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// allocator_arg_t + +struct _LIBCPP_VISIBLE allocator_arg_t { }; + +extern const allocator_arg_t allocator_arg; + +// addressof + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +addressof(_Tp& __x) _NOEXCEPT +{ + return (_Tp*)&(char&)__x; +} + +#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) +// Objective-C++ Automatic Reference Counting uses qualified pointers +// that require special addressof() signatures. When +// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler +// itself is providing these definitions. Otherwise, we provide them. +template +inline _LIBCPP_INLINE_VISIBILITY +__strong _Tp* +addressof(__strong _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK +template +inline _LIBCPP_INLINE_VISIBILITY +__weak _Tp* +addressof(__weak _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +__autoreleasing _Tp* +addressof(__autoreleasing _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__unsafe_unretained _Tp* +addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +template class allocator; + +template <> +class _LIBCPP_VISIBLE allocator +{ +public: + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + + template struct rebind {typedef allocator<_Up> other;}; +}; + +// pointer_traits + +template +struct __has_element_type +{ +private: + struct __two {char _; char __;}; + template static __two __test(...); + template static char __test(typename _Up::element_type* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template ::value> +struct __pointer_traits_element_type; + +template +struct __pointer_traits_element_type<_Ptr, true> +{ + typedef typename _Ptr::element_type type; +}; + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template