mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
syncronise code with cooledit-3.13.0 this fixes some odds and ends.
in particular, leaking syntax.c that was chomping memory. Also, should note the bzip2 and gzip filters and better support for Windows CR importing - windows guys should take a look at this if you are still out there. dunno if it works yet.
This commit is contained in:
parent
cbb0435c9e
commit
e0e49f355c
620
gtkedit/edit.c
620
gtkedit/edit.c
@ -73,6 +73,8 @@
|
||||
Returns '\n' if out of bounds.
|
||||
*/
|
||||
|
||||
static int push_action_disabled = 0;
|
||||
|
||||
#ifndef NO_INLINE_GETBYTE
|
||||
|
||||
int edit_get_byte (WEdit * edit, long byte_index)
|
||||
@ -103,6 +105,25 @@ char *edit_get_buffer_as_text (WEdit * e)
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
/* Note on CRLF->LF translation: */
|
||||
|
||||
#if MY_O_TEXT
|
||||
#error MY_O_TEXT is depreciated. CR_LF_TRANSLATION must be defined which does CR-LF translation internally. See note in source.
|
||||
#endif
|
||||
|
||||
/*
|
||||
The edit_open_file (previously edit_load_file) function uses
|
||||
init_dynamic_edit_buffers to load a file. This is unnecessary
|
||||
since you can just as well fopen the file and insert the
|
||||
characters one by one. The real reason for
|
||||
init_dynamic_edit_buffers (besides allocating the buffers) is
|
||||
as an optimisation - it uses raw block reads and inserts large
|
||||
chunks at a time. It is hence extremely fast at loading files.
|
||||
Where we might not want to use it is if we were doing
|
||||
CRLF->LF translation or if we were reading from a pipe.
|
||||
*/
|
||||
|
||||
/* Initialisation routines */
|
||||
|
||||
/* returns 1 on error */
|
||||
@ -110,14 +131,6 @@ char *edit_get_buffer_as_text (WEdit * e)
|
||||
/* cursor set to start of file */
|
||||
int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *text)
|
||||
{
|
||||
|
||||
#if defined CR_LF_TRANSLATION
|
||||
/* Variables needed for safe handling of Translation from Microsoft CR/LF EOL to
|
||||
Unix Style LF EOL - Franco */
|
||||
long bytes_wanted,bytes_read,bytes_missing;
|
||||
char *p;
|
||||
#endif
|
||||
|
||||
long buf;
|
||||
int j, file = -1, buf2;
|
||||
|
||||
@ -127,9 +140,9 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
|
||||
}
|
||||
|
||||
if (filename)
|
||||
if ((file = open ((char *) filename, O_RDONLY | MY_O_TEXT)) == -1) {
|
||||
if ((file = open ((char *) filename, O_RDONLY)) == -1) {
|
||||
/* The file-name is printed after the ':' */
|
||||
edit_error_dialog (_(" Error "), get_sys_error (catstrs (_(" Failed trying to open file for reading: "), filename, " ", 0)));
|
||||
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0)));
|
||||
return 1;
|
||||
}
|
||||
edit->curs2 = edit->last_byte;
|
||||
@ -138,59 +151,18 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
|
||||
|
||||
edit->buffers2[buf2] = CMalloc (EDIT_BUF_SIZE);
|
||||
|
||||
/*
|
||||
_read returns the number of bytes read,
|
||||
which may be less than count if there are fewer than count bytes left in the file
|
||||
or if the file was opened in text mode,
|
||||
in which case each carriage return–linefeed (CR-LF) pair is replaced
|
||||
with a single linefeed character. Only the single linefeed character is counted
|
||||
in the return value. The replacement does not affect the file pointer.
|
||||
|
||||
_eof returns 1 if the current position is end of file, or 0 if it is not.
|
||||
A return value of -1 indicates an error; in this case, errno is set to EBADF,
|
||||
which indicates an invalid file handle.
|
||||
*/
|
||||
if (filename){
|
||||
|
||||
#if defined CR_LF_TRANSLATION
|
||||
bytes_wanted=edit->curs2 & M_EDIT_BUF_SIZE;
|
||||
p = (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE);
|
||||
bytes_read = read (file, p , edit->curs2 & M_EDIT_BUF_SIZE);
|
||||
bytes_missing = bytes_wanted - bytes_read ;
|
||||
while(bytes_missing ){
|
||||
p += bytes_read;
|
||||
bytes_read = read(file,p,bytes_missing);
|
||||
if(bytes_read <= 0) break;
|
||||
bytes_missing -= bytes_read ;
|
||||
}
|
||||
#else
|
||||
if (filename) {
|
||||
read (file, (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE), edit->curs2 & M_EDIT_BUF_SIZE);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
memcpy (edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE), text, edit->curs2 & M_EDIT_BUF_SIZE);
|
||||
text += edit->curs2 & M_EDIT_BUF_SIZE;
|
||||
}
|
||||
|
||||
for (buf = buf2 - 1; buf >= 0; buf--) {
|
||||
edit->buffers2[buf] = CMalloc (EDIT_BUF_SIZE);
|
||||
if (filename){
|
||||
#if defined CR_LF_TRANSLATION
|
||||
bytes_wanted = EDIT_BUF_SIZE;
|
||||
p = (char *) edit->buffers2[buf];
|
||||
bytes_read = read (file, p, EDIT_BUF_SIZE);
|
||||
bytes_missing = bytes_wanted - bytes_read ;
|
||||
while(bytes_missing ){
|
||||
p += bytes_read;
|
||||
bytes_read = read(file,p,bytes_missing);
|
||||
if(bytes_read <= 0) break;
|
||||
bytes_missing -= bytes_read ;
|
||||
}
|
||||
#else
|
||||
if (filename) {
|
||||
read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
memcpy (edit->buffers2[buf], text, EDIT_BUF_SIZE);
|
||||
text += EDIT_BUF_SIZE;
|
||||
}
|
||||
@ -199,81 +171,261 @@ which indicates an invalid file handle.
|
||||
edit->curs1 = 0;
|
||||
if (file != -1)
|
||||
close (file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* detecting an error on save is easy: just check if every byte has been written. */
|
||||
/* detecting an error on read, is not so easy 'cos there is not way to tell
|
||||
whether you read everything or not. */
|
||||
/* FIXME: add proper `triple_pipe_open' to read, write and check errors. */
|
||||
static struct edit_filters {
|
||||
char *read, *write, *extension;
|
||||
} all_filters[] = {
|
||||
|
||||
{
|
||||
"bzip2 -cd %s 2>&1", "bzip2 > %s", ".bz2"
|
||||
},
|
||||
{
|
||||
"gzip -cd %s 2>&1", "gzip > %s", ".gz"
|
||||
},
|
||||
{
|
||||
"compress -cd %s 2>&1", "compress > %s", ".Z"
|
||||
}
|
||||
};
|
||||
|
||||
static int edit_find_filter (const char *filename)
|
||||
{
|
||||
int i, l;
|
||||
if (!filename)
|
||||
return -1;
|
||||
l = strlen (filename);
|
||||
for (i = 0; i < sizeof (all_filters) / sizeof (struct edit_filters); i++) {
|
||||
int e;
|
||||
e = strlen (all_filters[i].extension);
|
||||
if (l > e)
|
||||
if (!strcmp (all_filters[i].extension, filename + l - e))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *edit_get_filter (const char *filename)
|
||||
{
|
||||
int i, l;
|
||||
char *p;
|
||||
i = edit_find_filter (filename);
|
||||
if (i < 0)
|
||||
return 0;
|
||||
l = strlen (filename);
|
||||
p = malloc (strlen (all_filters[i].read) + l + 2);
|
||||
sprintf (p, all_filters[i].read, filename);
|
||||
return p;
|
||||
}
|
||||
|
||||
char *edit_get_write_filter (char *writename, char *filename)
|
||||
{
|
||||
int i, l;
|
||||
char *p;
|
||||
i = edit_find_filter (filename);
|
||||
if (i < 0)
|
||||
return 0;
|
||||
l = strlen (writename);
|
||||
p = malloc (strlen (all_filters[i].write) + l + 2);
|
||||
sprintf (p, all_filters[i].write, writename);
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifdef CR_LF_TRANSLATION
|
||||
/* reads into buffer, replace \r\n with \n */
|
||||
long edit_insert_stream (WEdit * edit, FILE * f)
|
||||
{
|
||||
int a = -1, b;
|
||||
long i;
|
||||
while ((b = fgetc (f))) {
|
||||
if (a == '\r' && b == '\n') {
|
||||
edit_insert (edit, '\n');
|
||||
i++;
|
||||
a = -1;
|
||||
continue;
|
||||
} else if (a >= 0) {
|
||||
edit_insert (edit, a);
|
||||
i++;
|
||||
}
|
||||
a = b;
|
||||
}
|
||||
if (a >= 0)
|
||||
edit_insert (edit, a);
|
||||
return i;
|
||||
}
|
||||
/* writes buffer, replaces, replace \n with \r\n */
|
||||
long edit_write_stream (WEdit * edit, FILE * f)
|
||||
{
|
||||
long i;
|
||||
int c;
|
||||
for (i = 0; i < edit->last_byte; i++) {
|
||||
c = edit_get_byte (edit, i);
|
||||
if (c == '\n') {
|
||||
if (fputc ('\r', f) < 0)
|
||||
break;
|
||||
if (fputc ('\n', f) < 0)
|
||||
break;
|
||||
} else {
|
||||
if (fputc (c, f) < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
#else
|
||||
long edit_insert_stream (WEdit * edit, FILE * f)
|
||||
{
|
||||
int c;
|
||||
long i = 0;
|
||||
while ((c = fgetc (f)) >= 0) {
|
||||
edit_insert (edit, c);
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
long edit_write_stream (WEdit * edit, FILE * f)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < edit->last_byte; i++)
|
||||
if (fputc (edit_get_byte (edit, i), f) < 0)
|
||||
break;
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define TEMP_BUF_LEN 1024
|
||||
|
||||
/* inserts a file at the cursor, returns 1 on success */
|
||||
int edit_insert_file (WEdit * edit, const char *filename)
|
||||
{
|
||||
char *p;
|
||||
if ((p = edit_get_filter (filename))) {
|
||||
FILE *f;
|
||||
long current = edit->curs1;
|
||||
f = (FILE *) popen (p, "r");
|
||||
if (f) {
|
||||
edit_insert_stream (edit, f);
|
||||
edit_cursor_move (edit, current - edit->curs1);
|
||||
if (pclose (f) > 0) {
|
||||
edit_error_dialog (_ (" Error "), catstrs (_ (" Error reading from pipe: "), p, " ", 0));
|
||||
free (p);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open pipe for reading: "), p, " ", 0)));
|
||||
free (p);
|
||||
return 0;
|
||||
}
|
||||
free (p);
|
||||
#ifdef CR_LF_TRANSLATION
|
||||
} else {
|
||||
FILE *f;
|
||||
long current = edit->curs1;
|
||||
f = fopen (filename, "r");
|
||||
if (f) {
|
||||
edit_insert_stream (edit, f);
|
||||
edit_cursor_move (edit, current - edit->curs1);
|
||||
if (fclose (f)) {
|
||||
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Error reading file: "), filename, " ", 0)));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0)));
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
} else {
|
||||
int i, file, blocklen;
|
||||
long current = edit->curs1;
|
||||
unsigned char *buf;
|
||||
if ((file = open ((char *) filename, O_RDONLY)) == -1)
|
||||
return 0;
|
||||
buf = malloc (TEMP_BUF_LEN);
|
||||
while ((blocklen = read (file, (char *) buf, TEMP_BUF_LEN)) > 0) {
|
||||
for (i = 0; i < blocklen; i++)
|
||||
edit_insert (edit, buf[i]);
|
||||
}
|
||||
edit_cursor_move (edit, current - edit->curs1);
|
||||
free (buf);
|
||||
close (file);
|
||||
if (blocklen)
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int check_file_access (WEdit *edit, const char *filename, struct stat *st)
|
||||
{
|
||||
int file;
|
||||
#if defined(MIDNIGHT) || defined(GTK)
|
||||
if ((file = open ((char *) filename, O_RDONLY)) < 0) {
|
||||
close (creat ((char *) filename, 0666));
|
||||
if ((file = open ((char *) filename, O_RDONLY)) < 0) {
|
||||
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (" Fail trying to open the file, ", filename, ", for reading ", 0)));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if ((file = open ((char *) filename, O_RDONLY)) < 0) {
|
||||
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0)));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
if (stat ((char *) filename, st) < 0) {
|
||||
close (file);
|
||||
/* The file-name is printed after the ':' */
|
||||
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Cannot get size/permissions info on file: "), filename, " ", 0)));
|
||||
return 1;
|
||||
}
|
||||
if (S_ISDIR (st->st_mode) || S_ISSOCK (st->st_mode)
|
||||
|| S_ISFIFO (st->st_mode)) {
|
||||
close (file);
|
||||
/* The file-name is printed after the ':' */
|
||||
edit_error_dialog (_ (" Error "), catstrs (_ (" Not an ordinary file: "), filename, " ", 0));
|
||||
return 1;
|
||||
}
|
||||
if (st->st_size >= SIZE_LIMIT) {
|
||||
close (file);
|
||||
/* The file-name is printed after the ':' */
|
||||
edit_error_dialog (_ (" Error "), catstrs (_ (" File is too large: "), \
|
||||
filename, _ (" \n Increase edit.h:MAXBUF and recompile the editor. "), 0));
|
||||
return 1;
|
||||
}
|
||||
close (file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* returns 1 on error */
|
||||
int edit_load_file (WEdit * edit, const char *filename, const char *text, unsigned long text_size)
|
||||
int edit_open_file (WEdit * edit, const char *filename, const char *text, unsigned long text_size)
|
||||
{
|
||||
struct stat s;
|
||||
int file;
|
||||
|
||||
/* VARS for Lastbyte calculation in TEXT mode FRANCO */
|
||||
#if defined CR_LF_TRANSLATION
|
||||
char tmp_buf[1024];
|
||||
long real_size,bytes_read;
|
||||
#endif
|
||||
|
||||
struct stat st;
|
||||
if (text) {
|
||||
edit->last_byte = text_size;
|
||||
filename = NULL;
|
||||
filename = 0;
|
||||
} else {
|
||||
int r;
|
||||
r = check_file_access (edit, filename, &st);
|
||||
#if defined(MIDNIGHT) || defined(GTK)
|
||||
if ((file = open ((char *) filename, O_RDONLY | MY_O_TEXT )) < 0)
|
||||
{
|
||||
close(creat((char *) filename, 0666));
|
||||
if ((file = open ((char *) filename, O_RDONLY | MY_O_TEXT )) < 0) {
|
||||
edit_error_dialog (_(" Error "), get_sys_error (catstrs (" Fail trying to open the file, ", filename, ", for reading ", 0)));
|
||||
return 1;
|
||||
}
|
||||
edit->delete_file = 1;
|
||||
}
|
||||
if (r == 2)
|
||||
return edit->delete_file = 1;
|
||||
#endif
|
||||
if (r)
|
||||
return 1;
|
||||
edit->stat = st;
|
||||
#ifndef CR_LF_TRANSLATION
|
||||
edit->last_byte = st.st_size;
|
||||
#else
|
||||
if ((file = open ((char *) filename, O_RDONLY)) < 0) {
|
||||
edit_error_dialog (_(" Error "), get_sys_error (catstrs (_(" Failed trying to open file for reading: "), filename, " ", 0)));
|
||||
return 1;
|
||||
}
|
||||
/* going to read the file into the buffer later byte by byte */
|
||||
edit->last_byte = 0;
|
||||
filename = 0;
|
||||
text = "";
|
||||
#endif
|
||||
if (stat ((char *) filename, &s) < 0) {
|
||||
close (file);
|
||||
/* The file-name is printed after the ':' */
|
||||
edit_error_dialog (_(" Error "), get_sys_error (catstrs (_(" Cannot get size/permissions info on file: "), filename, " ", 0)));
|
||||
return 1;
|
||||
}
|
||||
if (S_ISDIR (s.st_mode) || S_ISSOCK (s.st_mode)
|
||||
|| S_ISFIFO (s.st_mode)) {
|
||||
close (file);
|
||||
/* The file-name is printed after the ':' */
|
||||
edit_error_dialog (_(" Error "), catstrs (_(" Not an ordinary file: "), filename, " ", 0));
|
||||
return 1;
|
||||
}
|
||||
if (s.st_size >= SIZE_LIMIT) {
|
||||
close (file);
|
||||
/* The file-name is printed after the ':' */
|
||||
edit_error_dialog (_(" Error "), catstrs (_(" File is too large: "), \
|
||||
filename, _(" \n Increase edit.h:MAXBUF and recompile the editor. "), 0));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Lastbyte calculation in TEXT mode FRANCO */
|
||||
#if defined CR_LF_TRANSLATION
|
||||
if(file && (!text)){
|
||||
real_size=0;
|
||||
tmp_buf[sizeof (tmp_buf) - 1] = 0;
|
||||
while((bytes_read = read(file,tmp_buf,1024)) > 0){
|
||||
real_size += bytes_read;
|
||||
}
|
||||
s.st_size = real_size;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
close (file);
|
||||
edit->last_byte = s.st_size;
|
||||
edit->stat = s;
|
||||
}
|
||||
|
||||
return init_dynamic_edit_buffers (edit, filename, text);
|
||||
}
|
||||
|
||||
@ -282,7 +434,6 @@ int edit_load_file (WEdit * edit, const char *filename, const char *text, unsign
|
||||
#else
|
||||
int space_width;
|
||||
extern int option_long_whitespace;
|
||||
extern unsigned char per_char[256];
|
||||
|
||||
void edit_set_space_width (int s)
|
||||
{
|
||||
@ -291,26 +442,25 @@ void edit_set_space_width (int s)
|
||||
|
||||
#endif
|
||||
|
||||
int (*edit_file_is_open) (char *) = 0;
|
||||
|
||||
/* fills in the edit struct. returns 0 on fail. Pass edit as NULL for this */
|
||||
WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size)
|
||||
{
|
||||
char *f;
|
||||
int to_free = 0;
|
||||
int use_filter = 0;
|
||||
#ifndef MIDNIGHT
|
||||
if (option_long_whitespace)
|
||||
edit_set_space_width (per_char[' '] * 2);
|
||||
edit_set_space_width (FONT_PER_CHAR[' '] * 2);
|
||||
else
|
||||
edit_set_space_width (per_char[' ']);
|
||||
edit_set_space_width (FONT_PER_CHAR[' ']);
|
||||
#endif
|
||||
if (!edit) {
|
||||
edit = malloc (sizeof (WEdit));
|
||||
memset (edit, 0, sizeof (WEdit));
|
||||
to_free = 1;
|
||||
}
|
||||
if (!edit) {
|
||||
edit_error_dialog (_(" Error "), _(" Error allocating memory "));
|
||||
return 0;
|
||||
}
|
||||
memset (&(edit->from_here), 0, (unsigned long) &(edit->to_here) - (unsigned long) &(edit->from_here));
|
||||
#ifndef MIDNIGHT
|
||||
edit->max_column = columns * FONT_MEAN_WIDTH;
|
||||
@ -324,13 +474,32 @@ WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, co
|
||||
if (!dir)
|
||||
dir = "";
|
||||
f = (char *) filename;
|
||||
if (filename)
|
||||
if (filename) {
|
||||
f = catstrs (dir, filename, 0);
|
||||
if (edit_load_file (edit, f, text, text_size)) {
|
||||
if (edit_file_is_open)
|
||||
if ((*edit_file_is_open) (f)) {
|
||||
if (to_free)
|
||||
free (edit);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (edit_find_filter (f) < 0) {
|
||||
#ifdef CR_LF_TRANSLATION
|
||||
use_filter = 1;
|
||||
#endif
|
||||
if (edit_open_file (edit, f, text, text_size)) {
|
||||
/* edit_load_file already gives an error message */
|
||||
if (to_free)
|
||||
free (edit);
|
||||
return 0;
|
||||
if (to_free)
|
||||
free (edit);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
use_filter = 1;
|
||||
if (edit_open_file (edit, 0, "", 0)) {
|
||||
if (to_free)
|
||||
free (edit);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
edit->force |= REDRAW_PAGE;
|
||||
if (filename) {
|
||||
@ -338,18 +507,32 @@ WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, co
|
||||
edit_split_filename (edit, (char *) filename);
|
||||
} else {
|
||||
edit->filename = (char *) strdup ("");
|
||||
edit->dir = (char *) strdup(dir);
|
||||
edit->dir = (char *) strdup (dir);
|
||||
}
|
||||
edit->stack_size = START_STACK_SIZE;
|
||||
edit->stack_size_mask = START_STACK_SIZE - 1;
|
||||
edit->undo_stack = malloc ((edit->stack_size + 10) * sizeof (long));
|
||||
if (!edit->undo_stack) {
|
||||
edit_error_dialog (_(" Error "), _(" Error allocating memory "));
|
||||
if (to_free)
|
||||
free (edit);
|
||||
return 0;
|
||||
}
|
||||
edit->total_lines = edit_count_lines (edit, 0, edit->last_byte);
|
||||
if (use_filter) {
|
||||
struct stat st;
|
||||
push_action_disabled = 1;
|
||||
if (check_file_access (edit, filename, &st)) {
|
||||
edit_clean (edit);
|
||||
if (to_free)
|
||||
free (edit);
|
||||
return 0;
|
||||
}
|
||||
edit->stat = st;
|
||||
if (!edit_insert_file (edit, f)) {
|
||||
edit_clean (edit);
|
||||
if (to_free)
|
||||
free (edit);
|
||||
return 0;
|
||||
}
|
||||
/* FIXME: this should be an unmodification() function */
|
||||
push_action_disabled = 0;
|
||||
}
|
||||
edit->modified = 0;
|
||||
edit_load_syntax (edit, 0, 0);
|
||||
{
|
||||
int fg, bg;
|
||||
@ -358,7 +541,6 @@ WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, co
|
||||
return edit;
|
||||
}
|
||||
|
||||
|
||||
/* clear the edit struct, freeing everything in it. returns 1 on success */
|
||||
int edit_clean (WEdit * edit)
|
||||
{
|
||||
@ -408,12 +590,20 @@ int edit_renew (WEdit * edit)
|
||||
/* returns 1 on success, if returns 0, the edit struct would have been free'd */
|
||||
int edit_reload (WEdit * edit, const char *filename, const char *text, const char *dir, unsigned long text_size)
|
||||
{
|
||||
WEdit *e;
|
||||
int lines = edit->num_widget_lines;
|
||||
int columns = edit->num_widget_columns;
|
||||
edit_clean (edit);
|
||||
if (!edit_init (edit, lines, columns, filename, text, dir, text_size)) {
|
||||
e = malloc (sizeof (WEdit));
|
||||
memset (e, 0, sizeof (WEdit));
|
||||
e->widget = edit->widget;
|
||||
e->macro_i = -1;
|
||||
if (!edit_init (e, lines, columns, filename, text, dir, text_size)) {
|
||||
free (e);
|
||||
return 0;
|
||||
}
|
||||
edit_clean (edit);
|
||||
memcpy (edit, e, sizeof (WEdit));
|
||||
free (e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -458,8 +648,6 @@ int edit_reload (WEdit * edit, const char *filename, const char *text, const cha
|
||||
|
||||
*/
|
||||
|
||||
static int push_action_disabled = 0;
|
||||
|
||||
void edit_push_action (WEdit * edit, long c,...)
|
||||
{
|
||||
unsigned long sp = edit->stack_pointer;
|
||||
@ -585,6 +773,7 @@ static inline void edit_modification (WEdit * edit)
|
||||
{
|
||||
edit->caches_valid = 0;
|
||||
edit->modified = 1;
|
||||
edit->screen_modified = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1054,8 +1243,10 @@ void edit_scroll_upward (WEdit * edit, unsigned long i)
|
||||
edit->start_display = edit_move_backward (edit, edit->start_display, i);
|
||||
edit->force |= REDRAW_PAGE;
|
||||
edit->force &= (0xfff - REDRAW_CHAR_ONLY);
|
||||
#ifndef MIDNIGHT
|
||||
#endif
|
||||
}
|
||||
edit_update_curs_row(edit);
|
||||
edit_update_curs_row (edit);
|
||||
}
|
||||
|
||||
|
||||
@ -1071,8 +1262,10 @@ void edit_scroll_downward (WEdit * edit, int i)
|
||||
edit->start_display = edit_move_forward (edit, edit->start_display, i, 0);
|
||||
edit->force |= REDRAW_PAGE;
|
||||
edit->force &= (0xfff - REDRAW_CHAR_ONLY);
|
||||
#ifndef MIDNIGHT
|
||||
#endif
|
||||
}
|
||||
edit_update_curs_row(edit);
|
||||
edit_update_curs_row (edit);
|
||||
}
|
||||
|
||||
void edit_scroll_right (WEdit * edit, int i)
|
||||
@ -1192,7 +1385,7 @@ long edit_find_line (WEdit * edit, int line)
|
||||
}
|
||||
if (m == 0)
|
||||
return edit->line_offsets[j]; /* know the offset exactly */
|
||||
if (m == 1)
|
||||
if (m == 1 && j >= 3)
|
||||
i = j; /* one line different - caller might be looping, so stay in this cache */
|
||||
else
|
||||
i = 3 + (rand () % (N_LINE_CACHES - 3));
|
||||
@ -1647,11 +1840,15 @@ void edit_delete_line (WEdit * edit)
|
||||
edit_insert (edit, '\n');
|
||||
}
|
||||
|
||||
static void insert_spaces_tab (WEdit * edit)
|
||||
static void insert_spaces_tab (WEdit * edit, int half)
|
||||
{
|
||||
int i = option_tab_spacing;
|
||||
while (i--)
|
||||
int i;
|
||||
edit_update_curs_col (edit);
|
||||
i = ((edit->curs_col / (option_tab_spacing * space_width / (half + 1))) + 1) * (option_tab_spacing * space_width / (half + 1)) - edit->curs_col;
|
||||
while (i > 0) {
|
||||
edit_insert (edit, ' ');
|
||||
i -= space_width;
|
||||
}
|
||||
}
|
||||
|
||||
static int is_aligned_on_a_tab (WEdit * edit)
|
||||
@ -1738,23 +1935,18 @@ static void edit_tab_cmd (WEdit * edit)
|
||||
/*insert a half tab (usually four spaces) unless there is a
|
||||
half tab already behind, then delete it and insert a
|
||||
full tab. */
|
||||
if (right_of_four_spaces (edit)) {
|
||||
if (!option_fill_tabs_with_spaces && right_of_four_spaces (edit)) {
|
||||
for (i = 1; i <= HALF_TAB_SIZE; i++)
|
||||
edit_backspace (edit);
|
||||
if (option_fill_tabs_with_spaces) {
|
||||
insert_spaces_tab (edit);
|
||||
} else {
|
||||
edit_insert (edit, '\t');
|
||||
}
|
||||
edit_insert (edit, '\t');
|
||||
} else {
|
||||
for (i = 1; i <= HALF_TAB_SIZE; i++)
|
||||
edit_insert (edit, ' ');
|
||||
insert_spaces_tab (edit, 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (option_fill_tabs_with_spaces) {
|
||||
insert_spaces_tab (edit);
|
||||
insert_spaces_tab (edit, 0);
|
||||
} else {
|
||||
edit_insert (edit, '\t');
|
||||
}
|
||||
@ -1771,10 +1963,14 @@ static void check_and_wrap_line (WEdit * edit)
|
||||
edit_update_curs_col (edit);
|
||||
#ifdef MIDNIGHT
|
||||
if (edit->curs_col < option_word_wrap_line_length)
|
||||
#else
|
||||
if (edit->curs_col < option_word_wrap_line_length * FONT_MEAN_WIDTH)
|
||||
#endif
|
||||
return;
|
||||
#else
|
||||
CPushFont ("editor", 0);
|
||||
c = FONT_MEAN_WIDTH;
|
||||
CPopFont ();
|
||||
if (edit->curs_col < option_word_wrap_line_length * c)
|
||||
return;
|
||||
#endif
|
||||
curs = edit->curs1;
|
||||
for (;;) {
|
||||
curs--;
|
||||
@ -1823,43 +2019,75 @@ void edit_push_key_press (WEdit * edit)
|
||||
}
|
||||
|
||||
/* this find the matching bracket in either direction, and sets edit->bracket */
|
||||
void edit_find_bracket (WEdit * edit)
|
||||
static long edit_get_bracket (WEdit * edit, int in_screen, unsigned long furthest_bracket_search)
|
||||
{
|
||||
const char *b = "{}{[][()(", *p;
|
||||
int i = 1, a, inc = -1, c, d, n = 0;
|
||||
unsigned long j = 0;
|
||||
long q;
|
||||
edit_update_curs_row (edit);
|
||||
c = edit_get_byte (edit, edit->curs1);
|
||||
p = strchr (b, c);
|
||||
/* no limit */
|
||||
if (!furthest_bracket_search)
|
||||
furthest_bracket_search--;
|
||||
/* not on a bracket at all */
|
||||
if (!p)
|
||||
return -1;
|
||||
/* the matching bracket */
|
||||
d = p[1];
|
||||
/* going left or right? */
|
||||
if (strchr ("{[(", c))
|
||||
inc = 1;
|
||||
for (q = edit->curs1 + inc;; q += inc) {
|
||||
/* out of buffer? */
|
||||
if (q >= edit->last_byte || q < 0)
|
||||
break;
|
||||
a = edit_get_byte (edit, q);
|
||||
/* don't want to eat CPU */
|
||||
if (j++ > furthest_bracket_search)
|
||||
break;
|
||||
/* out of screen? */
|
||||
if (in_screen) {
|
||||
if (q < edit->start_display)
|
||||
break;
|
||||
/* count lines if searching downward */
|
||||
if (inc > 0 && a == '\n')
|
||||
if (n++ >= edit->num_widget_lines - edit->curs_row) /* out of screen */
|
||||
break;
|
||||
}
|
||||
/* count bracket depth */
|
||||
i += (a == c) - (a == d);
|
||||
/* return if bracket depth is zero */
|
||||
if (!i)
|
||||
return q;
|
||||
}
|
||||
/* no match */
|
||||
return -1;
|
||||
}
|
||||
|
||||
static long last_bracket = -1;
|
||||
|
||||
static void edit_find_bracket (WEdit * edit)
|
||||
{
|
||||
if (option_find_bracket) {
|
||||
const char *b = "{}{[][()(", *p;
|
||||
static int last_bracket = -1;
|
||||
int i = 1, a, inc = -1, c, d, n = 0, j = 0;
|
||||
long q;
|
||||
|
||||
edit->bracket = -1;
|
||||
c = edit_get_byte (edit, edit->curs1);
|
||||
p = strchr (b, c);
|
||||
edit_update_curs_row (edit);
|
||||
if (p) {
|
||||
d = p[1];
|
||||
if (strchr ("{[(", c))
|
||||
inc = 1;
|
||||
for (q = edit->curs1 + inc;; q += inc) {
|
||||
if (q >= edit->last_byte || q < edit->start_display || j++ > 10000)
|
||||
break;
|
||||
a = edit_get_byte (edit, q);
|
||||
if (inc > 0 && a == '\n')
|
||||
n++;
|
||||
if (n >= edit->num_widget_lines - edit->curs_row) /* out of screen */
|
||||
break;
|
||||
i += (a == c) - (a == d);
|
||||
if (!i) {
|
||||
edit->bracket = q;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
edit->bracket = edit_get_bracket (edit, 1, 10000);
|
||||
if (last_bracket != edit->bracket)
|
||||
edit->force |= REDRAW_PAGE;
|
||||
last_bracket = edit->bracket;
|
||||
}
|
||||
}
|
||||
|
||||
static void edit_goto_matching_bracket (WEdit *edit)
|
||||
{
|
||||
long q;
|
||||
q = edit_get_bracket (edit, 0, 0);
|
||||
if (q < 0)
|
||||
return;
|
||||
edit->bracket = edit->curs1;
|
||||
edit->force |= REDRAW_PAGE;
|
||||
edit_cursor_move (edit, q - edit->curs1);
|
||||
}
|
||||
|
||||
/* this executes a command as though the user initiated it through a key press. */
|
||||
/* callback with WIDGET_KEY as a message calls this after translating the key
|
||||
@ -2179,6 +2407,7 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion)
|
||||
break;
|
||||
|
||||
case CK_Toggle_Bookmark:
|
||||
book_mark_clear (edit, edit->curs_line, BOOK_MARK_FOUND_COLOR);
|
||||
if (book_mark_query_color (edit, edit->curs_line, BOOK_MARK_COLOR))
|
||||
book_mark_clear (edit, edit->curs_line, BOOK_MARK_COLOR);
|
||||
else
|
||||
@ -2186,6 +2415,7 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion)
|
||||
break;
|
||||
case CK_Flush_Bookmarks:
|
||||
book_mark_flush (edit, BOOK_MARK_COLOR);
|
||||
book_mark_flush (edit, BOOK_MARK_FOUND_COLOR);
|
||||
edit->force |= REDRAW_PAGE;
|
||||
break;
|
||||
case CK_Next_Bookmark:
|
||||
@ -2305,12 +2535,17 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion)
|
||||
break;
|
||||
|
||||
case CK_Date:{
|
||||
char s[1024];
|
||||
|
||||
time_t t;
|
||||
#ifdef HAVE_STRFTIME
|
||||
char s[1024];
|
||||
#endif
|
||||
time (&t);
|
||||
#ifdef HAVE_STRFTIME
|
||||
strftime (s, 1024, "%c", localtime (&t));
|
||||
edit_printf (edit, s);
|
||||
#else
|
||||
edit_printf (edit, ctime (&t));
|
||||
#endif
|
||||
edit->force |= REDRAW_PAGE;
|
||||
break;
|
||||
}
|
||||
@ -2324,6 +2559,9 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion)
|
||||
case CK_Delete_Macro:
|
||||
edit_delete_macro_cmd (edit);
|
||||
break;
|
||||
case CK_Match_Bracket:
|
||||
edit_goto_matching_bracket (edit);
|
||||
break;
|
||||
#ifdef MIDNIGHT
|
||||
case CK_Sort:
|
||||
edit_sort_cmd (edit);
|
||||
@ -2339,6 +2577,8 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion)
|
||||
case CK_Mail:
|
||||
case CK_Find_File:
|
||||
case CK_Ctags:
|
||||
case CK_Terminal:
|
||||
case CK_Terminal_App:
|
||||
#endif
|
||||
case CK_Complete:
|
||||
case CK_Cancel:
|
||||
|
@ -172,6 +172,7 @@
|
||||
#define SEARCH_DIALOG_OPTION_NO_REGEX 2
|
||||
#define SEARCH_DIALOG_OPTION_NO_CASE 4
|
||||
#define SEARCH_DIALOG_OPTION_BACKWARDS 8
|
||||
#define SEARCH_DIALOG_OPTION_BOOKMARK 16
|
||||
|
||||
#define SYNTAX_FILE "/.cedit/Syntax"
|
||||
#define CLIP_FILE "/.cedit/cooledit.clip"
|
||||
@ -325,7 +326,9 @@ struct _syntax_marker {
|
||||
|
||||
struct _book_mark {
|
||||
int line; /* line number */
|
||||
#define BOOK_MARK_COLOR ((0 << 8) | 26) /* black on white */
|
||||
// #define BOOK_MARK_COLOR ((0 << 8) | 26) /* black on white */
|
||||
#define BOOK_MARK_COLOR ((25 << 8) | 5)
|
||||
#define BOOK_MARK_FOUND_COLOR ((26 << 8) | 4)
|
||||
int c; /* colour */
|
||||
struct _book_mark *next;
|
||||
struct _book_mark *prev;
|
||||
@ -374,6 +377,7 @@ struct editor_widget {
|
||||
unsigned char overwrite;
|
||||
unsigned char modified; /*has the file been changed?: 1 if char inserted or
|
||||
deleted at all since last load or save */
|
||||
unsigned char screen_modified; /* has the file been changed since the last screen draw? */
|
||||
#if defined(MIDNIGHT) || defined(GTK)
|
||||
int delete_file; /* has the file been created in edit_load_file? Delete
|
||||
it at end of editing when it hasn't been modified
|
||||
@ -484,7 +488,6 @@ static inline int edit_get_byte (WEdit * edit, long byte_index)
|
||||
#endif
|
||||
|
||||
char *edit_get_buffer_as_text (WEdit * edit);
|
||||
int edit_load_file (WEdit * edit, const char *filename, const char *text, unsigned long text_size);
|
||||
int edit_count_lines (WEdit * edit, long current, int upto);
|
||||
long edit_move_forward (WEdit * edit, long current, int lines, long upto);
|
||||
long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
|
||||
@ -590,6 +593,10 @@ void book_mark_dec (WEdit * edit, int line);
|
||||
|
||||
#ifdef MIDNIGHT
|
||||
|
||||
#define CPushFont(x,y)
|
||||
#define CPopFont()
|
||||
#define FIXED_FONT 1
|
||||
|
||||
/* put OS2/NT/WIN95 defines here */
|
||||
|
||||
# ifdef USE_O_TEXT
|
||||
@ -638,6 +645,9 @@ extern char *edit_init_error_msg;
|
||||
#else /* ! MIDNIGHT */
|
||||
|
||||
# ifdef GTK
|
||||
# define CPushFont(x,y)
|
||||
# define CPopFont()
|
||||
# define FIXED_FONT gtk_edit_fixed_font
|
||||
# define get_sys_error(s) (s)
|
||||
|
||||
# define open mc_open
|
||||
@ -676,7 +686,7 @@ extern char *edit_init_error_msg;
|
||||
# define FONT_OFFSET_X 0
|
||||
# define FONT_OFFSET_Y FONT_BASE_LINE
|
||||
|
||||
# define per_char gtk_edit_font_width_per_char
|
||||
# define FONT_PER_CHAR gtk_edit_font_width_per_char
|
||||
|
||||
# ifndef _GTK_EDIT_C
|
||||
extern guchar gtk_edit_font_width_per_char[256];
|
||||
|
@ -48,6 +48,7 @@ int replace_prompt = 1;
|
||||
int replace_whole = 0;
|
||||
int replace_case = 0;
|
||||
int replace_backwards = 0;
|
||||
int search_create_bookmark = 0;
|
||||
|
||||
/* queries on a save */
|
||||
#ifdef MIDNIGHT
|
||||
@ -243,79 +244,122 @@ int my_open (const char *pathname, int flags,...)
|
||||
/* returns 0 on error */
|
||||
int edit_save_file (WEdit * edit, const char *filename)
|
||||
{
|
||||
long buf;
|
||||
char *p;
|
||||
long filelen = 0;
|
||||
int file;
|
||||
char *savename = (char *) filename;
|
||||
int this_save_mode;
|
||||
FILE *file;
|
||||
char *savename = 0;
|
||||
int this_save_mode, fd;
|
||||
|
||||
if ((file = open (savename, O_WRONLY)) == -1) {
|
||||
this_save_mode = 0; /* the file does not exists yet, so no safe save or backup necessary */
|
||||
if (!filename)
|
||||
return 0;
|
||||
if (!*filename)
|
||||
return 0;
|
||||
|
||||
savename = (char *) strdup ((char *) filename);
|
||||
|
||||
if ((fd = open (savename, O_WRONLY)) == -1) {
|
||||
this_save_mode = 0; /* the file does not exists yet, so no safe save or backup necessary */
|
||||
} else {
|
||||
close (file);
|
||||
close (fd);
|
||||
this_save_mode = option_save_mode;
|
||||
}
|
||||
|
||||
if (this_save_mode > 0) {
|
||||
char *savedir = ".", *slashpos = strrchr (filename, '/');
|
||||
if (slashpos != 0) {
|
||||
char *savedir, *slashpos;
|
||||
savedir = (char *) strdup (".");
|
||||
slashpos = strrchr (filename, '/');
|
||||
if (slashpos) {
|
||||
free (savedir);
|
||||
savedir = (char *) strdup (filename);
|
||||
if (savedir == 0)
|
||||
return 0;
|
||||
savedir[slashpos - filename + 1] = '\0';
|
||||
}
|
||||
if (savename)
|
||||
free (savename);
|
||||
savename = (char *) tempnam (savedir, "cooledit");
|
||||
if (slashpos)
|
||||
free (savedir);
|
||||
free (savedir);
|
||||
if (!savename)
|
||||
return 0;
|
||||
}
|
||||
if ((file = open (savename, O_CREAT | O_WRONLY | O_TRUNC | MY_O_TEXT, edit->stat.st_mode)) == -1) {
|
||||
if (this_save_mode > 0)
|
||||
free (savename);
|
||||
return 0;
|
||||
goto error_save;
|
||||
}
|
||||
if ((file = fopen (savename, "w+")) == 0)
|
||||
goto error_save;
|
||||
chmod (savename, edit->stat.st_mode);
|
||||
chown (savename, edit->stat.st_uid, edit->stat.st_gid);
|
||||
buf = 0;
|
||||
while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) {
|
||||
filelen += write (file, (char *) edit->buffers1[buf], EDIT_BUF_SIZE);
|
||||
buf++;
|
||||
}
|
||||
filelen += write (file, (char *) edit->buffers1[buf], edit->curs1 & M_EDIT_BUF_SIZE);
|
||||
|
||||
if (edit->curs2) {
|
||||
edit->curs2--;
|
||||
buf = (edit->curs2 >> S_EDIT_BUF_SIZE);
|
||||
filelen += write (file, (char *) edit->buffers2[buf] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1, 1 + (edit->curs2 & M_EDIT_BUF_SIZE));
|
||||
buf--;
|
||||
while (buf >= 0) {
|
||||
filelen += write (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE);
|
||||
buf--;
|
||||
}
|
||||
edit->curs2++;
|
||||
}
|
||||
close (file);
|
||||
|
||||
if (filelen == edit->last_byte) {
|
||||
if (this_save_mode == 2) {
|
||||
if (rename (filename, catstrs (filename, option_backup_ext, 0)) == -1) { /* catstrs free's automatically */
|
||||
free (savename);
|
||||
return 0;
|
||||
/* pipe save */
|
||||
if ((p = (char *) edit_get_write_filter (savename, filename))) {
|
||||
fclose (file);
|
||||
file = (FILE *) popen (p, "w");
|
||||
if (file) {
|
||||
filelen = edit_write_stream (edit, file);
|
||||
#if 1
|
||||
pclose (file);
|
||||
#else
|
||||
if (pclose (file) > 0) {
|
||||
edit_error_dialog (_ (" Error "), catstrs (_ (" Error writing to pipe: "), p, " ", 0));
|
||||
free (p);
|
||||
goto error_save;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open pipe for writing: "), p, " ", 0)));
|
||||
free (p);
|
||||
goto error_save;
|
||||
}
|
||||
if (this_save_mode > 0) {
|
||||
if (rename (savename, filename) == -1) {
|
||||
free (savename);
|
||||
return 0;
|
||||
}
|
||||
free (savename);
|
||||
}
|
||||
return 1;
|
||||
free (p);
|
||||
#ifdef CR_LF_TRANSLATION
|
||||
} else { /* optimised save */
|
||||
filelen = edit_write_stream (edit, f);
|
||||
fclose (file);
|
||||
#else
|
||||
} else {
|
||||
if (this_save_mode > 0)
|
||||
free (savename);
|
||||
return 0;
|
||||
long buf;
|
||||
buf = 0;
|
||||
filelen = edit->last_byte;
|
||||
while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) {
|
||||
if (fwrite ((char *) edit->buffers1[buf], EDIT_BUF_SIZE, 1, file) != 1) {
|
||||
filelen = -1;
|
||||
break;
|
||||
}
|
||||
buf++;
|
||||
}
|
||||
if (fwrite ((char *) edit->buffers1[buf], edit->curs1 & M_EDIT_BUF_SIZE, 1, file) == -1) {
|
||||
filelen = -1;
|
||||
} else if (edit->curs2) {
|
||||
edit->curs2--;
|
||||
buf = (edit->curs2 >> S_EDIT_BUF_SIZE);
|
||||
if (fwrite ((char *) edit->buffers2[buf] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1, 1 + (edit->curs2 & M_EDIT_BUF_SIZE), 1, file) != 1) {
|
||||
filelen = -1;
|
||||
} else {
|
||||
buf--;
|
||||
while (buf >= 0) {
|
||||
if (fwrite ((char *) edit->buffers2[buf], EDIT_BUF_SIZE, 1, file) != 1) {
|
||||
filelen = -1;
|
||||
break;
|
||||
}
|
||||
buf--;
|
||||
}
|
||||
}
|
||||
edit->curs2++;
|
||||
}
|
||||
fclose (file);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (filelen != edit->last_byte)
|
||||
goto error_save;
|
||||
if (this_save_mode == 2)
|
||||
if (rename (filename, catstrs (filename, option_backup_ext, 0)) == -1)
|
||||
goto error_save;
|
||||
if (this_save_mode > 0)
|
||||
if (rename (savename, filename) == -1)
|
||||
goto error_save;
|
||||
if (savename)
|
||||
free (savename);
|
||||
return 1;
|
||||
error_save:
|
||||
if (savename)
|
||||
free (savename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef MIDNIGHT
|
||||
@ -326,6 +370,7 @@ int edit_save_file (WEdit * edit, const char *filename)
|
||||
*/
|
||||
void menu_save_mode_cmd (void)
|
||||
{
|
||||
#define DLG_X 38
|
||||
#define DLG_Y 10
|
||||
static char *str_result;
|
||||
static int save_mode_new;
|
||||
@ -336,52 +381,29 @@ void menu_save_mode_cmd (void)
|
||||
N_("Do backups -->")};
|
||||
static QuickWidget widgets[] =
|
||||
{
|
||||
{quick_button, 18, 0, 7, DLG_Y, N_("&Cancel"), 0,
|
||||
{quick_button, 18, DLG_X, 7, DLG_Y, N_("&Cancel"), 0,
|
||||
B_CANCEL, 0, 0, XV_WLAY_DONTCARE, "c"},
|
||||
{quick_button, 6, 0, 7, DLG_Y, N_("&Ok"), 0,
|
||||
{quick_button, 6, DLG_X, 7, DLG_Y, N_("&Ok"), 0,
|
||||
B_ENTER, 0, 0, XV_WLAY_DONTCARE, "o"},
|
||||
{quick_input, 23, 0, 5, DLG_Y, 0, 9,
|
||||
{quick_input, 23, DLG_X, 5, DLG_Y, 0, 9,
|
||||
0, 0, &str_result, XV_WLAY_DONTCARE, "i"},
|
||||
{quick_label, 23, 0, 4, DLG_Y, N_("Extension:"), 0,
|
||||
{quick_label, 22, DLG_X, 4, DLG_Y, N_("Extension:"), 0,
|
||||
0, 0, 0, XV_WLAY_DONTCARE, "savemext"},
|
||||
{quick_radio, 4, 0, 3, DLG_Y, "", 3,
|
||||
{quick_radio, 4, DLG_X, 3, DLG_Y, "", 3,
|
||||
0, &save_mode_new, str, XV_WLAY_DONTCARE, "t"},
|
||||
{0}};
|
||||
static QuickDialog dialog =
|
||||
/* NLS ? */
|
||||
{0, DLG_Y, -1, -1, N_(" Edit Save Mode "), "[Edit Save Mode]",
|
||||
{DLG_X, DLG_Y, -1, -1, N_(" Edit Save Mode "), "[Edit Save Mode]",
|
||||
"esm", widgets};
|
||||
static int i18n_flag = 0;
|
||||
|
||||
if (!i18n_flag) {
|
||||
int i;
|
||||
int maxlen = 0;
|
||||
int dlg_x;
|
||||
int l1;
|
||||
|
||||
/* Ok/Cancel buttons */
|
||||
l1 = strlen (_(widgets[0].text)) + strlen (_(widgets[1].text)) + 5;
|
||||
maxlen = max (maxlen, l1);
|
||||
|
||||
for (i = 0; i < 3; i++ ) {
|
||||
for (i = 0; i < 3; i++ )
|
||||
str[i] = _(str[i]);
|
||||
maxlen = max (maxlen, strlen (str[i]) + 7);
|
||||
}
|
||||
i18n_flag = 1;
|
||||
|
||||
dlg_x = maxlen + strlen (_(widgets[3].text)) + 5 + 1;
|
||||
widgets[2].hotkey_pos = strlen (_(widgets[3].text)); /* input field length */
|
||||
dlg_x = min (COLS, dlg_x);
|
||||
dialog.xlen = dlg_x;
|
||||
|
||||
i = (dlg_x - l1)/3;
|
||||
widgets[1].relative_x = i;
|
||||
widgets[0].relative_x = i + strlen (_(widgets[1].text)) + i + 4;
|
||||
|
||||
widgets[2].relative_x = widgets[3].relative_x = maxlen + 2;
|
||||
|
||||
for (i = 0; i < sizeof (widgets)/sizeof (widgets[0]); i++)
|
||||
widgets[i].x_divisions = dlg_x;
|
||||
}
|
||||
|
||||
widgets[2].text = option_backup_ext;
|
||||
@ -473,7 +495,11 @@ static char *canonicalize_pathname (char *p)
|
||||
void edit_split_filename (WEdit * edit, char *longname)
|
||||
{
|
||||
char *exp, *p;
|
||||
exp = canonicalize_pathname (longname); /* this ensures a full path */
|
||||
#if defined(MIDNIGHT) || defined(GTK)
|
||||
exp = canonicalize_pathname (longname);
|
||||
#else
|
||||
exp = pathdup (longname); /* this ensures a full path */
|
||||
#endif
|
||||
if (edit->filename)
|
||||
free (edit->filename);
|
||||
if (edit->dir)
|
||||
@ -844,21 +870,13 @@ int edit_new_cmd (WEdit * edit)
|
||||
}
|
||||
|
||||
/* returns 1 on error */
|
||||
int edit_load_file_from_filename (WEdit *edit, char *exp)
|
||||
int edit_load_file_from_filename (WEdit * edit, char *exp)
|
||||
{
|
||||
int file;
|
||||
if ((file = open ((char *) exp, O_RDONLY, MY_O_TEXT)) != -1) {
|
||||
close (file);
|
||||
if (!edit_reload (edit, exp, 0, "", 0))
|
||||
return 1;
|
||||
edit_split_filename (edit, exp);
|
||||
edit->modified = 0;
|
||||
return 0;
|
||||
} else {
|
||||
/* Heads the 'Load' file dialog box */
|
||||
edit_error_dialog (_ (" Load "), get_sys_error (_ (" Error trying to open file for reading ")));
|
||||
}
|
||||
return 1;
|
||||
if (!edit_reload (edit, exp, 0, "", 0))
|
||||
return 1;
|
||||
edit_split_filename (edit, exp);
|
||||
edit->modified = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int edit_load_cmd (WEdit * edit)
|
||||
@ -1164,39 +1182,36 @@ int edit_block_delete_cmd (WEdit * edit)
|
||||
|
||||
int edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos)
|
||||
{
|
||||
if (replace_prompt) {
|
||||
QuickWidget quick_widgets[] =
|
||||
{
|
||||
QuickWidget quick_widgets[] =
|
||||
{
|
||||
/* NLS for hotkeys? */
|
||||
{quick_button, 63, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_("&Cancel"),
|
||||
0, B_CANCEL, 0, 0, XV_WLAY_DONTCARE, NULL},
|
||||
{quick_button, 50, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_("o&Ne"),
|
||||
0, B_REPLACE_ONE, 0, 0, XV_WLAY_DONTCARE, NULL},
|
||||
{quick_button, 37, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_("al&L"),
|
||||
0, B_REPLACE_ALL, 0, 0, XV_WLAY_DONTCARE, NULL},
|
||||
{quick_button, 21, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_("&Skip"),
|
||||
0, B_SKIP_REPLACE, 0, 0, XV_WLAY_DONTCARE, NULL},
|
||||
{quick_button, 4, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_("&Replace"),
|
||||
0, B_ENTER, 0, 0, XV_WLAY_DONTCARE, NULL},
|
||||
{quick_label, 2, CONFIRM_DLG_WIDTH, 2, CONFIRM_DLG_HEIGTH, 0,
|
||||
0, 0, 0, XV_WLAY_DONTCARE, 0},
|
||||
{0}};
|
||||
{quick_button, 63, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("&Cancel"),
|
||||
0, B_CANCEL, 0, 0, XV_WLAY_DONTCARE, NULL},
|
||||
{quick_button, 50, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("o&Ne"),
|
||||
0, B_REPLACE_ONE, 0, 0, XV_WLAY_DONTCARE, NULL},
|
||||
{quick_button, 37, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("al&L"),
|
||||
0, B_REPLACE_ALL, 0, 0, XV_WLAY_DONTCARE, NULL},
|
||||
{quick_button, 21, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("&Skip"),
|
||||
0, B_SKIP_REPLACE, 0, 0, XV_WLAY_DONTCARE, NULL},
|
||||
{quick_button, 4, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("&Replace"),
|
||||
0, B_ENTER, 0, 0, XV_WLAY_DONTCARE, NULL},
|
||||
{quick_label, 2, CONFIRM_DLG_WIDTH, 2, CONFIRM_DLG_HEIGTH, 0,
|
||||
0, 0, 0, XV_WLAY_DONTCARE, 0},
|
||||
{0}};
|
||||
|
||||
quick_widgets[5].text = catstrs (_(" Replace with: "), replace_text, 0);
|
||||
quick_widgets[4].text = catstrs (_ (" Replace with: "), replace_text, 0);
|
||||
|
||||
{
|
||||
QuickDialog Quick_input =
|
||||
{CONFIRM_DLG_WIDTH, CONFIRM_DLG_HEIGTH, 0, 0, N_(" Confirm replace "),
|
||||
"[Input Line Keys]", "quick_input", 0 /*quick_widgets */ };
|
||||
{
|
||||
QuickDialog Quick_input =
|
||||
{CONFIRM_DLG_WIDTH, CONFIRM_DLG_HEIGTH, 0, 0, N_ (" Confirm replace "),
|
||||
"[Input Line Keys]", "quick_input", 0 /*quick_widgets */ };
|
||||
|
||||
Quick_input.widgets = quick_widgets;
|
||||
Quick_input.widgets = quick_widgets;
|
||||
|
||||
Quick_input.xpos = xpos;
|
||||
Quick_input.ypos = ypos;
|
||||
return quick_dialog (&Quick_input);
|
||||
}
|
||||
} else
|
||||
return 0;
|
||||
Quick_input.xpos = xpos;
|
||||
Quick_input.ypos = ypos;
|
||||
return quick_dialog (&Quick_input);
|
||||
}
|
||||
}
|
||||
|
||||
void edit_replace_dialog (WEdit * edit, char **search_text, char **replace_text, char **arg_order)
|
||||
@ -1369,12 +1384,16 @@ void edit_search_replace_dialog (Window parent, int x, int y, char **search_text
|
||||
CState s;
|
||||
int xh, yh, h, xb, ys, yc, yb, yr;
|
||||
CWidget *m;
|
||||
int text_input_width ;
|
||||
|
||||
CBackupState (&s);
|
||||
CDisable ("*");
|
||||
|
||||
win = CDrawHeadedDialog ("replace", parent, x, y, heading);
|
||||
CGetHintPos (&xh, &h);
|
||||
#ifdef NEXT_LOOK
|
||||
xh += NEXT_SPACING ;
|
||||
#endif
|
||||
|
||||
/* NLS hotkey ? */
|
||||
CIdent ("replace")->position = WINDOW_ALWAYS_RAISED;
|
||||
@ -1413,21 +1432,31 @@ void edit_search_replace_dialog (Window parent, int x, int y, char **search_text
|
||||
yb = yh;
|
||||
CGetHintPos (0, &yh);
|
||||
CGetHintPos (&xb, 0);
|
||||
|
||||
#ifdef NEXT_LOOK
|
||||
xb += NEXT_SPACING ;
|
||||
#endif
|
||||
if (option & SEARCH_DIALOG_OPTION_BACKWARDS) {
|
||||
CDrawSwitch ("replace.bkwd", win, xh, yh, replace_backwards, _(" Backwards "), 0);
|
||||
/* Tool hint */
|
||||
CSetToolHint ("replace.bkwd", _("Warning: Searching backward can be slow"));
|
||||
CSetToolHint ("replace.bkwd.label", _("Warning: Searching backward can be slow"));
|
||||
yb = yh;
|
||||
}
|
||||
if (replace_text) {
|
||||
yr = ys;
|
||||
if (option & SEARCH_DIALOG_OPTION_BACKWARDS)
|
||||
yr = yc;
|
||||
else
|
||||
yr = ys;
|
||||
} else {
|
||||
yr = yb;
|
||||
if (option & SEARCH_DIALOG_OPTION_BACKWARDS) {
|
||||
if (option & SEARCH_DIALOG_OPTION_BOOKMARK)
|
||||
yr = yb;
|
||||
else
|
||||
yr = yh;
|
||||
} else {
|
||||
if (option & SEARCH_DIALOG_OPTION_BOOKMARK)
|
||||
yr = yc;
|
||||
else
|
||||
yr = yb;
|
||||
}
|
||||
}
|
||||
|
||||
if (replace_text) {
|
||||
@ -1436,6 +1465,15 @@ void edit_search_replace_dialog (Window parent, int x, int y, char **search_text
|
||||
CSetToolHint ("replace.pr", _("Ask before making each replacement"));
|
||||
CGetHintPos (0, &yr);
|
||||
CDrawSwitch ("replace.all", win, xb, yr, replace_all, _(" Replace all "), 0);
|
||||
/* Tool hint */
|
||||
CSetToolHint ("replace.all", _("Replace repeatedly"));
|
||||
CGetHintPos (0, &yr);
|
||||
}
|
||||
if (option & SEARCH_DIALOG_OPTION_BOOKMARK) {
|
||||
CDrawSwitch ("replace.bkmk", win, xb, yr, search_create_bookmark, _(" Bookmarks "), 0);
|
||||
/* Tool hint */
|
||||
CSetToolHint ("replace.bkmk", _("Create bookmarks at all lines found"));
|
||||
CSetToolHint ("replace.bkmk.label", _("Create bookmarks at all lines found"));
|
||||
CGetHintPos (0, &yr);
|
||||
}
|
||||
CDrawSwitch ("replace.scanf", win, xb, yr, replace_scanf, _(" Scanf expression "), 1);
|
||||
@ -1443,20 +1481,43 @@ void edit_search_replace_dialog (Window parent, int x, int y, char **search_text
|
||||
CSetToolHint ("replace.scanf", _("Allows entering of a C format string,\nsee the scanf man page"));
|
||||
|
||||
get_hint_limits (&x, &y);
|
||||
#ifdef NEXT_LOOK
|
||||
{
|
||||
int btn_width, x, y ;
|
||||
CGetHintPos (&x, &y);
|
||||
|
||||
y += NEXT_SPACING * 2 ;
|
||||
x += NEXT_SPACING * 2 ;
|
||||
CTextSize (&btn_width, 0, " Cancel ");
|
||||
btn_width += 4 + BUTTON_RELIEF * 2;
|
||||
x -= (btn_width + NEXT_SPACING) * 2 + NEXT_SPACING;
|
||||
|
||||
CDrawButton ("replace.ok", win, x+btn_width + NEXT_SPACING * 2, y, AUTO_WIDTH, AUTO_HEIGHT, " Ok ");
|
||||
CDrawButton ("replace.cancel", win, x, y, AUTO_WIDTH, AUTO_HEIGHT, " Cancel ");
|
||||
CGetHintPos (0, &y);
|
||||
x += (btn_width + NEXT_SPACING) * 2 + NEXT_SPACING;
|
||||
reset_hint_pos (x, y + NEXT_SPACING*2);
|
||||
}
|
||||
#else
|
||||
CDrawPixmapButton ("replace.ok", win, x - WIDGET_SPACING - TICK_BUTTON_WIDTH, h, PIXMAP_BUTTON_TICK);
|
||||
CDrawPixmapButton ("replace.cancel", win, x - WIDGET_SPACING - TICK_BUTTON_WIDTH, h + WIDGET_SPACING + TICK_BUTTON_WIDTH, PIXMAP_BUTTON_CROSS);
|
||||
#endif
|
||||
/* Tool hint */
|
||||
CSetToolHint ("replace.ok", _("Begin search, Enter"));
|
||||
CDrawPixmapButton ("replace.cancel", win, x - WIDGET_SPACING - TICK_BUTTON_WIDTH, h + WIDGET_SPACING + TICK_BUTTON_WIDTH, PIXMAP_BUTTON_CROSS);
|
||||
/* Tool hint */
|
||||
CSetToolHint ("replace.cancel", _("Abort this dialog, Esc"));
|
||||
CSetSizeHintPos ("replace");
|
||||
CMapDialog ("replace");
|
||||
|
||||
m = CIdent ("replace");
|
||||
CSetWidgetSize ("replace.sinp", m->width - WIDGET_SPACING * 3 - 4 - TICK_BUTTON_WIDTH, (CIdent ("replace.sinp"))->height);
|
||||
#ifdef NEXT_LOOK
|
||||
text_input_width = m->width - WIDGET_SPACING * 3 - 4 - NEXT_SPACING*2 ;
|
||||
#else
|
||||
text_input_width = m->width - WIDGET_SPACING * 3 - 4 - TICK_BUTTON_WIDTH ;
|
||||
#endif
|
||||
CSetWidgetSize ("replace.sinp", text_input_width, (CIdent ("replace.sinp"))->height);
|
||||
if (replace_text) {
|
||||
CSetWidgetSize ("replace.rinp", m->width - WIDGET_SPACING * 3 - 4 - TICK_BUTTON_WIDTH, (CIdent ("replace.rinp"))->height);
|
||||
CSetWidgetSize ("replace.ainp", m->width - WIDGET_SPACING * 3 - 4 - TICK_BUTTON_WIDTH, (CIdent ("replace.ainp"))->height);
|
||||
CSetWidgetSize ("replace.rinp", text_input_width, (CIdent ("replace.rinp"))->height);
|
||||
CSetWidgetSize ("replace.ainp", text_input_width, (CIdent ("replace.ainp"))->height);
|
||||
}
|
||||
CFocus (CIdent ("replace.sinp"));
|
||||
|
||||
@ -1497,6 +1558,12 @@ void edit_search_replace_dialog (Window parent, int x, int y, char **search_text
|
||||
replace_backwards = 0;
|
||||
}
|
||||
|
||||
if (option & SEARCH_DIALOG_OPTION_BOOKMARK) {
|
||||
search_create_bookmark = CIdent ("replace.bkmk")->keypressed;
|
||||
} else {
|
||||
search_create_bookmark = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1507,7 +1574,7 @@ void edit_search_replace_dialog (Window parent, int x, int y, char **search_text
|
||||
void edit_search_dialog (WEdit * edit, char **search_text)
|
||||
{
|
||||
/* Heads the 'Search' dialog box */
|
||||
edit_search_replace_dialog (WIN_MESSAGES, search_text, 0, 0, _(" Search "), SEARCH_DIALOG_OPTION_BACKWARDS);
|
||||
edit_search_replace_dialog (WIN_MESSAGES, search_text, 0, 0, _(" Search "), SEARCH_DIALOG_OPTION_BACKWARDS | SEARCH_DIALOG_OPTION_BOOKMARK);
|
||||
}
|
||||
|
||||
void edit_replace_dialog (WEdit * edit, char **search_text, char **replace_text, char **arg_order)
|
||||
@ -1571,44 +1638,38 @@ void edit_replace_dialog (WEdit * edit, char **search_text, char **replace_text,
|
||||
|
||||
int edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos)
|
||||
{
|
||||
if (replace_prompt) {
|
||||
char *s;
|
||||
s = gtk_dialog_cauldron (
|
||||
"Replace", GTK_CAULDRON_TOPLEVEL | GTK_CAULDRON_GRAB,
|
||||
" ( (Replace with:)d %Ld )xf / ( %Bxfrq || %Bxfq || %Bxfq || %Bxfq || %Bxfgq )f",
|
||||
replace_text,
|
||||
"Replace", "Skip", "Replace all", "Replace one",
|
||||
GNOME_STOCK_BUTTON_CANCEL
|
||||
);
|
||||
if (s == GTK_CAULDRON_ESCAPE || !s || s == GNOME_STOCK_BUTTON_CANCEL)
|
||||
return B_CANCEL;
|
||||
if (!strcmp (s, "Replace all"))
|
||||
return B_REPLACE_ALL;
|
||||
if (!strcmp (s, "Replace one"))
|
||||
return B_REPLACE_ONE;
|
||||
if (!strcmp (s, "Skip"))
|
||||
return B_SKIP_REPLACE;
|
||||
if (!strcmp (s, "Replace"))
|
||||
return B_ENTER;
|
||||
}
|
||||
return 0;
|
||||
char *s;
|
||||
s = gtk_dialog_cauldron (
|
||||
"Replace", GTK_CAULDRON_TOPLEVEL | GTK_CAULDRON_GRAB,
|
||||
" ( (Replace with:)d %Ld )xf / ( %Bxfrq || %Bxfq || %Bxfq || %Bxfq || %Bxfgq )f",
|
||||
replace_text,
|
||||
"Replace", "Skip", "Replace all", "Replace one",
|
||||
GNOME_STOCK_BUTTON_CANCEL
|
||||
);
|
||||
if (s == GTK_CAULDRON_ESCAPE || !s || s == GNOME_STOCK_BUTTON_CANCEL)
|
||||
return B_CANCEL;
|
||||
if (!strcmp (s, "Replace all"))
|
||||
return B_REPLACE_ALL;
|
||||
if (!strcmp (s, "Replace one"))
|
||||
return B_REPLACE_ONE;
|
||||
if (!strcmp (s, "Skip"))
|
||||
return B_SKIP_REPLACE;
|
||||
if (!strcmp (s, "Replace"))
|
||||
return B_ENTER;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos)
|
||||
{
|
||||
if (replace_prompt) {
|
||||
int q, x[] =
|
||||
{
|
||||
B_CANCEL, B_ENTER, B_SKIP_REPLACE, B_REPLACE_ALL, B_REPLACE_ONE, B_CANCEL
|
||||
};
|
||||
q = CQueryDialog (WIN_MESSAGES + (edit->curs_line < 8 ? edit->num_widget_lines / 2 * FONT_PIX_PER_LINE + CYof (edit->widget) : 0),
|
||||
_ (" Replace "), catstrs (_ (" Replace with: "), replace_text, 0), _ ("Replace"), _ ("Skip"), _ ("Replace all"), _ ("Replace one"), _ ("Cancel"), 0);
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
return x[q + 1];
|
||||
}
|
||||
return 0;
|
||||
int q, x[] =
|
||||
{
|
||||
B_CANCEL, B_ENTER, B_SKIP_REPLACE, B_REPLACE_ALL, B_REPLACE_ONE, B_CANCEL
|
||||
};
|
||||
q = CQueryDialog (WIN_MESSAGES + (edit->curs_line < 8 ? edit->num_widget_lines / 2 * FONT_PIX_PER_LINE + CYof (edit->widget) : 0),
|
||||
_ (" Replace "), catstrs (_ (" Replace with: "), replace_text, 0), _ ("Replace"), _ ("Skip"), _ ("Replace all"), _ ("Replace one"), _ ("Cancel"), 0);
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
return x[q + 1];
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1981,10 +2042,10 @@ void edit_replace_cmd (WEdit * edit, int again)
|
||||
char *exp3 = "";
|
||||
int replace_yes;
|
||||
int replace_continue;
|
||||
int treplace_prompt = replace_prompt;
|
||||
int treplace_prompt = 0;
|
||||
int i = 0;
|
||||
long times_replaced = 0, last_search;
|
||||
char fin_string[32];
|
||||
char fin_string[64];
|
||||
int argord[NUM_REPL_ARGS];
|
||||
|
||||
if (!edit) {
|
||||
@ -2019,6 +2080,7 @@ void edit_replace_cmd (WEdit * edit, int again)
|
||||
} else {
|
||||
edit_push_action (edit, KEY_PRESS + edit->start_display);
|
||||
edit_replace_dialog (edit, &exp1, &exp2, &exp3);
|
||||
treplace_prompt = replace_prompt;
|
||||
}
|
||||
|
||||
if (!exp1 || !*exp1) {
|
||||
@ -2103,7 +2165,7 @@ void edit_replace_cmd (WEdit * edit, int again)
|
||||
edit_push_key_press (edit);
|
||||
|
||||
switch (edit_replace_prompt (edit, exp2, /*and prompt 2/3 down */
|
||||
edit->num_widget_columns / 2 - 39, edit->num_widget_lines * 2 / 3)) {
|
||||
edit->num_widget_columns / 2 - 33, edit->num_widget_lines * 2 / 3)) {
|
||||
case B_ENTER:
|
||||
break;
|
||||
case B_SKIP_REPLACE:
|
||||
@ -2204,7 +2266,6 @@ void edit_search_cmd (WEdit * edit, int again)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
exp = old ? old : exp;
|
||||
if (again) { /*ctrl-hotkey for search again. */
|
||||
if (!old)
|
||||
@ -2222,31 +2283,60 @@ void edit_search_cmd (WEdit * edit, int again)
|
||||
free (old);
|
||||
old = (char *) strdup (exp);
|
||||
|
||||
if (edit->found_len && edit->search_start == edit->found_start + 1 && replace_backwards)
|
||||
edit->search_start--;
|
||||
|
||||
if (edit->found_len && edit->search_start == edit->found_start - 1 && !replace_backwards)
|
||||
edit->search_start++;
|
||||
|
||||
edit->search_start = edit_find (edit->search_start, (unsigned char *) exp, &len, edit->last_byte,
|
||||
(int (*)(void *, long)) edit_get_byte, (void *) edit, 0);
|
||||
|
||||
if (edit->search_start >= 0) {
|
||||
edit->found_start = edit->search_start;
|
||||
edit->found_len = len;
|
||||
|
||||
edit_cursor_move (edit, edit->search_start - edit->curs1);
|
||||
edit_scroll_screen_over_cursor (edit);
|
||||
if (replace_backwards)
|
||||
edit->search_start--;
|
||||
else
|
||||
edit->search_start++;
|
||||
} else if (edit->search_start == -3) {
|
||||
edit->search_start = edit->curs1;
|
||||
regexp_error (edit);
|
||||
if (search_create_bookmark) {
|
||||
int found = 0, books = 0;
|
||||
int l = 0, l_last = -1;
|
||||
long p, q = 0;
|
||||
for (;;) {
|
||||
p = edit_find (q, (unsigned char *) exp, &len, edit->last_byte,
|
||||
(int (*)(void *, long)) edit_get_byte, (void *) edit, 0);
|
||||
if (p < 0)
|
||||
break;
|
||||
found++;
|
||||
l += edit_count_lines (edit, q, p);
|
||||
if (l != l_last) {
|
||||
book_mark_insert (edit, l, BOOK_MARK_FOUND_COLOR);
|
||||
books++;
|
||||
}
|
||||
l_last = l;
|
||||
q = p + 1;
|
||||
}
|
||||
if (found) {
|
||||
char fin_string[64];
|
||||
/* in response to number of bookmarks added because of string being found %d times */
|
||||
sprintf (fin_string, _ (" %d finds made, %d bookmarks added "), found, books);
|
||||
edit_message_dialog (_ (" Search "), fin_string);
|
||||
} else {
|
||||
edit_error_dialog (_ (" Search "), _ (" Search string not found. "));
|
||||
}
|
||||
} else {
|
||||
edit->search_start = edit->curs1;
|
||||
edit_error_dialog (_(" Search "), _(" Search string not found. "));
|
||||
|
||||
if (edit->found_len && edit->search_start == edit->found_start + 1 && replace_backwards)
|
||||
edit->search_start--;
|
||||
|
||||
if (edit->found_len && edit->search_start == edit->found_start - 1 && !replace_backwards)
|
||||
edit->search_start++;
|
||||
|
||||
edit->search_start = edit_find (edit->search_start, (unsigned char *) exp, &len, edit->last_byte,
|
||||
(int (*)(void *, long)) edit_get_byte, (void *) edit, 0);
|
||||
|
||||
if (edit->search_start >= 0) {
|
||||
edit->found_start = edit->search_start;
|
||||
edit->found_len = len;
|
||||
|
||||
edit_cursor_move (edit, edit->search_start - edit->curs1);
|
||||
edit_scroll_screen_over_cursor (edit);
|
||||
if (replace_backwards)
|
||||
edit->search_start--;
|
||||
else
|
||||
edit->search_start++;
|
||||
} else if (edit->search_start == -3) {
|
||||
edit->search_start = edit->curs1;
|
||||
regexp_error (edit);
|
||||
} else {
|
||||
edit->search_start = edit->curs1;
|
||||
edit_error_dialog (_ (" Search "), _ (" Search string not found. "));
|
||||
}
|
||||
}
|
||||
}
|
||||
free (exp);
|
||||
@ -2688,29 +2778,6 @@ int edit_save_block_cmd (WEdit * edit)
|
||||
}
|
||||
|
||||
|
||||
/* inserts a file at the cursor, returns 1 on success */
|
||||
int edit_insert_file (WEdit * edit, const char *filename)
|
||||
{
|
||||
int i, file, blocklen;
|
||||
long current = edit->curs1;
|
||||
unsigned char *buf;
|
||||
|
||||
if ((file = open ((char *) filename, O_RDONLY)) == -1)
|
||||
return 0;
|
||||
buf = malloc (TEMP_BUF_LEN);
|
||||
while ((blocklen = read (file, (char *) buf, TEMP_BUF_LEN)) > 0) {
|
||||
for (i = 0; i < blocklen; i++)
|
||||
edit_insert (edit, buf[i]);
|
||||
}
|
||||
edit_cursor_move (edit, current - edit->curs1);
|
||||
free (buf);
|
||||
close (file);
|
||||
if (blocklen)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* returns 1 on success */
|
||||
int edit_insert_file_cmd (WEdit * edit)
|
||||
{
|
||||
|
@ -88,6 +88,9 @@
|
||||
#define CK_Type_Load_Python 418
|
||||
#define CK_Find_File 419
|
||||
#define CK_Ctags 420
|
||||
#define CK_Match_Bracket 421
|
||||
#define CK_Terminal 422
|
||||
#define CK_Terminal_App 423
|
||||
|
||||
/* application control */
|
||||
#define CK_Save_Desktop 451
|
||||
|
@ -103,9 +103,6 @@ void edit_status (WEdit * edit)
|
||||
|
||||
#else
|
||||
|
||||
#ifndef GTK
|
||||
extern int fixed_font;
|
||||
#endif
|
||||
|
||||
void render_status (CWidget * wdt, int expose);
|
||||
|
||||
@ -154,6 +151,7 @@ void edit_status (WEdit * edit)
|
||||
end_mark = start_mark = 0;
|
||||
if ((COptionsOf (edit->widget) & EDITOR_NO_TEXT))
|
||||
return;
|
||||
CPushFont ("editor", 0);
|
||||
m = edit->stat.st_mode;
|
||||
p = edit->filename ? edit->filename : "";
|
||||
sprintf (s, "\034%c%s\033\035 \034-%c%c%c%c%c%c%c%c%c\035 \034%s%s%s%c\035 \034\030%02ld\033\035 \034%-4ld+%2ld=\030%4ld\033/%3ld\035 \034*%-5ld/%5ldb=%c%3d\035%c \034\001%ld\033\035",
|
||||
@ -183,6 +181,7 @@ void edit_status (WEdit * edit)
|
||||
wdt->text = (char *) strdup (s);
|
||||
CSetWidgetSize (id, CWidthOf (edit->widget), CHeightOf (wdt));
|
||||
render_status (wdt, 0);
|
||||
CPopFont ();
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -220,7 +219,6 @@ int cursor_out_of_screen (WEdit * edit)
|
||||
}
|
||||
|
||||
#ifndef MIDNIGHT
|
||||
extern unsigned char per_char[256];
|
||||
int edit_width_of_long_printable (int c);
|
||||
#endif
|
||||
|
||||
@ -464,9 +462,10 @@ static void edit_draw_this_line (WEdit * edit, long b, long row, long start_col,
|
||||
|
||||
#else
|
||||
|
||||
int edit_mouse_pending (Window win);
|
||||
#define edit_draw_this_line edit_draw_this_line_proportional
|
||||
|
||||
int option_smooth_scrolling = 0;
|
||||
|
||||
static int key_pending (WEdit * edit)
|
||||
{
|
||||
static int flush = 0, line = 0;
|
||||
@ -475,7 +474,7 @@ static int key_pending (WEdit * edit)
|
||||
#else
|
||||
if (!edit) {
|
||||
flush = line = 0;
|
||||
} else if (!(edit->force & REDRAW_COMPLETELY) && !EditExposeRedraw) {
|
||||
} else if (!(edit->force & REDRAW_COMPLETELY) && !EditExposeRedraw && !option_smooth_scrolling) {
|
||||
/* this flushes the display in logarithmic intervals - so both fast and
|
||||
slow machines will get good performance vs nice-refreshing */
|
||||
if ((1 << flush) == ++line) {
|
||||
@ -502,12 +501,14 @@ static void edit_draw_this_char (WEdit * edit, long curs, long row)
|
||||
}
|
||||
|
||||
/* cursor must be in screen for other than REDRAW_PAGE passed in force */
|
||||
void render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column)
|
||||
void render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
|
||||
long end_column)
|
||||
{
|
||||
long row = 0, curs_row;
|
||||
static int prev_curs_row = 0;
|
||||
static int prev_start_col = 0;
|
||||
static long prev_curs = 0;
|
||||
static long prev_start = -1;
|
||||
|
||||
#ifndef MIDNIGHT
|
||||
static unsigned long prev_win = 0;
|
||||
@ -516,6 +517,8 @@ void render_edit_text (WEdit * edit, long start_row, long start_column, long end
|
||||
int force = edit->force;
|
||||
long b;
|
||||
|
||||
CPushFont ("editor", 0);
|
||||
|
||||
#ifndef MIDNIGHT
|
||||
key_pending (0);
|
||||
#endif
|
||||
@ -533,6 +536,60 @@ void render_edit_text (WEdit * edit, long start_row, long start_column, long end
|
||||
#endif
|
||||
#endif
|
||||
) {
|
||||
int time_division = 5;
|
||||
#if 0
|
||||
if (CPending ())
|
||||
time_division--;
|
||||
#endif
|
||||
#if !defined(MIDNIGHT) && !defined(GTK)
|
||||
if (prev_start < 0)
|
||||
prev_start = edit->start_line;
|
||||
if (option_smooth_scrolling && prev_win == CWindowOf (edit->widget) && !edit->screen_modified) {
|
||||
int i, t;
|
||||
int pos1, pos2;
|
||||
i = edit->start_line - prev_start;
|
||||
if (i <= time_division && i > 0) {
|
||||
edit_draw_proportional (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
for (pos2 = 0, t = 0; t < time_division; t++) {
|
||||
int move;
|
||||
pos1 = FONT_PIX_PER_LINE * i * (t + 1) / time_division;
|
||||
move = pos1 - pos2;
|
||||
pos2 += move;
|
||||
XCopyArea (CDisplay, edit->widget->winid, edit->widget->winid, CGC,
|
||||
EDIT_TEXT_HORIZONTAL_OFFSET,
|
||||
EDIT_TEXT_VERTICAL_OFFSET + move,
|
||||
edit->widget->width - EDIT_FRAME_W,
|
||||
edit->widget->height - EDIT_FRAME_H - move,
|
||||
EDIT_TEXT_HORIZONTAL_OFFSET, EDIT_TEXT_VERTICAL_OFFSET);
|
||||
XClearArea (CDisplay, edit->widget->winid, EDIT_TEXT_HORIZONTAL_OFFSET,
|
||||
edit->widget->height - EDIT_FRAME_H +
|
||||
EDIT_TEXT_VERTICAL_OFFSET - move,
|
||||
edit->widget->width - EDIT_FRAME_W, move, 0);
|
||||
XFlush (CDisplay);
|
||||
pause ();
|
||||
}
|
||||
} else if (i >= -time_division && i < 0) {
|
||||
edit_draw_proportional (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
i = -i;
|
||||
for (pos2 = 0, t = 0; t < time_division; t++) {
|
||||
int move;
|
||||
pos1 = FONT_PIX_PER_LINE * i * (t + 1) / time_division;
|
||||
move = pos1 - pos2;
|
||||
pos2 += move;
|
||||
XCopyArea (CDisplay, edit->widget->winid, edit->widget->winid, CGC,
|
||||
EDIT_TEXT_HORIZONTAL_OFFSET, EDIT_TEXT_VERTICAL_OFFSET,
|
||||
edit->widget->width - EDIT_FRAME_W,
|
||||
edit->widget->height - EDIT_FRAME_H -
|
||||
move, EDIT_TEXT_HORIZONTAL_OFFSET, EDIT_TEXT_VERTICAL_OFFSET + move);
|
||||
XClearArea (CDisplay, edit->widget->winid, EDIT_TEXT_HORIZONTAL_OFFSET,
|
||||
EDIT_TEXT_VERTICAL_OFFSET,
|
||||
edit->widget->width - EDIT_FRAME_W, move, 0);
|
||||
XFlush (CDisplay);
|
||||
pause ();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!(force & REDRAW_IN_BOUNDS)) { /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
|
||||
start_row = 0;
|
||||
end_row = edit->num_widget_lines - 1;
|
||||
@ -569,7 +626,7 @@ void render_edit_text (WEdit * edit, long start_row, long start_column, long end
|
||||
}
|
||||
}
|
||||
}
|
||||
/* if (force & REDRAW_LINE) { ---> default */
|
||||
/* if (force & REDRAW_LINE) ---> default */
|
||||
b = edit_bol (edit, edit->curs1);
|
||||
if (curs_row >= start_row && curs_row <= end_row) {
|
||||
if (key_pending (edit))
|
||||
@ -632,6 +689,9 @@ void render_edit_text (WEdit * edit, long start_row, long start_column, long end
|
||||
#endif
|
||||
#endif
|
||||
exit_render:
|
||||
edit->screen_modified = 0;
|
||||
prev_start = edit->start_line;
|
||||
CPopFont ();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -664,15 +724,17 @@ void edit_render_tidbits (CWidget * wdt)
|
||||
|
||||
win = wdt->winid;
|
||||
isfocussed = (win == CGetFocus ());
|
||||
|
||||
CSetColor (COLOR_FLAT);
|
||||
|
||||
#ifdef NEXT_LOOK
|
||||
render_bevel (win, 0, 0, w - 1, h - 1, 1, 1); /*most outer border bevel */
|
||||
#else
|
||||
if (isfocussed) {
|
||||
render_bevel (win, 0, 0, w - 1, h - 1, 3, 1); /*most outer border bevel */
|
||||
} else {
|
||||
render_bevel (win, 2, 2, w - 3, h - 3, 1, 1); /*border bevel */
|
||||
render_bevel (win, 0, 0, w - 1, h - 1, 2, 0); /*most outer border bevel */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -697,9 +759,9 @@ void edit_render (WEdit * edit, int page, int row_start, int col_start, int row_
|
||||
redraw_labels (edit->widget.parent, (Widget *) edit);
|
||||
#else
|
||||
if (option_long_whitespace)
|
||||
edit_set_space_width (per_char[' '] * 2);
|
||||
edit_set_space_width (FONT_PER_CHAR[' '] * 2);
|
||||
else
|
||||
edit_set_space_width (per_char[' ']);
|
||||
edit_set_space_width (FONT_PER_CHAR[' ']);
|
||||
#ifdef GTK
|
||||
win = (GtkEdit *) edit->widget;
|
||||
#endif
|
||||
@ -726,7 +788,6 @@ void edit_render (WEdit * edit, int page, int row_start, int col_start, int row_
|
||||
set_cursor_position (0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
render_edit_text (edit, row_start, col_start, row_end, col_end);
|
||||
if (edit->force) /* edit->force != 0 means a key was pending and the redraw
|
||||
was halted, so next time we must redraw everything in case stuff
|
||||
@ -738,8 +799,10 @@ void edit_render (WEdit * edit, int page, int row_start, int col_start, int row_
|
||||
#ifdef GTK
|
||||
/* ***************** */
|
||||
#else
|
||||
#ifndef NEXT_LOOK
|
||||
CSetColor (edit_normal_background_color);
|
||||
CLine (CWindowOf (edit->widget), 3, 3, 3, CHeightOf (edit->widget) - 4);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -749,6 +812,7 @@ void edit_render (WEdit * edit, int page, int row_start, int col_start, int row_
|
||||
void edit_render_expose (WEdit * edit, XExposeEvent * xexpose)
|
||||
{
|
||||
int row_start, col_start, row_end, col_end;
|
||||
CPushFont ("editor", 0);
|
||||
EditExposeRedraw = 1;
|
||||
edit->num_widget_lines = (CHeightOf (edit->widget) - EDIT_FRAME_H) / FONT_PIX_PER_LINE;
|
||||
edit->num_widget_columns = (CWidthOf (edit->widget) - EDIT_FRAME_W) / FONT_MEAN_WIDTH;
|
||||
@ -759,12 +823,15 @@ void edit_render_expose (WEdit * edit, XExposeEvent * xexpose)
|
||||
edit_convert_expose_to_area (xexpose, &row_start, &col_start, &row_end, &col_end);
|
||||
edit_render (edit, 1, row_start, col_start, row_end, col_end);
|
||||
}
|
||||
CPopFont ();
|
||||
EditExposeRedraw = 0;
|
||||
}
|
||||
|
||||
void edit_render_keypress (WEdit * edit)
|
||||
{
|
||||
CPushFont ("editor", 0);
|
||||
edit_render (edit, 0, 0, 0, 0, 0);
|
||||
CPopFont ();
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -71,14 +71,14 @@ void edit_wrap_cmd ()
|
||||
|
||||
void edit_about_cmd ()
|
||||
{
|
||||
edit_message_dialog (wedit->mainid, 20, 20, _(" About "),
|
||||
_("\n"
|
||||
edit_message_dialog (wedit->mainid, 20, 20, " About ",
|
||||
"\n"
|
||||
" Cooledit v3.11.5\n"
|
||||
"\n"
|
||||
" Copyright (C) 1996 the Free Software Foundation\n"
|
||||
"\n"
|
||||
" A user friendly text editor written\n"
|
||||
" for the Midnight Commander.\n")
|
||||
" for the Midnight Commander.\n"
|
||||
);
|
||||
}
|
||||
|
||||
@ -113,6 +113,7 @@ void menu_beginning_cmd (void) { menu_cmd (CK_Beginning_Of_Text); }
|
||||
void menu_end_cmd (void) { menu_cmd (CK_End_Of_Text); }
|
||||
void menu_refresh_cmd (void) { menu_cmd (CK_Refresh); }
|
||||
void menu_goto_line (void) { menu_cmd (CK_Goto); }
|
||||
void menu_goto_bracket (void) { menu_cmd (CK_Match_Bracket); }
|
||||
void menu_lit_cmd (void) { menu_key (XCTRL ('q')); }
|
||||
void menu_format_paragraph (void) { menu_cmd (CK_Paragraph_Format); }
|
||||
void edit_options_dialog (void);
|
||||
@ -201,6 +202,7 @@ static menu_entry SearReplMenuEmacs[] =
|
||||
static menu_entry CmdMenu[] =
|
||||
{
|
||||
{' ', N_("&Goto line... M-l"), 'G', menu_goto_line},
|
||||
{' ', N_("goto matching &Bracket M-b"), 'B', menu_goto_bracket},
|
||||
{' ', "", ' ', 0},
|
||||
{' ', N_("insert &Literal... C-q"), 'L', menu_lit_cmd},
|
||||
{' ', "", ' ', 0},
|
||||
@ -223,6 +225,7 @@ static menu_entry CmdMenu[] =
|
||||
static menu_entry CmdMenuEmacs[] =
|
||||
{
|
||||
{' ', N_("&Goto line... M-l"), 'G', menu_goto_line},
|
||||
{' ', N_("goto matching &Bracket M-b"), 'B', menu_goto_bracket},
|
||||
{' ', "", ' ', 0},
|
||||
{' ', N_("insert &Literal... C-q"), 'L', menu_lit_cmd},
|
||||
{' ', "", ' ', 0},
|
||||
@ -448,9 +451,10 @@ void CDrawEditMenuButtons (const char *ident, Window parent, Window focus_return
|
||||
|
||||
CGetHintPos (&x, &d);
|
||||
|
||||
CDrawMenuButton (catstrs (ident, ".commandmenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 11,
|
||||
CDrawMenuButton (catstrs (ident, ".commandmenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 12,
|
||||
_(" Command "),
|
||||
_("Goto line...\tM-l"), '~', menu_cmd, (unsigned long) CK_Goto,
|
||||
_("Goto matching bracket\tM-b"), '~', menu_cmd, (unsigned long) CK_Match_Bracket,
|
||||
"", ' ', (void *) 0, 0L,
|
||||
_("Start record macro\tC-r"), '~', menu_cmd, (unsigned long) CK_Begin_Record_Macro,
|
||||
_("Finish record macro...\tC-r"), '~', menu_cmd, (unsigned long) CK_End_Record_Macro,
|
||||
|
@ -18,7 +18,7 @@
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307, USA.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "edit.h"
|
||||
@ -95,7 +95,7 @@ static void xy (int x, int y, int *x_return, int *y_return)
|
||||
edit_translate_xy (x, y, x_return, y_return);
|
||||
}
|
||||
|
||||
static long cp (WEdit *edit, int x, int y)
|
||||
static long cp (WEdit * edit, int x, int y)
|
||||
{
|
||||
return edit_get_click_pos (edit, x, y);
|
||||
}
|
||||
@ -122,13 +122,13 @@ static int erange (WEdit * edit, long start, long end, int click)
|
||||
return (start <= click && click < end);
|
||||
}
|
||||
|
||||
static void fin_mark (WEdit *edit)
|
||||
static void fin_mark (WEdit * edit)
|
||||
{
|
||||
if (edit->mark2 < 0)
|
||||
edit_mark_cmd (edit, 0);
|
||||
}
|
||||
|
||||
static void move_mark (WEdit *edit)
|
||||
static void move_mark (WEdit * edit)
|
||||
{
|
||||
edit_mark_cmd (edit, 1);
|
||||
edit_mark_cmd (edit, 0);
|
||||
@ -162,12 +162,12 @@ static char *get_block (WEdit * edit, long start_mark, long end_mark, int *type,
|
||||
return t;
|
||||
}
|
||||
|
||||
static void move (WEdit *edit, long click, int y)
|
||||
static void move (WEdit * edit, long click, int y)
|
||||
{
|
||||
edit_cursor_move (edit, click - edit->curs1);
|
||||
}
|
||||
|
||||
static void dclick (WEdit *edit, XEvent *event)
|
||||
static void dclick (WEdit * edit, XEvent * event)
|
||||
{
|
||||
edit_mark_cmd (edit, 1);
|
||||
edit_right_word_move (edit, 1);
|
||||
@ -176,7 +176,7 @@ static void dclick (WEdit *edit, XEvent *event)
|
||||
release_mark (edit, event);
|
||||
}
|
||||
|
||||
static void redraw (WEdit *edit, long click)
|
||||
static void redraw (WEdit * edit, long click)
|
||||
{
|
||||
mouse_redraw (edit, click);
|
||||
}
|
||||
@ -246,7 +246,7 @@ static int insert_drop (WEdit * e, Window from, unsigned char *data, int size, i
|
||||
}
|
||||
|
||||
static char *mime_majors[2] =
|
||||
{"text", 0};
|
||||
{"text", 0};
|
||||
|
||||
struct mouse_funcs edit_mouse_funcs =
|
||||
{
|
||||
@ -269,25 +269,31 @@ struct mouse_funcs edit_mouse_funcs =
|
||||
mime_majors
|
||||
};
|
||||
|
||||
static void render_book_marks (CWidget *w);
|
||||
static void render_book_marks (CWidget * w);
|
||||
extern int option_editor_bg_normal;
|
||||
void edit_tri_cursor (Window win);
|
||||
|
||||
/* starting_directory is for the filebrowser */
|
||||
CWidget *CDrawEditor (const char *identifier, Window parent, int x, int y,
|
||||
int width, int height, const char *text, const char *filename,
|
||||
const char *starting_directory, unsigned int options, unsigned long text_size)
|
||||
const char *starting_directory, unsigned int options, unsigned long text_size)
|
||||
{
|
||||
static int made_directory = 0;
|
||||
int extra_space_for_hscroll = 0;
|
||||
CWidget *w;
|
||||
WEdit *e;
|
||||
|
||||
CPushFont ("editor", 0);
|
||||
#ifdef NEXT_LOOK
|
||||
x += NEXT_SPACING;
|
||||
if (options & EDITOR_HORIZ_SCROLL)
|
||||
extra_space_for_hscroll = 21;
|
||||
#else
|
||||
if (options & EDITOR_HORIZ_SCROLL)
|
||||
extra_space_for_hscroll = 8;
|
||||
|
||||
#endif
|
||||
wedit = w = CSetupWidget (identifier, parent, x, y,
|
||||
width + EDIT_FRAME_W, height + EDIT_FRAME_H, C_EDITOR_WIDGET,
|
||||
width + EDIT_FRAME_W, height + EDIT_FRAME_H, C_EDITOR_WIDGET,
|
||||
ExposureMask | ButtonPressMask | ButtonReleaseMask | \
|
||||
KeyPressMask | KeyReleaseMask | ButtonMotionMask | \
|
||||
PropertyChangeMask | StructureNotifyMask | \
|
||||
@ -315,6 +321,7 @@ CWidget *CDrawEditor (const char *identifier, Window parent, int x, int y,
|
||||
if (!w->editor) {
|
||||
/* Not essential to translate */
|
||||
CError (_ ("Error initialising editor.\n"));
|
||||
CPopFont ();
|
||||
return 0;
|
||||
}
|
||||
w->editor->widget = w;
|
||||
@ -323,25 +330,47 @@ CWidget *CDrawEditor (const char *identifier, Window parent, int x, int y,
|
||||
if (!w->editor) {
|
||||
free (e);
|
||||
CDestroyWidget (w->ident);
|
||||
CPopFont ();
|
||||
return 0;
|
||||
}
|
||||
e->macro_i = -1;
|
||||
e->widget = w;
|
||||
|
||||
set_hint_pos (x + width + EDIT_FRAME_W + WIDGET_SPACING, y + height + EDIT_FRAME_H + WIDGET_SPACING + extra_space_for_hscroll);
|
||||
if (extra_space_for_hscroll) {
|
||||
w->hori_scrollbar = CDrawHorizontalScrollbar (catstrs (identifier, ".hsc", 0), parent,
|
||||
x, y + height + EDIT_FRAME_H, width + EDIT_FRAME_W, 12, 0, 0);
|
||||
CSetScrollbarCallback (w->hori_scrollbar->ident, w->ident, link_hscrollbar_to_editor);
|
||||
}
|
||||
if (!(options & EDITOR_NO_TEXT))
|
||||
CDrawStatus (catstrs (identifier, ".text", 0), parent, x, y + height + 3 + EDIT_FRAME_H + WIDGET_SPACING + extra_space_for_hscroll, width + EDIT_FRAME_W, e->filename);
|
||||
if (!(options & EDITOR_NO_SCROLL)) {
|
||||
w->vert_scrollbar = CDrawVerticalScrollbar (catstrs (identifier, ".vsc", 0), parent,
|
||||
x + width + EDIT_FRAME_W + WIDGET_SPACING, y, height + EDIT_FRAME_H, 20, 0, 0);
|
||||
x + width + EDIT_FRAME_W + WIDGET_SPACING, y, height + EDIT_FRAME_H,
|
||||
#ifdef NEXT_LOOK
|
||||
AUTO_WIDTH,
|
||||
#else
|
||||
20,
|
||||
#endif
|
||||
0, 0);
|
||||
CSetScrollbarCallback (w->vert_scrollbar->ident, w->ident, link_scrollbar_to_editor);
|
||||
w->vert_scrollbar->scroll_bar_extra_render = render_book_marks;
|
||||
}
|
||||
set_hint_pos (x + width + EDIT_FRAME_W + WIDGET_SPACING, y + height + EDIT_FRAME_H + WIDGET_SPACING + extra_space_for_hscroll);
|
||||
if (extra_space_for_hscroll) {
|
||||
w->hori_scrollbar = CDrawHorizontalScrollbar (catstrs (identifier, ".hsc", 0), parent,
|
||||
x, y + height + EDIT_FRAME_H, width + EDIT_FRAME_W,
|
||||
#ifdef NEXT_LOOK
|
||||
AUTO_HEIGHT,
|
||||
#else
|
||||
12,
|
||||
#endif
|
||||
0, 0);
|
||||
CSetScrollbarCallback (w->hori_scrollbar->ident, w->ident, link_hscrollbar_to_editor);
|
||||
}
|
||||
CGetHintPos (0, &y);
|
||||
if (!(options & EDITOR_NO_TEXT)) {
|
||||
CPushFont ("widget", 0);
|
||||
#ifdef NEXT_LOOK
|
||||
CDrawStatus (catstrs (identifier, ".text", 0), parent, x, y + WIDGET_SPACING + NEXT_SPACING, width + EDIT_FRAME_W, e->filename);
|
||||
#else
|
||||
CDrawStatus (catstrs (identifier, ".text", 0), parent, x, y, width + EDIT_FRAME_W, e->filename);
|
||||
#endif
|
||||
CPopFont ();
|
||||
}
|
||||
CPopFont ();
|
||||
return w;
|
||||
}
|
||||
|
||||
@ -362,7 +391,7 @@ static void render_book_marks (CWidget * w)
|
||||
for (p = edit->book_mark; p->next; p = p->next);
|
||||
for (; p->prev; p = p->prev) {
|
||||
int y = (CWidthOf (w) + 2 * CWidthOf (w) / 3 + 4) + (int) ((double) l * p->line / edit->total_lines);
|
||||
CSetColor (color_palette (p->c & 0xFF));
|
||||
CSetColor (color_palette (((p->c & 0xFF00) >> 8) ? ((p->c & 0xFF00) >> 8) : (p->c & 0xFF)));
|
||||
CLine (CWindowOf (w), 5, y, CWidthOf (w) - 6, y);
|
||||
}
|
||||
}
|
||||
@ -371,6 +400,7 @@ void update_scroll_bars (WEdit * e)
|
||||
{
|
||||
int i, x1, x2;
|
||||
CWidget *scroll;
|
||||
CPushFont ("editor", 0);
|
||||
scroll = e->widget->vert_scrollbar;
|
||||
if (scroll) {
|
||||
i = e->total_lines - e->start_line + 1;
|
||||
@ -406,10 +436,12 @@ void update_scroll_bars (WEdit * e)
|
||||
EditExposeRedraw = 0;
|
||||
}
|
||||
}
|
||||
CPopFont ();
|
||||
}
|
||||
|
||||
void edit_mouse_mark (WEdit * edit, XEvent * event, int double_click)
|
||||
{
|
||||
CPushFont ("editor", 0);
|
||||
edit_update_curs_row (edit);
|
||||
edit_update_curs_col (edit);
|
||||
if (event->type != MotionNotify) {
|
||||
@ -422,10 +454,11 @@ void edit_mouse_mark (WEdit * edit, XEvent * event, int double_click)
|
||||
edit->found_len = 0;
|
||||
}
|
||||
mouse_mark (
|
||||
event,
|
||||
double_click,
|
||||
edit->widget->funcs
|
||||
);
|
||||
event,
|
||||
double_click,
|
||||
edit->widget->funcs
|
||||
);
|
||||
CPopFont ();
|
||||
}
|
||||
|
||||
void link_scrollbar_to_editor (CWidget * scrollbar, CWidget * editor, XEvent * xevent, CEvent * cwevent, int whichscrbutton)
|
||||
@ -437,6 +470,7 @@ void link_scrollbar_to_editor (CWidget * scrollbar, CWidget * editor, XEvent * x
|
||||
return;
|
||||
if (!e->widget->vert_scrollbar)
|
||||
return;
|
||||
CPushFont ("editor", 0);
|
||||
start_line = e->start_line;
|
||||
if ((xevent->type == ButtonRelease || xevent->type == MotionNotify) && whichscrbutton == 3) {
|
||||
edit_move_display (e, (double) scrollbar->firstline * e->total_lines / 65535.0 + 1);
|
||||
@ -470,13 +504,16 @@ void link_scrollbar_to_editor (CWidget * scrollbar, CWidget * editor, XEvent * x
|
||||
if (start_line != e->start_line) {
|
||||
e->force |= REDRAW_PAGE | REDRAW_LINE;
|
||||
set_cursor_position (0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
if (CCheckWindowEvent (xevent->xany.window, ButtonReleaseMask | ButtonMotionMask, 0))
|
||||
if (CCheckWindowEvent (xevent->xany.window, ButtonReleaseMask | ButtonMotionMask, 0)) {
|
||||
CPopFont ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e->force) {
|
||||
edit_render_keypress (e);
|
||||
edit_status (e);
|
||||
}
|
||||
CPopFont ();
|
||||
}
|
||||
|
||||
void link_hscrollbar_to_editor (CWidget * scrollbar, CWidget * editor, XEvent * xevent, CEvent * cwevent, int whichscrbutton)
|
||||
@ -488,6 +525,7 @@ void link_hscrollbar_to_editor (CWidget * scrollbar, CWidget * editor, XEvent *
|
||||
return;
|
||||
if (!e->widget->hori_scrollbar)
|
||||
return;
|
||||
CPushFont ("editor", 0);
|
||||
start_col = (-e->start_col);
|
||||
if ((xevent->type == ButtonRelease || xevent->type == MotionNotify) && whichscrbutton == 3) {
|
||||
e->start_col = (double) scrollbar->firstline * e->max_column / 65535.0 + 1;
|
||||
@ -519,13 +557,16 @@ void link_hscrollbar_to_editor (CWidget * scrollbar, CWidget * editor, XEvent *
|
||||
if (start_col != (-e->start_col)) {
|
||||
e->force |= REDRAW_PAGE | REDRAW_LINE;
|
||||
set_cursor_position (0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
if (CCheckWindowEvent (xevent->xany.window, ButtonReleaseMask | ButtonMotionMask, 0))
|
||||
if (CCheckWindowEvent (xevent->xany.window, ButtonReleaseMask | ButtonMotionMask, 0)) {
|
||||
CPopFont ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e->force) {
|
||||
edit_render_keypress (e);
|
||||
edit_status (e);
|
||||
}
|
||||
CPopFont ();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -559,7 +600,7 @@ void selection_send (XSelectionRequestEvent * rq)
|
||||
* XXX: yes, but Xlib requires that you pass it 64 bits for 32bit
|
||||
* quantities on 64 bit archs.
|
||||
*/
|
||||
/* typedef CARD32 Atom32; */
|
||||
/* typedef CARD32 Atom32; */
|
||||
|
||||
Atom target_list[2];
|
||||
|
||||
@ -641,6 +682,7 @@ void edit_update_screen (WEdit * e)
|
||||
if (!e->force)
|
||||
return;
|
||||
|
||||
CPushFont ("editor", 0);
|
||||
edit_scroll_screen_over_cursor (e);
|
||||
edit_update_curs_row (e);
|
||||
edit_update_curs_col (e);
|
||||
@ -656,10 +698,12 @@ void edit_update_screen (WEdit * e)
|
||||
} else if (CCheckWindowEvent (e->widget->winid, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, 0)
|
||||
|| CKeyPending ()) {
|
||||
e->force |= REDRAW_PAGE;
|
||||
CPopFont ();
|
||||
return;
|
||||
} else {
|
||||
edit_render_keypress (e);
|
||||
}
|
||||
CPopFont ();
|
||||
}
|
||||
|
||||
extern int space_width;
|
||||
@ -959,11 +1003,10 @@ int edit (const char *_file, int line)
|
||||
char *text = 0;
|
||||
|
||||
if (option_backup_ext_int != -1) {
|
||||
option_backup_ext = malloc (sizeof(int) + 1);
|
||||
option_backup_ext[sizeof(int)] = '\0';
|
||||
option_backup_ext = malloc (sizeof (int) + 1);
|
||||
option_backup_ext[sizeof (int)] = '\0';
|
||||
memcpy (option_backup_ext, (char *) &option_backup_ext_int, sizeof (int));
|
||||
}
|
||||
|
||||
if (!made_directory) {
|
||||
mkdir (catstrs (home_dir, EDIT_DIR, 0), 0700);
|
||||
made_directory = 1;
|
||||
@ -977,7 +1020,7 @@ int edit (const char *_file, int line)
|
||||
text = "";
|
||||
|
||||
if (!(wedit = edit_init (NULL, LINES - 2, COLS, _file, text, "", 0))) {
|
||||
message (1, _(" Error "), get_error_msg (""));
|
||||
message (1, _ (" Error "), get_error_msg (""));
|
||||
return 0;
|
||||
}
|
||||
wedit->macro_i = -1;
|
||||
@ -1090,17 +1133,17 @@ void edit_labels (WEdit * edit)
|
||||
{
|
||||
Dlg_head *h = edit->widget.parent;
|
||||
|
||||
edit_my_define (h, 1, _("Help"), cmd_F1, edit);
|
||||
edit_my_define (h, 2, _("Save"), cmd_F2, edit);
|
||||
edit_my_define (h, 3, _("Mark"), cmd_F3, edit);
|
||||
edit_my_define (h, 4, _("Replac"), cmd_F4, edit);
|
||||
edit_my_define (h, 5, _("Copy"), cmd_F5, edit);
|
||||
edit_my_define (h, 6, _("Move"), cmd_F6, edit);
|
||||
edit_my_define (h, 7, _("Search"), cmd_F7, edit);
|
||||
edit_my_define (h, 8, _("Delete"), cmd_F8, edit);
|
||||
edit_my_define (h, 1, _ ("Help"), cmd_F1, edit);
|
||||
edit_my_define (h, 2, _ ("Save"), cmd_F2, edit);
|
||||
edit_my_define (h, 3, _ ("Mark"), cmd_F3, edit);
|
||||
edit_my_define (h, 4, _ ("Replac"), cmd_F4, edit);
|
||||
edit_my_define (h, 5, _ ("Copy"), cmd_F5, edit);
|
||||
edit_my_define (h, 6, _ ("Move"), cmd_F6, edit);
|
||||
edit_my_define (h, 7, _ ("Search"), cmd_F7, edit);
|
||||
edit_my_define (h, 8, _ ("Delete"), cmd_F8, edit);
|
||||
if (!edit->have_frame)
|
||||
edit_my_define (h, 9, _("PullDn"), edit_menu_cmd, edit);
|
||||
edit_my_define (h, 10, _("Quit"), cmd_F10, edit);
|
||||
edit_my_define (h, 9, _ ("PullDn"), edit_menu_cmd, edit);
|
||||
edit_my_define (h, 10, _ ("Quit"), cmd_F10, edit);
|
||||
|
||||
redraw_labels (h, (Widget *) edit);
|
||||
}
|
||||
@ -1123,7 +1166,7 @@ void edit_adjust_size (Dlg_head * h)
|
||||
widget_set_size (&edit_menubar->widget, 0, 0, 1, COLS);
|
||||
|
||||
#ifdef RESIZABLE_MENUBAR
|
||||
menubar_arrange(edit_menubar);
|
||||
menubar_arrange (edit_menubar);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,6 @@ struct cache_line {
|
||||
cache_type data[CACHE_WIDTH];
|
||||
};
|
||||
|
||||
extern unsigned char per_char[256];
|
||||
|
||||
/* background colors: marked is refers to mouse highlighting, highlighted refers to a found string. */
|
||||
extern unsigned long edit_abnormal_color, edit_marked_abnormal_color;
|
||||
@ -117,54 +116,54 @@ static inline int convert_to_long_printable (int c, unsigned char *t)
|
||||
if (isgraph (c)) {
|
||||
t[0] = c;
|
||||
t[1] = 0;
|
||||
return per_char[c];
|
||||
return FONT_PER_CHAR[c];
|
||||
}
|
||||
if (c == ' ') {
|
||||
if (option_long_whitespace) {
|
||||
t[0] = ' ';
|
||||
t[1] = ' ';
|
||||
t[2] = 0;
|
||||
return per_char[' '] + per_char[' '];
|
||||
return FONT_PER_CHAR[' '] + FONT_PER_CHAR[' '];
|
||||
} else {
|
||||
t[0] = ' ';
|
||||
t[1] = 0;
|
||||
return per_char[' '];
|
||||
return FONT_PER_CHAR[' '];
|
||||
}
|
||||
}
|
||||
if (option_international_characters && per_char[c]) {
|
||||
if (option_international_characters && FONT_PER_CHAR[c]) {
|
||||
t[0] = c;
|
||||
t[1] = 0;
|
||||
return per_char[c];
|
||||
return FONT_PER_CHAR[c];
|
||||
}
|
||||
if (c > '~') {
|
||||
t[0] = ("0123456789ABCDEF")[c >> 4];
|
||||
t[1] = ("0123456789ABCDEF")[c & 0xF];
|
||||
t[2] = 'h';
|
||||
t[3] = 0;
|
||||
return per_char[t[0]] + per_char[t[1]] + per_char[t[2]];
|
||||
return FONT_PER_CHAR[t[0]] + FONT_PER_CHAR[t[1]] + FONT_PER_CHAR[t[2]];
|
||||
}
|
||||
t[0] = '^';
|
||||
t[1] = c + '@';
|
||||
t[2] = 0;
|
||||
return per_char[t[0]] + per_char[t[1]];
|
||||
return FONT_PER_CHAR[t[0]] + FONT_PER_CHAR[t[1]];
|
||||
}
|
||||
|
||||
/* same as above but just gets the length */
|
||||
static inline int width_of_long_printable (int c)
|
||||
{
|
||||
if (isgraph (c))
|
||||
return per_char[c];
|
||||
return FONT_PER_CHAR[c];
|
||||
if (c == ' ') {
|
||||
if (option_long_whitespace)
|
||||
return per_char[' '] + per_char[' '];
|
||||
return FONT_PER_CHAR[' '] + FONT_PER_CHAR[' '];
|
||||
else
|
||||
return per_char[' '];
|
||||
return FONT_PER_CHAR[' '];
|
||||
}
|
||||
if (option_international_characters && per_char[c])
|
||||
return per_char[c];
|
||||
if (option_international_characters && FONT_PER_CHAR[c])
|
||||
return FONT_PER_CHAR[c];
|
||||
if (c > '~')
|
||||
return per_char[(unsigned char) ("0123456789ABCDEF")[c >> 4]] + per_char[(unsigned char) ("0123456789ABCDEF")[c & 0xF]] + per_char[(unsigned char) 'h'];
|
||||
return per_char['^'] + per_char[c + '@'];
|
||||
return FONT_PER_CHAR[(unsigned char) ("0123456789ABCDEF")[c >> 4]] + FONT_PER_CHAR[(unsigned char) ("0123456789ABCDEF")[c & 0xF]] + FONT_PER_CHAR[(unsigned char) 'h'];
|
||||
return FONT_PER_CHAR['^'] + FONT_PER_CHAR[c + '@'];
|
||||
}
|
||||
|
||||
int edit_width_of_long_printable (int c)
|
||||
@ -173,7 +172,7 @@ int edit_width_of_long_printable (int c)
|
||||
}
|
||||
|
||||
/* returns x pixel pos of char at offset *q with x not more than l */
|
||||
int calc_text_pos (WEdit * edit, long b, long *q, int l)
|
||||
static int calc_text_pos (WEdit * edit, long b, long *q, int l)
|
||||
{
|
||||
int x = 0, c, xn;
|
||||
for (;;) {
|
||||
@ -204,7 +203,7 @@ int calc_text_pos (WEdit * edit, long b, long *q, int l)
|
||||
|
||||
|
||||
/* calcs pixel length of the line beginning at b up to upto */
|
||||
int calc_text_len (WEdit * edit, long b, long upto)
|
||||
static int calc_text_len (WEdit * edit, long b, long upto)
|
||||
{
|
||||
int x = 0, c;
|
||||
for (;;) {
|
||||
@ -235,13 +234,15 @@ int calc_text_len (WEdit * edit, long b, long upto)
|
||||
/* If upto is zero returns index of pixels across from current. */
|
||||
long edit_move_forward3 (WEdit * edit, long current, int pixels, long upto)
|
||||
{
|
||||
CPushFont ("editor", 0);
|
||||
if (upto) {
|
||||
return calc_text_len (edit, current, upto);
|
||||
current = calc_text_len (edit, current, upto);
|
||||
} else if (pixels) {
|
||||
long q;
|
||||
calc_text_pos (edit, current, &q, pixels);
|
||||
return q;
|
||||
current = q;
|
||||
}
|
||||
CPopFont ();
|
||||
return current;
|
||||
}
|
||||
|
||||
@ -252,7 +253,7 @@ static inline cache_type get_style_fast (WEdit * edit, long q, int c)
|
||||
{
|
||||
cache_type s = 0;
|
||||
unsigned int fg, bg;
|
||||
if (!(isprint (c) || (option_international_characters && per_char[c])))
|
||||
if (!(isprint (c) || (option_international_characters && FONT_PER_CHAR[c])))
|
||||
if (c != '\n' && c != '\t')
|
||||
s |= MOD_ABNORMAL * 256;
|
||||
edit_get_syntax_color (edit, q, (int *) &fg, (int *) &bg);
|
||||
@ -279,14 +280,14 @@ static inline cache_type get_style (WEdit * edit, long q, int c, long m1, long m
|
||||
s |= MOD_BOLD * 256;
|
||||
if (q >= edit->found_start && q < edit->found_start + edit->found_len)
|
||||
s |= MOD_HIGHLIGHTED * 256;
|
||||
if (!(isprint (c) || (option_international_characters && per_char[c])))
|
||||
if (!(isprint (c) || (option_international_characters && FONT_PER_CHAR[c])))
|
||||
if (c != '\n' && c != '\t')
|
||||
s |= MOD_ABNORMAL * 256;
|
||||
edit_get_syntax_color (edit, q, (int *) &fg, (int *) &bg);
|
||||
return s | ((fg & 0xFF) << 24) | ((bg & 0xFF) << 16);
|
||||
}
|
||||
|
||||
void convert_text (WEdit * edit, long q, cache_type * p, int x, int x_max, int row)
|
||||
static void convert_text (WEdit * edit, long q, cache_type * p, int x, int x_max, int row)
|
||||
{
|
||||
int c;
|
||||
cache_type s;
|
||||
@ -315,13 +316,13 @@ void convert_text (WEdit * edit, long q, cache_type * p, int x, int x_max, int r
|
||||
q--;
|
||||
goto the_default;
|
||||
case '\t':
|
||||
if (fixed_font) {
|
||||
if (FIXED_FONT) {
|
||||
int t;
|
||||
t = next_tab_pos (x);
|
||||
t = min (t, x_max);
|
||||
s = *p;
|
||||
while (x < t) {
|
||||
x += per_char[' '];
|
||||
x += FONT_PER_CHAR[' '];
|
||||
*p++ = s | ' ';
|
||||
}
|
||||
} else {
|
||||
@ -361,13 +362,13 @@ void convert_text (WEdit * edit, long q, cache_type * p, int x, int x_max, int r
|
||||
edit->max_column = x;
|
||||
return;
|
||||
case '\t':
|
||||
if (fixed_font) {
|
||||
if (FIXED_FONT) {
|
||||
int t;
|
||||
t = next_tab_pos (x);
|
||||
t = min (t, x_max);
|
||||
s = *p;
|
||||
while (x < t) {
|
||||
x += per_char[' '];
|
||||
x += FONT_PER_CHAR[' '];
|
||||
*p++ = s | ' ';
|
||||
}
|
||||
} else {
|
||||
@ -404,13 +405,13 @@ void convert_text (WEdit * edit, long q, cache_type * p, int x, int x_max, int r
|
||||
edit->max_column = x;
|
||||
return;
|
||||
case '\t':
|
||||
if (fixed_font) {
|
||||
if (FIXED_FONT) {
|
||||
int t;
|
||||
t = next_tab_pos (x);
|
||||
t = min (t, x_max);
|
||||
s = *p;
|
||||
while (x < t) {
|
||||
x += per_char[' '];
|
||||
x += FONT_PER_CHAR[' '];
|
||||
*p++ = s | ' ';
|
||||
}
|
||||
} else {
|
||||
@ -461,7 +462,7 @@ static inline int next_tab (int x, int scroll_right)
|
||||
return next_tab_pos (x - scroll_right - EDIT_TEXT_HORIZONTAL_OFFSET) - x + scroll_right + EDIT_TEXT_HORIZONTAL_OFFSET;
|
||||
}
|
||||
|
||||
int draw_tab (Window win, int x, int y, cache_type s, int scroll_right)
|
||||
static int draw_tab (Window win, int x, int y, cache_type s, int scroll_right)
|
||||
{
|
||||
int l;
|
||||
#ifdef GTK
|
||||
@ -476,14 +477,14 @@ int draw_tab (Window win, int x, int y, cache_type s, int scroll_right)
|
||||
gdk_draw_rectangle (win->text_area, win->gc, 1, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
|
||||
/* if we printed a cursor: */
|
||||
if (s & (MOD_CURSOR * 256))
|
||||
edit_set_cursor (win, x, y, bg.pixel, fg.pixel, per_char[' '], ' ');
|
||||
edit_set_cursor (win, x, y, bg.pixel, fg.pixel, FONT_PER_CHAR[' '], ' ');
|
||||
#else
|
||||
set_style_color (s, &fg, &bg);
|
||||
CSetColor (bg);
|
||||
CRectangle (win, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
|
||||
/* if we printed a cursor: */
|
||||
if (s & (MOD_CURSOR * 256))
|
||||
edit_set_cursor (win, x, y, bg, fg, per_char[' '], ' ');
|
||||
edit_set_cursor (win, x, y, bg, fg, FONT_PER_CHAR[' '], ' ');
|
||||
#endif
|
||||
return x + l;
|
||||
}
|
||||
@ -509,7 +510,7 @@ static inline void draw_space (Window win, int x, int y, cache_type s, int l)
|
||||
CRectangle (win, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
|
||||
/* if we printed a cursor: */
|
||||
if (s & (MOD_CURSOR * 256))
|
||||
edit_set_cursor (win, x, y, bg, fg, per_char[' '], ' ');
|
||||
edit_set_cursor (win, x, y, bg, fg, FONT_PER_CHAR[' '], ' ');
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -567,7 +568,7 @@ gdk_draw_image_text (GdkDrawable *drawable,
|
||||
|
||||
#endif
|
||||
|
||||
int draw_string (Window win, int x, int y, cache_type s, unsigned char *text, int length)
|
||||
static int draw_string (Window win, int x, int y, cache_type s, unsigned char *text, int length)
|
||||
{
|
||||
#ifdef GTK
|
||||
GdkColor fg, bg;
|
||||
@ -584,8 +585,8 @@ int draw_string (Window win, int x, int y, cache_type s, unsigned char *text, in
|
||||
underlined = set_style_color (s, &fg, &bg);
|
||||
CSetBackgroundColor (bg);
|
||||
CSetColor (fg);
|
||||
CImageString (win, x + FONT_OFFSET_X, y + FONT_OFFSET_Y, (char *) text, length);
|
||||
l = CTextWidth (win, (char *) text, length);
|
||||
CImageText (win, x + FONT_OFFSET_X, y + FONT_OFFSET_Y, (char *) text, length);
|
||||
l = CTextWidth ((char *) text, length);
|
||||
if (underlined) {
|
||||
int i, h, inc;
|
||||
inc = FONT_MEAN_WIDTH * 2 / 3;
|
||||
@ -602,11 +603,11 @@ int draw_string (Window win, int x, int y, cache_type s, unsigned char *text, in
|
||||
/* if we printed a cursor: */
|
||||
#ifdef GTK
|
||||
if (s & (MOD_CURSOR * 256))
|
||||
edit_set_cursor (win, x, y, bg.pixel, fg.pixel, per_char[*text], *text);
|
||||
edit_set_cursor (win, x, y, bg.pixel, fg.pixel, FONT_PER_CHAR[*text], *text);
|
||||
return x + gdk_text_width (GTK_WIDGET (win)->style->font, text, length);
|
||||
#else
|
||||
if (s & (MOD_CURSOR * 256))
|
||||
edit_set_cursor (win, x, y, bg, fg, per_char[*text], *text);
|
||||
edit_set_cursor (win, x, y, bg, fg, FONT_PER_CHAR[*text], *text);
|
||||
return x + l;
|
||||
#endif
|
||||
}
|
||||
@ -669,7 +670,7 @@ static void cover_trail (Window win, int x_start, int x_new, int x_old, int y)
|
||||
gdk_draw_rectangle (win->text_area, win->gc, 1, x_new, y + FONT_OVERHEAD, x_old - x_new, FONT_HEIGHT);
|
||||
#else
|
||||
CSetColor (edit_normal_background_color);
|
||||
CRectangle (win, x_new, y + FONT_OVERHEAD, x_old - x_new, FONT_HEIGHT + (FONT_OVERHEAD != 0 && !fixed_font));
|
||||
CRectangle (win, x_new, y + FONT_OVERHEAD, x_old - x_new, FONT_HEIGHT + (FONT_OVERHEAD != 0 && !FIXED_FONT));
|
||||
#endif
|
||||
} else {
|
||||
#ifdef GTK
|
||||
@ -679,7 +680,7 @@ static void cover_trail (Window win, int x_start, int x_new, int x_old, int y)
|
||||
#endif
|
||||
}
|
||||
/* true type fonts print stuff out of the bounding box (aaaaaaaaarrrgh!!) */
|
||||
if (!fixed_font)
|
||||
if (!FIXED_FONT)
|
||||
if (FONT_OVERHEAD && x_new > EDIT_TEXT_HORIZONTAL_OFFSET)
|
||||
#ifdef GTK
|
||||
gdk_draw_line (win->text_area, win->gc, max (x_start, EDIT_TEXT_HORIZONTAL_OFFSET), y + FONT_HEIGHT + FONT_OVERHEAD, x_new - 1, y + FONT_HEIGHT + FONT_OVERHEAD);
|
||||
@ -718,13 +719,16 @@ void edit_draw_proportional (void *data,
|
||||
x_max -= 3;
|
||||
|
||||
/* if its not the same window, reset the screen rememberer */
|
||||
if (last != win) {
|
||||
if (last != win || !win) {
|
||||
last = win;
|
||||
for (i = 0; i < CACHE_HEIGHT; i++) {
|
||||
lines[i].x0 = NOT_VALID;
|
||||
lines[i].x1 = x_max;
|
||||
}
|
||||
if (!win)
|
||||
return;
|
||||
}
|
||||
|
||||
/* get point to start drawing */
|
||||
x0 = (*calctextpos) (data, b, &q, -scroll_right + x_offset);
|
||||
/* q contains the offset in the edit buffer */
|
||||
@ -740,7 +744,7 @@ void edit_draw_proportional (void *data,
|
||||
if (!EditExposeRedraw) {
|
||||
if (lines[row].x0 == x0 && row < CACHE_HEIGHT) { /* i.e. also && lines[row].x0 != NOT_VALID */
|
||||
ignore_text = get_ignore_length (lines[row].data, line);
|
||||
if (fixed_font)
|
||||
if (FIXED_FONT)
|
||||
ignore_trailer = get_ignore_trailer (lines[row].data, line, ignore_text);
|
||||
}
|
||||
}
|
||||
@ -790,7 +794,7 @@ void edit_draw_proportional (void *data,
|
||||
#ifdef GTK
|
||||
x += gdk_text_width (GTK_WIDGET(win)->style->font, text, i);
|
||||
#else
|
||||
x += CTextWidth (win, (char *) text, i);
|
||||
x += CTextWidth ((char *) text, i);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -833,7 +837,7 @@ void edit_draw_this_line_proportional (WEdit * edit, long b, int row, int start_
|
||||
(int (*) (void *, long, long *, int)) calc_text_pos,
|
||||
edit->start_col, CWindowOf (edit->widget),
|
||||
end_column, b, row, row * FONT_PIX_PER_LINE + EDIT_TEXT_VERTICAL_OFFSET,
|
||||
EditExposeRedraw ? start_column : 0, per_char[' '] * TAB_SIZE);
|
||||
EditExposeRedraw ? start_column : 0, FONT_PER_CHAR[' '] * TAB_SIZE);
|
||||
}
|
||||
|
||||
|
||||
@ -847,7 +851,7 @@ static inline int nroff_printable (int c)
|
||||
}
|
||||
|
||||
|
||||
int calc_text_pos_str (unsigned char *text, long b, long *q, int l)
|
||||
static int calc_text_pos_str (unsigned char *text, long b, long *q, int l)
|
||||
{
|
||||
int x = 0, c = 0, xn = 0, d;
|
||||
for (;;) {
|
||||
@ -865,12 +869,12 @@ int calc_text_pos_str (unsigned char *text, long b, long *q, int l)
|
||||
break;
|
||||
case '\b':
|
||||
if (d)
|
||||
xn = x - per_char[d];
|
||||
xn = x - FONT_PER_CHAR[d];
|
||||
break;
|
||||
default:
|
||||
if (!nroff_printable (c))
|
||||
c = ' ';
|
||||
xn = x + per_char[c];
|
||||
xn = x + FONT_PER_CHAR[c];
|
||||
break;
|
||||
}
|
||||
if (xn > l)
|
||||
@ -885,7 +889,9 @@ int calc_text_pos_str (unsigned char *text, long b, long *q, int l)
|
||||
int prop_font_strcolmove (unsigned char *str, int i, int column)
|
||||
{
|
||||
long q;
|
||||
CPushFont ("editor", 0);
|
||||
calc_text_pos_str (str, i, &q, column * FONT_MEAN_WIDTH);
|
||||
CPopFont ();
|
||||
return q;
|
||||
}
|
||||
|
||||
@ -896,42 +902,13 @@ int prop_font_strcolmove (unsigned char *str, int i, int column)
|
||||
*q and the characters pixel x pos from b is return'ed. */
|
||||
int calc_text_pos2 (CWidget * w, long b, long *q, int l)
|
||||
{
|
||||
return calc_text_pos_str ((unsigned char *) w->text, b, q, l);
|
||||
int r;
|
||||
CPushFont ("editor", 0);
|
||||
r = calc_text_pos_str ((unsigned char *) w->text, b, q, l);
|
||||
CPopFont ();
|
||||
return r;
|
||||
}
|
||||
|
||||
/* calcs pixel length of the line beginning at b up to upto */
|
||||
int calc_text_len2 (CWidget *w, long b, long upto)
|
||||
{
|
||||
int x = 0, c = 0, d;
|
||||
for (;;) {
|
||||
if (b == upto)
|
||||
return x;
|
||||
d = c;
|
||||
c = w->text[b];
|
||||
switch (c) {
|
||||
case '\n':
|
||||
case '\0':
|
||||
return x;
|
||||
case '\t':
|
||||
x = next_tab_pos (x);
|
||||
break;
|
||||
case '\r':
|
||||
break;
|
||||
case '\b':
|
||||
if (d)
|
||||
x -= per_char[d];
|
||||
break;
|
||||
default:
|
||||
if (!nroff_printable (c))
|
||||
c = ' ';
|
||||
x += per_char[c];
|
||||
break;
|
||||
}
|
||||
b++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int highlight_this_line;
|
||||
|
||||
/* this is for the text widget (i.e. nroff formatting) */
|
||||
@ -961,18 +938,18 @@ void convert_text2 (CWidget * w, long q, cache_type *line, int x, int x_max, int
|
||||
*p++ |= ' ';
|
||||
if (highlight_this_line) {
|
||||
q--;
|
||||
x += per_char[' '];
|
||||
x += FONT_PER_CHAR[' '];
|
||||
} else
|
||||
return;
|
||||
break;
|
||||
case '\t':
|
||||
if (fixed_font) {
|
||||
if (FIXED_FONT) {
|
||||
int i;
|
||||
i = next_tab_pos (x) - x;
|
||||
x += i;
|
||||
s = *p;
|
||||
while (i > 0) {
|
||||
i -= per_char[' '];
|
||||
i -= FONT_PER_CHAR[' '];
|
||||
*p++ = s | ' ';
|
||||
*p = 0;
|
||||
}
|
||||
@ -986,7 +963,7 @@ void convert_text2 (CWidget * w, long q, cache_type *line, int x, int x_max, int
|
||||
case '\b':
|
||||
if (d) {
|
||||
--p;
|
||||
x -= per_char[d];
|
||||
x -= FONT_PER_CHAR[d];
|
||||
if (d == '_')
|
||||
*p |= MOD_ITALIC * 256;
|
||||
else
|
||||
@ -998,7 +975,7 @@ void convert_text2 (CWidget * w, long q, cache_type *line, int x, int x_max, int
|
||||
c = ' ';
|
||||
*p |= MOD_ABNORMAL * 256;
|
||||
}
|
||||
x += per_char[c];
|
||||
x += FONT_PER_CHAR[c];
|
||||
*p &= 0xFFFFFF00UL;
|
||||
*p |= c;
|
||||
p++;
|
||||
|
182
gtkedit/syntax.c
182
gtkedit/syntax.c
@ -55,10 +55,19 @@ void edit_load_syntax (WEdit * edit, char **names, char *type);
|
||||
void edit_free_syntax_rules (WEdit * edit);
|
||||
void edit_get_syntax_color (WEdit * edit, long byte_index, int *fg, int *bg);
|
||||
|
||||
#ifdef HAVE_MAD
|
||||
static void *mad_syntax_malloc (size_t x, char *file, int line)
|
||||
#define syntax_malloc(x) mad_syntax_malloc (x, __FILE__, __LINE__)
|
||||
#else
|
||||
static void *syntax_malloc (size_t x)
|
||||
#endif
|
||||
{
|
||||
void *p;
|
||||
#ifdef HAVE_MAD
|
||||
p = mad_alloc (x, file, line);
|
||||
#else
|
||||
p = malloc (x);
|
||||
#endif
|
||||
memset (p, 0, x);
|
||||
return p;
|
||||
}
|
||||
@ -327,7 +336,7 @@ static struct syntax_rule edit_get_rule (WEdit * edit, long byte_index)
|
||||
if (i > (edit->syntax_marker ? edit->syntax_marker->offset + SYNTAX_MARKER_DENSITY : SYNTAX_MARKER_DENSITY)) {
|
||||
struct _syntax_marker *s;
|
||||
s = edit->syntax_marker;
|
||||
edit->syntax_marker = malloc (sizeof (struct _syntax_marker));
|
||||
edit->syntax_marker = syntax_malloc (sizeof (struct _syntax_marker));
|
||||
edit->syntax_marker->next = s;
|
||||
edit->syntax_marker->offset = i;
|
||||
edit->syntax_marker->rule = edit->rule;
|
||||
@ -384,11 +393,20 @@ void edit_get_syntax_color (WEdit * edit, long byte_index, int *fg, int *bg)
|
||||
Returns 0 on error/eof or a count of the number of bytes read
|
||||
including the newline. Result must be free'd.
|
||||
*/
|
||||
#ifdef HAVE_MAD
|
||||
static int mad_read_one_line (char **line, FILE * f, char *file, int line_)
|
||||
#define read_one_line(a,b) mad_read_one_line(a,b,__FILE__,__LINE__)
|
||||
#else
|
||||
static int read_one_line (char **line, FILE * f)
|
||||
#endif
|
||||
{
|
||||
char *p;
|
||||
int len = 256, c, r = 0, i = 0;
|
||||
#ifdef HAVE_MAD
|
||||
p = mad_syntax_malloc (len, file, line_);
|
||||
#else
|
||||
p = syntax_malloc (len);
|
||||
#endif
|
||||
for (;;) {
|
||||
c = fgetc (f);
|
||||
if (c == -1) {
|
||||
@ -631,7 +649,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
|
||||
line = save_line + 1;
|
||||
syntax_free (error_file_name);
|
||||
if (l)
|
||||
free (l);
|
||||
syntax_free (l);
|
||||
if (!read_one_line (&l, f))
|
||||
break;
|
||||
} else {
|
||||
@ -828,7 +846,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
|
||||
for (j = 1; c->keyword[j]; j++)
|
||||
*p++ = c->keyword[j]->first;
|
||||
*p = '\0';
|
||||
c->keyword_first_chars = malloc (strlen (first_chars) + 2);
|
||||
c->keyword_first_chars = syntax_malloc (strlen (first_chars) + 2);
|
||||
strcpy (c->keyword_first_chars, first_chars);
|
||||
}
|
||||
}
|
||||
@ -843,7 +861,7 @@ static char *strdupc (char *s, int c)
|
||||
{
|
||||
char *t;
|
||||
int l;
|
||||
strcpy (t = malloc ((l = strlen (s)) + 3), s);
|
||||
strcpy (t = syntax_malloc ((l = strlen (s)) + 3), s);
|
||||
t[l] = c;
|
||||
t[l + 1] = '\0';
|
||||
return t;
|
||||
@ -860,11 +878,11 @@ static void edit_syntax_clear_keyword (WEdit * edit, int context, int j)
|
||||
s->rule.keyword = 0;
|
||||
else if (s->rule.keyword > j)
|
||||
s->rule.keyword--;
|
||||
free (c->keyword[j]->keyword);
|
||||
free (c->keyword[j]->whole_word_chars_left);
|
||||
free (c->keyword[j]->whole_word_chars_right);
|
||||
free (c->keyword[j]);
|
||||
memcpy (&c->keyword[j], &c->keyword[j + 1], (MAX_WORDS_PER_CONTEXT - j) * sizeof (struct keyword *));
|
||||
syntax_free (c->keyword[j]->keyword);
|
||||
syntax_free (c->keyword[j]->whole_word_chars_left);
|
||||
syntax_free (c->keyword[j]->whole_word_chars_right);
|
||||
syntax_free (c->keyword[j]);
|
||||
memcpy (&c->keyword[j], &c->keyword[j + 1], (MAX_WORDS_PER_CONTEXT - j - 1) * sizeof (struct keyword *));
|
||||
strcpy (&c->keyword_first_chars[j], &c->keyword_first_chars[j + 1]);
|
||||
}
|
||||
|
||||
@ -893,7 +911,7 @@ static int edit_syntax_add_keyword (WEdit * edit, char *keyword, int context, ti
|
||||
}
|
||||
}
|
||||
/* are we out of space? */
|
||||
if (j >= MAX_WORDS_PER_CONTEXT - 1)
|
||||
if (j >= MAX_WORDS_PER_CONTEXT - 2)
|
||||
return 1;
|
||||
/* add the new keyword and date it */
|
||||
c->keyword[j + 1] = 0;
|
||||
@ -910,7 +928,7 @@ static int edit_syntax_add_keyword (WEdit * edit, char *keyword, int context, ti
|
||||
c->keyword[j]->whole_word_chars_right = (char *) strdup ("-'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ¡¢£¤¥¦§§¨©©ª«¬®®¯°±²³´µ¶¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ");
|
||||
c->keyword[j]->time = t;
|
||||
s = strdupc (c->keyword_first_chars, c->keyword[j]->first);
|
||||
free (c->keyword_first_chars);
|
||||
syntax_free (c->keyword_first_chars);
|
||||
c->keyword_first_chars = s;
|
||||
return 0;
|
||||
}
|
||||
@ -952,12 +970,12 @@ static int edit_check_spelling_at (WEdit * edit, long byte_index)
|
||||
if (p2 <= p1)
|
||||
return 0;
|
||||
/* create string */
|
||||
q = p = malloc (p2 - p1 + 2);
|
||||
q = p = syntax_malloc (p2 - p1 + 2);
|
||||
for (; p1 < p2; p1++)
|
||||
*p++ = edit_get_byte (edit, p1);
|
||||
*p = '\0';
|
||||
if (q[0] == '-' || strlen ((char *) q) > 40) { /* if you are using words over 40 characters, you are on your own */
|
||||
free (q);
|
||||
syntax_free (q);
|
||||
return 0;
|
||||
}
|
||||
time (&t);
|
||||
@ -966,7 +984,7 @@ static int edit_check_spelling_at (WEdit * edit, long byte_index)
|
||||
if (!strcmp (c->keyword[j]->keyword, (char *) q)) {
|
||||
if (c->keyword[j]->time)
|
||||
c->keyword[j]->time = t;
|
||||
free (q);
|
||||
syntax_free (q);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -978,11 +996,11 @@ static int edit_check_spelling_at (WEdit * edit, long byte_index)
|
||||
r = fgetc (spelling_pipe_in);
|
||||
} while (r == -1 && errno == EINTR);
|
||||
if (r == -1) {
|
||||
free (q);
|
||||
syntax_free (q);
|
||||
return 1;
|
||||
}
|
||||
if (r == '\n') { /* ispell sometimes returns just blank line if it is given bad characters */
|
||||
free (q);
|
||||
syntax_free (q);
|
||||
return 0;
|
||||
}
|
||||
/* now read ispell output untill we get two blanks lines - we are not intersted in this part */
|
||||
@ -991,7 +1009,7 @@ static int edit_check_spelling_at (WEdit * edit, long byte_index)
|
||||
} while (c1 == -1 && errno == EINTR);
|
||||
for (;;) {
|
||||
if (c1 == -1) {
|
||||
free (q);
|
||||
syntax_free (q);
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
@ -1003,12 +1021,12 @@ static int edit_check_spelling_at (WEdit * edit, long byte_index)
|
||||
}
|
||||
/* spelled ok */
|
||||
if (r == '*' || r == '+' || r == '-') {
|
||||
free (q);
|
||||
syntax_free (q);
|
||||
return 0;
|
||||
}
|
||||
/* not spelled ok - so add a syntax keyword for this word */
|
||||
edit_syntax_add_keyword (edit, (char *) q, context, t);
|
||||
free (q);
|
||||
syntax_free (q);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1146,7 +1164,7 @@ void edit_free_syntax_rules (WEdit * edit)
|
||||
syntax_free (edit->rules);
|
||||
}
|
||||
|
||||
#define CURRENT_SYNTAX_RULES_VERSION "61"
|
||||
#define CURRENT_SYNTAX_RULES_VERSION "62"
|
||||
|
||||
char *syntax_text[] = {
|
||||
"# syntax rules version " CURRENT_SYNTAX_RULES_VERSION,
|
||||
@ -1178,12 +1196,9 @@ char *syntax_text[] = {
|
||||
"context default",
|
||||
"",
|
||||
"",
|
||||
"file ..\\*\\\\.diff$ Unified\\sDiff\\sOutput ^diff.\\*(-u|--unified)",
|
||||
"file ..\\*\\\\.(diff|rej|patch)$ Diff\\sOutput ^diff",
|
||||
"include diff.syntax",
|
||||
"",
|
||||
"file ..\\*\\\\.diff$ Context\\sDiff\\sOutput ^diff.\\*(-c|--context)",
|
||||
"include diffc.syntax",
|
||||
"",
|
||||
"file ..\\*\\\\.lsm$ LSM\\sFile",
|
||||
"include lsm.syntax",
|
||||
"",
|
||||
@ -1217,6 +1232,9 @@ char *syntax_text[] = {
|
||||
"file ..\\*\\\\.([chC]|CC|cxx|cc|cpp|CPP|CXX)$ C/C\\+\\+\\sProgram",
|
||||
"include c.syntax",
|
||||
"",
|
||||
"file ..\\*\\\\.[fF]$ Fortran\\sProgram",
|
||||
"include fortran.syntax",
|
||||
"",
|
||||
"file ..\\*\\\\.i$ SWIG\\sSource",
|
||||
"include swig.syntax",
|
||||
"",
|
||||
@ -1348,9 +1366,9 @@ FILE *upgrade_syntax_file (char *syntax_file)
|
||||
rename (syntax_file, s);
|
||||
unlink (syntax_file); /* might rename() fail ? */
|
||||
#if defined(MIDNIGHT) || defined(GTK)
|
||||
edit_message_dialog (_(" Load Syntax Rules "), _(" Your syntax rule file is outdated \n A new rule file is being installed. \n Your old rule file has been saved with a .OLD extension. "));
|
||||
edit_message_dialog (" Load Syntax Rules ", " Your syntax rule file is outdated \n A new rule file is being installed. \n Your old rule file has been saved with a .OLD extension. ");
|
||||
#else
|
||||
CMessageDialog (0, 20, 20, 0,_(" Load Syntax Rules "), _(" Your syntax rule file is outdated \n A new rule file is being installed. \n Your old rule file has been saved with a .OLD extension. "));
|
||||
CMessageDialog (0, 20, 20, 0, " Load Syntax Rules ", " Your syntax rule file is outdated \n A new rule file is being installed. \n Your old rule file has been saved with a .OLD extension. ");
|
||||
#endif
|
||||
return upgrade_syntax_file (syntax_file);
|
||||
}
|
||||
@ -1362,82 +1380,96 @@ FILE *upgrade_syntax_file (char *syntax_file)
|
||||
static int edit_read_syntax_file (WEdit * edit, char **names, char *syntax_file, char *editor_file, char *first_line, char *type)
|
||||
{
|
||||
FILE *f;
|
||||
regex_t r, r2;
|
||||
regex_t r;
|
||||
regmatch_t pmatch[1];
|
||||
char *args[1024], *l;
|
||||
char *args[1024], *l = 0;
|
||||
int line = 0;
|
||||
int argc;
|
||||
int result = 0;
|
||||
int count = 0;
|
||||
|
||||
f = upgrade_syntax_file (syntax_file);
|
||||
if (!f)
|
||||
return -1;
|
||||
args[0] = 0;
|
||||
|
||||
for (;;) {
|
||||
line++;
|
||||
syntax_free (l);
|
||||
if (!read_one_line (&l, f))
|
||||
break;
|
||||
get_args (l, args, &argc);
|
||||
if (!args[0]) {
|
||||
} else if (!strcmp (args[0], "file")) {
|
||||
if (!args[1] || !args[2]) {
|
||||
result = line;
|
||||
break;
|
||||
}
|
||||
if (!args[0])
|
||||
continue;
|
||||
/* looking for `file ...' lines only */
|
||||
if (strcmp (args[0], "file")) {
|
||||
free_args (args);
|
||||
continue;
|
||||
}
|
||||
/* must have two args or report error */
|
||||
if (!args[1] || !args[2]) {
|
||||
result = line;
|
||||
break;
|
||||
}
|
||||
if (names) {
|
||||
/* 1: just collecting a list of names of rule sets */
|
||||
names[count++] = (char *) strdup (args[2]);
|
||||
names[count] = 0;
|
||||
} else if (type) {
|
||||
/* 2: rule set was explicitly specified by the caller */
|
||||
if (!strcmp (type, args[2]))
|
||||
goto found_type;
|
||||
} else if (editor_file && edit) {
|
||||
/* 3: auto-detect rule set from regular expressions */
|
||||
int q;
|
||||
if (regcomp (&r, args[1], REG_EXTENDED)) {
|
||||
result = line;
|
||||
break;
|
||||
}
|
||||
if (regcomp (&r2, args[3] ? args[3] : "^nEvEr MaTcH aNyThInG$", REG_EXTENDED)) {
|
||||
result = line;
|
||||
break;
|
||||
}
|
||||
if (names) {
|
||||
names[count++] = (char *) strdup (args[2]);
|
||||
names[count] = 0;
|
||||
} else if (type) {
|
||||
if (!strcmp (type, args[2]))
|
||||
goto found_type;
|
||||
} else if (editor_file && edit) {
|
||||
if (!regexec (&r, editor_file, 1, pmatch, 0) || !regexec (&r2, first_line, 1, pmatch, 0)) {
|
||||
int line_error;
|
||||
found_type:
|
||||
line_error = edit_read_syntax_rules (edit, f);
|
||||
if (line_error) {
|
||||
if (!error_file_name) /* an included file */
|
||||
result = line + line_error;
|
||||
else
|
||||
result = line_error;
|
||||
} else {
|
||||
syntax_free (edit->syntax_type);
|
||||
edit->syntax_type = (char *) strdup (args[2]);
|
||||
/* if there are no rules then turn off syntax highlighting for speed */
|
||||
if (!edit->rules[1])
|
||||
if (!edit->rules[0]->keyword[1] && !edit->rules[0]->spelling) {
|
||||
edit_free_syntax_rules (edit);
|
||||
break;
|
||||
}
|
||||
if (syntax_change_callback)
|
||||
#ifdef MIDNIGHT
|
||||
(*syntax_change_callback) (&edit->widget);
|
||||
#else
|
||||
(*syntax_change_callback) (edit->widget);
|
||||
#endif
|
||||
}
|
||||
/* does filename match arg 1 ? */
|
||||
q = !regexec (&r, editor_file, 1, pmatch, 0);
|
||||
regfree (&r);
|
||||
if (!q && args[3]) {
|
||||
if (regcomp (&r, args[3], REG_EXTENDED)) {
|
||||
result = line;
|
||||
break;
|
||||
}
|
||||
/* does first line match arg 3 ? */
|
||||
q = !regexec (&r, first_line, 1, pmatch, 0);
|
||||
regfree (&r);
|
||||
}
|
||||
if (q) {
|
||||
int line_error;
|
||||
found_type:
|
||||
line_error = edit_read_syntax_rules (edit, f);
|
||||
if (line_error) {
|
||||
if (!error_file_name) /* an included file */
|
||||
result = line + line_error;
|
||||
else
|
||||
result = line_error;
|
||||
} else {
|
||||
syntax_free (edit->syntax_type);
|
||||
edit->syntax_type = (char *) strdup (args[2]);
|
||||
/* if there are no rules then turn off syntax highlighting for speed */
|
||||
if (!edit->rules[1])
|
||||
if (!edit->rules[0]->keyword[1] && !edit->rules[0]->spelling) {
|
||||
edit_free_syntax_rules (edit);
|
||||
break;
|
||||
}
|
||||
/* notify the callback of a change in rule set */
|
||||
if (syntax_change_callback)
|
||||
#ifdef MIDNIGHT
|
||||
(*syntax_change_callback) (&edit->widget);
|
||||
#else
|
||||
(*syntax_change_callback) (edit->widget);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
free_args (args);
|
||||
syntax_free (l);
|
||||
}
|
||||
free_args (args);
|
||||
syntax_free (l);
|
||||
|
||||
fclose (f);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -107,9 +107,9 @@ static long end_paragraph (WEdit * edit, long p, int force)
|
||||
return edit_eol (edit, edit_move_forward (edit, edit_bol (edit, edit->curs1), i - edit->curs_line, 0));
|
||||
}
|
||||
|
||||
static char *get_paragraph (WEdit * edit, long p, long q, int indent, int *size)
|
||||
static unsigned char *get_paragraph (WEdit * edit, long p, long q, int indent, int *size)
|
||||
{
|
||||
char *s, *t;
|
||||
unsigned char *s, *t;
|
||||
#if 0
|
||||
t = malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length + 10);
|
||||
#else
|
||||
@ -129,9 +129,9 @@ static char *get_paragraph (WEdit * edit, long p, long q, int indent, int *size)
|
||||
return t;
|
||||
}
|
||||
|
||||
static void strip_newlines (char *t, int size)
|
||||
static void strip_newlines (unsigned char *t, int size)
|
||||
{
|
||||
char *p = t;
|
||||
unsigned char *p = t;
|
||||
while (size--) {
|
||||
*p = *p == '\n' ? ' ' : *p;
|
||||
p++;
|
||||
@ -152,7 +152,7 @@ static inline int next_tab_pos (int x)
|
||||
{
|
||||
return x += tab_width - x % tab_width;
|
||||
}
|
||||
static int line_pixel_length (char *t, long b, int l)
|
||||
static int line_pixel_length (unsigned char *t, long b, int l)
|
||||
{
|
||||
int x = 0, c, xn = 0;
|
||||
for (;;) {
|
||||
@ -180,7 +180,7 @@ static int line_pixel_length (char *t, long b, int l)
|
||||
}
|
||||
|
||||
/* find the start of a word */
|
||||
static int next_word_start (char *t, int q, int size)
|
||||
static int next_word_start (unsigned char *t, int q, int size)
|
||||
{
|
||||
int i;
|
||||
for (i = q;; i++) {
|
||||
@ -201,7 +201,7 @@ static int next_word_start (char *t, int q, int size)
|
||||
}
|
||||
|
||||
/* find the start of a word */
|
||||
static int word_start (char *t, int q, int size)
|
||||
static int word_start (unsigned char *t, int q, int size)
|
||||
{
|
||||
int i = q;
|
||||
if (t[q] == ' ' || t[q] == '\t')
|
||||
@ -220,7 +220,7 @@ static int word_start (char *t, int q, int size)
|
||||
}
|
||||
|
||||
/* replaces ' ' with '\n' to properly format a paragraph */
|
||||
static void format_this (char *t, int size, int indent)
|
||||
static void format_this (unsigned char *t, int size, int indent)
|
||||
{
|
||||
int q = 0, ww;
|
||||
strip_newlines (t, size);
|
||||
@ -258,7 +258,7 @@ static void replace_at (WEdit * edit, long q, int c)
|
||||
void edit_insert_indent (WEdit * edit, int indent);
|
||||
|
||||
/* replaces a block of text */
|
||||
static void put_paragraph (WEdit * edit, char *t, long p, long q, int indent, int size)
|
||||
static void put_paragraph (WEdit * edit, unsigned char *t, long p, long q, int indent, int size)
|
||||
{
|
||||
long cursor;
|
||||
int i, c = 0;
|
||||
@ -315,7 +315,7 @@ void format_paragraph (WEdit * edit, int force)
|
||||
{
|
||||
long p, q;
|
||||
int size;
|
||||
char *t;
|
||||
unsigned char *t;
|
||||
int indent = 0;
|
||||
if (option_word_wrap_line_length < 2)
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user