Чтение онлайн

ЖАНРЫ

UNIX — универсальная среда программирования
Шрифт:

3.8.56

ttyin1.c

ttyin /* process response from /dev/tty (version 1) */

{

 char buf[BUFSIZ];

 FILE *efopen;

 static FILE *tty = NULL;

 if (tty == NULL)

tty = efopen("/dev/tty", "r");

 if (fgets(buf, BUFSIZ, tty) == NULL || buf[0] == 'q')

exit(0);

 else /* ordinary line */

return buf[0];

}

3.8.57

ttyin2.c

ttyin /* process response from /dev/tty (version 2) */

{

 char buf[BUFSIZ];

 FILE *efopen;

 static FILE *tty = NULL;

 if (tty == NULL)

tty = efopen("/dev/tty", "r");

 for (;;) {

if (fgets(buf,BUFSIZ,tty) == NULL || buf[0] == 'q')

exit(0);

else if (buf[0] == '!') {

system(buf+1); /* BUG here */

printf("!\n");

}

else /* ordinary line */

return buf[0];

 }

}

#include "system.c"

3.5.58

vis1.c

/* vis: make funny characters visible (version 1) */

#include <stdio.h>

#include <ctype.h>

main {

 int c;

 while ((c = getchar) != EOF)

if (isascii(c) &&

(isprint(c) || c=='\n' || c=='\t' || c==' '))

putchar(c);

else

printf("\\%03o", c);

 exit(0);

}

3.5.59

vis2.c

/* vis: make funny characters visible (version 2) */

#include <stdio.h>

#include <ctype.h>

main(argc, argv)

 int argc;

 char *argv[];

{

 int
с, strip = 0;

 if (argc > 1 && strcmp(argv[1] , "-s") == 0)

strip = 1;

 while ((c = getchar) != EOF) if (isascii(c) &&

(isprint(c) || c=='\n' || c=='\t' || c==' '))

putchar(c);

 else if (!strip)

printf("\\%03o", c);

 exit(0);

}

3.8.60

vis3.c

/* vis: make funny characters visible (version 3) */

#include <stdio.h>

#include <ctype.h>

int strip = 0; /* 1 => discard special characters */

main(argc, argv)

 int argc;

 char *argv[];

{

 int i;

 FILE *fp;

 while (argc > 1 && argv[1][0] == '-') {

switch (argv[1][1]) {

case 's': /* -s: strip funny chars */

strip = 1;

break;

default:

fprintf(stderr, "%s: unknown arg %s\n",

argv[0], argv[1]);

exit(1);

}

argc--;

argv++;

 }

 if (argc == 1)

vis(stdin);

 for (i = 1; i < argc; i++)

if ((fp=fopen(argv[i], "r")) == NULL) {

fprintf(stderr, "%s: can't open %s\n",

argv[0], argv[i]);

exit(1);

} else {

vis(fp);

fclose(fp);

}

 exit(0);

}

vis(fp) /* make chars visible in FILE *fp */

 FILE *fp;

{

 int c;

 while ((c = getc(fp)) != EOF)

if (isascii(c) &&

(isprint(c) || c=='\n' || c=='\t' || c==' '))

putchar(c);

else if (!strip)

printf("\\%03o",
с);

}

3.8.61

waitfile.c

/* waitfile: wait until file stops changing */

#include <stdio.h>

#include <sys/types.h>

#include <sys/stat.h>

char *progname;

main(argc, argv)

 int argc;

 char *argv[];

Поделиться с друзьями: