ez—for the Programmer

In this article, Terry Gliedt continues his tour through the Andrew project and gives us a taste of another aspect of it. Here's the ez editor again, but this time as a source view editor for the programmer in us all.
Compiling Your Code

ez has support to assist you in finding compile errors. This is done by invoking make, capturing the output and then asking ez to show you the source lines in error. This is done by creating a second window of the source (select New Window on the Window menu card). In either of the source windows, select Start Compile on the Make menu card. You can see the results in Figure 6. When the compile completes and there are errors, select Next Error on the Make menu card. ez will then switch files to the offending file (if necessary) and show the line identified in error by the compiler. Correct the errors and start the process over again.

Figure 6a. Finding compile errors

Figure 6b.Compile errors

Code Analysis

Sometimes just having the editor format the source helps to understand the code. The first time I used ez on my C source, I immediately noticed that some code was shown as comments. “Ha! A bug in ez”, I thought. Well, there was a bug, but not in ez. I discovered I had missed an ending comment delimiter in a program that I thought was working. I actually had 10 lines of code commented out. That was enough to convince me of the value of views in ez.

Figure 7. Compressing lines in source program

ez is not a complete source browser in the sense of some commercial applications, but rather it provides a set of functions to help you to navigate through your source. Sometimes you don't want to see some parts of your program. Highlight that part of your program with the mouse and select Compress region on the Source Text menu card and you will see something like that shown in Figure 7. If you click in the “compressed lines” box, the code will be shown again. Selecting Decompress all on the Source Text menu card will expand all compressed source areas.

The program ctags is a program found on most Unix systems. It will generate a file called tags which contains cross-reference information on the functions within a set of source files. You can also get cross-reference information on variables by issuing the command “ctags -v *.h *.c”. ez can use this file to show you where functions or variables are defined. Load the tags file by selecting the menu item Load New Tag File or Rebuild Tag File on the Tags menu card. To find where a variable or function is defined, select the variable with your mouse and select Find Tag on the Tags menu card. ez will switch to the file where this is defined and show you the line where it is defined.

Templates

So far we have been talking about editing existing source files. ez provides additional support when you edit a new, non-existent source file, by providing a means for you to control a “template” or default file. Each language has its own template file which can be found in /usr/andrew/lib/tpls. You can tailor your own by creating your own template directory and telling AUIS applications where your templates are by defining the

TEMPLATEPATH environment variable. To set this up, issue the following commands:

mkdir $HOME/tpls
cp /usr/andrew/lib/tpls/c.tpl $HOME/tpls
export TEMPLATEPATH=${HOME}/tpls:/usr/andrew/lib/tpls   # For bash/ksh
setenv TEMPLATEPATH ${HOME}/tpls:/usr/andrew/lib/tpls   # For
csh/tcsh

Figure 8. Template for C language source file

Now you can edit your own $HOME/tpls/c.tpl template and tailor this to your needs. Figure 8 shows you one such template. What you will see is much like a conventional program source, and indeed, it is. This is where you put your own “boiler-plate”; code you'd want in most any program. More interesting, however, is the existence of dogtags (what's in a name?). These are fields, delimited with “<@” and “@>”, which are automatically substituted when the template is loaded. For instance in Figure 8, you see <@name@>, which is replaced with the name of the file being edited (fig1.c). Most of these are pretty obvious. For a complete list of all dogtags, see the help text shown by the command auishelp dogtags.

______________________

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix