9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] g
@ 2021-08-10 18:03 Stuart Morrow
  2021-08-11  1:13 ` ori
  0 siblings, 1 reply; 9+ messages in thread
From: Stuart Morrow @ 2021-08-10 18:03 UTC (permalink / raw)
  To: 9front

G tries to look in ndb/?.cs and upas/ml/?.ml.

These files are binaries.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9front] g
  2021-08-10 18:03 [9front] g Stuart Morrow
@ 2021-08-11  1:13 ` ori
  2021-08-11 20:15   ` Stuart Morrow
  0 siblings, 1 reply; 9+ messages in thread
From: ori @ 2021-08-11  1:13 UTC (permalink / raw)
  To: 9front

Quoth Stuart Morrow <morrow.stuart@gmail.com>:
> G tries to look in ndb/?.cs and upas/ml/?.ml.
> 
> These files are binaries.
> 

You're correct, it does.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9front] g
  2021-08-11  1:13 ` ori
@ 2021-08-11 20:15   ` Stuart Morrow
  2021-08-11 20:32     ` Stuart Morrow
  2021-08-13  2:43     ` Alex Musolino
  0 siblings, 2 replies; 9+ messages in thread
From: Stuart Morrow @ 2021-08-11 20:15 UTC (permalink / raw)
  To: 9front

Yeah, I suppose it would also look in ?.awk, ?.cpp, ?.mk, and ?.rc.

I was about to solve this on my system with

	nfile -m $files | awk -F\t '$2 ~ /^text|application.x-sh/ { print $1 }'

where nfile is a file(1) that actually uses a frog to separate,
but then that reads every file two times (once by nfile, once
by grep), so I suppose the right thing all along was to have a
grep that can identify binary files by itself (as on other OSes).

Anyway, while we're on the subject, is there anything that
actually relies on Plan 9's (and Research Unix's) wrong grep -c
behaviour? (If I want just the number of lines, I can do grep|wc…)

Anyway here's nfile:

diff file.c nfile.c
176c176
< void	type(char*, int);
---
> void	type(char*);
223,226d222
< 	int i, j, maxlen;
< 	char *cp;
< 	Rune r;
<
236,244d231
< 	maxlen = 0;
< 	if(mime == 0 || argc > 1){
< 		for(i = 0; i < argc; i++) {
< 			for (j = 0, cp = argv[i]; *cp; j++, cp += chartorune(&r, cp))
< 					;
< 			if(j > maxlen)
< 				maxlen = j;
< 		}
< 	}
247c234
< 			print ("stdin: ");
---
> 			print("stdin\t");
251,252c238,239
< 		for(i = 0; i < argc; i++)
< 			type(argv[i], maxlen);
---
> 		for(int i = 0; i < argc; i++)
> 			type(argv[i]);
258c245
< type(char *file, int nlen)
---
> type(char *file)
260,272c247
< 	Rune r;
< 	int i;
< 	char *p;
<
< 	if(nlen > 0){
< 		slash = 0;
< 		for (i = 0, p = file; *p; i++) {
< 			if (*p == '/')			/* find rightmost slash */
< 				slash = p;
< 			p += chartorune(&r, p);		/* count runes */
< 		}
< 		print("%s:%*s",file, nlen-i+1, "");
< 	}
---
> 	print("%s\t", file);

--- //.git/fs/object/a9bccf9e9b1bd408629edaac277f6b3a3a4ab6fb/tree/sys/man/1/file
+++ sys/man/1/file
@@ -106,7 +106,19 @@
 .I file
 decides its input is
 binary.
+.PP
+.I Nfile
+is the same but
+filename and classification are tab-separated.
 .SH SOURCE
 .B /sys/src/cmd/file.c
+.br
+.B /sys/src/cmd/nfile.c
 .SH BUGS
 It can make mistakes.
+.br
+.I File
+should be implemented as an
+.I nfile
+wrapper.
+
--- //.git/fs/object/a9bccf9e9b1bd408629edaac277f6b3a3a4ab6fb/tree/sys/man/1/resample
+++ sys/man/1/resample
@@ -82,4 +82,5 @@
 .B /sys/src/cmd/resize.c
 .SH "SEE ALSO
 .IR crop (1),
-.IR image (6)
+.IR image (6),
+.IR file (1)


(The relevance of file to resample is it's the easiest way to find out
 an image's size and this isn't documented anywhere.)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9front] g
  2021-08-11 20:15   ` Stuart Morrow
