* edit.h: Don't inclide malloc.h. Use g_malloc() and g_free()

instead.  Adjust all dependencies.
This commit is contained in:
Pavel Roskin 2002-12-15 18:55:53 +00:00
parent 77bd4c7f55
commit aaf569bd48
9 changed files with 254 additions and 190 deletions

View File

@ -1,5 +1,8 @@
2002-12-15 Pavel Roskin <proski@gnu.org> 2002-12-15 Pavel Roskin <proski@gnu.org>
* edit.h: Don't inclide malloc.h. Use g_malloc() and g_free()
instead. Adjust all dependencies.
* edit.c (edit_load_file): Merge edit_open_file(). Disable fast * edit.c (edit_load_file): Merge edit_open_file(). Disable fast
loading on non-local VFS because the file size can be wrong. loading on non-local VFS because the file size can be wrong.
(init_dynamic_edit_buffers): Split into edit_init_buffers() and (init_dynamic_edit_buffers): Split into edit_init_buffers() and

View File

@ -44,8 +44,7 @@ struct _book_mark *book_mark_find (WEdit * edit, int line)
struct _book_mark *p; struct _book_mark *p;
if (!edit->book_mark) { if (!edit->book_mark) {
/* must have an imaginary top bookmark at line -1 to make things less complicated */ /* must have an imaginary top bookmark at line -1 to make things less complicated */
edit->book_mark = malloc (sizeof (struct _book_mark)); edit->book_mark = g_malloc0 (sizeof (struct _book_mark));
memset (edit->book_mark, 0, sizeof (struct _book_mark));
edit->book_mark->line = -1; edit->book_mark->line = -1;
return edit->book_mark; return edit->book_mark;
} }
@ -115,12 +114,14 @@ int book_mark_query_all (WEdit * edit, int line, int *c)
} }
/* insert a bookmark at this line */ /* insert a bookmark at this line */
void book_mark_insert (WEdit * edit, int line, int c) void
book_mark_insert (WEdit *edit, int line, int c)
{ {
struct _book_mark *p, *q; struct _book_mark *p, *q;
p = book_mark_find (edit, line); p = book_mark_find (edit, line);
#if 0 #if 0
if (p->line == line) { /* already exists, so just change the colour */ if (p->line == line) {
/* already exists, so just change the colour */
if (p->c != c) { if (p->c != c) {
edit->force |= REDRAW_LINE; edit->force |= REDRAW_LINE;
p->c = c; p->c = c;
@ -129,13 +130,12 @@ void book_mark_insert (WEdit * edit, int line, int c)
} }
#endif #endif
edit->force |= REDRAW_LINE; edit->force |= REDRAW_LINE;
/* create list entry */ /* create list entry */
q = malloc (sizeof (struct _book_mark)); q = g_malloc0 (sizeof (struct _book_mark));
memset (q, 0, sizeof (struct _book_mark));
q->line = line; q->line = line;
q->c = c; q->c = c;
q->next = p->next; q->next = p->next;
/* insert into list */ /* insert into list */
q->prev = p; q->prev = p;
if (p->next) if (p->next)
p->next->prev = q; p->next->prev = q;
@ -159,13 +159,13 @@ int book_mark_clear (WEdit * edit, int line, int c)
p->prev->next = p->next; p->prev->next = p->next;
if (p->next) if (p->next)
p->next->prev = p->prev; p->next->prev = p->prev;
free (p); g_free (p);
break; break;
} }
} }
/* if there is only our dummy book mark left, clear it for speed */ /* if there is only our dummy book mark left, clear it for speed */
if (edit->book_mark->line == -1 && !edit->book_mark->next) { if (edit->book_mark->line == -1 && !edit->book_mark->next) {
free (edit->book_mark); g_free (edit->book_mark);
edit->book_mark = 0; edit->book_mark = 0;
} }
return r; return r;
@ -186,11 +186,11 @@ void book_mark_flush (WEdit * edit, int c)
q->prev->next = q->next; q->prev->next = q->next;
if (p) if (p)
p->prev = q->prev; p->prev = q->prev;
free (q); g_free (q);
} }
} }
if (!edit->book_mark->next) { if (!edit->book_mark->next) {
free (edit->book_mark); g_free (edit->book_mark);
edit->book_mark = 0; edit->book_mark = 0;
} }
} }

View File

