Chapter 4. Using Source View

Source View is a simple text editor supplied in the CASEVision environment that displays the lines of text in a source code file. You can start Source View from most CASEVision tools by choosing the appropriate menu command, usually “Source View.” In some tools, you can double-click icons representing source code to start Source View. Source View displays the source code, scrolled to the appropriate place.

This chapter covers these topics:

Source View Window and Menus

The basic Source View window is shown in Figure 4-1 with its two standard menus displayed and major areas indicated.

Figure 4-1. The Source View Window


All Source View windows have these components:

menu bar 


always contains the File and Display menus.

display area 


contains the source code to be edited.

annotation column 


displays line numbers (if requested) and icons specific to particular CASEVision tools.

annotated scroll bar 


is different from a standard scroll bar in that it indicates all occurrences of a target string during a search and lets you scroll to an occurrence by clicking its indicator.

file specification field 


displays the current file and lets you change files.

source status indicator 


indicates Read Only, Editable, or Modified status.

The Source View menus and annotation margin icons vary depending on the tool from which Source View is accessed. For example, the Source View window executed from the CASEVision/WorkShop Debugger has margin annotations for traps and a program counter. and two additional menus: Traps and PC. The Source View window from Profiling View in the WorkShop Performance Analyzer displays usage statistics in the annotation margin.

File Menu

Figure 4-2. File Menu


The File menu (see Figure 4-2) provides these selections to deal with source code files:

“Open...” 


loads a source file.

“Save” 


records changes made to the source file. If the file comes up Read Only, you must first select the “Make Editable” item, also from this menu.

“Save As...” 


records changes made to the source file under a different filename.

“Save As Text...” 


records the information in the display area and annotation margin (including line numbers and performance statistics if displayed) as a text file.

“Open Separate...” 


lets you select another file from a file browser and opens a new Source View window containing that file.

“Insert File...” 


inserts the text of a file within your current file. By default, this selection is inactive (grayed-out) in the File menu when the buffer is Read Only. “Insert File...” is enabled when you click the “Make Editable” command.

“Clone” 


opens a duplicate Source View window containing the same file, in the same location as the original window.

“Fork Editor” 


starts your default editor on the current file. The default editor is determined by the editorCommand resource in the app-defaults file. The value of this resource defaults to wsh -c vi +%d, which means run vi in a wsh window and scroll to the current line. If the editor lets you specify a starting line, enter %d in the resource to indicate the new line number.

“Recompile” 


is functional only if you have installed CASEVision/WorkShop. It starts the Build Manager, a WorkShop tool that lets you compile the source code associated with the current executable.

“Make Editable”/“Make Read Only” 


toggles the source code displayed between writable and read-only states so that you can edit your code. “Make Editable” is the default selection because the source code is initially Read Only.

“Search...” 


searches for a literal or regular expression. Each instance of the target is marked by a search target indicator in the scroll trough area. Clicking an indicator with the middle mouse button scrolls Main View to the point.

“Go To Line...” 


lets you scroll to a position in the source code by specifying a line number or moving a slider. “Go To Line...” brings up a dialog box similar to the one shown in Figure 4-3.

Figure 4-3. Go To Line Dialog Box


You can enter a line number or use the slider at the top of the box to select a line number. You do not have to display line numbers to use this feature.

“Versioning” 


provides access to the configuration management tool, if you have designated one. The cvconfig script lets you designate CASEVision/ClearCase from SGI, RCS or SCCS. Simply type:

cvconfig [clearcase | rcs | sccs] 

Figure 4-4. ”Versioning” Submenu


The “Versioning” submenu appears in Figure 4-4.

Selecting any of these options displays a shell in which you can access the configuration management tool. The selections in the submenu are:

“Versioning”:“CheckIn” 


saves the source file and checks it into the database as a new version.

“Versioning”:“CheckOut” 


recalls the source file from the tool's database if you have the proper authority, locks it, and makes it editable.

“Versioning”:“UncheckOut” 


cancels the checkout, with no changes registered.

“Close” 


closes the Source View window.

Display Menu

Figure 4-5. Display menu


The Display menu in Main View (see Figure 4-5) provides these selections to annotate the source code displayed:

“Show Line Numbers”/“Hide Line Numbers” 