@ 2021-08-11 20:32     ` Stuart Morrow
  2021-08-12  5:38       ` Alex Musolino
  2021-08-13  2:43     ` Alex Musolino
  1 sibling, 1 reply; 9+ messages in thread
From: Stuart Morrow @ 2021-08-11 20:32 UTC (permalink / raw)
  To: 9front

I wonder why file doesn't use Bprint. (As it is, it can call print any
number of times before it prints a newline.)

The case against is, of course, normal use of file just has a few files.

The case against the case against is you were going to be linking in
the bio stuff *anyway*. This has been true since First Edition.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9front] g
  2021-08-11 20:32     ` Stuart Morrow
@ 2021-08-12  5:38       ` Alex Musolino
  0 siblings, 0 replies; 9+ messages in thread
From: Alex Musolino @ 2021-08-12  5:38 UTC (permalink / raw)
  To: 9front

> I wonder why file doesn't use Bprint.  (As it is, it can call print
> any number of times before it prints a newline.)

If I had to guess: because it's easier to just type print(...) and not
have to setup a Biobuf for stdout.

> The case against is, of course, normal use of file just has a few
> files.
> 
> The case against the case against is you were going to be linking in
> the bio stuff *anyway*.  This has been true since First Edition.

I can't imagine there'd be much resistance if you were to provide a
patch.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9front] g
  2021-08-11 20:15   ` Stuart Morrow
  2021-08-11 20:32     ` Stuart Morrow
@ 2021-08-13  2:43     ` Alex Musolino
  2021-08-14 21:38       ` Stuart Morrow
  1 sibling, 1 reply; 9+ messages in thread
From: Alex Musolino @ 2021-08-13  2:43 UTC (permalink / raw)
  To: 9front

> I was about to solve this on my system with
> 
> 	nfile -m $files | awk -F\t '$2 ~ /^text|application.x-sh/ { print $1 }'
> 
> where nfile is a file(1) that actually uses a frog to separate,

You don't need to create a new program.  Just specify the awk field
separator regex correctly, i.e. -F ': *'.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9front] g
  2021-08-13  2:43     ` Alex Musolino
@ 2021-08-14 21:38       ` Stuart Morrow
  2021-08-14 21:45         ` Stuart Morrow
  2021-08-15  2:42         ` Alex Musolino
  0 siblings, 2 replies; 9+ messages in thread
From: Stuart Morrow @ 2021-08-14 21:38 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 535 bytes --]

> You don't need to create a new program.  Just specify the awk field
> separator regex correctly, i.e. -F ': *'.

For scripting you do - Plan 9 permits tarded filenames.

Bprint thing is attached. Nfile is in there too, for anyone that has
nfile (anticipating the dream of elastic tabstops?).

I also patched g to do a grep dry-run before walk. So we don't have to
wait on the disk or network to find out if we need to obtain a special
typing wand.

ls.c and ascii.c need a certain fix (hint: look at their 'Binit' line).

Good night

[-- Attachment #2: diffs --]
[-- Type: application/octet-stream, Size: 15789 bytes --]

--- //.git/fs/object/2af46e406bbd443ae10025777247798a685afc3c/tree/sys/man/2/bio
+++ sys/man/2/bio
@@ -12,7 +12,7 @@
 .ft L
 .nf
 .ta \w'    'u +\w'    'u +\w'    'u +\w'    'u +\w'    'u
-typedef struct Biobufhdr	Biobufhdr;
+typedef struct Biobufhdr Biobufhdr;
 struct Biobufhdr {
 	void	*aux;		/* user data */
 	...			/* internals */
--- //.git/fs/object/2af46e406bbd443ae10025777247798a685afc3c/tree/sys/man/2/complete
+++ sys/man/2/complete
@@ -11,7 +11,7 @@
 .ft L
 .nf
 .ta \w'    'u +\w'    'u +\w'    'u +\w'    'u +\w'    'u
-typedef struct Completion	Completion;
+typedef struct Completion Completion;
 struct Completion{
 	uchar advance;		/* whether forward progress has been made */
 	uchar complete;	/* whether the completion now represents a file or directory */

--- //.git/fs/object/2af46e406bbd443ae10025777247798a685afc3c/tree/rc/bin/g
+++ rc/bin/g
@@ -17,6 +17,7 @@
 
 suffixes='\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|hs|java|lua|lx|mk|ml|mli|ms|myr|pl|py|rc|sh|tex|xy)$'
 fullnames='(^|/)mkfile$'
+fn check { grep $pattern </dev/null || ~ $status *syntax* && exit $status }
 switch($#*){
 case 0
 	echo 'usage: g [flags] pattern [files]' >[1=2]
@@ -23,9 +24,11 @@
 	exit usage
 case 1
 	pattern=$1
+	check
 	files=`$nl{walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null}
 case *
 	pattern=$1
