📄 reader.cxx
字号:
// Program to read Aportis format files on the Agenda VR3// by $Author: agenda $. Current version $Revision: 1.36 $, $Date: 2001/10/10 19:55:20 $.// This is a $State: Exp $ version.// Baseline is $Name: V1_1 $//// $Log: reader.cxx,v $// Revision 1.36 2001/10/10 19:55:20 agenda// First release candidate with background autogenning.//// Revision 1.35 2001/10/10 19:37:40 agenda// Background autogenning seems to be working - now to tidy it up!//// Revision 1.34 2001/10/04 21:29:53 agenda// First round of "slow and small" bug fixes//// Revision 1.33 2001/10/03 19:19:17 agenda// Slow but small background auto-genning//// Revision 1.32 2001/10/02 21:41:11 agenda// Background autogen//// Revision 1.31 2001/09/08 23:08:45 agenda// Added tight spacing option//// Revision 1.30 2001/09/07 14:56:26 agenda// Improvements to window placement etc.//// Revision 1.29 2001/09/06 00:03:41 agenda// Removed FP version of fl_width, put CBars info info dialogue and// made the buffdoc and myoutput objects a little more self-contained.//// Revision 1.28 2001/09/05 02:22:26 agenda// Converted myoutput to a widget, added progress bars and some minor bug fixes.//// Revision 1.27 2001/09/01 14:30:13 agenda// Check-in for actual beta-release 1.0a//// Revision 1.26 2001/08/30 00:07:06 agenda// Added filesize info and prepared for next release//// Revision 1.25 2001/08/28 10:31:13 agenda// Version 1.0 beta A//// Revision 1.24 2001/08/16 20:23:45 agenda// First working version with bookmarks//// Revision 1.23 2001/08/05 19:14:06 agenda// Started adding in bookmarks proper//// Revision 1.21 2001/07/04 21:16:29 agenda// Ready for initial release//// Revision 1.20 2001/06/19 21:24:57 agenda// First release candidate//// Revision 1.19 2001/06/13 21:06:43 agenda// Now works reasonably well and quite quickly too!//// Revision 1.18 2001/06/10 21:29:53 agenda// Replaced multiline output with direct drawing of text//// Revision 1.17 2001/06/07 23:34:00 agenda// First working(?) version with Flek and flpda.//// Revision 1.16 2001/06/07 21:54:51 agenda// Changed over to use text rather than Sixpack compression as the third data type.//// Revision 1.15 2001/06/07 21:41:47 agenda// Made a bit more robust!//// Revision 1.14 2001/06/07 21:30:00 agenda// First working version//// Revision 1.16 2001/06/01 12:09:55 agenda// Version which works with ppm//// Revision 1.15 2001/05/28 05:09:10 agenda// Done some restructuring so that plugging in other decompression schemes should be easier.// Changed the page-up code to be more efficient and more accurate - though it may get messy if there is no formatting// in the input file as it looks for paragraphs to regain synchronisation.//// Still to do:// User defined bookmarks// Allow some overlap between pages// Find// Tidy up the page-up code to use a circular array of pointers and a single// char* rather than a circular array of char*'s// Tidy up the page-up code in general//// Revision 1.14 2001/05/26 10:44:43 agenda// Check-in just prior to some restructuring//// Revision 1.13 2001/05/11 05:07:59 agenda// First attempt to do bookmarks. Works on workstation but fails on Agenda.//// Revision 1.12 2001/05/11 03:25:17 agenda// Corrected a bug when a match overlaps the current position. Added two optional command line arguments to open a particular file at a particuler location at startup.//// Revision 1.11 2001/04/29 22:21:36 agenda// Added a little bit of book-marking but I couldn't get the dbm stuff// on the Agenda to work.// Added magnify and reduce and embolden.//// Revision 1.10 2001/04/22 21:38:58 agenda// Removed obsolete tBuf class, made buffers a more realistic size// and a bit of tidying up.//// Revision 1.9 2001/04/22 14:42:47 agenda// Page up and Page down now working, though page up is approximate and not// particularly efficient. Most of the stuff is there to allow bookmarks// but the actual GUI and storage for bookmarks is still TBD.//// Currently can use Alt-f to query/set the current position so bookmarks// can be managed manually, for now.//// Revision 1.8 2001/04/21 20:38:00 agenda// Added some stuff to go to a particular point in the file.// To get it working properly requires some major changes to// the decompression stuff so this check-in is just so I// can revert if I mess up the next set of changes.//// Revision 1.7 2001/04/21 08:44:28 agenda// Tidied up page down a bit.// Other stuff to do which I left out of my last check-in is to get find working// (or maybe just remove it)//// Revision 1.6 2001/04/21 08:07:00 agenda// First useable version with buffering.// Still to do:// Enable page-up// Bookmarks// Allow some overlap between pages// Currently each page has no text in common with the previous page.// Normally you would expect the first line of a new page to be the same// as the last line of the next page. I happen to quite like how it// (accidentally) works now so I may not change it.//// Revision 1.4 2001/04/14 23:05:03 agenda// Tidied up header and clarified where other headers are quoted.//// Revision 1.3 2001/04/14 22:53:16 agenda// Begun adding in version control info, etc.//// Revision 1.2 2001/04/14 22:40:44 agenda// Improved handling of page-up/down events//// Revision 1.1 2001/04/14 21:44:23 agenda// Initial revision// ============================================================================//static char rcsid[] = "$Id: reader.cxx,v 1.36 2001/10/10 19:55:20 agenda Exp $";// Decompression based (very heavily) on://// ------------- Begin quoted header -------------// MakeDoc// version 2//// Compresses text files into a format that is ready to export to a Pilot// and work with Rick Bram's PilotDOC reader.//// Copyright (C) Pat Beirne, 2000.// Distributable under the GNU General Public License Version 2 or later.//// ver 0.6 enforce 31 char limit on database names// ver 0.7 change header and record0 to structs// ver 2.0 added category control on the command line// changed extensions from .prc to .pdb// -------------- End quoted header --------------//// Remainder based (more loosely) on//// ------------- Begin quoted header -------------// A simple text editor program for the Fast Light Tool Kit (FLTK).//// This program is described in Chapter 4 of the FLTK Programmer's Guide.//// Copyright 1998-2000 by Bill Spitzak and others.//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Library General Public// License as published by the Free Software Foundation; either// version 2 of the License, or (at your option) any later version.//// This library 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// Library General Public License for more details.//// You should have received a copy of the GNU Library General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307// USA.//// Please report all bugs and problems to "fltk-bugs@fltk.org".// -------------- End quoted header --------------//// Note that it is unlikely that any bug found in this program// will be relevant to the fltk organisation as it will almost// certainly be one of mine.#include <stdio.h> // Standard library files#ifdef _SLOW#include <unistd.h>#endif#include <stdlib.h>#include <string.h>#include <errno.h>//#include <string>#ifdef AGENDA#include <flpda/Widget_Factory.h>#include <Flek/Fl_App_Window.H>#endif#include <FL/Fl.H> // Main FLTK header file#include <FL/Fl_Group.H> // Fl_Group header file#include <FL/Fl_Window.H> // Fl_Window header file#include <FL/fl_ask.H> // FLTK convenience functions#if defined(RAW) || !defined(AGENDA)#include <FL/fl_file_chooser.H>#else//#include "fl_ag_file_chooser.H" // FLTK file chooser#include "my_fl_file_chooser.H" // FLTK file chooser#endif#include <FL/Fl_Menu_Bar.H> // Fl_Menu_Bar header file#include <FL/Fl_Input.H> // Fl_Input header file#ifdef AGENDA#include <flpda/Fl_Paged_Select_Browser.H> // Fl_Multiline_Input header file#else#include <FL/Fl_Select_Browser.H> // Fl_Multiline_Input header file#endif#include <FL/Fl_Multiline_Output.H> // Fl_Multiline_Input header file#include <FL/Fl_Button.H> // Fl_Button header file#include <FL/Fl_Return_Button.H> // Fl_Return_Button header file#include <FL/Fl_Int_Input.H>#include <FL/fl_draw.H>#include <FL/filename.H>#include <sys/stat.h>#include <fcntl.h>#ifdef USEBKMKS#ifdef WS#include <db1/db.h>#else#include <db.h>#endif#endif#include "CFilter.h"#include "CBuffer.h"#include "CBar.h"//#include "unistd.h"#ifdef USEBKMKS#define LASTFILE "/////lastfileopened/////"#define PREFRNCE "/////preferences/////"#endif#ifdef USEBKMKSvoid setbkmkkey(const char *file, const char *mark, DBT* key);DB* bkmks;#endiftypedef unsigned char byte;typedef unsigned long DWORD;typedef unsigned short WORD;char filename[1024];char search[256];#include "Aportis.h"#ifndef SMALL#include "ppm_expander.h"#endif//#include "Sixpack.h"#include "Text.h"#ifdef AGENDAvoid centre_window(Fl_Window* p){ p->position((Fl::w()-p->w()) >> 1, (Fl::h()-p->h()) >> 1);}#endifvoid Cancel_cb(Fl_Widget *widget, void *data){ widget->window()->hide();}class BuffDoc { CBuffer lastword; bool lastispara; CExpander* exp; CFilterChain* filt;public: ~BuffDoc() { delete filt; delete exp; } BuffDoc() { exp = NULL; filt = NULL; } void setfilter(CFilterChain* _f) { if (filt != NULL) delete filt; filt = _f; filt->setsource(exp); } CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); } bool hasrandomaccess() { return exp->hasrandomaccess(); } bool iseol() { return (lastword[0] == '\0'); } int openfile(char *src) { // printf("Trying aportis %x\n",exp); if (exp != NULL) delete exp; exp = new Aportis; lastword[0] = '\0'; lastispara = false; // printf("Calling openfile\n"); int ret = exp->openfile(src); // printf("Called openfile\n"); if (ret == -1) { // fl_alert("problem opening source file:%s",src); // printf("problem opening source file\n"); delete exp; exp = NULL; return ret; } if (ret == -2) { // printf("file contains %x, %x",head.dwCreator, head.dwType); delete exp;#ifndef SMALL // printf("Trying ppms\n"); exp = new ppm_expander; ret = exp->openfile(src); if (ret != 0) { delete exp; exp = new Text; // printf("Trying text\n"); ret = exp->openfile(src); }#else exp = new Text; ret = exp->openfile(src);#endif } if (ret != 0) { fl_alert("WARNING: unknown file compression type:%d",ret); } lastword[0] = '\0'; lastispara = false; exp->locate(0); filt->setsource(exp); return 0; } int getch() { return (exp == NULL) ? EOF : filt->getch(); } unsigned int locate() { return (exp == NULL) ? 0 : exp->locate()-strlen(lastword.data()); } void locate(unsigned int n); bool getline(CBuffer* buff, int w); void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); } int getpara(CBuffer& buff) { int ch, i = 0; while ((ch = getch()) != 10 && ch != EOF) buff[i++] = ch; buff[i] = '\0'; if (i == 0 && ch == EOF) return -1; return i; }};void BuffDoc::locate(unsigned int n){ lastword[0] = '\0'; lastispara = false; // char linebuf[1024]; if (exp != NULL) exp->locate(n); // while (exp.locate() < n && getline(linebuf,w)); }bool BuffDoc::getline(CBuffer* buff, int w){ int len = 0, ch, lastcheck = 0; *buff = lastword.data(); lastcheck = len = buff->length(); unsigned int slen = fl_widthi(buff->data(),len); if (slen > w) { for ( ; len > 0; len--) { if (fl_widthi(buff->data(),len) < w) break; } lastword = buff->data() + len - 1; (*buff)[len-1] = '-'; (*buff)[len] = '\0'; return true; } if (lastispara) { lastispara = false; lastword[0] = '\0'; len = buff->length(); while (fl_widthi(buff->data(),len) > w) len--; (*buff)[len] = '\0'; return true; } lastispara = false; while (slen < w) { lastcheck = len; while ((ch = getch()) != ' ' && ch != '\012' && ch != EOF) { (*buff)[len++] = ch; } slen = fl_widthi(buff->data(),len); (*buff)[len++] = ' '; if (slen < w && ch != ' ') { lastcheck = len; break; } lastispara = (ch == '\012'); } (*buff)[len] = '\0'; lastword = buff->data()+lastcheck; (*buff)[(lastcheck > 0) ? lastcheck-1:lastcheck] = '\0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -