Browse Source

Plan 9 from Bell Labs 2003-11-29

David du Colombier 20 years ago
parent
commit
666c3b04d3
4 changed files with 31 additions and 13 deletions
  1. 3 3
      dist/replica/plan9.db
  2. 3 0
      dist/replica/plan9.log
  3. 5 0
      sys/man/1/fmt
  4. 20 10
      sys/src/cmd/fmt.c

+ 3 - 3
dist/replica/plan9.db

@@ -226,7 +226,7 @@
 386/bin/faces - 775 sys sys 1064598137 191011
 386/bin/factor - 775 sys sys 1064598138 59887
 386/bin/file - 775 sys sys 1065017417 118088
-386/bin/fmt - 775 sys sys 1069592366 63525
+386/bin/fmt - 775 sys sys 1070032020 63683
 386/bin/fortune - 775 sys sys 1064598140 66084
 386/bin/fossil - 20000000775 sys sys 1042005470 0
 386/bin/fossil/conf - 775 sys sys 1056364255 1497
@@ -4614,7 +4614,7 @@ sys/man/1/faces - 664 sys sys 1045501346 2052
 sys/man/1/factor - 664 sys sys 957920005 1019
 sys/man/1/file - 664 sys sys 1015024739 1578
 sys/man/1/filter - 664 sys sys 1041108741 4403
-sys/man/1/fmt - 664 sys sys 1034016352 1471
+sys/man/1/fmt - 664 sys sys 1070032221 1557
 sys/man/1/fortune - 664 sys sys 944959673 449
 sys/man/1/freq - 664 sys sys 944959673 735
 sys/man/1/grap - 664 sys sys 944959675 6417
@@ -7417,7 +7417,7 @@ sys/src/cmd/fax/receiverc - 775 sys sys 944960990 581
 sys/src/cmd/fax/send.c - 664 sys sys 944960990 923
 sys/src/cmd/fax/subr.c - 664 sys sys 1015090401 1245
 sys/src/cmd/file.c - 664 sys sys 1065017417 20590
-sys/src/cmd/fmt.c - 664 sys sys 1069018548 3897
+sys/src/cmd/fmt.c - 664 sys sys 1070032009 4088
 sys/src/cmd/fortune.c - 664 sys sys 1035832953 1674
 sys/src/cmd/fossil - 20000000775 sys sys 1042005512 0
 sys/src/cmd/fossil/9.h - 664 sys sys 1069683864 4268

+ 3 - 0
dist/replica/plan9.log

@@ -12814,3 +12814,6 @@
 1069819220 0 c sys/src/cmd/disk/mkext.c - 664 sys sys 1069818199 5500
 1069819220 1 c sys/src/cmd/fossil/9p.c - 664 sys sys 1069818231 21498
 1069885828 0 c sys/man/8/fossilcons - 664 sys sys 1069884636 15073
+1070033454 0 c 386/bin/fmt - 775 sys sys 1070032020 63683
+1070033454 1 c sys/man/1/fmt - 664 sys sys 1070032221 1557
+1070033454 2 c sys/src/cmd/fmt.c - 664 sys sys 1070032009 4088

+ 5 - 0
sys/man/1/fmt

@@ -43,6 +43,9 @@ A synonym for
 Indent
 .I n
 spaces (default 0).
+.TP
+.BI -j
+Do not join short lines: only fold long lines.
 .PP
 Empty lines and initial white space in input lines are preserved.
 Empty lines are inserted between input files.
@@ -79,6 +82,8 @@ as the base URL for the document when displaying anchors; sets
 .BI -a .
 .SH SOURCE
 .B /sys/src/cmd/fmt.c
+.PP
+.B /sys/src/cmd/htmlfmt
 .SH BUGS
 .I Htmlfmt
 makes no attempt to render the two-dimensional geometry of tables;

+ 20 - 10
sys/src/cmd/fmt.c