+	check
 	shift
 	for(f in $*){
 		if(test -d $f)

--- //.git/fs/object/2af46e406bbd443ae10025777247798a685afc3c/tree/sys/src/cmd/file.c
+++ sys/src/cmd/file.c
@@ -9,6 +9,7 @@
  */
 #define	LENDIAN(p)	((p)[0] | ((p)[1]<<8) | ((p)[2]<<16) | ((p)[3]<<24))
 
+Biobuf	bout;
 uchar	buf[6001];
 short	cfreq[140];
 short	wfreq[50];
@@ -233,6 +234,8 @@
 		exits("usage");
 	}ARGEND;
 
+	Binit(&bout, 1, OWRITE);
+
 	maxlen = 0;
 	if(mime == 0 || argc > 1){
 		for(i = 0; i < argc; i++) {
@@ -244,7 +247,7 @@
 	}
 	if (argc <= 0) {
 		if(!mime)
-			print ("stdin: ");
+			Bprint(&bout, "stdin: ");
 		filetype(0);
 	}
 	else {
@@ -251,6 +254,7 @@
 		for(i = 0; i < argc; i++)
 			type(argv[i], maxlen);
 	}
+	Bterm(&bout);
 	exits(0);
 }
 
@@ -268,10 +272,11 @@
 				slash = p;
 			p += chartorune(&r, p);		/* count runes */
 		}
-		print("%s:%*s",file, nlen-i+1, "");
+		Bprint(&bout, "%s:%*s",file, nlen-i+1, "");
 	}
 	fname = file;
 	if ((fd = open(file, OREAD)) < 0) {
+		Bflush(&bout);
 		fprint(2, "cannot open: %r\n");
 		return;
 	}
