Introduction
Introduction Statistics Contact Development Disclaimer Help
Standardize more code on wide characters. - sam - An updated version of the sam…
git clone git://vernunftzentrum.de/sam.git
Log
Files
Refs
LICENSE
---
commit 97562b07dcb8e2eca6523d2820f504275c6a9bb4
parent ab21252fbf883e2f6fd0f8293ea109839f37728c
Author: Rob King <[email protected]>
Date: Thu, 20 Oct 2016 17:00:56 -0500
Standardize more code on wide characters.
Eventually I'd like to see sam use wide characters exclusively,
except for obvious exceptions (e.g. arguments to syscalls).
Diffstat:
sam/error.c | 19 ++++++++-----------
sam/io.c | 12 ++++++------
sam/mesg.c | 4 ++--
sam/regexp.c | 10 +++++-----
sam/sam.c | 18 +++++++++---------
sam/sam.h | 4 ++--
sam/shell.c | 6 +++---
sam/sys.c | 2 +-
sam/unix.c | 10 +++++-----
sam/xec.c | 7 ++-----
10 files changed, 43 insertions(+), 49 deletions(-)
---
diff --git a/sam/error.c b/sam/error.c
@@ -95,7 +95,7 @@ error_c(Err s, int c)
void
warn(Warn s)
{
- dprint("?warning: %s\n", wmsg[s]);
+ dprint(L"?warning: %s\n", wmsg[s]);
}
void
@@ -113,24 +113,21 @@ warn_SS(Warn s, String *a, String *b)
void
warn_s(Warn s, char *a)
{
- dprint("?warning: %s `%s'\n", wmsg[s], a);
+ dprint(L"?warning: %s `%s'\n", wmsg[s], a);
}
void
-termwrite(char *s)
+termwrite(wchar_t *p)
{
- String *p;
+ size_t l = wcslen(p);
if(downloaded){
- p = tmpcstr(s);
if(cmd)
- Finsert(cmd, p, cmdpt);
+ Finsert(cmd, tmprstr(p, l), cmdpt);
else
- Strinsert(&cmdstr, p, cmdstr.n);
- cmdptadv += p->n;
- Strclose(p);
- free(p);
+ Strinsert(&cmdstr, tmprstr(p, l), cmdstr.n);
+ cmdptadv += wcslen(p);
}else
- Write(STDERR_FILENO, s, strlen(s));
+ fprintf(stderr, "%ls", p);
}
diff --git a/sam/io.c b/sam/io.c
@@ -49,14 +49,14 @@ writef(File *f)
genc = Strtoc(&genstr);
if((io=creat(genc, 0666L)) < 0)
error_s(Ecreate, genc);
- dprint("%s: ", genc);
+ dprint(L"%s: ", genc);
if(statfd(io, 0, 0, 0, &length, &appendonly) > 0 && appendonly && length>0)
error(Eappend);
n = writeio(f);
if(f->name.s[0]==0 || samename)
state(f, addr.r.p1==0 && addr.r.p2==f->nrunes? Clean : Dirty);
if(newfile)
- dprint("(new file) ");
+ dprint(L"(new file) ");
if(addr.r.p2>0 && Fchars(f, &c, addr.r.p2-1, addr.r.p2) && c!='\n')
warn(Wnotnewline);
closeio(n);
@@ -148,7 +148,7 @@ closeio(Posn p)
close(io);
io = 0;
if(p >= 0)
- dprint("#%lu\n", p);
+ dprint(L"#%lu\n", p);
}
int remotefd0 = 0;
@@ -204,7 +204,7 @@ connectto(char *machine)
int p1[2], p2[2];
if(pipe(p1)<0 || pipe(p2)<0){
- dprint("can't pipe\n");
+ dprint(L"can't pipe\n");
exit(EXIT_FAILURE);
}
remotefd0 = p1[0];
@@ -218,11 +218,11 @@ connectto(char *machine)
close(p2[0]);
close(p2[1]);
execlp(getenv("RSH") ? getenv("RSH") : RXPATH, getenv("RSH") ? getenv(…
- dprint("can't exec %s\n", RXPATH);
+ dprint(L"can't exec %s\n", RXPATH);
exit(EXIT_FAILURE);
case -1:
- dprint("can't fork\n");
+ dprint(L"can't fork\n");
exit(EXIT_FAILURE);
}
close(p1[1]);
diff --git a/sam/mesg.c b/sam/mesg.c
@@ -451,7 +451,7 @@ inmesg(Tmesg type)
m = snarfbuf->nrunes;
if(m > 32000) { /* tmprstr stores len in a int16_t */
m = 32000;
- dprint("?warning: snarf buffer truncated\n");
+ dprint(L"?warning: snarf buffer truncated\n");
}
rp = malloc(m*sizeof(wchar_t));
if(rp){
@@ -465,7 +465,7 @@ inmesg(Tmesg type)
Write(1, c, i);
free(c);
} else
- dprint("snarf buffer too long\n");
+ dprint(L"snarf buffer too long\n");
break;
case Tsetsnarf:
diff --git a/sam/regexp.c b/sam/regexp.c
@@ -371,12 +371,12 @@ dumpstack(void){
Node *stk;
int *ip;
- dprint("operators\n");
+ dprint(L"operators\n");
for(ip = atorstack; ip<atorp; ip++)
- dprint("0%o\n", *ip);
- dprint("operands\n");
+ dprint(L"0%o\n", *ip);
+ dprint(L"operands\n");
for(stk = andstack; stk<andp; stk++)
- dprint("0%o\t0%o\n", stk->first->type, stk->last->type);
+ dprint(L"0%o\t0%o\n", stk->first->type, stk->last->type);
}
void
dump(void){
@@ -384,7 +384,7 @@ dump(void){
l = program;
do{
- dprint("%d:\t0%o\t%d\t%d\n", l-program, l->type,
+ dprint(L"%d:\t0%o\t%d\t%d\n", l-program, l->type,
l->left-program, l->right-program);
}while(l++->type);
}
diff --git a/sam/sam.c b/sam/sam.c
@@ -232,7 +232,7 @@ panic(char *s)
if(!panicking++ && !setjmp(mainloop)){
wasd = downloaded;
downloaded = 0;
- dprint("sam: panic: %s\n", s);
+ dprint(L"sam: panic: %s\n", s);
if(wasd)
fprintf(stderr, "sam: panic: %s\n", s);
rescue();
@@ -247,7 +247,7 @@ hiccough(char *s)
exit(EXIT_FAILURE);
if(s)
- dprint("%s\n", s);
+ dprint(L"%s\n", s);
resetcmd();
resetxec();
@@ -467,7 +467,7 @@ filename(File *f)
if(genc)
free(genc);
genc = Strtoc(&f->name);
- dprint("%c%c%c %s\n", " '"[f->state==Dirty],
+ dprint(L"%c%c%c %s\n", " '"[f->state==Dirty],
"-+"[f->rasp!=0], " ."[f==curfile], genc);
}
@@ -739,15 +739,15 @@ printposn(File *f, int charsonly)
/* check if addr ends with '\n' */
if(addr.r.p2>0 && addr.r.p2>addr.r.p1 && (Fgetcset(f, addr.r.p2-1),Fge…
--l2;
- dprint("%lu", l1);
+ dprint(L"%lu", l1);
if(l2 != l1)
- dprint(",%lu", l2);
- dprint("; ");
+ dprint(L",%lu", l2);
+ dprint(L"; ");
}
- dprint("#%lu", addr.r.p1);
+ dprint(L"#%lu", addr.r.p1);
if(addr.r.p2 != addr.r.p1)
- dprint(",#%lu", addr.r.p2);
- dprint("\n");
+ dprint(L",#%lu", addr.r.p2);
+ dprint(L"\n");
}
void
diff --git a/sam/sam.h b/sam/sam.h
@@ -197,7 +197,7 @@ void delete(File*);
void delfile(File*);
void dellist(List*, int);
void doubleclick(File*, Posn);
-void dprint(char*, ...);
+void dprint(wchar_t *, ...);
void edit(File*, int);
void *emalloc(uint64_t);
void *erealloc(void*, uint64_t);
@@ -268,7 +268,7 @@ String *tmpcstr(char*);
String *tmprstr(wchar_t*, int);
void freetmpstr(String*);
void termcommand(void);
-void termwrite(char*);
+void termwrite(wchar_t *);
File *tofile(String*);
void toterminal(File*, int);
void trytoclose(File*);
diff --git a/sam/shell.c b/sam/shell.c
@@ -127,7 +127,7 @@ plan9(File *f, int type, String *s, int nest)
if(downloaded)
checkerrs();
if(!nest)
- dprint("!\n");
+ dprint(L"!\n");
return retcode;
}
@@ -146,9 +146,9 @@ checkerrs(void)
if(*p=='\n')
nl++;
*p = 0;
- dprint("%s", buf);
+ dprint(L"%s", buf);
if(p-buf < l-1)
- dprint("(sam: more in %s)\n", errfile);
+ dprint(L"(sam: more in %s)\n", errfile);
}
close(f);
}
diff --git a/sam/sys.c b/sam/sys.c
@@ -27,7 +27,7 @@ syserror(char *a)
if(!inerror){
inerror = true;
strncpy(buf, strerror(errno), ERRLEN);
- dprint("%s: ", a);
+ dprint(L"%s: ", a);
error_s(Eio, buf);
}
}
diff --git a/sam/unix.c b/sam/unix.c
@@ -37,7 +37,7 @@ print_ss(char *s, String *a, String *b)
for (cp = bp, rp = b->s; *rp; rp++)
cp += runetochar(cp, *rp);
*cp = 0;
- dprint("?warning: %s `%.*s' and `%.*s'\n", s, a->n, ap, b->n, bp);
+ dprint(L"?warning: %s `%.*s' and `%.*s'\n", s, a->n, ap, b->n, bp);
free(ap);
free(bp);
}
@@ -52,7 +52,7 @@ print_s(char *s, String *a)
for (cp = ap, rp = a->s; *rp; rp++)
cp += runetochar(cp, *rp);
*cp = 0;
- dprint("?warning: %s `%.*s'\n", s, a->n, ap);
+ dprint(L"?warning: %s `%.*s'\n", s, a->n, ap);
free(ap);
}
@@ -141,13 +141,13 @@ erealloc(void *p, uint64_t n)
}
void
-dprint(char *z, ...)
+dprint(wchar_t *z, ...)
{
va_list args;
- char buf[BLOCKSIZE + 1] = {0};
+ wchar_t buf[BLOCKSIZE + 1] = {0};
va_start(args, z);
- vsnprintf(buf, BLOCKSIZE, z, args);
+ vswprintf(buf, BLOCKSIZE, z, args);
termwrite(buf);
va_end(args);
}
diff --git a/sam/xec.c b/sam/xec.c
@@ -362,7 +362,6 @@ display(File *f)
{
Posn p1, p2;
int np, n;
- char *c;
p1 = addr.r.p1;
p2 = addr.r.p2;
@@ -374,12 +373,10 @@ display(File *f)
if(n <= 0)
panic("display");
genbuf[n] = 0;
- c = Strtoc(tmprstr(genbuf, n+1));
if(downloaded)
- termwrite(c);
+ termwrite(genbuf);
else
- Write(1, c, strlen(c));
- free(c);
+ fprintf(stdout, "%ls", genbuf);
p1+=n;
}
f->dot = addr;
You are viewing proxied material from vernunftzentrum.de. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.