Commit 693d3253 authored by Daniel Kahn Gillmor's avatar Daniel Kahn Gillmor

Imported Upstream version 3.02

parents cfd4aadb a0d93c6c
......@@ -22,7 +22,7 @@ LINK := gcc
LFLAGS :=
LIBS :=
PREFIX=/usr/local
PREFIX=$(DESTDIR)/usr/local
BINDIR=$(PREFIX)/bin
MANDIR=$(PREFIX)/man/man1
......@@ -71,6 +71,8 @@ install: tweak tweak.1
clean:
rm -f *.o tweak tweak.1 btree.html
.PHONY: release clean install
main.o: main.c tweak.h
keytab.o: keytab.c tweak.h
actions.o: actions.c tweak.h
......
......@@ -462,6 +462,8 @@ static void act_copy (void) {
static void act_paste (void) {
fileoffset_t cutsize, new_top;
if (!cutbuffer)
return;
cutsize = buf_length (cutbuffer);
if (!insert_mode) {
if (cur_pos + cutsize > file_size) {
......
......@@ -662,4 +662,4 @@ repeatedly).
downloaded at
\W{http://www.chiark.greenend.org.uk/~sgtatham/tweak/}\cw{http://www.chiark.greenend.org.uk/~sgtatham/tweak/}.
\versionid $Id: btree.but 4828 2004-11-19 18:48:59Z simon $
\versionid tweak version 3.02
......@@ -989,7 +989,6 @@ bt_element_t bt_findrelpos(btree *bt, bt_element_t element, cmpfn_t cmp,
int child, is_elt;
bt_element_t gotit;
int pos = 0;
int count;
if (!cmp) cmp = bt->cmp;
......@@ -1011,7 +1010,6 @@ bt_element_t bt_findrelpos(btree *bt, bt_element_t element, cmpfn_t cmp,
n = bt_read_lock_root(bt);
if (!n)
return NULL;
count = bt_node_count(bt, n);
while (n) {
child = bt_lookup_cmp(bt, n, element, cmp, &is_elt);
if (is_elt) {
......
......@@ -320,12 +320,12 @@ I've also sketched a means of converting this into a data structure for an ordin
</p>
<h2><a name="S11"></a>11. References</h2>
<p>
Donald Knuth's &#8216;The Art of Computer Programming&#8217; (<a href="http://en.wikipedia.org/w/wiki.phtml?title=Special:Booksources&isbn=0201485419">Addison-Wesley, ISBN 0201485419</a>) presents at least some of the same ideas as this article. Counted and unsorted trees are mentioned in volume 3; splitting and joining are also described (although Knuth does them on AVL trees, which are significantly more fiddly to split than B-trees; you have to cut the tree into lots of little pieces, and then put them all back together by using the join algorithm repeatedly).
Donald Knuth's &#8216;The Art of Computer Programming&#8217; (<a href="http://en.wikipedia.org/w/wiki.phtml?title=Special:Booksources&amp;isbn=0201485419">Addison-Wesley, ISBN 0201485419</a>) presents at least some of the same ideas as this article. Counted and unsorted trees are mentioned in volume 3; splitting and joining are also described (although Knuth does them on AVL trees, which are significantly more fiddly to split than B-trees; you have to cut the tree into lots of little pieces, and then put them all back together by using the join algorithm repeatedly).
</p>
<p>
&#8216;Tweak&#8217;, a hex editor implementing this data structure, can be downloaded at <a href="http://www.chiark.greenend.org.uk/~sgtatham/tweak/"><code>http://www.chiark.greenend.org.uk/~sgtatham/tweak/</code></a>.
</p>
<hr><address>
[$Id: btree.but 4828 2004-11-19 18:48:59Z simon $]</address></body>
[tweak version 3.02]</address></body>
</html>
......@@ -190,10 +190,10 @@ static void load_file (char *);
char toprint[256]; /* LUT: printable versions of chars */
char hex[256][3]; /* LUT: binary to hex, 1 byte */
char message[80];
char message[512];
char decstatus[] = "%s TWEAK "VER": %-18.18s %s posn=%-10"OFF"d size=%-10"OFF"d";
char hexstatus[] = "%s TWEAK "VER": %-18.18s %s posn=0x%-8"OFF"X size=0x%-8"OFF"X";
char decstatus[] = "%s TWEAK: %-18.18s %s posn=%-10"OFF"d size=%-10"OFF"d";
char hexstatus[] = "%s TWEAK: %-18.18s %s posn=0x%-8"OFF"X size=0x%-8"OFF"X";
char *statfmt = hexstatus;
char last_char;
......@@ -219,6 +219,14 @@ fileoffset_t file_size = 0, top_pos = 0, cur_pos = 0, mark_point = 0;
int scrlines;
void usage(FILE *fp)
{
fprintf(fp,
"usage: %s [-f] [-l] [-e] filename\n"
" or %s -D to write default tweak.rc to stdout\n",
pname, pname);
}
/*
* Main program
*/
......@@ -230,17 +238,26 @@ int main(int argc, char **argv) {
*/
pname = *argv; /* program name */
if (argc < 2) {
fprintf(stderr,
"usage: %s [-f] [-l] [-e] filename\n"
" or %s -D to write default tweak.rc to stdout\n",
pname, pname);
return 0;
usage(stderr);
return 1;
}
while (--argc > 0) {
char c, *p = *++argv, *value;
if (*p == '-') {
if (*p == '-' && p[1] == '-') {
if (!strcmp(p, "--version")) {
printf("%s version %s\n", pname, VER);
return 0;
} else if (!strcmp(p, "--help")) {
usage(stdout);
return 0;
} else {
fprintf(stderr, "%s: unrecognised long option `%s'\n",
pname, p);
return 1;
}
} else if (*p == '-') {
p++;
while (*p) switch (c = *p++) {
case 'o': case 'O':
......@@ -318,7 +335,8 @@ int main(int argc, char **argv) {
void fix_offset(void) {
if (3*width+11 > display_cols) {
width = (display_cols-11) / 3;
sprintf (message, "Width reduced to %"OFF"d to fit on the screen", width);
snprintf (message, sizeof(message),
"Width reduced to %"OFF"d to fit on the screen", width);
}
if (4*width+14 > display_cols) {
ascii_enabled = FALSE;
......@@ -384,13 +402,15 @@ static void load_file (char *fname) {
}
fclose (fp);
assert(file_size == buf_length(filedata));
sprintf(message, "loaded %s (size %"OFF"d == 0x%"OFF"X).",
fname, file_size, file_size);
snprintf(message, sizeof(message),
"loaded %s (size %"OFF"d == 0x%"OFF"X).",
fname, file_size, file_size);
} else {
filedata = buf_new_from_file(fp);
file_size = buf_length(filedata);
sprintf(message, "opened %s (size %"OFF"d == 0x%"OFF"X).",
fname, file_size, file_size);
snprintf(message, sizeof(message),
"opened %s (size %"OFF"d == 0x%"OFF"X).",
fname, file_size, file_size);
}
new_file = FALSE;
} else {
......@@ -400,7 +420,7 @@ static void load_file (char *fname) {
exit (1);
}
filedata = buf_new_empty();
sprintf(message, "New file %s.", fname);
snprintf(message, sizeof(message), "New file %s.", fname);
new_file = TRUE;
}
}
......@@ -469,7 +489,7 @@ int backup_file (void) {
}
static unsigned char *scrbuf = NULL;
static int scrbuflines = 0;
static int scrbufsize = 0;
/*
* Draw the screen, for normal usage.
......@@ -484,16 +504,15 @@ void draw_scr (void) {
char *linebuf;
scrlines = display_rows - 2;
if (scrlines > scrbuflines) {
scrbuf = (scrbuf ?
realloc(scrbuf, scrlines*width) :
malloc(scrlines*width));
scrsize = scrlines * width;
if (scrsize > scrbufsize) {
scrbuf = (scrbuf ? realloc(scrbuf, scrsize) : malloc(scrsize));
if (!scrbuf) {
done();
fprintf(stderr, "%s: out of memory!\n", pname);
exit (2);
}
scrbuflines = scrlines;
scrbufsize = scrsize;
}
linebuf = malloc(width*4+20);
......@@ -509,7 +528,8 @@ void draw_scr (void) {
scroff = width - offset;
else
scroff = 0;
scrsize = scrlines * width - scroff;
scrsize -= scroff;
if (scrsize > file_size - top_pos)
scrsize = file_size - top_pos;
......@@ -691,7 +711,7 @@ int get_str (char *prompt, char *buf, int highlight) {
} else if (c == 27 || c == 7) {
display_beep();
display_post_error();
strcpy (message, "User Break!");
snprintf(message, sizeof(message), "User Break!");
return FALSE;
}
......@@ -760,7 +780,7 @@ void suspend(void) {
init();
#else
display_beep();
strcpy(message, "Suspend function not yet implemented.");
snprintf(message, sizeof(message), "Suspend function not yet implemented.");
#endif
}
......
......@@ -274,3 +274,5 @@ command names, and edit the file to do what you want.
This man page probably ought to contain an explicit list of internal
command names, rather than simply referring you to the default
\cw{.tweakrc}.
\versionid tweak version 3.02
This diff is collapsed.
#ifndef TWEAK_TWEAK_H
#define TWEAK_TWEAK_H
#if defined(__APPLE__) && !defined(unix)
#define unix 1
#endif
#ifndef NO_LARGE_FILES
#ifndef _LARGEFILE_SOURCE
......@@ -27,7 +31,9 @@
#define ABORT 7 /* character code for ^G */
#endif
#define VER "3.01" /* version */
#ifndef VER
#define VER "3.02"
#endif
#define SEARCH_BLK 65536 /* so can this */
#define SAVE_BLKSIZ 32768 /* and this too */
......@@ -70,7 +76,7 @@ typedef void (*keyact) (void);
typedef struct buffer buffer;
extern char toprint[256], hex[256][3], message[80];
extern char toprint[256], hex[256][3], message[512];
extern char decstatus[], hexstatus[], *statfmt;
extern char last_char, *pname, *filename;
extern buffer *filedata, *cutbuffer;
......
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