@@ -292,12 +297,12 @@
 
 	if(memcmp(buf, "\x00\x00\xFE\xFF", 4) == 0){
 		if(!mime)
-			print("utf-32be ");
+			Bprint(&bout, "utf-32be ");
 		return;
 	} else
 	if(memcmp(buf, "\xFE\xFF\x00\x00", 4) == 0){
 		if(!mime)
-			print("utf-32le ");
+			Bprint(&bout, "utf-32le ");
 		return;
 	} else
 	if(memcmp(buf, "\xEF\xBB\xBF", 3) == 0){
@@ -307,7 +312,7 @@
 	} else
 	if(memcmp(buf, "\xFE\xFF", 2) == 0){
 		if(!mime)
-			print("utf-16be ");
+			Bprint(&bout, "utf-16be ");
 
 		nbuf -= 2;
 		rb = malloc(nbuf+1);
@@ -324,7 +329,7 @@
 	} else
 	if(memcmp(buf, "\xFF\xFE", 2) == 0){
 		if(!mime)
-			print("utf-16le ");
+			Bprint(&bout, "utf-16le ");
 
 		nbuf -= 2;
 		rb = malloc(nbuf+1);
@@ -351,28 +356,30 @@
 	free(mbuf);
 	mbuf = dirfstat(fd);
 	if(mbuf == nil){
+		Bflush(&bout);
 		fprint(2, "cannot stat: %r\n");
 		return;
 	}
 	if(mbuf->mode & DMDIR) {
-		print("%s\n", mime ? OCTET : "directory");
+		Bprint(&bout, "%s\n", mime ? OCTET : "directory");
 		return;
 	}
 	if(mbuf->type != 'M' && mbuf->type != '|') {
 		if(mime)
-			print("%s\n", OCTET);
+			Bprint(&bout, "%s\n", OCTET);
 		else
-			print("special file #%C/%s\n", mbuf->type, mbuf->name);
+			Bprint(&bout, "special file #%C/%s\n", mbuf->type, mbuf->name);
 		return;
 	}
 	/* may be reading a pipe on standard input */
 	nbuf = readn(fd, buf, sizeof(buf)-1);
 	if(nbuf < 0) {
+		Bflush(&bout);
 		fprint(2, "cannot read: %r\n");
 		return;
 	}
 	if(nbuf == 0) {
-		print("%s\n", mime ? PLAIN : "empty file");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "empty file");
 		return;
 	}
 	buf[nbuf] = 0;
@@ -442,16 +449,16 @@
 	 * print out gross classification
 	 */
 	if (nbuf < 100 && !mime)
-		print(mime ? PLAIN : "short ");
+		Bprint(&bout, mime ? PLAIN : "short ");
 	if (guess == Fascii)
-		print("%s\n", mime ? PLAIN : "Ascii");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "Ascii");
 	else if (guess == Feascii)
-		print("%s\n", mime ? PLAIN : "extended ascii");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "extended ascii");
 	else if (guess == Flatin)
-		print("%s\n", mime ? PLAIN : "latin ascii");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "latin ascii");
 	else if (guess == Futf && utf_count() < 4)
 		print_utf();
-	else print("%s\n", mime ? OCTET : "binary");
+	else Bprint(&bout, "%s\n", mime ? OCTET : "binary");
 }
 
 void
@@ -522,12 +529,12 @@
 	int i, printed, j;
 
 	if(mime){
-		print("%s\n", PLAIN);
+		Bprint(&bout, "%s\n", PLAIN);
 		return;
 	}
 	if (chkascii()) {
 		printed = 1;
-		print("Ascii");
+		Bprint(&bout, "Ascii");
 	} else
 		printed = 0;
 	for (i = 0; language[i].name; i++)
@@ -543,7 +550,7 @@
 			case Normal:
 			case First:
 				if (printed)
-					print(" & ");
+					Bprint(&bout, " & ");
 				else printed = 1;
 				print("%s", language[i].name);
 				break;
@@ -553,8 +560,8 @@
 			}
 		}
 	if(!printed)
-		print("UTF");
-	print(" text\n");
+		Bprint(&bout, "UTF");
+	Bprint(&bout, " text\n");
 }
 
 void
@@ -648,7 +655,7 @@
 
 	for(i=0; i<ntab; i++)
 		if((x&tab[i].mask) == tab[i].x){
-			print("%s\n", mime ? tab[i].mime : tab[i].desc);
+			Bprint(&bout, "%s\n", mime ? tab[i].mime : tab[i].desc);
 			return 1;
 		}
 	return 0;
@@ -698,7 +705,7 @@
 			continue;
 		x = LENDIAN(buf);
 		if((x&tp->mask) == tp->x){
-			print("%s\n", mime ? tp->mime : tp->desc);
+			Bprint(&bout, "%s\n", mime ? tp->mime : tp->desc);
 			return 1;
 		}
 	}
@@ -718,7 +725,7 @@
 
 	seek(fd, 0, 0);		/* reposition to start of file */
 	if(crackhdr(fd, &f)) {
-		print("%s\n", mime ? OCTET : f.name);
+		Bprint(&bout, "%s\n", mime ? OCTET : f.name);
 		return 1;
 	}
 	return 0;
