Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[da0faa]: elkscmd / file_utils / more.c Maximize Restore History

Download this file

more.c    128 lines (107 with data), 1.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright (c) 1993 by David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
*
* Most simple built-in commands are here.
*/
#include "futils.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <pwd.h>
#include <grp.h>
#include <utime.h>
#include <errno.h>
void
main(argc, argv)
char **argv;
{
FILE *fp;
int fd, cin;
char *name;
char ch;
int line;
int col;
char buf[80];
cin = 0;
do {
if(argc >= 2) {
name = *(++argv);
fd = open(name, O_RDONLY);
if (fd == -1) {
perror(name);
exit(1);
}
write(STDOUT_FILENO,"<< ",3);
write(STDOUT_FILENO,name,strlen(name));
write(STDOUT_FILENO," >>\n",4);
} else {
fd = 0;
cin = open("/dev/tty0", "r");
if (!cin)
cin = fopen("/dev/console", "r");
write(STDOUT_FILENO,"<< stdin >>\n",12);
}
line = 1;
col = 0;
while ((fd > -1) && ((read(fd, &ch, 1)) != 0)) {
switch (ch) {
case '\r':
col = 0;
break;
case '\n':
line++;
col = 0;
break;
case '\t':
col = ((col + 1) | 0x07) + 1;
break;
case '\b':
if (col > 0)
col--;
break;
default:
col++;
}
putchar(ch);
if (col >= 80) {
col -= 80;
line++;
}
if (line < 25)
continue;
if (col > 0)
putchar('\n');
write(STDOUT_FILENO,"--More--",8);
fflush(stdout);
if (read(cin, buf, sizeof(buf)) < 1) {
perror("more: ");
if (fd > -1)
close(fd);
exit(0);
}
ch = buf[0];
if (ch == ':')
ch = buf[1];
switch (ch) {
case 'N':
case 'n':
close(fd);
fd = -1;
break;
case 'Q':
case 'q':
close(fd);
exit(0);
}
col = 0;
line = 1;
}
if (fd)
close(fd);
} while(--argc > 1);
exit(0);
}