Introduction

The Origin C integrated development environment is called Code Builder. To open Code Builder, click the Code Builder button [image] on the Origin Standard toolbar.

The workspace is the main organizational tool in Code Builder. Conceptually, the workspace is a container to help you organize your program files. The workspace contains four predefined folders named Project, System, Temporary, and User, each of which can contain program files (including source files, header files, LabTalk script files, and text files). Code Builder includes a Workspace window to help you organize and find files in the folders of your workspace.

When you first open Code Builder, a default workspace displays. To add new files to the workspace, click the New button [image]. To open existing files in the workspace, click the Open button [image]. Source files can be added to the workspace and/or opened (viewed) in the Code Builder Multiple Document Interface (MDI). Added files can be either opened or not opened in the MDI and opened files can be either added or not added to the workspace. Only those files opened in Code Builder can be edited and only files that have been added to the workspace appear in the Code Builder Workspace window. Of those added to the workspace, only the source files can be compiled and linked.

If you have opened a source file and you want to add it to the workspace:

  1. Activate the source file window in the MDI.

  2. Press CTRL+W or select File:Add to Workspace from the Code Builder menu

Note: Files added to the workspace through the Code Builder user interface are added to the User folder.

When Code Builder creates a new source file, it adds default contents including comments and an include directive:

#include <origin.h>

The Origin.h system header file contains include directives for many other Origin C system header files including all NAG header files. Including the Origin.h header file is required for programmatic access to internal Origin objects and is precompiled causing it to load and link very quickly. For these reasons, it is recommended that you include Origin.h in all your Origin C source files.

Note: To open the origin.h header file in the MDI, right-click on the line #include <origin.h> in the source file and then select Open "origin.h" from the shortcut menu. You can open any included file using this method as long as the include directive is not commented out.

To compile and link the functions that have been added to the workspace, click the Build button [image] on the Standard toolbar. If you encounter a compile error in the Output window, double-click on the error line to activate the source file and locate the error.

To test your Origin C function in Code Builder, you can call the function from the upper pane of Code Builder's LabTalk Console. For example, if your function definition is:

void test()

{

printf("hello world\n");

}

Then you would call your function by entering test in the upper pane of the LabTalk Console.

To save your current workspace with a specified name and path, select File:Save Workspace As. To open a saved workspace, select File:Open Workspace.


Working with Workspaces

When you first open Code Builder, a default workspace named Untitled.ocw loads.

To begin developing your program, you can add new [image] or open existing [image] source files, header files, LabTalk script files, and text files. You can save your changes as Untitled.ocw or you can save to a new workspace file name.

The Code Builder workspace is the main organizational tool for developing your programs and serves two primary functions:

  • The workspace folder structure organizes and facilitates easy access to your files. For more information see the section Navigating in the Workspace Using the Workspace Tree.

  • Only source files added to the workspace can be compiled and linked. To better understand this aspect of the Code Builder workspace, see Building the Workspace.

You can create different workspaces for each of your programs, or develop all your programs in the same workspace. Like an Origin project file, only one workspace can be open in Code Builder at a time.


Creating a New Workspace

To create a new workspace, select File:New Workspace. If a previous workspace is open, you will be asked if you want to save changes to that workspace. The new workspace that opens is named Untitled.ocw and is saved in the \OriginC subfolder.


Opening an Existing Workspace

To open an existing workspace, select File:Open Workspace. If you have made changes to your current workspace, you will be asked if you want to save the changes.


Navigating in the Workspace Using the Workspace Tree

Files added to the Project folder are automatically included inside the open Origin project file and are built whenever the Origin project file containing them is opened by Origin. Files in the Project folder are always available to be executed as long as the Origin project file containing them is opened. Files in the Project folder remain in the Project folder until they are dragged out into either the System or User folders, until they are removed using the Remove shortcut menu item, or until a new Origin project file (*.OPJ) is opened. Files in the Project folder remain even when a new Code Builder workspace is created or opened.

Files added to the System folder are automatically re-added to the workspace as system files when Origin or Code Builder starts and each time a new workspace is created or an existing workspace file is opened. Files in the System folder are always included in the workspace and any Origin C functions in system files are always available to be executed once the workspace has been built.

By default, the System folder contains several OriginLab source files including one named sys_utils.c. These files contain Origin C functions used by Origin itself and in general should not be removed from the System folder (in fact, sys_utils.c can physically not be removed). Users can specify their own source files as system files by dragging them from the Project, Temporary, or User folders into the System folder. Once added to the System folder, a file will remain in the System folder until the user drags (moves) the file out of the System folder or removes the file from the workspace using the Remove shortcut menu item. Files can also be designated as system files in the Origin.ini file but it is recommend that users add files into the System folder using the Code Builder interface.

