Programming by Brian W
Total Page:16
File Type:pdf, Size:1020Kb
6sun® • microsystems PrograInIning Utilities for the Sun Workstation® Sun Microsystems, Inc. • 2550 Garcia Avenue • Mountain View, CA 94043 • 415-960-1300 Credits and Acknowledgements The chapters of this manual were originally derived from the work of many people at Bell Laboratories, the Univer sity of California at Berkeley', and other noble institutions. Their names and the titles of the original works appear here. UNIX Programming by Brian W. Kernighan and Dennis M. Ritchie, Bell Laboratories, Murray Hill, New Jersey. Lint, a C Program Checker by S. C. Johnson, Bell Laboratories, Murray Hill, New Jersey. Make -A Program for Maintaining Computer Programs by S. I. Feldman, Bell Laboratories, Murray Hill, New Jersey. The M4 Macro Processor by Brian W. Kernighan and Dennis M. Ritchie, Bell Laboratories, Murray Hill, New Jersey. Lex - A Lexical Analyzer Generator by M. E. Lesk and E. Schmidt, Bell Laboratories, Murray Hill, New Jersey. Yacc - Yet Another Compiler-Compiler by Stephen C. Johnson, Bell Laboratories, Murray Hill, New Jersey. Source Code Control System User's Guide by L. E. Bonanni and C. A. Salemi, Bell Laboratories, Piscataway, New Jersey. Source Code Control System by Eric Allman, Formerly of Project Ingres, University of California at Berkeley. Trademarks Multibus is a trademark of Intel Corporation. Sun Workstation is a trademark of Sun Microsystems Incorporated. UNIX is a trademark of Bell Laboratories. Copyright © 1983, 1984, 1985, by Sun Microsystems. This publication is protected by Federal Copyright Law, with all rights reserved. No part of this publica tion may be reproduced, stored in a retrieval system, translated, transcribed, or transmitted, in any form, or by any means manual, electric, electronic, electro-magnetic, mechanical, chemical, optical, or otherwise, without prior explicit written permission from Sun Microsystems. Contents Chapter 1 UNIX Programming ...................................................................................... 3 1.1. Basics ...................................................................................................................................... 3 1.2. The 'Standard Input' and 'Standard Output' ................................................... 4 1.3. The Standard 110 Library ............................................................................................ 6 1.4. Low-Level Input Output .............................................................................................. 9 1.5. Processes ............................................................................................................................... 14 1.6. Signals - Interrupts and All That ......................................................................... 19 1.7. The Standard 110 Library ............................................................................................ 23 Chapter 2 Tools for the C Programming Language ....................................... 33 2.1. ctags - Build Index File for C Functions ................................................. 33 2.2. Lint - A C Program Checker ................................................................................. 35 Chapter 3 Make - Maintaining Computer Programs ................................. 49 3.1. Basic Features .................................................................................................................... 50 3.2. Description Files .............................................................................................................. 52 3.3. Using the make Command ...................................................................................... 56 3.4. Implicit Rules .................................................................................................................... 59 3.5. Example ................................................................................................................................ 61 3.6. Suggestions and Warnings ......................................................................................... 63 3.7. Making Archive Libraries .......................................................................................... 64 3.8. Suffixes and Transformation Rules ....................................................................... 65 Chapter 4 Source Code Control System .................................................................. 71 -iii- Contents Continued 4.1. Learning me Lingo ......................................................................................................... 74 4.2. Creating sees Database Files with sees create ................................ 75 4.3. Retrieving Files for Compilation with sees get ................................... 75 4.4. Changing Files (Creating Deltas) ........................................................................... 76 4.5. Restoring Old Versions ................................................................................................ 79 4.6. Auditing Changes ............................................................................................................ 80 4.7. Shorthand Notations ...................................................................................................... 81 4.8. Using sees on a Project ............................................................................................... 82 4.9. Saving Yourself ................................................................................................................ 82 4.10. Managing SCCS Files wim sees admin ................................................ 83 4.11. Maintaining Different Versions (Branches) .................................................. 83 4.12. Using sees with make ........................................................................................... 85 4.13. SCCS Quick Reference ............................................................................................. 89 Chapter 5 Performance Analysis .................................................................................. 93 5.1. time - Display Time Used by Program ...................................................... 93 5.2. prof - Generate Profile of Program .............................................................. 96 5.3. gprof - Generate Call Graph Profile of Program ................................. 98 5.4. teov - Statement-level Analysis of Program ........................................... 100 Chapter 6 m4 - A Macro Processor ......................................................................... 107 6.1. Using the m4 Command .............................................................................................. 108 6.2. Defining Macros ............................................................................................................... 108 6.3. Quoting and Comments ............................................................................................... 109 6.4. Macros with Arguments .............................................................................................. 110 6.5. Arithmetic Built-ins ....................................................................................................... 111 6.6. File Manipulation ............................................................................................................ 112 6.7. Running System Commands ..................................................................................... 113 6.8. Conditionals ........................................................................................................................ 113 6.9. String Manipulation ....................................................................................................... 114 6.10. Printing ............................................................................................................................... 115 6.11. Summary of Built-in m4 Macros ....................................................................... 115 -iv- Contents Continued Chapter 7 Lex - A Lexical Analyzer Generator ............................................ 119 7.1. Lex Source ........................................................................................................................... 122 7.2. Lex Regular Expressions ............................................................................................. 123 7.3. Lex Actions ......................................................................................................................... 126 7.4. Ambiguous Source Rules ............................................................................................ 129 7.5. Lex Source Definitions ................................................................................................. 131 7.6. Using lex .......................................................................................................................... 132 7.7. Lex and Yacc ..................................................................................................................... 133 7.8. Examples .............................................................................................................................. 133 7.9. Left Context-Sensitivity .............................................................................................. 136 7.10. Character Set ................................................................................................................... 138 7.11. Summary of Source Format ...................................................................................