edbrowse documentation

edbrowse Documentation, a User's Guide

Chapter 0, Contents

Chapter 1, Preface

Chapter 2, Quick Reference Guide

Chapter 3, The Editor

Chapter 4, Web Browser

Chapter 5, Javascript

Chapter 6, Edbrowse Scripts and the Configuration File

Chapter 7, Mail Client

Chapter 8, Database Access

Chapter 9, Other Command Line Utilities


Chapter 1, Preface

Maintainer

Chris Brannon chris@the-brannons.com

Author

Karl Dahlke eklhad@gmail.com.  Please see the wikipedia article for a history of edbrowse, and an overview of its features.

Copyright Notice

This program is copyright © Karl Dahlke (and other authors and contributors), 2000-2014.  It is made available by the authors under the terms of the GNU General Public License (GPL), as articulated by the Free Software Foundation.  It may be used for any purpose, and redistributed, provided this copyright notice is included.

Disclaimer

Edbrowse is provided as-is, with no implied warranty of fitness for any particular purpose.  It might trash your precious files.  It might send bad data across the Internet, causing you to buy a $37,000 elephant instead of $37 worth of printer supplies.  It may delete all the rows in your mysql customer table.  This is a spare-time project written by a couple of volunteers, that (understandably) cannot attain the quality and rigor of corporate or government software.  By using this program, you agree to use it as-is.

Acknowledgements

Chris Brannon wrote or modified at least 20% of the code, and provided valuable ideas for the overall design. He now maintains edbrowse.

Adam Thompson converted the javascript interface from C to C++, as required by Mozilla JS versions 2.4 and higher.  He has become a valuable member of the development team.

Jeremy O'Brien ported the software to Mac OS X.

Several people translated the output and error messages into other languages, and they are given due credit in the Languages section below.

Overview

This program is, at first glance, a reimplementation of /bin/ed.  In fact you might issue a few ed commands and not realize that you are actually running this program.  But as you proceed you will eventually discover some discrepancies, areas where edbrowse differs from ed.  These are discussed below.

Reinventing ed seems like a complete waste of time, until you realize that this program also acts as a browser - a browser embedded inside ed.  You can edit a URL as easily as a local file, and activate browse mode to render the html tags in a manner that is appropriate for a command-response program such as this.  In other words, we discard most of the formatting information and retain the links and fill-out forms.  This allows blind users to access the Internet through an application that is compatible with the linear nature of speech or braille.

If edbrowse is not included in your distribution, there is a perl version, with fewer features, that you can bring up right away on any computer: Linux, Unix, Mac, Windows, etc.  Give edbrowse.pl a try, and if you like it then you can git the package and build it from source to realize the full-featured C version.

If you are a Linux user, and your distribution doesn't package edbrowse, you can use the aforementioned perl version of course, but you can also run the full-featured C version, without going through the hassle of building it yourself.  Statically-linked executables for 32 bit and 64 bit architectures are maintained on the edbrowse home page.

This documentation assumes you are familiar with ed.  In fact it helps if you are fluent in ed.  Experience with internet browsers and the associated terminology is also helpful.

Other Languages

First, a few words about character sets (charsets).  English is easily contained within a byte stream, one letter per byte.  In fact, each letter fits in 7 bits; the eighth bit is not needed, and is set to 0.  This system is called ascii, and as you can see, it is English specific.

Indo-european languages bring in more characters, such as ñ (Spanish), è (French), and ö (German).  These can still fit within single bytes, by setting the eighth bit to 1, according to the ISO8859-1 standard.  Still other languages, such as Czech and Hungarian, fit within the iso8859-2 standard, which assigns different characters to the bytes above 127.  And there is iso8859-3, and so on.  Select your code page, and all the letters of your language still fit within one byte.  This is the iso8859 standard, and it is backward compatible with ascii.  In other words, z is 122 in ascii and in every iso8859-x code page, but the higher numbers, above 127, could represent different letters in different languages.