Files can not be dragged or moved into the Temporary folder using the Code Builder interface; Files can only be added to the Temporary folder by calling the LabTalk method run.LoadOC or the Origin C method Project.FindFunction. The Temporary folder contains only those source files dynamically added to the workspace by the these two methods and is emptied whenever a new workspace file is opened. Files added to the Temporary folder are removed from the workspace when you close Origin or Code Builder and when you open a new or existing workspace file. Files can also be removed from the Temporary folder by dragging the file out of the Temporary folder or by removing the file from the workspace using the Remove shortcut menu item.

Files added to the workspace using the Code Builder interface are added to the User folder when:

  • A newly created source file is added to the Code Builder workspace (see Creating a New File and Adding it to the Workspace).

  • An existing source file is opened and added to the workspace (see Opening an Existing File and Adding it to the Workspace).

  • An opened file is added to the workspace (see Adding Open Files to the Workspace).

Users can also drag or move files into the User folder from the Project, Temporary, and System folders.

Files added to the User folder are removed from the workspace when you:

  • Open a new or existing workspace file.

  • Manually remove them using the Remove shortcut menu item.

  • Drag or move them into the System or Project folders.

A list of the files in the User folder can be saved to a workspace file (of type *.OCW) by saving the Code Builder workspace. The next time the saved workspace file is opened by Code Builder, all files listed in the workspace file are added and will appear in the User folder of the workspace. The path and file name of the workspace file currently open in Code Builder is always displayed just to the right of the User folder name. Also, when Code Builder is opened it always loads the last opened workspace file from the previous session of Code Builder.

See Saving a Workspace and Opening an Existing Workspace for more information on saving and opening a workspace.

Navigating in the Workspace Using the Workspace Tree

The Code Builder Workspace window is similar to Windows™ Explorer in that it is a tree-like tool designed to help you organize and find files added to the Code Builder workspace. The Code Builder Workspace window is opened by selecting the View:Workspace menu item in Code Builder. Each time a file is added to the Code Builder workspace an icon representing the file is added to one of four folders in the workspace tree. The four predefined workspace folders are named Project, System, Temporary, and User and are described more fully below. The workspace tree can be used to organize and navigate between the source, header, LabTalk script, and text files added to your workspace. For example, if you double-click on a file icon in the workspace tree it will open and activate the file in the Code Builder Multiple Document Interface (MDI).

To view the icons of files added to folders in the Code Builder Workspace window, click the [+] symbol next to the Project, System, Temporary, and User folders in the workspace tree. To collapse a branch of the workspace tree click the appropriate [–] symbol.

Each of the four predefined folders (Project, System, Temporary, and User) contain files added to the workspace by different means. Files in each of the four folders are also removed from the workspace by different Code Builder events making any Origin C functions they contain more or less readily available to be executed. Files in each of the four folders can be moved by dragging them to any other folder except files can not be dragged (moved) into the Temporary folder. Files can also be removed from the workspace by right-clicking on them in the tree and then selecting Remove from the shortcut menu.

Files added to the Project Folder

Files added to the System Folder

Files added to the Temporary Folder

Files added to the User Folder

For more information on when and how files in the Code Builder workspace are built, see Four Methods of Building the Code Builder Workspace.


Building a Workspace

Code Builder provides a build and rebuild option for building your workspace. Furthermore, you can exclude selected files from the build process.

To learn more, see Building the Workspace.


Saving a Workspace

To save the workspace, select File:Save Workspace As to specify a file name and path, or select File:Save if you have saved the workspace prior to your current changes. Workspace files have a .OCW extension. Only files added to User folder of the Code Builder workspace are saved in workspace files.

Note: The files that were opened in the MDI when you save and close a workspace will be open in the MDI when you re-open the workspace, assuming they are still located in the same path/file name.


Sharing a Workspace with Another Origin User

To share a workspace file including all the source, header, LabTalk script, and text files that have been added to the workspace, you cannot simply send your colleague the .OCW workspace file. This file contains links to your added files, not the actual files. Thus, to share a workspace you would need to send the workspace file and the individual files, and your colleague would then need to save the individual files using the same relative path to the workspace file. However, an easier method is to pack your workspace file and the added source, header, script, and text files into an Origin Pack file (*.OPK). Origin provides a dialog box (Tools:Pack/Unpack OPK Files) similar to the WinZip interface for selecting and packing files. Your colleague can then drag this single file onto their Origin program to "install" the workspace and related files.


Working with Files