@@ -744,19 +751,19 @@
 		p = tmp;
 
 	if (strcmp("rc", p) == 0)
-		print("%s\n", mime ? PLAIN : "rc executable file");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "rc executable file");
 	else if (strcmp("sh", p) == 0)
-		print("%s\n", mime ? "application/x-sh" : "sh executable file");
+		Bprint(&bout, "%s\n", mime ? "application/x-sh" : "sh executable file");
 	else if (strcmp("bash", p) == 0)
-		print("%s\n", mime ? "application/x-sh" : "bash executable file");
+		Bprint(&bout, "%s\n", mime ? "application/x-sh" : "bash executable file");
 	else if (strcmp("awk", p) == 0)
-		print("%s\n", mime ? PLAIN : "awk executable file");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "awk executable file");
 	else if (strcmp("sed", p) == 0)
-		print("%s\n", mime ? PLAIN : "sed executable file");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "sed executable file");
 	else if (strcmp("perl", p) == 0)
-		print("%s\n", mime ? PLAIN : "perl executable file");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "perl executable file");
 	else
-		print("%s\n", mime ? PLAIN : "unknown executable file");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "unknown executable file");
 	return 1;
 }
 
@@ -817,9 +824,9 @@
 	chksum = strtol(hdr->chksum, 0, 8);
 	if (hdr->name[0] != '\0' && checksum(hp) == chksum) {
 		if (strcmp(hdr->magic, "ustar") == 0)
-			print(mime? "application/x-ustar\n": "posix tar archive\n");
+			Bprint(&bout, mime? "application/x-ustar\n": "posix tar archive\n");
 		else
-			print(mime? "application/x-tar\n": "tar archive\n");
+			Bprint(&bout, mime? "application/x-tar\n": "tar archive\n");
 		return 1;
 	}
 	return 0;
@@ -935,7 +942,7 @@
 		if(l == -1)
 			l = strlen(p->key);
 		if(nbuf >= l && memcmp(buf, p->key, l) == 0) {
-			print("%s\n", mime ? p->mime : p->filetype);
+			Bprint(&bout, "%s\n", mime ? p->mime : p->filetype);
 			return 1;
 		}
 	}
@@ -944,9 +951,9 @@
 			if(buf[i] == '\n')
 				break;
 		if(mime)
-			print("%s\n", OCTET);
+			Bprint(&bout, "%s\n", OCTET);
 		else
-			print("%.*s picture\n", utfnlen((char*)buf+5, i-5), (char*)buf+5);
+			Bprint(&bout, "%.*s picture\n", utfnlen((char*)buf+5, i-5), (char*)buf+5);
 		return 1;
 	}
 	return 0;
@@ -977,7 +984,7 @@
 		if (readn(fd, buf, n) != n)
 			continue;
 		if(memcmp(buf, p->key, n) == 0) {
-			print("%s\n", mime ? p->mime : p->filetype);
+			Bprint(&bout, "%s\n", mime ? p->mime : p->filetype);
 			return 1;
 		}
 	}
