mirror of
https://github.com/macports/pallet.git
synced 2026-07-12 18:18:47 -07:00
Deleting gsoc08-framework branch for macports source files
git-svn-id: https://svn.macports.org/repository/macports/branches/gsoc08-framework@39829 d073be05-634f-4543-b044-5fe20cf6d1d6
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
TCLPKG= @OUR_INCLUDED_PACKAGES@ \
|
||||
cregistry \
|
||||
macports1.0 \
|
||||
port1.0 \
|
||||
package1.0 \
|
||||
pextlib1.0 \
|
||||
registry1.0 \
|
||||
registry2.0 \
|
||||
darwintracelib1.0 \
|
||||
tclobjc1.0
|
||||
SUBDIR= ${TCLPKG} @PATHCONF@ port programs
|
||||
|
||||
all::
|
||||
|
||||
distclean::
|
||||
rm -f config.h
|
||||
rm -f Makefile
|
||||
|
||||
test::
|
||||
|
||||
include ../Mk/macports.subdir.mk
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
OBJS= CFLib.o
|
||||
SHLIB_NAME= CFLib${SHLIB_SUFFIX}
|
||||
LIBS+= -framework CoreFoundation
|
||||
INSTALLDIR= ${DESTDIR}${datadir}/macports/Tcl/cflib1.0
|
||||
|
||||
include ../../Mk/macports.autoconf.mk
|
||||
include ../../Mk/macports.tea.mk
|
||||
@@ -1,293 +0,0 @@
|
||||
/* src/config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define if using the Apple Foundation framework */
|
||||
#undef APPLE_FOUNDATION
|
||||
|
||||
/* Define if using the Apple Objective-C runtime and compiler. */
|
||||
#undef APPLE_RUNTIME
|
||||
|
||||
/* Define to 1 if the `closedir' function returns void instead of `int'. */
|
||||
#undef CLOSEDIR_VOID
|
||||
|
||||
/* Define if using the GNUstep Foundation library */
|
||||
#undef GNUSTEP_FOUNDATION
|
||||
|
||||
/* Define if using the GNU Objective-C runtime and compiler. */
|
||||
#undef GNU_RUNTIME
|
||||
|
||||
/* Define to 1 if you have the `bzero' function. */
|
||||
#undef HAVE_BZERO
|
||||
|
||||
/* Define to 1 if you have the `copyfile' function. */
|
||||
#undef HAVE_COPYFILE
|
||||
|
||||
/* Define to 1 if you have the <crt_externs.h> header file. */
|
||||
#undef HAVE_CRT_EXTERNS_H
|
||||
|
||||
/* Define to 1 if you have the curl_easy_strerror function. */
|
||||
#undef HAVE_CURL_EASY_STRERROR
|
||||
|
||||
/* Define to 1 if you have the declaration of `completion_matches', and to 0
|
||||
if you don't. */
|
||||
#undef HAVE_DECL_COMPLETION_MATCHES
|
||||
|
||||
/* Define to 1 if you have the declaration of `filename_completion_function',
|
||||
and to 0 if you don't. */
|
||||
#undef HAVE_DECL_FILENAME_COMPLETION_FUNCTION
|
||||
|
||||
/* Define to 1 if you have the declaration of `rl_completion_matches', and to
|
||||
0 if you don't. */
|
||||
#undef HAVE_DECL_RL_COMPLETION_MATCHES
|
||||
|
||||
/* Define to 1 if you have the declaration of
|
||||
`rl_filename_completion_function', and to 0 if you don't. */
|
||||
#undef HAVE_DECL_RL_FILENAME_COMPLETION_FUNCTION
|
||||
|
||||
/* Define to 1 if you have the declaration of
|
||||
`rl_username_completion_function', and to 0 if you don't. */
|
||||
#undef HAVE_DECL_RL_USERNAME_COMPLETION_FUNCTION
|
||||
|
||||
/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_STRERROR_R
|
||||
|
||||
/* Define to 1 if you have the declaration of `username_completion_function',
|
||||
and to 0 if you don't. */
|
||||
#undef HAVE_DECL_USERNAME_COMPLETION_FUNCTION
|
||||
|
||||
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_DIRENT_H
|
||||
|
||||
/* Define to 1 if you have the `dup2' function. */
|
||||
#undef HAVE_DUP2
|
||||
|
||||
/* Define to 1 if you have the <err.h> header file. */
|
||||
#undef HAVE_ERR_H
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the `fgetln' function. */
|
||||
#undef HAVE_FGETLN
|
||||
|
||||
/* Define to 1 if you have the `flock' function. */
|
||||
#undef HAVE_FLOCK
|
||||
|
||||
/* Define to 1 if you have the `fork' function. */
|
||||
#undef HAVE_FORK
|
||||
|
||||
/* Define if CoreFoundation framework is available */
|
||||
#undef HAVE_FRAMEWORK_COREFOUNDATION
|
||||
|
||||
/* Define if IOKit framework is available */
|
||||
#undef HAVE_FRAMEWORK_IOKIT
|
||||
|
||||
/* Define if SystemConfiguration framework is available */
|
||||
#undef HAVE_FRAMEWORK_SYSTEMCONFIGURATION
|
||||
|
||||
/* Define if function CFNotificationCenterGetDarwinNotifyCenter in
|
||||
CoreFoundation framework */
|
||||
#undef HAVE_FUNCTION_CFNOTIFICATIONCENTERGETDARWINNOTIFYCENTER
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define if you have the `crypto' library (-lcrypto). */
|
||||
#undef HAVE_LIBCRYPTO
|
||||
|
||||
/* Define to 1 if you have the <libgen.h> header file. */
|
||||
#undef HAVE_LIBGEN_H
|
||||
|
||||
/* Define if you have the `md' library (-lmd). */
|
||||
#undef HAVE_LIBMD
|
||||
|
||||
/* Define to 1 if you have the `readline' library (-lreadline). */
|
||||
#undef HAVE_LIBREADLINE
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#undef HAVE_LIMITS_H
|
||||
|
||||
/* Define to 1 if you have the `lockf' function. */
|
||||
#undef HAVE_LOCKF
|
||||
|
||||
/* Define to 1 if you have the <md5.h> header file. */
|
||||
#undef HAVE_MD5_H
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#undef HAVE_MEMSET
|
||||
|
||||
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
|
||||
#undef HAVE_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <objc/objc.h> header file. */
|
||||
#undef HAVE_OBJC_OBJC_H
|
||||
|
||||
/* Define to 1 if you have the <openssl/md5.h> header file. */
|
||||
#undef HAVE_OPENSSL_MD5_H
|
||||
|
||||
/* Define to 1 if you have the <paths.h> header file. */
|
||||
#undef HAVE_PATHS_H
|
||||
|
||||
/* Define if you have POSIX threads libraries and header files. */
|
||||
#undef HAVE_PTHREAD
|
||||
|
||||
/* Define to 1 if you have the <pwd.h> header file. */
|
||||
#undef HAVE_PWD_H
|
||||
|
||||
/* Define to 1 if you have the <readline/history.h> header file. */
|
||||
#undef HAVE_READLINE_HISTORY_H
|
||||
|
||||
/* Define to 1 if you have the <readline/readline.h> header file. */
|
||||
#undef HAVE_READLINE_READLINE_H
|
||||
|
||||
/* Define to 1 if you have the `regcomp' function. */
|
||||
#undef HAVE_REGCOMP
|
||||
|
||||
/* Define to 1 if you have the `setmode' function. */
|
||||
#undef HAVE_SETMODE
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strcasecmp' function. */
|
||||
#undef HAVE_STRCASECMP
|
||||
|
||||
/* Define to 1 if you have the `strdup' function. */
|
||||
#undef HAVE_STRDUP
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#undef HAVE_STRERROR
|
||||
|
||||
/* Define to 1 if you have the `strerror_r' function. */
|
||||
#undef HAVE_STRERROR_R
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strlcpy' function. */
|
||||
#undef HAVE_STRLCPY
|
||||
|
||||
/* Define to 1 if you have the `strncasecmp' function. */
|
||||
#undef HAVE_STRNCASECMP
|
||||
|
||||
/* Define to 1 if you have the `strtol' function. */
|
||||
#undef HAVE_STRTOL
|
||||
|
||||
/* Define to 1 if you have the <sys/cdefs.h> header file. */
|
||||
#undef HAVE_SYS_CDEFS_H
|
||||
|
||||
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_DIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/fcntl.h> header file. */
|
||||
#undef HAVE_SYS_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/file.h> header file. */
|
||||
#undef HAVE_SYS_FILE_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/paths.h> header file. */
|
||||
#undef HAVE_SYS_PATHS_H
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
|
||||
#undef HAVE_SYS_WAIT_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to 1 if you have the <utime.h> header file. */
|
||||
#undef HAVE_UTIME_H
|
||||
|
||||
/* Define to 1 if you have the `vfork' function. */
|
||||
#undef HAVE_VFORK
|
||||
|
||||
/* Define to 1 if you have the <vfork.h> header file. */
|
||||
#undef HAVE_VFORK_H
|
||||
|
||||
/* Define to 1 if `fork' works. */
|
||||
#undef HAVE_WORKING_FORK
|
||||
|
||||
/* Define to 1 if `vfork' works. */
|
||||
#undef HAVE_WORKING_VFORK
|
||||
|
||||
/* Lowest non-system-reserved GID. */
|
||||
#undef MIN_USABLE_GID
|
||||
|
||||
/* Lowest non-system-reserved UID. */
|
||||
#undef MIN_USABLE_UID
|
||||
|
||||
/* Mark private symbols */
|
||||
#undef MP_PRIVATE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||
your system. */
|
||||
#undef PTHREAD_CREATE_JOINABLE
|
||||
|
||||
/* Define to 1 if readlink does not conform with POSIX 1003.1a (where third
|
||||
argument is a size_t and return value is a ssize_t) */
|
||||
#undef READLINK_IS_NOT_P1003_1A
|
||||
|
||||
/* Define to 1 if static build is requested */
|
||||
#undef STATIC_BUILD
|
||||
|
||||
/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
|
||||
#undef STAT_MACROS_BROKEN
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define to 1 if strerror_r returns char *. */
|
||||
#undef STRERROR_R_CHAR_P
|
||||
|
||||
/* SDK for SDK redirect in tracelib */
|
||||
#undef TRACE_SDK
|
||||
|
||||
/* Attribute to mark unused variables */
|
||||
#undef UNUSED
|
||||
|
||||
/* Define to 1 if the X Window System is missing or not being used. */
|
||||
#undef X_DISPLAY_MISSING
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef pid_t
|
||||
|
||||
/* Define as `fork' if `vfork' does not work. */
|
||||
#undef vfork
|
||||
@@ -1,27 +0,0 @@
|
||||
# $Id$
|
||||
|
||||
OBJS = registry.o entry.o sql.o
|
||||
STLIB_NAME = cregistry.a
|
||||
RANLIB = ranlib
|
||||
|
||||
|
||||
include ../../Mk/macports.autoconf.mk
|
||||
|
||||
|
||||
all:: ${STLIB_NAME}
|
||||
|
||||
.c.o:
|
||||
${CC} -c -DUSE_TCL_STUBS ${CFLAGS} ${TCL_DEFS} ${SHLIB_CFLAGS} $< -o $@
|
||||
|
||||
${STLIB_NAME}:: ${OBJS}
|
||||
${STLIB_LD} ${STLIB_NAME} ${OBJS}
|
||||
${RANLIB} ${STLIB_NAME}
|
||||
|
||||
clean::
|
||||
rm -f ${STLIB_NAME} ${OBJS}
|
||||
|
||||
distclean:: clean
|
||||
|
||||
test:
|
||||
|
||||
install:: ${STLIB_NAME}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* entry.h
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2007 Chris Pickel <sfiera@macports.org>
|
||||
* 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 _CENTRY_H
|
||||
#define _CENTRY_H
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include <cregistry/registry.h>
|
||||
|
||||
typedef enum {
|
||||
reg_strategy_exact = 1,
|
||||
reg_strategy_glob = 2,
|
||||
reg_strategy_regexp = 3
|
||||
} reg_strategy;
|
||||
|
||||
typedef struct {
|
||||
sqlite_int64 id; /* rowid in database */
|
||||
reg_registry* reg; /* associated registry */
|
||||
char* proc; /* name of Tcl proc, if using Tcl */
|
||||
} reg_entry;
|
||||
|
||||
reg_entry* reg_entry_create(reg_registry* reg, char* name, char* version,
|
||||
char* revision, char* variants, char* epoch, reg_error* errPtr);
|
||||
|
||||
reg_entry* reg_entry_open(reg_registry* reg, char* name, char* version,
|
||||
char* revision, char* variants, char* epoch, reg_error* errPtr);
|
||||
|
||||
int reg_entry_delete(reg_entry* entry, reg_error* errPtr);
|
||||
|
||||
void reg_entry_free(reg_entry* entry);
|
||||
|
||||
int reg_entry_search(reg_registry* reg, char** keys, char** vals, int key_count,
|
||||
int strategy, reg_entry*** entries, reg_error* errPtr);
|
||||
|
||||
int reg_entry_imaged(reg_registry* reg, const char* name, const char* version,
|
||||
const char* revision, const char* variants, reg_entry*** entries,
|
||||
reg_error* errPtr);
|
||||
int reg_entry_installed(reg_registry* reg, char* name, reg_entry*** entries,
|
||||
reg_error* errPtr);
|
||||
|
||||
int reg_entry_owner(reg_registry* reg, char* path, reg_entry** entry,
|
||||
reg_error* errPtr);
|
||||
|
||||
int reg_entry_propget(reg_entry* entry, char* key, char** value,
|
||||
reg_error* errPtr);
|
||||
int reg_entry_propset(reg_entry* entry, char* key, char* value,
|
||||
reg_error* errPtr);
|
||||
|
||||
int reg_entry_map(reg_entry* entry, char** files, int file_count,
|
||||
reg_error* errPtr);
|
||||
int reg_entry_unmap(reg_entry* entry, char** files, int file_count,
|
||||
reg_error* errPtr);
|
||||
|
||||
int reg_entry_files(reg_entry* entry, char*** files, reg_error* errPtr);
|
||||
int reg_entry_imagefiles(reg_entry* entry, char*** files, reg_error* errPtr);
|
||||
|
||||
int reg_entry_activate(reg_entry* entry, char** files, char** as_files,
|
||||
int file_count, reg_error* errPtr);
|
||||
int reg_entry_deactivate(reg_entry* entry, char** files, int file_count,
|
||||
reg_error* errPtr);
|
||||
|
||||
int reg_entry_dependents(reg_entry* entry, reg_entry*** dependents,
|
||||
reg_error* errPtr);
|
||||
int reg_entry_dependencies(reg_entry* entry, reg_entry*** dependencies,
|
||||
reg_error* errPtr);
|
||||
int reg_entry_depends(reg_entry* entry, char* name, reg_error* errPtr);
|
||||
|
||||
int reg_all_open_entries(reg_registry* reg, reg_entry*** entries);
|
||||
|
||||
#endif /* _CENTRY_H */
|
||||
@@ -1,388 +0,0 @@
|
||||
/*
|
||||
* registry.c
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2007 Chris Pickel <sfiera@macports.org>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <sqlite3.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <cregistry/entry.h>
|
||||
#include <cregistry/sql.h>
|
||||
|
||||
/*
|
||||
* TODO: maybe all the errPtrs could be made a property of `reg_registry`
|
||||
* instead, and be destroyed with it? That would make memory-management
|
||||
* much easier for errors, and there's no need to have more than one error
|
||||
* alive at any given time.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Destroys a `reg_error` object. This should be called on any reg_error when a
|
||||
* registry function returns a failure condition; depending on the function,
|
||||
* failure could be false, negative, or null.
|
||||
*
|
||||
* @param [in] errPtr the error to destroy
|
||||
*/
|
||||
void reg_error_destruct(reg_error* errPtr) {
|
||||
if (errPtr->free) {
|
||||
errPtr->free(errPtr->description);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets `errPtr` according to the last error in `db`. Convenience function for
|
||||
* internal use only. Sets the error code to REG_SQLITE_ERROR and sets an
|
||||
* appropriate error description (including a query if non-NULL).
|
||||
*
|
||||
* @param [in] db sqlite3 database connection which had the error
|
||||
* @param [out] errPtr an error to write to
|
||||
* @param [in] query the query that this error occurred during
|
||||
*/
|
||||
void reg_sqlite_error(sqlite3* db, reg_error* errPtr, char* query) {
|
||||
errPtr->code = REG_SQLITE_ERROR;
|
||||
errPtr->free = (reg_error_destructor*)sqlite3_free;
|
||||
if (query == NULL) {
|
||||
errPtr->description = sqlite3_mprintf("sqlite error: %s",
|
||||
sqlite3_errmsg(db));
|
||||
} else {
|
||||
errPtr->description = sqlite3_mprintf("sqlite error: %s while "
|
||||
"executing query: %s", sqlite3_errmsg(db), query);
|
||||
}
|
||||
}
|
||||
|
||||
void reg_throw(reg_error* errPtr, char* code, char* fmt, ...) {
|
||||
va_list list;
|
||||
va_start(list, fmt);
|
||||
errPtr->description = sqlite3_vmprintf(fmt, list);
|
||||
va_end(list);
|
||||
|
||||
errPtr->code = code;
|
||||
errPtr->free = (reg_error_destructor*)sqlite3_free;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new registry object. To start using a registry, one must first be
|
||||
* attached with `reg_attach`.
|
||||
*
|
||||
* @param [out] regPtr address of the allocated registry
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int reg_open(reg_registry** regPtr, reg_error* errPtr) {
|
||||
reg_registry* reg = malloc(sizeof(reg_registry));
|
||||
if (sqlite3_open(NULL, ®->db) == SQLITE_OK) {
|
||||
if (init_db(reg->db, errPtr)) {
|
||||
reg->status = reg_none;
|
||||
*regPtr = reg;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
reg_sqlite_error(reg->db, errPtr, NULL);
|
||||
}
|
||||
sqlite3_close(reg->db);
|
||||
free(reg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a registry object. Will detach if necessary.
|
||||
*
|
||||
* @param [in] reg the registry to close
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int reg_close(reg_registry* reg, reg_error* errPtr) {
|
||||
if ((reg->status & reg_attached) && !reg_detach(reg, errPtr)) {
|
||||
return 0;
|
||||
}
|
||||
if (sqlite3_close(reg->db) == SQLITE_OK) {
|
||||
free(reg);
|
||||
return 1;
|
||||
} else {
|
||||
reg_throw(errPtr, REG_SQLITE_ERROR, "registry db not closed correctly "
|
||||
"(%s)\n", sqlite3_errmsg(reg->db));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches a registry database to the registry object. Prior to calling this,
|
||||
* the registry object is not actually connected to the registry. This function
|
||||
* attaches it so it can be queried and manipulated.
|
||||
*
|
||||
* @param [in] reg the registry to attach to
|
||||
* @param [in] path path to the registry db on disk
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int reg_attach(reg_registry* reg, const char* path, reg_error* errPtr) {
|
||||
struct stat sb;
|
||||
int initialized = 1; /* registry already exists */
|
||||
int can_write = 1; /* can write to this location */
|
||||
int result = 0;
|
||||
if (reg->status & reg_attached) {
|
||||
reg_throw(errPtr, REG_MISUSE, "a database is already attached to this "
|
||||
"registry");
|
||||
return 0;
|
||||
}
|
||||
if (stat(path, &sb) != 0) {
|
||||
initialized = 0;
|
||||
if (errno == ENOENT) {
|
||||
char *dirc, *dname;
|
||||
dirc = strdup(path);
|
||||
dname = dirname(dirc);
|
||||
if (stat(dname, &sb) != 0) {
|
||||
can_write = 0;
|
||||
}
|
||||
free(dirc);
|
||||
} else {
|
||||
can_write = 0;
|
||||
}
|
||||
}
|
||||
/* can_write is still true if one of the stat calls succeeded */
|
||||
if (can_write) {
|
||||
if (sb.st_uid == getuid()) {
|
||||
if (!(sb.st_mode & S_IWUSR)) {
|
||||
can_write = 0;
|
||||
}
|
||||
} else if (sb.st_gid == getgid()) {
|
||||
if (!(sb.st_mode & S_IWGRP)) {
|
||||
can_write = 0;
|
||||
}
|
||||
} else {
|
||||
if (!(sb.st_mode & S_IWOTH)) {
|
||||
can_write = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (initialized || can_write) {
|
||||
sqlite3_stmt* stmt;
|
||||
char* query = sqlite3_mprintf("ATTACH DATABASE '%q' AS registry", path);
|
||||
if (sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
|
||||
int r;
|
||||
do {
|
||||
r = sqlite3_step(stmt);
|
||||
switch (r) {
|
||||
case SQLITE_DONE:
|
||||
if (initialized || (create_tables(reg->db, errPtr))) {
|
||||
Tcl_InitHashTable(®->open_entries,
|
||||
sizeof(sqlite_int64)/sizeof(int));
|
||||
reg->status |= reg_attached;
|
||||
result = 1;
|
||||
}
|
||||
break;
|
||||
case SQLITE_BUSY:
|
||||
break;
|
||||
default:
|
||||
reg_sqlite_error(reg->db, errPtr, query);
|
||||
}
|
||||
} while (r == SQLITE_BUSY);
|
||||
} else {
|
||||
reg_sqlite_error(reg->db, errPtr, query);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_free(query);
|
||||
} else {
|
||||
reg_throw(errPtr, REG_CANNOT_INIT, "port registry doesn't exist at "
|
||||
"\"%q\" and couldn't write to this location", path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches a registry database from the registry object. This does some cleanup
|
||||
* for an attached registry, then detaches it. Allocated `reg_entry` objects are
|
||||
* deleted here.
|
||||
*
|
||||
* @param [in] reg registry to detach from
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int reg_detach(reg_registry* reg, reg_error* errPtr) {
|
||||
sqlite3_stmt* stmt;
|
||||
int result = 0;
|
||||
char* query = "DETACH DATABASE registry";
|
||||
if (!(reg->status & reg_attached)) {
|
||||
reg_throw(errPtr,REG_MISUSE,"no database is attached to this registry");
|
||||
return 0;
|
||||
}
|
||||
if (sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
|
||||
int r;
|
||||
reg_entry* entry;
|
||||
Tcl_HashEntry* curr;
|
||||
Tcl_HashSearch search;
|
||||
do {
|
||||
r = sqlite3_step(stmt);
|
||||
switch (r) {
|
||||
case SQLITE_DONE:
|
||||
for (curr = Tcl_FirstHashEntry(®->open_entries, &search);
|
||||
curr != NULL; curr = Tcl_NextHashEntry(&search)) {
|
||||
entry = Tcl_GetHashValue(curr);
|
||||
if (entry->proc) {
|
||||
free(entry->proc);
|
||||
}
|
||||
free(entry);
|
||||
}
|
||||
Tcl_DeleteHashTable(®->open_entries);
|
||||
reg->status &= ~reg_attached;
|
||||
result = 1;
|
||||
break;
|
||||
case SQLITE_BUSY:
|
||||
break;
|
||||
default:
|
||||
reg_sqlite_error(reg->db, errPtr, query);
|
||||
break;
|
||||
}
|
||||
} while (r == SQLITE_BUSY);
|
||||
} else {
|
||||
reg_sqlite_error(reg->db, errPtr, query);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for `reg_start_read` and `reg_start_write`.
|
||||
*/
|
||||
static int reg_start(reg_registry* reg, const char* query, reg_error* errPtr) {
|
||||
if (reg->status & reg_transacting) {
|
||||
reg_throw(errPtr, REG_MISUSE, "couldn't start transaction because a "
|
||||
"transaction is already open");
|
||||
errPtr->free = NULL;
|
||||
return 0;
|
||||
} else {
|
||||
int r;
|
||||
do {
|
||||
r = sqlite3_exec(reg->db, query, NULL, NULL, NULL);
|
||||
if (r == SQLITE_OK) {
|
||||
return 1;
|
||||
}
|
||||
} while (r == SQLITE_BUSY);
|
||||
reg_sqlite_error(reg->db, errPtr, NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a read transaction on registry. This acquires a shared lock on the
|
||||
* database. It must be released with `reg_commit` or `reg_rollback` (it doesn't
|
||||
* actually matter which, since the transaction won't have changed any values).
|
||||
*
|
||||
* @param [in] reg registry to start transaction on
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int reg_start_read(reg_registry* reg, reg_error* errPtr) {
|
||||
if (reg_start(reg, "BEGIN", errPtr)) {
|
||||
reg->status |= reg_transacting;
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a write transaction on registry. This acquires an exclusive lock on
|
||||
* the database. It must be released with `reg_commit` or `reg_rollback`.
|
||||
*
|
||||
* @param [in] reg registry to start transaction on
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int reg_start_write(reg_registry* reg, reg_error* errPtr) {
|
||||
if (reg_start(reg, "BEGIN EXCLUSIVE", errPtr)) {
|
||||
reg->status |= reg_transacting | reg_can_write;
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for `reg_commit` and `reg_rollback`.
|
||||
*/
|
||||
static int reg_end(reg_registry* reg, const char* query, reg_error* errPtr) {
|
||||
if (!(reg->status & reg_transacting)) {
|
||||
reg_throw(errPtr, REG_MISUSE, "couldn't end transaction because no "
|
||||
"transaction is open");
|
||||
return 0;
|
||||
} else {
|
||||
int r;
|
||||
do {
|
||||
r = sqlite3_exec(reg->db, query, NULL, NULL, NULL);
|
||||
if (r == SQLITE_OK) {
|
||||
return 1;
|
||||
}
|
||||
} while (r == SQLITE_BUSY);
|
||||
reg_sqlite_error(reg->db, errPtr, NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits the current transaction. All values written since `reg_start_*` was
|
||||
* called will be written to the database.
|
||||
*
|
||||
* @param [in] reg registry to commit transaction to
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int reg_commit(reg_registry* reg, reg_error* errPtr) {
|
||||
if (reg_end(reg, "COMMIT", errPtr)) {
|
||||
reg->status &= ~(reg_transacting | reg_can_write);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rolls back the current transaction. All values written since `reg_start_*`
|
||||
* was called will be reverted, and no changes will be written to the database.
|
||||
*
|
||||
* @param [in] reg registry to roll back transaction from
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int reg_rollback(reg_registry* reg, reg_error* errPtr) {
|
||||
if (reg_end(reg, "ROLLBACK", errPtr)) {
|
||||
reg->status &= ~(reg_transacting | reg_can_write);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* registry.h
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2007 Chris Pickel <sfiera@macports.org>
|
||||
* 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 _CREG_H
|
||||
#define _CREG_H
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include <tcl.h>
|
||||
|
||||
#define REG_NOT_FOUND "registry::not-found"
|
||||
#define REG_INVALID "registry::invalid"
|
||||
#define REG_CONSTRAINT "registry::constraint"
|
||||
#define REG_SQLITE_ERROR "registry::sqlite-error"
|
||||
#define REG_MISUSE "registry::misuse"
|
||||
#define REG_CANNOT_INIT "registry::cannot-init"
|
||||
#define REG_ALREADY_ACTIVE "registry::already-active"
|
||||
|
||||
typedef void reg_error_destructor(const char* description);
|
||||
|
||||
typedef struct {
|
||||
char* code;
|
||||
const char* description;
|
||||
reg_error_destructor* free;
|
||||
} reg_error;
|
||||
|
||||
void reg_sqlite_error(sqlite3* db, reg_error* errPtr, char* query);
|
||||
void reg_error_destruct(reg_error* errPtr);
|
||||
void reg_throw(reg_error* errPtr, char* code, char* fmt, ...);
|
||||
|
||||
typedef int (cast_function)(void* userdata, void** dst, void* src,
|
||||
reg_error* errPtr);
|
||||
typedef void (free_function)(void* userdata, void* item);
|
||||
|
||||
enum {
|
||||
reg_none = 0,
|
||||
reg_attached = 1,
|
||||
reg_transacting = 2,
|
||||
reg_can_write = 4
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
sqlite3* db;
|
||||
int status;
|
||||
Tcl_HashTable open_entries;
|
||||
} reg_registry;
|
||||
|
||||
int reg_open(reg_registry** regPtr, reg_error* errPtr);
|
||||
int reg_close(reg_registry* reg, reg_error* errPtr);
|
||||
|
||||
int reg_attach(reg_registry* reg, const char* path, reg_error* errPtr);
|
||||
int reg_detach(reg_registry* reg, reg_error* errPtr);
|
||||
|
||||
int reg_start_read(reg_registry* reg, reg_error* errPtr);
|
||||
int reg_start_write(reg_registry* reg, reg_error* errPtr);
|
||||
int reg_commit(reg_registry* reg, reg_error* errPtr);
|
||||
int reg_rollback(reg_registry* reg, reg_error* errPtr);
|
||||
|
||||
#endif /* _CREG_H */
|
||||
@@ -1,348 +0,0 @@
|
||||
/*
|
||||
* sql.c
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2007 Chris Pickel <sfiera@macports.org>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <tcl.h>
|
||||
#include <sqlite3.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <cregistry/registry.h>
|
||||
#include <cregistry/sql.h>
|
||||
|
||||
/*
|
||||
* TODO: maybe this could be made into something that could be separately loaded
|
||||
* by sqlite3? It's a bit hard to query the registry with the command-line
|
||||
* sqlite3 tool because of the missing VERSION collation. My understanding
|
||||
* is that you can make a dylib that can be loaded using an sql statement,
|
||||
* which is less than transparent, but certainly reasonable.
|
||||
*
|
||||
* TODO: break out rpm_vercomp into a separate file which can be shared by
|
||||
* pextlib and cregistry. The version here is slightly modified so as to
|
||||
* take explicit string lengths. Since these are available in Tcl it's an
|
||||
* easy change and might be a tiny bit faster; it's necessary for the
|
||||
* application here.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Executes a null-terminated list of queries. Pass it a list of queries, it'll
|
||||
* execute them. This is mainly intended for initialization, when you have a
|
||||
* number of standard queries to execute.
|
||||
*
|
||||
* @param [in] db database to execute queries on
|
||||
* @param [in] queries NULL-terminated list of queries
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int do_queries(sqlite3* db, char** queries, reg_error* errPtr) {
|
||||
char** query;
|
||||
for (query = queries; *query != NULL; query++) {
|
||||
sqlite3_stmt* stmt;
|
||||
if ((sqlite3_prepare(db, *query, -1, &stmt, NULL) != SQLITE_OK)
|
||||
|| (sqlite3_step(stmt) != SQLITE_DONE)) {
|
||||
reg_sqlite_error(db, errPtr, *query);
|
||||
sqlite3_finalize(stmt);
|
||||
return 0;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* REGEXP function for sqlite3. Takes two arguments; the first is the value and
|
||||
* the second the pattern. If the pattern is invalid, errors out. Otherwise,
|
||||
* returns true if the value matches the pattern and false otherwise.
|
||||
*
|
||||
* This function is made available in sqlite3 as the REGEXP operator.
|
||||
*
|
||||
* @param [in] context sqlite3-defined structure
|
||||
* @param [in] argc number of arguments - always 2 and hence unused
|
||||
* @param [in] argv 0: value to match; 1: pattern to match against
|
||||
*/
|
||||
static void sql_regexp(sqlite3_context* context, int argc UNUSED,
|
||||
sqlite3_value** argv) {
|
||||
const char* value = (const char*)sqlite3_value_text(argv[0]);
|
||||
const char* pattern = (const char*)sqlite3_value_text(argv[1]);
|
||||
switch (Tcl_RegExpMatch(NULL, value, pattern)) {
|
||||
case 0:
|
||||
sqlite3_result_int(context, 0);
|
||||
break;
|
||||
case 1:
|
||||
sqlite3_result_int(context, 1);
|
||||
break;
|
||||
case -1:
|
||||
sqlite3_result_error(context, "invalid pattern", -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NOW function for sqlite3. Takes no arguments. Returns the unix timestamp of
|
||||
* the current time.
|
||||
*
|
||||
* @param [in] context sqlite3-defined structure
|
||||
* @param [in] argc number of arguments - always 2 and hence unused
|
||||
* @param [in] argv 0: value to match; 1: pattern to match against
|
||||
*/
|
||||
static void sql_now(sqlite3_context* context, int argc UNUSED,
|
||||
sqlite3_value** argv UNUSED) {
|
||||
sqlite3_result_int(context, time(NULL));
|
||||
}
|
||||
|
||||
/**
|
||||
* RPM version comparison. Shamelessly copied from Pextlib, with some changes to
|
||||
* use string lengths instead of strlen by default. That's necessary to make it
|
||||
* work with sqlite3 collations. It should be shared with Pextlib, rather than
|
||||
* just copied though.
|
||||
*
|
||||
* @param [in] versionA first version string, i.e. "1.4.1"
|
||||
* @param [in] lengthA length of first version string, or -1 to use strlen
|
||||
* @param [in] versionB second version string, i.e. "1.4.2"
|
||||
* @param [in] lengthA length of second version string, or -1 to use strlen
|
||||
* @return -1 if A < B; 0 if A = B; 1 if A > B
|
||||
*/
|
||||
static int rpm_vercomp (const char *versionA, int lengthA, const char *versionB,
|
||||
int lengthB) {
|
||||
const char *endA, *endB;
|
||||
const char *ptrA, *ptrB;
|
||||
const char *eptrA, *eptrB;
|
||||
|
||||
if (lengthA < 0)
|
||||
lengthA = strlen(versionA);
|
||||
if (lengthB < 0)
|
||||
lengthB = strlen(versionB);
|
||||
|
||||
/* if versions equal, return zero */
|
||||
if(lengthA == lengthB && !strncmp(versionA, versionB, lengthA))
|
||||
return 0;
|
||||
|
||||
ptrA = versionA;
|
||||
ptrB = versionB;
|
||||
endA = versionA + lengthA;
|
||||
endB = versionB + lengthB;
|
||||
while (ptrA != endA && ptrB != endB) {
|
||||
/* skip all non-alphanumeric characters */
|
||||
while (ptrA != endB && !isalnum(*ptrA))
|
||||
ptrA++;
|
||||
while (ptrB != endB && !isalnum(*ptrB))
|
||||
ptrB++;
|
||||
|
||||
eptrA = ptrA;
|
||||
eptrB = ptrB;
|
||||
|
||||
/* Somewhat arbitrary rules as per RPM's implementation.
|
||||
* This code could be more clever, but we're aiming
|
||||
* for clarity instead. */
|
||||
|
||||
/* If versionB's segment is not a digit segment, but
|
||||
* versionA's segment IS a digit segment, return 1.
|
||||
* (Added for redhat compatibility. See redhat bugzilla
|
||||
* #50977 for details) */
|
||||
if (!isdigit(*ptrB)) {
|
||||
if (isdigit(*ptrA))
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Otherwise, if the segments are of different types,
|
||||
* return -1 */
|
||||
|
||||
if ((isdigit(*ptrA) && isalpha(*ptrB)) || (isalpha(*ptrA) && isdigit(*ptrB)))
|
||||
return -1;
|
||||
|
||||
/* Find the first segment composed of entirely alphabetical
|
||||
* or numeric members */
|
||||
if (isalpha(*ptrA)) {
|
||||
while (eptrA != endA && isalpha(*eptrA))
|
||||
eptrA++;
|
||||
|
||||
while (eptrB != endB && isalpha(*eptrB))
|
||||
eptrB++;
|
||||
} else {
|
||||
int countA = 0, countB = 0;
|
||||
while (eptrA != endA && isdigit(*eptrA)) {
|
||||
countA++;
|
||||
eptrA++;
|
||||
}
|
||||
while (eptrB != endB && isdigit(*eptrB)) {
|
||||
countB++;
|
||||
eptrB++;
|
||||
}
|
||||
|
||||
/* skip leading '0' characters */
|
||||
while (ptrA != eptrA && *ptrA == '0') {
|
||||
ptrA++;
|
||||
countA--;
|
||||
}
|
||||
while (ptrB != eptrB && *ptrB == '0') {
|
||||
ptrB++;
|
||||
countB--;
|
||||
}
|
||||
|
||||
/* If A is longer than B, return 1 */
|
||||
if (countA > countB)
|
||||
return 1;
|
||||
|
||||
/* If B is longer than A, return -1 */
|
||||
if (countB > countA)
|
||||
return -1;
|
||||
}
|
||||
/* Compare strings lexicographically */
|
||||
while (ptrA != eptrA && ptrB != eptrB && *ptrA == *ptrB) {
|
||||
ptrA++;
|
||||
ptrB++;
|
||||
}
|
||||
if (ptrA != eptrA && ptrB != eptrB)
|
||||
return *ptrA - *ptrB;
|
||||
|
||||
ptrA = eptrA;
|
||||
ptrB = eptrB;
|
||||
}
|
||||
|
||||
/* If both pointers are null, all alphanumeric
|
||||
* characters were identical and only seperating
|
||||
* characters differed. According to RPM, these
|
||||
* version strings are equal */
|
||||
if (ptrA == endA && ptrB == endB)
|
||||
return 0;
|
||||
|
||||
/* If A has unchecked characters, return 1
|
||||
* Otherwise, if B has remaining unchecked characters,
|
||||
* return -1 */
|
||||
if (ptrA != endA)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* VERSION collation for sqlite3. This function collates text according to
|
||||
* pextlib's rpm-vercomp function. This allows direct comparison and sorting of
|
||||
* version columns, such as port.version and port.revision.
|
||||
*
|
||||
* @param [in] userdata unused
|
||||
* @param [in] alen length of first string
|
||||
* @param [in] a first string
|
||||
* @param [in] blen length of second string
|
||||
* @param [in] b second string
|
||||
* @return -1 if a < b; 0 if a = b; 1 if a > b
|
||||
*/
|
||||
static int sql_version(void* userdata UNUSED, int alen, const void* a, int blen,
|
||||
const void* b) {
|
||||
return rpm_vercomp((const char*)a, alen, (const char*)b, blen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates tables in the registry. This function is called upon an uninitialized
|
||||
* database to create the tables needed to record state between invocations of
|
||||
* `port`.
|
||||
*
|
||||
* @param [in] db database with an attached registry db
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int create_tables(sqlite3* db, reg_error* errPtr) {
|
||||
static char* queries[] = {
|
||||
"BEGIN",
|
||||
|
||||
/* metadata table */
|
||||
"CREATE TABLE registry.metadata (key UNIQUE, value)",
|
||||
"INSERT INTO registry.metadata (key, value) VALUES ('version', 1.000)",
|
||||
"INSERT INTO registry.metadata (key, value) VALUES ('created', NOW())",
|
||||
|
||||
/* ports table */
|
||||
"CREATE TABLE registry.ports ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
"name, portfile, url, location, epoch, version COLLATE VERSION, "
|
||||
"revision COLLATE VERSION, variants, default_variants, state, "
|
||||
"date, installtype, "
|
||||
"UNIQUE (name, epoch, version, revision, variants), "
|
||||
"UNIQUE (url, epoch, version, revision, variants)"
|
||||
")",
|
||||
"CREATE INDEX registry.port_name ON ports "
|
||||
"(name, epoch, version, revision, variants)",
|
||||
"CREATE INDEX registry.port_url ON ports "
|
||||
"(url, epoch, version, revision, variants)",
|
||||
"CREATE INDEX registry.port_state ON ports (state)",
|
||||
|
||||
/* file map */
|
||||
"CREATE TABLE registry.files (id, path, actual_path, active, mtime, "
|
||||
"md5sum, editable)",
|
||||
"CREATE INDEX registry.file_port ON files (id)",
|
||||
"CREATE INDEX registry.file_path ON files(path)",
|
||||
"CREATE INDEX registry.file_actual ON files(actual_path)",
|
||||
|
||||
/* dependency map */
|
||||
"CREATE TABLE registry.dependencies (id, name)",
|
||||
"CREATE INDEX registry.dep_name ON dependencies (name)",
|
||||
|
||||
"COMMIT",
|
||||
NULL
|
||||
};
|
||||
return do_queries(db, queries, errPtr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes database connection. This function creates all the temporary
|
||||
* tables used by the registry. It also registers the user functions and
|
||||
* collations declared here, making them available.
|
||||
*
|
||||
* @param [in] db database to initialize
|
||||
* @param [out] errPtr on error, a description of the error that occurred
|
||||
* @return true if success; false if failure
|
||||
*/
|
||||
int init_db(sqlite3* db, reg_error* errPtr) {
|
||||
static char* queries[] = {
|
||||
"BEGIN",
|
||||
|
||||
/* items cache */
|
||||
"CREATE TEMPORARY TABLE items (refcount, proc UNIQUE, name, url, path, "
|
||||
"worker, options, variants)",
|
||||
|
||||
/* indexes list */
|
||||
"CREATE TEMPORARY TABLE indexes (file, name, attached)",
|
||||
|
||||
"COMMIT",
|
||||
NULL
|
||||
};
|
||||
|
||||
/* I'm not error-checking these. I don't think I need to. */
|
||||
sqlite3_create_function(db, "REGEXP", 2, SQLITE_UTF8, NULL, sql_regexp,
|
||||
NULL, NULL);
|
||||
sqlite3_create_function(db, "NOW", 0, SQLITE_ANY, NULL, sql_now, NULL,
|
||||
NULL);
|
||||
|
||||
sqlite3_create_collation(db, "VERSION", SQLITE_UTF8, NULL, sql_version);
|
||||
|
||||
return do_queries(db, queries, errPtr);
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* sql.h
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2007 Chris Pickel <sfiera@macports.org>
|
||||
* 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 _SQL_H
|
||||
#define _SQL_H
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include <cregistry/registry.h>
|
||||
|
||||
int create_tables(sqlite3* db, reg_error* errPtr);
|
||||
int init_db(sqlite3* db, reg_error* errPtr);
|
||||
|
||||
#endif /* _SQL_H */
|
||||
@@ -1,8 +0,0 @@
|
||||
OBJS= darwintrace.o
|
||||
SHLIB_NAME= darwintrace${SHLIB_SUFFIX}
|
||||
INSTALLDIR= ${DESTDIR}${datadir}/macports/Tcl/darwintrace1.0
|
||||
|
||||
test::
|
||||
|
||||
include ../../Mk/macports.autoconf.mk
|
||||
include ../../Mk/macports.tea.mk
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,27 +0,0 @@
|
||||
SRCS= macports.tcl macports_dlist.tcl macports_util.tcl \
|
||||
macports_autoconf.tcl macports_index.tcl macports_fastload.tcl
|
||||
OBJS= macports.o portconf.o session.o util.o
|
||||
SHLIB_NAME= MacPorts${SHLIB_SUFFIX}
|
||||
|
||||
INSTALLDIR= ${DESTDIR}${TCL_PACKAGE_DIR}/macports1.0
|
||||
|
||||
include ../../Mk/macports.autoconf.mk
|
||||
include ../../Mk/macports.tea.mk
|
||||
|
||||
test::
|
||||
${TCLSH} tests/macports_dlist.tcl
|
||||
${TCLSH} tests/macports_util.tcl
|
||||
|
||||
distclean:: clean
|
||||
rm -f macports_autoconf.tcl macports_fastload.tcl ${SHLIB_NAME}
|
||||
|
||||
install::
|
||||
$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} ${INSTALLDIR}
|
||||
|
||||
$(SILENT) set -x; for file in ${SRCS}; do \
|
||||
$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 $$file ${INSTALLDIR}/$$file; \
|
||||
done
|
||||
|
||||
echo "${TCL_PACKAGE_DIR}" > ${DESTDIR}${prefix}/var/macports/.tclpackage
|
||||
|
||||
$(SILENT) $(TCLSH) ../pkg_mkindex.tcl ${INSTALLDIR}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* macports.c
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2003 Apple Computer, Inc.
|
||||
* 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.
|
||||
* 3. Neither the name of Apple Computer, Inc. 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 OWNER 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.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <tcl.h>
|
||||
|
||||
int macports_Init(Tcl_Interp *interp)
|
||||
{
|
||||
if(Tcl_InitStubs(interp, "8.3", 0) == NULL)
|
||||
return TCL_ERROR;
|
||||
if(Tcl_PkgProvide(interp, "macports", "1.0") != TCL_OK)
|
||||
return TCL_ERROR;
|
||||
return TCL_OK;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* macports.h
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2003 Apple Computer, Inc.
|
||||
* 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.
|
||||
* 3. Neither the name of Apple Computer, Inc. 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 OWNER 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 __MACPORTS_H__
|
||||
#define __MACPORTS_H__
|
||||
|
||||
typedef void* mp_session_t;
|
||||
typedef void* mp_software_t;
|
||||
|
||||
typedef void* mp_array_t;
|
||||
mp_array_t mp_array_create();
|
||||
mp_array_t mp_array_create_copy(mp_array_t a);
|
||||
mp_array_t mp_array_retain(mp_array_t a);
|
||||
void mp_array_release(mp_array_t a);
|
||||
void mp_array_append(mp_array_t a, const void* data);
|
||||
int mp_array_get_count(mp_array_t a);
|
||||
const void* mp_array_get_index(mp_array_t a, int index);
|
||||
/* something for delete */
|
||||
|
||||
mp_session_t mp_session_open();
|
||||
int mp_session_sync_index();
|
||||
|
||||
int mp_software_search(mp_session_t mp, const char* regexp, mp_software_t* out_matches, int* out_count);
|
||||
mp_software_t mp_software_open_portfile(mp_session_t mp, const char* path, const char** options);
|
||||
mp_session_t mp_software_get_session(mp_software_t sw);
|
||||
mp_software_t mp_software_exec(mp_software_t sw, const char* target);
|
||||
int mp_softare_close(mp_software_t sw);
|
||||
|
||||
int mp_session_close();
|
||||
|
||||
#endif /* __MACPORTS_H__ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,47 +0,0 @@
|
||||
Index: macports.tcl
|
||||
===================================================================
|
||||
--- macports.tcl (revision 37802)
|
||||
+++ macports.tcl (working copy)
|
||||
@@ -76,6 +76,13 @@
|
||||
# ui_channels returns a list of channels to output the message to, empty for
|
||||
# no message.
|
||||
# if these functions are not provided, defaults are used.
|
||||
+# Clients of the library may optionally provide ui_init with the following
|
||||
+# prototype.
|
||||
+# proc ui_init {priority prefix channels message}
|
||||
+# ui_init needs to correctly define the proc ::ui_$priority {message} or throw
|
||||
+# an error.
|
||||
+# if this function is not provided or throws an error, default procedures for
|
||||
+# ui_$priority are defined.
|
||||
|
||||
# ui_options accessor
|
||||
proc macports::ui_isset {val} {
|
||||
@@ -118,15 +125,19 @@
|
||||
set prefix [ui_prefix_default $priority]
|
||||
}
|
||||
|
||||
- if {$nbchans == 1} {
|
||||
- set chan [lindex $channels 0]
|
||||
- proc ::ui_$priority {str} [subst { puts $chan "$prefix\$str" }]
|
||||
- } else {
|
||||
- proc ::ui_$priority {str} [subst {
|
||||
- foreach chan \$channels {
|
||||
- puts $chan "$prefix\$str"
|
||||
- }
|
||||
- }]
|
||||
+ try {
|
||||
+ ::ui_init $priority $prefix $channels $message
|
||||
+ } catch * {
|
||||
+ if {$nbchans == 1} {
|
||||
+ set chan [lindex $channels 0]
|
||||
+ proc ::ui_$priority {str} [subst { puts $chan "$prefix\$str" }]
|
||||
+ } else {
|
||||
+ proc ::ui_$priority {str} [subst {
|
||||
+ foreach chan \$channels {
|
||||
+ puts $chan "$prefix\$str"
|
||||
+ }
|
||||
+ }]
|
||||
+ }
|
||||
}
|
||||
|
||||
# Call ui_$priority
|
||||
@@ -1,41 +0,0 @@
|
||||
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
|
||||
# macports-autoconf.tcl.in
|
||||
# $Id$
|
||||
#
|
||||
# Copyright (c) 2002 - 2003 Apple Computer, Inc.
|
||||
# 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.
|
||||
# 3. Neither the name of Apple Computer, Inc. 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 OWNER 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.
|
||||
#
|
||||
package provide macports 1.0
|
||||
|
||||
namespace eval macports::autoconf {
|
||||
variable macports_conf_path "@MPCONFIGDIR_EXPANDED@"
|
||||
variable macports_version "@MP_VERSION@"
|
||||
variable macports_user_dir "~/.macports"
|
||||
variable svn_path "@SVN@"
|
||||
variable rsync_path "@RSYNC@"
|
||||
variable open_path "@OPEN@"
|
||||
}
|
||||
@@ -1,393 +0,0 @@
|
||||
# macports1.0/macports_dlist.tcl
|
||||
# $Id$
|
||||
#
|
||||
# Copyright (c) 2003 Kevin Van Vechten <kevin@opendarwin.org>
|
||||
# Copyright (c) 2002 Apple Computer, Inc.
|
||||
# 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.
|
||||
# 3. Neither the name of Apple Computer, Inc. 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 OWNER 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.
|
||||
|
||||
package provide macports_dlist 1.0
|
||||
|
||||
# dependency dependency list evaluation package
|
||||
#
|
||||
# This package provides a generic mechanism for managing a list of
|
||||
# dependencies. The basic model is that each dependency item
|
||||
# contains a list of tokens it Requires and tokens it Provides.
|
||||
# A dependency is selected once all of the tokens it Requires have
|
||||
# been provided by another dependency, or if a dependency has no
|
||||
# requirements.
|
||||
|
||||
# Conceptually a dlist is an ordered list of ditem elements.
|
||||
# The order perserves the dependency hierarchy.
|
||||
|
||||
# A dlist is an ordinary TCL list.
|
||||
# A ditem should be created with the [ditem_create] procedure,
|
||||
# and treated as an opaque reference.
|
||||
# A statusdict is an ordinary TCL array, though macports_dlist
|
||||
# should be given complete domain over its contents.
|
||||
# XXX: should statusdict and dlist be part of a ditem tuple?
|
||||
# Values in the status dict will be {-1, 0, 1} for {failure,
|
||||
# pending, success} respectively.
|
||||
|
||||
# dlist_search
|
||||
# Returns all dependency entries whose 'key' contains 'value'.
|
||||
# dlist - the dependency list to search
|
||||
# key - the key to compare: Requires, Provides, et al.
|
||||
# value - the value to compare
|
||||
|
||||
proc dlist_search {dlist key value} {
|
||||
set result {}
|
||||
foreach ditem $dlist {
|
||||
if {[ditem_contains $ditem $key $value]} {
|
||||
lappend result $ditem
|
||||
}
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
# dlist_delete
|
||||
# Deletes the specified ditem from the dlist.
|
||||
# dlist - the list to search
|
||||
# ditem - the item to delete
|
||||
proc dlist_delete {dlist ditem} {
|
||||
upvar $dlist uplist
|
||||
set ix [lsearch -exact $uplist $ditem]
|
||||
if {$ix >= 0} {
|
||||
set uplist [lreplace $uplist $ix $ix]
|
||||
}
|
||||
}
|
||||
|
||||
# dlist_has_pending
|
||||
# Returns true if the dlist contains ditems
|
||||
# which will provide one of the specified names,
|
||||
# and thus are still "pending".
|
||||
# dlist - the dependency list to search
|
||||
# tokens - the list of pending tokens to check for
|
||||
|
||||
proc dlist_has_pending {dlist tokens} {
|
||||
foreach token $tokens {
|
||||
if {[llength [dlist_search $dlist provides $token]] > 0} {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
# dlist_count_unmet
|
||||
# Returns the total number of unmet dependencies in
|
||||
# the list of tokens. If the tokens are in the status
|
||||
# dictionary with a successful result code, they are
|
||||
# considered met.
|
||||
proc dlist_count_unmet {dlist statusdict tokens} {
|
||||
upvar $statusdict upstatus
|
||||
set result 0
|
||||
foreach token $tokens {
|
||||
if {[info exists upstatus($token)] &&
|
||||
$upstatus($token) == 1} {
|
||||
continue
|
||||
} else {
|
||||
incr result
|
||||
}
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
# ditem_create
|
||||
# Create a new array in the macports_dlist namespace
|
||||
# returns the name of the array. This should be used as
|
||||
# the ditem handle.
|
||||
|
||||
proc ditem_create {} {
|
||||
return [macports_dlist::ditem_create]
|
||||
}
|
||||
|
||||
# ditem_key
|
||||
# Sets and returns the given key of the dependency item.
|
||||
# ditem - the dependency item to operate on
|
||||
# key - the key to set
|
||||
# value - optional value to set the key to
|
||||
|
||||
proc ditem_key {ditem args} {
|
||||
set nbargs [llength $args]
|
||||
if {$nbargs > 1} {
|
||||
return [macports_dlist::ditem_key $ditem [lindex $args 0] [lindex $args 1]]
|
||||
} elseif {$nbargs == 1} {
|
||||
return [macports_dlist::ditem_key $ditem [lindex $args 0]]
|
||||
} else {
|
||||
return [macports_dlist::ditem_key $ditem]
|
||||
}
|
||||
}
|
||||
|
||||
# ditem_append
|
||||
# Appends the value to the given key of the dependency item.
|
||||
# ditem - the dependency item to operate on
|
||||
# key - the key to append to
|
||||
# value - the value to append to the key
|
||||
|
||||
proc ditem_append {ditem key args} {
|
||||
eval "return \[macports_dlist::ditem_append $ditem $key $args\]"
|
||||
}
|
||||
|
||||
# ditem_append_unique
|
||||
# Appends the value to the given key of the dependency item if
|
||||
# they were not there yet.
|
||||
# ditem - the dependency item to operate on
|
||||
# key - the key to append to
|
||||
# value - the value to append to the key
|
||||
|
||||
proc ditem_append_unique {ditem key args} {
|
||||
eval "return \[macports_dlist::ditem_append_unique $ditem $key $args\]"
|
||||
}
|
||||
|
||||
# ditem_contains
|
||||
# Tests whether the ditem key contains the specified value;
|
||||
# or if the value is omitted, tests whether the key exists.
|
||||
# ditem - the dependency item to test
|
||||
# key - the key to examine
|
||||
# value - optional value to search for in the key
|
||||
proc ditem_contains {ditem key args} {
|
||||
eval "return \[macports_dlist::ditem_contains $ditem $key $args\]"
|
||||
}
|
||||
|
||||
# dlist_append_dependents
|
||||
# Returns the ditems which are dependents of the ditem specified.
|
||||
# dlist - the dependency list to search
|
||||
# ditem - the item which itself, and its dependents should be selected
|
||||
# result - used for recursing, pass empty initially.
|
||||
|
||||
proc dlist_append_dependents {dlist ditem result} {
|
||||
# Only append things if the root item is not in the list.
|
||||
# (otherwise, it means we already did this sub-graph)
|
||||
if {[lsearch $result $ditem] == -1} {
|
||||
lappend result $ditem
|
||||
|
||||
# Recursively append any hard dependencies.
|
||||
foreach token [ditem_key $ditem requires] {
|
||||
foreach provider [dlist_search $dlist provides $token] {
|
||||
set result [dlist_append_dependents $dlist $provider $result]
|
||||
}
|
||||
}
|
||||
# XXX: add soft-dependencies?
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
# dlist_get_next
|
||||
# Returns the any eligible item from the dependency list.
|
||||
# Eligibility is a function of the ditems in the list and
|
||||
# the status dictionary. A ditem is eligible when all of
|
||||
# the services it Requires are present in the status
|
||||
# dictionary with a successful result code.
|
||||
#
|
||||
# Notes: this implementation of get next defers items based
|
||||
# on unfulfilled tokens in the Uses key. However these items
|
||||
# will eventually be returned if there are no alternatives.
|
||||
# Soft-dependencies can be implemented in this way.
|
||||
# dlist - the dependency list to select from
|
||||
# statusdict - the status dictionary describing the history
|
||||
# of the dependency list.
|
||||
|
||||
proc dlist_get_next {dlist statusdict} {
|
||||
upvar $statusdict upstatus
|
||||
set nextitem {}
|
||||
|
||||
# arbitrary large number ~ INT_MAX
|
||||
set minfailed 2000000000
|
||||
|
||||
foreach ditem $dlist {
|
||||
# Skip if the ditem has unsatisfied hard dependencies
|
||||
if {[dlist_count_unmet $dlist upstatus [ditem_key $ditem requires]]} {
|
||||
continue
|
||||
}
|
||||
|
||||
# We will favor the ditem with the fewest unmet soft dependencies
|
||||
set unmet [dlist_count_unmet $dlist upstatus [ditem_key $ditem uses]]
|
||||
|
||||
# Delay items with unment soft dependencies that can eventually be met
|
||||
if {$unmet > 0 && [dlist_has_pending $dlist [ditem_key $ditem uses]]} {
|
||||
continue
|
||||
}
|
||||
|
||||
if {$unmet >= $minfailed} {
|
||||
# not better than the last pick
|
||||
continue
|
||||
} else {
|
||||
# better than the last pick (fewer unmet soft deps)
|
||||
set minfailed $unmet
|
||||
set nextitem $ditem
|
||||
}
|
||||
}
|
||||
return $nextitem
|
||||
}
|
||||
|
||||
# dlist_eval
|
||||
# Evaluate the dlist, select each eligible ditem according to
|
||||
# the optional selector argument (the default selector is
|
||||
# dlist_get_next). The specified handler is then invoked on
|
||||
# each ditem in the order they are selected. When no more
|
||||
# ditems are eligible to run (the selector returns {}) then
|
||||
# dlist_eval will exit with a list of the remaining ditems,
|
||||
# or {} if all ditems were evaluated.
|
||||
# dlist - the dependency list to evaluate
|
||||
# testcond - test condition to populate the status dictionary
|
||||
# should return {-1, 0, 1}
|
||||
# handler - the handler to invoke on each ditem
|
||||
# canfail - If 1, then progress will not stop when a failure
|
||||
# occures; if 0, then dlist_eval will return on the
|
||||
# first failure
|
||||
# selector - the selector for determining eligibility
|
||||
|
||||
proc dlist_eval {dlist testcond handler {canfail "0"} {selector "dlist_get_next"}} {
|
||||
array set statusdict [list]
|
||||
|
||||
# Do a pre-run seeing if any items automagically
|
||||
# can evaluate to true.
|
||||
if {$testcond != ""} {
|
||||
foreach ditem $dlist {
|
||||
if {[eval "expr \[\$testcond \$ditem\] == 1"]} {
|
||||
foreach token [ditem_key $ditem provides] {
|
||||
set statusdict($token) 1
|
||||
}
|
||||
dlist_delete dlist $ditem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Loop for as long as there are ditems in the dlist.
|
||||
while {1} {
|
||||
set ditem [$selector $dlist statusdict]
|
||||
|
||||
if {$ditem == {}} {
|
||||
break
|
||||
} else {
|
||||
# $handler should return a unix status code, 0 for success.
|
||||
# statusdict notation is 1 for success
|
||||
if {[catch {eval "$handler $ditem"} result]} {
|
||||
puts $result
|
||||
return $dlist
|
||||
}
|
||||
# No news is good news at this point.
|
||||
if {$result == {}} { set result 0 }
|
||||
|
||||
foreach token [ditem_key $ditem provides] {
|
||||
set statusdict($token) [expr $result == 0]
|
||||
}
|
||||
|
||||
# Abort if we're not allowed to fail
|
||||
if {$canfail == 0 && $result != 0} {
|
||||
return $dlist
|
||||
}
|
||||
|
||||
# Delete the ditem from the waiting list.
|
||||
dlist_delete dlist $ditem
|
||||
}
|
||||
}
|
||||
|
||||
# Return the list of lusers
|
||||
return $dlist
|
||||
}
|
||||
|
||||
|
||||
##### Private API #####
|
||||
# Anything below this point is subject to change without notice.
|
||||
#####
|
||||
|
||||
# Each ditem is actually an array in the macports_dlist
|
||||
# namespace. ditem keys correspond to the equivalent array
|
||||
# key. A dlist is simply a list of names of ditem arrays.
|
||||
# All private API functions exist in the macports_dlist
|
||||
# namespace.
|
||||
|
||||
namespace eval macports_dlist {
|
||||
|
||||
variable ditem_uniqid 0
|
||||
|
||||
proc ditem_create {} {
|
||||
variable ditem_uniqid
|
||||
incr ditem_uniqid
|
||||
set ditem "ditem_${ditem_uniqid}"
|
||||
variable $ditem
|
||||
array set $ditem [list]
|
||||
return $ditem
|
||||
}
|
||||
|
||||
proc ditem_key {ditem args} {
|
||||
variable $ditem
|
||||
set nbargs [llength $args]
|
||||
if {$nbargs > 1} {
|
||||
set key [lindex $args 0]
|
||||
array set $ditem [list $key [lindex $args 1]]
|
||||
return [lindex [array get $ditem $key] 1]
|
||||
} elseif {$nbargs == 1} {
|
||||
set key [lindex $args 0]
|
||||
return [lindex [array get $ditem $key] 1]
|
||||
} else {
|
||||
return [array get $ditem]
|
||||
}
|
||||
}
|
||||
|
||||
proc ditem_append {ditem key args} {
|
||||
variable $ditem
|
||||
set x [lindex [array get $ditem $key] 1]
|
||||
if {$x != {}} {
|
||||
eval "lappend x $args"
|
||||
} else {
|
||||
set x $args
|
||||
}
|
||||
array set $ditem [list $key $x]
|
||||
return $x
|
||||
}
|
||||
|
||||
proc ditem_append_unique {ditem key args} {
|
||||
variable $ditem
|
||||
set x [lindex [array get $ditem $key] 1]
|
||||
if {$x != {}} {
|
||||
eval "lappend x $args"
|
||||
set x [lsort -unique $x]
|
||||
} else {
|
||||
set x $args
|
||||
}
|
||||
array set $ditem [list $key $x]
|
||||
return $x
|
||||
}
|
||||
|
||||
proc ditem_contains {ditem key args} {
|
||||
variable $ditem
|
||||
if {[llength $args] == 0} {
|
||||
eval "return \[info exists ${ditem}($key)\]"
|
||||
} else {
|
||||
set x [lindex [array get $ditem $key] 1]
|
||||
if {[llength $x] > 0 && [lsearch -exact $x [lindex $args 0]] != -1} {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# End of macports_dlist namespace
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user