source: trunk/minix/commands/yap/process.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.1 KB
RevLine 
[9]1/* Copyright (c) 1985 Ceriel J.H. Jacobs */
2
3# ifndef lint
4static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/process.c,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $";
5# endif
6
7# define _PROCESS_
8
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"
30
31static int nfiles; /* Number of filenames on command line */
32
33/*
34 * Visit a file, file name is "fn".
35 */
36
37VOID
38visitfile(fn) char *fn; {
39 struct stat statbuf;
40
41 if (stdf > 0) {
42 /*
43 * Close old input file
44 */
45 (VOID) close(stdf);
46 }
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;
55 }
56 else { /* Get size for percentage in prompt */
57 (VOID) fstat(stdf, &statbuf);
58 maxpos = statbuf.st_size;
59 }
60 do_clean();
61 d_clean();
62}
63
64/*
65 * process the input files, one by one.
66 * If there is none, input is from a pipe.
67 */
68
69VOID
70processfiles(n,argv) char ** argv; {
71
72 static char *dummies[3];
73 long arg;
74
75 if (!(nfiles = n)) {
76 /*
77 * Input from pipe
78 */
79 currentfile = "standard-input";
80 /*
81 * Take care that *(filenames - 1) and *(filenames + 1) are 0
82 */
83 filenames = &dummies[1];
84 d_clean();
85 do_clean();
86 }
87 else {
88 filenames = argv;
89 (VOID) nextfile(0);
90 }
91 *--argv = 0;
92 if (startcomm) {
93 n = getcomm(&arg);
94 if (commands[n].c_flags & NEEDS_SCREEN) {
95 redraw(0);
96 }
97 do_comm(n,arg);
98 startcomm = 0;
99 }
100 redraw(1);
101 if (setjmp(SetJmpBuf)) {
102 nflush();
103 redraw(1);
104 }
105 DoneSetJmp = 1;
106 for (;;) {
107 interrupt = 0;
108 n = getcomm(&arg);
109 do_comm(n, arg);
110 }
111}
112
113/*
114 * Get the next file the user asks for.
115 */
116
117int
118nextfile(n) {
119 register i;
120
121 if ((i = filecount + n) >= nfiles || i < 0) {
122 return 1;
123 }
124 filecount = i;
125 visitfile(filenames[i]);
126 return 0;
127}
Note: See TracBrowser for help on using the repository browser.