@@ -989,18 +996,18 @@
 {
 	if (strncmp((char*)buf, "FORM", 4) == 0 &&
 	    strncmp((char*)buf+8, "AIFF", 4) == 0) {
-		print("%s\n", mime? "audio/x-aiff": "aiff audio");
+		Bprint(&bout, "%s\n", mime? "audio/x-aiff": "aiff audio");
 		return 1;
 	}
 	if (strncmp((char*)buf, "RIFF", 4) == 0) {
 		if (strncmp((char*)buf+8, "WAVE", 4) == 0)
-			print("%s\n", mime? "audio/wave": "wave audio");
+			Bprint(&bout, "%s\n", mime? "audio/wave": "wave audio");
 		else if (strncmp((char*)buf+8, "AVI ", 4) == 0)
-			print("%s\n", mime? "video/avi": "avi video");
+			Bprint(&bout, "%s\n", mime? "video/avi": "avi video");
 		else if (strncmp((char*)buf+8, "WEBP", 4) == 0)
-			print("%s\n", mime? "image/webp": "webp image");
+			Bprint(&bout, "%s\n", mime? "image/webp": "webp image");
 		else
-			print("%s\n", mime? OCTET : "riff file");
+			Bprint(&bout, "%s\n", mime? OCTET : "riff file");
 		return 1;
 	}
 	return 0;
@@ -1036,7 +1043,7 @@
 	if(strncmp(++p, "+++ ", 4) == 0)
 	if((p = strchr(p, '\n')) != nil)
 	if(strncmp(++p, "@@ ", 3) == 0){
-		print("%s\n", mime ? "text/plain" : "unified diff output");
+		Bprint(&bout, "%s\n", mime ? "text/plain" : "unified diff output");
 		return 1;
 	}
 	return 0;
@@ -1068,7 +1075,7 @@
 				p += n;
 				if(p < buf+nbuf && strchr("\t\r\n />", *p)){
 					if(++count > 2) {
-						print("%s\n", mime ? "text/html" : "HTML file");
+						Bprint(&bout, "%s\n", mime ? "text/html" : "HTML file");
 						return 1;
 					}
 				}
@@ -1126,7 +1133,7 @@
 		p = q+1;
 	}
 	if(count >= 3){
-		print("%s\n", mime ? "message/rfc822" : "email file");
+		Bprint(&bout, "%s\n", mime ? "message/rfc822" : "email file");
 		return 1;
 	}
 	return 0;
@@ -1143,7 +1150,7 @@
 		return 0;
 	*q = 0;
 	if(strncmp(p, "From ", 5) == 0 && strstr(p, " remote from ") == nil){
-		print("%s\n", mime ? "application/mbox" : "mail box");
+		Bprint(&bout, "%s\n", mime ? "application/mbox" : "mail box");
 		return 1;
 	}
 	*q = '\n';
@@ -1164,9 +1171,9 @@
 	if(type < 0)
 		return 0;
 	if(mime)
-		print("%s\n", OCTET);
+		Bprint(&bout, "%s\n", OCTET);
 	else
-		print("%s intermediate\n", name);
+		Bprint(&bout, "%s intermediate\n", name);
 	return 1;
 }
 
@@ -1197,13 +1204,13 @@
 
 yes:
 	if(mime){
-		print("%s\n", PLAIN);
+		Bprint(&bout, "%s\n", PLAIN);
 		return 1;
 	}
 	if(wfreq[Alword] > 0)
-		print("alef program\n");
+		Bprint(&bout, "alef program\n");
 	else
-		print("c program\n");
+		Bprint(&bout, "c program\n");
 	return 1;
 }
 
@@ -1215,7 +1222,7 @@
 	 */
 	if(wfreq[Lword] < 4)
 		return 0;
-	print("%s\n", mime ? PLAIN : "limbo program");
+	Bprint(&bout, "%s\n", mime ? PLAIN : "limbo program");
 	return 1;
 }
 
@@ -1227,7 +1234,7 @@
 	 */
 	if(wfreq[Aword] < 2)
 		return 0;
-	print("%s\n", mime ? PLAIN : "as program");
+	Bprint(&bout, "%s\n", mime ? PLAIN : "as program");
 	return 1;
 }
 
@@ -1260,7 +1267,7 @@
 			return 0;
 	} else
 		return 0;
-	print("%s\n", mime ? "image/tga" : "targa image");
+	Bprint(&bout, "%s\n", mime ? "image/tga" : "targa image");
 	return 1;
 }
 
