Commit Diff


commit - 5c8a0421712a471a00dbf78f7ea054b366ba471b
commit + e5aa96acbf9107cd78f2536364c36f9a15751313
blob - ec403b11bb6dc85b167b5e6c3f6e1a5ea2f738df
blob + 65a4e189c791e504df09c6f069aed7c17596ac7f
--- src/lib9/fmt/charstod.c
+++ src/lib9/fmt/charstod.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - cee3f4e43ea259b634c41c3d1664839ac9b425eb
blob + 873d69263e4cb0ee980512d67c3ed591150dca91
--- src/lib9/fmt/dofmt.c
+++ src/lib9/fmt/dofmt.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
@@ -339,10 +339,12 @@ __ifmt(Fmt *f)
 	 * Unsigned verbs
 	 */
 	switch(f->r){
-	case 'o':
-	case 'u':
+	/* unsigned by default only on Unix 
 	case 'x':
 	case 'X':
+	*/
+	case 'o':
+	case 'u':
 		fl |= FmtUnsigned;
 		break;
 	}
@@ -402,7 +404,9 @@ __ifmt(Fmt *f)
 	default:
 		return -1;
 	}
-	if(!(fl & FmtUnsigned)){
+	if(fl & FmtUnsigned)
+		fl &= ~(FmtSign|FmtSpace);
+	else{
 		if(isv && (vlong)vu < 0){
 			vu = -(vlong)vu;
 			neg = 1;
@@ -410,8 +414,6 @@ __ifmt(Fmt *f)
 			u = -(long)u;
 			neg = 1;
 		}
-	}else{
-		fl &= ~(FmtSign|FmtSpace);	/* no + for unsigned conversions */
 	}
 	p = buf + sizeof buf - 1;
 	n = 0;
blob - cdaee8a5f0c7a02fd2ef7893f6e3536b660d42f8
blob + 5b547d510a766d5a76a9664f1b6ab0fead57aa89
--- src/lib9/fmt/dorfmt.c
+++ src/lib9/fmt/dorfmt.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
@@ -53,7 +53,7 @@ dorfmt(Fmt *f, const Rune *fmt)
 			f->stop = s;
 		}
 
-		fmt = __fmtdispatch(f, fmt, 1);
+		fmt = __fmtdispatch(f, (Rune*)fmt, 1);
 		if(fmt == nil)
 			return -1;
 	}
blob - 2184705426ca459a31e50dc20fae2627b1641ce7
blob + df6c31010dbe320599435688f98c092216ebb0e9
--- src/lib9/fmt/errfmt.c
+++ src/lib9/fmt/errfmt.c
@@ -14,7 +14,7 @@
 #include <stdarg.h>
 #include <errno.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 234f03d9c5d0e2e17c89143cf1b54f92a3478794
blob + a7e57997b0605e27b48caf0e87f4f51f856694ac
--- src/lib9/fmt/fltfmt.c
+++ src/lib9/fmt/fltfmt.c
@@ -18,9 +18,10 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <fmt.h>
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
-#include "nan.h"
 
 enum
 {
blob - 976bf7ca2e43c6f908f6aed8ac07e1b3dd58de3f
blob + f9d8328d45c8dcb8d85e2918be47d58557343f99
--- src/lib9/fmt/fmt.c
+++ src/lib9/fmt/fmt.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
@@ -64,7 +64,11 @@ static Convfmt knownfmt[] = {
 	'p',	__ifmt,
 	'r',	__errfmt,
 	's',	__strfmt,
-	'u',	__flagfmt,	/* in Unix, __ifmt */
+#ifdef PLAN9PORT
+	'u',	__flagfmt,
+#else
+	'u',	__ifmt,
+#endif
 	'x',	__ifmt,
 	0,	nil,
 };
@@ -103,7 +107,7 @@ __fmtinstall(int c, Fmts f)
 }
 
 int
-fmtinstall(int c, Fmts f)
+fmtinstall(int c, int (*f)(Fmt*))
 {
 	int ret;
 
blob - 894687677446435d38a1814580ab95affdf92bd6
blob + bfb2aa976be2c61443330f572bedd08fef51e712
--- src/lib9/fmt/fmtdef.h
+++ src/lib9/fmt/fmtdef.h
@@ -11,6 +11,7 @@
  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
+
 /*
  * dofmt -- format to a buffer
  * the number of characters formatted is returned,
@@ -18,30 +19,7 @@
  * if the buffer is ever filled, flush is called.
  * it should reset the buffer and return whether formatting should continue.
  */
-#define uchar _fmtuchar
-#define ushort _fmtushort
-#define uint _fmtuint
-#define ulong _fmtulong
-#define vlong _fmtvlong
-#define uvlong _fmtuvlong
 
-#ifndef USED
-#define USED(x) if(x);else
-#endif
-
-typedef unsigned char		uchar;
-typedef unsigned short		ushort;
-typedef unsigned int		uint;
-typedef unsigned long		ulong;
-
-#ifndef NOVLONGS
-typedef unsigned long long	uvlong;
-typedef long long		vlong;
-#endif
-
-#undef nil
-#define nil		0	/* cannot be ((void*)0) because used for function pointers */
-
 typedef int (*Fmts)(Fmt*);
 
 typedef struct Quoteinfo Quoteinfo;
@@ -54,32 +32,37 @@ struct Quoteinfo
 	int	nbytesout;	/* number of bytes that will be generated */
 };
 
-void	*__fmtflush(Fmt*, void*, int);
-void	*__fmtdispatch(Fmt*, void*, int);
-int	__floatfmt(Fmt*, double);
-int	__fmtpad(Fmt*, int);
-int	__rfmtpad(Fmt*, int);
-int	__fmtFdFlush(Fmt*);
+/* Edit .+1,/^$/ |cfn |grep -v static | grep __ */
+double       __Inf(int sign);
+double       __NaN(void);
+int          __badfmt(Fmt *f);
+int          __charfmt(Fmt *f);
+int          __countfmt(Fmt *f);
+int          __efgfmt(Fmt *fmt);
+int          __errfmt(Fmt *f);
+int          __flagfmt(Fmt *f);
+int          __fmtFdFlush(Fmt *f);
+int          __fmtcpy(Fmt *f, const void *vm, int n, int sz);
+void*        __fmtdispatch(Fmt *f, void *fmt, int isrunes);
+void *       __fmtflush(Fmt *f, void *t, int len);
+void         __fmtlock(void);
+int          __fmtpad(Fmt *f, int n);
+double       __fmtpow10(int n);
+int          __fmtrcpy(Fmt *f, const void *vm, int n);
+void         __fmtunlock(void);
+int          __ifmt(Fmt *f);
+int          __isInf(double d, int sign);
+int          __isNaN(double d);
+int          __needsquotes(char *s, int *quotelenp);
+int          __percentfmt(Fmt *f);
+void         __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int runesout);
+int          __quotestrfmt(int runesin, Fmt *f);
+int          __rfmtpad(Fmt *f, int n);
+int          __runefmt(Fmt *f);
+int          __runeneedsquotes(Rune *r, int *quotelenp);
+int          __runesfmt(Fmt *f);
+int          __strfmt(Fmt *f);
 
-int	__efgfmt(Fmt*);
-int	__charfmt(Fmt*);
-int	__runefmt(Fmt*);
-int	__runesfmt(Fmt*);
-int	__countfmt(Fmt*);
-int	__flagfmt(Fmt*);
-int	__percentfmt(Fmt*);
-int	__ifmt(Fmt*);
-int	__strfmt(Fmt*);
-int	__badfmt(Fmt*);
-int	__fmtcpy(Fmt*, const void*, int, int);
-int	__fmtrcpy(Fmt*, const void*, int n);
-int	__errfmt(Fmt *f);
-
-double	__fmtpow10(int);
-
-void	__fmtlock(void);
-void	__fmtunlock(void);
-
 #define FMTCHAR(f, t, s, c)\
 	do{\
 	if(t + 1 > (char*)s){\
blob - d4251402aa64e76b968af7728479e3a9dfb3b8a2
blob + 5de42ae6ef1ce71305d36820b855bb3196065d57
--- src/lib9/fmt/fmtfd.c
+++ src/lib9/fmt/fmtfd.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 796feab23d5dcb4e819e3849a885a0bdc20dc43c
blob + 73bf47c4fe7f763bda88142472fe78cc379eb7a7
--- src/lib9/fmt/fmtfdflush.c
+++ src/lib9/fmt/fmtfdflush.c
@@ -13,6 +13,7 @@
  */
 #include <stdarg.h>
 #include <unistd.h>
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - fffe81cfcce099b044848539bc56d319ea29c9f8
blob + 7501ce41619d30b0bc5b10091884636c82fd722d
--- src/lib9/fmt/fmtlock.c
+++ src/lib9/fmt/fmtlock.c
@@ -12,6 +12,7 @@
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
 #include <stdarg.h>
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - c682f49f4b5433f5666a0ac002a4d840273dc1f7
blob + 7044d5bd41740892398a4b11091b1cd9515c6528
--- src/lib9/fmt/fmtprint.c
+++ src/lib9/fmt/fmtprint.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 9d5633d6cd706733f80055be4251e19b790dea72
blob + b8f00c18812afc36e67a3d5966fdacfa9af31296
--- src/lib9/fmt/fmtquote.c
+++ src/lib9/fmt/fmtquote.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - a034546bccf294e3cca51c05b9a47962da16ee93
blob + a7f620eb2690f96c2c582010887ffc5417982236
--- src/lib9/fmt/fmtrune.c
+++ src/lib9/fmt/fmtrune.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 0b227166d81548e2b589783721cc4879d94dee1b
blob + b4b6818548d03766cfde943597c8130aff83e5a2
--- src/lib9/fmt/fmtstr.c
+++ src/lib9/fmt/fmtstr.c
@@ -11,9 +11,20 @@
  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
+/*
+ * Plan 9 port version must include libc.h in order to 
+ * get Plan 9 debugging malloc, which sometimes returns
+ * different pointers than the standard malloc. 
+ */
+#ifdef PLAN9PORT
 #include <u.h>
 #include <libc.h>
+#else
+#include <stdlib.h>
+#include "plan9.h"
+#include "fmt.h"
 #include "fmtdef.h"
+#endif
 
 static int
 fmtStrFlush(Fmt *f)
blob - 60974a0b17442ec0a5c1bb087e60f1f67a92aebc
blob + d1176a50dd06b8ce385cb029116bf46ac984b067
--- src/lib9/fmt/fmtvprint.c
+++ src/lib9/fmt/fmtvprint.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - c8b889de61cacb0a4c9cd3b44fea1724b954534c
blob + b14338066f9aa0e5eae85e2311697603291567a4
--- src/lib9/fmt/fprint.c
+++ src/lib9/fmt/fprint.c
@@ -12,8 +12,9 @@
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
 #include <stdarg.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
+#include "fmtdef.h"
 
 int
 fprint(int fd, char *fmt, ...)
blob - dcdcd799324387b103f403a972fb99dc90830c4e
blob + 6e355a20faf7e896e9e863b2a2338ec6bcbf9159
--- src/lib9/fmt/nan64.c
+++ src/lib9/fmt/nan64.c
@@ -5,24 +5,17 @@
  * same byte ordering.
  */
 
-#include "nan.h"
+#include "plan9.h"
+#include "fmt.h"
+#include "fmtdef.h"
 
 #if defined (__APPLE__) || (__powerpc__)
 #define _NEEDLL
 #endif
 
-typedef unsigned long long uvlong;
-typedef unsigned long ulong;
-
-#ifdef _NEEDLL
-static uvlong uvnan    = 0x7FF0000000000001LL;
-static uvlong uvinf    = 0x7FF0000000000000LL;
-static uvlong uvneginf = 0xFFF0000000000000LL;
-#else
 static uvlong uvnan    = ((uvlong)0x7FF00000<<32)|0x00000001;
 static uvlong uvinf    = ((uvlong)0x7FF00000<<32)|0x00000000;
 static uvlong uvneginf = ((uvlong)0xFFF00000<<32)|0x00000000;
-#endif
 
 double
 __NaN(void)
@@ -72,5 +65,3 @@ __isInf(double d, int sign)
 	else
 		return x==uvneginf;
 }
-
-
blob - 65a426c30f87ed0feb314fc6d49d7d3e5cab4094
blob + ecd8b6dc929d8504f7d35794a551d494d2083d1f
--- src/lib9/fmt/pow10.c
+++ src/lib9/fmt/pow10.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 381a1da9253f60b4f82805d0c1768cc70681e7a9
blob + 81f202f897c491964eaa7f49615be9e4386a5a9c
--- src/lib9/fmt/print.c
+++ src/lib9/fmt/print.c
@@ -12,8 +12,9 @@
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
 #include <stdarg.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
+#include "fmtdef.h"
 
 int
 print(char *fmt, ...)
blob - 9ec84cd0981ca290c9be6c91557511653d8729ea
blob + 533763952be5a8841c07eb0dc3b99a1c2a8e7f11
--- src/lib9/fmt/runefmtstr.c
+++ src/lib9/fmt/runefmtstr.c
@@ -11,9 +11,20 @@
  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
+/*
+ * Plan 9 port version must include libc.h in order to 
+ * get Plan 9 debugging malloc, which sometimes returns
+ * different pointers than the standard malloc. 
+ */
+#ifdef PLAN9PORT
 #include <u.h>
 #include <libc.h>
+#else
+#include <stdlib.h>
+#include "plan9.h"
+#include "fmt.h"
 #include "fmtdef.h"
+#endif
 
 static int
 runeFmtStrFlush(Fmt *f)
blob - 7829a4399ed3aa9ac77def2c8281525fe7d2983e
blob + 2753b580e0ff99f8a8b087ac197e3a5fc581f945
--- src/lib9/fmt/runeseprint.c
+++ src/lib9/fmt/runeseprint.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 538ae0ee308d69dab05d8a2e1c91d78f3875d4b7
blob + 285ec190557f17f29206dd81f21a4907a1e7e31a
--- src/lib9/fmt/runesmprint.c
+++ src/lib9/fmt/runesmprint.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 5abb6dbf1f31dbe08a5fb187a11291a0e6a6c4da
blob + 2fd1b417fa768f152a38d90d507170ae2b00ae96
--- src/lib9/fmt/runesnprint.c
+++ src/lib9/fmt/runesnprint.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 8abfeb65897fefad201ee63a6f2f97953d037b83
blob + ad66efaf6e28c770b2093d9f7c25542031f14db6
--- src/lib9/fmt/runesprint.c
+++ src/lib9/fmt/runesprint.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - a9ef99b912db83b94b5464dd88b1d66ff018f793
blob + 72f7e1b0a0fc89f33ec9193b0aca84ca004d16cf
--- src/lib9/fmt/runevseprint.c
+++ src/lib9/fmt/runevseprint.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 3326da81efc7cac076a74946f9ca106c72bbbff3
blob + 988e5c021ad660b04acf73073cf53087025dcf42
--- src/lib9/fmt/runevsmprint.c
+++ src/lib9/fmt/runevsmprint.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <stdlib.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 71557e5b77c09f65effe8bd1038b76529e0677dc
blob + 8aff7345a35c7f6b5e9ba645d508ff5345e81aea
--- src/lib9/fmt/runevsnprint.c
+++ src/lib9/fmt/runevsnprint.c
@@ -13,7 +13,7 @@
  */
 #include <stdarg.h>
 #include <string.h>
-#include "utf.h"
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - d5031a2b16c6de2208dc98d5db603036f797c002
blob + 32f60c69783b0ef9fc4a47b89eace68219b52960
--- src/lib9/fmt/seprint.c
+++ src/lib9/fmt/seprint.c
@@ -12,7 +12,9 @@
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
 #include <stdarg.h>
+#include "plan9.h"
 #include "fmt.h"
+#include "fmtdef.h"
 
 char*
 seprint(char *buf, char *e, char *fmt, ...)
blob - 543411a0ad260fc0b31207d2f01b8e8047ae2fca
blob + 1bc8975aeb61f61ce1cb6b8603c9b73f75caee99
--- src/lib9/fmt/smprint.c
+++ src/lib9/fmt/smprint.c
@@ -12,7 +12,9 @@
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
 #include <stdarg.h>
+#include "plan9.h"
 #include "fmt.h"
+#include "fmtdef.h"
 
 char*
 smprint(char *fmt, ...)
blob - 594606d21eac12a48d9ca7bc5601ef96ebf512c9
blob + 693affd74b143a93cfd4fd5ee5b05dbe1f2a90d6
--- src/lib9/fmt/snprint.c
+++ src/lib9/fmt/snprint.c
@@ -12,7 +12,9 @@
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
 #include <stdarg.h>
+#include "plan9.h"
 #include "fmt.h"
+#include "fmtdef.h"
 
 int
 snprint(char *buf, int len, char *fmt, ...)
blob - 8551ca3c685477d90e22bab0dc142bdc9ed0bdeb
blob + 8313b169e639d3e02c416f31cfd019ce9dc42fd5
--- src/lib9/fmt/sprint.c
+++ src/lib9/fmt/sprint.c
@@ -13,6 +13,8 @@
  */
 #include <stdarg.h>
 #include <fmt.h>
+#include "plan9.h"
+#include "fmt.h"
 #include "fmtdef.h"
 
 int
blob - 685b7faea4dc34a86d63e977cf738e74fc378f22
blob + 5939dd90df206fd3473f5854afeddb6c3ecbfb4e
--- src/lib9/fmt/strtod.c
+++ src/lib9/fmt/strtod.c
@@ -17,15 +17,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include "plan9.h"
 #include "fmt.h"
-#include "nan.h"
-
-#ifndef nelem
-#define nelem(x)	(sizeof(x)/sizeof *(x))
-#endif
-#define nil ((void*)0)
-#define ulong _fmtulong
-typedef unsigned long ulong;
+#include "fmtdef.h"
 
 static ulong
 umuldiv(ulong a, ulong b, ulong c)
blob - a1a1d5edc05d8ad2fcf6d32b146d8db1d2ff0a9f
blob + 650f0f559c50326cb655ef00c9d327684bf2e747
--- src/lib9/fmt/test.c
+++ src/lib9/fmt/test.c
@@ -13,7 +13,9 @@
  */
 #include <stdarg.h>
 #include <utf.h>
+#include "plan9.h"
 #include "fmt.h"
+#include "fmtdef.h"
 
 int
 main(int argc, char *argv[])
blob - 711b6588fad535c8d8ed659dd75ca924f97fd6cc
blob + 1df47477406e4d50ef441ad34928b4ea2fef57cf
--- src/lib9/fmt/vfprint.c
+++ src/lib9/fmt/vfprint.c
@@ -12,6 +12,7 @@
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
 #include <stdarg.h>
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - a1be5e40ccdc66fd085e29a10251f1cd741222f0
blob + 9eb674ac4a07a346ed61c138120592ed0263f2e2
--- src/lib9/fmt/vseprint.c
+++ src/lib9/fmt/vseprint.c
@@ -12,6 +12,7 @@
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
 #include <stdarg.h>
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 4f55c41cbb03af7f6b36a9698060fbe1a26c19f8
blob + 871531ee3d098d56ca9df1a98ad0315ba002b63d
--- src/lib9/fmt/vsmprint.c
+++ src/lib9/fmt/vsmprint.c
@@ -13,6 +13,7 @@
  */
 #include <stdlib.h>
 #include <stdarg.h>
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - 7272ab62c725b81b9a9c52ae39d9ec41e0b27bc6
blob + ec05d48a2c099fb71579f8061943ffaed2c2977b
--- src/lib9/fmt/vsnprint.c
+++ src/lib9/fmt/vsnprint.c
@@ -13,6 +13,7 @@
  */
 #include <stdlib.h>
 #include <stdarg.h>
+#include "plan9.h"
 #include "fmt.h"
 #include "fmtdef.h"
 
blob - e1aaa9be9908cef3726e43ac1c14aba263c31992
blob + 1cf8c7e6575d1075cae1cd2e1e467faf1fba79bc
--- src/lib9/utf/rune.c
+++ src/lib9/utf/rune.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 enum
 {
blob - e1e8c9d576e3dd25642f5e91d3b8137087c44973
blob + f345a1b68812aa675808840b580d567a149a684f
--- src/lib9/utf/runestrcat.c
+++ src/lib9/utf/runestrcat.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 Rune*
 runestrcat(Rune *s1, Rune *s2)
blob - 45ee673a5992b3bcb4869a14a7b215a48dbb55e6
blob + 90d05e5adda1f7b3bc4d6d76a1d02aa6e9460c7e
--- src/lib9/utf/runestrchr.c
+++ src/lib9/utf/runestrchr.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 Rune*
 runestrchr(Rune *s, Rune c)
blob - d14145f3828f984b49bab82b58165b80dbe9ee27
blob + 359062758cb83f8ea37cdc7eaad2d1b4caad37bb
--- src/lib9/utf/runestrcmp.c
+++ src/lib9/utf/runestrcmp.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 int
 runestrcmp(Rune *s1, Rune *s2)
blob - 9d7aa026a8063fec4061ded8d2efdf2c2b41e9f7
blob + b8c2411fe6108734184bc2b2ce549f5a25cac8d0
--- src/lib9/utf/runestrcpy.c
+++ src/lib9/utf/runestrcpy.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 Rune*
 runestrcpy(Rune *s1, Rune *s2)
blob - 97a889c8f10ebeb156dec0c655228858cfa6d800
blob + 7accedaac187a5d68672d5f6ee7b1a9150396ac3
--- src/lib9/utf/runestrdup.c
+++ src/lib9/utf/runestrdup.c
@@ -14,8 +14,8 @@
 #include <stdarg.h>
 #include <string.h>
 #include <stdlib.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 Rune*
 runestrdup(Rune *s) 
blob - f3e4a096b4b03889a7a0d02d0ad6a5ce5ac70e1e
blob + 83450c9a54c910a59a0cdae28ade2572f8499007
--- src/lib9/utf/runestrecpy.c
+++ src/lib9/utf/runestrecpy.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 Rune*
 runestrecpy(Rune *s1, Rune *es1, Rune *s2)
blob - bca3050c55a8ee5d855819584cb13c187e0059ce
blob + 0096d52592b87e927b246576235e8580398312e9
--- src/lib9/utf/runestrlen.c
+++ src/lib9/utf/runestrlen.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 long
 runestrlen(Rune *s)
blob - 74400c30e8699a594fc09e66f273741618a1d436
blob + 7404fb9a0f4b669ecd5bb4699d6c1eb692008662
--- src/lib9/utf/runestrncat.c
+++ src/lib9/utf/runestrncat.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 Rune*
 runestrncat(Rune *s1, Rune *s2, long n)
blob - dbd9da45c5e4eef46a0de125f421b7717a6b3340
blob + 4fbdb0a1ecc2b40e2f6ebcf82585189aae7e1ba2
--- src/lib9/utf/runestrncmp.c
+++ src/lib9/utf/runestrncmp.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 int
 runestrncmp(Rune *s1, Rune *s2, long n)
blob - acba7bc2bd589adfa0516b50ea52ea41a3401c42
blob + f2517347d87ad0a4bdb5ac56d0add29b62434086
--- src/lib9/utf/runestrncpy.c
+++ src/lib9/utf/runestrncpy.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 Rune*
 runestrncpy(Rune *s1, Rune *s2, long n)
blob - 1f40c5a655f6331d363a3336cbfe5a08bcc4ca71
blob + 1f36854840b8e836e46de59b86a4eefb6b3793cf
--- src/lib9/utf/runestrrchr.c
+++ src/lib9/utf/runestrrchr.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 Rune*
 runestrrchr(Rune *s, Rune c)
blob - 48583a3d5efb027fc825527d21f32cbcc0d6a828
blob + 8be7a03214208e971bccc1367f58449bfd5eef96
--- src/lib9/utf/runestrstr.c
+++ src/lib9/utf/runestrstr.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 /*
  * Return pointer to first occurrence of s2 in s1,
blob - ffae30e69a05c6fc50117939f7870c570fb08401
blob + 41a3272918ea59beea3711dfbbe6d2c1b2c5c69c
--- src/lib9/utf/runetype.c
+++ src/lib9/utf/runetype.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 /*
  * alpha ranges -
@@ -1030,8 +1030,7 @@ Rune	__totitle1[] =
 	0x01f3, 499,	/* dz Dz */
 };
 
-static
-Rune*
+static Rune*
 bsearch(Rune c, Rune *t, int n, int ne)
 {
 	Rune *p;
blob - 4b58ae87e42b5fe5a25b3536e9539250b6742cf3
blob + 1ff41813b86d48e39d7e8d9258c5a894018e3025
--- src/lib9/utf/utfdef.h
+++ src/lib9/utf/utfdef.h
@@ -1,14 +1,33 @@
-#define uchar _utfuchar
-#define ushort _utfushort
-#define uint _utfuint
-#define ulong _utfulong
-#define vlong _utfvlong
-#define uvlong _utfuvlong
+/*
+ * compiler directive on Plan 9
+ */
+#ifndef USED
+#define USED(x) if(x);else
+#endif
 
+/*
+ * easiest way to make sure these are defined
+ */
+#define uchar	_fmtuchar
+#define ushort	_fmtushort
+#define uint	_fmtuint
+#define ulong	_fmtulong
+#define vlong	_fmtvlong
+#define uvlong	_fmtuvlong
 typedef unsigned char		uchar;
 typedef unsigned short		ushort;
 typedef unsigned int		uint;
 typedef unsigned long		ulong;
+typedef unsigned long long	uvlong;
+typedef long long		vlong;
 
-#define nelem(x) (sizeof(x)/sizeof((x)[0]))
-#define nil ((void*)0)
+/*
+ * nil cannot be ((void*)0) on ANSI C,
+ * because it is used for function pointers
+ */
+#undef	nil
+#define	nil	0
+
+#undef	nelem
+#define	nelem	((void*)0)
+
blob - 571593503f49aa1f94ca72a8f78aa4ba25bc01ec
blob + fde9338c135dc2b5b4f11e4c0984eaee7245dbf7
--- src/lib9/utf/utfecpy.c
+++ src/lib9/utf/utfecpy.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 char*
 utfecpy(char *to, char *e, char *from)
blob - a10a5318a9e74ac90d5c849e0366ae648a6ba3d0
blob + 2e8c666ac229afe00a9f48389aaa8d71fcb1af44
--- src/lib9/utf/utflen.c
+++ src/lib9/utf/utflen.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 int
 utflen(char *s)
blob - 66d674fd249c3a6c9ee607374afb33f4adcc10b8
blob + 6418f6190c562b71a747a41e6eceb441d11ce21a
--- src/lib9/utf/utfnlen.c
+++ src/lib9/utf/utfnlen.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 int
 utfnlen(char *s, long m)
blob - 37d2a72559983334d5ccaf8df986b9f0e0e999c5
blob + fc84d6b8dfed79485c11d8a5eb43bd49348dc69f
--- src/lib9/utf/utfrrune.c
+++ src/lib9/utf/utfrrune.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 char*
 utfrrune(char *s, long c)
blob - 1a2e04c9f5160ba531c096b34b4e3c1b68ec883c
blob + 5aa476a90b598d458c3480c8b0a9f31a5a9a3052
--- src/lib9/utf/utfrune.c
+++ src/lib9/utf/utfrune.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 char*
 utfrune(char *s, long c)
blob - ea36036121e8c58d3a3dcaf8eb080f63bd4116db
blob + 70873cc32912d9f7d90fd1c5a565d3a7cba61028
--- src/lib9/utf/utfutf.c
+++ src/lib9/utf/utfutf.c
@@ -13,8 +13,8 @@
  */
 #include <stdarg.h>
 #include <string.h>
+#include "plan9.h"
 #include "utf.h"
-#include "utfdef.h"
 
 
 /*