This worked well for a while, but what if you want to write one paragraph in French and one in Czech?  You either switch from iso8859-1 to iso8859-2 in mid stream, or we come up with a new standard that represents all letters in all languages simultaneously.  This charset, which obviously will not fit into a single byte, is known as utf8, and it has become the new standard across the computer industry.  Software does not have to select an iso8859 page and map numbers to letters in a manner that depends on the country you live in.  Instead, ñ is represented by two bytes, not one.  This is transparent to you; you see the same letter on the screen, and you hear the same sounds if your screen reader passes these letters to a speech synthesizer.  A quick way to tell which system you are on is to echo $LANG.  If it ends in utf8 or utf-8, and it probably will, then your console is using utf8, and it expects two-byte sequences.  Your files will contain these underlying sequences, and you probably aren't even aware of it.  Older pre-utf8 systems store each character in a single byte, with an iso8859 codepage doing the translation.

There's much more to say about charsets; this is merely a brief introduction.  I need not go further, because edbrowse only supports iso8859 ⇔ utf8 at this time.  Chinese, for example, requires 3 and 4 byte sequences, which map into unicode.  Edbrowse doesn't handle this level of complexity at this time.

The output and error messages, such as "search string not found", have been internationalized, so that edbrowse can support most European languages.  Set the environment variable LANG to interact with edbrowse in your home language.  Supported languages are shown below.  If you can translate edbrowse into additional languages, please let me know.

English: LANG=en (this is the default)

French: LANG=fr by Erwin Bliesenick including documentation

Brazilian Portuguese: LANG=pt_br by Cleverson Casarin Uliana

Polish: LANG=pl_pl by Wojciech Gac

When an output or error message is displayed, accented letters are printed using single bytes, vectoring through an iso8859 page, unless the string utf8 or utf-8 appears in $LANG, whence the nonascii characters are generated using utf8.  LANG=fr-FR.UTF-8 is a common setting in France.  Similarly, the contents of a buffer, be it a local document or an internet website, are displayed as single bytes or two-byte sequences, according to $LANG.  Bear in mind, utf8 has become the standard, and edbrowse may not display text or error messages through iso8859 for long.  In other words, iso8859 is deprecated.

If an older file is read into edbrowse, i.e. read into an empty buffer, and that file is in iso8859, while your computer is set to run in utf8, then that file is converted on the fly, before you ever see it.  Thus it will look normal to you.  If I did everything right, you shouldn't notice any difference.  (Use the iu command to disable this feature.)

When you write data out to the same file, e.g. if you have made some corrections or additions, I convert it back to its original single-byte iso8859 charset.  Thus you can send the edited file back to your friend, and it will be in his charset as he expects.  However, if you write the data, or any portion of that data, into a new file, I will leave it in the charset that is used by your computer.

These conversions should never take place on zip files, or executable files, or other forms of binary data.  If you see the words "converting to iso8859" or "converting to utf8", and the file is something other than international text, we have a problem.  Don't try to run the converted executable; it won't work.

If your world is utf8, the search function can lead to some confusion.  Consider the Spanish word niño, for a boy child.  If you search for ni.o, you may not find this line of text.  The dot stands for one character, and should match ñ, but this accented letter takes up two bytes.  Ironically, you have to search for ni..o, and you will find what you are looking for.  Needless to say, this is very confusing.

Search and substitute is performed by the pcre library, and fortunately for us, the latest version supports utf8.  I pass pcre an option that tells it to treat certain two-byte sequences as single letters, and it behaves the way you want it to.  Searching for ni.o works again.  If you want to disable utf8 search and substitute temporarily, use the su8 command.

Some websites offer their contents in multiple languages.  For example, twitter.com has an English version, a French version, and so forth.  It is possible to select the language when requesting the page.  Edbrowse supports this via the localizeweb keyword in its configuration file.  For instance, the following entry in .ebrc indicates that you want the French version, when it is available.

localizeweb = fr


Chapter 2, Quick Reference Guide

Quick Reference Guide

