ref: 7f189830897b8e338087b45dfba9b7ff18a9bb24
parent: f8e3db6d29a44708872dd51a57b74033fdac41b6
author: Jacob Moody <[email protected]>
date: Mon Feb 13 19:02:14 EST 2023
initial port
--- a/char.c
+++ b/char.c
@@ -1,8 +1,8 @@
/* reading characters and escapes */
+#include <u.h>
+#include <libc.h>
#include <ctype.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "roff.h"
/* return the length of a utf-8 character based on its first byte */
--- a/clr.c
+++ b/clr.c
@@ -1,8 +1,8 @@
/* color management */
+#include <u.h>
+#include <libc.h>
#include <ctype.h>
#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
#include "roff.h"
static struct color {
--- a/cp.c
+++ b/cp.c
@@ -1,7 +1,7 @@
/* copy-mode character interpretation */
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "roff.h"
static int cp_blkdep; /* input block depth (text in \{ and \}) */
--- a/dev.c
+++ b/dev.c
@@ -1,8 +1,8 @@
/* output device */
-#include <ctype.h>
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <ctype.h>
#include "roff.h"
static char dev_dir[PATHLEN]; /* device directory */
--- a/dict.c
+++ b/dict.c
@@ -1,6 +1,6 @@
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "roff.h"
#define CNTMIN (1 << 10)
--- a/dir.c
+++ b/dir.c
@@ -1,7 +1,7 @@
/* output text direction */
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "roff.h"
int dir_do; /* enable text direction processing */
--- a/draw.c
+++ b/draw.c
@@ -1,7 +1,8 @@
/* helper for drawing commands in ren.c */
+#include <u.h>
+#include <libc.h>
#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
+#include <stdio.h>
#include "roff.h"
static int cwid(char *c)
--- a/eval.c
+++ b/eval.c
@@ -1,7 +1,8 @@
/* evaluation of integer expressions */
-#include <ctype.h>
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <string.h>
+#include <ctype.h>
#include "roff.h"
#define SCHAR "icpPvmnu" /* scale indicators */
--- a/fmt.c
+++ b/fmt.c
@@ -11,9 +11,9 @@
* means the call should be repeated after fetching previously
* formatted lines via fmt_nextline().
*/
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "roff.h"
#define FMT_LLEN(f) MAX(0, (f)->ll - (f)->li - (f)->lI)
--- a/font.c
+++ b/font.c
@@ -1,7 +1,7 @@
/* font handling */
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "roff.h"
/* convert wid in device unitwidth size to size sz */
--- a/hyph.c
+++ b/hyph.c
@@ -1,7 +1,8 @@
/* hyphenation */
+#include <u.h>
+#include <libc.h>
#include <ctype.h>
#include <stdio.h>
-#include <string.h>
#include "roff.h"
#include "hyen.h"
--- a/in.c
+++ b/in.c
@@ -1,7 +1,7 @@
/* input stream management */
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "roff.h"
struct inbuf {
--- a/iset.c
+++ b/iset.c
@@ -1,5 +1,5 @@
-#include <stdlib.h>
-#include <string.h>
+#include <u.h>
+#include <libc.h>
#include "roff.h"
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1))
@@ -43,7 +43,7 @@
int *iset_get(struct iset *iset, int key)
{
- return key >= 0 && key < iset->cnt ? iset->set[key] : NULL;
+ return key >= 0 && key < iset->cnt ? iset->set[key] : nil;
}
int iset_len(struct iset *iset, int key)
--- a/map.c
+++ b/map.c
@@ -1,6 +1,7 @@
/* mapping register/macro names to indices */
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <string.h>
#include "roff.h"
#define MAPBEG 256 /* the entries reserved for .x names */
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,33 @@
+</$objtype/mkfile
+
+FDIR=/sys/lib/neatroff/font
+MDIR=/sys/lib/neatroff/tmac
+
+CFLAGS=-Fpw -DTROFFFDIR="/sys/lib/neatroff/font" -DTROFFMDIR="/sys/lib/neatroff/tmac"
+BIN=/$objtype/bin/
+TARG=neatroff
+
+OFILES=\
+ roff.$O\
+ dev.$O\
+ font.$O\
+ in.$O\
+ cp.$O\
+ tr.$O\
+ ren.$O\
+ out.$O\
+ reg.$O\
+ sbuf.$O\
+ fmt.$O\
+ eval.$O\
+ draw.$O\
+ wb.$O\
+ hyph.$O\
+ map.$O\
+ clr.$O\
+ char.$O\
+ dict.$O\
+ iset.$O\
+ dir.$O\
+
+</sys/src/cmd/mkone
--- a/out.c
+++ b/out.c
@@ -1,9 +1,8 @@
/* generating troff output */
-#include <ctype.h>
-#include <stdarg.h>
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <ctype.h>
#include "roff.h"
static int out_nl = 1;
--- a/reg.c
+++ b/reg.c
@@ -1,11 +1,8 @@
/* registers and environments */
-#include <ctype.h>
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
+#include <ctype.h>
#include "roff.h"
#define NENVS 64 /* number of environment registers */
@@ -258,13 +255,16 @@
static void init_time(void)
{
- time_t t = time(NULL);
- struct tm *tm = localtime(&t);
- num_set(map("dw"), tm->tm_wday + 1);
- num_set(map("dy"), tm->tm_mday);
- num_set(map("mo"), tm->tm_mon + 1);
- num_set(map("yr"), tm->tm_year % 100);
- num_set(map(".yr"), 1900 + tm->tm_year);
+ Tzone *tz;
+ Tm tm;
+ tz = tzload("local");
+ tmnow(&tm, tz);
+
+ num_set(map("dw"), tm.wday + 1);
+ num_set(map("dy"), tm.mday);
+ num_set(map("mo"), tm.mon + 1);
+ num_set(map("yr"), tm.year % 100);
+ num_set(map(".yr"), 1900 + tm.year);
}
static void init_globals(void)
--- a/ren.c
+++ b/ren.c
@@ -1,8 +1,8 @@
/* rendering lines and managing traps */
-#include <ctype.h>
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <ctype.h>
#include "roff.h"
#define NOPAGE 0x40000000 /* undefined bp_next */
--- a/roff.c
+++ b/roff.c
@@ -15,10 +15,9 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <stdarg.h>
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
#include "roff.h"
void errmsg(char *fmt, ...)
@@ -32,12 +31,12 @@
void errdie(char *msg)
{
fprintf(stderr, "%s", msg);
- exit(1);
+ exits(msg);
}
void *mextend(void *old, long oldsz, long newsz, int memsz)
{
- void *new = xmalloc(newsz * memsz);
+ char *new = xmalloc(newsz * memsz);
memcpy(new, old, oldsz * memsz);
memset(new + oldsz * memsz, 0, (newsz - oldsz) * memsz);
free(old);
--- a/sbuf.c
+++ b/sbuf.c
@@ -1,8 +1,7 @@
/* variable length string buffer */
-#include <stdarg.h>
+#include <u.h>
+#include <libc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "roff.h"
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1))
--- a/tr.c
+++ b/tr.c
@@ -1,8 +1,8 @@
/* built-in troff requests */
+#include <u.h>
+#include <libc.h>
#include <ctype.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "roff.h"
static int tr_nl = 1; /* just read a newline */
@@ -131,7 +131,7 @@
cp_copymode(0);
if (empty) {
sbuf_done(&sbuf);
- return NULL;
+ return nil;
}
return sbuf_out(&sbuf);
}
@@ -161,7 +161,7 @@
{
int first = 1;
int c;
- char *req = NULL;
+ char *req = nil;
cp_back('\n');
cp_copymode(1);
while ((c = cp_next()) >= 0) {
@@ -175,7 +175,7 @@
}
req = read_name(n_cp);
if (!strcmp(end, req)) {
- in_push(end, NULL);
+ in_push(end, nil);
cp_back(c_cc);
break;
}
@@ -184,7 +184,7 @@
sbuf_append(sbuf, req);
}
free(req);
- req = NULL;
+ req = nil;
}
}
free(req);
@@ -210,10 +210,10 @@
static void tr_ig(char **args)
{
- macrobody(NULL, args[1] ? args[1] : ".");
+ macrobody(nil, args[1] ? args[1] : ".");
}
-/* read into sbuf until stop; if stop is NULL, stop at whitespace */
+/* read into sbuf until stop; if stop is nil, stop at whitespace */
static int read_until(struct sbuf *sbuf, char *stop,
int (*next)(void), void (*back)(int))
{
@@ -276,7 +276,7 @@
struct sbuf sbuf;
int ret;
sbuf_init(&sbuf);
- read_until(&sbuf, NULL, next, back);
+ read_until(&sbuf, nil, next, back);
ret = eval(sbuf_buf(&sbuf), '\0') > 0;
sbuf_done(&sbuf);
return ret;
@@ -389,7 +389,7 @@
static void tr_sy(char **args)
{
- system(args[1]);
+ //system(args[1]);
}
static void tr_lt(char **args)
@@ -600,7 +600,7 @@
static void tr_cs(char **args)
{
- struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : NULL;
+ struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : nil;
if (fn)
font_setcs(fn, args[2] ? eval(args[2], 0) : 0,
args[3] ? eval(args[3], 0) : 0);
@@ -608,7 +608,7 @@
static void tr_fzoom(char **args)
{
- struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : NULL;
+ struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : nil;
if (fn)
font_setzoom(fn, args[2] ? eval(args[2], 0) : 0);
}
@@ -615,7 +615,7 @@
static void tr_tkf(char **args)
{
- struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : NULL;
+ struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : nil;
if (fn && args[5])
font_track(fn, eval(args[2], 0), eval(args[3], 0),
eval(args[4], 0), eval(args[5], 0));
@@ -623,7 +623,7 @@
static void tr_ff(char **args)
{
- struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : NULL;
+ struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : nil;
int i;
for (i = 2; i < NARGS; i++)
if (fn && args[i] && args[i][0] && args[i][1])
@@ -632,7 +632,7 @@
static void tr_ffsc(char **args)
{
- struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : NULL;
+ struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : nil;
if (fn)
font_scrp(fn, args[2]);
if (fn)
@@ -663,7 +663,7 @@
static void tr_bd(char **args)
{
- struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : NULL;
+ struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : nil;
if (!args[1] || !strcmp("S", args[1]))
return;
if (fn)
@@ -783,7 +783,7 @@
char *cdef_map(char *c, int fn)
{
int i = cdef_find(c, fn);
- return !cdef_expanding && i >= 0 ? cdef_dst[i] : NULL;
+ return !cdef_expanding && i >= 0 ? cdef_dst[i] : nil;
}
int cdef_expand(struct wb *wb, char *s, int fn)
@@ -808,7 +808,7 @@
if (!strcmp(cdef_src[i], c)) {
if (!fn || (fp > 0 && cdef_fn[i] == fp)) {
free(cdef_dst[i]);
- cdef_dst[i] = NULL;
+ cdef_dst[i] = nil;
cdef_src[i][0] = '\0';
}
}
@@ -842,15 +842,15 @@
int i;
for (i = 1; i < NARGS; i++)
if (args[i])
- cdef_remove(NULL, args[i]);
+ cdef_remove(nil, args[i]);
}
static void tr_char(char **args)
{
if (args[2])
- cdef_add(NULL, args[1], args[2]);
+ cdef_add(nil, args[1], args[2]);
else
- cdef_remove(NULL, args[1]);
+ cdef_remove(nil, args[1]);
}
static void tr_ochar(char **args)
@@ -863,7 +863,7 @@
static void tr_fmap(char **args)
{
- struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : NULL;
+ struct font *fn = args[1] ? dev_font(dev_pos(args[1])) : nil;
if (fn && args[2])
font_map(fn, args[2], args[3]);
}
@@ -1264,7 +1264,7 @@
int tr_nextreq(void)
{
char *mac;
- char *arg0 = NULL;
+ char *arg0 = nil;
int c;
if (!tr_nl)
return 1;
--- a/wb.c
+++ b/wb.c
@@ -1,8 +1,8 @@
/* word buffer */
+#include <u.h>
+#include <libc.h>
#include <ctype.h>
-#include <stdlib.h>
#include <stdio.h>
-#include <string.h>
#include "roff.h"
/* the current font, size and color */