Message: previous - next
Month: June 2018

Re: [Users] Slightly OT: The Thompson-Davis Editor

From: Leslie Turriff <jlturriff@...>
Date: Tue, 12 Jun 2018 12:53:56 -0500
On 2018-06-10 02:27:27 David C. Rankin wrote:
> On 06/09/2018 10:16 PM, Leslie Turriff wrote:
> > 	I'm using the source code for the open-source Thompson-Davis Editor
> > <>, "a simple, public domain, multi-file,
> > multi-window binary and text file editor written for IBM PCs and close
> > compatibles running DOS, Win32 (console) or Linux" to learn C and curses
> > programming.
> > 	You may have noticed its coincidental acronym :-) and yes, it stores
> > it's configuration information in $TDEHOME.  TDE is small but
> > non-trivial, and I think it will be a good resource for someone like me,
> > who is attempting to get a grip on programming in the *nix environment;
> > it's not so big as to be overwhelming, yet not as useless as
> > HelloWorld.c.
> > 	Thoughts?
> >
> > Leslie
> Leslie,
>   If you truly want to learn C, and you are looking for editors, you have
> two basic classes of editors you can use (both more than capable). Your
> choices are either traditional text-console/curses based (e.g. vim, emacs
> and what sounds like Thompson-Davis is), or you have your ui-toolkit based
> editors like kate, kwrite, geany ( or
> codeblocks (
>   Of the two, I prefer the ui-toolkit based editors, but I'm at home with
> vim as well. In the ui category -- you really cannot do better than
> kate/kwrite (and if you aren't smart enough to use TDE, then a geany or
> codeblocks work well).
>   For the text/curses based class, it's a preferences thing. vim, or emacs
> are both incredibly capable, though I find emacs a bit heavier than vim.
	Since my background is in the green-screen environment of IBM's mainframe 
computers, I prefer editors that don't require me to stop typing and use the 
mouse to perform certain operations, and I'm used to having actual commands 
(as opposed to ctlrl or alt sequences.  The editor I'm using today is Blair 
Thompson's X2, but it has some irritating bugs in the Unix version that 
haven't been addressed.  The worst problem I have with it is that I can't 
override the font size in the X Windows version, and I need a microscope to 
read its text.  Since Blair doesn't seem to be interested in fixing these 
minor issues, I've been looking for what I consider a suitable replacement 
for X2.
>   Learning C is one of the best choices you can make. Nothing else (aside
> from assembly) provides you the complete control over hardware as C does.
> However, working at the hardware level comes with great responsibility. You
> are responsible for memory management. One-byte too few and you walk off
> into the realm of Undefined Behavior. Leaning C, you learn to program and
> will be a better programmer as a result, regardless of which language you
> ultimately end up writing in.
	I tend to agree.  I started in the computer industry in the early '70s (long 
before PCs were thought of), so I know how to program, but not in C; my 
familiarity is with FORTRAN, COBOL and Rexx.  Finding useful examples of C 
code that I can use to get a comprehensive feel for the language is 
difficult; Hello World is so trivial as to be useless, and finding something 
that actually does useful work while being small enough to get my head around 
has been difficult.   Hopefully, with TDEditor I'll be able to kill two birds 
with one stone, learning to write C and producing a text editor that has the 
features I want.
>   The best advice anyone can give you in learning C is simply to slow-down.
> C is an exact language. Understand every declaration, the proper use of
> each library function and for God sake validate the return of every
> allocation and every I/O call. You don't digest the whole library at once.
> When you use a library function, open the man page -- read it -- pay
> careful attention to all parameter type, return types and the RETURN
> section of the page.
	C has a certain reputation as a language that makes it very easy for a 
neophyte programmer to shoot himself in the foot; I intend to be very 
careful. :-)
> (pay particular attention to the man page for the scanf family -- which
> provides no end of pitfall for the new C programmer who fails to learn the
> distinction between a *matching* and *input* failure and fails to
> understand that when either occur, no further characters are extracted from
> the input stream and are left unread -- just waiting to bite you on your
> next call)
>   When you are learning, forget an IDE, build your code on the command line
> so you actually learn what the compiler option are and how to correctly use
> them -- then you can properly use an IDE. Until you understand how to
> compile and link your code -- there is no way you can tell an IDE how to do
> it.
	When I learned to program there was no such thing as an IDE, and I've never 
found them particularly useful.  (When I started out, my IDE was an IBM 029 
keypunch machine.  The closest I got to an IDE on the mainframe was ISPF's 
PDF editor's ability to insert code snippets. :-) )
>   *Always* compile with *warnings enabled* and do not accept code until it
> compile cleanly, without warning. For gcc/clang that means adding -Wall
> -Wextra -pedantic (and I would add -Wshadow) to your command line. (clang
> also provides -Weverything). If you hop on a windoze box, the for VS
> (cl.exe) use /W3 (/Wall provides a great deal of non-code specific warnings
> that are a bit much).
	Okay.  I must note, though, that many of the packages that I've installed 
from source tarballs are liberally sprinkled with warnings, even though their 
authors presumably consider their code to be production quality.
	In TDEditor, for example, gcc complains about these two code snippets:

|            if (token == "User" ||
|                (parse_token( line, token ), stricmp( token, "User" )) == 0) 

in config.c produces

|	Compiling config.c
|	config.c: In function ‘process_menu’:
|	config.c:1988:23: warning: comparison with string literal results in 
unspecified behavior [-Waddress]
|	             if (token == "User" ||
|	                       ^

which makes some sense, though in the languages I'm familiar with such a 
construction's behaviour is well-defined; I would guess that defining "User" 
as a string constant would make the compiler happy?

|	static const char *fc, *fc2;

in pull.c produces
|	Compiling pull.c
|	pull.c: In function ‘make_menu’:
|	pull.c:835:25: warning: variable ‘fc2’ set but not used 
|	 static const char *fc, *fc2;
|	                         ^

which makes no sense at all, since

|	      fc2 = (frame < 3) ? fc : graphic_char[2];

certainly looks to me like it's being used.  I can see where C got that 
reputation. :-)

>   Finally, go get an account on -- seriously. If you have
> a C question -- it has probably already be answered 50 times over, and the
> answer peer-reviewed. (the same applies for just about any language, it is
> a fantastic site) Before you post a question you are expected to have
> searched for a similar one and taken the,
> visited and when posting
> always provide a (a minimal, complete
> and verifiable example -- meaning something those there can compile to
> verify your code behavior and help debug)
	I've used StackOverflow many times, though I don't have an account there.  
What's the advantage of having an account?
>   Learning C isn't something you'll do in a day, or a week, or month, or
>   year -- it is a journey -- enjoy the ride. 
	No kidding. :-)