1
1

Code indentation in src/editor directory

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
Slava Zanko 2010-11-10 20:30:23 +02:00 коммит произвёл Andrew Borodin
родитель 61345bd8e2
Коммит cb4bdfa00d
18 изменённых файлов: 3700 добавлений и 2885 удалений

Просмотреть файл

@ -44,7 +44,18 @@
#include "edit-widget.h"
/* note, if there is more than one bookmark on a line, then they are
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/** note, if there is more than one bookmark on a line, then they are
appended after each other and the last one is always the one found
by book_mark_found() i.e. last in is the one seen */
@ -59,7 +70,9 @@ double_marks (WEdit * edit, struct _book_mark *p)
return p;
}
/* returns the first bookmark on or before this line */
/* --------------------------------------------------------------------------------------------- */
/** returns the first bookmark on or before this line */
struct _book_mark *
book_mark_find (WEdit * edit, int line)
{
@ -96,7 +109,7 @@ book_mark_find (WEdit * edit, int line)
for (p = edit->book_mark; p != NULL; p = p->prev)
{
if (p->next != NULL && p->next->line <= line)
break; /* gone past it going upward */
break; /* gone past it going upward */
if (p->line <= line)
{
@ -116,10 +129,15 @@ book_mark_find (WEdit * edit, int line)
}
}
return NULL; /* can't get here */
return NULL; /* can't get here */
}
/* returns true if a bookmark exists at this line of color c */
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/** returns true if a bookmark exists at this line of color c */
int
book_mark_query_color (WEdit * edit, int line, int c)
{
@ -138,7 +156,9 @@ book_mark_query_color (WEdit * edit, int line, int c)
return 0;
}
/* insert a bookmark at this line */
/* --------------------------------------------------------------------------------------------- */
/** insert a bookmark at this line */
void
book_mark_insert (WEdit * edit, size_t line, int c)
{
@ -170,8 +190,11 @@ book_mark_insert (WEdit * edit, size_t line, int c)
p->next = q;
}
/* remove a bookmark if there is one at this line matching this color - c of -1 clear all */
/* returns non-zero on not-found */
/* --------------------------------------------------------------------------------------------- */
/** remove a bookmark if there is one at this line matching this color - c of -1 clear all
* @returns non-zero on not-found
*/
int
book_mark_clear (WEdit * edit, int line, int c)
{
@ -205,7 +228,9 @@ book_mark_clear (WEdit * edit, int line, int c)
return r;
}
/* clear all bookmarks matching this color, if c is -1 clears all */
/* --------------------------------------------------------------------------------------------- */
/** clear all bookmarks matching this color, if c is -1 clears all */
void
book_mark_flush (WEdit * edit, int c)
{
@ -237,7 +262,9 @@ book_mark_flush (WEdit * edit, int c)
edit->force |= REDRAW_PAGE;
}
/* shift down bookmarks after this line */
/* --------------------------------------------------------------------------------------------- */
/** shift down bookmarks after this line */
void
book_mark_inc (WEdit * edit, int line)
{
@ -250,7 +277,9 @@ book_mark_inc (WEdit * edit, int line)
}
}
/* shift up bookmarks after this line */
/* --------------------------------------------------------------------------------------------- */
/** shift up bookmarks after this line */
void
book_mark_dec (WEdit * edit, int line)
{
@ -263,7 +292,9 @@ book_mark_dec (WEdit * edit, int line)
}
}
/* prepare line positions of bookmarks to be saved to file */
/* --------------------------------------------------------------------------------------------- */
/** prepare line positions of bookmarks to be saved to file */
void
book_mark_serialize (WEdit * edit, int color)
{
@ -284,7 +315,9 @@ book_mark_serialize (WEdit * edit, int color)
}
}
/* restore bookmarks from saved line positions */
/* --------------------------------------------------------------------------------------------- */
/** restore bookmarks from saved line positions */
void
book_mark_restore (WEdit * edit, int color)
{
@ -296,3 +329,5 @@ book_mark_restore (WEdit * edit, int color)
book_mark_insert (edit, g_array_index (edit->serialized_bookmarks, size_t, i), color);
}
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -33,16 +33,29 @@
#include "edit-impl.h"
#include "edit-widget.h"
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
#define MAX_ENTRY_LEN 40
#define LIST_LINES 14
#define N_DFLT_ENTRIES 2
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static int
pstrcmp (const void *p1, const void *p2)
{
return strcmp (*(char **) p1, *(char **) p2);
}
/* --------------------------------------------------------------------------------------------- */
static int
exec_edit_syntax_dialog (const char **names, const char *current_syntax)
{
@ -63,6 +76,10 @@ exec_edit_syntax_dialog (const char **names, const char *current_syntax)
return run_listbox (syntaxlist);
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
edit_syntax_dialog (WEdit * edit)
{
@ -112,3 +129,5 @@ edit_syntax_dialog (WEdit * edit)
g_strfreev (names);
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -27,8 +27,8 @@
* \date 1996, 1997
*/
#ifndef MC_EDIT_IMPL_H
#define MC_EDIT_IMPL_H
#ifndef MC__EDIT_IMPL_H
#define MC__EDIT_IMPL_H
#include <stdio.h>
@ -36,6 +36,8 @@
#include "src/dialog.h" /* cb_ret_t */
#include "src/editor/edit.h"
/*** typedefs(not structures) and defined constants **********************************************/
#define SEARCH_DIALOG_OPTION_NO_SCANF (1 << 0)
#define SEARCH_DIALOG_OPTION_NO_REGEX (1 << 1)
#define SEARCH_DIALOG_OPTION_NO_CASE (1 << 2)
@ -116,6 +118,51 @@
#define MAX_HISTORY_MOVETO 50
#define LINE_STATE_WIDTH 8
#define LB_NAMES (LB_MAC + 1)
#define get_sys_error(s) (s)
#define edit_error_dialog(h,s) query_dialog (h, s, D_ERROR, 1, _("&Dismiss"))
#define edit_query_dialog2(h,t,a,b) query_dialog (h, t, D_NORMAL, 2, a, b)
#define edit_query_dialog3(h,t,a,b,c) query_dialog (h, t, D_NORMAL, 3, a, b, c)
#ifndef MAX_PATH_LEN
#ifdef PATH_MAX
#define MAX_PATH_LEN PATH_MAX
#else
#define MAX_PATH_LEN 1024
#endif
#endif
/*** enums ***************************************************************************************/
/* type for file which is currently being edited */
typedef enum
{
EDIT_FILE_COMMON = 0,
EDIT_FILE_SYNTAX = 1,
EDIT_FILE_MENU = 2
} edit_current_file_t;
/* line breaks */
typedef enum
{
LB_ASIS = 0,
LB_UNIX,
LB_WIN,
LB_MAC
} LineBreaks;
typedef enum
{
EDIT_QUICK_SAVE = 0,
EDIT_SAFE_SAVE,
EDIT_DO_BACKUP
} edit_save_mode_t;
/*** structures declarations (and typedefs of structures)*****************************************/
/* search/replace options */
typedef struct edit_search_options_t
{
@ -139,30 +186,35 @@ struct macro
int ch;
};
/* type for file which is currently being edited */
typedef enum
{
EDIT_FILE_COMMON = 0,
EDIT_FILE_SYNTAX = 1,
EDIT_FILE_MENU = 2
} edit_current_file_t;
/* line breaks */
typedef enum
{
LB_ASIS = 0,
LB_UNIX,
LB_WIN,
LB_MAC
} LineBreaks;
#define LB_NAMES (LB_MAC + 1)
struct Widget;
struct WMenuBar;
/*** global variables defined in .c file *********************************************************/
extern const char VERTICAL_MAGIC[5];
/* if enable_show_tabs_tws ==1 then use visible_tab visible_tws */
extern int enable_show_tabs_tws;
extern edit_search_options_t edit_search_options;
extern int edit_stack_iterator;
extern edit_stack_type edit_history_moveto[MAX_HISTORY_MOVETO];
extern int option_line_state_width;
extern int option_max_undo;
extern int option_auto_syntax;
extern int option_edit_right_extreme;
extern int option_edit_left_extreme;
extern int option_edit_top_extreme;
extern int option_edit_bottom_extreme;
extern const char *option_whole_chars_search;
extern gboolean search_create_bookmark;
/*** declarations of public functions ************************************************************/
int edit_drop_hotkey_menu (WEdit * e, int key);
void edit_menu_cmd (WEdit * e);
void edit_init_menu (struct WMenuBar *menubar);
@ -193,7 +245,7 @@ void edit_update_curs_row (WEdit * edit);
void edit_update_curs_col (WEdit * edit);
void edit_find_bracket (WEdit * edit);
int edit_reload_line (WEdit * edit, const char *filename, long line);
void edit_set_codeset (WEdit *edit);
void edit_set_codeset (WEdit * edit);
void edit_block_copy_cmd (WEdit * edit);
void edit_block_move_cmd (WEdit * edit);
@ -298,44 +350,6 @@ unsigned int edit_lock_file (WEdit * edit);
/* either command or char_for_insertion must be passed as -1 */
void edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion);
#define get_sys_error(s) (s)
/*** inline functions ****************************************************************************/
#define edit_error_dialog(h,s) query_dialog (h, s, D_ERROR, 1, _("&Dismiss"))
#define edit_query_dialog2(h,t,a,b) query_dialog (h, t, D_NORMAL, 2, a, b)
#define edit_query_dialog3(h,t,a,b,c) query_dialog (h, t, D_NORMAL, 3, a, b, c)
#ifndef MAX_PATH_LEN
#ifdef PATH_MAX
#define MAX_PATH_LEN PATH_MAX
#else
#define MAX_PATH_LEN 1024
#endif
#endif
extern edit_search_options_t edit_search_options;
extern int edit_stack_iterator;
extern edit_stack_type edit_history_moveto[MAX_HISTORY_MOVETO];
extern int option_line_state_width;
typedef enum
{
EDIT_QUICK_SAVE = 0,
EDIT_SAFE_SAVE,
EDIT_DO_BACKUP
} edit_save_mode_t;
extern int option_max_undo;
extern int option_auto_syntax;
extern int option_edit_right_extreme;
extern int option_edit_left_extreme;
extern int option_edit_top_extreme;
extern int option_edit_bottom_extreme;
extern const char *option_whole_chars_search;
extern gboolean search_create_bookmark;
#endif /* MC_EDIT_IMPL_H */
#endif /* MC__EDIT_IMPL_H */

Просмотреть файл

@ -1,19 +1,24 @@
/** \file
* \brief Header: editor widget WEdit
*/
#ifndef MC_EDIT_WIDGET_H
#define MC_EDIT_WIDGET_H
#ifndef MC__EDIT_WIDGET_H
#define MC__EDIT_WIDGET_H
#include "src/dialog.h" /* Widget */
#include "lib/search.h" /* mc_search_t */
#include "edit-impl.h"
/*** typedefs(not structures) and defined constants **********************************************/
#define MAX_MACRO_LENGTH 1024
#define N_LINE_CACHES 32
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
struct _book_mark
{
int line; /* line number */
@ -107,7 +112,7 @@ struct WEdit
unsigned long stack_bottom;
unsigned int stack_disable:1; /* If not 0, don't save events in the undo stack */
struct stat stat1; /* Result of mc_fstat() on the file */
struct stat stat1; /* Result of mc_fstat() on the file */
unsigned int skip_detach_prompt:1; /* Do not prompt whether to detach a file anymore */
/* syntax higlighting */
@ -115,13 +120,13 @@ struct WEdit
struct context_rule **rules;
long last_get_rule;
struct syntax_rule rule;
char *syntax_type; /* description of syntax highlighting type being used */
GTree *defines; /* List of defines */
char *syntax_type; /* description of syntax highlighting type being used */
GTree *defines; /* List of defines */
gboolean is_case_insensitive; /* selects language case sensitivity */
/* macro stuff */
int macro_i; /* index to macro[], -1 if not recording a macro */
int macro_depth; /* depth of the macro recursion */
int macro_i; /* index to macro[], -1 if not recording a macro */
int macro_depth; /* depth of the macro recursion */
struct macro macro[MAX_MACRO_LENGTH];
/* user map stuff */
@ -135,4 +140,9 @@ struct WEdit
};
#endif /* MC_EDIT_WIDGET_H */
/*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/
/*** inline functions ****************************************************************************/
#endif /* MC__EDIT_WIDGET_H */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -3,7 +3,7 @@
Copyright (C) 1996, 1997, 2009 Free Software Foundation, Inc.
Authors: 1996, 1997 Paul Sheer
2009 Andrew Borodin
2009 Andrew Borodin
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -19,7 +19,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
*/
/** \file edit.h
* \brief Header: editor public API
@ -29,17 +29,25 @@
* \date 2009
*/
#ifndef MC_EDIT_H
#define MC_EDIT_H
#ifndef MC__EDIT_H
#define MC__EDIT_H
#include "lib/global.h" /* PATH_SEP_STR */
#include "lib/global.h" /* PATH_SEP_STR */
#include "lib/fileloc.h"
/*** typedefs(not structures) and defined constants **********************************************/
#define DEFAULT_WRAP_LINE_LENGTH 72
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
/* Editor widget */
struct WEdit;
typedef struct WEdit WEdit;
#define DEFAULT_WRAP_LINE_LENGTH 72
/*** global variables defined in .c file *********************************************************/
extern int option_word_wrap_line_length;
extern int option_typewriter_wrap;
@ -65,14 +73,17 @@ extern int simple_statusbar;
extern int option_check_nl_at_eof;
extern int show_right_margin;
/*** declarations of public functions ************************************************************/
/* used in main() */
void edit_stack_init (void);
void edit_stack_free (void);
int edit_file (const char *_file, int line);
const char *edit_get_file_name (const WEdit *edit);
int edit_get_curs_col (const WEdit *edit);
const char *edit_get_syntax_type (const WEdit *edit);
const char *edit_get_file_name (const WEdit * edit);
int edit_get_curs_col (const WEdit * edit);
const char *edit_get_syntax_type (const WEdit * edit);
#endif /* MC_EDIT_H */
/*** inline functions ****************************************************************************/
#endif /* MC__EDIT_H */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -44,8 +44,7 @@
#include "src/editor/etags.h"
#include "src/editor/editcmd_dialogs.h"
/*** global variables **************************************************/
/*** global variables ****************************************************************************/
edit_search_options_t edit_search_options = {
.type = MC_SEARCH_T_NORMAL,
@ -56,7 +55,7 @@ edit_search_options_t edit_search_options = {
.all_codepages = FALSE
};
/*** file scope macro definitions **************************************/
/*** file scope macro definitions ****************************************************************/
#define SEARCH_DLG_WIDTH 58
#define SEARCH_DLG_MIN_HEIGHT 13
@ -66,11 +65,12 @@ edit_search_options_t edit_search_options = {
#define REPLACE_DLG_MIN_HEIGHT 17
#define REPLACE_DLG_HEIGHT_SUPPLY 5
/*** file scope type declarations **************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables **********************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions **********************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static cb_ret_t
editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget * sender,
@ -87,7 +87,9 @@ editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget * sender,
}
}
/*** public functions **************************************************/
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default,
@ -330,7 +332,6 @@ editcmd_dialog_search_show (WEdit * edit)
}
/* --------------------------------------------------------------------------------------------- */
/* gets a raw key from the keyboard. Passing cancel = 1 draws
a cancel button thus allowing c-c etc. Alternatively, cancel = 0
will return the next key pressed. ctrl-a (=B_CANCEL), ctrl-g, ctrl-c,
@ -344,7 +345,7 @@ editcmd_dialog_raw_key_query (const char *heading, const char *query, int cancel
struct Dlg_head *raw_dlg =
create_dlg (TRUE, 0, 0, 7, w, dialog_colors, editcmd_dialog_raw_key_query_cb,
NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB);
add_widget (raw_dlg, input_new (3 - cancel, w - 5, input_get_default_colors(),
add_widget (raw_dlg, input_new (3 - cancel, w - 5, input_get_default_colors (),
2, "", 0, INPUT_COMPLETE_DEFAULT));
add_widget (raw_dlg, label_new (3 - cancel, 2, query));
if (cancel)
@ -361,8 +362,8 @@ editcmd_dialog_raw_key_query (const char *heading, const char *query, int cancel
}
/* --------------------------------------------------------------------------------------------- */
/* let the user select its preferred completion */
void
editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
struct selection *compl, int num_compl)
@ -447,8 +448,8 @@ editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
}
/* --------------------------------------------------------------------------------------------- */
/* let the user select where function definition */
void
editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_len, int word_len,
etags_hash_t * def_hash, int num_lines)

