[27035] in Source-Commits
/svn/athena r25905 - in trunk/athena/lib/athdir: . src
daemon@ATHENA.MIT.EDU (Alexander Chernyakhovsky)
Tue Apr 9 17:07:07 2013
Date: Tue, 9 Apr 2013 17:07:01 -0400
From: Alexander Chernyakhovsky <achernya@MIT.EDU>
Message-Id: <201304092107.r39L718k019193@drugstore.mit.edu>
To: source-commits@MIT.EDU
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Author: achernya
Date: 2013-04-09 17:07:01 -0400 (Tue, 09 Apr 2013)
New Revision: 25905
Added:
trunk/athena/lib/athdir/AUTHORS
trunk/athena/lib/athdir/COPYING
trunk/athena/lib/athdir/ChangeLog
trunk/athena/lib/athdir/Makefile.am
trunk/athena/lib/athdir/NEWS
trunk/athena/lib/athdir/README
trunk/athena/lib/athdir/autogen.sh
trunk/athena/lib/athdir/m4/
trunk/athena/lib/athdir/src/
trunk/athena/lib/athdir/src/Makefile.am
trunk/athena/lib/athdir/src/athdir.c
trunk/athena/lib/athdir/src/athdir.h
trunk/athena/lib/athdir/src/athdir.pc.in
trunk/athena/lib/athdir/src/stringlist.c
trunk/athena/lib/athdir/src/stringlist.h
Removed:
trunk/athena/lib/athdir/Makefile.in
trunk/athena/lib/athdir/athdir.c
trunk/athena/lib/athdir/athdir.h
trunk/athena/lib/athdir/athdir.pc.in
trunk/athena/lib/athdir/stringlist.c
trunk/athena/lib/athdir/stringlist.h
Modified:
trunk/athena/lib/athdir/configure.ac
Log:
Transform athdir into an automake project; also relicense to BSD-2-Clause
Added: trunk/athena/lib/athdir/AUTHORS
===================================================================
Added: trunk/athena/lib/athdir/COPYING
===================================================================
--- trunk/athena/lib/athdir/COPYING (rev 0)
+++ trunk/athena/lib/athdir/COPYING 2013-04-09 21:07:01 UTC (rev 25905)
@@ -0,0 +1,30 @@
+Copyright 1998 by the Massachusetts Institute of Technology.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+* 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.
+
+* Neither the name of the M.I.T nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"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
+COPYRIGHT HOLDER OR CONTRIBUTORS 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.
Added: trunk/athena/lib/athdir/ChangeLog
===================================================================
Added: trunk/athena/lib/athdir/Makefile.am
===================================================================
--- trunk/athena/lib/athdir/Makefile.am (rev 0)
+++ trunk/athena/lib/athdir/Makefile.am 2013-04-09 21:07:01 UTC (rev 25905)
@@ -0,0 +1,3 @@
+ACLOCAL_AMFLAGS = --install -I m4
+SUBDIRS = src
+EXTRA_DIST = autogen.sh
Added: trunk/athena/lib/athdir/NEWS
===================================================================
Added: trunk/athena/lib/athdir/README
===================================================================
Added: trunk/athena/lib/athdir/autogen.sh
===================================================================
--- trunk/athena/lib/athdir/autogen.sh (rev 0)
+++ trunk/athena/lib/athdir/autogen.sh 2013-04-09 21:07:01 UTC (rev 25905)
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec autoreconf -fi
Property changes on: trunk/athena/lib/athdir/autogen.sh
___________________________________________________________________
Added: svn:executable
+ *
Modified: trunk/athena/lib/athdir/configure.ac
===================================================================
--- trunk/athena/lib/athdir/configure.ac 2013-04-09 19:13:05 UTC (rev 25904)
+++ trunk/athena/lib/athdir/configure.ac 2013-04-09 21:07:01 UTC (rev 25905)
@@ -1,15 +1,44 @@
-dnl Process this file with autoconf to produce a configure script.
-AC_INIT([libathdir], [10.0.2])
-AC_CONFIG_SRCDIR([athdir.c])
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+AC_PREREQ([2.67])
+AC_INIT([libathdir], [10.0.2], [debathena@mit.edu])
+AM_INIT_AUTOMAKE([-Wall])
+AM_MAINTAINER_MODE([enable])
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_SRCDIR([src/athdir.c])
+AC_CONFIG_HEADERS([config.h])
+
+# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
+# automake 1.12 seems to require this, but automake 1.11 doesn't recognize it
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+LT_INIT
AC_PROG_LIBTOOL
-AC_PROG_MKDIR_P
-AS_IF([test x"$ATHENA_SYS" = x], [AC_MSG_ERROR([ATHENA_SYS must be set])])
-AS_IF([test x"$ATHENA_HOSTTYPE" = x], [AC_MSG_ERROR([ATHENA_HOSTTYPE must be set])])
-AC_DEFINE_UNQUOTED([ATHSYS], ["$ATHENA_SYS"])
-AC_DEFINE_UNQUOTED([HOSTTYPE_$ATHENA_HOSTTYPE])
-AC_CONFIG_FILES([Makefile athdir.pc])
+# Checks for libraries.
+
+# Checks for header files.
+AC_CHECK_HEADERS([stdlib.h string.h sys/param.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_FUNC_REALLOC
+AC_CHECK_FUNCS([strchr])
+
+# More stuff
+AS_IF([test x"$ATHENA_SYS" = x], [AC_MSG_ERROR([ATHENA_SYS must be set])])
+AS_IF([test x"$ATHENA_HOSTTYPE" = x], [AC_MSG_ERROR([ATHENA_HOSTTYPE must be set])])
+AC_DEFINE_UNQUOTED([ATHSYS], ["$ATHENA_SYS"], [Define the Athena System Version])
+AC_DEFINE_UNQUOTED([HOSTTYPE_$ATHENA_HOSTTYPE], [Define the type of the Athena System])
+
+
+AC_CONFIG_FILES([Makefile
+ src/Makefile
+ src/athdir.pc
+])
AC_OUTPUT
Added: trunk/athena/lib/athdir/src/Makefile.am
===================================================================
--- trunk/athena/lib/athdir/src/Makefile.am (rev 0)
+++ trunk/athena/lib/athdir/src/Makefile.am 2013-04-09 21:07:01 UTC (rev 25905)
@@ -0,0 +1,9 @@
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = athdir.pc
+
+include_HEADERS = athdir.h
+
+lib_LTLIBRARIES = libathdir.la
+libathdir_la_SOURCES = \
+ athdir.c \
+ stringlist.c
Copied: trunk/athena/lib/athdir/src/athdir.c (from rev 25903, trunk/athena/lib/athdir/athdir.c)
===================================================================
--- trunk/athena/lib/athdir/src/athdir.c (rev 0)
+++ trunk/athena/lib/athdir/src/athdir.c 2013-04-09 21:07:01 UTC (rev 25905)
@@ -0,0 +1,382 @@
+/* Copyright 1998 by the Massachusetts Institute of Technology.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * 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.
+ *
+ * * Neither the name of the M.I.T nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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
+ * COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ */
+
+/* This file implements the main athdir library calls. */
+
+static const char rcsid[] = "$Id: athdir.c,v 1.6 1999-10-23 19:28:46 danw Exp $";
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h> /* MAXPATHLEN */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "athdir.h"
+#include "stringlist.h"
+#include "config.h"
+
+/* Define HOSTTYPE for the platforms where `machtype`bin has historic
+ * use. Never add new platforms to this list.
+ */
+#if defined(HOSTTYPE_sun4)
+#define HOSTTYPE "sun4"
+#elif defined(HOSTTYPE_linux)
+#define HOSTTYPE "linux"
+#elif defined(HOSTTYPE_inbsd)
+#define HOSTTYPE "inbsd"
+#endif
+
+#ifdef HOSTTYPE
+char *hosttype = HOSTTYPE;
+#else
+char *hosttype = NULL;
+#endif
+
+/* Definition of known conventions and what flavors they are. */
+
+typedef struct {
+ char *name;
+ int flavor;
+} Convention;
+
+#define ARCHflavor (1<<0)
+#define MACHflavor (1<<1)
+#define PLAINflavor (1<<2)
+#define SYSflavor (1<<3)
+#define DEPENDENTflavor (1<<8)
+#define INDEPENDENTflavor (1<<9)
+#define ATSYSflag (1<<16)
+
+#define NUMCONVENTIONS 5
+
+Convention conventions[NUMCONVENTIONS] = {
+ { NULL, ARCHflavor | MACHflavor | PLAINflavor |
+ DEPENDENTflavor | INDEPENDENTflavor },
+ { "%p/arch/%s/%t", ARCHflavor | DEPENDENTflavor | ATSYSflag },
+ { "%p/%s/%t", SYSflavor | DEPENDENTflavor | ATSYSflag },
+ { "%p/%m%t", MACHflavor | DEPENDENTflavor },
+ { "%p/%t", PLAINflavor | INDEPENDENTflavor }
+};
+
+/* Editorial tagging for what conventions are acceptable or
+ * preferable for what types.
+ */
+
+typedef struct {
+ char *type;
+ int allowedFlavors; /* searching parameters */
+ int preferredFlavor; /* creating paramaters */
+} Editorial;
+
+Editorial editorials[] = {
+ { "bin", ARCHflavor | SYSflavor | MACHflavor, DEPENDENTflavor },
+ { "lib", ARCHflavor | SYSflavor | MACHflavor, DEPENDENTflavor },
+ { "etc", ARCHflavor | SYSflavor | MACHflavor, DEPENDENTflavor },
+ { "man", ARCHflavor | PLAINflavor, INDEPENDENTflavor },
+ { "include", ARCHflavor | PLAINflavor, INDEPENDENTflavor },
+ { NULL, ARCHflavor | PLAINflavor, DEPENDENTflavor }
+};
+
+/* path = template(dir, type, sys, machine)
+ * %p = path (dir)
+ * %t = type
+ * %s = sys
+ * %m = machine
+ * %foo is inserted if the corresponding string is NULL.
+ * If this happens, expand returns 1 (not a valid path).
+ * If expand runs out of memory, it returns -1 (and path is NULL).
+ * Otherwise, expand returns 0.
+ */
+static int expand(char **path, char *template, char *dir,
+ char *type, char *sys, char *machine)
+{
+ char *src, *dst, *oldpath;
+ int somenull = 0, size;
+
+ src = template;
+ size = strlen(template) + 1;
+ dst = oldpath = *path = malloc(size);
+ *dst = '\0';
+
+ while (*src != '\0')
+ {
+ if (*src != '%')
+ *dst++ = *src++;
+ else
+ {
+
+#define copystring(casec, cases, string) \
+ case casec: \
+ src++; \
+ if (string) \
+ { \
+ *path = realloc(*path, size += strlen(string)); \
+ if (!*path) \
+ return -1; \
+ dst = *path + (dst - oldpath); \
+ oldpath = *path; \
+ strcpy(dst, string); \
+ dst += strlen(string); \
+ } \
+ else \
+ { \
+ strcpy(dst, cases); \
+ dst += 2; \
+ somenull = 1; \
+ } \
+ break;
+
+ src++;
+ switch(*src)
+ {
+ copystring('p', "%p", dir);
+ copystring('t', "%t", type);
+ copystring('s', "%s", sys);
+ copystring('m', "%m", machine);
+
+#undef copystring
+
+ case '\0':
+ break;
+
+ default:
+ *dst++ = '%';
+ *dst++ = *src++;
+ break;
+ }
+ }
+ }
+
+ *dst = '\0';
+ return somenull;
+}
+
+static int template_flavor(char *template)
+{
+ int flavor = ARCHflavor | MACHflavor | PLAINflavor
+ | DEPENDENTflavor | INDEPENDENTflavor;
+ char *ptr;
+
+ if (template == NULL)
+ return 0;
+
+ for (ptr = strchr(template, '%'); ptr != NULL; ptr = strchr(ptr + 1, '%'))
+ {
+ if (*(ptr+1) == 's')
+ flavor |= ATSYSflag;
+ }
+
+ return flavor;
+}
+
+int athdir_native(char *what, char *sys)
+{
+ char *ptr;
+
+ /* If sys is NULL, fall back to ATHENA_SYS if it's set, otherwise
+ * use the compiled-in value.
+ */
+ if (sys == NULL)
+ {
+ sys = getenv("ATHENA_SYS");
+ if (sys == NULL || strchr(sys, '/') != NULL)
+ sys = ATHSYS;
+ }
+
+ for (ptr = strchr(what, sys[0]); ptr != NULL; ptr = strchr(ptr + 1, sys[0]))
+ {
+ if (!strncmp(ptr, sys, strlen(sys)))
+ return 1;
+ }
+
+ return 0;
+}
+
+/* You are in a twisty little maze of interconnecting flags, all different.
+ */
+char **athdir_get_paths(char *base_path, char *type,
+ char *sys, char **syscompat, char *machine,
+ char *aux, int flags)
+{
+ char *path;
+ string_list *path_list = NULL, *compat_list = NULL;
+ int t, j, complete, preferredFlavor, want_break;
+ struct stat statbuf;
+ char **current_compat, **mysyscompat = NULL, *compat_env;
+
+ /* If sys is NULL, fall back to ATHENA_SYS if it's set, otherwise
+ * use the compiled-in value.
+ */
+ if (sys == NULL)
+ {
+ sys = getenv("ATHENA_SYS");
+ if (sys == NULL || strchr(sys, '/') != NULL)
+ sys = ATHSYS;
+ }
+
+ /* Generate the syscompat array from the environment if it wasn't
+ * passed in.
+ */
+ if (syscompat == NULL)
+ {
+ /* We're compatible with ourselves. */
+ if (athdir__add_string(&compat_list, sys, 0))
+ return NULL;
+ compat_env = getenv("ATHENA_SYS_COMPAT");
+ if (compat_env != NULL && !strchr(compat_env, '/'))
+ {
+ if (athdir__parse_string(&compat_list, compat_env, ':'))
+ return NULL;
+ }
+ syscompat = mysyscompat = athdir__make_string_array(&compat_list);
+ }
+
+ /* If machine is NULL, use whatever was compiled in. */
+ if (machine == NULL)
+ machine = hosttype;
+
+ /* Zeroeth convention is optionally provided by the caller. */
+ conventions[0].name = aux;
+ conventions[0].flavor = template_flavor(aux);
+
+ /* Find matching editorial for the type of directory requested
+ * (to be consulted later).
+ */
+ for (t = 0; editorials[t].type != NULL; t++)
+ {
+ if (type != NULL && !strcmp(type, editorials[t].type))
+ break;
+ }
+
+ if (flags & ATHDIR_MACHINEDEPENDENT)
+ preferredFlavor = DEPENDENTflavor;
+ else
+ {
+ if (flags & ATHDIR_MACHINEINDEPENDENT)
+ preferredFlavor = INDEPENDENTflavor;
+ else
+ preferredFlavor = editorials[t].preferredFlavor;
+ }
+
+ /* Cycle through matching conventions */
+ for (j = 0; j < NUMCONVENTIONS; j++)
+ {
+ if (conventions[j].name == NULL)
+ continue; /* conventions[0], the caller specified convention,
+ * is not set. */
+ want_break = 0;
+
+ if (
+ /* If the editorial says this is a reasonable convention
+ * for this type
+ */
+ (editorials[t].allowedFlavors & conventions[j].flavor) ||
+
+ /* or we don't care what the editorials say */
+ (flags & ATHDIR_SUPPRESSEDITORIALS) ||
+
+ /* or something more explicit than the editorials has been
+ * specified
+ */
+ (((ATHDIR_MACHINEDEPENDENT | ATHDIR_MACHINEINDEPENDENT) & flags) &&
+ (flags & ATHDIR_SUPPRESSSEARCH)))
+ {
+ /* If we're looking for a specific flavor (machine dependent/
+ * machine independent) and this isn't it, keep going.
+ */
+ if ((ATHDIR_SUPPRESSSEARCH & flags) &&
+ !(preferredFlavor & conventions[j].flavor))
+ continue;
+
+ for (current_compat = syscompat; *current_compat != NULL;
+ current_compat++)
+ {
+ complete = !expand(&path, conventions[j].name,
+ base_path, type, *current_compat, hosttype);
+
+ if (!path)
+ return NULL;
+
+ /* If we're listing everything, or we only care about the
+ * first match for creation purposes (both cases where we
+ * don't want to stat()), store this match.
+ */
+ if ((flags & ATHDIR_LISTSEARCHDIRECTORIES) ||
+ ((flags & ATHDIR_SUPPRESSSEARCH) && complete))
+ {
+ if (athdir__add_string(&path_list, path, 0))
+ {
+ free(path);
+ return NULL;
+ }
+ free(path);
+
+ /* In this case (first match for creation) we're done. */
+ if (flags & ATHDIR_SUPPRESSSEARCH)
+ {
+ want_break = 1;
+ break;
+ }
+ }
+ else /* If it's there, store it and be done. */
+ if (complete && !stat(path, &statbuf))
+ {
+ if (athdir__add_string(&path_list, path, 0))
+ {
+ free(path);
+ return NULL;
+ }
+ free(path);
+ want_break = 1;
+ break;
+ }
+ else
+ free(path);
+
+ /* Don't loop over @sys values unless ATSYSflag. */
+ if (!(conventions[j].flavor & ATSYSflag))
+ break;
+ }
+ }
+
+ if (want_break)
+ break;
+ }
+
+ athdir__free_string_array(mysyscompat);
+ return athdir__make_string_array(&path_list);
+}
+
+void athdir_free_paths(char **paths)
+{
+ athdir__free_string_array(paths);
+}
Copied: trunk/athena/lib/athdir/src/athdir.h (from rev 25903, trunk/athena/lib/athdir/athdir.h)
===================================================================
--- trunk/athena/lib/athdir/src/athdir.h (rev 0)
+++ trunk/athena/lib/athdir/src/athdir.h 2013-04-09 21:07:01 UTC (rev 25905)
@@ -0,0 +1,50 @@
+/* $Id: athdir.h,v 1.1 1998-03-17 03:43:09 cfields Exp $ */
+
+/* Copyright 1998 by the Massachusetts Institute of Technology.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * 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.
+ *
+ * * Neither the name of the M.I.T nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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
+ * COPYRIGHT HOLDER OR CONTRIBUTORS 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 ATHDIR__H
+#define ATHDIR__H
+
+#define ATHDIR_SUPPRESSEDITORIALS (1<<0)
+#define ATHDIR_SUPPRESSSEARCH (1<<1)
+#define ATHDIR_MACHINEDEPENDENT (1<<2)
+#define ATHDIR_MACHINEINDEPENDENT (1<<3)
+#define ATHDIR_LISTSEARCHDIRECTORIES (1<<4)
+
+char **athdir_get_paths(char *base_path, char *type,
+ char *sys, char **syscompat, char *machine,
+ char *aux, int flags);
+void athdir_free_paths(char **paths);
+int athdir_native(char *what, char *sys);
+
+#endif
Copied: trunk/athena/lib/athdir/src/athdir.pc.in (from rev 25903, trunk/athena/lib/athdir/athdir.pc.in)
===================================================================
--- trunk/athena/lib/athdir/src/athdir.pc.in (rev 0)
+++ trunk/athena/lib/athdir/src/athdir.pc.in 2013-04-09 21:07:01 UTC (rev 25905)
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: athdir
+Description: The Athena directory location library
+Version: @PACKAGE_VERSION@
+Libs: -L${libdir} -lathdir
+Cflags: -I${includedir}
Copied: trunk/athena/lib/athdir/src/stringlist.c (from rev 25903, trunk/athena/lib/athdir/stringlist.c)
===================================================================
--- trunk/athena/lib/athdir/src/stringlist.c (rev 0)
+++ trunk/athena/lib/athdir/src/stringlist.c 2013-04-09 21:07:01 UTC (rev 25905)
@@ -0,0 +1,207 @@
+/* Copyright 1998 by the Massachusetts Institute of Technology.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * 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.
+ *
+ * * Neither the name of the M.I.T nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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
+ * COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ */
+
+/* This file implements basic string array functions and structures
+ * to be used by software using the athdir library.
+ */
+
+static const char rcsid[] = "$Id: stringlist.c,v 1.2 1999-10-23 19:28:46 danw Exp $";
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "stringlist.h"
+
+#define CHUNKSIZE 10
+
+/* athdir__add_string
+ * Add a copy of "string" to "list," and to the front of "list" if
+ * "front" is false. If "list" is NULL, initialize it as well.
+ */
+int athdir__add_string(string_list **list, char *string, int front)
+{
+ char *newstring;
+ int index;
+
+ /* To add nothing, do nothing. */
+ if (string == NULL)
+ return 0;
+
+ if (list == NULL)
+ return -1;
+
+ /* Initialize the structure if it's NULL. */
+ if (*list == NULL)
+ {
+ *list = malloc(sizeof(string_list));
+
+ if (*list == NULL)
+ return -1;
+
+ (*list)->strings = malloc(CHUNKSIZE * sizeof(char *));
+ if ((*list)->strings == NULL)
+ {
+ free(*list);
+ *list = NULL;
+ return -1;
+ }
+
+ (*list)->alloced = CHUNKSIZE;
+ (*list)->length = 0;
+ (*list)->strings[0] = NULL;
+ }
+
+ /* Allocate more list space if the list is full. */
+ if ((*list)->alloced == (*list)->length + 1) /* must be NULL terminated */
+ {
+ (*list)->strings = realloc((*list)->strings,
+ ((*list)->alloced + CHUNKSIZE) * sizeof(char *));
+ if ((*list)->strings == NULL)
+ {
+ free(*list);
+ return -1;
+ }
+ (*list)->alloced += CHUNKSIZE;
+ }
+
+ /* Make our own copy of the string. */
+ newstring = malloc(strlen(string) + 1);
+ if (newstring == NULL)
+ return -1;
+ strcpy(newstring, string);
+
+ /* Add the string to the list. */
+ if (front)
+ {
+ (*list)->length++;
+ for (index = (*list)->length; index > 0; index--)
+ (*list)->strings[index] = (*list)->strings[index - 1];
+ (*list)->strings[0] = newstring;
+ }
+ else
+ {
+ (*list)->strings[(*list)->length] = newstring;
+ (*list)->length++;
+ (*list)->strings[(*list)->length] = NULL;
+ }
+
+ return 0;
+}
+
+/* athdir__make_string_array
+ * Returns a NULL terminated array of strings (or NULL if the list
+ * is empty) while freeing the surrounding structure. free_string_array
+ * the array when finished.
+ */
+char **athdir__make_string_array(string_list **list)
+{
+ char **strings = NULL;
+
+ if (list != NULL && *list != NULL)
+ {
+ if ((*list)->strings[0] != NULL)
+ strings = (*list)->strings;
+ else
+ free((*list)->strings);
+
+ free(*list);
+ *list = NULL;
+ }
+
+ return strings;
+}
+
+/* athdir__free_string_array
+ * Frees a string array generated by athdir__make_string_array.
+ */
+void athdir__free_string_array(char **array)
+{
+ char **ptr;
+
+ if (array != NULL)
+ {
+ for (ptr = array; *ptr != NULL; ptr++)
+ free(*ptr);
+
+ free(array);
+ }
+}
+
+/* athdir__parse_string
+ * Parse "string" using "sep" as a separator into separate strings, adding
+ * adding each substring to the end of "list." Nondestructive to string,
+ * doesn't point to string.
+ */
+int athdir__parse_string(string_list **list, char *string, char sep)
+{
+ char *ptr, *sep_ptr;
+ char *value;
+ int length;
+
+ if (string != NULL)
+ {
+ /* Allocate a buffer big enough for any substring of string. */
+ value = malloc(strlen(string) + 1);
+ if (value == NULL)
+ return -1;
+
+ ptr = string;
+ while (*ptr != '\0')
+ {
+ /* Figure out the length of this substring. */
+ sep_ptr = strchr(ptr, sep);
+ if (sep_ptr == NULL)
+ length = strlen(ptr);
+ else
+ length = sep_ptr - ptr;
+
+ /* Make a copy to be copied by athdir__add_string. */
+ strncpy(value, ptr, length);
+ value[length] = '\0';
+
+ if (athdir__add_string(list, value, 0))
+ {
+ free(value);
+ return -1;
+ }
+
+ ptr += length;
+ if (*ptr == sep)
+ ptr++;
+ }
+
+ free(value);
+ }
+
+ return 0;
+}
Copied: trunk/athena/lib/athdir/src/stringlist.h (from rev 25903, trunk/athena/lib/athdir/stringlist.h)
===================================================================
--- trunk/athena/lib/athdir/src/stringlist.h (rev 0)
+++ trunk/athena/lib/athdir/src/stringlist.h 2013-04-09 21:07:01 UTC (rev 25905)
@@ -0,0 +1,43 @@
+/* $Id: stringlist.h,v 1.1 1998-03-17 03:44:04 cfields Exp $ */
+
+/* Copyright 1998 by the Massachusetts Institute of Technology.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * 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.
+ *
+ * * Neither the name of the M.I.T nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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
+ * COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ */
+
+typedef struct {
+ int alloced, length;
+ char **strings;
+} string_list;
+
+int athdir__add_string(string_list **list, char *string, int front);
+int athdir__parse_string(string_list **list, char *string, char sep);
+char **athdir__make_string_array(string_list **list);
+void athdir__free_string_array(char **array);