integrate text editor and command interpreter
Brought to you by:
johnston
|
From: <ivt...@li...> - 2000-02-25 23:22:11
|
Patch: ivtools-000226-johnston-027
For: ivtools-0.8
Author: joh...@us...
This is an intermediate patch to ivtools-0.8. To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:
patch -p0 <ThisFile
Summary of Changes:
- derive ComGlyph's ComTextEditor and ComTE_View from IVGlyph's
EivTextEditor and TE_View. This adds an interactive command
interpreter capability to the text editor object, where the user can
enter expressions and see results computed. While a command history
plus anything else goes to stdout, the results follow just the
expression, so it is sometimes easier to keep track of the commands
you're using. All of stdout could be rerouted to the texteditor
window in the future. vhclmaps vhclviewer is the first place in the
source tree where this capability is exposed for now. Check it out.
- settle on "dotname" for the command that returns the name of a
name/value attribute pair. This is because "." (dot) is the operator
used to create attribute list objects in the comterp command
interpreter. Normally most attribute objects are automatically
indirected to the attribute value when finally applied, but in this
command overrides that and returns the symbol which is the attribute
name.
Index: top_ivtools/MANIFEST
diff -c top_ivtools/MANIFEST:1.1 top_ivtools/MANIFEST:1.2
*** top_ivtools/MANIFEST:1.1 Tue Jan 18 03:06:44 2000
--- ./MANIFEST Sat Feb 26 03:07:22 2000
***************
*** 125,130 ****
--- 125,134 ----
ivtools-0.8/src/ComGlyph/Makefile
ivtools-0.8/src/ComGlyph/attrdialog.c
ivtools-0.8/src/ComGlyph/attrdialog.h
+ ivtools-0.8/src/ComGlyph/comtextedit.c
+ ivtools-0.8/src/ComGlyph/comtextedit.h
+ ivtools-0.8/src/ComGlyph/comtextview.c
+ ivtools-0.8/src/ComGlyph/comtextview.h
ivtools-0.8/src/ComGlyph/terpdialog.c
ivtools-0.8/src/ComGlyph/terpdialog.h
ivtools-0.8/src/ComTerp/Imakefile
Index: ComTerp/comterp.c
diff -c ComTerp/comterp.c:1.8 ComTerp/comterp.c:1.9
*** ComTerp/comterp.c:1.8 Wed Feb 23 04:27:32 2000
--- src/ComTerp/comterp.c Sat Feb 26 03:07:26 2000
***************
*** 679,687 ****
_quitflag = flag;
}
! int ComTerp::run(boolean once) {
! int status = 0;
_errbuf[0] = '\0';
filebuf fbuf;
if (handler()) {
--- 679,689 ----
_quitflag = flag;
}
! int ComTerp::run(boolean one_expr) {
! int status = 1;
_errbuf[0] = '\0';
+ char errbuf_save[BUFSIZ];
+ errbuf_save[0] = '\0';
filebuf fbuf;
if (handler()) {
***************
*** 695,701 ****
--- 697,707 ----
while (!eof() && !quitflag() && !eolflag) {
if (read_expr()) {
+ status = 0;
+ int top_before = _stack_top;
eval_expr();
+ if (top_before == _stack_top)
+ status = 2;
err_str( _errbuf, BUFSIZ, "comterp" );
if (strlen(_errbuf)==0) {
if (quitflag()) {
***************
*** 707,725 ****
}
} else {
out << _errbuf << "\n"; out.flush();
_errbuf[0] = '\0';
}
} else {
err_str( _errbuf, BUFSIZ, "comterp" );
if (strlen(_errbuf)>0) {
out << _errbuf << "\n"; out.flush();
_errbuf[0] = '\0';
! } else
eolflag = true;
}
_stack_top = -1;
! if (once) break;
}
return status;
}
--- 713,736 ----
}
} else {
out << _errbuf << "\n"; out.flush();
+ strcpy(errbuf_save, _errbuf);
_errbuf[0] = '\0';
}
} else {
err_str( _errbuf, BUFSIZ, "comterp" );
if (strlen(_errbuf)>0) {
out << _errbuf << "\n"; out.flush();
+ strcpy(errbuf_save, _errbuf);
_errbuf[0] = '\0';
! } else {
eolflag = true;
+ if (errbuf_save[0]) strcpy(_errbuf, errbuf_save);
+ }
}
_stack_top = -1;
! if (one_expr) break;
}
+ if (status==1 && _pfnum==0) status=2;
return status;
}
***************
*** 771,777 ****
add_command("iterate", new IterateFunc(this));
add_command("dot", new DotFunc(this));
! add_command("name", new DotNameFunc(this));
add_command("list", new ListFunc(this));
add_command("at", new ListAtFunc(this));
--- 782,788 ----
add_command("iterate", new IterateFunc(this));
add_command("dot", new DotFunc(this));
! add_command("dotname", new DotNameFunc(this));
add_command("list", new ListFunc(this));
add_command("at", new ListAtFunc(this));
Index: ComTerp/comterp.h
diff -c ComTerp/comterp.h:1.4 ComTerp/comterp.h:1.5
*** ComTerp/comterp.h:1.4 Sat Feb 19 00:59:05 2000
--- src/ComTerp/comterp.h Sat Feb 26 03:07:26 2000
***************
*** 148,155 ****
virtual void exit(int status=0);
// call _exit().
! virtual int run(boolean once=false);
! // run interpreter until end-of-file or quit command, unless 'once' is true.
virtual int runfile(const char* filename);
// run interpreter on contents of 'filename'.
void add_defaults();
--- 148,159 ----
virtual void exit(int status=0);
// call _exit().
! virtual int run(boolean one_expr=false);
! // run interpreter until end-of-file or quit command, unless
! // 'one_expr' is true. Leave 'one_expr' false when using a ComTerpServ.
! // Return Value: -1 if eof, 0 if normal operation, 1 if
! // partial expression parsed, 2 if no result computed
!
virtual int runfile(const char* filename);
// run interpreter on contents of 'filename'.
void add_defaults();
***************
*** 206,211 ****
--- 210,218 ----
void clr_val_for_next_func();
// clear out ComValue to pass to subequent command
+ unsigned int& linenum() { return _linenum; }
+ // count of lines processed
+
protected:
void incr_stack();
void incr_stack(int n);
***************
*** 232,237 ****
--- 239,245 ----
unsigned int _stack_siz;
boolean _quitflag;
char* _errbuf;
+ char* _errbuf2;
int _pfoff;
boolean _brief; // when used to produce ComValue output
boolean _just_reset;
Index: IVGlyph/textedit.c
diff -c IVGlyph/textedit.c:1.1 IVGlyph/textedit.c:1.2
*** IVGlyph/textedit.c:1.1 Tue Jan 18 03:08:21 2000
--- src/IVGlyph/textedit.c Sat Feb 26 03:07:33 2000
***************
*** 52,82 ****
#include "texteditor.h"
#include "textview.h"
- // Adjustable, used to control scrolling
- class TE_Adjustable : public Adjustable, public Observer {
- public:
- TE_Adjustable(TE_View*);
-
- virtual void update(Observable*);
-
- virtual Coord lower(DimensionName) const;
- virtual Coord upper(DimensionName) const;
- virtual Coord length(DimensionName) const;
- virtual Coord cur_lower(DimensionName) const;
- virtual Coord cur_upper(DimensionName) const;
- virtual Coord cur_length(DimensionName) const;
-
- virtual void scroll_forward(DimensionName);
- virtual void scroll_backward(DimensionName);
- virtual void page_forward(DimensionName);
- virtual void page_backward(DimensionName);
-
- virtual void scroll_to(DimensionName, Coord lower);
- virtual void scroll_by(DimensionName, long);
- private:
- TE_View* te_view_;
- };
-
// TE Adjustable
TE_Adjustable::TE_Adjustable(TE_View* te_view)
--- 52,57 ----
***************
*** 155,160 ****
--- 130,137 ----
notify(Dimension_Y); // notify scrollbar
}
+
+ EivTextEditor::EivTextEditor() { }
EivTextEditor::EivTextEditor(Style* s, boolean active)
{
Index: IVGlyph/textedit.h
diff -c IVGlyph/textedit.h:1.1 IVGlyph/textedit.h:1.2
*** IVGlyph/textedit.h:1.1 Tue Jan 18 03:08:21 2000
--- src/IVGlyph/textedit.h Sat Feb 26 03:07:33 2000
***************
*** 28,41 ****
--- 28,46 ----
// TextEditor*textFont fixed
//
+ #include <InterViews/monoglyph.h>
+
typedef unsigned int EivTextUnit;
+ class Style;
+ class InputHandler;
class TE_Adjustable;
class TE_View;
class EivTextEditor : public MonoGlyph {
public:
EivTextEditor(Style*, boolean active= true);
+ EivTextEditor();
virtual ~EivTextEditor();
// load/save file. Default for save is to save to current
***************
*** 90,95 ****
--- 95,128 ----
TE_View* te_view_;
Glyph* sb_;
Style* style_;
+ };
+
+ #include <InterViews/adjust.h>
+ #include <InterViews/observe.h>
+
+ // Adjustable, used to control scrolling
+ class TE_Adjustable : public Adjustable, public Observer {
+ public:
+ TE_Adjustable(TE_View*);
+
+ virtual void update(Observable*);
+
+ virtual FloatCoord lower(DimensionName) const;
+ virtual FloatCoord upper(DimensionName) const;
+ virtual FloatCoord length(DimensionName) const;
+ virtual FloatCoord cur_lower(DimensionName) const;
+ virtual FloatCoord cur_upper(DimensionName) const;
+ virtual FloatCoord cur_length(DimensionName) const;
+
+ virtual void scroll_forward(DimensionName);
+ virtual void scroll_backward(DimensionName);
+ virtual void page_forward(DimensionName);
+ virtual void page_backward(DimensionName);
+
+ virtual void scroll_to(DimensionName, FloatCoord lower);
+ virtual void scroll_by(DimensionName, long);
+ private:
+ TE_View* te_view_;
};
#endif
Index: IVGlyph/textview.h
diff -c IVGlyph/textview.h:1.4 IVGlyph/textview.h:1.5
*** IVGlyph/textview.h:1.4 Wed Feb 2 03:09:40 2000
--- src/IVGlyph/textview.h Sat Feb 26 03:07:33 2000
***************
*** 131,137 ****
const char* text();
void text(const char*, boolean update =true);
! private:
void scroll_to_line(int line);
void make_visible(const boolean scroll_page = true);
int event_to_index(const Event&);
--- 131,138 ----
const char* text();
void text(const char*, boolean update =true);
!
! protected:
void scroll_to_line(int line);
void make_visible(const boolean scroll_page = true);
int event_to_index(const Event&);
Index: ComGlyph/Imakefile
diff -c ComGlyph/Imakefile:1.1 ComGlyph/Imakefile:1.2
*** ComGlyph/Imakefile:1.1 Tue Jan 18 03:09:44 2000
--- src/ComGlyph/Imakefile Sat Feb 26 03:07:46 2000
***************
*** 16,21 ****
--- 16,23 ----
#define Obj31(file) MakeObjectFromSrcFlags(file, -Uiv2_6_compatible -I$(TOP)/src/include $(TOP_CCINCLUDES))
Obj31(attrdialog)
+ Obj31(comtextedit)
+ Obj31(comtextview)
Obj31(terpdialog)
IncludeDependencies()
Index: ComGlyph/comtextedit.c
diff -c /dev/null ComGlyph/comtextedit.c:1.1
*** /dev/null Sat Feb 26 03:07:47 2000
--- src/ComGlyph/comtextedit.c Sat Feb 26 03:07:46 2000
***************
*** 0 ****
--- 1,110 ----
+ /*
+ * Copyright (c) 2000 IET Inc
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * related documentation and data files for any purpose is hereby granted
+ * without fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the names of the copyright holders not
+ * be used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. The copyright holders
+ * make no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+ // layered on top of classes distributed with this license:
+ //
+ // Simple Text Editor Implementation
+ //
+ // Copyright (C) 1993 Ellemtel Telecommunication Systems Labratories
+ //
+ // Permission is granted to any individual or institution to use, copy,
+ // modify, and distribute this software, provided that this complete
+ // copyright and permission notice is maintained, intact, in all copies
+ // and supporting documentation.
+ //
+ // Ellemtel Telecommunication Systems Labratories make no representation
+ // of the suitability of this software for any purpose. It is provided
+ // "as is" without any expressed or implied warranty.
+ //
+ // Jan Andersson, Torpa Konsult AB
+ // ja...@to... - 1993-08-29
+ //
+
+ #include <ComTerp/comterpserv.h>
+ #include <ComGlyph/comtextedit.h>
+ #include <ComGlyph/comtextview.h>
+ #include <IVGlyph/textbuff.h>
+ #include <InterViews/background.h>
+ #include <InterViews/color.h>
+ #include <InterViews/layout.h>
+ #include <InterViews/session.h>
+ #include <InterViews/style.h>
+ #include <InterViews/style.h>
+ #include <IV-look/kit.h>
+ #include <OS/string.h>
+
+ ComTextEditor::ComTextEditor(Style* s, ComTerpServ* comterp, boolean active) : EivTextEditor() {
+
+ const LayoutKit& layout = *LayoutKit::instance();
+ WidgetKit& kit = *WidgetKit::instance();
+
+ style_ = new Style("TextEditor", s);
+ Resource::ref(style_);
+
+ double rows = 24;
+ (void) style_->find_attribute("rows", rows);
+ double cols = 80;
+ (void) style_->find_attribute("columns", cols);
+
+ // create buffer and view
+ EivTextBuffer* te_buffer = new EivTextBuffer();
+ te_view_ = new ComTE_View(style_, te_buffer, int(rows), int(cols), active);
+ ((ComTE_View*)te_view_)->comterp(comterp);
+
+ // attach adjustable and scrollbar
+ te_adjustable_ = new TE_Adjustable(te_view_);
+ te_view_->attach(te_adjustable_);
+ sb_ = kit.vscroll_bar(te_adjustable_);
+
+ Display* d = Session::instance()->default_display();
+ const Color* bg = Color::lookup(d, "#aaaaaa");
+ if (bg == nil)
+ bg = new Color(0.7,0.7,0.7,1.0);
+
+ body(
+ new Background(
+ layout.margin(
+ layout.hbox(
+ kit.inset_frame(
+ layout.vcenter(layout.margin(te_view_, 2.0), 1.0)
+ ),
+ layout.hspace(4.0),
+ sb_
+ ),
+ 5.0),
+ bg
+ )
+ );
+ }
+
+ ComTextEditor::~ComTextEditor()
+ {
+ }
+
+ ComTE_View* ComTextEditor::comtextview() { return (ComTE_View*)te_view_; }
+
+
+
+
+
+
Index: ComGlyph/comtextedit.h
diff -c /dev/null ComGlyph/comtextedit.h:1.1
*** /dev/null Sat Feb 26 03:07:47 2000
--- src/ComGlyph/comtextedit.h Sat Feb 26 03:07:46 2000
***************
*** 0 ****
--- 1,60 ----
+ /*
+ * Copyright (c) 2000 IET Inc
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * related documentation and data files for any purpose is hereby granted
+ * without fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the names of the copyright holders not
+ * be used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. The copyright holders
+ * make no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+ // layered on top of classes distributed with this license:
+ //
+ // Simple Text Editor
+ //
+ //
+ // Copyright (C) 1993 Ellemtel Telecommunication Systems Labratories
+ //
+ // Permission is granted to any individual or institution to use, copy,
+ // modify, and distribute this software, provided that this complete
+ // copyright and permission notice is maintained, intact, in all copies
+ // and supporting documentation.
+ //
+ // Ellemtel Telecommunication Systems Labratories make no representation
+ // of the suitability of this software for any purpose. It is provided
+ // "as is" without any expressed or implied warranty.
+ //
+ // Jan Andersson, Torpa Konsult AB
+ // ja...@to... - 1993-08-29
+
+ #ifndef com_texteditor_h
+ #define com_texteditor_h
+
+ #include <IVGlyph/textedit.h>
+
+ class ComTE_View;
+ class ComTerpServ;
+ class Style;
+
+ class ComTextEditor : public EivTextEditor {
+ public:
+ ComTextEditor(Style*, ComTerpServ* comterp=nil, boolean active=true);
+ virtual ~ComTextEditor(); ComTE_View* comtextview();
+
+ };
+
+ #endif
+
Index: ComGlyph/comtextview.c
diff -c /dev/null ComGlyph/comtextview.c:1.1
*** /dev/null Sat Feb 26 03:07:47 2000
--- src/ComGlyph/comtextview.c Sat Feb 26 03:07:46 2000
***************
*** 0 ****
--- 1,242 ----
+ /*
+ * Copyright (c) 2000 IET Inc
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * related documentation and data files for any purpose is hereby granted
+ * without fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the names of the copyright holders not
+ * be used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. The copyright holders
+ * make no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+ // layered on top of classes distributed with this license:
+ //
+ // Simple Text Editor Implementation
+ //
+ // Copyright (C) 1993 Ellemtel Telecommunication Systems Labratories
+ //
+ // Permission is granted to any individual or institution to use, copy,
+ // modify, and distribute this software, provided that this complete
+ // copyright and permission notice is maintained, intact, in all copies
+ // and supporting documentation.
+ //
+ // Ellemtel Telecommunication Systems Labratories make no representation
+ // of the suitability of this software for any purpose. It is provided
+ // "as is" without any expressed or implied warranty.
+ //
+ // Jan Andersson, Torpa Konsult AB
+ // ja...@to... - 1993-08-29
+ //
+
+
+ #include <ComGlyph/comtextview.h>
+ #include <IVGlyph/textbuff.h>
+ #include <IVGlyph/texteditor.h>
+ #include <InterViews/event.h>
+ #include <ComTerp/comterpserv.h>
+ #include <ComTerp/comvalue.h>
+ #include <ctype.h>
+ #include <iostream.h>
+ #include <strstream.h>
+
+ #define XK_MISCELLANY /* to get the keysym's we need */
+ #include <X11/keysymdef.h>
+
+ // Note: Sun-specific keyboard symbols
+ static TE_ViewKeySymInfo default_key_sym_map[] = {
+ { XK_Down, &TE_View::down },
+ { XK_Up, &TE_View::up },
+ { XK_Left, &TE_View::left },
+ { XK_Right, &TE_View::right },
+ { XK_BackSpace, &TE_View::delete_backward },
+ { XK_Delete, &TE_View::delete_backward },
+ { XK_Return, (TE_ViewKeyFunc)&ComTE_View::newline },
+ { XK_Linefeed, (TE_ViewKeyFunc)&ComTE_View::newline },
+ { XK_KP_Enter, (TE_ViewKeyFunc)&ComTE_View::newline },
+ { XK_R9, &TE_View::page_up }, // PgUp
+ { XK_R15, &TE_View::page_down }, // PgDn
+ { XK_L6, &TE_View::copy }, // Copy (L6)
+ { XK_L8, &TE_View::paste_buffer }, // Paste (L8)
+ { XK_L9, &TE_View::find_selection_forward }, // Find (L9)
+ { XK_L10, &TE_View::cut }, // Cut (L10)
+ { XK_R7, &TE_View::beginning_of_text }, // Home
+ { XK_R13, &TE_View::end_of_text }, // End
+ { 0, nil }
+ };
+
+ implementSelectionCallback(ComTE_View);
+ implementActionCallback(ComTE_View);
+
+ // TE View
+
+ ComTE_View::ComTE_View(Style* s, EivTextBuffer* te_buffer, int rows, int cols,
+ boolean active)
+ : TE_View(s, te_buffer, rows, cols, active)
+ {
+ _continuation = false;
+ _parendepth = 0;
+ }
+
+ ComTE_View::~ComTE_View()
+ {
+ }
+
+ void ComTE_View::keystroke(const Event& e)
+ {
+ if (active_) {
+ current_window_ = e.window();
+
+ // check if known key symbol
+ unsigned long keysym = e.keysym();
+ for (TE_ViewKeySymInfo* k = &default_key_sym_map[0];
+ k->keysym != 0; k++) {
+ if (keysym == k->keysym) {
+ TE_ViewKeyFunc f = k->func;
+ (this->*f)();
+ return;
+ }
+ }
+
+ // map event to key
+ signed char c;
+ if (e.mapkey((char *)&c, 1) == 0)
+ return;
+
+ // check if known key map
+ #ifndef __sgi /* avoid SGI gcc warning */
+ if (c >= 0) { // fix alt-V on linux/pc
+ #else
+ if (1) {
+ #endif
+ TE_ViewKeyFunc f = key_[c];
+ if (f != nil) {
+ (this->*f)();
+ return;
+ }
+ }
+
+ #ifndef __sgi /* avoid SGI gcc warning */
+ if (c >= 0 && (isspace(c) || !iscntrl(c)))
+ #else
+ if (isspace(c) || !iscntrl(c))
+ #endif
+ insert_char(c);
+ else
+ cerr << "Unknown character - ignored!\n";
+ }
+ }
+
+ void ComTE_View::newline()
+ {
+ beginning_of_line();
+ int mark = text_editor_->Dot();
+ end_of_line();
+ int dot = text_editor_->Dot();
+ int len = dot-mark;
+ char* buffer = new char [len+1];
+ te_buffer_->Copy(mark, buffer, len);
+ buffer[len] = '\0';
+
+ /* put newline in text editor */
+ insert_char('\n');
+
+ /* run this line through comterp */
+ boolean old_brief = comterp()->brief();
+ comterp()->brief(1);
+ cout << "\n" << comterp()->linenum()+1 << ": " << buffer << "\n";
+
+ /* strip # comments */
+ /* and keep track of paren depth at the same time */
+ boolean inquote = false;
+ char* bufptr = buffer;
+ while(*bufptr) {
+ if (!inquote && (*bufptr== '(' || *bufptr=='[' || *bufptr =='{'))
+ _parendepth++;
+ else if (!inquote && (*bufptr== ')' || *bufptr==']' || *bufptr =='}'))
+ _parendepth--;
+
+ if (!inquote && *bufptr=='#')
+ *bufptr = '\0';
+ else if (*bufptr=='"') {
+ if (inquote) {
+ if (*(bufptr-1)!= '\\') inquote = false;
+ } else
+ inquote = true;
+ }
+ ++bufptr;
+ }
+
+ /* check for trailing semi-colon that isn't in parens, and remove it */
+ bufptr = buffer + strlen(buffer) - 1;
+ if (!_parendepth) {
+ while(bufptr>=buffer) {
+ char ch = *bufptr;
+ if (ch==';') {
+ *bufptr=' ';
+ break;
+ } else if (!isspace(ch))
+ break;
+ bufptr--;
+ }
+ }
+
+ /* remove the "> " prompt if there was one */
+ bufptr = buffer;
+ if (_continuation) {
+ if (buffer[0]=='>') {
+ beginning_of_line();
+ backward_line();
+ delete_forward();
+ insert_char(' ');
+ bufptr++;
+ if (buffer[1]==' ') {
+ delete_forward();
+ insert_char(' ');
+ bufptr++;
+ }
+ }
+ forward_line();
+ end_of_line();
+ }
+
+ /* load and interpret if expression closed */
+ comterp()->load_string(bufptr);
+ int status = comterp()->ComTerp::run(false /* !once */);
+ comterp()->linenum()--;
+ ComValue result(comterp()->stack_top(1));
+ ostream* out = new strstream();
+ if (*comterp()->errmsg()) {
+ *out << comterp()->errmsg() << "\n";
+ cout << comterp()->errmsg() << "\n";
+ } else {
+ if (status==0) {
+ result.comterp(comterp());
+ *out << result << "\n";
+ _continuation = false;
+ _parendepth=0;
+ } else if (status==1) {
+ insert_string("> ", 2);
+ _continuation = true;
+ }
+ }
+ out->put('\0');
+ out->flush();
+ strstream* sout = (strstream*)out;
+ insert_string(sout->str(), strlen(sout->str()));
+ comterp()->brief(old_brief);
+ delete out;
+ delete buffer;
+ }
+
Index: ComGlyph/comtextview.h
diff -c /dev/null ComGlyph/comtextview.h:1.1
*** /dev/null Sat Feb 26 03:07:47 2000
--- src/ComGlyph/comtextview.h Sat Feb 26 03:07:46 2000
***************
*** 0 ****
--- 1,68 ----
+ /*
+ * Copyright (c) 2000 IET Inc
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * related documentation and data files for any purpose is hereby granted
+ * without fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the names of the copyright holders not
+ * be used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. The copyright holders
+ * make no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+ // layered on top of classes distributed with this license:
+ //
+ // Simple Text Editor Implementation
+ //
+ // Copyright (C) 1993 Ellemtel Telecommunication Systems Labratories
+ //
+ // Permission is granted to any individual or institution to use, copy,
+ // modify, and distribute this software, provided that this complete
+ // copyright and permission notice is maintained, intact, in all copies
+ // and supporting documentation.
+ //
+ // Ellemtel Telecommunication Systems Labratories make no representation
+ // of the suitability of this software for any purpose. It is provided
+ // "as is" without any expressed or implied warranty.
+ //
+ // Jan Andersson, Torpa Konsult AB
+ // ja...@to... - 1993-08-29
+ //
+
+ #ifndef comtextview_h
+ #define comtextview_h
+
+ #include <IVGlyph/textview.h>
+
+ class ComTerpServ;
+
+ class ComTE_View :public TE_View {
+ public:
+ ComTE_View(Style*, EivTextBuffer*, int rows, int cols, boolean active);
+ ~ComTE_View();
+
+ virtual void keystroke(const Event&);
+ void newline();
+ ComTerpServ* comterp() { return _comterp; }
+ void comterp(ComTerpServ* cterp) { _comterp = cterp; }
+ private:
+
+ ComTerpServ* _comterp;
+ boolean _continuation;
+ int _parendepth;
+ };
+
+ declareSelectionCallback(ComTE_View);
+ declareActionCallback(ComTE_View);
+
+ #endif
Index: ComUnidraw/comeditor.h
diff -c ComUnidraw/comeditor.h:1.1 ComUnidraw/comeditor.h:1.2
*** ComUnidraw/comeditor.h:1.1 Tue Jan 18 03:11:05 2000
--- src/ComUnidraw/comeditor.h Sat Feb 26 03:07:50 2000
***************
*** 49,55 ****
--- 49,59 ----
ComTerpServ* GetComTerp() { return _terp;}
// return pointer to associated ComTerp (always a ComTerpServ).
+ ComTerpServ* comterp() { return _terp;}
+ // return pointer to associated ComTerp (always a ComTerpServ).
void SetComTerp(ComTerpServ* terp) { _terp = terp;}
+ // set pointer to associated ComTerp (always a ComTerpServ).
+ void comterp(ComTerpServ* terp) { _terp = terp;}
// set pointer to associated ComTerp (always a ComTerpServ).
virtual void ExecuteCmd(Command* cmd);
Index: FrameUnidraw/framekit.c
diff -c FrameUnidraw/framekit.c:1.2 FrameUnidraw/framekit.c:1.3
*** FrameUnidraw/framekit.c:1.2 Wed Feb 23 04:27:54 2000
--- src/FrameUnidraw/framekit.c Sat Feb 26 03:07:52 2000
***************
*** 65,70 ****
--- 65,71 ----
#include <UniIdraw/idkybd.h>
+ #include <InterViews/box.h>
#include <InterViews/frame.h>
#include <InterViews/layout.h>
#include <InterViews/session.h>
***************
*** 74,80 ****
#include <InterViews/window.h>
#include <IV-look/kit.h>
#include <IV-look/mf_kit.h>
! #include <IVGlyph/textedit.h>
#include <OS/string.h>
--- 75,81 ----
#include <InterViews/window.h>
#include <IV-look/kit.h>
#include <IV-look/mf_kit.h>
! #include <ComGlyph/comtextedit.h>
#include <OS/string.h>
***************
*** 96,101 ****
--- 97,104 ----
FrameKit* FrameKit::_framekit = nil;
FrameKit::FrameKit () {
+ _set_button_flag = true;
+ _clr_button_flag = true;
}
FrameKit* FrameKit::Instance() {
***************
*** 178,215 ****
ed->GetKeyMap()->Execute(CODE_SELECT);
topbox->append(ed);
if (!bookgeom) {
! EivTextEditor* texteditor = new EivTextEditor(wk.style());
((FrameEditor*)ed)->_texteditor = texteditor;
! Button* set = wk.push_button("Set", new ActionCallback(FrameEditor)(
(FrameEditor*)ed, &FrameEditor::SetText
! ));
! Button* clear = wk.push_button("Clear", new ActionCallback(FrameEditor)(
(FrameEditor*)ed, &FrameEditor::ClearText
! ));
! topbox->append(
! wk.outset_frame(
! layout.hbox(
! layout.vcenter(
! layout.margin(
! layout.vbox(
! layout.hcenter(set),
! layout.vspace(10),
! layout.hcenter(clear)
! ),
! 10
! )
! ),
! layout.vcenter(texteditor)
! )
! )
! );
! topbox->append(
! wk.outset_frame(
! layout.hbox(
! layout.vcenter(mousedoc_observer)
! )
! )
! );
}
ManagedWindow* w = new ApplicationWindow(topbox);
--- 181,253 ----
ed->GetKeyMap()->Execute(CODE_SELECT);
topbox->append(ed);
if (!bookgeom) {
! boolean set_flag = ((FrameKit*)kit)->_set_button_flag;
! boolean clr_flag = ((FrameKit*)kit)->_clr_button_flag;
! EivTextEditor* texteditor = nil;
! if(!set_flag && !clr_flag) {
! texteditor = new ComTextEditor(wk.style(), ed->comterp());
! }
! else
! texteditor = new EivTextEditor(wk.style());
((FrameEditor*)ed)->_texteditor = texteditor;
! Button* set = set_flag ? wk.push_button("Set", new ActionCallback(FrameEditor)(
(FrameEditor*)ed, &FrameEditor::SetText
! )) : nil;
! Button* clear = clr_flag ? wk.push_button("Clear", new ActionCallback(FrameEditor)(
(FrameEditor*)ed, &FrameEditor::ClearText
! )) : nil;
! Glyph* buttonbox = nil;
! if (set && !clear) {
! buttonbox =
! layout.vbox(
! layout.hcenter(set));
! } else if (!set && clear) {
! buttonbox =
! layout.vbox(
! layout.hcenter(clear));
! } else if (set && clear) {
! buttonbox =
! layout.vbox(
! layout.hcenter(set),
! layout.vspace(10),
! layout.hcenter(clear)
! );
! }
! if (buttonbox) {
! topbox->append(
! wk.outset_frame(
! layout.hbox(
! layout.vcenter(
! layout.margin(
! buttonbox,
! 10
! )
! ),
! layout.vcenter(texteditor)
! )
! )
! );
! } else {
! topbox->append(
! wk.outset_frame(
! layout.hbox(
! layout.vcenter(
! layout.margin(
! layout.vbox(
! wk.label("type help"),
! layout.vspace(10),
! wk.label("to print"),
! layout.vspace(10),
! wk.label("info to stdout")
! ),
! 10
! )
! ),
! layout.vcenter(texteditor)
! )
! )
! );
! }
}
ManagedWindow* w = new ApplicationWindow(topbox);
Index: FrameUnidraw/framekit.h
diff -c FrameUnidraw/framekit.h:1.1 FrameUnidraw/framekit.h:1.2
*** FrameUnidraw/framekit.h:1.1 Tue Jan 18 03:11:16 2000
--- src/FrameUnidraw/framekit.h Sat Feb 26 03:07:52 2000
***************
*** 55,60 ****
--- 55,62 ----
static FrameKit* Instance();
protected:
static FrameKit* _framekit;
+ boolean _set_button_flag;
+ boolean _clr_button_flag;
};
#include <InterViews/action.h>
*** /dev/null Sat Feb 26 03:08:07 PST 2000
--- patches/ivtools-000226-johnston-027
*************** patches/ivtools-000226-johnston-027
*** 0 ****
--- 1 ----
+ ivtools-000226-johnston-027
|