@ -232,7 +232,7 @@ edit_get_filter (const char *filename)
if (i < 0) if (i < 0)
return 0; return 0;
l = strlen (filename); l = strlen (filename);
p = malloc (strlen (all_filters[i].read) + l + 2); p = g_malloc (strlen (all_filters[i].read) + l + 2);
sprintf (p, all_filters[i].read, filename); sprintf (p, all_filters[i].read, filename);
return p; return p;
} }
@ -245,7 +245,7 @@ char *edit_get_write_filter (char *writename, const char *filename)
if (i < 0) if (i < 0)
return 0; return 0;
l = strlen (writename); l = strlen (writename);
p = malloc (strlen (all_filters[i].write) + l + 2); p = g_malloc (strlen (all_filters[i].write) + l + 2);
sprintf (p, all_filters[i].write, writename); sprintf (p, all_filters[i].write, writename);
return p; return p;
} }
@ -284,7 +284,8 @@ long edit_write_stream (WEdit * edit, FILE * f)
*/ */
/* inserts a file at the cursor, returns 1 on success */ /* inserts a file at the cursor, returns 1 on success */
int edit_insert_file (WEdit * edit, const char *filename) int
edit_insert_file (WEdit *edit, const char *filename)
{ {
char *p; char *p;
if ((p = edit_get_filter (filename))) { if ((p = edit_get_filter (filename))) {
@ -295,21 +296,28 @@ int edit_insert_file (WEdit * edit, const char *filename)
edit_insert_stream (edit, f); edit_insert_stream (edit, f);
edit_cursor_move (edit, current - edit->curs1); edit_cursor_move (edit, current - edit->curs1);
if (pclose (f) > 0) { if (pclose (f) > 0) {
edit_error_dialog (_ ("Error"), catstrs (_ (" Error reading from pipe: "), p, " ", 0)); edit_error_dialog (_("Error"),
free (p); catstrs (_
(" Error reading from pipe: "),
p, " ", 0));
g_free (p);
return 0; return 0;
} }
} else { } else {
edit_error_dialog (_ ("Error"), get_sys_error (catstrs (_ (" Cannot open pipe for reading: "), p, " ", 0))); edit_error_dialog (_("Error"),
free (p); get_sys_error (catstrs
(_
(" Cannot open pipe for reading: "),
p, " ", 0)));
g_free (p);
return 0; return 0;
} }
free (p); g_free (p);
} else { } else {
int i, file, blocklen; int i, file, blocklen;
long current = edit->curs1; long current = edit->curs1;
unsigned char *buf; unsigned char *buf;
if ((file = mc_open (filename, O_RDONLY | O_BINARY )) == -1) if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1)
return 0; return 0;
buf = g_malloc (TEMP_BUF_LEN); buf = g_malloc (TEMP_BUF_LEN);
while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0) { while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0) {
@ -535,8 +543,7 @@ edit_init (WEdit *edit, int lines, int columns, const char *filename,
option_whole_chars_search = option_whole_chars_search_buf; option_whole_chars_search = option_whole_chars_search_buf;
} }
#endif /* ENABLE_NLS */ #endif /* ENABLE_NLS */
edit = g_malloc (sizeof (WEdit)); edit = g_malloc0 (sizeof (WEdit));
memset (edit, 0, sizeof (WEdit));
to_free = 1; to_free = 1;
} }
edit_purge_widget (edit); edit_purge_widget (edit);
@ -550,7 +557,7 @@ edit_init (WEdit *edit, int lines, int columns, const char *filename,
edit_set_filename (edit, filename); edit_set_filename (edit, filename);
edit->stack_size = START_STACK_SIZE; edit->stack_size = START_STACK_SIZE;
edit->stack_size_mask = START_STACK_SIZE - 1; edit->stack_size_mask = START_STACK_SIZE - 1;
edit->undo_stack = malloc ((edit->stack_size + 10) * sizeof (long)); edit->undo_stack = g_malloc ((edit->stack_size + 10) * sizeof (long));
if (edit_load_file (edit)) { if (edit_load_file (edit)) {
/* edit_load_file already gives an error message */ /* edit_load_file already gives an error message */
if (to_free) if (to_free)
@ -599,8 +606,7 @@ edit_clean (WEdit *edit)
g_free (edit->buffers2[j]); g_free (edit->buffers2[j]);
} }
if (edit->undo_stack) g_free (edit->undo_stack);
free (edit->undo_stack);
g_free (edit->filename); g_free (edit->filename);
edit_purge_widget (edit); edit_purge_widget (edit);
@ -632,8 +638,7 @@ edit_reload (WEdit *edit, const char *filename)
WEdit *e; WEdit *e;
int lines = edit->num_widget_lines; int lines = edit->num_widget_lines;
int columns = edit->num_widget_columns; int columns = edit->num_widget_columns;
e = g_malloc (sizeof (WEdit)); e = g_malloc0 (sizeof (WEdit));
memset (e, 0, sizeof (WEdit));
e->widget = edit->widget; e->widget = edit->widget;
e->macro_i = -1; e->macro_i = -1;
if (!edit_init (e, lines, columns, filename, 0)) { if (!edit_init (e, lines, columns, filename, 0)) {
@ -697,10 +702,10 @@ void edit_push_action (WEdit * edit, long c,...)
if (option_max_undo < 256) if (option_max_undo < 256)
option_max_undo = 256; option_max_undo = 256;
if (edit->stack_size < option_max_undo) { if (edit->stack_size < option_max_undo) {
t = malloc ((edit->stack_size * 2 + 10) * sizeof (long)); t = g_malloc ((edit->stack_size * 2 + 10) * sizeof (long));
if (t) { if (t) {
memcpy (t, edit->undo_stack, sizeof (long) * edit->stack_size); memcpy (t, edit->undo_stack, sizeof (long) * edit->stack_size);
free (edit->undo_stack); g_free (edit->undo_stack);
edit->undo_stack = t; edit->undo_stack = t;
edit->stack_size <<= 1; edit->stack_size <<= 1;
edit->stack_size_mask = edit->stack_size - 1; edit->stack_size_mask = edit->stack_size - 1;
@ -823,19 +828,20 @@ static inline void edit_modification (WEdit * edit)
Returns char passed over, inserted or removed. Returns char passed over, inserted or removed.
*/ */
void edit_insert (WEdit * edit, int c) void
edit_insert (WEdit *edit, int c)
{ {
/* check if file has grown to large */ /* check if file has grown to large */
if (edit->last_byte >= SIZE_LIMIT) if (edit->last_byte >= SIZE_LIMIT)
return; return;
/* first we must update the position of the display window */ /* first we must update the position of the display window */
if (edit->curs1 < edit->start_display) { if (edit->curs1 < edit->start_display) {
edit->start_display++; edit->start_display++;
if (c == '\n') if (c == '\n')
edit->start_line++; edit->start_line++;
} }
/* now we must update some info on the file and check if a redraw is required */ /* now we must update some info on the file and check if a redraw is required */
if (c == '\n') { if (c == '\n') {
if (edit->book_mark) if (edit->book_mark)
book_mark_inc (edit, edit->curs_line); book_mark_inc (edit, edit->curs_line);
@ -843,28 +849,31 @@ void edit_insert (WEdit * edit, int c)
edit->total_lines++; edit->total_lines++;
edit->force |= REDRAW_LINE_ABOVE | REDRAW_AFTER_CURSOR; edit->force |= REDRAW_LINE_ABOVE | REDRAW_AFTER_CURSOR;
} }
/* tell that we've modified the file */ /* tell that we've modified the file */
edit_modification (edit); edit_modification (edit);
/* save the reverse command onto the undo stack */ /* save the reverse command onto the undo stack */
edit_push_action (edit, BACKSPACE); edit_push_action (edit, BACKSPACE);
/* update markers */ /* update markers */
edit->mark1 += (edit->mark1 > edit->curs1); edit->mark1 += (edit->mark1 > edit->curs1);
edit->mark2 += (edit->mark2 > edit->curs1); edit->mark2 += (edit->mark2 > edit->curs1);
edit->last_get_rule += (edit->last_get_rule > edit->curs1); edit->last_get_rule += (edit->last_get_rule > edit->curs1);
/* add a new buffer if we've reached the end of the last one */ /* add a new buffer if we've reached the end of the last one */
if (!(edit->curs1 & M_EDIT_BUF_SIZE)) if (!(edit->curs1 & M_EDIT_BUF_SIZE))
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = malloc (EDIT_BUF_SIZE); edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] =
g_malloc (EDIT_BUF_SIZE);
/* perfprm the insertion */ /* perform the insertion */
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->curs1 & M_EDIT_BUF_SIZE] = (unsigned char) c; edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->
curs1 & M_EDIT_BUF_SIZE]
= (unsigned char) c;
/* update file length */ /* update file length */
edit->last_byte++; edit->last_byte++;
/* update cursor position */ /* update cursor position */
edit->curs1++; edit->curs1++;
} }
@ -990,7 +999,8 @@ static void memqcpy (WEdit * edit, unsigned char *dest, unsigned char *src, int
} }
} }
int edit_move_backward_lots (WEdit * edit, long increment) int
edit_move_backward_lots (WEdit *edit, long increment)
{ {
int r, s, t; int r, s, t;
unsigned char *p; unsigned char *p;
@ -1008,17 +1018,22 @@ int edit_move_backward_lots (WEdit * edit, long increment)
p = 0; p = 0;
if (s > r) { if (s > r) {
memqcpy (edit, edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t - r, memqcpy (edit,
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] + s - r, r); edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t - r,
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] + s - r,
r);
} else { } else {
if (s) { if (s) {
memqcpy (edit, edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t - s, memqcpy (edit,
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE], s); edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t -
s, edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE], s);
p = edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE]; p = edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE];
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = 0; edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = 0;
} }
memqcpy (edit, edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t - r, memqcpy (edit,
edit->buffers1[(edit->curs1 >> S_EDIT_BUF_SIZE) - 1] + EDIT_BUF_SIZE - (r - s), r - s); edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t - r,
edit->buffers1[(edit->curs1 >> S_EDIT_BUF_SIZE) - 1] +
EDIT_BUF_SIZE - (r - s), r - s);
} }
increment -= r; increment -= r;
edit->curs1 -= r; edit->curs1 -= r;
@ -1027,10 +1042,11 @@ int edit_move_backward_lots (WEdit * edit, long increment)
if (p) if (p)
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = p; edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = p;
else else
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = malloc (EDIT_BUF_SIZE); edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] =
g_malloc (EDIT_BUF_SIZE);
} else { } else {
if (p) if (p)
free (p); g_free (p);
} }
s = edit->curs1 & M_EDIT_BUF_SIZE; s = edit->curs1 & M_EDIT_BUF_SIZE;
@ -1043,7 +1059,8 @@ int edit_move_backward_lots (WEdit * edit, long increment)
if (r < t) if (r < t)
t = r; t = r;
memqcpy (edit, memqcpy (edit,
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + EDIT_BUF_SIZE - t, edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] +
EDIT_BUF_SIZE - t,
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] + s - t, edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] + s - t,
t); t);
if (r >= s) { if (r >= s) {
@ -1052,9 +1069,10 @@ int edit_move_backward_lots (WEdit * edit, long increment)
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = 0; edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = 0;
} }
memqcpy (edit, memqcpy (edit,
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + EDIT_BUF_SIZE - r, edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] +
edit->buffers1[(edit->curs1 >> S_EDIT_BUF_SIZE) - 1] + EDIT_BUF_SIZE - (r - s), EDIT_BUF_SIZE - r,
r - s); edit->buffers1[(edit->curs1 >> S_EDIT_BUF_SIZE) - 1] +
EDIT_BUF_SIZE - (r - s), r - s);
} }
increment -= r; increment -= r;
edit->curs1 -= r; edit->curs1 -= r;
@ -1063,10 +1081,10 @@ int edit_move_backward_lots (WEdit * edit, long increment)
if (p) if (p)
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = p; edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = p;
else else
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = malloc (EDIT_BUF_SIZE); edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] =
g_malloc (EDIT_BUF_SIZE);
} else { } else {
if (p) g_free (p);
free (p);
} }
} }
return edit_get_byte (edit, edit->curs1); return edit_get_byte (edit, edit->curs1);
@ -1096,7 +1114,7 @@ int edit_cursor_move (WEdit * edit, long increment)
c = edit_get_byte (edit, edit->curs1 - 1); c = edit_get_byte (edit, edit->curs1 - 1);
if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE)) if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE))
edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = malloc (EDIT_BUF_SIZE); edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE);
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c; edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c;
edit->curs2++; edit->curs2++;
c = edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->curs1 - 1) & M_EDIT_BUF_SIZE]; c = edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->curs1 - 1) & M_EDIT_BUF_SIZE];
@ -1121,7 +1139,7 @@ int edit_cursor_move (WEdit * edit, long increment)
c = edit_get_byte (edit, edit->curs1); c = edit_get_byte (edit, edit->curs1);
if (!(edit->curs1 & M_EDIT_BUF_SIZE)) if (!(edit->curs1 & M_EDIT_BUF_SIZE))
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = malloc (EDIT_BUF_SIZE); edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE);
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->curs1 & M_EDIT_BUF_SIZE] = c; edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->curs1 & M_EDIT_BUF_SIZE] = c;
edit->curs1++; edit->curs1++;
c = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - ((edit->curs2 - 1) & M_EDIT_BUF_SIZE) - 1]; c = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - ((edit->curs2 - 1) & M_EDIT_BUF_SIZE) - 1];
@ -1600,19 +1618,21 @@ void edit_push_markers (WEdit * edit)
} }
/* return -1 on nothing to store or error, zero otherwise */ /* return -1 on nothing to store or error, zero otherwise */
void edit_get_selection (WEdit * edit) void
edit_get_selection (WEdit *edit)
{ {
long start_mark, end_mark; long start_mark, end_mark;
if (eval_marks (edit, &start_mark, &end_mark)) if (eval_marks (edit, &start_mark, &end_mark))
return; return;
if (selection_history[current_selection].len < 4096) /* large selections should not be held -- to save memory */ if (selection_history[current_selection].len < 4096) /* large selections should not be held -- to save memory */
current_selection = (current_selection + 1) % NUM_SELECTION_HISTORY; current_selection =
(current_selection + 1) % NUM_SELECTION_HISTORY;
selection_history[current_selection].len = end_mark - start_mark; selection_history[current_selection].len = end_mark - start_mark;
if (selection_history[current_selection].text) g_free (selection_history[current_selection].text);
free (selection_history[current_selection].text); selection_history[current_selection].text =
selection_history[current_selection].text = malloc (selection_history[current_selection].len + 1); g_malloc (selection_history[current_selection].len + 1);
if (!selection_history[current_selection].text) { if (!selection_history[current_selection].text) {
selection_history[current_selection].text = malloc (1); selection_history[current_selection].text = g_malloc (1);
*selection_history[current_selection].text = 0; *selection_history[current_selection].text = 0;
selection_history[current_selection].len = 0; selection_history[current_selection].len = 0;
} else { } else {

View File

@ -36,9 +36,6 @@
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H)
# include <malloc.h>
#endif
#include "src/global.h" #include "src/global.h"

View File

@ -196,7 +196,8 @@ void edit_refresh_cmd (WEdit * edit)
c) rename <tempnam> to <filename>. */ c) rename <tempnam> to <filename>. */
/* returns 0 on error */ /* returns 0 on error */
int edit_save_file (WEdit * edit, const char *filename) int
edit_save_file (WEdit *edit, const char *filename)
{ {
char *p; char *p;
long filelen = 0; long filelen = 0;
@ -223,13 +224,13 @@ int edit_save_file (WEdit * edit, const char *filename)
char *savedir, *slashpos, *saveprefix; char *savedir, *slashpos, *saveprefix;
slashpos = strrchr (filename, PATH_SEP); slashpos = strrchr (filename, PATH_SEP);
if (slashpos) { if (slashpos) {
savedir = (char *) strdup (filename); savedir = g_strdup (filename);
savedir[slashpos - filename + 1] = '\0'; savedir[slashpos - filename + 1] = '\0';
} else } else
savedir = (char *) strdup ("."); savedir = g_strdup (".");
saveprefix = concat_dir_and_file (savedir, "cooledit"); saveprefix = concat_dir_and_file (savedir, "cooledit");
free (savedir); g_free (savedir);
fd = mc_mkstemps(&savename, saveprefix, NULL); fd = mc_mkstemps (&savename, saveprefix, NULL);
g_free (saveprefix); g_free (saveprefix);
if (!savename) if (!savename)
return 0; return 0;
@ -245,8 +246,9 @@ int edit_save_file (WEdit * edit, const char *filename)
mc_chown (savename, edit->stat1.st_uid, edit->stat1.st_gid); mc_chown (savename, edit->stat1.st_uid, edit->stat1.st_gid);
mc_chmod (savename, edit->stat1.st_mode); mc_chmod (savename, edit->stat1.st_mode);
if ((fd = mc_open (savename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY , if ((fd =
edit->stat1.st_mode)) == -1) mc_open (savename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY,
edit->stat1.st_mode)) == -1)
goto error_save; goto error_save;
/* pipe save */ /* pipe save */
@ -254,7 +256,7 @@ int edit_save_file (WEdit * edit, const char *filename)
FILE *file; FILE *file;
mc_close (fd); mc_close (fd);
file = (FILE *) popen (p, "w"); file = (FILE *) popen (p, "w");
if (file) { if (file) {
filelen = edit_write_stream (edit, file); filelen = edit_write_stream (edit, file);
@ -262,38 +264,55 @@ int edit_save_file (WEdit * edit, const char *filename)
pclose (file); pclose (file);
#else #else
if (pclose (file) != 0) { if (pclose (file) != 0) {
edit_error_dialog (_ ("Error"), catstrs (_ (" Error writing to pipe: "), p, " ", 0)); edit_error_dialog (_("Error"),
free (p); catstrs (_(" Error writing to pipe: "),
p, " ", 0));
g_free (p);
goto error_save; goto error_save;
} }
#endif #endif
} else { } else {
edit_error_dialog (_ ("Error"), get_sys_error (catstrs (_ (" Cannot open pipe for writing: "), p, " ", 0))); edit_error_dialog (_("Error"),
free (p); get_sys_error (catstrs
(_
(" Cannot open pipe for writing: "),
p, " ", 0)));
g_free (p);
goto error_save; goto error_save;
} }
free (p); g_free (p);
} else { } else {
long buf; long buf;
buf = 0; buf = 0;
filelen = edit->last_byte; filelen = edit->last_byte;
while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) { while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) {
if (mc_write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) { if (mc_write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE)
!= EDIT_BUF_SIZE) {
mc_close (fd); mc_close (fd);
goto error_save; goto error_save;
} }
buf++; buf++;
} }
if (mc_write (fd, (char *) edit->buffers1[buf], edit->curs1 & M_EDIT_BUF_SIZE) != (edit->curs1 & M_EDIT_BUF_SIZE)) { if (mc_write
(fd, (char *) edit->buffers1[buf],
edit->curs1 & M_EDIT_BUF_SIZE) !=
(edit->curs1 & M_EDIT_BUF_SIZE)) {
filelen = -1; filelen = -1;
} else if (edit->curs2) { } else if (edit->curs2) {
edit->curs2--; edit->curs2--;
buf = (edit->curs2 >> S_EDIT_BUF_SIZE); buf = (edit->curs2 >> S_EDIT_BUF_SIZE);
if (mc_write (fd, (char *) edit->buffers2[buf] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1, 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) { if (mc_write
(fd,
(char *) edit->buffers2[buf] + EDIT_BUF_SIZE -
(edit->curs2 & M_EDIT_BUF_SIZE) - 1,
1 + (edit->curs2 & M_EDIT_BUF_SIZE)) !=
1 + (edit->curs2 & M_EDIT_BUF_SIZE)) {
filelen = -1; filelen = -1;
} else { } else {
while (--buf >= 0) { while (--buf >= 0) {
if (mc_write (fd, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) { if (mc_write
(fd, (char *) edit->buffers2[buf],
EDIT_BUF_SIZE) != EDIT_BUF_SIZE) {
filelen = -1; filelen = -1;
break; break;
} }
@ -308,7 +327,8 @@ int edit_save_file (WEdit * edit, const char *filename)
if (filelen != edit->last_byte) if (filelen != edit->last_byte)
goto error_save; goto error_save;
if (this_save_mode == 2) if (this_save_mode == 2)
if (mc_rename (filename, catstrs (filename, option_backup_ext, 0)) == -1) if (mc_rename (filename, catstrs (filename, option_backup_ext, 0))
== -1)
goto error_save; goto error_save;
if (this_save_mode > 0) if (this_save_mode > 0)
if (mc_rename (savename, filename) == -1) if (mc_rename (savename, filename) == -1)
@ -405,7 +425,7 @@ edit_set_filename (WEdit *edit, const char *f)
g_free (edit->filename); g_free (edit->filename);
if (!f) if (!f)
f = ""; f = "";
edit->filename = (char *) g_strdup (f); edit->filename = g_strdup (f);
} }
/* Here we want to warn the users of overwriting an existing file, /* Here we want to warn the users of overwriting an existing file,
@ -840,7 +860,8 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int wid
} }
void edit_block_copy_cmd (WEdit * edit) void
edit_block_copy_cmd (WEdit *edit)
{ {
long start_mark, end_mark, current = edit->curs1; long start_mark, end_mark, current = edit->curs1;
int size, x; int size, x;
@ -851,23 +872,25 @@ void edit_block_copy_cmd (WEdit * edit)
if (eval_marks (edit, &start_mark, &end_mark)) if (eval_marks (edit, &start_mark, &end_mark))
return; return;
if (column_highlighting) if (column_highlighting)
if ((x >= edit->column1 && x < edit->column2) || (x > edit->column2 && x <= edit->column1)) if ((x >= edit->column1 && x < edit->column2)
|| (x > edit->column2 && x <= edit->column1))
return; return;
copy_buf = edit_get_block (edit, start_mark, end_mark, &size); copy_buf = edit_get_block (edit, start_mark, end_mark, &size);
/* all that gets pushed are deletes hence little space is used on the stack */ /* all that gets pushed are deletes hence little space is used on the stack */
edit_push_markers (edit); edit_push_markers (edit);
if (column_highlighting) { if (column_highlighting) {
edit_insert_column_of_text (edit, copy_buf, size, abs (edit->column2 - edit->column1)); edit_insert_column_of_text (edit, copy_buf, size,
abs (edit->column2 - edit->column1));
} else { } else {
while (size--) while (size--)
edit_insert_ahead (edit, copy_buf[size]); edit_insert_ahead (edit, copy_buf[size]);
} }
free (copy_buf); g_free (copy_buf);
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
if (column_highlighting) { if (column_highlighting) {
@ -875,13 +898,15 @@ void edit_block_copy_cmd (WEdit * edit)
edit_push_action (edit, COLUMN_ON); edit_push_action (edit, COLUMN_ON);
column_highlighting = 0; column_highlighting = 0;
} else if (start_mark < current && end_mark > current) } else if (start_mark < current && end_mark > current)
edit_set_markers (edit, start_mark, end_mark + end_mark - start_mark, 0, 0); edit_set_markers (edit, start_mark,
end_mark + end_mark - start_mark, 0, 0);
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
} }
void edit_block_move_cmd (WEdit * edit) void
edit_block_move_cmd (WEdit *edit)
{ {
long count; long count;
long current; long current;
@ -896,13 +921,18 @@ void edit_block_move_cmd (WEdit * edit)
edit_update_curs_col (edit); edit_update_curs_col (edit);
x = edit->curs_col; x = edit->curs_col;
if (start_mark <= edit->curs1 && end_mark >= edit->curs1) if (start_mark <= edit->curs1 && end_mark >= edit->curs1)
if ((x > edit->column1 && x < edit->column2) || (x > edit->column2 && x < edit->column1)) if ((x > edit->column1 && x < edit->column2)
|| (x > edit->column2 && x < edit->column1))
return; return;
} else if (start_mark <= edit->curs1 && end_mark >= edit->curs1) } else if (start_mark <= edit->curs1 && end_mark >= edit->curs1)
return; return;
if ((end_mark - start_mark) > option_max_undo / 2) if ((end_mark - start_mark) > option_max_undo / 2)
if (edit_query_dialog2 (_ ("Warning"), _ (" Block is large, you may not be able to undo this action. "), _ ("Continue"), _ ("Cancel"))) if (edit_query_dialog2
(_("Warning"),
_
(" Block is large, you may not be able to undo this action. "),
_("Continue"), _("Cancel")))
return; return;
edit_push_markers (edit); edit_push_markers (edit);
@ -920,7 +950,10 @@ void edit_block_move_cmd (WEdit * edit)
deleted = 1; deleted = 1;
} }
edit_move_to_line (edit, line); edit_move_to_line (edit, line);
edit_cursor_move (edit, edit_move_forward3 (edit, edit_bol (edit, edit->curs1), x, 0) - edit->curs1); edit_cursor_move (edit,
edit_move_forward3 (edit,
edit_bol (edit, edit->curs1),
x, 0) - edit->curs1);
edit_insert_column_of_text (edit, copy_buf, size, c2 - c1); edit_insert_column_of_text (edit, copy_buf, size, c2 - c1);
if (!deleted) { if (!deleted) {
line = edit->curs_line; line = edit->curs_line;
@ -928,13 +961,17 @@ void edit_block_move_cmd (WEdit * edit)
x = edit->curs_col; x = edit->curs_col;
edit_block_delete_cmd (edit); edit_block_delete_cmd (edit);
edit_move_to_line (edit, line); edit_move_to_line (edit, line);
edit_cursor_move (edit, edit_move_forward3 (edit, edit_bol (edit, edit->curs1), x, 0) - edit->curs1); edit_cursor_move (edit,
edit_move_forward3 (edit,
edit_bol (edit,
edit->curs1),
x, 0) - edit->curs1);
} }
edit_set_markers (edit, 0, 0, 0, 0); edit_set_markers (edit, 0, 0, 0, 0);
edit_push_action (edit, COLUMN_ON); edit_push_action (edit, COLUMN_ON);
column_highlighting = 0; column_highlighting = 0;
} else { } else {
copy_buf = malloc (end_mark - start_mark); copy_buf = g_malloc (end_mark - start_mark);
edit_cursor_move (edit, start_mark - edit->curs1); edit_cursor_move (edit, start_mark - edit->curs1);
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
count = start_mark; count = start_mark;
@ -943,14 +980,18 @@ void edit_block_move_cmd (WEdit * edit)
count++; count++;
} }
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
edit_cursor_move (edit, current - edit->curs1 - (((current - edit->curs1) > 0) ? end_mark - start_mark : 0)); edit_cursor_move (edit,
current - edit->curs1 -
(((current - edit->curs1) >
0) ? end_mark - start_mark : 0));
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
while (count-- > start_mark) while (count-- > start_mark)
edit_insert_ahead (edit, copy_buf[end_mark - count - 1]); edit_insert_ahead (edit, copy_buf[end_mark - count - 1]);
edit_set_markers (edit, edit->curs1, edit->curs1 + end_mark - start_mark, 0, 0); edit_set_markers (edit, edit->curs1,
edit->curs1 + end_mark - start_mark, 0, 0);
} }
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
free (copy_buf); g_free (copy_buf);
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
} }
@ -1260,7 +1301,8 @@ static long sargs[NUM_REPL_ARGS][256 / sizeof (long)];
/* This function is a modification of mc-3.2.10/src/view.c:regexp_view_search() */ /* This function is a modification of mc-3.2.10/src/view.c:regexp_view_search() */
/* returns -3 on error in pattern, -1 on not found, found_len = 0 if either */ /* returns -3 on error in pattern, -1 on not found, found_len = 0 if either */
static int static int
string_regexp_search (char *pattern, char *string, int len, int match_type, int match_bol, int icase, int *found_len, void *d) string_regexp_search (char *pattern, char *string, int len, int match_type,
int match_bol, int icase, int *found_len, void *d)
{ {
static regex_t r; static regex_t r;
static char *old_pattern = NULL; static char *old_pattern = NULL;
@ -1272,21 +1314,25 @@ string_regexp_search (char *pattern, char *string, int len, int match_type, int
if (!pmatch) if (!pmatch)
pmatch = s; pmatch = s;
if (!old_pattern || strcmp (old_pattern, pattern) || old_type != match_type || old_icase != icase) { if (!old_pattern || strcmp (old_pattern, pattern)
|| old_type != match_type || old_icase != icase) {
if (old_pattern) { if (old_pattern) {
regfree (&r); regfree (&r);
free (old_pattern); g_free (old_pattern);
old_pattern = 0; old_pattern = 0;
} }
if (regcomp (&r, pattern, REG_EXTENDED | (icase ? REG_ICASE : 0))) { if (regcomp (&r, pattern, REG_EXTENDED | (icase ? REG_ICASE : 0))) {
*found_len = 0; *found_len = 0;
return -3; return -3;
} }
old_pattern = (char *) strdup (pattern); old_pattern = g_strdup (pattern);
old_type = match_type; old_type = match_type;
old_icase = icase; old_icase = icase;
} }
if (regexec (&r, string, d ? NUM_REPL_ARGS : 1, pmatch, ((match_bol || match_type != match_normal) ? 0 : REG_NOTBOL)) != 0) { if (regexec
(&r, string, d ? NUM_REPL_ARGS : 1, pmatch,
((match_bol
|| match_type != match_normal) ? 0 : REG_NOTBOL)) != 0) {
*found_len = 0; *found_len = 0;
return -1; return -1;
} }
@ -1990,19 +2036,22 @@ void edit_quit_cmd (WEdit * edit)
#define TEMP_BUF_LEN 1024 #define TEMP_BUF_LEN 1024
/* returns a null terminated length of text. Result must be free'd */ /* Return a null terminated length of text. Result must be g_free'd */
unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l) unsigned char *
edit_get_block (WEdit *edit, long start, long finish, int *l)
{ {
unsigned char *s, *r; unsigned char *s, *r;
r = s = malloc (finish - start + 1); r = s = g_malloc (finish - start + 1);
if (column_highlighting) { if (column_highlighting) {
*l = 0; *l = 0;
while (start < finish) { /* copy from buffer, excluding chars that are out of the column 'margins' */ /* copy from buffer, excluding chars that are out of the column 'margins' */
while (start < finish) {
int c, x; int c, x;
x = edit_move_forward3 (edit, edit_bol (edit, start), 0, start); x = edit_move_forward3 (edit, edit_bol (edit, start), 0,
start);
c = edit_get_byte (edit, start); c = edit_get_byte (edit, start);
if ((x >= edit->column1 && x < edit->column2) if ((x >= edit->column1 && x < edit->column2)
|| (x >= edit->column2 && x < edit->column1) || c == '\n') { || (x >= edit->column2 && x < edit->column1) || c == '\n') {
*s++ = c; *s++ = c;
(*l)++; (*l)++;
} }
@ -2040,12 +2089,12 @@ edit_save_block (WEdit * edit, const char *filename, long start,
p += r; p += r;
len -= r; len -= r;
} }
free (block); g_free (block);
} else { } else {
unsigned char *buf; unsigned char *buf;
int i = start, end; int i = start, end;
len = finish - start; len = finish - start;
buf = malloc (TEMP_BUF_LEN); buf = g_malloc (TEMP_BUF_LEN);
while (start != finish) { while (start != finish) {
end = min (finish, start + TEMP_BUF_LEN); end = min (finish, start + TEMP_BUF_LEN);
for (; i < end; i++) for (; i < end; i++)
@ -2053,7 +2102,7 @@ edit_save_block (WEdit * edit, const char *filename, long start,
len -= mc_write (file, (char *) buf, end - start); len -= mc_write (file, (char *) buf, end - start);
start = end; start = end;
} }
free (buf); g_free (buf);
} }
mc_close (file); mc_close (file);
if (len) if (len)

View File

@ -85,12 +85,13 @@ static void status_string (WEdit * edit, char *s, int w, int fill)
} }
/* how to get as much onto the status line as is numerically possible :) */ /* how to get as much onto the status line as is numerically possible :) */
void edit_status (WEdit * edit) void
edit_status (WEdit *edit)
{ {
int w, i, t; int w, i, t;
char *s; char *s;
w = edit->widget.cols - (edit->have_frame * 2); w = edit->widget.cols - (edit->have_frame * 2);
s = malloc (w + 16); s = g_malloc (w + 16);
if (w < 4) if (w < 4)
w = 4; w = 4;
memset (s, ' ', w); memset (s, ' ', w);
@ -105,14 +106,14 @@ void edit_status (WEdit * edit)
s[i] = ' '; s[i] = ' ';
} }
t = w - 20; t = w - 20;
if (t > 1) /* g_snprintf() must write at least '\000' */ if (t > 1) /* g_snprintf() must write at least '\000' */
status_string (edit, s + 20, t + 1 /* for '\000' */ , ' '); status_string (edit, s + 20, t + 1 /* for '\000' */ , ' ');
} }
s[w] = 0; s[w] = 0;
printw ("%-*s", w, s); printw ("%-*s", w, s);
attrset (EDITOR_NORMAL_COLOR); attrset (EDITOR_NORMAL_COLOR);
free (s); g_free (s);
} }
/* this scrolls the text so that cursor is on the screen */ /* this scrolls the text so that cursor is on the screen */

