Use vis(3) to print unprintable characters
authorChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Thu, 6 Feb 1992 08:30:10 +0000 (00:30 -0800)
committerChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Thu, 6 Feb 1992 08:30:10 +0000 (00:30 -0800)
SCCS-vsn: bin/csh/str.c 5.12
SCCS-vsn: bin/csh/csh.c 5.34
SCCS-vsn: bin/csh/extern.h 5.13
SCCS-vsn: bin/csh/file.c 5.23
SCCS-vsn: bin/csh/func.c 5.34

usr/src/bin/csh/csh.c
usr/src/bin/csh/extern.h
usr/src/bin/csh/file.c
usr/src/bin/csh/func.c
usr/src/bin/csh/str.c

index f0e3346..468b278 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)csh.c      5.33 (Berkeley) %G%";
+static char sccsid[] = "@(#)csh.c      5.34 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -734,23 +734,39 @@ srcunit(unit, onlyown, hflg)
 void
 rechist()
 {
 void
 rechist()
 {
-    Char    buf[BUFSIZ];
+    Char    buf[BUFSIZ], hbuf[BUFSIZ], *hfile;
     int     fp, ftmp, oldidfds;
     int     fp, ftmp, oldidfds;
+    struct  varent *shist;
 
     if (!fast) {
 
     if (!fast) {
-       if (value(STRsavehist)[0] == '\0')
-           return;
-       (void) Strcpy(buf, value(STRhome));
-       (void) Strcat(buf, STRsldthist);
-       fp = creat(short2str(buf), 0600);
-       if (fp == -1)
-           return;
+       /*
+        * If $savehist is just set, we use the value of $history
+        * else we use the value in $savehist
+        */
+       if (shist = adrof(STRsavehist)) {
+           if (shist->vec[0][0] != '\0')
+               (void) Strcpy(hbuf, shist->vec[0]);
+           else if ((shist = adrof(STRhistory)) && shist->vec[0][0] != '\0')
+               (void) Strcpy(hbuf, shist->vec[0]);
+           else
+               return;
+       }
+       else
+           return;
+
+       if ((hfile = value(STRhistfile)) == STRNULL) {
+           hfile = Strcpy(buf, value(STRhome));
+           (void) Strcat(buf, STRsldthist);
+       }
+
+       if ((fp = creat(short2str(hfile), 0600)) == -1) 
+           return;
+
        oldidfds = didfds;
        didfds = 0;
        ftmp = SHOUT;
        SHOUT = fp;
        oldidfds = didfds;
        didfds = 0;
        ftmp = SHOUT;
        SHOUT = fp;
-       (void) Strcpy(buf, value(STRsavehist));
-       dumphist[2] = buf;
+       dumphist[2] = hbuf;
        dohist(dumphist, NULL);
        SHOUT = ftmp;
        (void) close(fp);
        dohist(dumphist, NULL);
        SHOUT = ftmp;
        (void) close(fp);
@@ -1172,8 +1188,11 @@ vis_fputc(ch, fp)
 
     if (ch & QUOTE) 
        return fputc(ch & TRIM, fp);
 
     if (ch & QUOTE) 
        return fputc(ch & TRIM, fp);
-    (void) vis(uenc, ch & TRIM, 
-              AsciiOnly ? VIS_NOSLASH : (VIS_NLS | VIS_NOSLASH), 0);
+    /* 
+     * XXX: When we are in AsciiOnly we want all characters >= 0200 to
+     * be encoded, but currently there is no way in vis to do that.
+     */
+    (void) vis(uenc, ch & TRIM, VIS_NOSLASH, 0);
     return fputs(uenc, fp);
 }
 
     return fputs(uenc, fp);
 }
 
index 94780a5..15ae831 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)extern.h    5.12 (Berkeley) %G%
+ *     @(#)extern.h    5.13 (Berkeley) %G%
  */
 
 #include <sys/cdefs.h>
  */
 
 #include <sys/cdefs.h>
@@ -138,7 +138,7 @@ void          rscan __P((Char **, void (*)()));
 void     tglob __P((Char **));
 void     trim __P((Char **));
 #ifdef FILEC
 void     tglob __P((Char **));
 void     trim __P((Char **));
 #ifdef FILEC
-int      sortscmp __P((void *, void *));
+int      sortscmp __P((const ptr_t, const ptr_t));
 #endif /* FILEC */
 
 /*
 #endif /* FILEC */
 
 /*
index 3be9429..0946920 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)file.c     5.22 (Berkeley) %G%";
+static char sccsid[] = "@(#)file.c     5.23 (Berkeley) %G%";
 #endif /* not lint */
 
 #ifdef FILEC
 #endif /* not lint */
 
 #ifdef FILEC
@@ -491,7 +491,8 @@ again:                              /* search for matches */
        return (numitems);
     }
     else {                     /* LIST */
        return (numitems);
     }
     else {                     /* LIST */
-       qsort((ptr_t) items, numitems, sizeof(items[0]), sortscmp);
+       qsort((ptr_t) items, numitems, sizeof(items[0]), 
+               (int (*) __P((const void *, const void *))) sortscmp);
        print_by_column(looking_for_lognames ? NULL : tilded_dir,
                        items, numitems);
        if (items != NULL)
        print_by_column(looking_for_lognames ? NULL : tilded_dir,
                        items, numitems);
        if (items != NULL)
index b50a447..f3a4541 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)func.c     5.33 (Berkeley) %G%";
+static char sccsid[] = "@(#)func.c     5.34 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -1230,9 +1230,13 @@ getval(lp, v)
 badscal:
        stderror(ERR_NAME | ERR_SCALEF);
     }
 badscal:
        stderror(ERR_NAME | ERR_SCALEF);
     }
-    if ((f + 0.5) >= (float) 0x7fffffff || (f + 0.5) < (float) 0x80000000)
-       stderror(ERR_NAME | ERR_SCALEF);
-    return ((RLIM_TYPE) (f + 0.5));
+    f += 0.5;
+    if (f > (float) 0x7fffffff)
+       return 0x7fffffff;
+    else if (f < (float) 0x80000000)
+       return 0x80000000;
+    else
+       return ((RLIM_TYPE) f);
 }
 
 static void
 }
 
 static void
index ee3f336..c3ed6d8 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)str.c      5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)str.c      5.12 (Berkeley) %G%";
 #endif /* not lint */
 
 #define MALLOC_INCR    128
 #endif /* not lint */
 
 #define MALLOC_INCR    128
@@ -431,8 +431,11 @@ vis_str(cp)
                            xmalloc((size_t) n * sizeof(char)));
        dstsize = n;
     }
                            xmalloc((size_t) n * sizeof(char)));
        dstsize = n;
     }
-    (void) strvis(sdst, short2str(cp), 
-                 AsciiOnly ? VIS_NOSLASH : (VIS_NLS | VIS_NOSLASH));
+    /* 
+     * XXX: When we are in AsciiOnly we want all characters >= 0200 to
+     * be encoded, but currently there is no way in vis to do that.
+     */
+    (void) strvis(sdst, short2str(cp), VIS_NOSLASH);
     return (sdst);
 }
     
     return (sdst);
 }