displays or hides line numbers corresponding to the source code to the left of the display area.

“Preferences...” 


displays a dialog box (see Figure 4-6) that shows or hides the icons from the other CASEVision tools: Parallel Analyzer (Loops button), Performance Analyzer (Performance button), and Tester (Test button).

Figure 4-6. Display Preferences Dialog Box


Source View Usage

To start Source View, choose “Source View” from the Views menu (if your current CASEVision tool does not have a Views menu, consult the appropriate user guide to find out how to access Source View). In most CASEVision graphical views, double-clicking a node (rectangle) displays a Source View window containing the selected code.

Some alternative methods for starting Source View from the CASEVision WorkShop tool are:

  • In the Performance Analyzer, clicking the Source button in the main window, double-clicking a node in Call Graph View, or double-clicking a call stack in Heap View all display Source View.

  • In the Static Analyzer, choosing “Edit Selected Item” from the Admin menu, or double-clicking an element in the Static Analyzer's main display brings up Source View.

Opening a Different File

When you start the Source View window from a CASEVision tool, Source View displays the source code selected from the parent tool. To access a different source code file, choose “Open...” from the File menu and make a selection from the File Browser.

You can also open a new file using the file specification field in the bottom left corner of the Source View window. Move the cursor into the area, type the new file's pathname, and press <Enter>. If you enter a filename that doesn't already exist, Source View creates a new file using that filename.

Viewing Source Code

The Source View window displays source code in its display area, the central area of the window. Use the scroll bar at the right to scroll through the lines of text. To see the full length of each line of code, drag any corner of the window out to increase the window width. If you're working with exceptionally long lines of code, or want to keep the Source View window small, you can add a horizontal scroll bar to the Source View window by adding the line

*textEdit.scrollHorizontal: True

to your .Xdefaults file before you start Source View. Deleting the line from .Xdefaults or changing True to False removes the horizontal scroll bar the next time you start Source View.

To view a specific line of code in Source View, choose “Go To Line...” from the File menu to open the Go To Line dialog box shown in Figure 4-3.

You can enter the line number in either of two ways:

  • Drag the slider in the top of the window to the desired line number.

  • Move the cursor into the Go to line field and type the line number you want.

Once you set the line number, either click the OK button or press <Enter> to close the window and jump to the line number in Source View's display area. If you click the Cancel button, you close the Go To Line dialog box without scrolling the text in the display area.

Using the Annotation Column

Source View can display more than just the text of a source code file. It displays additional information in its annotation margin, which you control through Display menu commands. If you choose “Show Line Numbers,” you'll see icons specific to the CASEVision tool. For example, Figure 4-7 shows a program counter at a stop trap, a stop trap, and a sample trap in a WorkShop Debugger Source View window.

Figure 4-7. Icons in the WorkShop Debugger Source View Window


By default, the annotation margin automatically shows icons. To hide the icons or the line numbers, choose either “Hide Icons” or “Hide Line Numbers” from the Display menu.

Searching for Text

To search for text in a source code file, choose “Search” from the File menu, which opens the Search dialog box (shown in Figure 4-8).

Figure 4-8. The Search Dialog Box


The Search dialog box provides a Search field where you can enter a target string. It also has a set of buttons that offers three search types:

Literal Case Sensitive 


finds all text that literally matches the search text and treats upper- and lowercase characters as different characters. For example, it matches “new” with “new”, but not with “New” or “NEW.”

Literal Case Insensitive 


finds all text that matches the search text literally and without regard to case. For example, it matches “new” with “New”, “new”, or “NEw.”

Regular Expression 