You can open the following types of files in the Code Builder MDI. Each of these file types can also be added to your workspace. In addition, preprocessed source files of type *.OP can be added to the workspace (but not opened in Code Builder).

  • Source Files: Source files contain Origin C functions that, once compiled, can be called from Origin. Source files have either a .c or .cpp extension.

  • Header Files: Header files contain Origin C function prototypes and macro definitions. Header files have a .h extension.

  • LabTalk Script Files: LabTalk script files are text files containing sections of LabTalk script. LabTalk script files can be run from Origin. Additionally, LabTalk script files can call Origin C functions. LabTalk script files have a .ogs extension.

  • Text Files: Text files can be used to document programming notes. They can also be used for LabTalk script and initialization files. Text files have a .txt extension. There are two special types of text files:

    • Configuration files can define LabTalk variables, macros, and functions, as well as new menu commands. Configuration files have a .cnf extension. If you create a new configuration file in Code Builder, the default extension will be .txt. After creating the file, you can change the extension to .cnf from Windows Explorer.

    • Initialization files can preset a number of Origin options. (For an example, review the Origin.ini file located in your Origin folder.) Initialization files have a .ini extension. If you create a new initialization file in Code Builder, the default extension will be .txt. After creating the file, you can change the extension to .ini from Windows Explorer.

Creating a New File and Adding it to the Workspace

Customizing the Source File Template

Opening an Existing File and Adding it to the Workspace

Opening an Existing File without Adding it to the Workspace

Adding Open Files to the Workspace

Specifying Workspace Files as Project, System, Temporary, or User Files

Locating Files that Contain a Specified Character String

Navigating in Files Using the Workspace Tree

Activating Files in the MDI from the Workspace Window

Removing Files from the Workspace

Excluding Files from the Workspace


Creating a New File and Adding it to the Workspace

To create a new source, header, LabTalk script, or text file, click the New button [image] on the Standard toolbar or select File:New. This action opens the New File dialog box.

When creating a new source file, you have the option to add the file to your current workspace. You also have the option to create the new source file with default contents.

  • Only source files that have been added to the workspace can be compiled.

  • If you select the Fill with Default Contents check box, the new source file is created with the following text:

The Origin.h header file contains #include directives for many of the most commonly used Origin C system header files including all the NAG header files. Origin.h is a precompiled header file and consequently loads and links quickly. Including Origin.h is probably sufficient for most applications and is recommended. To be certain you are including the necessary header files for the Origin C functions you plan to call, open the Origin C Language Reference section of this help file and search for the function(s). For each function, the help topic lists the header file in which the function is prototyped.

Note: To open origin.h in the MDI, right-click on the line #include "origin.h" in the source file and then select Open "origin.h" from the shortcut menu. You can open any included header file using this procedure.

If you are creating a new header, LabTalk script, or text file, you do not have the option of automatically adding the file to the workspace. However, after the new file opens in the MDI, you can add the file to the workspace by selecting File:Add to Workspace.

When creating a new source or header file, the default folder is the \OriginC subfolder. The default folder for a LabTalk script or text file is the Origin folder. When creating your file, you can specify the default folder or a custom folder. This choice is mainly organizational, as you can always specify a path when referencing these files in your code.


Customizing the Source File Template

When you create a new source file, the New File dialog box provides a Fill with Default Contents check box. If you select this, the new source file includes starting comments and a #include directive for origin.h. The new source file is created by the default.c template located in the \OriginC subfolder. You can open, edit, and save this template file to customize the default contents of new source files.


Opening an Existing File and Adding it to the Workspace

To open a source, header, LabTalk script, or text file and add the file to the workspace:

either:

  1. Click the Open button [image] on the Standard toolbar or select the File:Open menu item.

  2. Check the Add to Workspace checkbox at the bottom of the Open dialog box.

  3. Select your file.

  4. Click Open.

or:

  1. Right-click on the Project, System, or User folder icons in the Workspace window and select Add Files from the shortcut menu.

  2. Check the Open Files checkbox at the bottom of the Add Files to Workspace dialog box to open the file in the MDI.

  3. Select your file.

  4. Click Open.

Adding files to the workspace provides the following programming advantages:

  • Files that are added to the workspace display as icons in the folders of the Workspace window. You can thus easily locate files and display them in the MDI.

  • Only source files that have been added to the workspace can be compiled.

  • In addition to loading and building workspaces from Code Builder, Origin provides a method to programmatically load and build a workspace. If you have functions that are coded in separate source files, but the source files are part of the same workspace file, you can programmatically load and build the workspace file and call the functions.


Opening an Existing File without Adding it to the Workspace

To open an existing source, header, LabTalk script, or text file without adding it to the workspace:

  1. Click the Open button [image] on the Standard toolbar or select File:Open.

  2. Clear the Add to Workspace check box at the bottom of the Open dialog box.

  3. Select your file and click Open.

You can also right-click on a #include preprocessor directive line in a source file opened in the MDI and select Open:FileName from the shortcut menu. For example, to open Origin.h in the MDI, right-click on the line #include "origin.h" in the source file and then select Open "origin.h" from the shortcut menu.