@@ -1273,7 +1280,7 @@
 	e = p + nbuf-1;
 	while((p < e) && (p = memchr(p, 0xFF, e - p))){
 		if((p[1] & 0xFE) == 0xFA){
-			print("%s\n", mime ? "audio/mpeg" : "mp3 audio");
+			Bprint(&bout, "%s\n", mime ? "audio/mpeg" : "mp3 audio");
 			return 1;
 		}
 		p++;
@@ -1289,11 +1296,11 @@
 	if(memcmp(&buf[4], "ftyp", 4) != 0)
 		return 0;
 	if(memcmp(&buf[8], "isom", 4) == 0 || memcmp(&buf[8], "mp4", 3) == 0){
-		print("%s\n", mime ? "video/mp4" : "mp4 video");
+		Bprint(&bout, "%s\n", mime ? "video/mp4" : "mp4 video");
 		return 1;
 	}
 	if(memcmp(&buf[8], "M4A ", 4) == 0){
-		print("%s\n", mime ? "audio/m4a" : "m4a audio");
+		Bprint(&bout, "%s\n", mime ? "audio/m4a" : "m4a audio");
 		return 1;
 	}
 	return 0;
@@ -1320,18 +1327,18 @@
 	cs /= 8.;
 	if(cs <= 24.322) {
 		if(buf[0]==0x1f && buf[1]==0x9d)
-			print("%s\n", mime ? "application/x-compress" : "compressed");
+			Bprint(&bout, "%s\n", mime ? "application/x-compress" : "compressed");
 		else
 		if(buf[0]==0x1f && buf[1]==0x8b)
-			print("%s\n", mime ? "application/x-gzip" : "gzip compressed");
+			Bprint(&bout, "%s\n", mime ? "application/x-gzip" : "gzip compressed");
 		else
 		if(buf[0]=='B' && buf[1]=='Z' && buf[2]=='h')
-			print("%s\n", mime ? "application/x-bzip2" : "bzip2 compressed");
+			Bprint(&bout, "%s\n", mime ? "application/x-bzip2" : "bzip2 compressed");
 		else
 		if(buf[0]==0x78 && buf[1]==0x9c)
-			print("%s\n", mime ? "application/x-deflate" : "zlib compressed");
+			Bprint(&bout, "%s\n", mime ? "application/x-deflate" : "zlib compressed");
 		else
-			print("%s\n", mime ? OCTET : "encrypted");
+			Bprint(&bout, "%s\n", mime ? OCTET : "encrypted");
 		return 1;
 	}
 	return 0;
@@ -1386,7 +1393,7 @@
 		rare += cfreq[tolower(*p)];
 	}
 	if(vow*5 >= nbuf-cfreq[' '] && comm >= 10*rare) {
-		print("%s\n", mime ? PLAIN : "English text");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "English text");
 		return 1;
 	}
 	return 0;
@@ -1493,7 +1500,7 @@
 	 * for subfont, the subfont header should follow immediately.
 	 */
 	if (cmpr) {
-		print(mime ? "image/p9bit\n" : "Compressed %splan 9 image or subfont, depth %d, size %dx%d\n",
+		Bprint(&bout, mime ? "image/p9bit\n" : "Compressed %splan 9 image or subfont, depth %d, size %dx%d\n",
 			newlabel, dep, hix, hiy);
 		return 1;
 	}
@@ -1503,12 +1510,12 @@
 	 */
 	if (len != 0 && (mbuf->length == 0 || mbuf->length == len ||
 	    mbuf->length > len && mbuf->length < len+P9BITLEN)) {
-		print(mime ? "image/p9bit\n" : "%splan 9 image, depth %d, size %dx%d\n",
+		Bprint(&bout, mime ? "image/p9bit\n" : "%splan 9 image, depth %d, size %dx%d\n",
 			newlabel, dep, hix, hiy);
 		return 1;
 	}
 	if (p9subfont(buf+len)) {
-		print(mime ? "image/p9bit\n" : "%ssubfont file, depth %d, size %dx%d\n",
+		Bprint(&bout, mime ? "image/p9bit\n" : "%ssubfont file, depth %d, size %dx%d\n",
 			newlabel, dep, hix, hiy);
 		return 1;
 	}
@@ -1579,7 +1586,7 @@
 		}
 	}
 	if (i) {
-		print("%s\n", mime ? PLAIN : "font file");
+		Bprint(&bout, "%s\n", mime ? PLAIN : "font file");
 		return 1;
 	}
 	return 0;
@@ -1604,7 +1611,7 @@
 isrtf(void)
 {
 	if(strstr((char *)buf, "\\rtf1")){
-		print(mime ? "application/rtf\n" : "rich text format\n");
+		Bprint(&bout, mime ? "application/rtf\n" : "rich text format\n");
 		return 1;
 	}
 	return 0;
@@ -1614,7 +1621,7 @@
 ismsdos(void)
 {
 	if (buf[0] == 0x4d && buf[1] == 0x5a){
-		print(mime ? "application/x-msdownload\n" : "MSDOS executable\n");
+		Bprint(&bout, mime ? "application/x-msdownload\n" : "MSDOS executable\n");
 		return 1;
 	}
 	return 0;
@@ -1629,10 +1636,10 @@
 		return 0;
 	switch(buf[2]){
 	case 1:
-		print(mime ? "image/x-icon\n" : "Microsoft icon file\n");
+		Bprint(&bout, mime ? "image/x-icon\n" : "Microsoft icon file\n");
 		return 1;
 	case 2:
-		print(mime ? "image/x-icon\n" : "Microsoft cursor file\n");
+		Bprint(&bout, mime ? "image/x-icon\n" : "Microsoft cursor file\n");
 		return 1;
 	}
 	return 0;
@@ -1694,10 +1701,10 @@
 
 			if(n>0 && n < nelem(type) && type[n])
 				t = type[n];
-			print("%s ELF %s\n", p, t);
+			Bprint(&bout, "%s ELF %s\n", p, t);
 		}
 		else
-			print("application/x-elf-executable\n");
+			Bprint(&bout, "application/x-elf-executable\n");
 		return 1;
 	}
 
@@ -1736,8 +1743,8 @@
 	}
 
 	if(mime)
