dav-text_0.9.0.orig/main.c0000644000175000017500000005210613561760706014050 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include "main.h" #include "buffers.h" #include "structs.h" #include "fileIO.h" #include "screenIO.h" #include "keyboard.h" #include "features.h" #include "undo.h" #include "move.h" int maxY,maxX; int helpBarUpdate=0; char *version = "Dav - 0.9.0\n\nCopyright 2001-2003 David Gucwa\nCopyright 2017-2019 Adam Bilbrough"; char *license = "This program is free software under the GPL version 2 license."; /* Preferences and default values */ int maxUndoLength = 500; char undoEnabled=1; char autoIndent=1; int numberOfBuffers = 10; char bottomRowToggle = 1; char bufferQuit = 0; char tabWidth = 8; char smartCursor = 1; char optimize = 0; int *lastDisplayed; //Number of characters last displayed on various lines char displayWholeScreen = 0; struct buffer *buffers; struct buffer *currentBuffer; int currentBufferNum = 0; int main(int argc, char *argv[]) { int x, y, i; int keypress; signal(2,sigcatch); Fn_ptr[0] = search; Fn_ptr[1] = save; Fn_ptr[2] = saveAs; Fn_ptr[3] = askLoad; Fn_ptr[4] = tryQuit; Fn_ptr[5] = Undo; Fn_ptr[7] = toggleAutoIndent; Fn_ptr[8] = tryCompile; Fn_ptr[9] = toggleBottomRow; loadSettings(); if(numberOfBuffers > 100) numberOfBuffers = 100; buffers = (struct buffer *)malloc(numberOfBuffers * sizeof(struct buffer)); //Set up initial buffers for(x=0;xnext = buffers[x].tail; buffers[x].head->data = NULL; buffers[x].tail->prev = buffers[x].head; buffers[x].tail->next = buffers[x].tail; buffers[x].tail->data = NULL; buffers[x].tail->hasTabs = 0; currentBuffer = &buffers[x]; addLineAfter(buffers[x].head, " "); buffers[x].cursor.l = buffers[x].head->next; buffers[x].cursor.offset = 0; buffers[x].cursor.lineNum = 0; buffers[x].topLine.l = buffers[x].head->next; buffers[x].topLine.offset = 0; buffers[x].topLine.lineNum = 0; buffers[x].topLine.cursX = buffers[x].topLine.cursY = 0; buffers[x].cursor.cursX = buffers[x].cursor.cursY = 0; buffers[x].cursor.wantCursX = 0; buffers[x].currentLine = &buffers[x].cursor.l; buffers[x].lineUpdate.offset = -1; buffers[x].numLines = 0; buffers[x].updated = 0; if(undoEnabled) buffers[x].undoMoves = (struct undoMove *)malloc(maxUndoLength*sizeof(struct undoMove)); buffers[x].undoBufferPointer = buffers[x].undoBufferLength = 0; } currentBuffer = &buffers[0]; initscr(); cbreak(); nonl(); intrflush(stdscr, FALSE); keypad(stdscr, TRUE); getmaxyx(stdscr,maxY,maxX); for(x = 0; x< maxX; x++) { for(y = 0; y< maxY; y++) { mvaddch(y, x,' '); } } move(0,0); lastDisplayed = (int *)malloc(maxY*sizeof(int)); /* For Debian issue #872848 ~Adam */ for (i = 0; i < argc; i++) { if (argv[i][0] == '-') { doArguments(argc,argv); } if (argv[i][0] == '+') { doAlternativeArguments(argc,argv); } } helpBar(); showRow(); while(1) { move(currentBuffer->cursor.cursY,currentBuffer->cursor.cursX); keypress=getch(); keyHit(keypress,undoEnabled); displayScreen(); showRow(); if(helpBarUpdate) { helpBarUpdate--; if(!helpBarUpdate) helpBar(); } } return 0; } void nothing() { currentBuffer->lineUpdate.offset = -1; } void tryQuit() { int t; if(!currentBuffer->updated) { if(!bufferQuit) quit(""); else closeBuffer(); return; } displayBottomRow(); mvaddstr(maxY-1,0,"Save before quitting? y/n/[C]"); move(maxY-1,26); t = getch(); mvaddch(maxY-1,26,' '); if(t=='y' || t=='Y') { save(); t = 'n'; } if(t=='n' || t=='N') { if(!bufferQuit) quit(""); else closeBuffer(); } helpBarUpdate = 1; currentBuffer->lineUpdate.offset = -1; } void quit(char *text) { struct line *l; int t; for(t=0;tnext; if(l->prev->data) free(l->prev->data); free(l->prev); } free(buffers[t].tail); } free(buffers); free(lastDisplayed); printf("%s",text); exit(0); } void doArguments(int argc, char *argv[]) { int x; char firstFile = 1; for(x=1;xnext; struct line *newLine = (struct line *)malloc(sizeof(struct line)); temp->prev = newLine; whichLine->next = newLine; newLine->next = temp; newLine->prev = whichLine; newLine->data = (char *)malloc(strlen(data)); strcpy(newLine->data, data); newLine->length = strlen(data); countTabs(newLine); currentBuffer->numLines++; } char positionDown(struct position *p) { /* Returns 0 upon normal movement Returns 1 if the position stayed on the same line (end of file) */ int tempX = p->cursX; char temp = 0; while(!temp) { /* Move the cursor right until it wraps to the next line. If it hits the end of the file, return 1 instead. */ temp = moveRight(p); if(temp==1) { return 1; } } while(1) { /* Move the cursor right until it hits the correct location. */ if(p->cursX >= tempX) { return 0; } else if(p->offset == p->l->length - 1) { return 0; } temp = moveRight(p); if(temp == 1) { return 0; } else if(temp > 1) { moveLeft(p); return 0; } } } char positionUp(struct position *p) { /* Returns 0 upon normal movement Returns 1 if the position stayed on the same line (beginning of file) */ int tempX = p->cursX; char temp=0; while(!temp) { temp = moveLeft(p); if(temp==1) { if(p == ¤tBuffer->cursor) { currentBuffer->cursor.wantCursX = currentBuffer->cursor.cursX; } return 1; } } while(1) { if(p->cursX <= tempX) { return 0; } temp = moveLeft(p); if(temp == 1) { return 0; } else if(temp > 1) { moveRight(p); return 0; } } } void connectLines(struct line *baseline) { struct line *l = baseline->next; char *ptr = (char *)malloc(baseline->length + l->length); memmove(ptr, baseline->data, baseline->length); memmove(ptr+baseline->length, l->data, l->length); free(baseline->data); baseline->data = ptr; baseline->length += l->length; baseline->next = l->next; l->next->prev = baseline; baseline->hasTabs += l->hasTabs; free(l->data); free(l); currentBuffer->numLines--; } void determineLineNum(struct position *p) { struct position temp; int cX=p->cursX,cY=p->cursY; temp.l = currentBuffer->head->next; temp.offset = 0; temp.lineNum = 0; while(temp.l != p->l) positionDown(&temp); while(temp.offset+maxX <= p->offset) positionDown(&temp); p->lineNum = temp.lineNum; p->cursX=cX; p->cursY=cY; } void countTabs(struct line *l) { int t; l->hasTabs = 0; for(t=l->length-1;t>=0;t--) if(l->data[t]==9) l->hasTabs++; } void determineCursX(struct position *p) { struct position temp; char c; temp.l = p->l; temp.offset = 0; temp.cursX = 0; while(p->offset!=temp.offset) { c = temp.l->data[temp.offset]; temp.offset++; if(c!=9) temp.cursX++; else temp.cursX+= tabWidth - (temp.cursX % tabWidth); if(temp.cursX >= maxX) temp.cursX=0; } p->cursX = temp.cursX; } void logMsg(char *msg) { char text[256]; sprintf(text, "echo \"%s\" >> log", msg); int system_return = system(text); if(system_return) { return; } } void sigcatch() { quit(""); } void radixSort(char **strings, int number) { char **buckets[256]; int numberInBuckets[256]; int radix = 0; int t; int i,j; for(i=0; i<256; i++) { buckets[i] = (char **)malloc(0*sizeof(char *)); } for(radix=255; radix>=0; radix--) { for(t=0; t<256; t++) { numberInBuckets[t] = 0; } for(t=0; t= high) { //Zero or one element return; } if (high - low == 1) { //Only two elements if (strcmp(strings[high], strings[low]) < 0) { temp = strings[high]; strings[high] = strings[low]; strings[low] = temp; } return; } //Swap axis element with last element axis = (rand() % (high - low + 1)) + low; temp = strings[axis]; strings[axis] = strings[high]; strings[high] = temp; axis = high; high--; while (1) { while (strcmp(strings[low], strings[axis]) <= 0 && low < high) { low++; } while (strcmp(strings[high], strings[axis]) >= 0 && low < high) { high--; } if (low >= high) { break; } temp = strings[low]; strings[low] = strings[high]; strings[high] = temp; } if (strcmp(strings[low], strings[axis]) < 0) { low++; } temp = strings[axis]; strings[axis] = strings[low]; strings[low] = temp; randomizedQuickSort(strings, oldLow, low-1); randomizedQuickSort(strings, low+1, oldHigh); } dav-text_0.9.0.orig/COPYING0000644000175000017500000004313113427617637014016 0ustar atsbatsb GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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. dav-text_0.9.0.orig/Makefile0000644000175000017500000000134613427617637014425 0ustar atsbatsbprefix=/usr/local CC=gcc OBJECTS=main.o \ buffers.o \ fileIO.o \ screenIO.o \ keyboard.o \ features.o \ undo.o \ move.o CFLAGS+=-D_FORTIFY_SOURCE=2 -g -Wall -Wextra -Wpointer-arith -Wuninitialized -Wshadow -Winit-self -Wmissing-declarations -Wformat -Wformat-security -Werror=format-security LDFLAGS+=-lncurses -z now dav: $(OBJECTS) $(CC) $(CFLAGS) $(CPPFLAGS) $(OBJECTS) $(LDFLAGS) -o dav install: install -D dav $(DESTDIR)$(prefix)/bin/dav mkdir -p $(DESTDIR)$(prefix)/share/man/man1 install -D dav.1.gz $(DESTDIR)$(prefix)/share/man/man1/ uninstall: rm $(DESTDIR)$(prefix)/bin/dav rm $(DESTDIR)$(prefix)/share/man/man1/dav.1.gz clean: -rm -rf dav core *.o tags dav-text_0.9.0.orig/README.md0000644000175000017500000000102013427617637014231 0ustar atsbatsb[![Build Status](https://travis-ci.org/atsb/dav-text.svg?branch=master)](https://travis-ci.org/atsb/dav-text) Welcome to DAV! (Dav Ain't Vi) Disclaimer: This program may or may not do anything you desire it to do. Use Dav at your own risk. Install: If you downloaded source and not binaries, you'll have to 'make'. Either way though, as root, run 'make install' Copyright issues: This program is copyrighted under the GNU General Public License See the file COPYING Contact: https://github.com/atsb/dav-text dav-text_0.9.0.orig/buffers.c0000644000175000017500000000454313427617637014567 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "buffers.h" #include "screenIO.h" #include extern int numberOfBuffers; extern int helpBarUpdate; extern char smartCursor; extern struct buffer *buffers; extern struct buffer *currentBuffer; extern int currentBufferNum; void keyHit(int keypress, char undoNow); void quit(char *text); void goToNextBuffer() { currentBufferNum++; if(currentBufferNum == numberOfBuffers) currentBufferNum = 0; currentBuffer = &buffers[currentBufferNum]; currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing = 1; helpBarUpdate=1; } void goToPrevBuffer() { currentBufferNum--; if(currentBufferNum == -1) currentBufferNum = numberOfBuffers - 1; currentBuffer = &buffers[currentBufferNum]; currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing = 1; helpBarUpdate=1; } void closeBuffer() { struct buffer *b = currentBuffer; char tempSmartCursor = smartCursor; smartCursor = 0; //Go to the very beginning of the buffer while(currentBuffer->cursor.l!=currentBuffer->head->next || currentBuffer->cursor.offset!=0) keyHit(259, 0); //Key_Up //Wipe out lines while(currentBuffer->numLines) keyHit(21, 0); //Ctrl-U keyHit(21, 0); //Last remaining line currentBuffer->updated = 0; strcpy(currentBuffer->fname, ""); while(strcmp(currentBuffer->fname, "") == 0 && !currentBuffer->updated) { goToPrevBuffer(); if(currentBuffer == b) quit(""); } smartCursor = tempSmartCursor; //helpBarUpdate = 1; //currentBuffer->lineUpdate.offset = -1; displayScreen(); } dav-text_0.9.0.orig/buffers.h0000644000175000017500000000156313427617637014573 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef buffers_h #define buffers_h #include "structs.h" void goToNextBuffer(); void goToPrevBuffer(); void closeBuffer(); #endif dav-text_0.9.0.orig/changelog0000644000175000017500000000401013427617637014626 0ustar atsbatsbv0.8.9 Cleaned up code to prevent some new warnings fro GCC8. v0.8.8 Rewrote helpbar in buffer (bottom bar in editor) to make it clear and clean Clarified some text to make it easier to understand Removed optimizing flag in the Makefile which caused crashes on some systems Moved LDFLAGS in the Makefile which caused link failures on some systems v0.8.7 Fixed unsigned to signed integer comparisons Added return values for some calls Clarified help instructions v0.8.6 Updated Makefile with more strict compilation flags Implemented +# lnumval arguments (like nano) v0.8.5 Fixed -l# command-line option to work correctly toward the end of the file. Yet more accuracy fixes regarding cursor movement in the presence of tabs. Yet more display fixes regarding terminal window resizing. v0.8.4 Fixed up the quicksort implementation; it was not 100% accurate before. Fixed window-resizing code. It should be 100% accurate now. Removed a redundant free() that sometimes segfaulted. Updated the version number. v0.8.3 thought it was v0.8.2 v0.8.3 Buffer-closing-related bugfixes. Dav will load up the first specified file (of several) instead of the last. v0.8.2 Fixed an error where moving the cursor left off the top of the screen caused a freeze. Specifying multiple files at command line opens them into separate buffers. Load/save menu dialogue is sorted by filename. Type of sort is selectable in ~/.davrc under "optimize". Closing a buffer changes the buffer filename to the empty string. Closing a buffer when other buffers are open will no longer sometimes close Dav. Fixed minor memory leaks. Fixed a freeze that sometimes occurred when searching/replacing. v0.8.1 Added SmartCursor functionality. Minor code optimizations. Window resizing bugfix. Lots of code cleanups. Separated code into separate files. v0.8.0 Some code cleanups. Added menu load/save interface. v0.7.6 Added an option to the .davrc file to set the tab width. The default value is 8. v0.7.5 Changed the way Undo works, made it more efficient and faster and more reliable. dav-text_0.9.0.orig/dav.1.gz0000644000175000017500000000142413427617637014235 0ustar atsbatsb{_\dav.1T]o@|X/MMK*E%&P^kw5ƦU܇MRDG+ B@%/LkmЄ 9ş0V Gb2w9 Ngx%`D <|g>]OnGn>F~%~ڸR]KEQMUI+[/疓?.U|[P(o||򼀆0?j/lr2R^YmniŔ4<oP4zݲpƅmM%h3ĥbt/PTpm@ë L[>f>/.dh, !PS9GHdFդ) ǝr29m$B%$FdN}~9-Ϛ[ 3-s>d2aIwKKo⤦AJ"Ѫ^~qV:q]fM%0 Stpdav-text_0.9.0.orig/features.c0000644000175000017500000001423113427617637014744 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include "features.h" #include "main.h" #include "screenIO.h" #include "fileIO.h" #include "keyboard.h" #include "buffers.h" #include "move.h" void search() { char *t; int offset; struct line *l = *currentBuffer->currentLine; char down=1; //Whether or not the found word is below the current position char count=2; if (currentBuffer->head->next->next == currentBuffer->tail && currentBuffer->head->next->length == 1) { //No characters in the buffer return; } if (helpBarUpdate==0 || strcmp(currentBuffer->searchString,"")==0) { displayBottomRow(); mvaddstr(maxY-1,0,"Search for what word?"); mvgetstr(maxY-1,22,currentBuffer->searchString); } if (l == currentBuffer->tail->prev && currentBuffer->cursor.offset >= l->length - 2) { l = currentBuffer->head->next; offset = 0; down = 0; } else { offset = currentBuffer->cursor.offset + 1; } while (1) { t = ( char *)strstr(l->data + offset, currentBuffer->searchString); if (t!=NULL) break; offset = 0; l = l->next; if (l==((*currentBuffer->currentLine)->next)) count--; if (l==currentBuffer->tail) { l = currentBuffer->head->next; down=0; } if (count==0) break; } if (t==NULL) { displayBottomRow(); mvaddstr(maxY-1,0,"String not found."); helpBarUpdate=2; strcpy(currentBuffer->searchString,""); return; } offset = t - l->data; if (down) { while(currentBuffer->cursor.l != l) moveDown(¤tBuffer->cursor); } else { while(currentBuffer->cursor.l != l) moveUp(¤tBuffer->cursor); } while(currentBuffer->cursor.offset < offset) { if (moveRight(¤tBuffer->cursor) == 1) break; } while(currentBuffer->cursor.offset > offset) { if (moveLeft(¤tBuffer->cursor) == 1) break; } currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing = 1; helpBarUpdate = 2; } void replace() { static char replaceString[80]; static char findString[80]; char *t; int offset; struct line *l = *currentBuffer->currentLine; char down=1; //Whether or not the found word is below the current position char count=2; if(helpBarUpdate==0 || !strcmp(findString,"") || !strcmp(replaceString,"")) { displayBottomRow(); mvaddstr(maxY-1, 0, "Replace what?"); mvgetstr(maxY-1, 14, findString); displayBottomRow(); mvaddstr(maxY-1, 0, "Replace with what?"); mvgetstr(maxY-1, 19, replaceString); } offset = currentBuffer->cursor.offset + 1; while(1) { t = ( char *)strstr(l->data + offset, findString); if(t!=NULL) break; offset = 0; l = l->next; if(l==((*currentBuffer->currentLine)->next)) count--; if(l==currentBuffer->tail) { l = currentBuffer->head->next; down=0; } if(count==0) break; } if(t==NULL) { displayBottomRow(); mvaddstr(maxY-1,0,"String not found."); helpBarUpdate=2; strcpy(findString,""); return; } offset = t - l->data; if (down) { while(currentBuffer->cursor.l != l) moveDown(¤tBuffer->cursor); } else { while(currentBuffer->cursor.l != l) moveUp(¤tBuffer->cursor); } while(currentBuffer->cursor.offset < offset) { if (moveRight(¤tBuffer->cursor) == 1) break; } while(currentBuffer->cursor.offset > offset) { if (moveLeft(¤tBuffer->cursor) == 1) break; } //Delete the findstring for(offset = strlen(findString);offset;offset--) keyHit(330, 0); //Add the replacestring for(offset=0;(long unsigned int)offsetlineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing = 1; helpBarUpdate = 2; } void tryCompile() { FILE *fp; displayBottomRow(); mvaddstr(maxY-1,0,"Running Makefile..."); ungetch(' '); getch(); if(strcmp(currentBuffer->fname, "")) save(); int feature_system_return = system("make 2>dav.err >/dev/null"); if(feature_system_return) { return; } fp = fopen("dav.err","r"); fgetc(fp); if(feof(fp)) { displayBottomRow(); mvaddstr(maxY-1,0,"Compile successful."); helpBarUpdate = 2; } else { displayBottomRow(); while(currentBuffer->head->next->next != currentBuffer->tail || currentBuffer->head->next->length!=1) goToNextBuffer(); load("dav.err"); currentBuffer->lineUpdate = currentBuffer->cursor; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing=1; helpBarUpdate = 1; } fclose(fp); int feature_system_remove_return = system("rm dav.err"); if(feature_system_remove_return) { return; } } void gotoLine(int line) { while(currentBuffer->cursor.lineNum < line - 1) { if(scrollDown()) { break; } } while (currentBuffer->cursor.lineNum < line - 1) { if (positionDown(¤tBuffer->cursor)) { break; } } currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing = 1; displayScreen(); } void toggleAutoIndent() { currentBuffer->lineUpdate.offset = -1; autoIndent = !autoIndent; displayBottomRow(); mvaddstr(maxY-1,0,"Auto indenting set to"); mvaddch(maxY-1,22,autoIndent+48); helpBarUpdate = 2; } void toggleBottomRow() { bottomRowToggle = !bottomRowToggle; helpBar(); currentBuffer->lineUpdate.offset = -1; } dav-text_0.9.0.orig/features.h0000644000175000017500000000163213427617637014752 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef features_h #define features_h void search(); void replace(); void tryCompile(); void gotoLine(int line); void toggleAutoIndent(); void toggleBottomRow(); #endif dav-text_0.9.0.orig/fileIO.c0000644000175000017500000001463613427617637014306 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include "fileIO.h" #include "structs.h" #include "screenIO.h" #include "keyboard.h" #include "main.h" extern struct buffer *currentBuffer; extern int helpBarUpdate; extern int maxY; extern char autoIndent; void save() { if(!strcmp(currentBuffer->fname, "")) { doSave("."); } else { doSave(currentBuffer->fname); } currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->lineUpdate.cursY = 0; currentBuffer->keepGoing=1; } void saveAs() { char *ptr = (char *)malloc(strlen(currentBuffer->fname)); strcpy(ptr, currentBuffer->fname); if(!strcmp(doSave("."), "")) { strcpy(currentBuffer->fname, ptr); } free(ptr); currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->lineUpdate.cursY = 0; currentBuffer->keepGoing=1; } char *doSave(char *filename) { int t; FILE *fp; struct line *l = currentBuffer->head->next; struct stat s; helpBarUpdate = 1; if(!strcmp(filename, "")) return ""; stat(filename, &s); if(S_ISDIR(s.st_mode)) { while(1) { char newFile[256]; DIR *dir = opendir(filename); char **choices = malloc(sizeof(char *)); int n = 1; char answer[256]; struct dirent *d; choices[0] = malloc(7); strcpy(choices[0], "Cancel"); while(1) { d = readdir(dir); if(d==NULL) { break; exit(EXIT_FAILURE); } n++; choices = realloc(choices, n*sizeof(char *)); choices[n-1] = malloc(256); snprintf(choices[n-1], 256, "%s", d->d_name); } closedir(dir); if (optimize == 0) { //Memory efficiency randomizedQuickSort(&choices[1], 0, n-2); } else { //Cpu efficiency radixSort(&choices[1], n-1); } listChoice(n, choices, answer, "File to save as?"); if(!strcmp(answer, "DAV_CANCEL")) { newFile[0] = '\0'; } else if(!strcmp(answer, ".")) { sprintf(newFile, "%s", filename); } else if(!strcmp(answer, "..")) { sprintf(newFile, "%s/%s", filename, answer); } else { sprintf(newFile, "%s/%s", filename, answer); } for(n--;n>=0;n--) { free(choices[n]); } free(choices); return doSave(newFile); } } fp = fopen(filename, "w"); helpBarUpdate = 2; if(fp==NULL) { mvaddstr(maxY-1,0, "You do not have the proper permissions to save to that file"); return ""; } while(l!=currentBuffer->tail->prev) { for(t=0;tlength;t++) putc(l->data[t],fp); l = l->next; } for(t=0;tlength-1;t++) putc(l->data[t],fp); fclose(fp); displayBottomRow(); mvaddstr(maxY-1,0,"File successfully saved."); strcpy(currentBuffer->fname, filename); currentBuffer->updated = 0; return currentBuffer->fname; } void load(char *filename) { char t; int i; struct stat s; FILE *fp; stat(filename, &s); if(!strcmp(filename, "")) return; if(S_ISDIR(s.st_mode)) //File is a directory { DIR *dir = opendir(filename); char **choices = malloc(sizeof(char *)); int n = 1; char answer[256]; char newFile[256]; struct dirent *d; choices[0] = malloc(7); strcpy(choices[0], "Cancel"); while(1) { d = readdir(dir); if(d==NULL) { break; exit(EXIT_FAILURE); } n++; choices = realloc(choices, n*sizeof(char *)); choices[n-1] = malloc(256); snprintf(choices[n-1], 256, "%s", d->d_name); } closedir(dir); if (optimize == 0) { //Memory efficiency randomizedQuickSort(&choices[1], 0, n-2); } else { //Cpu efficiency radixSort(&choices[1], n-1); } listChoice(n, choices, answer, "File to load?"); if(!strcmp(answer, "DAV_CANCEL")) { currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->keepGoing=1; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->lineUpdate.cursY = 0; newFile[0] = '\0'; } else if(!strcmp(answer, ".")) { sprintf(newFile, "%s", filename); } else if(!strcmp(answer, "..")) { sprintf(newFile, "%s/%s", filename, answer); } else { sprintf(newFile, "%s/%s", filename, answer); } for(n--;n>=0;n--) free(choices[n]); free(choices); load(newFile); return; } fp = fopen(filename,"r"); strcpy(currentBuffer->fname, filename); if(fp==NULL) { displayBottomRow(); mvaddstr(maxY-1,0,"Couldn't open file."); helpBarUpdate=2; return; } //Go to the very beginning of the buffer while(currentBuffer->cursor.l!=currentBuffer->head->next || currentBuffer->cursor.offset!=0) keyHit(259, 0); //Key_Up //Wipe out lines while(currentBuffer->numLines) keyHit(21, 0); //Ctrl-U keyHit(21, 0); //Last remaining line //Turn off autoindenting and read from the file t = autoIndent; autoIndent = 0; i = (int)getc(fp); if(i=='\n') i=13; while(i!=EOF) { keyHit(i,0); i = (int)getc(fp); if(i=='\n') i=13; } fclose(fp); autoIndent = t; //Go back up to the top while(currentBuffer->cursor.l!=currentBuffer->head->next || currentBuffer->cursor.offset!=0) keyHit(259, 0); //Key_Up currentBuffer->lineUpdate = currentBuffer->cursor; currentBuffer->keepGoing=1; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->lineUpdate.cursY = 0; currentBuffer->updated = 0; } void askLoad() { load("."); helpBarUpdate = 1; } dav-text_0.9.0.orig/fileIO.h0000644000175000017500000000157613427617637014312 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef fileIO_h #define fileIO_h char *doSave(char *filename); void save(); void saveAs(); void load(char *filename); void askLoad(); #endif dav-text_0.9.0.orig/keyboard.c0000644000175000017500000003665713427617637014746 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include "keyboard.h" #include "main.h" #include "screenIO.h" #include "undo.h" #include "move.h" void keyHit(int keypress, char undoNow) { int t=0,t2=0; int x; static char ctrl=0; char *ptr; char **data; if(keypress==27) { ctrl=3; return; } if(keypress==79 && ctrl==3) { ctrl--; return; } if(keypress==99 && ctrl==2) { currentBuffer->lineUpdate.offset = -1; ctrl=0; helpBarUpdate = 1; data = &((*currentBuffer->currentLine)->data); t=currentBuffer->cursor.cursY; currentBuffer->lineUpdate = currentBuffer->cursor; currentBuffer->lineUpdate.lineNum = currentBuffer->cursor.cursY; while((*data)[currentBuffer->cursor.offset]!=' ' && (*data)[currentBuffer->cursor.offset]!='\n' && (*data)[currentBuffer->cursor.offset]!=9) if(moveRight(¤tBuffer->cursor)) break; while((*data)[currentBuffer->cursor.offset]==' ' || (*data)[currentBuffer->cursor.offset]=='\n' || (*data)[currentBuffer->cursor.offset]==9) if(moveRight(¤tBuffer->cursor)) break; return; } if(keypress==100 && ctrl==2) { currentBuffer->lineUpdate.offset = -1; ctrl=0; helpBarUpdate = 1; data = &((*currentBuffer->currentLine)->data); t=currentBuffer->cursor.cursY; currentBuffer->lineUpdate = currentBuffer->cursor; currentBuffer->lineUpdate.lineNum = currentBuffer->cursor.cursY; moveLeft(¤tBuffer->cursor); while((*data)[currentBuffer->cursor.offset]==' ' || (*data)[currentBuffer->cursor.offset]=='\n' || (*data)[currentBuffer->cursor.offset]==9) if(moveLeft(¤tBuffer->cursor)) break; while((*data)[currentBuffer->cursor.offset]!=' ' && (*data)[currentBuffer->cursor.offset]!='\n' && (*data)[currentBuffer->cursor.offset]!=9) if(moveLeft(¤tBuffer->cursor)) break; moveRight(¤tBuffer->cursor); return; } if(keypress==91 && ctrl==3) { ctrl--; return; } if(keypress==55 && ctrl==2) { ctrl=1; return; } else if((keypress==94 && ctrl==1) || keypress==391) { currentBuffer->cursor.cursY = currentBuffer->cursor.cursX = currentBuffer->cursor.offset = 0; currentBuffer->cursor.l = currentBuffer->head->next; currentBuffer->topLine = currentBuffer->cursor; currentBuffer->lineUpdate = currentBuffer->cursor; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing=1; ctrl=0; return; } else if(keypress==335 || keypress==386) { *currentBuffer->currentLine = currentBuffer->tail->prev; currentBuffer->cursor.offset = (*currentBuffer->currentLine)->length - 1; determineCursX(¤tBuffer->cursor); currentBuffer->cursor.cursY=0; currentBuffer->topLine=currentBuffer->cursor; currentBuffer->topLine.cursX = currentBuffer->topLine.offset = 0; for(t=0;tlineUpdate=currentBuffer->topLine; currentBuffer->lineUpdate.lineNum=0; currentBuffer->keepGoing=1; return; } ctrl=0; switch(keypress) { case 410: displayBottomRow(); break; case -1: /* Window Resizing */ { struct line *tempLine = currentBuffer->cursor.l; t = currentBuffer->cursor.offset; /* Reset to top left */ keyHit(262, 0); /* Home key */ while (currentBuffer->cursor.cursY > 0) { keyHit(259, 0); /* Up key */ } getmaxyx(stdscr,maxY,maxX); free(lastDisplayed); lastDisplayed = (int *)malloc(maxY*sizeof(int)); memset(lastDisplayed,0,maxY*sizeof(int)); helpBar(); while (currentBuffer->cursor.l != tempLine) { keyHit(258, 0); /* Down key */ } while (currentBuffer->cursor.offset < t) { keyHit(261, 0); /* Right key */ } while (currentBuffer->cursor.offset > t) { keyHit(260, 0); /* Left */ } currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing = 1; /* Tell the display to refresh the whole screen */ displayWholeScreen = 1; break; } case 265: //Function keys case 266: case 267: case 268: case 269: case 270: case 271: case 272: case 273: case 274: case 275: case 276: currentBuffer->lineUpdate.offset = -1; (*Fn_ptr[keypress-265])(); break; case 258: //Down currentBuffer->lineUpdate.offset = -1; moveDown(¤tBuffer->cursor); if(smartCursor) { while(currentBuffer->cursor.wantCursX > currentBuffer->cursor.cursX && currentBuffer->cursor.cursX < ((*currentBuffer->currentLine)->length % maxX) - 1) { moveRight(¤tBuffer->cursor); } } break; case 259: //Up currentBuffer->lineUpdate.offset = -1; moveUp(¤tBuffer->cursor); if(smartCursor) { while(currentBuffer->cursor.wantCursX > currentBuffer->cursor.cursX && currentBuffer->cursor.cursX < ((*currentBuffer->currentLine)->length % maxX) - 1) { moveRight(¤tBuffer->cursor); } } break; case 260: /* Left */ currentBuffer->lineUpdate.offset = -1; moveLeft(¤tBuffer->cursor); currentBuffer->cursor.wantCursX = currentBuffer->cursor.cursX; break; case 261: /* Right */ currentBuffer->lineUpdate.offset = -1; moveRight(¤tBuffer->cursor); currentBuffer->cursor.wantCursX = currentBuffer->cursor.cursX; break; case 338: /* PgDn */ currentBuffer->lineUpdate.offset = -1; x = currentBuffer->cursor.cursY + 2; for(t=maxY-1; t; t--) { moveDown(¤tBuffer->cursor); } for(t=0; tcursor.wantCursX > currentBuffer->cursor.cursX && currentBuffer->cursor.cursX < (*currentBuffer->currentLine)->length - 1) { moveRight(¤tBuffer->cursor); } } break; case 339: //PgUp currentBuffer->lineUpdate.offset = -1; x = currentBuffer->cursor.cursY; for(t=0;tcursor); for(t=0;tcursor.wantCursX > currentBuffer->cursor.cursX && currentBuffer->cursor.cursX < (*currentBuffer->currentLine)->length - 1) { moveRight(¤tBuffer->cursor); } } break; case 262: //Home currentBuffer->lineUpdate.offset = -1; while(currentBuffer->cursor.cursX) moveLeft(¤tBuffer->cursor); currentBuffer->cursor.wantCursX = currentBuffer->cursor.cursX; break; case 360: //End t2=currentBuffer->topLine.lineNum; while(1) { t=moveRight(¤tBuffer->cursor); if(t==1) break; else if(t>1) { moveLeft(¤tBuffer->cursor); break; } } currentBuffer->lineUpdate.offset = -1; if(t2!=currentBuffer->topLine.lineNum) scrollUp(); currentBuffer->cursor.wantCursX = currentBuffer->cursor.cursX; break; case 263: //Backspace case 8: //Shift- or Ctrl-Backspace if(*currentBuffer->currentLine==currentBuffer->head->next && currentBuffer->cursor.offset==0) { currentBuffer->lineUpdate.offset = -1; break; } moveLeft(¤tBuffer->cursor); //Continue on to delete case 330: //Delete if((*currentBuffer->currentLine)->next==currentBuffer->tail && currentBuffer->cursor.offset==(*currentBuffer->currentLine)->length-1) break; if(undoNow) Do(0); if((*currentBuffer->currentLine)->data[currentBuffer->cursor.offset]==9) (*currentBuffer->currentLine)->hasTabs--; x = ((*currentBuffer->currentLine)->data[currentBuffer->cursor.offset]=='\n'); (*currentBuffer->currentLine)->length--; ptr = (*currentBuffer->currentLine)->data; memmove(ptr + currentBuffer->cursor.offset, ptr + currentBuffer->cursor.offset + 1, currentBuffer->cursor.l->length - currentBuffer->cursor.offset); (*currentBuffer->currentLine)->data = ( char *)realloc((*currentBuffer->currentLine)->data, (*currentBuffer->currentLine)->length); currentBuffer->lineUpdate = currentBuffer->cursor; currentBuffer->lineUpdate.lineNum = currentBuffer->cursor.cursY; if(!((*currentBuffer->currentLine)->length%maxX)) currentBuffer->keepGoing=1; if(x) { connectLines(*currentBuffer->currentLine); currentBuffer->keepGoing=1; } currentBuffer->updated = 1; currentBuffer->cursor.wantCursX = currentBuffer->cursor.cursX; break; case 21: //Ctrl-U keyHit(262,undoNow); //Home for(x=(*currentBuffer->currentLine)->length;x;x--) { keyHit(330,undoNow); //Delete } break; case 11: //Ctrl-K if(currentBuffer->cursor.offset==(*currentBuffer->currentLine)->length - 1) { keyHit(330,undoNow); break; } x = currentBuffer->cursor.cursX; keyHit(360, undoNow); //End if(currentBuffer->cursor.l->data[currentBuffer->cursor.offset] != '\n') { keyHit(330, undoNow); //Delete } while(currentBuffer->cursor.cursX > x) { keyHit(263, undoNow); //Backspace } break; case 13: //Enter if(undoNow) Do(1); currentBuffer->updated = 1; currentBuffer->cursor.cursY++; currentBuffer->cursor.cursX = 0; currentBuffer->cursor.lineNum++; if(autoIndent) { for(t2=0;(*currentBuffer->currentLine)->data[t2]==9 && t2cursor.offset;t2++); for(t=t2;(*currentBuffer->currentLine)->data[t]==' ' && tcursor.offset;t++); t-=t2; } addLineAfter(*currentBuffer->currentLine, ""); x = (*currentBuffer->currentLine)->length; ptr = ( char *)malloc(x - currentBuffer->cursor.offset); memmove(ptr, (*currentBuffer->currentLine)->data + currentBuffer->cursor.offset, x - currentBuffer->cursor.offset); free((*currentBuffer->currentLine)->next->data); (*currentBuffer->currentLine)->next->data = ptr; (*currentBuffer->currentLine)->next->length = x - currentBuffer->cursor.offset; (*currentBuffer->currentLine)->data = ( char *)realloc((*currentBuffer->currentLine)->data, currentBuffer->cursor.offset + 1); (*currentBuffer->currentLine)->length = currentBuffer->cursor.offset + 1; (*currentBuffer->currentLine)->data[(*currentBuffer->currentLine)->length - 1] = '\n'; *currentBuffer->currentLine = (*currentBuffer->currentLine)->next; currentBuffer->cursor.offset = 0; countTabs(*currentBuffer->currentLine); countTabs((*currentBuffer->currentLine)->next); if(autoIndent) { for(;t2;t2--) keyHit(9, undoNow); for(;t;t--) keyHit(' ',undoNow); } currentBuffer->lineUpdate=currentBuffer->cursor; do { moveLeft(¤tBuffer->lineUpdate); } while(currentBuffer->lineUpdate.offset); do { moveLeft(¤tBuffer->lineUpdate); } while(currentBuffer->lineUpdate.offset); currentBuffer->lineUpdate.lineNum = currentBuffer->lineUpdate.cursY; currentBuffer->keepGoing=1; if(currentBuffer->cursor.cursY==maxY-1) scrollDown(); currentBuffer->cursor.wantCursX = currentBuffer->cursor.cursX; break; default: //Anything that adds to the text if(undoNow) Do(1); currentBuffer->lineUpdate=currentBuffer->cursor; currentBuffer->lineUpdate.lineNum = currentBuffer->cursor.cursY; if(!((*currentBuffer->currentLine)->length % maxX)) currentBuffer->keepGoing = 1; if(keypress==9) //Tab { currentBuffer->cursor.cursX += tabWidth - 1 - (currentBuffer->cursor.cursX % tabWidth); (*currentBuffer->currentLine)->hasTabs++; } x = (*currentBuffer->currentLine)->length; (*currentBuffer->currentLine)->data = realloc((*currentBuffer->currentLine)->data, x + 1); memmove((*currentBuffer->currentLine)->data + currentBuffer->cursor.offset + 1, (*currentBuffer->currentLine)->data + currentBuffer->cursor.offset, x - currentBuffer->cursor.offset); (*currentBuffer->currentLine)->data[currentBuffer->cursor.offset] = ( char)keypress; (*currentBuffer->currentLine)->length++; currentBuffer->cursor.offset++; currentBuffer->cursor.cursX++; if(currentBuffer->cursor.cursX>=maxX) { currentBuffer->cursor.cursX = 0; if(++currentBuffer->cursor.cursY>=maxY-1) scrollDown(); } currentBuffer->cursor.wantCursX = currentBuffer->cursor.cursX; currentBuffer->updated = 1; } } void listChoice(int n, char **choices, char *answer, char *message) { int start = 0; int end; int selected = 0; int t; int line; int keypress; char newName[256]; int x,y; char focus = 0; newName[0] = '\0'; while(1) { for(y=0;y= n) ? n : start + maxY - 1; for(t=start;t"); mvaddstr(maxY-1, 0, message); mvaddstr(maxY-1, strlen(message)+1, newName); keypress = getch(); if(keypress == 258) { //Down focus = 0; if(selected < n-1) selected++; if(selected - start == maxY-1) start++; } else if(keypress == 259) { //Up focus = 0; if(selected) selected--; if(selected < start) start--; } else if(keypress == 13) { //Enter strcpy(answer, focus ? newName : choices[selected]); if(focus == 0 && selected == 0) //Special case, cancel strcpy(answer, "DAV_CANCEL"); break; } else if(keypress == 263) { //Backspace focus = 1; if(strlen(newName) != 0) newName[strlen(newName) - 1] = '\0'; } else if(keypress == 338) { //PgDn focus = 0; for(t=0;t= maxY-1) start++; } else { focus = 1; newName[strlen(newName) + 1] = '\0'; newName[strlen(newName)] = keypress; } } for(y=0;y #include #include "structs.h" char scrollDown(); char scrollUp(); void doArguments(int argc, char *argv[]); void doAlternativeArguments(int argc, char *argv[]); void quit(char *text); void displayHelp(); void displayVersion(); void sigcatch(); void loadSettings(); void writeRC(FILE *fp); void tryQuit(); void nothing(); void logMsg(char *msg); void radixSort(char **strings, int number); void randomizedQuickSort(char **strings, int low, int high); typedef void (*ptrToFunction)(); void addLineAfter(struct line *whichLine, char *data); void connectLines(struct line *baseline); void determineLineNum(struct position *p); void countTabs(struct line *l); void determineCursX(struct position *p); ptrToFunction Fn_ptr[12]; //Bindings for the Fn keys; Fx = Fn_ptr[x-1] extern int maxY,maxX; extern int helpBarUpdate; extern char *version; //Preferences and default values extern int maxUndoLength; extern char undoEnabled; extern char autoIndent; extern int numberOfBuffers; extern char bottomRowToggle; extern char bufferQuit; extern char tabWidth; extern char smartCursor; extern char optimize; extern int *lastDisplayed; /* Number of characters last displayed on various lines */ extern char displayWholeScreen; /* Whether to refresh the whole screen */ extern struct buffer *buffers; extern struct buffer *currentBuffer; extern int currentBufferNum; #endif dav-text_0.9.0.orig/move.c0000644000175000017500000000755113427617637014103 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "move.h" #include "main.h" void moveDown(struct position *p) { positionDown(p); if(p->cursY==maxY-1 && p==¤tBuffer->cursor) { scrollDown(); } } void moveUp(struct position *p) { positionUp(p); if(p->cursY==-1 && p==¤tBuffer->cursor) { scrollUp(); } } char moveLeft(struct position *p) { /* Returns 0 upon normal movement Returns 1 if the position could not be moved left Returns 2 if moving left caused the position to enter the previous line Returns 3 if moving left caused the position to wrap on the same line */ char r = 0; if(p->l == currentBuffer->head->next && p->offset == 0) { /* Beginning of file */ return 1; } if(!p->offset) { /* Beginning of line */ p->l = p->l->prev; p->offset = p->l->length - 1; if(p->l->hasTabs) { determineCursX(p); } else { p->cursX = p->offset % maxX; } p->cursY--; p->lineNum--; r = 2; } else { p->offset--; if(!p->cursX) { r = 3; p->cursY--; if(p->l->hasTabs) { determineCursX(p); } else { p->cursX = maxX - 1; } } else { if(p->l->hasTabs) determineCursX(p); else p->cursX--; } } if(p->cursY==-1 && p==¤tBuffer->cursor) { scrollUp(); } return r; } char moveRight(struct position *p) { /* Returns 0 upon normal movement Returns 1 if the position could not be moved right (end of file) Returns 2 if moving right caused the position to enter the next line Returns 3 if moving right caused the position to wrap on the same line */ char r=0; if(p->l->next == currentBuffer->tail && p->offset == p->l->length-1) { /* End of file */ return 1; } if(p->offset < p->l->length - 1) { /* Normal movement */ int temp = p->cursX; p->offset++; if (p->l->hasTabs) { determineCursX(p); } else { p->cursX++; if (p->cursX == maxX) { p->cursX=0; } } if (p->cursX < temp) { p->cursY++; r = 3; } } else { /* Next line */ p->l = p->l->next; p->cursX = p->offset = 0; p->cursY++; p->lineNum++; r = 2; //Hit a new line } if(p->cursY == maxY-1 && p==¤tBuffer->cursor) { scrollDown(); } return r; } char scrollDown() { /* Returns 1 if the screen did not scroll down */ if(currentBuffer->topLine.lineNum + (maxY>>1) > currentBuffer->numLines) { return 1; } if(currentBuffer->cursor.cursY==0) { positionDown(¤tBuffer->cursor); } if(!positionDown(¤tBuffer->topLine)) { currentBuffer->cursor.cursY--; } currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing = 1; return 0; } char scrollUp() { /* Returns 1 if the screen did not scroll up */ if(currentBuffer->cursor.cursY==maxY-1) { positionUp(¤tBuffer->cursor); } if(!positionUp(¤tBuffer->topLine)) { currentBuffer->cursor.cursY++; } currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing = 1; return 0; } dav-text_0.9.0.orig/move.h0000644000175000017500000000221213427617637014075 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef move_h #define move_h #include "structs.h" char positionDown(struct position *p); char positionUp(struct position *p); void moveUp(struct position *p); void moveDown(struct position *p); char moveLeft(struct position *p); //Returns 1 when you hit the beginning of the buffer char moveRight(struct position *p); //Returns 1 when you hit the end of the buffer char scrollDown(); char scrollUp(); #endif dav-text_0.9.0.orig/screenIO.c0000644000175000017500000001311613427617637014636 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "screenIO.h" #include "main.h" #include "fileIO.h" #include "features.h" #include "buffers.h" #include "undo.h" #include "move.h" void displayLine(int line, struct position *pos) { int ch; char *data = pos->l->data + pos->offset; int length = pos->l->length; char *end = pos->l->data + length; int screenX = 0; if(pos->l != currentBuffer->tail) { while(1) { ch = *data++; if(ch==9) { /* Tab */ while((screenX % tabWidth) != tabWidth-1) { mvaddch(line, screenX++, ' '); } } mvaddch(line, screenX, ch); if (screenX++ >= maxX || data==end) { screenX--; break; } } } length = lastDisplayed[line]; lastDisplayed[line] = screenX; while (screenXlineUpdate.lineNum; if(currentBuffer->lineUpdate.offset == -1) { return; } if (displayWholeScreen) { int i; for (i=0; ilineUpdate.cursX) { moveLeft(¤tBuffer->lineUpdate); } do { displayLine(lineNum++, ¤tBuffer->lineUpdate); } while(!positionDown(¤tBuffer->lineUpdate) && currentBuffer->lineUpdate.cursYkeepGoing) { while(lineNumlineUpdate); if(positionDown(¤tBuffer->lineUpdate)==1) { currentBuffer->lineUpdate.l = currentBuffer->tail; } lineNum++; } } currentBuffer->keepGoing = 0; } void showRow() { char num[5]; char total[5]; int t; num[0] = ((currentBuffer->cursor.lineNum+1)/10000) % 10 + 48; num[1] = ((currentBuffer->cursor.lineNum+1)/1000) % 10 + 48; num[2] = ((currentBuffer->cursor.lineNum+1)/100) % 10 + 48; num[3] = ((currentBuffer->cursor.lineNum+1)/10) % 10 + 48; num[4] = (currentBuffer->cursor.lineNum+1) % 10 + 48; total[0] = ((currentBuffer->numLines+1)/10000) % 10 + 48; total[1] = ((currentBuffer->numLines+1)/1000) % 10 + 48; total[2] = ((currentBuffer->numLines+1)/100) % 10 + 48; total[3] = ((currentBuffer->numLines+1)/10) % 10 + 48; total[4] = (currentBuffer->numLines+1) % 10 + 48; for (t=0; t<4; t++) { if(num[t]==48) { num[t]=' '; } else { break; } } for (t=0; t<4; t++) { if(total[t]==48) { total[t]=' '; } else { break; } } mvaddstr(maxY-1,maxX-11,num); mvaddch(maxY-1,maxX-6,'/'); mvaddstr(maxY-1,maxX-5,total); } void helpBar() { char c[200]; char *ptr = c; int t; displayBottomRow(); if(bottomRowToggle) { for(t=0;t<12;t++) { if(Fn_ptr[t] == search) { strcpy(ptr,KEY_F1); ptr += 3; strcpy(ptr,KEY_F1_TEXT); ptr+=7; } else if(Fn_ptr[t] == save) { strcpy(ptr,KEY_F2); ptr += 3; strcpy(ptr,KEY_F2_TEXT); ptr+=5; } else if(Fn_ptr[t] == saveAs) { strcpy(ptr,KEY_F3); ptr += 3; strcpy(ptr,KEY_F3_TEXT); ptr+=7; } else if(Fn_ptr[t] == askLoad) { strcpy(ptr,KEY_F4); ptr += 3; strcpy(ptr,KEY_F4_TEXT); ptr+=5; } else if(Fn_ptr[t] == tryQuit) { strcpy(ptr,KEY_F5); ptr += 3; strcpy(ptr,KEY_F5_TEXT); ptr+=5; } else if(Fn_ptr[t] == Undo) { strcpy(ptr,KEY_F6); ptr += 3; strcpy(ptr,KEY_F6_TEXT); ptr+=8; } else if(Fn_ptr[t] == toggleAutoIndent) { strcpy(ptr,KEY_F8); ptr += 3; strcpy(ptr,KEY_F8_TEXT); ptr+=11; } else if(Fn_ptr[t] == tryCompile) { strcpy(ptr,KEY_F9); ptr += 3; strcpy(ptr,KEY_F9_TEXT); ptr+=8; } else if(Fn_ptr[t] == toggleBottomRow) { strcpy(ptr,KEY_F10); ptr += 4; strcpy(ptr,KEY_F10_TEXT); ptr+=15; } else if(Fn_ptr[t] == replace) { strcpy(ptr, "Replace "); ptr+=8; } else if(Fn_ptr[t] == goToNextBuffer) { strcpy(ptr, "Next "); ptr+=9; } else if(Fn_ptr[t] == goToPrevBuffer) { strcpy(ptr, "Prev "); ptr+=5; } else if(Fn_ptr[t] == nothing) { ptr-=3; } } *ptr = '\0'; mvaddnstr(maxY-1,0,c,maxX-1); } else { char temp[3]; temp[0] = (currentBufferNum / 10) + '0'; temp[1] = (currentBufferNum % 10) + '0'; temp[2] = '\0'; strcpy(c,"Editing "); strcat(c,currentBuffer->fname); strcat(c," ["); if(currentBufferNum >= 10) { strcat(c,temp); } else { strcat(c,temp+1); } strcat(c,"]"); mvaddstr(maxY-1,0,c); } showRow(); } void displayBottomRow() { int x; for(x=maxX-12; x; x--) { mvaddch(maxY-1, x, ' '); } } dav-text_0.9.0.orig/screenIO.h0000644000175000017500000000311013427617637014634 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef screenIO_h #define screenIO_h #include "structs.h" void displayScreen(); void showRow(); void helpBar(); void displayBottomRow(); void displayLine(int line, struct position *pos); /* * do not modify the whitespace in the defines * the whitespace is used for padding the * bottombar in the editor (helpbar). */ #define KEY_F1 "F1:" #define KEY_F2 "F2:" #define KEY_F3 "F3:" #define KEY_F4 "F4:" #define KEY_F5 "F5:" #define KEY_F6 "F6:" #define KEY_F8 "F8:" #define KEY_F9 "F9:" #define KEY_F10 "F10:" #define KEY_F1_TEXT "Search|" #define KEY_F2_TEXT "Save|" #define KEY_F3_TEXT "SaveAs|" #define KEY_F4_TEXT "Load|" #define KEY_F5_TEXT "Quit|" #define KEY_F6_TEXT "Undo|" #define KEY_F8_TEXT "AutoIndent|" #define KEY_F9_TEXT "Compile|" #define KEY_F10_TEXT "BottomRow|" #endif dav-text_0.9.0.orig/structs.h0000644000175000017500000000272313427617637014645 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef structs_h #define structs_h struct line { char *data; int length; struct line *next; struct line *prev; char hasTabs; }; struct position { struct line *l; int offset; int lineNum; int cursX,cursY; int wantCursX; }; struct undoMove { /* Reverses some modification to a buffer */ int line, offset; char c; /* What was added or removed */ }; struct buffer { char searchString[80]; int numLines; struct line *head,*tail; struct position cursor; struct position topLine; struct position lineUpdate; char keepGoing; struct line **currentLine; char fname[80]; int lineNumBak; char updated; struct undoMove *undoMoves; int undoBufferPointer; int undoBufferLength; }; #endif dav-text_0.9.0.orig/undo.c0000644000175000017500000000511013427617637014067 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "undo.h" #include "main.h" #include "keyboard.h" #include "move.h" void Do(int keypress) { switch(keypress) { case 0: addToUndo((int)currentBuffer->cursor.l->data[currentBuffer->cursor.offset]); break; case 1: addToUndo(0); break; default: break; } } void addToUndo(int keypress) { currentBuffer->undoMoves[currentBuffer->undoBufferPointer].c = keypress; currentBuffer->undoMoves[currentBuffer->undoBufferPointer].line = currentBuffer->cursor.lineNum; currentBuffer->undoMoves[currentBuffer->undoBufferPointer].offset = currentBuffer->cursor.offset; currentBuffer->undoBufferPointer++; currentBuffer->undoBufferPointer %= maxUndoLength; if(++currentBuffer->undoBufferLength>maxUndoLength) currentBuffer->undoBufferLength--; } void Undo() { int key; if(!undoEnabled) return; if(currentBuffer->undoBufferLength==0) return; currentBuffer->undoBufferLength--; if(--currentBuffer->undoBufferPointer == -1) currentBuffer->undoBufferPointer=maxUndoLength-1; key = (int)currentBuffer->undoMoves[currentBuffer->undoBufferPointer].c; while(currentBuffer->cursor.lineNum > currentBuffer->undoMoves[currentBuffer->undoBufferPointer].line) moveUp(¤tBuffer->cursor); while(currentBuffer->cursor.lineNum < currentBuffer->undoMoves[currentBuffer->undoBufferPointer].line) moveDown(¤tBuffer->cursor); while(currentBuffer->cursor.offset < currentBuffer->undoMoves[currentBuffer->undoBufferPointer].offset) moveRight(¤tBuffer->cursor); while(currentBuffer->cursor.offset > currentBuffer->undoMoves[currentBuffer->undoBufferPointer].offset) moveLeft(¤tBuffer->cursor); if(key=='\n') key=13; if(key == 0) key = 330; keyHit(key,0); currentBuffer->lineUpdate = currentBuffer->topLine; currentBuffer->lineUpdate.lineNum = 0; currentBuffer->keepGoing = 1; } dav-text_0.9.0.orig/undo.h0000644000175000017500000000152713427617637014104 0ustar atsbatsb/* Copyright 2001-2003 David Gucwa Copyright 2017-2019 Adam Bilbrough 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef undo_h #define undo_h void Do(int keypress); void addToUndo(int keypress); void Undo(); #endif dav-text_0.9.0.orig/0000700000175000017500000000000013561761257012744 5ustar atsbatsb