Typo's.
[minix3.git] / commands / yap / process.c
blob2429127b39902cb8c3f8a9103a26ca592b0b528f
1 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
3 # ifndef lint
4 static char rcsid[] = "$Header$";
5 # endif
7 # define _PROCESS_
9 # include "in_all.h"
10 # if USG_OPEN
11 # include <fcntl.h>
12 # endif
13 # if BSD4_2_OPEN
14 # include <sys/file.h>
15 # endif
16 # if POSIX_OPEN
17 # include <sys/types.h>
18 # include <fcntl.h>
19 # endif
20 # include <sys/types.h>
21 # include <sys/stat.h>
22 # include "process.h"
23 # include "commands.h"
24 # include "display.h"
25 # include "prompt.h"
26 # include "getline.h"
27 # include "main.h"
28 # include "options.h"
29 # include "output.h"
31 static int nfiles; /* Number of filenames on command line */
34 * Visit a file, file name is "fn".
37 VOID
38 visitfile(fn) char *fn; {
39 struct stat statbuf;
41 if (stdf > 0) {
43 * Close old input file
45 (VOID) close(stdf);
47 currentfile = fn;
48 # if USG_OPEN || BSD4_2_OPEN || POSIX_OPEN
49 if ((stdf = open(fn,O_RDONLY,0)) < 0) {
50 # else
51 if ((stdf = open(fn,0)) < 0) {
52 # endif
53 error(": could not open");
54 maxpos = 0;
56 else { /* Get size for percentage in prompt */
57 (VOID) fstat(stdf, &statbuf);
58 maxpos = statbuf.st_size;
60 do_clean();
61 d_clean();
65 * process the input files, one by one.
66 * If there is none, input is from a pipe.
69 VOID
70 processfiles(n,argv) char ** argv; {
72 static char *dummies[3];
73 long arg;
75 if (!(nfiles = n)) {
77 * Input from pipe
79 currentfile = "standard-input";
81 * Take care that *(filenames - 1) and *(filenames + 1) are 0
83 filenames = &dummies[1];
84 d_clean();
85 do_clean();
87 else {
88 filenames = argv;
89 (VOID) nextfile(0);
91 *--argv = 0;
92 if (startcomm) {
93 n = getcomm(&arg);
94 if (commands[n].c_flags & NEEDS_SCREEN) {
95 redraw(0);
97 do_comm(n,arg);
98 startcomm = 0;
100 redraw(1);
101 if (setjmp(SetJmpBuf)) {
102 nflush();
103 redraw(1);
105 DoneSetJmp = 1;
106 for (;;) {
107 interrupt = 0;
108 n = getcomm(&arg);
109 do_comm(n, arg);
114 * Get the next file the user asks for.
118 nextfile(n) {
119 register i;
121 if ((i = filecount + n) >= nfiles || i < 0) {
122 return 1;
124 filecount = i;
125 visitfile(filenames[i]);
126 return 0;