View File

@ -160,7 +160,7 @@ edit (const char *_file, int line)
WButtonBar *edit_bar; WButtonBar *edit_bar;
if (option_backup_ext_int != -1) { if (option_backup_ext_int != -1) {
option_backup_ext = malloc (sizeof (int) + 1); option_backup_ext = g_malloc (sizeof (int) + 1);
option_backup_ext[sizeof (int)] = '\0'; option_backup_ext[sizeof (int)] = '\0';
memcpy (option_backup_ext, (char *) &option_backup_ext_int, memcpy (option_backup_ext, (char *) &option_backup_ext_int,
sizeof (int)); sizeof (int));

View File

@ -81,16 +81,7 @@ struct _syntax_marker {
int option_syntax_highlighting = 1; int option_syntax_highlighting = 1;
static inline void *syntax_malloc (size_t x) #define syntax_g_free(x) do {if(x) {g_free(x); (x)=0;}} while (0)
{
void *p;
p = malloc (x);
memset (p, 0, x);
return p;
}
#define syntax_free(x) {if(x){free(x);(x)=0;}}
#define syntax_g_free(x) {if(x){g_free(x);(x)=0;}}
static long compare_word_to_right (WEdit * edit, long i, char *text, char *whole_left, char *whole_right, int line_start) static long compare_word_to_right (WEdit * edit, long i, char *text, char *whole_left, char *whole_right, int line_start)
{ {
@ -355,7 +346,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)) { if (i > (edit->syntax_marker ? edit->syntax_marker->offset + SYNTAX_MARKER_DENSITY : SYNTAX_MARKER_DENSITY)) {
struct _syntax_marker *s; struct _syntax_marker *s;
s = edit->syntax_marker; s = edit->syntax_marker;
edit->syntax_marker = syntax_malloc (sizeof (struct _syntax_marker)); edit->syntax_marker = g_malloc0 (sizeof (struct _syntax_marker));
edit->syntax_marker->next = s; edit->syntax_marker->next = s;
edit->syntax_marker->offset = i; edit->syntax_marker->offset = i;
edit->syntax_marker->rule = edit->rule; edit->syntax_marker->rule = edit->rule;
@ -377,7 +368,7 @@ static struct syntax_rule edit_get_rule (WEdit * edit, long byte_index)
break; break;
} }
s = edit->syntax_marker->next; s = edit->syntax_marker->next;
syntax_free (edit->syntax_marker); syntax_g_free (edit->syntax_marker);
edit->syntax_marker = s; edit->syntax_marker = s;
} }
} }
@ -411,7 +402,7 @@ static int read_one_line (char **line, FILE * f)
{ {
char *p; char *p;
int len = 256, c, r = 0, i = 0; int len = 256, c, r = 0, i = 0;
p = syntax_malloc (len); p = g_malloc0 (len);
for (;;) { for (;;) {
c = fgetc (f); c = fgetc (f);
@ -428,9 +419,9 @@ static int read_one_line (char **line, FILE * f)
} else { } else {
if (i >= len - 1) { if (i >= len - 1) {
char *q; char *q;
q = syntax_malloc (len * 2); q = g_malloc0 (len * 2);
memcpy (q, p, len); memcpy (q, p, len);
syntax_free (p); syntax_g_free (p);
p = q; p = q;
len *= 2; len *= 2;
} }
@ -603,7 +594,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
strcpy (whole_left, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_01234567890"); strcpy (whole_left, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_01234567890");
strcpy (whole_right, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_01234567890"); strcpy (whole_right, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_01234567890");
r = edit->rules = syntax_malloc (MAX_CONTEXTS * sizeof (struct context_rule *)); r = edit->rules = g_malloc0 (MAX_CONTEXTS * sizeof (struct context_rule *));
for (;;) { for (;;) {
char **a; char **a;
@ -617,7 +608,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
line = save_line + 1; line = save_line + 1;
syntax_g_free (error_file_name); syntax_g_free (error_file_name);
if (l) if (l)
syntax_free (l); syntax_g_free (l);
if (!read_one_line (&l, f)) if (!read_one_line (&l, f))
break; break;
} else { } else {
@ -663,12 +654,12 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
break_a; break_a;
} }
a++; a++;
c = r[0] = syntax_malloc (sizeof (struct context_rule)); c = r[0] = g_malloc0 (sizeof (struct context_rule));
c->left = (char *) strdup (" "); c->left = g_strdup (" ");
c->right = (char *) strdup (" "); c->right = g_strdup (" ");
num_contexts = 0; num_contexts = 0;
} else { } else {
c = r[num_contexts] = syntax_malloc (sizeof (struct context_rule)); c = r[num_contexts] = g_malloc0 (sizeof (struct context_rule));
if (!strcmp (*a, "exclusive")) { if (!strcmp (*a, "exclusive")) {
a++; a++;
c->between_delimiters = 1; c->between_delimiters = 1;
@ -676,14 +667,14 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
check_a; check_a;
if (!strcmp (*a, "whole")) { if (!strcmp (*a, "whole")) {
a++; a++;
c->whole_word_chars_left = (char *) strdup (whole_left); c->whole_word_chars_left = g_strdup (whole_left);
c->whole_word_chars_right = (char *) strdup (whole_right); c->whole_word_chars_right = g_strdup (whole_right);
} else if (!strcmp (*a, "wholeleft")) { } else if (!strcmp (*a, "wholeleft")) {
a++; a++;
c->whole_word_chars_left = (char *) strdup (whole_left); c->whole_word_chars_left = g_strdup (whole_left);
} else if (!strcmp (*a, "wholeright")) { } else if (!strcmp (*a, "wholeright")) {
a++; a++;
c->whole_word_chars_right = (char *) strdup (whole_right); c->whole_word_chars_right = g_strdup (whole_right);
} }
check_a; check_a;
if (!strcmp (*a, "linestart")) { if (!strcmp (*a, "linestart")) {
@ -691,23 +682,23 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
c->line_start_left = 1; c->line_start_left = 1;
} }
check_a; check_a;
c->left = (char *) strdup (*a++); c->left = g_strdup (*a++);
check_a; check_a;
if (!strcmp (*a, "linestart")) { if (!strcmp (*a, "linestart")) {
a++; a++;
c->line_start_right = 1; c->line_start_right = 1;
} }
check_a; check_a;
c->right = (char *) strdup (*a++); c->right = g_strdup (*a++);
c->first_left = *c->left; c->first_left = *c->left;
c->first_right = *c->right; c->first_right = *c->right;
} }
c->keyword = syntax_malloc (MAX_WORDS_PER_CONTEXT * sizeof (struct key_word *)); c->keyword = g_malloc0 (MAX_WORDS_PER_CONTEXT * sizeof (struct key_word *));
#if 0 #if 0
c->max_words = MAX_WORDS_PER_CONTEXT; c->max_words = MAX_WORDS_PER_CONTEXT;
#endif #endif
num_words = 1; num_words = 1;
c->keyword[0] = syntax_malloc (sizeof (struct key_word)); c->keyword[0] = g_malloc0 (sizeof (struct key_word));
fg = *a; fg = *a;
if (*a) if (*a)
a++; a++;
@ -717,7 +708,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
strcpy (last_fg, fg ? fg : ""); strcpy (last_fg, fg ? fg : "");
strcpy (last_bg, bg ? bg : ""); strcpy (last_bg, bg ? bg : "");
c->keyword[0]->color = this_try_alloc_color_pair (fg, bg); c->keyword[0]->color = this_try_alloc_color_pair (fg, bg);
c->keyword[0]->keyword = (char *) strdup (" "); c->keyword[0]->keyword = g_strdup (" ");
check_not_a; check_not_a;
num_contexts++; num_contexts++;
} else if (!strcmp (args[0], "spellcheck")) { } else if (!strcmp (args[0], "spellcheck")) {
@ -731,17 +722,17 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
if (num_words == -1) if (num_words == -1)
break_a; break_a;
check_a; check_a;
k = r[num_contexts - 1]->keyword[num_words] = syntax_malloc (sizeof (struct key_word)); k = r[num_contexts - 1]->keyword[num_words] = g_malloc0 (sizeof (struct key_word));
if (!strcmp (*a, "whole")) { if (!strcmp (*a, "whole")) {
a++; a++;
k->whole_word_chars_left = (char *) strdup (whole_left); k->whole_word_chars_left = g_strdup (whole_left);
k->whole_word_chars_right = (char *) strdup (whole_right); k->whole_word_chars_right = g_strdup (whole_right);
} else if (!strcmp (*a, "wholeleft")) { } else if (!strcmp (*a, "wholeleft")) {
a++; a++;
k->whole_word_chars_left = (char *) strdup (whole_left); k->whole_word_chars_left = g_strdup (whole_left);
} else if (!strcmp (*a, "wholeright")) { } else if (!strcmp (*a, "wholeright")) {
a++; a++;
k->whole_word_chars_right = (char *) strdup (whole_right); k->whole_word_chars_right = g_strdup (whole_right);
} }
check_a; check_a;
if (!strcmp (*a, "linestart")) { if (!strcmp (*a, "linestart")) {
@ -752,7 +743,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
if (!strcmp (*a, "whole")) { if (!strcmp (*a, "whole")) {
break_a; break_a;
} }
k->keyword = (char *) strdup (*a++); k->keyword = g_strdup (*a++);
k->first = *k->keyword; k->first = *k->keyword;
fg = *a; fg = *a;
if (*a) if (*a)
@ -775,13 +766,13 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
break_a; break_a;
} }
free_args (args); free_args (args);
syntax_free (l); syntax_g_free (l);
} }
free_args (args); free_args (args);
syntax_free (l); syntax_g_free (l);
if (!edit->rules[0]) if (!edit->rules[0])
syntax_free (edit->rules); syntax_g_free (edit->rules);
if (result) if (result)
return result; return result;
@ -800,7 +791,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
for (j = 1; c->keyword[j]; j++) for (j = 1; c->keyword[j]; j++)
*p++ = c->keyword[j]->first; *p++ = c->keyword[j]->first;
*p = '\0'; *p = '\0';
c->keyword_first_chars = syntax_malloc (strlen (first_chars) + 2); c->keyword_first_chars = g_malloc0 (strlen (first_chars) + 2);
strcpy (c->keyword_first_chars, first_chars); strcpy (c->keyword_first_chars, first_chars);
} }
} }
@ -816,31 +807,31 @@ void edit_free_syntax_rules (WEdit * edit)
if (!edit->rules) if (!edit->rules)
return; return;
edit_get_rule (edit, -1); edit_get_rule (edit, -1);
syntax_free (edit->syntax_type); syntax_g_free (edit->syntax_type);
edit->syntax_type = 0; edit->syntax_type = 0;
for (i = 0; edit->rules[i]; i++) { for (i = 0; edit->rules[i]; i++) {
if (edit->rules[i]->keyword) { if (edit->rules[i]->keyword) {
for (j = 0; edit->rules[i]->keyword[j]; j++) { for (j = 0; edit->rules[i]->keyword[j]; j++) {
syntax_free (edit->rules[i]->keyword[j]->keyword); syntax_g_free (edit->rules[i]->keyword[j]->keyword);
syntax_free (edit->rules[i]->keyword[j]->whole_word_chars_left); syntax_g_free (edit->rules[i]->keyword[j]->whole_word_chars_left);
syntax_free (edit->rules[i]->keyword[j]->whole_word_chars_right); syntax_g_free (edit->rules[i]->keyword[j]->whole_word_chars_right);
syntax_free (edit->rules[i]->keyword[j]); syntax_g_free (edit->rules[i]->keyword[j]);
} }
} }
syntax_free (edit->rules[i]->left); syntax_g_free (edit->rules[i]->left);
syntax_free (edit->rules[i]->right); syntax_g_free (edit->rules[i]->right);
syntax_free (edit->rules[i]->whole_word_chars_left); syntax_g_free (edit->rules[i]->whole_word_chars_left);
syntax_free (edit->rules[i]->whole_word_chars_right); syntax_g_free (edit->rules[i]->whole_word_chars_right);
syntax_free (edit->rules[i]->keyword); syntax_g_free (edit->rules[i]->keyword);
syntax_free (edit->rules[i]->keyword_first_chars); syntax_g_free (edit->rules[i]->keyword_first_chars);
syntax_free (edit->rules[i]); syntax_g_free (edit->rules[i]);
} }
while (edit->syntax_marker) { while (edit->syntax_marker) {
struct _syntax_marker *s = edit->syntax_marker->next; struct _syntax_marker *s = edit->syntax_marker->next;
syntax_free (edit->syntax_marker); syntax_g_free (edit->syntax_marker);
edit->syntax_marker = s; edit->syntax_marker = s;
} }
syntax_free (edit->rules); syntax_g_free (edit->rules);
} }
/* returns -1 on file error, line number on error in file syntax */ /* returns -1 on file error, line number on error in file syntax */
@ -867,7 +858,7 @@ static int edit_read_syntax_file (WEdit * edit, char **names, char *syntax_file,
args[0] = 0; args[0] = 0;
for (;;) { for (;;) {
line++; line++;
syntax_free (l); syntax_g_free (l);
if (!read_one_line (&l, f)) if (!read_one_line (&l, f))
break; break;
get_args (l, args, &argc); get_args (l, args, &argc);
@ -885,7 +876,7 @@ static int edit_read_syntax_file (WEdit * edit, char **names, char *syntax_file,
} }
if (names) { if (names) {
/* 1: just collecting a list of names of rule sets */ /* 1: just collecting a list of names of rule sets */
names[count++] = (char *) strdup (args[2]); names[count++] = g_strdup (args[2]);
names[count] = 0; names[count] = 0;
} else if (type) { } else if (type) {
/* 2: rule set was explicitly specified by the caller */ /* 2: rule set was explicitly specified by the caller */
@ -920,8 +911,8 @@ static int edit_read_syntax_file (WEdit * edit, char **names, char *syntax_file,
else else
result = line_error; result = line_error;
} else { } else {
syntax_free (edit->syntax_type); syntax_g_free (edit->syntax_type);
edit->syntax_type = (char *) strdup (args[2]); edit->syntax_type = g_strdup (args[2]);
/* if there are no rules then turn off syntax highlighting for speed */ /* if there are no rules then turn off syntax highlighting for speed */
if (!edit->rules[1]) if (!edit->rules[1])
if (!edit->rules[0]->keyword[1] && !edit->rules[0]->spelling) { if (!edit->rules[0]->keyword[1] && !edit->rules[0]->spelling) {
@ -935,7 +926,7 @@ static int edit_read_syntax_file (WEdit * edit, char **names, char *syntax_file,
free_args (args); free_args (args);
} }
free_args (args); free_args (args);
syntax_free (l); syntax_g_free (l);
fclose (f); fclose (f);
return result; return result;
} }

View File

@ -115,13 +115,15 @@ end_paragraph (WEdit *edit, int force)
i - edit->curs_line, 0)); i - edit->curs_line, 0));
} }
static unsigned 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)
{ {
unsigned char *s, *t; unsigned char *s, *t;
#if 0 #if 0
t = malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length + 10); t = g_malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length +
10);
#else #else
t = malloc (2 * (q - p) + 100); t = g_malloc (2 * (q - p) + 100);
#endif #endif
if (!t) if (!t)
return 0; return 0;
@ -307,7 +309,8 @@ static int test_indent (WEdit * edit, long p, long q)
return indent; return indent;
} }
void format_paragraph (WEdit * edit, int force) void
format_paragraph (WEdit *edit, int force)
{ {
long p, q; long p, q;
int size; int size;
@ -326,13 +329,13 @@ void format_paragraph (WEdit * edit, int force)
if (!force) { if (!force) {
int i; int i;
if (strchr (NO_FORMAT_CHARS_START, *t)) { if (strchr (NO_FORMAT_CHARS_START, *t)) {
free (t); g_free (t);
return; return;
} }
for (i = 0; i < size - 1; i++) { for (i = 0; i < size - 1; i++) {
if (t[i] == '\n') { if (t[i] == '\n') {
if (strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1])) { if (strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1])) {
free (t); g_free (t);
return; return;
} }
} }
@ -340,8 +343,8 @@ void format_paragraph (WEdit * edit, int force)
} }
format_this (t, q - p, indent); format_this (t, q - p, indent);
put_paragraph (edit, t, p, q, indent, size); put_paragraph (edit, t, p, q, indent, size);
free (t); g_free (t);
/* Scroll left as much as possible to show the formatted paragraph */ /* Scroll left as much as possible to show the formatted paragraph */
edit_scroll_left(edit, - edit->start_col); edit_scroll_left (edit, -edit->start_col);
} }