summaryrefslogtreecommitdiff
path: root/assorted
diff options
context:
space:
mode:
Diffstat (limited to 'assorted')
-rw-r--r--assorted/.gitignore1
-rw-r--r--assorted/Makefile.am7
-rw-r--r--assorted/deque2.c119
-rw-r--r--assorted/pack.c103
-rw-r--r--assorted/tofrac.c71
-rw-r--r--assorted/unit2any.c49
6 files changed, 0 insertions, 350 deletions
diff --git a/assorted/.gitignore b/assorted/.gitignore
deleted file mode 100644
index 7c16b0a..0000000
--- a/assorted/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/unit2any
diff --git a/assorted/Makefile.am b/assorted/Makefile.am
deleted file mode 100644
index fc3c7f1..0000000
--- a/assorted/Makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-# -*- Makefile -*-
-
-AM_CPPFLAGS = -I${top_srcdir}/include
-
-noinst_PROGRAMS = unit2any
-
-unit2any_LDADD = ../src/libHX.la
diff --git a/assorted/deque2.c b/assorted/deque2.c
deleted file mode 100644
index e5c4798..0000000
--- a/assorted/deque2.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * libHX/assorted/deque2.c
- * Copyright Jan Engelhardt, 2002-2007
- *
- * This file is part of libHX. libHX is free software; you can
- * redistribute it and/or modify it under the terms of the GNU Lesser
- * General Public License as published by the Free Software Foundation;
- * either version 2.1 or (at your option) any later version.
- *
- * deque2.c:
- * Assorted DEQUE functions that are not deemed to be useful in the
- * (compiled) library at this time.
- */
-#include <stdio.h>
-#include <libHX.h>
-
-EXPORT_SYMBOL struct HXdeque_node *HXdeque_rfind(struct HXdeque *dq,
- const void *ptr)
-{
- struct HXdeque_node *trav;
- for (trav = dq->last; trav != NULL; trav = trav->prev)
- if (trav->ptr == ptr)
- return trav;
- return NULL;
-}
-
-EXPORT_SYMBOL void *HXdeque_rget(struct HXdeque *dq, const void *ptr)
-{
- struct HXdeque_node *trav;
- for (trav = dq->last; trav != NULL; trav = trav->prev)
- if (trav->ptr == ptr)
- return trav->ptr;
- return NULL;
-}
-
-EXPORT_SYMBOL void *HXdeque_sget(struct HXdeque *dq, const char *s)
-{
- struct HXdeque_node *trav;
- for (trav = dq->first; trav != NULL; trav = trav->next)
- if (strcmp(trav->ptr, s) == 0)
- return trav->ptr;
- return NULL;
-}
-
-EXPORT_SYMBOL struct HXdeque_node *HXdeque_dup(struct HXdeque *dq)
-{
- /*
- * Duplicate the object on top of the stack by popping it off and
- * adding it again, twice.
- */
- if (dq->last == NULL)
- return NULL;
-
- /*
- * The mathematical axiomatic definition is that the last element is
- * popped off and pushed twice. We optimize by simply "looking" at the
- * last and push it again.
- */
- return HXdeque_push(dq, dq->last->ptr);
-}
-
-EXPORT_SYMBOL struct HXdeque_node *HXdeque_rdup(struct HXdeque *dq)
-{
- /* Same as HXdeque_dup(), but works on the bottom of the stack */
- if (dq->first == NULL)
- return NULL;
- return HXdeque_unshift(dq, dq->first->ptr);
-}
-
-EXPORT_SYMBOL struct HXdeque_node *HXdeque_toprr(struct HXdeque *dq)
-{
- /*
- * Rotates the topmost three items right ([bottom]...CBA[top] =>
- * [bottom]...ACB[top]). Also works if there are only two items in the
- * stack.
- */
- struct HXdeque_node *p = dq->last;
- if (p == NULL)
- return NULL;
- HXdeque_down(p);
- HXdeque_down(p);
- return p;
-}
-
-EXPORT_SYMBOL struct HXdeque_node *HXdeque_toprl(struct HXdeque *dq)
-{
- /* Rotates the topmost three items left (...CBA => ...BAC) */
- struct HXdeque_node *p = dq->last;
- if (p == NULL)
- return NULL;
- if (p->Prev != NULL) p = p->Prev;
- if (p->Prev != NULL) p = p->Prev;
- HXdeque_up(p);
- HXdeque_up(p);
- return p;
-}
-
-EXPORT_SYMBOL struct HXdeque_node *HXdeque_botrr(struct HXdeque *dq)
-{
- /* (CBA... => ...ACB) */
- struct HXdeque_node *p = dq->first;
- if (p == NULL)
- return NULL;
- if (p->Prev != NULL) p = p->Prev;
- if (p->Prev != NULL) p = p->Prev;
- HXdeque_down(p);
- HXdeque_down(p);
- return p;
-}
-
-EXPORT_SYMBOL struct HXdeque_node *HXdeque_botrl(struct HXdeque *dq)
-{
- struct HXdeque_node *p = dq->first;
- if (p == NULL)
- return NULL;
- HXdeque_up(p);
- HXdeque_up(p);
- return p;
-}
diff --git a/assorted/pack.c b/assorted/pack.c
deleted file mode 100644
index 9eec65e..0000000
--- a/assorted/pack.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * libHX/assorted/pack.c
- * Copyright Jan Engelhardt, 1999-2005
- *
- * This file is part of libHX. libHX is free software; you can
- * redistribute it and/or modify it under the terms of the GNU Lesser
- * General Public License as published by the Free Software Foundation;
- * either version 2.1 or (at your option) any later version.
- */
-#include <sys/types.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <string.h>
-
-size_t HX_pack(char *buf, size_t buflen, const char *fmt, ...)
-{
- char *obp = buf;
- int run = 1;
- va_list ap;
- va_start(ap, fmt);
-
- while (run && *fmt != '\0') {
- switch (*fmt++) {
- case 'A': /* string with up to 255 chars */
- case 'a': {
- const char *src = va_arg(ap, const char *);
- size_t slen = strlen(src) & 0xFF;
- if (buflen < slen + 1) {
- run = 0;
- break;
- }
- *buf++ = slen;
- memcpy(buf, src, slen);
- buf += slen;
- buflen -= slen + 1;
- break;
- }
- case 'C': /* unsigned char */
- case 'c':
- if (buflen-- < 1) {
- run = 0;
- break;
- }
- /*
- * Minimum object's size being pushed on the stack is 2
- * bytes since short int is promoted to int when passed
- * thru va_arg and stays uncasted. (FIXME)
- */
- *buf++ = va_arg(ap, unsigned int);
- break;
- case 'H': /* unsigned short */
- case 'h':
- if (buflen < sizeof(uint16_t)) {
- run = 0;
- break;
- }
- *((uint16_t *)buf) = va_arg(ap, uint16_t);
- buf += sizeof(uint16_t);
- buflen -= sizeof(uint16_t);
- break;
- case 'L': /* unsigned long */
- case 'l':
- if (buflen < sizeof(uint32_t)) {
- run = 0;
- break;
- }
- *((uint32_t *)buf) = va_arg(ap, uint32_t);
- buf += sizeof(uint32_t);
- buflen -= sizeof(uint32_t);
- break;
- case 'S': /* string with up to 65535 chars */
- case 's': {
- const char *src = va_arg(ap, const char *);
- size_t slen = strlen(src) & 0xFFFF;
- if (buflen < slen + 2) {
- run = 0;
- break;
- }
- *((unsigned short *)buf) = slen;
- memcpy(buf += 2, src, slen);
- buf += slen;
- buflen -= slen + 2;
- break;
- }
- case 'V': /* fixed size string */
- case 'v': {
- void *src = va_arg(ap, void *);
- size_t slen = va_arg(ap, size_t);
- if (buflen < slen) {
- run = 0;
- break;
- }
- memcpy(buf, src, slen);
- buf += slen;
- buflen -= slen;
- break;
- }
- } /* switch */
- }
-
- va_end(ap);
- return buf - obp;
-}
diff --git a/assorted/tofrac.c b/assorted/tofrac.c
deleted file mode 100644
index e4c1480..0000000
--- a/assorted/tofrac.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * libHX/assorted/tofrac.c
- * Copyright Jan Engelhardt, 1999-2010
- *
- * This file is part of libHX. libHX is free software; you can
- * redistribute it and/or modify it under the terms of the GNU Lesser
- * General Public License as published by the Free Software Foundation;
- * either version 2.1 or (at your option) any later version.
- */
-/*
- * Calculates a readable fraction (i.e. 1/3) from arg and puts the
- * *numerator into num, the denominator into *denom. Since the fraction
- * is found out by an iterative loop, you can specify the minimum value
- * of the denominator in *num and the maximum value of the denominator
- * into *denom before calling the function.
- *
- * If a suitable fraction has been found (within the range of the
- * minimum / maximum denominator, *num and *denom will be overwritten
- * with the results and true is returned; false for no success.
- *
- * You need to re-put your min/max denom values into *num and *denom
- * then.
- */
-#include <sys/types.h>
-#include <limits.h>
-#include <math.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-/* This simplistic version does not deal with negative numbers. */
-
-static bool HX_tofrac(double arg, unsigned long *num, unsigned long *denom)
-{
- unsigned long i, min_denom = *num, max_denom = *denom;
- double j, s;
-
- /*
- * This tries all possible denominators until @arg multiplied by @i
- * gives a number that has a fractional part of 0, which is when we
- * found the optimal fraction.
- */
- for (i = min_denom; i < max_denom; ++i) {
- s = arg * i;
- modf(s, &j);
- if (s == j) {
- *num = j;
- *denom = i;
- return true;
- }
- }
- return false;
-}
-
-int main(int argc, const char **argv)
-{
- unsigned long d = 1, n = ULONG_MAX;
-
- if (argc < 2) {
- fprintf(stderr, "Usage: %s 3.141592\n", *argv);
- return EXIT_FAILURE;
- }
-
- if (!HX_tofrac(strtod(argv[1], NULL), &d, &n)) {
- fprintf(stderr, "Our algorithm was too weak :-)\n");
- return EXIT_FAILURE;
- }
-
- printf("%lu/%lu\n", d, n);
- return EXIT_SUCCESS;
-}
diff --git a/assorted/unit2any.c b/assorted/unit2any.c
deleted file mode 100644
index 74e87d3..0000000
--- a/assorted/unit2any.c
+++ /dev/null
@@ -1,49 +0,0 @@
-#include <stdbool.h>
-#include <stdlib.h>
-#include <libHX/option.h>
-
-static double dpi = 96;
-
-static void px2any(const struct HXoptcb *cbi)
-{
- double px = cbi->data_dbl;
-
- printf("%f px are (at %f DPI) equal to:\n", px, dpi);
- printf("\t%f inch\n", px / dpi);
- printf("\t%f pt\n", px * 72 / dpi);
- printf("\t%f cm\n", px * 2.54 / dpi);
-}
-
-static void pt2any(const struct HXoptcb *cbi)
-{
- double pt = cbi->data_dbl;
-
- printf("%f pt are equal to:\n", pt);
- printf("\t%f inch\n", pt / 72);
- printf("\t%f px (at %f DPI)\n", dpi * pt / 72, dpi);
- printf("\t%f cm\n", pt * 2.54 / 72);
-}
-
-static const struct HXoption option_table[] = {
- {.sh = 'D', .ln = "dpi", .type = HXTYPE_DOUBLE, .ptr = &dpi,
- .help = "Resolution (default: 96 dpi)"},
- {.sh = 'P', .ln = "px", .type = HXTYPE_DOUBLE, .cb = px2any},
- {.sh = 'p', .ln = "pt", .type = HXTYPE_DOUBLE, .cb = pt2any},
- HXOPT_AUTOHELP,
- HXOPT_TABLEEND,
-};
-
-static bool get_options(int *argc, const char ***argv)
-{
-}
-
-int main(int argc, const char **argv)
-{
- int ret;
-
- ret = HX_getopt(option_table, &argc, &argv, HXOPT_USAGEONERR);
- if (ret != HXOPT_ERR_SUCCESS)
- return EXIT_FAILURE;
-
-
-}