Note: Only source files that have been added to the workspace can be compiled.


Adding Open Files to the Workspace

To add a file that is already open in the MDI to the Code Builder workspace:

1. Make the file active in the MDI. (You can CTRL+TAB through the open files, select the file from the Window menu, or click on the file in the MDI.)

2. Once the file is active, select the File:Add to Workspace menu item or simultaneously press the CTRL+W keyboard keys.


Specifying Workspace Files as Project, System, Temporary, or User Files

Files added to the Code Builder workspace can be specified as Project, System, Temporary, or User files by moving them into their correspondingly named workspace folders. Each of the four predefined folders contain files added to the workspace by different means. Files in each of the four folders are also removed from the workspace by different Code Builder events making any Origin C functions they contain more or less readily available to be executed. Files in each of the four folders can be moved by dragging them to any other folder except files can not be dragged into the Temporary folder. Files can also be removed from the workspace by right-clicking on them in the tree and then selecting Remove from the shortcut menu.

Files added to the Project folder are automatically included inside the open Origin project file and are built whenever the Origin project file containing them is opened by Origin. Source files in the Project folder are always available to be executed as long as the Origin project file containing them is opened. Files in the Project folder remain in the Project folder until a new Origin project file (*.OPJ) is opened. Files in the Project folder remain even when a new Code Builder workspace is created or opened.

Files added to the System folder are automatically re-added to the workspace as system files when Origin or Code Builder starts and each time a new workspace is created or an existing workspace file is opened. Source files in the System folder are always included in the workspace and Origin C functions in system files are always available to be executed once the workspace has been built.

Files added to the Temporary folder are removed from the workspace when you close Origin or Code Builder and when you open a new or existing workspace file. Files can not be dragged or moved into the Temporary folder using the Code Builder interface; Files can only be added to the Temporary folder by calling the LabTalk method run.LoadOC or the Origin C method Project.FindFunction which dynamically add them to the workspace.

Files added to the workspace using the Code Builder interface are always added to the User folder. When a newly created source file is added to the Code Builder workspace, when an existing source file is opened and added to the workspace, and when an opened file is added to the workspace, the file is automatically added to the User folder. Files can only be manually removed from the User folder by dragging them into the System or Project folders or by right-clicking on them and selecting Remove from the shortcut menu.

For more information on the Project, System, Temporary, and User workspace folders, see Navigating in the Workspace Using the Workspace Tree. For more information on when and how files in the Code Builder workspace are built, see Four Methods of Building the Code Builder Workspace.


Locating Files that Contain a Specified Character String

To find files that contain a specified character string, select Edit:Find in Files or click the Find in Files button [image] on the Standard toolbar.

Type the desired search string in the Find What combo box. Code Builder retains your search string for future use. To access previous search strings, click the down arrow to open the Find What combo box.

  • To limit your search to instances of the string that are whole words, select the Match Whole Word Only. A whole word is a string that is surrounded by white space or punctuation, unless the string occurs at the start or end of a line. If Match Whole Word Only is cleared, the search finds all matches of the string.

  • To perform a case sensitive search, select Match Case.

  • To include subfolders in your search, select Look in Subfolders.

  • To omit comments from the search, select Skip Comments.

After you click Find, the search results are output to the Output window. If occurrences of the string were found, you can double-click on the line in the Output window to open the file. The line containing the search string will be marked.


Navigating in Files Using the Workspace Tree

After you compile the functions in a source file, you can display the function definitions, function declarations, classes, structures, and type definitions encountered during compilation in the workspace tree. To activate this display, right-click on a source file’s icon in the workspace window (use CTRL or SHIFT for multiple selection) and select Show:Type from the shortcut menu.

You can then double-click on the workspace icon for the function definition, function declaration, class, structure, or type definition to open the source file.

The source file is opened in the MDI and the cursor is positioned at the associated line of code.


Activating Files in the MDI from the Workspace Window

Files that have been added to the workspace have associated icons in the Workspace window. To open a file in the MDI, double-click on the associated icon in the workspace tree or right-click and select Open from the shortcut menu.

Note: The MDI is Code Builder's interface for viewing and editing source, header, LabTalk script, and text files. Files can be viewed in the MDI whether or not they are part of the workspace. Similarly, you can close a file in the MDI and its workspace status is not affected.


Removing Files from the Workspace

To remove a file from the workspace, select the source file icon in the workspace window (use CTRL or SHIFT for multiple selection) and press DEL or right-click and select Remove from the shortcut menu.

Note: When you remove a file from the workspace, the file still exists (for example, the .C source file).


Excluding Files from the Workspace

To keep a file part of the workspace but to exclude it from the build process, select the source file icon in the workspace window (use CTRL or SHIFT for multiple selection) and then right-click and select Set as Exclude from the shortcut menu.


