Many small edits.

This commit is contained in:
rsc 2005-01-13 04:49:19 +00:00
parent 741f510ce7
commit c8b6342d3c
160 changed files with 2204 additions and 864 deletions

View file

@ -21,9 +21,9 @@ void
usage(void)
{
if(mk9660)
fprint(2, "usage: disk/mk9660 [-D:] [-9cjr] [-b bootfile] [-p proto] [-s src] cdimage\n");
fprint(2, "usage: mk9660 [-D:] [-9cjr] [-b bootfile] [-p proto] [-s src] cdimage\n");
else
fprint(2, "usage: disk/dump9660 [-D:] [-9cjr] [-m maxsize] [-n now] [-p proto] [-s src] cdimage\n");
fprint(2, "usage: dump9660 [-D:] [-9cjr] [-m maxsize] [-n now] [-p proto] [-s src] cdimage\n");
exits("usage");
}
@ -42,7 +42,7 @@ main(int argc, char **argv)
fix = 0;
status = nil;
memset(&info, 0, sizeof info);
proto = "/sys/lib/sysconfig/proto/allproto";
proto = unsharp("#9/proto/allproto");
src = "./";
info.volumename = atom("9CD");

View file

@ -357,7 +357,7 @@ userinit(void)
sprint(buf, "#9/acid/%s", mach->name);
loadmodule(unsharp(buf));
p = getenv("home");
p = getenv("HOME");
if(p != 0) {
sprint(buf, "%s/lib/acid", p);
silent = 1;

View file

@ -123,9 +123,7 @@ threadmain(int argc, char *argv[])
quotefmtinstall();
cputype = getenv("cputype");
objtype = getenv("objtype");
home = getenv("home");
if(home == nil)
home = getenv("HOME");
home = getenv("HOME");
p = getenv("tabstop");
if(p != nil){
maxtab = strtoul(p, nil, 0);

View file

@ -961,7 +961,7 @@ main(int argc, char **argv)
if(lflag) {
argv--;
argc++;
argv[1] = "/sys/lib/bclib";
argv[1] = unsharp("#9/lib/bclib");
}
if(cflag) {
yyinit(argc, argv);

View file

@ -75,7 +75,7 @@ main(int argc, char *argv[])
for(i=0; i<argc || (i==0 && argc==0); i++){
if(i==0 && argc==0)
snprint(buf, sizeof(buf),
"/usr/%s/lib/calendar", getuser());
"%s/lib/calendar", getenv("HOME"));
else
strcpy(buf, argv[i]);
fd = open(buf, OREAD);

View file

@ -134,6 +134,9 @@ void movieprintkey(void);
long pgwnextoff(long);
void pgwprintentry(Entry,int);
void pgwprintkey(void);
void rogetprintentry(Entry, int);
long rogetnextoff(long);
void rogetprintkey(void);
long slangnextoff(long);
void slangprintentry(Entry, int);
void slangprintkey(void);

View file

@ -2,7 +2,7 @@
TARG=dict
LFILES=oed.$O ahd.$O pcollins.$O pcollinsg.$O movie.$O slang.$O robert.$O\
world.$O jis208.$O gb2312.$O thesaurus.$O simple.$O pgw.$O
world.$O jis208.$O gb2312.$O thesaurus.$O simple.$O pgw.$O roget.$O\
OFILES=dict.$O\
$LFILES\

147
src/cmd/dict/roget.c Normal file
View file

@ -0,0 +1,147 @@
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ctype.h>
#include "dict.h"
/* Roget's Thesaurus from project Gutenberg */
/* static long Last = 0; */
void
rogetprintentry(Entry e, int cmd)
{
int spc;
char c, *p;
spc = 0;
p = e.start;
if(cmd == 'h'){
while(!isspace(*p) && p < e.end)
p++;
while(strncmp(p, " -- ", 4) != 0 && p < e.end){
while(isspace(*p) && p < e.end)
p++;
if (*p == '[' || *p == '{'){
c = (*p == '[')? ']': '}';
while(*p != c && p < e.end)
p++;
p++;
continue;
}
if (isdigit(*p) || ispunct(*p)){
while(!isspace(*p) && p < e.end)
p++;
continue;
}
if (isspace(*p))
spc = 1;
else
if (spc){
outchar(' ');
spc = 0;
}
while(!isspace(*p) && p < e.end)
outchar(*p++);
}
return;
}
while(p < e.end && !isspace(*p))
p++;
while(p < e.end && isspace(*p))
p++;
while (p < e.end){
if (p < e.end -4 && strncmp(p, " -- ", 4) == 0){ /* first line */
outnl(2);
p += 4;
spc = 0;
}
if (p < e.end -2 && strncmp(p, "[ ", 4) == 0){ /* twiddle layout */
outchars(" [");
continue;
}
if (p < e.end -4 && strncmp(p, "&c (", 4) == 0){ /* usefull xref */
if (spc)
outchar(' ');
outchar('/');
while(p < e.end && *p != '(')
p++;
p++;
while(p < e.end && *p != ')')
outchar(*p++);
p++;
while(p < e.end && isspace(*p))
p++;
while(p < e.end && isdigit(*p))
p++;
outchar('/');
continue;
}
if (p < e.end -3 && strncmp(p, "&c ", 3) == 0){ /* less usefull xref */
while(p < e.end && !isdigit(*p))
p++;
while(p < e.end && isdigit(*p))
p++;
continue;
}
if (*p == '\n' && p < (e.end -1)){ /* their newlines */
spc = 0;
p++;
if (isspace(*p)){ /* their continuation line */
while (isspace(*p))
p++;
p--;
}
else{
outnl(2);
}
}
if (spc && *p != ';' && *p != '.' &&
*p != ',' && !isspace(*p)){ /* drop spaces before punct */
spc = 0;
outchar(' ');
}
if (isspace(*p))
spc = 1;
else
outchar(*p);
p++;
}
outnl(0);
}
long
rogetnextoff(long fromoff)
{
int i;
vlong l;
char *p;
Bseek(bdict, fromoff, 0);
Brdline(bdict, '\n');
while ((p = Brdline(bdict, '\n')) != nil){
l = Blinelen(bdict);
if (!isdigit(*p))
continue;
for (i = 0; i < l-4; i++)
if (strncmp(p+i, " -- ", 4) == 0)
return Boffset(bdict)-l;
}
return Boffset(bdict);
}
void
rogetprintkey(void)
{
Bprint(bout, "No pronunciation key.\n");
}

View file

@ -16,6 +16,9 @@ Dict dicts[] = {
{"thesaurus", "Collins Thesaurus",
"#9/dict/thesaurus", "#9/dict/thesindex",
thesnextoff, thesprintentry, thesprintkey},
{"roget", "Project Gutenberg Roget's Thesaurus",
"#9/dict/roget", "#9/dict/rogetindex",
rogetnextoff, rogetprintentry, rogetprintkey},
{"ce", "Gendai Chinese->English",
"#9/dict/world/sansdata/sandic24.dat",

102
src/cmd/draw/iconv.c Normal file
View file

@ -0,0 +1,102 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
void
usage(void)
{
fprint(2, "usage: iconv [-u] [-c chanstr] [file]\n");
exits("usage");
}
void
writeuncompressed(int fd, Memimage *m)
{
char chanstr[32];
int bpl, y, j;
uchar *buf;
if(chantostr(chanstr, m->chan) == nil)
sysfatal("can't convert channel descriptor: %r");
fprint(fd, "%11s %11d %11d %11d %11d ",
chanstr, m->r.min.x, m->r.min.y, m->r.max.x, m->r.max.y);
bpl = bytesperline(m->r, m->depth);
buf = malloc(bpl);
if(buf == nil)
sysfatal("malloc failed: %r");
for(y=m->r.min.y; y<m->r.max.y; y++){
j = unloadmemimage(m, Rect(m->r.min.x, y, m->r.max.x, y+1), buf, bpl);
if(j != bpl)
sysfatal("image unload failed: %r");
if(write(fd, buf, bpl) != bpl)
sysfatal("write failed: %r");
}
free(buf);
}
void
main(int argc, char *argv[])
{
char *tostr, *file;
int fd, uncompressed;
ulong tochan;
Memimage *m, *n;
tostr = nil;
uncompressed = 0;
ARGBEGIN{
case 'c':
tostr = EARGF(usage());
break;
case 'u':
uncompressed = 1;
break;
default:
usage();
}ARGEND
memimageinit();
file = "<stdin>";
m = nil;
switch(argc){
case 0:
m = readmemimage(0);
break;
case 1:
file = argv[0];
fd = open(file, OREAD);
if(fd < 0)
sysfatal("can't open %s: %r", file);
m = readmemimage(fd);
close(fd);
break;
default:
usage();
}
if(m == nil)
sysfatal("can't read %s: %r", file);
if(tostr == nil)
tochan = m->chan;
else{
tochan = strtochan(tostr);
if(tochan == 0)
sysfatal("bad channel descriptor '%s'", tostr);
}
n = allocmemimage(m->r, tochan);
if(n == nil)
sysfatal("can't allocate new image: %r");
memimagedraw(n, n->r, m, m->r.min, nil, ZP, S);
if(uncompressed)
writeuncompressed(1, n);
else
writememimage(1, n);
exits(nil);
}

View file

@ -146,7 +146,7 @@ main(int argc, char *argv[])
vflag = 0;
}
if(oflag) {
p1 = "/fd/1";
p1 = "/dev/stdout";
p2 = savedfile;
while(*p2++ = *p1++)
;

View file

@ -21,6 +21,9 @@ main(int argc, char *argv[])
flags[ARGC()]++;
break;
case 'E': /* ignore, turns gnu grep into egrep */
break;
case 'e':
flags['e']++;
lineno = 0;

View file

@ -32,7 +32,7 @@ enum
void
usage(void)
{
fprint(2, "usage: %s [-s service] [-n remote-ns] [-fd] [-p remote-prog] remote-system\n", argv0);
fprint(2, "usage: %s [-df] [-s service] [-n remote-ns] [-p remote-prog] remote-system\n", argv0);
exits("usage");
}

View file

@ -21,7 +21,7 @@ char *mapindex(char *);
proj projection;
static char *mapdir = "/lib/map"; /* default map directory */
static char *mapdir = "#9/map"; /* default map directory */
struct file {
char *name;
char *color;
@ -150,6 +150,7 @@ main(int argc, char *argv[])
double dd;
if(sizeof(short)!=2)
abort(); /* getshort() won't work */
mapdir = unsharp(mapdir);
s = getenv("MAP");
if(s)
file[0].name = s;

View file

@ -9,7 +9,7 @@ fn demo {proj=$1; shift;
echo t $type
echo 'm -8192 -8192'
echo t $proj - $label
MAP=world MAPDIR=/lib/map map $proj $* -s -d 5
MAP=world MAPDIR=$PLAN9/map map $proj $* -s -d 5
}
sleep 5
}

View file

@ -1,9 +1,9 @@
|$PLAN9/bin/rc
MKSHELL=$PLAN9/bin/rc
use-rc:V:
for(i in a b c)
echo $i
|/bin/sh
MKSHELL=/bin/sh
use-sh:V:
for i in a b c
do

View file

@ -91,18 +91,18 @@ cp = wtos(tail, ' '); print("assign %s to %s\n", head->s, cp); free(cp);
*/
setvar(head->s, (void *) tail);
symlook(head->s, S_WESET, (void *)"");
if(strcmp(head->s, "MKSHELL") == 0){
if((err = setshell(tail)) != nil){
SYNERR(hline);
fprint(2, "%s\n", err);
Exit();
break;
}
}
}
if(attr)
symlook(head->s, S_NOEXPORT, (void *)"");
break;
case 'S':
if((err = setshell(tail)) != nil){
SYNERR(hline);
fprint(2, "%s\n", err);
Exit();
break;
}
break;
default:
SYNERR(hline);
fprint(2, "expected one of :<=\n");
@ -144,19 +144,14 @@ rhead(char *line, Word **h, Word **t, int *attr, char **prog)
int n;
Word *w;
if(*line == '|'){
sep = 'S'; /* shell */
p = line+1;
}else{
p = shellt->charin(line,":=<");
if(p == 0)
return('?');
sep = *p;
*p++ = 0;
if(sep == '<' && *p == '|'){
sep = '|';
p++;
}
p = shellt->charin(line,":=<");
if(p == 0)
return('?');
sep = *p;
*p++ = 0;
if(sep == '<' && *p == '|'){
sep = '|';
p++;
}
*attr = 0;
*prog = 0;

View file

@ -41,6 +41,7 @@ initshell(void)
{
shellcmd = stow(shells[0]->name);
shellt = shells[0];
setvar("MKSHELL", shellcmd);
}
void
@ -72,5 +73,6 @@ popshell(void)
shellstack = s->next;
shellt = s->t;
shellcmd = s->w;
setvar("MKSHELL", shellcmd);
free(s);
}

View file

@ -1,6 +1,6 @@
<$PLAN9/src/mkhdr
TARG=`ls *.[cy] | grep -v "\.tab\.c$" | sed 's/\.[cy]//'`
TARG=`ls *.[cy] | egrep -v "\.tab\.c$" | sed 's/\.[cy]//'`
<$PLAN9/src/mkmany

View file

@ -101,7 +101,7 @@ read_dir(int update)
n_count = 0;
n_list = malloc(NINC*sizeof(File));
na = NINC;
home = getenv("home");
home = getenv("HOME");
if(home) {
sprint(newstime, TFILE, home);
d = dirstat(newstime);

View file

@ -43,9 +43,7 @@ threadmain(int argc, char *argv[])
}ARGEND
user = getuser();
home = getenv("home");
if(home == nil)
home = getenv("HOME");
home = getenv("HOME");
if(user==nil || home==nil)
error("can't initialize $user or $home: %r");
if(plumbfile == nil){

View file

@ -90,6 +90,7 @@ var *newvar(char *name, var *next)
v->changed=0;
v->fnchanged=0;
v->next=next;
v->changefn = 0;
return v;
}
/*

View file

@ -1,4 +1,5 @@
#include <u.h>
#include <sys/stat.h>
#include <libc.h>
#define rmdir p9rmdir
@ -16,6 +17,13 @@ err(char *f)
}
}
int
issymlink(char *name)
{
struct stat s;
return lstat(name, &s) >= 0 && S_ISLNK(s.st_mode);
}
/*
* f is a non-empty directory. Remove its contents and then it.
*/
@ -48,7 +56,7 @@ rmdir(char *f)
ndir = 0;
for(i=0; i<n; i++){
snprint(name, nname, "%s/%s", f, dirbuf[i].name);
if(remove(name) != -1)
if(remove(name) != -1 || issymlink(name))
dirbuf[i].qid.type = QTFILE; /* so we won't recurse */
else{
if(dirbuf[i].qid.type & QTDIR)

View file

@ -17,7 +17,7 @@ Rune *right[]= {
char RSAM[] = "sam";
char SAMTERM[] = "/bin/aux/samterm";
char HOME[] = "home";
char HOME[] = "HOME";
char TMPDIR[] = "/tmp";
char SH[] = "rc";
char SHPATH[] = "/bin/rc";

View file

@ -356,7 +356,7 @@ tempfile(int n)
static uint pid;
char *dir;
dir = "/tmp";
dir = "/var/tmp";
if(args.tname)
dir = args.tname;
if(strlen(dir) >= nelem(file)-20) {

View file

@ -36,7 +36,6 @@ OFILES=\
mkfont.$O\
openfont.$O\
poly.$O\
readcolmap.$O\
readimage.$O\
readsubfont.$O\
rectclip.$O\
@ -52,7 +51,6 @@ OFILES=\
subfontname.$O\
unloadimage.$O\
window.$O\
writecolmap.$O\
writeimage.$O\
writesubfont.$O\
md-alloc.$O\

View file

@ -1,49 +0,0 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <bio.h>
static ulong
getval(char **p)
{
ulong v;
char *q;
v = strtoul(*p, &q, 0);
v |= v<<8;
v |= v<<16;
*p = q;
return v;
}
void
readcolmap(Display *d, RGB *colmap)
{
int i;
char *p, *q;
Biobuf *b;
char buf[128];
USED(screen);
sprint(buf, "/dev/draw/%d/colormap", d->dirno);
b = Bopen(buf, OREAD);
if(b == 0)
drawerror(d, "rdcolmap: can't open colormap device");
for(;;) {
p = Brdline(b, '\n');
if(p == 0)
break;
i = strtoul(p, &q, 0);
if(i < 0 || i > 255) {
fprint(2, "rdcolmap: bad index\n");
exits("bad");
}
p = q;
colmap[255-i].red = getval(&p);
colmap[255-i].green = getval(&p);
colmap[255-i].blue = getval(&p);
}
Bterm(b);
}

View file

@ -1,35 +0,0 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
/*
* This code (and the devdraw interface) will have to change
* if we ever get bitmaps with ldepth > 3, because the
* colormap will have to be written in chunks
*/
void
writecolmap(Display *d, RGB *m)
{
int i, n, fd;
char buf[64], *t;
ulong r, g, b;
sprint(buf, "/dev/draw/%d/colormap", d->dirno);
fd = open(buf, OWRITE);
if(fd < 0)
drawerror(d, "wrcolmap: open colormap failed");
t = malloc(8192);
n = 0;
for(i = 0; i < 256; i++) {
r = m[i].red>>24;
g = m[i].green>>24;
b = m[i].blue>>24;
n += sprint(t+n, "%d %lud %lud %lud\n", 255-i, r, g, b);
}
i = write(fd, t, n);
free(t);
close(fd);
if(i != n)
drawerror(d, "wrcolmap: bad write");
}

View file

@ -346,9 +346,7 @@ xattach(char *label)
display_resources = XResourceManagerString(_x.display);
if(display_resources == nil){
home = getenv("home");
if(home == nil)
home = getenv("HOME");
home = getenv("HOME");
if(home!=nil && (file=smprint("%s/.Xdefaults", home)) != nil){
XrmCombineFileDatabase(file, &database, False);
free(file);

View file

@ -249,6 +249,7 @@ chanalt(Alt *a)
Channel *c;
_Thread *t;
needstack(512);
for(i=0; a[i].op != CHANEND && a[i].op != CHANNOBLK; i++)
;
n = i;

View file

@ -42,10 +42,12 @@ child(void)
fprint(2, "%s: wait pid %d stopped\n", argv0, pid);
return;
}
#ifdef WIFCONTINUED
if(WIFCONTINUED(status)){
fprint(2, "%s: wait pid %d continued\n", argv0, pid);
return;
}
#endif
fprint(2, "%s: wait pid %d status 0x%ux\n", argv0, pid, status);
_exit(99);
}
@ -84,8 +86,6 @@ _threadsetupdaemonize(void)
sigpid = 1;
threadlinklibrary();
if(pipe(p) < 0)
sysfatal("passer pipe: %r");

View file

@ -169,6 +169,7 @@ _threadswitch(void)
{
Proc *p;
needstack(0);
p = proc();
//print("threadswtch %p\n", p);
contextswitch(&p->thread->context, &p->schedcontext);
@ -324,6 +325,20 @@ threadsetstate(char *fmt, ...)
va_end(arg);
}
void
needstack(int n)
{
_Thread *t;
t = proc()->thread;
if((char*)&t <= (char*)t->stk
|| (char*)&t - (char*)t->stk < 256+n){
fprint(2, "thread stack overflow\n");
abort();
}
}
/*
* locking
*/
@ -499,11 +514,6 @@ threadmainstart(void *v)
threadmain(threadargc, threadargv);
}
void
threadlinklibrary(void)
{
}
int
main(int argc, char **argv)
{