3 .\" Copyright (C) Caldera International Inc. 2001-2002.
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code and documentation must retain the above
10 .\" copyright notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed or owned by Caldera
17 .\" International, Inc.
18 .\" 4. Neither the name of Caldera International, Inc. nor the names of other
19 .\" contributors may be used to endorse or promote products derived from
20 .\" this software without specific prior written permission.
22 .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23 .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT,
27 .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 .\" POSSIBILITY OF SUCH DAMAGE.
35 .\" @(#)u4 8.1 (Berkeley) 6/8/93
40 There will be no attempt made to teach any of
41 the programming languages available
42 but a few words of advice are in order.
43 One of the reasons why the
45 system is a productive programming environment
46 is that there is already a rich set of tools available,
47 and facilities like pipes, I/O redirection,
48 and the capabilities of the shell
49 often make it possible to do a job
50 by pasting together programs that already exist
51 instead of writing from scratch.
55 The pipe mechanism lets you fabricate quite complicated operations
56 out of spare parts that already exist.
58 the first draft of the
63 cat ... \f2collect the files\f3
64 | tr ... \f2put each word on a new line\f3
65 | tr ... \f2delete punctuation, etc.\f3
66 | sort \f2into dictionary order\f3
67 | uniq \f2discard duplicates\f3
68 | comm \f2print words in text\f3
69 \f2 but not in dictionary\f3
71 More pieces have been added subsequently,
72 but this goes a long way
73 for such a small effort.
75 The editor can be made to do things that would normally
76 require special programs on other systems.
77 For example, to list the first and last lines of each of a
78 set of files, such as a book,
79 you could laboriously type
91 But you can do the job much more easily.
96 to get the list of filenames into a file.
97 Then edit this file to make the necessary
98 series of editing commands
99 (using the global commands of
108 the same output as the laborious hand typing.
111 you can use the fact that the shell will perform loops,
112 repeating a set of commands over and over again
113 for a set of arguments:
120 This sets the shell variable
122 to each file name in turn,
123 then does the command.
124 You can type this command at the terminal,
125 or put it in a file for later execution.
127 Programming the Shell
129 An option often overlooked by newcomers
130 is that the shell is itself a programming language,
138 and interrupt handling.
141 many building-block programs,
142 you can sometimes avoid writing a new program
143 merely by piecing together some of the building blocks
144 with shell command files.
146 We will not go into any details here;
147 examples and rules can be found in
149 An Introduction to the
157 If you are undertaking anything substantial,
158 C is the only reasonable choice of programming language:
168 as are most of the programs that run on it.
169 It is also an easy language to use
170 once you get started.
171 C is introduced and fully described in
173 The C Programming Language
175 B. W. Kernighan and D. M. Ritchie
176 (Prentice-Hall, 1978).
177 Several sections of the manual
178 describe the system interfaces, that is,
180 and similar functions.
184 for more complicated things.
186 Most input and output in C is best handled with the
187 standard I/O library,
188 which provides a set of I/O functions
189 that exist in compatible form on most machines
190 that have C compilers.
191 In general, it's wisest to confine the system interactions
192 in a program to the facilities provided by this library.
194 C programs that don't depend too much on special features of
197 can be moved to other computers that have C compilers.
198 The list of such machines grows daily;
199 in addition to the original
201 it currently includes
204 IBM 370 and PC families,
206 Data General Nova and Eclipse,
209 Motorola 68000 family (including machines like Sun Microsystems and
215 Calls to the standard I/O library will work on all of these machines.
217 There are a number of supporting programs that go with C.
219 checks C programs for potential portability problems,
220 and detects errors such as mismatched argument types
221 and uninitialized variables.
224 (anything whose source is on more than one file)
226 allows you to specify the dependencies among the source files
227 and the processing steps needed to make a new version;
228 it then checks the times that the pieces were last changed
229 and does the minimal amount of recompiling
230 to create a consistent updated version.
234 is useful for digging through the dead bodies
236 but is rather hard to learn to use effectively.
237 The most effective debugging tool is still
238 careful thought, coupled with judiciously placed
241 The C compiler provides a limited instrumentation service,
243 where programs spend their time and what parts are worth optimizing.
244 Compile the routines with the
247 after the test run, use
249 to print an execution profile.
252 will give you the gross run-time statistics
253 of a program, but they are not super accurate or reproducible.
261 there are two possibilities.
264 which gives you the decent control structures
265 and free-form input that characterize C,
266 yet lets you write code that
267 is still portable to other environments.
271 tends to produce large and relatively slow-running
273 Furthermore, supporting software like
276 etc., are all virtually useless with Fortran programs.
277 There may also be a Fortran 77 compiler on your system.
279 this is a viable alternative to
281 and has the non-trivial advantage that it is compatible with C
282 and related programs.
283 (The Ratfor processor
285 can be used with Fortran 77 too.)
287 If your application requires you to translate
288 a language into a set of actions or another language,
289 you are in effect building a compiler,
290 though probably a small one.
296 which helps you develop a compiler quickly.
299 lexical analyzer generator does the same job
300 for the simpler languages that can be expressed as regular expressions.
301 It can be used by itself,
302 or as a front end to recognize inputs for a
309 require some sophistication to use,
310 but the initial effort of learning them
311 can be repaid many times over in programs
312 that are easy to change later on.
316 systems also make available other languages,
318 Algol 68, APL, Basic, Lisp, Pascal, and Snobol.
319 Whether these are useful depends largely on the local environment:
320 if someone cares about the language and has worked on it,
321 it may be in good shape.
322 If not, the odds are strong that it
323 will be more trouble than it's worth.