Commit 55752113 authored by Peter Pentchev's avatar Peter Pentchev

Drop commented-out tests and implementations of POSIX functions.

The test code and the fallback implementations of these functions
have been commented out since the hexer 1.0.0 release.
parent c4916a4a
......@@ -10,6 +10,10 @@ Change log for hexer, the multi-view binary editor
- move the terminal initialization a bit later in the processing
of the command-line options to avoid spurious output when
usage, version, or features information is requested
- drop the commented-out code for testing and implementing
functions expected in a POSIX environment as warned in
version 1.0.0, namely strcmp(), strcasecmp(), memmove(),
strerror(), and the float.h header file
1.0.4 2018/03/24
- allow hexer to be cross-built: if CC_FOR_BUILD is defined in
......
......@@ -60,7 +60,7 @@ MYC = myc
CTAGS = ctags -tawf tags
OBJECTS = buffer.o tio.o edit.o main.o hexer.o readline.o regex.o port.o \
OBJECTS = buffer.o tio.o edit.o main.o hexer.o readline.o regex.o \
exh.o set.o map.o signal.o util.o commands.o helptext.o calc.o
all: $(HEXER)
......@@ -101,25 +101,6 @@ config.h:
printf "\\n#define HAVE_%s\\t%d\\n" "$$item" "$$value" >> config.h.auto; \
done
# These configuration settings are deprecated; hexer expects
# a POSIX environment that provides these functions and
# header files. If the build breaks or hexer doesn't run
# properly, try moving some of these to the upper section so
# the configuration stage can actually check for them; please
# also let the author know what your operating system, platform,
# and build environment is.
#
for item in \
STRCMP \
STRCASECMP \
MEMMOVE \
FLOAT_H \
STRERROR \
; do \
echo "Assuming $$item is present"; \
printf "\\n/* Assumed; please let the author know if the build breaks */\\n#define HAVE_%s\\t%d\\n" "$$item" 1 >> config.h.auto; \
done
[ ! -e config.h ] || rm config.h
mv config.h.auto config.h
......
......@@ -3,7 +3,7 @@
*/
/* Copyright (c) 1995,1996 Sascha Demetrio
* Copyright (c) 2009, 2010, 2015 Peter Pentchev
* Copyright (c) 2009, 2010, 2015, 2018 Peter Pentchev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -83,22 +83,6 @@ Buffer *last_buffer = 0;
* `last_number' and `last_length' are set to 0, 1, -1 (respectively).
*/
#if !HAVE_MEMMOVE
static void
b_memmove(char *t, const char *s, const unsigned long count)
{
register long i;
if (t > s)
for (i = count - 1; i >= 0; --i) t[i] = s[i];
else
for (i = 0; i < count; ++i) t[i] = s[i];
}
/* b_memmove */
#else
#define b_memmove(a, b, c) memmove(a, b, c)
#endif
/* Whenever the buffer is modified, the macro `BUFFER_CHANGED' is called.
* Purpose: 1. The buffer is marked modified; 2. Discard all information
* line numbers that could have become invalid by the modification.
......@@ -241,10 +225,10 @@ b_read(Buffer *buffer, char *target, unsigned long position, unsigned long count
if (!(block = find_block(buffer, position))) return -1;
if (count + position > buffer->size) count = buffer->size - position;
if (count <= r) {
b_memmove(target, block->data + ofs, count);
memmove(target, block->data + ofs, count);
return count;
} else {
b_memmove(target, block->data + ofs, r);
memmove(target, block->data + ofs, r);
long more = b_read(buffer, target + r, position + r, count - r);
if (more < 0)
return more;
......@@ -264,11 +248,11 @@ b_write(Buffer *buffer, char *source, unsigned long position, unsigned long coun
if (!(block = find_block(buffer, position))) return 0;
if (count + position > buffer->size) count = buffer->size - position;
if (count <= (bs - position % bs)) {
b_memmove(block->data + position % bs, source, count);
memmove(block->data + position % bs, source, count);
return count;
} else {
unsigned long r = bs - position % bs;
b_memmove(block->data + position % bs, source, r);
memmove(block->data + position % bs, source, r);
return r + b_write(buffer, source + r, position + r, count - r);
}
}
......@@ -397,14 +381,14 @@ b_copy_forward(Buffer *buffer, unsigned long target_position, unsigned long sour
if (count <= bs - t_offset) {
if (count <= bs - s_offset) {
assert(s_block = find_block(buffer, source_position));
b_memmove(t_block->data + t_offset, s_block->data + s_offset, count);
memmove(t_block->data + t_offset, s_block->data + s_offset, count);
} else {
assert(s_offset > t_offset);
assert(s_block = find_block(buffer, source_position + count));
b_memmove(t_block->data + tr_offset - sr_offset, s_block->data,
memmove(t_block->data + tr_offset - sr_offset, s_block->data,
sr_offset);
assert(s_block = find_block(buffer, source_position));
b_memmove(t_block->data + t_offset, s_block->data + s_offset,
memmove(t_block->data + t_offset, s_block->data + s_offset,
count - sr_offset);
}
return count;
......@@ -413,18 +397,18 @@ b_copy_forward(Buffer *buffer, unsigned long target_position, unsigned long sour
if (tr_offset >= sr_offset) {
if (sr_offset) {
assert(s_block = find_block(buffer, source_position + count));
b_memmove(t_block->data + tr_offset - sr_offset,
memmove(t_block->data + tr_offset - sr_offset,
s_block->data, sr_offset);
}
if (sr_offset != tr_offset) {
assert(s_block =
find_block(buffer, source_position + count - tr_offset));
b_memmove(t_block->data, s_block->data + bs - tr_offset + sr_offset,
memmove(t_block->data, s_block->data + bs - tr_offset + sr_offset,
tr_offset - sr_offset);
}
} else {
assert(s_block = find_block(buffer, source_position + count));
b_memmove(t_block->data, s_block->data + sr_offset - tr_offset,
memmove(t_block->data, s_block->data + sr_offset - tr_offset,
tr_offset);
}
r += b_copy_forward(buffer, target_position, source_position, count - r);
......
......@@ -55,9 +55,7 @@
#include <ctype.h>
#include <assert.h>
#include <math.h>
#if HAVE_FLOAT_H
#include <float.h>
#endif
#include <limits.h>
#include "buffer.h"
......
/*-
* Copyright (c) 2016 Peter Pentchev
* Copyright (c) 2016, 2018 Peter Pentchev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -40,22 +40,10 @@
* SUCH DAMAGE.
*/
#if defined(TEST_STRCMP)
#include <string.h>
#elif defined(TEST_STRCASECMP)
#include <string.h>
#include <strings.h>
#elif defined(TEST_SIGTYPE_INT)
#if defined(TEST_SIGTYPE_INT)
#include <signal.h>
#elif defined(TEST_MEMMOVE)
#include <string.h>
#elif defined(TEST_FLOAT_H)
#include <float.h>
#elif defined(TEST_ALLOCA_H)
#include <alloca.h>
#elif defined(TEST_STRERROR)
#include <stdio.h>
#include <string.h>
#elif defined(TEST_VASPRINTF)
#define _GNU_SOURCE
#include <stdarg.h>
......@@ -90,23 +78,10 @@ int main(void)
{
char buf[128] = "1";
#if defined(TEST_STRCMP)
buf[0] = '0' + (strcmp("a", "b") != 0);
#elif defined(TEST_STRCASECMP)
buf[0] = '0' + (strcasecmp("a", "b") != 0);
#elif defined(TEST_SIGTYPE_INT)
#if defined(TEST_SIGTYPE_INT)
buf[0] = '0' + (signal(SIGINT, handler) != SIG_ERR);
#elif defined(TEST_MEMMOVE)
buf[1] = '1';
buf[2] = '\0';
memmove(buf, buf + 1, 2);
#elif defined(TEST_FLOAT_H)
buf[0] = '1';
#elif defined(TEST_ALLOCA_H)
buf[0] = '1';
#elif defined(TEST_STRERROR)
const char *res = strerror(2);
buf[0] = res[0];
#elif defined(TEST_VASPRINTF)
const char * const res = run_vasprintf(buf, 1);
buf[0] = res[0];
......
/* port.c 4/10/1995
* Functions missing on some OSs.
*/
/* This file has been placed int the PUBLIC DOMAIN by the author.
*/
#include "config.h"
#include <ctype.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#ifndef FD_ZERO
#include <poll.h>
#endif
#if !HAVE_STRCMP
int
strcmp(const char *a, const char *b)
{
while (*a && *b && *a == *b) ++a, ++b;
return *a > *b ? 1 : *a < *b ? -1 : 0;
}
/* strcmp */
#endif
#if !HAVE_STRCASECMP
int
strcasecmp(const char *s1, const char *s2)
{
while (*s1 && *s2 && tolower(*s1) == tolower(*s2)) ++s1, ++s2;
return *s1 > *s2 ? 1 : *s1 < *s2 ? -1 : 0;
}
/* strcasecmp */
#endif
/* end of port.c */
/* VIM configuration: (do not delete this line)
*
* vim:bk:nodg:efm=%f\:%l\:%m:hid:icon:
* vim:sw=2:sm:textwidth=79:ul=1024:wrap:
*/
......@@ -16,7 +16,7 @@
*/
/* Copyright (c) 1995,1996 Sascha Demetrio
* Copyright (c) 2009 - 2011, 2015, 2016 Peter Pentchev
* Copyright (c) 2009 - 2011, 2015, 2016, 2018 Peter Pentchev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -241,7 +241,7 @@ static long buffer_base;
#define REGEX_ADVANCE { \
if (bp >= buffer + REGEX_BLOCKSIZE) { \
long ii; \
rx_memmove(buffer - REGEX_BLOCKSIZE, buffer, 2 * REGEX_BLOCKSIZE); \
memmove(buffer - REGEX_BLOCKSIZE, buffer, 2 * REGEX_BLOCKSIZE); \
buffer_base += REGEX_BLOCKSIZE; \
rx_seek(buffer_base + REGEX_BLOCKSIZE); \
ii = rx_read(buffer + REGEX_BLOCKSIZE, REGEX_BLOCKSIZE); \
......@@ -251,7 +251,7 @@ static long buffer_base;
} \
bp -= REGEX_BLOCKSIZE; \
} else if (bp < buffer) { \
rx_memmove(buffer + REGEX_BLOCKSIZE, buffer, REGEX_BLOCKSIZE); \
memmove(buffer + REGEX_BLOCKSIZE, buffer, REGEX_BLOCKSIZE); \
buffer_base -= REGEX_BLOCKSIZE; \
if (position >= REGEX_BLOCKSIZE) { \
rx_seek(buffer_base - REGEX_BLOCKSIZE); \
......@@ -264,22 +264,6 @@ static long buffer_base;
} \
}
#if !HAVE_MEMMOVE
static void
rx_memmove(char *t, const char *s, const long count)
{
register long i;
if (t > s)
for (i = count - 1; i >= 0; --i) t[i] = s[i];
else
for (i = 0; i < count; ++i) t[i] = s[i];
}
/* rx_memmove */
#else
#define rx_memmove(a, b, c) (void)memmove(a, b, c)
#endif
int
regex_init(long (*read)(char *, long), long (*seek)(long), long (*tell)(void))
{
......@@ -302,7 +286,7 @@ regex_set_position(long position)
if (position - buffer_base > REGEX_BLOCKSIZE) {
if (position - buffer_base < 2 * REGEX_BLOCKSIZE) {
bp = buffer + (position & REGEX_BLOCKMASK);
rx_memmove(buffer - REGEX_BLOCKSIZE, buffer, 2 * REGEX_BLOCKSIZE);
memmove(buffer - REGEX_BLOCKSIZE, buffer, 2 * REGEX_BLOCKSIZE);
buffer_base += REGEX_BLOCKSIZE;
rx_seek(buffer_base);
i = rx_read(buffer + REGEX_BLOCKSIZE, REGEX_BLOCKSIZE);
......
......@@ -2,7 +2,7 @@
*/
/* Copyright (c) 1995,1996 Sascha Demetrio
* Copyright (c) 2009, 2015 Peter Pentchev
* Copyright (c) 2009, 2015, 2018 Peter Pentchev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -94,30 +94,6 @@ util_strsort(char **list)
}
/* util_strsort */
#if !HAVE_STRERROR
#ifndef BSD
extern const char * const sys_errlist[];
#endif
extern const int sys_nerr;
/*
* We are using an error buffer instead of just returning the result from
* strerror(3) to avoid constness warnings. Yes, this makes this function
* not-thread-safe. Well, strerror(3) isn't.
*/
static char errbuf[512];
char *
strerror(int errnum)
{
if (errnum >= sys_nerr)
strcpy(errbuf, "Unknown error");
else
snprintf(errbuf, sizeof(errbuf), "%s", sys_errlist[errnum]);
return (errbuf);
}
#endif /* HAVE_STRERROR */
int
write_buf(const int fd, const char * const buf, const size_t len)
{
......
/* Copyright (c) 2009, 2015 Peter Pentchev
/* Copyright (c) 2009, 2015, 2018 Peter Pentchev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -42,10 +42,6 @@
#ifndef _UTIL_H_
#define _UTIL_H_
#if !HAVE_STRERROR
char *strerror(int);
#endif
int util_strsort(char **);
int util_trunc(char *);
int write_buf(int, const char *, size_t);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment