Download presentation
Presentation is loading. Please wait.
Published byOwen Powers Modified over 9 years ago
1
1 Programming Tools, C Programming in UNIX, Make, and SCCS
2
2 What we’ll be looking at… zC compiler zmake utility zsccs (Source Code Control System) zrcs (Revision Control System) zprogramming examples
3
3 Programming in C zUNIX was developed in C yprovides easy access for system calls yand a variety of libraries are available zyou use the editor of your choice (like vi) zcreate source code file ending with “.c”
4
4 C Programming Example /* Program name: Hello World Created: August 1, 1999 Author: Author’s name*/ #include main () { printf (“Hello World\n”); }
5
5 C Programming Example /* Program name: Hello World Created: August 1, 1999 Author: Author's name */ #include main () { char *name; printf("Please enter your name: "); scanf("%s", name); printf ("Hello, %s!\n", name); }
6
6 C Programming Example /* program - tabs.c convert tabs in standard input to spaces in standard output while keeping columns */ #include #defineTABSIZE8 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;
7
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 ---*/
8
8 #include statement zangle brackets yie. #include ylook for header file in standard directory y/usr/include on most systems zquotes “/xxx/yyy/zzz.h” ygets header file from directory you specify yie. #include “/alex/cprogs/ledg.h”
9
9 Compiling zgcc tab.c (We are using a freeware C compiler called gcc) zthere are 4 processes called in turn by gcc ypreprocessor ycompiler -- creates assembler code yassembler -- creates object -.o file ylinker (link editor) -- creates executable image xa.out (by default) xor you can specify with -o switch
10
10 other switches…. z-l (“el” not “one”) yspecify other libraries to search z-O yoptimize program z-o ygive executable the name of your choice z-c ysuppress linking (link editor) phase
11
11 cheap debug tool... zdisplay debug info from program to stderr yan example for the tab.c program might be: x fprintf(stderr, “before function is called, posn is %d\n”, posn) xremember posn was declared variable in the program yimbed as many “print” statements as you need xany where you need them.... zdon’t forget to remove ALL of the debug print statements when you are done!!! y....or at least comment them out!
12
12 lint zno, it isn’t something from your pocket… zit is a C program verifier ychecks program for bugs and possible portability problems ylint is VERY strict (unlike the C compiler) znot all bugs are catastrophic ybut if lint complains you should try to fix your code before compiling….
13
13 debuggers zyou can use whichever debugger you wish yor is available on your system zsome choices might be: yadb, sdb, debug, or dbx zthey tend to be command line oriented and interactive zcan be used to look into a core file as well!
14
14 Controlling Processes zfork() - creates a new child process zwait() - cause parent process to wait for child to finish running before it resumes execution zexit() - cause a process to exit znice() - change the priority of a process zkill() - send a signal to a process
15
15 Filesystem Access zstat() - get status information from an inode zaccess() - check file access permissions zcreat() - create a new file zopen() - open an existing file zread() - read a file zwrite() - write a file zclose() - close a file zunlink() - unlink a file (delete name reference to inode) zchmod() - change file access permissions zchown() - change file ownership
16
16 make utility zlarge programs tend to have many source and header files that depend on one another in complex ways zmake automates the process of determining which modules need to be compiled due to their dependency relationships zlooks at dependency lines in file makefile in the working directory
17
17 make (cont…) zat it’s simplest ydependency lines indicate relationships among files, specifying a target file that depends on one or more prerequisite files yif any prerequisite is newer than a target then update target based on construction commands that follow the dependency line ymake usually stops when it encounters an error during the construction process
18
18 a simple makefile target:prerequisite-list construction-commands for example….. to compile the program “mytab” mytab:tab.c gcc -o mytab tabs.c
19
19...a more complicated makefile form:size.o length.o gcc -o form size.o length.o size.o:size.c form.h gcc -c size.c length.o:length.c form.h gcc -c length.c form.h:num.h table.h cat num.h table.h > form.h
20
20 another example... # # makefile for compute # compute:compute.o calc.o gcc -o compute compute.o calc.o compute.o:compute.c compute.h gcc -c -O compute.c calc.o:calc.c gcc -c calc.c clean: note this is on next line @-rm *.o
21
21 executing make zmake (on aries you’ll find make in the /usr/ccs/bin directory) yuses makefile in the current working directory yif program is current, then make does nothing except tell you so yyou can directly refer to any label in the makefile xie. make clean xor. make compute (the default for this example)
22
22 touch zIf you perform a successful make, you will sometimes want to repeat the entire process again for testing purposes zIf 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 zTouch will change the last modification time of any file ie; touch -c tabs.c zBy default if the specified file doesn’t exist it is created with a zero size. To prevent use the –c option
23
23 Source Code Management zhelps keep track of projects involving many files over long periods of time zhelps keep track of versions yfor both source code and documentation za must have when more than one person is working on the project
24
24 Source Code Management zUNIX systems include two utilities for managing and tracking changes to files ySCCS, the Source Code Control System xincluded with SVR4 yRCS, the Revision Control System xprovided as add-on by many manufacturers zthey can be used on any text file ybut are usually used to manage source code and software documentation
25
25 SCCS zwhen you change a SCCS file and record the changes in SCCS, the set of changes is referred to as a delta zeach delta has an associated: yversion number zin SCCS the version number is known as a: ySCCS Identification String (SID)
26
26 SID zconsists of either 2 or 4 numbers zfirst two (which are always used) yrelease ylevel zdefault for initial file creation is 1.1 zyou have control over the numbering yyou can skip level numbers yand change release numbers
27
27 SID (continued…) zthe second two numbers represent: ybranch ysequence number zdefault to 1.1 yso you could see something like 2.3.1.1 zused when changes are made to an intermediate version of a file xbranching away from the sequential development
28
28 SCCS commands…. zsccs - a front end to the SCCS utility. yautomatically prepends SCCS/s. to any filename arguments ygreat stuff if you are using the SCCS subdirectory! zNote: 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
29
29 SCCS commands…. zBasic setup and editing zadmin ycreate or add new SCCS files ychange options for SCCS files ysccs admin -itab.c SCCS/s.tabs.c zget yretrieve text version of SCCS files y-e switch gets an editable text file! ysccs get –e SCCS/s.tabs.c yWill give you a tabs.c file that can be edited in your current directory yAlso creates a p.tabs.c that goes away when the file is returned to the library
30
30 SCCS commands…. zdelta yincorporate changes to one or more SCCS files yi.e., append a new delta ynormally removes the original text file zunget ycancel a previous get -e ydon’t create a new delta
31
31 SCCS commands…. zFixing deltas ycdc xchange delta comments ycomb xcombine consecutive deltas into a single delta xproduces script that must be run to actually accomplish the task yrmdel -r xremove a delta from SCCS files
32
32 SCCS commands…. zInformation yhelp xonline help facility yprs xprint formatted info about SCCS files ysact xreport on editing activity on SCCS files ywhat xsearch for @(#) pattern and print text that follows
33
33 SCCS commands…. zMore commands ysccsdiff xshow differences between any two SCCS files sccs sccsdiff -r1.1 -r1.2 SCCS/s.tab.c yval xvalidate an SCCS file
34
34 Creating a SCCS file zadmin -iname filename yname: file SCCS will encode yfilename: name of SCCS encoded file xalways start with s. xfor example: admin -ihello s.hello creates encoded file in the current working directory xor: admin -hello SCCS/s.hello assuming you’ve created a subdirectory called SCCS to store the encoded files separate from the working directory
35
35 Retrieving a SCCS file zget yretrieve text version of SCCS file yuse -e option to retrieve an editable file yif you are using the SCCS subdirectory: xsccs get -e SCCS/s.hello - and - y-r option xchange major version number (say 1.5 to 2.1) xretrieve earlier version (which causes a branch)
36
36 Recording changes to SCCS file zdelta yincorporate changes (add a delta) to one or more SCCS files yused to store changes made in file retrieved by get - e command yexample: xsccs delta hello -or- xSccs delta SCCS/s.hello yprompts for comment xend with D on line by itself
37
37 Controlling access to SCCS zuse admin to establish list of users who are allowed to make deltas. yby default the list is empty ywhich means anyone can make deltas yif the list is not empty only those on the list can make deltas ydone on a ‘per file’ basis - each file under control of SCCS has a separate list
38
38 Controlling access (continued) zexamples: yadding users to the list xsccs admin -ainstructor1 -astudent1 SCCS/s.hello xsccs admin -astudent2 -astudent3 hello yerasing users from the list xsccs admin -einstructor2 SCCS/s.hello ylock and unlock releases xsccs admin -fl2 hello(locks release 2 of hello) xsccs admin -fla hello(unlocks all releases)
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.