16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Development Tools<br />

CFLAGS = -Aa -O<br />

INCLUDE = -I$(BASE)/include<br />

LIBS = $(BASE)/lib/glib.a \<br />

$(BASE)/lib/ulib.a<br />

PROG<br />

OBJS<br />

= $(BASE)/bin/compsort<br />

= main.a compare.o quicksort.o \ rankorder.o<br />

$(PROG): $(OBJS)<br />

@echo "linking ..."<br />

@$(CC) $(CFLAGS) -o $(PROG) $(OBJS) $(LIBS)<br />

@echo "Done"<br />

$(OBJS): compare.h<br />

$(CC) $(CFLAGS) $(INCLUDE) -c $*.c<br />

# --------------------------------------------------<br />

TOUCH<br />

Allows you to change dates on individual files<br />

/* Example C program to demonstrate <strong>the</strong> make utility */<br />

/* convert tabs in standard input to spaces in<br />

standard output while maintaining columns */<br />

/*<br />

* $ cc tabs.c OR $ make tabs<br />

* $ a.out $ tabs<br />

* Four components of compilation process:<br />

* Preprocessor<br />

* Compiler<br />

* Assembler<br />

* Link Editor<br />

*/<br />

/* preprocessor directives */<br />

# include redefine TABSIZE 8<br />

/* prototypes */<br />

int findstop(int col);<br />

main()<br />

{<br />

int c; /* char read from stdin */<br />

int posn=0; /* column position of char */<br />

int inc; /* column increment to tab stop */<br />

}<br />

while ((c = getchar()) != EOF){<br />

switch(c){<br />

case '\t': /* c is a tab */<br />

inc = findstop(posn);<br />

posn += inc;<br />

for (; inc > 0; inc--)<br />

putchar(' ');<br />

break;<br />

case '\n': /* c is a newline */<br />

putchar(c);<br />

posn = 0;<br />

break;<br />

default: /* c is anything else */<br />

putchar(c);<br />

posn++;<br />

break;<br />

}<br />

}<br />

53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!