Table Of ContentS O F T W A R E
S Y S T E M S
SECOND EDITION
Joseph Vybihal
McGill University
Danielle Azar
Lebanese American University
Kendall Hunt
publish in g compa n y
Contents
Preface ix
Acknowledgments xiii
CHAPTER l Understanding Software Systems .......................................... 1
Software as a System 1
Tue Internet as an Example 5
Run-time Environments as an Example 11
CHAPTER 2 Understanding Unix. ....................................................... 15
Tue Unix Operating System 16
Tue Unix Shell 18
Tue Unix Session and Command-line Interface 19
Example Unix Session 40
Tue Unix Scripting Environment 42
Test Yourself! 53
CHAPTER 3 Understanding C ........................................................... 55
CompilingUnder Unix 55
Some Useful Standard C Libraries 100
Problems 103
CHAPTER 4 Understanding Systems Programming. ................................. 105
Modular Programming in C 106
GNU Tools 113
Tue Operating System and C API 136
CHAPTER 5 Understanding Internet Programming .................................. 151
Tue Internet Run-time Environment 151
Tue Internet and Inter-process Communication 152
CGI Programming 153
Tue OS Shell and CGI 157
CGiandC 158
Hyper Text Markup Language (HTML) 162
Tue HTML Document and Syntax 163
A Web Site 166
iii
HTML Commands 167
Cascading Style Sheets ( CSS) 172
A Catalog of CSS Statements 176
Server-side Communication 177
CHAPTER 6 Instant Python ............................................................. 183
Programming Example 1: Statements and Comments 184
Programming Example 2: Strings 184
Programming Example 3: Types, Variables, Identifiers, and Literals 185
Programming Example 4: The Print Statement 186
Programming Example 5: Prompting for Input 187
Programming Example 6: Lists 188
Programming Example 7: Tuples 190
Programming Example 8: Dictionaries 190
Programming Example 9: Conditionals and Boolean Expressions 191
Programming Example 10: The While-loop 193
Programming Example 11: The For-loop and the Range Function 193
Programming Example 12: Break, Continue, and Else Used with Loops 194
Programming Example 13: Functions 194
Programming Example 14: File I/0 and Exceptions 196
Programming Example 15: More on Exceptions 198
Programming Example 16: Writing an Object to a File (Pickling or Serialization) 199
Programming Example 17: Classes and Inheritance 200
Programming Example 18: Modules 202
Problems 205
CHAPTER 7 Instant Perl ................................................................ 207
Programming Example 1: Statements, Comments, and the Print Statement 208
Programming Example 2: Identifiers, Types, Variables, and Variable Substitutions 209
Programming Example 3: Arrays 212
Programming Example 4: More on Arrays 214
Programming Example 5: Expressions and Operators 215
Programming Example 6: Conditionals (if-statement) 216
Programming Example 7: Conditionals (unless-statement) 217
Programming Example 8: Loops 217
Programming Example 9: Subroutines 218
Programming Example 10: References 220
Programming Example 11: Regular Expressions 221
Programming Example 12: File Handles 223
Problems 225
iv
CHAPTER 8 Instant XML ............................................................... 227
XML File Structure 228
lheDTDFile 229
Problems 235
CHAPTER 9 "11'11\{[.an.dl>ll'I'l\ll. ..................................................... 237
XHTML 237
DHTML 246
Problems 251
CHAPTER 10 InstantJavaScript ......................................................... 253
Programming Example 1: A First Program 253
Programming Example 2: Variables and Types 254
Programming Example 3: Using JavaScript to Format a Page 255
Programming Example 4: Functions 256
Programming Example 5: Scope 257
Programming Example 6: Conditionals (The If-statement) 258
Programming Example 7: Conditionals (The Switch-statement) 259
Programming Example 8: Loops and Labels 260
Programming Example 9: Events 262
Programming Example 10 : Prompting for Input 263
Programming Example 11: Regular Expressions 264
Programming Example 12: Strings 265
Programming Example 13: Printing 267
Programming Example 14: Arrays 267
Programming Example 15: Tue Math Object 268
Programming Example 16: Forms 270
Problems 273
CHAPTER 11 Instantlava Applets ....................................................... 275
Programming Example 1: A Simple Hello World Applet 275
Programming Example 2: Drawing Shapes 276
Programming Example 3: Events and Listeners 278
Programming Example 4: Images 280
Programming Example 5: GUis 281
Programming Example 6: Audio 282
Programming Example 7: Animations 283
Problems 285
v
To my wife Electra and my children Abigail and Bethany,
as well as Remus. -JPV
To my life partner Elie, my parents, and my sister Pascale. - DA
Preface
INTRODUCTION
The Software Systems course at McGill University covers many fundamental topics in com-
puter science. This comprehensive approach allows the student to experience the manner in
which multiple software systems can be combined, through programming, into a single super
system. The problem with the course was its requirement that students should purchase five
textbooks. Textbooks are expensive. This reduced most students to purchasing less than what
they needed. The more adventurous student attempted to find material online, share, or pur-
chase older versions of these texts. We have attempted to address this issue through this single
textbook.
We assume that readers of this text have already completed at least one college-level program-
ming course. With this in mind, some of the details of how programming works are assumed
to be understood. Why an if-statement works the way it does, for example, is something the
reader should already be familiar with. This assumption would also go for understanding the
run-time of functions and methods. The text will define these terms and provide examples for
these concepts, but instruction will focus on more pertinent issues.
Our goal is to in troduce readers to programs that intercommunicate with each other. These
programs form a system, which in turn constitutes a new org anism, a super program. These
super programs are application programs in their o wn right; examples would be I nternet
stores and cloud computing. end of this readers will have amassed basic skills rang-
ing from systems programming to cloud computing. This text should be viewed as an irtroduc-
tion to these areas.
KEY FEATURES
The text first introduces readers to operating systems and shell scr ipting. This introduction
enables the student to manipulate the operating system environment both by hand (through
command-line commands) and through programs (using shell scripting). Since networks and
log-in sessions are an important part of modem operating systems, readers will acquire knowl-
edge of these domains as well, and also of how they can be influenced by programming. Our
operating system of choice is Unix (and its derivatives).
ix
The text continues with advanced programming techniques using the C Pr ogramming
language. Readers learn ho w to mix oper a ting system comm ands and C Pr ogramming
to create their first S oftware System. Fundamental programming tools and techniques
are introduced next, using the GNU Tool Set together with simple software engineering
strategies.
Then we look at how the Internet functions and communicates over a network. We see how
to program in that environment. Readers then learn how to combine all these elements
into a super program, like a web store, a web game, or a cloud application. The primary
tools for this programming will be the Internet technologies like HTML, CGI, CSS, XML,
PHP, and JavaScript. Server-side Internet technologies would include Unix, C, Python, and
Perl, to name a few.
The Instant chapters are used for fur ther explorations in languages and tools th at facilitate
software systems programming. Ify ou are an experienced programmer, you can go directly to
the Instant chapters. Each one stands on its own.
HOW TO USE THIS BOOK: CHAPTER ORGANIZATION
This text assumes readers have already completed a college-level course in pr ogramrning,
ideally Object Oriented programming; but, any programming language would do. Given this
qualification, readers can take two paths: "Other than the college-level programming course,
I do not know much more about programming" (figure Pl), or "I am an experienced program-
mer who wants to learn more about web development" (figure P2).
FIGURE P1: Standard Path FIGURE P2: Experienced Path
Chapter 6
Chapter 1
Chapter 7
Chapter 8
Chapter 5
Chapter 9
Chapters 6 & 7
Chapter 8
Chapter 10
Chapter 5
Chapter 9
Chapter 11
Chapters 1O & 11
x