-		print("application/x-face\n");
+		Bprint(&bout, "application/x-face\n");
 	else
-		print("face image depth %d\n", ldepth);
+		Bprint(&bout, "face image depth %d\n", ldepth);
 	return 1;
 }

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9front] g
  2021-08-14 21:38       ` Stuart Morrow
@ 2021-08-14 21:45         ` Stuart Morrow
  2021-08-15  2:42         ` Alex Musolino
  1 sibling, 0 replies; 9+ messages in thread
From: Stuart Morrow @ 2021-08-14 21:45 UTC (permalink / raw)
  To: 9front

Oh- and when I said Plan 9's grep -c is wrong, I thought at that time
that on modern operating systems grep -c counts matches rather than
lines (cause like, why dedicate a flag to something that's so easy to
do from the shell?) and that Plan 9 was the odd one out.  Nope.  I was
wrong - and so are _all_ greps, it would seem.

In case that confused anyone.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9front] g
  2021-08-14 21:38       ` Stuart Morrow
  2021-08-14 21:45         ` Stuart Morrow
@ 2021-08-15  2:42         ` Alex Musolino
  1 sibling, 0 replies; 9+ messages in thread
From: Alex Musolino @ 2021-08-15  2:42 UTC (permalink / raw)
  To: 9front

> > You don't need to create a new program.  Just specify the awk field
> > separator regex correctly, i.e. -F ': *'.
> 
> For scripting you do - Plan 9 permits tarded filenames.

Well, today I learnt that you can't put tabs in filenames on plan9.  I
suppose I should be proud that I've not tried such a darstadly act
until now.

Even supposing ': ' appears in some filenames, the fact that it does
*not* appear in MIME types means you can still have AWK do the dirty
work.

	file -m * | awk -F: '$NF ~ /^( *)text|application.x-sh/ {
		for(i=1;i<NF;i++){
			if(i>1)
				printf FS;
			printf "%s", $i
		}
		printf "\n"
	}'

I know McIlroy says to write new programs but in this case I think a
-t option for file(1) would be preferable over nfile, if the above
proves to be defeatable.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-08-16 10:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 18:03 [9front] g Stuart Morrow
2021-08-11  1:13 ` ori
2021-08-11 20:15   ` Stuart Morrow
2021-08-11 20:32     ` Stuart Morrow
2021-08-12  5:38       ` Alex Musolino
2021-08-13  2:43     ` Alex Musolino
2021-08-14 21:38       ` Stuart Morrow
2021-08-14 21:45         ` Stuart Morrow
2021-08-15  2:42         ` Alex Musolino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).