Working with the Text Editor

Code Builder provides a text editor window for viewing, editing, and printing source, header, LabTalk script, and text files. When you open a file in Code Builder, the file opens in a new text editor window in the Multiple Document Interface (MDI) region of Code Builder.

The text editor window supports standard keyboard and mouse text selection and cursor control. You can also perform the following editing operations:

  • Cut, copy, paste, and delete text.

  • Undo and redo your editing actions.

  • Drag (copy) selected text between text editor windows.

  • Drag (move) selected text within a text editor window.

For information on managing files, see Working with Files.

Changing the Active Text Editor Window

Working with Multiple Views of the Same File

Customizing the Text Editor

Syntax Coloring

Searching for Text

Navigating in a File


Changing the Active Text Editor Window

To change the active text editor window when multiple windows are open in the MDI, perform one of the following operations:

  • Select the window from the Window menu.

  • Click on the window in the MDI.

  • Double-click on the file's icon in the workspace window tree (if the file has been added to the workspace).

  • Press CTRL+TAB to activate the next window or press CTRL+SHIFT+TAB to activate the previous window.


Working with Multiple Views of the Same File

If you have a lot of code in a single source file, you may want to view different sections of your code at the same time. To do this, perform one of the following operations:

  • To open a second instance of a file in a text editor window, activate the desired window in the MDI and then select Window:New Window. The first window is renamed with a :1 suffix (for example, MyFitFunctions.c:1). The second window is named with a :2 suffix (for example, MyFitFunctions.c:2). You can scroll each window independently. You can also edit either window. Changes you make to one window are reflected in the other.

  • You can horizontally split a window into two view panes. To do this, position the mouse pointer over the split box which is located above the arrow at the top of the window's vertical scroll bar. When the pointer changes to a double arrow, drag the split box down to create the second view pane. You can now make changes to your source file from either view pane.

  • You can also vertically split a window into two view panes. To do this, position the mouse pointer over the split box which is located to the left of the arrow at the left of the window's horizontal scroll bar. When the pointer changes to a double arrow, drag the split box to the right to create the second view pane. You can now make changes to your source file from either view pane.


Customizing the Text Editor

The following settings in the text editor can be customized:

  • Tabs and indents.

  • Font, font style, and font size.

(To learn how to customize the colors used for different elements of your code, see Syntax Coloring.)

Setting Tabs and Indents

