publib-0.40/0000775000175000017500000000000011767707451011027 5ustar ajkajkpublib-0.40/iset/0000775000175000017500000000000011767707451011773 5ustar ajkajkpublib-0.40/iset/iset_copy.c0000664000175000017500000000423111767417657014143 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_copy.c -- create a copy of an iset * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_copy.c,v 1.3 1994/07/16 15:28:52 liw Exp $" */ #include #include #include #include "publib/iset.h" #include "publib/errormsg.h" Iset *iset_copy(const Iset *is) { Iset *isnew; struct __iset_range *r, *rnew; assert(is != NULL); isnew = iset_create(); if (isnew == NULL) return NULL; for (r = is->lowest; r != NULL; r = r->next) { rnew = malloc(sizeof(struct __iset_range)); if (rnew == NULL) { __publib_error("malloc failed"); iset_destroy(isnew); return NULL; } rnew->start = r->start; rnew->end = r->end; rnew->prev = isnew->highest; rnew->next = NULL; isnew->highest = rnew; if (isnew->lowest == NULL) isnew->lowest = rnew; } return isnew; } publib-0.40/iset/iset_range.c0000664000175000017500000000353211767417657014270 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_range.c -- return the range of numbers in an iset * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_range.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #include #include /* need NULL */ #include "publib/iset.h" void iset_range(const Iset *is, long *lowest, long *highest) { assert(is != NULL); assert(is->lowest != NULL); assert(is->highest != NULL); if (lowest != NULL) *lowest = is->lowest->start; if (highest != NULL) *highest = is->highest->start; } publib-0.40/iset/iset_isect.c0000664000175000017500000000364211767417657014305 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_iset.c -- remove elements from set that are not also in another set * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_isect.c,v 1.1.1.1 1993/11/20 17:02:32 liw Exp $" */ #include #include /* need NULL */ #include "publib/iset.h" int iset_isect(Iset *is1, const Iset *is2) { struct __iset_range *r; long i; assert(is1 != NULL); assert(is2 != NULL); for (r = is1->lowest; r != NULL; r = r->next) for (i = r->start; i <= r->end; ++i) if (!iset_contains(is2, i)) if (iset_remove(is1, i) == -1) return -1; return 0; } publib-0.40/iset/iset_add.c0000664000175000017500000000726411767417657013732 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_add.c -- add an integer to an iset * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_add.c,v 1.5 1995/08/25 20:45:09 liw Exp $" */ #include #include #include "publib/iset.h" #include "publib/errormsg.h" /* insert new range into a list of ranges */ static int new_range(long start, long end, struct __iset_range *before, Iset *is) { struct __iset_range *rnew; assert(before != NULL); assert(is != NULL); rnew = malloc(sizeof(struct __iset_range)); if (rnew == NULL) { __publib_error("malloc failed"); return -1; } rnew->start = start; rnew->end = end; if (before == NULL) { /* append to list of ranges */ rnew->next = NULL; rnew->prev = is->highest; if (is->highest != NULL) is->highest->next = rnew; is->highest = rnew; if (is->lowest == NULL) is->lowest = rnew; } else { /* insert before `before' */ rnew->next = before; rnew->prev = before->prev; before->prev = rnew; if (rnew->prev != NULL) rnew->prev->next = rnew; else { is->lowest = rnew; if (is->highest == NULL) is->highest = rnew; } } return 0; } /* see if a range is adjacent to its neighbors and join it with them if so */ static void join_ranges(Iset *is, struct __iset_range *r) { struct __iset_range *temp; assert(is != NULL); assert(r != NULL); if (r->prev != NULL && r->prev->end == r->start-1) { r->prev->end = r->end; r->prev->next = r->next; if (r->next != NULL) r->next->prev = r->prev; else is->highest = r->prev; temp = r; r = r->prev; free(temp); } if (r->next != NULL && r->next->start == r->end+1) { r->next->start = r->start; r->next->prev = r->prev; if (r->prev != NULL) r->prev->next = r->next; else is->lowest = r->next; free(r); } } int iset_add(Iset *is, long number) { struct __iset_range *r; assert(is != NULL); for (r = is->lowest; r != NULL; r = r->next) { if (r->start <= number && number <= r->end) return 0; /* number already in set */ if (number == r->start-1) { --r->start; join_ranges(is, r); return 0; /* increase existing range */ } if (number == r->end+1) { ++r->end; join_ranges(is, r); return 0; /* increase existing range */ } if (number < r->start) return new_range(number, number, r, is); } /* FIXME: the following will never work! */ return new_range(number, number, NULL, is); } publib-0.40/iset/iset_create.c0000664000175000017500000000341111767417657014433 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_create.c -- create an empty integer set * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_create.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #include #include "publib/iset.h" #include "publib/errormsg.h" Iset *iset_create(void) { Iset *is; is = malloc(sizeof(Iset)); if (is == NULL) { __publib_error("malloc failed"); return NULL; } is->lowest = is->highest = NULL; return is; } publib-0.40/iset/iset_is_empty.c0000664000175000017500000000326211767417657015025 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_is_empty.c -- test whether an iset is empty * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_is_empty.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #include #include /* need NULL */ #include "publib/iset.h" int iset_is_empty(const Iset *is) { assert(is != NULL); return is->lowest == NULL; } publib-0.40/iset/iset_add_rng.c0000664000175000017500000000344611767417657014576 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_add_range.c -- add a range of integers to an iset * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_add_rng.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #include #include #include "publib/iset.h" int iset_add_range(Iset *is, long number1, long number2) { long i; assert(is != NULL); assert(number1 <= number2); for (i = number1; i <= number2; ++i) if (iset_add(is, i) == -1) return -1; return 0; } publib-0.40/iset/iset_nth_rng.c0000664000175000017500000000363711767417657014641 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_nth_rng.c -- return the ends of the nth consecutive range of values * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_nth_rng.c,v 1.1.1.1 1993/11/20 17:02:32 liw Exp $" */ #include #include #include "publib/iset.h" int iset_nth_range(const Iset *is, long n, long *lo, long *hi) { struct __iset_range *r; assert(is != NULL); assert(lo != NULL); assert(hi != NULL); assert(n > 0); for (r = is->lowest; n > 1 && r != NULL; --n, r = r->next) continue; if (r == NULL) return -1; *lo = r->start; *hi = r->end; return 0; } publib-0.40/iset/iset_clear.c0000664000175000017500000000337411767417657014266 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * is_clear.c -- make an iset be empty * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_clear.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #include #include #include "publib/iset.h" void iset_clear(Iset *is) { struct __iset_range *r; assert(is != NULL); while (is->lowest != NULL) { r = is->lowest; is->lowest = is->lowest->next; free(r); } is->highest = NULL; } publib-0.40/iset/iset_contains.c0000664000175000017500000000352411767417657015013 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_contains.c -- check whether an iset contains a number * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_contains.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #include #include /* need NULL */ #include "publib/iset.h" int iset_contains(const Iset *is, long number) { struct __iset_range *r; assert(is != NULL); for (r = is->lowest; r != NULL && r->end < number; r = r->next) continue; return (r != NULL && r->start <= number && number <= r->end); } publib-0.40/iset/iset_rm_rng.c0000664000175000017500000000350211767417657014455 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_remove_range.c -- remove a range of numbers from an iset * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_rm_rng.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #include #include /* need NULL */ #include "publib/iset.h" int iset_remove_range(Iset *is, long number1, long number2) { long i; assert(is != NULL); assert(number1 <= number2); for (i = number1; i <= number2; ++i) if (iset_remove(is, i) == -1) return -1; return 0; } publib-0.40/iset/iset_remove.c0000664000175000017500000000514611767417657014474 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_remove.c -- remove a number from an iset * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_remove.c,v 1.3 1994/07/16 15:28:53 liw Exp $" */ #include #include #include "publib/iset.h" #include "publib/errormsg.h" int iset_remove(Iset *is, long number) { struct __iset_range *r, *rnew; assert(is != NULL); for (r = is->lowest; r != NULL && r->end < number; r = r->next) continue; if (r == NULL || r->start > number) return 0; /* number not in iset, nothing to do */ assert(r->start <= number && number <= r->end); if (r->start == number && r->end == number) { if (r->prev == NULL) is->lowest = r->next; else r->prev->next = r->next; if (r->next == NULL) is->highest = r->prev; else r->next->prev = r->prev; free(r); return 0; } if (r->start == number) { ++r->start; return 0; } if (r->end == number) { --r->end; return 0; } /* split range into two */ rnew = malloc(sizeof(struct __iset_range)); if (rnew == NULL) { __publib_error("malloc failed"); return -1; } rnew->start = number+1; rnew->end = r->end; r->end = number-1; assert(is->lowest != NULL); rnew->next = r->next; rnew->prev = r; r->next = rnew; if (rnew->next != NULL) rnew->next->prev = rnew; return 0; } publib-0.40/iset/iset_diff.c0000664000175000017500000000347411767417657014111 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_diff.c -- take set difference * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_diff.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #include #include /* need NULL */ #include "publib/iset.h" int iset_diff(Iset *is1, const Iset *is2) { struct __iset_range *r; assert(is1 != NULL); assert(is2 != NULL); for (r = is2->lowest; r != NULL; r = r->next) if (iset_remove_range(is1, r->start, r->end) == -1) return -1; return 0; } publib-0.40/iset/iset_union.c0000664000175000017500000000352311767417657014324 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_union.c -- add all numbers in an iset to another iset * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_union.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #include #include /* need NULL */ #include "publib/iset.h" int iset_union(Iset *is1, const Iset *is2) { struct __iset_range *r; assert(is1 != NULL); assert(is2 != NULL); for (r = is2->lowest; r != NULL; r = r->next) if (iset_add_range(is1, r->start, r->end) == -1) return -1; return 0; } publib-0.40/iset/test_add.c0000664000175000017500000000374611767417657013746 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * add.c -- add numbers to an iset, then print out minimum ranges * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: test_add.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #undef NDEBUG #include #include #include #include "publib/iset.h" void dump(Iset *is) { struct __iset_range *r; printf("dump:"); for (r = is->lowest; r != NULL; r = r->next) printf(" %ld-%ld", r->start, r->end); printf("\n"); } int main(void) { int i; Iset *is; assert((is = iset_create()) != NULL); dump(is); while (scanf("%d", &i) == 1) { assert(iset_add(is, i) != -1); dump(is); } iset_destroy(is); exit(0); } publib-0.40/iset/iset_destroy.c0000664000175000017500000000324011767417657014661 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset_destroy.c -- free resources allocated to an iset * * Part of publib. See man page for more information * "@(#)publib-iset:$Id: iset_destroy.c,v 1.1.1.1 1993/11/20 17:02:31 liw Exp $" */ #include #include #include "publib/iset.h" void iset_destroy(Iset *is) { assert(is != NULL); iset_clear(is); free(is); } publib-0.40/lockfile/0000775000175000017500000000000011767707451012617 5ustar ajkajkpublib-0.40/lockfile/lockfile.c0000664000175000017500000000466411767417657014573 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: lockfile.c * Purpose: Create a lock file. * Author: Lars Wirzenius * Version: $Id: lockfile.c,v 1.2 1997/04/26 23:52:21 liw Exp $ */ #include #include #include #include #include #include #include #include "publib/lockfile.h" /* * Function: lockfile_create * Purpose: Create a lock file. */ int lockfile_create(const char *lockname) { char tempname[FILENAME_MAX + 256]; /* enough for template */ char dir[FILENAME_MAX]; struct stat st; int e, fd; if (strlen(lockname) > FILENAME_MAX) { errno = ENAMETOOLONG; return -1; } fndir(dir, lockname); fnjoin(tempname, dir, ".temp-lock"); fd = open(tempname, O_CREAT | O_EXCL, 0600); if (fd == -1) return -1; (void) close(fd); if (link(tempname, lockname) == -1 || stat(lockname, &st) == -1 || st.st_nlink != 2) { e = errno; (void) unlink(tempname); errno = e; return -1; } (void) unlink(tempname); return 0; } /* * Function: lockfile_remove * Purpose: Remove a lock file. */ int lockfile_remove(const char *lockname) { return unlink(lockname); } publib-0.40/alloc/0000775000175000017500000000000011767707451012121 5ustar ajkajkpublib-0.40/alloc/memdup.c0000664000175000017500000000344611767417657013571 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memdup.c -- duplicate memory block * * Part of publib. See man page for more information * "@(#)publib-alloc:$Id: memdup.c,v 1.2 1995/11/26 10:13:06 liw Exp $" */ #include #include #include #include "publib/alloc.h" #include "publib/errormsg.h" void *memdup(const void *p, size_t n) { void *q; assert(p != NULL); assert(n > 0); q = malloc(n); if (q == NULL) __publib_error("malloc failed"); else memcpy(q, p, n); return q; } publib-0.40/alloc/dynarr.c0000664000175000017500000000462611767417657013602 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * dynarr.c -- dynamic arrays * * Part of publib. See man page for more information * "@(#)publib-alloc:$Id: dynarr.c,v 1.5 1995/11/26 10:13:06 liw Exp $" */ #include #include #include #include "publib/alloc.h" #include "publib/errormsg.h" void dynarr_init(struct dynarr *da, size_t elsize) { assert(da != NULL); da->data = NULL; da->alloc = da->used = 0; da->elsize = elsize; } int dynarr_resize(struct dynarr *da, size_t newsize) { void *p; assert(da != NULL); assert(newsize > 0); if ((p = realloc(da->data, newsize * da->elsize)) == NULL) return -1; da->data = p; da->alloc = newsize; if (da->used > newsize) da->used = newsize; return 0; } int dynarr_copy(struct dynarr *copy, const struct dynarr *orig) { dynarr_init(copy, orig->elsize); if (orig->used > 0) { if (dynarr_resize(copy, orig->used) == -1) return -1; memcpy(copy->data, orig->data, orig->elsize * orig->used); } copy->used = orig->used; return 0; } void dynarr_free(struct dynarr *da) { assert(da != NULL); free(da->data); dynarr_init(da, da->elsize); } publib-0.40/alloc/xrealloc.c0000664000175000017500000000343411767417657014110 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * xrealloc.c -- error checking realloc * * Part of publib. See man page for more information * "@(#)publib-alloc:$Id: xrealloc.c,v 1.3 1994/07/16 12:06:38 liw Exp $" */ #include #include #include "publib/alloc.h" #include "publib/errormsg.h" void *xrealloc(void *p, size_t n) { char *q; assert(n > 0); if (p == NULL) q = malloc(n); else q = realloc(p, n); if (q == NULL) __publib_error("malloc or realloc failed"); return q; } publib-0.40/alloc/xfree.c0000664000175000017500000000316711767417657013413 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * xfree.c -- frontend for free (mostly for symmetricity with x*alloc) * * Part of publib. See man page for more information * "@(#)publib-alloc:$Id: xfree.c,v 1.1.1.1 1993/11/20 17:01:28 liw Exp $" */ #include #include "publib/alloc.h" void xfree(void *p) { if (p != NULL) free(p); } publib-0.40/alloc/xmemdup.c0000664000175000017500000000343511767417657013757 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * xmemdup.c -- error checking memdup * * Part of publib. See man page for more information * "@(#)publib-alloc:$Id: xmemdup.c,v 1.2 1994/12/27 12:39:13 wirzeniu Exp $" */ #include #include #include "publib/alloc.h" #include "publib/errormsg.h" void *xmemdup(const void *p, size_t n) { char *q; assert(p != NULL); assert(n > 0); q = memdup(p, n); if (q == NULL) { __publib_error("memdup failed"); exit(EXIT_FAILURE); } return q; } publib-0.40/alloc/xstrdup.c0000664000175000017500000000340411767417657014005 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * xstrdup.c -- error checking string duplication * * Part of publib. See man page for more information * "@(#)publib-alloc:$Id: xstrdup.c,v 1.1.1.1 1993/11/20 17:01:28 liw Exp $" */ #include #include #include #include "publib/alloc.h" #include "publib/errormsg.h" char *xstrdup(const char *s) { char *p; assert(s != NULL); p = strdup(s); if (p == NULL) __publib_error("strdup failed"); return p; } publib-0.40/alloc/xmalloc.c0000664000175000017500000000336711767417657013743 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * xmalloc.c -- error checking malloc * * Part of publib. See man page for more information * "@(#)publib-alloc:$Id: xmalloc.c,v 1.4 1994/12/27 12:39:53 wirzeniu Exp $" */ #include #include #include "publib/alloc.h" #include "publib/errormsg.h" void *xmalloc(size_t n) { char *q; assert(n > 0); q = malloc(n); if (q == NULL) { __publib_error("malloc failed"); exit(EXIT_FAILURE); } return q; } publib-0.40/main/0000775000175000017500000000000011767707451011753 5ustar ajkajkpublib-0.40/main/test-main-filter.c0000664000175000017500000000411011767417657015305 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * test-main-filter.c -- test the main_filter function * * Lars Wirzenius. * Part of Publib. See publib(3). * "@(#)publib-main:$Id: test-main-filter.c,v 1.1 1995/12/05 21:33:55 liw Exp $" */ #include #include static int count_lines(FILE *f, char *name, void *totalptr) { long lines; int c; lines = 0; while ((c = getc(f)) != EOF) if (c == '\n') ++lines; *((long *) totalptr) += lines; if (ferror(f)) return -1; printf("%6ld %s\n", lines, name); return 0; } int main(int argc, char **argv) { long total_lines = 0; int ret; set_progname(argv[0], "test-main-filter"); ret = main_filter(argc-1, argv+1, count_lines, &total_lines); printf("main_filter returned %d, total_lines=%ld\n", ret, total_lines); return 0; } publib-0.40/main/main_filter.c0000664000175000017500000000463711767417657014430 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * main_filter.c -- process files for a typical UNIX filter. * * Lars Wirzenius. * Part of Publib. See publib(3). * "@(#)publib-main:$Id: main_filter.c,v 1.3 2003/11/15 18:24:10 liw Exp $" */ #include #include #include #include "publib/errormsg.h" #include "publib/main.h" int main_filter(int n, char **v, int (*fun)(FILE *, char *, void *), void *x) { FILE *f; int i, ret; assert(n >= 0); assert(v != NULL); assert(fun != NULL); #ifndef NDEBUG for (i = 0; i < n; ++i) assert(v[i] != NULL); #endif ret = 0; if (n == 0) ret = fun(stdin, "stdin", x); else { for (i = 0; i < n; ++i) { if (strcmp(v[i], "-") == 0) f = stdin; else { f = fopen(v[i], "r"); if (f == NULL) { errormsg(0, -1, "couldn't open " "file `%s' for reading", v[i]); continue; } } if (fun(f, v[i], x) == -1) ret = -1; if (ferror(f)) { errormsg(0, -1, "error with file `%s'", v[i]); ret = -1; } if (f != stdin && fclose(f) == EOF) { errormsg(0, -1, "error closing file `%s'", v[i]); } } } return ret; } publib-0.40/ChangeLog.old0000664000175000017500000000530511767420007013346 0ustar ajkajk2006-03-12 Lars Wirzenius * publib is now being maintained under bzr, and this change log is replaced by commit messages to bzr, plus a NEWS file that gets updated at release time. 2004-08-07 Lars Wirzenius * framework/link-alternative-names: Fixed to work with Posix sh, not just Bash. * Making release version 0.38. 2004-08-05 Lars Wirzenius * Removed liw/cfg and liw/lsm, since no-body uses them and they were broken and I didn't feel like fixing them. (Anyone wanting to take over publib development should probably say so now.) * Removed "pub" from the tbuf.3 manual page, since it was the only one that had the suffix. * Making release version 0.37. 2004-07-11 Lars Wirzenius * Making release version 0.36. 2004-07-11 Lars Wirzenius * liw/strutil/struncstr.c: Bugfix for octal escape sequences: three digit sequences now work. Thanks to Peter T. Beuer for the bug report and fix. 2004-02-21 Lars Wirzenius * liw/expr: Removed, since it was broken, and too simple to really be useful, and I didn't want to spend the time to fix it. 2003-11-15 Lars Wirzenius * Making release version 0.35. 2003-11-15 Lars Wirzenius * liw/base64/base64.c: Rewrote the encoding and decoding functions, since the old code was crap. The bug was reported by Timothee Besset, though I didn't use his code to fix it. The old code did not work with MIME conforming base64 implementations. * liw/lsm/lsm_read_entry.c: Fixed compiler warning by initializing a variable. Wasn't a bug, but shutting up the compiler was worth it. * liw/main/main_filter.c, liw/sbuf/test-sbuf.c, liw/tbuf/tbuf.c: Added missing includes for * liw/tbuf/test_tbuf_with_stats.c: Commented out unused static functions to shut up a compiler warning. 2002-05-23 Lars Wirzenius * framework/Generic.mk, framework/link-alternative-names, liw/publibdocs/Makefile: Manual pages are installed compressed, and links to alternative names are created * framework/Makefile.in: Installation directories are now created. * Creating release 0.34. 2002-05-23 Lars Wirzenius * debian/*: Removed from upstream. I no longer maintain the Debian package. * Changes: Deleted. * liw/cfgtool/cfgtool_repo.c: Added a missing #include . * liw/nntp/nntp.c: Added a missing initialization of a variable. * liw/tbuf/tbuf.c: Commented out an unused static function. * liw/sbuf/sbuf_srch.c: Added missing #include for ( needs it). Thanks to Dmitry Astapov . * Releasing version 0.33. publib-0.40/echoexec.sh0000664000175000017500000000246511767417747013163 0ustar ajkajk#!/bin/sh # Copyright (c) 2012 Antti-Juhani Kaijanaho # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. echo $@ exec $@publib-0.40/log/0000775000175000017500000000000011767707451011610 5ustar ajkajkpublib-0.40/log/log.c0000664000175000017500000001155411767417657012551 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * log.c -- log files * * Part of publib. See man page for more information * "@(#)publib-log:$Id: log.c,v 1.12 1997/05/09 13:49:16 liw Exp $" */ #include #include #include #include "publib/log.h" #include "publib/errormsg.h" #define MAX 256 static struct { FILE *f; int min; int use_localtime; } logs[MAX]; static int nlogs = 0; static int log_is_on = 1; int log_open(const char *filename, int min_level) { FILE *f; assert(filename != NULL); assert(nlogs >= 0 && nlogs <= MAX); if (nlogs == MAX) { __publib_error("too many log files"); return -1; } f = fopen(filename, "a"); if (f == NULL) { __publib_error("fopen failed"); return -1; } logs[nlogs].f = f; logs[nlogs].min = min_level; logs[nlogs].use_localtime = 0; return nlogs++; } int log_add(FILE *f, int min_level) { assert(f != NULL); assert(nlogs >= 0 && nlogs <= MAX); if (nlogs == MAX) { __publib_error("too many log files"); return -1; } logs[nlogs].f = f; logs[nlogs].min = min_level; logs[nlogs].use_localtime = 0; return nlogs++; } void log_set_level(int logid, int min_level) { assert(logid >= 0); assert(logid < nlogs); logs[logid].min = min_level; } void log_set_localtime(int logid, int use_localtime) { assert(logid >= 0); assert(logid < nlogs); logs[logid].use_localtime = use_localtime; } int log_close(void) { int i, ret; assert(nlogs >= 0 && nlogs <= MAX); ret = 0; for (i = 0; i < nlogs; ++i) { if (fclose(logs[i].f) != 0) { __publib_error("fclose failed for logfile"); ret = -1; } } return ret; } void log_off(void) { log_is_on = 0; } void log_on(void) { log_is_on = 1; } /* All the functions log_chat through log_fatal are exactly the same, * except for the level argument to log_vprintf. Therefore, we use * a macro to emphasize the similarity and to avoid unnecessary * differences. */ #define do_log_at_level(level) \ void log_##level(const char *fmt, ...) { \ va_list args; \ struct tm *tm; \ time_t t; \ char buf1[100]; \ char buf2[200]; \ const char *p; \ int i; \ long pid; \ if (!log_is_on) return; \ p = get_progname(); \ if (*p == '\0') p = "unknown"; \ tm = NULL; \ pid = (long) getpid(); \ for (i = 0; i < nlogs; ++i) { \ if (log_level_##level < logs[i].min) continue; \ if (tm == NULL) { \ time(&t); \ if (logs[i].use_localtime) \ tm = localtime(&t); \ else \ tm = gmtime(&t); \ strftime(buf1, sizeof(buf1), \ "%Y-%m-%d %H-%M-%S %Z %%.50s %%ld %%d ", tm); \ sprintf(buf2, buf1, p, pid, log_level_##level);\ } \ va_start(args, fmt); \ (void) fputs(buf2, logs[i].f); \ (void) vfprintf(logs[i].f, fmt, args); \ (void) fflush(logs[i].f); \ va_end(args); \ } \ } do_log_at_level(chat) do_log_at_level(note) do_log_at_level(warn) do_log_at_level(error) do_log_at_level(fatal) void log_printf(int level, const char *fmt, ...) { va_list args; struct tm *tm; time_t t; char buf1[100]; char buf2[100]; const char *p; int i; long pid; if (!log_is_on) return; p = get_progname(); if (*p == '\0') p = "unknown"; tm = NULL; pid = (long) getpid(); for (i = 0; i < nlogs; ++i) { if (level >= logs[i].min) { if (tm == NULL) { time(&t); if (logs[i].use_localtime) tm = localtime(&t); else tm = gmtime(&t); strftime(buf1, sizeof(buf1), "%Y-%m-%d %H-%M-%S %Z %%.50s %%ld %%d ", tm); sprintf(buf2, buf1, p, pid, level); } va_start(args, fmt); (void) fputs(buf2, logs[i].f); (void) vfprintf(logs[i].f, fmt, args); (void) fflush(logs[i].f); va_end(args); } } } publib-0.40/log/test-log.c0000664000175000017500000000374211767417657013526 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * logtest.c -- test the log file routines * * Part of publib. See man page for more information * "@(#)publib-log:$Id: test-log.c,v 1.3 1997/05/09 13:49:16 liw Exp $" */ #include "publib/log.h" #include "publib/errormsg.h" int main(int argc, char **argv) { int i; set_progname(argv[0], "logtest"); i = log_open("test.log", log_level_error); log_set_localtime(i, 1); log_chat("1- This shouldn't be printed\n"); log_error("2- This should be printed\n"); log_off(); log_error("3- This shouldn't be printed\n"); log_on(); log_error("4- This should be printed\n"); log_printf(log_level_error, "5- This should be printed\n"); log_close(); return 0; } publib-0.40/base64/0000775000175000017500000000000011767707451012113 5ustar ajkajkpublib-0.40/base64/base64.c0000664000175000017500000000755411767417657013364 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: base64.c * Purpose: Implementation of MIME's Base64 encoding and decoding. * Author: Lars Wirzenius * Version: $Id: base64.c,v 1.2 2003/11/15 18:24:10 liw Exp $ */ #include #include "publib/base64.h" static const unsigned char sixtet_to_base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* * Function: base64_length * Purpose: Compute minimum length of encoded output. */ size_t base64_length(size_t n) { return 4*(n+3)/3 + 1; } /* * Function: base64_encode * Purpose: Convert octets to base64 * Note: Output buffer must be at least base64_length(n) chars. */ size_t base64_encode(char *to, const char *from, size_t n) { unsigned w; char *to_start; unsigned char *fromp; to_start = to; fromp = (unsigned char *) from; for (; n >= 3; n -= 3, fromp += 3) { w = (fromp[0] << 16) | (fromp[1] << 8) | fromp[2]; *to++ = sixtet_to_base64[(w >> 18) & 0x3f]; *to++ = sixtet_to_base64[(w >> 12) & 0x3f]; *to++ = sixtet_to_base64[(w >> 6) & 0x3f]; *to++ = sixtet_to_base64[w & 0x3f]; } switch (n) { case 0: /* Nothing to do */ break; case 1: w = fromp[0]; *to++ = sixtet_to_base64[(w >> 2) & 0x3f]; *to++ = sixtet_to_base64[(w << 4) & 0x3f]; *to++ = '='; *to++ = '='; break; case 2: w = (fromp[0] << 8) | fromp[1]; *to++ = sixtet_to_base64[(w >> 10) & 0x3f]; *to++ = sixtet_to_base64[(w >> 4) & 0x3f]; *to++ = sixtet_to_base64[(w << 2) & 0x3f]; *to++ = '='; break; } return to - to_start; } /* * Function: base64_decode * Purpose: Convert base64 to octets. * Note: Output buffer must be at least 3*n/4 chars. * The output buffer does not get a '\0' appended. */ size_t base64_decode(char *to, const char *from, size_t len) { static int base64_to_sixtet[UCHAR_MAX + 1]; static int tab_init = 0; int i; unsigned bitbuf; int nbits; unsigned char *fromp; char *to_start; if (!tab_init) { tab_init = 1; for (i = 0; i <= UCHAR_MAX + 1; ++i) base64_to_sixtet[i] = -1; for (i = 0; sixtet_to_base64[i] != '\0'; ++i) base64_to_sixtet[sixtet_to_base64[i]] = i; } to_start = to; bitbuf = 0; nbits = 0; fromp = (unsigned char *) from; for (i = 0; i < len && fromp[i] != '='; ++i) { if (base64_to_sixtet[fromp[i]] != -1) { bitbuf = (bitbuf << 6) | base64_to_sixtet[fromp[i]]; nbits += 6; if (nbits >= 8) { *to++ = (bitbuf >> (nbits - 8)) & 0xff; bitbuf >>= 8; nbits -= 8; } } } return to - to_start; } publib-0.40/strutil/0000775000175000017500000000000011767707451012535 5ustar ajkajkpublib-0.40/strutil/memarrfill.c0000664000175000017500000000343111767417657015042 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memarrfill.c -- copy first element of array to all elements * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memarrfill.c,v 1.1 1994/07/12 21:04:52 liw Exp $" */ #include #include #include "publib/strutil.h" void *memarrfill(void *arr, size_t elsize, size_t nelem) { assert(arr != NULL); assert(elsize > 0); if (nelem > 0) memfill((char*)arr+elsize, (nelem-1)*elsize, arr, elsize); return arr; } publib-0.40/strutil/strvars.c0000664000175000017500000000750711767417657014424 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strvars.c -- expand variables in string * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: strvars.c,v 1.6 1995/08/24 16:51:36 liw Exp $" */ #include #include #include #include "publib/strutil.h" #include "publib/errormsg.h" /* * Add `s' to end of `*r', allocating more memory. */ static int add_to_end(char **r, size_t *size, const char *str, size_t n) { char *p; p = realloc(*r, *size + n); if (p == NULL) { __publib_error("realloc failed"); return -1; } *r = p; memcpy(*r + *size, str, n); *size += n; return 0; } /* * Copy to next '$' or end of string (including '\0'). Return -1 for * error (out of memory), or 0 for '$' not found, or 1 for '$' found. * Advance *str appropriately. */ static int copy_to_dollar(char **r, size_t *size, const char **str) { size_t n; int ret; n = strcspn(*str, "$"); assert((*str)[n] == '\0' || (*str)[n] == '$'); if ((*str)[n] == '\0') { ++n; ret = 0; } else ret = 1; if (n > 0) { if (add_to_end(r, size, *str, n) == -1) return -1; *str += n; } return ret; } /* * Get value of a variable. Return NULL for failure, otherwise value. */ static char *value_of(const char **str, char *(*expand)(const char *)) { char *value; assert(str != NULL); assert(*str != NULL); assert(**str == '$'); if ((*str)[1] == '\0') { value = "$"; *str += 2; } else if ((*str)[1] == '(') { char *name; size_t n = strcspn(*str+2, ")"); if ((*str)[n] == '\0') { __publib_error("syntax error for variable reference"); return NULL; } *str += 2; name = strndup(*str, n); if (name == NULL) { __publib_error("strdup failed"); return NULL; } value = expand(name); free(name); if (value == NULL) { __publib_error("unknown variable name"); return NULL; } *str += n; } else { char onechar[] = "x"; onechar[0] = (*str)[1]; value = expand(onechar); if (value == NULL) { __publib_error("unknown variable name"); return NULL; } *str += 2; } return value; } int strvars(char **res, const char *str, char *(*expand)(const char *)) { char *r, *value; size_t size; int ret; assert(res != NULL); assert(str != NULL); assert(expand != NULL); r = NULL; size = 0; for (;;) { ret = copy_to_dollar(&r, &size, &str); if (ret == -1) return -1; else if (ret == 0) break; value = value_of(&str, expand); if (value == NULL) return -1; if (add_to_end(&r, &size, value, strlen(value) + 1) == -1) return -1; } *res = r; return 0; } publib-0.40/strutil/memrmem.c0000664000175000017500000000405411767417657014351 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memrmem.c -- reverse search for memory block inside another memory block * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memrmem.c,v 1.1 1994/06/20 20:30:01 liw Exp $" */ #include #include #include "publib/strutil.h" void *memrmem(const void *v, size_t size, const void *pat, size_t patsize) { const char *p; assert(v != NULL); assert(pat != NULL); /* Special cases */ if (size < patsize) return NULL; if (patsize == 0) return (void *) v; /* xxx - this will make p < v if pattern not found; potential portability problem */ for (p = v, p += size-patsize; size >= patsize; --p, --size) if (memcmp(p, pat, patsize) == 0) return (void *) p; return NULL; } publib-0.40/strutil/memshuffle.c0000664000175000017500000000357511767417657015054 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memshuffle.c -- make an array be in random order * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memshuffle.c,v 1.3 1994/06/20 20:30:02 liw Exp $" */ #include #include #include #include "publib/strutil.h" void *memshuffle(void *base, size_t elsize, size_t nelem) { size_t i; char *p; assert(base != NULL); assert(elsize > 0); for (p = base; nelem > 0; --nelem, p += elsize) { i = rand() / (RAND_MAX / nelem + 1); if (i > 0) memswap(p, p + i*elsize, elsize); } return base; } publib-0.40/strutil/strmove.c0000664000175000017500000000333711767417657014414 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strmove.c -- copy a string to another, possibly overlapping place * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strmove.c,v 1.1 1994/06/20 20:30:20 liw Exp $" */ #include #include #include "publib/strutil.h" char *strmove(char *tgt, const char *src) { assert(tgt != NULL); assert(src != NULL); return memmove(tgt, src, strlen(src) + 1); } publib-0.40/strutil/strdiff.c0000664000175000017500000000332011767417657014346 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strdiff.c -- find first difference between two strings * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: strdiff.c,v 1.1 1995/08/14 22:05:35 liw Exp $" */ #include #include #include "publib/strutil.h" size_t strdiff(const char *s, const char *t) { size_t n; for (n = 0; *s != '\0' && *s++ == *t++; ++n) continue; return n; } publib-0.40/strutil/strrev.c0000664000175000017500000000333411767417657014237 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strrev.c -- reverse a string in place * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strrev.c,v 1.3 1996/08/12 01:04:24 liw Exp $" */ #include #include #include "publib/strutil.h" char *strrev(char *s) { char c, *t, *origs = s; assert(s != NULL); t = s+strlen(s); while (s < t) { c = *s; *s++ = *--t; *t = c; } return origs; } publib-0.40/strutil/strtrim.c0000664000175000017500000000323111767417657014412 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strtrim.c -- remove leading and trailing blanks from string * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: strtrim.c,v 1.1.1.1 1994/02/03 17:25:29 liw Exp $" */ #include #include "publib/strutil.h" char *strtrim(char *s) { assert(s != NULL); strrtrim(s); strltrim(s); return s; } publib-0.40/strutil/strhash.c0000664000175000017500000000332311767417657014364 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strhash.c -- compute a hash value for a string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strhash.c,v 1.1 1994/06/20 20:30:15 liw Exp $" */ #include #include #include "publib/strutil.h" unsigned long strhash(const char *s) { unsigned long h; assert(s != NULL); for (h = 0; *s != '\0'; ++s) h = (h * 33) | *s; return h; } publib-0.40/strutil/strtrexpand.c0000664000175000017500000000441411767417657015270 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strtrexpand.c -- expand tr-like notation in string * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: strtrexpand.c,v 1.1 1994/06/20 20:30:43 liw Exp $" */ #include #include #include #include #include "publib/strutil.h" /* a-b: everything from charcode a to charcode b \a: the character a \o \oo \ooo : character with octal code o */ #define odigit(c) (c >= '0' && c <= '7') void strtrexpand(char *tgt, const char *src) { int c; while (src[0] != '\0') { if (src[0] == '\\' && odigit(src[1])) { ++src; c = *src++ - '0'; if (odigit(*src)) c = c*8 + *src++ - '0'; if (odigit(*src)) c = c*8 + *src++ - '0'; *tgt++ = c; } else if (src[0] == '\\') { *tgt++ = src[1]; src += 2; } else if (src[1] == '-' && src[2] != '\0') { for (c = src[0]; c <= src[2]; ++c) *tgt++ = c; src += 3; } else { *tgt++ = *src++; } } *tgt = '\0'; } publib-0.40/strutil/memdel.c0000664000175000017500000000332511767417657014155 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memdel.c -- delete bytes from beginning of memory block * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memdel.c,v 1.1 1994/06/20 20:29:52 liw Exp $" */ #include #include #include "publib/strutil.h" void *memdel(void *p, size_t size, size_t n) { assert(p != NULL); assert(n <= size); memmove(p, (char*)p + n, size-n); return p; } publib-0.40/strutil/strset.c0000664000175000017500000000332011767417657014231 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strset.c -- set all characters in a string to a given character * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strset.c,v 1.1 1994/06/20 20:30:36 liw Exp $" */ #include #include #include "publib/strutil.h" char *strset(char *str, int c) { char *s; assert(str != NULL); for (s = str; *s != '\0'; ++s) *s = c; return str; } publib-0.40/strutil/strcstr.c0000664000175000017500000000534311767417657014420 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strcstr.c -- convert binary data into C string literal notation * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strcstr.c,v 1.2 1994/02/05 17:08:43 liw Exp $" */ #include #include #include #include #include "publib/strutil.h" /* Append a character to the end of the result string if it fits. */ #define append(c) (void)((m < max-1) && (str[m++] = (c))) void strcstr(char *str, size_t max, const void *block, size_t n) { static const char print[] = "'\"?\\abfnrtv"; static const char unprint[] = "'\"?\\\a\b\f\n\r\t\v"; int i, thishex, prevhex; const char *p, *data; size_t m; assert(str != NULL); assert(max > 0); assert(block != NULL); assert(!memoverlap(str, max, block, n)); data = block; m = 0; prevhex = 0; while (m < max-1 && n-- > 0) { thishex = 0; if (*data == '\0') { append('\\'); append('0'); if (isdigit(data[1])) { append('0'); append('0'); } ++data; } else if ((p = strchr(unprint, *data)) != NULL) { append('\\'); append(print[p-unprint]); ++data; } else if (isprint(*data) && !(prevhex && isxdigit(*data))) append(*data++); else { append('\\'); append('x'); i = (CHAR_BIT/4+1)*4-4; while (m < max-1 && i >= 0) { append("0123456789abcdef"[(*data & (0xf << i)) >> i]); i -= 4; } thishex = 1; ++data; } prevhex = thishex; } append('\0'); } publib-0.40/strutil/stracat.c0000664000175000017500000000700711767417657014354 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stracat.c -- concatenate many strings into an allocated memory block * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: stracat.c,v 1.5 1994/07/16 15:29:17 liw Exp $" */ #include #include #include #include #include "publib/strutil.h" #include "publib/errormsg.h" #define N 1024 char *stracat(const char *s, ...) { va_list args; char *q, *block; const char *p; size_t size, len; size_t lentab[N]; int n, i; assert(s != NULL); /* * Compute the amount of memory needed for the target string. * * I could use realloc to make it larger if an initial guess * at its size would be too little, but this way we avoid doing * calling realloc many times, which is a win, because it can * be pretty slow. However, I haven't actually tested that * this is faster. :-(. * * I use another untested speed hack (but this one should be * obvious -- famous last words): to avoid having to compute the * length of each string twice, I store the lengths in an array, * lentab. If there are more strings than will fit into lentab, * then the rest will still have their lengths computed twice. * N, the length of lentab, should be made large enough that it * seldom happens, and small enough that there is not significant * memory loss. On memory-starved machines (such as PCs running * under MS-DOS), one has to take into account also a minuscule stack * size. On machines with real memory management, a thousand or ten * should be a pretty good value for N. */ n = 1; lentab[0] = strlen(s); size = 1 + lentab[0]; va_start(args, s); while ((p = va_arg(args, char *)) != NULL) { len = strlen(p); size += len; if (n < N) lentab[n++] = len; } va_end(args); /* * Allocate the block. */ block = malloc(size); if (block == NULL) { __publib_error("malloc failed"); return NULL; } /* * Concatenate the strings to the allocated block. */ memcpy(block, s, lentab[0]); q = block + lentab[0]; i = 1; va_start(args, s); while ((p = va_arg(args, const char *)) != NULL) { len = (i < n) ? lentab[i++] : strlen(p); memcpy(q, p, len); q += len; } *q = '\0'; va_end(args); return block; } publib-0.40/strutil/strrstr.c0000664000175000017500000000366111767417657014440 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strrstr.c -- find last occurence of string in another string * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: strrstr.c,v 1.1.1.1 1994/02/03 17:25:29 liw Exp $" */ #include #include #include "publib/strutil.h" char *strrstr(const char *str, const char *pat) { size_t len, patlen; const char *p; assert(str != NULL); assert(pat != NULL); len = strlen(str); patlen = strlen(pat); if (patlen > len) return NULL; for (p = str + (len - patlen); p > str; --p) if (*p == *pat && strncmp(p, pat, patlen) == 0) return (char *) p; return NULL; } publib-0.40/strutil/strchange.c0000664000175000017500000000371511767417657014673 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strchange.c -- change beginning of string to another string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strchange.c,v 1.1 1994/06/20 20:30:08 liw Exp $" */ #include #include #include "publib/strutil.h" char *strchange(char *str, size_t changelen, const char *new, size_t newlen) { size_t n; assert(str != NULL); assert(new != NULL); assert(!stroverlap(str, new)); n = strlen(str); if (n < changelen) changelen = n; n = strlen(new); if (n < newlen) newlen = n; memmove(str+newlen, str+changelen, strlen(str+changelen)+1); memcpy(str, new, newlen); return str; } publib-0.40/strutil/memins.c0000664000175000017500000000356611767417657014211 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memins.c -- insert bytes at beginning of memory block * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memins.c,v 1.1 1994/02/05 17:09:24 liw Exp $" */ #include #include #include "publib/strutil.h" void *memins(void *tgt, size_t tgtsize, const void *src, size_t srcsize) { assert(tgt != NULL); assert(src != NULL); assert(!memoverlap(tgt, tgtsize, src, srcsize)); if (tgtsize > 0) memmove((char *)tgt + srcsize, tgt, tgtsize); if (srcsize > 0) memcpy(tgt, src, srcsize); return tgt; } publib-0.40/strutil/strmtrim.c0000664000175000017500000000376411767417657014602 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strmtrim.c -- replace multiple white spaces with single blanks within string * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: strmtrim.c,v 1.1 1994/06/20 20:30:22 liw Exp $" */ #include #include #include "publib/strutil.h" char *strmtrim(char *str) { char *s, *t, *u; assert(str != NULL); for (s = str; isspace(*s); ++s) continue; t = s; for (;;) { if (!isspace(*t)) { *s = *t; if (*t == '\0') break; ++s; ++t; } else { u = t; while (isspace(*++t)) continue; if (*t == '\0') { while ((*s++ = *u++) != '\0') continue; break; } *s++ = ' '; } } return str; } publib-0.40/strutil/strins.c0000664000175000017500000000361111767417657014232 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strins.c -- insert a string at the beginning of another string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strins.c,v 1.2 1994/02/05 17:08:44 liw Exp $" */ #include #include #include "publib/strutil.h" char *strins(char *tgt, const char *src) { size_t srclen; assert(tgt != NULL); assert(src != NULL); assert(!memoverlap(tgt, strlen(tgt)+strlen(src)+1, src, strlen(src)+1)); srclen = strlen(src); memmove(tgt + srclen, tgt, strlen(tgt) + 1); /* +1 for '\0' */ memcpy(tgt, src, srclen); return tgt; } publib-0.40/strutil/strndup.c0000664000175000017500000000363711767417657014417 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strndup.c -- duplicate at most a given beginning of a string * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: strndup.c,v 1.1 1994/06/20 20:30:24 liw Exp $" */ #include #include #include #include #include "publib/strutil.h" #include "publib/errormsg.h" char *strndup(const char *str, size_t n) { char *dup; size_t len; len = strlen(str); if (n > len) n = len; dup = malloc(n+1); if (dup == NULL) { __publib_error("malloc failed"); return NULL; } memcpy(dup, str, n); dup[n] = '\0'; return dup; } publib-0.40/strutil/strendzap.c0000664000175000017500000000355211767417657014726 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strendzap.c -- remove pat from end of str, if it is there * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strendzap.c,v 1.2 1994/07/22 12:22:51 liw Exp $" */ #include #include #include "publib/strutil.h" int strendzap(char *str, const char *pat) { size_t len, patlen; assert(str != NULL); assert(pat != NULL); len = strlen(str); patlen = strlen(pat); if (patlen <= len) { str += len - patlen; if (strcmp(str, pat) == 0) { *str = '\0'; return 1; } } return 0; } publib-0.40/strutil/strshuffle.c0000664000175000017500000000332011767417657015072 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strshuffle.c -- make the characters in a string be in random order * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strshuffle.c,v 1.1 1994/06/20 20:30:38 liw Exp $" */ #include #include #include #include "publib/strutil.h" char *strshuffle(char *str) { assert(str != NULL); return memshuffle(str, 1, strlen(str)); } publib-0.40/strutil/strzap.c0000664000175000017500000000354711767417657014243 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strzap.c -- remove pat from beginning of str, if it is there * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strzap.c,v 1.2 1994/07/22 12:22:54 liw Exp $" */ #include #include #include "publib/strutil.h" int strzap(char *str, const char *pat) { size_t len, patlen; assert(str != NULL); assert(pat != NULL); len = strlen(str); patlen = strlen(pat); if (patlen <= len && memcmp(str, pat, patlen) == 0) { memmove(str, str+patlen, len-patlen+1); return 1; } return 0; } publib-0.40/strutil/strright.c0000664000175000017500000000336611767417657014565 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strright.c -- return a pointer to the beginning of the rightmost n chars * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strright.c,v 1.1 1994/06/20 20:30:32 liw Exp $" */ #include #include #include "publib/strutil.h" char *strright(const char *s, size_t n) { size_t len; assert(s != NULL); len = strlen(s); if (n > len) n = 0; return (char *)s + (len - n); } publib-0.40/strutil/struncstr.c0000664000175000017500000000605211767417657014761 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * struncstr.c -- convert C string literal notation into binary data * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: struncstr.c,v 1.4 2004/07/11 10:19:19 liw Exp $" */ #include #include #include #include "publib/strutil.h" /* Append a character to the end of the data block, if it fits. */ #define append(c) (void)(m < max && (data[m++] = (c))) /* Convert hexadecimal character to its corresponding integer value. Assume that the character is valid. */ #define hextoint(c) hexvalues[strchr(hexdigits, (c))-hexdigits]; void struncstr(void *block, const char *str, size_t max) { static const char print[] = "'\"?\\abfnrtv"; static const char unprint[] = "'\"?\\\a\b\f\n\r\t\v"; static const char hexdigits[] = "0123456789abcdefABCDEF"; static const char hexvalues[] = "\0\1\2\3\4\5\6\7\x8\x9" "\xa\xb\xc\xd\xe\xf" "\xA\xB\xC\xD\xE\xF"; char *p, *data; unsigned c; size_t m; int i; assert(str != NULL); assert(block != NULL); assert(!memoverlap(block, max, str, strlen(str)+1)); data = block; m = 0; while (m < max && *str != '\0') { if (*str != '\\') /* printable character? */ append(*str++); else if (str[1] == 'x') { /* hex escape sequence? */ str += 2; c = 0; while (isxdigit(*str)) { c = (c << 4) | hextoint(*str); ++str; } append(c); } else if (isdigit(str[1])) { /* octal escape sequence? */ ++str; c = i = 0; while (i++ < 3 && isdigit(*str)) c = (c << 3) | hextoint(*str++); append(c); } else if ((p = strchr(print, str[1])) != NULL) { append(unprint[p-print]); /* simple esc sequence */ str += 2; } else { /* undefined sequence! */ append('\\'); append(str[1]); str += 2; } } } publib-0.40/strutil/strinit.c0000664000175000017500000000332211767417657014403 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strinit.c -- initialize a string to a given length with a given character * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strinit.c,v 1.1 1994/06/20 20:30:17 liw Exp $" */ #include #include #include "publib/strutil.h" char *strinit(char *s, int c, size_t len) { assert(s != NULL); memset(s, c, len); s[len] = '\0'; return s; } publib-0.40/strutil/strnins.c0000664000175000017500000000367711767417657014424 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strnins.c -- insert prefix of a string at the beginning of another string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strnins.c,v 1.1 1994/07/25 23:15:39 liw Exp $" */ #include #include #include "publib/strutil.h" char *strnins(char *tgt, const char *src, size_t n) { size_t srclen; assert(tgt != NULL); assert(src != NULL); assert(!memoverlap(tgt, strlen(tgt)+strlen(src)+1, src, strlen(src)+1)); srclen = strlen(src); if (srclen > n) srclen = n; memmove(tgt + srclen, tgt, strlen(tgt) + 1); /* +1 for '\0' */ memcpy(tgt, src, srclen); return tgt; } publib-0.40/strutil/memmem.c0000664000175000017500000000352111767417657014165 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memmem.c -- search for memory block inside another memory block * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memmem.c,v 1.1 1994/06/20 20:29:57 liw Exp $" */ #include #include #include "publib/strutil.h" void *memmem(const void *v, size_t size, const void *pat, size_t patsize) { const char *p; assert(v != NULL); assert(pat != NULL); for (p = v; size >= patsize; ++p, --size) if (memcmp(p, pat, patsize) == 0) return (void*) p; return NULL; } publib-0.40/strutil/memfill.c0000664000175000017500000000365411767417657014344 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memfill.c -- fill memory area with pattern * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memfill.c,v 1.2 1994/02/05 17:08:42 liw Exp $" */ #include #include #include "publib/strutil.h" void *memfill(void *buf, size_t bufsize, const void *pat, size_t patsize) { char *p; assert(buf != NULL); assert(bufsize > 0); assert(pat != NULL); assert(patsize > 0); assert(!memoverlap(buf, bufsize, pat, patsize)); for (p = buf; bufsize > patsize; p += patsize, bufsize -= patsize) memcpy(p, pat, patsize); memcpy(p, pat, bufsize); return buf; } publib-0.40/strutil/strsub.c0000664000175000017500000000414011767417657014230 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strsub.c -- substitute first occurence of pattern with another string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strsub.c,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" */ #include #include #include "publib/strutil.h" char *strsub(char *str, const char *pat, const char *sub) { size_t lenpat, lensub, lenstr; assert(str != NULL); assert(pat != NULL); assert(*pat != '\0'); assert(sub != NULL); str = strstr(str, pat); if (str == NULL) return NULL; lenstr = strlen(str); lenpat = strlen(pat); lensub = strlen(sub); /* make room for substituted string, or remove slack after it */ if (lensub != lenpat) memmove(str + lensub, str + lenpat, lenstr + 1 - lenpat); memcpy(str, sub, lensub); return str + lensub; } publib-0.40/strutil/struntabify.c0000664000175000017500000000361511767417657015266 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * struntabify.c -- convert tabs to spaces * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: struntabify.c,v 1.1 1994/06/20 20:30:45 liw Exp $" */ #include #include #include #include #include "publib/strutil.h" char *struntabify(char *str, size_t tabsize) { size_t n; char *s; assert(str != NULL); assert(tabsize > 0); s = str; while ((s = strchr(s, '\t')) != NULL) { n = tabsize - (s-str)%tabsize; memmove(s+1 + n-1, s+1, strlen(s+1)+1); memset(s, ' ', n); s += n; } return str; } publib-0.40/strutil/stroverlap.c0000664000175000017500000000333011767417657015107 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stroverlap.c -- check whether two strings overlap * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: stroverlap.c,v 1.1 1994/06/20 20:30:28 liw Exp $" */ #include #include #include "publib/strutil.h" int stroverlap(const char *s, const char *t) { assert(s != NULL); assert(t != NULL); return memoverlap(s, strlen(s)+1, t, strlen(t)+1); } publib-0.40/strutil/strrtrim.c0000664000175000017500000000340011767417657014572 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strrtrim.c -- remove trailing whitespace from a string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strrtrim.c,v 1.3 1994/07/16 12:11:02 liw Exp $" */ #include #include #include #include "publib/strutil.h" char *strrtrim(char *s) { char *t, *tt; assert(s != NULL); for (tt = t = s; *t != '\0'; ++t) if (!isspace(*t)) tt = t+1; *tt = '\0'; return s; } publib-0.40/strutil/strend.c0000664000175000017500000000324711767417657014214 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strend.c -- return pointer to the '\0' terminator of a string * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: strend.c,v 1.1 1994/06/20 20:30:11 liw Exp $" */ #include #include #include "publib/strutil.h" char *strend(const char *s) { assert(s != NULL); return (char *)s + strlen(s); } publib-0.40/strutil/memrev.c0000664000175000017500000000344711767417657014212 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memrev.c -- reverse an array in place * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memrev.c,v 1.1.1.1 1994/02/03 17:25:31 liw Exp $" */ #include #include #include "publib/strutil.h" void *memrev(void *block, size_t elsize, size_t elnum) { char *s, *t; assert(block != NULL); assert(elsize > 0); for (s = block, t = s + (elnum-1)*elsize; s < t; s+=elsize, t-=elsize) memswap(s, t, elsize); return block; } publib-0.40/strutil/memoverlap.c0000664000175000017500000000465311767417657015066 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memoverlap.c -- check whether two memory areas overlap * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memoverlap.c,v 1.3 1994/06/20 20:29:59 liw Exp $" */ #include #include #include "publib/strutil.h" /* NOTE: This implementation assumes that arbitrary pointers can be compared. You need to fix it for a system where this doesn't hold. */ int memoverlap(const void *t, size_t tsize, const void *s, size_t ssize) { const char *ct, *cs; if (t == NULL || s == NULL) return 0; ct = t; cs = s; if (ssize == 0) ssize = 1; if (tsize == 0) tsize = 1; return (cs+ssize-1 >= ct && cs <= ct+tsize-1) || (ct+tsize-1 >= cs && ct <= cs+ssize-1); } /* As a curiosity, the following should be a strictly standard-conforming implementation. It's rather useless for real work. */ #if 0 int memoverlap(const void *t, size_t tsize, const void *s, size_t ssize) { const char *ct, *cs; size_t nt, ns; for (ct = t, nt = 0; nt < tsize; ++nt, ++ct) for (cs = s, ns = 0; ns < ssize; ++ns, ++cs) if (cs == ct) return 1; return 0; } #endif publib-0.40/strutil/stranaxfrm.c0000664000175000017500000000400211767417657015070 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stranaxfrm.c -- make a string into canonical order for anagram comparison * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: stranaxfrm.c,v 1.1 1994/06/20 20:30:06 liw Exp $" */ #include #include "publib/strutil.h" char *stranaxfrm(char *str) { char c, *s, *t, *min; assert(str != NULL); /* * Sort the letters in the string, using selection sort. While * slowish for long strings, it should be quite fast enough for * the usual short ones. (Beep! Untested efficiency claim!) */ for (s = str; *s != '\0'; ++s) { for (min = t = s; *t != '\0'; ++t) if (*t < *min) min = t; c = *s; *s = *min; *min = c; } return str; } publib-0.40/strutil/strltrim.c0000664000175000017500000000342411767417657014572 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strltrim.c -- remove leading whitespace from string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strltrim.c,v 1.1.1.1 1994/02/03 17:25:29 liw Exp $" */ #include #include #include #include "publib/strutil.h" char *strltrim(char *s) { char *t; assert(s != NULL); for (t = s; isspace(*t); ++t) continue; memmove(s, t, strlen(t)+1); /* +1 so that '\0' is moved too */ return s; } publib-0.40/strutil/strgsub.c0000664000175000017500000000430511767417657014402 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strgsub.c -- substitute all occurences of pattern with another string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strgsub.c,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" */ #include #include #include "publib/strutil.h" int strgsub(char *str, const char *pat, const char *sub, size_t max) { size_t lenpat, lensub; const char *p; int n; assert(str != NULL); assert(pat != NULL); assert(*pat != '\0'); assert(sub != NULL); assert(max >= strlen(str)+1); /* * Check that the all substitutions will fit. */ lenpat = strlen(pat); lensub = strlen(sub); if (lenpat < lensub) { for (n = 0, p = str; (p = strstr(p, pat)) != NULL; p += lenpat) ++n; if (strlen(str)+1 + n*(lensub-lenpat) > max) return -1; } /* * Substitute. */ for (n = 0; (str = strsub(str, pat, sub)) != NULL; ++n) continue; return n; } publib-0.40/strutil/strnlen.c0000664000175000017500000000333711767417657014402 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strnlen.c -- give length of string, which needn't be zero terminated * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strnlen.c,v 1.1 1994/12/27 13:34:26 wirzeniu Exp $" */ #include #include #include "publib/strutil.h" size_t strnlen(const char *s, size_t n) { const char *p; p = memchr(s, '\0', n); if (p == NULL) return n; return p-s; } publib-0.40/strutil/strrot13.c0000664000175000017500000000353011767417657014411 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strrot13.c -- encrypt string with rot13 * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strrot13.c,v 1.1.1.1 1994/02/03 17:25:31 liw Exp $" */ #include #include "publib/strutil.h" #define N 26 /* Warning: this code assumes ASCII */ char *strrot13(char *str) { char *s = str; while (*s != '\0') { if ((*s >= 'a' && *s <= 'm') || (*s >= 'A' && *s <= 'M')) *s += 13; else if ((*s >= 'n' && *s <= 'z') || (*s >= 'N' && *s <= 'Z')) *s -= 13; ++s; } return str; } publib-0.40/strutil/memrchr.c0000664000175000017500000000343511767417657014351 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memrchr.c -- reverse search for character inside another memory block * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memrchr.c,v 1.2 1994/10/06 11:09:24 liw Exp $" */ #include #include #include "publib/strutil.h" void *memrchr(const void *v, int c, size_t size) { const char *p; assert(v != NULL); p = (const char *)v + size; while (size-- > 0) if (*--p == c) return (void *) p; return NULL; } publib-0.40/strutil/strmaxcpy.c0000664000175000017500000000345111767417657014744 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strmaxcpy.c -- copy at most a given number of characters of string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strmaxcpy.c,v 1.3 1994/07/31 23:30:44 liw Exp $" */ #include #include #include "publib/strutil.h" char *strmaxcpy(char *tgt, const char *src, size_t n) { assert(tgt != NULL); assert(src != NULL); assert(!memoverlap(tgt, n+1, src, strlen(src)+1)); *tgt = '\0'; strncat(tgt, src, n); return tgt; } publib-0.40/strutil/memswap.c0000664000175000017500000000401011767417657014353 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memswap.c -- swap contents of two memory blocks * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memswap.c,v 1.2 1994/02/05 17:08:43 liw Exp $" */ #include #include #include "publib/strutil.h" /* The size of the auxiliary array that is used while swapping */ #define N 1024 void memswap(void *block1, void *block2, size_t n) { char *s, *t, buf[N]; assert(block1 != NULL); assert(block2 != NULL); assert(!memoverlap(block1, n, block2, n)); s = block1; t = block2; while (n > N) { memcpy(buf, s, N); memcpy(s, t, N); memcpy(t, buf, N); s += N; t += N; n -= N; } memcpy(buf, s, n); memcpy(s, t, n); memcpy(t, buf, n); } publib-0.40/strutil/strtabify.c0000664000175000017500000000422611767417657014722 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strtabify.c -- convert runs of spaces and tabs to tabs (+ necessary spaces) * * Part of publib. See man page for more information. * "@(#)publib-strutil:$Id: strtabify.c,v 1.1 1994/06/20 20:30:40 liw Exp $" */ #include #include #include #include #include "publib/strutil.h" #define nexttab(col) ((col) + tabsize - (col)%tabsize) char *strtabify(char *str, size_t tabsize) { size_t scol, tcol; char *s, *t; tcol = scol = 0; t = s = str; do { switch (*s) { case ' ': ++scol; break; case '\t': scol = nexttab(scol); break; default: while (nexttab(tcol) <= scol) { *t++ = '\t'; tcol = nexttab(tcol); } while (tcol < scol) { *t++ = ' '; ++tcol; } *t++ = *s; ++scol; tcol = scol; break; } } while (*s++ != '\0'); return str; } publib-0.40/strutil/strsplit.c0000664000175000017500000000571511767417657014603 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strsplit.c -- split a string into "words" * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strsplit.c,v 1.3 1994/02/19 20:58:38 liw Exp $" */ #include #include #include #include #include "publib/strutil.h" static char *find_nonsep(const char *s, const char *sep); static char *find_sep(const char *s, const char *sep); int strsplit(char *s, char **words, int maxw, const char *sep) { char *start, *end, *endstr; int count; assert(s != NULL); assert(words != NULL || maxw == 0); assert(sep != NULL); assert(!memoverlap(s, strlen(s)+1, sep, strlen(sep)+1)); count = 0; end = s; endstr = strchr(s, '\0'); while (end < endstr) { start = find_nonsep(end, sep); if (start == NULL) break; end = find_sep(start, sep); *end++ = '\0'; if (count < maxw) words[count] = start; ++count; } return count; } /* Find first character that is not a separator, starting with the character at s. Return NULL if not found. */ static char *find_nonsep(const char *s, const char *sep) { if (sep != NULL) s += strspn(s, sep); else while (isspace(*s)) ++s; return *s == '\0' ? NULL : (char *) s; } /* Find first character that is a separator, starting with the character at s. Treat '\0' as a separator, so that the call always succeeds. */ static char *find_sep(const char *s, const char *sep) { if (sep != NULL) s += strcspn(s, sep); else while (*s != '\0' && !isspace(*s)) ++s; return (char *) s; } publib-0.40/strutil/memisort.c0000664000175000017500000000416211767417657014551 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * memisort.c -- sort new element in sorted array * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: memisort.c,v 1.1 1994/02/06 09:45:09 liw Exp $" */ #include #include #include "publib/strutil.h" void memisort(void *base, size_t nelem, size_t elsize, const void *new, int (*comp)(const void *, const void *)) { char *p, *top, *cbase; assert(base != NULL); assert(elsize > 0); assert(new != NULL); assert(comp != NULL); assert(!memoverlap(base, nelem*elsize, new, elsize)); cbase = (char *) base; top = cbase + nelem*elsize; for (p = top; p > cbase; p -= elsize) if ((*comp)(new, p-elsize) >= 0) break; if (p < top) memmove(p+elsize, p, (size_t) (top-p)); /* we're lost if ptrdiff_t < size_t */ memcpy(p, new, elsize); } publib-0.40/strutil/strdel.c0000664000175000017500000000336011767417657014206 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strdel.c -- remove characters from the beginning of a string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strdel.c,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" */ #include #include #include "publib/strutil.h" char *strdel(char *s, size_t n) { size_t len; assert(s != NULL); len = strlen(s); if (n > len) n = len; memmove(s, s+n, len+1 - n); return s; } publib-0.40/strutil/strcins.c0000664000175000017500000000327011767417657014376 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * strcins.c -- insert a char at the beginning of a string * * Part of publib. See man page for more information * "@(#)publib-strutil:$Id: strcins.c,v 1.2 1994/07/25 23:15:35 liw Exp $" */ #include #include #include "publib/strutil.h" void strcins(char *str, int c) { assert(str != NULL); memmove(str+1, str, strlen(str)+1); *str = c; } publib-0.40/TODO0000664000175000017500000000554311767326366011530 0ustar ajkajk* log: syslog, __file__ and __line__ automatically * have indexes with all publib-manual pages * manual pages should be compressed for Debian. * manual pages should have optional suffix * install should create target dirs * several module daddy dirs * build shared libraries * create some automatic testing (even if rudimentary) * config files: write back as well, and retain comments in the original * getaline: make it possible to restrict the size of one line * extensible printf; snprintf * something to replace scanf? * tab positions * isxdigit, isodigit * function to read from file/string C tokens * ...and C tokens in general? * guaranteed good random number generator, with randomize * bitfiles * dynamic arrays, multidimensional too * files: length of file, copy files and streams, move files (across disks), get list of files in a directory, select files in list, do operation for all/selected files in list (i.e., copy/move/rename/delete) * strings: approximate matching; non-null-terminated strings; fast strstr * rfc822 et al mail message handling; UNIX mailbox handling * dos framework: write program to read the list files to be compiled (scan the modules directory's subdirectories) and output a BC++ project file * function to compare strings numerically: abc1 < abc2 < abc10 * strexpandvars * bitarr: set, clear ranges * cmp: cmp_uchararr, ucharstr, cmp_schararr, scharstr * symtab * fname: /./ -> / * iset: hashtable+bitmap * expr: unget_token: error if ungot_count too large * expr: don't have globals at all * expr: on errors, free ungot tokens as well * automatic more for output * Template: not-explicitly-changing input files * recognize function keys / other key sequences * tmpdir - create temporary directory (to be deleted on normal exit) * handle errno correctly * dates and times, handle all timezones, all possible times (i.e., as long a time range as possible), support the timesrc timezone db, conversions to and from string formats; make it as a replacement for normal ? * incremental searches from arrays (generic) * file copy, move, rename * get list of filenames; directory tree; display as ascii * bm or knp search routines (memfmem[setup], memfrmem, strfstr, strfrstr, f for fancy) * compression * write text on library function design: degrees of tightness (Meyers), uniform interface, how to deal with errors, try to define function so it can't fail, use asserts properly to catch errors, don't blend status codes and useful data, but do otherwise follow the unix system call interface; memory allocation principles * allocation of fixed size blocks (handles a few sizes automatically, keeps a list of freed blocks of the given sizes) * write better text on the design of the framework, the modules, and their interface; write tutorial on writing a module * fname: there is no suffix in ".profile". publib-0.40/link-alternative-names0000664000175000017500000000400111767417657015325 0ustar ajkajk#!/bin/sh # Copyright (c) 1996 Lars Wirzenius # Copyright (c) 2012 Antti-Juhani Kaijanaho # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. set -e mode=install while [ $# -gt 0 ] do case "$1" in "-r") mode=uninstall;; *) break;; esac shift done rmsnd() { rm -f "$2" } find_names() { zcat -f "$@" | sed -n '/^\.SH NAME/,/^\.SH SYNOPSIS/p' | grep -v '^\.SH ' | tr '\12' ' ' | sed 's/ \\- .*//' | tr , ' ' | sed 's/ */ /g' } echoexec() { echo $@ $@ } for name in `find_names "$1"` do tgt="$2/$name$3.gz" if [ $mode = install ] ; then if [ ! -f $tgt -a ! -L $tgt ] then echoexec ln -sf `basename $1`.gz $tgt fi else if [ -L $tgt ] ; then echoexec rm $tgt fi fi done publib-0.40/files/0000775000175000017500000000000011767707451012131 5ustar ajkajkpublib-0.40/files/xgetaline.c0000664000175000017500000000341311767417657014264 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * xgetaline.c -- error checking front-end for getaline * * Part of publib. See man page for more information * "@(#)publib-files:$Id: xgetaline.c,v 1.3 1995/08/11 15:53:18 liw Exp $" */ #include #include #include "publib/errormsg.h" #include "publib/files.h" char *xgetaline(FILE *fp) { char *p; p = getaline(fp); if (p == NULL && ferror(fp)) { __publib_error("getaline failed"); exit(EXIT_FAILURE); } return p; } publib-0.40/files/getaline.c0000664000175000017500000000637711767417657014110 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * getaline.c -- read arbitrarily long line from file * * Part of publib. See man page for more information * "@(#)publib-files:$Id: getaline.c,v 1.4 1996/04/28 14:01:19 liw Exp $" */ #include #include #include #include "publib/errormsg.h" #include "publib/files.h" char *getaline(FILE *f) { char *buf; /* buffer for line */ size_t size; /* size of buffer */ size_t inc; /* how much to enlarge buffer */ size_t len; /* # of chars stored into buf before '\0' */ char *p; const size_t thres = 128; /* initial buffer size (most lines should fit into this size, so think of this as the "long line threshold"). */ const size_t mucho = 128; /* if there is at least this much wasted space when the whole buffer has been read, try to reclaim it. Don't make this too small, else there is too much time wasted trying to reclaim a couple of bytes. */ const size_t mininc = 64; /* minimum number of bytes by which to increase the allocated memory */ len = 0; size = thres; buf = malloc(size); if (buf == NULL) { __publib_error("malloc failed"); return NULL; } while (fgets(buf+len, size-len, f) != NULL) { len += strlen(buf+len); if (len > 0 && buf[len-1] == '\n') break; /* the whole line has been read */ for (inc = size, p = NULL; inc > mininc; inc /= 2) if ((p = realloc(buf, size + inc)) != NULL) break; if (p == NULL) { __publib_error("realloc failed"); free(buf); return NULL; /* couldn't get more memory */ } size += inc; buf = p; } if (len == 0) { if (ferror(f)) __publib_error("I/O error"); free(buf); return NULL; /* nothing read (eof or error) */ } if (buf[len-1] == '\n') /* remove newline, if there */ buf[--len] = '\0'; if (size - len > mucho) { /* a plenitude of unused memory? */ p = realloc(buf, len+1); if (p != NULL) { buf = p; size = len+1; } } return buf; } publib-0.40/files/xfopen.c0000664000175000017500000000372411767417657013610 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * xfopen.c -- error checking front-end for fopen * * Part of publib. See man page for more information * "@(#)publib-files:$Id: xfopen.c,v 1.1.1.1 1993/11/20 17:02:01 liw Exp $" */ #include #include #include "publib/errormsg.h" #include "publib/files.h" FILE *xfopen(const char *filename, const char *mode) { FILE *f; f = fopen(filename, mode); if (f == NULL) { /* can't use __publib_error here, because the message is useless without the extra information */ errormsg(__liberror & (__abort_on_error | __exit_on_error), errno, "xfopen: %s: can't open file in mode `%s'", filename, mode); } return f; } publib-0.40/files/xfclose.c0000664000175000017500000000351311767417657013750 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * xfclose.c -- error checking front-end for fclose * * Part of publib. See man page for more information * "@(#)publib-files:$Id: xfclose.c,v 1.2 1995/08/11 15:53:17 liw Exp $" */ #include #include #include #include "publib/errormsg.h" #include "publib/files.h" void xfclose(FILE *f) { if (ferror(f)) { __publib_error("An error during file I/O"); exit(EXIT_FAILURE); } if (fclose(f) != 0) { __publib_error("An error while closeing a file"); exit(EXIT_FAILURE); } } publib-0.40/files/fassert.c0000664000175000017500000000345311767417657013757 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fassert.c -- check for errors on stream * * Part of publib. See man page for more information * "@(#)publib-files:$Id: fassert.c,v 1.2 1995/08/11 15:53:16 liw Exp $" */ #include #include #include #include "publib/errormsg.h" #include "publib/files.h" void fassert(FILE *fp) { if (fp == NULL) { __publib_error("argument is NULL"); exit(EXIT_FAILURE); } if (ferror(fp)) { __publib_error("I/O error on file"); exit(EXIT_FAILURE); } } publib-0.40/files/xfseek.c0000664000175000017500000000335211767417657013573 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * xfseek.c -- error checking front-end for fseek * * Part of publib. See man page for more information * "@(#)publib-files:$Id: xfseek.c,v 1.2 1995/08/11 15:53:17 liw Exp $" */ #include #include #include "publib/errormsg.h" #include "publib/files.h" void xfseek(FILE *f, long off, int origin) { if (fseek(f, off, origin) != 0) { __publib_error("fseek failed"); exit(EXIT_FAILURE); } } publib-0.40/files/file_io.c0000664000175000017500000001406011767417657013712 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: file_io.c * Purpose: File I/O. * Author: Lars Wirzenius * Version: "@(#)publib:$Id: file_io.c,v 1.1 1996/11/05 21:15:46 liw Exp $" */ #include #include #include #include #include #include #include #include #include "publib/alloc.h" #include "publib/files.h" #include "publib/errormsg.h" #define MAX_TRIES 1024 static int create_save_temp_file(const char *, char *, int *); static int copy_modes(const char *, const char *); static int make_backup_name(char *, const char *, size_t); int file_read_open(FILE *f, void **data, size_t *size) { struct dynarr da; int c; dynarr_init(&da, 1); while ((c = getc(f)) != EOF && !ferror(stdout)) { if (dynarr_resize(&da, da.used + 2) == -1) { __publib_error("out of memory"); dynarr_free(&da); (void) fclose(f); return -1; } ((char *) da.data)[da.used++] = c; } if (ferror(f)) { __publib_error("error reading from file"); return -1; } *data = da.data; *size = da.used; return 0; } int file_read(const char *pathname, void **data, size_t *size) { FILE *f; int ret; f = fopen(pathname, "r"); if (f == NULL) { __publib_error("error opening file for reading"); return -1; } ret = file_read_open(f, data, size); if (fclose(f) == EOF) { __publib_error("error closing file after reading"); ret = -1; } return ret; } int file_write(const char *pathname, void *data, size_t n) { FILE *f; int c; f = fopen(pathname, "w"); if (f == NULL) { __publib_error("couldn't open file for writing"); return -1; } (void) fwrite(data ? data : "", 1, n, f); c = ferror(f); if (fclose(f) == EOF || c) { __publib_error("error writing to file"); return -1; } return 0; } int file_save(const char *name, void *data, size_t size, int keep_backup) { FILE *f; int c, fd; char temp_name[FILENAME_MAX]; char back_name[sizeof(temp_name) + 4]; if (strlen(name) + 64 > sizeof(temp_name)) { __publib_error("filename is too long (can't save)"); return -1; } if (make_backup_name(back_name, name, sizeof(back_name)) == -1) return -1; if (create_save_temp_file(name, temp_name, &fd) == -1) return -1; f = fdopen(fd, "w"); if (f == NULL) { __publib_error("error opening file"); return -1; } (void) fwrite(data ? data : "", 1, size, f); c = ferror(f); if (fclose(f) == EOF || c) { __publib_error("error closing file"); return -1; } if (rename(name, back_name) == -1 && errno != ENOENT) { __publib_error("rename of original failed (can't save)"); return -1; } if (rename(temp_name, name) == -1) { __publib_error("rename of new failed (can't save)"); return -1; } if (copy_modes(back_name, name) == -1) return -1; if (!keep_backup) { if (remove(back_name) == -1 && errno != ENOENT) { __publib_error("remove of backup failed (can't save)"); return -1; } } return 0; } /**********************************************************************/ /* * Function: create_save_temp_file * Purpose: Create a new file in same directory as the file to be saved. * Arguments: original the name of the original file * buf where the new file's name is stored * fd where file descriptor of new file is stored * Return: -1 for failure, 0 for success. * Note: buf should be big enough; strlen(original) + 64 should * be enough (unless you have _really_ big unsigned longs). */ static int create_save_temp_file(const char *original, char *buf, int *fd) { char *p; unsigned long i; time_t random; strcpy(buf, original); p = strrchr(buf, '/'); if (p != NULL) p[1] = '\0'; else buf[0] = '\0'; time(&random); *fd = -1; p = strchr(buf, '\0'); for (i = 0; i < MAX_TRIES && *fd == -1; ++i) { sprintf(p, "#%lu-%lu#", (unsigned long) random, i); *fd = open(buf, O_WRONLY | O_CREAT | O_EXCL, 0600); if (*fd == -1 && errno != EEXIST) { __publib_error("can't create temporary file"); return -1; } } if (*fd == -1) return -1; return 0; } /* * Function: copy_modes * Purpose: Copy the permissions from one file to another. * Arguments: src original file * tgt target file * Return: -1 for error, 0 for OK. */ static int copy_modes(const char *src, const char *tgt) { struct stat st; if (stat(src, &st) == -1) { if (errno == ENOENT) return 0; __publib_error("Can't stat file (can't complete save)"); return -1; } if (chmod(tgt, st.st_mode) == -1) { __publib_error("Can't chmod file (can't complete save)"); return -1; } return 0; } /* * Function: make_backup_name * Purpose: Create name of backup file from original file. * Note: The target buffer must be big enough. */ static int make_backup_name(char *back, const char *orig, size_t max) { if (strlen(orig) + 2 > max) return -1; sprintf(back, "%s~", orig); return 0; } publib-0.40/tbuf/0000775000175000017500000000000011767707451011767 5ustar ajkajkpublib-0.40/tbuf/test_tbuf_with_stats.c0000664000175000017500000001106711767417657016416 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * test_tbuf_with_stats.c -- do tbuf buffer ops given in input, give stats for every input line: Read description of operation from stdin apply it print statistics of new tree delete old tree operations: offset length newlength replace offset..(length-1) with random text of length newlength statistics: length of buffer height of chunk tree nodes in tree number of chunks in tree total amount of memory used by tree * * Part of Publib, see man page for more information. * "@(#)publib-tbuf:$Id: test_tbuf_with_stats.c,v 1.6 2003/11/15 18:24:11 liw Exp $" */ #include #include #include #include "publib/tbuf.h" static void panic(const char *msg) { fprintf(stderr, "PANIC: %s\n", msg); exit(EXIT_FAILURE); } static Tbuf *x_tbuf_create(const char *str, size_t len) { Tbuf *tbuf; tbuf = tbuf_create(str, len); if (tbuf == NULL) panic("tbuf_create returned NULL"); return tbuf; } #if 0 static Tbuf *x_tbuf_copy(Tbuf *tbuf, size_t offset, size_t len) { Tbuf *tbuf2; tbuf2 = tbuf_copy(tbuf, offset, len); if (tbuf2 == NULL) panic("tbuf_copy returned NULL"); return tbuf2; } #endif static Tbuf *x_tbuf_cat(Tbuf *tbuf1, Tbuf *tbuf2) { Tbuf *tbuf; tbuf = tbuf_cat(tbuf1, tbuf2); if (tbuf == NULL) panic("tbuf_cat returned NULL"); return tbuf; } #if 0 static char *x_make_text(size_t wanted) { static char *buf = NULL; static size_t len = 0; if (wanted > len) { buf = realloc(buf, wanted); if (buf == NULL) panic("out of memory constructing a string"); memset(buf + len, 'x', wanted - len); len = wanted; } return buf; } #endif static void print_stats(Tbuf *tbuf) { struct tbuf_stat stat; tbuf_get_stats(&stat, tbuf); printf("%lu %lu %lu %lu %lu %lu\n", (unsigned long) stat.tbuf_length, (unsigned long) stat.tbuf_height, (unsigned long) stat.tbuf_nodes, (unsigned long) stat.tbuf_chunks, (unsigned long) stat.tbuf_memory_total, (unsigned long) stat.tbuf_nodes_with_few_kids); } static void test_single_inserts(int number) { Tbuf *tbuf, *tbuf_char, *tbuf_new; tbuf = x_tbuf_create("", 0); while (number-- > 0) { tbuf_char = x_tbuf_create("x", 1); tbuf_new = x_tbuf_cat(tbuf, tbuf_char); print_stats(tbuf_new); tbuf_destroy(tbuf_char); tbuf_destroy(tbuf); tbuf = tbuf_new; } } int main(int argc, char **argv) { #if 1 test_single_inserts(10000); return 0; #else Tbuf *tbuf, *tbuf_new, *tbuf1, *tbuf2, *tbuf3, *tbuf4; unsigned long offset, len, new_len, lineno; FILE *f; if (argc == 1) f = stdin; else { f = fopen(argv[1], "r"); if (f == NULL) { perror("fopen"); exit(EXIT_FAILURE); } } tbuf = x_tbuf_create("", 0); lineno = 0; while (fscanf(f, "%lu%lu%lu", &offset, &len, &new_len) == 3) { ++lineno; #if 0 fprintf(stderr, "line %lu %lu %lu %lu\n", lineno, offset, len, new_len); #endif tbuf1 = x_tbuf_copy(tbuf, 0, offset); tbuf2 = x_tbuf_create(x_make_text(new_len), new_len); tbuf3 = x_tbuf_copy(tbuf, offset + len, tbuf_length(tbuf) - offset - len); tbuf4 = x_tbuf_cat(tbuf1, tbuf2); tbuf_new = x_tbuf_cat(tbuf4, tbuf3); tbuf_destroy(tbuf1); tbuf_destroy(tbuf2); tbuf_destroy(tbuf3); tbuf_destroy(tbuf4); print_stats(tbuf_new); if (tbuf != NULL) tbuf_destroy(tbuf); tbuf = tbuf_new; } fclose(f); return 0; #endif } publib-0.40/tbuf/tbuf.c0000664000175000017500000006735511767433362013110 0ustar ajkajk/* Part of publib. Copyright (c) 2012 Antti-Juhani Kaijanaho Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * tbuf.c -- implement text editor buffers using trees * * Part of Publib, see man page for more information. * * * A brief description of how this works. * XXX probably needs to be updated * * The text of a buffer is broken down into `chunks', which contain up to * CHUNK_MAX characters each. The chunks are kept in a B-tree -like tree, * as leaf nodes. Chunks and trees are not modified after they have been * created. Instead, if the buffer needs to be modified, a copy is made, * but those parts of the buffer that have not been modifed are shared * between the original and the new copy. * * For example, assume we have the following tree, representing the buffer * "abcdef" (with CHUNK_MAX being 3): * * {=] * / \ * abc def * * ("[=]" is an interior node.) Now assume that we want to delete "abc" from * the buffer. We then create a new buffer that has a new interior node that * has only one child, the chunk that contains "def": * * {=] [=] * / \ : * abc def <......../ * * This way, the only new memory needed is that for the (small) interior node. * In a larger example some of the interior nodes would be shared as well. * * When the original buffer is no longer needed, it can be destroyed. This * does not destroy the "def" chunk, since it is shared. * * Similarly, when two buffers are catenated, the new tree uses as many * chunks and interior nodes of the old tree as possible. When sharing * is impossible, some nodes are copied and the copies are altered as * necessary. * * We use reference counting to implement the sharing of nodes and chunks * between trees. When a node or chunk is created, it's reference count * is set to 1. When a new tree is created and a new node is created and * points at a node in the old tree, the reference count for the old node is * incremented. However, nodes and chunks below that node are not touched, * since the new node does not directly reference them. When a tree is * destroyed, reference counts are decremented and if they fall to zero, * the node or chunk is freed. * */ #include #include #include #include #include #include "publib/tbuf.h" /* * Internal data structures. * * This has some potential improvement for the future: At the moment, all * chunks and nodes are allocated with separate calls to malloc, and at least * in some environments this is rather expensive, both in CPU time and memory * use. It would probably make sense to allocate lots of memory at once with * malloc, and then have a simpler custom memory allocator that gives out parts * of the large piece of malloc'd memory. At least for the chunk and node * structs, which are of a constant size; not necessarily for the text parts * of chunks. */ /* The maximum number of characters in a chunk. */ #define CHUNK_MAX 10 /* XXX */ #ifndef CHUNK_MAX #define CHUNK_MAX 128 #endif /* The chunk itself. */ typedef struct chunk Chunk; struct chunk { Chunk *next; size_t length; char *chars; unsigned visited:1; }; /* The maximum number of children a node may contain. */ #define NODE_MAX 3 /* XXX */ #ifndef NODE_MAX #define NODE_MAX 8 #endif /* The node itself. `height' is the level of this node, counting from leafs (level 1) upwards, so that a node having chunks as its children has a height of 2. `length' is the length of all chunks in the subtree for which this node is root. */ typedef struct node Node; struct node { Node *next; size_t height, length, kids; union { Chunk *chunk[NODE_MAX]; Node *node[NODE_MAX]; } x; unsigned visited:1; }; /* The buffer as presented to the user. (Of course, the user never sees inside this structure. Bondage and discipline needs to be enforced, them program writing lusers are dangerous.) `height' is the height of the tree containing the buffer. If it is 0, the buffer is empty. If 1, the tree only needs a chunk, so use x.chunk. Otherwise, there is at least one node, so use x.root. `offset' is the offset where `our' part of the character sequence described by the tree begins. `length' is the number of characters that belong to this buffer after the offset. This allows us to implement tbuf_copy very cheaply: it does not need to modify any part of the tree, just create a new Tbuf with modified offset and length fields. */ struct tbuf { Tbuf *next, *prev; size_t height, offset, length; union { Chunk *chunk; Node *root; } x; }; /* List of all Tbufs, Nodes and Chunk that exist at the moment. Needed for garbage collection. */ static Tbuf *tbuf_chain = NULL; static Node *node_chain = NULL; static Chunk *chunk_chain = NULL; /* List of unused Nodes. */ static Node *free_nodes = NULL; /* * Routines to print out the data structures for debugging. These are not * normally enabled. */ #if 1 #define dump_chunk(f, level, chunk) ((void) 0) #define dump_node(f, level, node) ((void) 0) #define dump_tbuf(f, tbuf) ((void) 0) #else static void dump_chunk(FILE *f, int level, Chunk *chunk) { int c, spaces; size_t i; spaces = level * 2; fprintf(f, "%*schunk at %p\n", spaces, "", (void *) chunk); fprintf(f, "%*s..length=%lu\n", spaces, "", (unsigned long) chunk->length); fprintf(f, "%*s..chars(%p)=<", spaces, "", (void *) chunk->chars); fflush(f); for (i = 0; i < chunk->length; ++i) { c = chunk->chars[i]; if (isprint(c)) fprintf(f, "%c", c); else fprintf(f, "<%02x>", (unsigned) c); } fprintf(f, ">\n"); } static void dump_node(FILE *f, int level, Node *node) { int spaces; size_t i; spaces = level * 2; fprintf(f, "%*snode at %p\n", spaces, "", (void *) node); fprintf(f, "%*s..height=%lu\n", spaces, "", (unsigned long) node->height); fprintf(f, "%*s..length=%lu\n", spaces, "", (unsigned long) node->length); fprintf(f, "%*s..kids=%lu\n", spaces, "", (unsigned long) node->kids); if (node->height == 2) { for (i = 0; i < node->kids; ++i) dump_chunk(f, level + 1, node->x.chunk[i]); } else { for (i = 0; i < node->kids; ++i) dump_node(f, level + 1, node->x.node[i]); } } static void dump_tbuf(FILE *f, Tbuf *tbuf) { fprintf(f, "tbuf at %p\n", (void *) tbuf); fprintf(f, "..height=%lu\n", (unsigned long) tbuf->height); fprintf(f, "..offset=%lu\n", (unsigned long) tbuf->offset); fprintf(f, "..length=%lu\n", (unsigned long) tbuf->length); if (tbuf->height == 1) dump_chunk(f, 1, tbuf->x.chunk); else if (tbuf->height >= 2) dump_node(f, 1, tbuf->x.root); fprintf(f, "end of tbuf dump at %p\n", (void *) tbuf); } #endif /* * tbuf_create and the routines it needs. `new_chunk' is used elsewhere as * well. */ /* Create a new chunk. Advance `*chars' and reduce `*nchars' by the length of the newly created chunk. */ static Chunk *new_chunk(const char **chars, size_t *nchars) { size_t n; Chunk *chunk; if (*nchars <= CHUNK_MAX) n = *nchars; else n = CHUNK_MAX; chunk = malloc(sizeof(Chunk)); if (chunk == NULL) return NULL; if (n == 0) chunk->chars = NULL; else { chunk->chars = malloc(n); if (chunk->chars == NULL) { free(chunk); return NULL; } memcpy(chunk->chars, *chars, n); } chunk->length = n; *chars += n; *nchars -= n; chunk->visited = 0; chunk->next = chunk_chain; chunk_chain = chunk; return chunk; } static Node *new_empty_node(void) { Node *node; if (free_nodes == NULL) { node = malloc(sizeof(Node)); if (node == NULL) return NULL; } else { node = free_nodes; free_nodes = free_nodes->next; } node->next = node_chain; node_chain = node; node->height = 0; node->length = 0; node->kids = 0; node->visited = 0; return node; } /* Create a new node. `*chars' and `*nchars' as for new_chunk (surprisingly enough :). */ static Node *new_node(size_t height, const char **chars, size_t *nchars) { Node *node; size_t i; node = new_empty_node(); if (node == NULL) return NULL; node->height = height; node->length = 0; node->visited = 0; if (height == 2) { for (i = 0; i < NODE_MAX && *nchars > 0; ++i) { node->x.chunk[i] = new_chunk(chars, nchars); if (node->x.chunk[i] == NULL) return NULL; node->length += node->x.chunk[i]->length; } } else { for (i = 0; i < NODE_MAX && *nchars > 0; ++i) { node->x.node[i] = new_node(height-1, chars, nchars); if (node->x.node[i] == NULL) return NULL; node->length += node->x.node[i]->length; } } node->kids = i; return node; } /* Build a tree of nodes and chunks. */ static void *build_tree(size_t *height, const char *chars, size_t nchars) { size_t max_length_for_height; assert(nchars > 0); *height = 1; max_length_for_height = CHUNK_MAX; while (max_length_for_height < nchars) { ++*height; max_length_for_height *= NODE_MAX; } if (*height == 1) return new_chunk(&chars, &nchars); else return new_node(*height, &chars, &nchars); } static Tbuf *new_tbuf(void) { Tbuf *tbuf; tbuf = malloc(sizeof(Tbuf)); if (tbuf == NULL) return NULL; tbuf->height = 0; tbuf->offset = 0; tbuf->length = 0; tbuf->next = tbuf_chain; tbuf->prev = NULL; if (tbuf_chain != NULL) tbuf_chain->prev = tbuf; tbuf_chain = tbuf; return tbuf; } Tbuf *tbuf_create(const char *chars, size_t nchars) { Tbuf *tbuf; void *p; tbuf = new_tbuf(); if (nchars == 0) { p = NULL; } else { p = build_tree(&tbuf->height, chars, nchars); if (p == NULL) { tbuf_destroy(tbuf); return NULL; } } switch (tbuf->height) { case 0: tbuf->x.chunk = NULL; break; case 1: tbuf->x.chunk = p; break; default: tbuf->x.root = p; break; } tbuf->length = nchars; return tbuf; } /* * tbuf_destroy and the routines it needs. */ static void chunk_destroy(Chunk *chunk) { if (chunk != NULL) { free(chunk->chars); free(chunk); } } static void node_destroy(Node *node) { node->next = free_nodes; free_nodes = node; } static void node_zero_visited(Node *node) { size_t i; node->visited = 0; if (node->height == 2) { for (i = 0; i < node->kids; ++i) node->x.chunk[i]->visited = 0; } else { for (i = 0; i < node->kids; ++i) node_zero_visited(node->x.node[i]); } } static void garbage_collect(void) { Tbuf *tbuf; Node *node, *new_node_chain, *next_node; Chunk *chunk, *new_chunk_chain, *next_chunk; for (chunk = chunk_chain; chunk != NULL; chunk = chunk->next) chunk->visited = 1; for (node = node_chain; node != NULL; node = node->next) node->visited = 1; for (tbuf = tbuf_chain; tbuf != NULL; tbuf = tbuf->next) { switch (tbuf->height) { case 0: break; case 1: tbuf->x.chunk->visited = 0; break; default: node_zero_visited(tbuf->x.root); } } new_chunk_chain = NULL; for (chunk = chunk_chain; chunk != NULL; chunk = next_chunk) { next_chunk = chunk->next; if (chunk->visited == 1) chunk_destroy(chunk); else { chunk->next = new_chunk_chain; new_chunk_chain = chunk; } } chunk_chain = new_chunk_chain; new_node_chain = NULL; for (node = node_chain; node != NULL; node = next_node) { next_node = node->next; if (node->visited == 1) node_destroy(node); else { node->next = new_node_chain; new_node_chain = node; } } node_chain = new_node_chain; } void tbuf_destroy(Tbuf *tbuf) { assert(tbuf != NULL); #if 1 if (tbuf_chain == tbuf) tbuf_chain = tbuf->next; if (tbuf->prev != NULL) tbuf->prev->next = tbuf->next; if (tbuf->next != NULL) tbuf->next->prev = tbuf->prev; free(tbuf); #endif garbage_collect(); } /* * tbuf_chars and the routines it needs. */ /* Copy part of a chunk to a character array, and advance the pointer to the array by the amount copied. */ static void chunk_collect(char **chars, Chunk *chunk, size_t off, size_t n) { memcpy(*chars, chunk->chars + off, n); *chars += n; } /* Visit all relevant chunks and copy the relevant parts of them. Subtrees can sometimes be skipped completely, based on `*off' and their length. */ static void node_collect(char **chars, Node *node, size_t *off, size_t *n) { size_t i; Chunk *chunk; if (node->length <= *off) *off -= node->length; else if (node->height > 2) { for (i = 0; i < node->kids && *n > 0; ++i) node_collect(chars, node->x.node[i], off, n); } else { for (i = 0; i < node->kids && *n > 0; ++i) { chunk = node->x.chunk[i]; if (chunk->length <= *off) *off -= chunk->length; else if (*n <= chunk->length) { chunk_collect(chars, chunk, *off, *n); *n = 0; } else { chunk_collect(chars, chunk, *off, chunk->length); *off = 0; *n -= chunk->length; } } } } void tbuf_chars(char *chars, Tbuf *tbuf, size_t start, size_t length) { assert(chars != NULL); assert(tbuf != NULL); if (start >= tbuf->length || length == 0) return; if (start + length > tbuf->length) length = tbuf->length - start; start += tbuf->offset; if (tbuf->height == 1) chunk_collect(&chars, tbuf->x.chunk, start, length); else node_collect(&chars, tbuf->x.root, &start, &length); } /* * tbuf_cat and stuff that it needs. This is the most difficult operation * and needs the largest amount of code. This needs pictures to be explained, * I think, and I don't have the time to draw them now. */ /* Create a new chunk out an old one. */ static Chunk *copy_chunk(Chunk *chunk, size_t offset, size_t length) { const char *p; assert(offset < chunk->length); assert(offset + length <= chunk->length); p = chunk->chars + offset; return new_chunk(&p, &length); } /* Create a new node out of an old one. */ /* NOTE: to is "up to", not inclusive. */ static Node *copy_node(Node *node, void *before, size_t from, size_t to, void *after) { Node *node_new; size_t i; node_new = new_empty_node(); if (node_new == NULL) return NULL; node_new->height = node->height; node_new->length = 0; node_new->kids = 0; if (node_new->height == 2) { if (before != NULL) node_new->x.chunk[node_new->kids++] = before; for (i = from; i < to; ++i) node_new->x.chunk[node_new->kids++] = node->x.chunk[i]; if (after != NULL) node_new->x.chunk[node_new->kids++] = after; for (i = 0; i < node_new->kids; ++i) node_new->length += node_new->x.chunk[i]->length; } else { if (before != NULL) node_new->x.node[node_new->kids++] = before; for (i = from; i < to; ++i) node_new->x.node[node_new->kids++] = node->x.node[i]; if (after != NULL) node_new->x.node[node_new->kids++] = after; for (i = 0; i < node_new->kids; ++i) node_new->length += node_new->x.node[i]->length; } assert(node_new->kids > 0); return node_new; } /* Create a new node tree out of an old one that begins after `offset' in the old one. */ static Node *chop_before(Node *root, size_t offset) { Node *node, *node_new, *root_new; Chunk *chunk, *chunk_new; size_t i, orig_offset; if (offset == 0) return root; orig_offset = offset; if (root->height == 2) { for (i = 0; ; ++i) { assert(i < root->kids); chunk = root->x.chunk[i]; if (chunk->length >= offset) break; offset -= chunk->length; } if (offset == chunk->length) chunk_new = NULL; else { chunk_new = copy_chunk(chunk, offset, chunk->length - offset); if (chunk_new == NULL) return NULL; } root_new = copy_node(root, chunk_new, i+1, root->kids, NULL); if (root_new == NULL) return NULL; assert(root_new->length == root->length - orig_offset); } else { for (i = 0; ; ++i) { assert(i < root->kids); node = root->x.node[i]; if (node->length >= offset) break; offset -= node->length; } if (offset == node->length) node_new = NULL; else { node_new = chop_before(node, offset); if (node_new == NULL) return NULL; } root_new = copy_node(root, node_new, i+1, root->kids, NULL); if (root_new == NULL) return NULL; assert(root_new->length == root->length - orig_offset); } return root_new; } /* Create a new node tree out of an old one that ends before `offset' in the old one. */ static Node *chop_after(Node *root, size_t offset) { Node *node, *node_new, *root_new; Chunk *chunk, *chunk_new; size_t i, orig_offset; if (offset >= root->length) return root; orig_offset = offset; if (root->height == 2) { for (i = 0; ; ++i) { assert(i < root->kids); chunk = root->x.chunk[i]; if (chunk->length > offset) break; offset -= chunk->length; } chunk_new = copy_chunk(chunk, 0, offset); if (chunk_new == NULL) return NULL; assert(chunk_new->length == offset); root_new = copy_node(root, NULL, 0, i, chunk_new); if (root_new == NULL) return NULL; assert(root_new->length == orig_offset); } else { for (i = 0; ; ++i) { assert(i < root->kids); node = root->x.node[i]; if (node->length > offset) break; offset -= node->length; } node_new = chop_after(node, offset); if (node_new == NULL) return NULL; root_new = copy_node(root, NULL, 0, i, node_new); if (root_new == NULL) return NULL; assert(root_new->length == orig_offset); } assert(root_new->height == root->height); return root_new; } /* Make sure a node tree is at least of a particular height. */ static void *make_of_height(size_t wanted, void *ptr, size_t current) { Node *ptr_new; while (current < wanted) { ptr_new = new_empty_node(); if (ptr_new == NULL) return NULL; ptr_new->height = current + 1; ptr_new->kids = 1; switch (current) { case 0: assert(ptr == NULL); ptr_new->x.chunk[0] = NULL; ptr_new->length = 0; break; case 1: ptr_new->x.chunk[0] = ptr; ptr_new->length = ((Chunk *) ptr)->length; break; default: ptr_new->x.node[0] = ptr; ptr_new->length = ((Node *) ptr)->length; break; } ptr = ptr_new; ++current; } return ptr; } #if 0 static Node *make_root(Tbuf *tbuf) { Node *root; assert(tbuf->height > 0); if (tbuf->height >= 2) return tbuf->x.root; root = new_empty_node(); if (root == NULL) return NULL; root->height = 2; root->length = tbuf->length; root->kids = 1; root->x.chunk[0] = tbuf->x.chunk; return root; } static Chunk *rightmost_chunk(Node *root) { assert(root->height >= 2); while (root->height > 2) root = root->x.node[root->kids - 1]; return root->x.chunk[root->kids - 1]; } static Chunk *leftmost_chunk(Node *root) { assert(root->height >= 2); while (root->height > 2) root = root->x.node[0]; return root->x.chunk[0]; } static Node *replace_rightmost_chunk(Node *root, Chunk *chunk) { Node *new, *new_kid; int i; new = new_empty_node(); if (new == NULL) return NULL; new->height = root->height; new->kids = root->kids; if (root->height == 2) { new->length = root->length - root->x.chunk[root->kids-1]->length + chunk->length; for (i = 0; i < root->kids-1; ++i) new->x.chunk[i] = root->x.chunk[i]; new->x.chunk[root->kids-1] = chunk; } else { new_kid = replace_rightmost_chunk(root->x.node[root->kids-1], chunk); new->length = root->length - root->x.node[root->kids-1]->length + new_kid->length; for (i = 0; i < root->kids-1; ++i) new->x.node[i] = root->x.node[i]; new->x.node[root->kids-1] = new_kid; } assert(new->kids > 0); return new; } #endif static Tbuf *copy_tbuf(Tbuf *tbuf) { Tbuf *new; new = new_tbuf(); if (new == NULL) return NULL; new->height = tbuf->height; new->offset = tbuf->offset; new->length = tbuf->length; new->x = tbuf->x; return new; } static Node *trim_chunk_tree(Tbuf *tbuf) { Node *root; Chunk *chunk; switch (tbuf->height) { case 0: assert(0); return NULL; case 1: root = new_empty_node(); if (root == NULL) return NULL; chunk = tbuf->x.chunk; root->length = chunk->length; root->height = 2; root->kids = 1; root->x.chunk[0] = chunk; return root; default: root = tbuf->x.root; root = chop_after(root, tbuf->offset + tbuf->length); if (root == NULL) return NULL; return chop_before(root, tbuf->offset); } /*NOTREACHED*/ } static void copy_kids(void **kids, int *total, void **tab, int from, int to) { int i; for (i = from; i <= to; ++i) kids[(*total)++] = tab[i]; } static void copy_kids_to_node(Node *node, void **kids, int from, int to) { int i; Chunk *ckid; Node *nkid; switch (node->height) { case 1: assert(0); break; case 2: for (i = from; i <= to; ++i) { ckid = kids[i]; node->x.chunk[node->kids++] = ckid; node->length += ckid->length; } break; default: for (i = from; i <= to; ++i) { nkid = kids[i]; node->x.node[node->kids++] = nkid; node->length += nkid->length; } break; } } static void collect_right_side(void **tab, Node *root) { int i; for (i = root->height; i > 2; --i) { tab[i] = root; root = root->x.node[root->kids-1]; } assert(root->height == 2); tab[1] = root->x.chunk[root->kids-1]; } static void collect_left_side(void **tab, Node *root) { int i; for (i = root->height; i > 2; --i) { tab[i] = root; root = root->x.node[0]; } assert(root->height == 2); tab[1] = root->x.chunk[0]; } static void combine_chunks(void **p1, void **p2, Chunk *chunk1, Chunk *chunk2) { size_t len1, len2, len; char buf[CHUNK_MAX]; const char *cstr; assert(p1 != NULL); assert(p2 != NULL); assert(chunk1 != NULL); assert(chunk2 != NULL); len1 = chunk1->length; len2 = chunk2->length; if (len1 + len2 > CHUNK_MAX) { *p1 = chunk1; *p2 = chunk2; } else { memcpy(buf, chunk1->chars, len1); memcpy(buf + len1, chunk2->chars, len2); cstr = buf; len = len1 + len2; *p1 = new_chunk(&cstr, &len); *p2 = NULL; assert(((Chunk *) *p1)->length == len1 + len2); } } #define SMART_CAT_HEIGHT 100 static Node *smart_cat(Tbuf *tbuf1, Tbuf *tbuf2, Node *root1, Node *root2) { void *tab1[SMART_CAT_HEIGHT] = { NULL, }; void *tab2[SMART_CAT_HEIGHT] = { NULL, }; void *allkids[NODE_MAX * 2]; void *p1, *p2, *q1, *q2; size_t i, h1, h2, h_max; int kids1, kids2, total_kids; h1 = root1->height; h2 = root2->height; assert(h1 > 0); assert(h2 > 0); if (h1 >= SMART_CAT_HEIGHT || h2 >= SMART_CAT_HEIGHT) return NULL; /* stupid_cat will handle this */ if (h1 < h2) h_max = h2; else h_max = h1; collect_right_side(tab1, root1); collect_left_side(tab2, root2); combine_chunks(&p1, &p2, tab1[1], tab2[1]); if (p1 == NULL) return NULL; for (i = 2; i <= h_max; ++i) { kids1 = (tab1[i] == NULL) ? 0 : ((Node *) tab1[i])->kids; kids2 = (tab2[i] == NULL) ? 0 : ((Node *) tab2[i])->kids; if (kids1 + kids2 > NODE_MAX) return NULL; total_kids = 0; copy_kids(allkids, &total_kids, tab1, 0, kids1-2); if (p1 != NULL) allkids[total_kids++] = p1; if (p2 != NULL) allkids[total_kids++] = p2; copy_kids(allkids, &total_kids, tab1, 1, kids2-1); if (total_kids > NODE_MAX) { q1 = new_empty_node(); if (q1 == NULL) return NULL; ((Node *)q1)->height = i; copy_kids_to_node(q1, allkids, 0, NODE_MAX-1); q2 = new_empty_node(); if (q2 == NULL) return NULL; ((Node *)q2)->height = i; copy_kids_to_node(q2, allkids, NODE_MAX, total_kids-1); } else { q1 = new_empty_node(); if (q1 == NULL) return NULL; ((Node *)q1)->height = i; copy_kids_to_node(q1, allkids, 0, total_kids-1); q2 = NULL; } p1 = q1; p2 = q2; } if (p2 != NULL) return NULL; assert(p1 != NULL); return p1; } static Node *stupid_cat(Tbuf *tbuf1, Tbuf *tbuf2, Node *p1, Node *p2) { Node *new_root; size_t h1, h2; printf("stupid_cat: ------------------------------------------------\n"); h1 = p1->height; h2 = p2->height; if (h1 < h2) { p1 = make_of_height(h2, p1, h1); h1 = h2; } else if (h2 < h2) { p2 = make_of_height(h1, p2, h2); h2 = h1; } assert(h1 > 1); if (p1 == NULL || p2 == NULL) return NULL; new_root = new_empty_node(); new_root->height = h1 + 1; new_root->length = p1->length + p2->length; new_root->kids = 2; new_root->x.node[0] = p1; new_root->x.node[1] = p2; return new_root; } Tbuf *tbuf_cat(Tbuf *tbuf1, Tbuf *tbuf2) { Tbuf *tbuf_new; Node *p1, *p2, *new_root; if (tbuf1->length == 0) return copy_tbuf(tbuf2); if (tbuf2->length == 0) return copy_tbuf(tbuf1); p1 = trim_chunk_tree(tbuf1); p2 = trim_chunk_tree(tbuf2); if (p1 == NULL || p2 == NULL) return NULL; new_root = smart_cat(tbuf1, tbuf2, p1, p2); if (new_root == NULL) new_root = stupid_cat(tbuf1, tbuf2, p1, p2); if (new_root == NULL) return NULL; tbuf_new = new_tbuf(); if (tbuf_new == NULL) return NULL; tbuf_new->height = new_root->height; tbuf_new->length = new_root->length; tbuf_new->x.root = new_root; return tbuf_new; } /* * tbuf_copy needs no auxiliary routines of its own. */ Tbuf *tbuf_copy(Tbuf *tbuf, size_t start, size_t length) { Tbuf *tbuf_new; Node *temp; if (start >= tbuf->length || length == 0) return tbuf_create("", 0); if (start + length > tbuf->length) length = tbuf->length - start; tbuf_new = new_tbuf(); if (tbuf_new == NULL) return NULL; switch (tbuf->height) { case 0: tbuf_new->height = 0; tbuf_new->offset = 0; tbuf_new->length = 0; break; case 1: tbuf_new->height = 1; tbuf_new->offset = tbuf->offset + start; tbuf_new->length = length; tbuf_new->x.chunk = tbuf->x.chunk; break; default: #if 1 temp = chop_before(tbuf->x.root, tbuf->offset); temp = chop_after(temp, tbuf->length); while (temp->height > 2 && temp->kids == 1) temp = temp->x.node[0]; tbuf_new->x.root = temp; tbuf_new->height = temp->height; #else tbuf_new->x.root = tbuf->x.root; tbuf_new->height = tbuf->height; #endif tbuf_new->offset = 0; tbuf_new->length = length; break; } return tbuf_new; } /* * tbuf_get_stats. Statistics gathering. */ static void gather_chunk_stats(struct tbuf_stat *stat, Chunk *chunk, int shared) { size_t chunk_memory; if (!chunk->visited) { ++stat->tbuf_chunks; chunk_memory = sizeof(Chunk) + chunk->length; stat->tbuf_memory_total += chunk_memory; chunk->visited = 1; } } static void gather_node_stats(struct tbuf_stat *stat, Node *node, int shared) { size_t i; if (!node->visited) { ++stat->tbuf_nodes; stat->tbuf_memory_total += sizeof(Node); if (node->kids < 3) ++stat->tbuf_nodes_with_few_kids; if (node->height == 2) { for (i = 0; i < node->kids; ++i) gather_chunk_stats(stat, node->x.chunk[i], shared); } else { for (i = 0; i < node->kids; ++i) gather_node_stats(stat, node->x.node[i], shared); } node->visited = 1; } } void tbuf_get_stats(struct tbuf_stat *stat, Tbuf *tbuf) { stat->tbuf = tbuf; stat->tbuf_length = tbuf->length; stat->tbuf_height = tbuf->height; stat->tbuf_nodes = 0; stat->tbuf_chunks = 0; stat->tbuf_memory_total = sizeof(Tbuf); stat->tbuf_nodes_with_few_kids = 0; switch (tbuf->height) { case 0: break; case 1: tbuf->x.chunk->visited = 0; gather_chunk_stats(stat, tbuf->x.chunk, 0); break; default: node_zero_visited(tbuf->x.root); gather_node_stats(stat, tbuf->x.root, 0); break; } } /* * Return length of buffer. */ size_t tbuf_length(Tbuf *tbuf) { return tbuf->length; } publib-0.40/tbuf/test_tbuf.c0000664000175000017500000000614311767432776014143 0ustar ajkajk/* Part of publib. Copyright (c) 2012 Antti-Juhani Kaijanaho. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * test_tbuf.c -- test program for tbuf * * Part of Publib, see man page for more information. */ #include #include #include #include "publib/tbuf.h" static void panic(const char *msg) { fprintf(stderr, "PANIC: %s\n", msg); exit(EXIT_FAILURE); } static Tbuf *x_tbuf_create(const char *str, size_t len) { Tbuf *tbuf; tbuf = tbuf_create(str, len); if (tbuf == NULL) panic("tbuf_create returned NULL"); return tbuf; } static Tbuf *x_tbuf_copy(Tbuf *tbuf, size_t offset, size_t len) { Tbuf *tbuf2; tbuf2 = tbuf_copy(tbuf, offset, len); if (tbuf2 == NULL) panic("tbuf_copy returned NULL"); return tbuf2; } static Tbuf *x_tbuf_cat(Tbuf *tbuf1, Tbuf *tbuf2) { Tbuf *tbuf; tbuf = tbuf_cat(tbuf1, tbuf2); if (tbuf == NULL) panic("tbuf_cat returned NULL"); return tbuf; } int main(void) { Tbuf *tbuf, *tbuf2, *tbuf3; char str[] = "abcdefghijklmnopqrstuvwxyz"; char buf[10240]; size_t len, len2, max; max = strlen(str); for (len = 0; len <= max; ++len) { tbuf = x_tbuf_create(str, len); memset(buf, 0, sizeof(buf)); tbuf_chars(buf, tbuf, 0, len); printf("buf =<%s> (len=%zu)\n", buf, len); tbuf2 = x_tbuf_copy(tbuf, 0, len); tbuf_destroy(tbuf); memset(buf, 0, sizeof(buf)); tbuf_chars(buf, tbuf2, 0, len); printf("buf2=<%s> (len=%zu)\n", buf, len); tbuf_destroy(tbuf2); } for (len = 0; len <= max; ++len) { tbuf = x_tbuf_create(str, len); for (len2 = 0; len2 <= max; ++len2) { tbuf2 = x_tbuf_create(str, len2); tbuf3 = x_tbuf_cat(tbuf, tbuf2); memset(buf, 0, sizeof(buf)); tbuf_chars(buf, tbuf3, 0, len + len2); printf("buf=<%s> (len=%zu len2=%zu)\n", buf, len, len2); tbuf_destroy(tbuf2); tbuf_destroy(tbuf3); } } return 0; } publib-0.40/queue/0000775000175000017500000000000011767707451012153 5ustar ajkajkpublib-0.40/queue/queue.c0000664000175000017500000001035611767417657013456 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: queue.c * Purpose: Implement the queue abstract data type. * Author: Lars Wirzenius * Version: "@(#)publib:$Id: queue.c,v 1.1.1.1 1996/01/18 15:44:03 liw Exp $" */ #include #include #include "publib/queue.h" #include "publib/alloc.h" #include "publib/errormsg.h" /* * Function: queue_create * Purpose: Create a new queue. * Arguments: None. * Return: Pointer to queue handle. */ Queue *queue_create(void) { Queue *q; q = malloc(sizeof(*q)); if (q == NULL) { __publib_error("queue_create: out of memory"); return NULL; } q->queue_front = NULL; q->queue_behind = NULL; return q; } /* * Function: queue_destroy * Purpose: Destroy a queue and its contents. * Arguments: q pointer to queue * Return: Nothing. */ void queue_destroy(Queue *q) { assert(q != NULL); while (q->queue_front != NULL) (void) queue_remove(q); free(q); } /* * Function: queue_front * Purpose: Return foremost datum in queue. * Arguments: q pointer to queue * Return: Pointer to data. */ void *queue_front(Queue *q) { assert(q != NULL); assert(q->queue_front != NULL); return q->queue_front->queue_data; } /* * Function: queue_remove * Purpose: Remove and return foremost datum in queue. * Arguments: q pointer to queue * Return: Pointer to data. */ void *queue_remove(Queue *q) { struct queue_node *p; void *data; assert(q != NULL); assert(q->queue_front != NULL); p = q->queue_front; data = p->queue_data; q->queue_front = p->queue_previous; if (q->queue_front == NULL) q->queue_behind = NULL; free(p); return data; } /* * Function: queue_is_empty * Purpose: Is the queue empty? * Arguments: q pointer to queue * Return: 0 for not empty, 1 for empty. */ int queue_is_empty(Queue *q) { assert(q != NULL); return q->queue_front == NULL; } /* * Function: queue_add * Purpose: Add a new datum at end of queue. * Arguments: q pointer to queue * data pointer to data * size size of data * Description: queue_add adds a new datum at the behind end of a queue. * If `size' is 0, it only adds the pointer value `data'. * Otherwise it makes a copy of the datum (first `size' * bytes beginning at `data') and adds that into the queue. * In the latter case, when the datum is removed from the queue, * it is the responsibility of the user to free the memory. * Return: -1 for failure (memory allocation error), 0 for OK. */ int queue_add(Queue *q, const void *data, size_t size) { struct queue_node *p; p = malloc(sizeof(*p)); if (p == NULL) { __publib_error("queue_add: out of memory"); return -1; } if (size > 0) { data = memdup(data, size); if (data == NULL) { __publib_error("queue_add: out of memory"); free(p); return -1; } } p->queue_previous = NULL; p->queue_data = (void *) data; if (q->queue_behind == NULL) { q->queue_behind = p; q->queue_front = p; } else { q->queue_behind->queue_previous = p; q->queue_behind = p; } return 0; } publib-0.40/queue/test-queue.c0000664000175000017500000000441511767417657014432 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: test-queue.c * Purpose: Test the queue data structure routines. * Author: Lars Wirzenius * Version: "@(#)publib:$Id: test-queue.c,v 1.1.1.1 1996/01/18 15:44:03 liw Exp $" */ #include #include int main(void) { Queue *q; char *str[] = { "hello, world", "ciao, bambino", "hasta la vista, baby", "I'll be back", "you talking to me?", }; const int n = sizeof(str) / sizeof(*str); int i; __set_liberror(__complain_on_error | __exit_on_error); q = queue_create(); if (!queue_is_empty(q)) errormsg(1, 0, "queue not empty after creation"); for (i = 0; i < n; ++i) { (void) queue_add(q, str[i], 0); if (queue_is_empty(q)) errormsg(1, 0, "queue is empty after add"); } for (i = 0; i < n; ++i) if (queue_remove(q) != str[i]) errormsg(1, 0, "queue not in order"); if (!queue_is_empty(q)) errormsg(1, 0, "queue is not empty after removals"); queue_destroy(q); printf("queue seems to work\n"); return 0; } publib-0.40/configure0000775000175000017500000035317411767647616012761 0ustar ajkajk#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.68 for publib 0.40. # # Report bugs to . # # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 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. ## ## -------------------- ## # 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=: # Pre-4.2 versions of Zsh do 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_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } 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.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= 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 $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do 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_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV export CONFIG_SHELL case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org and $0: publib@lists.kaijanaho.info about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_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 || $as_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" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error 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 if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # 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 as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # 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" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_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 } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac 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 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then 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 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='mkdir -p "$as_dir"' 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'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/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 ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='publib' PACKAGE_TARNAME='publib' PACKAGE_VERSION='0.40' PACKAGE_STRING='publib 0.40' PACKAGE_BUGREPORT='publib@lists.kaijanaho.info' PACKAGE_URL='' ac_unique_file="man/publib.3" ac_subst_vars='LTLIBOBJS LIBOBJS MAKE MKDIR_P RANLIB INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM MDMF OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= 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' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' 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 ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. 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 ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) 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 ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -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_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=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_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$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 | -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_alias ;; -host=* | --host=* | --hos=* | --ho=*) 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 ;; -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 ;; -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) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --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 ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) 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 ;; -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) 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_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=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 ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_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 ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. 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 eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # 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 # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe $as_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 .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # 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 the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | 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 srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" 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 # # 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 publib 0.40 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/publib] --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 if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of publib 0.40:";; esac 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 (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to . _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" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && 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=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_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 $as_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 publib configure 0.40 generated by GNU Autoconf 2.68 Copyright (C) 2010 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 ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack 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 ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_compile 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 publib $as_me 0.40, which was generated by GNU Autoconf 2.68. 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=. $as_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=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append 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 as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset 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 $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" 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_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; 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 $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_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'; as_fn_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 $as_echo "/* confdefs.h */" > 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 cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_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,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_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 # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_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. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## 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 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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&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}gcc" $as_echo "$as_me:${as_lineno-$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 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&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" $as_echo "$as_me:${as_lineno-$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 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then 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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&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" $as_echo "$as_me:${as_lineno-$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 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no 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" $as_echo "$as_me:${as_lineno-$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 $# != 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 ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi 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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&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$ac_prog" $as_echo "$as_me:${as_lineno-$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 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi 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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&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" $as_echo "$as_me:${as_lineno-$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 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM 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. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.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 ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; 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 | *.dSYM | *.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 ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 $as_echo_n "checking for C compiler default output file name... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 $as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; 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 | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 $as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 $as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } if ${ac_cv_objext+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* 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 ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; 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 | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 $as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if ${ac_cv_c_compiler_gnu+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if ${ac_cv_prog_cc_g+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi 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 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if ${ac_cv_prog_cc_c89+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* 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; } /* 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" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg 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) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : 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=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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking CFLAGS for maximum warnings" >&5 $as_echo_n "checking CFLAGS for maximum warnings... " >&6; } if ${ac_cv_cflags_warn_all+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_cflags_warn_all="no, unknown" ac_save_CFLAGS="$CFLAGS" for ac_arg in "-warn all % -warn all" "-pedantic % -Wall" "-xstrconst % -v" "-std1 % -verbose -w0 -warnprotos" "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" "-ansi -ansiE % -fullwarn" "+ESlit % +w1" "-Xc % -pvctl,fullmsg" "-h conform % -h msglevel 2" # do CFLAGS="$ac_save_CFLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'` cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_cflags_warn_all=`echo $ac_arg | sed -e 's,.*% *,,'` ; break fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext done CFLAGS="$ac_save_CFLAGS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cflags_warn_all" >&5 $as_echo "$ac_cv_cflags_warn_all" >&6; } case ".$ac_cv_cflags_warn_all" in .ok|.ok,*) ;; .|.no|.no,*) ;; *) if ${CFLAGS+:} false; then : case " $CFLAGS " in *" $ac_cv_cflags_warn_all "*) { { $as_echo "$as_me:${as_lineno-$LINENO}: : CFLAGS already contains \$ac_cv_cflags_warn_all"; } >&5 (: CFLAGS already contains $ac_cv_cflags_warn_all) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; *) { { $as_echo "$as_me:${as_lineno-$LINENO}: : CFLAGS=\"\$CFLAGS \$ac_cv_cflags_warn_all\""; } >&5 (: CFLAGS="$CFLAGS $ac_cv_cflags_warn_all") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } CFLAGS="$CFLAGS $ac_cv_cflags_warn_all" ;; esac else CFLAGS="$ac_cv_cflags_warn_all" fi ;; 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 # Test for -MD { $as_echo "$as_me:${as_lineno-$LINENO}: checking checking whether $CC -MD -MF works" >&5 $as_echo_n "checking checking whether $CC -MD -MF works... " >&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 rm -f main/conftest.d cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include "publib.h" _ACEOF mv conftest.c main/conftest.c $CC -Iincludes $CPPFLAGS $CFLAGS \ -MD -MF main/conftest.d -c main/conftest.c -o main/conftest.o if test -r main/conftest.d ; then MDMF='-MD -MF $*.d' { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else MDMF="" { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi rm -f main/conftest.d main/conftest.c main/conftest.o ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do if test -f "$ac_dir/install-sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install-sh -c" break elif test -f "$ac_dir/install.sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install.sh -c" break elif test -f "$ac_dir/shtool"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/shtool install -c" break fi done if test -z "$ac_aux_dir"; then as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 fi # These three variables are undocumented and unsupported, # and are intended to be withdrawn in a future Autoconf release. # They can cause serious problems if a builder's source tree is in a directory # whose full name contains unusual characters. ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install # AmigaOS /C/install, which installs bootblocks on floppy discs # AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # OS/2's system install, which has a completely different semantic # ./install, which can be erroneously created by make from ./install.sh. # Reject install programs that cannot install multiple files. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 $as_echo_n "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then if ${ac_cv_path_install+:} false; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. # Account for people who put trailing slashes in PATH elements. case $as_dir/ in #(( ./ | .// | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. # Don't use installbsd from OSF since it installs stuff as root # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : elif test $ac_prog = install && grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # program-specific install script used by HP pwplus--don't use. : else rm -rf conftest.one conftest.two conftest.dir echo one > conftest.one echo two > conftest.two mkdir conftest.dir if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && test -s conftest.one && test -s conftest.two && test -s conftest.dir/conftest.one && test -s conftest.dir/conftest.two then ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" break 3 fi fi fi done done ;; esac done IFS=$as_save_IFS rm -rf conftest.one conftest.two conftest.dir fi if test "${ac_cv_path_install+set}" = set; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a # value for INSTALL within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. INSTALL=$ac_install_sh fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 $as_echo "$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}' test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' 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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_RANLIB+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$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_RANLIB="${ac_tool_prefix}ranlib" $as_echo "$as_me:${as_lineno-$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 if test -n "$RANLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 $as_echo "$RANLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : $as_echo_n "(cached) " >&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" $as_echo "$as_me:${as_lineno-$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 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 $as_echo "$ac_ct_RANLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_RANLIB" = x; then RANLIB=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RANLIB=$ac_ct_RANLIB fi else RANLIB="$ac_cv_prog_RANLIB" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 $as_echo_n "checking for a thread-safe mkdir -p... " >&6; } if test -z "$MKDIR_P"; then if ${ac_cv_path_mkdir+:} false; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( 'mkdir (GNU coreutils) '* | \ 'mkdir (coreutils) '* | \ 'mkdir (fileutils) '4.1*) ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext break 3;; esac done done done IFS=$as_save_IFS fi test -d ./--version && rmdir ./--version if test "${ac_cv_path_mkdir+set}" = set; then MKDIR_P="$ac_cv_path_mkdir -p" else # As a last resort, use the slow shell script. Don't cache a # value for MKDIR_P within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. MKDIR_P="$ac_install_sh -d" fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 $as_echo "$MKDIR_P" >&6; } # Extract the first word of "gmake", so it can be a program name with args. set dummy gmake; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_MAKE+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$MAKE"; then ac_cv_prog_MAKE="$MAKE" # 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_MAKE="gmake" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS test -z "$ac_cv_prog_MAKE" && ac_cv_prog_MAKE="make" fi fi MAKE=$ac_cv_prog_MAKE if test -n "$MAKE"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAKE" >&5 $as_echo "$MAKE" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi 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, 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. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `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, 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. ( 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_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; 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 if test "x$cache_file" != "x/dev/null"; then { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) mv -f confcache "$cache_file"$$ && mv -f "$cache_file"$$ "$cache_file" ;; #( *) mv -f confcache "$cache_file" ;; esac fi fi else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' # Transform confdefs.h into DEFS. # Protect against shell expansion while executing Makefile rules. # Protect against Makefile macro expansion. # # 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=' :mline /\\$/{ N s,\\\n,, b mline } 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= U= 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=`$as_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. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## 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=: # Pre-4.2 versions of Zsh do 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_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } 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.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= 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 $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith 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 if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # 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 ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac 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 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then 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 else as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_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 || $as_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" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' 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 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=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 publib $as_me 0.40, which was generated by GNU Autoconf 2.68. 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 case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent 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_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ publib config.status 0.40 configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" Copyright (C) 2010 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' INSTALL='$INSTALL' MKDIR_P='$MKDIR_P' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. 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=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= 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 ) $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --he | --h | --help | --hel | -h ) $as_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. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append 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 || ac_write_fail=1 if \$ac_cs_recheck; then set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX $as_echo "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; 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= ac_tmp= trap 'exit_status=$? : "${ac_tmp:=$tmp}" { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries 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[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" eval set X " :F $CONFIG_FILES " shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[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="$ac_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 || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append 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 '` $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 $as_echo "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`$as_echo "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$ac_tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac 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 || $as_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"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_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 case $ac_mode in :F) # # CONFIG_FILE # case $INSTALL in [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; esac ac_MKDIR_P=$MKDIR_P case $MKDIR_P in [\\/$]* | ?:[\\/]* ) ;; */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; esac _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # 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= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 $as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 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 || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;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 s&@INSTALL@&$ac_INSTALL&;t t s&@MKDIR_P@&$ac_MKDIR_P&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 $as_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 "$ac_tmp/stdin" case $ac_file in -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac done # for ac_tag as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # 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 || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi publib-0.40/README0000664000175000017500000001210511767671347011712 0ustar ajkajk P U B L I B Publib is a heterogenous library for the C programming language, originally intended as an extension of the standard library but now mostly of legacy interest. The library was written by Lars Wirzenius. As of October 2006, it is maintained by Antti-Juhani Kaijanaho. Publib is currently in maintenance mode: there are no plans to introduce new functionality at this time. Please check whether your operating system vendor provides a prepackaged version of Publib. Normally you should use that version instead of installing from source, unless you have special needs. For installing from source, the following should be enough to install on a typical Linux or Unix system: ./configure make make install The first two commands do not need any special privileges. The third requires write access to several directories in /usr/local/. The INSTALL file gives information about options you can give to configure for customizing such an installation. The following applies only to installations from source: Please retain the configured source of the version you installed. That will allow you to uninstall the package using "make uninstall"; it is a good idea to do that before installing a new version. For library documentation, see the publib.3 and other manual pages distributed with the library (in the man/ subdirectoryof the source distribution). Developers using the library and redistributors of the library are encouraged to subscribe to the publib mailing list; send mail to publib-subscribe@lists.kaijanaho.info to subscibe. The list is archived publically (updated once day) at http://lists.kaijanaho.info/archives/publib/threads.html . This list will receive release announcements, and it is the preferred forum for bug reports. Development sources are hosted in Git. There's a source browser at http://code.google.com/p/publib/source/browse/ and a local clone can be obtained via git clone https://code.google.com/p/publib/ Bugs may be reported to the mailing list, or (preferably) to the issue tracker at http://code.google.com/p/publib/issues/list. New releases (since 1.40) are distributed from http://code.google.com/p/publib/downloads/list and are announced on the mailing list. Happy hacking, Antti-Juhani Kaijanaho (antti-juhani@kaijanaho.fi) Sienitie 2 B 27 40640 JYVÄSKYLÄ FINLAND -----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<----- Ancient History (by Lars Wirzenius long, long time ago) The Publib effort started from an article posted to gnu.misc.discuss, comp.sources.d, and comp.software-eng at the end of February, 1992, by Steve Nuchia. He then created the mailing list which has been used for communication, library@sccsi.com. Several people were active in the discussion at the beginning. Lars Wirzenius built a few prototypes for the framework, based on the discussions on the list. Paul Sander and Greg Woods especially gave valuable comments on them. Patrik Andersin noted the problem with running configure twice with different module directories and the headers not being copied correctly. The first version released outside of the list was 0.2, posted on February 19 to alt.sources by Lars Wirzenius. The list has been rather dead since the end of 1993. The second version was 0.3, posted to alt.sources and put on the ftp sites on July 16, 1994. The third version was 0.4, not posted to alt.sources, only put on the ftp sites on October 10, 1994. The fourth version was 0.5, not posted to alt.sources or comp.sources.unix, only put on the ftp sites in May, 1995. -----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<----- This file as well as the rest of Publib is distributed under the simplified (two-clause) BSD license: Copyright © 2012 Antti-Juhani Kaijanaho. Copyright © 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. publib-0.40/sbuf/0000775000175000017500000000000011767707451011766 5ustar ajkajkpublib-0.40/sbuf/test-colmark.c0000664000175000017500000000526011767433142014533 0ustar ajkajk/* Part of publib. Copyright (c) 2012 Antti-Juhani Kaijanaho. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * test-sbuf.c -- test various parts of the sbuf routines * * At the moment, only one test is done: if we have the following text: * * "abcdefghi" * * and two marks ("def" and the other variable), and change the text of * one mark, is the other updated correctly? */ #include static Sbuf *buf; static Sbufmark *mark1, *mark2; static void setup(void) { if (buf != NULL) { sbuf_unmark(mark1); sbuf_unmark(mark2); sbuf_destroy(buf); } buf = sbuf_create(); mark1 = sbuf_mark(buf, 0, 0); mark2 = sbuf_mark(buf, 0, 0); sbuf_strchange(mark1, "abcd\377fghi(x[123]y)abcdefghi", 27); sbuf_remark(mark1, 3, 3); } static void dump(void) { sbuf_dump("buf", buf); sbuf_mark_dump("mark1", mark1); sbuf_mark_dump("mark2", mark2); } int main(void) { __set_liberror(__complain_on_error | __exit_on_error); { char foo[1000]; int ret; setup(); sbuf_remark(mark1, 0, sbuf_length(buf)); (void) sbuf_strchange(mark1, "abcdef\nghijkl\nmnopqr\nstuvwx\n", 28); /* 0123456 789abcd */ sbuf_remark(mark1, 1, 11); sbuf_mark_set_columnar(mark1, 1); (void)sbuf_mark_length(mark1); sbuf_strat(foo, mark1); sbuf_remark(mark2, 14, 0); sbuf_mark_set_columnar(mark2, 1); dump(); ret = sbuf_change(mark2, mark1); printf("ret == %d\n", ret); dump(); } sbuf_destroy(buf); return 0; } publib-0.40/sbuf/sbuf_srch.c0000664000175000017500000001307611767417657014125 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * sbuf_srch.c -- implement searching routines for text editor buffer * * Part of Publib. See manpage for more information. * "@(#)publib-sbuf:$Id: sbuf_srch.c,v 1.5 2002/05/23 12:01:58 liw Exp $" */ #include #include #include #include #include "publib/sbuf.h" typedef long func(Sbuf *, long, const char *, size_t); static func is_match; static func is_match_nocase; static int srch_forward(Sbufmark *, Sbufmark *, const char *, size_t, func *); static int srch_backward(Sbufmark *, Sbufmark *, const char *, size_t, func *); static int srch_forward_regex(Sbufmark *, Sbufmark *, const char *, size_t, unsigned long); static int srch_backward_regex(Sbufmark *, Sbufmark *, const char *, size_t, unsigned long); int sbuf_search(Sbufmark *m, Sbufmark *inside, const char *str, size_t len, unsigned long opts) { if (opts & SBUF_REGEX) { if (opts & SBUF_BACKWARD) return srch_backward_regex(m, inside, str, len, opts); return srch_forward_regex(m, inside, str, len, opts); } switch (opts) { case SBUF_BACKWARD | SBUF_IGNORE_CASE: return srch_backward(m, inside, str, len, is_match_nocase); case SBUF_BACKWARD: return srch_backward(m, inside, str, len, is_match); case SBUF_IGNORE_CASE: return srch_forward(m, inside, str, len, is_match_nocase); case 0: return srch_forward(m, inside, str, len, is_match); } return -1; /* if options are invalid... */ } static int srch_forward(Sbufmark *m, Sbufmark *inside, const char *str, size_t len, func *match) { Sbuf *buf; long begin, end, pos, match_len; buf = inside->buf; begin = sbuf_mark_begin(inside); end = sbuf_mark_end(inside); for (pos = begin; pos + len <= end; ++pos) { match_len = match(buf, pos, str, len); if (match_len >= 0) { sbuf_remark(m, pos, match_len); return 0; } } return -1; } static int srch_backward(Sbufmark *m, Sbufmark *inside, const char *str, size_t len, func *match) { Sbuf *buf; long begin, end, pos, match_len; buf = inside->buf; begin = sbuf_mark_begin(inside); end = sbuf_mark_end(inside); for (pos = end - len; pos >= begin; --pos) { match_len = match(buf, pos, str, len); if (match_len >= 0) { sbuf_remark(m, pos, match_len); return 0; } } return -1; } static int srch_forward_regex(Sbufmark *m, Sbufmark *inside, const char *str, size_t len, unsigned long opts) { Sbuf *buf; regex_t preg; regmatch_t pmatch[1]; char *text; long ret, begin, end; int n; int mask; buf = inside->buf; text = sbuf_lock(buf); if (text == NULL) return -1; begin = sbuf_mark_begin(inside); end = sbuf_mark_end(inside); mask = REG_EXTENDED | REG_NEWLINE; if (opts & SBUF_IGNORE_CASE) mask |= REG_ICASE; /* fixme: str need not be zero delimited */ ret = -1; if (regcomp(&preg, str, mask) == 0) { n = regexec(&preg, text + begin, 1, pmatch, 0); if (n == 0 && pmatch[0].rm_so != -1 && pmatch[0].rm_eo + begin <= end) { ret = 0; sbuf_remark(m, begin + pmatch[0].rm_so, pmatch[0].rm_eo - pmatch[0].rm_so); } regfree(&preg); } sbuf_unlock(buf); return ret; } static int srch_backward_regex(Sbufmark *m, Sbufmark *inside, const char *str, size_t len, unsigned long opts) { long ibegin, iend; long mbegin, mlen; if (srch_forward_regex(m, inside, str, len, opts) == -1) return -1; ibegin = sbuf_mark_begin(inside); iend = sbuf_mark_end(inside); do { mbegin = sbuf_mark_begin(m); mlen = sbuf_mark_length(m); if (mbegin+1 >= iend) break; sbuf_remark(inside, mbegin+1, iend - (mbegin+1)); } while (srch_forward_regex(m, inside, str, len, opts) == 0); sbuf_remark(inside, ibegin, iend - ibegin); sbuf_remark(m, mbegin, mlen); return 0; } static long is_match(Sbuf *buf, long pos, const char *str, size_t len) { long buflen, match_len; buflen = sbuf_length(buf); match_len = len; while (len > 0 && pos < buflen && *str == sbuf_charat(buf, pos)) { ++pos; ++str; --len; } if (len == 0) return match_len; return -1; } static long is_match_nocase(Sbuf *buf, long pos, const char *str, size_t len) { long buflen, match_len; int c; buflen = sbuf_length(buf); match_len = len; while (len > 0 && pos < buflen) { c = sbuf_charat(buf, pos); if (toupper(*str) != toupper(c)) break; ++pos; ++str; --len; } if (len == 0) return match_len; return -1; } publib-0.40/sbuf/sbuf_io.c0000664000175000017500000001655011767417657013575 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * sbuf_io.c -- reading and writing buffers and marks * * Part of Publib. See manpage for more information. * "@(#)publib-sbuf:$Id: sbuf_io.c,v 1.7 1997/04/30 22:41:15 liw Exp $" */ #include #include #include #include #include #include #include #include #include #include "publib/sbuf.h" #include "publib/errormsg.h" #define IO_BUFFER_SIZE 8*1024 #define MAX_TRIES 1024 static int create_save_temp_file(const char *, char *, int *); static int copy_modes(const char *, const char *); static int make_backup_name(char *, char *, size_t); int sbuf_load(Sbuf *buf) { FILE *f; int ret; sbuf_set_flags(buf, SBUF_LOADED_FLAG); ret = 0; if (buf->name == NULL) goto ok; sbuf_remark(buf->aux, 0, sbuf_length(buf)); if (sbuf_strchange(buf->aux, "", 0) == -1) { __publib_error("error clearing old contents of file"); return -1; } f = fopen(buf->name, "r"); if (f == NULL) { if (errno == ENOENT) goto ok; __publib_error("error loading file (no permission?)"); return -1; } ret = sbuf_insert_file(buf->aux, f); if (fclose(f) == EOF) { __publib_error("error closing file while loading buffer"); ret = -1; } ok: sbuf_clear_flags(buf, SBUF_DIRTY_FLAG); return ret; } int sbuf_save(Sbuf *buf, int keep_backup) { FILE *f; int e, fd, ret; char temp_name[FILENAME_MAX]; char back_name[sizeof(temp_name) + 4]; if (buf->name == NULL) { __publib_error("file has no name (can't save)"); return -1; } if (strlen(buf->name) + 64 > sizeof(temp_name)) { __publib_error("filename is too long (can't save)"); return -1; } if (make_backup_name(back_name, buf->name, sizeof(back_name)) == -1) { __publib_error("backup name too long"); return -1; } if (create_save_temp_file(buf->name, temp_name, &fd) == -1) return -1; f = fdopen(fd, "w"); if (f == NULL) { __publib_error("error opening file"); return -1; } sbuf_remark(buf->aux, 0, sbuf_length(buf)); ret = sbuf_write_to_file(buf->aux, f); e = errno; if (fclose(f) == EOF) { if (ret == 0) { e = errno; __publib_error("error closing file"); } ret = -1; } if (rename(buf->name, back_name) == -1 && errno != ENOENT) { __publib_error("rename of original failed (can't save)"); return -1; } if (rename(temp_name, buf->name) == -1) { __publib_error("rename of new failed (can't save)"); return -1; } if (copy_modes(back_name, buf->name) == -1) return -1; if (!keep_backup) { if (remove(back_name) == -1 && errno != ENOENT) { __publib_error("remove of backup failed (can't save)"); return -1; } } if (ret == 0) sbuf_set_dirty(buf, 0); else errno = e; return ret; } int sbuf_insert_file(Sbufmark *mark, FILE *f) { char iobuf[IO_BUFFER_SIZE]; size_t n; long begin; begin = sbuf_mark_begin(mark); while ((n = fread(iobuf, 1, IO_BUFFER_SIZE, f)) > 0 && !ferror(f)) { sbuf_remark(mark, sbuf_mark_end(mark), 0); if (sbuf_strchange(mark, iobuf, n) == -1) goto error; } if (!ferror(f)) return 0; /*FALLTHROUGH*/ __publib_error("error reading file"); error: sbuf_remark(mark, begin, sbuf_mark_end(mark) - begin); (void) sbuf_strchange(mark, "", 0); return -1; } int sbuf_write_to(Sbufmark *mark, const char *filename) { FILE *f; int ret, e; f = fopen(filename, "w"); if (f == NULL) { __publib_error("couldn't open file for writing"); return -1; } e = 0; ret = sbuf_write_to_file(mark, f); if (ret == -1) { e = errno; ret = -1; } if (fclose(f) == EOF) { if (e == 0) e = errno; ret = -1; } errno = e; return ret; } int sbuf_write_to_file(Sbufmark *m, FILE *f) { char iobuf[IO_BUFFER_SIZE]; char *p; long i, n, nn, pos; Sbuf *buf; n = sbuf_mark_length(m); pos = sbuf_mark_begin(m); buf = m->buf; while (n > 0) { nn = (n < IO_BUFFER_SIZE) ? n : IO_BUFFER_SIZE; n -= nn; for (i = 0, p = iobuf; i < nn; ++i, ++p, ++pos) *p = sbuf_charat(buf, pos); if (fwrite(iobuf, nn, 1, f) != 1) { __publib_error("error writing to file"); return -1; } } return 0; } /********************************************************************** * Local functions. */ /* * Function: create_save_temp_file * Purpose: Create a new file in same directory as the file to be saved. * Arguments: original the name of the original file * buf where the new file's name is stored * fd where file descriptor of new file is stored * Return: -1 for failure, 0 for success. * Note: buf should be big enough; strlen(original) + 64 should * be enough (unless you have _really_ big unsigned longs). */ static int create_save_temp_file(const char *original, char *buf, int *fd) { char *p; unsigned long i; time_t random; strcpy(buf, original); p = strrchr(buf, '/'); if (p != NULL) p[1] = '\0'; else buf[0] = '\0'; time(&random); *fd = -1; p = strchr(buf, '\0'); for (i = 0; i < MAX_TRIES && *fd == -1; ++i) { sprintf(p, "#%lu-%lu#", (unsigned long) random, i); *fd = open(buf, O_WRONLY | O_CREAT | O_EXCL, 0600); if (*fd == -1 && errno != EEXIST) { __publib_error("can't create temporary file"); return -1; } } if (*fd == -1) return -1; return 0; } /* * Function: copy_modes * Purpose: Copy the permissions from one file to another, or invent * them if the file is new (use umask). * Arguments: src original file * tgt target file * Return: -1 for error, 0 for OK. */ static int copy_modes(const char *src, const char *tgt) { struct stat st; mode_t mode; if (stat(src, &st) == -1) { if (errno != ENOENT) { __publib_error("Can't stat file (can't complete save)"); return -1; } mode = umask(0); (void) umask(mode); mode = 0666 & ~mode; } else mode = st.st_mode; if (chmod(tgt, mode) == -1) { __publib_error("Can't chmod file (can't complete save)"); return -1; } return 0; } /* * Function: make_backup_name * Purpose: Create name of backup file from original file. * Note: The target buffer must be big enough. */ static int make_backup_name(char *back, char *orig, size_t max) { if (strlen(orig) + 2 > max) return -1; sprintf(back, "%s~", orig); return 0; } publib-0.40/sbuf/test-sbuf-undo.c0000664000175000017500000000460111767417657015020 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * test-sbuf-undo.c -- test undo parts of the sbuf routines */ #include static Sbuf *buf; static Sbufmark *mark1, *mark2; static void setup(void) { if (buf != NULL) { sbuf_unmark(mark1); sbuf_unmark(mark2); sbuf_destroy(buf); } buf = sbuf_create(); mark1 = sbuf_mark(buf, 0, 0); mark2 = sbuf_mark(buf, 0, 0); } static void dump(void) { char tmp[1024]; printf("buf = `%s'\n", sbuf_lock(buf)); sbuf_unlock(buf); sbuf_strat(tmp, mark1); printf("mark1 = %ld-%ld, len=%ld, text=`%s'\n", sbuf_mark_begin(mark1), sbuf_mark_end(mark1), sbuf_mark_length(mark1), tmp); sbuf_strat(tmp, mark2); printf("mark2 = %ld-%ld, len=%ld, text=`%s'\n", sbuf_mark_begin(mark2), sbuf_mark_end(mark2), sbuf_mark_length(mark2), tmp); printf("\n"); } int main(void) { __set_liberror(__complain_on_error | __exit_on_error); setup(); printf("initial:\n"); dump(); printf("change=%d\n", sbuf_strchange(mark1, "abc", 3)); dump(); printf("undo=%d\n", sbuf_undo_atomic(buf)); dump(); sbuf_destroy(buf); printf("test-sbuf done\n"); return 0; } publib-0.40/sbuf/test-sbuf.c0000664000175000017500000001213111767417657014052 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * test-sbuf.c -- test various parts of the sbuf routines * * At the moment, only one test is done: if we have the following text: * * "abcdefghi" * * and two marks ("def" and the other variable), and change the text of * one mark, is the other updated correctly? */ #include #include static Sbuf *buf; static Sbufmark *mark1, *mark2; static void setup(void) { if (buf != NULL) { sbuf_unmark(mark1); sbuf_unmark(mark2); sbuf_destroy(buf); } buf = sbuf_create(); mark1 = sbuf_mark(buf, 0, 0); mark2 = sbuf_mark(buf, 0, 0); sbuf_strchange(mark1, "abcd\377fghi(x[123]y)abcdefghi", 27); sbuf_remark(mark1, 3, 3); } static void dump(void) { char tmp[1024]; printf("buf = `%s'\n", sbuf_lock(buf)); sbuf_unlock(buf); sbuf_strat(tmp, mark1); printf("mark1 = %ld-%ld, len=%ld, text=`%s'\n", sbuf_mark_begin(mark1), sbuf_mark_end(mark1), sbuf_mark_length(mark1), tmp); sbuf_strat(tmp, mark2); printf("mark2 = %ld-%ld, len=%ld, text=`%s'\n", sbuf_mark_begin(mark2), sbuf_mark_end(mark2), sbuf_mark_length(mark2), tmp); printf("\n"); } static void delete(long from, long n, long newfrom, long newn) { printf("deleting %ld-%ld (-> mark1 should be: %ld-%ld)\n", from, from+n, newfrom, newfrom + newn); setup(); sbuf_remark(mark2, from, n); sbuf_strchange(mark2, "", 0); dump(); } static void insert(long at, const char *what, long newfrom, long newn) { printf("insert `%s' at %ld (-> mark1 should be: %ld-%ld)\n", what, at, newfrom, newfrom + newn); setup(); sbuf_remark(mark2, at, 0); sbuf_strchange(mark2, what, strlen(what)); dump(); } static void search(long pos, const char *str, unsigned long opts) { int ret; setup(); sbuf_remark(mark1, pos, sbuf_length(buf) - pos); ret = sbuf_search(mark2, mark1, str, strlen(str), opts); printf("search '%s' at %ld: ret=%d range=(%ld,%ld)\n", str, pos, ret, sbuf_mark_begin(mark2), sbuf_mark_length(mark2)); } static void find_pair(long pos) { setup(); printf("find_pair at %ld: ret=%ld\n", pos, sbuf_find_pair(buf, pos)); } int main(void) { int i; printf("test-sbuf starting...\n"); __set_liberror(__complain_on_error | __exit_on_error); setup(); printf("character 4 (macro): %d\n", sbuf_charat(buf, 4)); printf("character 4 (funcn): %d\n", (sbuf_charat)(buf, 4)); delete(0, 2, 1, 3); /* delete "ab" */ delete(0, 3, 0, 3); /* delete "abc" */ delete(0, 4, 0, 2); /* delete "abcd" */ delete(3, 2, 3, 1); /* delete "de" */ delete(3, 3, 3, 0); /* delete "def" */ delete(3, 4, 3, 0); /* delete "defg" */ delete(5, 2, 3, 2); /* delete "fg" */ delete(6, 3, 3, 3); /* delete "ghi" */ delete(7, 2, 3, 3); /* delete "hi" */ for (i = 0; i < 3; ++i) insert(i, ".", 4, 3); for (i = 3; i < 6; ++i) insert(i, ".", 3, 4); for (i = 6; i < 10; ++i)insert(i, ".", 3, 3); search(0, "abc", 0); search(0, "def", 0); search(1, "...", 0); search(0, "abc", SBUF_BACKWARD); search(0, "def", SBUF_BACKWARD); search(1, "...", SBUF_BACKWARD); search(0, "ABC", SBUF_IGNORE_CASE); search(0, "DEF", SBUF_IGNORE_CASE); search(1, "...", SBUF_IGNORE_CASE); search(0, "ABC", SBUF_IGNORE_CASE | SBUF_BACKWARD); search(0, "DEF", SBUF_IGNORE_CASE | SBUF_BACKWARD); search(1, "...", SBUF_IGNORE_CASE | SBUF_BACKWARD); find_pair(0); find_pair(9); find_pair(11); find_pair(15); find_pair(17); { char foo[1000]; int ret; setup(); sbuf_remark(mark1, 0, 10); (void) sbuf_strchange(mark1, "abcdef\nqwerty\n", 14); /* 0123456 789abcd */ sbuf_remark(mark1, 1, 11); sbuf_mark_set_columnar(mark1, 1); sbuf_strat(foo, mark1); printf("foo=<%s>\n", foo); ret = sbuf_strchange(mark1, "", 0); printf("ret == %d\n", ret); dump(); } printf("undo:\n"); setup(); dump(); printf("ret=%d\n", sbuf_undo_atomic(buf)); dump(); sbuf_destroy(buf); printf("test-sbuf done\n"); return 0; } publib-0.40/sbuf/sbuf_aux.c0000664000175000017500000003013111767432471013741 0ustar ajkajk/* Part of publib. Copyright (c) 2012 Antti-Juhani Kaijanaho. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * sbuf_aux.c -- auxiliary routines for text editors * * Part of Publib. See manpage for more information. * "@(#)publib-sbuf:$Id: sbuf_aux.c,v 1.14 1996/12/18 15:52:26 liw Exp $" */ #include #include #include #include #include #include #include "publib/sbuf.h" #include "publib/errormsg.h" /* * This macro is used by sbuf_bow and sbuf_eow to determine if a * character is a `letter', i.e., if it can belong to a word. */ #define letter(c) ((c) == '_' || isalnum(c)) /* * Local function prototypes. */ static void put_into_cache(Sbuf *, long, long); static int find_nearest(Sbuf *, long); static long compute_lineno(Sbuf *, long, long, long); static long find_pair(const unsigned char *, long, long); #ifdef NDEBUG #define check_pos_cache(x) ((void) 0) #else static void check_pos_cache(Sbuf *); #endif /* * Return position before first character on line containing pos. */ long sbuf_boln(Sbuf *buf, long pos) { while (pos > 0 && sbuf_charat(buf, pos-1) != '\n') --pos; return pos; } /* * Return position after last character (including newline) on line * containing pos. */ long sbuf_eoln(Sbuf *buf, long pos) { int c; while ((c = sbuf_charat(buf, pos)) != '\n' && c != EOF) ++pos; if (c == EOF) return pos; return pos+1; } /* * Return position before first character of the word that contains * pos. If pos is not within a word, return pos. */ long sbuf_bow(Sbuf *buf, long pos) { int c; c = sbuf_charat(buf, pos); if (!letter(c)) return pos; while (pos > 0 && (c = sbuf_charat(buf, pos-1), letter(c))) --pos; return pos; } /* * Return position after last character of the word that contains * pos. If pos is not within a word, return pos+1 (or pos, if at * EOF). */ long sbuf_eow(Sbuf *buf, long pos) { int c; c = sbuf_charat(buf, pos); if (!letter(c)) { if (c != EOF) ++pos; return pos; } while (letter(c)) { ++pos; c = sbuf_charat(buf, pos); } return pos; } /* * Return line number of character after position pos. The first line is line 0. */ long sbuf_lineno(Sbuf *buf, long pos) { int i; long lineno; struct __sbuf_pos_cache *cache; check_pos_cache(buf); cache = buf->pc.data; i = find_nearest(buf, pos); if (i == -1) lineno = compute_lineno(buf, pos, 0, 0); else lineno = compute_lineno(buf, pos, cache[i].pos, cache[i].lineno); if (i == -1 || cache[i].pos != pos) put_into_cache(buf, pos, lineno); check_pos_cache(buf); return lineno; } /* * Return position before first character of line number lineno * (first line is 0). FIXME: this should use the poscache to * find the closest position. */ long sbuf_linepos(Sbuf *buf, long lineno) { long gaplen; char *p, *q; p = buf->block; q = buf->block + buf->gappos; while (p < q && lineno > 0) { if (*p == '\n') --lineno; ++p; } if (lineno == 0) return p - buf->block; gaplen = buf->alloc - buf->len; p = buf->block + buf->gappos + gaplen; q = buf->block + buf->len + gaplen; while (p < q && lineno > 0) { if (*p == '\n') --lineno; ++p; } return p - buf->block - gaplen; } /* * Function: sbuf_colno * Purpose: Return column number of a text position. * Arguments: buf the buffer * pos the position * tab tab distance * Return: The column number. * Note: The first column is number 0. */ long sbuf_colno(Sbuf *buf, long pos, long tab) { long p, col; p = sbuf_boln(buf, pos); col = 0; while (p < pos) { if (sbuf_charat(buf, p) == '\t') col += tab - (col % tab); else ++col; ++p; } return col; } /* * Function: sbuf_colpos * Purpose: Return the position of the character in a given column. * Arguments: buf the buffer * pos the beginning of the line * col the column * tab tab distance * Return: The text position of the character that occupies the given * column. * Note: A tab occupies several character positions. If the line * is too short, the position of the newline or EOF that * ends the line is returned. */ long sbuf_colpos(Sbuf *buf, long pos, long col, long tab) { long i; i = 0; while (i < col) { switch (sbuf_charat(buf, pos)) { case '\n': case EOF: return pos; case '\t': i += tab - (i % tab); if (i > col) return pos; break; default: ++i; break; } ++pos; } return pos; } /* * Function: sbuf_clear_pos_cache * Purpose: Clear the poscache starting at position pos. */ void sbuf_clear_pos_cache(Sbuf *buf, long pos) { struct __sbuf_pos_cache *cache; check_pos_cache(buf); cache = buf->pc.data; while (buf->pc.used > 0 && cache[buf->pc.used-1].pos >= pos) --buf->pc.used; check_pos_cache(buf); } /* * Function: sbuf_adjust_pos_cache * Purpose: Adjust the poscache. * Description: The buffer has been modified by replacing pos..pos+oldlen-1 * with new text that is newlen chars long. The range now * has n more (n > 0) or fewer (n < 0) newlines. The cache * is adjusted so that each (p,lineno) pair is deleted or * updated as necessary to bring it up to date to the current * situation: pairs in the old range are deleted and those after * it are moved and the line number adjusted. */ void sbuf_adjust_pos_cache(Sbuf *buf, long pos, long oldlen, long newlen, long n) { int i, j; struct __sbuf_pos_cache *cache; check_pos_cache(buf); cache = buf->pc.data; /* fixme: bsearch should be used */ for (i = 0; i < buf->pc.used && cache[i].pos < pos; ++i) continue; j = i; for (; i < buf->pc.used && cache[i].pos < pos + oldlen; ++i) continue; memmove(cache + j, cache + i, (buf->pc.used - i) * sizeof(cache[0])); buf->pc.used -= i - j; for (; j < buf->pc.used; ++j) { cache[j].pos += newlen - oldlen; cache[j].lineno += n; } check_pos_cache(buf); } /* * Function: sbuf_find_pair * Purpose: Find pair to character at a given position. */ long sbuf_find_pair(Sbuf *buf, long pos) { unsigned char *str; str = (unsigned char *) sbuf_lock(buf); if (str == NULL) return -1; pos = find_pair(str, sbuf_length(buf), pos); sbuf_unlock(buf); return pos; } /* * Write position cache statistics to file. */ void sbuf_cache_stats(Sbuf *buf, FILE *f) { fprintf(f, "Sbuf position cache statistics (%p):\n", (void *) buf); fprintf(f, " hits: %6ld\n", buf->poshits); fprintf(f, " misses: %6ld\n", buf->posmisses); fprintf(f, " avg miss: %8.1f\n", buf->posmissavg); } /* * Is a position inside a mark? */ int sbuf_pos_inside_mark(Sbufmark *mark, long pos) { long begin, end, tabsize, poscol; begin = sbuf_mark_begin(mark); if (pos < begin) return 0; end = sbuf_mark_end(mark); if (pos >= end) return 0; if (!sbuf_mark_is_columnar(mark)) return 1; tabsize = 8; poscol = sbuf_colno(mark->buf, pos, tabsize); if (poscol < sbuf_colno(mark->buf, begin, tabsize)) return 0; return poscol < sbuf_colno(mark->buf, end, tabsize); } /************************************************************************** * Local functions follow. */ static int find_nearest(Sbuf *buf, long pos) { struct __sbuf_pos_cache *cache; int i; check_pos_cache(buf); cache = buf->pc.data; if (buf->pc.used == 0) return -1; if (buf->pc.used == 1 || pos <= cache[0].pos) return 0; if (pos >= cache[buf->pc.used-1].pos) return buf->pc.used-1; for (i = 0; pos > cache[i+1].pos; ++i) continue; check_pos_cache(buf); if (i == buf->pc.used-1) return i; else if (pos - cache[i].pos < cache[i+1].pos - pos) return i; else return i+1; } static long compute_lineno(Sbuf *buf, long pos, long known_pos, long lineno) { long orig_pos; orig_pos = known_pos; while (known_pos < pos) { if (sbuf_charat(buf, known_pos) == '\n') ++lineno; ++known_pos; } while (known_pos > pos) { --known_pos; if (sbuf_charat(buf, known_pos) == '\n') --lineno; } if (known_pos == orig_pos) ++buf->poshits; else { buf->posmissavg = (buf->posmisses * buf->posmissavg + labs(known_pos - orig_pos)) / (buf->posmisses + 1); ++buf->posmisses; } return lineno; } static void put_into_cache(Sbuf *buf, long pos, long lineno) { struct __sbuf_pos_cache *cache; long dist, mindist; int i, min; check_pos_cache(buf); if (buf->pc.used < SBUF_POS_CACHE_MAX && buf->pc.used == buf->pc.alloc) (void) dynarr_resize(&buf->pc, buf->pc.used + 1); cache = buf->pc.data; assert(buf->pc.alloc >= SBUF_POS_CACHE_MIN); if (buf->pc.used >= buf->pc.alloc - 1) { min = 2; mindist = cache[min].pos - cache[min-2].pos; for (i = 3; i < buf->pc.used; ++i) { dist = cache[i].pos - cache[i-2].pos; if (dist < mindist) { min = i; mindist = dist; } } for (i = min; i < buf->pc.used; ++i) cache[i-1] = cache[i]; --buf->pc.used; } for (i = buf->pc.used; i > 0; --i) { if (pos > cache[i-1].pos) break; cache[i] = cache[i-1]; } cache[i].pos = pos; cache[i].lineno = lineno; ++buf->pc.used; check_pos_cache(buf); } /* * Function: find_pair * Purpose: Given a buffer, find the pair of a character * Arguments: str the string of the buffer * len length of buffer * pos the position of the character * Return: -1 for no pair found, or position in buffer of pair. */ static long find_pair(const unsigned char *str, long len, long pos) { static unsigned char pairstr[] = "(){}[]"; static int pair[UCHAR_MAX + 1]; static int dir[UCHAR_MAX + 1]; static int init = 0; int c; if (pos < 0 || pos >= len) return -1; if (!init) { for (c = 0; c < UCHAR_MAX + 1; ++c) { pair[c] = EOF; dir[c] = 0; } assert(strlen((char*)pairstr) % 2 == 0); for (c = 0; pairstr[c] != '\0'; c += 2) { pair[pairstr[c]] = pairstr[c+1]; pair[pairstr[c+1]] =pairstr[c]; dir[pairstr[c]] = 1; dir[pairstr[c+1]] = -1; } init = 1; } c = str[pos]; if (pair[c] == EOF) return -1; for (;;) { assert(dir[c] != 0); do { pos += dir[c]; if (pos < 0 || pos >= len) return -1; } while (pair[str[pos]] == EOF); if (pair[str[pos]] == c) return pos; if (dir[str[pos]] != dir[c]) return -1; pos = find_pair(str, len, pos); if (pos < 0 || pos >= len) return -1; } } /* * Function: check_pos_cache * Purpose: Check that the pos cache is OK. */ #ifndef NDEBUG static void check_pos_cache(Sbuf *buf) { int i; struct __sbuf_pos_cache *cache; assert(buf->pc.alloc >= SBUF_POS_CACHE_MIN); assert(buf->pc.alloc <= SBUF_POS_CACHE_MAX); if (buf->pc.used == 0) return; cache = buf->pc.data; assert(buf->pc.used > 0); assert(cache[0].pos >= 0); assert(cache[0].lineno >= 0); for (i = 1; i < buf->pc.used; ++i) { assert(cache[i].pos >= 0); assert(cache[i].lineno >= 0); assert(cache[i].pos > cache[i-1].pos); assert(cache[i].lineno >= cache[i-1].lineno); } } #endif publib-0.40/sbuf/sbuf.c0000664000175000017500000005204411767433223013067 0ustar ajkajk/* Part of publib. Copyright (c) 2012 Antti-Juhani Kaijanaho. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * sbuf.c -- simple text editor buffer routines * * Part of Publib. See manpage for more information. */ #include #include #include #include #include #include "publib/sbuf.h" #include "publib/errormsg.h" #ifdef SBUF_LOG #include #else #define getpid() 0 #endif /* Return length of gap */ #define gaplen(buf) (buf->alloc - buf->len) /* * Prototypes for local functions. */ static int replace_mark_part(Sbuf *, long, long, const char *, long, long); static void adjust_marks(Sbuf *, long, long, long); static int remove_columnar_mark(Sbufmark *); static long count_chars(const char *, int, long); static int insert_columnar_text(Sbuf *, Sbufmark *, const char *, long, long); static int strchange(Sbuf *, long, long, const char *, long); static void __sbuf_log(const char *, ...); /* Create a buffer. */ Sbuf *sbuf_create(void) { Sbuf *buf; buf = malloc(sizeof(Sbuf)); if (buf == NULL) { __publib_error("malloc failed"); return NULL; } buf->block = NULL; buf->name = NULL; buf->flags = 0; buf->gappos = 0; buf->alloc = 0; buf->len = 0; buf->marks = NULL; buf->markalloc = 0; dynarr_init(&buf->pc, sizeof(struct __sbuf_pos_cache)); if (dynarr_resize(&buf->pc, SBUF_POS_CACHE_MIN) == -1) { dynarr_free(&buf->pc); free(buf); return NULL; } buf->poshits = 0; buf->posmisses = 0; buf->posmissavg = 0; buf->log_head = NULL; buf->log_tail = NULL; sbuf_validate(buf); buf->aux = sbuf_mark(buf, 0, 0); if (buf == NULL) { sbuf_destroy(buf); return NULL; } return buf; } /* Destroy a buffer */ void sbuf_destroy(Sbuf *buf) { sbuf_validate(buf); free(buf->block); free(buf->marks); free(buf); } /* Check that all the data structures for the buffer are OK. Abort program if they aren't. */ void (sbuf_validate)(Sbuf *buf) { struct __sbufmark *m; size_t i; assert(buf != NULL); assert(buf->len <= buf->alloc); assert(buf->block != NULL || buf->alloc == 0); assert(buf->gappos <= buf->alloc); assert(buf->len <= buf->alloc); assert(buf->marks != NULL || buf->markalloc == 0); for (i = 0; i < buf->markalloc; ++i) { m = buf->marks + i; if (m->inuse) assert(m->begin + m->len <= buf->len); } } /* Move gap before the pos'th character in text, and make sure it is at least len characters. */ int sbuf_movegap(Sbuf *buf, size_t pos, size_t len) { char *p; sbuf_validate(buf); assert(pos <= buf->len); assert(!sbuf_has_flags(buf, SBUF_LOCKED_FLAG)); if (gaplen(buf) < len || buf->block == NULL) { if (buf->block != NULL && sbuf_movegap(buf, buf->len, 0) < 0) { __publib_error("recursive sbuf_failed (can't happen)"); return -1; } p = realloc(buf->block, buf->alloc + len + 4); if (p == NULL) { __publib_error("realloc failed"); return -1; } buf->block = p; buf->alloc += len; } assert(buf->block != NULL); if (pos < buf->gappos) memmove(buf->block + pos + gaplen(buf), buf->block + pos, buf->gappos - pos); else memmove(buf->block + buf->gappos, buf->block + buf->gappos + gaplen(buf), pos - buf->gappos); buf->gappos = pos; sbuf_validate(buf); return 0; } char *sbuf_get_name(Sbuf *buf) { return buf->name; } int sbuf_set_name(Sbuf *buf, const char *newname) { newname = strdup(newname); if (newname == NULL) return -1; free(buf->name); buf->name = (char *) newname; return 0; } unsigned long sbuf_get_flags(Sbuf *buf) { return buf->flags; } int sbuf_has_flags(Sbuf *buf, unsigned long mask) { return (buf->flags & mask) == mask; } void sbuf_set_all_flags(Sbuf *buf, unsigned long flags) { buf->flags = flags; } void sbuf_set_flags(Sbuf *buf, unsigned long mask) { buf->flags |= mask; } void sbuf_clear_flags(Sbuf *buf, unsigned long mask) { buf->flags &= ~mask; } /* * Function: sbuf_is_dirty * Purpose: Return dirty bit for buffer. */ int sbuf_is_dirty(Sbuf *buf) { return sbuf_has_flags(buf, SBUF_DIRTY_FLAG); } /* * Function: sbuf_set_dirty * Purpose: Set dirty bit for buffer. */ void sbuf_set_dirty(Sbuf *buf, int dirty) { if (dirty) sbuf_set_flags(buf, SBUF_DIRTY_FLAG); else sbuf_clear_flags(buf, SBUF_DIRTY_FLAG); } /* Lock buffer against changes and return pointer to a contiguous block of memory holding the buffer contents (which may be modified except its length may not be modified). */ char *sbuf_lock(Sbuf *buf) { sbuf_validate(buf); assert(!sbuf_has_flags(buf, SBUF_LOCKED_FLAG)); if (sbuf_movegap(buf, buf->len, 0) == -1) { __publib_error("sbuf_movegap failed"); return NULL; } sbuf_set_flags(buf, SBUF_LOCKED_FLAG); return buf->block; } /* Release a lock on a buffer. The user may not assume that the pointer returned by sbuf_lock is usable any longer. */ void sbuf_unlock(Sbuf *buf) { sbuf_validate(buf); assert(sbuf_has_flags(buf, SBUF_LOCKED_FLAG)); sbuf_clear_flags(buf, SBUF_LOCKED_FLAG); } /* Return length (== number of character in the buffer). */ long (sbuf_length)(Sbuf *buf) { sbuf_validate(buf); return buf->len; } /* Return the character at position pos. Return EOF if just after last character. */ int (sbuf_charat)(Sbuf *buf, long pos) { sbuf_validate(buf); assert(pos >= 0); assert(pos <= buf->len); if (pos == buf->len) return EOF; assert(buf->block != NULL); if (pos < buf->gappos) return (unsigned char) buf->block[pos]; return (unsigned char) buf->block[pos + gaplen(buf)]; } /* Create a mark. */ Sbufmark *sbuf_mark(Sbuf *buf, long pos, long len) { struct __sbufmark *p; Sbufmark *q; size_t i; sbuf_validate(buf); assert(pos >= 0); assert(len >= 0); assert(pos + len <= buf->len); p = NULL; for (i = 0; i < buf->markalloc; ++i) { if (!buf->marks[i].inuse) { p = buf->marks + i; break; } } if (p == NULL) { i = buf->markalloc + 8; p = realloc(buf->marks, i * sizeof(struct __sbufmark)); if (p == NULL) { __publib_error("realloc failed"); return NULL; } buf->marks = p; p = buf->marks + buf->markalloc; while (buf->markalloc < i) buf->marks[buf->markalloc++].inuse = 0; buf->markalloc = i; } q = malloc(sizeof(Sbufmark)); if (q == NULL) { __publib_error("malloc failed"); return NULL; } p->inuse = 1; p->begin = pos; p->len = len; p->dirty = 0; p->columnar = 0; p->code = 0; p->handle = q; q->buf = buf; q->mark = p - buf->marks; sbuf_validate(buf); sbuf_validate_mark(q); return q; } /* Destroy a mark. */ void sbuf_unmark(Sbufmark *mark) { sbuf_validate_mark(mark); mark->buf->marks[mark->mark].inuse = 0; } /* Check that a mark's data structures are ok. */ void (sbuf_validate_mark)(Sbufmark *mark) { assert(mark != NULL); sbuf_validate(mark->buf); assert(mark->mark < mark->buf->markalloc); assert(mark->buf->marks[mark->mark].inuse); } /* Move an existing mark. */ void sbuf_remark(Sbufmark *mark, long pos, long len) { sbuf_validate_mark(mark); assert(pos >= 0); assert(len >= 0); assert(pos + len <= mark->buf->len); mark->buf->marks[mark->mark].begin = pos; mark->buf->marks[mark->mark].len = len; mark->buf->marks[mark->mark].dirty = 0; } /* Return starting position of mark. */ long (sbuf_mark_begin)(Sbufmark *mark) { sbuf_validate_mark(mark); return mark->buf->marks[mark->mark].begin; } /* Return end position of mark. */ long (sbuf_mark_end)(Sbufmark *mark) { sbuf_validate_mark(mark); return mark->buf->marks[mark->mark].begin + mark->buf->marks[mark->mark].len; } /* Return length of mark. */ long (sbuf_mark_length)(Sbufmark *mark) { struct __sbufmark *m; long len, tabsize, startcol, endcol, col, pos; int c; sbuf_validate_mark(mark); m = mark->buf->marks + mark->mark; if (!m->columnar) return m->len; len = 0; tabsize = 8; startcol = sbuf_colno(mark->buf, m->begin, tabsize); endcol = sbuf_colno(mark->buf, m->begin + m->len, tabsize); col = startcol; c = EOF; for (pos = 0; pos < m->len; ++pos) { c = sbuf_charat(mark->buf, m->begin + pos); if (c == '\n') { ++len; col = 0; } else { if (col >= startcol && col < endcol) ++len; if (c == '\t') col += tabsize - (col % tabsize); else ++col; } } return len; } /* Return dirty bit. */ int (sbuf_mark_is_dirty)(Sbufmark *mark) { sbuf_validate_mark(mark); return mark->buf->marks[mark->mark].dirty; } /* Set dirty bit. */ void (sbuf_mark_set_dirty)(Sbufmark *mark, int dirty) { sbuf_validate_mark(mark); mark->buf->marks[mark->mark].dirty = dirty; } /* Return columnar mode. */ int (sbuf_mark_is_columnar)(Sbufmark *mark) { sbuf_validate_mark(mark); return mark->buf->marks[mark->mark].columnar; } /* Set columnar mode. */ void (sbuf_mark_set_columnar)(Sbufmark *mark, int mode) { sbuf_validate_mark(mark); mark->buf->marks[mark->mark].columnar = !!mode; } void sbuf_set_mark_code(Sbufmark *mark, int code) { mark->buf->marks[mark->mark].code = code; } int sbuf_get_mark_code(Sbufmark *mark) { return mark->buf->marks[mark->mark].code; } Sbufmark *sbuf_find_mark_by_code(Sbuf *buf, int code) { int i; struct __sbufmark *m; if (code == 0) return NULL; for (i = 0; i < buf->markalloc; ++i) { m = buf->marks + i; if (m->inuse && m->code == code) return m->handle; } return NULL; } /* Copy marked text to a string. */ void sbuf_strat(char *str, Sbufmark *mark) { struct __sbufmark *m; char *p; const int tabsize = 8; long startcol, endcol, col, pos; assert(str != NULL); sbuf_validate_mark(mark); m = mark->buf->marks + mark->mark; p = sbuf_lock(mark->buf); if (m->columnar) { startcol = sbuf_colno(mark->buf, m->begin, tabsize); endcol = sbuf_colno(mark->buf, m->begin + m->len, tabsize); col = startcol; for (pos = m->len, p += m->begin; pos > 0; --pos, ++p) { if (*p == '\n') { *str++ = *p; col = 0; } else { if (col >= startcol && col < endcol) *str++ = *p; if (*p == '\t') col += tabsize - (col % tabsize); else ++col; } } *str = '\0'; } else { if (m->len > 0) memcpy(str, p + m->begin, m->len); str[m->len] = '\0'; } sbuf_unlock(mark->buf); } /* Replace the contents of a mark with a string. */ int sbuf_strchange(Sbufmark *mark, const char *str, size_t len) { struct __sbufmark *m; sbuf_validate_mark(mark); assert(str != NULL); assert(!sbuf_has_flags(mark->buf, SBUF_LOCKED_FLAG)); m = mark->buf->marks + mark->mark; __sbuf_log("%d %p %ld %ld %ld\n", getpid(), (void *) mark->buf, m->begin, m->len, len, (long) len); if (m->columnar) { if (remove_columnar_mark(mark) == -1) return -1; if (insert_columnar_text(mark->buf, mark, str, len, 8) == -1) return -1; } else { if (strchange(mark->buf, m->begin, m->len, str, len) == -1) return -1; sbuf_validate_mark(mark); } return 0; } /* Replace contents of one mark with those of another mark. The marks may overlap. */ int sbuf_change(Sbufmark *mark, Sbufmark *repl) { char *temp, tempbuf[10240]; long len; int ret; sbuf_validate_mark(mark); sbuf_validate_mark(repl); len = sbuf_mark_length(repl); if (len < sizeof tempbuf) temp = tempbuf; else { temp = malloc(len+1); if (temp == NULL) { __publib_error("malloc failed"); return -1; } } sbuf_strat(temp, repl); ret = sbuf_strchange(mark, temp, len); if (temp != tempbuf) free(temp); return ret; } /* * Function: sbuf_undo_atomic * Purpose: Undo one entry from the change log. */ int sbuf_undo_atomic(Sbuf *buf) { struct __sbuf_change *p; if (buf->log_tail == NULL) return -1; p = buf->log_tail; if (strchange(buf, p->pos, p->newlen, p->oldtext, p->oldlen) == -1) return -1; return 0; } /* * Function: sbuf_dump * Purpose: Dump contents of buffer for debugging purposes. */ void sbuf_dump(const char *msg, Sbuf *buf) { long i, len; int c; if (msg != NULL && *msg != '\0') printf("%s: ", msg); printf("<<"); len = sbuf_length(buf); for (i = 0; i < len; ++i) { c = sbuf_charat(buf, i); switch (c) { case '\n': printf("\\n"); break; case '\t': printf("\\t"); break; case '\0': printf("\\0"); break; case '\\': printf("\\\\"); break; default: printf("%c", c); break; } } printf(">>\n"); } /* * Function: sbuf_mark_dump * Purpose: Dump contents of mark for debugging purposes. */ void sbuf_mark_dump(const char *msg, Sbufmark *mark) { char buf[1000]; long i, len; if (msg != NULL && *msg != '\0') printf("%s: ", msg); printf("%ld-%ld (%ld) col=%d", sbuf_mark_begin(mark), sbuf_mark_end(mark), sbuf_mark_length(mark), sbuf_mark_is_columnar(mark)); len = sbuf_mark_length(mark); if (len >= sizeof(buf)) printf(" (mark too long for output)\n"); else { sbuf_strat(buf, mark); printf(" <<"); for (i = 0; i < len; ++i) { switch (buf[i]) { case '\n': printf("\\n"); break; case '\t': printf("\\t"); break; case '\0': printf("\\0"); break; case '\\': printf("\\\\"); break; default: printf("%c", buf[i]); break; } } printf(">>\n"); } } /********************************************************************** * Local functions follow. */ /* * Function: string_dim * Purpose: Return string dimensions as a column. */ static void string_dim(const char *s, long len, long *w, long *h) { long i, n; int prev; prev = '\n'; *h = *w = n = 0; for (i = 0; i < len; ++i) { if (prev == '\n') ++(*h); if (s[i] == '\n') { if (n > *w) *w = n; n = 0; } else ++n; prev = s[i]; } } #if UNDO /* * Function: changelog_entry * Purpose: Create a new changelog entry. */ static struct __sbuf_change *changelog_entry(long pos, long newlen, const char *oldtext, long oldlen, int dirty) { struct __sbuf_change *log; log = malloc(sizeof(struct __sbuf_change)); if (log == NULL) { __publib_error("out of memory"); return NULL; } if (oldlen == 0) log->oldtext = NULL; else { log->oldtext = malloc(oldlen); if (log->oldtext == NULL) { __publib_error("out of memory"); free(log); return NULL; } } log->pos = pos; log->newlen = newlen; memcpy(log->oldtext, oldtext, oldlen); log->oldlen = oldlen; log->buffer_was_dirty = dirty; log->last_composite = 0; log->next = NULL; log->prev = NULL; return log; } /* * Function: changelog_add * Purpose: Add new entry to change log. Forget old ones, if log is big. */ static void changelog_add(Sbuf *buf, struct __sbuf_change *log) { long n, nn; struct __sbuf_change *p; if (buf->log_tail == NULL) { buf->log_head = log; buf->log_tail = log; } else { log->prev = buf->log_tail; buf->log_tail->next = log; buf->log_tail = log; } for (n = 0; log != NULL; log = log->prev) { nn = n + sizeof(*log) + log->oldlen; if (nn > buf->log_max) break; n = nn; } if (log != NULL) { while (buf->log_head != log) { p = buf->log_head; buf->log_head = p->next; buf->log_head->prev = NULL; free(p->oldtext); free(p); } } } #endif /* * Function: replace_mark_part * Purpose: Replace bytes pos..pos+len-1 in the buffer with * the first n bytes from beginning of string, padding the * replacement with spaces so that it fills w bytes, if * necessary. * Note: This can be used to replace the whole contents of a mark, * or to do line-by-line replacements, if the mark is columnar. */ static int replace_mark_part(Sbuf *buf, long pos, long len, const char *s, long n, long w) { #if UNDO struct __sbuf_change *log; #endif assert(n <= w); if (sbuf_movegap(buf, pos, w) == -1) return -1; #if UNDO log = changelog_entry(pos, w, buf->block + buf->gappos + gaplen(buf), len, buf->flags & SBUF_DIRTY_FLAG); if (log == NULL) return -1; #endif buf->len -= len; memcpy(buf->block + buf->gappos, s, n); if (n < w) memset(buf->block + buf->gappos + n, ' ', w - n); buf->len += w; buf->gappos += w; sbuf_set_dirty(buf, 1); #if UNDO changelog_add(buf, log); #endif return 0; } /* * Function: adjust_marks * Purpose: The range (begin,len) has been changed to (begin,newlen). * Adjust all marks in buffer accordingly. */ static void adjust_marks(Sbuf *buf, long begin, long len, long newlen) { struct __sbufmark *m; long mend, oldend; int i; oldend = begin + len; for (i = 0; i < buf->markalloc; ++i) { m = buf->marks + i; if (!m->inuse) continue; mend = m->begin + m->len; if (m->begin < begin && mend > begin) { /* m starts before, extends into or after old */ if (mend <= oldend) m->len = newlen + begin - m->begin; else m->len = m->len - len + newlen; m->dirty = 1; } else if (m->begin >= begin && m->begin <= oldend) { /* m starts within or at beginning of old */ m->begin = begin; if (mend > oldend) m->len = newlen + (mend - oldend); else m->len = newlen; m->dirty = 1; } else if (m->begin >= oldend) { /* m starts at or after end of old */ m->begin += newlen - len; } assert(m->begin >= 0); assert(m->len >= 0); assert(m->begin <= buf->len); assert(m->begin + m->len <= buf->len); } } /* * Function: remove_columnar_mark * Purpose: Remove the selected bit in all lines of a columnar mark. */ static int remove_columnar_mark(Sbufmark *mark) { long start_pos, end_pos; long start_col, end_col; long p, pp, q, r; const int tabsize = 8; start_pos = sbuf_mark_begin(mark); end_pos = sbuf_mark_end(mark); start_col = sbuf_colno(mark->buf, start_pos, tabsize); end_col = sbuf_colno(mark->buf, end_pos, tabsize); if (start_col > end_col) return -1; pp = sbuf_boln(mark->buf, start_pos); p = sbuf_boln(mark->buf, end_pos); for (; p >= pp; p = sbuf_boln(mark->buf, p-1)) { q = sbuf_colpos(mark->buf, p, start_col, tabsize); r = sbuf_colpos(mark->buf, p, end_col, tabsize); if (replace_mark_part(mark->buf, q, r-q, "", 0, 0) == -1) return -1; /* fixme to use sbuf_adjust_pos_cache */ sbuf_clear_pos_cache(mark->buf, p); adjust_marks(mark->buf, q, r-q, 0); sbuf_validate_mark(mark); } return 0; } /* * Function: count_chars * Purpose: The number of occurences of a character in a memory area. */ static long count_chars(const char *s, int c, long len) { long n; const char *end; for (n = 0, end = s+len; s < end; ++s) { s = memchr(s, c, end - s); if (s == NULL) break; ++n; } return n; } /* * Function: insert_columnar_text * Purpose: Insert a column of text into buffer. */ static int insert_columnar_text(Sbuf *buf, Sbufmark *mark, const char *s, long len, long tab) { long i, n, w, h, col, end, pos, begin; string_dim(s, len, &w, &h); pos = sbuf_mark_begin(mark); begin = end = pos; col = sbuf_colno(buf, pos, tab); for (i = 0; i < len; i += n) { for (n = 0; i+n < len && s[i+n] != '\n'; ++n) continue; if (replace_mark_part(buf, pos, 0, s+i, n, w) == -1) return -1; adjust_marks(buf, pos, 0, w); /* fixme to use sbuf_adjust_pos_cache */ sbuf_clear_pos_cache(buf, pos); end = pos + w; pos = sbuf_eoln(buf, pos); pos = sbuf_colpos(buf, pos, col, tab); if (i+n < len && s[i+n] == '\n') ++n; } sbuf_remark(mark, begin, end-begin); return 0; } /* * Function: strchange * Purpose: Replace part of buffer with new text. */ static int strchange(Sbuf *buf, long pos, long len, const char *text, long textlen) { long old_lines, new_lines; if (sbuf_movegap(buf, pos + len, 0) == -1) return -1; old_lines = count_chars(buf->block + pos, '\n', len); new_lines = count_chars(text, '\n', textlen); if (replace_mark_part(buf, pos, len, text, textlen, textlen) == -1) return -1; sbuf_adjust_pos_cache(buf, pos, len, textlen, new_lines - old_lines); adjust_marks(buf, pos, len, textlen); return 0; } /* * Function: __sbuf_log * Purpose: Write (and open, if necessary) a log file for logging changes to sbufs. */ static void __sbuf_log(const char *fmt, ...) { #if SBUF_LOG static FILE *log = NULL; va_list args; if (log == NULL) { log = fopen("/home/liw/sbuf-changes-log", "a"); if (log == NULL) return; } va_start(args, fmt); vfprintf(log, fmt, args); va_end(args); (void) fflush(log); #endif } publib-0.40/stack/0000775000175000017500000000000011767707451012134 5ustar ajkajkpublib-0.40/stack/stack_create.c0000664000175000017500000000346511767417657014746 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stack_create.c -- create a new (and empty) stack * * Part of publib. See man page for more information * "@(#)publib-stack:$Id: stack_create.c,v 1.3 1994/07/16 15:29:06 liw Exp $" */ #include #include "publib/stack.h" #include "publib/errormsg.h" Stack *stack_create(void) { Stack *st; st = malloc(sizeof(Stack)); if (st == NULL) { __publib_error("malloc failed"); return NULL; } st->data = NULL; st->size = NULL; st->allocated = 0; st->used = 0; return st; } publib-0.40/stack/stack_destroy.c0000664000175000017500000000340111767417657015162 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stack_destroy.c -- free resources allocated for stack * * Part of publib. See man page for more information * "@(#)publib-stack:$Id: stack_destroy.c,v 1.1.1.1 1993/11/20 17:02:51 liw Exp $" */ #include #include #include "publib/stack.h" void stack_destroy(Stack *st) { assert(st != NULL); assert(st->used <= st->allocated); while (st->used > 0) stack_pop(st); free(st->size); free(st->data); free(st); } publib-0.40/stack/stack_emptyp.c0000664000175000017500000000320011767417657015004 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stack_is_empty.c -- test if stack is empty * * Part of publib. See man page for more information * "@(#)publib-stack:$Id: stack_emptyp.c,v 1.1.1.1 1993/11/20 17:02:51 liw Exp $" */ #include #include "publib/stack.h" int stack_is_empty(Stack *st) { assert(st != NULL); return st->used == 0; } publib-0.40/stack/stack_push.c0000664000175000017500000000501111767417657014447 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stack_push.c -- push element on top of stack * * Part of publib. See man page for more information * "@(#)publib-stack:$Id: stack_push.c,v 1.3 1994/07/16 15:29:08 liw Exp $" */ #include #include #include #include "publib/stack.h" #include "publib/errormsg.h" int stack_push(Stack *st, void *data, size_t bytes) { void *p; size_t n; assert(st != NULL); assert(st->used <= st->allocated); assert(data != NULL); if (st->used == st->allocated) { n = st->allocated + 64; p = realloc(st->data, n * sizeof(void *)); if (p == NULL) { __publib_error("realloc failed"); return -1; } st->data = p; p = realloc(st->size, n * sizeof(size_t)); if (p == NULL) { __publib_error("realloc failed"); return -1; } st->size = p; while (st->allocated < n) { st->data[st->allocated] = NULL; st->size[st->allocated] = 0; ++st->allocated; } } if (bytes == 0) { st->data[st->used] = data; st->size[st->used] = 0; } else { p = malloc(bytes); if (p == NULL) { __publib_error("malloc failed"); free(p); return -1; } memcpy(p, data, bytes); st->data[st->used] = p; st->size[st->used] = bytes; } ++st->used; return 0; } publib-0.40/stack/stack_copy.c0000664000175000017500000000502611767417657014450 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stack_copy.c -- make a copy of a stack and pushed data * * Part of publib. See man page for more information * "@(#)publib-stack:$Id: stack_copy.c,v 1.3 1994/07/16 15:29:05 liw Exp $" */ #include #include #include #include "publib/stack.h" #include "publib/errormsg.h" Stack *stack_copy(Stack *st) { Stack *cp; size_t i; assert(st != NULL); cp = malloc(sizeof(Stack)); if (cp == NULL) { __publib_error("malloc failed"); return NULL; } cp->data = NULL; /* initializations needed for error return */ cp->size = NULL; cp->allocated = cp->used = st->used; if (cp->used == 0) return cp; cp->data = malloc(st->used * sizeof(void *)); if (cp->data == NULL) goto error; cp->size = malloc(st->used * sizeof(size_t)); if (cp->size == NULL) goto error; for (i = 0; i < st->used; ++i) { if (st->size[i] == 0) { cp->data[i] = st->data[i]; cp->size[i] = st->size[i]; } else { cp->data[i] = malloc(st->size[i]); if (cp->data[i] == NULL) goto error; memcpy(cp->data[i], st->data[i], st->size[i]); cp->size[i] = st->size[i]; } } return 0; error: __publib_error("malloc failed"); free(cp->data); free(cp->size); free(cp); return NULL; } publib-0.40/stack/stack_pop.c0000664000175000017500000000337311767417657014277 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stack_pop.c -- remove and return topmost element of stack * * Part of publib. See man page for more information * "@(#)publib-stack:$Id: stack_pop.c,v 1.1.1.1 1993/11/20 17:02:51 liw Exp $" */ #include #include "publib/stack.h" void *stack_pop(Stack *st) { void *p; assert(st != NULL); assert(st->used > 0); --st->used; p = st->data[st->used]; st->data[st->used] = NULL; st->size[st->used] = 0; return p; } publib-0.40/bitarr/0000775000175000017500000000000011767707451012312 5ustar ajkajkpublib-0.40/bitarr/ba_clear.c0000664000175000017500000000341111767417657014213 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_clear.c -- remove number from set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_clear.c,v 1.3 1995/05/12 14:43:58 wirzeniu Exp $" */ #include #include "publib/bitarr.h" void ba_clear(Bitarr *u, unsigned number) { assert(u != NULL); assert(u->rnglen == 0 || u->da.data != NULL); if (number < u->rnglen) { unsigned *w = u->da.data; w[ba_num2word(number)] &= ~ba_num2mask(number); } } publib-0.40/bitarr/ba_query.c0000664000175000017500000000341411767417657014275 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_query.c -- check if number belongs to set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_query.c,v 1.2 1995/05/12 14:44:05 wirzeniu Exp $" */ #include #include "publib/bitarr.h" int ba_query(Bitarr *u, unsigned number) { unsigned *w; assert(u != NULL); if (number >= u->rnglen) return 0; assert(u->da.data != NULL); w = u->da.data; return w[ba_num2word(number)] & ba_num2mask(number); } publib-0.40/bitarr/ba_destroy.c0000664000175000017500000000324111767417657014617 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_destroy.c -- free resources allocated to a set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_destroy.c,v 1.2 1995/05/12 14:44:01 wirzeniu Exp $" */ #include #include #include "publib/bitarr.h" void ba_destroy(Bitarr *u) { assert(u != NULL); dynarr_free(&u->da); free(u); } publib-0.40/bitarr/ba_copy.c0000664000175000017500000000356511767417657014111 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_copy.c -- create a copy of a set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_copy.c,v 1.4 1995/05/12 14:44:00 wirzeniu Exp $" */ #include #include #include #include "publib/bitarr.h" #include "publib/errormsg.h" Bitarr *ba_copy(const Bitarr *u) { Bitarr *uc; assert(u != NULL); assert(u->rnglen == 0 || u->da.data != NULL); uc = ba_create(); if (uc == NULL) return NULL; if (dynarr_copy(&uc->da, &u->da) == -1) return NULL; uc->rnglen = u->rnglen; return uc; } publib-0.40/bitarr/ba_resize.c0000664000175000017500000000371511767417657014435 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_resize.c -- change size of set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_resize.c,v 1.4 1995/05/12 14:44:06 wirzeniu Exp $" */ #include #include #include #include "publib/bitarr.h" #include "publib/errormsg.h" int ba_resize(Bitarr *u, size_t rnglen) { size_t oldsize, newsize; assert(u != NULL); oldsize = ba_num2word(u->rnglen); newsize = ba_num2word(rnglen); if (dynarr_resize(&u->da, newsize) == -1) return -1; if (oldsize < newsize) { unsigned *w = u->da.data; memset(w + oldsize, 0, newsize - oldsize); } u->rnglen = rnglen; return 0; } publib-0.40/bitarr/ba_clear_all.c0000664000175000017500000000336111767417657015047 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_clear_all.c -- make set empty * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_clear_all.c,v 1.2 1995/05/12 14:43:59 wirzeniu Exp $" */ #include #include #include "publib/bitarr.h" void ba_clear_all(Bitarr *u) { assert(u != NULL); assert(u->rnglen == 0 || u->da.data != NULL); if (u->da.alloc > 0) memset(u->da.data, 0, sizeof(unsigned)*u->da.alloc); } publib-0.40/bitarr/ba_not.c0000664000175000017500000000337511767417657013736 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_not.c -- complement a set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_not.c,v 1.2 1995/05/12 14:44:03 wirzeniu Exp $" */ #include #include "publib/bitarr.h" void ba_not(Bitarr *u) { size_t i, size; unsigned *w; assert(u != NULL); assert(u->rnglen == 0 || u->da.data != NULL); size = ba_num2word(u->rnglen); w = u->da.data; for (i = 0; i < size; ++i) w[i] = ~w[i]; } publib-0.40/bitarr/ba_or_ba.c0000664000175000017500000000416311767417657014214 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_or_ba.c -- or a set with another set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_or_ba.c,v 1.4 1995/05/12 14:44:04 wirzeniu Exp $" */ #include #include #include #include "publib/bitarr.h" #include "publib/errormsg.h" int ba_or_ba(Bitarr *u1, const Bitarr *u2) { size_t i, size; unsigned *w1, *w2; assert(u1 != NULL); assert(u2 != NULL); assert(u1->rnglen == 0 || u1->da.data != NULL); assert(u2->rnglen == 0 || u2->da.data != NULL); if (u1->rnglen < u2->rnglen && ba_resize(u1, u2->rnglen) == -1) { __publib_error("ba_resize failed"); return -1; } assert(u1->rnglen >= u2->rnglen); size = ba_num2word(u2->rnglen); w1 = u1->da.data; w2 = u2->da.data; for (i = 0; i < size; ++i) w1[i] |= w2[i]; return 0; } publib-0.40/bitarr/ba_set.c0000664000175000017500000000351411767417657013724 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_set.c -- add number to set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_set.c,v 1.4 1995/05/12 14:44:06 wirzeniu Exp $" */ #include #include "publib/bitarr.h" #include "publib/errormsg.h" int ba_set(Bitarr *u, unsigned number) { unsigned *w; assert(u != NULL); if (number >= u->rnglen && ba_resize(u, number+1) == -1) { __publib_error("ba_resize failed"); return -1; } w = u->da.data; w[ba_num2word(number)] |= ba_num2mask(number); return 0; } publib-0.40/bitarr/ba_create.c0000664000175000017500000000343111767417657014372 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_create.c -- create an empty set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_create.c,v 1.5 1995/05/12 14:44:00 wirzeniu Exp $" */ #include #include "publib/bitarr.h" #include "publib/errormsg.h" Bitarr *ba_create(void) { Bitarr *u; u = malloc(sizeof(Bitarr)); if (u == NULL) { __publib_error("malloc failed"); return NULL; } dynarr_init(&u->da, sizeof(unsigned)); u->rnglen = 0; return u; } publib-0.40/bitarr/ba_xor_ba.c0000664000175000017500000000373211767417657014405 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_xor_ba.c -- xor a set with another set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_xor_ba.c,v 1.3 1995/05/12 14:44:07 wirzeniu Exp $" */ #include #include "publib/bitarr.h" void ba_xor_ba(Bitarr *u1, const Bitarr *u2) { size_t i, size, u2size; unsigned *w1, *w2; assert(u1 != NULL); assert(u2 != NULL); assert(u1->rnglen == 0 || u1->da.data != NULL); assert(u2->rnglen == 0 || u2->da.data != NULL); size = ba_num2word(u1->rnglen); u2size = ba_num2word(u2->rnglen); if (u2size < size) size = u2size; w1 = u1->da.data; w2 = u2->da.data; for (i = 0; i < size; ++i) w1[i] ^= w2[i]; } publib-0.40/bitarr/ba_or_not_ba.c0000664000175000017500000000415011767417657015070 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_or_not_ba.c -- or a set with the complement of another set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_or_not_ba.c,v 1.3 1995/05/12 14:44:04 wirzeniu Exp $" */ #include #include #include #include "publib/bitarr.h" void ba_or_not_ba(Bitarr *u1, const Bitarr *u2) { size_t i, size, u1size; unsigned *w1, *w2; assert(u1 != NULL); assert(u2 != NULL); assert(u1->rnglen == 0 || u1->da.data != NULL); assert(u2->rnglen == 0 || u2->da.data != NULL); u1size = ba_num2word(u1->rnglen); size = ba_num2word(u2->rnglen); if (u1size < size) size = u1size; w1 = u1->da.data; w2 = u2->da.data; for (i = 0; i < size; ++i) w1[i] |= ~w2[i]; if (size < u1size) memset(w1 + size, ~(unsigned char)0, u1size - size); } publib-0.40/bitarr/ba_and_ba.c0000664000175000017500000000405311767417657014334 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ba_and_ba.c -- and a set with another set * * Part of publib. See man page for more information * "@(#)publib-bitarr:$Id: ba_and_ba.c,v 1.3 1995/05/12 14:43:58 wirzeniu Exp $" */ #include #include #include "publib/bitarr.h" void ba_and_ba(Bitarr *u1, const Bitarr *u2) { size_t i, size, u1size; unsigned *w1, *w2; assert(u1 != NULL); assert(u2 != NULL); assert(u1->rnglen == 0 || u1->da.data != NULL); assert(u2->rnglen == 0 || u2->da.data != NULL); u1size = ba_num2word(u1->rnglen); size = ba_num2word(u2->rnglen); if (u1size < size) size = u1size; w1 = u1->da.data; w2 = u2->da.data; for (i = 0; i < size; ++i) *w1++ &= *w2++; if (size < u1size) memset(w1 + size, 0, u1size - size); } publib-0.40/includes/0000775000175000017500000000000011767707451012635 5ustar ajkajkpublib-0.40/includes/publib/0000775000175000017500000000000011767707451014112 5ustar ajkajkpublib-0.40/includes/publib/hash.h0000664000175000017500000000434111767417657015216 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * hash.h -- hashing table routines * * Part of Publib, see man page for more information. * "@(#)publib-hash:$Id: hash.h,v 1.2 1995/09/23 09:11:54 liw Exp $" */ #ifndef __publib_hash_h_included #define __publib_hash_h_included #include /* need size_t */ #define __HASHTAB_SIZE 511 typedef unsigned long __hash_func(const void *); struct __hash_node { void *data; size_t size; unsigned long val; struct __hash_node *next; }; struct __hashtab { __hash_func *hash; int (*cmp)(const void *, const void *); struct __hash_node *tab[__HASHTAB_SIZE]; }; typedef struct __hashtab Hashtab; Hashtab *hash_create(__hash_func *, int (*)(const void *, const void *)); void hash_destroy(Hashtab *); void *hash_install(Hashtab *, const void *, size_t); void *hash_lookup(Hashtab *, const void *); int hash_uninstall(Hashtab *, const void *); int hash_iter(Hashtab *, int (*)(void *, void *), void *); #endif publib-0.40/includes/publib/bitarr.h0000664000175000017500000000505211767417657015556 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __publib_bitarr_h #define __publib_bitarr_h #include /* need size_t */ #include /* need CHAR_BIT */ #include /* need dynarr */ typedef struct { struct dynarr da; size_t rnglen; } Bitarr; /* How many bits are there in an unsigned int? */ #define ba_bits (sizeof(unsigned)*CHAR_BIT) /* Compute word a given bit is stored in */ #define ba_num2word(i) ((i) / ba_bits) /* Create bitmask for one word, given index into bit array */ #define ba_num2mask(i) (1 << ((i) % ba_bits)) Bitarr *ba_create(void); void ba_destroy(Bitarr *__ba); Bitarr *ba_copy(const Bitarr *__ba); int ba_resize(Bitarr *__ba, size_t __max_number); int ba_set(Bitarr *__ba, unsigned __number); /* ba[number] = 1 */ void ba_clear(Bitarr *__ba, unsigned __number); /* ba[number] = 0 */ void ba_clear_all(Bitarr *__ba); /* ba[*] = 0 */ int ba_query(Bitarr *__ba, unsigned __number); /* ba[number] */ void ba_and_ba(Bitarr *__ba1, const Bitarr *__ba2); /* ba1 &= ba2 */ int ba_or_ba(Bitarr *__ba1, const Bitarr *__ba2); /* ba1 |= ba2 */ void ba_xor_ba(Bitarr *__ba1, const Bitarr *__ba2); /* ba1 ^= ba2 */ void ba_or_not_ba(Bitarr *__ba1, const Bitarr *__ba2); /* ba1 |= ~ba2 */ void ba_not(Bitarr *__ba); /* ba = ~ba */ #endif publib-0.40/includes/publib/lockfile.h0000664000175000017500000000305411767417657016063 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: lockfile.h * Purpose: Declarations for lock files. * Author: Lars Wirzenius * Version: $Id: lockfile.h,v 1.1.1.1 1996/11/05 21:06:56 liw Exp $ */ int lockfile_create(const char *); int lockfile_remove(const char *); publib-0.40/includes/publib/log.h0000664000175000017500000000414711767417657015060 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * log.h -- log files * * Part of publib. See man page for more information * "@(#)publib-log:$Id: log.h,v 1.4 1997/05/09 13:43:49 liw Exp $" */ #ifndef __publib_log_h_included #define __publib_log_h_included #include /* need FILE */ #include /* need va_list */ enum log_level { log_level_chat, log_level_note, log_level_warn, log_level_error, log_level_fatal }; int log_open(const char *, int); int log_add(FILE *, int); void log_set_level(int, int); void log_set_localtime(int, int); int log_close(void); void log_off(void); void log_on(void); void log_chat(const char *, ...); void log_note(const char *, ...); void log_warn(const char *, ...); void log_error(const char *, ...); void log_fatal(const char *, ...); void log_printf(int, const char *, ...); #endif publib-0.40/includes/publib/queue.h0000664000175000017500000000461611767417657015424 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: queue.h * Purpose: Declarations for Publib's queue abstract data type. * Description: A queue is a list-like data structure where all additions * are done at one end (the behind of the queue) all deletions at * the other end (the front of the queue). It is very similar * to a queue in a large food store, except that no-one tries * to get in the queue anywhere except at the behind. * Note: This Publib module reserves all names beginning with * ``queue'' or ``Queue''. * Author: Lars Wirzenius * Version: "@(#)publib:$Id: queue.h,v 1.1.1.1 1996/01/18 15:44:03 liw Exp $" */ #ifndef __publib_queue_h_included #define __publib_queue_h_included #include typedef struct queue Queue; Queue *queue_create(void); void queue_destroy(Queue *); void *queue_front(Queue *); void *queue_remove(Queue *); int queue_is_empty(Queue *); int queue_add(Queue *, const void *, size_t); #ifdef __publib__ struct queue_node { void *queue_data; struct queue_node *queue_previous; }; struct queue { struct queue_node *queue_front, *queue_behind; }; #endif #endif publib-0.40/includes/publib/nntp.h0000664000175000017500000000610711767433541015242 0ustar ajkajk/* Part of publib. Copyright (c) 2012 Antti-Juhani Kaijanaho. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * nntp.h -- declarations for routines for NNTP clients * * Lars Wirzenius * Part of Publib. */ #ifndef __publib_nntp_h_included #define __publib_nntp_h_included #include #include #include struct nntp_article { struct dynarr headers; struct dynarr body; }; void nntp_init_article(struct nntp_article *); void nntp_clear_article(struct nntp_article *); int nntp_read_article_file(FILE *, struct nntp_article *); int nntp_read_article_nntp(int, struct nntp_article *); int nntp_write_article_file(FILE *, struct nntp_article *); int nntp_write_article_nntp(int, struct nntp_article *); int nntp_post_article(int, struct nntp_article *); int nntp_add_header(struct nntp_article *, const char *); int nntp_add_unique_header(struct nntp_article *, const char *, const char *); int nntp_add_body(struct nntp_article *, const char *); int nntp_get_header(char **, const struct nntp_article *, int); int nntp_remove_header(struct nntp_article *, int); int nntp_find_header(int *, const struct nntp_article *, int, const char *); int nntp_copy_header(struct nntp_article *, struct nntp_article *, const char *); int nntp_set_date(struct nntp_article *, time_t); int nntp_get_article_by_id(int, struct nntp_article *, const char *); int nntp_get_article_by_number(int, struct nntp_article *, int); int nntp_get_current_article(int); int nntp_open(int *, const char *, int); int nntp_close(int); int nntp_newnews(int, const char *, const char *, const char *, const char *); int nntp_next_line(int, char **); int nntp_post(int); int nntp_write_next_line(int, const char *); int nntp_write_end_line(int); int nntp_group(int, const char *); int nntp_goto_next_article(int); void nntp_do_logs(int, int); #endif publib-0.40/includes/publib/priq.h0000664000175000017500000000375611767417657015257 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: priq.h * Purpose: Declarations for priority queues. * Author: Lars Wirzenius * Version: "@(#)publib:$Id: priq.h,v 1.2 1997/01/01 19:38:46 liw Exp $" */ #ifndef __publib_priq_h_included #define __publib_priq_h_included typedef struct priq Priq; Priq *priq_create(int (*)(const void *, const void *)); void priq_destroy(Priq *); void priq_set_compare(Priq *, int (*)(const void *, const void *)); int priq_insert(Priq *, const void *, size_t); void *priq_remove(Priq *); int priq_is_empty(Priq *); void priq_dump(Priq *); #ifdef __publib__ #include struct priq { struct dynarr da; int (*compare)(const void *, const void *); }; #endif #endif publib-0.40/includes/publib/fname.h0000664000175000017500000000371611767417657015366 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fname.h -- filename manipulation * * Part of publib. * "@(#)publib-fname:$Id: fname.h,v 1.1.1.1 1993/11/20 17:02:15 liw Exp $" */ #ifndef __publib_fname_h #define __publib_fname_h #include /* need size_t */ char *fnbase(const char *); void fndelbeg(char *); void fndelend(char *); int fndelsuf(char *, const char *); void fndir(char *, const char *); int fnhome(char *, const char *); void fnjoin(char *, const char *, const char *); char *fnlastsuf(const char *); int fnpathfind(const char *, const char *, char *, size_t); size_t fnqualify(char *, const char *, size_t); size_t fnsetsuf(char *, const char *, size_t); #endif publib-0.40/includes/publib/strutil.h0000664000175000017500000001044611767417657016004 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __publib_strutil_h #define __publib_strutil_h #include /* need size_t */ void *memarrfill(void *, size_t, size_t); void *memdel(void *, size_t, size_t); void *memfill(void *, size_t, const void *, size_t); void *memins(void *, size_t, const void *, size_t); void memisort(void *, size_t, size_t, const void *, int (*)(const void *, const void *)); void *memmem(const void *, size_t, const void *, size_t); int memoverlap(const void *, size_t, const void *, size_t); void *memrchr(const void *, int, size_t); void *memrev(void *, size_t, size_t); void *memrmem(const void *, size_t, const void *, size_t); void memswap(void *, void *, size_t); void *memshuffle(void *, size_t, size_t); char *stracat(const char *, ...); char *stranaxfrm(char *); char *strchange(char *, size_t, const char *, size_t); void strcins(char *, int); void strcstr(char *, size_t, const void *, size_t); char *strdel(char *, size_t); size_t strdiff(const char *, const char *); char *strend(const char *); int strendzap(char *, const char *); int strgsub(char *, const char *, const char *, size_t); unsigned long strhash(const char *); char *strinit(char *, int, size_t); char *strins(char *, const char *); char *strltrim(char *); char *strnins(char *, const char *, size_t); size_t strnlen(const char *, size_t); char *strmaxcpy(char *, const char *, size_t); char *strmove(char *, const char *); char *strmtrim(char *); char *strndup(const char *, size_t); int stroverlap(const char *, const char *); char *strrev(char *); char *strright(const char *, size_t); char *strrot13(char *); char *strrstr(const char *, const char *); char *strset(char *, int); int strsplit(char *, char **, int, const char *); char *strsub(char *, const char *, const char *); char *strrtrim(char *); char *strtrim(char *); char *strshuffle(char *); char *strtabify(char *, size_t); void strtrexpand(char *, const char *); void struncstr(void *, const char *, size_t); char *struntabify(char *, size_t); int strvars(char **, const char *, char *(*)(const char *)); int strzap(char *, const char *); /* new */ #if 0 char *strmany(char *, const char *, size_t); unsigned long memsum(const void *buf, size_t n) { assert(buf != NULL); assert(0); /* This is as yet unwritten. I will need to find a good source for how the checksum is implemented in for example sum(1). I might be able to use GNU's or BSD's versions, but will have to look into licensing. */ return 0; } int strvercmp(const void *, const void *); int strgetver(const char *, int *, int *, int *); int strgetver(const char *version, int *major, int *minor, int *patchlevel) { char *p; assert(version != NULL); assert(major != NULL); assert(minor != NULL); assert(patchlevel != NULL); *major = (int) strtol(version, &p, 10); *minor = (int) strtol(p, &p, 10); *patchlevel = (int) strtol(p, &p, 10); if (*p != '\0' || p == version) return -1; if (*major < 0 || *minor < 0 || *patchlevel < 0) return -1; return 0; } int strsoundex(const char *); #endif #endif publib-0.40/includes/publib/base64.h0000664000175000017500000000334411767417657015361 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: base64.h * Purpose: Declarations for MIME's Base64 encoding and decoding. * Author: Lars Wirzenius * Version: $Id: base64.h,v 1.1.1.1 1996/11/05 21:01:42 liw Exp $ */ #ifndef __publib_base64_h_included #define __publib_base64_h_included #include size_t base64_length(size_t); size_t base64_encode(char *, const char *, size_t); size_t base64_decode(char *, const char *, size_t); #endif publib-0.40/includes/publib/main.h0000664000175000017500000000334711767417657015224 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * main.h -- declarations for main() utility functions * * Lars Wirzenius. * Part of Publib. See publib(3). * "@(#)publib-main:$Id: main.h,v 1.2 1996/01/07 22:02:58 liw Exp $" */ #ifndef __publib_main_h_included #define __publib_main_h_included #include struct option; int main_options(int, char **, struct option *); int main_filter(int, char **, int (*)(FILE *, char *, void *), void *); #endif publib-0.40/includes/publib/errormsg.h0000664000175000017500000000435611767417657016141 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * errormsg.h -- declarations for error message printing * * Part of publib * "@(#)publib-errormsg:$Id: errormsg.h,v 1.1.1.1 1995/08/06 21:57:17 liw Exp $" */ #ifndef __publib_errormsg_h #define __publib_errormsg_h /* * The following are meant for user programs. */ void set_progname(const char *__argv0, const char *__default); const char *get_progname(void); void errormsg(int __exitp, int __errno, const char *_fmt, ...); /* * The rest is meant for internal use by the publib library. */ enum __liberror { __exit_on_error = 0x01, __abort_on_error = 0x02, __complain_on_error = 0x04 }; extern enum __liberror __liberror; void __set_liberror(enum __liberror); #define __publib_error(msg) \ ((__liberror & __complain_on_error) \ && (errormsg(__liberror & (__abort_on_error | __exit_on_error), -1, \ "error inside publib library function: %s:%ld: %s", \ __FILE__, (int)__LINE__, (msg)), 0)) #endif publib-0.40/includes/publib/tbuf.h0000664000175000017500000000411711767417657015234 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * tbuf.h -- editor buffer implemented with a tree * * Part of Publib, See manual pages publib(3) and tbuf(3) for more information. * "@(#)publib-tbuf:$Id: tbuf.h,v 1.4 1998/12/23 18:03:21 liw Exp $" */ #ifndef __publib_tbuf_h_included #define __publib_tbuf_h_included #include typedef struct tbuf Tbuf; Tbuf *tbuf_create(const char *, size_t); void tbuf_destroy(Tbuf *); Tbuf *tbuf_copy(Tbuf *, size_t, size_t); Tbuf *tbuf_cat(Tbuf *, Tbuf *); size_t tbuf_length(Tbuf *); void tbuf_chars(char *, Tbuf *, size_t, size_t); struct tbuf_stat { Tbuf *tbuf; size_t tbuf_length; size_t tbuf_height; size_t tbuf_nodes; size_t tbuf_chunks; size_t tbuf_memory_total; size_t tbuf_nodes_with_few_kids; }; void tbuf_get_stats(struct tbuf_stat *, Tbuf *); #endif publib-0.40/includes/publib/cmp.h0000664000175000017500000000442511767417657015055 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * cmp.h -- comparison functions for qsort, bsearch, et al. * * Part of publib. * "@(#)publib-cmp:$Id: cmp.h,v 1.1.1.1 1993/11/20 17:01:45 liw Exp $" */ #ifndef __publib_cmp_h #define __publib_cmp_h #include /* size_t */ void cmp_set_offset(size_t __offset, int (*)(const void *, const void *)); int cmp_struct(const void *, const void *); int cmp_char(const void *, const void *); int cmp_short(const void *, const void *); int cmp_int(const void *, const void *); int cmp_long(const void *, const void *); int cmp_schar(const void *, const void *); int cmp_uchar(const void *, const void *); int cmp_ushort(const void *, const void *); int cmp_uint(const void *, const void *); int cmp_ulong(const void *, const void *); int cmp_float(const void *, const void *); int cmp_double(const void *, const void *); int cmp_ldouble(const void *, const void *); int cmp_charptr(const void *, const void *); int cmp_chararr(const void *, const void *); #endif publib-0.40/includes/publib/alloc.h0000664000175000017500000000401211767417657015360 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * publib/alloc.h - memory allocation routines for Publib * * Lars Wirzenius. Part of Publib (see publib(3)). * "@(#)publib-alloc:$Id: alloc.h,v 1.6 1998/10/25 20:48:37 liw Exp $" */ #ifndef __publib_alloc_h #define __publib_alloc_h #include /* need size_t */ struct dynarr { void *data; size_t elsize, alloc, used; }; void dynarr_init(struct dynarr *, size_t); int dynarr_resize(struct dynarr *, size_t); int dynarr_copy(struct dynarr *, const struct dynarr *); void dynarr_free(struct dynarr *); void *xmalloc(size_t); void *xrealloc(void *, size_t); void xfree(void *); char *xstrdup(const char *); void *memdup(const void *, size_t); void *xmemdup(const void *, size_t); #endif publib-0.40/includes/publib/files.h0000664000175000017500000000460411767417657015377 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * files.h -- utility functions for files * * Part of publib. * "@(#)publib-files:$Id: files.h,v 1.2 1996/11/05 21:15:47 liw Exp $" */ #ifndef __publib_files_h #define __publib_files_h #include /* need FILE, size_t */ FILE *xfopen(const char *__filename, const char *__mode); void xfclose(FILE *__fp); void xfseek(FILE *__fp, long __offset, int __origin); char *getaline(FILE *__fp); char *xgetaline(FILE *__fp); void fassert(FILE *__fp); int file_read(const char *, void **, size_t *); int file_read_open(FILE *, void **, size_t *); int file_save(const char *, void *, size_t, int); int file_write(const char *, void *, size_t); #if 0 /**/int copy_file(const char *__oldname, const char *__newname); /**/int fcopy_file(FILE *__oldfile, FILE *__newfile); /**/int move_file(const char *__oldname, const char *__newname); /**/int fmove_file(FILE *__oldfile, FILE *__newfile); /**/char *make_backup_file(const char *__fname); /**/int eprintf(const char *, ...); /**/int eprintf_register(void); /**/int snprintf(char *, size_t, const char *, ...); #endif #endif publib-0.40/includes/publib/sbuf.h0000664000175000017500000001674311767417657015243 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * sbuf.h -- simple text editor buffer routines * * Part of Publib. See manpage for more information. * "@(#)publib-sbuf:$Id: sbuf.h,v 1.21 1996/12/27 22:48:34 liw Exp $" */ #ifndef __publib_sbuf_included #define __publib_sbuf_included /* * Includes for types defined elsewhere. * These are all standard headers or Publib headers. */ #include /* need size_t and FILE */ #include /* need struct dynarr */ typedef struct __publib_sbuf Sbuf; struct __sbufmark { unsigned inuse:1; /* is this mark in use? */ unsigned dirty:1; /* has text in mark been modified? */ unsigned columnar:1; /* is the mark columnar? */ int code; /* code number for easy finding (0=no code) */ long begin; /* where the buffer begins ... */ long len; /* ...and how long it is */ struct __sbufmarkhandle *handle; }; /* * This is how the client sees a struct __bufmark. We can't use a * pointer directly, since the struct __bufmarks may move because of * realloc, and we can't assume that the client will be able to update * his pointers. */ typedef struct __sbufmarkhandle { Sbuf *buf; size_t mark; } Sbufmark; /* * sbuf_lineno caches the values it computes. The cache * contains entries of the following type. */ struct __sbuf_pos_cache { long pos; long lineno; }; #define SBUF_POS_CACHE_MAX (50000) #define SBUF_POS_CACHE_MIN (16) #if SBUF_POS_CACHE_MAX < SBUF_POS_CACHE_MIN #error Do not make SBUF_POS_CACHE_MAX smaller than SBUF_POS_CACHE_MIN. #endif #if SBUF_POS_CACHE_MIN < 16 #error Do not make SBUF_POS_CACHE_MIN too small. #endif /* * Flags for Sbuf. */ enum { SBUF_LOCKED_FLAG = 0x01, SBUF_DIRTY_FLAG = 0x02, SBUF_LOADED_FLAG = 0x04, /* Users are allowed to use and define meaning for the following */ SBUF_USER01_FLAG = 0x0100, SBUF_USER02_FLAG = 0x0200, SBUF_USER03_FLAG = 0x0400, SBUF_USER04_FLAG = 0x0800, SBUF_USER05_FLAG = 0x1000, SBUF_USER06_FLAG = 0x2000, SBUF_USER07_FLAG = 0x4000, SBUF_USER08_FLAG = 0x8000 }; struct __publib_sbuf { char *block; char *name; unsigned long flags; size_t gappos; size_t alloc; size_t len; struct __sbufmark *marks; size_t markalloc; Sbufmark *aux; struct dynarr pc; long poshits, posmisses; double posmissavg; struct __sbuf_change *log_head, *log_tail; long log_max; }; /* * Change log information for undo/redo. */ struct __sbuf_change { long pos; long newlen; char *oldtext; long oldlen; unsigned last_composite:1; unsigned buffer_was_dirty:1; struct __sbuf_change *next, *prev; }; /* * Default maximum size of change log. (struct __sbuf_change's and * saved oldtext's.) */ #define SBUF_MAX_CHANGE_LOG (64*1024) /* * The validation functions shouldn't generate any code when NDEBUG is * defined. This is the same behaviour as assert has. Note that the * prototypes and definitions of these functions are protected against * the macros by virtue of having the function names within parentheses. */ #ifdef NDEBUG #define sbuf_validate(buf) ((void)0) #define sbuf_validate_mark(m) ((void)0) #endif /* * Let's use the same NDEBUG flag to turn on a macro version of sbuf_charat. * _NO_ error checking for this baby. Use the non-macro version for that. */ #ifdef NDEBUG #include /* need EOF */ #define sbuf_charat(buf, pos) \ ((pos) == (buf)->len \ ? EOF \ : (int) (unsigned char) ((pos) < (buf)->gappos \ ? (buf)->block[(pos)] \ : (buf)->block[(pos) + (buf)->alloc - (buf)->len])) #endif /* * Er..., did someone say NDEBUG for macros? Some of the status/info routines * are used pretty heavily as well... */ #if 0 #ifdef NDEBUG #define sbuf_length(b) ((b)->len) #define sbuf_mark_begin(m) ((m)->buf->marks[(m)->mark].begin) /*#define sbuf_mark_length(m) ((m)->buf->marks[(m)->mark].len)*/ /*#define sbuf_mark_end(m) (sbuf_mark_begin(m) + sbuf_mark_length(m))*/ #define sbuf_mark_is_dirty(m) ((m)->buf->marks[(m)->mark].dirty) #define sbuf_mark_set_dirty(m,d) ((m)->buf->marks[(m)->mark].dirty = (d)) #endif #endif /* * Prototypes for functions provided by sbuf. */ Sbuf *sbuf_create(void); void sbuf_destroy(Sbuf *); void (sbuf_validate)(Sbuf *); char *sbuf_get_name(Sbuf *); int sbuf_set_name(Sbuf *, const char *); unsigned long sbuf_get_flags(Sbuf *); int sbuf_has_flags(Sbuf *, unsigned long); void sbuf_set_all_flags(Sbuf *, unsigned long); void sbuf_set_flags(Sbuf *, unsigned long); void sbuf_clear_flags(Sbuf *, unsigned long); int sbuf_is_dirty(Sbuf *); void sbuf_set_dirty(Sbuf *, int); Sbufmark *sbuf_mark(Sbuf *, long, long); void sbuf_remark(Sbufmark *, long, long); void sbuf_unmark(Sbufmark *); long (sbuf_mark_begin)(Sbufmark *); long (sbuf_mark_end)(Sbufmark *); long (sbuf_mark_length)(Sbufmark *); int (sbuf_mark_is_dirty)(Sbufmark *); void (sbuf_mark_set_dirty)(Sbufmark *, int); void (sbuf_validate_mark)(Sbufmark *); int sbuf_mark_is_columnar(Sbufmark *); void sbuf_mark_set_columnar(Sbufmark *, int); void sbuf_set_mark_code(Sbufmark *, int); int sbuf_get_mark_code(Sbufmark *); Sbufmark *sbuf_find_mark_by_code(Sbuf *, int); int sbuf_strchange(Sbufmark *, const char *, size_t); int sbuf_change(Sbufmark *, Sbufmark *); int (sbuf_charat)(Sbuf *, long); void sbuf_strat(char *, Sbufmark *); int sbuf_load(Sbuf *); int sbuf_save(Sbuf *, int); int sbuf_insert_file(Sbufmark *, FILE *); int sbuf_write_to_file(Sbufmark *, FILE *); int sbuf_write_to(Sbufmark *, const char *); long (sbuf_length)(Sbuf *); char *sbuf_lock(Sbuf *); void sbuf_unlock(Sbuf *); long sbuf_boln(Sbuf *, long); long sbuf_eoln(Sbuf *, long); long sbuf_bow(Sbuf *, long); long sbuf_eow(Sbuf *, long); long sbuf_lineno(Sbuf *, long); long sbuf_linepos(Sbuf *, long); long sbuf_colno(Sbuf *, long, long); long sbuf_colpos(Sbuf *, long, long, long); long sbuf_find_pair(Sbuf *, long); void sbuf_clear_pos_cache(Sbuf *, long); void sbuf_adjust_pos_cache(Sbuf *, long, long, long, long); void sbuf_cache_stats(Sbuf *, FILE *); #define SBUF_BACKWARD 0x01 #define SBUF_IGNORE_CASE 0x02 #define SBUF_REGEX 0x04 int sbuf_search(Sbufmark *, Sbufmark *, const char *, size_t, unsigned long); int sbuf_pos_inside_mark(Sbufmark *, long); void sbufgap_movegap(Sbuf *, size_t); void sbuf_dump(const char *, Sbuf *); void sbuf_mark_dump(const char *, Sbufmark *); int sbuf_undo_atomic(Sbuf *); #endif publib-0.40/includes/publib/iset.h0000664000175000017500000000443511767417657015243 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * iset.h -- sets of integers */ #ifndef __publib_iset_h #define __publib_iset_h struct __iset_range { long start, end; struct __iset_range *prev, *next; }; struct __publib_iset { struct __iset_range *lowest, *highest; }; typedef struct __publib_iset Iset; Iset *iset_create(void); void iset_destroy(Iset *__is); Iset *iset_copy(const Iset *__is); int iset_is_empty(const Iset *__is); int iset_add(Iset *__is, long __number); int iset_add_range(Iset *__is, long __number1, long __number2); int iset_remove(Iset *__is, long __number); int iset_remove_range(Iset *__is, long __number1, long __number2); void iset_clear(Iset *__is); int iset_contains(const Iset *__is, long __number); int iset_union(Iset *__is1, const Iset *__is2); int iset_diff(Iset *__is1, const Iset *__is2); int iset_isect(Iset *__is1, const Iset *__is2); void iset_range(const Iset *__is, long *__lowest, long *__highest); int iset_nth_range(const Iset *__is, long __n, long *__lo, long *__hi); #endif publib-0.40/includes/publib/stack.h0000664000175000017500000000352411767417657015402 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * stack.h -- stack routines * * Part of publib * "@(#)publib-stack:$Id: stack.h,v 1.1.1.1 1993/11/20 17:02:51 liw Exp $" */ #ifndef __publib_stack_h #define __publib_stack_h #include /* need size_t */ struct __stack { void **data; size_t *size; size_t allocated, used; }; typedef struct __stack Stack; Stack *stack_create(void); void stack_destroy(Stack *); void *stack_pop(Stack *); int stack_is_empty(Stack *); Stack *stack_copy(Stack *); int stack_push(Stack *, void *__data, size_t __bytes); #endif publib-0.40/includes/publib.h0000664000175000017500000000363211767417657014275 0ustar ajkajk/* Part of publib. Copyright (c) 1996 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __publib_h #define __publib_h #ifdef __cplusplus extern "C" { #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __cplusplus } #endif #endif publib-0.40/man/0000775000175000017500000000000011767707451011602 5ustar ajkajkpublib-0.40/man/memisort.30000664000175000017500000000422111767435743013526 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memisort.3,v 1.3 1996/04/08 22:27:28 liw Exp $" .\" .TH MEMISORT 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memisort \- insert new element into sorted array .SH SYNOPSIS .nf #include void \fBmemisort\fR(void *\fIbase\fR, size_t \fInelem\fR, size_t \fIelsize\fR, const void *\fInew\fR, int (*\fIcomp\fR)(const void *, const void *)); .SH DESCRIPTION \fImemisort\fR inserts a new element into a sorted array, in the proper place to keep the array sorted. \fIbase\fR, \fIelsize\fR, \fInelem\fR, and \fIcomp\fR are as for \fIqsort\fR(3), \fInew\fR is a pointer to the new element. .SH "SEE ALSO" publib(3), qsort(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/errormsg.30000664000175000017500000000767411767435601013537 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" Part of publib .\" "@(#)publib-errormsg:$Id: errormsg.3,v 1.1.1.1 1995/08/06 21:57:17 liw Exp $" .\" .TH ERRORMSG 3 .SH NAME errormsg, set_progname, get_progname \- printing error messages .SH SYNOPSIS #include .sp 1 .nf void \fIerrormsg\fR(int exitp, int eno, const char *fmt, ...); void \fIset_progname\fR(const char *argv0, const char *def); const char *\fIget_progname\fR(void); .SH "DESCRIPTION" The \fIerrormsg\fR function is used for printing error messages. It is a like a combination of fprintf(3) and perror(3), in that it makes it easy to add arbitrary, printf-like formatted text to the output, and makes it easy to include the system's error message (the error string corresponding to the eno parameter). Unlike perror, this function does not get the error code directly from errno, thus making it easier to do something else that might set it before printing out the error message. \fIerrormsg\fR also adds the name of the program to the output, if known. .PP The first argument to \fIerrormsg\fR should be 0 (don't exit program), 1 (exit program with \fIexit(EXIT_FAILURE)\fR) or 2 (with \fIabort()\fR). The second one should be 0 (don't print system error message), positive (print error message corresponding to the error code), or -1 (print the error message corresponding to \fIerrno\fR). .PP The \fIset_progname\fR function sets the program name. You need to call this function with at least one non-NULL parameter to get the program names included in the output. If either argument is non-NULL, it should point at strings that have static duration, i.e. they exist until the program terminates (or at least until the last error message has been printed); this is so that it is not necessary to create a copy of the name. (Either or both arguments can also be NULL.) .PP If the first argument is non-NULL, that is used as the name, otherwise the seconds argument is used. If both are NULL, no program name is included in the output. The reason for having two arguments is so that the caller doesn't have to do the test, and can just call .sp 1 .ti +5 \fIset_progname(argv[0], "default_name");\fR .sp 1 (it is valid for argv[0] to be NULL, under ISO C). .PP The \fIget_progname\fR function returns a pointer to the current name of the program, as set by \fIset_progname\fR. If \fIget_progname\fR returns NULL, then no name has been set and none is included in the output. This function is included for completeness, it is not really expected to be useful. .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/fname.30000664000175000017500000000465211767435625012764 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib:$Id: fname.3,v 1.1 1994/07/12 21:03:04 liw Exp $" .\" .TH FNAME 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME fnbase, fndelbeg, fndelend, fndelsuf, fndir, fnhome, fnjoin, fnlastsuf, fnsetsuf \- filename manipulation .SH SYNOPSIS .nf #include .sp 1 char *\fBfnbase\fR(const char *\fIfname\fR); void \fBfndelbeg\fR(char *\fIfname\fR); void \fBfndelend\fR(char *\fIfname\fR); int \fBfndelsuf\fR(char *\fIfname\fR, const char *\fIsuffix\fR); void \fBfndir\fR(char *\fIdir\fR, const char *\fIfname\fR); int \fBfnhome\fR(char *\fIhomedir\fR, const char *\fIusername\fR); void \fBfnjoin\fR(char *\fIres\fR, const char *\fIf1\fR, const char *\fIf2\fR); char *\fBfnlastsuf\fR(const char *\fIfname\fR); size_t \fBfnsetsuf\fR(char *\fIfname\fR, const char *\fIsuf\fR, size_t \fImax\fR); .SH DESCRIPTION These routines manipulate POSIX-style filenames. This manual page is still under construction. .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memmem.30000664000175000017500000000430011767435752013142 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memmem.3,v 1.1 1994/06/20 20:29:56 liw Exp $" .\" .TH MEMMEM 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memmem \- search for memory block inside another memory block .SH SYNOPSIS .nf #include void *\fBmemmem\fR(const void *\fIv\fR, size_t \fIsize\fR, const void *\fIpat\fR, size_t \fIpatsize\fR); .SH DESCRIPTION \fImemmem\fR searches for the pattern \fIpat\fR (length \fIpatsize\fR bytes) in the memory block \fIv\fR (length \fIsize\fR bytes). .SH "RETURN VALUE" \fImemmem\fR returns a pointer to the first byte of the first occurence it finds, or NULL if it doesn't find any occurence. .SH "SEE ALSO" publib(3), memrmem(3), strstr(3), strrstr(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/stroverlap.30000664000175000017500000000410411767436703014065 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: stroverlap.3,v 1.1 1994/06/20 20:30:25 liw Exp $" .\" .TH STROVERLAP 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME stroverlap \- check whether two strings overlap .SH SYNOPSIS .nf #include int \fBstroverlap\fR(const char *\fIs\fR, const char *\fIt\fR); .SH DESCRIPTION \fIstroverlap\fR checks whether the storage used by two strings overlap (i.e., if they even partially stored in the same place in memory). .SH "RETURN VALUE" \fIstroverlap\fR returns 0 for no overlap, nonzero for any overlap at all. .SH "SEE ALSO" publib(3), memoverlap(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strset.30000664000175000017500000000376311767436713013223 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strset.3,v 1.1 1994/06/20 20:30:35 liw Exp $" .\" .TH STRSET 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strset \- set all characters in a string to a given character .SH SYNOPSIS .nf #include char *\fBstrset\fR(char *\fIstr\fR, int \fIc\fR); .SH DESCRIPTION \fIstrset\fR will set all characters (before the terminating '\\0') in the string \fIstr\fR to \fIc\fR. .SH "RETURN VALUE" \fIstrset\fR returns its first argument. .SH "SEE ALSO" publib(3), memset(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strmove.30000664000175000017500000000412111767436674013371 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strmove.3,v 1.1 1994/06/20 20:30:18 liw Exp $" .\" .TH STRMOVE 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strmove \- make a copy of a string, handling overlapping strings .SH SYNOPSIS .nf #include char *\fBstrmove\fR(char *\fItgt\fR, const char *\fIsrc\fR); .SH DESCRIPTION \fIstrmove\fR copies the string \fIsrc\fR to \fItgt\fR, just like \fIstrcpy\fR(3), but handles overlapping moves correctly (cf. \fImemcpy\fR(3) vs. \fImemmove\fR(3)). .SH "RETURN VALUE" \fIstrmove\fR returns \fItgt\fR. .SH "SEE ALSO" publib(3), strcpy(3), memcpy(3), memmove(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strtabify.30000664000175000017500000000416111767436721013676 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strtabify.3,v 1.1 1994/06/20 20:30:39 liw Exp $" .\" .TH STRTABIFY 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strtabify \- convert runs of spaces and tabs to tabs .SH SYNOPSIS .nf #include char *\fBstrtabify\fR(char *\fIstr\fR, size_t \fItabsize\fR); .SH DESCRIPTION \fIstrtabify\fR will converts spaces and tabs to tabs and spaces (using the minimal amount of spaces required, possibly none), while preserving indentation. Tab positions are set every \fItabsize\fR columns. .SH "RETURN VALUE" \fIstrtabify\fR will return its first argument. .SH "SEE ALSO" publib(3), struntabify(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/__set_liberror.30000664000175000017500000000441411767436042014655 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" Part of publib .\" "@(#)publib-errormsg:$Id: __set_liberror.3,v 1.1.1.1 1995/08/06 21:57:17 liw Exp $" .\" .TH __SET_LIBERROR 3 .SH NAME __set_liberror \- modify error handling for publib .SH SYNOPSIS #include .sp 1 .br void __set_liberror(enum __liberror); .SH "DESCRIPTION" Unless the documentation for the function specifies otherwise, the default action when a library function notices an error is to abort whatever it was doing and return an error indication. It is possible to change this behaviour with \fI__set_liberror(3)\fR. The argument should be a bitwise OR of the following values: .sp 1 .nf __abort_on_error __exit_on_error __complain_on_error .in +5 .in -5 .sp 1 Note that \fI__abort_on_error\fR and \fI__exit_on_error\fR are mutually exclusive, only use one. .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strrtrim.30000664000175000017500000000447311767436712013563 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strrtrim.3,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" .\" .TH STRRTRIM 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strrtrim \- remove trailing whitespace .SH SYNOPSIS .nf #include char *\fBstrrtrim\fR(char *\fIs\fR); .SH DESCRIPTION \fIstrrtrim\fR removes all trailing whitespace characters from the end of a string. As whitespace is counted everything for which \fIisspace\fR(3) returns true. .SH "RETURN VALUE" \fIstrltrim\fR returns its argument. .SH EXAMPLE To remove whitespace from the end of all lines, you might do the following: .sp 1 .nf .in +5 #include int main(void) { char line[512]; while (fgets(line, sizeof(line), stdio) != NULL) { strrtrim(line); printf("%s", line); } return 0; } .in -5 .SH "SEE ALSO" publib(3), strtrim(3), strltrim(3), isspace(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/publib.30000664000175000017500000000451511767667422013153 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 2012 Antti-Juhani Kaijanaho. .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" .TH PUBLIB 3 .SH NAME publib \- introduction to publib .SH SYNOPSIS #include .br .SH "DESCRIPTION" \fIpublib\fR is a library of C functions that are useful in many of programs. It is an extension to the Standard C library (as defined by the ISO/ANSI C standard 9899-1990). To use the functions in publib, #include and link with the libpub.a library (adding -lpub at the end of the link command should work, if the library has been installed properly). .PP The library provides functions for .sp 1 .in +5 .nf string and memory area manipulation memory allocation .\" generic data structures I/O .\" configuration files comparison functions for qsort, bsearch, and others expression evaluation .\" dates and times .in -5 .sp 1 .fi .SH AUTHOR Publib was originally written by Lars Wirzenius. It is now maintained by Antti-Juhani Kaijanaho (antti-juhani@kaijanaho.fi). publib-0.40/man/strnins.30000664000175000017500000000434511767436702013372 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strnins.3,v 1.1 1994/07/25 23:15:37 liw Exp $" .\" .TH STRNINS 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strnins \- insert prefix of a string at the beginning of another string .SH SYNOPSIS .nf #include char *\fBstrnins\fR(char *\fItgt\fR, const char *\fIsrc\fR, size_t \fIn\fR); .SH DESCRIPTION \fIstrins\fR inserts upto \fIn\fR characters from the beginning of the \fIsrc\fR string at the beginning of the \fItgt\fR string. The strings must not overlap. The target string must contain enough memory to hold both strings. .SH "RETURN VALUE" \fIstrnins\fR returns its first argument. .SH EXAMPLE See the manual page for \fIstrdel\fR(3) for an example. .SH "SEE ALSO" publib(3), strdel(3), strins(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memswap.30000664000175000017500000000522611767436027013342 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memswap.3,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" .\" .TH MEMSWAP 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memswap \- swap the contents of two memory blocks .SH SYNOPSIS .nf #include void \fBmemswap\fR(void *\fIblock1\fR, void *\fIblock2\fR, size_t \fIn\fR); .SH DESCRIPTION \fImemswap\fR will swap the contents of the two blocks pointed by its first two arguments. The last argument gives the size of the memory blocks. .SH EXAMPLE To swap two structs, one might do the following. .sp 1 .nf .in +5 struct tm tm1, tm2; memswap(&tm1, &tm2, sizeof(struct tm)); .in -5 .SH BUGS Using \fImemswap\fR to swap small portions of memory is inefficient. It is not worth it to use it to swap variables of any of the basic types, for instance. Use inline code for such cases. However, for large portions of memory, e.g., arrays, it is convenient. .PP \fImemswap\fR can't swap variables whose address can't be taken. This excludes variables with the \fBregister\fR specifier and bitfields in structs. But then, there is no way to write a function (or macro) that can handle any kind of arguments. Life is hard. .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strrot13.30000664000175000017500000000437511767436707013403 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strrot13.3,v 1.1 1994/02/05 17:09:25 liw Exp $" .\" .TH STRROT13 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strrot13 \- encrypt or decrypt string using rot13 .SH SYNOPSIS .nf #include char *\fBstrrot13\fR(char *\fIstr\fR); .SH DESCRIPTION \fIstrrot13\fR converts the argument string using rot13, i.e., it replaces each letter a with n, n with a, b with o, o with b, and so on. Converting twice results in the original string. Non-letter characters are not converted. .PP The rot13 encryption method is used commonly on USENET to hide offensive text, or spoilers in discussions about movies or books, or in other similar occasions. .SH "RETURN VALUE" \fIstrrot13\fR returns its argument. .SH "SEE ALSO" publib(3), crypt(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strsub.30000664000175000017500000000507111767436717013217 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strsub.3,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" .\" .TH STRSUB 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strsub \- substitute first occurence of pattern with another string .SH SYNOPSIS .nf #include char *\fBstrsub\fR(char *\fIstr\fR, const char *\fIpat\fR, const char *\fIsub\fR); .SH DESCRIPTION \fIstrsub\fR finds the first occurence of the pattern \fIpat\fR in the string \fIstr\fR (using a method similar to \fIstrstr\fR(3), i.e., no regular expressions), and replaces it with \fIsub\fR. If \fIpat\fR does not occur in \fIstr\fR, no substitution is made. .PP Of course, if \fIsub\fR is an empty string, the pattern is deleted from the string. .SH "RETURN VALUE" \fIstrsub\fR returns a pointer to the first character after the substitution, or NULL if no substitution was made. .SH EXAMPLE To substitute up to two occurences of "foo" with "bar" in a line, one might do the following. .sp 1 .nf .in +5 p = strsub(line, "foo", "bar"); if (p != NULL) strsub(line, "foo", "bar"); .in -5 .SH "SEE ALSO" publib(3), strstr(3), strgsub(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strsplit.30000664000175000017500000001071311767436715013556 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strsplit.3,v 1.2 1994/02/19 20:58:36 liw Exp $" .\" .TH STRSPLIT 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strsplit \- split string into words .SH SYNOPSIS .nf #include int \fBstrsplit\fR(char *\fIsrc\fR, char **\fIwords\fR, int \fImaxw\fR, const char *\fIsep\fR); .SH DESCRIPTION \fIstrsplit\fR splits the \fIsrc\fR string into words separated by one or more of the characters in \fIsep\fR (or by whitespace characters, as specified by \fIisspace\fR(3), if \fIsep\fR is the empty string). Pointers to the words are stored in successive elements in the array pointed to by \fIwords\fR. No more than \fImaxw\fR pointers are stored. The input string is modifed by replacing the separator character following a word with '\\0'. However, if there are more than \fImaxw\fR words, only \fImaxw\fR-1 words will be returned, and the \fImaxw\fRth pointer in the array will point to the rest of the string. If \fImaxw\fR is 0, no modification is done. This can be used for counting how many words there are, e.g., so that space for the word pointer table can be allocated dynamically. .PP strsplit splits the src string into words separated by one or more of the characters in sep (or by whitespace characters, as defined by isspace(3), if sep is the empty string). The src string is modified by replacing the separator character after each word with '\\0'. A pointer to each word is stored into successive elements of the array words. If there are more than maxw words, a '\\0' is stored after the first maxw-1 words only, and the words[maxw-1] will contain a pointer to the rest of the string after the word in words[maxw-2]. .SH "RETURN VALUE" \fIstrsplit\fR returns the total number of words in the input string. .SH EXAMPLE Assuming that words are separated by white space, to count the number of words on a line, one might say the following. .sp 1 .nf .in +5 n = strsplit(line, NULL, 0, ""); .in -5 .PP To print out the fields of a colon-separated list (such as PATH, or a line from /etc/passwd or /etc/group), one might do the following. .sp 1 .nf .in +5 char *fields[15]; int i, n; n = strsplit(list, fields, 15, ":"); if (n > 15) n = 15; for (i = 0; i < n; ++i) printf("field %d: %s\\n", i, fields[i]); .in -5 .PP In real life, one would of course prefer to not restrict the number of fields, so one might either allocated the pointer table dynamically (first counting the number of words using something like the first example), or realize that since it is the original string that is being modified, one can do the following: .sp 1 .nf .in +5 char *fields[15]; int i, n; do { n = strsplit(list, fields, 15, ":"); if (n > 15) n = 15; for (i = 0; i < n; ++i) printf("field %d: %s\\n", i, fields[i]); list = field[n-1] + strlen(field[n-1]); } while (n == 15); .in -5 .SH "SEE ALSO" publib(3), strtok(3) .SH AUTHOR The idea for this function came from C-News source code by Henry Spencer and Geoff Collyer. Their function is very similar, but this implementation is by Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strshuffle.30000664000175000017500000000373511767436714014064 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strshuffle.3,v 1.1 1994/06/20 20:30:37 liw Exp $" .\" .TH STRSHUFFLE 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strshuffle \- make the characters in a string be in random order .SH SYNOPSIS .nf #include char *\fBstrshuffle\fR(char *\fIstr\fR); .SH DESCRIPTION \fIstrshuffle\fR will make the characters in a string be in random order. .SH "RETURN VALUE" \fIstrshuffle\fR will return its argument. .SH "SEE ALSO" publib(3), memshuffle(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/struntabify.30000664000175000017500000000417711767436727014256 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: struntabify.3,v 1.1 1994/06/20 20:30:44 liw Exp $" .\" .TH STRUNTABIFY 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME struntabify \- convert tabs to spaces .SH SYNOPSIS .nf #include char *\fBstruntabify\fR(char *\fIstr\fR, size_t \fItabsize\fR); .SH DESCRIPTION \fIstruntabify\fR will convert all tab characters ('\\t') in the string \fIstr\fR to spaces. Tab positions are at every \fItabsize\fR columns. The string is supposed to be big enough to hold the conversion, which is done in place. .SH "RETURN VALUE" \fIstruntabify\fR will return its first argument. .SH "SEE ALSO" publib(3), strtabify(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/dynarr.30000664000175000017500000000703511767435571013173 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-alloc:$Id: dynarr.3,v 1.2 1995/07/31 19:36:20 liw Exp $" .\" .TH DYNARR 3 "C Programmer's Manual" "Publib" "C Programmer's Manual" .SH NAME dynarr, dynarr_init, dynarr_resize, dynarr_free \- simple dynamic arrays .SH SYNOPSIS #include .sp 1 .nf void \fBdynarr_init\fR(struct dynarr *\fIda\fR, size_t \fIelsize\fR); int \fBdynarr_resize\fR(struct dynarr *\fIda\fR, size_t \fInewsize\fR); void \fBdynarr_free\fR(struct dynarr *\fIda\fR); .SH "DESCRIPTION" These functions make it easier to use dynamic arrays, i.e., arrays that are allocated with \fImalloc\fR(3) and resized with \fIrealloc\fR(3). Below is a typical code fragment for implementing a dynamic array that is resized as more input is read. .in +5 .sp 1 .nf char *p, *line; size_t alloc, len; len = 0; alloc = 1024; if ((line = malloc(alloc)) == NULL) abort(); while (fgets(line + len, alloc-len, stdin) != NULL) { len = strlen(line); alloc += 1024; if ((p = realloc(alloc)) == NULL) abort(); alloc = p; } .fi .in -5 .sp 1 (The error handling is intentionally simplified.) Below is the above fragment with the \fIdynarr\fR(3). .in +5 .sp 1 .nf struct dynarr da; dynarr_init(&da); while (fgets((char *)da.data + da.used, da.alloc-da.len, stdin) != NULL) { da.used = strlen(da.data); if (dynarr_resize(&da, da.alloc + 1024) == -1) abort(); } .fi .in -5 .sp 1 The code is a bit simpler, and all the memory allocation details and most of the error checking code is hidden away. .PP The dynamic array is represented by a \fIstruct dynarr\fR: .in +5 .sp 1 .nf struct dynarr { void *data; size_t alloc, used; }; .fi .in -5 .sp 1 The interface to the dynamic allocation has intentionally been made unopaque. .PP \fIdynarr_init\fR initializes a struct dynarr to be an empty array, \fIdynarr_resize\fR sets its size to be \fInewsize\fR, and \fIdynarr_free\fR frees the array (it will become an empty array again). .SH RETURNS \fIdynarr_resize\fR returns -1 if it failed, 0 if it succeeded. It does not change the array in any way if it failed. .SH "SEE ALSO" publib(3), malloc(3), realloc(3), strdup(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strdiff.30000664000175000017500000000426511767436127013335 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strdiff.3,v 1.1 1995/08/14 22:05:35 liw Exp $" .\" .TH STRDIFF 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strdiff \- locate first difference between two strings .SH SYNOPSIS .nf #include size_t \fBstrdiff\fR(const char *\fIstr1\fR, const char *\fIstr2\fR); .SH DESCRIPTION \fIstrdiff\fR finds the first character from the beginning that is different in the two strings \fIstr1\fR and \fIstr2\fR. The terminating zero characters are considered different. .SH "RETURN VALUE" \fIstrdiff\fR returns a the offset of the first pair of differring characters (or the offset of the first zero character it finds). .SH "SEE ALSO" publib(3), string(3), strcmp(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strvars.30000664000175000017500000000565211767436731013402 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strvars.3,v 1.2 1995/06/17 10:47:23 wirzeniu Exp $" .\" .TH STRVARS 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strvars \- expand variables in string .SH SYNOPSIS .nf #include int \fBstrvars\fR(char **\fIres\fR, const char *\fIstr\fR, char *(*\fIexpand\fR)(const char *)); .SH DESCRIPTION \fIstrvars\fR will replaces references to variables in the string \fIstr\fR with the values of the variables. A reference to a variable is of the form \fI$(foo)\fR or \fI$x\fR (where \fIx\fR is a single character, but not \fI$\fR). A dollar sign is expressed in the string as \fI$$\fR, and will be converted to \fI$\fR in the output. Memory for the expanded string is allocated dynamically, and \fI*res\fR is set to point to it. .PP The values of the variables are fetched using the function \fIexpand\fR. It is given the name of the variable as its argument, and must return a pointer to the value, or NULL if that variable doesn't exist. .SH "RETURN VALUE" \fIstrvars\fR will return 0 if successful, or NULL if an error occured (malformed input string, result too big, or unknown variable). .SH EXAMPLE To replace references to environment variables, one would the following. .sp 1 .nf .in +5 #include #include char line[1024]; char *res; if (strvars(&res, line, getenv) == NULL) errormsg(1, 0, "strvars failed"); printf("res = <%s>\\n", res); .in -5 .SH "SEE ALSO" publib(3), getenv(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/xmalloc.30000664000175000017500000000673111767436734013337 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-alloc:$Id: xmalloc.3,v 1.5 1998/10/25 20:48:38 liw Exp $" .\" .TH XMALLOC 3 "C Programmer's Manual" "Publib" "C Programmer's Manual" .SH NAME xmalloc, xrealloc, xfree, xstrdup, xmemdup, memdup \- memory allocation functions for Publib .SH SYNOPSIS #include .sp 1 .nf void *\fBxmalloc\fR(size_t \fIbytes\fR); void *\fBxrealloc\fR(void *\fIptr\fR, size_t \fIbytes\fR); void \fBxfree\fR(void *\fIptr\fR); char *\fBxstrdup\fR(const char *\fIstring\fR); void *\fBmemdup\fR(const void *\fImem\fR, size_t \fIbytes\fR); void *\fBxmemdup\fR(const void *\fImem\fR, size_t \fIbytes\fR); .SH "DESCRIPTION" These functions are utility functions for memory allocation from the publib library. \fIxmalloc\fR, \fIxrealloc\fR, and \fIxfree\fR are error checking versions of the standard library routines \fImalloc\fR, \fIrealloc\fR, and \fIfree\fR, respectively. They are guaranteed to never return unless there was no problem: if, for example, \fIxmalloc\fR is unable to allocate the requested amount of memory, it prints an error message and terminates the program. Hence, the caller does not need to check for a NULL return value, and the code that calls these functions is simpler due to the lack of error checks. .PP Similarly, \fIxstrdup\fR is an error checking version of the common (though not standard) \fIstrdup\fR routine, which creates a duplicate of a string by allocating memory for the copy with \fImalloc\fR. (For systems that lack \fIstrdup\fR, publib provides one in its portability module; it is always declared in .) .PP \fImemdup\fR is similar to \fIstrdup\fR, it creates a copy of an arbitrary memory area (the arguments are a pointer to the beginning of the area, and its size) by allocating memory for the copy with \fImalloc\fR. \fIxmemdup\fR is its error checking version. .SH NOTE \fIxmalloc\fR and \fIxrealloc\fR treat a request to allocate a block of 0 bytes as an error. \fIxrealloc\fR will allow its first argument to be NULL. .SH "SEE ALSO" publib(3), malloc(3), strdup(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memrev.30000664000175000017500000000431211767436006013154 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memrev.3,v 1.1.1.1 1994/02/03 17:25:29 liw Exp $" .\" .TH MEMREV 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memrev \- reverse an array in place .SH SYNOPSIS .nf #include void *\fBmemrev\fR(void *\fIblock\fR, size_t \fIelsize\fR, size_t \fIelnum\fR); .SH DESCRIPTION \fImemrev\fR will reverse an array, by swapping the contents of its elements. .SH "RETURN VALUE" \fImemrev\fR returns its first argument. .SH EXAMPLE To reverse an integer array one might do the following. .sp 1 .nf .in +5 int array[4] = { 1, 2, 3, 4 }; memrev(array, sizeof(array[0]), 4); .in -5 .sp 1 This will result in the array being { 4, 3, 2, 1 }. .SH "SEE ALSO" publib(3), strrev(3), memshuffle(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/cmp.30000664000175000017500000000710611767435555012454 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-cmp:$Id: cmp.3,v 1.2 1994/02/03 17:33:52 liw Exp $" .\" .TH COMPARE 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME cmp_set_offset, cmp_struct, cmp_char, cmp_short, cmp_int, cmp_long, cmp_float, cmp_double, cmp_long_double, cmp_schar, cmp_uchar, cmp_ushort, cmp_uint, cmp_ulong, cmp_charptr, cmp_chararr \- comparison functions for qsort, bsearch, and others .SH SYNOPSIS .nf #include void \fBcmp_set_offset\fR(size_t \fIoffset\fR, int (*)(const void *, const void *)); int \fBcmp_struct\fR(const void *, const void *); .sp 1 int \fBcmp_char\fR(const void *, const void *); int \fBcmp_short\fR(const void *, const void *); int \fBcmp_int\fR(const void *, const void *); int \fBcmp_long\fR(const void *, const void *); int \fBcmp_float\fR(const void *, const void *); int \fBcmp_double\fR(const void *, const void *); int \fBcmp_long_double\fR(const void *, const void *); .sp 1 int \fBcmp_schar\fR(const void *, const void *); .sp 1 int \fBcmp_uchar\fR(const void *, const void *); int \fBcmp_ushort\fR(const void *, const void *); int \fBcmp_uint\fR(const void *, const void *); int \fBcmp_ulong\fR(const void *, const void *); .sp 1 int \fBcmp_charptr\fR(const void *, const void *); int \fBcmp_chararr\fR(const void *, const void *); .fi .SH "DESCRIPTION" The functions declared above, with the exception of \fIcmp_set_offset\fR, compare two array elements of the indicated type when given pointers to them. The functions are designed to work with \fIqsort(3)\fR, \fIbsearch(3)\fR, and a number of other library functions which all need the same type of comparison function. They all return negative if the value indicated by the first argument is less than the second, 0 if they are the same, and positive otherwise. .PP \fIcmp_struct\fR compares elements of a structure. It needs to know the offset of the element, and a comparison function suitable for the type of the element. These are set with \fIcmp_set_offset\fR, which should be called before \fIqsort(3)\fR. The settings stay in effect until changed. .SH "SEE ALSO" publib(3), qsort(3), bsearch(3), isort(3), lsearch(3), lfind(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/fnqualify.30000664000175000017500000000525411767435662013674 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-fname:$Id: fnqualify.3,v 1.2 1994/02/03 17:34:02 liw Exp $" .\" .TH FNQUALIFY 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME fnqualify \- qualify a filename .SH SYNOPSIS .nf #include .sp 1 size_t \fBfnqualify\fR(char *\fIresult\fR, const char *\fIpath\fR, size_t \fImax\fR); .SH "DESCRIPTION" \fIfname_qualify\fR qualifies a filename. This means that if the input name is not an absolute name (i.e. starts from the root directory, e.g. is \fBfoo\fR, not \fB/tmp/foo\fR), the current directory will be prepended to it. Also, tilde conversion is done: if the filename begins with a tilde (~), the tilde is replaced with the home directory of the user, and if it begins with a tilde and a username, both are replaced with the home directory of the given user. .PP Simplifications like replacing /./ with /, and /foo/../bar with /bar are not done because of problems with symbolic links. .SH RETURNS The function returns -1 if there was some error, or the total size of the full name otherwise. The return value may be greater than the maximum size given by the last argument; only as much as allowed by that is actually written, though. .SH "SEE ALSO" publib(3), fname(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strrstr.30000664000175000017500000000475511767436710013421 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strrstr.3,v 1.1.1.1 1994/02/03 17:25:29 liw Exp $" .\" .TH STRRSTR 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strrstr \- locate last occurence of substring .SH SYNOPSIS .nf #include char *\fBstrrstr\fR(const char *\fIstr\fR, const char *\fIpat\fR); .SH DESCRIPTION \fIstrrstr\fR finds the last occurence of the string \fIpat\fR in the string \fIstr\fR. The terminating '\\0' characters are not compared. .SH "RETURN VALUE" \fIstrrstr\fR returns a pointer to the first character of the substring, or \fBNULL\fR if the substring is not found. .SH EXAMPLE To print out everything on each line starting with the last occurence of "/* " on each line, you might use the following code: .sp 1 .nf .in +5 #include #include int main(void) { char *p, line[512]; while (fgets(line, sizeof(line), stdin) != NULL) { p = strrstr(line, "/* "); if (p != NULL) printf("%s", p); } return 0; } .in -5 .SH "SEE ALSO" publib(3), string(3), strstr(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/files.30000664000175000017500000000613011767435611012764 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-files:$Id: files.3,v 1.2 1994/02/03 17:33:58 liw Exp $" .\" .TH FILES 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME xgetaline, xfseek, xfopen, xfclose, getaline, fassert \- file manipulation utilities .SH SYNOPSIS .nf #include .sp 1 FILE *\fBxfopen\fR(const char *\fIfilename\fR, const char *\fImode\fR); void \fBxfclose\fR(FILE *\fIfp\fR); void \fBxfseek\fR(FILE *\fIfp\fR, long \fIoffset\fR, int \fIorigin\fR); char *\fBgetaline\fR(FILE *\fIfp\fR); char *\fBxgetaline\fR(FILE *\fIfp\fR); void \fBfassert\fR(FILE *\fIfp\fR); .SH "DESCRIPTION" These functions are useful for file manipulation. The functions that begin with \fIx\fR work like the functions without the letter, except if there is an error, they print an error message and kill the program. .PP \fIgetaline\fR reads a line from the given file. It allocates the memory for the line with \fImalloc(3)\fR, and returns a pointer to the beginning of the line. If there is an error, it returns NULL. If the returned value is not NULL, the caller is responsible for freeing the memory. The newline is removed from the end of the line. .PP \fIfassert\fR checks that the argument is not NULL, and that (for a non-NULL argument) the file does not have its error indicator flag set. If either condition is true, it prints an error message and termiantes the program. If neither condition is true, it does nothing. This can be used to add checks that the I/O in a program is going well; however, it is mostly useful only for small programs, because more serious programs need to handle the errors more gracefully. .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strcins.30000664000175000017500000000375711767436103013360 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strcins.3,v 1.1 1994/07/22 21:02:15 liw Exp $" .\" .TH STRCINS 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strcins \- insert a character at the beginning of a string .SH SYNOPSIS .nf #include void \fBstrins\fR(char *\fIstr\fR, int \fIc\fR); .SH DESCRIPTION \fIstrcins\fR inserts the character \fIc\fR at the beginning of the string \fIstr\fR. The target string must contain enough memory to hold the result. .SH "SEE ALSO" publib(3), strdel(3), strins(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strrev.30000664000175000017500000000462311767436705013221 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strrev.3,v 1.3 1994/06/20 20:30:30 liw Exp $" .\" .TH STRREV 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strrev \- reverse a string in place .SH SYNOPSIS .nf #include char *\fBstrrev\fR(char *\fIstr\fR); .SH DESCRIPTION \fIstrrev\fR reverses the argument string in place, i.e., it swaps the \fIi\fRth character from the beginning with the \fIi\fRth character from the end. .SH "RETURN VALUE" \fIstrrev\fR returns its argument. .SH EXAMPLE Reversing "dlrow, elloh" would be done like the following. .sp 1 .nf .in +5 char str[] = "dlrow, elloh"; puts(strrev(str)); .in -5 .sp 1 .fi This would output "hello, world". Note that using the string literal as the argument would be an error, since it is not allowable to modify string literals. .SH BUGS Does not automatically detect palindromes, nor automatically return without doing anything. .SH "SEE ALSO" publib(3), memrev(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memoverlap.30000664000175000017500000000447611767435760014051 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memoverlap.3,v 1.1 1994/02/05 17:09:24 liw Exp $" .\" .TH MEMOVERLAP 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memoverlap \- check whether two memory blocks overlap .SH SYNOPSIS .nf #include int \fBmemoverlap\fR(const void *\fIt\fR, size_t \fIts\fR, const void *\fIs\fR, size_t \fIss\fR); .SH DESCRIPTION \fImemoverlap\fR checks whether the memory blocks \fIt\fR--(\fIt+ts-1\fR) and \fIs\fR--(\fIs+ss-1\fR) overlap. Neither pointer argument may be NULL, but the sizes may be 0. The memory blocks can be arbitrary, they do not have to be part of the same array. Therefore, this function hides the unportable pointer comparison that one would otherwise rely on. .SH "RETURN VALUE" \fImemoverlap\fR returns 0 if the blocks do not overlap, and nonzero if they do. .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strmtrim.30000664000175000017500000000423211767436676013560 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strmtrim.3,v 1.1 1994/06/20 20:30:21 liw Exp $" .\" .TH STRMTRIM 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strmtrim \- replace multiple white spaces with single blanks within string .SH SYNOPSIS .nf #include char *\fBstrmtrim\fR(char *\fIstr\fR); .SH DESCRIPTION \fIstrmtrim\fR will replace every run of whitespace characters (as defined by \fIisspace\fR(3)) with a single blank. It will not touch leading and trailing whitespace (use \fIstrltrim\fR(3) and \fIstrrtrim\fR(3) for those). .SH "RETURN VALUE" \fIstrmtrim\fR will return the value of its argument. .SH "SEE ALSO" publib(3), strtrim(3), strltrim(3), strrtrim(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memdel.30000664000175000017500000000422311767435721013130 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memdel.3,v 1.1 1994/06/20 20:29:51 liw Exp $" .\" .TH MEMDEL 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memdel \- remove bytes from beginning of memory block .SH SYNOPSIS .nf #include void *\fBmemdel\fR(void *\fIp\fR, size_t \fIsize\fR, size_t \fIn\fR); .SH DESCRIPTION \fImemdel\fR moves the contents of the block pointed to by \fIp\fR towards the beginning, \fIn\fR steps. The values of the last \fIn\fR bytes of the block are indeterminate. .PP \fIp\fR must not be a null pointer. \fIsize\fR and \fIn\fR may be zero. .SH "RETURN VALUE" \fImemdel\fR returns its first argument. .SH "SEE ALSO" publib(3), strdel(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strendzap.30000664000175000017500000000427011767436144013701 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strendzap.3,v 1.3 1994/07/22 12:22:50 liw Exp $" .\" .TH STRENDZAP 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strendzap \- remove pattern from end of str, if it is there .SH SYNOPSIS .nf #include int \fBstrendzap\fR(char *\fIstr\fR, const char *\fIpat\fR); .SH DESCRIPTION \fIstrendzap\fR removes \fIpat\fR from the end of \fIstr\fR if it is there. Otherwise, it does nothing. .SH "RETURN VALUE" \fIstrendzap\fR returns non-zero if it removed anything, 0 if not. .SH EXAMPLE To remove the suffix .c from the end of a filename, you might do this: .sp 1 .nf .in +5 #include strendzap(filename, ".c"); .in -5 .SH "SEE ALSO" publib(3), strzap(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strchange.30000664000175000017500000000426711767436075013656 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strchange.3,v 1.1 1994/06/20 20:30:07 liw Exp $" .\" .TH STRCHANGE 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strchange \- replace beginning of string with beginning of another string .SH SYNOPSIS .nf #include char *\fBstrchange\fR(char *\fIstr\fR, size_t \fIchangelen\fR, const char *\fInew\fR, size_t \fInewlen\fR); .SH DESCRIPTION \fIstrchange\fR will replace \fIchangelen\fR characters from the beginning of \fIstr\fR with \fInewlen\fR characters from the beginning of \fInew\fR. The rest of \fIstr\fR will moved appropriately. .SH "RETURN VALUE" \fIstrchange\fR will return its first argument. .SH "SEE ALSO" publib(3), strcpy(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/stack.30000664000175000017500000000415111767436051012767 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-stack:$Id: stack.3,v 1.2 1994/02/03 17:34:05 liw Exp $" .\" .TH STACK 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME stack_create, stack_destroy, stack_pop, stack_is_empty, stack_copy, stack_push \- manipulate stacks .SH SYNOPSIS .nf #include .br Stack *\fBstack_create\fR(void); void \fBstack_destroy\fR(Stack *); void *\fBstack_pop\fR(Stack *); int \fBstack_is_empty\fR(Stack *); Stack *\fBstack_copy\fR(Stack *); int \fBstack_push\fR(Stack *, void *\fIdata\fR, size_t \fIbytes\fR); .SH "DESCRIPTION" These functions operate on stacks. This manual page is shortish. .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strtrexpand.30000664000175000017500000000444611767436723014255 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strtrexpand.3,v 1.1 1994/06/20 20:30:41 liw Exp $" .\" .TH STRTREXPAND 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strtrexpand \- expand tr-like notation in string .SH SYNOPSIS .nf #include void \fBstrtrexpand\fR(char *\fItgt\fR, const char *\fIsrc\fR); .SH DESCRIPTION \fIstrtrexpand\fR will convert shorthand notation similar to that used by \fItr\fR(1) into the equivalent longhand notation. The supported short forms are: .TP 8 \fIa\fR-\fIb\fR All characters from \fIa\fR to \fIb\fR, inclusive, in the order given by their character codes. .TP \fI\\a\fR The character \fIa\fR. .TP \fI\\o \\oo \\ooo\fR Character with octal code \fIo\fR, \fIoo\fR, or \fIooo\fR, respectively. .SH "RETURN VALUE" \fIstrtrexpand\fR returns nothing. .SH "SEE ALSO" publib(3), tr(1) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/fnpathfind.30000664000175000017500000000553611767435652014021 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-fname:$Id: fnpathfind.3,v 1.2 1994/02/03 17:34:01 liw Exp $" .\" .TH FNPATHFIND 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME fnpathfind \- find a file in a list of directories .SH SYNOPSIS .nf #include .sp 1 int \fBfnpathfind\fR(const char *\fIpath\fR, const char *\fItgt\fR, char *\fIres\fR, size_t \fImax\fR); .SH "DESCRIPTION" \fIpathfind\fR looks for a file in a list of directories. The argument `path' is a colon separated list of directories, typically the contents of an environment variable like PATH, MANPATH, or CDPATH. The function will go through the directories in the path and look in each directory for a file given in argument `target' until it finds it. Only an exact match is reported, no wild cards or globbing. .PP The names that are matched are formed by taking an element from the path and prepending it to target. An empty element means the current directory, as does the name ".". .PP The function returns -1 for failure (not found or error), or the total size for the full name (the full name may have been truncated when stored into result). .SH BUGS The function uses dynamic memory allocation and may therefore fail due to insufficient memory. .PP It is not trivial to know in which directory the search ended. This makes is difficult to continue the search. .SH "SEE ALSO" publib(3), fname(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strright.30000664000175000017500000000411611767436706013540 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strright.3,v 1.1 1994/06/20 20:30:31 liw Exp $" .\" .TH STRRIGHT 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strright \- return a pointer to the beginning of the rightmost n chars in a string .SH SYNOPSIS .nf #include char *\fBstrright\fR(const char *\fIs\fR, size_t \fIn\fR); .SH DESCRIPTION \fIstrright\fR will return a pointer to the first of the \fIn\fR rightmost characters (not counting the '\\0') in the string \fIs\fR. It does \fInot\fR make a copy of the string, but will return a pointer into the argument string. .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/struncstr.30000664000175000017500000000427011767436726013744 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: struncstr.3,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" .\" .TH STRUNCSTR 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME struncstr \- convert printable C string notation to a memory block .SH SYNOPSIS .nf #include void \fBstruncstr\fR(void *\fIblock\fR, const char *\fIstr\fR, size_t \fImax\fR); .SH DESCRIPTION \fIstruncstr\fR converts a C string literal to the memory block it describes by converting all escape sequences to single characters. See a C reference manual or \fIstrcstr\fR(3) for a description of the C string literal notation. .PP \fImax\fR is the maximum number of characters to store into the memory block. .SH "SEE ALSO" publib(3), strcstr(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strtrim.30000664000175000017500000000453011767436725013377 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strtrim.3,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" .\" .TH STRTRIM 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strtrim \- remove leading and trailing whitespace .SH SYNOPSIS .nf #include char *\fBstrtrim\fR(char *\fIs\fR); .SH DESCRIPTION \fIstrtrim\fR removes all whitespace characters from the beginning and the end of a string. As whitespace is counted everything for which \fIisspace\fR(3) returns true. .SH "RETURN VALUE" \fIstrtrim\fR returns its argument. .SH EXAMPLE To remove whitespace from the beginning and end of all lines, you might do the following: .sp 1 .nf .in +5 #include int main(void) { char line[512]; while (fgets(line, sizeof(line), stdio) != NULL) { strtrim(line); printf("%s", line); } return 0; } .in -5 .SH "SEE ALSO" publib(3), strrtrim(3), strltrim(3), isspace(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/stracat.30000664000175000017500000000521311767436060013323 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: stracat.3,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" .\" .TH STRACAT 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME stracat \- concatenate many strings into an allocated memory block .SH SYNOPSIS .nf #include char *\fBstracat\fR(const char *\fIs\fR, ...); .SH DESCRIPTION \fIstracat\fR will allocate a block of memory with malloc and concatenate all arguments strings into this block. The user is supposed to free the returned block. The end of the argument list is signalled by a null pointer. .SH "RETURN VALUE" \fIstracat\fR returns a pointer to the allocated block, or NULL if it could not be allocated. .SH EXAMPLE To concatenate "hello, " and "world", one might say the following. .sp 1 .nf .in +5 p = stracat("hello, ", "world", (char *)NULL); if (p != NULL) puts(p); .in -5 .sp 1 Please note that it is necessary to case NULL as in the example above, since there is no information about the type of the argument available in the prototype, and since an unadorned NULL might not be of the correct type. (See any good C reference book or the comp.lang.c FAQ for more information.) .SH "SEE ALSO" publib(3), strcat(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memarrfill.30000664000175000017500000000417311767435714014025 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memarrfill.3,v 1.1 1994/07/12 21:11:35 liw Exp $" .\" .TH MEMARRFILL 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memarrfill \- fill an array with the value of its first element .SH SYNOPSIS .nf #include void *\fBmemarrfill\fR(void *\fIarr\fR, size_t \fIelsize\fR, size_t \fInelem\fR); .SH DESCRIPTION \fImemarrfill\fR sets all elements the array \fIarr\fR to the value of its first element. The array has \fInelem\fR elements (including the first one), each of which is \fIelsize\fR bytes big. .SH "RETURN VALUE" \fImemarrfill\fR returns its first argument. .SH "SEE ALSO" publib(3), memfill(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strgsub.30000664000175000017500000000522511767436152013360 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ .\" part of publib .\" "@(#)publib-strutil:$Id: strgsub.3,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" .\" .TH STRGSUB 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strgsub \- substitute all occurences of pattern with another string .SH SYNOPSIS .nf #include int \fBstrgsub\fR(char *\fIstr\fR, const char *\fIpat\fR, const char *\fIsub\fR, size_t \fImax\fR); .SH DESCRIPTION \fIstrgsub\fR finds all occurences of the pattern \fIpat\fR in the string \fIstr\fR (using a method similar to \fIstrstr\fR(3) to find the occurrences, i.e., no regular expressions), and replaces each with \fIsub\fR. If \fIpat\fR does not occur in \fIstr\fR, no substitution is made. The size (including the terminating '\\0') of the string after the substitutions may be at most \fImax\fR chars. If it would be larger, no substitutions are made. .PP Of course, if \fIsub\fR is an empty string, the occurences of the pattern are deleted from the string. .SH "RETURN VALUE" \fIstrgsub\fR returns the number of substitutions made, or -1 if the result would not have fit into \fImax\fR chars. .SH EXAMPLE To substitute every "foo" with "bar" in a line, one might do the following. .sp 1 .nf .in +5 strgsub(line, "foo", "bar", strlen(line)+1); .in -5 .SH "SEE ALSO" publib(3), strstr(3), strsub(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memins.30000664000175000017500000000472111767435735013165 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memins.3,v 1.2 1994/06/20 20:29:53 liw Exp $" .\" .TH MEMINS 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memins \- insert bytes at beginning of memory block .SH SYNOPSIS .nf #include void *\fBmemins\fR(void *\fItgt\fR, size_t \fItgtsize\fR, const void *\fIsrc\fR, size_t \fIsrcsize\fR); .SH DESCRIPTION \fImemins\fR inserts \fIsrcsize\fR bytes from \fIsrc\fR at the beginning of \fItgt\fR, but moves the first \fItgtsize\fR out of the way. The source and target memory blocks must not overlap. .SH "RETURN VALUE" \fImemins\fR returns its first argument. .SH EXAMPLE To insert a new element at the \fIi\fRth position of an array, one might do the following. .sp 1 .nf .in +5 int new, array[10]; memins(array+i, (10-i-1)*sizeof(array[0]), &new, sizeof(new)); .in -5 .sp 1 .fi Please note that the above code carefully avoids the trap of moving the last element of the array past the end of the array. .SH "SEE ALSO" publib(3), strins(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memrmem.30000664000175000017500000000425211767436014013322 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memrmem.3,v 1.1 1994/06/20 20:30:00 liw Exp $" .\" .TH MEMRMEM 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memrmem \- find last occurence of memory block within another memory block .SH SYNOPSIS .nf #include void *\fBmemrmem\fR(const void *\fIv\fR, size_t \fIsize\fR, const void *\fIpat\fR, size_t \fIpatsize\fR); .SH DESCRIPTION \fImemrmem\fR finds the last occurence of memory block \fIpat\fR within memory block \fIv\fR. .SH "RETURN VALUE" \fImemrmem\fR returns a pointer to the first byte of the match, if it finds any, or a null pointer if there are no matches. .SH "SEE ALSO" publib(3), memmem(3), strstr(3), strrstr(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strcstr.30000664000175000017500000000633011767436111013364 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strcstr.3,v 1.3 1996/07/16 12:25:39 liw Exp $" .\" .TH STRCSTR 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strcstr \- convert memory block to printable C string notation .SH SYNOPSIS .nf #include void \fBstrcstr\fR(char *\fIstr\fR, size_t \fImax\fR, const void *\fIblock\fR, size_t \fIn\fR); .SH DESCRIPTION \fIstrcstr\fR converts the contents of an arbitrary memory block (which need not be a zero terminated string) into a printable notation using normal C string literal syntax. This can be used for example to store potentially binary data in a file, or in debugging outputs. .PP All characters for which there is a simple shorthand escape sequence (', ", ?, \\, \\a, \\b, \\f, \\n, \\r, \\t, \\v) are stored using that notation. \\0 is stored as \\0. All other non-printable characters are stored using a hexadecimal escape sequence. All other printable characters are stored as is. .PP The \fIisprint\fR(3) macro is used to determine whether a character is printable (i.e., whether it is printed as is, or using special notation). Therefore, the output depends on the locale. .SH "RETURN VALUE" \fIstrcstr\fR returns nothing. .SH EXAMPLE The following code dumps input to the standard output in a guaranteed (modulo locale bugs) printable format. It might be used for debugging. .sp 1 .nf .in +5 #include #include int main(void) { char line[512]; char cstr[512*(CHAR_BIT/4+1+2)+1]; /* +2 for \\x, +1 for \\0, the rest to be able to store the hex code for 512 chars. */ while (fgets(line, sizeof(line), stdin) != NULL) { strcstr(cstr, sizeof(cstr), line, strlen(line)); printf("%s\n", cstr); } return 0; } .in -5 .SH "SEE ALSO" publib(3), strins(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/iset.30000664000175000017500000000600411767435676012641 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-iset:$Id: iset.3,v 1.2 1994/02/03 17:27:58 liw Exp $" .\" .TH ISET 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME iset_create, iset_destroy, iset_copy, iset_is_empty, iset_add, iset_add_range, iset_remove, iset_remove_range, iset_clear, iset_contains, iset_union, iset_diff, iset_isect, iset_range, iset_nth_range \- manipulate sets of integers .SH SYNOPSIS .nf #include .sp 1 Iset *\fBiset_create\fR(void); void \fBiset_destroy\fR(Iset *\fIis\fR); Iset *\fBiset_copy\fR(const Iset *\fIis\fR); .sp 1 int \fBiset_is_empty\fR(const Iset *\fIis\fR); int \fBiset_add\fR(Iset *\fIis\fR, long \fInumber\fR); int \fBiset_add_range\fR(Iset *\fIis\fR, long \fInumber1\fR, long \fInumber2\fR); int \fBiset_remove\fR(Iset *\fIis\fR, long \fInumber\fR); int \fBiset_remove_range\fR(Iset *\fIis\fR, long \fInumber1\fR, long \fInumber2\fR); void \fBiset_clear\fR(Iset *\fIis\fR); int \fBiset_contains\fR(const Iset *\fIis\fR, long \fInumber\fR); int \fBiset_union\fR(Iset *\fIis1\fR, const Iset *\fIis2\fR); int \fBiset_diff\fR(Iset *\fIis1\fR, const Iset *\fIis2\fR); int \fBiset_isect\fR(Iset *\fIis1\fR, const Iset *\fIis2\fR); void \fBiset_range\fR(const Iset *\fIis\fR, long *\fIlowest\fR, long *\fIhighest\fR); int \fBiset_nth_range\fR(const Iset *\fIis\fR, long \fIn\fR, long *\fIlo\fR, long *\fIhi\fR); .SH "DESCRIPTION" These functions operate on sets of integers (of type long). You clever people will know how to use them without my help, which saves me from writing a manual page. .SH "SEE ALSO" publib(3), bitarr(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/tbuf.30000664000175000017500000000702411767436733012633 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" "@(#)publib-tbuf:$Id: tbuf.3,v 1.2 2004/08/05 08:48:21 liw Exp $" .TH TBUF 3 .SH NAME tbuf_create, tbuf_destroy, tbuf_copy, tbuf_cat, tbuf_length, tbuf_chars \- manipulate text editor buffer .SH SYNOPSIS .nf .B #include .sp .BI "Tbuf *tbuf_create(const char *" chars ", size_t " len ");" .BI "void tbuf_destroy(Tbuf *" tbuf ");" .BI "Tbuf *tbuf_copy(Tbuf *" tbuf ", size_t " offset ", size_t" len ");" .BI "Tbuf *tbuf_cat(Tbuf *" tbuf ", Tbuf * " tbuf ");" .BI "size_t tbuf_length(Tbuf *" tbuf ");" .BI "void tbuf_chars(char *" chars ", Tbuf *" tbuf ", size_t " offset ", size_t " len ");" .fi .SH DESCRIPTION These routines create and manipulate simple text editor buffers, which can also be thought of as arbitrarily large text strings. The buffers are one-dimensional (i.e., not automatically divided into lines), and are indexed with character offsets. They are 8-bit and binary clean, i.e., they may contain any 8-bit characters, including the zero byte ('\\0'). .PP .B tbuf_create creates a buffer from a C character array, and .B tbuf_destroy destroys it. Once it's created, a buffer may not be modified. Instead, a new buffer needs to be created, using .B tbuf_cat and .BR tbuf_copy . They create the new buffer so that it shares as much memory as possible with the old buffer, so the immutability does not necessarily waste memory much. By never changing a buffer, it is rather simple to implement undo and redo: you only need to keep a list of buffers and display the suitable one to the user. The caller should remember to call .B tbuf_destroy for unnecessary buffers, of course. .PP .B tbuf_length returns the number of characters in the buffer. .B tbuf_copy copies part of a buffer into a C character array. The array is .I not zero-terminated; the caller must do it himself. .SH "RETURN VALUE" .BR tbuf_create , .BR tbuf_copy , and .B tbuf_cat return a pointer to the new buffer, or NULL if the operation failed. .PP .B tbuf_length returns the number of characters in the buffer. .PP .B tbuf_destroy and .B tbuf_chars return nothing and cannot fail. .SH "SEE ALSO" .BR publib "(3), " sbuf "(3)" .SH AUTHOR Lars Wirzenius, liw@iki.fi. publib-0.40/man/stranaxfrm.30000664000175000017500000000472711767436067014067 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: stranaxfrm.3,v 1.1 1994/06/20 20:30:05 liw Exp $" .\" .TH STRANAXFRM 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME stranaxfrm \- make a string into canonical form for anagram comparison .SH SYNOPSIS .nf #include char *\fBstranaxfrm\fI(char *\fIstr\fR); .SH DESCRIPTION \fIstranaxfrm\fR transforms a string into a canonical form for anagram comparisons. To check whether two strings are anagrams of each other (i.e., they contain the same characters, but in different order), compare their canonical forms. The canonical form merely has all the characters in the string sorted into ascending order. .PP To write a program to find anagrams, first convert a word list into canonical order, then look up words in that version of the word list by transforming them also to canonical order. .SH "RETURN VALUE" \fIstranaxfrm\fR returns its argument. .SH BUGS This function is of a whimsical nature. .SH "SEE ALSO" publib(3), strcmp(3), strcasecmp(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strhash.30000664000175000017500000000457011767436616013352 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strhash.3,v 1.1 1994/06/20 20:30:13 liw Exp $" .\" .TH STRHASH 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strhash \- hash function for strings .SH SYNOPSIS .nf #include unsigned long \fBstrhash\fR(const char *\fIs\fR); .SH DESCRIPTION \fIstrhash\fR is a hash function for strings. It uses an algorithm that tries to be good in most cases, but it is often possible to use a better algorithm that takes better into account the characteristics of the data for a given application. However, \fIstrhash\fR often good enough; test it before spending time to develop a better one. .SH "RETURN VALUE" \fIstrhash\fR returns the computed hash value. Note that the value is not scaled into any particular range (all values that an unsigned long can take are possible). The caller will have to do the scaling himself. .SH "SEE ALSO" publib(3), hashtab(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strend.30000664000175000017500000000360511767436134013166 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strend.3,v 1.1 1994/06/20 20:30:10 liw Exp $" .\" .TH STREND 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strend \- return pointer to the terminating '\\0' of a string .SH SYNOPSIS .nf #include char *\fBstrend\fR(const char *\fIs\fR); .SH DESCRIPTION \fIstrend\fR will return a pointer to the '\\0' that terminates a string. .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strzap.30000664000175000017500000000407411767436732013217 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strzap.3,v 1.2 1994/07/22 12:22:53 liw Exp $" .\" .TH STRZAP 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strzap \- remove pattern from beginning of string, if it is there .SH SYNOPSIS .nf #include int \fBstrzap\fR(char *\fIstr\fR, const char *\fIpat\fR); .SH DESCRIPTION \fIstrzap\fR compares the beginning of \fIstr\fR with all of \fIpat\fR, and if they are the same, it removes the beginning from \fIstr\fR. .SH "RETURN VALUE" \fIstrzap\fR returns non-zero if it removed anything, 0 if not. .SH "SEE ALSO" publib(3), strendzap(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strinit.30000664000175000017500000000454111767436652013370 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strinit.3,v 1.1 1994/06/20 20:30:16 liw Exp $" .\" .TH STRINIT 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strinit \- initialize a string with a given character to a given length .SH SYNOPSIS .nf #include char *\fBstrinit\fR(char *\fIs\fR, int \fIc\fR, size_t \fIlen\fR) { .SH DESCRIPTION \fIstrinit\fR initializes the string pointed to by \fIs\fR to be of length \fIlen\fR, all characters being \fIc\fR, where the terminating '\e0' is \fInot\fR included in the length, i.e., the string will use \fIlen+1\fR characters. .SH "RETURN VALUE" \fIstrinit\fR will return \fIs\fR. .SH EXAMPLE To initialize a string to consist of twenty underscores, one would do the following. .sp 1 .nf .in +5 #include char string[21]; /* note 21 to make room for '\e0' */ strinit(string, '_', 20); .in -5 .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memshuffle.30000664000175000017500000000527711767436021014024 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memshuffle.3,v 1.1.1.1 1994/02/03 17:25:30 liw Exp $" .\" .TH MEMSHUFFLE 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memshuffle \- make an array be in random order .SH SYNOPSIS .nf #include void *\fBmemshuffle\fR(void *\fIblock\fR, size_t \fIelsize\fR, size_t \fIelnum\fR); .SH DESCRIPTION \fImemshuffle\fR will move around the elements of an array in a random fashion. It uses the standard library function \fIrand\fR(3) to get the pseudo-random numbers it needs. The caller must set a suitable seed with \fIsrand\fR(3). .SH "RETURN VALUE" \fImemshuffle\fR returns its first argument. .SH EXAMPLE To shuffle an integer array one might do the following. .sp 1 .nf .in +5 int array[4] = { 1, 2, 3, 4 }; memshuffle(array, sizeof(array[0]), 4); .in -5 .SH BUGS On many systems \fIrand\fR(3) is not of very good quality. However, it is the only random number generator that can be assumed to exist. Making it possible for the caller to provide an alternate source of random numbers (e.g., via a function pointer) is perhaps too more trouble than its worth. A better way would be for everyone to fix their \fIrand\fR's. .SH "SEE ALSO" publib(3), memrev(3), rand(3), srand(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strmaxcpy.30000664000175000017500000000520411767436672013725 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strmaxcpy.3,v 1.1.1.1 1994/02/03 17:25:29 liw Exp $" .\" .TH STRMAXCPY 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strmaxcpy \- copy at most a given number of characters of string .SH SYNOPSIS .nf #include char *\fBstrmaxcpy\fR(char *\fItgt\fR, const char *\fIsrc\fR, size_t \fIn\fR); .SH DESCRIPTION \fIstrmaxcpy\fR copies up to \fIn-1\fR characters from the beginning of \fIsrc\fR to \fItgt\fR, then adds a '\\0'. \fIn\fR must be at least 1. The target string must be large enough to hold the result. .PP Note that unlike \fIstrncpy\fR(3), this function always terminates the result with '\\0'. It also doesn't fill the result with extra '\\0' characters. .SH "RETURN VALUE" \fIstrmaxcpy\fR returns its first argument. .SH EXAMPLE To print out the first 69 characters of a string, you might do the following (although familiarity with printf's format string might be more useful in this case). .sp 1 .nf .in +5 #include #include void print42(const char *string) { char copy[43]; /* 42 + '\\0' */ puts(strmaxcpy(copy, string, sizeof(copy))); } .in -5 .SH "SEE ALSO" publib(3), strncpy(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memrchr.30000664000175000017500000000413311767435767013334 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memrchr.3,v 1.1 1994/08/28 18:13:41 liw Exp $" .\" .TH MEMRCHR 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memrchr \- find last occurence of a character within another memory block .SH SYNOPSIS .nf #include void *\fBmemrchr\fR(const void *\fIv\fR, int \fIc\fR, size_t \fIsize\fR); .SH DESCRIPTION \fImemrchr\fR finds the last occurence of character \fIc\fR within memory block \fIv\fR, of length \fIsize\fR. .SH "RETURN VALUE" \fImemrchr\fR returns a pointer to the the match, if it finds any, or a null pointer if it doesn't. .SH "SEE ALSO" publib(3), memchr(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strndup.30000664000175000017500000000422111767436700013360 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strndup.3,v 1.1 1994/06/20 20:30:23 liw Exp $" .\" .TH STRNDUP 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strndup \- duplicate part of a string .SH SYNOPSIS .nf #include char *\fBstrndup\fR(const char *\fIstr\fR, size_t \fIn\fR); .SH DESCRIPTION \fIstrndup\fR will make a duplicate of the \fIn\fR first characters of \fIstr\fR, using \fImalloc\fR(3) to allocate memory for the duplicate. The caller is supposed to free the duplicate's memory when no longer needed. .SH "RETURN VALUE" \fIstrndup\fR will return a pointer to the duplicate, or NULL if no memory could be allocated. .SH "SEE ALSO" publib(3), strdup(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strins.30000664000175000017500000000423311767436660013213 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strins.3,v 1.2 1994/07/25 23:15:36 liw Exp $" .\" .TH STRINS 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strins \- insert a string at the beginning of another string .SH SYNOPSIS .nf #include char *\fBstrins\fR(char *\fItgt\fR, const char *\fIsrc\fR); .SH DESCRIPTION \fIstrins\fR inserts the \fIsrc\fR string at the beginning of the \fItgt\fR string. The strings must not overlap. The target string must contain enough memory to hold both strings. .SH "RETURN VALUE" \fIstrins\fR returns its first argument. .SH EXAMPLE See the manual page for \fIstrdel\fR(3) for an example. .SH "SEE ALSO" publib(3), strdel(3), strnins(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strltrim.30000664000175000017500000000467011767436667013565 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strltrim.3,v 1.1.1.1 1994/02/03 17:25:29 liw Exp $" .\" .TH STRLTRIM 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strltrim \- remove leading whitespace from string .SH SYNOPSIS .nf #include char *\fBstrltrim\fR(char *\fIs\fR); .SH DESCRIPTION \fIstrltrim\fR removes all leading whitespace characters from the beginning of a string, by moving everything starting from the first non-whitespace character to the beginning of the string. As whitespace is counted everything for which \fIisspace\fR(3) returns true. .SH "RETURN VALUE" \fIstrltrim\fR returns its argument. .SH EXAMPLE To remove all indentation from all lines in a program, you might do the following: .sp 1 .nf .in +5 #include int main(void) { char line[512]; while (fgets(line, sizeof(line), stdio) != NULL) { strltrim(line); printf("%s", line); } return 0; } .in -5 .SH "SEE ALSO" publib(3), strrtrim(3), strtrim(3), isspace(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/log.30000664000175000017500000001030011767435705012441 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-framework:$Id: log.3,v 1.4 1997/05/09 13:49:05 liw Exp $" .\" .TH LOG 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME log \- simple log file output .SH SYNOPSIS .nf #include .sp 1 int \fBlog_open\fR(const char *\fIfilename\fR, int \fImin_level\fR); int \fBlog_add\fR(FILE *\fIf\fR, int \fImin_level\fR); void \fBlog_set_level\fR(int \fIlog_handle\fR, int \fImin_level\fR); void \fBlog_set_localtime\fR(int \fIlog_handle\fR, int \fIuse_localtime\fR); int \fBlog_close\fR(void); void \fBlog_off\fR(void); void \fBlog_on\fR(void); void \fBlog_chat\fR(const char *\fIfmt\fR, ...); void \fBlog_note\fR(const char *\fIfmt\fR, ...); void \fBlog_warn\fR(const char *\fIfmt\fR, ...); void \fBlog_error\fR(const char *\fIfmt\fR, ...); void \fBlog_fatal\fR(const char *\fIfmt\fR, ...); void \fBlog_printf\fR(int \fIlevel\fR, const char *\fIfmt\fR, ...); .SH DESCRIPTION These routines implement a simple log file facility. There can be several log files open at the same time (up to 256, but limits on the number of concurrently open files may set a lower limit). Each log message is associated with a level of severity, which can be any integer, but the levels \fIlog_level_chat\fR, \fIlog_level_note\fR, \fIlog_level_warn\fR, \fIlog_level_error\fR, and \fIlog_level_fatal\fR are predefined, and can easily be used by calling the respective print functions (\fIlog_chat\fR, etc.); for other log levels, \fIlog_printf\fR must be called. Each open log file is associated by a minimum level. Messages below the minimum level are not output to that log file. .PP The log printing functions attempt to force the messages to be written to the disk (or wherever they're going), using \fIfflush\fR(3). This will hopefully avoid problems due to delayed messages that buffering may cause. .PP Log files are opened with \fIlog_open\fR. An already open file (such as \fIstderr\fR) can be added to the list of open log files with \fIlog_add\fR. (Note that the file should be opened in append mode, "a" to \fIfopen\fR(3)). Both of these functions set the minimum level as well. They return a log file handle, which is used to identify the log file to the other functions. The minimum level can later be adjusted with \fIlog_set_level\fR. \fIlog_close\fR closes all log files. .PP By default, times in log files are reported in UTC, but each log file can be set to use local time with \fIlog_set_localtime\fR. .PP Logging may temporarily be turned off for all log files at the same time with \fIlog_off\fR. It can be turned back on with \fIlog_on\fR. .SH "RETURN VALUE" \fIlog_open\fR and \fIlog_add\fR return a log file handle. \fIlog_close\fR returns -1 if the closing of any log file failed, 0 if all went well. .SH "SEE ALSO" publib(3), syslog(2) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/strdel.30000664000175000017500000000473211767436120013161 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strdel.3,v 1.1.1.1 1994/02/03 17:25:29 liw Exp $" .\" .TH STRDEL 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strdel \- delete characters from beginning of string .SH SYNOPSIS .nf #include char *\fBstrdel\fR(char *\fIs\fR, size_t \fIn\fR); .SH DESCRIPTION \fIstrdel\fR removes the first \fIn\fR characters of \fIs\fR. If \fIn\fR is greater than the length of the string, all characters in the string (not counting '\\0') are removed but no more. .SH "RETURN VALUE" \fIstrdel\fR returns its first argument. .SH EXAMPLE To change all occurences of "Pascal" in the input to "Yuck!", you might do the following: .sp 1 .nf .in +5 #include #include #include int main(void) { char line[512]; while (fgets(line, sizeof(line), stdio) != NULL) { while ((p = strstr(line, "Pascal")) != NULL) { strdel(p, 6); strins(p, "Yuck!"); } printf("%s", line); } return 0; } .in -5 .SH "SEE ALSO" publib(3), strins(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/bitarr.30000664000175000017500000000706511767435501013153 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-bitarr:$Id: bitarr.3,v 1.3 1994/08/28 17:06:25 liw Exp $" .\" .TH BITARR 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME ba_and_ba, ba_clear, ba_clear_all, ba_copy, ba_create, ba_destroy, ba_not, ba_or_ba, ba_or_not_ba, ba_query, ba_resize, ba_set, ba_xor_ba \- bit array manipulation .SH SYNOPSIS .nf #include .sp 1 Bitarr *\fBba_create\fR(void); void \fBba_destroy\fR(Bitarr *\fIba\fR); Bitarr *\fBba_copy\fR(const Bitarr *\fIba\fR); int \fBba_resize\fR(Bitarr *\fIba\fR, size_t \fImax_number\fR); .sp 1 int \fBba_set\fR(Bitarr *\fIba\fR, unsigned \fInumber\fR); int \fBba_clear\fR(Bitarr *\fIba\fR, unsigned \fInumber\fR); void \fBba_clear_all\fR(Bitarr *\fIba\fR); int \fBba_query\fR(Bitarr *\fIba\fR, unsigned \fInumber\fR); void \fBba_and_ba\fR(Bitarr *\fIba1\fR, const Bitarr *\fIba2\fR); int \fBba_or_ba\fR(Bitarr *\fIba1\fR, const Bitarr *\fIba2\fR); void \fBba_xor_ba\fR(Bitarr *\fIba1\fR, const Bitarr *\fIba2\fR); void \fBba_or_not_ba\fR(Bitarr *\fIba1\fR, const Bitarr *\fIba2\fR); void \fBba_not\fR(Bitarr *\fIba\fR); .SH "DESCRIPTION" These functions operate on bit arrays. \fIba_create\fR creates one and \fIba_destroy\fR it. \fIba_copy\fR makes a copy of one, and \fIba_resize\fR changes its size. The bit arrays resize themselves automatically, but \fIba_resize\fR can be used to get rid of extra memory allocated for the array, or to make sure there is enough memory allocated for the array (so that further operations are guaranteed to work). .PP \fIba_set\fR sets one element (bit) in the array to 1. \fIba_clear\fR clears one element (sets it to 0), \fIba_clear_all\fR clears all elements. \fIba_query\fR returns the current value of an element. .PP \fIba_and_ba\fR, \fIba_or_ba\fR, \fIba_xor_ba\fR, and \fIba_or_ba\fR do logical operations on two arrays. The result will be stored in the first one. \fIba_not\fR will invert all elements in the array. .SH RETURNS \fIba_create\fR and \fIba_copy\fR return a pointer to the new array, or NULL if they fail. Those that return an integer, return -1 for error, non-negative for success. .SH "SEE ALSO" publib(3), iset(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/hash.30000664000175000017500000001121611767677564012625 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 2012 Antti-Juhani Kaijanaho. .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" .TH HASH 3 "C Programmer's Manual" "Publib" "C Programmer's Manual" .SH NAME hash_create, hash_destroy, hash_install, hash_lookup, hash_uninstall, hash_iter \- generic hash tables .SH SYNOPSIS .nf #include .sp 1 Hashtab *\fBhash_create\fR(unsigned long (*\fIfun\fR)(void *), int (*\fIcmp\fR)(const void *, const void *)); void \fBhash_destroy\fR(Hashtab *\fIht\fR); void *\fBhash_install\fR(Hashtab *\fIht\fR, void *\fIdata\fR, size_t \fIsize\fR); void *\fBhash_lookup\fR(Hashtab *\fIht\fR, void *\fIdata\fR); int \fBhash_uninstall\fR(Hashtab *\fIht\fR, void *\fIdata\fR); int \fBhash_iter\fR(Hashtab *\fIht\fR, int (*\fIdoit\fR)(void *, void *), void *\fIparam\fR); .SH "DESCRIPTION" These functions implement generic hash tables. The table is created by \fIhash_create\fR and destroyed by \fIhash_destroy\fR. The \fIfun\fR argument is a pointer to the hashing function, which must convert a datum to an unsigned long, which is then converted to an index into the hashing table. \fIcmp\fR is a \fIqsort\fR(3)-like comparison functions, used to compare to (wannabe) hash table elements. .PP \fIhash_install\fR installs a new datum into the table. A pointer to the data and the size of the data are given as the arguments. If the size is 0, only the pointer value is copied to the table. Otherwise a copy of the data is made into dynamically allocated memory. .PP \fIhash_lookup\fR attempts to find a datum in the hash table. A pointer to another datum is given as the argument. The comparison function should compare equal (return 0) the desired datum and this datum (but the argument needn't be a fully initialized datum, although that is up to the writer of the comparison function). There cannot be two elements in the hash table that are equal (the comparison function returns 0 for them). It is up to the user to handle collisions. .PP \fIhash_uninstall\fR removes an element from a table. The argument is a pointer to a datum that identifies the element. .PP \fIhash_iter\fR goes through every element in the hash table and calls the \fIdoit\fR function for each. The first argument it provides to \fIdoit\fR is the element in question, the second is whatever was given to \fIhash_iter\fR as \fIparam\fR. If \fIdoit\fR returns -1 or 0 for any element in the hash table, \fIhash_iter\fR immediately returns without going through the remaining elements in the hash table. Any other return value from \fIdoit\fR is ignored. .SH RETURNS \fIhash_create\fR returns a pointer to the new hash table, or NULL if it fails. .PP \fIhash_install\fR returns a pointer to an element in the table (either the installed one, or one that was already installed, if one tries to install the same datum twice). .PP \fIhash_uninstall\fR returns 0 if it found the element in the array, or -1 if it didn't. .PP \fIhash_lookup\fR return a pointer to the element it finds, or NULL if it doesn't find anything beautiful. .PP \fIhash_iter\fR returns -1, 0, or 1. If \fIhash_iter\fR receives a return value of -1 or 0 for some element from \fIdoit\fR, \fIhash_iter\fR immediately returns -1 or 0, respectively. In all other cases \fIhash_iter\fR returns 1. .SH "SEE ALSO" publib(3), qsort(3), bsearch(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/man/memfill.30000664000175000017500000000463111767435730013315 0ustar ajkajk.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" 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 ``AS IS'' AND ANY EXPRESS .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: memfill.3,v 1.1.1.1 1994/02/03 17:25:31 liw Exp $" .\" .TH MEMFILL 3 "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME memfill \- fill memory area with pattern .SH SYNOPSIS .nf #include void *\fBmemfill\fR(void *\fIbuf\fR, size_t \fIsize\fR, const void *\fIpat\fR, size_t \fIpatsize\fR); .SH DESCRIPTION \fImemfill\fR copies consecutive bytes from the pattern \fIpat\fR to consecutive bytes in the memory area \fIbuf\fR, wrapping around in \fIpat\fR when its end is reached. \fIpatsize\fR is the size of the pattern, \fIsize\fR is the size of the memory area. The pattern and the memory area must not be overlapping. .SH "RETURN VALUE" \fImemfill\fR returns its first argument. .SH EXAMPLE To initialize an integer array one might do the following. .sp 1 .nf .in +5 int temp, array[1024]; temp = 1234; memfill(array, sizeof(array), &temp, sizeof(temp)); .in -5 .SH "SEE ALSO" publib(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi) publib-0.40/priq/0000775000175000017500000000000011767707451012002 5ustar ajkajkpublib-0.40/priq/test-priq.c0000664000175000017500000000604611767417657014112 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: test-priq.c * Purpose: Test priority queue routines. * Author: Lars Wirzenius * Version: "@(#)publib:$Id: test-priq.c,v 1.1.1.1 1996/01/18 17:55:38 liw Exp $" */ #include #include #include #define N 10 static int ascending(const void *a, const void *b) { const int aa = *(const int *) a; const int bb = *(const int *) b; if (aa < bb) return -1; if (aa > bb) return 1; return 0; } static int descending(const void *a, const void *b) { return -ascending(a, b); } static void build(int *arr, int n) { while (n-- > 0) *arr++ = rand() % 10; } static void dump(int *arr, int n) { #if 0 printf("arr:"); while (n-- > 0) printf(" %d", *arr++); printf("\n"); #endif } static void check_order(Priq *pq, int n, int (*o)(const void *,const void *)) { int *p, *prev; prev = priq_remove(pq); while (n-- > 1) { p = priq_remove(pq); if (o(p, prev) < 0) errormsg(1, 0, "priority queue not in order"); prev = p; } if (!priq_is_empty(pq)) errormsg(1, 0, "priority queue is not empty after removals"); } static void check_insert(Priq *pq, int *arr, int n) { while (n-- > 0) { priq_insert(pq, arr, 0); if (priq_is_empty(pq)) errormsg(1, 0, "priority queue empty after insertion"); ++arr; } } int main(void) { int arr[N]; Priq *pq; __set_liberror(__complain_on_error | __exit_on_error); pq = priq_create(ascending); if (!priq_is_empty(pq)) errormsg(1, 0, "priority queue not empty after creation"); build(arr, N); dump(arr, N); check_insert(pq, arr, N); check_order(pq, N, ascending); build(arr, N); dump(arr, N); check_insert(pq, arr, N); priq_set_compare(pq, descending); check_order(pq, N, descending); printf("priority queues seem to work\n"); return 0; } publib-0.40/priq/priq.c0000664000175000017500000001324711767417657013136 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: priq.c * Purpose: Implementation of priority queues. * Author: Lars Wirzenius * Version: "@(#)publib:$Id: priq.c,v 1.1.1.1 1996/01/18 17:55:38 liw Exp $" */ #include #include #include #include "publib/priq.h" #include "publib/errormsg.h" /* * Prototypes for local functions. */ static int always_same(const void *, const void *); static void percolate_down(Priq *, size_t); /* * Function: priq_create * Purpose: Create a new priority queue. * Arguments: compare comparison function for data elements * (NULL means all elements are equal) * Return: Pointer to new queue, NULL on error (memory allocation). */ Priq *priq_create(int (*compare)(const void *, const void *)) { Priq *pq; pq = malloc(sizeof(*pq)); if (pq == NULL) { __publib_error("priq_create: out of memory"); return NULL; } dynarr_init(&pq->da, sizeof(void *)); pq->compare = compare ? compare : always_same; return pq; } /* * Function: priq_destroy * Purpose: Destroy a priority queue. * Arguments: pq pointer to priority queue * Return: None. */ void priq_destroy(Priq *pq) { assert(pq != NULL); dynarr_free(&pq->da); free(pq); } /* * Function: priq_is_empty * Purpose: Is a priority queue empty? * Arguments: pq pointer to priority queue * Return: 0 for not empty, 1 for empty. */ int priq_is_empty(Priq *pq) { assert(pq != NULL); return pq->da.used == 0; } /* * Function: priq_insert * Purpose: Insert new element into priority queue. * Arguments: pq pointer to priority queue * data pointer to data * size size of data * Return: -1 for failure, 0 for success. */ int priq_insert(Priq *pq, const void *data, size_t size) { void **arr; size_t i; assert(pq != NULL); if (dynarr_resize(&pq->da, pq->da.used + 1) == -1) return -1; if (size > 0) { data = memdup(data, size); if (data == NULL) { __publib_error("priq_insert: out of memory"); return -1; } } arr = pq->da.data; ++pq->da.used; if (pq->da.used == 1) i = 0; else { i = pq->da.used - 1; while (i > 0 && pq->compare(arr[i/2], data) > 0) { arr[i] = arr[i/2]; i /= 2; } } arr[i] = (void *) data; return 0; } /* * Function: priq_remove * Purpose: Remove and return smallest element from priority queue. * Arguments: pq pointer to priority queue * Return: Pointer to data. */ void *priq_remove(Priq *pq) { void *smallest, **arr; assert(pq != NULL); assert(!priq_is_empty(pq)); arr = pq->da.data; smallest = arr[0]; --pq->da.used; if (pq->da.used > 0) { arr[0] = arr[pq->da.used]; percolate_down(pq, 0); } return smallest; } /* * Function: priq_set_compare * Purpose: Change the comparison function and reorder the priority queue. * Arguments: pq pointer to priority queue * compare new comparison function * Return: Nothing. */ void priq_set_compare(Priq *pq, int (*compare)(const void *, const void *)) { size_t i; assert(pq != NULL); pq->compare = compare ? compare : always_same; for (i = pq->da.used / 2; i-- > 0; ) percolate_down(pq, i); } /* * Function: priq_dump * Purpose: Dump contents of priority queue to stdout. * Arguments: pq pointer to priority queue * Return: Nothing. * Note: Assumes elements are pointers to integers. */ void priq_dump(Priq *pq) { size_t i; int **arr; printf("priq:"); arr = pq->da.data; for (i = 0; i < pq->da.used; ++i) printf(" %d", *arr[i]); printf("\n"); } /********************************************************************** * Local functions follow */ /* * Function: always_same * Purpose: Comparison function that always returns "same". * Note: See qsort(3) for a description of comparison functions. */ int always_same(const void *a, const void *b) { return 0; } /* * Function: percolate_down * Purpose: Make sure a subtree in a priority queue is ordered correctly. * Arguments: pq pointer to priority queue * i root element of subtree * Note: See Weiss, ``Data Structures and Analysis'', page 181, for * a description. * Note: Only the subtree root may be in wrong place. */ static void percolate_down(Priq *pq, size_t i) { size_t n, child; void *x, **arr; arr = pq->da.data; n = pq->da.used-1; assert(i <= n); x = arr[i]; while ((child = i*2+1) <= n) { if (child != n && pq->compare(arr[child+1], arr[child]) < 0) ++child; if (pq->compare(x, arr[child]) <= 0) break; arr[i] = arr[child]; i = child; } arr[i] = x; } publib-0.40/distcheck.mk0000664000175000017500000000446311767656056013334 0ustar ajkajk# Copyright (c) 2012 Antti-Juhani Kaijanaho # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SHELL = /bin/sh echoexec = sh echoexec.sh all : exit 1 # see Makefile.in distcheck run_distcheck : tar zxf $(tgz) mv $(base) $(base).orig @echo "# TEST INSTALL" tar zxf $(tgz) cd $(base) && ./configure $(MAKE) -C $(base) DESTDIR=../dest install test -f dest/usr/local/lib/libpub.a test ! -x dest/usr/local/lib/libpub.a test -f dest/usr/local/include/publib.h test ! -x dest/usr/local/include/publib.h @set -e ; for f in $(includes) ; do \ bn=`basename $$f` ;\ $(echoexec) test -f dest/usr/local/include/publib/$$bn ;\ $(echoexec) test ! -x dest/usr/local/include/publib/$$bn ;\ done @set -e ; for f in $(manpages) ; do \ bn=`basename $$f` ;\ $(echoexec) test -f dest/usr/local/share/man/man3/$$bn.gz ;\ $(echoexec) test ! -x dest/usr/local/share/man/man3/$$bn.gz ;\ done rm -rf $(base) dest @echo "# TEST DIST" tar zxf $(tgz) cd $(base) && ./configure $(MAKE) -C $(base) DESTDIR=../dest/ dist test -f dest/$(tgz) cd dest && tar zxf $(tgz) touch dest/$(base)/foobar diff -Naur $(base).orig dest/$(base) publib-0.40/cmp/0000775000175000017500000000000011767707451011606 5ustar ajkajkpublib-0.40/cmp/cmp.c0000664000175000017500000000545311767417657012546 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * cmp.c -- comparison function for qsort, bsearch, and others * * Part of publib. See man page for more information * "@(#)publib-cmp:$Id: cmp.c,v 1.1.1.1 1993/11/20 17:01:45 liw Exp $" */ #include #include #include "publib/cmp.h" static size_t offset = 0; static int (*member_cmp)(const void *, const void *) = NULL; void cmp_set_offset(size_t off, int (*cmp)(const void *, const void *)) { assert(cmp != cmp_struct); offset = off; member_cmp = cmp; } int cmp_struct(const void *e1, const void *e2) { const char *p1 = e1; const char *p2 = e2; assert(member_cmp != NULL); return member_cmp(p1 + offset, p2 + offset); } #define CAT(a,b) a##b #define SIMPLE_CMP(name, type) \ int CAT(cmp_,name) (const void *e1, const void *e2) { \ type p1 = *(const type *)e1; \ type p2 = *(const type *)e2; \ if (p1 < p2) \ return -1; \ if (p1 == p2) \ return 0; \ return 1; \ } SIMPLE_CMP(char, char) SIMPLE_CMP(short, short) SIMPLE_CMP(int, int) SIMPLE_CMP(long, long) SIMPLE_CMP(schar, signed char) SIMPLE_CMP(uchar, unsigned char) SIMPLE_CMP(ushort, unsigned short) SIMPLE_CMP(uint, unsigned int) SIMPLE_CMP(ulong, unsigned long) SIMPLE_CMP(float, float) SIMPLE_CMP(double, double) SIMPLE_CMP(ldouble, long double) int cmp_charptr(const void *e1, const void *e2) { return strcmp(*(const char **)e1, *(const char **)e2); } int cmp_chararr(const void *e1, const void *e2) { return strcmp((const char *)e1, (const char *)e2); } publib-0.40/nntp/0000775000175000017500000000000011767707451012006 5ustar ajkajkpublib-0.40/nntp/nntpart.c0000664000175000017500000001516511767417657013656 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * File: nntpart.c * Purpose: Routines for manipulating Usenet articles * Author: Lars Wirzenius * CVS: "@(#)publib:$Id: nntpart.c,v 1.4 1996/04/08 22:27:54 liw Exp $" */ #include #include #include #include #include #include #include "publib/nntp.h" #include "publib/nntp.h" #include "publib/files.h" void nntp_init_article(struct nntp_article *art) { dynarr_init(&art->headers, sizeof(char *)); dynarr_init(&art->body, sizeof(char *)); } void nntp_clear_article(struct nntp_article *art) { size_t i; char **p; for (p = art->headers.data, i = 0; i < art->headers.used; ++i) free(p[i]); for (p = art->body.data, i = 0; i < art->body.used; ++i) free(p[i]); art->headers.used = 0; art->body.used = 0; } int nntp_add_header(struct nntp_article *art, const char *line) { char *p; if (art->headers.used == art->headers.alloc) if (dynarr_resize(&art->headers, art->headers.used + 1) == -1) return -1; p = strdup(line); if (p == NULL) return -1; ((char **)art->headers.data)[art->headers.used] = p; ++art->headers.used; return 0; } int nntp_add_body(struct nntp_article *art, const char *line) { char *p; if (art->body.used == art->body.alloc) if (dynarr_resize(&art->body, art->body.used + 1) == -1) return -1; p = strdup(line); if (p == NULL) return -1; ((char **)art->body.data)[art->body.used] = p; ++art->body.used; return 0; } int nntp_add_unique_header(struct nntp_article *art, const char *hdr, const char *s) { char **p, *buf; int i, j, ret; p = art->headers.data; if (nntp_find_header(&i, art, 0, hdr) != -1) { do { for (j = i; j < art->headers.used; ++j) p[j] = p[j+1]; --art->headers.used; } while (i < art->headers.used && isspace(p[i][0])); } buf = malloc(strlen(hdr) + 2 + strlen(s) + 2); if (buf == NULL) return -1; sprintf(buf, "%s: %s", hdr, s); ret = nntp_add_header(art, buf); free(buf); return ret; } int nntp_read_article_file(FILE *f, struct nntp_article *art) { char *line; assert(f != NULL); assert(art != NULL); nntp_init_article(art); while ((line = getaline(f)) != NULL && *line != '\0') { if (nntp_add_header(art, line) == -1) return -1; free(line); } while ((line = getaline(f)) != NULL) { if (nntp_add_body(art, line) == -1) return -1; free(line); } return 0; } int nntp_post_article(int fd, struct nntp_article *art) { char **p; int i; assert(fd > 0); assert(art != NULL); if (nntp_post(fd) == -1) return -1; p = art->headers.data; for (i = 0; i < art->headers.used; ++i) if (nntp_write_next_line(fd, p[i]) == -1) return -1; if (nntp_write_next_line(fd, "") == -1) return -1; p = art->body.data; for (i = 0; i < art->body.used; ++i) if (nntp_write_next_line(fd, p[i]) == -1) return -1; if (nntp_write_end_line(fd) == -1) return -1; return 0; } int nntp_write_article_file(FILE *f, struct nntp_article *art) { char **p; int i; assert(f != NULL); assert(art != NULL); p = art->headers.data; for (i = 0; i < art->headers.used; ++i) if (fprintf(f, "%s\n", p[i]) == EOF) return -1; if (fprintf(f, "\n") == EOF) return -1; p = art->body.data; for (i = 0; i < art->body.used; ++i) if (fprintf(f, "%s\n", p[i]) == -1) return -1; if (fprintf(f, "\n") == EOF) return -1; return 0; } int nntp_find_header(int *j, const struct nntp_article *art, int i, const char *hdr) { char **p; size_t hdr_len; assert(art != NULL); assert(j != NULL); assert(i >= 0); assert(hdr != NULL); assert(*hdr != '\0'); assert(strchr(hdr, ':') == NULL); hdr_len = strlen(hdr); for (p = art->headers.data; i < art->headers.used; ++i) { /* FIXME: the comparison below should be case _in_sensitive */ if (strncmp(p[i], hdr, hdr_len) == 0 && p[i][hdr_len] == ':') { *j = i; return 0; } } return -1; } int nntp_get_header(char **p, const struct nntp_article *art, int i) { assert(p != NULL); assert(art != NULL); assert(i >= 0); if (i >= art->headers.used) return -1; *p = ((char **) art->headers.data)[i]; return 0; } void nntp_dump_article(FILE *f, struct nntp_article *art) { char **p; int i; fprintf(f, "dumping article:---------------------\n"); for (p = art->headers.data, i = 0; i < art->headers.used; ++i) fprintf(f, "%s\n", p[i]); fprintf(f, "-------------------------------------\n"); for (p = art->body.data, i = 0; i < art->body.used; ++i) fprintf(f, "%s\n", p[i]); fprintf(f, "done---------------------------------\n"); } int nntp_set_date(struct nntp_article *art, time_t date) { static const char * const weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", }; static const char * const month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", }; char buf[1024]; struct tm *tm; assert(art != NULL); tm = gmtime(&date); sprintf(buf, "%s, %02d %s %02d %02d:%02d:%02d GMT", weekday[tm->tm_wday], tm->tm_mday, month[tm->tm_mon], tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); if (nntp_add_unique_header(art, "Date", buf) == -1) return -1; return 0; } publib-0.40/nntp/nntp.c0000664000175000017500000002320611767417657013142 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * nntp.c -- some routines for NNTP clients * * Lars Wirzenius * Part of Publib, see README and publib(3) for more info. * "@(#)colawatcher:$Id: nntp.c,v 1.3 2002/05/23 12:01:58 liw Exp $" */ #include #include #include #include #include #include #include #include #include #include #include #include #include extern int h_errno; #include "publib/errormsg.h" #include "publib/strutil.h" #include "publib/log.h" #include "publib/nntp.h" /* * The port number of the NNTP service. */ #define NNTP_PORT 119 /* * Should we log I/O with the NNTP server? If we do, the log level is * log_level_chat. */ static int log_input = 0; static int log_output = 0; /* * Local functions. */ static int send_cmd(int, const char *, ...); static int recv_response(int); static int read_line(int fd, char *buf); static int nread(int fd, void *buf, int need); int write_all(int fd, const void *s); /* * Set log_input and log_output. */ void nntp_do_logs(int input, int output) { assert(input == 0 || input == 1); assert(output == 0 || output == 1); log_input = input; log_output = output; } /* * Open a connection to the NNTP server. Set *fd to be a descriptor for * the connection (the client mustn't use it). Return -1 for error, * 0 for OK (posting not allowed), or 1 for OK (posting allowed); */ int nntp_open(int *fd, const char *server, int use_mode_reader) { int s, tries, resp; struct in_addr addr; struct sockaddr_in serv; struct hostent *he; const int max = 16; /* max # of retries for gethostby*-functions */ assert(server != NULL); if (isdigit(*server)) { addr.s_addr = inet_addr(server); tries = 0; do { he = gethostbyaddr((void*)&addr, sizeof(addr), AF_INET); } while (he == NULL && h_errno == TRY_AGAIN && ++tries < max); if (he == NULL) { __publib_error("gethostbyaddr failed"); return -1; } } else { tries = 0; do { he = gethostbyname(server); } while (he == NULL && h_errno == TRY_AGAIN && ++tries < max); if (he == NULL) { __publib_error("gethostbyname failed"); return -1; } } assert(he->h_addrtype == AF_INET); s = socket(AF_INET, SOCK_STREAM, 0); if (s == -1) { __publib_error("couldn't create socket"); return -1; } memset(&serv, 0, sizeof(serv)); serv.sin_family = AF_INET; serv.sin_port = htons(NNTP_PORT); memcpy(&serv.sin_addr, he->h_addr_list[0], he->h_length); if (connect(s, (struct sockaddr *) &serv, sizeof(serv)) == -1) { __publib_error("couldn't connect to server"); (void) close(s); return -1; } while ((resp = recv_response(s)) != -1 && resp != 200 && resp != 201) __publib_error("received unexpected response at startup"); if (use_mode_reader) { if (send_cmd(s, "mode reader") == -1) { (void) close(s); return -1; } while ((resp = recv_response(s)) != -1 && resp != 200 && resp != 201) { __publib_error("received unexpected response " "after `mode reader'"); } } *fd = s; return (resp == 200) ? 1 : 0; } /* * Close an NNTP connection. Return -1 for error, 0 for OK. */ int nntp_close(int fd) { if (close(fd) == -1) { __publib_error("error closing NNTP connection"); return -1; } return 0; } /* * Send the NEWNEWS command. Return -1 for error, 0 for OK. The message * identifiers must be read separately, using nntp_next_line. */ int nntp_newnews(int fd, const char *grp, const char *date, const char *time, const char *tz) { if (send_cmd(fd, "NEWNEWS %s %s %s%s%s", grp, date, time, *tz == '\0' ? "" : " ", tz) == -1) return -1; for (;;) { switch (recv_response(fd)) { case 230: return 0; case 400: case 500: case 501: case 502: case 503: return -1; } } /*NOTREACHED*/ } /* * Start posting an article. Return -1 for error, 0 for OK. If OK, then * caller must use nntp_write_next_line() and nntp_write_end_line() to * send the actual article. */ int nntp_post(int fd) { if (send_cmd(fd, "POST") == -1) return -1; if (recv_response(fd) == 340) return 0; return -1; } /* * Select a given group. Return -1 for error, 0 for OK. */ int nntp_group(int fd, const char *group) { if (send_cmd(fd, "GROUP %s", group) == -1) return -1; if (recv_response(fd) == 211) return 0; return -1; } /* * Ask for the head and body of the current article. Return 0 for OK * (read the text with nntp_next_line), or -1 for error. */ int nntp_get_current_article(int fd) { if (send_cmd(fd, "ARTICLE") == -1) return -1; if (recv_response(fd) == 220) return 0; return -1; } /* * Select next article. Return -1 for error, or 0 for OK (request text * of article with nntp_get_current_article). */ int nntp_goto_next_article(int fd) { if (send_cmd(fd, "NEXT") == -1) return -1; switch (recv_response(fd)) { case 223: return 1; case 421: return 0; } return -1; } /* * Read next line from the NNTP connection; for users, this should always * be a data line, not a numeric+textual response from the server. * Return -1 for error, 0 for EOF (no more lines) and 1 for OK. Set * *line to point to the correct line; an internal buffer that will be * changed by the next call. */ int nntp_next_line(int fd, char **line) { static char buf[1024]; /* should be long enough */ if (read_line(fd, buf) == -1) return -1; if (strcmp(buf, ".") == 0) return 0; if (buf[0] == '.') *line = buf+1; else *line = buf; return 1; } /* * Write next line of data to the server. If line begins with a dot, * prefix it with another dot. Return -1 for error, 0 for OK. * Note that the line must be at most 10000 characters long. */ int nntp_write_next_line(int fd, const char *line) { size_t n; char buf[10240]; assert(line != NULL); n = strlen(line); assert(n+1 < sizeof(buf)); *buf = '\0'; if (*line == '.') strcat(buf, "."); strcat(buf, line); strendzap(buf, "\n"); strendzap(buf, "\r"); if (send_cmd(fd, "%s", buf) == -1) return -1; return 0; } /* * Write the end line for a data section (i.e., a solitary dot). * Return -1 for error, 0 for ok. */ int nntp_write_end_line(int fd) { if (send_cmd(fd, ".") == -1) return -1; if (recv_response(fd) != 240) return -1; return 0; } /* * Send a command to the server. */ static int send_cmd(int fd, const char *fmt, ...) { va_list args; char buf[10240]; va_start(args, fmt); vsprintf(buf, fmt, args); va_end(args); if (strlen(buf) > 510) { __publib_error("output line too long!\n"); return -1; } if (log_output) log_chat("nntp: sending: `%s'\n", buf); strcat(buf, "\r\n"); if (write_all(fd, buf) == -1) return -1; return 0; } /* * Read a response from the server (a line beginning with a numeric code). * Bypass all informative messages. Return the numeric code. */ static int recv_response(int fd) { char buf[10240]; int code; if (read_line(fd, buf) == -1) return -1; code = atoi(buf); if (code < 100 || code > 599) return -1; return code; } /* * Read a whole line (at most 512 bytes). */ static int read_line(int fd, char *buf) { int ret; char *start; start = buf; ret = 0; while (buf-start<512 && (ret = nread(fd, buf, 1)) == 0 && *buf != '\n') ++buf; if (ret != 0) return -1; assert(*buf == '\n'); if (buf > start && buf[-1] == '\r') --buf; *buf = '\0'; if (log_input) log_chat("nntp: from server: `%s'\n", start); return 0; } /* * Read `need' bytes from file/socket descriptor */ static int nread(int fd, void *buf, int need) { char *p; int n; p = buf; while (need > 0) { n = read(fd, p, need); if (n < 0) { __publib_error("read failed"); return -1; } if (n == 0) { __publib_error("got 0 bytes when expecting more"); return -1; } need -= n; p += n; } return 0; } /* * Write the whole string, even if there are signals. */ int write_all(int fd, const void *s) { size_t len; int n; len = strlen(s); while (len > 0) { n = write(fd, s, len); if (n < 0) { __publib_error("write failed"); return -1; } len -= n; } return 0; } publib-0.40/Makefile.in0000664000175000017500000002752011767656752013111 0ustar ajkajk# Copyright (c) 2012 Antti-Juhani Kaijanaho # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SHELL = /bin/sh PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_VERSION = @PACKAGE_VERSION@ srcdir = @srcdir@ CC = @CC@ CPPFLAGS = @CPPFLAGS@ CFLAGS = @CFLAGS@ MDMF = @MDMF@ LDFLAGS = @LDFLAGS@ INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_DIR = ${INSTALL} -d MKDIR_P = @MKDIR_P@ RANLIB = @RANLIB@ AR = ar LN = ln echoexec = sh $(srcdir)/echoexec.sh link_alternative_names = sh $(srcdir)/link-alternative-names prefix = @prefix@ exec_prefix = @exec_prefix@ datarootdir = @datarootdir@ includedir = @includedir@ libdir = @libdir@ mandir = @mandir@ man3dir = ${mandir}/man3 man3ext = .3 objs = alloc/memdup.o \ alloc/xmalloc.o \ alloc/xrealloc.o \ alloc/xfree.o \ alloc/xstrdup.o \ alloc/xmemdup.o \ alloc/dynarr.o \ base64/base64.o \ bitarr/ba_and_ba.o \ bitarr/ba_clear.o \ bitarr/ba_clear_all.o \ bitarr/ba_copy.o \ bitarr/ba_create.o \ bitarr/ba_destroy.o \ bitarr/ba_not.o \ bitarr/ba_or_ba.o \ bitarr/ba_or_not_ba.o \ bitarr/ba_query.o \ bitarr/ba_resize.o \ bitarr/ba_set.o \ bitarr/ba_xor_ba.o \ cmp/cmp.o \ errormsg/errormsg.o \ files/xgetaline.o \ files/xfseek.o \ files/xfopen.o \ files/xfclose.o \ files/getaline.o \ files/fassert.o \ files/file_io.o \ fname/fnbase.o \ fname/fndelbeg.o \ fname/fndelend.o \ fname/fndelsuf.o \ fname/fndir.o \ fname/fnhome.o \ fname/fnjoin.o \ fname/fnlastsuf.o \ fname/fnpathfind.o \ fname/fnqualify.o \ fname/fnsetsuf.o \ hash/hash_create.o \ hash/hash_destroy.o \ hash/hash_install.o \ hash/hash_lookup.o \ hash/hash_uninstall.o \ hash/hash_iter.o \ iset/iset_add.o \ iset/iset_add_rng.o \ iset/iset_clear.o \ iset/iset_contains.o \ iset/iset_copy.o \ iset/iset_create.o \ iset/iset_destroy.o \ iset/iset_diff.o \ iset/iset_is_empty.o \ iset/iset_isect.o \ iset/iset_nth_rng.o \ iset/iset_range.o \ iset/iset_remove.o \ iset/iset_rm_rng.o \ iset/iset_union.o \ lockfile/lockfile.o \ log/log.o \ main/main_filter.o \ nntp/nntp.o \ nntp/nntpart.o \ priq/priq.o \ queue/queue.o \ sbuf/sbuf.o \ sbuf/sbuf_aux.o \ sbuf/sbuf_srch.o \ sbuf/sbuf_io.o \ stack/stack_copy.o \ stack/stack_create.o \ stack/stack_destroy.o \ stack/stack_emptyp.o \ stack/stack_pop.o \ stack/stack_push.o \ strutil/memarrfill.o \ strutil/memdel.o \ strutil/memfill.o \ strutil/memins.o \ strutil/memisort.o \ strutil/memmem.o \ strutil/memoverlap.o \ strutil/memrchr.o \ strutil/memrev.o \ strutil/memrmem.o \ strutil/memshuffle.o \ strutil/memswap.o \ strutil/stracat.o \ strutil/stranaxfrm.o \ strutil/strchange.o \ strutil/strcins.o \ strutil/strcstr.o \ strutil/strdel.o \ strutil/strdiff.o \ strutil/strend.o \ strutil/strendzap.o \ strutil/strgsub.o \ strutil/strhash.o \ strutil/strinit.o \ strutil/strins.o \ strutil/strltrim.o \ strutil/strmaxcpy.o \ strutil/strmove.o \ strutil/strmtrim.o \ strutil/strndup.o \ strutil/strnins.o \ strutil/strnlen.o \ strutil/stroverlap.o \ strutil/strrev.o \ strutil/strright.o \ strutil/strrot13.o \ strutil/strrstr.o \ strutil/strrtrim.o \ strutil/strset.o \ strutil/strshuffle.o \ strutil/strsplit.o \ strutil/strsub.o \ strutil/strtabify.o \ strutil/strtrexpand.o \ strutil/strtrim.o \ strutil/struncstr.o \ strutil/struntabify.o \ strutil/strvars.o \ strutil/strzap.o \ tbuf/tbuf.o srcs = $(objs:.o=.c) # excepting publib.h (special case!) includes = \ includes/publib/alloc.h \ includes/publib/base64.h \ includes/publib/bitarr.h \ includes/publib/cmp.h \ includes/publib/errormsg.h \ includes/publib/files.h \ includes/publib/fname.h \ includes/publib/hash.h \ includes/publib/iset.h \ includes/publib/lockfile.h \ includes/publib/log.h \ includes/publib/main.h \ includes/publib/nntp.h \ includes/publib/priq.h \ includes/publib/queue.h \ includes/publib/sbuf.h \ includes/publib/stack.h \ includes/publib/strutil.h \ includes/publib/tbuf.h manpages = \ man/bitarr.3 \ man/cmp.3 \ man/dynarr.3 \ man/errormsg.3 \ man/files.3 \ man/fname.3 \ man/fnpathfind.3 \ man/fnqualify.3 \ man/hash.3 \ man/iset.3 \ man/log.3 \ man/memarrfill.3 \ man/memdel.3 \ man/memfill.3 \ man/memins.3 \ man/memisort.3 \ man/memmem.3 \ man/memoverlap.3 \ man/memrchr.3 \ man/memrev.3 \ man/memrmem.3 \ man/memshuffle.3 \ man/memswap.3 \ man/publib.3 \ man/__set_liberror.3 \ man/stack.3 \ man/stracat.3 \ man/stranaxfrm.3 \ man/strchange.3 \ man/strcins.3 \ man/strcstr.3 \ man/strdel.3 \ man/strdiff.3 \ man/strend.3 \ man/strendzap.3 \ man/strgsub.3 \ man/strhash.3 \ man/strinit.3 \ man/strins.3 \ man/strltrim.3 \ man/strmaxcpy.3 \ man/strmove.3 \ man/strmtrim.3 \ man/strndup.3 \ man/strnins.3 \ man/stroverlap.3 \ man/strrev.3 \ man/strright.3 \ man/strrot13.3 \ man/strrstr.3 \ man/strrtrim.3 \ man/strset.3 \ man/strshuffle.3 \ man/strsplit.3 \ man/strsub.3 \ man/strtabify.3 \ man/strtrexpand.3 \ man/strtrim.3 \ man/struncstr.3 \ man/struntabify.3 \ man/strvars.3 \ man/strzap.3 \ man/tbuf.3 \ man/xmalloc.3 tests = iset/test_add.c \ main/test-main-filter.c \ log/test-log.c \ tbuf/test_tbuf_with_stats.c \ tbuf/test_tbuf.c \ queue/test-queue.c \ sbuf/test-colmark.c \ sbuf/test-sbuf-undo.c \ sbuf/test-sbuf.c \ priq/test-priq.c \ fname/test_fnqualify.c distfiles = $(srcs) $(includes) $(manpages) $(tests) \ aclocal.m4 ChangeLog.old configure configure.ac distcheck.mk \ echoexec.sh INSTALL includes/publib.h \ install-sh link-alternative-names Makefile.in NEWS README TODO all : libpub.a clean mostlyclean : $(RM) libpub.a */*.o */*.d distclean maintainer-clean : clean $(RM) config.log config.status install : libpub.a $(PRE_INSTALL) $(NORMAL_INSTALL) $(INSTALL_DIR) $(DESTDIR)$(includedir)/publib $(INSTALL_DIR) $(DESTDIR)$(libdir) $(INSTALL_DIR) $(DESTDIR)$(man3dir) $(INSTALL_DATA) libpub.a $(DESTDIR)$(libdir) $(INSTALL_DATA) includes/publib.h $(DESTDIR)$(includedir) @for f in $(includes) ; do \ $(echoexec) $(INSTALL_DATA) $$f $(DESTDIR)$(includedir)/publib/ ;\ done @for f in $(manpages) ; do\ if test -f $$f; then \ t="$(DESTDIR)$(man3dir)/`basename $$f .3`$(man3ext)"; \ $(echoexec) $(INSTALL_DATA) $$f "$$t" ;\ $(echoexec) gzip -9f "$$t" ;\ $(link_alternative_names) $$t $(DESTDIR)$(man3dir) $(man3ext) ;\ fi ;\ done $(POST_INSTALL) install-strip: install # No point in stripping a static library ... uninstall : $(PRE_UNINSTALL) $(NORMAL_UNINSTALL) $(RM) $(DESTDIR)$(libdir)/libpub.a $(RM) $(DESTDIR)$(includedir)publib.h @for f in $(includes) ; do \ $(echoexec) $(RM) $(DESTDIR)$(includedir)/publib/`basename $$f` ;\ done @for f in $(manpages) ; do\ t="$(DESTDIR)$(man3dir)/`basename $$f .3`$(man3ext)"; \ $(link_alternative_names) -r $$t $(DESTDIR)$(man3dir) $(man3ext) ;\ $(echoexec) $(RM) "$$t".gz ;\ done $(POST_UNINSTALL) libpub.a : $(objs) $(AR) cr $@ $^ $(RANLIB) $@ check : libpub.a @set -e; for f in $(tests) ; do\ $(echoexec) $(CC) -Iincludes $(CPPFLAGS) $(CFLAGS) $$f libpub.a ;\ echo './a.out /dev/null' ;\ ./a.out /dev/null ;\ $(echoexec) $(RM) a.out ;\ if test -r test.log; then rm test.log ; fi ;\ done dist_base = $(PACKAGE_TARNAME)-$(PACKAGE_VERSION) dist_tar = $(dist_base).tar dist_tgz = $(dist_tar).gz dist : $(dist_tgz) distsign : $(dist_tgz).asc $(dist_tgz) : $(distfiles) @if test -e $(DESTDIR)$(dist_base) ; then \ echo "$(DESTDIR)$(dist_base) exists; cannot continue" ; \ exit 1 ;\ fi $(MKDIR_P) $(DESTDIR)$(dist_base) @set -e ; for f in $(distfiles) ; do \ dir=$(DESTDIR)$(dist_base)/`dirname $$f` ; \ if ! test -d $$dir ; then \ $(echoexec) $(MKDIR_P) $$dir ;\ fi ;\ $(echoexec) $(LN) $$f $(DESTDIR)$(dist_base)/$$f ;\ done cd $(DESTDIR). && tar cf $(dist_tar) $(dist_base) gzip -9f $(DESTDIR)$(dist_tar) $(RM) -r $(DESTDIR)$(dist_base) $(dist_tgz).asc : $(dist_tgz) gpg --output $@ --clearsign --detach-sig $< distcheck_stage = distcheck_stage distcheck : $(dist_tgz) @if test -e $(DESTDIR)$(distcheck_stage) ; then \ echo "$(DESTDIR)$(distcheck_stage) exists; cannot continue" ; \ exit 1 ;\ fi $(MKDIR_P) $(DESTDIR)$(distcheck_stage) cp $(dist_tgz) $(DESTDIR)$(distcheck_stage) cp distcheck.mk $(DESTDIR)$(distcheck_stage)/Makefile cp echoexec.sh $(DESTDIR)$(distcheck_stage) $(MAKE) -C $(DESTDIR)$(distcheck_stage) \ base=$(dist_base) tgz=$(dist_tgz) \ includes="$(includes)" manpages="$(manpages)" \ run_distcheck $(RM) -r $(DESTDIR)$(distcheck_stage) .c.o: $(CC) -Iincludes -D__publib__ $(CPPFLAGS) $(CFLAGS) $(MDMF) -c $< -o $@ Makefile : Makefile.in config.status ./config.status config.status : configure ./configure configure : configure.ac aclocal.m4 autoconf aclocal.m4 : aclocal .SUFFIXES: .SUFFIXES: .c .o -include */*.d publib-0.40/INSTALL0000644000175000017500000003634011767427256012066 0ustar ajkajkInstallation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without warranty of any kind. Basic Installation ================== Briefly, the shell commands `./configure; make; make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for instructions specific to this package. Some packages provide this `INSTALL' file but do not implement all of the features documented below. The lack of an optional feature in a given package is not necessarily a bug. More recommendations for GNU packages can be found in *note Makefile Conventions: (standards)Makefile Conventions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' and enabled with `--cache-file=config.cache' or simply `-C') that saves the results of its tests to speed up reconfiguring. Caching is disabled by default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create `configure' by a program called `autoconf'. You 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: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. Running `configure' might take a while. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package, generally using the just-built uninstalled binaries. 4. Type `make install' to install the programs and any data files and documentation. When installing into a prefix owned by root, it is recommended that the package be configured and built as a regular user, and only the `make install' phase executed with root privileges. 5. Optionally, type `make installcheck' to repeat any self-tests, but this time using the binaries in their final installed location. This target does not install anything. Running this target as a regular user, particularly if the prior `make install' required root privileges, verifies that the installation completed correctly. 6. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. 7. Often, you can also type `make uninstall' to remove the installed files again. In practice, not all packages have tested that uninstallation works correctly, even though it is required by the GNU Coding Standards. 8. Some packages, particularly those that use Automake, provide `make distcheck', which can by used by developers to test that all other targets like `make install' and `make uninstall' work correctly. This target is generally not run by end users. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. Run `./configure --help' for details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here is an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. This is known as a "VPATH" build. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. On MacOS X 10.5 and later systems, you can create libraries and executables that work on multiple system types--known as "fat" or "universal" binaries--by specifying multiple `-arch' options to the compiler but only a single `-arch' option to the preprocessor. Like this: ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CPP="gcc -E" CXXCPP="g++ -E" This is not guaranteed to produce working output in all cases, you may have to build one architecture at a time and combine the results using the `lipo' tool if you have problems. Installation Names ================== By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PREFIX', where PREFIX must be an absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you pass the option `--exec-prefix=PREFIX' to `configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. In general, the default for these options is expressed in terms of `${prefix}', so that specifying just `--prefix' will affect all of the other directory specifications that were not explicitly provided. The most portable way to affect installation locations is to pass the correct locations to `configure'; however, many packages provide one or both of the following shortcuts of passing variable assignments to the `make install' command line to change installation locations without having to reconfigure or recompile. The first method involves providing an override variable for each affected directory. For example, `make install prefix=/alternate/directory' will choose an alternate location for all directory configuration variables that were expressed in terms of `${prefix}'. Any directories that were specified during `configure', but not in terms of `${prefix}', must each be overridden at install time for the entire installation to be relocated. The approach of makefile variable overrides for each directory variable is required by the GNU Coding Standards, and ideally causes no recompilation. However, some platforms have known limitations with the semantics of shared libraries that end up requiring recompilation when using this method, particularly noticeable in packages that use GNU Libtool. The second method involves providing the `DESTDIR' variable. For example, `make install DESTDIR=/alternate/directory' will prepend `/alternate/directory' before all installation names. The approach of `DESTDIR' overrides is not required by the GNU Coding Standards, and does not work on platforms that have drive letters. On the other hand, it does better at avoiding recompilation issues, and works well even when some directory options were not specified in terms of `${prefix}' at `configure' time. Optional Features ================= If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Some packages offer the ability to configure how verbose the execution of `make' will be. For these packages, running `./configure --enable-silent-rules' sets the default to minimal output, which can be overridden with `make V=1'; while running `./configure --disable-silent-rules' sets the default to verbose, which can be overridden with `make V=0'. Particular systems ================== On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC is not installed, it is recommended to use the following options in order to use an ANSI C compiler: ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot parse its `' header file. The option `-nodtk' can be used as a workaround. If GNU CC is not installed, it is therefore recommended to try ./configure CC="cc" and if that doesn't work, try ./configure CC="cc -nodtk" On Solaris, don't put `/usr/ucb' early in your `PATH'. This directory contains several dysfunctional programs; working variants of these programs are available in `/usr/bin'. So, if you need `/usr/ucb' in your `PATH', put it _after_ `/usr/bin'. On Haiku, software installed for all users goes in `/boot/common', not `/usr/local'. It is recommended to use the following options: ./configure --prefix=/boot/common Specifying the System Type ========================== There may be some features `configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the _same_ architectures, `configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should use the option `--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will eventually be run) with `--host=TYPE'. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc causes the specified `gcc' to be used as the C compiler (unless it is overridden in the site shell script). Unfortunately, this technique does not work for `CONFIG_SHELL' due to an Autoconf bug. Until the bug is fixed you can use this workaround: CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash `configure' Invocation ====================== `configure' recognizes the following options to control how it operates. `--help' `-h' Print a summary of all of the options to `configure', and exit. `--help=short' `--help=recursive' Print a summary of the options unique to this package's `configure', and exit. The `short' variant lists options used only in the top level, while the `recursive' variant lists options also present in any nested packages. `--version' `-V' Print the version of Autoconf used to generate the `configure' script, and exit. `--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, traditionally `config.cache'. FILE defaults to `/dev/null' to disable caching. `--config-cache' `-C' Alias for `--cache-file=config.cache'. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `--prefix=DIR' Use DIR as the installation prefix. *note Installation Names:: for more details, including other options available for fine-tuning the installation locations. `--no-create' `-n' Run the configure checks, but stop before creating any output files. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. publib-0.40/errormsg/0000775000175000017500000000000011767707451012667 5ustar ajkajkpublib-0.40/errormsg/errormsg.c0000664000175000017500000001015411767417657014702 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * errormsg.c -- print error message and optionally die * * Part of publib. See man page for more information * "@(#)publib-errormsg:$Id: errormsg.c,v 1.2 1999/03/24 22:29:13 liw Exp $" */ #include #include #include #include #include #include #include "publib/errormsg.h" static const char *progname = NULL; enum __liberror __liberror = __exit_on_error; void __set_liberror(enum __liberror i) { __liberror = i; } /* * Set program name; this is automatically included in the error messages. * Both arguments should point at strings that have static duration, i.e. * they exist until the program terminates (or at least until the last error * message has been printed); this is so that it is not necessary to create * a copy of the name. (The arguments can also be NULL.) * * If the first argument is non-NULL, that is used, otherwise the seconds * argument is used. If both are NULL, no program name is included in the * output. The reason for having two arguments is so that the caller * doesn't have to do the test, and can just call * set_progname(argv[0], "default_name"); * (it is valid for argv[0] to be NULL, under ISO C). */ void set_progname(const char *argv0, const char *def) { if (argv0 != NULL && *argv0 != '\0') progname = argv0; else if (def != NULL && *def != '\0') progname = def; } /* * Return program name set by set_progname, or an empty string if not set. */ const char *get_progname(void) { return progname != NULL ? progname : ""; } /* * Print error message; if exitp is 1, exit, if 2, abort, after printing * the message. If eno is positive, print error corresponding strerror * message; if eno is -1, use current value of errno. */ void errormsg(int do_after, int eno, const char *fmt, ...) { va_list args; size_t len; int print_newline, print_progname; if (eno == -1) /* this must be done before anything else */ eno = errno; assert(do_after == 0 || do_after == 1 || do_after == 2); assert(eno >= -1); /* there is no known maximum value for errno */ assert(fmt != NULL); fflush(NULL); /* output all pending output */ print_progname = (progname != NULL) && (*progname != '\0'); if (print_progname) fprintf(stderr, "%s: ", progname); va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); len = strlen(fmt); print_newline = (len > 0) && (fmt[len-1] == '\n'); if (eno != 0) { if (print_newline) { if (print_progname) fprintf(stderr, "%s: ", progname); fprintf(stderr, "Possible explanation: "); } else { fprintf(stderr, ": "); } fprintf(stderr, "%s\n", strerror(eno)); } else { if (!print_newline) fprintf(stderr, "\n"); /* make sure newline ends msg */ } fflush(stderr); switch (do_after) { case 1: exit(EXIT_FAILURE); case 2: abort(); } } publib-0.40/configure.ac0000664000175000017500000000400511767647175013322 0ustar ajkajk# Copyright (c) 2012 Antti-Juhani Kaijanaho # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. AC_PREREQ([2.68]) AC_INIT([publib],[0.40],[publib@lists.kaijanaho.info]) AC_CONFIG_SRCDIR([man/publib.3]) AC_PROG_CC AX_CFLAGS_WARN_ALL # Test for -MD AC_MSG_CHECKING([checking whether $CC -MD -MF works]) AC_LANG(C) rm -f main/conftest.d AC_LANG_CONFTEST([AC_LANG_SOURCE([@%:@include "publib.h"])]) mv conftest.c main/conftest.c $CC -Iincludes $CPPFLAGS $CFLAGS \ -MD -MF main/conftest.d -c main/conftest.c -o main/conftest.o if test -r main/conftest.d ; then MDMF='-MD -MF @S|@*.d' AC_MSG_RESULT(yes) else MDMF="" AC_MSG_RESULT(no) fi rm -f main/conftest.d main/conftest.c main/conftest.o AC_SUBST(MDMF) AC_PROG_INSTALL AC_PROG_RANLIB AC_PROG_MKDIR_P AC_CHECK_PROG(MAKE,gmake,gmake,make) AC_CONFIG_FILES([Makefile]) AC_OUTPUT publib-0.40/hash/0000775000175000017500000000000011767707451011752 5ustar ajkajkpublib-0.40/hash/hash_iter.c0000664000175000017500000000361211767417657014074 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * hash_iter.c -- iterate through all datums in a hash table * * Part of Publib, see man page for more information. * "@(#)publib-hash:$Id: hash_iter.c,v 1.1.1.1 1994/07/20 21:02:54 liw Exp $" */ #include #include "publib/hash.h" int hash_iter(Hashtab *ht, int (*doit)(void *, void *), void *param) { struct __hash_node *p; size_t i; assert(ht != NULL); assert(doit != NULL); for (i = 0; i < __HASHTAB_SIZE; ++i) for (p = ht->tab[i]; p != NULL; p = p->next) switch (doit(p->data, param)) { case 0: return 0; case -1: return -1; } return 1; } publib-0.40/hash/hash_lookup.c0000664000175000017500000000352311767417657014443 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * hash_lookup.c -- find a datum in a hash table * * Part of Publib, see man page for more information. * "@(#)publib-hash:$Id: hash_lookup.c,v 1.2 1995/09/23 09:11:55 liw Exp $" */ #include #include "publib/hash.h" void *hash_lookup(Hashtab *ht, const void *data) { struct __hash_node *p; unsigned long val; assert(ht != NULL); val = ht->hash(data); for (p = ht->tab[val % __HASHTAB_SIZE]; p != NULL; p = p->next) if (val == p->val && ht->cmp(data, p->data) == 0) return p->data; return NULL; } publib-0.40/hash/hash_install.c0000664000175000017500000000452211767417657014600 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * hash_install.c -- add a new data value in a hash table * * Part of Publib, see man page for more information. * "@(#)publib-hash:$Id: hash_install.c,v 1.3 1995/11/26 10:13:09 liw Exp $" */ #include #include #include #include "publib/hash.h" #include "publib/errormsg.h" void *hash_install(Hashtab *ht, const void *data, size_t size) { struct __hash_node *p; unsigned long val; size_t i; assert(ht != NULL); assert(data != NULL); val = ht->hash(data); i = val % __HASHTAB_SIZE; for (p = ht->tab[i]; p != NULL; p = p->next) if (val == p->val && ht->cmp(data, p->data) == 0) return p->data; p = malloc(sizeof(struct __hash_node)); if (p == NULL) { __publib_error("malloc failed"); return NULL; } if (size == 0) p->data = (void *) data; else if ((p->data = malloc(size)) == NULL) { __publib_error("malloc failed"); free(p); return NULL; } else memcpy(p->data, data, size); p->size = size; p->val = val; p->next = ht->tab[i]; ht->tab[i] = p; return p->data; } publib-0.40/hash/hash_uninstall.c0000664000175000017500000000410111767417657015134 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * hash_uninstall.c -- remove a datum from a hash table * * Part of Publib, see man page for more information. * "@(#)publib-hash:$Id: hash_uninstall.c,v 1.2 1995/09/23 09:11:55 liw Exp $" */ #include #include #include "publib/hash.h" int hash_uninstall(Hashtab *ht, const void *data) { struct __hash_node *p, *prev; unsigned long val; size_t i; assert(ht != NULL); assert(data != NULL); val = ht->hash(data); i = val % __HASHTAB_SIZE; for (prev = NULL, p = ht->tab[i]; p != NULL; prev = p, p = p->next) { if (val == p->val && ht->cmp(data, p->data) == 0) { if (prev == NULL) ht->tab[i] = p->next; else prev->next = p->next; if (p->size > 0) free(p->data); free(p); return 0; } } return -1; } publib-0.40/hash/hash_destroy.c0000664000175000017500000000352411767417657014624 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * hash_destroy.c -- destroy a hash table * * Part of Publib, see man page for more information. * "@(#)publib-hash:$Id: hash_destroy.c,v 1.1.1.1 1994/07/20 21:02:54 liw Exp $" */ #include #include #include "publib/hash.h" void hash_destroy(Hashtab *ht) { struct __hash_node *p; size_t i; assert(ht != NULL); for (i = 0; i < __HASHTAB_SIZE; ++i) { while (ht->tab[i] != NULL) { p = ht->tab[i]; ht->tab[i] = p->next; if (p->size > 0) free(p->data); free(p); } } free(ht); } publib-0.40/hash/hash_create.c0000664000175000017500000000367611767417657014406 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * hash_create.c -- create a hash table * * Part of Publib, see man page for more information. * "@(#)publib-hash:$Id: hash_create.c,v 1.1.1.1 1994/07/20 21:02:54 liw Exp $" */ #include #include #include "publib/hash.h" #include "publib/errormsg.h" Hashtab *hash_create(__hash_func *h, int (*cmp)(const void *, const void *)) { Hashtab *ht; size_t i; assert(h != NULL); assert(cmp != NULL); ht = malloc(sizeof(Hashtab)); if (ht == NULL) { __publib_error("malloc failed"); return NULL; } ht->hash = h; ht->cmp = cmp; for (i = 0; i < __HASHTAB_SIZE; ++i) ht->tab[i] = NULL; return ht; } publib-0.40/install-sh0000755000175000017500000003325611767707365013046 0ustar ajkajk#!/bin/sh # install - install a program, script, or datafile scriptversion=2011-01-19.21; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. # # Copyright (C) 1994 X Consortium # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the name of the X Consortium shall not # be used in advertising or otherwise to promote the sale, use or other deal- # ings in this Software without prior written authorization from the X Consor- # tium. # # # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent # `make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. nl=' ' IFS=" "" $nl" # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. doit=${DOITPROG-} if test -z "$doit"; then doit_exec=exec else doit_exec=$doit fi # Put in absolute file names if you don't have them in your path; # or use environment vars. chgrpprog=${CHGRPPROG-chgrp} chmodprog=${CHMODPROG-chmod} chownprog=${CHOWNPROG-chown} cmpprog=${CMPPROG-cmp} cpprog=${CPPROG-cp} mkdirprog=${MKDIRPROG-mkdir} mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} posix_glob='?' initialize_posix_glob=' test "$posix_glob" != "?" || { if (set -f) 2>/dev/null; then posix_glob= else posix_glob=: fi } ' posix_mkdir= # Desired mode of installed file. mode=0755 chgrpcmd= chmodcmd=$chmodprog chowncmd= mvcmd=$mvprog rmcmd="$rmprog -f" stripcmd= src= dst= dir_arg= dst_arg= copy_on_change=false no_target_directory= usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... In the 1st form, copy SRCFILE to DSTFILE. In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: --help display this help and exit. --version display version info and exit. -c (ignored) -C install only if different (preserve the last data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. -s $stripprog installed files. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG " while test $# -ne 0; do case $1 in -c) ;; -C) copy_on_change=true;; -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 case $mode in *' '* | *' '* | *' '* | *'*'* | *'?'* | *'['*) echo "$0: invalid mode: $mode" >&2 exit 1;; esac shift;; -o) chowncmd="$chownprog $2" shift;; -s) stripcmd=$stripprog;; -t) dst_arg=$2 # Protect names problematic for `test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac shift;; -T) no_target_directory=true;; --version) echo "$0 $scriptversion"; exit $?;; --) shift break;; -*) echo "$0: invalid option: $1" >&2 exit 1;; *) break;; esac shift done if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dst_arg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dst_arg" shift # fnord fi shift # arg dst_arg=$arg # Protect names problematic for `test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac done fi if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call `install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then do_exit='(exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13 trap "ret=143; $do_exit" 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. case $mode in # Optimize common cases. *644) cp_umask=133;; *755) cp_umask=22;; *[0-7]) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac fi for src do # Protect names problematic for `test' and other utilities. case $src in -* | [=\(\)!]) src=./$src;; esac if test -n "$dir_arg"; then dst=$src dstdir=$dst test -d "$dstdir" dstdir_status=$? else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi if test -z "$dst_arg"; then echo "$0: no destination specified." >&2 exit 1 fi dst=$dst_arg # If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then if test -n "$no_target_directory"; then echo "$0: $dst_arg: Is a directory" >&2 exit 1 fi dstdir=$dst dst=$dstdir/`basename "$src"` dstdir_status=0 else # Prefer dirname, but fall back on a substitute if dirname fails. dstdir=` (dirname "$dst") 2>/dev/null || expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$dst" : 'X\(//\)[^/]' \| \ X"$dst" : 'X\(//\)$' \| \ X"$dst" : 'X\(/\)' \| . 2>/dev/null || echo X"$dst" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q' ` test -d "$dstdir" dstdir_status=$? fi fi obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') # Create intermediate dirs using mode 755 as modified by the umask. # This is like FreeBSD 'install' as of 1997-10-28. umask=`umask` case $stripcmd.$umask in # Optimize common cases. *[2367][2367]) mkdir_umask=$umask;; .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; *[0-7]) mkdir_umask=`expr $umask + 22 \ - $umask % 100 % 40 + $umask % 20 \ - $umask % 10 % 4 + $umask % 2 `;; *) mkdir_umask=$umask,go-w;; esac # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then mkdir_mode=-m$mode else mkdir_mode= fi posix_mkdir=false case $umask in *[123567][0-7][0-7]) # POSIX mkdir -p sets u+wx bits regardless of umask, which # is incompatible with FreeBSD 'install' when (umask & 300) != 0. ;; *) tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 if (umask $mkdir_umask && exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibilities with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writeable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. ls_ld_tmpdir=`ls -ld "$tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && $mkdirprog -m$different_mode -p -- "$tmpdir" && { ls_ld_tmpdir_1=`ls -ld "$tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi rmdir "$tmpdir/d" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null fi trap '' 0;; esac;; esac if $posix_mkdir && ( umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else # The umask is ridiculous, or mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in /*) prefix='/';; [-=\(\)!]*) prefix='./';; *) prefix='';; esac eval "$initialize_posix_glob" oIFS=$IFS IFS=/ $posix_glob set -f set fnord $dstdir shift $posix_glob set +f IFS=$oIFS prefixes= for d do test X"$d" = X && continue prefix=$prefix$d if test -d "$prefix"; then prefixes= else if $posix_mkdir; then (umask=$mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 else case $prefix in *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; *) qprefix=$prefix;; esac prefixes="$prefixes '$qprefix'" fi fi prefix=$prefix/ done if test -n "$prefixes"; then # Don't fail if two instances are running concurrently. (umask $mkdir_umask && eval "\$doit_exec \$mkdirprog $prefixes") || test -d "$dstdir" || exit 1 obsolete_mkdir_used=true fi fi fi if test -n "$dir_arg"; then { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else # Make a couple of temp file names in the proper directory. dsttmp=$dstdir/_inst.$$_ rmtmp=$dstdir/_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && eval "$initialize_posix_glob" && $posix_glob set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && $posix_glob set +f && test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then rm -f "$dsttmp" else # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f. { # Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { test ! -f "$dst" || $doit $rmcmd -f "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 } } && # Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 trap '' 0 fi done # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: publib-0.40/NEWS0000664000175000017500000000116611767671577011543 0ustar ajkajkNEWS about the publib project ============================= Version 0.40 ------------ * Lars Wirzenius has passed maintenance of publib to Antti-Juhani Kaijanaho. * Publib no longer includes the framework; instead, a conventional configure--make build system is provided. Publib now consists of the library modules formerly known as liw-modules. * Minor bugfixes have been made to the library modules. Version 0.39 ------------ * liw/cfgtool has been removed. It was obsolete since about a decade. * liw/strutils/strsplit has been fixed, thanks to bug report from Ron Fox. publib-0.40/aclocal.m40000664000175000017500000002031411767426320012660 0ustar ajkajk# generated automatically by aclocal 1.11.3 -*- Autoconf -*- # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, # 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, # Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. # =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_append_flag.html # =========================================================================== # # SYNOPSIS # # AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE]) # # DESCRIPTION # # FLAG is appended to the FLAGS-VARIABLE shell variable, with a space # added in between. # # If FLAGS-VARIABLE is not specified, the current language's flags (e.g. # CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains # FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly # FLAG. # # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. # # LICENSE # # Copyright (c) 2008 Guido U. Draheim # Copyright (c) 2011 Maarten Bosmans # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Archive. When you make and distribute a # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. #serial 2 AC_DEFUN([AX_APPEND_FLAG], [AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])])dnl AS_VAR_SET_IF(FLAGS, [case " AS_VAR_GET(FLAGS) " in *" $1 "*) AC_RUN_LOG([: FLAGS already contains $1]) ;; *) AC_RUN_LOG([: FLAGS="$FLAGS $1"]) AS_VAR_SET(FLAGS, ["AS_VAR_GET(FLAGS) $1"]) ;; esac], [AS_VAR_SET(FLAGS,["$1"])]) AS_VAR_POPDEF([FLAGS])dnl ])dnl AX_APPEND_FLAG # =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_cflags_warn_all.html # =========================================================================== # # SYNOPSIS # # AX_CFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])] # AX_CXXFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])] # AX_FCFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])] # # DESCRIPTION # # Try to find a compiler option that enables most reasonable warnings. # # For the GNU compiler it will be -Wall (and -ansi -pedantic) The result # is added to the shellvar being CFLAGS, CXXFLAGS, or FCFLAGS by default. # # Currently this macro knows about the GCC, Solaris, Digital Unix, AIX, # HP-UX, IRIX, NEC SX-5 (Super-UX 10), Cray J90 (Unicos 10.0.0.8), and # Intel compilers. For a given compiler, the Fortran flags are much more # experimental than their C equivalents. # # - $1 shell-variable-to-add-to : CFLAGS, CXXFLAGS, or FCFLAGS # - $2 add-value-if-not-found : nothing # - $3 action-if-found : add value to shellvariable # - $4 action-if-not-found : nothing # # NOTE: These macros depend on AX_APPEND_FLAG. # # LICENSE # # Copyright (c) 2008 Guido U. Draheim # Copyright (c) 2010 Rhys Ulerich # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 3 of the License, or (at your # option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Archive. When you make and distribute a # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. #serial 13 AC_DEFUN([AX_FLAGS_WARN_ALL],[dnl AS_VAR_PUSHDEF([FLAGS],[_AC_LANG_PREFIX[]FLAGS])dnl AS_VAR_PUSHDEF([VAR],[ac_cv_[]_AC_LANG_ABBREV[]flags_warn_all])dnl AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings], VAR,[VAR="no, unknown" ac_save_[]FLAGS="$[]FLAGS" for ac_arg dnl in "-warn all % -warn all" dnl Intel "-pedantic % -Wall" dnl GCC "-xstrconst % -v" dnl Solaris C "-std1 % -verbose -w0 -warnprotos" dnl Digital Unix "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX "-ansi -ansiE % -fullwarn" dnl IRIX "+ESlit % +w1" dnl HP-UX C "-Xc % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10) "-h conform % -h msglevel 2" dnl Cray C (Unicos) # do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'` AC_COMPILE_IFELSE([AC_LANG_PROGRAM], [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break]) done FLAGS="$ac_save_[]FLAGS" ]) AS_VAR_POPDEF([FLAGS])dnl case ".$VAR" in .ok|.ok,*) m4_ifvaln($3,$3) ;; .|.no|.no,*) m4_default($4,[m4_ifval($2,[AX_APPEND_FLAG([$2], [$1])])]) ;; *) m4_default($3,[AX_APPEND_FLAG([$VAR], [$1])]) ;; esac AS_VAR_POPDEF([VAR])dnl ])dnl AX_FLAGS_WARN_ALL dnl implementation tactics: dnl the for-argument contains a list of options. The first part of dnl these does only exist to detect the compiler - usually it is dnl a global option to enable -ansi or -extrawarnings. All other dnl compilers will fail about it. That was needed since a lot of dnl compilers will give false positives for some option-syntax dnl like -Woption or -Xoption as they think of it is a pass-through dnl to later compile stages or something. The "%" is used as a dnl delimiter. A non-option comment can be given after "%%" marks dnl which will be shown but not added to the respective C/CXXFLAGS. AC_DEFUN([AX_CFLAGS_WARN_ALL],[dnl AC_LANG_PUSH([C]) AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4]) AC_LANG_POP([C]) ]) AC_DEFUN([AX_CXXFLAGS_WARN_ALL],[dnl AC_LANG_PUSH([C++]) AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4]) AC_LANG_POP([C++]) ]) AC_DEFUN([AX_FCFLAGS_WARN_ALL],[dnl AC_LANG_PUSH([Fortran]) AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4]) AC_LANG_POP([Fortran]) ]) publib-0.40/fname/0000775000175000017500000000000011767707451012115 5ustar ajkajkpublib-0.40/fname/fnjoin.c0000664000175000017500000000361111767417657013553 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fnjoin.c -- join two filenames together * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fnjoin.c,v 1.2 1994/06/20 20:49:23 liw Exp $" */ #include #include #include #include "publib/fname.h" void fnjoin(char *res, const char *f1, const char *f2) { const char *p; assert(res != NULL); assert(f1 != NULL); assert(*f1 != '\0'); assert(f2 != NULL); assert(*f2 != '\0'); p = strchr(f1, '\0'); if ((p > f1 && p[-1] == '/') || *f2 == '/') p = ""; else p = "/"; sprintf(res, "%s%s%s", f1, p, f2); } publib-0.40/fname/fndelend.c0000664000175000017500000000330211767417657014044 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fndelend.c -- delete last filename in a pathname * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fndelend.c,v 1.2 1994/06/20 20:49:19 liw Exp $" */ #include #include #include "publib/fname.h" void fndelend(char *fname) { char *p; assert(fname != NULL); p = strrchr(fname, '/'); *(p == NULL ? fname : p) = '\0'; } publib-0.40/fname/fnqualify.c0000664000175000017500000000615411767417657014273 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fnqualify.c -- qualify a filename * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fnqualify.c,v 1.5 1996/08/12 01:03:57 liw Exp $" */ #include #include #include #include #include #include "publib/fname.h" #include "publib/errormsg.h" #ifndef USERNAME_MAX #define USERNAME_MAX 9 #endif size_t fnqualify(char *result, const char *path, size_t max) { size_t len, size; struct passwd *pwd; const char *p; char username[USERNAME_MAX]; assert(result != NULL); assert(path != NULL); assert(max > 0); /* Is it qualified already? */ if (path[0] == '/') { strncpy(result, path, max); result[max-1] = '\0'; return strlen(path) + 1; } /* Do we just need to prepend the current directory? */ if (path[0] != '~') { if (getcwd(result, max) == NULL) { __publib_error("getcwd failed"); return -1; } len = strlen(result); size = len + 1 + strlen(path) + 1; /* +2 for '/' and '\0' */ if (size > max) return size; sprintf(result + len, "/%s", path); return size; } /* We need to do tilde substitution, get the password entry (which includes the name of the home directory) */ if (path[1] == '\0' || path[1] == '/') { pwd = getpwuid(getuid()); if (path[1] == '\0') p = path + 1; else p = path + 2; } else { p = strchr(path, '/'); if (p == NULL) p = strchr(path, '\0'); size = (size_t) (p-path); if (size > sizeof(username)) return -1; memcpy(username, path+1, size); username[size-1] = '\0'; pwd = getpwnam(username); if (*p == '/') ++p; } if (pwd == NULL) return -1; /* Now we have all the necessary information, build the result */ size = strlen(pwd->pw_dir) + 1 + strlen(p) + 1; if (size < max) sprintf(result, "%s/%s", pwd->pw_dir, p); return size; } publib-0.40/fname/fnsetsuf.c0000664000175000017500000000403211767417657014123 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fnsetsuf.c -- replace (last) suffix of filename * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fnsetsuf.c,v 1.2 1994/06/20 20:49:27 liw Exp $" */ #include #include #include "publib/fname.h" size_t fnsetsuf(char *fname, const char *suffix, size_t max) { char *dot; size_t needed; assert(fname != NULL); assert(suffix != NULL); assert(max > 0); dot = fnlastsuf(fname); if (dot == NULL) { needed = strlen(fname) + strlen(suffix) + 1; if (needed > max) return needed; strcat(fname, suffix); } else { needed = (strlen(fname) - strlen(dot)) + strlen(suffix) + 1; if (needed > max) return needed; strcpy(dot, suffix); } return needed; } publib-0.40/fname/fnlastsuf.c0000664000175000017500000000325711767417657014303 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fnlastsuf.c -- find last suffix in basename of filename * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fnlastsuf.c,v 1.2 1994/06/20 20:49:24 liw Exp $" */ #include #include #include "publib/fname.h" char *fnlastsuf(const char *fname) { assert(fname != NULL); return strchr(fnbase(fname), '.'); } publib-0.40/fname/fndelbeg.c0000664000175000017500000000346511767417657014045 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fndelbeg.c -- delete first part of filename * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fndelbeg.c,v 1.2 1994/06/20 20:49:18 liw Exp $" */ #include #include #include "publib/fname.h" void fndelbeg(char *fname) { char *p; assert(fname != NULL); if (*fname == '/') memmove(fname, fname+1, strlen(fname)+1); else { p = strchr(fname, '/'); if (p == NULL) *fname = '\0'; else memmove(fname, p, strlen(p) + 1); } } publib-0.40/fname/fndir.c0000664000175000017500000000346611767417657013402 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fndir.c -- copy all but basename of filename * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fndir.c,v 1.2 1994/06/20 20:49:21 liw Exp $" */ #include #include #include "publib/fname.h" void fndir(char *dir, const char *fname) { char *base; assert(dir != NULL); assert(fname != NULL); base = fnbase(fname); if (base == fname) strcpy(dir, "."); else { memcpy(dir, fname, (size_t)(base-fname)); dir[base-fname] = '\0'; } } publib-0.40/fname/fnhome.c0000664000175000017500000000375311767417657013553 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fnhome.c -- return home directory of user * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fnhome.c,v 1.4 1994/07/16 15:28:39 liw Exp $" */ #include #include #include #include #include "publib/fname.h" #include "publib/errormsg.h" int fnhome(char *homedir, const char *username) { struct passwd *pwd; assert(homedir != NULL); assert(username != NULL); assert(*username != '\0'); if (username == NULL) pwd = getpwuid(getuid()); else pwd = getpwnam(username); if (pwd == NULL) { __publib_error("can't find home directory"); return -1; } strcpy(homedir, pwd->pw_dir); return 0; } publib-0.40/fname/test_fnqualify.c0000664000175000017500000000346211767417657015331 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * test_fnqualify.c -- test fnqualify * * Part of publib. * "@(#)publib-fname:$Id: test_fnqualify.c,v 1.1.1.1 1993/11/20 17:02:15 liw Exp $" */ #include #include "publib/fname.h" int main(int argc, char **argv) { int i; char buf[FILENAME_MAX]; size_t n; for (i = 1; i < argc; ++i) { n = fnqualify(buf, argv[i], sizeof(buf)); printf("input: `%s'\n", argv[i]); printf("output: `%s'\n", buf); printf("n: %lu\n", (unsigned long) n); printf("\n"); } return 0; } publib-0.40/fname/fnpathfind.c0000664000175000017500000000670511767417657014420 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fnpathfind.c -- find file in a list of directories * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fnpathfind.c,v 1.4 1994/07/16 15:28:42 liw Exp $" */ #include #include #include #include #include "publib/fname.h" #include "publib/errormsg.h" /* XXX - there is a standard unix function pathfind ... */ int fnpathfind(const char *path, const char *tgt, char *result, size_t max) { char *p; /* auxiliary pointer */ char *colon; /* where the next colon is */ char *fullname; /* the full name of the current possibility */ size_t cursize; /* current block size allocated for fullname */ size_t fullsize; /* size of current possibility (<= cursize) */ size_t dirlen; /* length of the current component of path */ size_t tgtlen; /* length of the tgt */ assert(path != NULL); assert(tgt != NULL); assert(result != NULL); assert(max > 0); tgtlen = strlen(tgt); fullname = NULL; cursize = 0; for (; *path != '\0'; path = colon + (*colon == '\0' ? 0 : 1)) { /* find end of current path element (next colon, or the trailing '\0' if last element */ colon = strchr(path, ':'); if (colon == NULL) colon = strchr(path, '\0'); /* compute size of full name: dirname + "/" + tgt + trailing '\0' except that the "/" is only needed if the dirname doesn't end in a slash. Then make sure fullname is at least big enough. */ dirlen = colon - path; fullsize = dirlen + (dirlen ? 0 : 1) + tgtlen + 1; if (cursize < fullsize) { p = realloc(fullname, fullsize); if (p == NULL) { __publib_error("realloc failed"); free(fullname); return -1; } fullname = p; cursize = fullsize; } /* construct the full name */ strncpy(fullname, path, dirlen); p = fullname + dirlen; if (dirlen > 0 && fullname[dirlen-1] != '/') *p++ = '/'; strcpy(p, tgt); /* does it exist? if so, copy to result and return */ if (access(fullname, 00) == 00) { strncpy(result, fullname, max); result[max-1] = '\0'; free(fullname); return fullsize; } } /* we didn't find anything */ free(fullname); return -1; } publib-0.40/fname/fnbase.c0000664000175000017500000000334411767417657013531 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fnbase.c -- find start of basename in filename * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fnbase.c,v 1.2 1994/06/20 20:47:47 liw Exp $" */ #include #include #include "publib/fname.h" char *fnbase(const char *fname) { char *base; assert(fname != NULL); base = strrchr(fname, '/'); if (base == NULL) return (char *) fname; return base+1; } publib-0.40/fname/fndelsuf.c0000664000175000017500000000355511767417657014105 0ustar ajkajk/* Part of publib. Copyright (c) 1994-2006 Lars Wirzenius. 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. 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fndelsuf.c -- delete last suffix from basename of filename * * Part of publib. See man page for more information * "@(#)publib-fname:$Id: fndelsuf.c,v 1.2 1994/06/20 20:49:20 liw Exp $" */ #include #include #include "publib/fname.h" int fndelsuf(char *fname, const char *suffix) { char *dot; assert(fname != NULL); assert(suffix != NULL); assert(*suffix != '\0'); dot = fnlastsuf(fname); if (dot == NULL) return -1; if (suffix == NULL || strcmp(dot, suffix) == 0) { *dot = '\0'; return 0; } return -1; }