@@ -7,15 +7,17 @@
  * block up paragraphs, possibly with indentation
  */
 
-int extraindent = 0;			/* how many spaces to indent all lines */
+int extraindent = 0;		/* how many spaces to indent all lines */
 int indent = 0;			/* current value of indent, before extra indent */
 int length = 70;		/* how many columns per output line */
+int join = 1;			/* can lines be joined? */
 int maxtab = 8;
 Biobuf bin;
 Biobuf bout;
 
 typedef struct Word Word;
 struct Word{
+	int	bol;
 	int	indent;
 	char	text[1];
 };
@@ -39,6 +41,9 @@ main(int argc, char **argv)
 	case 'i':
 		extraindent = atoi(EARGF(usage()));
 		break;
+	case 'j':
+		join = 0;
+		break;
 	case 'w':
 	case 'l':
 		length = atoi(EARGF(usage()));
@@ -106,7 +111,7 @@ indentof(char **linep)
 }
 
 Word**
-addword(Word **words, int *nwordp, char *s, int l, int indent)
+addword(Word **words, int *nwordp, char *s, int l, int indent, int bol)
 {
 	Word *w;
 
@@ -114,6 +119,7 @@ addword(Word **words, int *nwordp, char *s, int l, int indent)
 	memmove(w->text, s, l);
 	w->text[l] = '\0';
 	w->indent = indent;
+	w->bol = bol;
 	words = realloc(words, (*nwordp+1)*sizeof(Word*));
 	words[(*nwordp)++] = w;
 	return words;
@@ -122,26 +128,26 @@ addword(Word **words, int *nwordp, char *s, int l, int indent)
 Word**
 parseline(char *line, Word **words, int *nwordp)
 {
-	int ind, l, blankline;
+	int ind, l, bol;
 
 	ind = indentof(&line);
 	indent = ind;
-	blankline = 1;
+	bol = 1;
 	for(;;){
 		/* find next word */
 		while(*line==' ' || *line=='\t')
 			line++;
 		if(*line == '\0'){
-			if(blankline)
-				return addword(words, nwordp, "", 0, -1);
+			if(bol)
+				return addword(words, nwordp, "", 0, -1, bol);
 			break;
 		}
-		blankline = 0;
 		/* how long is this word? */
 		for(l=0; line[l]; l++)
 			if(line[l]==' ' || line[l]=='\t')
 				break;
-		words = addword(words, nwordp, line, l, indent);
+		words = addword(words, nwordp, line, l, indent, bol);
+		bol = 0;
 		line += l;
 	}
 	return words;
@@ -169,6 +175,8 @@ nspaceafter(char *s)
 	n = strlen(s);
 	if(n < 2)
 		return 1;
+	if(isupper(s[0]) && n < 4)
+		return 1;
 	if(strchr(".!?", s[n-1]) != nil)
 		return 2;
 	return 1;
@@ -178,7 +186,7 @@ nspaceafter(char *s)
 void
 printwords(Word **w, int nw)
 {
-	int i, j, col, nsp;
+	int i, j, n, col, nsp;
 
 	/* one output line per loop */
 	for(i=0; i<nw; ){
@@ -192,7 +200,7 @@ printwords(Word **w, int nw)
 		col = extraindent+w[i]->indent;
 		printindent(col);
 		/* emit words until overflow; always emit at least one word */
-		for(;;){
+		for(n=0;; n++){
 			Bprint(&bout, "%s", w[i]->text);
 			col += utflen(w[i]->text);
 			if(++i == nw)
@@ -202,6 +210,8 @@ printwords(Word **w, int nw)
 			nsp = nspaceafter(w[i-1]->text);
 			if(col+nsp+utflen(w[i]->text) > extraindent+length)
 				break;	/* fold line */
+			if(!join && n != 0 && w[i]->bol)
+				break;
 			for(j=0; j<nsp; j++)
 				Bputc(&bout, ' ');	/* emit space; another word will follow */
 			col += nsp;