wrox professional linuxprogramming

1058
Professional LINUX Programming

Upload: thanhmaikmt

Post on 19-May-2015

2.458 views

Category:

Education


1 download

TRANSCRIPT

  • 1. Professional LINUX Programming

2. Table of Contents Professional Linux Programming.....................................................................................................................1 Introduction.........................................................................................................................................................9 Welcome.................................................................................................................................................9 Who is This Book for?............................................................................................................................9 What's Covered in This Book?...............................................................................................................9 What You Need to Use This Book.......................................................................................................12 Source Code..........................................................................................................................................12 Conventions..........................................................................................................................................13 Chapter 1: Application Design.......................................................................................................................14 Overview...............................................................................................................................................14 Development Models............................................................................................................................15 The Waterfall model........................................................................................................................15 Iterative development......................................................................................................................15 'Fast Track' Development...............................................................................................................16 Test Early, Test Often....................................................................................................................16 The DVD Store.....................................................................................................................................17 Initial Requirements.......................................................................................................................18 Analyzing the User Requirements..................................................................................................18 Statement of Requirements...................................................................................................................23 Use Cases.......................................................................................................................................25 Application Architecture.......................................................................................................................26 Detailed Design..............................................................................................................................27 Data Access Functions...................................................................................................................28 Member Functions..........................................................................................................................29 Title Functions................................................................................................................................30 Disk Functions................................................................................................................................31 Rental Functions.............................................................................................................................32 Reference Implementation.............................................................................................................33 Resources..............................................................................................................................................33 Summary...............................................................................................................................................34 Chapter 2: CVS................................................................................................................................................35 Overview...............................................................................................................................................35 Tools for Linux.....................................................................................................................................35 Terminology..........................................................................................................................................36 The Repository......................................................................................................................................36 Single User CVS projects.....................................................................................................................37 CVS Command Format..................................................................................................................37 Environment Variables...................................................................................................................38 Importing a New Project................................................................................................................39 Starting Work on Our Project.........................................................................................................40 Checking Our Changes Against the Repository.............................................................................41 Updating the Repository with Our Changes...................................................................................42 Releasing the Project......................................................................................................................43 Reviewing Changes........................................................................................................................44 Adding and Removing Files from a Project...................................................................................44 Professional LINUX Programming i 3. Table of Contents Chapter 2: CVS Keyword Substitution.....................................................................................................................44 Revisions, Tags and Branches..............................................................................................................45 Revisions........................................................................................................................................45 Tags................................................................................................................................................46 Branches.........................................................................................................................................48 Multiuser CVS....................................................................................................................................53 Working Collaboratively................................................................................................................53 Working with Watches...................................................................................................................55 More Fun with CVS..............................................................................................................................55 Binary Files....................................................................................................................................55 Correcting Bad Annotations...........................................................................................................55 Accessing CVS Across a Network.......................................................................................................55 GUI CVS Clients..................................................................................................................................57 Resources..............................................................................................................................................59 Summary...............................................................................................................................................59 Chapter 3: Databases.......................................................................................................................................61 Overview...............................................................................................................................................61 Choosing a Database.............................................................................................................................61 mSQL.............................................................................................................................................62 MySQL...........................................................................................................................................62 PostgreSQL....................................................................................................................................62 Which is Right for Me?..................................................................................................................62 PostgreSQL...........................................................................................................................................63 Installation and Commissioning.....................................................................................................63 Database Fundamentals........................................................................................................................68 First Normal Form..........................................................................................................................68 Second Normal Form.....................................................................................................................69 Third Normal Form........................................................................................................................69 Denormalization...........................................................................................................................69 A Simple Database.........................................................................................................................69 Using psql.............................................................................................................................................73 Commands to psql..........................................................................................................................73 Data Definition Commands............................................................................................................74 Data Manipulation Commands.......................................................................................................79 Transactions....................................................................................................................................85 Database Design Tips...........................................................................................................................86 Resources..............................................................................................................................................87 Summary...............................................................................................................................................88 Chapter 4: PostgreSQL Interfacing...............................................................................................................89 Accessing PostgreSQL from Code.......................................................................................................89 Libpq..............................................................................................................................................89 ECPG............................................................................................................................................106 Which Method to Use?.................................................................................................................114 The Application..................................................................................................................................114 Summary.............................................................................................................................................120 Professional LINUX Programming ii 4. Table of Contents Chapter 5: MySQL........................................................................................................................................121 Installation and Commissioning.........................................................................................................121 Precompiled Packages................................................................................................................121 Building from Source...................................................................................................................122 Postinstall Configuration............................................................................................................123 MySQL Administration......................................................................................................................124 Commands....................................................................................................................................124 Creating Users, and Giving Them Permissions............................................................................127 Passwords.....................................................................................................................................129 Creating a Database......................................................................................................................129 SQL Support in PostgreSQL and MySQL..........................................................................................130 Accessing MySQL Data from C.........................................................................................................132 Connection Routines....................................................................................................................132 Error Handling..............................................................................................................................135 Executing SQL Statements...........................................................................................................136 Miscellaneous Functions..............................................................................................................147 Resources............................................................................................................................................147 Summary.............................................................................................................................................148 Chapter 6: Tackling Bugs.............................................................................................................................149 Overview.............................................................................................................................................149 Error Classes.......................................................................................................................................149 Reporting Errors..................................................................................................................................149 Detecting Software Errors...................................................................................................................152 Types of Software Error......................................................................................................................152 Debug Statements...............................................................................................................................153 Assertions.....................................................................................................................................156 Where Are You?.................................................................................................................................158 Backtrace......................................................................................................................................160 Preparing to Debug.............................................................................................................................162 Using the Debugger......................................................................................................................163 Simple GDB Commands..............................................................................................................164 Other GDB Features.....................................................................................................................166 Resources......................................................................................................................................167 Summary.............................................................................................................................................167 Chapter 7: LDAP Directory Services...........................................................................................................169 What is a Directory Service?..............................................................................................................169 X.500 and LDAP..........................................................................................................................169 Structure of a Directory Server...........................................................................................................170 The Naming of Parts.....................................................................................................................171 dn Naming....................................................................................................................................171 Object Components......................................................................................................................172 LDAP Directory Tree...................................................................................................................174 LDIF Files....................................................................................................................................175 Installing and Configuring an LDAP Server......................................................................................176 Steps in Installing OpenLDAP.....................................................................................................176 Configuring OpenLDAP..............................................................................................................177 Professional LINUX Programming iii 5. Table of Contents Chapter 7: LDAP Directory Services Running the Server.............................................................................................................................179 Accessing LDAP from C....................................................................................................................180 Initialize the LDAP Library.........................................................................................................181 Bind to the LDAP Server.............................................................................................................181 LDAP Error Handling..................................................................................................................182 A First LDAP Client Program......................................................................................................183 Searching......................................................................................................................................183 Changing the Data...............................................................................................................................192 Adding a New Entry.....................................................................................................................192 Modifying an Entry......................................................................................................................195 Deleting an Entry..........................................................................................................................197 The Application..................................................................................................................................198 Resources............................................................................................................................................198 Summary.............................................................................................................................................198 Chapter 8: GUI programming with GNOME/GTK+................................................................................200 Overview.............................................................................................................................................200 The GTK+/GNOME libraries.............................................................................................................200 glib.................................................................................................................................................201 GTK+............................................................................................................................................201 GDK..............................................................................................................................................201 Imlib..............................................................................................................................................201 ORBit.............................................................................................................................................201 libGnorba.......................................................................................................................................201 glib......................................................................................................................................................202 Types............................................................................................................................................202 Macros..........................................................................................................................................203 String functions............................................................................................................................205 Memory Allocation......................................................................................................................206 Lists..............................................................................................................................................207 GTK+..................................................................................................................................................209 Widgets.........................................................................................................................................209 gtk_init and gtk_main...................................................................................................................214 Example GTK+ Application........................................................................................................214 GNOME Basics..................................................................................................................................215 gnome_init.....................................................................................................................................216 GnomeApp....................................................................................................................................216 Menus and Toolbars.....................................................................................................................216 Dialogs..........................................................................................................................................219 Creating a GnomeDialog...............................................................................................................220 Example GNOME Application....................................................................................................225 The GNOME Source Tree..................................................................................................................227 configure.in....................................................................................................................................228 Makefile.am...................................................................................................................................229 Configuration Saving...................................................................................................................230 Storing data....................................................................................................................................230 Reading the Stored Data................................................................................................................231 Professional LINUX Programming iv 6. Table of Contents Chapter 8: GUI programming with GNOME/GTK+ Session Management....................................................................................................................232 Command Line Parsing Using popt.............................................................................................234 GNOME/GTK+ Resources..........................................................................................................237 Summary.............................................................................................................................................237 Chapter 9: GUI Building with Glade and GTK+/GNOME.......................................................................238 Overview.............................................................................................................................................238 Overview of Glade..............................................................................................................................238 A Word on GUI Design................................................................................................................239 A Glade Tutorial.................................................................................................................................239 Main Window...............................................................................................................................240 The Palette....................................................................................................................................241 The Properties Window................................................................................................................244 The Gladebuilt Source Tree.......................................................................................................248 lookup_widget..............................................................................................................................249 Adding Code.................................................................................................................................250 libglade.........................................................................................................................................252 The DVD Store GNOME GUI...........................................................................................................254 Design...........................................................................................................................................255 Compiling and Running dvdstore.................................................................................................255 Structure.......................................................................................................................................260 Code..............................................................................................................................................261 Summary.............................................................................................................................................285 Chapter 10: Flex and Bison...........................................................................................................................286 Overview.............................................................................................................................................286 Input Structure....................................................................................................................................286 Scanners and Parsers....................................................................................................................288 How Generators Work..................................................................................................................288 Scanners..............................................................................................................................................289 A Simple Scanner.........................................................................................................................289 Scanner Specifications.................................................................................................................290 Longest Match Principle..............................................................................................................294 Regular Expressions.....................................................................................................................295 Actions..........................................................................................................................................297 Redirecting Scanner Input and Output.........................................................................................297 Returning Tokens.........................................................................................................................298 Context Sensitive Scanners..........................................................................................................299 Options to flex..............................................................................................................................300 Parsers.................................................................................................................................................300 Generating Parsers........................................................................................................................301 Creating a Syntax Tester..............................................................................................................306 Token Types.................................................................................................................................309 Actions in Rules...........................................................................................................................310 Options to bison............................................................................................................................316 Conflicts in Grammars.................................................................................................................317 Arithmetic Expressions................................................................................................................318 Professional LINUX Programming v 7. Table of Contents Chapter 10: Flex and Bison Resources............................................................................................................................................319 Summary.............................................................................................................................................319 Chapter 11: Testing Tools.............................................................................................................................320 Overview.............................................................................................................................................320 Testing Requirements Types...............................................................................................................320 Application Architecture..............................................................................................................320 Steps.............................................................................................................................................321 General Testing............................................................................................................................321 Regression Testing.......................................................................................................................322 A Test Program............................................................................................................................324 Testing the dvdstore Program.......................................................................................................328 Scripting Tests..............................................................................................................................329 expect............................................................................................................................................329 Memory Problems........................................................................................................................331 Installing mpatrol.........................................................................................................................337 Using mpatrol...............................................................................................................................338 Testing Coverage..........................................................................................................................342 Performance Testing.....................................................................................................................349 Summary.............................................................................................................................................351 Chapter 12: Secure Programming...............................................................................................................352 What is Secure Programming?............................................................................................................352 Why Secure Programming is Hard.....................................................................................................352 Stealthy Bugs.................................................................................................................................352 The Virtue of Paranoia..................................................................................................................353 Filesystem Security......................................................................................................................354 Authenticating Users....................................................................................................................357 Using Cryptography Securely......................................................................................................369 A Short Introduction to Cryptography..........................................................................................369 PublicKey Crypto........................................................................................................................369 Secure Hash Algorithms................................................................................................................370 On Writing Custom/Proprietary Algorithms.................................................................................370 Secure Network Programming.....................................................................................................374 Writing Protocols.........................................................................................................................374 Standard Network Cryptography Tools.......................................................................................378 SSL/TLS........................................................................................................................................378 ssh..................................................................................................................................................378 Problems With the Environment..................................................................................................379 Python...........................................................................................................................................385 PHP...............................................................................................................................................386 Resources............................................................................................................................................386 Internet Information......................................................................................................................386 Summary.............................................................................................................................................387 Professional LINUX Programming vi 8. Table of Contents Chapter 13: GUI Programming with KDE/Qt............................................................................................388 Introduction.........................................................................................................................................388 About Qt.......................................................................................................................................388 About KDE...................................................................................................................................388 Installing Qt..................................................................................................................................389 Installing KDE..............................................................................................................................390 Libraries........................................................................................................................................390 Programming Applications Using Qt.................................................................................................390 Getting Started: Hello World.......................................................................................................391 Simplifying Makefile Management With tmake..........................................................................392 Signals and Slots..........................................................................................................................393 'Hello world' Revisited.................................................................................................................395 Deriving From Base Classes........................................................................................................396 Widgets.........................................................................................................................................398 Layouts.........................................................................................................................................399 Programming Applications Using KDE.............................................................................................403 A Simple Text Editor...................................................................................................................403 Resources............................................................................................................................................409 Summary.............................................................................................................................................410 Chapter 14: Writing the DVD Store GUI Using KDE/Qt..........................................................................411 Overview.............................................................................................................................................411 Application Design.......................................................................................................................411 Main Window...............................................................................................................................413 Member Dialog.............................................................................................................................418 Rent Dialog...................................................................................................................................421 Rental Report Dialog....................................................................................................................423 Search Window............................................................................................................................423 The Settings Manager...................................................................................................................428 Adjusting the Code to KDE................................................................................................................430 KConfig and SettingsManager......................................................................................................435 Resources............................................................................................................................................435 Summary.............................................................................................................................................435 Chapter 15: Python........................................................................................................................................437 Introduction.........................................................................................................................................437 Features........................................................................................................................................438 Python: The Right Tool for the Job..............................................................................................441 ...but not every job!......................................................................................................................441 Installing Python.................................................................................................................................441 Running Python..................................................................................................................................443 The Interactive Interpreter............................................................................................................443 Command Argument....................................................................................................................444 Script Argument...........................................................................................................................444 'Standalone' Executable................................................................................................................444 The Details..........................................................................................................................................445 Interpreter and ByteCompilation...............................................................................................445 Comment Syntax..........................................................................................................................445 Professional LINUX Programming vii 9. Table of Contents Chapter 15: Python Case Sensitivity............................................................................................................................446 BuiltIn Data Types and Operators.............................................................................................446 Variables.......................................................................................................................................455 Block Structure Syntax.................................................................................................................455 Statement Syntax..........................................................................................................................456 Functions......................................................................................................................................462 BuiltIn Functions........................................................................................................................463 Namespaces..................................................................................................................................464 Modules and Packages.................................................................................................................464 Some Modules From The Standard Distribution.........................................................................464 Classes and Objects......................................................................................................................465 Extending Python.........................................................................................................................467 An Example Program: Penny Pinching..............................................................................................467 Online Resources................................................................................................................................472 Summary.............................................................................................................................................472 Chapter 16: Creating Web Interfaces with PHP........................................................................................474 Overview.............................................................................................................................................474 PHP and ServerSide Scripting..........................................................................................................474 Serverside scripting....................................................................................................................474 PHP capabilities...........................................................................................................................476 Installing and Configuring PHP..........................................................................................................476 Building and Installing PHP as a CGI Interpreter.........................................................................477 Building and Installing PHP with Apache as an Apache module.................................................478 Installing PHP from an RPM.........................................................................................................479 Configuring PHP...........................................................................................................................479 Introducing PHP syntax......................................................................................................................481 Variables, Constants and Data types............................................................................................481 Operators in PHP..........................................................................................................................482 Statements....................................................................................................................................483 Functions......................................................................................................................................484 Arrays...........................................................................................................................................485 Using PHP with the DVD project.......................................................................................................485 HTTP, HTML and PHP................................................................................................................486 Application..........................................................................................................................................488 Login............................................................................................................................................488 Reservation status.........................................................................................................................488 Search for titles.............................................................................................................................488 Reserve Titles...............................................................................................................................488 Cancellation..................................................................................................................................488 dvdstorefunctions.php..................................................................................................................489 dvdstorecommon.php...................................................................................................................494 dvdstorelogin.php.........................................................................................................................497 dvdstoresearch.php.......................................................................................................................498 dvdstorestatus.php........................................................................................................................500 dvdstorecancel.php.......................................................................................................................500 dvdstorereserve.php......................................................................................................................501 Professional LINUX Programming viii 10. Table of Contents Chapter 16: Creating Web Interfaces with PHP Summary.............................................................................................................................................502 Resources............................................................................................................................................502 Chapter 17: Embedding and Extending Python with C/C++....................................................................503 Overview.............................................................................................................................................503 Extending Python with a C/C++ extension module.....................................................................503 Embedding Python in a Host Program.........................................................................................504 Developing Extension Modules in C/C++..........................................................................................504 Required Software Tools..............................................................................................................504 Extending Python Using SWIG...................................................................................................505 Extending Python Using the C API....................................................................................................529 Python Object Types....................................................................................................................529 Reference Counting and Ownership.............................................................................................530 Overview of Developing C Extension Modules...........................................................................531 Simple Functions..........................................................................................................................533 A Slightly More Complex Function.............................................................................................534 The Global Interpreter Lock.........................................................................................................535 Creating New Python Object Types.............................................................................................535 Encapsulating C++ Objects Using the CAPI.............................................................................542 Embedding Python in C/C++ Programs.............................................................................................544 The Embedding Development Environment................................................................................545 Embedding Python Using Highlevel Functions.........................................................................545 Statically Linking a Host Program to an Extension Module........................................................547 Embedding Python Using Lowerlevel Calls..............................................................................548 General Suggestions............................................................................................................................558 Resources............................................................................................................................................559 Summary.............................................................................................................................................559 Chapter 18: Remote Procedure Calls..........................................................................................................560 Overview.............................................................................................................................................560 A Simple Networked DVD Store Database........................................................................................561 BSD Sockets.................................................................................................................................561 Coding Issues Using the BSD Socket Interface...........................................................................565 ONC RPC Architecture and Concepts.........................................................................................566 Why Use RPC in the DVD Store Application?..................................................................................567 RPC Tools and Utilities......................................................................................................................568 rpcgen the RPC Protocol Compiler.............................................................................................568 Applying RPCs to the DVD Store......................................................................................................570 Functions Without Arguments or Return Types..........................................................................570 Functions with Simple Arguments and Simple Return Types.....................................................578 More Complex Examples.............................................................................................................579 Returning Arrays..........................................................................................................................582 Client Timeouts............................................................................................................................585 Authentication.....................................................................................................................................586 AUTH_NONE..............................................................................................................................586 AUTH_UNIX...............................................................................................................................586 ClientSide Authentication Support............................................................................................586 Professional LINUX Programming ix 11. Table of Contents Chapter 18: Remote Procedure Calls ServerSide Authentication Support............................................................................................587 Using RPC Servers with /etc/inetd.conf.............................................................................................589 Other Methods to Simplify Network Programming...........................................................................590 Resources............................................................................................................................................590 Summary.............................................................................................................................................591 Chapter 19: Multimedia and Linux.............................................................................................................592 Overview.............................................................................................................................................592 The Current State of Affairs...............................................................................................................592 Program Integration............................................................................................................................593 Sound..................................................................................................................................................593 Devices.........................................................................................................................................594 Handling Standard Audio Formats...............................................................................................595 DoItYourself............................................................................................................................597 Moving Pictures..................................................................................................................................611 Software Players...........................................................................................................................611 Hardware Players.........................................................................................................................612 Hybrids.........................................................................................................................................613 Political and Legal Issues....................................................................................................................614 References...........................................................................................................................................614 Summary.............................................................................................................................................615 Chapter 20: CORBA......................................................................................................................................616 Overview.............................................................................................................................................616 Interface Definition Language (IDL)..................................................................................................616 Object Request Broker (ORB)............................................................................................................616 Interoperable Object Reference (IOR)................................................................................................617 Object Adapter....................................................................................................................................617 Servers.................................................................................................................................................617 Naming and Trading services.............................................................................................................618 Evaluating CORBA............................................................................................................................618 CORBA and RPC...............................................................................................................................619 CORBA and Sockets..........................................................................................................................620 Systems Similar To CORBA..............................................................................................................621 DCOM or COM+.........................................................................................................................621 Java Remote Method Invocation (RMI).......................................................................................622 Enterprise JavaBeans....................................................................................................................622 IBM MQSeries.............................................................................................................................622 SOAP............................................................................................................................................622 IDL: Defining Interfaces.....................................................................................................................623 Modules........................................................................................................................................623 Interfaces......................................................................................................................................624 Basic Data Types..........................................................................................................................625 Template Types............................................................................................................................625 Example DVD Application..........................................................................................................630 Language Mappings............................................................................................................................633 Language Mapping Components..................................................................................................634 Professional LINUX Programming x 12. Table of Contents Chapter 20: CORBA C Mappings..................................................................................................................................635 An Introductory Example: A Simple Messaging System...................................................................640 Simple Messaging........................................................................................................................640 Using ORBit With The IDL.........................................................................................................641 The Message Client......................................................................................................................641 The Message Server.....................................................................................................................643 Compiling the ORBit Application................................................................................................644 Running The Message Application..............................................................................................645 Resources............................................................................................................................................645 Summary.............................................................................................................................................646 Chapter 21: Implementing CORBA with ORBit........................................................................................647 Overview.............................................................................................................................................647 Using CORBA for the DVD Store Application..................................................................................647 The DVD Client...........................................................................................................................648 The DVD Server...........................................................................................................................648 A Logging Server.........................................................................................................................648 Validation Server..........................................................................................................................648 Client Code...................................................................................................................................649 Log Server....................................................................................................................................649 DVD Server..................................................................................................................................650 Putting It All Together.................................................................................................................663 Using libgnorba...................................................................................................................................664 Configuring ORBit for MultiHost Use.............................................................................................664 GOAD GNOME Object Activation Directory................................................................................665 The Use of CORBA in GNOME........................................................................................................665 Advanced CORBA Functionality.......................................................................................................666 Dynamic Interface Invocation......................................................................................................667 CORBAServices...........................................................................................................................667 CORBAFacilities..........................................................................................................................671 Designing and Running Scalable CORBA Services....................................................................671 Resources............................................................................................................................................675 Summary.............................................................................................................................................675 Chapter 22: Diskless Systems.......................................................................................................................676 Overview.............................................................................................................................................676 A Little History...................................................................................................................................676 What, No Disk?...................................................................................................................................677 Why Go Diskless?...............................................................................................................................678 How Does It Work?............................................................................................................................678 Starting a Diskless System...........................................................................................................679 Network Identification for Diskless Systems...............................................................................680 Running an Operating System......................................................................................................681 Server Configuration...........................................................................................................................682 Boot Image Creation...........................................................................................................................684 Diskless Linux Kernel.........................................................................................................................685 Root File Systems...............................................................................................................................688 Professional LINUX Programming xi 13. Table of Contents Chapter 22: Diskless Systems Problems.............................................................................................................................................690 Client Applications.............................................................................................................................691 Summary.............................................................................................................................................692 Chapter 23: XML and libxml.......................................................................................................................694 Overview.............................................................................................................................................694 XML Document Structure..................................................................................................................695 XML Syntax.................................................................................................................................695 Wellformed XML......................................................................................................................696 Valid XML...................................................................................................................................699 XML Parsing.......................................................................................................................................703 DOM.............................................................................................................................................703 SAX..............................................................................................................................................704 libXML a.k.a. gnomexml...........................................................................................................704 The Complete Parser....................................................................................................................716 main()............................................................................................................................................717 start_document()............................................................................................................................718 end_document().............................................................................................................................718 start_element()...............................................................................................................................718 end_element()................................................................................................................................719 chars_found().................................................................................................................................719 get_event_from_name()................................................................................................................720 state_event_machine()...................................................................................................................721 Resources............................................................................................................................................722 Summary.............................................................................................................................................722 Chapter 24: Beowulf Clusters.......................................................................................................................723 Overview.............................................................................................................................................723 Hardware Setup...................................................................................................................................723 Software Configuration.......................................................................................................................724 Programming a Beowulf Cluster........................................................................................................724 Programming Using MPI....................................................................................................................724 The Basic Functionality of an MPI Program................................................................................726 Compiling and Executing a Simple MPI Program.......................................................................727 A Distributed MP3 Encoder.........................................................................................................728 Communication Performance of a Beowulf Cluster....................................................................730 A Review of Advanced Features of MPI.....................................................................................733 Some MPI Programming Examples:............................................................................................739 Programming with PVM.....................................................................................................................748 Comparison with MPI..................................................................................................................748 Obtaining and Installing PVM.....................................................................................................749 A Review of PVM Library Routines............................................................................................749 A Sample PVM Program..............................................................................................................751 Resources............................................................................................................................................753 Summary.............................................................................................................................................753 Some Useful Beowulf Links.........................................................................................................753 Professional LINUX Programming xii 14. Table of Contents Chapter 25: Documentation..........................................................................................................................754 Overview.............................................................................................................................................754 Defining the Audience..................................................................................................................754 End User Documentation: GUIs...................................................................................................755 Power User/System Administrator Documentation.....................................................................758 It's All About Structure: From Single Program to Distributed Systems......................................768 Documentation Tools...................................................................................................................768 Developer Documentation............................................................................................................775 Summary.............................................................................................................................................781 Chapter 26: Device Drivers...........................................................................................................................783 Overview.............................................................................................................................................783 Execution Context...............................................................................................................................783 Module and Initialization Code..........................................................................................................784 Linker Sections...................................................................................................................................785 Example Module Code.................................................................................................................785 PCI Devices and Drivers.....................................................................................................................786 struct pci_dev...............................................................................................................................786 Finding PCI Devices....................................................................................................................787 PCI Drivers...................................................................................................................................788 PCI Access Functions...................................................................................................................789 Resource Allocation.....................................................................................................................790 Interrupt Handlers.........................................................................................................................791 Access to User Space Memory.....................................................................................................793 The kiobuf Architecture...............................................................................................................795 Locking Primitives.......................................................................................................................798 Scheduling and Wait Queues.......................................................................................................800 Module Use Counts......................................................................................................................805 Making It Build............................................................................................................................806 What to Do with Your New Driver.....................................................................................................808 Submitting a New Driver.............................................................................................................809 Summary.............................................................................................................................................810 Chapter 27: Distributing the Appendix lication.........................................................................................811 Overview.............................................................................................................................................811 RPM Packages....................................................................................................................................812 The RPM User..............................................................................................................................812 What Do I Have Installed?...........................................................................................................813 The RPM Database.......................................................................................................................814 Anatomy of an RPM Package......................................................................................................822 Source Packages...........................................................................................................................823 configure, autoconf and automake......................................................................................................824 Source RPM Packages..................................................................................................................827 Building an RPM Package..................................................................................................................828 Patches................................................................................................................................................832 Making a Patch.............................................................................................................................832 Applying a Patch..........................................................................................................................834 GNATS...............................................................................................................................................834 Professional LINUX Programming xiii 15. Table of Contents Chapter 27: Distributing the Appendix lication Summary.............................................................................................................................................835 Chapter 28: Internationalization..................................................................................................................836 Overview.............................................................................................................................................836 I18N Terminology..............................................................................................................................837 Isn't Unicode the Answer?..................................................................................................................838 Unicode........................................................................................................................................838 The Character Encoding Problem.......................................................................................................843 ISO 2022: Extension Techniques for Coded Character Sets........................................................843 Programming with Unicode.........................................................................................................844 I18N Models and the System Environment........................................................................................849 The POSIX Locale Model............................................................................................................850 Collation........................................................................................................................................851 Character Type..............................................................................................................................852 Messages.......................................................................................................................................852 Monetary.......................................................................................................................................852 Numeric.........................................................................................................................................852 Time...............................................................................................................................................852 The X/Open Portability Guide (XPG)..........................................................................................853 Output Formatting and Input Processing............................................................................................855 The X Window System................................................................................................................855 Practical Considerations of I18N Programming.................................................................................860 I18N and Internal Text Processing...............................................................................................861 Programming with Locales..........................................................................................................862 Category Dimensions...................................................................................................................862 Category Conversions..................................................................................................................863 Category I/O.................................................................................................................................863 Category String formatting...........................................................................................................863 Category Character classification.................................................................................................863 Category Conversions..................................................................................................................863 Category String copying and filling.............................................................................................864 Category String searching............................................................................................................864 Category Collation.......................................................................................................................864 Category Regular expressions......................................................................................................864 Category Locale manipulation.....................................................................................................864 Category Message catalogs..........................................................................................................864 I18N and Xlib Programming........................................................................................................870 I18N and Linux GUIs...................................................................................................................876 Status of I18N for Linux Software Development........................................................................878 I18N in Real Software Development Projects....................................................................................878 Object Oriented Programming and I18N.....................................................................................879 Application Builders and I18N.....................................................................................................880 Where Next for Linux I18N?.......................................