Here are the ed and edbrowse commands, all in one place.  This is a quick reference guide.  Most of these commands will not make sense until you read the rest of the documentation.

q: quit the current session
qt: quit the program completely, whether you've written your files or not
!command: shell escape
p: print the current line
4,7p: print lines 4 through 7
+3p: advance 3 lines and print
+3: same as +3p, print is default command
-: previous line
---: back up three lines
'a,'bp: print a range of lines, marked with labels a and b
kb: mark the current line as b
l: list the current line, showing invisible chars and end markers
eo: end markers off
el: show end markers ^$ when a line is listed
ep: show end markers when a line is listed or printed
lna: expand all nonascii chars into hex when a line is listed (toggle)
n: print the current line with its line number
z22: print the next 22 lines
z: print another 22 lines
=: print the number of lines in the file
X: make this the current line (a no-op)
s/x/y/: replace x with y on the current line
s/x/y: replace x with y and print the result
s//y/: use the last substitution string, in this case x
s/x/%/: use the last replacement string
s: repeat the previous substitute command
s/x/y/2: replace the second instance of x with y on the current line
4,7s/x/y/g: replace all instances of x with y on lines 4 through 7
/x/: look for the line containing x
/x: same as /x/
/x/i: look for the line containing x or X
?x?: look backwards for x
ci: searches and substitutions are case insensitive
cs: searches and substitutions are case sensitive
sg: substitution strings are global across sessions
sl: substitution strings are local to their sessions
su8: search and substitute uses utf8 character sequences (toggle)
lc: convert line to lower case
mc: convert line to mixed case
uc: convert line to upper case
s/x/uc: convert x to X on the current line
h: help, explain the last question mark
f: print the name of the current file
f foo: set the file name to foo
f/: retain only the lass component of the filename
e: print the number of the current session
e3: move to session 3
e foo: edit the file named foo
r foo: read the contents of foo into the current buffer
w foo: write the current buffer to foo
w+ foo: append to foo
w/: write to the lass component of the filename
d: delete the current line
1,$d: delete all the lines, 1 through eof
D: delete the current line and print the next line
dr: directory is readonly
dw: directory is writable, and d moves files to your trash bin
dx: directory is writable, and d deletes files
hf: show hidden files in directory listing (toggle)
u: undo the last command
i: insert text before the current line, end with a period
c: change the current line, enter a new block of text, end with period
a: add text after the current line, end with a period
a+: include the line you just typed in, when you thought you were in append mode
4,7m11: move lines 4 through 7 to line 11
4,7t11: copy lines 4 through 7 to line 11
3,4j: join lines 3 and 4 together
3,4J: join lines 3 and 4 together with a space between
g/x/ p: print every line that has an x
v/x/ p: print every line that does not have an x
B: find the line with the balancing brace
b: browse the current file, which is assumed to be in html
b foo.html: edit the file foo.html and browse it
b url: fetch url from the internet and browse it
ub: unbrowse a file
ft: show the title of the current web page
fd: show the description of the current web page
fk: show the keywords of the current web page
hr: http redirection (toggle)
js: allow javascript (toggle)
sr: send referrer (toggle)
fma: ftp mode active
fmp: ftp mode passive
rf: refresh the web page or directory listing
et: edit this web page as pure text
vs: verify ssl connections (toggle)
ua3: pretend to be the third user agent in your config file
g: go to the link on the current line
g2: go to the second link on the current line
^: the back key, go back to the web page you were looking at before
i=xyz: set the input field on the current line to xyz
i2=xyz: set the second input field on the current line to xyz
i2*: push the second button on the current line, usually submit or reset
i3?: describe the third input field on the current line
db: set debug level [0-7]
cd: change directory
bl: break line into sentences and phrases
bd: binary detection on files (toggle)
rl: use readline() on input (toggle)
pb: play buffer (audio)
iu: automatically convert between iso8859 and utf8 (toggle)
su8: search/substitute using utf8 (toggle)
ds=source,login,password: set the data source
sht: show tables
shc: show columns (and primary key) for the current table
shf: show foreign keys for the current table
fbc: fetch blob columns (toggle)
sm: send mail [account number]
re: reply to a mail message
rea: reply to all
ip: show referenced ip numbers, usually for saved mail messages
Tips for Avoiding Line Numbers If you're new to ed, you may find this program awkward.  I often receive complaints about line numbers.  People hate line numbers.  (Remember basic and fortran?)  They don't want to read the first page line by line, 1p 2p 3p 4p 5p etc.  Well I hate line numbers too, and I never use them.  Haven't for years.

