From faff6e61730896d7d1bf3210ecced28a8f0fc387 Mon Sep 17 00:00:00 2001 From: Diego Hernan Borghetti Date: Thu, 14 Feb 2008 00:49:33 -0300 Subject: [PATCH] Initial revision of Eco, a simple text editor. --- COPYING | 353 +++++++++++++++++++++++++++++++++++++++ Makefile | 57 +++++++ README | 72 ++++++++ buffer.c | 575 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ buffer.h | 105 ++++++++++++ cmd.c | 204 ++++++++++++++++++++++ cmd.h | 32 ++++ config.c | 308 ++++++++++++++++++++++++++++++++++ config.h | 39 +++++ debug.c | 48 ++++++ debug.h | 15 ++ eco.h | 42 +++++ file.c | 104 ++++++++++++ file.h | 12 ++ func.c | 82 +++++++++ func.h | 24 +++ key.c | 94 +++++++++++ key.h | 28 ++++ kill.c | 63 +++++++ kill.h | 16 ++ main.c | 512 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ screen.c | 174 +++++++++++++++++++ screen.h | 39 +++++ status.c | 180 ++++++++++++++++++++ status.h | 13 ++ term.c | 208 +++++++++++++++++++++++ term.h | 51 ++++++ update.c | 220 ++++++++++++++++++++++++ update.h | 11 ++ view.c | 94 +++++++++++ view.h | 81 +++++++++ 31 files changed, 3856 insertions(+) create mode 100644 COPYING create mode 100644 Makefile create mode 100644 README create mode 100644 buffer.c create mode 100644 buffer.h create mode 100644 cmd.c create mode 100644 cmd.h create mode 100644 config.c create mode 100644 config.h create mode 100644 debug.c create mode 100644 debug.h create mode 100644 eco.h create mode 100644 file.c create mode 100644 file.h create mode 100644 func.c create mode 100644 func.h create mode 100644 key.c create mode 100644 key.h create mode 100644 kill.c create mode 100644 kill.h create mode 100644 main.c create mode 100644 screen.c create mode 100644 screen.h create mode 100644 status.c create mode 100644 status.h create mode 100644 term.c create mode 100644 term.h create mode 100644 update.c create mode 100644 update.h create mode 100644 view.c create mode 100644 view.h diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d92e1b5 --- /dev/null +++ b/COPYING @@ -0,0 +1,353 @@ + + Note! that the GPL below is copyrighted by the Free Software + Foundation, but the instance of code that it refers to (the Eco + text editor) is copyrighted by me. + + Also note that the only valid version of the GPL as far as eco + is concerned is _this_ particular version of the license (ie v2, not + v2.2 or v3.x or whatever), unless explicitly otherwise stated. + + Diego Hernan Borghetti + +---------------------------------------- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2df8b9d --- /dev/null +++ b/Makefile @@ -0,0 +1,57 @@ +# +# Makefile for Eco. +# + +# +# Custom options. +BUILD = + +# +# Install directory. +PREFIX = $(HOME) +BINDIR = $(PREFIX)/bin + +# +# User OPTIONS +# + +# Add the following line to get an eco.debug file +#BUILD += -DWITH_DEBUG + +# +# End of user options +# + +SOURCE = term.c screen.c status.c key.c main.c buffer.c update.c file.c \ +cmd.c debug.c func.c config.c kill.c view.c + +MODULES = term.o screen.o status.o key.o main.o buffer.o update.o file.o \ +cmd.o debug.o func.o config.o kill.o view.o + +CC = gcc +CFLAGS = -O2 -Wall -g +LIBS = -lcurses + +TARGET = eco + +.PHONY: clean install uninstall + +all: modules + @echo " Link $(TARGET)"; \ + $(CC) $(MODULES) -o $(TARGET) $(LIBS) $(CFLAGS) $(BUILD) + +modules: + @echo "Building Modules"; \ + for i in $(SOURCE); do \ + echo " CC $$i"; \ + $(CC) -c $$i $(CFLAGS) $(BUILD) || exit 1; \ + done + +clean: + rm -f $(MODULES) $(TARGET) + +install: + cp $(TARGET) $(BINDIR) + +uninstall: + rm -f $(BINDIR)/$(TARGET) diff --git a/README b/README new file mode 100644 index 0000000..2482211 --- /dev/null +++ b/README @@ -0,0 +1,72 @@ + Eco + A simple text editor. + +Eco is an Open Source project covered by the GNU General Public License +version 2, check the COPYING file for more details. + +It is maintained by Diego Hernan Borghetti and only test in Linux, so +ideas, patch, bugs, whatever are welcome to bdiego@gmail.com + +Eco is a small and simple text editor, need termios (ncurses) for set +the terminal characteristics and ansi scape sequence to draw in the +terminal. + +The build and install process is really simple, just type make and +following by make install. + +The Makefile is really simple now, if you need special library, cc flag +or any other thing, you can use the BUILD variable. + +The default directory to install is HOME/bin, but you can change it +in the Makefile (PREFIX variable). + + +Key binding +=========== + + The key binding can not be change from config file, it's build-in, and +it's: + + CX - CC - Quit + CX - CS - Save file + CK - Kill the current line + CR - Rotate the view + CG - Goto to line N + CX - CF - Find a file + CU - Force a scren update + CS - Forward search + CB - Backward search + CX - CR - Search and replace + CH - Backspace + CI - Tab + CM - Carriage ret + + Other key binding that maybe change: + CC - Cut the current line (put in the kill buffer) + CY - Paste the text from the kill buffer into the current buf + CL - Clean the kill buffer + +Colors +====== + + Eco only use color for two things, the status line and the line where the +cursor is, both color can be set in the config file (HOME/.eco) in two +section like: + +[ View ] + foreground = COLOR + background = COLOR + +[ Screen ] + current_line_foreground = COLOR + current_line_background = COLOR + +and COLOR can be: + 0 - Black + 1 - Red + 2 - Green + 3 - Yellow + 4 - Blue + 5 - Magenta + 6 - Cyan + 7 - White diff --git a/buffer.c b/buffer.c new file mode 100644 index 0000000..a73789a --- /dev/null +++ b/buffer.c @@ -0,0 +1,575 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include + +#include "buffer.h" +#include "kill.h" + + +E_Line *e_line_alloc(void) +{ + E_Line *ln; + + ln= (E_Line *)malloc(sizeof(E_Line)); + ln->next= NULL; + ln->prev= NULL; + ln->flag= 0; + ln->size= 16; + ln->used= 0; + ln->text= (char *)malloc(16); + return(ln); +} + +void e_line_realloc(E_Line *ln) +{ + ln->size+= 16; + ln->text= (char *)realloc((void *)ln->text, ln->size); +} + +void e_line_free(E_Line *ln) +{ + free((void *)ln->text); + free((void *)ln); +} + +void e_line_add(E_Buffer *bf, E_Line *ln) +{ + ln->next= bf->line->next; + ln->prev= bf->line; + + if (ln->next) + ln->next->prev= ln; + bf->line->next= ln; + bf->line= ln; + bf->nlines++; +} + +void e_line_add_first(E_Buffer *bf, E_Line *ln) +{ + ln->next= bf->lines; + ln->prev= NULL; + + if (ln->next) + ln->next->prev= ln; + + bf->lines= ln; + bf->first= ln; /* auto-reframe. */ + bf->nlines++; +} + +void e_line_remove(E_Buffer *bf, E_Line *ln) +{ + if (ln->next) + ln->next->prev= ln->prev; + if (ln->prev) + ln->prev->next= ln->next; + + if (bf->lines == ln) + bf->lines= ln->next; + + if (bf->first == ln) { + if (bf->first->prev) + bf->first= bf->first->prev; + else + bf->first= bf->first->next; + } + + if (bf->line == ln) { + if (bf->line->next) + bf->line= bf->line->next; + else + bf->line= bf->line->prev; + } + + ln->next= NULL; + ln->prev= NULL; + bf->nlines--; +} + +E_Buffer *e_buffer_new(char *file) +{ + E_Buffer *bf; + + bf= (E_Buffer *)malloc(sizeof(E_Buffer)); + bf->next= NULL; + bf->file= strdup(file); + + /* remove the full path, only show the name. */ + bf->name= strrchr(file, '/'); + if (!bf->name) + bf->name= bf->file; + else + bf->name++; + + bf->lines= e_line_alloc(); + bf->first= bf->lines; + bf->line= bf->lines; + bf->dot= 0; + bf->dot_pad= 0; + bf->flag= 0; + bf->nlines= 1; + bf->nl= 1; + return(bf); +} + +void e_buffer_free(E_Buffer *bf) +{ + E_Line *p; + + free((void *)bf->file); + while (bf->lines) { + p= bf->lines->next; + e_line_free(bf->lines); + bf->lines= p; + } + free((void *)bf); +} + +void e_buffer_recalc(E_Buffer *bf) +{ + E_Line *p; + + bf->nl= 1; + p= bf->lines; + while (p) { + if (p == bf->line) + break; + bf->nl++; + p= p->next; + } +} + +/* Add a new line at the current position in the buffer. */ +void e_buffer_newline(E_Buffer *bf) +{ + E_Line *ln; + + BUFFER_SET(bf, BUFFER_FLUSH); + + ln= e_line_alloc(); + e_line_add(bf, ln); + + /* Always clean the current position, the new line don't + * have any text.. + */ + bf->dot= 0; + bf->nl++; +} + +/* Add a new line at the begin of the buffer. */ +void e_buffer_newline_first(E_Buffer *bf) +{ + E_Line *ln; + + BUFFER_SET(bf, BUFFER_FLUSH); + + ln= e_line_alloc(); + e_line_add_first(bf, ln); + bf->dot= 0; + bf->nl++; +} + +/* Split the current line in two line, the starting + * point for split is the current cursor position. + */ +void e_buffer_splitline(E_Buffer *bf) +{ + E_Line *ln; + int i, dot; + + /* save the current line. */ + ln= bf->line; + + /* and the cursor position. */ + dot= bf->dot; + + /* insert a new line and add all the character + * from the current position, to the end. + */ + e_buffer_newline(bf); + for (i= dot; i < ln->used; i++) + e_buffer_insert(bf, ln->text[i]); + + ln->used= dot; + + /* Always go to the begin of the line. */ + bf->dot= 0; +} + +/* Join two line, the source line is the current line and + * the dest line is the prev. + */ +void e_buffer_joinline(E_Buffer *bf) +{ + E_Line *ln; + int i, dot; + + /* if we are at the begin, return. */ + if (!bf->line->prev) + return; + + /* save the current line. */ + ln= bf->line; + + /* move to the previous. */ + e_buffer_up(bf); + + /* put the cursor to the end of the line. */ + bf->dot= bf->line->used; + + /* and save the position. */ + dot= bf->dot; + + /* insert all the characters. */ + for (i= 0; i < ln->used; i++) + e_buffer_insert(bf, ln->text[i]); + + /* remove the unused line. */ + e_line_remove(bf, ln); + e_line_free(ln); + + /* restore the original cursor position. */ + bf->dot= dot; + e_buffer_recalc(bf); +} + +/* Remove the current line from the buffer, this also + * can save the line in the cut-buffer. + */ +void e_buffer_killline(E_Buffer *bf, int cut) +{ + E_Line *ln; + + if (cut) + e_kill_cut(bf->line); + + if ((!bf->line->prev) && (!bf->line->next)) { + /* If we don't have previous or next line, + * the only thing to do is clean the + * current line. + */ + e_buffer_cleanline(bf); + return; + } + else if (!bf->line->next) { + /* If we don't have next line, only clean. */ + e_buffer_cleanline(bf); + return; + } + + if (bf->line->used) { + /* This work like emacs, if the line have text + * first clean the text. + */ + e_buffer_cleanline(bf); + return; + } + + /* And if the line don't have text, remove it. */ + BUFFER_SET(bf, BUFFER_FLUSH); + + ln= bf->line; + e_buffer_down(bf); + e_line_remove(bf, ln); + e_line_free(ln); + e_buffer_recalc(bf); +} + +/* Insert a character in the current line at the current + * cursor position. + */ +void e_buffer_insert(E_Buffer *bf, int c) +{ + int i; + + BUFFER_SET(bf, BUFFER_FLUSH); + + /* check if we need reallocate the line. */ + if ((bf->line->used+1) >= bf->line->size) + e_line_realloc(bf->line); + + /* if the cursor is not at the end of the line, + * we need scroll the text to the right. + */ + if (bf->dot != bf->line->used) { + for (i= bf->line->used; i > bf->dot; i--) + bf->line->text[i]= bf->line->text[i-1]; + } + + /* insert the new character. */ + bf->line->text[bf->dot]= c; + bf->dot++; + bf->line->used++; +} + +/* Just that, insert a backspace ;) */ +void e_buffer_backspace(E_Buffer *bf) +{ + int i; + + /* The only case that we have here is if the coursor position + * is at the begin of the line, in that case we need join + * the two lines. + */ + if (bf->dot > 0) { + BUFFER_SET(bf, BUFFER_FLUSH); + + /* If the cursor is not at the end of the line, + * we need scroll the text. + */ + for (i= bf->dot; i < bf->line->used; i++) + bf->line->text[i-1]= bf->line->text[i]; + bf->dot--; + bf->line->used--; + } + else + e_buffer_joinline(bf); +} + +void e_buffer_del(E_Buffer *bf) +{ + if (bf->dot+1 < bf->line->used) { + bf->dot++; + e_buffer_backspace(bf); + } +} + +void e_buffer_up(E_Buffer *bf) +{ + if (bf->line->prev) { + bf->line= bf->line->prev; + if (bf->dot > bf->line->used) + bf->dot= bf->line->used; + bf->nl--; + } +} + +void e_buffer_down(E_Buffer *bf) +{ + if (bf->line->next) { + bf->line= bf->line->next; + if (bf->dot > bf->line->used) + bf->dot= bf->line->used; + bf->nl++; + } +} + +void e_buffer_left(E_Buffer *bf) +{ + if (bf->dot > 0) + bf->dot--; + else { + e_buffer_up(bf); + e_buffer_eol(bf); + } +} + +void e_buffer_right(E_Buffer *bf) +{ + if (bf->dot < bf->line->used) + bf->dot++; + else { + e_buffer_down(bf); + e_buffer_bol(bf); + } +} + +void e_buffer_goto_begin(E_Buffer *bf) +{ + bf->line= bf->lines; + bf->dot= 0; + bf->nl= 1; +} + +void e_buffer_goto_end(E_Buffer *bf) +{ + E_Line *p; + + p= bf->line; + while (p->next) + p= p->next; + + bf->line= p; + bf->dot= 0; + bf->nl= bf->nlines+1; /* zero */ +} + +void e_buffer_bol(E_Buffer *bf) +{ + bf->dot= 0; +} + +void e_buffer_eol(E_Buffer *bf) +{ + bf->dot= bf->line->used; +} + +void e_buffer_scroll(E_Buffer *bf, int nline, int dir) +{ + int i; + + for(i= 0; i < nline; i++) { + if (dir) { + if (!bf->first->prev) + break; + bf->first= bf->first->prev; + } + else { + if (!bf->first->next) + break; + bf->first= bf->first->next; + } + } + bf->line= bf->first; + if (bf->dot > bf->line->used) + bf->dot= bf->line->used; + e_buffer_recalc(bf); +} + +void e_buffer_goto(E_Buffer *bf, int line) +{ + E_Line *p; + int num; + + num= 1; + p= bf->lines; + while (p) { + if (num == line) + break; + num++; + p= p->next; + } + + if (!p) + return; + + bf->nl= num; + bf->line= p; + if (bf->dot > bf->line->used) + bf->dot= 0; +} + +void e_buffer_cleanline(E_Buffer *bf) +{ + BUFFER_SET(bf, BUFFER_FLUSH); + + bf->line->used= 0; + bf->dot= 0; +} + +E_Line *__e_buffer_search(E_Buffer *bf, char *pattern, int *dot_found, int dir) +{ + E_Line *ln; + int i, e, a, len, dot, found; + + len= strlen(pattern); + found= 0; + dot= 0; + + /* I know.. this is not the best backward.. but work. */ + if (dir == BUFFER_SEARCH_FORWARD) + ln= bf->line; + else + ln= bf->line->prev; + + while (ln) { + if (dir == BUFFER_SEARCH_FORWARD && ln == bf->line) + i= bf->dot; + else + i= 0; + + for (; i < ln->used; i++) { + if (ln->text[i] == pattern[0]) { + /* save the current position of the cursor. */ + a= i; + dot= i; + found= 1; + + for (e= 0; e < len; e++) { + if (ln->text[i] != pattern[e]) { + found= 0; + break; + } + + i++; + if (i > ln->used) { + found= 0; + break; + } + } + + i= a; + } + + if (found) + break; + } + + if (found) + break; + + if (dir == BUFFER_SEARCH_FORWARD) + ln= ln->next; + else + ln= ln->prev; + } + + if (dir == BUFFER_SEARCH_FORWARD) + *dot_found= (dot+len); + else + *dot_found= dot; + + return(ln); +} + +void e_buffer_search(E_Buffer *bf, char *pattern, int dir) +{ + E_Line *ln; + int dot; + + ln= __e_buffer_search(bf, pattern, &dot, dir); + if (ln) { + bf->first= ln; + bf->line= ln; + bf->dot= dot; + e_buffer_recalc(bf); + } +} + +int e_buffer_replace(E_Buffer *bf, char *pattern, char *replace) +{ + E_Line *ln; + int i, c, len, ncount, dot; + + c= strlen(pattern); + len= strlen(replace); + ncount= 0; + + ln= __e_buffer_search(bf, pattern, &dot, BUFFER_SEARCH_FORWARD); + while (ln) { + /* first set the line, so all the next call + * work fine. + */ + bf->first= ln; + bf->line= ln; + bf->dot= dot; + e_buffer_recalc(bf); + + /* now remove the pattern. */ + for (i= 0; i < c; i++) + e_buffer_backspace(bf); + + /* and now insert the new string. */ + for (i= 0; i < len; i++) + e_buffer_insert(bf, replace[i]); + + ncount++; + ln= __e_buffer_search(bf, pattern, &dot, BUFFER_SEARCH_FORWARD); + } + return(ncount); +} diff --git a/buffer.h b/buffer.h new file mode 100644 index 0000000..f732919 --- /dev/null +++ b/buffer.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_BUFFER_H +#define _ECO_BUFFER_H + +typedef struct _E_Line { + struct _E_Line *next; + struct _E_Line *prev; + + /* line flags. */ + char flag; + + /* chunk of text. */ + char *text; + + /* chunk size. */ + int size; + + /* memory used. */ + int used; +} E_Line; + +typedef struct _E_Buffer { + struct _E_Buffer *next; + + /* buffer file. */ + char *file; + + /* buffer name a shortcut for show in the status line. */ + char *name; + + /* line list. */ + E_Line *lines; + + /* "top-level" line. */ + E_Line *first; + + /* current "edit" line. */ + E_Line *line; + + /* cursor position in the "current line" */ + short dot; + + /* real pad for big lines. */ + short dot_pad; + + /* buffer flags. */ + char flag; + + /* number of lines in this buffer. */ + int nlines; + + /* current line number. */ + int nl; +} E_Buffer; + +/* buffer->flag */ +#define BUFFER_FLUSH (1<<0) +#define BUFFER_CMODE (1<<1) + +/* buffer search mode. */ +#define BUFFER_SEARCH_FORWARD 0 +#define BUFFER_SEARCH_BACKWARD 1 + +/* set/unset buffer flags */ +#define BUFFER_SET(b, f) \ +if (!(b->flag & f)) \ + b->flag|= (f) + +#define BUFFER_UNSET(b, f) \ +if (b->flag & f) \ + b->flag&= ~(f) + +E_Buffer *e_buffer_new(char *file); +void e_buffer_free(E_Buffer *bf); + +void e_buffer_newline(E_Buffer *bf); +void e_buffer_newline_first(E_Buffer *bf); +void e_buffer_joinline(E_Buffer *bf); +void e_buffer_splitline(E_Buffer *bf); +void e_buffer_cleanline(E_Buffer *bf); +void e_buffer_insert(E_Buffer *bf, int c); +void e_buffer_backspace(E_Buffer *bf); +void e_buffer_del(E_Buffer *bf); +void e_buffer_killline(E_Buffer *bf, int cut); + +void e_buffer_up(E_Buffer *bf); +void e_buffer_down(E_Buffer *bf); +void e_buffer_left(E_Buffer *bf); +void e_buffer_right(E_Buffer *bf); + +void e_buffer_goto(E_Buffer *bf, int line); +void e_buffer_goto_begin(E_Buffer *bf); +void e_buffer_goto_end(E_Buffer *bf); +void e_buffer_bol(E_Buffer *bf); +void e_buffer_eol(E_Buffer *bf); +void e_buffer_scroll(E_Buffer *bf, int nline, int dir); + +void e_buffer_search(E_Buffer *bf, char *pattern, int dir); +int e_buffer_replace(E_Buffer *bf, char *pattern, char *replace); + +#endif /* _ECO_BUFFER_H */ diff --git a/cmd.c b/cmd.c new file mode 100644 index 0000000..a77b122 --- /dev/null +++ b/cmd.c @@ -0,0 +1,204 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include + +#include "term.h" +#include "screen.h" +#include "buffer.h" +#include "view.h" +#include "eco.h" +#include "file.h" +#include "status.h" +#include "cmd.h" +#include "kill.h" +#include "update.h" + + +void e_cmd_cr(E_Eco *ec) +{ + if (ec->view->b->dot == 0) { + if (ec->view->b->line->prev) { + e_buffer_up(ec->view->b); + e_buffer_eol(ec->view->b); + e_buffer_newline(ec->view->b); + e_buffer_down(ec->view->b); + } + else { + e_buffer_newline_first(ec->view->b); + } + } + else if (ec->view->b->dot == ec->view->b->line->used) + e_buffer_newline(ec->view->b); + else { + e_buffer_splitline(ec->view->b); + } + e_view_redraw(ec->view); +} + +void e_cmd_ht(E_Eco *ec) +{ + e_buffer_insert(ec->view->b, '\t'); + e_view_redraw(ec->view); +} + +void e_cmd_backspace(E_Eco *ec) +{ + e_buffer_backspace(ec->view->b); + e_view_redraw(ec->view); +} + +void e_cmd_write(E_Eco *ec) +{ + char *buf; + + if (!strcmp(ec->view->b->file, "main")) { + buf= e_status_get_msg(ec, "File: "); + if (!buf) + return; + + free((void *) ec->view->b->file); + ec->view->b->file= strdup(buf); + } + e_file_write(ec, ec->view->b); +} + +void e_cmd_killline(E_Eco *ec) +{ + e_buffer_killline(ec->view->b, 0); + e_view_redraw(ec->view); +} + +void e_cmd_rotate(E_Eco *ec) +{ + e_list_rotate(ec); +} + +void e_cmd_goto(E_Eco *ec) +{ + char *buf; + int line; + + buf= e_status_get_msg(ec, "Line: "); + if (buf) { + line= atoi(buf); + e_buffer_goto(ec->view->b, line); + e_view_redraw(ec->view); + } +} + +void e_cmd_find_file(E_Eco *ec) +{ + E_Buffer *bf; + E_View *v; + char *buf; + int st; + + buf= e_status_get_msg(ec, "Find File: "); + if (buf) { + bf= e_list_find(ec, buf); + if (bf) { + v= e_list_view_find(ec, bf); + e_view_unshow(ec->view); + e_view_show(v); + e_view_redraw(v); + ec->view= v; + } + else { + bf= e_file_read(buf, &st); + if (bf) { + v= e_view_new(ec->sc); + v->b= bf; + e_list_view_add(ec, v); + e_list_add(ec, bf); + + e_view_show(v); + e_view_redraw(v); + e_view_unshow(ec->view); + ec->view= v; + } + } + } +} + +void e_cmd_cutline(E_Eco *ec) +{ + e_buffer_killline(ec->view->b, 1); + e_view_redraw(ec->view); +} + +void e_cmd_paste(E_Eco *ec) +{ + e_kill_paste(ec->view->b); + e_view_redraw(ec->view); +} + +void e_cmd_cleankill(E_Eco *ec) +{ + e_kill_clean(); +} + +void e_cmd_update(E_Eco *ec) +{ + e_view_redraw(ec->view); + e_update(ec); + e_status_draw(ec); + e_screen_swap(ec->tr, ec->sc, 1); + e_term_flush(); +} + +void e_cmd_search_forward(E_Eco *ec) +{ + char *buf; + + buf= e_status_get_msg(ec, "Search: "); + if (buf) { + strcpy(ec->view->search, buf); + e_buffer_search(ec->view->b, ec->view->search, BUFFER_SEARCH_FORWARD); + e_status_set_msg(ec, "(Search: %s)", ec->view->search); + e_view_redraw(ec->view); + } + else if (ec->view->search) { + e_buffer_search(ec->view->b, ec->view->search, BUFFER_SEARCH_FORWARD); + e_status_set_msg(ec, "(Search: %s)", ec->view->search); + e_view_redraw(ec->view); + } +} + +void e_cmd_search_backward(E_Eco *ec) +{ + char *buf; + + buf= e_status_get_msg(ec, "Search: "); + if (buf) { + strcpy(ec->view->search, buf); + e_buffer_search(ec->view->b, ec->view->search, BUFFER_SEARCH_BACKWARD); + e_status_set_msg(ec, "(Search: %s)", ec->view->search); + e_view_redraw(ec->view); + } + else if (ec->view->search) { + e_buffer_search(ec->view->b, ec->view->search, BUFFER_SEARCH_BACKWARD); + e_status_set_msg(ec, "(Search: %s)", ec->view->search); + e_view_redraw(ec->view); + } +} + +void e_cmd_replace(E_Eco *ec) +{ + char *buf; + int num; + + buf= e_status_get_msg(ec, "Replace: "); + if (buf) { + strcpy(ec->view->search, buf); + buf= e_status_get_msg(ec, "With: "); + if (buf) { + num= e_buffer_replace(ec->view->b, ec->view->search, buf); + e_status_set_msg(ec, "(%d subsitutions)", num); + } + } +} diff --git a/cmd.h b/cmd.h new file mode 100644 index 0000000..775e786 --- /dev/null +++ b/cmd.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_CMD_H +#define _ECO_CMD_H + +void e_cmd_cr(E_Eco *ec); +void e_cmd_ht(E_Eco *ec); +void e_cmd_backspace(E_Eco *ec); + +void e_cmd_write(E_Eco *ec); +void e_cmd_killline(E_Eco *ec); +void e_cmd_rotate(E_Eco *ec); +void e_cmd_goto(E_Eco *ec); +void e_cmd_find_file(E_Eco *ec); + +void e_cmd_cutline(E_Eco *ec); +void e_cmd_paste(E_Eco *ec); +void e_cmd_cleankill(E_Eco *ec); + +void e_cmd_update(E_Eco *ec); + +void e_cmd_search_forward(E_Eco *ec); +void e_cmd_search_backward(E_Eco *ec); +void e_cmd_replace(E_Eco *ec); + +void e_cmd_split(E_Eco *ec); +void e_cmd_change_view(E_Eco *ec); + +#endif /* _ECO_CMD_H */ diff --git a/config.c b/config.c new file mode 100644 index 0000000..e551001 --- /dev/null +++ b/config.c @@ -0,0 +1,308 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include + +#include "debug.h" +#include "config.h" + + +/* sections list. */ +E_Section *sections= NULL; + +int e_config_read_line(FILE *fp, char *buf, int len) +{ + int i, c; + + for (i= 0; i < len; i++) { + c= fgetc(fp); + if (c == EOF) { + if (i) { + buf[i]= '\0'; + return(i); + } + return(-1); + } + + if (c == '\n') { + buf[i]= '\0'; + return(i); + } + buf[i]= c; + } + + /* the line is too big, so we skip this. */ + return(0); +} + +int __e_config_is_section(char *line) +{ + char *p; + + p= line; + while (p && (*p == ' ' || *p == '\t')) + p++; + + if (*p == '[') + return(0); + return(1); +} + +int __e_config_is_option(char *line) +{ + char *p; + + p= strchr(line, '='); + if (p) + return(0); + return(1); +} + +E_Section *__e_config_section(char *line) +{ + E_Section *sc; + char *p; + int i, found; + + sc= (E_Section *)malloc(sizeof(E_Section)); + sc->next= NULL; + sc->list= NULL; + sc->last= NULL; + + /* is valid if the line have space or tab befor the '[' */ + p= line; + while (*p == ' ' || *p == '\t') + p++; + + /* ok, this is the first character != of ' ' or '\t' + * and is the start of the section, '[' that is why + * we add a + two character. + */ + p+= 2; + + /* at this point we are in the start of the section name, + * but need take care that the section name maybe have space, + * for eg. [ Keys ] and not [Keys].. so we support both model. + */ + while (p && (*p == ' ' || *p == '\t')) + p++; + + if (!p) { + free((void *)sc); + return(NULL); + } + + /* count the number of character. */ + for (i= 0, found= 0; i < strlen(p); i++) { + if (p[i] == ' ' || p[i] == ']') { + found= 1; + break; + } + } + + if (!found) { + free((void *)sc); + return(NULL); + } + + sc->name= (char *)malloc(i+1); + i= 0; + while (p) { + if (*p == ' ' || *p == ']') { + sc->name[i]= '\0'; + break; + } + sc->name[i]= *p; + i++; + p++; + } + + return(sc); +} + +E_Config *__e_config_option(char *line) +{ + E_Config *cf; + char *p; + int i; + + cf= (E_Config *)malloc(sizeof(E_Config)); + cf->next= NULL; + cf->key= NULL; + cf->value= NULL; + + /* the options always can have tab or ' ' */ + p= line; + while (*p == ' ' || *p == '\t') + p++; + + /* count the number of characters. */ + for (i= 0; i < strlen(p); i++) { + if (p[i] == ' ' || p[i] == '=') + break; + } + + cf->key= (char *)malloc(i+1); + i= 0; + while (p) { + if (*p == ' ' || *p == '=') { + cf->key[i]= '\0'; + break; + } + cf->key[i]= *p; + i++; + p++; + } + + /* now the value. */ + p= strchr(line, '='); + p++; + + /* the value also have space or tab, so skip it. */ + while (p && (*p == ' ' || *p == '\t')) + p++; + + cf->value= (char *)malloc(strlen(p)+1); + strcpy(cf->value, p); + return(cf); +} + +void e_config_parse(char *file) +{ + E_Section *sc; + E_Config *cf; + FILE *fp; + char *line; + int i; + + fp= fopen(file, "r"); + if (!fp) + return; + + line= (char *)malloc(1024); + sc= NULL; + i= e_config_read_line(fp, line, 1023); + while (i != -1) { + if (i == 0) + goto next_line; + + /* skip comments and blank lines */ + if (line[0] == '#' || line[0] == '\n') + goto next_line; + + if (__e_config_is_section(line) == 0) { + sc= __e_config_section(line); + sc->next= sections; + sections= sc; + goto next_line; + } + + /* if we don't have a section, skip this line. */ + if (!sc) + goto next_line; + + if (__e_config_is_option(line) == 0) { + cf= __e_config_option(line); + cf->next= NULL; + if (!sc->list) + sc->list= cf; + if (sc->last) + sc->last->next= cf; + sc->last= cf; + } +next_line: + i= e_config_read_line(fp, line, 1023); + } + +#ifdef WITH_DEBUG + e_debug_printf("==> Config File <==\n"); + sc= sections; + while (sc) { + e_debug_printf("Section: (%s)\n", sc->name); + cf= sc->list; + while (cf) { + e_debug_printf("\tKey: (%s)\n", cf->key); + e_debug_printf("\tValue: (%s)\n", cf->value); + cf= cf->next; + } + sc= sc->next; + } + e_debug_printf("==> End Config File <==\n"); +#endif + + fclose(fp); + free((void *)line); +} + +void e_config_init(void) +{ + char *home; + char *file; + + home= getenv("HOME"); + if (!home) + return; + + file= (char *)malloc(strlen(home) + 6); + sprintf(file, "%s/.eco", home); + e_config_parse(file); + free((void *)file); +} + +E_Section *e_config_find_section(char *name) +{ + E_Section *p; + + p= sections; + while (p) { + if (!strcmp(p->name, name)) + return(p); + p= p->next; + } + return(NULL); +} + +E_Config *e_config_find_config(E_Section *sc, char *key) +{ + E_Config *p; + + p= sc->list; + while (p) { + if (!strcmp(p->key, key)) + return(p); + p= p->next; + } + return(NULL); +} + +char *e_config_get(char *name, char *key) +{ + E_Section *sc; + E_Config *cf; + + sc= e_config_find_section(name); + if (sc) { + cf= e_config_find_config(sc, key); + if (cf) + return(cf->value); + } + return(NULL); +} + +int e_config_get_int(char *name, char *key) +{ + E_Section *sc; + E_Config *cf; + + sc= e_config_find_section(name); + if (sc) { + cf= e_config_find_config(sc, key); + if (cf) + return(atoi(cf->value)); + } + return(-1); +} diff --git a/config.h b/config.h new file mode 100644 index 0000000..c576392 --- /dev/null +++ b/config.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_CONFIG_H +#define _ECO_CONFIG_H + +typedef struct _E_Config { + struct _E_Config *next; + + /* key, name ... */ + char *key; + + /* value, function, name ... */ + char *value; +} E_Config; + +typedef struct _E_Section { + struct _E_Section *next; + + /* section name. */ + char *name; + + /* list of key/value pair. */ + E_Config *list; + E_Config *last; +} E_Section; + +void e_config_init(void); +void e_config_parse(char *file); + +E_Section *e_config_find_section(char *name); +E_Config *e_config_find_config(E_Section *sc, char *key); + +char *e_config_get(char *name, char *key); +int e_config_get_int(char *name, char *key); + +#endif /* _ECO_CONFIG_H */ diff --git a/debug.c b/debug.c new file mode 100644 index 0000000..03fe68c --- /dev/null +++ b/debug.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include + + +#ifdef WITH_DEBUG + +/* debug file. */ +FILE *_dbg_fp= NULL; + +#endif + +void e_debug_init(void) +{ +#ifdef WITH_DEBUG + _dbg_fp= fopen("eco.debug", "w"); + if (_dbg_fp) + setvbuf(_dbg_fp, NULL, _IONBF, 0); +#endif +} + +void e_debug_end(void) +{ +#ifdef WITH_DEBUG + if (_dbg_fp) { + fclose(_dbg_fp); + _dbg_fp= NULL; + } +#endif +} + +void e_debug_printf(char *fmt, ...) +{ +#ifdef WITH_DEBUG + va_list ap; + + if (!_dbg_fp) + return; + + va_start(ap, fmt); + vfprintf(_dbg_fp, fmt, ap); + va_end(ap); +#endif +} diff --git a/debug.h b/debug.h new file mode 100644 index 0000000..3cd578a --- /dev/null +++ b/debug.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_DEBUG_H +#define _ECO_DEBUG_H + +#include + +void e_debug_init(void); +void e_debug_end(void); +void e_debug_printf(char *fmt, ...); + +#endif /* _ECO_DEBUG_H */ diff --git a/eco.h b/eco.h new file mode 100644 index 0000000..28fa510 --- /dev/null +++ b/eco.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_H +#define _ECO_H + +typedef struct _E_Eco { + /* tell when need leave the loop.. */ + int loop; + + /* terminal struct. */ + E_Term *tr; + + /* virtual terminal. */ + E_Screen *sc; + + /* buffer list. */ + E_Buffer *buffers; + + /* active view and buffer. */ + E_View *view; + + /* view list. */ + E_View *view_list; + + /* default screen colors. */ + int fg; + int bg; +} E_Eco; + +E_Buffer *e_list_find(E_Eco *ec, char *name); +void e_list_rotate(E_Eco *ec); +void e_list_add(E_Eco *ec, E_Buffer *bf); +void e_list_remove(E_Eco *ec, E_Buffer *bf); + +void e_list_view_add(E_Eco *ec, E_View *v); +void e_list_view_rem(E_Eco *ec, E_View *v); +E_View *e_list_view_find(E_Eco *ec, E_Buffer *b); + +#endif /* _ECO_H */ diff --git a/file.c b/file.c new file mode 100644 index 0000000..1d36634 --- /dev/null +++ b/file.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "term.h" +#include "screen.h" +#include "buffer.h" +#include "view.h" +#include "eco.h" +#include "status.h" + + +E_Buffer *e_file_read(char *file, int *status) +{ + struct stat st; + E_Buffer *bf; + FILE *fp; + int c; + + /* clean error status. */ + *status= 0; + + bf= e_buffer_new(file); + if (!bf) + return(NULL); + + if (stat(file, &st)) { + e_buffer_free(bf); + return(NULL); + } + + if (!(S_ISREG(st.st_mode))) { + /* this is not a regular file. */ + *status= 1; + + e_buffer_free(bf); + return(NULL); + } + + fp= fopen(file, "r"); + if (!fp) { + /* the file exist, but we can't read it. */ + *status= 1; + + e_buffer_free(bf); + return(NULL); + } + + c= fgetc(fp); + while (!feof(fp)) { + if (c == '\n') + e_buffer_newline(bf); + else if (c == '\t') + e_buffer_insert(bf, '\t'); + else + e_buffer_insert(bf, c); + c= fgetc(fp); + } + + e_buffer_goto_begin(bf); + BUFFER_UNSET(bf, BUFFER_FLUSH); + fclose(fp); + return(bf); +} + +void e_file_write(E_Eco *ec, E_Buffer *bf) +{ + FILE *fp; + E_Line *ln; + int i, nlines; + + if (!(bf->flag & BUFFER_FLUSH)) + return; + + fp= fopen(bf->file, "w"); + if (!fp) + return; + + ln= bf->lines; + nlines= 0; + while (ln) { + for (i= 0; i < ln->used; i++) + fputc(ln->text[i], fp); + + if (ln->next) + fputc('\n', fp); + nlines++; + ln= ln->next; + } + + fclose(fp); + BUFFER_UNSET(bf, BUFFER_FLUSH); + + e_status_set_msg(ec, "(Wrote %d lines)", nlines); +} diff --git a/file.h b/file.h new file mode 100644 index 0000000..99ed719 --- /dev/null +++ b/file.h @@ -0,0 +1,12 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_FILE_H +#define _ECO_FILE_H + +E_Buffer *e_file_read(char *file, int *status); +void e_file_write(E_Eco *ec, E_Buffer *bf); + +#endif /* _ECO_FILE_H */ diff --git a/func.c b/func.c new file mode 100644 index 0000000..cc28289 --- /dev/null +++ b/func.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include + +#include "term.h" +#include "screen.h" +#include "buffer.h" +#include "view.h" +#include "eco.h" +#include "func.h" + + +/* name to function binding list. */ +E_Function *functions= NULL; + +void e_func_free(void) +{ + E_Function *p; + + while (functions) { + p= functions->next; + free((void *)functions); + functions= p; + } +} + +E_Function *e_func_find(char *name) +{ + E_Function *p; + + p= functions; + while (p) { + if (!strcmp(p->name, name)) + return(p); + p= p->next; + } + return(NULL); +} + +void e_func_add(char *name, void (*func)(E_Eco *)) +{ + E_Function *fn; + + fn= e_func_find(name); + if (fn) + return; + + fn= (E_Function *)malloc(sizeof(E_Function)); + if (!fn) + return; + + fn->name= name; + fn->func= func; + fn->next= functions; + functions= fn; +} + +void e_func_remove(char *name) +{ + E_Function *p, *p1; + + p= functions; + p1= NULL; + while (p) { + if (!strcmp(p->name, name)) { + if (p1) + p1->next= p->next; + else + functions= p->next; + + free((void *)p); + return; + } + p1= p; + p= p->next; + } +} diff --git a/func.h b/func.h new file mode 100644 index 0000000..2d32bed --- /dev/null +++ b/func.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_FUNC_H +#define _ECO_FUNC_H + +typedef struct _E_Function { + struct _E_Function *next; + + /* function name. */ + char *name; + + /* pointer to the function. */ + void (*func)(E_Eco *); +} E_Function; + +void e_func_free(void); +E_Function *e_func_find(char *name); +void e_func_add(char *name, void (*func)(E_Eco *)); +void e_func_remove(char *name); + +#endif /* _ECO_FUNC_H */ diff --git a/key.c b/key.c new file mode 100644 index 0000000..8a42684 --- /dev/null +++ b/key.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include + +#include "term.h" +#include "screen.h" +#include "buffer.h" +#include "view.h" +#include "eco.h" +#include "status.h" +#include "key.h" + + +/* key list. */ +E_Key *keys= NULL; + +void e_key_free(void) +{ + E_Key *p; + + while (keys) { + p= keys->next; + free((void *)keys); + keys= p; + } +} + +E_Key *__e_key_find(short code, short ctrl_x) +{ + E_Key *p; + + p= keys; + while (p) { + if (p->code == code && p->ctrl_x == ctrl_x) + return(p); + p= p->next; + } + return(NULL); +} + +void e_key_add(short code, short ctrl_x, void (*cb)(E_Eco *)) +{ + E_Key *key= __e_key_find(code, ctrl_x); + + if (key) + return; + + key= (E_Key *)malloc(sizeof(E_Key)); + if (!key) + return; + + key->next= keys; + key->ctrl_x= ctrl_x; + key->code= code; + key->exec= cb; + keys= key; +} + +void e_key_remove(short code, short ctrl_x) +{ + E_Key *p, *p1; + + p= keys; + p1= NULL; + while (p) { + if (p->code == code && p->ctrl_x == ctrl_x) { + if (p1) + p1->next= p->next; + else + keys= p->next; + + free((void *)p); + return; + } + p1= p; + p= p->next; + } +} + +int e_key_exec(E_Eco *ec, short code, short ctrl_x) +{ + E_Key *key; + + key= __e_key_find(code, ctrl_x); + if (key) { + (*key->exec) (ec); + return(0); + } + return(1); +} diff --git a/key.h b/key.h new file mode 100644 index 0000000..1859e48 --- /dev/null +++ b/key.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_KEY_H +#define _ECO_KEY_H + +typedef struct _E_Key { + struct _E_Key *next; + + /* need ctrl + X ? */ + short ctrl_x; + + /* key code. */ + short code; + + /* callback. */ + void (*exec)(E_Eco *); +} E_Key; + +void e_key_free(void); + +void e_key_add(short code, short ctrl_x, void (*cb)(E_Eco *)); +void e_key_remove(short code, short ctrl_x); +int e_key_exec(E_Eco *ec, short code, short ctrl_x); + +#endif /* _ECO_KEY_H */ diff --git a/kill.c b/kill.c new file mode 100644 index 0000000..cbb984e --- /dev/null +++ b/kill.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include + +#include "term.h" +#include "screen.h" +#include "buffer.h" +#include "view.h" +#include "eco.h" + + +/* "kill" buffer, all the text that you cut/remove go here. */ +E_Buffer *kill_buf= NULL; + +void e_kill_init(void) +{ + kill_buf= e_buffer_new("KillBuffer"); +} + +void e_kill_end(void) +{ + e_buffer_free(kill_buf); +} + +void e_kill_cut(E_Line *ln) +{ + int i; + + if (!ln->used) { + /* just a \n. */ + e_buffer_newline(kill_buf); + return; + } + + for (i= 0; i < ln->used; i++) + e_buffer_insert(kill_buf, ln->text[i]); +} + +void e_kill_paste(E_Buffer *bf) +{ + E_Line *p; + int i; + + p= kill_buf->lines; + while (p) { + for (i= 0; i < p->used; i++) + e_buffer_insert(bf, p->text[i]); + e_buffer_newline(bf); + p= p->next; + } +} + +void e_kill_clean(void) +{ + /* just drop the buffer, this is bad, but work ;) */ + e_kill_end(); + e_kill_init(); +} diff --git a/kill.h b/kill.h new file mode 100644 index 0000000..c3279f3 --- /dev/null +++ b/kill.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_KILL_H +#define _ECO_KILL_H + +void e_kill_init(void); +void e_kill_end(void); + +void e_kill_cut(E_Line *ln); +void e_kill_paste(E_Buffer *bf); +void e_kill_clean(void); + +#endif /* _ECO_KILL_H */ diff --git a/main.c b/main.c new file mode 100644 index 0000000..782c437 --- /dev/null +++ b/main.c @@ -0,0 +1,512 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include +#include +#include + +#include "debug.h" +#include "term.h" +#include "screen.h" +#include "buffer.h" +#include "view.h" +#include "eco.h" +#include "file.h" +#include "status.h" +#include "update.h" +#include "key.h" +#include "func.h" +#include "cmd.h" +#include "config.h" +#include "kill.h" + + +/* only global in this file!! */ +E_Eco *E; + +int e_check_unsave(E_Eco *ec) +{ + E_Buffer *p; + char *s, *buf; + + buf= (char *)malloc(512); + p= ec->buffers; + while (p) { + if (!strcmp(p->file, "main")) { + p= p->next; + continue; + } + + if (p->flag & BUFFER_FLUSH) { + sprintf(buf, "Modified buffer (%s), save (y/n/c)? ", p->file); + while (!(s= e_status_get_msg(ec, buf))) + ; + + if (s[0] == 'y') + e_file_write(ec, p); + else if (s[0] == 'c') { + free((void *)buf); + return(1); + } + } + p= p->next; + } + free((void *)buf); + return(0); +} + +void e_signal(int num) +{ + E->loop= 0; +} + +void e_signal_size(int num) +{ + struct winsize ws; + E_View *v; + + if (ioctl(0, TIOCGWINSZ, &ws)) + return; + + if (ws.ws_row-1 == E->tr->nrow && ws.ws_col == E->tr->ncol) + return; + + E->tr->nrow= ws.ws_row-1; + E->tr->ncol= ws.ws_col; + + /* yes... fix this. */ + e_screen_free(E->sc); + E->sc= e_screen_init(E->tr); + + /* ok, we need resize all the view. */ + v= E->view_list; + while (v) { + e_view_resize(v, E->sc->nrow, E->sc->ncol); + v= v->next; + } + + /* clearn term and screen. */ + e_term_move(0, 0); + e_term_eeop(E->tr); + + e_screen_move(E->sc, 0, 0); + e_screen_eeop(E->sc); + e_update(E); + e_status_draw(E); + e_screen_swap(E->tr, E->sc, 1); + e_term_flush(); + signal(SIGWINCH, e_signal_size); +} + +void e_quit(E_Eco *ec) +{ + if (e_check_unsave(ec)) + return; + E->loop= 0; +} + +void e_keymap_init(void) +{ + e_key_add('C', 1, e_quit); + e_key_add('S', 1, e_cmd_write); + e_key_add('K', 0, e_cmd_killline); + e_key_add('R', 0, e_cmd_rotate); + e_key_add('G', 0, e_cmd_goto); + e_key_add('F', 1, e_cmd_find_file); + e_key_add('U', 0, e_cmd_update); + e_key_add('S', 0, e_cmd_search_forward); + e_key_add('B', 0, e_cmd_search_backward); + e_key_add('R', 1, e_cmd_replace); + + e_key_add('M', 0, e_cmd_cr); + e_key_add('I', 0, e_cmd_ht); + e_key_add('H', 0, e_cmd_backspace); + e_key_add('C', 0, e_cmd_cutline); + e_key_add('Y', 0, e_cmd_paste); + e_key_add('L', 0, e_cmd_cleankill); +} + +void e_mode_move(E_Eco *ec) +{ + int c, redraw; + + c= e_term_getc(); + redraw= 0; + + if (c == '[') { + c= e_term_getc(); + if (c == 'D') { + e_buffer_left(ec->view->b); + redraw= 1; + } + else if (c == 'C') { + e_buffer_right(ec->view->b); + redraw= 1; + } + else if (c == 'A') { + e_buffer_up(ec->view->b); + redraw= 1; + } + else if (c == 'B') { + e_buffer_down(ec->view->b); + redraw= 1; + } + else if (c == 'H') { + e_buffer_bol(ec->view->b); + redraw= 1; + } + else if (c == 'F') { + e_buffer_eol(ec->view->b); + redraw= 1; + } + else if (c == '1') { + c= e_term_getc(); + if (c == '~') { + e_buffer_bol(ec->view->b); + redraw= 1; + } + else if (c == '7') { + c= e_term_getc(); + if (c == '7') { + if (ec->view->b->dot == ec->view->b->line->used) { + e_buffer_down(ec->view->b); + e_buffer_joinline(ec->view->b); + } + else + e_buffer_del(ec->view->b); + redraw= 1; + } + } + } + else if (c == '3') { + c= e_term_getc(); + if (c == '~') { + if (ec->view->b->dot == ec->view->b->line->used) { + e_buffer_down(ec->view->b); + e_buffer_joinline(ec->view->b); + } + else + e_buffer_del(ec->view->b); + redraw= 1; + } + } + else if (c == '4') { + c= e_term_getc(); + if (c == '~') { + e_buffer_eol(ec->view->b); + redraw= 1; + } + } + else if (c == '5') { + c= e_term_getc(); + if (c == '~') { + e_buffer_scroll(ec->view->b, ec->sc->nrow - 3, 1); + redraw= 1; + } + } + else if (c == '6') { + c= e_term_getc(); + if (c == '~') { + e_buffer_scroll(ec->view->b, ec->sc->nrow - 3, 0); + redraw= 1; + } + } + else if (c == '[') { + c= e_term_getc(); + if (c == '3') { + c= e_term_getc(); + if (c == '~') { + if (ec->view->b->dot == ec->view->b->line->used) { + e_buffer_down(ec->view->b); + e_buffer_joinline(ec->view->b); + } + else + e_buffer_del(ec->view->b); + redraw= 1; + } + } + } + } + else if (c == 'O') { + c= e_term_getc(); + if (c == 'F') { + e_buffer_eol(ec->view->b); + redraw= 1; + } + else if (c == 'H') { + e_buffer_bol(ec->view->b); + redraw= 1; + } + } + + if (redraw) + e_view_redraw(ec->view); +} + +void e_mode_cmd(E_Eco *ec, int c) +{ + short ctrl_x; + + c= c + '@'; + ctrl_x= 0; + + if (c == 'X') { + c= e_term_getc(); + ctrl_x= 1; + + if (c > 0x00 && c < 0x20) + c= c + '@'; + + /* yes, ctrl+G always cancel the command. */ + if (c == 'G') + return; + } + e_key_exec(ec, c, ctrl_x); +} + +void e_mode_edit(E_Eco *ec, int c) +{ + if (c == 0x7f) + e_buffer_backspace(ec->view->b); + else + e_buffer_insert(ec->view->b, c); + e_view_redraw(ec->view); +} + +int main(int argc, char **argv) +{ + E_Buffer *bf; + E_View *v; + int c, i, st; + + E= (E_Eco *)malloc(sizeof(E_Eco)); + if (!E) { + perror("malloc"); + exit(-1); + } + + e_debug_init(); + e_config_init(); + + E->tr= e_term_open(); + E->sc= e_screen_init(E->tr); + + /* handler signal. */ + signal(SIGTERM, e_signal); + signal(SIGQUIT, e_signal); + signal(SIGWINCH, e_signal_size); + + /* view list. */ + E->view_list= NULL; + + /* buffers list. */ + E->buffers= NULL; + + argc--; + argv++; + + for (i= 0; i < argc; i++) { + /* parse options here!! */ + bf= e_file_read(argv[i], &st); + if ((!bf) && (!st)) + bf= e_buffer_new(argv[i]); + + if (bf) { + v= e_view_new(E->sc); + v->b= bf; + e_list_view_add(E, v); + e_list_add(E, bf); + } + } + + if (!E->buffers) { + /* default buffer. */ + bf= e_buffer_new("main"); + v= e_view_new(E->sc); + v->b= bf; + e_list_view_add(E, v); + e_list_add(E, bf); + } + + /* and add to the view. */ + E->view= E->view_list; + e_view_show(E->view); + e_view_redraw(E->view); + + /* name to functions binding. */ + e_func_add("e_quit", e_quit); + e_func_add("e_cmd_write", e_cmd_write); + e_func_add("e_cmd_killline", e_cmd_killline); + e_func_add("e_cmd_rotate", e_cmd_rotate); + e_func_add("e_cmd_goto", e_cmd_goto); + e_func_add("e_cmd_cr", e_cmd_cr); + e_func_add("e_cmd_ht", e_cmd_ht); + e_func_add("e_cmd_backspace", e_cmd_backspace); + e_func_add("e_cmd_find_file", e_cmd_find_file); + e_func_add("e_cmd_cutline", e_cmd_cutline); + e_func_add("e_cmd_paste", e_cmd_paste); + e_func_add("e_cmd_cleankill", e_cmd_cleankill); + + /* load user keymap. */ + e_keymap_init(); + + /* init the kill buffer. */ + e_kill_init(); + + /* default colors. */ + E->fg= E_TR_WHITE; + E->bg= E_TR_BLACK; + + /* clean term and screen. */ + e_term_move(0, 0); + e_term_eeop(E->tr); + + e_screen_move(E->sc, 0, 0); + e_screen_eeop(E->sc); + e_update(E); + e_status_draw(E); + e_screen_swap(E->tr, E->sc, 1); + + /* and start the loop. */ + E->loop= 1; + + while (E->loop) { + c= e_term_getc(); + /* + * Clear the status message, before + * call any other functions. + */ + E->view->stmsg= 0; + + if (c == E_TR_ESC) + e_mode_move(E); + else if (c > 0x00 && c < 0x20) + e_mode_cmd(E, c); + else if (c > 0x1f && c <= 0x7f) + e_mode_edit(E, c); + + e_update(E); + e_status_draw(E); + e_screen_swap(E->tr, E->sc, 0); + e_term_flush(); + } + + while (E->buffers) { + /* + * Don't need check for changes, the e_quit + * function already handler it. + */ + bf= E->buffers->next; + e_buffer_free(E->buffers); + E->buffers= bf; + } + + e_kill_end(); + e_key_free(); + + while (E->view_list) { + v= E->view_list->next; + e_view_free(E->view_list); + E->view_list= v; + } + + e_screen_free(E->sc); + e_term_close(E->tr); + free((void *)E); + e_debug_end(); + + return(0); +} + +void e_list_rotate(E_Eco *ec) +{ + e_view_unshow(ec->view); + if (ec->view->next) + ec->view= ec->view->next; + else + ec->view= ec->view_list; + + e_view_show(ec->view); + e_view_redraw(ec->view); +} + +E_Buffer *e_list_find(E_Eco *ec, char *name) +{ + E_Buffer *p; + + p= ec->buffers; + while (p) { + if (!strcmp(p->file, name)) + return(p); + p= p->next; + } + return(NULL); +} + +void e_list_add(E_Eco *ec, E_Buffer *bf) +{ + bf->next= ec->buffers; + ec->buffers= bf; +} + +void e_list_remove(E_Eco *ec, E_Buffer *bf) +{ + E_Buffer *p, *p1; + + p= ec->buffers; + p1= NULL; + while (p) { + if (p == bf) { + if (p1) + p1->next= p->next; + else + ec->buffers= p->next; + + bf->next= NULL; + return; + } + p1= p; + p= p->next; + } +} + +void e_list_view_add(E_Eco *ec, E_View *v) +{ + v->next= ec->view_list; + v->prev= NULL; + if (ec->view_list) + ec->view_list->prev= v; + ec->view_list= v; +} + +void e_list_view_rem(E_Eco *ec, E_View *v) +{ + if (v->prev) + v->prev->next= v->next; + if (v->next) + v->next->prev= v->prev; + + if (v == ec->view_list) { + if (v->next) + ec->view_list= v->next; + else + ec->view_list= v->prev; + } +} + +E_View *e_list_view_find(E_Eco *ec, E_Buffer *b) +{ + E_View *v; + + v= ec->view_list; + while (v) { + if (v->b == b) + return(v); + v= v->next; + } + return(NULL); +} diff --git a/screen.c b/screen.c new file mode 100644 index 0000000..4096e2e --- /dev/null +++ b/screen.c @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include + +#include "term.h" +#include "screen.h" + + +E_Screen *e_screen_init(E_Term *tr) +{ + E_ScreenLine *ln; + E_Screen *sc; + int i; + + sc= (E_Screen *)malloc(sizeof(E_Screen)); + if (!sc) { + e_term_close(tr); + perror("malloc"); + exit (-1); + } + + sc->vscr= (E_ScreenLine **)malloc(sizeof(E_ScreenLine *) * tr->nrow); + sc->pscr= (E_ScreenLine **)malloc(sizeof(E_ScreenLine *) * tr->nrow); + if ((!sc->vscr) || (!sc->pscr)) { + e_term_close(tr); + perror("malloc"); + exit(-1); + } + + sc->nrow= tr->nrow; + sc->ncol= tr->ncol; + sc->row= 0; + sc->col= 0; + + for (i= 0; i < tr->nrow; i++) { + ln= (E_ScreenLine *)malloc(sizeof(E_ScreenLine)+tr->ncol); + if (!ln) { + e_term_close(tr); + perror("malloc"); + exit(-1); + } + ln->fcol= E_TR_WHITE; + ln->bcol= E_TR_BLACK; + sc->vscr[i]= ln; + + ln= (E_ScreenLine *)malloc(sizeof(E_ScreenLine)+tr->ncol); + if (!ln) { + e_term_close(tr); + perror("malloc"); + exit(-1); + } + ln->fcol= E_TR_WHITE; + ln->bcol= E_TR_BLACK; + sc->pscr[i]= ln; + } + return(sc); +} + +void e_screen_free(E_Screen *sc) +{ + E_ScreenLine *ln; + int i; + + for (i= 0; i < sc->nrow; i++) { + ln= sc->vscr[i]; + free((void *)ln); + + ln= sc->pscr[i]; + free((void *)ln); + } + + free((void *)sc->vscr); + free((void *)sc->pscr); + free((void *)sc); +} + +void e_screen_putc(E_Screen *sc, int c) +{ + E_ScreenLine *ln; + + if (sc->row >= 0 && sc->row < sc->nrow) { + ln= sc->vscr[sc->row]; + ln->text[sc->col]= c; + } +} + +void e_screen_move(E_Screen *sc, int row, int col) +{ + sc->row= row; + sc->col= col; +} + +void e_screen_eeol(E_Screen *sc) +{ + E_ScreenLine *ln; + int i; + + if (sc->row >= 0 && sc->row < sc->nrow) { + ln= sc->vscr[sc->row]; + for (i= sc->col; i < sc->ncol; i++) + ln->text[i]= ' '; + } +} + +void e_screen_color(E_Screen *sc, int row, int fcol, int bcol) +{ + E_ScreenLine *ln; + + if (row < 0 || row >= sc->nrow) + return; + + ln= sc->vscr[row]; + ln->fcol= fcol; + ln->bcol= bcol; +} + +void e_screen_eeop(E_Screen *sc) +{ + E_ScreenLine *ln; + int e, i; + + if (sc->row >= 0 && sc->row < sc->nrow) { + for(e= 0; e < sc->nrow; e++) { + ln= sc->vscr[e]; + for (i= 0; i < sc->ncol; i++) + ln->text[i]= ' '; + } + } +} + +void e_screen_swap(E_Term *tr, E_Screen *sc, int user_force) +{ + E_ScreenLine *vln, *pln; + int e, i, force; + + e_term_fgcol(tr, E_TR_WHITE); + e_term_bgcol(tr, E_TR_BLACK); + + for(e= 0; e < sc->nrow; e++) { + vln= sc->vscr[e]; + pln= sc->pscr[e]; + force= user_force; + + if (vln->fcol != pln->fcol || vln->bcol != pln->bcol) { + pln->fcol= vln->fcol; + pln->bcol= vln->bcol; + force= 1; + } + + e_term_fgcol(tr, pln->fcol); + e_term_bgcol(tr, pln->bcol); + + for (i= 0; i < sc->ncol; i++) { + if (force || vln->text[i] != pln->text[i]) { + e_term_move(e, i); + e_term_putc(vln->text[i]); + pln->text[i]= vln->text[i]; + } + } + + /* reset the color for the next draw. */ + vln->fcol= E_TR_WHITE; + vln->bcol= E_TR_BLACK; + } + + /* restore the original position of the cursor. */ + e_term_move(sc->row, sc->col); + e_term_flush(); +} diff --git a/screen.h b/screen.h new file mode 100644 index 0000000..d58a81c --- /dev/null +++ b/screen.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_SCREEN_H +#define _ECO_SCREEN_H + +typedef struct _E_ScreenLine { + int fcol; + int bcol; + + char text[]; +} E_ScreenLine; + +typedef struct _E_Screen { + E_ScreenLine **vscr; + E_ScreenLine **pscr; + + /* screen size, number of row and columns. */ + int nrow; + int ncol; + + /* current position of the cursor. */ + int row; + int col; +} E_Screen; + +E_Screen *e_screen_init(E_Term *tr); +void e_screen_free(E_Screen *sc); + +void e_screen_putc(E_Screen *sc, int c); +void e_screen_move(E_Screen *sc, int row, int col); +void e_screen_eeol(E_Screen *sc); +void e_screen_eeop(E_Screen *sc); +void e_screen_color(E_Screen *sc, int row, int fcol, int bcol); +void e_screen_swap(E_Term *tr, E_Screen *sc, int user_force); + +#endif /* _ECO_SCREEN_H */ diff --git a/status.c b/status.c new file mode 100644 index 0000000..6b94333 --- /dev/null +++ b/status.c @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include + +#include "term.h" +#include "screen.h" +#include "buffer.h" +#include "view.h" +#include "eco.h" +#include "status.h" + + +void e_status_putc(E_Eco *ec, int c) +{ + if (ec->view->stcol > ec->view->rcol) + return; + + e_term_move(ec->view->strow, ec->view->stcol); + if (c == '*') { + e_term_fgcol(ec->tr, E_TR_RED); + e_term_bgcol(ec->tr, E_TR_BLACK); + } + else { + e_term_fgcol(ec->tr, ec->view->stfg); + e_term_bgcol(ec->tr, ec->view->stbg); + } + + e_term_putc(c); + ec->view->stcol++; +} + +void e_status_putc_string(E_Eco *ec, char *s) +{ + int i; + + for (i= 0; i < strlen (s); i++) + e_status_putc(ec, s[i]); +} + +void e_status_putc_msg(E_Eco *ec) +{ + int i; + + if (!ec->view->stmsg) + return; + + for (i= 0; i < ec->view->stused; i++) + e_status_putc(ec, ec->view->stbuf[i]); +} + +void e_status_set_msg(E_Eco *ec, char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vsnprintf(ec->view->stbuf, 79, fmt, ap); + ec->view->stused= strlen(ec->view->stbuf); + va_end(ap); + + ec->view->stused++; + ec->view->stmsg= 1; + return; +} + +char *e_status_get_msg(E_Eco *ec, char *prompt) +{ + int i, c, val; + + ec->view->stcol= ec->view->col; + ec->view->strow= ec->view->rrow; + + /* need clean the status line. */ + /* this work in all terms ? */ + e_term_move(ec->view->strow, ec->view->stcol); + e_term_eeol(); + i= 0; + val= 0; + + if (prompt) + e_status_putc_string(ec, prompt); + else + e_status_putc(ec, ':'); + + for (;;) { + c= e_term_getc(); + if (c == '\r') { + ec->view->stbuf[i]= '\0'; + if (i) + val= 1; + break; + } + else if (c == '\b' && i) { + ec->view->stcol--; + e_status_putc(ec, ' '); + ec->view->stcol--; + e_term_move(ec->view->strow, ec->view->stcol); + ec->view->stbuf[i]= '\0'; + i--; + e_term_flush(); + } + else if (c > 0x00 && c < 0x20) { + c= c + '@'; + if (c == 'G') + return(NULL); + } + else if ((c >= 0x20) && (c < 0x7f)) { + ec->view->stbuf[i]= c; + i++; + e_status_putc(ec, c); + e_term_flush(); + } + } + + if (val) + return(ec->view->stbuf); + return(NULL); +} + +void e_status_draw(E_Eco *ec) +{ + char buf[24]; + int ocol, orow; + int rcol, i; + + /* + * The status draw is always call after e_update, so + * the physical and virtual cursor are already sync, + * we need save the current position to restore + * in the end. + */ + orow= ec->tr->row; + ocol= ec->tr->col; + + ec->view->stcol= ec->view->col; + ec->view->strow= ec->view->rrow; + + if (ec->view->b->flag & BUFFER_FLUSH) + e_status_putc(ec, '*'); + + e_status_putc(ec, '('); + e_status_putc_string(ec, ec->view->b->name); + + for (i= 0, rcol= 0; i < ec->view->b->dot; i++) { + if (ec->view->b->line->text[i] == '\t') + rcol+= 7; + rcol++; + } + + sprintf(buf, ") L(%d/%d) C(%d/%d) ", ec->view->b->nl, ec->view->b->nlines, + rcol+1, ec->view->b->line->used+1); + e_status_putc_string(ec, buf); + + /* put the percent of the file. */ + if (ec->view->b->line == ec->view->b->lines) + e_status_putc_string(ec, "Top "); + else if (!ec->view->b->line->next) + e_status_putc_string(ec, "Bottom "); + else { + int ratio= (100L * ec->view->b->nl)/ec->view->b->nlines; + + if (ratio > 99) + ratio= 99; + + sprintf(buf, "%2d%% ", ratio); + e_status_putc_string(ec, buf); + } + + e_status_putc_msg(ec); + + while (ec->view->stcol < ec->view->rcol) + e_status_putc(ec, ' '); + + e_term_move(orow, ocol); + e_term_flush(); +} diff --git a/status.h b/status.h new file mode 100644 index 0000000..84800f7 --- /dev/null +++ b/status.h @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_STATUS_H +#define _ECO_STATUS_H + +void e_status_draw(E_Eco *ec); +void e_status_set_msg(E_Eco *ec, char *fmt, ...); +char *e_status_get_msg(E_Eco *ec, char *prompt); + +#endif /* _ECO_STATUS_H */ diff --git a/term.c b/term.c new file mode 100644 index 0000000..dec4b51 --- /dev/null +++ b/term.c @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "term.h" +#include "config.h" + + +static struct termios otermios; /* original terminal characteristics */ +static struct termios ntermios; /* charactoristics to use inside */ + +E_Term *e_term_open(void) +{ + struct winsize ws; + E_Term *tr; + char *s; + + tr= (E_Term *)malloc(sizeof(E_Term)); + if (!tr) { + perror("malloc"); + exit(-1); + } + + tr->name= getenv("TERM"); + if (!tr->name) { + printf("Shell variable TERM not defined!"); + exit(-1); + } + + if (strcmp(tr->name, "vt100") && strcmp(tr->name, "linux") && + strcmp (tr->name, "xterm") && strcmp(tr->name, "ansi")) { + printf("Invalid terminal type: [%s]", tr->name); + exit(1); + } + + + tcgetattr(0, &otermios); + + ntermios= otermios; + ntermios.c_iflag&= ~(IGNBRK | BRKINT | IGNPAR | PARMRK + | INPCK | INLCR | IGNCR | ICRNL | IXON); + + ntermios.c_oflag&= ~(OPOST | ONLCR | OLCUC | OCRNL | ONOCR | ONLRET); + + ntermios.c_lflag&= ~(ISIG | ICANON | XCASE | ECHO | ECHOE | ECHOK + | ECHONL | NOFLSH | TOSTOP | ECHOCTL | + ECHOPRT | ECHOKE | FLUSHO | PENDIN | IEXTEN); + + ntermios.c_cc[VMIN] = 1; + ntermios.c_cc[VTIME] = 0; + tcsetattr(0, TCSADRAIN, &ntermios); + + /* init default entrys. */ + tr->col= 999; + tr->row= 999; + tr->fgcolor= E_TR_WHITE; + tr->bgcolor= E_TR_BLACK; + + if (ioctl(0, TIOCGWINSZ, &ws)) { + s= getenv("LINES"); + if (!s) + tr->nrow= 23; + else { + tr->nrow= atoi(s); + tr->nrow--; + } + + s= getenv("COLUMNS"); + if (!s) + tr->ncol= 80; + else + tr->ncol= atoi(s); + } + else { + tr->nrow= ws.ws_row-1; + tr->ncol= ws.ws_col; + } + + return(tr); +} + +void e_term_close(E_Term *tr) +{ + e_term_fgcol(tr, E_TR_WHITE); + e_term_bgcol(tr, E_TR_BLACK); + e_term_eeop(tr); + tcsetattr(0, TCSADRAIN, &otermios); +} + +void e_term_putc(int c) +{ + fputc(c, stdout); +} + +void e_term_flush(void) +{ + int status; + + status= fflush(stdout); + while (status < 0 && errno == EAGAIN) { + sleep(1); + status= fflush(stdout); + } + if (status < 0) + exit(15); +} + +int e_term_getc(void) +{ + return(255 & fgetc(stdin)); +} + +void e_term_parm(int n) +{ + int q, r; + + q= n / 10; + if (q != 0) { + r= q / 10; + if (r != 0) { + e_term_putc((r % 10) + '0'); + } + e_term_putc((q % 10) + '0'); + } + e_term_putc((n % 10) + '0'); +} + +void e_term_fgcol(E_Term *tr, int color) +{ + if (color != tr->fgcolor) { + e_term_putc(E_TR_ESC); + e_term_putc('['); + e_term_parm(color + 30); + e_term_putc('m'); + tr->fgcolor= color; + } +} + +void e_term_bgcol(E_Term *tr, int color) +{ + if (color != tr->bgcolor) { + e_term_putc(E_TR_ESC); + e_term_putc('['); + e_term_parm(color + 40); + e_term_putc('m'); + tr->bgcolor= color; + } +} + +void e_term_move(int row, int col) +{ + e_term_putc(E_TR_ESC); + e_term_putc('['); + e_term_parm(row + 1); + e_term_putc(';'); + e_term_parm(col + 1); + e_term_putc('H'); +} + +void e_term_eeol(void) +{ + e_term_putc(E_TR_ESC); + e_term_putc('['); + e_term_putc('K'); +} + +void e_term_eeop(E_Term *tr) +{ + e_term_fgcol(tr, tr->fgcolor); + e_term_bgcol(tr, tr->bgcolor); + e_term_putc(E_TR_ESC); + e_term_putc('['); + e_term_putc('J'); +} + +void e_term_rev(E_Term *tr, int state) +{ + int ftmp, btmp; + + e_term_putc(E_TR_ESC); + e_term_putc('['); + e_term_putc(state ? '7' : '0'); + e_term_putc('m'); + + if (!state) { + ftmp = tr->fgcolor; + btmp = tr->bgcolor; + tr->fgcolor = -1; + tr->bgcolor = -1; + e_term_fgcol(tr, ftmp); + e_term_bgcol(tr, btmp); + } +} + +void e_term_beep ( void ) +{ + e_term_putc(E_TR_BEL); + e_term_flush(); +} diff --git a/term.h b/term.h new file mode 100644 index 0000000..8613a86 --- /dev/null +++ b/term.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_TERM_H +#define _ECO_TERM_H + +typedef struct E_Term { + char *name; + + int row; + int col; + + int nrow; + int ncol; + + int fgcolor; + int bgcolor; +} E_Term; + +/* term colors. */ +#define E_TR_BLACK 0 +#define E_TR_RED 1 +#define E_TR_GREEN 2 +#define E_TR_YELLOW 3 +#define E_TR_BLUE 4 +#define E_TR_MAGENTA 5 +#define E_TR_CYAN 6 +#define E_TR_WHITE 7 + +/* term characters. */ +#define E_TR_BEL 0x07 +#define E_TR_ESC 0x1B + +E_Term *e_term_open(void); +void e_term_close(E_Term *tr); + +int e_term_getc(void); +void e_term_putc(int c); +void e_term_flush(void); + +void e_term_fgcol(E_Term *tr, int color); +void e_term_bgcol(E_Term *tr, int color); +void e_term_move(int row, int col); +void e_term_eeol(void); +void e_term_eeop(E_Term *tr); +void e_term_rev(E_Term *tr, int state); +void e_term_beep(void); + +#endif /* _ECO_TERM_H */ diff --git a/update.c b/update.c new file mode 100644 index 0000000..c8ae39b --- /dev/null +++ b/update.c @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include + +#include "debug.h" +#include "term.h" +#include "screen.h" +#include "buffer.h" +#include "view.h" +#include "config.h" +#include "eco.h" + + +int e_update_get_tab(E_Eco *ec, int col) +{ + int tab; + + tab= 8 + ec->view->col; + while (tab <= col) + tab+= 8; + return(tab); +} + +int e_update_line(E_Eco *ec, E_Line *ln, int row) +{ + int i, col, tab; + int fgcol, bgcol; + + if (ec->view->b->line == ln) { + fgcol= e_config_get_int("Screen", "current_line_foreground"); + bgcol= e_config_get_int("Screen", "current_line_background"); + if (fgcol == -1) + fgcol= E_TR_YELLOW; + if (bgcol == -1) + bgcol= E_TR_BLACK; + + e_screen_color(ec->sc, row, fgcol, bgcol); + i= ec->view->b->dot_pad; + } + else { + e_screen_color(ec->sc, row, E_TR_WHITE, E_TR_BLACK); + i= 0; + } + + for (col= ec->view->col; col < ec->view->rcol && i < ln->used; i++, col++) { + if (ln->text[i] == '\t') { + tab= e_update_get_tab(ec, col); + while (col != tab) { + e_screen_move(ec->sc, row, col); + e_screen_putc(ec->sc, ' '); + col++; + } + col--; + } + else { + e_screen_move(ec->sc, row, col); + if (ln->text[i] >= 0x20 && ln->text[i] < 0x7f) + e_screen_putc(ec->sc, ln->text[i]); + else + e_screen_putc(ec->sc, ' '); + } + } + + /* clean the rest of the line. */ + if (col < ec->view->rcol) { + e_screen_move(ec->sc, row, col); + e_screen_eeol(ec->sc); + } + return(row); +} + +int __get_real_col(E_Eco *ec, E_Line *ln, int dot) +{ + int col, i; + + for (i= dot, col= ec->view->col; i < ec->view->b->dot; i++) { + if (ec->view->b->line->text[i] == '\t') + col= e_update_get_tab(ec, col); + else + col++; + } + return(col); +} + +void __reframe(E_Eco *ec) +{ + E_Line *p; + int row, col, found, i; + + /* check if we need pad the dot. */ + col= __get_real_col(ec, ec->view->b->line, 0); + ec->view->b->dot_pad= 0; + + while (col > ec->view->rcol) { + /* ok we need pad this, but go one-by-one so the + * left/right keys work fine. + */ + ec->view->b->dot_pad++; + col= __get_real_col(ec, ec->view->b->line, ec->view->b->dot_pad); + } + + p= ec->view->b->first; + row= ec->view->row; + found= 0; + while (p) { + if (p == ec->view->b->line) { + found= 1; + break; + } + + row++; + p= p->next; + } + + e_debug_printf("Check if need reframe\n"); + /* + * This can happen, the current line is before + * the first line and from the first to the end + * is < nrow, so need be sure. + */ + if ((row < ec->view->rrow) && (found)) + return; + + /* + * The first line of the buffer is out of the screen, + * need re-frame it. + * The easy why is just make the current line, the first + * line of the buffer, so we have a complet scroll, but + * we can define some number here, so the user can + * set the number of line to scroll. + */ + ec->view->b->first= ec->view->b->line; + for (i= 0; i < 3; i++) { + if (!ec->view->b->first->prev) + break; + ec->view->b->first= ec->view->b->first->prev; + } + e_debug_printf("Reframe buffer\n"); +} + +void e_update_cursor(E_Eco *ec) +{ + E_Line *p; + int row, col; + + /* + * This function sync the physical and virtual + * cursor position, assume that the buffer don't + * need reframe. + * + * First, match the current row. + */ + row= ec->view->row; + p= ec->view->b->first; + while (p) { + if (p == ec->view->b->line) + break; + + row++; + p= p->next; + } + + /* second check if the line is "extend" or not. */ + col= __get_real_col(ec, ec->view->b->line, 0); + + if (col > ec->view->rcol) + col= __get_real_col(ec, ec->view->b->line, ec->view->b->dot_pad); + + e_screen_move(ec->sc, row, col); + e_term_move(row, col); +} + +void e_update(E_Eco *ec) +{ + E_View *v, *vp; + E_Line *ln; + int row; + + /* first save the active view. */ + v= ec->view; + + /* now update all the view that are show and need redraw. */ + vp= ec->view_list; + while (vp) { + if ((vp->flag & VIEW_REDRAW) && (vp->flag & VIEW_SHOW)) { + /* make the active, just for draw. */ + ec->view= vp; + + /* check for scroll. */ + __reframe(ec); + + ln= ec->view->b->first; + row= ec->view->row; + while (ln && (row < ec->view->rrow)) { + row= e_update_line(ec, ln, row); + row++; + ln= ln->next; + } + + /* fill the unused lines. */ + while (row < ec->view->rrow) { + e_screen_move(ec->sc, row, ec->view->col); + e_screen_putc(ec->sc, '~'); + e_screen_move(ec->sc, row, ec->view->col+1); + e_screen_eeol(ec->sc); + row++; + } + + vp->flag &= ~VIEW_REDRAW; + } + vp= vp->next; + } + + /* restore the active view. */ + ec->view= v; + e_update_cursor(ec); +} diff --git a/update.h b/update.h new file mode 100644 index 0000000..b167f3e --- /dev/null +++ b/update.h @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_UPDATE_H +#define _ECO_UPDATE_H + +void e_update(E_Eco *ec); + +#endif /* _ECO_UPDATE_H */ diff --git a/view.c b/view.c new file mode 100644 index 0000000..21d1453 --- /dev/null +++ b/view.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#include +#include +#include + +#include "term.h" +#include "screen.h" +#include "buffer.h" +#include "view.h" +#include "config.h" + + +E_View *e_view_new(E_Screen *sc) +{ + E_View *v; + + v= (E_View *)malloc(sizeof(E_View)); + v->next= NULL; + v->prev= NULL; + + /* by default, all the screen. */ + v->row= 0; + v->col= 0; + v->nrow= sc->nrow; + v->ncol= sc->ncol; + v->rrow= sc->nrow; + v->rcol= sc->ncol; + v->b= NULL; + v->search[0]= '\0'; + + v->stfg= e_config_get_int("View", "foreground"); + v->stbg= e_config_get_int("View", "background"); + if (v->stfg == -1) + v->stfg= E_TR_GREEN; + if (v->stbg == -1) + v->stbg= E_TR_BLACK; + + v->stbuf[0]= '\0'; + v->stcol= v->col; + v->strow= v->rrow; + v->stused= 0; + v->stmsg= 0; + v->flag= 0; + return(v); +} + +void e_view_free(E_View *v) +{ + free((void *)v); +} + +void e_view_move(E_View *v, int row, int col) +{ + v->row= row; + v->col= col; + v->rrow= row + v->nrow; + v->rcol= col; + v->strow= v->rrow; + v->stcol= v->rcol; + e_view_redraw(v); +} + +void e_view_resize(E_View *v, int nrow, int ncol) +{ + v->nrow= nrow; + v->ncol= ncol; + v->rrow= v->row + nrow; + v->rcol= v->col + ncol; + v->strow= v->rrow; + v->stcol= v->col; + e_view_redraw(v); +} + +void e_view_redraw(E_View *v) +{ + if (!(v->flag & VIEW_REDRAW)) + v->flag |= VIEW_REDRAW; +} + +void e_view_show(E_View *v) +{ + if (!(v->flag & VIEW_SHOW)) + v->flag |= VIEW_SHOW; +} + +void e_view_unshow(E_View *v) +{ + if (v->flag & VIEW_SHOW) + v->flag &= ~VIEW_SHOW; +} diff --git a/view.h b/view.h new file mode 100644 index 0000000..cb55fe7 --- /dev/null +++ b/view.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2008 Diego Hernan Borghetti. + * Eco + */ + +#ifndef _ECO_VIEW_H +#define _ECO_VIEW_H + +typedef struct _E_View { + struct _E_View *next; + struct _E_View *prev; + + /* The "View" is a region of the screen when we + * draw the buffer, it's like a canvas. + * + * The screen can be split in N number of view + * and every view have a buffer attached. + * + * + * The row and col have the start position of the + * view, in screen coordinates. + * + * The nrow and ncol is the size of the view, but + * _NOT_ in the screen. + * + * The rrow and rcol is the end position of the + * view, in screen coordinates (srow + row, scol + col) + */ + + /* start position. */ + int row; + int col; + + /* view size. */ + int nrow; + int ncol; + + /* real view size. */ + int rrow; + int rcol; + + /* buffer attached to this view. */ + E_Buffer *b; + + /* last search string. */ + char search[80]; + + /* status line. */ + int stfg; + int stbg; + + /* minibuf for status line. */ + char stbuf[80]; + + /* minibuf position. */ + int stcol; + int strow; + int stused; + + /* have a message to show ? */ + int stmsg; + + /* view flag. */ + char flag; +} E_View; + +/* view->flag */ +#define VIEW_REDRAW (1<<0) +#define VIEW_SHOW (1<<1) + +E_View *e_view_new(E_Screen *sc); +void e_view_free(E_View *v); + +void e_view_move(E_View *v, int row, int col); +void e_view_resize(E_View *v, int nrow, int ncol); + +void e_view_show(E_View *v); +void e_view_unshow(E_View *v); +void e_view_redraw(E_View *v); + +#endif /* _ECO_VIEW_H */ -- 2.11.4.GIT