+ All Categories
Home > Documents > 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

1 Programming Tools, C Programming in UNIX, Make, and SCCS.

Date post: 03-Jan-2016
Category:
Upload: owen-powers
View: 225 times
Download: 1 times
Share this document with a friend
38
1 Programming Tools, C Programming in UNIX, Make, and SCCS
Transcript
Page 1: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

1

Programming Tools,C Programming in UNIX,Make, and SCCS

Page 2: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

2

What we’ll be looking at…

C compilermake utilitysccs (Source Code Control

System)rcs (Revision Control System)programming examples

Page 3: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

3

Programming in C

UNIX was developed in C provides easy access for system calls and a variety of libraries are available

you use the editor of your choice (like vi)

create source code file ending with “.c”

Page 4: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

4

C Programming Example

/* Program name: Hello World Created: August 1, 1999 Author: Author’s name*/

#include <stdio.h>main (){ printf (“Hello World\n”);}

Page 5: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

5

C Programming Example

/* Program name: Hello World Created: August 1, 1999 Author: Author's name */#include <stdio.h>main (){

char *name;

printf("Please enter your name: ");scanf("%s", name);printf ("Hello, %s!\n", name);

}

Page 6: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

6

C Programming Example

/* program - tabs.cconvert tabs in standard input to spaces in standard output while keeping columns

*/#include <stdio.h>#define TABSIZE 8

main(){char ch; /* character read from stdin */int posn = 0; /* column position of character */int inc; /* column increment to tab stop */

while ((ch = getchar() ) != EOF) switch(ch) { case ‘\t’: /* ch is a tab */

inc = findstop(posn);posn += inc;for ( ; inc > 0; inc--) putchar(‘ ‘); break;

Page 7: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

7

example (cont.)

case ‘\n’: /* ch is a newline */putchar(ch);posn = 0;break;

default: /* ch is anything else */putchar(ch);posn++;break;

}}

/*------------------------------------------------------------------*//* function to compute size of increment to next tab stop */

findstop()int col; /* column position of tab character */{return (TABSIZE - (col % TABSIZE));}

/*--- eof - tab.c ---*/

Page 8: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

8

#include statement

angle brackets <stdio.h> ie. #include <stdio.h> look for header file in standard directory /usr/include on most systems

quotes “/xxx/yyy/zzz.h” gets header file from directory you

specify ie. #include “/alex/cprogs/ledg.h”

Page 9: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

9

Compiling

gcc tab.c (We are using a freeware C compiler called gcc)

there are 4 processes called in turn by gcc preprocessor compiler -- creates assembler code assembler -- creates object - .o file linker (link editor) -- creates executable

image a.out (by default)or you can specify with -o switch

Page 10: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

10

other switches….

-l (“el” not “one”) specify other libraries to search

-O optimize program

-o give executable the name of your choice

-c suppress linking (link editor) phase

Page 11: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

11

cheap debug tool...

display debug info from program to stderr an example for the tab.c program might be:

fprintf(stderr, “before function is called, posn is %d\n”, posn) remember posn was declared variable in the program

imbed as many “print” statements as you need any where you need them....

don’t forget to remove ALL of the debug print statements when you are done!!! ....or at least comment them out!

Page 12: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

12

lint

no, it isn’t something from your pocket…

it is a C program verifier checks program for bugs and possible

portability problems lint is VERY strict (unlike the C compiler)

not all bugs are catastrophic but if lint complains you should try to fix

your code before compiling….

Page 13: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

13

debuggers

you can use whichever debugger you wish or is available on your system

some choices might be: adb, sdb, debug, or dbx

they tend to be command line oriented and interactive

can be used to look into a core file as well!

Page 14: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

14

Controlling Processes

fork() - creates a new child processwait() - cause parent process to wait

for child to finish running before it resumes execution

exit() - cause a process to exitnice() - change the priority of a

processkill() - send a signal to a process

Page 15: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

15

Filesystem Access

stat() - get status information from an inode access() - check file access permissions creat() - create a new file open() - open an existing file read() - read a file write() - write a file close() - close a file unlink() - unlink a file (delete name reference to

inode) chmod() - change file access permissions chown() - change file ownership

Page 16: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

16

make utility

large programs tend to have many source and header files that depend on one another in complex ways

make automates the process of determining which modules need to be compiled due to their dependency relationships

looks at dependency lines in file makefile in the working directory

Page 17: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

17

make (cont…)

at it’s simplest dependency lines indicate relationships

among files, specifying a target file that depends on one or more prerequisite files

if any prerequisite is newer than a target then update target based on construction commands that follow the dependency line

make usually stops when it encounters an error during the construction process

Page 18: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

18

a simple makefile

target: prerequisite-listconstruction-commands

for example…..to compile the program “mytab”

mytab: tab.cgcc -o mytab tabs.c

Page 19: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

19

...a more complicated makefile

form: size.o length.ogcc -o form size.o length.o

size.o: size.c form.hgcc -c size.c

length.o: length.c form.hgcc -c length.c

form.h: num.h table.hcat num.h table.h > form.h

Page 20: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

20