If you just want to read the whole document, type ,p.  That works, if you use a command line speech adapter.  The whole document is in buffer, and you can read through it using the function keys on your adapter.  Now I realize most people still use screen readers, so this won't work.  Still, there's an easy way to step through screen by screen.  Start with 0z24 to get the first 24 lines.  Then the z command will give you the next 24, and the next 24, and so on.  You may want to use 22, or 23, or whatever makes sense relative to your screen.

Another approach is to simply hit return, again and again, and proceed line by line.

Once you are use to the regular expressions, you can jump to any part of the document, even a large document, in record time simply by searching for a unique text fragment.  This comes with practice.  Sometimes I guess wrong, and my search string is not unique.  I wind up somewhere else and have to search again.  This doesn't happen very often.  I usually get to the right place in one or two tries.

If you want to mark certain lines of text, please don't try to remember the line numbers.  Use the k command to mark them.  I usually use ka and kb to mark the start and end of a block of text, while kc marks the new location.  The move command is then 'a,'bm'c - with absolutely no line numbers.  This is standard ed fair, though most people never take advantage of it.

To look for links on a web page, search for the left brace.  Yes, you may stumble across a literal left brace in the text, but this doesn't happen very often.  You might access a particular link by typing /{Next}/g.  Similarly, you can look for input fields by searching for the less than sign.  This will make sense as you read about the representation of web pages below.  And of course, multiple operations can be scripted, a feature unique to this browser.

These are just some of the tips and tricks that will make you as fast and efficient as anybody using a screen editor or browser, provided you are familiar with the page.  My wife is always amazed at how quickly I can negotiate websites, or edit the common documents that we work on together.  However, you will never be faster than your sighted colleague when traveling through unfamiliar territory, no matter what system you use.  That is a pipe dream.

Mailing List

There is a mailing list for users of edbrowse and other command line utilities.  You can join by sending mail to commandline-subscribe@yahoogroups.com.


Chapter 3, The Editor

Important Deviations From /bin/ed

