|
|
In this section we describe a variety of programming tools supported in the SCO OpenServer environment. By ``programming tools'' we mean those offered for use on a computer running a current release of SCO OpenServer. Since these are separately purchasable items, not all of them will necessarily be installed on your machine. On the other hand, you may have programming tools and languages available on your machine that came from another source and are not mentioned in this discussion.
C is intimately associated with the UNIX system since it was originally developed for use in recoding the UNIX system kernel. If you need to use a lot of SCO OpenServer function calls for low-level I/O, memory or device management, or interprocess communication, C is a logical first choice. Most programs, however, do not require such direct interfaces with the operating system, so the decision to choose C might better be based on one or more of the following characteristics:
Refer to Programming in standard C and C++ for complete details on C.
It takes fairly concentrated use of the C language over a period of several months to reach your full potential as a C programmer. If you are a casual programmer, you might make it easier for yourself if you choose a scripting-based alternative. Most of the discussion of system programming in this chapter are expressed in terms of C, although all of these interfaces may be used from C++ as well.
C++ is a general purpose programming language with a bias towards systems programming that:
Java is a general purpose programming language with a bias towards network programming that:
You can use the shell to create programs (new commands). Such programs are also called shell procedures. Refer to Software development tools for information on how to create and execute shell programs using commands, variables, positional parameters, return codes, and basic programming control structures.
The awk program (its name is an acronym constructed from the initials of its developers) scans an input file for lines that match pattern(s) described in a specification file. When awk finds a line that matches a pattern, it performs actions also described in the specification. It is not uncommon that an awk program can be written in a couple of lines to do functions that would take a couple of pages to describe in a programming language like FORTRAN or C. For example, consider a case where you have a set of records that consist of a key field and a second field that represents a quantity, and the task is to output the sum of the quantities for each key. The pseudocode for such a program might look like this:
SORT RECORDS Read the first record into a hold area; Read additional records until EOF; { If the key matches the key of the record in the hold area, add the quantity to the quantity field of the held record; If the key does not match the key of the held record, write the held record, move the new record to the hold area; } At EOF, write out the last record from the hold area.
An awk program to accomplish this task would look like this:
{ qty[$1] += $2 } END { for (key in qty) print key, qty[key] }This illustrates only one characteristic of awk; its ability to work with associative arrays. With awk, the input file does not have to be sorted, which is a requirement of the pseudoprogram.
For detailed information on awk, see ``Programming with awk'' and awk(C).
lex is a lexical analyzer that can be added to C or FORTRAN programs. A lexical analyzer is interested in the vocabulary of a language rather than its grammar, which is a system of rules defining the structure of a language. lex can produce C language subroutines that recognize regular expressions specified by the user, take some action when a regular expression is recognized, and pass the output stream on to the next program.
For detailed information on lex, see ``Lexical analysis with lex'' and lex(CP).
yacc (Yet Another Compiler Compiler) is a tool for describing an input language to a computer program. yacc produces a C language subroutine that parses an input stream according to rules laid down in a specification file. The yacc specification file establishes a set of grammatical rules together with actions to be taken when tokens in the input match the rules. lex may be used with yacc to control the input process and pass tokens to the parser that applies the grammatical rules.
For detailed information on yacc, see ``Parsing with yacc'' and yacc(CP).
m4 is a macro processor that can be used as a preprocessor for assembly language and C programs. For details, see ``m4 macro processor'' and m4(C).
These are two popular scripting languages for which pre-built open source implementations are available. Perl is oriented towards system utility tasks, while PHP is oriented towards web-based applications.