home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1991-03-01 | 133.6 KB | 2,876 lines
%@1@%%@AB@%Microsoft C - Installing and Using the Professional Development System%@AE@%%@EH@%%@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% %@AB@%Microsoft (R) C - Installing and Using the Professional Development System%@AE@%%@NL@% %@NL@% %@AB@%FOR MS (R) OS/2 AND MS-DOS (R) %@AB@%%@AB@%%@AE@%%@AI@%OPERATING SYSTEMS%@AE@%%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% %@NL@% %@NL@% MICROSOFT CORPORATION %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@%%@NL@% %@NL@% Information in this document is subject to change without notice and does not represent a commitment on the part of Microsoft Corporation. The software described in this document is furnished under a license agreement or nondisclosure agreement. The software may be used or copied only in accordance with the terms of the agreement. It is against the law to copy the software on any medium except as specifically allowed in the license or nondisclosure agreement. No part of this manual may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying and recording, for any purpose without the express written permission of Microsoft. (C) Copyright Microsoft Corporation, 1990. All rights reserved.%@NL@% %@NL@% Printed and bound in the United States of America.%@NL@% %@NL@% Microsoft, MS, MS-DOS, and CodeView are registered trademarks and Windows is a trademark of Microsoft Corporation.%@NL@% %@NL@% 386-Max is a trademark of Qualitas, Inc.%@NL@% %@NL@% BRIEF is a registered trademark of UnderWare, Inc.%@NL@% %@NL@% IBM is a registered trademark of International Business Machines Corporation.%@NL@% %@NL@% UNIX is a registered trademark of American Telephone and Telegraph Company.%@NL@% %@NL@% %@NL@% %@NL@% Document No. LN06516-1189 OEMO711-6Z 10 9 8 7 6 5 4 3 2 1 %@AI@%%@AE@%%@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@AB@%Chapter 1%@AE@%%@BO: 16ba@% %@AB@%The Microsoft(R) C Professional Development System%@AE@%%@NL@% %@NL@% Before You Proceed%@BO: 20f6@%%@NL@% System Requirements%@BO: 21e8@%%@NL@% Package Contents%@BO: 264d@%%@NL@% Features New to Version 6.0%@BO: 3112@%%@NL@% Why Microsoft Programmer's WorkBench?%@BO: 3876@%%@NL@% %@NL@% %@AB@%Chapter 2%@AE@%%@BO: 4787@% %@AB@%Installing Microsoft C%@AE@%%@NL@% %@NL@% Running SETUP%@BO: 4e18@%%@NL@% Supplying SETUP Information%@BO: 5047@%%@NL@% Correcting Mistakes%@BO: 5492@%%@NL@% First Screen: Installing Libraries%@BO: 5748@%%@NL@% Second Screen: Installing Additional Files%@BO: 6ebf@%%@NL@% Third Screen: Specifying Directories%@BO: 7314@%%@NL@% Checking Available Disk Space%@BO: 7727@%%@NL@% SETUP Options%@BO: 7a72@%%@NL@% Configuring Your System%@BO: 7de7@%%@NL@% Choosing a Target Operating Environment%@BO: 9028@%%@NL@% Configuring Extended Memory for CodeView%@BO: 9e86@%%@NL@% Customizing Microsoft C%@BO: a92e@%%@NL@% %@NL@% %@AB@%Chapter 3%@AE@%%@BO: abd9@% %@AB@%Using the Programmer's WorkBench%@AE@%%@NL@% %@NL@% Starting PWB%@BO: b3c3@%%@NL@% Specifying a Source File%@BO: b5c3@%%@NL@% Command-Line Options%@BO: b749@%%@NL@% Using Windows and Menus%@BO: be47@%%@NL@% Windows%@BO: c121@%%@NL@% Menus%@BO: cc8d@%%@NL@% Dialog Boxes%@BO: ef99@%%@NL@% Getting Help%@BO: fd1c@%%@NL@% Using the Editor%@BO: 103e2@%%@NL@% Moving Around in a Source File%@BO: 104f6@%%@NL@% Customizing the Editor%@BO: 12315@%%@NL@% Compiling and Linking%@BO: 1382c@%%@NL@% Building Programs in PWB%@BO: 13cc4@%%@NL@% Compiling and Linking from the Command Line%@BO: 166cb@%%@NL@% Debugging Programs%@BO: 16f56@%%@NL@% Using the Browser%@BO: 1764e@%%@NL@% Debugging with CodeView%@BO: 182a9@%%@NL@% Running IO.C%@BO: 1a763@%%@NL@% Debugging IO.C%@BO: 1b0a7@%%@NL@% Getting More Details%@BO: 1b456@%%@NL@% %@NL@% %@AB@%Chapter 4%@AE@%%@BO: 1b748@% %@AB@%Using the On-Line Reference%@AE@%%@NL@% %@NL@% Structure of the Microsoft Advisor%@BO: 1bb8e@%%@NL@% Navigating Through the Microsoft Advisor%@BO: 1beb7@%%@NL@% Using the Help Menu%@BO: 1c180@%%@NL@% Using the F1 Key%@BO: 1c82d@%%@NL@% Using Hyperlinks%@BO: 1cd2a@%%@NL@% Using Help Windows and Dialog Boxes%@BO: 1d640@%%@NL@% Accessing Different Types of Information%@BO: 1ec73@%%@NL@% Specifying Temporary Help Files%@BO: 1f973@%%@NL@% Using QuickHelp%@BO: 1fbf6@%%@NL@% Using the /HELP Switch%@BO: 1fefc@%%@NL@% Using the QH Command%@BO: 20078@%%@NL@% %@NL@% %@NL@% %@NL@% %@CR:C6A00010001 @%%@1@%%@AB@%Chapter 1 The Microsoft(R) C Professional Development System%@AE@%%@EH@%%@NL@% %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@% %@NL@% The Microsoft C Professional Development System is a collection of tools designed to increase DOS and OS/2 programming efficiency. The system offers %@NL@% %@NL@% %@NL@% ■ A customizable editor that is capable of being extended%@NL@% %@NL@% ■ An optimizing and incremental compiler%@NL@% %@NL@% ■ An intelligent linker%@NL@% %@NL@% ■ A project-oriented Make utility%@NL@% %@NL@% ■ A source-level browser%@NL@% %@NL@% ■ A complete on-line reference system%@NL@% %@NL@% ■ A source-level, window-oriented debugger %@NL@% %@NL@% %@NL@% The Programmer's WorkBench (PWB) integrates these tools, creating an environment in which you can edit, compile, link, and debug your programs. %@NL@% %@NL@% This book is a general introduction to the Microsoft C Professional Development System. This chapter introduces some of the features of the Professional Development System. Chapter 2 describes how to install the Professional Development System. Chapter 3 introduces the Programmer's WorkBench. Chapter 4 shows how to use the on-line reference system─a complete reference to the Professional Development System and the C language, which is available both within PWB and at the OS/2 and DOS command lines. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%Microsoft documentation uses the term "OS/2" to refer to the OS/2 systems─ %@AI@%Microsoft Operating System/2 (MS%@AI@%(R)%@AE@%%@AI@% OS/2) and IBM%@AE@%%@AI@%(R)%@AE@%%@AI@% %@AE@%%@AI@% OS/2. Similarly, the %@AI@%term "DOS" refers to both the MS-DOS%@AE@%%@AI@%(R)%@AE@%%@AI@% and IBM Personal Computer DOS %@AI@%operating systems. The name of a specific operating system is used when it %@AI@%is necessary to note features that are unique to the system.%@AE@%%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% If you'd like further information about a topic as you read through this book, you can consult %@NL@% %@NL@% %@NL@% ■ %@AI@%Advanced Programming Techniques%@AE@%%@NL@% %@NL@% ■ The %@AI@%C Reference%@AE@% guide%@NL@% %@NL@% ■ The on-line reference system (as discussed in Chapter 4)%@NL@% %@NL@% %@NL@% All of these sources are included in the Microsoft C package; they present detailed information about the various components of the Professional Development System. %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00010002 @%%@AB@%Before You Proceed%@AE@%%@EH@%%@NL@% %@NL@% Before installing Microsoft C, take a few minutes to make sure your computer meets minimum system requirements and that your package is complete. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00010003 @%%@AB@%System Requirements%@AE@%%@EH@%%@NL@% %@NL@% Microsoft C requires the following configuration: %@NL@% %@NL@% %@NL@% ■ An IBM Personal Computer or 100% compatible running DOS version 3.0 or later or OS/2 version 1.1 or later. %@NL@% %@NL@% ■ An 8088 processor (a minimum of an 8 megahertz, 80286 processor is recommended).%@NL@% %@NL@% ■ 512K (kilobytes) of available memory (RAM) for operating under DOS (1 megabyte of RAM is recommended).%@NL@% %@NL@% ■ 3 megabytes of RAM for operating under OS/2 (4 megabytes of RAM are recommended).%@NL@% %@NL@% ■ At least 384K of extended memory if you want to debug large DOS programs.%@NL@% %@NL@% ■ One hard-disk drive with a minimum of 8 megabytes of free space. (Depending on the options you want, you may need up to 20 megabytes of disk space.)%@NL@% %@NL@% ■ One 1.2 megabyte, 5.25-inch floppy disk drive or one 720K, 3.5-inch floppy disk drive.%@NL@% %@NL@% %@NL@% Programs compiled with Microsoft C version 6.0 support DOS versions 2.1 and later. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00010004 @%%@AB@%Package Contents%@AE@%%@EH@%%@NL@% %@NL@% Check your Microsoft C package to see if everything is there. If any pieces are missing, contact the retailer from whom you purchased Microsoft C. %@NL@% %@NL@% In the package, you should find the following items: %@NL@% %@NL@% %@NL@% ■ Registration card. There are many advantages to being a registered owner of Microsoft C version 6.0, including notification of future software releases and easy access to customer assistance. Please take the time to fill out and mail the registration card now. (If you are already a registered owner of an earlier version of Microsoft C, a registration card is not included with the update.)%@NL@% %@NL@% ■ Disks. The distribution disk labeled "Setup/Compiler" contains a file named PACKING.LST that lists the location and description of all disk files in the Microsoft C package. Files on the disks are compacted and are uncompressed with the Setup program as they are installed. Microsoft C is distributed on 5.25-inch high density disks or 3.5-inch disks. If you need 360K disks to install the compiler, please send in the 3.5-inch media order card contained in the C 6.0 package or call Microsoft Customer Service (1-800-426-9400).%@NL@% %@NL@% ■ %@AI@%Installing and Using Microsoft C.%@AE@% It explains how to install and use Microsoft C.%@NL@% %@NL@% ■ %@AI@%Advanced Programming Techniques.%@AE@% This book discusses advanced topics concerning Microsoft C. Part 1, "Improving Program Performance," examines options and methods for producing more efficient code. Part 2, "Improving Programmer Productivity," describes tools and techniques the Professional Development System offers to help you work more efficiently. Part 3, "Special Environments," discusses graphics, mixed-language programming, and portability. Part 4, "OS/2 Support," discusses developing OS/2 applications with the Professional Development System.%@NL@% %@NL@% ■ %@AI@%C Reference.%@AE@% This book includes a summary of compiler, linker, editor, the Microsoft CodeView(R) debugger, and other tool commands; a brief language reference; and a complete list of library functions.%@NL@% %@NL@% ■ %@AI@%Product Assistance Request.%@AE@% If you need to contact Microsoft Product Support, be sure to fill out this questionnaire before calling.%@NL@% %@NL@% ■ %@AI@%Documentation Feedback Card.%@AE@% To help Microsoft improve its documentation, a postage-paid survey mailer is included. Please take the time to fill out the card with any comments or suggestions. %@NL@% %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00010005 @%%@AB@%Features New to Version 6.0%@AE@%%@EH@%%@NL@% %@NL@% If you've used an earlier version of Microsoft C, you'll find many new capabilities in version 6.0, and you'll discover that you can perform familiar operations more quickly: %@NL@% %@NL@% %@NL@% ■ Speed up development with the integrated PWB environment, including a fast-turnaround incremental compiler and linker.%@NL@% %@NL@% ■ Increase program efficiency with global optimization and smaller run-time libraries.%@NL@% %@NL@% ■ Build programs more easily with the new Make facility (NMAKE) and PWB's powerful project capabilities.%@NL@% %@NL@% ■ Insert assembly code directly into your C source code with the integrated in-line assembler.%@NL@% %@NL@% ■ Track down program bugs and logic errors more quickly with the new Microsoft CodeView debugger version 3.0. With an 80286 or 80386 processor and 1 megabyte or more of RAM, you can debug a program of any size in real mode.%@NL@% %@NL@% ■ Access all C run-time, language, compiler, linker, and utility documentation with the Microsoft Advisor and QuickHelp on-line reference systems.%@NL@% %@NL@% ■ Cross-reference program functions and variables with the PWB Source Browser.%@NL@% %@NL@% ■ Create OS/2 applications with increased support for dynamic-link libraries (DLLs), multiple threads, and improved debugging options.%@NL@% %@NL@% ■ Use based pointers to control placement of data in segments and generate better code for far-pointer manipulation.%@NL@% %@NL@% ■ Pass function parameters more efficiently with the %@AB@%_fastcall%@AE@% calling convention.%@NL@% %@NL@% ■ Edit source code with PWB's mouse- and window-oriented editor, which has all the functionality of the Microsoft Editor.%@NL@% %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00010006 @%%@AB@%Why Microsoft Programmer's WorkBench?%@AE@%%@EH@%%@NL@% %@NL@% The Programmer's WorkBench offers a wide array of features that can cut development time and increase your productivity. %@NL@% %@NL@% One feature that sets PWB apart from other development systems is its fully integrated, mouse- and window-based development environment. Most operations can be performed with menu selections or single keyboard commands. You never need to leave PWB to edit, build, debug, and run a program. %@NL@% %@NL@% PWB is built around the Microsoft Editor. The editor is completely extensible and can easily be configured to meet your personal needs. The editor combines advanced features such as macros and regular-expression search capabilities with the simplicity of a window-based application (see Figure 1.1). %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% As you develop your program, you can find information in the Microsoft Advisor on-line reference system instead of paging through manuals. A menu command provides complete information on the C language and run-time libraries. The Microsoft Advisor also supplies details on PWB, the compiler, linker, CodeView, and even the reference system itself. Figure 1.2 shows summary information on %@AB@%printf%@AE@%. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% When you're ready to compile the program, you don't need to remember the full range of command-line compiler options. All of the options are conveniently available in a PWB dialog box and can be clicked on or off (see Figure 1.3). Setting options is simply a matter of using the mouse or keyboard to select compiler, linker, NMAKE, and CodeView switches. %@NL@% %@NL@% PWB uses the powerful NMAKE tool to speed up development. NMAKE examines each module of a program to determine whether changes have been made that require the module to be recompiled. NMAKE then automatically compiles the modules as necessary and links them. When you're ready to build your program, you just select a single menu command to start the process. PWB invokes NMAKE and builds an application, using the options you set. %@NL@% %@NL@% If any errors are encountered, PWB displays an error window with a full listing of the compile and link errors (see Figure 1.4). The editor indicates the source line containing the error, and you can use the on-line reference system to provide comprehensive information about each error. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% Once a program has been successfully built, you can run it from within PWB to test it. If you need to make modifications, you can interrupt the program and return directly to PWB to make the changes. %@NL@% %@NL@% Another useful PWB feature is the Source Browser. With the Browser you can examine your code and display information about function and variable relationships (see Figure 1.5). This option is helpful in tracking program flow and isolating bugs. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% For bugs that are more difficult to locate and understand, use PWB's Debug Build option, and invoke the CodeView debugger directly from PWB. Then you can step and trace through your code at the source level and examine variables, registers, and memory (see Figure 1.6). %@NL@% %@NL@% Once you locate the bug you can exit CodeView and return directly to PWB, where you can fix the problem. When the code is completely debugged, a final release program can be built by using PWB's Release Build option. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@CR:C6A00020001 @%%@1@%%@AB@%Chapter 2 Installing Microsoft C%@AE@%%@EH@%%@NL@% %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@% %@NL@% This chapter describes how to install Microsoft C on your system, configure extended memory for use with CodeView, and customize components of Microsoft C. %@NL@% %@NL@% Files on the disks are compressed; SETUP.EXE is provided for installing Microsoft C under DOS and OS/2 operating environments. SETUP uncompresses and copies a variety of files─the compiler, the linker, the Programmer's WorkBench (PWB), the library manager, libraries, the help system, and others─from the distribution disks to your hard disk. SETUP also can build combined libraries from component libraries such as math libraries, memory-model-specific base libraries, and graphics libraries; and can build additional libraries as needed. %@NL@% %@NL@% Before you run the SETUP utility, back up the distribution disks and make sure you have enough disk space (between 5 and 10 megabytes, depending on which options you select) to install the Professional Development System. Then read the first part of the README.DOC file to see whether it has any information concerning the installation process. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%If you are installing Microsoft C from 3.5-inch disks, SETUP.EXE is found on %@AI@%the disk labeled "Setup." If you are using 5.25-inch disks, SETUP is on the %@AI@%disk labeled "Setup and Compiler."%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00020002 @%%@AB@%Running SETUP%@AE@%%@EH@%%@NL@% %@NL@% Insert the disk containing the SETUP program in drive A, make that drive the current drive, then run SETUP.EXE. The program first displays a screen reminding you to read the documentation before installing Microsoft C (see Figure 2.1). This initial screen also points out that the default answers to SETUP's questions are usually good when you first install Microsoft C. Press ENTER to proceed. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00020003 @%%@AB@%Supplying SETUP Information%@AE@%%@EH@%%@NL@% %@NL@% Before SETUP can install Microsoft C, it needs information about your system and the type of programming you intend to do. This first stage of SETUP is a series of questions divided among three screens. Default answers to the questions appear in brackets; you can press ENTER to accept the defaults, or you can type in your own answers to override the defaults. Detailed information on the questions appears at the bottom of each screen. Each screen concludes by asking if you want to change any of your choices. Press N and then ENTER to move to the next screen. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%The questions that are displayed on your screen may differ slightly from the %@AI@%questions that are shown in this chapter. For example, if DOS is specified %@AI@%as the host operating mode, later questions will refer to DOS.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00020004 @%%@AB@%Correcting Mistakes%@AE@%%@EH@%%@NL@% %@NL@% If you want to change any of your choices, press Y. The questions will be repeated, but the choices you previously made become the default answers. %@NL@% %@NL@% To exit the SETUP program at any time without saving default answers, press CTRL+C. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%The SETUP program doesn't erase any files from the distribution disks. If %@AI@%you make a mistake during the setup process, just run SETUP again.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00020005 @%%@AB@%First Screen: Installing Libraries%@AE@%%@EH@%%@NL@% %@NL@% On the first SETUP screen (see Figure 2.2), you supply information SETUP uses to build run-time library files on your hard disk. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% %@NL@% %@4@%%@AB@%Selecting the Operating Mode%@AE@%%@EH@%%@NL@% %@NL@% Microsoft C can run under both OS/2 and DOS, and it can create executable files for either environment. Select the host operating mode under which your computer will usually run. Applications intended for OS/2 and DOS use different libraries. Specify the target operating mode for which you will most frequently be developing executable files. Both modes may optionally be selected. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Building Combined Libraries%@AE@%%@EH@%%@NL@% %@NL@% SETUP can create combined libraries for the memory model, math options, and operating modes you specify. Combined libraries reduce the amount of time required for linking. %@NL@% %@NL@% The component libraries can be left on your hard disk after combined libraries are built. However, you should delete them to free disk space unless you plan to build additional combined libraries in the near future. %@NL@% %@NL@% You have the option of including the graphics libraries GRAPHICS.LIB and PGCHART.LIB in your combined libraries. GRAPHICS.LIB contains numerous functions for drawing lines, rectangles, circles, and other shapes. PGCHART.LIB contains functions for creating presentation-quality, high-resolution graphs. (Under OS/2 protected mode, you also have the option of including another library, GRTEXTP.LIB, in your combined library. This library provides support for OS/2 text-mode functions.) If you choose not to include these libraries in the combined libraries, they will be copied onto your disk as separate libraries. If you then use routines from these libraries, you will need to explicitly specify the libraries when you link. %@NL@% %@NL@% The first time you install Microsoft C, you should create only one or two combined libraries. If you need other memory models, math packages, or operating modes, rerun the SETUP program with the /L option. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Choosing Math Options%@AE@%%@EH@%%@NL@% %@NL@% The math options you choose determine which math component libraries are included in your combined libraries. The default provided by SETUP depends on whether it detects a math coprocessor. %@NL@% %@NL@% Programs that use the 8087 library run only on a machine equipped with a math coprocessor. The 80x87 option generates applications that perform fast floating-point math. %@NL@% %@NL@% Programs linked with the emulator library will run on any computer, whether or not it has a coprocessor. If the computer has a coprocessor, the emulator library uses the coprocessor to perform all floating-point math operations. Otherwise, the library emulates a coprocessor. %@NL@% %@NL@% The alternate math library uses an alternate number representation; when a coprocessor is not present, programs using this library run faster than programs using the emulator. (Even if a coprocessor is installed, the alternate math library routines will not use it.) Selecting the alternate math library sacrifices some accuracy for increased execution speed and decreased program size. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%You may include all math libraries in your libraries, but doing so triples %@AI@%the number of combined libraries SETUP builds, thus tripling installation %@AI@%time and increasing storage requirements. If you intend to install all %@AI@%possible library configurations, you'll need approximately 6 megabytes of %@AI@%free space on your hard disk just for libraries. If you install just one %@AI@%library, you'll need about 3.3 megabytes.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% For more information on math options, see Chapter 4, "Controlling Floating-Point Math Operations," in %@AI@%Advanced Programming Techniques%@AE@%. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Choosing Memory Models%@AE@%%@EH@%%@NL@% %@NL@% Microsoft C supports six standard memory models. Table 2.1 illustrates the relationship between the available memory models and the limits placed on their code and data segments. %@NL@% %@NL@% %@AB@%Table 2.1 Memory Models%@AE@% %@TH: 16 526 02 14 20 42 @%Memory Model Code Segment Limit Data Segment Limit%@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%Tiny 64K 64K (CODE + DATA)Small 64K 64KMedium None 64KCompact 64K NoneLarge None NoneHuge None None%@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%%@TE: 16 526 02 14 20 42 @% For more information on memory models, see Chapter 2, "Managing Memory," in %@AI@%Advanced Programming Techniques%@AE@%. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Specifying Default Library Names%@AE@%%@EH@%%@NL@% %@NL@% SETUP normally gives each combined library a name of the form %@AI@%m%@AE@%LIBC%@AI@%fs%@AE@%.LIB, where %@AI@%m%@AE@% is S, M ,C, or L (memory model); %@AI@%f%@AE@% is A, E, or 7 (math library); and %@AI@%s%@AE@% is R or P (operating mode). %@NL@% %@NL@% This question will vary according to the target operating system you selected. If you chose OS/2, you will be asked whether to use the default OS/2 library names. If you selected both operating modes, you will be asked whether to use the default libraries for OS/2 and DOS. %@NL@% %@NL@% If you selected only one operating mode, or if you selected both but plan to program in one mode predominantly, you should have SETUP give default names to all libraries built for that mode. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00020006 @%%@AB@%Second Screen: Installing Additional Files%@AE@%%@EH@%%@NL@% %@NL@% Your answers to questions on this screen determine whether PWB is installed (see Figure 2.3). %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% %@NL@% %@4@%%@AB@%Installing PWB%@AE@%%@EH@%%@NL@% %@NL@% You may choose not to install PWB if you plan to use only the command-line version of the compiler and linker. If you install PWB, you can choose to configure the PWB editor so that it is similar to the BRIEF(R) editor. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Installing the Microsoft Mouse%@AE@%%@EH@%%@NL@% %@NL@% If you have chosen OS/2 real mode and DOS as the host operating mode, you are asked whether you want to install the most recent version of the Microsoft Mouse device driver. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Copying Patch Files%@AE@%%@EH@%%@NL@% %@NL@% If you have chosen OS/2 real mode and DOS as the host operating mode, you have the option of installing a patch for dealing with floating-point exceptions found under PC-DOS version 3.20. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00020007 @%%@AB@%Third Screen: Specifying Directories%@AE@%%@EH@%%@NL@% %@NL@% On this screen, you specify the directories into which SETUP copies library, header, and other files (see Figure 2.4). You can choose to override the default options for directory names. Be sure to enter complete path names for your own directories. If the specified directories don't exist, SETUP asks whether you want to create them. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% The questions about protected-mode executable files and dynamic link libraries appear only if OS/2 protected mode has been selected as the target operating mode. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%The questions about executable files concern the location of development %@AI@%tools, not the executable files you create with Microsoft C.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00020008 @%%@AB@%Checking Available Disk Space%@AE@%%@EH@%%@NL@% %@NL@% Before moving to stage two, SETUP checks your hard disk to see how much free space is available. If you don't have enough room to install Microsoft C, an error message informs you how much space is required for the files you've requested. %@NL@% %@NL@% If you don't have enough room on your hard disk, you can either delete existing hard-disk files or reduce the number of requested libraries. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%If you feel that SETUP has incorrectly sized your disk for some reason, you %@AI@%can disable space checking by using the /NOFREE option.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00020009 @%%@AB@%SETUP Options%@AE@%%@EH@%%@NL@% %@NL@% SETUP has several options: /?, /COPY, /HELP, /LIB, /NOFREE, and /NOHELP. With the exception of /? and /HELP, you should %@AI@%not%@AE@% use any of the options the first time you run SETUP. The /? and /HELP options (see Figure 2.5) present information about the options. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% The /COPY option uncompresses and copies individual files from the distribution disks. The /LIB option builds additional combined libraries after you have already installed Microsoft C, without going through the entire setup process. /NOFREE instructs SETUP not to check for available free disk space before uncompressing and copying files. The /NOHELP option suppresses the SETUP help information displayed at the bottom of the screen. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00020010 @%%@AB@%Configuring Your System%@AE@%%@EH@%%@NL@% %@NL@% When SETUP has finished creating the combined libraries and placing them in the directories you specified, it creates files that are used for configuring your system. %@NL@% %@NL@% If you selected OS/2 real mode or DOS as the host environment, SETUP creates three files: NEW-VARS.BAT, NEW-CONF.SYS, and TOOLS.PRE. The files NEW-VARS.BAT and NEW-CONF.SYS are placed in the directory C:\C600\BIN; the file TOOLS.PRE is placed in the directory C:\C600\INIT. (These are the default directory names. If you have overridden them with your own choices, SETUP places these files in the directories you specified.) %@NL@% %@NL@% If you selected OS/2 protected mode as the host environment, SETUP creates two files: NEW-VARS.CMD and TOOLS.PRE. The file NEW-VARS.CMD is placed in the directory C:\C600\BINP; the file TOOLS.PRE is placed in the directory C:\C600\INIT. (These are the default directory names. If you have overridden them with your own choices, SETUP places these files in the directories you specified.) %@NL@% %@NL@% To permanently configure your system for Microsoft C, you must add the respective file contents to your AUTOEXEC.BAT (or STARTUP.CMD), CONFIG.SYS, and TOOLS.INI files, and reboot your system. You can, however, run NEW-VARS.BAT or NEW-VARS.CMD to set environment variables before you use Microsoft C. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Changing AUTOEXEC.BAT or STARTUP.CMD%@AE@%%@EH@%%@NL@% %@NL@% The NEW-VARS.BAT and NEW-VARS.CMD files contain batch file commands that set environment variables. Insert these commands into the AUTOEXEC.BAT or STARTUP.CMD file. Table 2.2 describes the meaning of each variable. %@NL@% %@NL@% %@AB@%Table 2.2 Environment Variables%@AE@% %@TH: 16 673 02 34 44 @%Variable Description%@AB@%──────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%PATH Path to search for applicationsLIB Location of run-time librariesINCLUDE Location of include (.H) filesHELPFILES Location of help (.HLP) filesINIT Location of initialization filesTEMP Location of PWB/LINK temporary files%@AB@%──────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%%@TE: 16 673 02 34 44 @% %@NL@% %@4@%%@AB@%Modifying CONFIG.SYS%@AE@%%@EH@%%@NL@% %@NL@% If the host operating mode is OS/2 real mode or DOS, be sure the %@AS@% files %@AE@% and %@AS@% buffer %@AE@% values in CONFIG.SYS are large enough for Microsoft C. The values in NEW-CONF.SYS are minimums. The values in CONFIG.SYS should be greater than or equal to these amounts. Additionally, with OS/2, make sure the %@AS@% %@AS@%LIBPATH= %@AE@% line of the CONFIG.SYS file specifies the location of the file MSHELP.DLL. OS/2 users who want to use the CodeView debugger must also include the statement %@AS@% IOPL=YES%@AE@%. %@NL@% %@NL@% To use the extended memory features of CodeView under DOS, set %@AS@%DEVICE=HIMEM.SYS %@AE@% (with HIMEM's fully qualified path name). See the section in this chapter titled "Configuring Extended Memory for CodeView" for additional information on running CodeView with extended memory in a DOS environment. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Modifying TOOLS.INI%@AE@%%@EH@%%@NL@% %@NL@% SETUP creates a file called TOOLS.PRE. This file contains various PWB settings, such as those that specify libraries. You should add the contents of the TOOLS.PRE file to your existing TOOLS.INI file; if TOOLS.INI does not exist, you should rename TOOLS.PRE to TOOLS.INI. %@NL@% %@NL@% The TOOLS.INI file contains many configuration options, which help you customize the following utilities in Microsoft C: %@NL@% %@NL@% %@NL@% ■ PWB%@NL@% %@NL@% ■ The CodeView debugger%@NL@% %@NL@% ■ The Microsoft Advisor help system%@NL@% %@NL@% ■ The NMAKE utility%@NL@% %@NL@% %@NL@% You can use the PWB editor or a word processor to change the settings in the TOOLS.INI file. These are some of the options you can change: %@NL@% %@NL@% %@NL@% ■ The colors and the number of lines displayed by CodeView and PWB%@NL@% %@NL@% ■ Macros for PWB%@NL@% %@NL@% ■ Key assignments for PWB%@NL@% %@NL@% ■ Default key settings for PWB%@NL@% %@NL@% ■ The location of help files used by the Microsoft Advisor%@NL@% %@NL@% ■ Options for NMAKE%@NL@% %@NL@% %@NL@% A complete table of TOOLS.INI settings is available in on-line help and the %@AI@%C Reference%@AE@%. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00020011 @%%@AB@%Choosing a Target Operating Environment%@AE@%%@EH@%%@NL@% %@NL@% In many cases you will program primarily for either the OS/2 protected mode or the DOS 3.x - OS/2 real mode and use one combined library. Allowing SETUP to make either DOS or OS/2 the default environment is the easiest method, but you can also manually choose a target environment. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Choosing Defaults for a Single Mode%@AE@%%@EH@%%@NL@% %@NL@% Start by deciding which operating mode will be the default environment. Then give the combined library for that mode the default combined-library name. The composition of library names is explained in the section "Specifying Default Library Names." %@NL@% %@NL@% For example, the following steps will create a protected-mode executable file using the small memory model and the emulation floating-point library: %@NL@% %@NL@% %@NL@% 1. Use SETUP to create SLIBCEP.LIB, the combined library for the small memory model, floating-point emulation, and protected mode.%@NL@% %@NL@% 2. Rename SLIBCEP.LIB as SLIBCE.LIB (the same name without P), the default combined library name for the small memory model and floating-point emulation library.%@NL@% %@NL@% %@NL@% At this point you can use PWB or invoke the command-line compiler, CL, without specifying the target operating environment for your application. (In this example, you still need to supply the appropriate PWB or CL options to select a memory model and floating point options.) If you don't specify a memory-model option or floating-point option on the command line, the linker links SLIBCE.LIB, creating an executable file that runs in OS/2 protected mode. %@NL@% %@NL@% The same general procedure works for real mode, other memory models, and floating-point libraries: Create the appropriate operating mode and combined library, and give it the appropriate default combined-library name. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Selecting a Mode at Compile Time%@AE@%%@EH@%%@NL@% %@NL@% If you need the flexibility of programming for both operating modes, you should use SETUP to create the combined libraries that you need for each model. Once you have created the combined libraries, you can select a model either by using the PWB options found in the C Compiler Options dialog box or the CL options listed in Table 2.3. %@NL@% %@NL@% %@AB@%Table 2.3 Operating Environment Options%@AE@% %@TH: 10 594 02 08 52 18 @%Option Environment Library Selected%@AB@%──────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%/Lp OS/2 protected mode %@AI@%m%@AE@%LIBC%@AI@%f%@AE@%P.LIB/Lr DOS 3.x - OS/2 real mode %@AI@%m%@AE@%LIBC%@AI@%f%@AE@%R.LIB/Lc DOS 3.x (synonym for /Lr) %@AI@%m%@AE@%LIBC%@AI@%f%@AE@%R.LIB%@AB@%──────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%%@TE: 10 594 02 08 52 18 @% Using these options causes CL to substitute one of these library names for the default combined-library name in the object module's library-search record. %@NL@% %@NL@% These options automatically set the /NODEFAULTLIBRARYSEARCH linker option, which overrides the default library (the syntax is /NOD:%@AI@%libraryname%@AE@%). For example, if you are programming for the OS/2 protected mode with the small memory model and floating-point emulation, and you supply the /Lp option for CL, the compiler passes the following option to the linker: %@NL@% %@NL@% %@AS@% /NOD:slibce slibcep%@AE@%%@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00020012 @%%@AB@%Configuring Extended Memory for CodeView%@AE@%%@EH@%%@NL@% %@NL@% Extended memory refers to memory at physical addresses above 1 megabyte that can be accessed by an 80%@AI@%x%@AE@%86 CPU in protected mode. %@NL@% %@NL@% As previously mentioned, in order to use the extended memory features of CodeView under a DOS environment, you must set %@AS@% DEVICE=HIMEM.SYS %@AE@% (with HIMEM's fully qualified path name) in the CONFIG.SYS file. A sample entry of how to implement HIMEM is found in the NEW-CONF.SYS file that SETUP creates. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%HIMEM.SYS is an implementation of the XMS 2.x standard. The complete XMS %@AI@%source and specification are available from the Microsoft Information %@AI@%Center; call 1-800-426-9400.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% In addition, there are several factors to consider when using CodeView under DOS with extended memory: %@NL@% %@NL@% %@NL@% ■ At least 384K of extended memory should be set aside for use with HIMEM.SYS.%@NL@% %@NL@% ■ Other memory managers such as 386-Max(tm) or QEMM may not work in conjunction with HIMEM.SYS. You should use only one memory manager.%@NL@% %@NL@% ■ Older versions of HIMEM.SYS may present problems. Use the most recent version included on the distribution disks.%@NL@% %@NL@% ■ Many RAM disk (VDISK) and disk cache programs are incompatible with HIMEM.SYS. The HIMEM.SYS compatible RAMDRIVE RAM disk and SMARTDRV disk cache programs are provided on the distribution disks. If you are operating under Microsoft Windows(tm) , the SMARTDRV application shipped with the Professional Development System is incompatible with Windows 2.11, and is compatible only with Windows 3.0.%@NL@% %@NL@% ■ Check the documentation of installed terminate-and-stay-resident (TSR) programs to see if they are compatible with HIMEM/XMS 2.x. You can incrementally install each TSR until you find a potential offender.%@NL@% %@NL@% %@NL@% If you choose to install the HIMEM, RAMDRIVE, and SMARTDRV files, SETUP places them in the C:\C600\BIN directory. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%Extended memory should not be confused with %@AI@%expanded memory%@AE@%%@AI@%. Expanded memory %@AI@%refers to bank-switched memory that overcomes the 640K RAM limitation found %@AI@%in the 8088 processor.%@AE@%%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00020013 @%%@AB@%Customizing Microsoft C%@AE@%%@EH@%%@NL@% %@NL@% In addition to modifying the TOOLS.INI file, Microsoft C can be customized in other ways. For example, a variety of editor functions and options can be set within PWB by using the Editor Settings command on the Options menu. %@NL@% %@NL@% For more information about customizing PWB, refer to Chapter 3 or see Chapter 8, "Customizing the Microsoft Programmer's WorkBench," in %@AI@%Advanced %@AI@%Programming Techniques%@AE@%. More information about customizing NMAKE and other utilities can also be found in %@AI@%Advanced Programming Techniques%@AE@%. %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@CR:C6A00030001 @%%@1@%%@AB@%Chapter 3 Using the Programmer's WorkBench%@AE@%%@EH@%%@NL@% %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@% %@NL@% This chapter introduces the Programmer's WorkBench (PWB)─a powerful integrated tool designed to make writing and debugging programs easier. PWB is a window-oriented programming environment that incorporates a text editor, a compiler, a linker, a debugger, a Make utility, a source-code browser, and an on-line help database. PWB provides an alternative to switching between command-linebased programs: You can edit, compile, link and debug from within an integrated environment. To demonstrate various features of PWB, this chapter provides a sample program for you to compile, link, and debug. %@NL@% %@NL@% This chapter explains how to start PWB and then introduces the following elements of PWB: %@NL@% %@NL@% %@NL@% ■ Windows and menus. You can quickly find the command you need with the menu system. The section "Using Windows and Menus" explains how to open and close windows and how to navigate through the menus.%@NL@% %@NL@% ■ Programmer's editor. Features such as "bookmarks," macros, customized key commands, and enhanced search capabilities decrease the amount of time you spend writing code.%@NL@% %@NL@% ■ Integrated compiler and linker. You can compile, link, and run a program without ever leaving the editor. PWB's integrated environment and project-management facilities save you hours of development time.%@NL@% %@NL@% ■ Integrated browser and debugger. With the Source Browser, you can quickly find a data declaration or function definition within your source code, and find references to all functions and variables in a multi-module program. With the CodeView debugger, you can set breakpoints, examine variables and machine registers, and step through execution of your program one line at a time.%@NL@% %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00030002 @%%@AB@%Starting PWB%@AE@%%@EH@%%@NL@% %@NL@% To run PWB for the first time, type %@NL@% %@NL@% %@AS@% PWB%@AE@%%@NL@% %@NL@% at the command line. (If errors occur, PWB displays error messages. See the README.DOC file for further information.) %@NL@% %@NL@% You can immediately begin writing source code in the new, untitled window that appears. PWB maintains a history of the files you have opened. The next time you run PWB, it opens the last file you worked on. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030003 @%%@AB@%Specifying a Source File%@AE@%%@EH@%%@NL@% %@NL@% You can open an existing source file by entering its name on the command line after the PWB command. If PWB can't find the specified file in the current directory, it asks if you want to create a new file. You can also open an existing source file with the Open command in the File menu. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030004 @%%@AB@%Command-Line Options%@AE@%%@EH@%%@NL@% %@NL@% PWB has several command-line options that you can issue when you start the program. %@NL@% %@NL@% %@AB@%Option%@AE@% %@AB@%Action%@AE@% %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@% /e %@AI@%string%@AE@% The %@AI@%string%@AE@% represents a series of PWB commands that will be executed at start-up. /t %@AI@%file%@AE@% Indicates the specified file is temporary, and should not be kept in the file history. You must precede the name of each temporary file with a /t. /D Prevents all PWB initialization and status files from being read at start-up. /DS Prevents the CURRENT.STS file from being read. /DT Prevents the TOOLS.INI file from being read at start-up. /r Turns on the global "no-edit mode," which gives all files opened with PWB Read Only status. /m %@AI@%bookmark%@AE@% Positions the cursor at the file location designated by %@AI@%bookmark%@AE@%. /? Lists the command-line options for starting up PWB. %@NL@% %@2@%%@CR:C6A00030005 @%%@AB@%Using Windows and Menus%@AE@%%@EH@%%@NL@% %@NL@% This section introduces the PWB environment and describes how to control windows and choose commands from the menus. Terms used to describe elements of the PWB environment are also presented. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%You can enter commands in PWB with the keyboard or a Microsoft (or fully %@AI@%compatible) Mouse. Unless the Right mouse button is specifically mentioned, %@AI@%"clicking" means that you press and release the Left mouse button once.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030006 @%%@AB@%Windows%@AE@%%@EH@%%@NL@% %@NL@% Figure 3.1 shows parts of a typical PWB screen. Some of the elements provide information only. For example, if CAPS LOCK is on, the letter %@AS@% C %@AE@% appears in the lower right corner of the screen; the letter %@AS@% C %@AE@% is informational. Other parts perform actions triggered by a specific keystroke or mouse action. For example, if you click the button in the upper left corner of a window, the window closes. The button is active rather than informational. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% The parts of a PWB screen and their use are listed in Table 3.1 below. %@NL@% %@NL@% %@AB@%Table 3.1 Parts of a PWB Screen%@AE@% %@TH: 44 2135 02 22 54 @%Name Use%@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%Menu bar Lists names of available menus.Close button Closes window (appears only if more than one window is displayed).Title bar Shows name of file currently being edited.Windows Contain source code or display information associated with on-line help.Maximize button Enlarges or restores window to its original size.Screen number Indicates number of help screen in the on-line help database.Scroll bars Indicate cursor position in the current file and allow cursor movement.Reference bar Lists shortcut keystrokes (keyboard users) and directs PWB commands (mouse users); summar izes menu contents and displays other information.File-type indicator Indicates type of file. %@AS@%C%@AE@%: C source. %@AS@%text%@AE@%: any other user-created file. %@AS@%pseudo%@AE@%: file-like means of displaying data.Line and column Shows current line and column of text cursor.indicators Status indicators %@AS@%A%@AE@%: Meta condition is on.%@AS@%%@AE@% %@AS@%B%@AE@%: Background compile in OS/2.%@AS@%%@AE@% %@AS@%C%@AE@%: CAPS LOCK is on.%@AS@%%@AE@% %@AS@%L%@AE@%: A CR isn't used to terminate a line.%@AS@%%@AE@% %@AS@%M%@AE@%: File has been modified.%@AS@%%@AE@% %@AS@%N%@AE@%: NUM LOCK is on.%@AS@%%@AE@% %@AS@%O%@AE@%: Overtype is on.%@AS@%%@AE@% %@AS@%R%@AE@%: The file is set to Read Only status.%@AS@%%@AE@% %@AS@%T%@AE@%: File is temporary.%@AS@%%@AE@% %@AS@%X%@AE@%: A macro is recording.%@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%%@TE: 44 2135 02 22 54 @% %@NL@% %@3@%%@CR:C6A00030007 @%%@AB@%Menus%@AE@%%@EH@%%@NL@% %@NL@% The menu bar contains seven or more menus which can be accessed at any time. A brief description of the selected menu command is displayed in the reference bar. To get further information about what a menu does, invoke the on-line help system by using the ALT and ARROW keys to highlight a menu title or menu command, then press F1; or point the mouse cursor at the menu command and click the Right mouse button. %@NL@% %@NL@% PWB has the following menus: %@NL@% %@NL@% %@AU@%(Please refer to the printed %@AE@% The File menu allows you to clear the %@AU@%book)%@AE@% Source window, load an existing source file, merge a file with the file in memory, display the next file in the file list specified at start-up, save the current file, save the current file under a different name, print the selection or current file contents, temporarily exit to DOS or OS/2, or permanently exit PWB. Additionally, a list of recently opened source files is displayed at the bottom of the menu. %@AU@%(Please refer to the printed %@AE@% The Edit menu allows you to delete, cut, %@AU@%book)%@AE@% copy, and paste text. Anchors can be set in the text as reference points for selection. Box, stream, and line mode determine how text will be selected with the cursor. Read Only status protects source files. Commands to record, play, and edit recorded macros are also available in this menu. These items are discussed further in the section "Using the Editor." %@AU@%(Please refer to the printed %@AE@% The View menu controls the active %@AU@%book)%@AE@% window. A window can be closed, sized, and split vertically or horizontally with the menu commands. %@AU@%(Please refer to the printed %@AE@% The Search menu invokes commands that %@AU@%book)%@AE@% find or change text in source files. Commands to search the source file for compilation errors are also available. Commonly accessed text can be identified with "bookmarks." Once a bookmark is associated with a certain position in the source file, the Go To Mark command moves the cursor to that location. %@AU@%(Please refer to the printed %@AE@% The Make menu is used for compiling or %@AU@%book)%@AE@% building (to "build" means to compile and link) programs. From this menu, you also create or edit program lists, which name the components of multi-module programs. %@AU@%(Please refer to the printed %@AE@% The Run menu is used to execute your %@AU@%book)%@AE@% compiled program. Compiled programs can be debugged with CodeView using the Debug command. The Run menu also has options for issuing DOS or OS/2 commands and adding applications as PWB menu items (for example, the Customize Menu command). %@AU@%(Please refer to the printed %@AE@% The items in the Options menu control %@AU@%book)%@AE@% the integrated environment. The Environment command temporarily changes path names for libraries, include files, and help files. Both Key Assignments and Editor Settings customize the operation of the PWB editor. The Build Options command saves current build options, determines what type of program will be built (OS/2, DOS) with the Initial Build option, and specifies whether the program is built as a debug or release version. The Browse, C Compiler, CodeView, LINK, and NMAKE commands configure their respective applications. %@AU@%(Please refer to the printed %@AE@% The commands in the optional Browse menu %@AU@%book)%@AE@% are used to scan through data declarations and functions once a program has been compiled. Program call trees, references to variables, and symbol relationships can be shown in the Browser window. Menu items are disabled unless you have compiled your program with options that generate a Browser database. %@AU@%(Please refer to the printed %@AE@% The optional Help menu accesses the %@AU@%book)%@AE@% on-line reference system. For more information, see Chapter 4, "Using the On-Line Reference." %@NL@% %@4@%%@AB@%Choosing Menu Commands%@AE@%%@EH@%%@NL@% %@NL@% Choose a command from a menu by "pulling down" or "opening" the menu. %@NL@% %@NL@% To choose a command from the keyboard: %@NL@% %@NL@% %@NL@% 1. Press the ALT key to activate the menu bar.%@NL@% %@NL@% 2. Press the highlighted character in the menu name (such as F for File), or use the right and left ARROW keys to select a menu. The left and right ARROW keys only select the menu; they do not open it.%@NL@% %@NL@% 3. Press the highlighted character in the command name (such as S for Save in the File menu), or use the up and down ARROW keys to highlight the command and then press ENTER.%@NL@% %@NL@% %@NL@% To choose a command with the mouse: %@NL@% %@NL@% %@NL@% 1. Open the menu by clicking the menu name.%@NL@% %@NL@% 2. Click the command.%@NL@% %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Closing Menus%@AE@%%@EH@%%@NL@% %@NL@% If you open a menu and then decide you don't want to issue a command, you can close the menu in any of these ways: %@NL@% %@NL@% %@NL@% ■ Press the ESC key%@NL@% %@NL@% ■ Click the mouse somewhere outside of the menu%@NL@% %@NL@% ■ Press ALT twice%@NL@% %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Using Shortcut Keys%@AE@%%@EH@%%@NL@% %@NL@% Certain menu items are followed by the names of keys or key combinations. These are "shortcut keys" for commonly used commands. Instead of issuing a command by opening a menu, press the shortcut key to issue the command. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%The reference bar at the bottom of the screen displays common shortcut keys. %@AI@%You can click any of these buttons to execute the indicated command.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@4@%%@AB@%Shaded Commands%@AE@%%@EH@%%@NL@% %@NL@% When a command within a menu is in grayed type, it is "disabled," or unavailable for use; some condition prevents the command from being used. For example, when PWB is first run, and no programs have been compiled or linked, the Next Error and Previous Error commands in the Search menu are both disabled. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Ellipses%@AE@%%@EH@%%@NL@% %@NL@% If a command is followed by three periods (an ellipsis), it means more information must be provided before the command is executed. You provide this information in a dialog box that appears when you issue the command. If a command is not followed by an ellipsis, it is executed immediately. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030008 @%%@AB@%Dialog Boxes%@AE@%%@EH@%%@NL@% %@NL@% Some menu commands cause dialog boxes to appear. For example, Figure 3.2 shows the dialog box opened by the Search menu's Find command. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%Dialog boxes usually offer shortcut keys. Shortcut keys are identified by %@AI@%highlighted letters, and can be activated by pressing the corresponding key.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% Dialog boxes can contain one or more of the items in the following list. Press ALT and the item's highlighted letter or press the TAB or SHIFT+TAB keys to move among items in a dialog box. Dialog items can be set either with keyboard commands or with the mouse. %@NL@% %@NL@% %@AB@%Item%@AE@% %@AB@%Description%@AE@% %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@% Option buttons () Offer a list of choices; only one option can be chosen. Use the ARROW keys to move between the choices. In Figure 3.2, three option buttons set the direction of the search (Forward, Backward, Find All). Check box [X] A yes/no switch. If the box is empty, the option is turned off. If it contains the letter X, the feature is on. Press the SPACEBAR or use the up and down ARROW keys to turn a check box on or off. Text box [. . . . .] Accepts text that you enter. In Figure 3.2, Find Text requires you to type in the text to search for. Command buttons Pass commands to the dialog box < OK > (enclosed in angle brackets). The OK button means to use the current settings. The Cancel button exits the dialog box and does not change the current settings. If one of the command buttons is highlighted, press ENTER to execute that command. Clicking a command button also executes it. If a button contains an ellipsis, it indicates that another dialog box will appear when the command is carried out. List boxes Display lists of information, such as the contents of the current disk directory, inside a list box. If the number of items exceeds the list box space, press the ARROW keys and PGUP/PGDN or click the scroll bar to move around the list. %@NL@% %@3@%%@CR:C6A00030009 @%%@AB@%Getting Help%@AE@%%@EH@%%@NL@% %@NL@% PWB uses the Microsoft Advisor on-line help system to provide information about PWB, the compiler, the linker, the CodeView debugger, other utilities, and topics relating to the C language. Information can be displayed at any time and at any point you're using PWB or CodeView. For a complete discussion of the on-line reference, see Chapter 4. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Menu Help%@AE@%%@EH@%%@NL@% %@NL@% To get information about a PWB menu command, choose the command with the ARROW key, then press F1; or point the mouse cursor at the menu command and click with the Right mouse button. A help window then appears with information about the command. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Dialog-Box Help%@AE@%%@EH@%%@NL@% %@NL@% Many dialog boxes have a help button that provides additional information about the dialog box and its contents. To display the information, click the Help button with the mouse or press F1. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%The Help Menu%@AE@%%@EH@%%@NL@% %@NL@% You can also use the commands listed in the Help menu to display an index of all help topics, a table of contents, and information about using the on-line reference system itself. %@NL@% %@NL@% Choose the Contents command to display a global contents screen for the entire help system. The main contents lists information divided by topic, such as PWB, CodeView, or the C language. From the main contents, you can navigate to a selected topic's table of contents by clicking that topic. %@NL@% %@NL@% Choose the Index command to display a main index where you can move to other indexes for different components of the Microsoft C help database. %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00030010 @%%@AB@%Using the Editor%@AE@%%@EH@%%@NL@% %@NL@% The program editor is an important part of the PWB environment. This section provides a brief overview of its major functions, and assumes you are using the default key assignments. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030011 @%%@AB@%Moving Around in a Source File%@AE@%%@EH@%%@NL@% %@NL@% Many of the keys within the editor work as you would expect them to. For example: %@NL@% %@NL@% %@NL@% ■ The PGDN and PGUP keys advance forward or back within the file.%@NL@% %@NL@% ■ The HOME key moves the cursor to the beginning of the current line.%@NL@% %@NL@% ■ The END key moves the cursor to the end of the current line.%@NL@% %@NL@% ■ The ARROW keys move the cursor one character or one line at a time. %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%For a complete list of editor commands, refer to the on-line help system's %@AI@%PWB Function Quick Reference section on the PWB global contents screen.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@NL@% %@NL@% If you click in the shaded area on either side of the scroll box (position marker) in the scroll bar, you move the cursor one full window at a time in that direction. If you click on the scroll-bar arrows, you move the cursor one row or column in the corresponding direction. If you click and drag the scroll box, you move the cursor to the corresponding position within the file. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Defining a Block%@AE@%%@EH@%%@NL@% %@NL@% To define a block with the PWB editor using the keyboard: %@NL@% %@NL@% %@NL@% 1. Move the cursor to the beginning of the block. %@NL@% %@NL@% 2. Hold down the SHIFT key and move the cursor to the end of the block. %@NL@% %@NL@% 3. Use the other cursor keys (HOME, END, CTRL+RIGHT, and so on) while you're holding down SHIFT to extend the block.%@NL@% %@NL@% %@NL@% To define a block with the PWB editor using the mouse: %@NL@% %@NL@% %@NL@% 1. Move the cursor to the beginning of the block. %@NL@% %@NL@% 2. While holding down the left button, move to the end of the block.%@NL@% %@NL@% %@NL@% Once a block has been defined, it can be erased (press DEL), or placed into the Clipboard, a temporary buffer, by cutting (press SHIFT+DEL) or by copying (press CTRL+INS). Once in the Clipboard, the block can be inserted at a cursor location (press SHIFT+INS). While a block is defined, anything you type will delete the highlighted block and then insert the typed characters. %@NL@% %@NL@% Three text-selection modes are available in the Edit menu: %@NL@% %@NL@% %@NL@% 1. Box mode selects text in a rectangular area whose opposite corners are the starting and ending cursor positions.%@NL@% %@NL@% 2. Line mode selects entire lines of text from the starting cursor position to the ending cursor position.%@NL@% %@NL@% 3. Stream mode selects all text from the starting cursor position to the ending cursor location.%@NL@% %@NL@% %@NL@% Selecting a mode from the Edit menu changes the menu item to a new mode. The mode displayed in the menu is the next available text-selection mode. %@NL@% %@NL@% You can also toggle through the selection modes during text selection by clicking the Right mouse button while you hold down the Left mouse button. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Setting Bookmarks%@AE@%%@EH@%%@NL@% %@NL@% You can set bookmarks anywhere in your source code with the Define Mark command in the Search menu. Move the cursor to the location you want to mark, then choose Define Mark. %@NL@% %@NL@% In the dialog box that appears, type the name you want to give the bookmark. The source file name and the row and column are already entered. Press ENTER to save the bookmark for the current session. To permanently save a bookmark, you must use the Add To Mark File option. Permanent bookmarks can be loaded with the Set Mark File command in the Search menu. %@NL@% %@NL@% To move the cursor to a bookmark, choose the Go To Mark command from the Search menu. A list of all bookmarks is displayed. Select the bookmark from the list using the ARROW keys or click the selected bookmark with the Left mouse button. Press ENTER to go to the bookmark. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Setting Anchors%@AE@%%@EH@%%@NL@% %@NL@% An anchor is a temporary marker that identifies a cursor position somewhere in the text. Use anchors to select large blocks of text. %@NL@% %@NL@% To set an anchor, move the cursor to the desired location and use the Set Anchor command in the Edit menu. Use the Select To Anchor command in the Edit menu to select all text between the current cursor position and the anchor. Only one anchor may be set at a time. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Searching for and Changing Text%@AE@%%@EH@%%@NL@% %@NL@% You can search for a string of text by using the Find command in the Search menu. Type the string you want to look for, then use the check boxes to set options such as wraparound search and case sensitivity. The Files button allows you to specify a list of files to be searched for the designated string. %@NL@% %@NL@% Once a string has been located, use the Repeat Last Find command in the Search menu (or press the shortcut key, F3) to move to the next occurrence of the string. If you specified several files to search, press SHIFT+F3 to move to the next occurrence of the string. %@NL@% %@NL@% To modify several instances of a string in the source file, use the Change command in the Search menu. Enter the target string, the replacement string, and the search options. %@NL@% %@NL@% PWB also supports the search and replace of text patterns using regular expressions. Both UNIX(R) and non-UNIX regular expression syntaxes are supported. For further information, see the on-line reference system. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%Multi-file searches run a built-in GREP facility, and text that is found may %@AI@%be scanned with the Next Error and Previous Error commands.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@4@%%@AB@%Creating Macros%@AE@%%@EH@%%@NL@% %@NL@% Editing tasks that you perform frequently can be saved as macros. A macro is the record of a sequence of commands and/or literal text. Each macro has a key combination that is used to "play back" the recorded actions. %@NL@% %@NL@% For example, suppose several programmers are working on a file and need to keep track of who made what changes. A macro can be used to insert a comment with the programmer's name. %@NL@% %@NL@% To create such a macro, choose the Set Record command in the Edit menu and enter a macro name and associated key combination. For this example, call the macro %@AS@% modname %@AE@% and let the key combination be CTRL+J. (Any key combination can be used for a macro.) After you've named the macro, choose the Record On command from the Edit menu. A bullet will appear to the left of the menu command and an X in the status line, indicating all keystrokes and menu commands are being recorded. Then type the following: %@NL@% %@NL@% %@AS@% /* j. courtney coded this */%@AE@%%@NL@% %@NL@% To stop the recording, choose Record On once again, which causes the bullet to disappear. This action associates all the recorded actions with the previously selected macro. Now, each time you press the CTRL+J key combination for the macro, the comment you typed is instantly inserted at the cursor position. %@NL@% %@NL@% You save macros to the TOOLS.INI file when you save the <record> pseudofile which can be reached by the Edit Macro command in the Edit menu. They may be changed or deleted by modifying the file. See the section "Customizing PWB" in on-line help for additional information about macros. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030012 @%%@AB@%Customizing the Editor%@AE@%%@EH@%%@NL@% %@NL@% You can customize the PWB editor to meet your needs. Editor settings can be modified, keyboard commands can be assigned, and command sets from other editors can be emulated. In addition, customized extensions to the editor can be written in C. See the on-line reference system and Chapter 8, "Customizing PWB," in %@AI@%Advanced Programming Techniques%@AE@%, for complete details. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Changing Editor Settings%@AE@%%@EH@%%@NL@% %@NL@% The PWB editor has a variety of settings you can customize, such as word wrap, color, and width of tab stops. %@NL@% %@NL@% View or modify the settings by choosing the Editor Settings command from the Options menu. A pseudofile named <assign> appears. (The title bar says "Current Assignments and Settings," but the name <assign> appears in the File menu's list of files.) This file displays numerous editor settings in the format %@AI@%setting%@AE@%:%@AI@%value%@AE@%, where %@AI@%setting%@AE@% is the name of the setting, and %@AI@%value%@AE@% is a Boolean, numeric, or text value. You can learn about a setting by positioning the cursor on it and pressing F1. %@NL@% %@NL@% To change the value of a setting, enter a new value. The change does not take effect until you move the cursor to a different line. To save the changed assignments, press SHIFT+F2 (if the default keyboard assignments are in effect) or choose the Save command in the File menu. If you do not save, the assignments will be temporary and will last only for the duration of the PWB session. %@NL@% %@NL@% To return to your source file, press F2. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Modifying Keyboard Assignments%@AE@%%@EH@%%@NL@% %@NL@% You can easily change all PWB keyboard assignments. Functions such as %@AB@%delete%@AE@%, %@AB@%home%@AE@%, and %@AB@%copy%@AE@% can be reassigned by choosing the Key Assignments command from the Options menu. %@NL@% %@NL@% A pseudofile named <assign> appears. (The title bar says "Current Assignments and Settings," but the name <assign> appears in the File menu's list of files.) This file lists PWB functions and the keys to which they are assigned. These appear in the format %@AI@%function%@AE@%:%@AI@%keyname%@AE@%. You can learn about a PWB function by positioning the cursor on the function name and pressing F1. A list of unused keys follows the assignment list. %@NL@% %@NL@% To assign a new key to a function, replace %@AI@%keyname%@AE@% with the name of the new key. The change does not take effect until you move the cursor to a different line. %@NL@% %@NL@% When you move the cursor to a different line, the line with the new assignment is highlighted. To make the assignment permanent, save the file by pressing SHIFT+F2 or by choosing the Save command in the File menu. This updates the TOOLS.INI file, where changes to key assignments are stored. %@NL@% %@NL@% To remove a key from a given function, assign the %@AB@%unassigned%@AE@% function to the key. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Using Advanced Editor Features%@AE@%%@EH@%%@NL@% %@NL@% Most of the standard editing features in PWB are intuitive and easy to use. However, there are also many advanced editing options that allow you to customize and control the editor beyond simple menu commands. %@NL@% %@NL@% The PWB editor incorporates all of the powerful features found in the Microsoft Editor. A variety of functions and switches can be set to further customize the PWB editor and enhance its performance. A complete list of editor functions and settings is available in the on-line reference system. %@NL@% %@NL@% New or altered functions and settings can be added to the TOOLS.INI file so they are immediately loaded when PWB starts up. Or, they can be interactively entered while you are working in the PWB environment. %@NL@% %@NL@% For example, to interactively assign a key command to the editor's %@AB@%curdate%@AE@% function, which enters the current date at the cursor, first press ALT+A, then type the following into the argument dialog box: %@NL@% %@NL@% %@AS@% Curdate:SHIFT+CTRL+T%@AE@%%@NL@% %@NL@% Press ALT+= to assign the key to the function. %@NL@% %@NL@% Now, whenever you press SHIFT+CTRL+T, the current date will instantly be inserted at the editor's cursor position. %@NL@% %@NL@% For detailed information about advanced PWB editor features, refer to the %@AI@%Microsoft C Reference%@AE@% and the on-line reference system. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Reconfiguring the Editor%@AE@%%@EH@%%@NL@% %@NL@% If you wish to use another set of editing commands, PWB comes with an additional .INI file containing key assignments for the BRIEF editor. You can add the contents of the file to TOOLS.INI, or you can simulate other editors' command sets by using the customization techniques previously described. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Using Another Editor%@AE@%%@EH@%%@NL@% %@NL@% If you prefer to use another word processor or text editor, choose the Run menu's Customize Menu command. This command is used to add other programs (including word processors) to the Run menu so that you can run them from within the PWB environment. Through the dialog box you can specify directory paths and arguments to pass, and assign a key-command equivalent to run the editor. When you exit the program, you return to PWB. %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00030013 @%%@AB@%Compiling and Linking%@AE@%%@EH@%%@NL@% %@NL@% PWB uses a project-oriented approach to compiling and linking programs. After a source file has been created and a program list associated with it, PWB produces a makefile. A "program list" is a list of all of the source files that make up the program; the "makefile" contains information about the source files that compose the project. Whenever a multi-module program is compiled or linked, the NMAKE utility examines the makefile and determines which part of the project will be affected. %@NL@% %@NL@% The process of creating an executable file by compiling and linking is known as "building." When you build an application, the source code is first compiled on a module-by-module basis into .OBJ files, and then linked with the appropriate libraries. %@NL@% %@NL@% Makefiles are especially useful with multi-module programs, because only those source files that have changed are recompiled. This results in faster build times, since existing source files that haven't been changed are not recompiled. After you set a program list, building is a one-step process in PWB. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030014 @%%@AB@%Building Programs in PWB%@AE@%%@EH@%%@NL@% %@NL@% This section illustrates how to build programs under the PWB environment. To start, type in this sample program: %@NL@% %@NL@% %@AS@% /* IO.C: String input and output */ %@AS@% %@AS@% #include <stdio.h> %@AS@% %@AS@% main() %@AS@% { %@AS@% char date[30]; %@AS@% %@AS@% printf( "Enter today's date: \n" ); %@AS@% gets( date ); %@AS@% printf( "Sample program run on %s\n", date ); %@AS@% }%@AE@%%@NL@% %@NL@% This simple program uses the %@AS@% printf %@AE@% and %@AS@% gets %@AE@% library functions to prompt for, and then print, today's date. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Saving the Program%@AE@%%@EH@%%@NL@% %@NL@% To save the source file, pull down the File menu and choose either Save or Save As. If the file is new or you choose Save As, a dialog box prompts you for a file name (see Figure 3.3). If you choose Save with an existing file, PWB automatically saves the file under the name listed in the title bar of the source window. To save a copy of a file under a different name, choose Save As. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% Type in the new name of the source file, IO.C. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Setting and Clearing the Program List%@AE@%%@EH@%%@NL@% %@NL@% The Set Program List command in the Make menu tells PWB which makefile to use in building a program. It clears the current makefile setting, instructs PWB to use the makefile you have specified, and specifies which Browser (.BSC) file is associated with the current project. %@NL@% %@NL@% After you have saved the source file IO.C, choose the Set Program List command in the Make menu. In the dialog box that appears, type the base file name (IO), then press ENTER (see Figure 3.4). PWB automatically provides a .MAK extension. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% If the makefile does not exist, PWB asks if you want to create a new makefile; answer yes to this dialog box. Another dialog box titled Edit Program List appears, listing all files in the current directory. From the list, select the files you want to include in the project (in this example, just IO.C). %@NL@% %@NL@% Press TAB until the cursor is within the list box containing the directory of files (another box lists the directory names). Use the ARROW keys to move to the IO.C file. Press ENTER and the file name appears in the program list below. Once the file is selected, press TAB until the Save List command button is highlighted, and then press ENTER. %@NL@% %@NL@% If you have a mouse, click IO.C once and then click the Add/Delete button (or just double-click IO.C). Once the file appears in the program list, click the Save List command button to save the makefile. %@NL@% %@NL@% PWB automatically determines the contents of the makefile based on the files you selected. You can edit the .MAK text file to change or add additional commands. %@NL@% %@NL@% If you want to create a new program or instruct PWB to "forget" about the current program, use the Clear Program List command in the Make menu. This action clears the current program list setting. You can then specify a new program to build with Set Program List. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Setting Build Options%@AE@%%@EH@%%@NL@% %@NL@% Before compiling the program, you must specify the type of program you will be building. This is done with the Build Options command in the Options menu. Build Options calls a dialog box, whose Set Initial Build Options button presents a series of predefined compiler settings for creating programs (such as bound EXE, DOS EXE, DOS COM) and OS/2 .DLL libraries. Once an initial build option has been chosen, its settings can be changed with the C Compiler Options command in the Options menu. %@NL@% %@NL@% To specify an existing build option: %@NL@% %@NL@% %@NL@% 1. Choose the Build Options command from the Options menu%@NL@% %@NL@% 2. Select the Set Initial Build Options button%@NL@% %@NL@% 3. Use the mouse or the ARROW keys to select a build option from the list and press ENTER%@NL@% %@NL@% %@NL@% To save your own group of build option settings: %@NL@% %@NL@% %@NL@% 1. Select the appropriate settings in the C Compiler Options dialog box%@NL@% %@NL@% 2. Choose the Build Options command from the Options menu%@NL@% %@NL@% 3. Select the Save Current Build Options button%@NL@% %@NL@% 4. Type a description of the options and press ENTER%@NL@% %@NL@% %@NL@% The settings are now available through the Set Initial Build Options dialog box. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Compiling and Linking the Program%@AE@%%@EH@%%@NL@% %@NL@% You can set a variety of compiler directives in the Options menu. The C Compiler Options command provides options for memory model, processor type, and other global settings that affect overall compilation (see Figure 3.5). %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% From within the C Compiler Options dialog box, you can use the Set Debug Options and Set Release Options buttons to easily create debug and release versions of your program. %@NL@% %@NL@% When you select the Set Debug Options button, a dialog box appears in which you can set parameters such as stack checking, optimization, and debug information. These settings also apply to programs built with the Debug Build option, which you select from the dialog box displayed by the Build Options command. Use debug settings when you are in the development phase and actively debugging your program. When the Release Build option is checked in the Build Options dialog box, the parameters specified in the Set Release Options dialog box apply. %@NL@% %@NL@% Similar debug and release options are also available for the linker with the LINK Options command in the Options menu (see Figure 3.6). You can display the options in both the C Compiler Options and LINK Options dialog boxes with the Show Debug Options and Show Release Options buttons. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% The Set Release Options button in the C Compiler Options dialog box offers the same choices as Set Debug Options, but Set Release applies them to a final version of the program. Use these settings when your program is completely debugged and ready for release. %@NL@% %@NL@% For this example, use the default settings in the C Compiler Options dialog box. %@NL@% %@NL@% Before building the sample program, make sure that its name appears after the Compile File and Build commands in the Make menu. If the name does not appear after the Build command, choose the Set Program List command in the Make menu to set the makefile as the current project. %@NL@% %@NL@% To build the program, choose the Build command in the Make menu. If a compile or link error occurs, the build terminates, and the error appears in the Compile Results window. Use the on-line reference system to explain unknown errors by selecting the error and pressing F1. If you are using OS/2 and errors occur, you will be informed and asked if you want to see the compile log. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Running the Program%@AE@%%@EH@%%@NL@% %@NL@% After the program has been built, the name of your executable file is appended to the Execute command in the Run menu. Choose Execute to run the program. When the program is finished running, press any key to return to PWB. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Building from Multiple Source Files%@AE@%%@EH@%%@NL@% %@NL@% You can build most applications from more than one source file. This section demonstrates how to create a multi-module program. %@NL@% %@NL@% First, edit the IO.C program: %@NL@% %@NL@% %@AS@% /* IO.C: Illustrates external functions */ %@AS@% %@AS@% #include <stdio.h> %@AS@% %@AS@% void outsider(void); /* Add this function. */ %@AS@% void sample(void); /* Add this function. */ %@AS@% %@AS@% main() %@AS@% { %@AS@% char date[30]; %@AS@% %@AS@% sample(); /* Call new function. */ %@AS@% outsider(); /* Call new function. */ %@AS@% printf( "Enter today's date: \n" ); %@AS@% gets( date ); %@AS@% printf( "Sample program run on %s\n", date ); %@AS@% } %@AS@% %@AS@% /* Implement the new sample function. */ %@AS@% void sample(void) %@AS@% { %@AS@% printf( "A sample function.\n" ); %@AS@% }%@AE@%%@NL@% %@NL@% The %@AS@% main %@AE@% function calls two new functions defined within the program: %@AS@% %@AS@%sample %@AE@% and %@AS@% outsider%@AE@%. %@NL@% %@NL@% Save the changed file and then choose New from the File menu. Type in a second source file: %@NL@% %@NL@% %@AS@% /* IOB.C: Second module for IO.C */ %@AS@% %@AS@% #include <stdio.h> %@AS@% %@AS@% void outsider(void); %@AS@% %@AS@% void outsider(void) %@AS@% { %@AS@% printf( "This line is from the file IOB.C.\n" ); %@AS@% }%@AE@%%@NL@% %@NL@% Save it as IOB.C. The two source files are combined to produce a multi-module program. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Multiple Modules and the Program List%@AE@%%@EH@%%@NL@% %@NL@% Since the example program now uses two source files, the makefile must be changed to tell PWB which files should be compiled. Choose the Edit Program List command from the Make menu, add the IOB.C file to the list, and save it. When you create multimodule programs, the order of the file names added is inconsequential. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%A program list can include source files (with the .C extension), assembler %@AI@%files (.ASM), object files (.OBJ), library files (.LIB), definition files %@AI@%(.DEF), and resource files (.RC). For example, if you didn't include the %@AI@%graphics libraries in the combined library when you ran the SETUP program, %@AI@%you can place GRAPHICS.LIB in the program list to gain access to graphics %@AI@%functions under DOS.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% At this point you can compile and link the program. %@NL@% %@NL@% When you choose the Rebuild All command from the Make menu, every .C file in the program list is compiled into a .OBJ file. Then all of the .OBJ files are linked with .LIB files to create one .EXE file. %@NL@% %@NL@% If you choose the Build command, the NMAKE utility checks the time and date stamps on the source and object files. If the source code has not changed since the last time a Build command was executed, unchanged files are not recompiled. Consequently, the Build command is often faster than Rebuild All. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030015 @%%@AB@%Compiling and Linking from the Command Line%@AE@%%@EH@%%@NL@% %@NL@% You are not restricted to using the PWB environment to create executable programs. Programs can be compiled and linked with Microsoft C at the DOS or OS/2 command line. %@NL@% %@NL@% The CL.EXE program may be used to compile and link programs. PWB automatically executes CL, or you can manually execute it at the command line. Simply enter CL followed by a space and the name of the source file to create a .EXE program. %@NL@% %@NL@% In addition, a variety of command-line options can be used. For example, %@NL@% %@NL@% %@AS@% CL /AM IO.C%@AE@%%@NL@% %@NL@% causes the program to be compiled using the medium memory model instead of the default small model. Any compiler options should appear before the names of the files to be compiled. %@NL@% %@NL@% You can find a complete list of compiler and linker options in the %@AI@%C %@AI@%Reference%@AE@% or by typing %@NL@% %@NL@% %@AS@% CL /HELP%@AE@%%@NL@% %@NL@% to invoke the on-line reference system. %@NL@% %@NL@% You can also use CL to build multi-module programs by specifying all source files to be compiled: %@NL@% %@NL@% %@AS@% CL IO.C IOB.C%@AE@%%@NL@% %@NL@% This command builds a program called IO.EXE, because IO.C is listed first. %@NL@% %@NL@% Another way to build a multi-module program is to compile the two files and then manually link them: %@NL@% %@NL@% %@AS@% CL /c IO.C %@AS@% CL /c IOB.C %@AS@% LINK IO.OBJ IOB.OBJ%@AE@%%@NL@% %@NL@% The /c option instructs CL to compile but not link. Once the .OBJ files have been created, use the linker to create the executable file. %@NL@% %@NL@% Since a makefile named IO.MAK has already been created using PWB, you can also use the NMAKE utility to build IO.EXE. Simply pass it the name of the makefile: %@NL@% %@NL@% %@AS@% NMAKE /F IO.MAK%@AE@%%@NL@% %@NL@% If you don't provide /F and a file name, NMAKE searches for a file named MAKEFILE. %@NL@% %@NL@% For a complete list of compiler, linker, and NMAKE options, see %@AI@%Advanced %@AI@%Programming Techniques%@AE@%, the%@AI@% C Reference%@AE@%, or the on-line reference system. %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00030016 @%%@AB@%Debugging Programs%@AE@%%@EH@%%@NL@% %@NL@% PWB has a variety of resources available for debugging programs. They range from simple compile- and link-error messages to sophisticated source browsing and source- or assembly-level debugging. %@NL@% %@NL@% When compile-time errors occur, the cursor moves to the line that caused the first error and a brief description of the error appears in the reference bar. Use the Next Error and Previous Error commands in the Search menu to move the cursor to the lines where other errors occurred. %@NL@% %@NL@% To view a complete list of errors, choose the Compile Results command from the View menu. Use the Set Error command in the Search menu to select the error under the cursor as the current error. This command synchronizes the source and error windows so that the source-code line that contains the error appears in the source window. %@NL@% %@NL@% The Microsoft Advisor can be used to display on-line help about the error. In the Compile Results window, move the cursor to the error number and press F1. %@NL@% %@NL@% PWB incorporates a source-code browser and interfaces with the CodeView debugger. The Browser displays information about function and data relationships. CodeView is a window-oriented symbolic debugger that lets you step through your code and examine variables and data as the program executes. %@NL@% %@NL@% Before a program can take advantage of the Browser or CodeView, the appropriate %@AB@%debug%@AE@% or %@AB@%browse%@AE@% switches must be set with the C Compiler Options and Browse Options commands in the Options menu. As an example, build one of the sample programs previously listed with the debug options to experiment with the Browser and CodeView. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030017 @%%@AB@%Using the Browser%@AE@%%@EH@%%@NL@% %@NL@% The commands on the Browse menu are referred to collectively as the PWB Source Browser. These commands allow you to search a database comprising selected files, to get a list of references and definitions, build a call tree and outline, or create a list of relationships among program symbols. Figure 3.7 shows the functions called by %@AS@% main %@AE@% in IO.C. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% Before using these commands, you must define the database the Source Browser is going to search. %@NL@% %@NL@% To define a database: %@NL@% %@NL@% %@NL@% 1. Generate a program list using the Set Program List command in the Make menu. The files contained in the program list make up the database.%@NL@% %@NL@% 2. Choose Browse Options from the Options menu. You must select the Generate Browse Information field in the dialog box to create the Source Browser database. The rest of the fields on this dialog box offer you choices of how to build the database; they are optional.%@NL@% %@NL@% 3. Build your program using the commands in the Make Menu. When you build the program, a file with the same program-list root name and a .BSC (Browser Source Cache) extension is created. This file contains reference information that the Browser uses.%@NL@% %@NL@% %@NL@% Once you have completed these steps, Browse Menu commands are ready for you to use. %@NL@% %@NL@% %@NL@% ■ The Goto Definition command provides a list of symbols and variables that occur within include files and modules. You can immediately open the file at the line number where the definition occurred by selecting the <OK> button.%@NL@% %@NL@% ■ The Goto Reference command displays a list of files and line numbers where symbols and variables have been referenced in include files and modules.%@NL@% %@NL@% ■ The View Relationships command provides detailed information about various portions of your program. You can examine functions, macros, types, and variables by their use, definition, or inclusion in include files and modules.%@NL@% %@NL@% ■ The List References command displays references to functions, macros, types, and variables. You can move the cursor to a reference, and then use the Goto Definition or Goto Reference commands to show occurrences of the reference.%@NL@% %@NL@% ■ The Call Tree command displays a tree structure of function calls within the program.%@NL@% %@NL@% %@NL@% For additional information about the Browser, refer to the on-line reference system. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%You can create a Browser information file with the CL (command-line) %@AI@%compiler by using the /FR or /Fr options. This creates a .SBR file which can %@AI@%be converted to a .BSC file with the PWBRMAKE.EXE utility.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030018 @%%@AB@%Debugging with CodeView%@AE@%%@EH@%%@NL@% %@NL@% PWB provides access to the Microsoft CodeView debugger. After a program has been built, CodeView can be used to step through the source code, displaying output, registers, and variables as each line is executed (see Figure 3.8). You can set breakpoints and watchpoints to further aid in debugging. CodeView uses the Microsoft Advisor to provide on-line help about its operation and options, in addition to information about any C keywords in the program you are debugging. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTES %@AI@%CodeView version 3.0 is compatible with releases of OS/2 later than version %@AI@%1.0. If you encounter problems exiting CodeView, you either have an older %@AI@%version of OS/2 or the wrong version of the DOSCALLS.DLL file.%@AE@%%@NL@% %@AI@%If you use CodeView from the OS/2 DOS compatibility box, be sure the /S %@AI@%(Swap Screen in Buffers) option is set in the CodeView Options dialog box. %@AI@%If the option is not set, the mouse cursor is not displayed while you are %@AI@%debugging.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@4@%%@AB@%Preparing a Debug Build%@AE@%%@EH@%%@NL@% %@NL@% It's easy to create a debug version of a program so it can be examined with CodeView. %@NL@% %@NL@% First, choose C Compiler Options from the Options menu, then select the Set Debug Options button. This dialog box contains a variety of settings for a debug build. Although most of the dialog box options can be set to your preference, you must check the CodeView option under the Debug Information heading, which is on by default. In addition, code optimization options, which are off by default, should be unchecked so that code movement does not affect debugging. %@NL@% %@NL@% The CodeView Options command in PWB's Options menu provides a variety of choices for configuring CodeView. These include two-monitor debugging, memory allocation, and the number of lines on the screen. For now, use the default settings initially displayed. %@NL@% %@NL@% In order for the compiler to build a program that contains the necessary CodeView information, you must check the Debug option, set in the dialog box displayed by the Build Options command in the Options menu. In addition, the CodeView option, which is on by default, must be selected in the Set Debug Options dialog box. %@NL@% %@NL@% To demonstrate how CodeView works, set the debug options as listed above, then rebuild the IO.C program using the Rebuild All command in the Make menu. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Examining the Program%@AE@%%@EH@%%@NL@% %@NL@% After your program has been built with the appropriate debug options, choose the Debug command from the Run menu. PWB immediately transfers control to the CodeView debugger, loading the current project as indicated in the program list. %@NL@% %@NL@% When you switch from PWB to CodeView, the program appears in the source window. Choose the Source command in the Options menu or type the %@AS@% S+ %@AE@% command in CodeView's command window to display the code in C, the %@AS@% S- %@AE@% command for assembly language, or the %@AS@% S& %@AE@% command for a combination of the two. With C or mixed-source options, a line number appears to the left of each line of source code as a reference. %@NL@% %@NL@% In addition to the source code, commands in the View menu show windows displaying memory, registers, and local variables. CodeView windows are similar to PWB windows in that they can be scrolled, sized, and closed. Multiple windows can appear on the screen at once, displaying a variety of information. A list of shortcut keys and buttons appears at the bottom of the screen. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Setting Watch Expressions and Breakpoints%@AE@%%@EH@%%@NL@% %@NL@% Watch expressions and breakpoints are optional CodeView settings that display variable values and interrupt execution of the program. %@NL@% %@NL@% A "watch expression" is a variable within the program that CodeView continually watches. Watch expressions are displayed with the Watch command in the View menu. As the value of a variable changes, the value changes in the watch window. %@NL@% %@NL@% To add a variable to the watch expression list, select the variable and choose the Add Watch command from the Watch menu or use the W%@AB@% %@AE@%command in the command window. You can optionally enter the variable name in the dialog box. Watch expressions are removed with the Delete Watch command in the watch menu or with the Y command in the command window. %@NL@% %@NL@% To set a watch variable in the IO.C file, use the cursor to highlight the %@AS@% %@AS@%date %@AE@% variable in the CodeView source window. Then choose the Add Watch command from the Watch menu. The %@AS@% date %@AE@% variable appears in the Expression text box. Press ENTER or click the OK button to store the watch variable. %@NL@% %@NL@% CodeView also incorporates a temporary watch option called a QuickWatch. Highlight a variable in the source window with the mouse or cursor. Choose the QuickWatch command from the Watch menu. A dialog box appears with the current value of the variable. You can add any QuickWatch variable to the watch window with the Add Watch dialog option. %@NL@% %@NL@% You can expand any structures or arrays that are set as watch expressions (identified with a "+" in the watch window) to show individual elements. Position the cursor on the variable name and either double-click the Left mouse button or press ENTER (see Figure 3.9). %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% A "breakpoint" is an instruction that tells CodeView to interrupt execution at a certain location or when an expression becomes true. %@NL@% %@NL@% Use breakpoints to gain control of the program before an error occurs and to quickly move to a part of the program you want to trace. When CodeView stops at a breakpoint, you can then single-step or trace through instructions until you find the problem. %@NL@% %@NL@% Set a breakpoint by positioning the cursor on the line at which you want the program to stop and then pressing F9. Alternatively, you can choose the Set Breakpoint command from the Watch menu. A dialog box presents a series of options for setting types of breakpoints. Breakpoints are modified or deleted with the Edit Breakpoints command in the Watch menu. %@NL@% %@NL@% Set a breakpoint in the IO.C file by moving the cursor in the CodeView source window to the line that reads %@NL@% %@NL@% %@AS@% printf( "A sample function.\n" );%@AE@%%@NL@% %@NL@% From the Watch menu, choose the Set Breakpoint command. The number of the line the cursor appears on is displayed in the dialog box. Press ENTER or click the OK button with the mouse to store the breakpoint. After the breakpoint has been set, the line it occurs on is highlighted. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Running the Program%@AE@%%@EH@%%@NL@% %@NL@% CodeView runs your program and displays each source line as it executes. If an error occurs, CodeView stops at the instruction that caused the error. CodeView also halts execution at breakpoints. %@NL@% %@NL@% If a program requires arguments to be passed from the command line, these arguments can be entered with the Set Runtime Arguments command in the Run menu. %@NL@% %@NL@% Table 3.2 lists several CodeView commands for running a program. %@NL@% %@NL@% %@AB@%Table 3.2 CodeView Run Commands%@AE@% %@TH: 12 473 02 06 08 64 @%Key Name Use%@AB@%──────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%F5 Go Executes the program to the next breakpoint, error, or end of the programF8 Trace Executes a single lineF10 Step Executes a single line, but doesn't trace into functions%@AB@%──────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%%@TE: 12 473 02 06 08 64 @% Run commands can be entered by pressing the appropriate key or clicking the commands at the bottom of the screen. With the Trace and Step commands, each line is highlighted as it is executed. The Go command executes each line until it stops at an error, a breakpoint, or the end of the program. If you choose the Animate command, each line is highlighted as it executes. To force the run commands to start at the beginning of the program, use the Restart command in the Run menu. %@NL@% %@NL@% The Screen Swap setting in the Options menu controls display of the output. If the option is turned on, CodeView switches to the output screen after each line executes, and then switch back to the source window. You can turn the option off during portions of your program that don't access the screen to reduce the distracting flicker of switching screens. If you want to view the output screen longer, choose the Output command from the View menu. Press any key to exit the output screen and return to CodeView. %@NL@% %@NL@% In addition to single-stepping through a program, the Animate command in the Run menu automatically steps through the program, highlighting each line as it proceeds. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030019 @%%@AB@%Running IO.C%@AE@%%@EH@%%@NL@% %@NL@% To demonstrate some of these commands with the IO.C program, make the source window active by pressing F6 or by clicking its title bar, then choose the Restart command from the Run menu. This command clears memory and prepares the program to start execution at the first line of %@AS@% main%@AE@%. %@NL@% %@NL@% Press F5 or select the Go button at the bottom of the screen to start the program. The program executes until it reaches the breakpoint set at the %@AS@% %@AS@%sample %@AE@% function. %@NL@% %@NL@% Use F10 or the Step button to execute each statement until you come to the %@AS@% %@AS@%outsider %@AE@% function. If you press F8 or the Trace button at the %@AS@% outsider %@AE@% function, CodeView traces through each statement of the function. If you use the Step button or F10, CodeView executes the function without tracing through it and moves on to the next program statement. %@NL@% %@NL@% Continue stepping through the program until you reach the %@AS@% gets ( date ) %@AE@% statement. Press F10; CodeView switches to the output screen and prompts you to enter a date. Type today's date and press ENTER. CodeView regains control and moves to the next statement. %@NL@% %@NL@% Since %@AS@% date %@AE@% was set as a watch variable and now contains data, use the mouse or press F6 to make the watch window active. Move the cursor to %@AS@% date %@AE@% and press ENTER. This expands the display of the array and shows all of the elements. Press ENTER again while the cursor is on %@AS@% date %@AE@% to contract the array. %@NL@% %@NL@% Because %@AS@% date %@AE@% is also a local variable, it is shown in the local window with all variables local to the current function. You can expand or contract data in the local and the watch windows . %@NL@% %@NL@% Another way to view the contents of %@AS@% date %@AE@% is to put the cursor on it in the CodeView source window and choose QuickWatch from the Watch menu. The %@AS@% date %@AE@% variable is immediately displayed in its expanded form. Press ENTER or click the OK button to leave the dialog box. %@NL@% %@NL@% Press F10 to finish stepping through the program. A dialog box informs you that the program has completed execution normally. Press ENTER to clear the dialog box and complete your debugging session. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00030020 @%%@AB@%Debugging IO.C%@AE@%%@EH@%%@NL@% %@NL@% To see how CodeView deals with a bug in a program, use the Exit command in the File menu to return to PWB, then add this function to the IO.C program, and call it from %@AS@% main%@AE@%: %@NL@% %@NL@% %@AS@% void bounds_error(void) %@AS@% { %@AS@% int loop, the_num[10]; %@AS@% %@AS@% for(loop = 0; loop < 15; loop++) %@AS@% the_num[loop] = loop; }%@AE@%%@NL@% %@NL@% Set the appropriate debug options, rebuild the program, and return to CodeView. %@NL@% %@NL@% Use the F8 Trace command to execute the program. The program runs until it reaches the %@AS@% for %@AE@% statement in the %@AS@% bounds_error %@AE@% function, where the array bounds are exceeded. The output window reports an error while a CodeView dialog box indicates the program has terminated. At this point you can return to PWB, locate the error, and correct it. %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00030021 @%%@AB@%Getting More Details%@AE@%%@EH@%%@NL@% %@NL@% PWB, the compiler, the linker, NMAKE, and CodeView all have other features and options that go beyond the scope of this introduction. %@NL@% %@NL@% Refer to %@AI@%Advanced Programming Techniques%@AE@% for information about PWB, NMAKE, CodeView, and other tools, and the %@AI@%C Reference%@AE@% for a comprehensive listing of all commands and options for the applications included with Microsoft C. %@NL@% %@NL@% In addition, information about any component of the Professional Development System can be accessed through the Microsoft Advisor reference system. For a complete discussion of the on-line reference, see Chapter 4. %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@NL@% %@CR:C6A00040001 @%%@1@%%@AB@%Chapter 4 Using the On-Line Reference%@AE@%%@EH@%%@NL@% %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@% %@NL@% Microsoft C offers two types of on-line reference systems: %@NL@% %@NL@% %@NL@% ■ The Microsoft Advisor, found within the Programmer's WorkBench (PWB) and CodeView environments.%@NL@% %@NL@% ■ The QuickHelp program, accessed from the OS/2 or DOS command line.%@NL@% %@NL@% %@NL@% Both systems provide the same information on important C topics and utilities provided with the Professional Development System, which include the C language, run-time libraries, CodeView, and PWB. %@NL@% %@NL@% The first section of this chapter, "Structure of the Microsoft Advisor," outlines the structure and contents of the on-line reference database. The second section, "Navigating Through the Microsoft Advisor," takes you on a quick tour of the system. The third section, "Using QuickHelp," explains how to use the QuickHelp program and how it differs from the Microsoft Advisor. %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00040002 @%%@AB@%Structure of the Microsoft Advisor%@AE@%%@EH@%%@NL@% %@NL@% The Microsoft Advisor can be compared to a librarian managing a collection of books. Each book, or help file, has its own table of contents, index, and pages of information. The Advisor organizes the help files with a global contents and index. All of the files are listed, and their specific tables of contents and indexes can be accessed through the global references. The global contents screen is shown in Figure 4.1. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% You can access a variety of information from the on-line reference system. Information regarding the C language, run-time libraries, errors, and the reference system itself is available. %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00040003 @%%@AB@%Navigating Through the Microsoft Advisor%@AE@%%@EH@%%@NL@% %@NL@% You request information about a topic in a window by positioning the cursor over it and pressing F1 or clicking the Right mouse button once. The help system then searches through the help files for information about the topic. If it finds the topic, the help system displays information in the help window. If help cannot be found for a particular word or symbol, a message informs you that no information is associated with the topic. Sometimes, a topic with the same name occurs in several help files. In such cases, a dialog box is displayed in which you can select the context of the topic. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00040004 @%%@AB@%Using the Help Menu%@AE@%%@EH@%%@NL@% %@NL@% The simplest method for accessing the on-line reference is by using the commands found in the Help menu. All of these commands present information in the Help window. %@NL@% %@NL@% %@AB@%Command%@AE@% %@AB@%Description%@AE@% %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@% Index Displays the global index of help-file categories (see Figure 4.2). Contents Displays the global contents screen for the categories found in the help files. Topic: Provides information about the topic that the cursor is currently positioned over. If information about the topic is available, the topic's name is appended to the Topic: command. Otherwise, this menu option is grayed. Help on Help Displays information about using the on-line reference itself. Next Is useful if a topic with the same name appears in more than one help file. This option locates the next occurrence of the topic name and displays the information associated with it. %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00040005 @%%@AB@%Using the F1 Key%@AE@%%@EH@%%@NL@% %@NL@% You can use the F1 key to get information about any menu command or PWB dialog box, as well as information on C keywords, operators, and run-time library functions. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Menu Help%@AE@%%@EH@%%@NL@% %@NL@% To view information about a menu item, first pull down the menu, then %@NL@% %@NL@% %@NL@% ■ Use the cursor keys to highlight the command, and press F1, or%@NL@% %@NL@% ■ Move the mouse cursor on the command and click the Right mouse button%@NL@% %@NL@% %@NL@% Figure 4.3 shows the help information for the Cut command in the Edit menu. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% %@NL@% %@4@%%@AB@%Keyword and Library-Function Help%@AE@%%@EH@%%@NL@% %@NL@% To view information about a C keyword, operator, or run-time library function, %@NL@% %@NL@% %@NL@% ■ Put the cursor on the keyword or function name, and press F1, or%@NL@% %@NL@% ■ Click the command with the Right mouse button%@NL@% %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Dialog-Box Help%@AE@%%@EH@%%@NL@% %@NL@% To view information about a PWB dialog box, simply press F1 while the dialog box is displayed, or click on the help button. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00040006 @%%@AB@%Using Hyperlinks%@AE@%%@EH@%%@NL@% %@NL@% Hyperlinks are cross-references that connect related topic information. %@NL@% %@NL@% Hyperlinks enclosed by the < and > characters are called "buttons." Navigate through the on-line help system by using these buttons. %@NL@% %@NL@% You can press TAB to move to the next hyperlink button within the current help window. SHIFT+TAB moves back to the previous button. Typing any letter moves the cursor to the next button that begins with the letter; holding SHIFT down and typing a letter moves the cursor backward. %@NL@% %@NL@% The Microsoft Advisor also recognizes C keywords, library functions, constants defined by Microsoft C, and similar identifiers as hyperlinks, but they are unmarked hyperlinks. Unmarked hyperlinks are recognized by the Microsoft Advisor wherever they appear in the help-information text or %@AI@%in %@AI@%your source code%@AE@%. However, an unmarked hyperlink is not delimited with the < and > characters, and you can't move to it with the TAB key. An unmarked hyperlink can only be executed by placing the cursor on it and pressing F1, or pointing to it with the mouse cursor and clicking the Right mouse button. %@NL@% %@NL@% You can access a hyperlink in several ways. First move either the mouse or text cursor to a hyperlink, then either %@NL@% %@NL@% %@NL@% ■ Press F1%@NL@% %@NL@% ■ Click the Right mouse button%@NL@% %@NL@% ■ Click the Left mouse button twice (double-click)%@NL@% %@NL@% %@NL@% Highlighted button hyperlinks can also be executed by pressing ENTER or SPACEBAR. %@NL@% %@NL@% Any of these actions displays information about the topic the cursor is positioned on. If the topic isn't a hyperlink, a message informs you that no information on the topic could be found. %@NL@% %@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@% NOTE %@AI@%CodeView uses the Right mouse button differently in the source window. %@AI@%Clicking the Right button in the source window executes the program to the %@AI@%line the mouse was clicked on. However, once the help window is displayed, %@AI@%the Right mouse button can be used to select hyperlinks.%@AE@%%@NL@% ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00040007 @%%@AB@%Using Help Windows and Dialog Boxes%@AE@%%@EH@%%@NL@% %@NL@% The Microsoft Advisor displays information in windows or dialog boxes. Help windows and dialog boxes function the same as other windows and dialog boxes found in PWB and CodeView. For a complete description of windows and dialog boxes, refer to Chapter 3, "Using the Programmer's WorkBench." %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Using the Help Window%@AE@%%@EH@%%@NL@% %@NL@% The help window displays various contents, indexes, and information about selected topics. Some screens of information are larger than the help window; information beyond the window borders can be viewed by using the scroll bars or the cursor-movement keys. The - u - symbol indicates the end of information in the help window. %@NL@% %@NL@% %@AB@%Navigating with Hyperlink Buttons%@AE@% - At the top of the help window is a row of buttons that are useful for moving through the reference system: %@NL@% %@NL@% %@AB@%Button%@AE@% %@AB@%Description%@AE@% %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@% < Up > Moves upward in the hierarchy of help screens. Since information is ordered in a logical way, moving from the general to the specific, this command is useful for moving up the information tree. < Contents > Displays the global contents screen. This command is useful because it always returns you to a known point in the on-line help system hierarchy. < Index > Displays the global index list. Selecting an item from the list displays the index for that category. < Back > Moves you to the last on-line help screen you saw. Screens on a particular topic frequently are physically grouped together in a help file. You can press CTRL+F1 to display information about the next physical topic in the help file. %@NL@% %@NL@% %@AB@%Viewing the Previous Help Screen%@AE@% - The Microsoft Advisor remembers the last 20 help screens you've accessed. To return to a previous screen, use the < Back > button or hold down the ALT key and press F1 as many times as necessary to return to the screen you want to see. The help screen that appears is active; you can ask for help on any of its hyperlinks or topics. %@NL@% %@NL@% You can always return to the global contents screen by pressing SHIFT+F1. %@NL@% %@NL@% %@AB@%Copying and Pasting Help Information%@AE@% - Any text that appears in the help window can easily be copied to another window. For example, to test an example program from the help window, you only have to copy it to the source window and compile it. %@NL@% %@NL@% To copy and paste using the keyboard, follow these steps: %@NL@% %@NL@% %@NL@% 1. Move the cursor to the beginning or the end of the text you want to select. Hold down the SHIFT key and move the cursor to the other end of the text. The text is now highlighted.%@NL@% %@NL@% 2. Execute the Copy command: Press ALT to activate the menus, E for Edit, then C for Copy. Note that the menu lists the shortcut command (CTRL+INS), which can be substituted for ALT+E, then C.%@NL@% %@NL@% 3. Press F6 to switch to another window. Position the cursor where you want to insert the text, and execute the Paste command: ALT+E then P, or use the SHIFT+INS shortcut. The text from the help window is inserted at the current cursor position.%@NL@% %@NL@% %@NL@% To copy and paste using the mouse, follow these steps: %@NL@% %@NL@% %@NL@% 1. Click the Left mouse button and drag the cursor (hold down the button while moving the mouse) to select the text you want to copy.%@NL@% %@NL@% 2. Choose Copy from the Edit menu (or press CTRL+INS).%@NL@% %@NL@% 3. Move the mouse cursor to the location where you want to insert the text, and click once. Then choose Paste from the Edit menu. The text from the help window is inserted at the current cursor position.%@NL@% %@NL@% %@NL@% %@AB@%Closing the Help Window%@AE@% - Once you're through working with the reference system, you can close the active help window and return to the source window by %@NL@% %@NL@% %@NL@% ■ Pressing ESC%@NL@% %@NL@% ■ Clicking the Close button in the upper left corner of the window with the Left mouse button%@NL@% %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Using Help Dialog Boxes%@AE@%%@EH@%%@NL@% %@NL@% Help dialog boxes contain information about menu commands and their dialog boxes. A help dialog box differs from a help window in that it is displayed over the source window and any other windows that are displayed. Unlike the help window, a help dialog box must be closed before you can execute any menu commands. The Cancel button in the lower right portion of the dialog box closes the help dialog box. %@NL@% %@NL@% To view information about any PWB dialog box, you can %@NL@% %@NL@% %@NL@% ■ Press F1%@NL@% %@NL@% ■ Click the Help button in the dialog box with the Left mouse button%@NL@% %@NL@% %@NL@% Either of these commands causes a help dialog box to appear. To close a help dialog box, %@NL@% %@NL@% %@NL@% ■ Press ESC%@NL@% %@NL@% ■ Click the dialog box's Cancel button by using the Left mouse button%@NL@% %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00040008 @%%@AB@%Accessing Different Types of Information%@AE@%%@EH@%%@NL@% %@NL@% This section presents some strategies for accessing the different types of information available within the on-line reference system. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Keyword Information%@AE@%%@EH@%%@NL@% %@NL@% To get information about any keyword, operator, symbolic constant, or library function, display the appropriate index for the keyword, select the keyword's first letter from the index, then scroll down the list of entries and select the topic's hyperlink. If you know the exact name of a keyword, it is often quicker to simply type it in the source window and press F1 to locate it through an index. %@NL@% %@NL@% Information about keywords can also be viewed by using the %@AB@%arg%@AE@% command and entering the keyword with F1 in the %@AB@%arg%@AE@% command dialog box. Assuming that you have the %@AB@%arg%@AE@% function assigned to %@AS@% alt+a%@AE@%, the following series of keystrokes displays help on the %@AB@%printf%@AE@% function: %@NL@% %@NL@% %@AS@% alt+a printf F1%@AE@%%@NL@% %@NL@% Figure 4.4 shows the information screen that then appears. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% When information about a function is shown in the help window, two additional hyperlink buttons are displayed. %@NL@% %@NL@% %@NL@% ■ < Description > provides a detailed explanation of the function. When the information is displayed, the button changes to < Summary >. Click this button to return to the summarized information about the function.%@NL@% %@NL@% ■ < Example > displays C source code that provides an example of how the function is used.%@NL@% %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Topical Information%@AE@%%@EH@%%@NL@% %@NL@% The on-line reference system is useful when you want an overview of the available reference topics, or when you only have a general idea of what information you need. Start with the global contents screen, then select any hyperlinks that relate to the topic. You can traverse the hyperlinks until you locate the necessary information. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Menu and Dialog-Box Information%@AE@%%@EH@%%@NL@% %@NL@% You can get information about any menu command or dialog box by pressing F1 when the menu command is highlighted or the dialog box is displayed. This is helpful when you are first learning to use the Professional Development System and are not completely familiar with all of the features. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Error Information%@AE@%%@EH@%%@NL@% %@NL@% The Microsoft Advisor provides information about compiler and linker error messages. %@NL@% %@NL@% To find the meaning of an error message using the keyboard, %@NL@% %@NL@% %@NL@% 1. Press F6 to move the cursor to the error window%@NL@% %@NL@% 2. Position the cursor on the error number%@NL@% %@NL@% 3. Press F1%@NL@% %@NL@% %@NL@% or with the mouse, %@NL@% %@NL@% %@NL@% 1. Position the mouse cursor on the error number%@NL@% %@NL@% 2. Click the Right mouse button%@NL@% %@NL@% %@NL@% Help on error messages is also available directly from the PWB source window by entering the %@AB@%arg%@AE@% command with the error number and its alphabetic prefix, and then pressing F1. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00040009 @%%@AB@%Specifying Temporary Help Files%@AE@%%@EH@%%@NL@% %@NL@% You can temporarily load other help files using the Environment command in the PWB Options menu. The Microsoft Advisor searches help files you specify in this text box before it searches the standard Development System help files as specified by the HELPFILES environment variable. Use the help files text box to override (for the current session only) the help-file path defined in the HELPFILES variable. When programming with mixed languages, you may want to temporarily load the help files for each of the languages you're using. %@NL@% %@NL@% %@NL@% %@2@%%@CR:C6A00040010 @%%@AB@%Using QuickHelp%@AE@%%@EH@%%@NL@% %@NL@% QuickHelp is a separate application that provides access to any help file. It uses the same help files as the Microsoft Advisor, and presents information about topics in the same way. QuickHelp is designed for the developer who prefers using command-line utilities or another editor, and doesn't have access to the Microsoft Advisor through PWB. %@NL@% %@NL@% Major utilities and applications that come with the Microsoft C package invoke QuickHelp and display related information if you use the /HELP switch. You can also use QuickHelp from the command line, as explained in the following sections. Once you are in the QuickHelp program, select which help file you want to view. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00040011 @%%@AB@%Using the /HELP Switch%@AE@%%@EH@%%@NL@% %@NL@% You can get immediate information on major components of Microsoft C by using the /HELP switch. %@NL@% %@NL@% For example, to learn about the LIB utility, enter %@NL@% %@NL@% %@AS@% LIB /HELP%@AE@%%@NL@% %@NL@% QuickHelp will run and immediately display information about LIB. %@NL@% %@NL@% %@NL@% %@3@%%@CR:C6A00040012 @%%@AB@%Using the QH Command%@AE@%%@EH@%%@NL@% %@NL@% You can also run QuickHelp by typing QH at the DOS or OS/2 command line. Specify an application to get help about, such as %@NL@% %@NL@% %@AS@% QH LIB.EXE%@AE@%%@NL@% %@NL@% In addition to information about programs, QuickHelp can also display information about run-time errors. You can type the error number with its alphabetic prefix after the QH command at the DOS or OS/2 command line. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Opening and Closing Help Files%@AE@%%@EH@%%@NL@% %@NL@% If no file name is specified when QuickHelp is run, it looks for the environment variable HELPFILES, and opens all listed .HLP files. If the HELPFILES variable isn't present, all .HLP files in directories specified by the PATH environment variable are loaded. %@NL@% %@NL@% Choose the List Database command on the File menu to view a list of all the currently open help files. %@NL@% %@NL@% To open additional help files, %@NL@% %@NL@% %@NL@% ■ Choose the Open Database command from the File menu.%@NL@% %@NL@% ■ Type the fully qualified path name of the help file to be opened in the dialog box that appears. You can specify all help files in a directory with *.HLP.%@NL@% %@NL@% ■ Press ENTER or click the OK button with the Left mouse button.%@NL@% %@NL@% %@NL@% To close an open help file, %@NL@% %@NL@% %@NL@% ■ Choose the Close Database command from the File menu.%@NL@% %@NL@% ■ Use the mouse or keyboard to select which help file you would like to close from the list of help files displayed in the menu%@NL@% %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Displaying a Topic%@AE@%%@EH@%%@NL@% %@NL@% You can view information about a topic by using the Search command in the View menu. When topic information is displayed, it is shown in the same format as information presented by the Microsoft Advisor. %@NL@% %@NL@% To display a topic from any of the open help files, %@NL@% %@NL@% %@NL@% ■ Choose the Search command from the View menu%@NL@% %@NL@% ■ Type the topic you want information about in the Search dialog box (the search is not case sensitive)%@NL@% %@NL@% ■ Press ENTER or click the OK button with the Left mouse button%@NL@% %@NL@% %@NL@% QuickHelp begins searching for the topic in the open help files. If the topic cannot be found, a dialog box informs you that the search failed. If the search is successful, information about the topic is displayed in the QuickHelp window. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Navigating Through Topics%@AE@%%@EH@%%@NL@% %@NL@% A series of commands on the View menu allow you to selectively display topics. These commands include the following: %@NL@% %@NL@% %@AB@%Command%@AE@% %@AB@%Description%@AE@% %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@% View History Displays a list of all the topics that have recently been displayed. You can view a topic in the list by selecting it and clicking the Right mouse button or pressing ENTER. View Last Displays the last topic you looked at. View Back Moves backward one topic in the help file. View Next Displays the next topic in the help file. %@NL@% %@4@%%@AB@%Using the QuickHelp Window%@AE@%%@EH@%%@NL@% %@NL@% The QuickHelp window (see Figure 4.5) is similar in function to the Microsoft Advisor help window, described earlier in this chapter. Information that doesn't fully fit in a window can be scrolled, and hyperlinks are used to display additional information. %@NL@% %@NL@% %@AU@%(This figure may be found in the printed book).%@AE@%%@NL@% %@NL@% The main differences between the two windows are %@NL@% %@NL@% %@NL@% ■ Information presented in QuickHelp cannot selectively be copied. See the section "Copying and Pasting in QuickHelp" that follows for more information.%@NL@% %@NL@% ■ The QuickHelp window cannot be closed.%@NL@% %@NL@% ■ Any information that appears on the screen can be sent to a printer by using the Print command in the File menu.%@NL@% %@NL@% %@NL@% %@NL@% %@4@%%@AB@%Copying and Pasting in QuickHelp%@AE@%%@EH@%%@NL@% %@NL@% In order to transfer information, you must first specify a new file with the Rename Paste File command in the File menu. Once the file is specified, choose either the Current Window or the Current Topic command in the Paste menu to transfer the text to that file. Be sure to specify a new file when you paste, since QuickHelp overwrites text in an existing file. %@NL@% %@NL@% %@NL@% %@4@%%@AB@%More About QuickHelp%@AE@%%@EH@%%@NL@% %@NL@% In addition to the features mentioned above, QuickHelp has a variety of other options such as changing the appearance of the help window, searching for text within topics, and controlling the function of the Right mouse button. %@NL@% %@NL@% To learn more about QuickHelp's features, make sure the QH.HLP file is loaded, then do one of the following: %@NL@% %@NL@% %@NL@% ■ Press F1 to view QuickHelp's on-line reference%@NL@% %@NL@% ■ Choose a menu command and press F1 or click the Right mouse button to get information about it%@NL@% %@NL@% ■ Refer to the %@AI@%C Reference%@AE@% guide for a list of QuickHelp options%@NL@% %@NL@% %@NL@% %@NL@% %@NL@%