Брайан Керниган - UNIX — универсальная среда программирования
- Название:UNIX — универсальная среда программирования
- Автор:
- Жанр:
- Издательство:Финансы и статистика
- Год:1992
- Город:Москва
- ISBN:5-289-00253-4
- Рейтинг:
- Избранное:Добавить в избранное
-
Отзывы:
-
Ваша оценка:
Брайан Керниган - UNIX — универсальная среда программирования краткое содержание
В книге американских авторов — разработчиков операционной системы UNIX — блестяще решена проблема автоматизации деятельности программиста, системной поддержки его творчества, выходящей за рамки языков программирования. Профессионалам открыт богатый "встроенный" арсенал системы UNIX. Многочисленными примерами иллюстрировано использование языка управления заданиями shell.
Для программистов-пользователей операционной системы UNIX.
UNIX — универсальная среда программирования - читать онлайн бесплатно ознакомительный отрывок
Интервал:
Закладка:
install(consts[i].name, VAR, consts[i].eval);
for (i = 0; builtins[i].name; i++) {
s = install(builtins[i].name, BLTIN, 0.0);
s->u.ptr = builtins[i].func;
}
}
3.7.16 makeapp
#!/bin/sh
cd hoc6
for i in hoc.y hoc.h symbol.c code.c init.c math.c makefile
do
echo "
**** $i ***************************************
"
sed 's/\\/\\e/g
s/^$/.sp .5/' $i |
awk '
{ print }
/(^ ;$)|(^})|(^%%)/ { print ".P3" }
'
done
3.7.17 makefile
CC = lcc
YFLAGS = -d
OBJS = hoc.o code.o init.o math.o symbol.o
hoc6: $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -lm -o hoc6
hoc.o code.o init.o symbol.o: hoc.h
code.o init.o symbol.o: x.tab.h
x.tab.h: y.tab.h
-cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
pr: hoc.y hoc.h code.c init.c math.c symbol.c
@pr $?
@touch pr
clean:
rm -f $(OBJS) [xy].tab.[ch]
3.7.18 math.c
#include
#include
extern int errno;
double errcheck();
double Log(x)
double x;
{
return errcheck(log(x), "log");
}
double Log10(x)
double x;
{
return errcheck(log10(x), "log10");
}
double Sqrt(x)
double x;
{
return errcheck(sqrt(x), "sqrt");
}
double Exp(x)
double x;
{
return errcheck(exp(x), "exp");
}
double Pow(x, y)
double x, y;
{
return errcheck(pow(x,y), "exponentiation");
}
double integer(x)
double x;
{
return (double)(long)x;
}
double errcheck(d, s) /* check result of library call */
double d;
char *s;
{
if (errno == EDOM) {
errno = 0;
execerror(s, "argument out of domain");
} else if (errno == ERANGE) {
errno = 0;
execerror(s, "result out of range");
}
return d;
}
3.7.19 mbox
From: Polyhedron Software Ltd <100013.461@CompuServe.COM>
To: ">INTERNET:bwk@research.att.com"
Subject: Message from Internet
Date: 10 May 91 04:07:07 EDT
Message-Id: <"910510080707 100013.461 CHE27-1"@CompuServe.COM>
Got your message. I'll pass it on to Tony. We haven't noticed any
errors at all in CompuServe mail, so far.
Regards
Graham Wood
From kam Thu May 9 10:58:06 EDT 1991
tony fritzpatrick called from england. he had spoken to you
last week about compuserve.
the number is:
100013,461
this is regarding the HOC6 listing.
he will call you back tomorrow
From pipe!subll276 Fri May 3 10:38:29 EDT 1991
Message to: BK
From: Tony Fitzpatrick
ECL
Highlands Farm
Greys Road
Henley OXON, RG 94 PS
ENGLAND
Telephone: 0491 - 575-989 (country code 45)
FAX: 0491 576 557
1. H would like permission
(which has already been granted by publisher) to
use HUC 6 program — commercial software.
2. Is the listing available on floppy disk?
3. Thank you for a very interesting and useful book.
4. He left his fax # and telephone #. He wasn't sure of the country code.
He would appreciate hearing from you via fax.
sub 11276
3.7.20 symbol.c
#include "hoc.h"
#include "y.tab.h"
static Symbol *symlist =0; /* symbol table: linked list */
Symbol *lookup(s) /* find s in symbol table */
char *s;
{
Symbol *sp;
for (sp = symlist; sp != (Symbol*)0; sp = sp->next)
if (strcmp(sp->name, s) == 0)
return sp;
return 0; /* 0 ==> not found */
}
Symbol *install(s, t, d) /* install s in symbol table */
char *s;
int t;
double d;
{
Symbol *sp;
char *emalloc();
sp = (Symbol*)emalloc(sizeof(Symbol));
sp->name = emalloc(strlen(s)+1); /* +1 for '\0' */
strcpy(sp->name, s);
sp->type = t;
sp->u.val = d;
sp->next = symlist; /* put at front of list */
symlist = sp;
return sp;
}
char *emalloc(n) /* check return from malloc */
unsigned n;
{
char *p, *malloc();
p = malloc(n);
if (p == 0)
execerror("out of memory", (char*)0);
return p;
}
3.8 Всякая всячина
3.8.1 addup1
awk '{ s += $'$1' }
END { print s }'
3.8.2. addup2
awk '
BEGIN { n = '$1' }
{ for (i = 1; i <= n; i++)
sum[i] += $i
}
END { for (i = 1; i <= n; i++) {
printf "%6g ", sum[i]
total += sum[i]
}
printf "; total = %6g\n", total
}'
3.8.3 backup
push -v panther $* /usr/bwk/eff/Code
3.8.4 backwards
# backwards: print input in backward line order
awk ' { line[NR] = $0 }
END { for (i = NR; i > 0; i--) print line[i] } ' $*
3.8.5 badpick.c
pick(s) /* offer choice of s */
char *s;
{
fprintf("%s? ", s);
if (ttyin() == 'y')
printf("%s\n", s);
}
3.8.6 bundle
# bundle: group files into distribution package
echo '# To unbundle, sh this file'
for i
do
echo "echo $i 1>&2"
echo "cat >$i <<'End of $i'"
cat $i
echo "End of $i"
done
3.8.7 cal
# cal: nicer interface to /usr/bin/cal
case $# in
0) set `date`; m=$2; y=$6 ;; # no args: use today
1) m=$1; set `date`; y=$6 ;; #1 arg: use this year
*) m=$1; y=$2 ;; #2 args: month and year
esac
case $m in
jan*|Jan*) m=1 ;;
feb*|Feb*) m=2 ;;
mar*|Mar*) m=3 ;;
apr*|Apr*) m=4 ;;
may*|May*) m=5 ;;
jun*|Jun*) m=6 ;;
jul*|Jul*) m=7 ;;
aug*|Aug*) m=8 ;;
sep*|Sep*) m=9 ;;
oct*|Oct*) m=10 ;;
nov*|Nov*) m=11 ;;
dec*|Dec*) m=12 ;;
[1-9]|10|11|12) ;; # numeric month
*) y=$m; m="" ;; # plain year
esac
/usr/bin/cal $m $y # run the real one
3.8.8 calendar1
# calendar: version 1 -- today only
awk <$HOME/calendar '
BEGIN { split("'"`date`"'", date) }
$1 == date[2] && $2 == date[3]
' | mail $NAME
3.8.9 calendar2
# calendar: version 2 -- today only, no quotes
(date; cat $HOME/calendar) |
awk '
NR == 1 { mon = $2; day = $3 } # set the date
NR > 1 && $1 == mon && $2 == day # print calendar lines
' | mail $NAME
3.8.10 calendar3
# calendar: version 3 -- today and tomorrow
awk <$HOME/calendar '
BEGIN {
x = "Jan 31 Feb 28 Mar 31 Apr 30 May 31 Jun 30 " \
"Jul 31 Aug 31 Sep 30 Oct 31 Nov 30 Dec 31 Jan 31"
split(x, data)
for (i = 1; i < 24; i += 2) {
days[data[i]] = data[i+1]
nextmon[data[i]] = data[i+2]
}
split("'"`date`"'", date)
mon1 = date[2]; day1 = date[3]
mon2 = mon1; day2 = day1 + 1
if (day1 >= days[mon1]) {
day2 = 1
mon2 = nextmon[mon1]
}
}
$1 == mon1 && $2 == day1 || $1 == mon2 && $2 == day2
' | mail $NAME
3.8.11 cat0.c
/* cat: minimal version */
#define SIZE 512 /* arbitrary */
main() {
char buf[SIZE];
int n;
while ((n = read(0, buf, sizeof buf)) > 0)
write(1, buf, n);
exit(0);
}
3.8.12 checkmail.c
/* checkmail: watch user's mailbox */
#include
#include
#include
char *progname;
char *maildir = "/usr/spool/mail"; /* system dependent */
main(argc, argv)
int argc;
char *argv[];
{
struct stat buf;
char *name, *getlogin();
int lastsize = 0;
progname = argv[0];
if ((name = getlogin()) == NULL)
error("can't get login name", (char*)0);
if (chdir(maildir) == -1)
Интервал:
Закладка: