1Edt - small footprint Wordstar clone for VT100 terminals 2Emt - small footprint Emacs clone for VT100 terminals 3Edx - small footprint Wordstar clone for the X Window system 4Emx - small footprint Emacs clone for the X Window system 5 6Version 1.01, June 19, 2002 7(C) 2002 Jean-Pierre Demailly <demailly@ujf-grenoble.fr> 8 9This package is derived from the Editor Kit edx-0.56 by Terry Loveall. 10Aside minor improvements of the editing routines (unlimited buffer size, 11left and right justification), it adds a variant of edx (aka emx) which uses 12Emacs bindings rather than Wordstar bindings. A compile switch also allows 13to produce edt/emt for VT100 consoles rather than for the X Window system. 14The editor engine is almost identical in all cases, provided by the 15routines contained in 'edit.c'. The programs just require the raw X11 16libraries (edx/emx), or the termcap library (edt/emt). 17 18Various compile options can be used to increase or reduce the feature set 19(see the Makefile for details). 20 21In particular, the standard compile options yield the possibility to use 22arbitrary key bindings, bound to Alt-? or Esc-!-?. They should 23be copied to /usr/share/edmtx/edxrc (resp. to /usr/share/edmtx/emxrc, etc) 24for a system wide installation, or in $HOME/.edxrc (resp. $HOME/.emxrc, etc). 25Check 'rc.example' to get an idea. 26 27============================================================================== 28 29Copy of original README of edx-0.56 by Terry Loveall 30---------------------------------------------------- 31 32Edx - an X wrapper around an ASCII terminal editor engine. 33Copyright (C) 2002, Terry Loveall, email: <loveall@qwest.net> 34This program is released into the public domain. 35 36THIS PROGRAM COMES WITH ABSOLUTELY NO WARRANTY OR BINARIES. COMPILE AND USE 37AT YOUR OWN RISK. 38 39To build: run 'make', copy the resulting binary named edx to some place in 40your path or run it in the build directory with './edx'. 41 42Please send any questions, bug fixes or improvements to the above email. 43------------------------------------------------------------------------ 44 45 ASCII Text Editor to X Conversion 46 and theory of operation 47 48The purpose of the edx.c/eeng.c package is a proof of concept for converting a 49'standard' ASCII terminal based text editor to the GUI X windows. 50 51Using a text editor as a native window application enables the user to have 52multiple applications open simultaneously on screen. Yet the available X text 53editors have always left something to be desired. Usually an incomplete or 54hostile UI coupled with one or more of the following: written in C++ 55preventing easy modification, over-sized binaries which are slow to load and 56respond or just plain buggy code. 57 58In the interest of attempting to alleviate some, if not all, of the above 59complaints, the edx text editor is presented. It is composed of two files: 60edx.c which provides the direct interface to X windows, and eeng.c which 61provides a relatively simple basic text editor engine. 62 63Edx.c description: 64 65The functions provided by edx.c are a generic set designed to provide all 66necessary functions that are not inherent to the text editor engine. 67 68Edx.c provides the basic X windows initialization code, character/mouse input, 69character/string output, cursor positioning, X clipboard selection and the 70main event driven executive loop. 71 72These are: 73 74Cursor: 75 76void gotoxy(int horz,int vert); 77void cursor_draw(unsigned long color); 78void draw_cursor(); 79void undraw_cursor(); 80 81Character: 82 83void drawstring(char *str, int len); 84void cputs(char *prntstr); 85int putch(char chr); 86void clreol(); 87void highvideo(); 88void lowvideo(); 89void clrscr(); 90 91Window support: 92 93void bell(); 94void update(); 95void sig_handler(int); 96void font_height(void); 97 98X clipboard selection 99 100int paste_primary(int win, int property, int Delete); 101int request_selection(int time); 102char *mrealloc(char *s, int len); 103void set_selection(); 104void send_selection(XSelectionRequestEvent * rq); 105void moveto(); 106void do_paste(); 107void do_select(int delete); 108 109App Initialization and execution: 110 111void init(int argc,char *argv[]); 112void handle_key(char *astr, int skey, int state); 113int main(int argc,char *argv[]); 114 115-------------------------- 116Terminal X app conversion: 117 118Converting an ASCII text editor, that runs in a terminal environment, to an 119event driven windowed GUI app is fairly straight forward in concept. 120 121The analysis results in a separation of functions into window dependent and 122window independent. 123 124For window dependent functions, analysis produces the following 6 categories: 125 1261. Window creation and application initialization. 1272. Executive loop and function dispatch. 1283. Window support. 1294. Character display 1305. Cursor management 1316. X clipboard/selection 132 133A potential 7th category, dialogs, is not included in X for the sake of 134program simplicity. Dialogs are presented and controlled in the context of the 135ASCII status bar by the editor engine. 136 1371. Window creation and application initialization: 138 139The function 'main(argc, argv)' is where window creation and initialization is 140controlled. The sequence is as follows: 141 142 disconnect from the console 143 144 call init: 145 open the display 146 setup to gracefully respond to exit requests from X 147 establish window manager hints data structure 148 setup font(s) 149 setup window dimensions 150 initialize clreol string to all blanks 151 create the only window 152 setup window hints 153 setup window class resource names 154 notify X on how to force the app to exit 155 specify accepted XEvent loop events 156 make the window real by mapping it 157 create the Graphic Context for drawing purposes 158 allocate required colors 159 apply colors to window 160 set the font 161 162 App init in main() 163 get command line options 164 open a (possibly) named file for editing 165 request/create WM_PROTOCOLS atom 166 set up the signal handler response 167 display the initial cursor 168 1692. Executive loop and function dispatch: 170 171At the successful completion of window creation and app initialization, 172execution enters the main() event loop, where requested events are decoded and 173dispatched to the appropriate functions. 174 175The event categories decoded are as follows: 176 177 Expose 178 MotionNotify 179 ButtonPress 180 Button1 181 Button2 182 Button3 183 ButtonRelease 184 Button1 185 Button2 186 Button3 187 KeyPress 188 ConfigureNotify 189 ClientMessage 190 DestroyNotify 191 192The four event categories of concern are ButtonPress, ButtonRelease, 193MotionNotify and KeyPress. 194 195The button and motion events call the editor functions which: 196 197 set the cursor position, 198 select text with highlights and 199 insert text from a buffer. 200 201KeyPress calls one of several key decoding functions that are mode specific in 202the text editor engine. These modes correspond to: 203 204 normal editor cursor and text input, 205 file and search string dialogs and 206 option settings. 207 2083. Window support: 209 210Window support amounts to only 5 functions that are broken out to improve 211readability. They are: 212 213 bell: make noise for incorrect input. 214 update: redraw the screen. 215 sig_handler: handle signal events from the OS. 216 font_height: calculate font height. 217 2184. Character display: 219 220 drawstring is the basic text output. 221 cputs outputs an ASCIIZ string. 222 putch just outputs one char. 223 lowvideo sets output to normal mode. 224 highvideo sets output to highligted mode. 225 clreol erases from the current output position to the right edge. 226 clrscr erases the entire window. 227 2285. Cursor management: 229 230 gotoxy positions the cursor relative to the upper left window corner. 231 cursor_draw draws a cursor at current location in the specified color. 232 draw_cursor draws a cursor in the foreground color. 233 undraw_cursor draws a cursor in the background color. 234 2356. X clipboard/selection: 236 237 mrealloc manages the buffer size for X selection 238 paste_primary sequentially feeds chars to handle_char for pasting 239 request_selection requests the current selection from XA_CUT_BUFFER0 if any 240 set_selection processes and sends the marked block to XA_CUT_BUFFER0 241 send_selection posts an event saying selection is available 242 moveto mouse support convenience function for multiple calls 243 do_paste paste function for both keyboard and mouse 244 do_select also for both keyboard and mouse 245 246------------------- 247Eeng.c description: 248 249Eeng.c provides window independent functions and is derived from a functional 250ASCII text editor in a non-windowed environment. Changes made to eeng.c amount 251to converting the following functions from loop form to single pass character 252decoding: 253 254main executive: 255 main_exec: dispatch ASCII characters and function keys for processing. 256 257all ASCII text dialogs: 258 file_save: file open/save/new. 259 goto_line: request specified line number to goto. 260 goto_col: request goto column in current line 261 goto_search: request string to search for. 262 goto_replace: request search string for search&replace operation. 263 replace_with: request replace string for search&replace operation. 264 ask_replace: confirm replacement (Y/N/Esc/!) for search&replace operation. 265 tab_size: request new tab size. 266 window_size: request new right margin for block reformat. 267 block_read: request file name to insert at current position. 268 block_write: request file name to write marked block to. 269 270select and set options: 271 show_mode: 272 273An additional change to the text dialogs was to use a generic string input 274with prompt format and a callback. The callback provides specific processing 275of the input string. 276 277The change to a windowed environment also required replacing all terminal I/O 278with equivalent X functions. This code did not change, but rather was replaced 279by the same named X functions. These functions are comprised of the X cursor 280and character groups. The major source difference was specifying function and 281control keys from <X11/keysymdef.h>. 282 283----------------------------- 284Basic eeng.c code structures: 285 286The center of the editor engine is the char* pointer 'line_start'. All 287operations center around it. cur_pos is calculated by 'line_start+x_offset'. 288Conversion from screen x co-ordinate is accomplished with 'get_tru'. Moving 289around within the text file always requires moving line_start and counting 290EOLs. 291 292Text display counts back 'y' number of lines to generate a complete screen in 293the function 'show_scr'. There, the left margin display offset 'lxo' is used 294to determine the start of each display line. lxo is primarily maintained by 295cursor_left and cursor_right functions. 296 297Text insertion and deletion is provided by the function 'file_resize', which, 298when destination address is greater than source, opens a gap for insert 299operations, or deletes when destination address is less than source. Undo 300recording basically monitors 'file_resize' plus a few special cases such as 301block_fill and others. 302 303Main program execution is controlled by the function 'main_exec' which is 304basically just a conditional state test to select the proper 'switch(key)' 305function from one of key_normal, key_control, ctrlk_key, ctrlq_key, func_key 306and key_alt. Each one of these decodes for a specific set of keys and the 307key state from the global key event data structure 'keve'. From there, the 308individual key functions are invoked. 309 310X windows just passes basic key values and keyboard state. The difference 311between an ASCII 'A' and a control 'A' is only in the bit indicating the 312control key is pressed. The bad part is the program has to decode this in 313order to respond reasonably. The good part is the program gets to decode this 314in order to respond reasonably and controls _all_ decoding. If you do not like 315the way edx operates you _can_ change it. 316 317Marked block operation is comprised of flag[BLK], the char pointer 'mk' and 318cur_pos. If flag[BLK] is set, only then can you have a marked block. 319 320File operations are basically treated as block operations, and do very 321conventional file I/O. 322 323External program execution: 324 325SYSTEM forks a new process to run '/bin/sh $@' 326gorun invokes a dialog to get a command line from the user to execute 327newedx invokes a new instance of edx 328mterm opens an rxvt terminal in the current directory 329 330For more detailed operation of the edx editor see the files 'MANUAL' and 331'eeng.c'. 332