Certain search/substitute commands may behave differently under this editor.  This is because the regular expressions are interpreted by the perl compatible regular expression (pcre) library, rather than the traditional regexp library.  Hence regular expressions have more features, and more power, than the regular expressions employed by /bin/ed.  The syntax is also somewhat different.  For instance, perl uses bare parentheses where ed uses escaped braces -- to delimit sections of matched text.  And perl uses $1 ... $9 to reference the matched substrings, whereas ed uses \1 ... \9.  Also, perl supports the i suffix, for case insensitive search, along with the traditional g suffix for global substitute.  There is no reason to describe all the nuances here.  Please read the perlre man page `man perlre' for a full description of regular expressions under perl.  Once you are accustomed to their power and flexibility, you'll never go back to ed.

Great! You've read the perlre man page, and you're back.  Here are a few changes that I've made to perl regular expressions.  I have found that ( and ) are almost always meant to be literal, as in searching for myFunction(), so I reverse the sense of escaped parentheses in perl.  That is, ( and ) now match the literal characters, and \( and \) are used to demark substrings of the matched text.  These substrings are then referenced, in the replacement string, by $1 through $9.  Similarly, | means a literal |, and \| is alternation.  I also change the sense of &, on the right hand side, to mean what it means in ed.  I leave ^ $ . [ ] + * ? and {m,n} alone, to be interpreted by perl, as described in the perlre man page.  However, if * is the first character, it is treated as a literal star.  This makes sense, as there is no previous character to modify.  Some versions of ed do this, some don't.  I find it convenient; when I want to replace * + or ? I don't have to escape it just because it is a modifier.  Similarly, an open bracket by itself is treated as literal.  These changes to regular expressions, to look more like ed, may be confusing if you are a perl expert.  Sorry about that, but I think these changes make this editor easier to use for everyone, especially the experienced ed users.  Below are some additional differences between this program and /bin/ed.

Subsequent sections describe new and interesting features, completely foreign to ed.  These include the simultaneous edit of multiple files similar to emacs and vi, and the ability to browse an html file and edit its fill-out form.  That's why I wrote the program in the first place.

Balancing Braces

The capital B command is of interest to programmers, and will probably not be used by casual home users.  It locates the line with the balancing brace, parenthesis, or bracket.  Consider the following code fragment.

    if(x == 3 &&
    y == 7) {
        printf("hello\n");
    } else {
        printf("world\n");
        exit(1);
    }

The capital B command, on either the second or the last line, moves to the middle line "} else {", because that balances the open brace.  On the first line, B moves to the second line, which balances the open parenthesis.  The second line balances {, rather than ), because braces have precedence over parentheses, which have precedence over brackets.  You can force a parenthesis match by typing B), which moves from line 2 back to line 1.

The B command on the else line is ambiguous - I don't know whether to look backwards or forwards.  You must type B{ or B}.

You can explicitly balance <>, as in multiline html tags, or `', used in some preprocessors such as m4.

Comments or literal strings that contain balancing punctuation marks will definitely throw edbrowse off the track.  If you are the author of the source, you might want to avoid braces in comments, or use comments to keep braces in balance.

static char openstring[] = "{block"; /* closing } is found elsewhere */

Context Switch

This program allows you to edit multiple files at the same time, and transfer text between them.  This is similar to the world of virtual terminals (Linux), where you switch between sessions via alt-f1 through alt-f6.  In this case you switch to a different editing session via the commands e1 through e6.  Note that `e 2' edits a file whose name is "2", whereas `e2' (without the space) switches to session 2.  Similarly, you can read the contents of session 3 into the current buffer via r3, and you can write the current buffer into session 5 via w5.  The latter command will produce a warning if session five already exists, and you have made changes to its text, but have not saved those changes.  In other words, you are about to lose your edits in session 5.  Typing h will produce the explanation: "Expecting `w' on session 5".

If you quit a session you are moved to the next valid editing session, wrapping around to session 1 if necessary.  The program exits when the last session quits.

Warning, the program contains a bug regarding the undo command.  If you switch to another session, then switch back, you cannot undo your last edit.  You'd think this would be easy to fix, but it is trickier than it seems, so I haven't gotten around to it.  I just wanted you to know.  Make sure everything is copacetic before you switch to another session.

Let's run through a cut&paste example.  You are editing file foo in session 1, and you realize that a paragraph from file bar would fit perfectly right here.  Here is how it might look.  Lines beginning with < are the user's input, and lines beginning with > form the program's responses.  The # sign delimits my injected comments, which would not normally appear in the middle of a line.

< e2   # switch to session 2
> new session
#  Unlike ed, the r command does not establish a file name, even if the
#  buffer is empty.
#  Thus "r bar" is safer than "e bar".
#  The text is not linked to the file bar,
#  and we cannot accidentally corrupt this file.
#  After all, we don't want to change bar, we just want to steal from it.
< r bar
> 28719
< /start/
> This is the start of the cool paragraph that you want to copy.
< 1,-d  # don't need the stuff before it
< /end/
> This is the end of the cool paragraph that you want to copy.
< +,$d  # don't need the stuff after it
< e1
> foo
< r2
> 3279  # size of text read from session 2
< q2  # clean house, get rid of session 2
< w  # write foo, with the new paragraph included
> 62121

The following moves the data from one file to another.

