From eb9a251dcc3183a4b70e3e1ceb087a1b8102d2e1 Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Sun, 26 Jul 2009 07:31:24 +0000 Subject: [PATCH] add: some utf8 procedures: * get_ptr_file (WView *view, offset_type byte_index) * get_ptr_string (WView *view, offset_type byte_index) * get_ptr_growing_buffer (WView *view, offset_type byte_index) * get_utf (WView *view, offset_type byte_index, int *char_width) add: property 'utf' in the struct Wview Signed-off-by: Slava Zanko Added temlate for splitting src/view.c into lot of smalest files (for better development and supporting). --- configure.ac | 1 + src/Makefile.am | 2 +- src/view.c | 1 - src/viewer/Makefile.am | 18 ++++++ src/viewer/actions_cmd.c | 55 ++++++++++++++++++ src/viewer/dialogs.c | 55 ++++++++++++++++++ src/viewer/hex.c | 55 ++++++++++++++++++ src/viewer/internal.h | 141 +++++++++++++++++++++++++++++++++++++++++++++++ src/viewer/lib.c | 55 ++++++++++++++++++ src/viewer/mcviewer.c | 55 ++++++++++++++++++ src/viewer/mcviewer.h | 25 +++++++++ src/viewer/nroff.c | 55 ++++++++++++++++++ src/viewer/plain.c | 55 ++++++++++++++++++ 13 files changed, 571 insertions(+), 2 deletions(-) create mode 100644 src/viewer/Makefile.am create mode 100644 src/viewer/actions_cmd.c create mode 100644 src/viewer/dialogs.c create mode 100644 src/viewer/hex.c create mode 100644 src/viewer/internal.h create mode 100644 src/viewer/lib.c create mode 100644 src/viewer/mcviewer.c create mode 100644 src/viewer/mcviewer.h create mode 100644 src/viewer/nroff.c create mode 100644 src/viewer/plain.c diff --git a/configure.ac b/configure.ac index 49f8d5d0e..159f24157 100644 --- a/configure.ac +++ b/configure.ac @@ -562,6 +562,7 @@ src/Makefile src/mcconfig/Makefile src/search/Makefile src/tty/Makefile +src/viewer/Makefile edit/Makefile syntax/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 2299b7860..c0503bd23 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = mcconfig search tty +SUBDIRS = mcconfig search tty viewer AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) $(PCRE_CFLAGS) diff --git a/src/view.c b/src/view.c index a226b2f14..74f078132 100644 --- a/src/view.c +++ b/src/view.c @@ -158,7 +158,6 @@ struct WView { growing buffer */ gboolean growbuf_finished; /* TRUE when all data has been read. */ - /* Editor modes */ gboolean hex_mode; /* Hexview or Hexedit */ gboolean hexedit_mode; /* Hexedit */ diff --git a/src/viewer/Makefile.am b/src/viewer/Makefile.am new file mode 100644 index 000000000..c453af861 --- /dev/null +++ b/src/viewer/Makefile.am @@ -0,0 +1,18 @@ + +noinst_LTLIBRARIES = libmcviewer.la + +libmcviewer_la_SOURCES = \ + actions_cmd.c \ + dialogs.c \ + hex.c \ + internal.h \ + lib.c \ + mcviewer.c \ + mcviewer.h \ + nroff.c \ + plain.c + +libmcviewer_la_CFLAGS=-I../ -I$(top_srcdir)/src \ + $(GLIB_CFLAGS) \ + -DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\" + diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c new file mode 100644 index 000000000..6962b4121 --- /dev/null +++ b/src/viewer/actions_cmd.c @@ -0,0 +1,55 @@ +/* + Internal file viewer for the Midnight Commander + Callback function for some actions (hotkeys, menu) + + Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, + 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. + + Written by: 1994, 1995, 1998 Miguel de Icaza + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + +#include "../src/global.h" +#include "../src/viewer/internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +/*** public functions ****************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/viewer/dialogs.c b/src/viewer/dialogs.c new file mode 100644 index 000000000..8921d2afb --- /dev/null +++ b/src/viewer/dialogs.c @@ -0,0 +1,55 @@ +/* + Internal file viewer for the Midnight Commander + Function for paint dialogs + + Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, + 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. + + Written by: 1994, 1995, 1998 Miguel de Icaza + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + +#include "../src/global.h" +#include "../src/viewer/internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +/*** public functions ****************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/viewer/hex.c b/src/viewer/hex.c new file mode 100644 index 000000000..5f85b6583 --- /dev/null +++ b/src/viewer/hex.c @@ -0,0 +1,55 @@ +/* + Internal file viewer for the Midnight Commander + Function for hex view + + Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, + 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. + + Written by: 1994, 1995, 1998 Miguel de Icaza + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + +#include "../src/global.h" +#include "../src/viewer/internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +/*** public functions ****************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/viewer/internal.h b/src/viewer/internal.h new file mode 100644 index 000000000..2b675eaf3 --- /dev/null +++ b/src/viewer/internal.h @@ -0,0 +1,141 @@ +#ifndef MC_VIEWER_INTERNAL_H +#define MC_VIEWER_INTERNAL_H + +#include "../src/widget.h" +#include "../src/search/search.h" + +/*** typedefs(not structures) and defined constants ********************/ + +typedef unsigned char byte; + +/* A width or height on the screen */ +typedef unsigned int screen_dimen; + +/* Offset in bytes into a file */ +typedef unsigned long offset_type; + +/*** enums *************************************************************/ + +/* data sources of the view */ +enum view_ds { + DS_NONE, /* No data available */ + DS_STDIO_PIPE, /* Data comes from a pipe using popen/pclose */ + DS_VFS_PIPE, /* Data comes from a piped-in VFS file */ + DS_FILE, /* Data comes from a VFS file */ + DS_STRING /* Data comes from a string in memory */ +}; + +/*** structures declarations (and typedefs of structures)***************/ + +struct area { + screen_dimen top, left; + screen_dimen height, width; +}; + + +struct WView { + Widget widget; + + char *filename; /* Name of the file */ + char *command; /* Command used to pipe data in */ + + enum view_ds datasource; /* Where the displayed data comes from */ + + /* stdio pipe data source */ + FILE *ds_stdio_pipe; /* Output of a shell command */ + + /* vfs pipe data source */ + int ds_vfs_pipe; /* Non-seekable vfs file descriptor */ + + /* vfs file data source */ + int ds_file_fd; /* File with random access */ + off_t ds_file_filesize; /* Size of the file */ + off_t ds_file_offset; /* Offset of the currently loaded data */ + byte *ds_file_data; /* Currently loaded data */ + size_t ds_file_datalen; /* Number of valid bytes in file_data */ + size_t ds_file_datasize; /* Number of allocated bytes in file_data */ + + /* string data source */ + byte *ds_string_data; /* The characters of the string */ + size_t ds_string_len; /* The length of the string */ + + /* Growing buffers information */ + gboolean growbuf_in_use; /* Use the growing buffers? */ + byte **growbuf_blockptr; /* Pointer to the block pointers */ + size_t growbuf_blocks; /* The number of blocks in *block_ptr */ + size_t growbuf_lastindex; /* Number of bytes in the last page of the + growing buffer */ + gboolean growbuf_finished; /* TRUE when all data has been read. */ + + /* Editor modes */ + gboolean hex_mode; /* Hexview or Hexedit */ + gboolean hexedit_mode; /* Hexedit */ + gboolean hexview_in_text; /* Is the hexview cursor in the text area? */ + gboolean text_nroff_mode; /* Nroff-style highlighting */ + gboolean text_wrap_mode; /* Wrap text lines to fit them on the screen */ + gboolean magic_mode; /* Preprocess the file using external programs */ + + /* Additional editor state */ + gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */ + GArray *coord_cache; /* Cache for mapping offsets to cursor positions */ + + /* Display information */ + screen_dimen dpy_frame_size;/* Size of the frame surrounding the real viewer */ + offset_type dpy_start; /* Offset of the displayed data */ + offset_type dpy_end; /* Offset after the displayed data */ + offset_type dpy_text_column;/* Number of skipped columns in non-wrap + * text mode */ + offset_type hex_cursor; /* Hexview cursor position in file */ + screen_dimen cursor_col; /* Cursor column */ + screen_dimen cursor_row; /* Cursor row */ + struct hexedit_change_node *change_list; /* Linked list of changes */ + struct area status_area; /* Where the status line is displayed */ + struct area ruler_area; /* Where the ruler is displayed */ + struct area data_area; /* Where the data is displayed */ + + int dirty; /* Number of skipped updates */ + gboolean dpy_bbar_dirty; /* Does the button bar need to be updated? */ + + /* Mode variables */ + int bytes_per_line; /* Number of bytes per line in hex mode */ + + /* Search variables */ + offset_type search_start; /* First character to start searching from */ + offset_type search_end; /* Length of found string or 0 if none was found */ + + /* Pointer to the last search command */ + gboolean want_to_quit; /* Prepare for cleanup ... */ + + /* Markers */ + int marker; /* mark to use */ + offset_type marks [10]; /* 10 marks: 0..9 */ + + int move_dir; /* return value from widget: + * 0 do nothing + * -1 view previous file + * 1 view next file + */ + + offset_type update_steps; /* The number of bytes between percent + * increments */ + offset_type update_activate;/* Last point where we updated the status */ + + /* converter for translation of text */ + GIConv converter; + + /* handle of search engine */ + mc_search_t *search; + gchar *last_search_string; + mc_search_type_t search_type; + gboolean search_all_codepages; + gboolean search_case; + gboolean search_backwards; + + int search_numNeedSkipChar; +}; + +/*** global variables defined in .c file *******************************/ + +/*** declarations of public functions **********************************/ + +#endif diff --git a/src/viewer/lib.c b/src/viewer/lib.c new file mode 100644 index 000000000..77104c1f1 --- /dev/null +++ b/src/viewer/lib.c @@ -0,0 +1,55 @@ +/* + Internal file viewer for the Midnight Commander + Common finctions (used from some other mcviewer functions) + + Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, + 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. + + Written by: 1994, 1995, 1998 Miguel de Icaza + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + +#include "../src/global.h" +#include "../src/viewer/internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +/*** public functions ****************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c new file mode 100644 index 000000000..e00141fe9 --- /dev/null +++ b/src/viewer/mcviewer.c @@ -0,0 +1,55 @@ +/* + Internal file viewer for the Midnight Commander + Interface functions + + Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, + 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. + + Written by: 1994, 1995, 1998 Miguel de Icaza + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + +#include "../src/global.h" +#include "../src/viewer/internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +/*** public functions ****************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/viewer/mcviewer.h b/src/viewer/mcviewer.h new file mode 100644 index 000000000..9ee319423 --- /dev/null +++ b/src/viewer/mcviewer.h @@ -0,0 +1,25 @@ +/** \file view.h + * \brief Header: internal file viewer + */ + +#ifndef MC_VIEWER_H +#define MC_VIEWER_H + +/*** typedefs(not structures) and defined constants ********************/ + +typedef struct WView WView; /* Can be cast to Widget */ + +/*** enums *************************************************************/ + +/*** structures declarations (and typedefs of structures)***************/ + +/*** global variables defined in .c file *******************************/ + +/*** declarations of public functions **********************************/ + +/* Creates a new WView object with the given properties. Caveat: the + * origin is in y-x order, while the extent is in x-y order. */ +extern WView *view_new (int y, int x, int cols, int lines, int is_panel); + + +#endif diff --git a/src/viewer/nroff.c b/src/viewer/nroff.c new file mode 100644 index 000000000..183faae22 --- /dev/null +++ b/src/viewer/nroff.c @@ -0,0 +1,55 @@ +/* + Internal file viewer for the Midnight Commander + Function for nroff-like view + + Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, + 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. + + Written by: 1994, 1995, 1998 Miguel de Icaza + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + +#include "../src/global.h" +#include "../src/viewer/internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +/*** public functions ****************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/viewer/plain.c b/src/viewer/plain.c new file mode 100644 index 000000000..b1b30c181 --- /dev/null +++ b/src/viewer/plain.c @@ -0,0 +1,55 @@ +/* + Internal file viewer for the Midnight Commander + Function for plain view + + Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, + 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. + + Written by: 1994, 1995, 1998 Miguel de Icaza + 1994, 1995 Janne Kukonlehto + 1995 Jakub Jelinek + 1996 Joseph M. Hinkle + 1997 Norbert Warmuth + 1998 Pavel Machek + 2004 Roland Illig + 2005 Roland Illig + 2009 Slava Zanko + 2009 Andrew Borodin + 2009 Ilia Maslakov + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + +#include "../src/global.h" +#include "../src/viewer/internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +/*** public functions ****************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ -- 2.11.4.GIT