Date: Thu, 28 Aug 2014 23:24:56 GMT From: ghostmansd@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273285 - in soc2014/ghostmansd/head: bin/colldb lib lib/libcolldb share/examples/colldb usr.bin usr.bin/colldb Message-ID: <201408282324.s7SNOu7c034479@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ghostmansd Date: Thu Aug 28 23:24:56 2014 New Revision: 273285 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273285 Log: colldb, its manual page and some small fixes Added: soc2014/ghostmansd/head/usr.bin/colldb/ - copied from r273177, soc2014/ghostmansd/head/bin/colldb/ soc2014/ghostmansd/head/usr.bin/colldb/Makefile (contents, props changed) soc2014/ghostmansd/head/usr.bin/colldb/colldb.c Deleted: soc2014/ghostmansd/head/bin/colldb/ Modified: soc2014/ghostmansd/head/lib/Makefile soc2014/ghostmansd/head/lib/libcolldb/Makefile soc2014/ghostmansd/head/lib/libcolldb/colldb.h soc2014/ghostmansd/head/share/examples/colldb/colldb.py soc2014/ghostmansd/head/usr.bin/Makefile Modified: soc2014/ghostmansd/head/lib/Makefile ============================================================================== --- soc2014/ghostmansd/head/lib/Makefile Thu Aug 28 22:52:20 2014 (r273284) +++ soc2014/ghostmansd/head/lib/Makefile Thu Aug 28 23:24:56 2014 (r273285) @@ -37,6 +37,7 @@ libcam \ ${_libcapsicum} \ ${_libcasper} \ + libcolldb \ ${_libcom_err} \ libcompat \ libcrypt \ @@ -114,10 +115,6 @@ ${_cuse} \ ${_tests} -.ifdef UNICODE -SUBDIR+= libcolldb -.endif - # Inter-library dependencies. When the makefile for a library contains LDADD # libraries, those libraries should be listed as build order dependencies here. Modified: soc2014/ghostmansd/head/lib/libcolldb/Makefile ============================================================================== --- soc2014/ghostmansd/head/lib/libcolldb/Makefile Thu Aug 28 22:52:20 2014 (r273284) +++ soc2014/ghostmansd/head/lib/libcolldb/Makefile Thu Aug 28 23:24:56 2014 (r273285) @@ -3,12 +3,7 @@ SRCS= colldb.c INCS= colldb.h MAN+= colldb.3 - CFLAGS+= -I${COLLDB} - -.colldb.py - install -m644 /usr/share/examples/collation - WARNS?= 3 .include <bsd.lib.mk> Modified: soc2014/ghostmansd/head/lib/libcolldb/colldb.h ============================================================================== --- soc2014/ghostmansd/head/lib/libcolldb/colldb.h Thu Aug 28 22:52:20 2014 (r273284) +++ soc2014/ghostmansd/head/lib/libcolldb/colldb.h Thu Aug 28 23:24:56 2014 (r273285) @@ -58,7 +58,12 @@ #define COLLDB_VERSION 0x00000001 -#define COLLDB_WEIGHTS_MAX 10 +#ifndef COLLDB_CHARS_MAX +#define COLLDB_CHARS_MAX 8 +#endif +#ifndef COLLDB_WEIGHTS_MAX +#define COLLDB_WEIGHTS_MAX 32 +#endif struct colldb_weight { uint8_t alternate; @@ -67,16 +72,19 @@ uint32_t level3; uint32_t level4; }; +#define COLLDB_WEIGHT_INIT {0, 0, 0, 0, 0} struct colldb_key { size_t count; uint32_t *chars; }; +#define COLLDB_KEY_INIT {0, NULL} struct colldb_value { size_t count; struct colldb_weight *weights; }; +#define COLLDB_VALUE_INIT {0, NULL} void* colldb_create(const char*, int mode); Modified: soc2014/ghostmansd/head/share/examples/colldb/colldb.py ============================================================================== --- soc2014/ghostmansd/head/share/examples/colldb/colldb.py Thu Aug 28 22:52:20 2014 (r273284) +++ soc2014/ghostmansd/head/share/examples/colldb/colldb.py Thu Aug 28 23:24:56 2014 (r273285) @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # *-* coding: utf-8 *-* """Python bindings for libcolldb""" Modified: soc2014/ghostmansd/head/usr.bin/Makefile ============================================================================== --- soc2014/ghostmansd/head/usr.bin/Makefile Thu Aug 28 22:52:20 2014 (r273284) +++ soc2014/ghostmansd/head/usr.bin/Makefile Thu Aug 28 23:24:56 2014 (r273285) @@ -26,6 +26,7 @@ ${_clang} \ cmp \ col \ + colldb \ colldef \ colrm \ column \ Added: soc2014/ghostmansd/head/usr.bin/colldb/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/ghostmansd/head/usr.bin/colldb/Makefile Thu Aug 28 23:24:56 2014 (r273285) @@ -0,0 +1,10 @@ +# @(#)Makefile 8.1 (Berkeley) 5/31/93 + +PROG= colldb +MAN= colldb.1 +DPADD= ${LIBCOLLDB} +LDADD= -lcolldb +MLINKS+= colldb.1 +LINKS+= ${BINDIR}/colldb + +.include <bsd.prog.mk> Added: soc2014/ghostmansd/head/usr.bin/colldb/colldb.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/ghostmansd/head/usr.bin/colldb/colldb.c Thu Aug 28 23:24:56 2014 (r273285) @@ -0,0 +1,172 @@ +/*- + * Copyright (c) 2014 Dmitry Selyutin. + * 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 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 AUTHOR 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, DECOMPOSITION, 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. + */ + +#define _WITH_GETLINE +#include <stdio.h> +#include <errno.h> +#include <ctype.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <stdint.h> +#include <colldb.h> + + +int +main(int argc, const char **argv) +{ + size_t i = 0; + int lineno = 0; + size_t cap = 0; + ssize_t len = 0; + FILE *src = NULL; + void *dst = NULL; + char *line = NULL; + char *iter = NULL; + char *repr = NULL; + char *check = NULL; + char *cdata = NULL; + char *wdata = NULL; + size_t ccount = 0; + size_t wcount = 0; + unsigned long code = 0; + uint32_t *levels[4] = {NULL}; + uint32_t chars[COLLDB_CHARS_MAX] = {0}; + struct colldb_key key = COLLDB_KEY_INIT; + struct colldb_value value = COLLDB_VALUE_INIT; + struct colldb_weight weights[COLLDB_WEIGHTS_MAX] = {COLLDB_WEIGHT_INIT}; + + if (argc != 3) { + fprintf(stderr, "usage: colldb source_file target_file\n"); + return (EXIT_FAILURE); + } + src = fopen(argv[1], "rb"); + if (src == NULL ) { + fprintf(stderr, "colldb: %s: %s\n", strerror(errno), argv[1]); + return (EXIT_FAILURE); + } + dst = colldb_create(argv[2], 0777); + if (dst == NULL) { + fprintf(stderr, "colldb: %s: %s\n", strerror(errno), argv[2]); + return (EXIT_FAILURE); + } + + for (lineno = 1; ((len = getline(&line, &cap, src)) != -1); ++lineno) { + if ((line[0] == '#') || (line[0] == '@') || (line[0] == '\n')) + continue; + cdata = line; + for (iter = cdata; *iter != '\n'; ++iter) { + if (*iter == ';') + break; + } + if (*iter != ';') + goto failure; + wdata = (iter + 1); + + /* Process characters. */ + ccount = 0; + for (--iter; iter != cdata; --iter) { + if (!isspace(*iter)) + break; + *iter = '\0'; + } + for (repr = cdata; *repr != '\0'; ++ccount) { + if (ccount > COLLDB_CHARS_MAX) { + fprintf(stderr, "colldb: %s[%d]: %s\n", + argv[1], lineno, "overlong chars sequence\n"); + free(line); + return (EXIT_FAILURE); + } + code = strtoul(repr, &check, 16); + if (repr == check) + goto failure; + chars[ccount] = (uint32_t)code; + repr = check; + } + + /* Process weights. */ + wcount = 0; + for (; isspace(*wdata); ++wdata); + for (iter = (line + len); iter != wdata; --iter) { + if (*iter == ']') + break; + *iter = '\0'; + } + for (repr = wdata; *repr != '\0'; ++wcount) { + if (ccount > COLLDB_CHARS_MAX) { + fprintf(stderr, "colldb: %s[%d]: %s\n", + argv[1], lineno, "overlong weights sequence\n"); + free(line); + return (EXIT_FAILURE); + } + if (*repr != '[') + goto failure; + ++repr; + levels[0] = &weights[wcount].level1; + levels[1] = &weights[wcount].level2; + levels[2] = &weights[wcount].level3; + levels[3] = &weights[wcount].level4; + if ((*repr != '.') && (*repr != '*')) + goto failure; + weights[wcount].alternate = (*repr++ == '*'); + for (i = 0; i < 4; ++i) { + code = strtoul(repr, &check, 16); + if (repr == check) + goto failure; + *(levels[i]) = (uint32_t)code; + if (isspace(*check) || + (*check == '.') || (*check == ']')) { + repr = (check + 1); + continue; + } + if ((*check == ']') && (i == 3)) + break; + goto failure; + } + } + + /* Store key and value pair. */ + key.count = ccount; + key.chars = chars; + value.count = wcount; + value.weights = weights; + fprintf(stderr, "%d\n", lineno); + if (colldb_put(dst, &key, &value) != 0) { + fprintf(stderr, "colldb: %s: %s\n", argv[2], strerror(errno)); + free(line); + return (EXIT_FAILURE); + } + } + colldb_close(dst); + fclose(src); + free(line); + return (EXIT_SUCCESS); + +failure: + fprintf(stderr, "colldb: %s[%d]: illegal format\n", argv[1], lineno); + free(line); + return (EXIT_FAILURE); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408282324.s7SNOu7c034479>