Bull AIX 5.2 - General Programming Guide

Category
Software
Type
Programming Guide
Bull
AIX 5L General Programming Concepts
Writing and Debugging Programs
AIX
86 A2 35EF 02
ORDER REFERENCE
Bull
AIX 5L General Programming Concepts
Writing and Debugging Programs
AIX
Software
May 2003
BULL CEDOC
357 AVENUE PATTON
B.P.20845
49008 ANGERS CEDEX 01
FRANCE
86 A2 35EF 02
ORDER REFERENCE
The following copyright notice protects this book under the Copyright laws of the United States of America
and other countries which prohibit such actions as, but not limited to, copying, distributing, modifying, and
making derivative works.
Copyright
Bull S.A. 1992, 2003
Printed in France
Suggestions and criticisms concerning the form, content, and presentation of
this book are invited. A form is provided at the end of this book for this purpose.
To order additional copies of this book or other Bull Technical Publications, you
are invited to use the Ordering Form also provided at the end of this book.
Trademarks and Acknowledgements
We acknowledge the right of proprietors of trademarks mentioned in this book.
AIX
R
is a registered trademark of International Business Machines Corporation, and is being used under
licence.
UNIX is a registered trademark in the United States of America and other countries licensed exclusively through
the Open Group.
Linux is a registered trademark of Linus Torvalds.
The information in this document is subject to change without notice. Groupe Bull will not be liable for errors
contained herein, or for incidental or consequential damages in connection with the use of this material.
Contents
About This Book ................................xi
Who Should Use This Book .............................xi
Highlighting ...................................xi
Case-Sensitivity in AIX ...............................xi
ISO 9000 ....................................xi
Related Publications................................xi
Chapter 1. Tools and Utilities ............................1
Entering a Program into the System ..........................1
Checking a Program ................................1
Compiling and Linking a Program ...........................1
Subroutines ...................................2
Shell Commands .................................2
Related Information ................................2
Chapter 2. Curses Library .............................5
Terminology ...................................5
Naming Conventions................................5
Structure of a Curses Program ............................6
Return Values ..................................6
Initializing Curses .................................6
Windows in the Curses Environment ..........................7
Manipulating Window Data with Curses .........................8
Controlling the Cursor with Curses ..........................11
Manipulating Characters with Curses .........................11
Understanding Terminals with Curses .........................21
Working with Color ................................26
Manipulating Video Attributes ............................26
Manipulating Soft Labels ..............................29
Curses Compatibility ...............................29
List of Additional Curses Subroutines .........................29
Chapter 3. Debugging Programs ..........................33
adb Debug Program Overview............................33
Getting Started with the adb Debug Program ......................33
Controlling Program Execution ...........................35
Using adb Expressions ..............................39
Customizing the adb Debug Program .........................41
Computing Numbers and Displaying Text ........................44
Displaying and Manipulating the Source File with the adb Program ..............45
adb Debug Program Reference Information .......................52
Example adb Program: adbsamp...........................56
Example adb Program: adbsamp2 ..........................57
Example adb Program: adbsamp3 ..........................57
Example of Directory and i-node Dumps in adb Debugging .................58
Example of Data Formatting in adb Debugging .....................60
Example of Tracing Multiple Functions in adb Debugging ..................62
dbx Symbolic Debug Program Overview ........................65
Using the dbx Debug Program ...........................65
Displaying and Manipulating the Source File with the dbx debug Program............68
Examining Program Data .............................72
Debugging at the Machine Level with dbx .......................78
Customizing the dbx Debugging Environment ......................80
© Copyright IBM Corp. 1997, 2003 iii
List of dbx Subcommands .............................82
Related Information................................84
Chapter 4. Error-Logging Overview .........................85
Error-Logging Facility ...............................85
Managing Error Logging ..............................86
Error Notification .................................89
Error Logging Tasks ...............................92
Error Logging and Alerts ..............................99
Error Logging Controls ..............................99
Related Information ...............................100
Chapter 5. File Systems and Logical Volumes ....................103
File Types...................................103
Working With JFS Directories ...........................105
Working with JFS2 Directories ...........................107
Working with JFS i-nodes .............................109
Working with JFS2 i-nodes ............................110
Allocating JFS File Space .............................112
Allocating JFS2 File Space ............................115
JFS File System Layout..............................117
JFS2 File System Layout .............................118
Writing Programs That Access Large Files .......................119
Linking for Programmers .............................126
Using File Descriptors ..............................128
Creating and Removing Files............................131
Working with File I/O...............................132
File Status ..................................139
File Accessibility ................................139
Creating New File System Types ..........................140
Logical Volume Programming ...........................143
Related Information ...............................144
Chapter 6. Floating-Point Exceptions ........................147
Floating-Point Exception Subroutines .........................147
Floating-Point Trap Handler Operation ........................148
Related Information ...............................155
Chapter 7. Input and Output Handling .......................157
Low-Level I/O Interfaces .............................157
Stream I/O Interfaces ..............................158
Terminal I/O Interfaces ..............................159
Asynchronous I/O Interfaces ............................160
Chapter 8. Large Program Support .........................161
Understanding the Large Address-Space Model .....................161
Understanding the Very Large Address-Space Model ...................162
Enabling the Large and Very Large Address-Space Models ................162
Executing Programs with Large Data Areas ......................163
Related Information ...............................164
Chapter 9. Programming on Multiprocessor Systems .................165
Identifying Processors ..............................165
Controlling Processor Use .............................166
Using Dynamic Processor Deallocation ........................169
Creating Locking Services .............................173
iv General Programming Concepts: Writing and Debugging Programs
Related Information ...............................175
Chapter 10. Multi-Threaded Programming ......................177
Understanding Threads and Processes ........................177
Thread-Safe and Threaded Libraries in AIX ......................182
Creating Threads ................................182
Terminating Threads ...............................185
Synchronization Overview .............................192
Using Mutexes .................................192
Using Condition Variables .............................198
Using Read-Write Locks .............................204
Joining Threads.................................211
Scheduling Threads ...............................214
Contention Scope and Concurrency Level .......................217
Synchronization Scheduling ............................218
One-Time Initializations ..............................220
Thread-Specific Data...............................221
Creating Complex Synchronization Objects ......................225
Signal Management ...............................229
Process Duplication and Termination .........................232
Threads Library Options .............................233
Writing Reentrant and Thread-Safe Code .......................242
Developing Multi-Threaded Programs ........................247
Developing Multi-Threaded Programs to Examine and Modify pthread Library Objects.......251
Developing Multi-Threaded Program Debuggers.....................254
Benefits of Threads ...............................259
Related Information ...............................260
Chapter 11. lex and yacc Program Information ....................265
Generating a Lexical Analyzer with the lex Command...................265
Using the lex Program with the yacc Program .....................266
Extended Regular Expressions in the lex Command ...................267
Passing Code to the Generated lex Program ......................270
Defining lex Substitution Strings...........................270
lex Library...................................271
Actions Taken by the Lexical Analyzer ........................272
lex Program Start Conditions ............................275
Creating a Parser with the yacc Program .......................276
The yacc Grammar File..............................276
Using the yacc Grammar File ...........................278
yacc Grammar File Declarations ..........................279
yacc Rules ..................................281
yacc Actions ..................................283
yacc Program Error Handling............................284
Parser Operation Generated by the yacc Command ...................285
Using Ambiguous Rules in the yacc Program ......................287
Turning on Debug Mode for a Parser Generated by the yacc Command ............288
Example Program for the lex and yacc Programs ....................289
Related Information ...............................293
Chapter 12. make Command ...........................295
Creating a Description File ............................295
Internal Rules for the make Program .........................298
Defining and Using Macros in a Description File.....................301
How the make Command Creates a Target File .....................305
Using the make Command with Source Code Control System (SCCS) Files ..........306
Contents v
Description Files Stored in the Source Code Control System (SCCS) .............307
Using the make Command with Non-Source Code Control System (SCCS) Files ........307
How the make Command Uses the Environment Variables .................307
Example of a Description File ...........................308
Chapter 13. m4 Macro Processor Overview .....................311
Using the m4 Macro Processor ...........................311
Creating a User-Defined Macro ...........................311
Using a Built-In m4 Macro .............................314
List of Additional m4 Macros ............................319
Chapter 14. Object Data Manager (ODM) ......................321
ODM Object Classes and Objects ..........................321
ODM Descriptors ................................325
ODM Object Searches ..............................328
List of ODM Commands and Subroutines .......................331
ODM Example Code and Output ..........................332
Related Information ...............................335
Chapter 15. Dynamic Logical Partitioning ......................337
DLPAR-Safe and -Aware Programs .........................337
Processor Bindings ...............................340
Integrating the DLPAR Operation into the Application ...................341
Actions Taken by DLPAR Scripts ..........................342
Making Kernel Extensions DLPAR-Aware .......................347
Related Information ...............................350
Chapter 16. sed Program Information ........................351
Manipulating Strings with sed ...........................351
Chapter 17. Shared Libraries and Shared Memory ...................357
Shared Objects and Runtime Linking .........................357
Shared Libraries and Lazy Loading .........................359
Creating a Shared Library .............................361
Program Address Space Overview..........................363
Understanding Memory Mapping ..........................365
Inter-Process Communication (IPC) Limits .......................369
Creating a Mapped Data File with the shmat Subroutine..................371
Creating a Copy-On-Write Mapped Data File with the shmat Subroutine ............372
Creating a Shared Memory Segment with the shmat Subroutine ...............372
Paging Space Programming Requirements ......................373
List of Memory Manipulation Services ........................374
List of Memory Mapping Services ..........................375
Related Information ...............................375
Chapter 18. System Memory Allocation Using the malloc Subsystem ...........377
Working with the Heap in 32-bit Applications ......................377
Working with the Heap in 64-bit Applications ......................378
Understanding System Allocation Policy........................378
User-Defined Malloc Replacement ..........................382
Debug Malloc Tool ...............................385
Malloc Multiheap ................................391
Malloc Buckets .................................393
Malloc Report .................................396
Malloc Trace ..................................397
Malloc Log ..................................398
vi General Programming Concepts: Writing and Debugging Programs
Malloc Disclaim.................................399
Chapter 19. Packaging Software for Installation....................401
Installation Procedure Requirements .........................401
Package Control Information Requirements ......................402
Format of a Software Package ...........................402
Package Partitioning Requirements .........................402
Software Vital Product Data (SWVPD) ........................402
Software Product Packaging Parts..........................403
Package and File Set Naming Conventions ......................403
File Set Revision Level Identification .........................405
Contents of a Software Package ..........................405
The lpp_name Package Information File .......................407
The liblpp.a Installation Control Library File ......................415
Further Description of Installation Control Files .....................418
Installation Control Files Specifically for Repackaged Products ...............422
Installation Files for Supplemental Disk Subsystems ...................424
Format of Distribution Media ............................424
Tape.....................................425
CD-ROM ...................................425
Diskette ...................................426
The Table of Contents File.............................426
The installp Processing of Product Packages ......................427
Installation Commands Used During Installation and Update Processing ............433
Chapter 20. Documentation Library Service .....................435
Language Support................................436
Writing your HTML Documents ...........................436
Making your Documents Printable ..........................436
Calling the Documentation Library Service From Your Documentation .............437
Creating Indexes of your Documentation .......................444
Removing Indexes of your Documentation .......................452
Packaging your Application’s Documentation ......................452
Chapter 21. Source Code Control System (SCCS) ...................455
Introduction to SCCS...............................455
SCCS Flag and Parameter Conventions .......................456
Creating, Editing, and Updating an SCCS File .....................456
Controlling and Tracking SCCS File Changes......................458
Detecting and Repairing Damaged SCCS Files .....................459
List of Additional SCCS Commands .........................460
Related Information ...............................460
Chapter 22. Subroutines, Example Programs, and Libraries ...............461
128-Bit Long Double Floating-Point Data Type .....................462
List of Character Manipulation Subroutines ......................464
List of Executable Program Creation Subroutines ....................465
List of Files and Directories Subroutines .......................465
List of FORTRAN BLAS Level 1: Vector-Vector Subroutines ................467
List of FORTRAN BLAS Level 2: Matrix-Vector Subroutines ................467
List of FORTRAN BLAS Level 3: Matrix-Matrix Subroutines ................468
List of Numerical Manipulation Subroutines ......................468
List of Long Long Integer Numerical Manipulation Subroutines ...............469
List of 128-Bit Long Double Numerical Manipulation Subroutines ..............469
List of Processes Subroutines ...........................470
List of Multi-threaded Programming Subroutines.....................472
Contents vii
List of Programmer’s Workbench Library Subroutines ...................473
List of Security and Auditing Subroutines .......................474
List of String Manipulation Subroutines ........................475
Programming Example for Manipulating Characters ...................476
Searching and Sorting Example Program .......................478
List of Operating System Libraries ..........................481
librs2.a Library .................................482
Related Information ...............................483
Chapter 23. System Management Interface Tool (SMIT) .................485
SMIT Screen Types ...............................485
SMIT Object Classes...............................488
SMIT Aliases and Fast Paths............................491
SMIT Information Command Descriptors .......................492
SMIT Command Generation and Execution ......................494
Adding Tasks to the SMIT Database .........................496
Debugging SMIT Database Extensions ........................497
Creating SMIT Help Information for a New Task .....................497
sm_menu_opt (SMIT Menu) Object Class .......................498
sm_name_hdr (SMIT Selector Header) Object Class ...................500
sm_cmd_opt (SMIT Dialog/Selector Command Option) Object Class .............502
sm_cmd_hdr (SMIT Dialog Header) Object Class ....................506
SMIT Example Program .............................508
Related Information ...............................520
Chapter 24. System Resource Controller ......................521
Subsystem Interaction with the SRC .........................521
SRC Objects..................................522
SRC Communication Types ............................526
Programming Subsystem Communication with the SRC ..................529
Defining Your Subsystem to the SRC.........................535
List of Additional SRC Subroutines..........................536
Related Information ...............................536
Chapter 25. Trace Facility ............................539
The Trace Facility Overview ............................539
Controlling the Trace ...............................539
Recording Trace Event Data ............................540
Generating a Trace Report ............................541
Extracting trace data from a dump ..........................541
Trace Facility Commands .............................541
Start the Trace Facility ..............................544
Related Information ...............................547
Chapter 26. tty Subsystem ............................549
TTY Subsystem Objectives ............................549
Line Discipline Module (ldterm) ...........................553
Converter Modules ...............................556
TTY Drivers ..................................557
Related Information ...............................558
Chapter 27. Loader Domains ...........................559
Using Loader Domains ..............................559
Creating/Deleting Loader Domains..........................561
viii General Programming Concepts: Writing and Debugging Programs
Appendix A. High-Resolution Time Measurements Using POWER-based Time Base or POWER
family Real-Time Clock ............................563
Appendix B. Trace Hook Identifiers ........................565
Trace Hook IDs: 001 through 10A ..........................565
Trace Hook IDs: 10B through 14E ..........................571
Trace Hook IDs: 152 through 19C ..........................579
Trace Hook IDs: 1A4 through 1BF ..........................582
Trace Hook IDs: 1C8 through 1CE..........................589
Trace Hook IDs: 1CF through 211 ..........................593
Trace Hook IDs: 212 through 220 ..........................598
Trace Hook IDs: 221 through 223 ..........................604
Trace Hook IDs: 224 through 226 ..........................609
Trace Hook IDs: 230 through 233 ..........................616
Trace Hook IDs: 240 through 252 ..........................617
Trace Hook IDs: 253 through 25A ..........................625
Trace Hook IDs: 271 through 280 ..........................633
Trace Hook IDs: 301 through 315 ..........................642
Trace Hook IDs: 3C5 through 3E2 ..........................646
Trace Hook IDs: 401 ...............................653
Trace Hook IDs: 402 ...............................659
Trace Hook IDs: 403 ...............................663
Trace Hook IDs: 404 ...............................668
Trace Hook IDs: 405 ...............................673
Trace Hook IDs: 406 ...............................678
Trace Hook IDs: 407 ...............................683
Trace Hook IDs: 408 ...............................688
Trace Hook IDs: 409 ...............................693
Trace Hook IDs: 411 through 418 ..........................697
Trace Hook IDs: 460 through 46E ..........................716
Trace Hook IDs: 5A0 through 5A4 ..........................720
Appendix C. Notices ..............................723
Trademarks ..................................724
Index ....................................727
Contents ix
x General Programming Concepts: Writing and Debugging Programs
About This Book
This book introduces you to the programming tools and interfaces available for writing and debugging
application programs using the AIX operating system.
This edition supports the release of AIX 5L Version 5.2 with the 5200-01 Recommended Maintenance
package. Any specific references to this maintenance package are indicated as AIX 5.2 with 5200-01.
Who Should Use This Book
This book is intended for programmers who write and debug application programs on the AIX operating
system. Users of this book should be familiar with the C programming language and AIX usage (entering
commands, creating and deleting files, editing files, and navigating the file system).
Highlighting
The following highlighting conventions are used in this book:
Bold Identifies commands, subroutines, keywords, files, structures, directories, and other items whose
names are predefined by the system. Also identifies graphical objects such as buttons, labels, and
icons that the user selects.
Italics Identifies parameters whose actual names or values are to be supplied by the user.
Monospace Identifies examples of specific data values, examples of text similar to what you might see
displayed, examples of portions of program code similar to what you might write as a programmer,
messages from the system, or information you should actually type.
Case-Sensitivity in AIX
Everything in the AIX operating system is case-sensitive, which means that it distinguishes between
uppercase and lowercase letters. For example, you can use the ls command to list files. If you type LS, the
system responds that the command is not found. Likewise, FILEA, FiLea, and filea are three distinct file
names, even if they reside in the same directory. To avoid causing undesirable actions to be performed,
always ensure that you use the correct case.
ISO 9000
ISO 9000 registered quality systems were used in the development and manufacturing of this product.
Related Publications
The following books contain information about or related to writing programs:
v AIX 5L Version 5.2 Kernel Extensions and Device Support Programming Concepts
v AIX 5L Version 5.2 Communications Programming Concepts
v AIX 5L Version 5.2 AIXwindows Programming Guide
v AIX 5L Version 5.2 System Management Guide: Operating System and Devices
v AIX 5L Version 5.2 System Management Guide: Communications and Networks
v AIX 5L Version 5.2 Commands Reference
v Keyboard Technical Reference
v AIX 5L Version 5.2 Technical Reference: Base Operating System and Extensions Volume 1
v AIX 5L Version 5.2 Technical Reference: Base Operating System and Extensions Volume 2
v Understanding the Diagnostic Subsystem for AIX
© Copyright IBM Corp. 1997, 2003 xi
xii General Programming Concepts: Writing and Debugging Programs
Chapter 1. Tools and Utilities
This chapter provides an overview of the tools and utilities that you can use to develop C language
programs. Many tools are provided to help you develop C language programs. The tools provide help in
the following programming areas:
v “Entering a Program into the System”
v “Checking a Program”
v “Compiling and Linking a Program”
v “Correcting Errors in a Program” on page 2
v “Building and Maintaining a Program” on page 2
“Subroutines” on page 2 and “Shell Commands” on page 2 are provided for use in a C language program.
Entering a Program into the System
The system has a line editor called ed for use in entering a program into a file. The system also has the
full-screen editor called vi, which displays one full screen of data at a time and allows interactive editing of
a file.
Checking a Program
The following commands allow you to check the format of a program for consistency and accuracy:
lint Checks for syntax and data type errors inaClanguage source program. The lint command checks
these areas of a program more carefully than the C language compiler does, and displays many
messages that point out possible problems.
cb ReformatsaClanguage source program into a consistent format that uses indentation levels to show
the structure of the program.
cflow Generates a diagram of the logic flow of a C language source program.
cxref Generates a list of all external references for each module of a C language source program, including
where the reference is resolved (if it is resolved in the program).
Compiling and Linking a Program
To make source code into a program that the system can run, you need to process the source file with a
compiler program and a linkage editor.
A compiler is a program that reads program text from a file and changes the programming language in that
file to a form that the system understands. The linkage editor connects program modules together and
determines how to put the finished program into memory. To create this final form of the program, the
system does the following:
v If a file contains compiler source code, the compiler translates it into object code.
v If a file contains assembler language, the assembler translates it into object code.
v The linkage editor links the object files created in the previous step with any other object files specified
in the compiler command.
Other programming languages available for use on the operating system include the FORTRAN, Pascal,
and Assembler languages. Refer to documentation on these programming languages for information on
compiling and linking programs written in them.
You can write parts of a program in different languages and have one main routine call and start the
separate routines to execute, or use the cc program to both assemble and link the program.
© Copyright IBM Corp. 1997, 2003 1
Correcting Errors in a Program
The following debugging tools are available for use:
v dbx symbolic debugger can be used to debug programs written in C language, Pascal, FORTRAN, and
Assembler language. For more information, see “dbx Symbolic Debug Program Overview” on page 65.
v adb “adb Debug Program Overview” on page 33 debugger provides subcommands to examine, debug,
and repair executable binary files and to examine non-ASCII data files.
v Kernel Debug Program can help to determine errors in code running in the kernel. The primary
application of this debugger is debugging device drivers.
When syntax errors or parameter naming inconsistencies are discovered in a program file, a text editor or
string-searching and string-editing programs can be used to locate and change strings in the file.
String-searching and string-editing programs include the grep, sed, and awk commands. To make many
changes in one or more program files, you can include the commands in a shell program and then run the
shell program to locate and change the code in the files.
Building and Maintaining a Program
Two facilities are provided to help you control program changes and build a program from many source
modules. These commands can be particularly useful in software development environments in which
many source modules are produced.
The make command builds a program from source modules. Since the make command compiles only
those modules changed since the last build, its use can reduce compilation time when many source
modules must be processed.
Chapter 21, “Source Code Control System (SCCS)”, on page 455 allows you to maintain separate versions
of a program without storing separate, complete copies of each version. The use of SCCS can reduce
storage requirements and help in tracking the development of a project that requires keeping many
versions of large programs.
Subroutines
Subroutines from system libraries handle many complex or repetitive programming situations so that you
can concentrate on unique programming situations. See Subroutines Overview (Chapter 22, “Subroutines,
Example Programs, and Libraries”, on page 461) for information on using subroutines and for lists of many
of the subroutines available on the system.
Shell Commands
You can include the functions of many of the shell commands in a C language program. Any shell
command used in a program must be available on all systems that use the program.
You can then use the fork and exec subroutines in a program to run the command as a process in a part
of the system that is separate from the program. The system subroutine also runs a shell command in a
program, and the popen subroutine uses shell filters.
Related Information
For further information on this topic, see the following:
v “Manipulating Strings with sed” on page 351
v “Generating a Lexical Analyzer with the lex Command” on page 265
v Chapter 12, “make Command”, on page 295
v Chapter 13, “m4 Macro Processor Overview”, on page 311
v Chapter 22, “Subroutines, Example Programs, and Libraries”, on page 461
2 General Programming Concepts: Writing and Debugging Programs
Subroutine References
The exec subroutine, fork subroutine, popen subroutine, system subroutine.
Chapter 1. Tools and Utilities 3
4 General Programming Concepts: Writing and Debugging Programs
Chapter 2. Curses Library
The curses library provides a set of functions that enable you to manipulate a terminal’s display regardless
of the terminal type. The curses library supports color. However, multibyte characters are not supported. All
references to characters in the curses documentation refer to single-byte characters. Throughout this
documentation, the curses library is referred to as curses.
The basis of curses programming is the window data structure. Using this structure, you can manipulate
data on a terminal’s display. You can instruct curses to treat the entire terminal display as one large
window, or you can create multiple windows on the display. The windows can be different sizes and can
overlap one another. A typical curses application has a single large window and one subwindow within it.
Each window on a terminal’s display has its own window data structure. This structure keeps state
information about the window, such as its size and where it is located on the display. Curses uses the
window data structure to obtain the relevant information it needs to carry out your instructions.
Terminology
When programming with curses, you should be familiar with the following terms:
Term Definition
current character The character that the logical cursor is currently on.
current line The line that the logical cursor is currently on.
curscr A virtual default window provided by curses. The curscr (current screen) is an internal
representation of what currently appears on the terminal’s external display. Do not
modify the curscr.
display A physical display connected to a workstation.
logical cursor The cursor location within each window. The window data structure keeps track of the
location of its logical cursor.
pad A type of window that is larger than the dimensions of the terminal’s display.
physical cursor The cursor that appears on a display. The workstation uses this cursor to write to the
display. There is only one physical cursor per display.
screen The window that fills the entire display. The screen is synonymous with the stdscr.
stdscr A virtual default window (standard screen) provided by curses that represents the
entire display.
window A pointer to a C data structure and the graphic representation of that data structure on
the display. A window can be thought of as a two-dimensional array representing how
all or part of the display looks at any point in time.
Naming Conventions
A single curses subroutine can have more than one version. Curses subroutines with multiple versions
follow distinct naming conventions that identify the separate versions. These conventions add a prefix to a
standard curses subroutine and identify what arguments the subroutine requires or what actions take place
when the subroutine is called. The different versions of curses subroutine names use the following
prefixes:
Prefix Description
w Identifies a subroutine that requires a window argument.
p Identifies a subroutine that requires a pad argument.
mv Identifies a subroutine that first performs a move to the program-supplied coordinates.
If a curses subroutine has multiple versions and does not include one of the preceding prefixes, the curses
default window stdscr (standard screen) is used. The majority of subroutines that use the stdscr are
© Copyright IBM Corp. 1997, 2003 5
macros created in the /usr/include/curses.h file using #define statements. The preprocessor replaces
these statements at compilation time. As a result, these macros do not appear in the compiled assembler
code, a trace, a debug program, or the curses source code.
If a curses subroutine has only a single version, it does not necessarily use stdscr. For example, the
printw subroutine prints a string to the stdscr. The wprintw subroutine prints a string to a specific window
by supplying the window argument. The mvprintw subroutine moves the specified coordinates to the
stdscr and then performs the same function as the printw subroutine. Likewise, the mvwprintw subroutine
moves the specified coordinates to the specified window and then performs the same function as the
wprintw subroutine.
Structure of a Curses Program
In general, a curses program has the following progression:
1. Start curses.
2. Check for color support (optional).
3. Start color (optional).
4. Create one or more windows.
5. Manipulate windows.
6. Destroy one or more windows.
7. Stop curses.
Some steps are optional, so your program does not have to follow this progression exactly.
Return Values
With a few exceptions, all curses subroutines return either the integer value ERR or the integer value OK.
Subroutines that do not follow this convention are noted appropriately. Subroutines that return pointers
always return a null pointer or an error.
Initializing Curses
Use the following commnads to initialize curses:
endwin Terminates the curses subroutine libraries and their data structures
initscr Initializes the curses subroutine library and its data structures
isendwin Returns TRUE if the endwin subroutine has been called without any subsequent calls to the
wrefresh subroutine
newterm Sets up a new terminal
setupterm Sets up the TERMINAL structure for use by curses
You must include the curses.h file at the beginning of any program that calls curses subroutines. To do
this, use the following statement:
#include <curses.h>
Before you can call subroutines that manipulate windows or screens, you must call the initscr or newterm
subroutine. These subroutines first save the terminal’s settings and then call the setupterm subroutine to
establish a curses terminal.
If you need to temporarily suspend curses, use a shell escape or subroutine. To resume after a temporary
escape, call the wrefresh or doupdate subroutine. Before exiting a curses program, you must call the
endwin subroutine. The endwin subroutine restores tty modes, moves the cursor to the lower-left corner
of the screen, and resets the terminal into the proper nonvisual mode.
6 General Programming Concepts: Writing and Debugging Programs
  • Page 1 1
  • Page 2 2
  • Page 3 3
  • Page 4 4
  • Page 5 5
  • Page 6 6
  • Page 7 7
  • Page 8 8
  • Page 9 9
  • Page 10 10
  • Page 11 11
  • Page 12 12
  • Page 13 13
  • Page 14 14
  • Page 15 15
  • Page 16 16
  • Page 17 17
  • Page 18 18
  • Page 19 19
  • Page 20 20
  • Page 21 21
  • Page 22 22
  • Page 23 23
  • Page 24 24
  • Page 25 25
  • Page 26 26
  • Page 27 27
  • Page 28 28
  • Page 29 29
  • Page 30 30
  • Page 31 31
  • Page 32 32
  • Page 33 33
  • Page 34 34
  • Page 35 35
  • Page 36 36
  • Page 37 37
  • Page 38 38
  • Page 39 39
  • Page 40 40
  • Page 41 41
  • Page 42 42
  • Page 43 43
  • Page 44 44
  • Page 45 45
  • Page 46 46
  • Page 47 47
  • Page 48 48
  • Page 49 49
  • Page 50 50
  • Page 51 51
  • Page 52 52
  • Page 53 53
  • Page 54 54
  • Page 55 55
  • Page 56 56
  • Page 57 57
  • Page 58 58
  • Page 59 59
  • Page 60 60
  • Page 61 61
  • Page 62 62
  • Page 63 63
  • Page 64 64
  • Page 65 65
  • Page 66 66
  • Page 67 67
  • Page 68 68
  • Page 69 69
  • Page 70 70
  • Page 71 71
  • Page 72 72
  • Page 73 73
  • Page 74 74
  • Page 75 75
  • Page 76 76
  • Page 77 77
  • Page 78 78
  • Page 79 79
  • Page 80 80
  • Page 81 81
  • Page 82 82
  • Page 83 83
  • Page 84 84
  • Page 85 85
  • Page 86 86
  • Page 87 87
  • Page 88 88
  • Page 89 89
  • Page 90 90
  • Page 91 91
  • Page 92 92
  • Page 93 93
  • Page 94 94
  • Page 95 95
  • Page 96 96
  • Page 97 97
  • Page 98 98
  • Page 99 99
  • Page 100 100
  • Page 101 101
  • Page 102 102
  • Page 103 103
  • Page 104 104
  • Page 105 105
  • Page 106 106
  • Page 107 107
  • Page 108 108
  • Page 109 109
  • Page 110 110
  • Page 111 111
  • Page 112 112
  • Page 113 113
  • Page 114 114
  • Page 115 115
  • Page 116 116
  • Page 117 117
  • Page 118 118
  • Page 119 119
  • Page 120 120
  • Page 121 121
  • Page 122 122
  • Page 123 123
  • Page 124 124
  • Page 125 125
  • Page 126 126
  • Page 127 127
  • Page 128 128
  • Page 129 129
  • Page 130 130
  • Page 131 131
  • Page 132 132
  • Page 133 133
  • Page 134 134
  • Page 135 135
  • Page 136 136
  • Page 137 137
  • Page 138 138
  • Page 139 139
  • Page 140 140
  • Page 141 141
  • Page 142 142
  • Page 143 143
  • Page 144 144
  • Page 145 145
  • Page 146 146
  • Page 147 147
  • Page 148 148
  • Page 149 149
  • Page 150 150
  • Page 151 151
  • Page 152 152
  • Page 153 153
  • Page 154 154
  • Page 155 155
  • Page 156 156
  • Page 157 157
  • Page 158 158
  • Page 159 159
  • Page 160 160
  • Page 161 161
  • Page 162 162
  • Page 163 163
  • Page 164 164
  • Page 165 165
  • Page 166 166
  • Page 167 167
  • Page 168 168
  • Page 169 169
  • Page 170 170
  • Page 171 171
  • Page 172 172
  • Page 173 173
  • Page 174 174
  • Page 175 175
  • Page 176 176
  • Page 177 177
  • Page 178 178
  • Page 179 179
  • Page 180 180
  • Page 181 181
  • Page 182 182
  • Page 183 183
  • Page 184 184
  • Page 185 185
  • Page 186 186
  • Page 187 187
  • Page 188 188
  • Page 189 189
  • Page 190 190
  • Page 191 191
  • Page 192 192
  • Page 193 193
  • Page 194 194
  • Page 195 195
  • Page 196 196
  • Page 197 197
  • Page 198 198
  • Page 199 199
  • Page 200 200
  • Page 201 201
  • Page 202 202
  • Page 203 203
  • Page 204 204
  • Page 205 205
  • Page 206 206
  • Page 207 207
  • Page 208 208
  • Page 209 209
  • Page 210 210
  • Page 211 211
  • Page 212 212
  • Page 213 213
  • Page 214 214
  • Page 215 215
  • Page 216 216
  • Page 217 217
  • Page 218 218
  • Page 219 219
  • Page 220 220
  • Page 221 221
  • Page 222 222
  • Page 223 223
  • Page 224 224
  • Page 225 225
  • Page 226 226
  • Page 227 227
  • Page 228 228
  • Page 229 229
  • Page 230 230
  • Page 231 231
  • Page 232 232
  • Page 233 233
  • Page 234 234
  • Page 235 235
  • Page 236 236
  • Page 237 237
  • Page 238 238
  • Page 239 239
  • Page 240 240
  • Page 241 241
  • Page 242 242
  • Page 243 243
  • Page 244 244
  • Page 245 245
  • Page 246 246
  • Page 247 247
  • Page 248 248
  • Page 249 249
  • Page 250 250
  • Page 251 251
  • Page 252 252
  • Page 253 253
  • Page 254 254
  • Page 255 255
  • Page 256 256
  • Page 257 257
  • Page 258 258
  • Page 259 259
  • Page 260 260
  • Page 261 261
  • Page 262 262
  • Page 263 263
  • Page 264 264
  • Page 265 265
  • Page 266 266
  • Page 267 267
  • Page 268 268
  • Page 269 269
  • Page 270 270
  • Page 271 271
  • Page 272 272
  • Page 273 273
  • Page 274 274
  • Page 275 275
  • Page 276 276
  • Page 277 277
  • Page 278 278
  • Page 279 279
  • Page 280 280
  • Page 281 281
  • Page 282 282
  • Page 283 283
  • Page 284 284
  • Page 285 285
  • Page 286 286
  • Page 287 287
  • Page 288 288
  • Page 289 289
  • Page 290 290
  • Page 291 291
  • Page 292 292
  • Page 293 293
  • Page 294 294
  • Page 295 295
  • Page 296 296
  • Page 297 297
  • Page 298 298
  • Page 299 299
  • Page 300 300
  • Page 301 301
  • Page 302 302
  • Page 303 303
  • Page 304 304
  • Page 305 305
  • Page 306 306
  • Page 307 307
  • Page 308 308
  • Page 309 309
  • Page 310 310
  • Page 311 311
  • Page 312 312
  • Page 313 313
  • Page 314 314
  • Page 315 315
  • Page 316 316
  • Page 317 317
  • Page 318 318
  • Page 319 319
  • Page 320 320
  • Page 321 321
  • Page 322 322
  • Page 323 323
  • Page 324 324
  • Page 325 325
  • Page 326 326
  • Page 327 327
  • Page 328 328
  • Page 329 329
  • Page 330 330
  • Page 331 331
  • Page 332 332
  • Page 333 333
  • Page 334 334
  • Page 335 335
  • Page 336 336
  • Page 337 337
  • Page 338 338
  • Page 339 339
  • Page 340 340
  • Page 341 341
  • Page 342 342
  • Page 343 343
  • Page 344 344
  • Page 345 345
  • Page 346 346
  • Page 347 347
  • Page 348 348
  • Page 349 349
  • Page 350 350
  • Page 351 351
  • Page 352 352
  • Page 353 353
  • Page 354 354
  • Page 355 355
  • Page 356 356
  • Page 357 357
  • Page 358 358
  • Page 359 359
  • Page 360 360
  • Page 361 361
  • Page 362 362
  • Page 363 363
  • Page 364 364
  • Page 365 365
  • Page 366 366
  • Page 367 367
  • Page 368 368
  • Page 369 369
  • Page 370 370
  • Page 371 371
  • Page 372 372
  • Page 373 373
  • Page 374 374
  • Page 375 375
  • Page 376 376
  • Page 377 377
  • Page 378 378
  • Page 379 379
  • Page 380 380
  • Page 381 381
  • Page 382 382
  • Page 383 383
  • Page 384 384
  • Page 385 385
  • Page 386 386
  • Page 387 387
  • Page 388 388
  • Page 389 389
  • Page 390 390
  • Page 391 391
  • Page 392 392
  • Page 393 393
  • Page 394 394
  • Page 395 395
  • Page 396 396
  • Page 397 397
  • Page 398 398
  • Page 399 399
  • Page 400 400
  • Page 401 401
  • Page 402 402
  • Page 403 403
  • Page 404 404
  • Page 405 405
  • Page 406 406
  • Page 407 407
  • Page 408 408
  • Page 409 409
  • Page 410 410
  • Page 411 411
  • Page 412 412
  • Page 413 413
  • Page 414 414
  • Page 415 415
  • Page 416 416
  • Page 417 417
  • Page 418 418
  • Page 419 419
  • Page 420 420
  • Page 421 421
  • Page 422 422
  • Page 423 423
  • Page 424 424
  • Page 425 425
  • Page 426 426
  • Page 427 427
  • Page 428 428
  • Page 429 429
  • Page 430 430
  • Page 431 431
  • Page 432 432
  • Page 433 433
  • Page 434 434
  • Page 435 435
  • Page 436 436
  • Page 437 437
  • Page 438 438
  • Page 439 439
  • Page 440 440
  • Page 441 441
  • Page 442 442
  • Page 443 443
  • Page 444 444
  • Page 445 445
  • Page 446 446
  • Page 447 447
  • Page 448 448
  • Page 449 449
  • Page 450 450
  • Page 451 451
  • Page 452 452
  • Page 453 453
  • Page 454 454
  • Page 455 455
  • Page 456 456
  • Page 457 457
  • Page 458 458
  • Page 459 459
  • Page 460 460
  • Page 461 461
  • Page 462 462
  • Page 463 463
  • Page 464 464
  • Page 465 465
  • Page 466 466
  • Page 467 467
  • Page 468 468
  • Page 469 469
  • Page 470 470
  • Page 471 471
  • Page 472 472
  • Page 473 473
  • Page 474 474
  • Page 475 475
  • Page 476 476
  • Page 477 477
  • Page 478 478
  • Page 479 479
  • Page 480 480
  • Page 481 481
  • Page 482 482
  • Page 483 483
  • Page 484 484
  • Page 485 485
  • Page 486 486
  • Page 487 487
  • Page 488 488
  • Page 489 489
  • Page 490 490
  • Page 491 491
  • Page 492 492
  • Page 493 493
  • Page 494 494
  • Page 495 495
  • Page 496 496
  • Page 497 497
  • Page 498 498
  • Page 499 499
  • Page 500 500
  • Page 501 501
  • Page 502 502
  • Page 503 503
  • Page 504 504
  • Page 505 505
  • Page 506 506
  • Page 507 507
  • Page 508 508
  • Page 509 509
  • Page 510 510
  • Page 511 511
  • Page 512 512
  • Page 513 513
  • Page 514 514
  • Page 515 515
  • Page 516 516
  • Page 517 517
  • Page 518 518
  • Page 519 519
  • Page 520 520
  • Page 521 521
  • Page 522 522
  • Page 523 523
  • Page 524 524
  • Page 525 525
  • Page 526 526
  • Page 527 527
  • Page 528 528
  • Page 529 529
  • Page 530 530
  • Page 531 531
  • Page 532 532
  • Page 533 533
  • Page 534 534
  • Page 535 535
  • Page 536 536
  • Page 537 537
  • Page 538 538
  • Page 539 539
  • Page 540 540
  • Page 541 541
  • Page 542 542
  • Page 543 543
  • Page 544 544
  • Page 545 545
  • Page 546 546
  • Page 547 547
  • Page 548 548
  • Page 549 549
  • Page 550 550
  • Page 551 551
  • Page 552 552
  • Page 553 553
  • Page 554 554
  • Page 555 555
  • Page 556 556
  • Page 557 557
  • Page 558 558
  • Page 559 559
  • Page 560 560
  • Page 561 561
  • Page 562 562
  • Page 563 563
  • Page 564 564
  • Page 565 565
  • Page 566 566
  • Page 567 567
  • Page 568 568
  • Page 569 569
  • Page 570 570
  • Page 571 571
  • Page 572 572
  • Page 573 573
  • Page 574 574
  • Page 575 575
  • Page 576 576
  • Page 577 577
  • Page 578 578
  • Page 579 579
  • Page 580 580
  • Page 581 581
  • Page 582 582
  • Page 583 583
  • Page 584 584
  • Page 585 585
  • Page 586 586
  • Page 587 587
  • Page 588 588
  • Page 589 589
  • Page 590 590
  • Page 591 591
  • Page 592 592
  • Page 593 593
  • Page 594 594
  • Page 595 595
  • Page 596 596
  • Page 597 597
  • Page 598 598
  • Page 599 599
  • Page 600 600
  • Page 601 601
  • Page 602 602
  • Page 603 603
  • Page 604 604
  • Page 605 605
  • Page 606 606
  • Page 607 607
  • Page 608 608
  • Page 609 609
  • Page 610 610
  • Page 611 611
  • Page 612 612
  • Page 613 613
  • Page 614 614
  • Page 615 615
  • Page 616 616
  • Page 617 617
  • Page 618 618
  • Page 619 619
  • Page 620 620
  • Page 621 621
  • Page 622 622
  • Page 623 623
  • Page 624 624
  • Page 625 625
  • Page 626 626
  • Page 627 627
  • Page 628 628
  • Page 629 629
  • Page 630 630
  • Page 631 631
  • Page 632 632
  • Page 633 633
  • Page 634 634
  • Page 635 635
  • Page 636 636
  • Page 637 637
  • Page 638 638
  • Page 639 639
  • Page 640 640
  • Page 641 641
  • Page 642 642
  • Page 643 643
  • Page 644 644
  • Page 645 645
  • Page 646 646
  • Page 647 647
  • Page 648 648
  • Page 649 649
  • Page 650 650
  • Page 651 651
  • Page 652 652
  • Page 653 653
  • Page 654 654
  • Page 655 655
  • Page 656 656
  • Page 657 657
  • Page 658 658
  • Page 659 659
  • Page 660 660
  • Page 661 661
  • Page 662 662
  • Page 663 663
  • Page 664 664
  • Page 665 665
  • Page 666 666
  • Page 667 667
  • Page 668 668
  • Page 669 669
  • Page 670 670
  • Page 671 671
  • Page 672 672
  • Page 673 673
  • Page 674 674
  • Page 675 675
  • Page 676 676
  • Page 677 677
  • Page 678 678
  • Page 679 679
  • Page 680 680
  • Page 681 681
  • Page 682 682
  • Page 683 683
  • Page 684 684
  • Page 685 685
  • Page 686 686
  • Page 687 687
  • Page 688 688
  • Page 689 689
  • Page 690 690
  • Page 691 691
  • Page 692 692
  • Page 693 693
  • Page 694 694
  • Page 695 695
  • Page 696 696
  • Page 697 697
  • Page 698 698
  • Page 699 699
  • Page 700 700
  • Page 701 701
  • Page 702 702
  • Page 703 703
  • Page 704 704
  • Page 705 705
  • Page 706 706
  • Page 707 707
  • Page 708 708
  • Page 709 709
  • Page 710 710
  • Page 711 711
  • Page 712 712
  • Page 713 713
  • Page 714 714
  • Page 715 715
  • Page 716 716
  • Page 717 717
  • Page 718 718
  • Page 719 719
  • Page 720 720
  • Page 721 721
  • Page 722 722
  • Page 723 723
  • Page 724 724
  • Page 725 725
  • Page 726 726
  • Page 727 727
  • Page 728 728
  • Page 729 729
  • Page 730 730
  • Page 731 731
  • Page 732 732
  • Page 733 733
  • Page 734 734
  • Page 735 735
  • Page 736 736
  • Page 737 737
  • Page 738 738
  • Page 739 739
  • Page 740 740
  • Page 741 741
  • Page 742 742
  • Page 743 743
  • Page 744 744
  • Page 745 745
  • Page 746 746
  • Page 747 747
  • Page 748 748
  • Page 749 749
  • Page 750 750
  • Page 751 751
  • Page 752 752
  • Page 753 753
  • Page 754 754
  • Page 755 755
  • Page 756 756
  • Page 757 757
  • Page 758 758
  • Page 759 759
  • Page 760 760
  • Page 761 761

Bull AIX 5.2 - General Programming Guide

Category
Software
Type
Programming Guide

Ask a question and I''ll find the answer in the document

Finding information in a document is now easier with AI