interprets the search text as a regular expression and finds text to match the expression. Regular expressions use special characters such as “*” and “[“ to construct wildcard strings for matching a range of text. You can find information about regular expression syntax in the man pages for ed; you'll find the same description in the On-Line Help card for Regular Expression.

To search for text, move the cursor into the Search field and enter the search text; then click the search option you want if it's not already set. Press <Enter> or click the Apply button to start the search. Source View searches through the entire file for matching text and indicates matches by highlighting the text where they occur. To show you where matches occur throughout the file, Source View displays search target indicators along the length of the scroll bar as shown in Figure 4-8. To scroll to a match, either click the indicator with the middle mouse button or drag the scroll handle to it. If a search is unsuccessful, no search target indicators appear on the scroll bar.

Figure 4-9. Search Target Indicators


Each time you press <Enter> or click Apply, Source View removes any existing search highlighting and indicators and adds new highlighting and indicators as the result of the new search. To clear highlights and indicators without starting a new search, click the Reset button, which clears the search text from the Search text area and removes highlights and indicators.

To close the Search window, click on either the Cancel or the Close button. Cancel closes the window and removes any highlighting and indicators left in the display area by the last search. Close closes the window and leaves highlighting and indicators in place.

Editing Text

A source code file viewed in Source View has one of the two modifiable statuses: Read Only or Editable. When the status is Read Only, you can't edit the source code file. When the status is Editable, you can edit text and make changes to the source code file. The source status indicator, located below the display area on the right side of the window, shows the status of the current source code file. It also displays Modified if you've made changes to the source code that haven't yet been saved

Generally, when you start Source View from a CASEVision tool, it displays the source code involved in the session, set to Read Only. To change the write status, choose “Make Editable” from the File menu. To change a file from Editable back to Read Only, choose “Make Read Only” from the File menu.

Editing text in an editable file follows typical text editing conventions. To select a block of text, drag from the beginning to the end of the text you want. To select a word, double-click the word. To select a line, triple-click the line.

Once you've selected text, you can delete it by pressing <Back Space>. If you type new characters while text is selected, you replace the selected text with the new text. To copy selected text to another location, move the cursor to the new location and middle-click. As long as the original text is selected, you can keep middle-clicking to insert copies of it into new locations.

To insert new text in the display area, click at the insertion point, then type new text. You can press the <Back Space> key to delete characters to the left of the insertion point.

If you want to insert an entire file as new text, click on the point where you want to insert, then choose “Insert File...” from the File menu. A file browser opens, where you can choose the file you want to insert. When you click OK to close the browser and load the file, Source View inserts the text of the file at the insertion point in the existing file.

Saving a Modified File

Once you've made changes to a source code file, you can save them using any of three commands in the File menu:

“Save” 


saves the modified file to the filename displayed in the file specification field in the bottom left corner of the Source View window.

“Save As...” 


opens a File Browser which lets you enter a new filename and save the modified file under that name.

“Save As Text...” 


also opens a File Browser in which you can enter a new filename and save the modified file under that name. The difference between this command and “Save As...” is that “Save As Text...” also saves line numbers if they're displayed and any text in the annotation margin of the display area, such as Performance Analyzer statistics.

Using an Alternate Text Editor

If you'd rather edit a source code file using a text editor other than Source View, choose “Fork Editor” from the File menu. By default, this command opens a new shell that runs vi and works on the file in Source View. To set up Source View so that it uses a different editor when you choose “Fork Editor,” add a line to the .Xdefaults file:

*editorCommand: <editor>

where <editor> is the text editor you wish to start. The default is

*editorCommand: xwsh -e vi +%d

which opens an X shell, executes vi using the current file as its target, and scrolls to the line number supplied after %d if there is one. You might try

*editorCommand: gnuemacs +%d 

or even

*editorCommand: jot

if you want to edit using either gnuemacs or jot.

Working with Multiple Source View Windows

Source View allows you to open other Source View windows by choosing either “Clone” or “Open Separate...” in the File menu. “Clone” opens a Source View window that displays the same file in the same location that you're viewing in the original window. “Open Separate...” opens a file browser where you can choose another source code file, and then opens a Source View window that displays the newly chosen file.

If you've started Source View from another CASEVision tool, such as the WorkShop Debugger or Static Analyzer, then it may display traps or search target indicators created by the parent tool. When you clone a Source View window showing this additional information, the information also appears in the cloned Source View window. Whenever you change a trap or work with the program counter in one of the cloned Source View windows, the trap and PC icons in the other Source View windows are updated to match.

Editing changes or viewpoint changes in one cloned Source View window aren't reflected, however, in other clones. When you scroll to a new location or change the text in one window, those changes don't appear in the other windows. Source View does provide a safeguard, though, and announces changes made to a file by one window with messages about the change that appear in the cloned windows.

Quitting Source View

To quit Source View, choose “Close” from the File menu.