diff options
author | aksr | 2015-06-28 14:34:07 +0200 |
---|---|---|
committer | aksr | 2015-06-28 14:34:07 +0200 |
commit | dc3a126cc2ba0670b1d822c578481191fc137830 (patch) | |
tree | d0cde6340de8baee90af7e89b5975d08b64440b6 | |
download | aur-dc3a126cc2ba0670b1d822c578481191fc137830.tar.gz |
Start.
-rw-r--r-- | .SRCINFO | 29 | ||||
-rw-r--r-- | PKGBUILD | 63 | ||||
-rw-r--r-- | config.h | 38 | ||||
-rw-r--r-- | echo.install | 13 | ||||
-rw-r--r-- | libhed_config.h | 30 | ||||
-rw-r--r-- | term.c | 283 |
6 files changed, 456 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..b33b02c1323e --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,29 @@ +pkgbase = hed-git + pkgdesc = Fast hexadecimal editor + pkgver = 0.5.r486.g44165a6 + pkgrel = 1 + url = http://repo.or.cz/w/hed.git + install = echo.install + arch = i686 + arch = x86_64 + license = GPL + makedepends = git + source = hed-git::git://repo.or.cz/hed.git + source = config.h + source = libhed_config.h + source = term.c + md5sums = SKIP + md5sums = 4ffceab7d450a05725620726d2221764 + md5sums = 6d028b0e51a8db5e4559336e65819729 + md5sums = 9b9a96aaf02d2105017fd6346e293ff8 + sha1sums = SKIP + sha1sums = e5a1eea38f3bc86fa97d76cf0d844d5a22cef0cb + sha1sums = b56277f1e2234933738c7ff753bdb01e13b879ab + sha1sums = 961239d4f14a932fd00bc0f923d5ce2daf396ec6 + sha256sums = SKIP + sha256sums = bc228fce426d79a69d5a6e7ae937e0e9d0d934afaf4ea712bf6a19d00a5deac4 + sha256sums = 59125dbeb12e94a2c527eb77c2eebaca684c80c4d9e1ffae8f90aff7b4622386 + sha256sums = 8e1d29f12e8582c55c43e28c85b585e4076a88f78aab37d8f6713b9d64e1206b + +pkgname = hed-git + diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..4bf42a07ff8e --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,63 @@ +# Maintainer: aksr <aksr at t-com dot me> +pkgname=hed-git +pkgver=0.5.r486.g44165a6 +pkgrel=1 +epoch= +pkgdesc="Fast hexadecimal editor" +arch=('i686' 'x86_64') +url="http://repo.or.cz/w/hed.git" +license=('GPL') +groups=() +depends=('') +makedepends=('git') +optdepends=() +checkdepends=() +provides=() +conflicts=() +replaces=() +backup=() +options=() +changelog= +install=echo.install +source=("$pkgname::git://repo.or.cz/hed.git" + 'config.h' + 'libhed_config.h' + 'term.c') +noextract=() +md5sums=('SKIP' + '4ffceab7d450a05725620726d2221764' + '6d028b0e51a8db5e4559336e65819729' + '9b9a96aaf02d2105017fd6346e293ff8') +sha1sums=('SKIP' + 'e5a1eea38f3bc86fa97d76cf0d844d5a22cef0cb' + 'b56277f1e2234933738c7ff753bdb01e13b879ab' + '961239d4f14a932fd00bc0f923d5ce2daf396ec6') +sha256sums=('SKIP' + 'bc228fce426d79a69d5a6e7ae937e0e9d0d934afaf4ea712bf6a19d00a5deac4' + '59125dbeb12e94a2c527eb77c2eebaca684c80c4d9e1ffae8f90aff7b4622386' + '8e1d29f12e8582c55c43e28c85b585e4076a88f78aab37d8f6713b9d64e1206b') + +pkgver() { + cd "$srcdir/$pkgname" + git describe --tags | sed -E 's/([^-]*-g)/r\1/;s/-/./g;s/hed.//' +} + +prepare() { + cd "$srcdir/$pkgname" + cp ../config.h config.h + cp ../term.c src/term/term.c + cp ../libhed_config.h libhed/config.h +} + +build() { + cd "$srcdir/$pkgname" + make +} + +package() { + cd "$srcdir/$pkgname" + make DESTDIR="$pkgdir/" PREFIX="/usr" install + install -Dm644 doc/README.dev $pkgdir/usr/share/doc/$pkgname/README + install -Dm644 COPYING $pkgdir/usr/share/licenses/$pkgname/COPYING +} + diff --git a/config.h b/config.h new file mode 100644 index 000000000000..5cb8ae533088 --- /dev/null +++ b/config.h @@ -0,0 +1,38 @@ +/* The configuration header file */ +/* $Id$ */ + +#ifndef HED__CONFIG_H +#define HED__CONFIG_H + +/* + * 'Mercy!' cried Gandalf. 'If the giving of information is to be the cure of + * your inquisitiveness, I shall spend all the rest of my days in answering + * you. What more do you want to know?' + * + * 'The names of all the stars, and of all living things, and the whole history + * of Middle-earth and Over-heaven and of the Sundering Seas,' laughed Pippin. + */ + +#include <libhed/config.h> + +/* Comment this out to remove color configuration */ +#define CONFIG_CUSTOM_COLORS 1 + +/* Below, several macros are defined. Modify them according to your system. */ + +/* Comment out if your system does not have getopt_long(). */ +#define HAVE_GETOPT_LONG + +/* Comment out if your system does not have memrchr(). */ +#define HAVE_MEMRCHR + +/* The biggest integer type available on the system. */ +#define BINT_TYPE long long + +#ifdef HED_CONFIG_LFS +# define _FILE_OFFSET_BITS 64 +#else +# define _FILE_OFFSET_BITS 32 +#endif + +#endif diff --git a/echo.install b/echo.install new file mode 100644 index 000000000000..249b4f4d7a0a --- /dev/null +++ b/echo.install @@ -0,0 +1,13 @@ +post_install() { + echo ">>> Compile-time configuration" + echo " You may want to tune the compile-time configuration:" + echo " * config.h: system-specific configuration" + echo " * libhed/config.h: low-level tweaks if you want to enable experimantal" + echo " features, or disable standard features to reduce code size." + echo " * src/term/term.c: default colors (see the definition of colordefs[])." +} + +post_upgrade() { + post_install +} + diff --git a/libhed_config.h b/libhed_config.h new file mode 100644 index 000000000000..3885d1edb353 --- /dev/null +++ b/libhed_config.h @@ -0,0 +1,30 @@ +/* libhed configuration header file */ + +/* This is a libhed PUBLIC file. + * This header file will be installed on the target system. + * When you add new things here, make sure they start with hed_. + */ + +#ifndef LIBHED__CONFIG_H +#define LIBHED__CONFIG_H + +/* Define which features should be enabled in the library. + * Comment/uncomment the defines as needed. + */ + +/* Comment this out to compile without LFS (Large File Support) */ +#define HED_CONFIG_LFS 1 + +/* Uncomment this if you want the EXPERIMENTAL mmap file backend */ +/* #define HED_CONFIG_MMAP 1 */ + +/* Comment this out if you don't want to include readahead support */ +#define HED_CONFIG_READAHEAD 1 + +/* Comment this out to remove swap file support */ +#define HED_CONFIG_SWAP 1 + +/* Comment this out to use traditional read/write for swap files */ +#define HED_CONFIG_SWAP_MMAP 1 + +#endif /* LIBHED__CONFIG_H */ diff --git a/term.c b/term.c new file mode 100644 index 000000000000..8a23eac55ab2 --- /dev/null +++ b/term.c @@ -0,0 +1,283 @@ +/* $Id$ */ + +/* + * hed - Hexadecimal editor + * Copyright (C) 2004 Petr Baudis <pasky@ucw.cz> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * `There's only stars, as I thought,' he said. Then he gave a low gasp, for + * the stars went out. As if a dark veil had been withdrawn, the Mirror grew + * grey, and then clear. There was sun shining, and the branches of trees were + * waving and tossing in the wind. + */ + +/* Feature macros needed for: + * - stpcpy + * - vasprintf + */ +#define _GNU_SOURCE + +#include <config.h> + +#include <curses.h> +#include <stdlib.h> + +#include <hed.h> + +#include <term/term.h> + + +static WINDOW *scr; +int color2attr[64]; + +#define DEFCOLOR(PN, FG, BG, ATTRS) \ + [ ( COLOR_ ## PN ) - 1 ] = { \ + .fg = ( COLOR_ ## FG ), \ + .bg = ( COLOR_ ## BG ), \ + .attrs = COLOR_PAIR( COLOR_ ## PN ) | (ATTRS ) } + +static struct { + short fg, bg; + int attrs; +} colordefs[] = { + // pair number fg bg attrs + DEFCOLOR(NEUTRAL, WHITE, BLACK, 0), + DEFCOLOR(OFFSET, YELLOW, BLACK, A_BOLD), + DEFCOLOR(STATUS, WHITE, BLACK, 0), + DEFCOLOR(MODE, WHITE, BLACK, A_BOLD), + DEFCOLOR(MARK, YELLOW, BLACK, A_BOLD), + DEFCOLOR(ERROR, RED, BLACK, A_BOLD), + DEFCOLOR(DIRTY, RED, BLACK, A_BOLD), + + DEFCOLOR(HEX, WHITE, BLACK, 0), + DEFCOLOR(UNHEX, WHITE, BLUE, 0), + DEFCOLOR(ASC, GREEN, BLACK, A_BOLD), + DEFCOLOR(UNASC, GREEN, BLUE, A_BOLD), + DEFCOLOR(CURHEX, WHITE, BLACK, A_BOLD), + DEFCOLOR(CURUNHEX, WHITE, BLUE, A_BOLD), + DEFCOLOR(CURASC, YELLOW, BLACK, A_BOLD), + DEFCOLOR(CURUNASC, YELLOW, BLUE, A_BOLD), +}; + +#undef DEFCOLOR + +#ifdef CONFIG_CUSTOM_COLORS + +#include <string.h> +#include <ctype.h> +#include <config/config.h> + +struct valdesc { + const char *const name; + const size_t len; + const int val; +}; + +static int +parseval(char **pstr, const struct valdesc *vals, int nvals, bool mult) +{ + char *p, *q; + size_t len; + int i, ret = 0; + + while (**pstr) { + for (p = *pstr; isspace(*p); ++p); + for (q = p; *q && !isspace(*q); ++q); + len = q - p; + *pstr = q; + + for (i = 0; i < nvals; ++i) { + if (vals[i].len != len) + continue; + if (strncasecmp(p, vals[i].name, len)) + continue; + ret |= vals[i].val; + } + if (!mult) + break; + } + return ret; +} + +static inline int +parsecolor(char **pstr) +{ +#define COLDESC(COL) { \ + .name = #COL, \ + .len = (sizeof(#COL)) - 1, \ + .val = COLOR_ ## COL } + static const struct valdesc colors[] = { + COLDESC(BLACK), + COLDESC(RED), + COLDESC(GREEN), + COLDESC(YELLOW), + COLDESC(BLUE), + COLDESC(MAGENTA), + COLDESC(CYAN), + COLDESC(WHITE), + }; +#undef COLDESC + + return parseval(pstr, + colors, sizeof(colors) / sizeof(colors[0]), + false); +} + +static inline int +parseattrs(char **pstr) +{ +#define ATTRDESC(ATTR) { \ + .name = #ATTR, \ + .len = (sizeof(#ATTR)) - 1, \ + .val = A_ ## ATTR } + static const struct valdesc attrs[] = { + ATTRDESC(NORMAL), + ATTRDESC(STANDOUT), + ATTRDESC(UNDERLINE), + ATTRDESC(REVERSE), + ATTRDESC(BLINK), + ATTRDESC(DIM), + ATTRDESC(BOLD), + ATTRDESC(PROTECT), + ATTRDESC(INVIS), + ATTRDESC(ALTCHARSET), + }; +#undef ATTRDESC + + return parseval(pstr, + attrs, sizeof(attrs) / sizeof(attrs[0]), + true); +} + +static void +config_colors(void) +{ + static const char * const names[] = { + "neutral", "offset", "status", "mode", + "mark", "error", "dirty", + "hex", "unhex", "asc", "unasc", + "curhex", "curunhex", "curasc", "curunasc" }; + int i; + + for (i = 0; i < sizeof(names) / sizeof(names[0]); ++i) { + char *spec, name[16]; + + strcpy(stpcpy(name, "color_"), names[i]); + if (! (spec = get_opt_str(name, NULL)) ) + continue; + + colordefs[i].fg = parsecolor(&spec); + colordefs[i].bg = parsecolor(&spec); + colordefs[i].attrs = parseattrs(&spec) | COLOR_PAIR(i + 1); + } +} + +#else + +#define config_colors() do { } while(0) + +#endif /* CONFIG_CUSTOM_COLORS */ + +/* Initialize the terminal. */ +void +term_init(void) +{ + int i; + + scr = initscr(); + cbreak(); noecho(); nonl(); + intrflush(scr, FALSE); + keypad(scr, TRUE); + + config_colors(); + start_color(); + for (i = 0; i < sizeof(colordefs) / sizeof(colordefs[0]); ++i) { + init_pair(i + 1, colordefs[i].fg, colordefs[i].bg); + color2attr[i+1] = colordefs[i].attrs; + } + + refresh(); +} + +/* Deinitialize the terminal. */ +void +term_done(void) +{ + endwin(); +} + +/* Redraw the terminal. */ +void term_redraw(void) +{ + refresh(); +} + + +/* Move the cursor around to the given position. */ +void +term_goto_cursor(int x, int y) +{ + move(y, x); +} + +/* Get window dimensions. */ +int +term_get_max_x(void) +{ + int x, y; + getmaxyx(stdscr, y, x); + return x; +} + +int +term_get_max_y(void) +{ + int x, y; + getmaxyx(stdscr, y, x); + return y; +} + +/* Clear the given line. Can move cursor around. */ +void +term_clear_line(int y) +{ + move(y, 0); + clrtoeol(); +} + +/* Print formatted output to the terminal. */ +int +term_printf(int x, int y, term_color color, const char *fmt, ...) +{ + va_list va; + char *str; + int len; + + va_start(va, fmt); + len = vasprintf(&str, fmt, va); + va_end(va); + term_print_string(x, y, color, str); + free(str); + return len; +} + +/* Get a character from the terminal. */ +int +term_get_char(void) +{ + return getch(); +} |