Просмотреть файл

@ -15,7 +15,8 @@ struct etags_hash_struct;
/*** structures declarations (and typedefs of structures)*****************************************/
struct selection {
struct selection
{
gchar *text;
gsize len;
};
@ -36,4 +37,5 @@ void editcmd_dialog_select_definition_show (WEdit *, char *, int, int, struct et
int);
int editcmd_dialog_replace_prompt_show (WEdit *, char *, char *, int, int);
#endif
/*** inline functions ****************************************************************************/
#endif /* MC__EDITCMD_DIALOGS_H */

Просмотреть файл

@ -52,6 +52,15 @@
#include "edit-impl.h"
#include "edit-widget.h"
/*** global variables ****************************************************************************/
/* Toggles statusbar draw style */
int simple_statusbar = 0;
int visible_tabs = 1, visible_tws = 1;
/*** file scope macro definitions ****************************************************************/
#define MAX_LINE_LEN 1024
/* Text styles */
@ -67,8 +76,23 @@
#define FONT_PIX_PER_LINE 1
#define FONT_MEAN_WIDTH 1
/* Toggles statusbar draw style */
int simple_statusbar = 0;
#define edit_move(x,y) widget_move(edit, y, x);
#define key_pending(x) (!is_idle())
/*** file scope type declarations ****************************************************************/
struct line_s
{
unsigned int ch;
unsigned int style;
};
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static inline void
status_string (WEdit * edit, char *s, int w)
@ -151,6 +175,8 @@ status_string (WEdit * edit, char *s, int w)
);
}
/* --------------------------------------------------------------------------------------------- */
static inline void
printwstr (const char *s, int len)
{
@ -158,124 +184,7 @@ printwstr (const char *s, int len)
tty_printf ("%-*.*s", len, len, s);
}
/* Draw the status line at the top of the widget. The size of the filename
* field varies depending on the width of the screen and the length of
* the filename. */
void
edit_status (WEdit * edit)
{
const int w = edit->widget.cols;
const size_t status_size = w + 1;
char *const status = g_malloc (status_size);
int status_len;
const char *fname = "";
int fname_len;
const int gap = 3; /* between the filename and the status */
const int right_gap = 5; /* at the right end of the screen */
const int preferred_fname_len = 16;
status_string (edit, status, status_size);
status_len = (int) str_term_width1 (status);
if (edit->filename)
fname = edit->filename;
fname_len = str_term_width1 (fname);
if (fname_len < preferred_fname_len)
fname_len = preferred_fname_len;
if (fname_len + gap + status_len + right_gap >= w)
{
if (preferred_fname_len + gap + status_len + right_gap >= w)
fname_len = preferred_fname_len;
else
fname_len = w - (gap + status_len + right_gap);
fname = str_trunc (fname, fname_len);
}
widget_move (edit, 0, 0);
tty_setcolor (STATUSBAR_COLOR);
printwstr (fname, fname_len + gap);
printwstr (status, w - (fname_len + gap));
if (simple_statusbar && edit->widget.cols > 30)
{
size_t percent;
if (edit->total_lines + 1 != 0)
percent = (edit->curs_line + 1) * 100 / (edit->total_lines + 1);
else
percent = 100;
widget_move (edit, 0, edit->widget.cols - 5);
tty_printf (" %3d%%", percent);
}
g_free (status);
}
/* this scrolls the text so that cursor is on the screen */
void
edit_scroll_screen_over_cursor (WEdit * edit)
{
int p;
int outby;
int b_extreme, t_extreme, l_extreme, r_extreme;
if (edit->num_widget_lines <= 0 || edit->num_widget_columns <= 0)
return;
edit->num_widget_columns -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
edit->num_widget_lines -= EDIT_TEXT_VERTICAL_OFFSET - 1;
r_extreme = EDIT_RIGHT_EXTREME;
l_extreme = EDIT_LEFT_EXTREME;
b_extreme = EDIT_BOTTOM_EXTREME;
t_extreme = EDIT_TOP_EXTREME;
if (edit->found_len)
{
b_extreme = max (edit->num_widget_lines / 4, b_extreme);
t_extreme = max (edit->num_widget_lines / 4, t_extreme);
}
if (b_extreme + t_extreme + 1 > edit->num_widget_lines)
{
int n;
n = b_extreme + t_extreme;
b_extreme = (b_extreme * (edit->num_widget_lines - 1)) / n;
t_extreme = (t_extreme * (edit->num_widget_lines - 1)) / n;
}
if (l_extreme + r_extreme + 1 > edit->num_widget_columns)
{
int n;
n = l_extreme + t_extreme;
l_extreme = (l_extreme * (edit->num_widget_columns - 1)) / n;
r_extreme = (r_extreme * (edit->num_widget_columns - 1)) / n;
}
p = edit_get_col (edit) + edit->over_col;
edit_update_curs_row (edit);
outby = p + edit->start_col - edit->num_widget_columns + 1 + (r_extreme + edit->found_len);
if (outby > 0)
edit_scroll_right (edit, outby);
outby = l_extreme - p - edit->start_col;
if (outby > 0)
edit_scroll_left (edit, outby);
p = edit->curs_row;
outby = p - edit->num_widget_lines + 1 + b_extreme;
if (outby > 0)
edit_scroll_downward (edit, outby);
outby = t_extreme - p;
if (outby > 0)
edit_scroll_upward (edit, outby);
edit_update_curs_row (edit);
edit->num_widget_lines += EDIT_TEXT_VERTICAL_OFFSET - 1;
edit->num_widget_columns += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
}
#define edit_move(x,y) widget_move(edit, y, x);
struct line_s
{
unsigned int ch;
unsigned int style;
};
/* --------------------------------------------------------------------------------------------- */
static inline void
print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
@ -391,9 +300,9 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
}
}
int visible_tabs = 1, visible_tws = 1;
/* --------------------------------------------------------------------------------------------- */
/** b is a pointer to the beginning of the line */
/* b is a pointer to the beginning of the line */
static void
edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_col)
{
@ -679,7 +588,7 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co
print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark);
}
#define key_pending(x) (!is_idle())
/* --------------------------------------------------------------------------------------------- */
static inline void
edit_draw_this_char (WEdit * edit, long curs, long row)
@ -688,7 +597,9 @@ edit_draw_this_char (WEdit * edit, long curs, long row)
edit_draw_this_line (edit, b, row, 0, edit->num_widget_columns - 1);
}
/* cursor must be in screen for other than REDRAW_PAGE passed in force */
/* --------------------------------------------------------------------------------------------- */
/** cursor must be in screen for other than REDRAW_PAGE passed in force */
static inline void
render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column)
{
@ -817,6 +728,8 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
edit->screen_modified = 0;
}
/* --------------------------------------------------------------------------------------------- */
static inline void
edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
{
@ -835,8 +748,128 @@ edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end,
edit->force |= REDRAW_PAGE;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/** Draw the status line at the top of the widget. The size of the filename
* field varies depending on the width of the screen and the length of
* the filename. */
void
edit_status (WEdit * edit)
{
const int w = edit->widget.cols;
const size_t status_size = w + 1;
char *const status = g_malloc (status_size);
int status_len;
const char *fname = "";
int fname_len;
const int gap = 3; /* between the filename and the status */
const int right_gap = 5; /* at the right end of the screen */
const int preferred_fname_len = 16;
status_string (edit, status, status_size);
status_len = (int) str_term_width1 (status);
if (edit->filename)
fname = edit->filename;
fname_len = str_term_width1 (fname);
if (fname_len < preferred_fname_len)
fname_len = preferred_fname_len;
if (fname_len + gap + status_len + right_gap >= w)
{
if (preferred_fname_len + gap + status_len + right_gap >= w)
fname_len = preferred_fname_len;
else
fname_len = w - (gap + status_len + right_gap);
fname = str_trunc (fname, fname_len);
}
widget_move (edit, 0, 0);
tty_setcolor (STATUSBAR_COLOR);
printwstr (fname, fname_len + gap);
printwstr (status, w - (fname_len + gap));
if (simple_statusbar && edit->widget.cols > 30)
{
size_t percent;
if (edit->total_lines + 1 != 0)
percent = (edit->curs_line + 1) * 100 / (edit->total_lines + 1);
else
percent = 100;
widget_move (edit, 0, edit->widget.cols - 5);
tty_printf (" %3d%%", percent);
}
g_free (status);
}
/* --------------------------------------------------------------------------------------------- */
/** this scrolls the text so that cursor is on the screen */
void
edit_scroll_screen_over_cursor (WEdit * edit)
{
int p;
int outby;
int b_extreme, t_extreme, l_extreme, r_extreme;
if (edit->num_widget_lines <= 0 || edit->num_widget_columns <= 0)
return;
edit->num_widget_columns -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
edit->num_widget_lines -= EDIT_TEXT_VERTICAL_OFFSET - 1;
r_extreme = EDIT_RIGHT_EXTREME;
l_extreme = EDIT_LEFT_EXTREME;
b_extreme = EDIT_BOTTOM_EXTREME;
t_extreme = EDIT_TOP_EXTREME;
if (edit->found_len)
{
b_extreme = max (edit->num_widget_lines / 4, b_extreme);
t_extreme = max (edit->num_widget_lines / 4, t_extreme);
}
if (b_extreme + t_extreme + 1 > edit->num_widget_lines)
{
int n;
n = b_extreme + t_extreme;
b_extreme = (b_extreme * (edit->num_widget_lines - 1)) / n;
t_extreme = (t_extreme * (edit->num_widget_lines - 1)) / n;
}
if (l_extreme + r_extreme + 1 > edit->num_widget_columns)
{
int n;
n = l_extreme + t_extreme;
l_extreme = (l_extreme * (edit->num_widget_columns - 1)) / n;
r_extreme = (r_extreme * (edit->num_widget_columns - 1)) / n;
}
p = edit_get_col (edit) + edit->over_col;
edit_update_curs_row (edit);
outby = p + edit->start_col - edit->num_widget_columns + 1 + (r_extreme + edit->found_len);
if (outby > 0)
edit_scroll_right (edit, outby);
outby = l_extreme - p - edit->start_col;
if (outby > 0)
edit_scroll_left (edit, outby);
p = edit->curs_row;
outby = p - edit->num_widget_lines + 1 + b_extreme;
if (outby > 0)
edit_scroll_downward (edit, outby);
outby = t_extreme - p;
if (outby > 0)
edit_scroll_upward (edit, outby);
edit_update_curs_row (edit);
edit->num_widget_lines += EDIT_TEXT_VERTICAL_OFFSET - 1;
edit->num_widget_columns += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
}
/* --------------------------------------------------------------------------------------------- */
void
edit_render_keypress (WEdit * edit)
{
edit_render (edit, 0, 0, 0, 0, 0);
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -19,7 +19,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
*/
/** \file
* \brief Source: editor key translation
@ -40,94 +40,133 @@
#include <stdlib.h>
#include "lib/global.h"
#include "lib/tty/tty.h" /* keys */
#include "lib/tty/key.h" /* KEY_M_SHIFT */
#include "lib/strutil.h" /* str_isutf8 () */
#include "lib/tty/tty.h" /* keys */
#include "lib/tty/key.h" /* KEY_M_SHIFT */
#include "lib/strutil.h" /* str_isutf8 () */
#include "edit-impl.h"
#include "edit-widget.h" /* edit->macro_i */
#include "edit-widget.h" /* edit->macro_i */
#include "editcmd_dialogs.h"
#include "src/cmddef.h" /* list of commands */
#include "src/keybind.h" /* lookup_keymap_command() */
#include "src/charsets.h" /* convert_from_input_c() */
#include "src/main.h" /* display_codepage */
#include "src/cmddef.h" /* list of commands */
#include "src/keybind.h" /* lookup_keymap_command() */
#include "src/charsets.h" /* convert_from_input_c() */
#include "src/main.h" /* display_codepage */
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/*
* Translate the keycode into either 'command' or 'char_for_insertion'.
* 'command' is one of the editor commands from cmddef.h.
*/
int
edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch)
{
unsigned long command = (unsigned long) CK_Insert_Char;
int char_for_insertion = -1;
int c;
/* an ordinary insertable character */
if (x_key < 256) {
if (x_key < 256)
{
#ifdef HAVE_CHARSET
if ( edit->charpoint >= 4 ) {
if (edit->charpoint >= 4)
{
edit->charpoint = 0;
edit->charbuf[edit->charpoint] = '\0';
}
if ( edit->charpoint < 4 ) {
if (edit->charpoint < 4)
{
edit->charbuf[edit->charpoint++] = x_key;
edit->charbuf[edit->charpoint] = '\0';
}
/* input from 8-bit locale */
if ( !utf8_display ) {
if (!utf8_display)
{
/* source in 8-bit codeset */
if (!edit->utf8) {
#endif /* HAVE_CHARSET */
if (!edit->utf8)
{
#endif /* HAVE_CHARSET */
c = convert_from_input_c (x_key);
if (is_printable (c)) {
if (is_printable (c))
{
char_for_insertion = c;
goto fin;
}
#ifdef HAVE_CHARSET
} else {
}
else
{
c = convert_from_input_c (x_key);
if (is_printable (c)) {
char_for_insertion = convert_from_8bit_to_utf_c2((unsigned char) x_key);
if (is_printable (c))
{
char_for_insertion = convert_from_8bit_to_utf_c2 ((unsigned char) x_key);
goto fin;
}
}
/* UTF-8 locale */
} else {
/* UTF-8 locale */
}
else
{
/* source in UTF-8 codeset */
if ( edit->utf8 ) {
if (edit->utf8)
{
int res = str_is_valid_char (edit->charbuf, edit->charpoint);
if (res < 0) {
if (res != -2) {
edit->charpoint = 0; /* broken multibyte char, skip */
if (res < 0)
{
if (res != -2)
{
edit->charpoint = 0; /* broken multibyte char, skip */
goto fin;
}
char_for_insertion = x_key;
goto fin;
} else {
edit->charbuf[edit->charpoint]='\0';
}
else
{
edit->charbuf[edit->charpoint] = '\0';
edit->charpoint = 0;
if ( g_unichar_isprint (g_utf8_get_char(edit->charbuf))) {
if (g_unichar_isprint (g_utf8_get_char (edit->charbuf)))
{
char_for_insertion = x_key;
goto fin;
}
}
/* 8-bit source */
} else {
/* 8-bit source */
}
else
{
int res = str_is_valid_char (edit->charbuf, edit->charpoint);
if (res < 0) {
if (res != -2) {
edit->charpoint = 0; /* broken multibyte char, skip */
if (res < 0)
{
if (res != -2)
{
edit->charpoint = 0; /* broken multibyte char, skip */
goto fin;
}
/* not finised multibyte input (in meddle multibyte utf-8 char) */
goto fin;
} else {
if ( g_unichar_isprint (g_utf8_get_char(edit->charbuf)) ) {
c = convert_from_utf_to_current ( edit->charbuf );
}
else
{
if (g_unichar_isprint (g_utf8_get_char (edit->charbuf)))
{
c = convert_from_utf_to_current (edit->charbuf);
edit->charbuf[0] = '\0';
edit->charpoint = 0;
char_for_insertion = c;
@ -139,22 +178,26 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
}
}
}
#endif /* HAVE_CHARSET */
#endif /* HAVE_CHARSET */
}
/* Commands specific to the key emulation */
if (edit->extmod) {
if (edit->extmod)
{
edit->extmod = 0;
command = lookup_keymap_command (editor_x_map, x_key);
} else
}
else
command = lookup_keymap_command (editor_map, x_key);
if (command == CK_Ignore_Key)
command = CK_Insert_Char;
fin:
*cmd = (int) command; /* FIXME */
*cmd = (int) command; /* FIXME */
*ch = char_for_insertion;
return (command == (unsigned long) CK_Insert_Char && char_for_insertion == -1) ? 0 : 1;
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -52,6 +52,17 @@
#include "edit-impl.h"
#include "edit-widget.h"
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static GList *
create_file_menu (void)
{
@ -75,6 +86,8 @@ create_file_menu (void)
return entries;
}
/* --------------------------------------------------------------------------------------------- */
static GList *
create_edit_menu (void)
{
@ -103,6 +116,8 @@ create_edit_menu (void)
return entries;
}
/* --------------------------------------------------------------------------------------------- */
static GList *
create_search_replace_menu (void)
{
@ -121,6 +136,8 @@ create_search_replace_menu (void)
return entries;
}
/* --------------------------------------------------------------------------------------------- */
static GList *
create_command_menu (void)
{
@ -132,7 +149,8 @@ create_command_menu (void)
entries =
g_list_append (entries, menu_entry_create (_("Go to matching &bracket"), CK_Match_Bracket));
entries =
g_list_append (entries, menu_entry_create (_("Toggle s&yntax highlighting"), CK_Toggle_Syntax));
g_list_append (entries,
menu_entry_create (_("Toggle s&yntax highlighting"), CK_Toggle_Syntax));
entries = g_list_append (entries, menu_separator_create ());
entries =
g_list_append (entries, menu_entry_create (_("&Find declaration"), CK_Find_Definition));
@ -164,6 +182,8 @@ create_command_menu (void)
return entries;
}
/* --------------------------------------------------------------------------------------------- */
static GList *
create_format_menu (void)
{
@ -183,6 +203,8 @@ create_format_menu (void)
return entries;
}
/* --------------------------------------------------------------------------------------------- */
static GList *
create_options_menu (void)
{
@ -202,6 +224,31 @@ create_options_menu (void)
return entries;
}
/* --------------------------------------------------------------------------------------------- */
static void
edit_drop_menu_cmd (WEdit * e, int which)
{
WMenuBar *menubar;
menubar = find_menubar (e->widget.owner);
if (!menubar->is_active)
{
menubar->is_active = TRUE;
menubar->is_dropped = (drop_menus != 0);
if (which >= 0)
menubar->selected = which;
menubar->previous_widget = dlg_get_current_widget_id (e->widget.owner);
dlg_select_widget (menubar);
}
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
edit_init_menu (struct WMenuBar *menubar)
{
@ -222,24 +269,7 @@ edit_init_menu (struct WMenuBar *menubar)
"[Internal File Editor]"));
}
static void
edit_drop_menu_cmd (WEdit * e, int which)
{
WMenuBar *menubar;
menubar = find_menubar (e->widget.owner);
if (!menubar->is_active)
{
menubar->is_active = TRUE;
menubar->is_dropped = (drop_menus != 0);
if (which >= 0)
menubar->selected = which;
menubar->previous_widget = dlg_get_current_widget_id (e->widget.owner);
dlg_select_widget (menubar);
}
}
/* --------------------------------------------------------------------------------------------- */
void
edit_menu_cmd (WEdit * e)
@ -247,6 +277,8 @@ edit_menu_cmd (WEdit * e)
edit_drop_menu_cmd (e, -1);
}
/* --------------------------------------------------------------------------------------------- */
int
edit_drop_hotkey_menu (WEdit * e, int key)
{
@ -278,3 +310,5 @@ edit_drop_hotkey_menu (WEdit * e, int key)
edit_drop_menu_cmd (e, m);
return 1;
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -39,9 +39,17 @@
#include "src/wtools.h" /* QuickDialog */
#include "src/setup.h" /* option_tab_spacing */
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
#define OPT_DLG_H 16
#define OPT_DLG_W 74
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
static const char *wrap_str[] = {
N_("None"),
N_("Dynamic paragraphing"),
@ -49,6 +57,9 @@ static const char *wrap_str[] = {
NULL
};
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
#ifdef ENABLE_NLS
static void
i18n_translate_array (const char *array[])
@ -61,6 +72,10 @@ i18n_translate_array (const char *array[])
}
#endif /* ENABLE_NLS */
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
edit_options_dialog (WEdit * edit)
{
@ -174,3 +189,5 @@ edit_options_dialog (WEdit * edit)
if (option_syntax_highlighting != old_syntax_hl)
edit_load_syntax (edit, NULL, edit->syntax_type);
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -54,7 +54,20 @@
#include "src/cmddef.h"
#include "src/keybind.h"
static cb_ret_t edit_callback (Widget *, widget_msg_t msg, int parm);
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
static cb_ret_t edit_callback (Widget * w, widget_msg_t msg, int parm);
/* --------------------------------------------------------------------------------------------- */
static char *
edit_get_shortcut (unsigned long command)
@ -75,8 +88,10 @@ edit_get_shortcut (unsigned long command)
return NULL;
}
/* --------------------------------------------------------------------------------------------- */
static char *
edit_get_title (const Dlg_head *h, size_t len)
edit_get_title (const Dlg_head * h, size_t len)
{
const WEdit *edit = (const WEdit *) find_widget_type (h, edit_callback);
const char *modified = edit->modified ? "(*) " : " ";
@ -89,6 +104,8 @@ edit_get_title (const Dlg_head *h, size_t len)
return g_strconcat (_("Edit: "), modified, file_label, (char *) NULL);
}
/* --------------------------------------------------------------------------------------------- */
static int
edit_event (Gpm_Event * event, void *data)
{
@ -182,6 +199,8 @@ edit_event (Gpm_Event * event, void *data)
return MOU_NORMAL;
}
/* --------------------------------------------------------------------------------------------- */
static cb_ret_t
edit_command_execute (WEdit * edit, unsigned long command)
{
@ -195,6 +214,8 @@ edit_command_execute (WEdit * edit, unsigned long command)
return MSG_HANDLED;
}
/* --------------------------------------------------------------------------------------------- */
static inline void
edit_set_buttonbar (WEdit * edit, WButtonBar * bb)
{
@ -210,7 +231,9 @@ edit_set_buttonbar (WEdit * edit, WButtonBar * bb)
buttonbar_set_label (bb, 10, Q_ ("ButtonBar|Quit"), editor_map, (Widget *) edit);
}
/* Callback for the edit dialog */
/* --------------------------------------------------------------------------------------------- */
/** Callback for the edit dialog */
static cb_ret_t
edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
{
@ -253,77 +276,7 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo
}
}
int
edit_file (const char *_file, int line)
{
static gboolean made_directory = FALSE;
Dlg_head *edit_dlg;
WEdit *wedit;
WMenuBar *menubar;
if (!made_directory)
{
char *dir = concat_dir_and_file (home_dir, EDIT_DIR);
made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
g_free (dir);
}
wedit = edit_init (NULL, LINES - 2, COLS, _file, line);
if (wedit == NULL)
return 0;
/* Create a new dialog and add it widgets to it */
edit_dlg =
create_dlg (FALSE, 0, 0, LINES, COLS, NULL, edit_dialog_callback,
"[Internal File Editor]", NULL, DLG_WANT_TAB);
edit_dlg->get_shortcut = edit_get_shortcut;
edit_dlg->get_title = edit_get_title;
menubar = menubar_new (0, 0, COLS, NULL);
add_widget (edit_dlg, menubar);
edit_init_menu (menubar);
init_widget (&(wedit->widget), 0, 0, LINES - 1, COLS, edit_callback, edit_event);
widget_want_cursor (wedit->widget, 1);
add_widget (edit_dlg, wedit);
add_widget (edit_dlg, buttonbar_new (TRUE));
run_dlg (edit_dlg);
if (edit_dlg->state == DLG_CLOSED)
destroy_dlg (edit_dlg);
return 1;
}
const char *
edit_get_file_name (const WEdit * edit)
{
return edit->filename;
}
void
edit_update_screen (WEdit * e)
{
edit_scroll_screen_over_cursor (e);
edit_update_curs_col (e);
edit_status (e);
/* pop all events for this window for internal handling */
if (!is_idle ())
e->force |= REDRAW_PAGE;
else
{
if (e->force & REDRAW_COMPLETELY)
e->force |= REDRAW_PAGE;
edit_render_keypress (e);
}
}
/* --------------------------------------------------------------------------------------------- */
static cb_ret_t
edit_callback (Widget * w, widget_msg_t msg, int parm)
@ -378,3 +331,85 @@ edit_callback (Widget * w, widget_msg_t msg, int parm)
return default_proc (msg, parm);
}
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
int
edit_file (const char *_file, int line)
{
static gboolean made_directory = FALSE;
Dlg_head *edit_dlg;
WEdit *wedit;
WMenuBar *menubar;
if (!made_directory)
{
char *dir = concat_dir_and_file (home_dir, EDIT_DIR);
made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
g_free (dir);
}
wedit = edit_init (NULL, LINES - 2, COLS, _file, line);
if (wedit == NULL)
return 0;
/* Create a new dialog and add it widgets to it */
edit_dlg =
create_dlg (FALSE, 0, 0, LINES, COLS, NULL, edit_dialog_callback,
"[Internal File Editor]", NULL, DLG_WANT_TAB);
edit_dlg->get_shortcut = edit_get_shortcut;
edit_dlg->get_title = edit_get_title;
menubar = menubar_new (0, 0, COLS, NULL);
add_widget (edit_dlg, menubar);
edit_init_menu (menubar);
init_widget (&(wedit->widget), 0, 0, LINES - 1, COLS, edit_callback, edit_event);
widget_want_cursor (wedit->widget, 1);
add_widget (edit_dlg, wedit);
add_widget (edit_dlg, buttonbar_new (TRUE));
run_dlg (edit_dlg);
if (edit_dlg->state == DLG_CLOSED)
destroy_dlg (edit_dlg);
return 1;
}
/* --------------------------------------------------------------------------------------------- */
const char *
edit_get_file_name (const WEdit * edit)
{
return edit->filename;
}
/* --------------------------------------------------------------------------------------------- */
void
edit_update_screen (WEdit * e)
{
edit_scroll_screen_over_cursor (e);
edit_update_curs_col (e);
edit_status (e);
/* pop all events for this window for internal handling */
if (!is_idle ())
e->force |= REDRAW_PAGE;
else
{
if (e->force & REDRAW_COMPLETELY)
e->force |= REDRAW_PAGE;
edit_render_keypress (e);
}
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -8,8 +8,8 @@
Copyright (C) 2009 Free Software Foundation, Inc.
Authors:
Ilia Maslakov <il.smind@gmail.com>, 2009
Slava Zanko <slavazanko@gmail.com>, 2009
Ilia Maslakov <il.smind@gmail.com>, 2009
Slava Zanko <slavazanko@gmail.com>, 2009
This file is part of the Midnight Commander.
@ -28,7 +28,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
*/
#include <config.h>
@ -41,11 +41,26 @@
#include "lib/global.h"
#include "src/editor/etags.h"
/*** file scope functions **********************************************/
/*** global variables ****************************************************************************/
static gboolean parse_define(char *buf, char **long_name, char **short_name, long *line)
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static gboolean
parse_define (char *buf, char **long_name, char **short_name, long *line)
{
enum {in_longname, in_shortname, in_shortname_first_char, in_line, finish} def_state = in_longname;
enum
{ in_longname, in_shortname, in_shortname_first_char, in_line, finish } def_state = in_longname;
static char longdef[LONG_DEF_LEN];
static char shortdef[SHORT_DEF_LEN];
@ -55,49 +70,73 @@ static gboolean parse_define(char *buf, char **long_name, char **short_name, lon
int nline = 0;
char c = *buf;
while ( !(c =='\0' || c =='\n') ) {
switch ( def_state ) {
while (!(c == '\0' || c == '\n'))
{
switch (def_state)
{
case in_longname:
if ( c == 0x01 ) {
if (c == 0x01)
{
def_state = in_line;
} else if ( c == 0x7F ) {
}
else if (c == 0x7F)
{
def_state = in_shortname;
} else {
if ( nlong < LONG_DEF_LEN - 1 ) {
}
else
{
if (nlong < LONG_DEF_LEN - 1)
{
longdef[nlong++] = c;
}
}
break;
case in_shortname_first_char:
if ( isdigit(c) ) {
if (isdigit (c))
{
nshort = 0;
buf--;
def_state = in_line;
} else if ( c == 0x01 ) {
}
else if (c == 0x01)
{
def_state = in_line;
} else {
if ( nshort < SHORT_DEF_LEN - 1 ) {
}
else
{
if (nshort < SHORT_DEF_LEN - 1)
{
shortdef[nshort++] = c;
def_state = in_shortname;
}
}
break;
case in_shortname:
if ( c == 0x01 ) {
if (c == 0x01)
{
def_state = in_line;
} else if ( c == '\n' ) {
}
else if (c == '\n')
{
def_state = finish;
} else {
if ( nshort < SHORT_DEF_LEN - 1 ) {
}
else
{
if (nshort < SHORT_DEF_LEN - 1)
{
shortdef[nshort++] = c;
}
}
break;
case in_line:
if ( c == ',' || c == '\n') {
if (c == ',' || c == '\n')
{
def_state = finish;
} else if ( isdigit(c) ) {
if ( nline < LINE_DEF_LEN - 1 ) {
}
else if (isdigit (c))
{
if (nline < LINE_DEF_LEN - 1)
{
linedef[nline++] = c;
}
}
@ -120,13 +159,16 @@ static gboolean parse_define(char *buf, char **long_name, char **short_name, lon
return FALSE;
}
/*** public functions **************************************************/
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
int etags_set_definition_hash(const char *tagfile, const char *start_path,
const char *match_func,
etags_hash_t *def_hash)
int
etags_set_definition_hash (const char *tagfile, const char *start_path,
const char *match_func, etags_hash_t * def_hash)
{
enum {start, in_filename, in_define} state = start;
enum
{ start, in_filename, in_define } state = start;
FILE *f;
static char buf[BUF_LARGE];
@ -137,11 +179,11 @@ int etags_set_definition_hash(const char *tagfile, const char *start_path,
char *chekedstr = NULL;
int num = 0; /* returned value */
int num = 0; /* returned value */
int pos;
char *filename = NULL;
if ( !match_func || !tagfile )
if (!match_func || !tagfile)
return 0;
/* open file with positions */
@ -149,44 +191,53 @@ int etags_set_definition_hash(const char *tagfile, const char *start_path,
if (f == NULL)
return 0;
while (fgets (buf, sizeof (buf), f)) {
while (fgets (buf, sizeof (buf), f))
{
switch ( state ) {
switch (state)
{
case start:
if ( buf[0] == 0x0C ) {
if (buf[0] == 0x0C)
{
state = in_filename;
}
break;
case in_filename:
pos = strcspn(buf, ",");
g_free(filename);
pos = strcspn (buf, ",");
g_free (filename);
filename = g_malloc (pos + 2);
g_strlcpy(filename, (char *)buf, pos + 1);
g_strlcpy (filename, (char *) buf, pos + 1);
state = in_define;
break;
case in_define:
if ( buf[0] == 0x0C ) {
if (buf[0] == 0x0C)
{
state = in_filename;
break;
}
/* check if the filename matches the define pos */
chekedstr = strstr (buf, match_func);
if ( chekedstr ) {
if (chekedstr)
{
parse_define (chekedstr, &longname, &shortname, &line);
if ( num < MAX_DEFINITIONS - 1 ) {
if (num < MAX_DEFINITIONS - 1)
{
def_hash[num].filename_len = strlen (filename);
def_hash[num].fullpath = g_build_filename ( start_path, filename, (char *) NULL);
def_hash[num].fullpath = g_build_filename (start_path, filename, (char *) NULL);
canonicalize_pathname (def_hash[num].fullpath);
def_hash[num].filename = g_strdup (filename);
if ( shortname ) {
if (shortname)
{
def_hash[num].short_define = g_strdup (shortname);
} else {
}
else
{
def_hash[num].short_define = g_strdup (longname);
}
def_hash[num].line = line;
g_free(shortname);
g_free(longname);
g_free (shortname);
g_free (longname);
num++;
}
}
@ -194,7 +245,9 @@ int etags_set_definition_hash(const char *tagfile, const char *start_path,
}
}
g_free(filename);
g_free (filename);
fclose (f);
return num;
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -1,24 +1,37 @@
#ifndef MC_EDIT_ETAGS_H
#define MC_EDIT_ETAGS_H 1
#ifndef MC__EDIT_ETAGS_H
#define MC__EDIT_ETAGS_H 1
#include <sys/types.h> /* size_t */
#include "lib/global.h" /* include <glib.h> */
#include <sys/types.h> /* size_t */
#include "lib/global.h" /* include <glib.h> */
/*** typedefs(not structures) and defined constants **********************************************/
#define MAX_WIDTH_DEF_DIALOG 60 /* max width def dialog */
#define MAX_DEFINITIONS 60 /* count found entries show */
#define MAX_DEFINITIONS 60 /* count found entries show */
#define SHORT_DEF_LEN 30
#define LONG_DEF_LEN 40
#define LINE_DEF_LEN 16
typedef struct etags_hash_struct {
size_t filename_len;
char *fullpath;
char *filename;
char *short_define;
long line;
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
typedef struct etags_hash_struct
{
size_t filename_len;
char *fullpath;
char *filename;
char *short_define;
long line;
} etags_hash_t;
int etags_set_definition_hash (const char *tagfile, const char *start_path,
const char *match_func, etags_hash_t *def_hash);
/*** global variables defined in .c file *********************************************************/
#endif /* MC_EDIT_ETAGS_H */
/*** declarations of public functions ************************************************************/
int etags_set_definition_hash (const char *tagfile, const char *start_path,
const char *match_func, etags_hash_t * def_hash);
/*** inline functions ****************************************************************************/
#endif /* MC__EDIT_ETAGS_H */

Просмотреть файл

@ -59,6 +59,12 @@
#include "edit-impl.h"
#include "edit-widget.h"
/*** global variables ****************************************************************************/
int option_syntax_highlighting = 1;
int option_auto_syntax = 1;
/*** file scope macro definitions ****************************************************************/
/* bytes */
#define SYNTAX_MARKER_DENSITY 512
@ -78,6 +84,15 @@
#define SYNTAX_TOKEN_BRACKET '\003'
#define SYNTAX_TOKEN_BRACE '\004'
#define whiteness(x) ((x) == '\t' || (x) == '\n' || (x) == ' ')
#define free_args(x)
#define break_a {result=line;break;}
#define check_a {if(!*a){result=line;break;}}
#define check_not_a {if(*a){result=line;break;}}
/*** file scope type declarations ****************************************************************/
struct key_word
{
char *keyword;
@ -112,8 +127,12 @@ struct _syntax_marker
struct _syntax_marker *next;
};
int option_syntax_highlighting = 1;
int option_auto_syntax = 1;
/*** file scope variables ************************************************************************/
static char *error_file_name = NULL;
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static gint
mc_defines_destroy (gpointer key, gpointer value, gpointer data)
@ -130,7 +149,9 @@ mc_defines_destroy (gpointer key, gpointer value, gpointer data)
return FALSE;
}
/* Completely destroys the defines tree */
/* --------------------------------------------------------------------------------------------- */
/** Completely destroys the defines tree */
static void
destroy_defines (GTree ** defines)
{
@ -139,13 +160,17 @@ destroy_defines (GTree ** defines)
*defines = NULL;
}
/* Wrapper for case insensitive mode */
/* --------------------------------------------------------------------------------------------- */
/** Wrapper for case insensitive mode */
inline static int
xx_tolower (WEdit * edit, int c)
{
return edit->is_case_insensitive ? tolower (c) : c;
}
/* --------------------------------------------------------------------------------------------- */
static void
subst_defines (GTree * defines, char **argv, char **argv_end)
{
@ -185,6 +210,8 @@ subst_defines (GTree * defines, char **argv, char **argv_end)
}
}
/* --------------------------------------------------------------------------------------------- */
static long
compare_word_to_right (WEdit * edit, long i, const char *text,
const char *whole_left, const char *whole_right, int line_start)
@ -230,7 +257,7 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
if (c == *p)
{
j = i;
if (*p == *text && p[1] == '\0') /* handle eg '+' and @+@ keywords properly */
if (*p == *text && p[1] == '\0') /* handle eg '+' and @+@ keywords properly */
break;
}
if (j && strchr ((char *) p + 1, c)) /* c exists further down, so it will get matched later */
@ -302,11 +329,14 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
return -1;
}
}
if (whole_right != NULL && strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))) != NULL)
if (whole_right != NULL
&& strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))) != NULL)
return -1;
return i;
}
/* --------------------------------------------------------------------------------------------- */
static const char *
xx_strchr (WEdit * edit, const unsigned char *s, int char_byte)
{
@ -316,6 +346,8 @@ xx_strchr (WEdit * edit, const unsigned char *s, int char_byte)
return (const char *) s;
}
/* --------------------------------------------------------------------------------------------- */
static struct syntax_rule
apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
{
@ -435,9 +467,8 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
{
long e;
e = compare_word_to_right (edit, i, r->right, r->whole_word_chars_left,
r->whole_word_chars_right,
r->line_start_right);
e = compare_word_to_right (edit, i, r->right, r->whole_word_chars_left,
r->whole_word_chars_right, r->line_start_right);
if (e >= end)
{
_rule.end = e;
@ -512,6 +543,8 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
return _rule;
}
/* --------------------------------------------------------------------------------------------- */
static struct syntax_rule
edit_get_rule (WEdit * edit, long byte_index)
{
@ -565,29 +598,22 @@ edit_get_rule (WEdit * edit, long byte_index)
return edit->rule;
}
/* --------------------------------------------------------------------------------------------- */
static inline void
translate_rule_to_color (WEdit * edit, struct syntax_rule rule, int *color)
{
*color = edit->rules[rule.context]->keyword[rule.keyword]->color;
}
void
edit_get_syntax_color (WEdit * edit, long byte_index, int *color)
{
if (!tty_use_colors ())
*color = 0;
else if (edit->rules && byte_index < edit->last_byte && option_syntax_highlighting)
translate_rule_to_color (edit, edit_get_rule (edit, byte_index), color);
else
*color = EDITOR_NORMAL_COLOR;
}
/*
/* --------------------------------------------------------------------------------------------- */
/**
Returns 0 on error/eof or a count of the number of bytes read
including the newline. Result must be free'd.
In case of an error, *line will not be modified.
*/
static size_t
read_one_line (char **line, FILE * f)
{
@ -637,6 +663,8 @@ read_one_line (char **line, FILE * f)
return r;
}
/* --------------------------------------------------------------------------------------------- */
static char *
convert (char *s)
{
@ -706,7 +734,7 @@ convert (char *s)
return r;
}
#define whiteness(x) ((x) == '\t' || (x) == '\n' || (x) == ' ')
/* --------------------------------------------------------------------------------------------- */
static int
get_args (char *l, char **args, int args_size)
@ -730,10 +758,7 @@ get_args (char *l, char **args, int args_size)
return argc;
}
#define free_args(x)
#define break_a {result=line;break;}
#define check_a {if(!*a){result=line;break;}}
#define check_not_a {if(*a){result=line;break;}}
/* --------------------------------------------------------------------------------------------- */
static int
this_try_alloc_color_pair (const char *fg, const char *bg)
@ -797,7 +822,7 @@ this_try_alloc_color_pair (const char *fg, const char *bg)
return tty_try_alloc_color_pair (fg, bg);
}
static char *error_file_name = NULL;
/* --------------------------------------------------------------------------------------------- */
static FILE *
open_include_file (const char *filename)
@ -827,6 +852,8 @@ open_include_file (const char *filename)
return fopen (error_file_name, "r");
}
/* --------------------------------------------------------------------------------------------- */
inline static void
xx_lowerize_line (WEdit * edit, char *line, size_t len)
{
@ -838,7 +865,9 @@ xx_lowerize_line (WEdit * edit, char *line, size_t len)
}
}
/* returns line number on error */
/* --------------------------------------------------------------------------------------------- */
/** returns line number on error */
static int
edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
{
@ -1191,52 +1220,7 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
return result;
}
void
edit_free_syntax_rules (WEdit * edit)
{
size_t i, j;
if (!edit)
return;
if (edit->defines)
destroy_defines (&edit->defines);
if (!edit->rules)
return;
edit_get_rule (edit, -1);
MC_PTR_FREE (edit->syntax_type);
for (i = 0; edit->rules[i]; i++)
{
if (edit->rules[i]->keyword)
{
for (j = 0; edit->rules[i]->keyword[j]; j++)
{
MC_PTR_FREE (edit->rules[i]->keyword[j]->keyword);
MC_PTR_FREE (edit->rules[i]->keyword[j]->whole_word_chars_left);
MC_PTR_FREE (edit->rules[i]->keyword[j]->whole_word_chars_right);
MC_PTR_FREE (edit->rules[i]->keyword[j]);
}
}
MC_PTR_FREE (edit->rules[i]->left);
MC_PTR_FREE (edit->rules[i]->right);
MC_PTR_FREE (edit->rules[i]->whole_word_chars_left);
MC_PTR_FREE (edit->rules[i]->whole_word_chars_right);
MC_PTR_FREE (edit->rules[i]->keyword);
MC_PTR_FREE (edit->rules[i]->keyword_first_chars);
MC_PTR_FREE (edit->rules[i]);
}
while (edit->syntax_marker)
{
struct _syntax_marker *s = edit->syntax_marker->next;
g_free (edit->syntax_marker);
edit->syntax_marker = s;
}
MC_PTR_FREE (edit->rules);
tty_color_free_all_tmp ();
}
/* --------------------------------------------------------------------------------------------- */
/* returns -1 on file error, line number on error in file syntax */
static int
@ -1373,6 +1357,8 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
return result;
}
/* --------------------------------------------------------------------------------------------- */
static char *
get_first_editor_line (WEdit * edit)
{
@ -1396,7 +1382,72 @@ get_first_editor_line (WEdit * edit)
return s;
}
/*
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
edit_get_syntax_color (WEdit * edit, long byte_index, int *color)
{
if (!tty_use_colors ())
*color = 0;
else if (edit->rules && byte_index < edit->last_byte && option_syntax_highlighting)
translate_rule_to_color (edit, edit_get_rule (edit, byte_index), color);
else
*color = EDITOR_NORMAL_COLOR;
}
/* --------------------------------------------------------------------------------------------- */
void
edit_free_syntax_rules (WEdit * edit)
{
size_t i, j;
if (!edit)
return;
if (edit->defines)
destroy_defines (&edit->defines);
if (!edit->rules)
return;
edit_get_rule (edit, -1);
MC_PTR_FREE (edit->syntax_type);
for (i = 0; edit->rules[i]; i++)
{
if (edit->rules[i]->keyword)
{
for (j = 0; edit->rules[i]->keyword[j]; j++)
{
MC_PTR_FREE (edit->rules[i]->keyword[j]->keyword);
MC_PTR_FREE (edit->rules[i]->keyword[j]->whole_word_chars_left);
MC_PTR_FREE (edit->rules[i]->keyword[j]->whole_word_chars_right);
MC_PTR_FREE (edit->rules[i]->keyword[j]);
}
}
MC_PTR_FREE (edit->rules[i]->left);
MC_PTR_FREE (edit->rules[i]->right);
MC_PTR_FREE (edit->rules[i]->whole_word_chars_left);
MC_PTR_FREE (edit->rules[i]->whole_word_chars_right);
MC_PTR_FREE (edit->rules[i]->keyword);
MC_PTR_FREE (edit->rules[i]->keyword_first_chars);
MC_PTR_FREE (edit->rules[i]);
}
while (edit->syntax_marker)
{
struct _syntax_marker *s = edit->syntax_marker->next;
g_free (edit->syntax_marker);
edit->syntax_marker = s;
}
MC_PTR_FREE (edit->rules);
tty_color_free_all_tmp ();
}
/* --------------------------------------------------------------------------------------------- */
/**
* Load rules into edit struct. Either edit or *pnames must be NULL. If
* edit is NULL, a list of types will be stored into names. If type is
* NULL, then the type will be selected according to the filename.
@ -1415,7 +1466,7 @@ edit_load_syntax (WEdit * edit, char ***pnames, const char *type)
{
char *saved_type;
saved_type = g_strdup (type); /* save edit->syntax_type */
saved_type = g_strdup (type); /* save edit->syntax_type */
edit_free_syntax_rules (edit);
edit->syntax_type = saved_type; /* restore edit->syntax_type */
}
@ -1457,8 +1508,12 @@ edit_load_syntax (WEdit * edit, char ***pnames, const char *type)
g_free (f);
}
/* --------------------------------------------------------------------------------------------- */
const char *
edit_get_syntax_type (const WEdit * edit)
{
return edit->syntax_type;
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -1,5 +1,5 @@
/* wordproc.c - word-processor mode for the editor: does dynamic
paragraph formatting.
paragraph formatting.
Copyright (C) 1996 Paul Sheer
This program is free software; you can redistribute it and/or modify
@ -39,18 +39,29 @@
#include "lib/global.h"
#include "src/setup.h" /* option_tab_spacing */
#include "src/setup.h" /* option_tab_spacing */
#include "edit-impl.h"
#include "edit-widget.h"
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
#define tab_width option_tab_spacing
#define NO_FORMAT_CHARS_START "-+*\\,.;:&>"
#define FONT_MEAN_WIDTH 1
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static long
line_start (WEdit *edit, long line)
line_start (WEdit * edit, long line)
{
long p, l;
@ -58,197 +69,232 @@ line_start (WEdit *edit, long line)
p = edit->curs1;
if (line < l)
p = edit_move_backward (edit, p, l - line);
p = edit_move_backward (edit, p, l - line);
else if (line > l)
p = edit_move_forward (edit, p, line - l, 0);
p = edit_move_forward (edit, p, line - l, 0);
p = edit_bol (edit, p);
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
p++;
return p;
}
static int bad_line_start (WEdit * edit, long p)
/* --------------------------------------------------------------------------------------------- */
static int
bad_line_start (WEdit * edit, long p)
{
int c;
c = edit_get_byte (edit, p);
if (c == '.') { /* `...' is acceptable */
if (edit_get_byte (edit, p + 1) == '.')
if (edit_get_byte (edit, p + 2) == '.')
return 0;
return 1;
if (c == '.')
{ /* `...' is acceptable */
if (edit_get_byte (edit, p + 1) == '.')
if (edit_get_byte (edit, p + 2) == '.')
return 0;
return 1;
}
if (c == '-') {
if (edit_get_byte (edit, p + 1) == '-')
if (edit_get_byte (edit, p + 2) == '-')
return 0; /* `---' is acceptable */
return 1;
if (c == '-')
{
if (edit_get_byte (edit, p + 1) == '-')
if (edit_get_byte (edit, p + 2) == '-')
return 0; /* `---' is acceptable */
return 1;
}
if (strchr (NO_FORMAT_CHARS_START, c))
return 1;
return 1;
return 0;
}
/*
/* --------------------------------------------------------------------------------------------- */
/**
* Find the start of the current paragraph for the purpose of formatting.
* Return position in the file.
*/
static long
begin_paragraph (WEdit *edit, int force)
begin_paragraph (WEdit * edit, int force)
{
long i;
for (i = edit->curs_line - 1; i >= 0; i--) {
if (line_is_blank (edit, i)) {
i++;
break;
}
if (force) {
if (bad_line_start (edit, line_start (edit, i))) {
i++;
break;
}
}
for (i = edit->curs_line - 1; i >= 0; i--)
{
if (line_is_blank (edit, i))
{
i++;
break;
}
if (force)
{
if (bad_line_start (edit, line_start (edit, i)))
{
i++;
break;
}
}
}
return edit_move_backward (edit, edit_bol (edit, edit->curs1),
edit->curs_line - i);
return edit_move_backward (edit, edit_bol (edit, edit->curs1), edit->curs_line - i);
}
/*
/* --------------------------------------------------------------------------------------------- */
/**
* Find the end of the current paragraph for the purpose of formatting.
* Return position in the file.
*/
static long
end_paragraph (WEdit *edit, int force)
end_paragraph (WEdit * edit, int force)
{
int i;
for (i = edit->curs_line + 1; i <= edit->total_lines; i++) {
if (line_is_blank (edit, i)) {
i--;
break;
}
if (force)
if (bad_line_start (edit, line_start (edit, i))) {
i--;
break;
}
for (i = edit->curs_line + 1; i <= edit->total_lines; i++)
{
if (line_is_blank (edit, i))
{
i--;
break;
}
if (force)
if (bad_line_start (edit, line_start (edit, i)))
{
i--;
break;
}
}
return edit_eol (edit,
edit_move_forward (edit, edit_bol (edit, edit->curs1),
i - edit->curs_line, 0));
edit_move_forward (edit, edit_bol (edit, edit->curs1),
i - edit->curs_line, 0));
}
/* --------------------------------------------------------------------------------------------- */
static unsigned char *
get_paragraph (WEdit *edit, long p, long q, int indent, int *size)
get_paragraph (WEdit * edit, long p, long q, int indent, int *size)
{
unsigned char *s, *t;
#if 0
t = g_try_malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length +
10);
t = g_try_malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length + 10);
#else
t = g_try_malloc (2 * (q - p) + 100);
#endif
if (t == NULL)
return NULL;
for (s = t; p < q; p++, s++) {
if (indent)
if (edit_get_byte (edit, p - 1) == '\n')
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
*s = edit_get_byte (edit, p);
return NULL;
for (s = t; p < q; p++, s++)
{
if (indent)
if (edit_get_byte (edit, p - 1) == '\n')
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
*s = edit_get_byte (edit, p);
}
*size = (unsigned long) s - (unsigned long) t;
t[*size] = '\n';
return t;
}
/* --------------------------------------------------------------------------------------------- */
static inline void
strip_newlines (unsigned char *t, int size)
{
unsigned char *p = t;
while (size-- != 0) {
if (*p == '\n')
*p = ' ';
p++;
while (size-- != 0)
{
if (*p == '\n')
*p = ' ';
p++;
}
}
/*
/* --------------------------------------------------------------------------------------------- */
/**
This function calculates the number of chars in a line specified to length l in pixels
*/
static inline int
next_tab_pos (int x)
{
return x += tab_width - x % tab_width;
}
/* --------------------------------------------------------------------------------------------- */
static inline int
line_pixel_length (unsigned char *t, long b, int l)
{
int x = 0, c, xn = 0;
for (;;) {
c = t[b];
switch (c) {
case '\n':
return b;
case '\t':
xn = next_tab_pos (x);
break;
default:
xn = x + 1;
break;
}
if (xn > l)
break;
x = xn;
b++;
for (;;)
{
c = t[b];
switch (c)
{
case '\n':
return b;
case '\t':
xn = next_tab_pos (x);
break;
default:
xn = x + 1;
break;
}
if (xn > l)
break;
x = xn;
b++;
}
return b;
}
/* --------------------------------------------------------------------------------------------- */
static int
next_word_start (unsigned char *t, int q, int size)
{
int i;
int saw_ws = 0;
for (i = q; i < size; i++) {
switch (t[i]) {
case '\n':
return -1;
case '\t':
case ' ':
saw_ws = 1;
break;
default:
if (saw_ws != 0)
return i;
break;
}
for (i = q; i < size; i++)
{
switch (t[i])
{
case '\n':
return -1;
case '\t':
case ' ':
saw_ws = 1;
break;
default:
if (saw_ws != 0)
return i;
break;
}
}
return -1;
}
/* find the start of a word */
/* --------------------------------------------------------------------------------------------- */
/** find the start of a word */
static inline int
word_start (unsigned char *t, int q, int size)
{
int i = q;
if (t[q] == ' ' || t[q] == '\t')
return next_word_start (t, q, size);
for (;;) {
int c;
if (!i)
return -1;
c = t[i - 1];
if (c == '\n')
return -1;
if (c == ' ' || c == '\t')
return i;
i--;
return next_word_start (t, q, size);
for (;;)
{
int c;
if (!i)
return -1;
c = t[i - 1];
if (c == '\n')
return -1;
if (c == ' ' || c == '\t')
return i;
i--;
}
}
/* replaces ' ' with '\n' to properly format a paragraph */
/* --------------------------------------------------------------------------------------------- */
/** replaces ' ' with '\n' to properly format a paragraph */
static inline void
format_this (unsigned char *t, int size, int indent)
{
@ -256,28 +302,31 @@ format_this (unsigned char *t, int size, int indent)
strip_newlines (t, size);
ww = option_word_wrap_line_length * FONT_MEAN_WIDTH - indent;
if (ww < FONT_MEAN_WIDTH * 2)
ww = FONT_MEAN_WIDTH * 2;
for (;;) {
int p;
q = line_pixel_length (t, q, ww);
if (q > size)
break;
if (t[q] == '\n')
break;
p = word_start (t, q, size);
if (p == -1)
q = next_word_start (t, q, size); /* Return the end of the word if the beginning
of the word is at the beginning of a line
(i.e. a very long word) */
else
q = p;
if (q == -1) /* end of paragraph */
break;
if (q)
t[q - 1] = '\n';
ww = FONT_MEAN_WIDTH * 2;
for (;;)
{
int p;
q = line_pixel_length (t, q, ww);
if (q > size)
break;
if (t[q] == '\n')
break;
p = word_start (t, q, size);
if (p == -1)
q = next_word_start (t, q, size); /* Return the end of the word if the beginning
of the word is at the beginning of a line
(i.e. a very long word) */
else
q = p;
if (q == -1) /* end of paragraph */
break;
if (q)
t[q - 1] = '\n';
}
}
/* --------------------------------------------------------------------------------------------- */
static inline void
replace_at (WEdit * edit, long q, int c)
{
@ -286,7 +335,9 @@ replace_at (WEdit * edit, long q, int c)
edit_insert_ahead (edit, c);
}
/* replaces a block of text */
/* --------------------------------------------------------------------------------------------- */
/** replaces a block of text */
static inline void
put_paragraph (WEdit * edit, unsigned char *t, long p, int indent, int size)
{
@ -294,83 +345,102 @@ put_paragraph (WEdit * edit, unsigned char *t, long p, int indent, int size)
int i, c = 0;
cursor = edit->curs1;
if (indent)
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
for (i = 0; i < size; i++, p++) {
if (i && indent) {
if (t[i - 1] == '\n' && c == '\n') {
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
} else if (t[i - 1] == '\n') {
long curs;
edit_cursor_move (edit, p - edit->curs1);
curs = edit->curs1;
edit_insert_indent (edit, indent);
if (cursor >= curs)
cursor += edit->curs1 - p;
p = edit->curs1;
} else if (c == '\n') {
edit_cursor_move (edit, p - edit->curs1);
while (strchr ("\t ", edit_get_byte (edit, p))) {
edit_delete (edit, 1);
if (cursor > edit->curs1)
cursor--;
}
p = edit->curs1;
}
}
c = edit_get_byte (edit, p);
if (c != t[i])
replace_at (edit, p, t[i]);
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
for (i = 0; i < size; i++, p++)
{
if (i && indent)
{
if (t[i - 1] == '\n' && c == '\n')
{
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
}
else if (t[i - 1] == '\n')
{
long curs;
edit_cursor_move (edit, p - edit->curs1);
curs = edit->curs1;
edit_insert_indent (edit, indent);
if (cursor >= curs)
cursor += edit->curs1 - p;
p = edit->curs1;
}
else if (c == '\n')
{
edit_cursor_move (edit, p - edit->curs1);
while (strchr ("\t ", edit_get_byte (edit, p)))
{
edit_delete (edit, 1);
if (cursor > edit->curs1)
cursor--;
}
p = edit->curs1;
}
}
c = edit_get_byte (edit, p);
if (c != t[i])
replace_at (edit, p, t[i]);
}
edit_cursor_move (edit, cursor - edit->curs1); /* restore cursor position */
edit_cursor_move (edit, cursor - edit->curs1); /* restore cursor position */
}
/* --------------------------------------------------------------------------------------------- */
static inline int
test_indent (WEdit * edit, long p, long q)
{
int indent;
indent = edit_indent_width (edit, p++);
if (!indent)
return 0;
return 0;
for (; p < q; p++)
if (edit_get_byte (edit, p - 1) == '\n')
if (indent != edit_indent_width (edit, p))
return 0;
if (edit_get_byte (edit, p - 1) == '\n')
if (indent != edit_indent_width (edit, p))
return 0;
return indent;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
format_paragraph (WEdit *edit, int force)
format_paragraph (WEdit * edit, int force)
{
long p, q;
int size;
unsigned char *t;
int indent = 0;
if (option_word_wrap_line_length < 2)
return;
return;
if (line_is_blank (edit, edit->curs_line))
return;
return;
p = begin_paragraph (edit, force);
q = end_paragraph (edit, force);
indent = test_indent (edit, p, q);
t = get_paragraph (edit, p, q, indent, &size);
if (!t)
return;
if (!force) {
int i;
if (strchr (NO_FORMAT_CHARS_START, *t)) {
g_free (t);
return;
}
for (i = 0; i < size - 1; i++) {
if (t[i] == '\n') {
if (strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1])) {
g_free (t);
return;
}
}
}
return;
if (!force)
{
int i;
if (strchr (NO_FORMAT_CHARS_START, *t))
{
g_free (t);
return;
}
for (i = 0; i < size - 1; i++)
{
if (t[i] == '\n')
{
if (strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1]))
{
g_free (t);
return;
}
}
}
}
format_this (t, q - p, indent);
put_paragraph (edit, t, p, indent, size);
@ -379,3 +449,5 @@ format_paragraph (WEdit *edit, int force)
/* Scroll left as much as possible to show the formatted paragraph */
edit_scroll_left (edit, -edit->start_col);
}
/* --------------------------------------------------------------------------------------------- */