updating sccs files due to restoring an older SCCS directory
[unix-history] / usr / src / usr.bin / ex / ex3.7recover / ex3.7recover.c
index 9781fb9..f97fa02 100644 (file)
@@ -1,20 +1,20 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/* Copyright (c) 1981 Regents of the University of California */
+static char *sccsid = "@(#)ex3.7recover.c      7.5     %G%";
+#include <stdio.h>     /* mjm: BUFSIZ: stdio = 512, VMUNIX = 1024 */
+#undef BUFSIZ          /* mjm: BUFSIZ different */
+#undef EOF             /* mjm: EOF and NULL effectively the same */
+#undef NULL
+
 #include "ex.h"
 #include "ex_temp.h"
 #include "ex_tty.h"
 #include "local/uparm.h"
 #include "ex.h"
 #include "ex_temp.h"
 #include "ex_tty.h"
 #include "local/uparm.h"
-
-#undef BUFSIZ
-#undef EOF
-#undef NULL
-
-#include <stdio.h>
 #include <sys/dir.h>
 
 #include <sys/dir.h>
 
+char xstr[1];          /* make loader happy */
+short tfile = -1;      /* ditto */
+
 /*
 /*
- * Ex recovery program
- *     exrecover dir name
- *     exrecover -r
  *
  * This program searches through the specified directory and then
  * the directory usrpath(preserve) looking for an instance of the specified
  *
  * This program searches through the specified directory and then
  * the directory usrpath(preserve) looking for an instance of the specified
@@ -138,7 +138,7 @@ main(argc, argv)
         */
        if (dol > zero) {
                addr1 = one; addr2 = dol; io = 1;
         */
        if (dol > zero) {
                addr1 = one; addr2 = dol; io = 1;
-               putfile();
+               putfile(0);
        }
 
        /*
        }
 
        /*
@@ -175,8 +175,13 @@ error(str, inf)
 {
 
        fprintf(stderr, str, inf);
 {
 
        fprintf(stderr, str, inf);
+#ifndef USG3TTY
        gtty(2, &tty);
        if ((tty.sg_flags & RAW) == 0)
        gtty(2, &tty);
        if ((tty.sg_flags & RAW) == 0)
+#else
+       ioctl(2, TCGETA, &tty);
+       if (tty.c_lflag & ICANON)
+#endif
                fprintf(stderr, "\n");
        exit(1);
 }
                fprintf(stderr, "\n");
        exit(1);
 }
@@ -190,15 +195,15 @@ error(str, inf)
 struct svfile {
        char    sf_name[FNSIZE + 1];
        int     sf_lines;
 struct svfile {
        char    sf_name[FNSIZE + 1];
        int     sf_lines;
-       char    sf_entry[DIRSIZ + 1];
+       char    sf_entry[MAXNAMLEN + 1];
        time_t  sf_time;
 };
 
 listfiles(dirname)
        char *dirname;
 {
        time_t  sf_time;
 };
 
 listfiles(dirname)
        char *dirname;
 {
-       register FILE *dir;
-       struct direct dirent;
+       register DIR *dir;
+       struct direct *dirent;
        int ecount, qucmp();
        register int f;
        char *cp;
        int ecount, qucmp();
        register int f;
        char *cp;
@@ -207,7 +212,7 @@ listfiles(dirname)
        /*
         * Open usrpath(preserve), and go there to make things quick.
         */
        /*
         * Open usrpath(preserve), and go there to make things quick.
         */
-       dir = fopen(dirname, "r");
+       dir = opendir(dirname);
        if (dir == NULL) {
                perror(dirname);
                return;
        if (dir == NULL) {
                perror(dirname);
                return;
@@ -222,13 +227,11 @@ listfiles(dirname)
         */
        fp = &svbuf[0];
        ecount = 0;
         */
        fp = &svbuf[0];
        ecount = 0;
-       while (fread((char *) &dirent, sizeof dirent, 1, dir) == 1) {
-               if (dirent.d_ino == 0)
-                       continue;
-               if (dirent.d_name[0] != 'E')
+       while ((dirent = readdir(dir)) != NULL) {
+               if (dirent->d_name[0] != 'E')
                        continue;
 #ifdef DEBUG
                        continue;
 #ifdef DEBUG
-               fprintf(stderr, "considering %s\n", dirent.d_name);
+               fprintf(stderr, "considering %s\n", dirent->d_name);
 #endif
                /*
                 * Name begins with E; open it and
 #endif
                /*
                 * Name begins with E; open it and
@@ -236,7 +239,7 @@ listfiles(dirname)
                 * If not, then don't bother with this file, it can't
                 * be ours.
                 */
                 * If not, then don't bother with this file, it can't
                 * be ours.
                 */
-               f = open(dirent.d_name, 0);
+               f = open(dirent->d_name, 0);
                if (f < 0) {
 #ifdef DEBUG
                        fprintf(stderr, "open failed\n");
                if (f < 0) {
 #ifdef DEBUG
                        fprintf(stderr, "open failed\n");
@@ -261,13 +264,13 @@ listfiles(dirname)
                /*
                 * Saved the day!
                 */
                /*
                 * Saved the day!
                 */
-               enter(fp++, dirent.d_name, ecount);
+               enter(fp++, dirent->d_name, ecount);
                ecount++;
 #ifdef DEBUG
                ecount++;
 #ifdef DEBUG
-               fprintf(stderr, "entered file %s\n", dirent.d_name);
+               fprintf(stderr, "entered file %s\n", dirent->d_name);
 #endif
        }
 #endif
        }
-       ignore(fclose(dir));
+       ignore(closedir(dir));
 
        /*
         * If any files were saved, then sort them and print
 
        /*
         * If any files were saved, then sort them and print
@@ -417,18 +420,15 @@ findtmp(dir)
 searchdir(dirname)
        char *dirname;
 {
 searchdir(dirname)
        char *dirname;
 {
-       struct direct dirent;
-       register FILE *dir;
+       struct direct *dirent;
+       register DIR *dir;
        char dbuf[BUFSIZ];
 
        char dbuf[BUFSIZ];
 
-       dir = fopen(dirname, "r");
+       dir = opendir(dirname);
        if (dir == NULL)
                return;
        if (dir == NULL)
                return;
-       setbuf(dir, dbuf);
-       while (fread((char *) &dirent, sizeof dirent, 1, dir) == 1) {
-               if (dirent.d_ino == 0)
-                       continue;
-               if (dirent.d_name[0] != 'E' || dirent.d_name[DIRSIZ - 1] != 0)
+       while ((dirent = readdir(dir)) != NULL) {
+               if (dirent->d_name[0] != 'E')
                        continue;
                /*
                 * Got a file in the directory starting with E...
                        continue;
                /*
                 * Got a file in the directory starting with E...
@@ -436,7 +436,7 @@ searchdir(dirname)
                 * later, and check that this is really a file
                 * we are looking for.
                 */
                 * later, and check that this is really a file
                 * we are looking for.
                 */
-               ignore(strcat(strcat(strcpy(nb, dirname), "/"), dirent.d_name));
+               ignore(strcat(strcat(strcpy(nb, dirname), "/"), dirent->d_name));
                if (yeah(nb)) {
                        /*
                         * Well, it is the file we are looking for.
                if (yeah(nb)) {
                        /*
                         * Well, it is the file we are looking for.
@@ -459,7 +459,7 @@ searchdir(dirname)
                }
                ignore(close(tfile));
        }
                }
                ignore(close(tfile));
        }
-       ignore(fclose(dir));
+       ignore(closedir(dir));
 }
 
 /*
 }
 
 /*