[comp.unix.xenix] Kernel Hacks & Weird Filenames

root@conexch.UUCP (Larry Dighera) (05/16/88)

In article <3267@phri.UUCP> roy@phri.UUCP (Roy Smith) writes:
>gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>> Geez.  Haven't you heard of "pipes and filters"?  Pipe the output of "ls"
>> into a filter [...]
>
>	In this case, it's a little bit complicated since the filter would
>have to be syntax-sensitive.  Just doing "ls | cat -v" is no good because you
>want to escape \n in file names but not at the end of lines.  You probably
>want to escape spaces in file names but no place else, etc.  I'm sure it's
>possible to write some sort of sed command which takes:
>
>-rw-r--r--  1 roy           491 Apr 27 14:01 calendar
>-rw-r--r--  1 roy           817 May 11 13:15  foo bar
>
>and correctly figures out that the second file name is " foo bar" and only
>escapes those two spaces, but it would be ugly and difficult.  Try and make
>that filter general enough to deal with the varient formats of "ls", "ls -l",
>"ls -ls", "ls -lsi", and "ls -lsig" and it sure starts to look like building
>control-character escapes into ls isn't such a bad idea after all.
>-- 
>Roy Smith, System Administrator
>Public Health Research Institute
>455 First Avenue, New York, NY 10016
>{allegra,philabs,cmcl2,rutgers}!phri!roy -or- phri!roy@uunet.uu.net

I must not understand the problem here, because this all looks very simple
to me.  

First, SCO Xenix's ls command supports the -b option which forces printing of
non-graphic characters in file names to be in the octal \ddd notaion.

Secondly, ls * | od -c essentially does the same.

Thirdly, here's a filter that displays all characters printable or not:


/* see.c    04/30/1986  20:14:14    Steve Kirby  */
 
#include <stdio.h>
#include <ctype.h>
 
main(argc,argv)
int argc;  char **argv;
{
  char *prog = argv[0];
 
  FILE *fopen(), *iFP;
 
  if (++argv, --argc)  
    for ( ; argc; ++argv, --argc)
    {
      if ( ( iFP = fopen(*argv,"r") ) == NULL )
        fprintf(stderr, "%s: can't open %s \n", prog, *argv ),  exit(1);
 
      see(iFP),   fclose(iFP);
    }
  else
    see(stdin);
 
  exit(0);
 
}
 
 
see(iFP)
FILE *iFP;
{
  int c;
 
  while ( ( c = getc(iFP) ) != EOF )
    if ( iscntrl(c) )
      printf("^%c%s", c + '@', c=='\n' ? "\n" : "" );
    else
      putchar(c);
 
}
 
/* eof see.c  */
 
Specifically what are you trying to do?  Can you give an example of a
command that you are trying to execute that prompted you to post your article?

Best Regards,
Larry Dighera


-- 
USPS: The Consultants' Exchange, PO Box 12100, Santa Ana, CA  92712
TELE: (714) 842-6348: BBS (N81); (714) 842-5851: Xenix guest account (E71)
UUCP: conexch Any ACU 2400 17148425851 ogin:-""-ogin:-""-ogin: nuucp
UUCP: ...!ucbvax!ucivax!icnvax!conexch!root || ...!trwrb!ucla-an!conexch!root

karish@denali.stanford.edu (Chuck Karish) (05/17/88)

In article <339@conexch.UUCP> root@conexch.UUCP (Larry Dighera) writes:
>I must not understand the problem here, because this all looks very simple
>to me.  
>
>First, SCO Xenix's ls command supports the -b option which forces printing of
>non-graphic characters in file names to be in the octal \ddd notaion.
>
>Secondly, ls * | od -c essentially does the same.

I use `od -c .'  The entries in my System V directories (AIX) are 16 bytes
wide, and just fit in one line of `od -c' output.


Chuck Karish		ARPA:	karish@denali.stanford.edu
			BITNET:	karish%denali@forsythe.stanford.edu
			UUCP:	{decvax,hplabs!hpda}!mindcrf!karish
			paper:	1825 California St. #5