View Full Version : Text editors?

January 1st, 2008, 09:19 AM
Has anybody here written a text editor before?

I'm thinking of doing a simple one for the kids to use on an old PC. I need something relatively 'friendly' for small kids to use, and none of my favorite old DOS text editors are suitable. This machine doesn't have a hard disk so a full blow word processor is not feasible either.

In my mind I'm thinking that each paragraph is represented by a string in memory, and the paragraphs are linked together by a linked list. This breaks the problem down a lot:

When rendering the screen, you walk the linked list and display each paragraph until you are past the end of the screen.
Editing is always done within a single paragraph. That makes operations like inserts feasible to do .. you are just adjusting that string, not the entire file.
Features like 'word wrap' wind up being implemented by the display routines. The contents of the paragraph remain unaffected by word wrap.

The downside to this approach is memory management. Using malloc and free naively could cause lots of fragmentation in memory. (There are lots of solutions to avoid this though.)

So, does anybody have experience with something like this?


January 1st, 2008, 11:16 AM
I haven't done the programming, but I remember the early 8-bit support magazines often having listings that could do exactly this sort of things.

There was one I played with published for the TRS-80 Mod 1. From what I remember, it was a small program which fitted in to 16k well. The big downside was that at various times the machine would just lock up for a while while memory "garbage collection" took place.

I don't remember details of the actual code unfortunately. Just that input was string by string (probaby an array).

January 1st, 2008, 12:12 PM
I have a very vague recollection of having tried to program a text editor like you're suggesting, but I can't remember when or why. I do know of some Basic word processors published as listings, but generally they're cumbersome to work with.

There ought to exist suitable text editors so you don't have to re-invent it unless you really are keen to do so. The full-screen EDIT in MS-DOS, perhaps the editor from Turbo Pascal and/or Norton Commander. DOS ports of Pico, Joe, whatever..

January 1st, 2008, 12:35 PM
You may have noticed from my TCP/IP project is that a lot of the joy is in doing it ...

I can't think of a text editor written in BASIC that would be suitable. I was thinking of something a bit faster, more than likely done in Turbo C++.

January 1st, 2008, 01:24 PM
There are DOS versions of Vi ;)

Yes, just joking :P

January 1st, 2008, 01:41 PM
I wrote a perfectly serviceable text editor in BASIC for the IBM PC/XT many years ago.

It was fairly limited, of course, but it worked well for its intended use and went into production. . .

The text contents were stored in a line-by array (in my case 72 columns by X rows as dictated by memory) and there were fairly simple routines for insert, delete, word wrap, etc.

Empty lines had a special character in the first cell. . .

There was, of course, no formatting or anything, but IIRC I had routines to load and save all or selected portions of text and implemented block copies and simple find/replace (these may have been added later. 25 years is a long time for my brain.)

I considered a rewrite in C at some point but had the same question(s) you do about memory allocation. I didn't want to do another full memory allocation version and I didn't quite know how I wanted to break up the text thereafter. (Lines, Paragraphs and "pages" were my considered options at the time with pages (fixed-length blocks of memory) being what I played with most before ditching the project.)

January 2nd, 2008, 01:24 AM
I recommend you create a boot disk with XtreePro on it, and get the kids to use the built in 1stWord word processor. It is very easy to use, very small, and therefore the whole lot should easily fit onto a floppy a boot/run quite quickly.


Terry Yager
January 4th, 2008, 06:39 PM
I've got an extra copy of Word* 3.3 you can have...


January 10th, 2008, 03:23 PM
Or PFS: Professional Write.

If you can get your hands on a copy, it will run from one floppy and is easy to learn and use.

Unless you just want to write your own editor, then have fun! :-)