another example...## makefile for compute#compute: compute.o calc.o

gcc -o compute compute.o calc.o

compute.o: compute.c compute.hgcc -c -O compute.c

calc.o: calc.cgcc -c calc.c

clean: note this is on next line@- rm *.o

Page 21: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

21

executing makemake<cr> (on aries you’ll find make in the

/usr/ccs/bin directory) uses makefile in the current working

directory if program is current, then make does

nothing except tell you so you can directly refer to any label in the

makefileie. make cleanor. make compute (the default for this

example)

Page 22: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

22

touch

If you perform a successful make, you will sometimes want to repeat the entire process again for testing purposes

If you get the message “file” is up to date then it is telling you that nothing has changed and it doesn’t need to run again

Touch will change the last modification time of any file ie; touch -c tabs.c

By default if the specified file doesn’t exist it is created with a zero size. To prevent use the –c option

Page 23: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

23

Source Code Management

helps keep track of projects involving many files over long periods of time

helps keep track of versions for both source code and

documentationa must have when more than one

person is working on the project

Page 24: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

24

Source Code Management

UNIX systems include two utilities for managing and tracking changes to files SCCS, the Source Code Control System

included with SVR4 RCS, the Revision Control System

provided as add-on by many manufacturers

they can be used on any text file but are usually used to manage source

code and software documentation

Page 25: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

25

SCCS

when you change a SCCS file and record the changes in SCCS, the set of changes is referred to as a delta

each delta has an associated: version number

in SCCS the version number is known as a: SCCS Identification String (SID)

Page 26: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

26

SID

consists of either 2 or 4 numbersfirst two (which are always used)

release level

default for initial file creation is 1.1you have control over the numbering

you can skip level numbers and change release numbers

Page 27: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

27

SID (continued…)

the second two numbers represent: branch sequence number

default to 1.1 so you could see something like 2.3.1.1

used when changes are made to an intermediate version of a file

branching away from the sequential development

Page 28: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

28

SCCS commands….

sccs - a front end to the SCCS utility. automatically prepends SCCS/s. to any

filename arguments great stuff if you are using the SCCS

subdirectory!

Note: you’ll need to know where the sccs commands such as admin live. I have the path included for some examples but not all in the following slides. On aries this path is /usr/bin

Page 29: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

29

SCCS commands…. Basic setup and editing admin

create or add new SCCS files change options for SCCS files sccs admin -itab.c SCCS/s.tabs.c

get retrieve text version of SCCS files -e switch gets an editable text file! sccs get –e SCCS/s.tabs.c Will give you a tabs.c file that can be edited in your

current directory Also creates a p.tabs.c that goes away when the file is

returned to the library

Page 30: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

30

SCCS commands….

delta incorporate changes to one or more SCCS

files i.e., append a new delta normally removes the original text file

unget cancel a previous get -e don’t create a new delta

Page 31: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

31

SCCS commands….

Fixing deltas cdc

change delta comments comb

combine consecutive deltas into a single delta

produces script that must be run to actually accomplish the task

rmdel -rremove a delta from SCCS files

Page 32: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

32

SCCS commands….

Information help

online help facility

prsprint formatted info about SCCS files

sactreport on editing activity on SCCS files

whatsearch for @(#) pattern and print text that follows

Page 33: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

33

SCCS commands….

More commands sccsdiff

show differences between any two SCCS files sccs sccsdiff -r1.1 -r1.2 SCCS/s.tab.c

valvalidate an SCCS file

Page 34: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

34

Creating a SCCS file

admin -iname filename name: file SCCS will encode filename: name of SCCS encoded file

always start with s.for example: admin -ihello s.hello

• creates encoded file in the current working directory

or: admin -hello SCCS/s.hello• assuming you’ve created a subdirectory called

SCCS to store the encoded files separate from the working directory

Page 35: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

35

Retrieving a SCCS file

get retrieve text version of SCCS file use -e option to retrieve an editable file if you are using the SCCS subdirectory:

sccs get -e SCCS/s.hello - and -

-r option change major version number (say 1.5 to 2.1)retrieve earlier version (which causes a

branch)

Page 36: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

36

Recording changes to SCCS file

delta incorporate changes (add a delta) to one or

more SCCS files used to store changes made in file retrieved by

get -e command example:

sccs delta hello -or- Sccs delta SCCS/s.hello

prompts for commentend with <CTRL>D on line by itself

Page 37: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

37

Controlling access to SCCS

use admin to establish list of users who are allowed to make deltas. by default the list is empty which means anyone can make deltas if the list is not empty only those on the

list can make deltas done on a ‘per file’ basis - each file under

control of SCCS has a separate list

Page 38: 1 Programming Tools, C Programming in UNIX, Make, and SCCS.

38

Controlling access (continued)

examples: adding users to the list

sccs admin -ainstructor1 -astudent1 SCCS/s.hellosccs admin -astudent2 -astudent3 hello

erasing users from the listsccs admin -einstructor2 SCCS/s.hello

lock and unlock releasessccs admin -fl2 hello (locks release 2 of hello)sccs admin -fla hello (unlocks all releases)


Recommended