xref: /original-bsd/old/refer/deliv/deliv1.c (revision e59fb703)
1 /*-
2  * %sccs.include.proprietary.c%
3  */
4 
5 #ifndef lint
6 static char sccsid[] = "@(#)deliv1.c	4.2 (Berkeley) 04/18/91";
7 #endif /* not lint */
8 
9 #include <stdio.h>
10 
11 main(argc, argv)	/* goes from file:begin,l to actual characters */
12 char *argv[];
13 {
14 	FILE *fopen(), *fa = NULL;
15 	char line[750], *p, name[100], *strcpy();
16 	long lp;
17 	int len;
18 
19 	if (argc > 1 && argv[1] && argv[1][0])
20 		chdir(argv[1]);
21 	name[0] = NULL;
22 	while (gets(line))
23 	{
24 		if (line[0] == '$' && line[1] == '$')
25 		{
26 			chdir(line+2);
27 			continue;
28 		}
29 		for (p = line; *p != ':'; p++)
30 			;
31 		*p++ = 0;
32 		sscanf(p, "%ld,%d", &lp, &len);
33 		if (p == line)
34 			fa = stdin;
35 		else
36 			if (strcmp(name, line) != 0)
37 			{
38 				if (fa != NULL)
39 					fclose(fa);
40 				fa = fopen(line, "r");
41 				if (fa == NULL)
42 					err("Can't open %s", line);
43 				strcpy(name, line);
44 			}
45 		if (fa != NULL)
46 		{
47 			fseek (fa, lp, 0);
48 			fread (line, 1, len, fa);
49 			line[len] = 0;
50 			fputs(line, stdout);
51 		}
52 	}
53 }
54