prompt:> cp `ataclib`/tutorial/* .To compile the wordcount program from the Makefile:
prompt:> makeThe output from make should look approximately like this:
cc -g -c wc.c
cc -g -c main.c
cc -g -o wordcount wc.o main.o
If you wish to compile the program manually, in one step:
prompt:> cc -g -o wordcount main.c wc.cThe complete source listings of the main.c, wc.c, and Makefile files are listed in Figure A- 1 through Figure A-3.
To remove the previously created object files and the executable file:
prompt:> make cleanTo compile the wordcount program with atac by prefixing the standard C compiler, cc:
prompt:> make CC="atac cc"The output generated by make should look something like this:
atac cc -g -c wc.c
atac cc -g -c main.c
atac cc -g -o wordcount wc.o main.o
/*
* main.c
*
* Modified from ``The C Programming Language''
* by Kernighan & Ritchie, 1978.
* page 18.
*
*/
#include <stdio.h>
main(argc,argv)
int argc;
char **argv;
{
char *p;
int linect, wordct, charct;
long tlinect = 0;
long twordct = 0;
long tcharct = 0;
int doline = 0;
int doword = 0;
int dochar = 0;
FILE *file;
if (argc > 1 && argv[1][0] == `-') {
for (p = argv[1] + 1; *p; ++p)
switch(*p) {
case `l':
doline = 1;
break;
case `w':
doword = 1;
break;
case `c':
dochar = 1;
break;
default:
fprintf(stderr, "invalid option: -%c\n",
*p);
case `?':
fputs("usage: wc [-lwc] [files]\n",
stderr);
return 1;
}
argv += 2;
}
|
else {
++argv;
doline = 1;
doword = 1;
dochar = 1;
}
do {
if (!*argv) {
count(stdin, &linect, &wordct, &charct);
print(doline, doword, dochar, linect,
wordct, charct, "");
return;
}
else {
file = fopen(*argv, "r");
if (file == NULL) {
perror(*argv);
return 1;
}
count(file, &linect, &wordct, &charct);
fclose(file);
print(doline, doword, dochar, linect, wordct,
charct, *argv);
}
tlinect += linect;
twordct += wordct;
tcharct += charct;
} while(*++argv);
print(doline, doword, dochar, tlinect, twordct,
tcharct, "total");
return 0;
}
static print(doline, doword, dochar, linect,
wordct, charct, file)
int doline, doword, dochar;
int linect, wordct, charct;
char *file;
{
if (doline)
printf(" %7ld", linect);
if (doword)
printf(" %7ld", wordct);
if (dochar)
printf(" %7ld", charct);
printf(" %s\n", file);
}
|
/*
* wc.c
*
* Modified from ``The C Programming Language''
* by Kernighan & Ritchie, 1978.
* page 18.
*
*/
#include <stdio.h>
#define IN1 /* inside a word */
#define OUT0 /* outside a word */
/* count lines, words and characters in input */
count(file, p_nl, p_nw, p_nc)
FILE *file;
int *p_nl, *p_nw, *p_nc;
{
|
int c, nl, nw, nc, state;
state = OUT;
nl = 0;
nw = 0;
nc = 0;
while (EOF != (c = getc(file))) {
++nc;
if (c == `\n')
++nl;
if (c == ` ` || c == `\n' || c == `\t')
state = OUT;
else if (state == OUT) {
state = IN;
++nw;
}
}
*p_nl = nl;
*p_nw = nw;
*p_nc = nc;
}
|
CFLAGS=-g wordcount: wc.o main.o $(CC) -g -o wordcount wc.o main.o wc_err: wc.o main_err.o $(CC) -g -o wc_err wc.o main_err.o clean: -@atactm wordcount.trace -@atactm wc_err.trace rm -f *.o wordcount wc_err rm -f *.atac *.trace *.dif *.features tests_log |
prompt:> atac cc -g -o wordcount main.c wc.cIn Section 13.2, A Tutorial, you are instructed to compile the wc_err program with atac. Do this by:
prompt:> make wc_err CC="atac cc"
prompt:> xcopy /I "C:\Program Files\Cleanscape\xSuds\tutorial\*" .If you installed into a different directory, use the path you chose for your installation in this command.
To compile the wordcount program from the Makefile:
prompt:> nmake -f makefile_ibm
prompt:> nmake -f makefile_mscIf you use the IBM C compiler Figure A-4 shows about how the output from nmake will appear.
prompt:> nmake -f makefile_ibm
IBM(R) Program Maintenance Utility for Windows(R)
Version 3.50.000 Feb 13 1996
Copyright (C) IBM Corporation 1988-1995
Copyright (C) Microsoft Corp. 1988-1991
All rights reserved.
icc /W0 /Q /c wc.c
icc /W0 /Q /c main.c
icc /W0 /Q wc.obj main.obj /Fe wordcount.exe.
|
If you use the Microsoft C compiler, it will look something like Figure A-5.
prompt:> nmake -f makefile_msc
Microsoft (R) Program Maintenance Utility Version 1.61.6038
Copyright (C) Microsoft Corp 1988-1996. All rights reserved.
cl /nologo /w /c wc.c
wc.c
cl /nologo /w /c main.c
main.c
cl /nologo /w wc.obj main.obj /link /out:wordcount.exe
|
The complete source listings of the main.c and wc.c files are in Figure A-1 and Figure A- 2. The Makefile file is listed in Figure A-6 for the IBM compiler and Figure A-7 for the Microsoft compiler.
CFLAGS=/W0 /Q wordcount.exe: wc.obj main.obj $(CC) $(CFLAGS) wc.obj main.obj /Fe wordcount.exe wc_err.exe: wc.obj main_err.obj $(CC) $(CFLAGS) wc.obj main_err.obj /Fe wc_err.exe clean: del wc.obj main.obj main_err.obj wordcount.exe wc_err.exe del wc.atac main.atac main_err.atac wordcount.trace wc_err.trace del main.dif wc.dif wc.features tests_log.txt |
CFLAGS=/nologo /w
wordcount.exe: wc.obj main.obj
$(CC) $(CFLAGS) wc.obj main.obj /link /out:wordcount.exe
wc_err.exe: wc.obj main_err.obj
$(CC) $(CFLAGS) wc.obj main_err.obj /link /out:wc_err.exe
clean:
del wc.obj main.obj main_err.obj wordcount.exe wc_err.exe
del wc.atac main.atac main_err.atac wordcount.trace wc_err.trace
del main.dif wc.dif wc.features tests_log.txt
|
To remove the previously created object files and the executable file:
prompt:> nmake -f makefile_ibm clean
prompt:> nmake -f makefile_msc cleanTo see the approximate output of these commands, refer to Figure A-8 or Figure A-9, according to the compiler you are using.
prompt:> nmake -f makefile_ibm clean
IBM(R) Program Maintenance Utility for Windows(R)
Version 3.50.000 Feb 13 1996
Copyright (C) IBM Corporation 1988-1995
Copyright (C) Microsoft Corp. 1988-1991
All rights reserved.
del wc.obj main.obj main_err.obj wordcount.exe wc_err.exe
Could Not Find D:\tutorial\main_err.obj
Could Not Find D:\tutorial\wc_err.exe
del wc.atac main.atac main_err.atac wordcount.trace wc_err.trace
Could Not Find D:\USERS\JLA\tutorial\wc.atac
Could Not Find D:\tutorial\main.atac
Could Not Find D:\tutorial\main_err.atac
Could Not Find D:\tutorial\wordcount.trace
Could Not Find D:\tutorial\wc_err.trace
del main.dif wc.dif wc.features tests_log.txt
Could Not Find D:\tutorial\main.dif
Could Not Find D:\tutorial\wc.dif
Could Not Find D:\tutorial\wc.features
Could Not Find D:\tutorial\tests_log.txt
|
prompt:> nmake -f makefile_msc clean
Microsoft (R) Program Maintenance Utility Version 1.61.6038
Copyright (C) Microsoft Corp 1988-1996. All rights reserved.
del wc.obj main.obj main_err.obj wordcount.exe wc_err.exe
Could Not Find D:\tutorial\main_err.obj
Could Not Find D:\tutorial\wc_err.exe
del wc.atac main.atac main_err.atac wordcount.trace wc_err.trace
Could Not Find D:\tutorial\main_err.atac
Could Not Find D:\tutorial\wordcount.trace
Could Not Find D:\tutorial\wc_err.trace
del main.dif wc.dif wc.features tests_log.txt
Could Not Find D:\tutorial\main.dif
Could Not Find D:\tutorial\wc.dif
Could Not Find D:\tutorial\wc.features
Could Not Find D:\tutorial\tests_log.txt
|
To compile the wordcount program with ATAC:
prompt:> nmake -f makefile_ibm CC=atacICC wordcount.exe
prompt:> nmake -f makefile_msc CC=atacCL wordcount.exeThe output generated by nmake should look something like :
prompt:> nmake -f makefile_ibm CC=atacICC wordcount.exe
IBM(R) Program Maintenance Utility for Windows(R)
Version 3.50.000 Feb 13 1996
Copyright (C) IBM Corporation 1988-1995
Copyright (C) Microsoft Corp. 1988-1991
All rights reserved.
atacICC /W0 /Q /c wc.c
atacICC /W0 /Q /c main.c
atacICC /W0 /Q wc.obj main.obj /Fe wordcount.exe
|
prompt:> nmake -f makefile_msc CC=atacCL wordcount.exe
Microsoft (R) Program Maintenance Utility Version 1.61.6038
Copyright (C) Microsoft Corp 1988-1996. All rights reserved.
atacCL /nologo /w /c wc.c
wc.c
wc.c
atacCL /nologo /w /c main.c
main.c
main.c
atacCL /nologo /w wc.obj main.obj /link /out:wordcount.exe
|
In Section 13.2, A Tutorial, you are instructed to compile the wc_err program with ATAC. Do this by:
prompt:> nmake -f makefile_ibm wc_err.exe
prompt:> nmake -f makefile_msc wc_err.exe