< e2
> new session
< e bar  # this time I'm going to change bar
> 28719
< /start/
> This is the start of the cool paragraph that you want to move.
< ka  # mark the paragraph
< /end/
> This is the end of the cool paragraph that you want to move.
< kb
< 'a,'bw3
> 3279
< 'a,'bd
< w  # write bar, without the cool paragraph
> 25440
< q
> no file  # now in session 3
< e1
> foo  # back to session 1
< r3
> 3279
< q3  # quit session 3 remotely, while still in session 1
< w  # write foo, with the new paragraph included
> 62121

An e command, by itself, tells you the current session, in case you've forgotten.  This is similar to f, by itself, which tells you the current file.

Usage

type `edbrowse -h' to produce the usage message.  You will see the -f, -fm, and -m options used in several different ways; just ignore them for now.  These three options cause edbrowse to act as a mail retriever or interactive mail client.  This will be discussed later.

The -dx option sets the debug level to x, where x is between 0 and 9.  The default is -d1, which prints the sizes of files as they are written and read.  Some people like -d2, which prints the URLs as you jump to new web pages or submit forms online.  Unless you are debugging the program, you probably don't want to go any higher than -d3.  On rare occasions you might want to set -d4, to see the http headers in and out.  Remember, the debug level can be changed on the fly by using the dbx command (x between 0 and 9).

The -e option causes edbrowse to exit when it encounters an error.  This is usually used by batch scripts.  If there is a problem, you don't want to march on, executing the rest of the edbrowse commands.  Note that set -e has the same effect in a bash script.

Use -c to suppress processing of, and edit, the .ebrc configuration file.  This config file will be described later.  And why would you want to do this?  Suppose you have made a change to this file, and thereby produced a syntax error, so that edbrowse cannot even get started.  Now you can't use edbrowse to fix your config file.  Of course you could rename the config file to something else, fix it, and put it back; but then you might discover another syntax error, and so on.  Instead, use the -c option to edit the config file directly.  It is automatically loaded into buffer 1.  Note that -c must be the first option.

The arguments are the files to edit.  Edbrowse reads these files into corresponding sessions and starts you off in session 1.  If there are no arguments, you start in session 1, but there is no text and no associated file.

If you like this program, and you want it to be your primary editor, you can set the following Unix alias.

alias e="/usr/local/bin/edbrowse"

If you do this, you can use `e filename', to edit a new file, whether you are inside edbrowse or at the shell prompt.  Very convenient.

Binary Characters

At all times, even when entering a file name, this program scans its input for binary codes.  Use the three character sequence ~bd to enter the nonascii character 0xbd, which is the code for 1/2.  Similarly, if you list a line with lna active, the 1/2 character is displayed as ~bd.  All nonascii and most control characters are entered and displayed in this manner.  Tab and newline must be entered directly from the keyboard.  Tab and backspace are displayed as > and < respectively.  If the following line is entered,

Hello~07 ~x is ~bd of y

And then listed, you will see the very same text, but there is a bell and a 1/2 character inside.  The ~x is not encoded into anything, because x is not a hex digit.  If you want to force a ~, even though there are hex digits following, use two tildes, ~~.

Be careful however; the above example assumes iso8859, and as mentioned earlier, utf8 is the new standard.  The control g bell is stillllowinH3> A)%/: useware tcessibloghouse Some people likeou want it tel Use ed those cdbrowse 

aliasthe threelikeo,n usl is stateal from it. ew andthe 1/2 ch likeouals (Linu tel Useadboon courrt. ew alikeouudvneed nwse es a
sg: substitution stan chdimes is a bel(togg the fsg: subst .,+w andthe 7 # swazlopen parenthesis.Similar writelace eandthe 1/2 ch likeoualpen pribe new and intnever d will prritelaph that you want to copy. <. ew afe first rray; dgh thlces in bvoule sg: subsoiug regardnput, a

re the fiis easily ed, the 4IFr ni.o, yibe , whence a
sat you want to co

rinthesithe data any, le. <