/*
* TODO possibly after that:
*
- * - Need to handle >2Gb files! Up the `filesize' type to long
- * long, and use it everywhere (not just in buffer.c).
- *
* - Multiple buffers, multiple on-screen windows.
* + ^X^F to open new file
* + ^X^R to open new file RO
* _and_ when pasting a cut buffer _into_ one.
*/
+#include "tweak.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
#endif
-#include "tweak.h"
-
static void init(void);
static void done(void);
static void load_file (char *);
char message[80];
-char decstatus[] = "%s TWEAK "VER": %-18.18s %s posn=%-10d size=%-10d";
-char hexstatus[] = "%s TWEAK "VER": %-18.18s %s posn=0x%-8X size=0x%-8X";
+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 *statfmt = hexstatus;
char last_char;
int modified = FALSE;
int new_file = FALSE; /* shouldn't need initialisation -
* but let's not take chances :-) */
-int width = 16;
-int realoffset = 0, offset = 16;
+fileoffset_t width = 16;
+fileoffset_t realoffset = 0, offset = 16;
int ascii_enabled = TRUE;
-long file_size = 0, top_pos = 0, cur_pos = 0, mark_point = 0;
+fileoffset_t file_size = 0, top_pos = 0, cur_pos = 0, mark_point = 0;
int scrlines;
* Main program
*/
int main(int argc, char **argv) {
- int newoffset = -1, newwidth = -1;
+ fileoffset_t newoffset = -1, newwidth = -1;
/*
* Parse command line arguments
}
switch (c) {
case 'o': case 'O':
- newoffset = strtol(value, NULL, 0); /* allow `0xXX' */
+ newoffset = parse_num(value, NULL);
break;
case 'w': case 'W':
- newwidth = strtol(value, NULL, 0);
+ newwidth = parse_num(value, NULL);
break;
}
break;
void fix_offset(void) {
if (3*width+11 > display_cols) {
width = (display_cols-11) / 3;
- sprintf (message, "Width reduced to %d to fit on the screen", width);
+ sprintf (message, "Width reduced to %"OFF"d to fit on the screen", width);
}
if (4*width+14 > display_cols) {
ascii_enabled = FALSE;
file_size = 0;
if ( (fp = fopen (fname, "rb")) ) {
if (eager_mode) {
- long len;
+ size_t len;
static char buffer[4096];
filedata = buf_new_empty();
}
fclose (fp);
assert(file_size == buf_length(filedata));
- sprintf(message, "loaded %s (size %ld == 0x%lX).",
+ sprintf(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 %ld == 0x%lX).",
+ sprintf(message, "opened %s (size %"OFF"d == 0x%"OFF"X).",
fname, file_size, file_size);
}
new_file = FALSE;
*/
int save_file (void) {
FILE *fp;
- long pos = 0;
+ fileoffset_t pos = 0;
if (look_mode)
return FALSE; /* do nothing! */
static char buffer[SAVE_BLKSIZ];
while (pos < file_size) {
- long size = file_size - pos;
+ fileoffset_t size = file_size - pos;
if (size > SAVE_BLKSIZ)
size = SAVE_BLKSIZ;
*/
void draw_scr (void) {
int scrsize, scroff, llen, i, j;
- long currpos;
- int marktop, markbot, mark;
+ fileoffset_t currpos;
+ fileoffset_t marktop, markbot;
+ int mark;
char *p;
unsigned char c, *q;
char *linebuf;
* requiring highlighting: a hex bit and an ascii
* bit.
*/
- int localstart= (currpos<marktop?marktop:currpos) - currpos;
- int localstop = (currpos+llen>markbot ? markbot :
- currpos+llen) - currpos;
+ fileoffset_t localstart= (currpos<marktop ? marktop :
+ currpos) - currpos;
+ fileoffset_t localstop = (currpos+llen>markbot ? markbot :
+ currpos+llen) - currpos;
localstart += width-llen;
localstop += width-llen;
display_write_chars(linebuf, 11+3*localstart);
update_required = TRUE;
}
-long parse_num (char *buffer, int *error) {
+fileoffset_t parse_num (char *buffer, int *error) {
if (error)
*error = FALSE;
if (!buffer[strspn(buffer, "0123456789")]) {
/* interpret as decimal */
- return atoi(buffer);
+ return ATOOFF(buffer);
} else if (buffer[0]=='0' && (buffer[1]=='X' || buffer[1]=='x') &&
!buffer[2+strspn(buffer+2,"0123456789ABCDEFabcdef")]) {
- return strtol(buffer+2, NULL, 16);
+ return STRTOOFF(buffer+2, NULL, 16);
} else if (buffer[0]=='$' &&
!buffer[1+strspn(buffer+1,"0123456789ABCDEFabcdef")]) {
- return strtol(buffer+1, NULL, 16);
+ return STRTOOFF(buffer+1, NULL, 16);
} else {
return 0;
if (error)