By default, the text editor automatically indents your text depending on the previous lines of code. For example, if the previous line is an open brace {, the text editor will automatically indent the next line of code. To disable or enable the auto indent feature, select Tools:Options and then clear or select the Auto Indent check box.

To change the tab and indent size, select Tools:Options and then edit the Tab Width combo box. (To return to the default settings, select Tools:Reset Options.)

To show tabs (and spaces) in the text editor window, select View:Show Tabs and Spaces.

Setting the Font, Font Style, and Font Size

To set the font, font style, and font size for the text editor windows, select Tools:Options and then click the Font button. After making your selection from the Font, Font Style, and Size controls, the Sample view box displays a preview.

Note: To return to the default settings, select Tools:Reset Options.


Syntax Coloring

To make your code easier to read and edit, the text editor automatically displays different elements of your code using different colors.

  • To turn syntax coloring on and off, select Tools:Syntax Coloring Enabled. This menu command is checked when selected (on) and unchecked when not selected (off).

  • To customize the colors used for the different code elements, select Tools:Options.

Select the desired code element from the Colors list box and then select the new color from the lower drop-down list.

Note: To return the syntax coloring to the default settings, select Tools:Reset Options.


Searching for Text

Code Builder provides tools for searching for strings in the active MDI file or in multiple files.

To locate a string in the active MDI file:

  • Type your search string in the combo box located on the Search toolbar and press ENTER. The first found instance of the string becomes highlighted in the MDI window. Press ENTER again to highlight the next instance of the string. Continue this process.

  • For more control over the search process, open the Find or Replace dialog boxes.

    • To open the Find dialog box, click the Find button [image] on the Edit toolbar or select Edit:Search.

    • To open the Replace dialog box, click the Replace button [image] on the Edit toolbar or select Edit:Replace.

For both dialog boxes, type the desired search string in the Find What combo box. Code Builder retains your search string for future access. To access previous search strings, click the down arrow to open the Find What combo box.

To limit your search to instances of the string that are whole words, select the Match Whole Word Only check box. A whole word is a string that is surrounded by white space or punctuation, unless the string occurs at the start or end of a line. If the Match Whole Word Only check box is cleared, the search finds all matches of the string.

To perform a case sensitive search, select the Match Case check box.

The Find dialog box allows you to specify the search direction in the file (up or down from the current cursor location). The Replace dialog box allows you to replace strings in the currently selected text (there must be text highlighted for this option to be available) or in the entire file.

Searching for Text in Multiple Files

To find files that contain a specified character string, select Edit:Find in Files or click the Find in Files button [image] on the Standard toolbar. Both actions open the Find in Files dialog box. For more information, see Locating Files that Contain a Specified Character String.


Navigating in a File

Text editor windows support standard keyboard and mouse file navigation methods. In addition, you can navigate in a file using the following techniques:

Using Bookmarks

Bookmarks allow you to flag lines of code so that you can easily return to the line later. To set a bookmark, click in the desired line and then click the Toggle Bookmark button [image] on the Edit toolbar. Alternatively, click in the desired line and select Edit:Toggle Bookmark or right-click and select Toggle Bookmark. After you set a bookmark, a blue-filled rectangle displays in the margin for that line.

Click the Next Bookmark button [image] to go to the next bookmark in the file. Click the Previous Bookmark button [image] to go to the previous bookmark.

To remove a bookmark, click in the desired line and then re-click the Toggle Bookmark button. To remove all the bookmarks in the current file, click the Clear Bookmarks button [image] on the Edit toolbar.

Go to the Matching Brace

If the cursor is active before or after an opening or closing brace {}, bracket [], or parenthesis (), click the Go to Matching Brace button [image] on the Edit toolbar or select Edit:Go to Matching Brace to highlight the matching brace.

Using the Find Dialog Box

If you want to go to the section of your file that contains a specific string, enter your string in the search string combo box located on the Search toolbar or in the Find dialog box (click the Find button [image] on the Edit toolbar). For more information, see Searching for Text.

Using the Workspace Tree in the Workspace Window

For each compiled source file, you can activate the display of workspace tree icons for the function definitions, function declarations, classes, structures, and type definitions encountered during compilation. This display feature is available from the source file's shortcut menu in the workspace tree.

You can then double-click on an icon in the workspace tree (for example, a function definition) to go to the respective location in the source file. For more information, see Navigating in Files Using the Workspace Tree.


Origin C Compiler

You can compile and link (build) your program automatically when you open an Origin project file, automatically when Origin starts, programmatically from LabTalk scripts or Origin C functions, and manually from within Code Builder. During the development of your program, you will most likely compile your functions manually from within Code Builder so that you can easily fix compile time errors and debug logic errors.

The following topics describe how to compile and link source files and how to build a workspace from within Code Builder. For information on automatically building source files when you open an Origin project file, on automatically building source files when Origin starts, and on programmatically building source files, see Four Methods of Building the Code Builder Workspace.

Note: Only source files that have been added to the Code Builder workspace can be compiled. To add an open source file to the Code Builder workspace, first make the source file is active in the MDI (for example, by pressing CTRL+TAB to activate the open files in sequence, by selecting the file from the Window menu, or by clicking on it in the Code Builder MDI). Once the source file is active in the MDI, select the File:Add to Workspace menu item or simultaneously press the CTRL+W keyboard keys.

Compiling Files

Stopping the Compiler

Building the Workspace


Compiling Files

To compile a source file from within Code Builder, perform one of the following operations:

  • Right-click on the file in the Workspace window and select Compile from the shortcut menu.

  • Select the file in the Workspace window and then click the Compile button [image] on the Standard toolbar.

To compile multiple files, select the desired files from the Workspace window and then perform one of the previous operations.

The compilation results are typed to the Output window. If an error message displays in the Output window, you can double-click on the message to go to the corresponding line of the source file in the Text Editor window.

Once you've compiled one or more source files, the source file's icon in the Workspace window displays a [+] next to it. You can click on this [+] to open the source file tree. This tree can display the function definitions, function declarations, classes, structures, and type definitions for the source file. This display is controlled from the source file icon's Show shortcut menu. For more information, see Navigating in Files Using the Workspace Tree.


Stopping the Compiler

To stop the compiler, perform one of the following operations:

  • Click the Stop button [image] on the Standard toolbar.

  • Select Tools:Stop Compile.

  • Press CTRL+BREAK.


Building the Workspace

To compile all the source files that have been added to the workspace and to perform linking, do one of the following:

  • Click the Build button [image] on the Standard toolbar.

  • Select Tools:Build.

  • Press SHIFT+F8.

If no files have changed since the last build, you will be notified of this in the Output window. In this case, you can force the compiler to rebuild by doing one of the following:

  • Click the Rebuild All button [image].

  • Select Tools:Rebuild All.

  • Press ALT+F8.

After building, the compiling and linking results are output to the Output window. If an error message displays in the Output window, you can double-click on the message to go to the corresponding line of the source file in the Text Editor window.

Once you've built the workspace, each source file's icon in the Workspace window displays a [+] next to it. You can click on this [+] to open the source file tree. This tree can display the function definitions, function declarations, classes, structures, and type definitions for the source file. This display is controlled from the source file icon's Show shortcut menu. For more information, see Navigating in Files Using the Workspace Tree.

To exclude a source file from the build process:

  1. Right-click on the source file's icon in the Workspace window and select Set as Exclude from the shortcut menu. The icon updates to display a red X on it ( [image] ).

Note: The workspace also has a Build on Startup option, available by right-clicking on the Workspace icon in the workspace window. This option controls whether or not the workspace will be rebuilt when you start an Origin session.

For more information on when and how files in the Code Builder workspace are built, see Four Methods of Building the Code Builder Workspace.


Debugger

Code Builder provides a number of methods for locating logic errors in your code. Before debugging the logic errors, you must correct any compile time errors and successfully compile your function(s).

The following topics explain how to use the debugging tools.

Setting and Removing Breakpoints

Starting the Debugger

Executing Code to a Specific Location

Stepping Into, Over, or Out of Functions

Monitoring the Value of a Variable

Stopping the Debugger


Setting and Removing Breakpoints

To locate logic errors in your program, you can step through your code by pausing execution at breakpoints and checking the values of variables.

To Set a Breakpoint:

  • Click in the line of code and do one of the following:

    • Press F9.

    • Select Debug:Toggle Breakpoints.

    • Click the Toggle Breakpoint button [image] on the Debug toolbar.

or

  • Right-click in the line of code and select Toggle Breakpoint from the shortcut menu.

You can set breakpoints in both debug and non-debug mode. After setting a breakpoint, a red circle displays in the left margin next to the line of code.

Note: The Enable Breakpoints button [image] on the Debug toolbar and the Debug:Enable Breakpoints menu command turn debug mode on or off. For more information, see Starting the Debugger.

Note: If the breakpoint displays as a hollow circle [image] , this indicates that the source file has not been added to the workspace. You must add the source file to the workspace before you can compile and debug it.

To Remove a Breakpoint:

  • Click in the line of code and do one of the following:

    • Press F9.

    • Select Debug:Toggle Breakpoints.

    • Click the Toggle Breakpoint button [image] on the Debug toolbar.

or

  • Right-click in the line of code and select Toggle Breakpoint from the shortcut menu.

You can remove breakpoints in both debug and non-debug mode.

To Remove all Breakpoints:

  • Select Debug:Clear All Breakpoints

  • Click the Clear Breakpoints button [image] on the Debug toolbar.


Starting the Debugger

To enter "debug mode" in Code Builder:

  1. Set one or more breakpoints in your function(s).

  2. Make sure that the Enable Breakpoints button [image] on the Debug toolbar (or the Debug:Enable Breakpoints menu command) is selected (this is the default state).

  3. Call your function from Code Builder's LabTalk Console or from Origin. For example, if your program starts by calling a function with the following function header:

void myFunc()

Then you would start debugging from the LabTalk Console by typing the following function call and pressing ENTER.

After you call your function, execution will proceed to the first breakpoint. You can also pause execution by pressing ESC or by selecting Debug:Break. After performing either of these actions, the cursor becomes active on the line where program execution paused.


Executing Code to a Specific Location

To debug your program up to a specific line in your source code, set a breakpoint at the line that you want to run up to (click in the line and press the F9 function key). Then begin debugging by doing the following:

  1. Make sure that the Enable Breakpoints button [image] on the Debug toolbar (or the Debug:Enable Breakpoints menu command) is selected.

  2. Call your function from Code Builder's LabTalk Console or from Origin.

The program will run up to the line containing the breakpoint.

  3. While still in Debug mode set another breakpoint (click in the line and press the F9 function key) several lines beneath the first breakpoint and then click the Go button [image] on the Debug toolbar again.

The program will run up to the line containing the second breakpoint.

To continue debugging, you can step through your code line by line by clicking the Step Into button [image] on the Debug toolbar (or by selecting the Debug:Step Into menu command). You can also step over or out of a function. See the next section for more information on the Step Into, Step Over, and Step Out buttons.


Stepping Into, Over, or Out of Functions

Stepping Into a Function

First, pause the program in debug mode at the function call line. To do this, do one of the following:

  • Set a breakpoint at the function call line.

  • Step through your code line by line until you reach the function call. While the program is paused at the function call line, click the Step Into button [image] on the Debug toolbar or select Debug:Step Into.

The debugger executes the function call statement and then pauses execution at the first line of the called function.

To continue executing your code one line at a time, click the Step Into [image] button.

Stepping Over a Function

The Step Into feature lets you step through a called function to check for logic errors in the function. However, you can also step over a called function. To do this, pause the code execution at the function call line that you want to step over (either by setting a breakpoint or by executing line by line up to the function call). While the program is paused at the function call line, click the Step Over button [image] on the Debug toolbar or select Debug:Step Over.

The debugger executes the function call and then pauses after the function returns.

Stepping Out of a Function

When execution is paused inside a function, you can click the Step Out button [image] on the Debug toolbar or select Debug:Step Out to step out of the function. The debugger executes the rest of the function without pausing, and then returns to the line after the function call and pauses.

Viewing the Function Calls and Going to a Function

If the function that you are calling to start your program contains calls to other functions, you can use the Call Stack window (View:Call Stack) to see the name of the function (and source code line number) that is currently executing as well as the functions that have been called but have not yet returned control to the calling function. When a function is called, it is added to the top of the Call Stack window. When a function returns control to the calling function, it is removed from the Call Stack window.

For example, in the following pseudo code:

void test1()

{

lines of code;

test2();

}

void test2()

{

lines of code;

test3();

return;

}

void test3()

{

lines of code;

return;

}

If you add a breakpoint in the test3 function and then start debugging the program, when program execution pauses in the test3 function, the Call Stack window will display the following call stack (where ## indicates the line number):

test3 line ##

test2 line ##

test1 line ##

To activate the cursor at a function call line in the source code, double-click on the respective function in the Call Stack window.


Monitoring the Value of a Variable

As you step through your code using breakpoints in debug mode, it is useful to monitor the value of variables to locate logic errors in your code. You can check a variable value by placing the mouse pointer over the variable in your source file. The current variable value displays in a pop-up box.

Additionally, Code Builder provides two windows to monitor variable values:

  • The Variables window

  • The Watch window.

Note: The Variables window only displays the values of variables having local scope and consequently does not display the values of LabTalk variables since they have global scope. However, the Watch window displays the values of variables having any scope and consequently does display the values of LabTalk variables.

The Variables Window

The Variables window (View:Local Variables) automatically displays all the variables for the current scope. As you step through the program in debug mode, the variable values update. Arrays, objects, and structures can be expanded in the window by clicking on the [+] box.

The Watch Window

The Watch window (View:Watch) allows you to specify which variables you want to watch the values of in debug mode. You can add and delete variables to the Watch window while in debug mode. You can also delete variables from the Watch window when you are not debugging a program.

Similar to the Variables window, the Watch window updates the variable values for the current scope as you step through the program in debug mode. Variables that are not in the current scope will show "Error" for their value.

Adding a Variable to the Watch Window

To specify a variable in the Watch window, first begin debugging. When program execution pauses (either at a breakpoint or at the current line if you pressed ESC), you can then add variables to the Watch window. To add a variable, double-click in the Name field just to the right of the horizontal line.

After double-clicking, a blank text box displays in the Name field with the cursor flashing. Type the variable name in this text box and press ENTER. After pressing ENTER, the variable name and its type display in the first line. A second line displays beneath your first variable. Repeat the process to add additional variables.

Removing a Variable from the Watch Window

To remove a variable from the Watch window, double-click on the variable name so that the name becomes highlighted in a text box. Press DEL and then press ENTER. This action deletes the variable from the Watch window. You can delete variables from this window independent of whether you are debugging.


Stopping the Debugger

To stop debugging your code, do one of the following:

  • Click the Stop Debugging button [image] on the Debug toolbar.

  • Select Debug:Stop Debugging from the Code Builder menu.


Debugging LabTalk Scripts

Most Code Builder debugging features work with LabTalk scripts the same as they do for Origin C code, with the condition that the script be saved in a text file of type *.OGS. Breakpoints can be set and cleared in LabTalk script and all Origin C Debug toolbar buttons work identically. In addition, the Debug toolbar has two buttons that only work for LabTalk script saved in text files of type *.OGS.

  • The Execute Current Section button [image] executes the current section of a script file. The current section is identified by highlighting the section name or by placing the cursor of the Code Builder text editor within the section name. If a breakpoint is set in the current section, debug mode is entered.

  • The Execute Selected Lines button [image] executes selected (highlighted) lines in a LabTalk script file but will not enter debug mode even if a breakpoint is encountered.

The Code Builder Local Variables window does not display LabTalk variables (LabTalk variables have global scope, not local) but the Watch window does display the values of all entered LabTalk variables including numeric, string, and system variables, section/macro arguments (e.g. %1), and even object properties.

Finally, the Code Builder Call Stack places and displays called script sections on the call stack along with Origin C function calls. The Code Builder Debugger seamlessly steps from sections of LabTalk script into Origin C code and back again.


LabTalk Console

The LabTalk console is a Code Builder window which is available for executing LabTalk script. Most often, you will use the LabTalk console to call your Origin C functions during the development process. To do this, type the LabTalk function call in the upper pane of the console. After pressing ENTER, the script is sent to the LabTalk interpreter and is executed. The output displays in the lower pane of the console.