ref: ae0d5a79909f7779bb0ba3d5bdfd0d9cdd959f2f
parent: a88a4afade93ace70e1650576da2ff7dffc61ffd
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Sun Feb 17 16:48:51 EST 2013
9boot: make print handle \n -> \r\n conversion, style
--- a/sys/src/boot/pc/fat.c
+++ b/sys/src/boot/pc/fat.c
@@ -384,21 +384,21 @@
drive = ((ushort*)sp)[5] & 0xFF;
if(findfat(&fat, drive, 0, 0)){- print("no fat\r\n");+ print("no fat\n");halt();
}
if(fatwalk(f = &fi, &fat, "plan9.ini")){- print("no config\r\n");+ print("no config\n");f = 0;
}
for(;;){kern = configure(f, path); f = 0;
if(fatwalk(&fi, &fat, kern)){- print("not found\r\n");+ print("not found\n");continue;
}
print(bootkern(&fi));
- print(crnl);
+ print("\n");}
}
--- a/sys/src/boot/pc/fns.h
+++ b/sys/src/boot/pc/fns.h
@@ -1,7 +1,6 @@
/* handy strings in l.s */
extern char origin[];
extern char hex[];
-extern char crnl[];
extern char bootname[];
/* l.s */
--- a/sys/src/boot/pc/iso.c
+++ b/sys/src/boot/pc/iso.c
@@ -161,17 +161,17 @@
close(&ex);
if(isowalk(f = &ex, drive, "/cfg/plan9.ini")){- print("no config\r\n");+ print("no config\n");f = 0;
}
for(;;){kern = configure(f, path); f = 0;
if(isowalk(&ex, drive, kern)){- print("not found\r\n");+ print("not found\n");continue;
}
print(bootkern(&ex));
- print(crnl);
+ print("\n");}
}
--- a/sys/src/boot/pc/l.s
+++ b/sys/src/boot/pc/l.s
@@ -295,9 +295,6 @@
#endif
-TEXT crnl(SB), $0
- BYTE $'\r'; BYTE $'\n'; BYTE $0
-
TEXT hex(SB), $0
BYTE $'0'; BYTE $'1'; BYTE $'2'; BYTE $'3';
BYTE $'4'; BYTE $'5'; BYTE $'6'; BYTE $'7';
--- a/sys/src/boot/pc/pxe.c
+++ b/sys/src/boot/pc/pxe.c
@@ -268,7 +268,7 @@
break;
case Tftp_ERROR:
print(t->pkt+4);
- print(crnl);
+ print("\n");default:
t->eof = 1;
return -1;
@@ -336,11 +336,11 @@
Tftp t;
if(pxeinit()){- print("pxe init\r\n");+ print("pxe init\n");halt();
}
if(getip(yip, sip, gip, mac)){- print("bad dhcp\r\n");+ print("bad dhcp\n");halt();
}
memmove(path, "/cfg/pxe/", 9);
@@ -347,16 +347,16 @@
memmove(path+9, mac, 13);
if(tftpopen(f = &t, path, yip, sip, gip))
if(tftpopen(f, "/cfg/pxe/default", yip, sip, gip)){- print("no config\r\n");+ print("no config\n");f = 0;
}
for(;;){kern = configure(f, path); f = 0;
if(tftpopen(&t, kern, yip, sip, gip)){- print("not found\r\n");+ print("not found\n");continue;
}
print(bootkern(&t));
- print(crnl);
+ print("\n");}
}
--- a/sys/src/boot/pc/sub.c
+++ b/sys/src/boot/pc/sub.c
@@ -38,9 +38,11 @@
uchar *s = src;
int r = 0;
- while(n-- > 0)
- if(r = (*d++ - *s++))
+ while(n-- > 0){+ r = *d++ - *s++;
+ if(r != 0)
break;
+ }
return r;
}
@@ -50,7 +52,7 @@
{char *p = s;
- while(*p)
+ while(*p != '\0')
p++;
return p - s;
@@ -59,18 +61,21 @@
char*
strchr(char *s, int c)
{- for(; *s; s++)
+ for(; *s != 0; s++)
if(*s == c)
return s;
- return 0;
+ return nil;
}
void
print(char *s)
{- while(*s)
+ while(*s != 0){+ if(*s == '\n')
+ putc('\r');putc(*s++);
+ }
}
int
@@ -103,10 +108,10 @@
p = buf;
do{- if(!f)
+ if(f == nil)
putc('>'); for(;;){- if(!f){+ if(f == nil){putc(*p = getc());
if(*p == '\r')
putc('\n');@@ -116,12 +121,12 @@
}
}else if(read(f, p, 1) <= 0)
return 0;
- if(strchr(crnl, *p))
+ if(strchr("\r\n", *p) != nil)break;
- if(p == buf && strchr(white, *p))
+ if(p == buf && strchr(white, *p) != nil)
continue; /* whitespace on start of line */
if(p >= buf + 64-1){- if(!f){+ if(f == nil){ putc('\b'); putc(' '); putc('\b');@@ -171,7 +176,7 @@
for(e = p+1; e < confend; e++)
if(*e == '\n')
break;
- if(!memcmp(p, s, n)){+ if(memcmp(p, s, n) == 0){p += n;
n = e - p;
buf[n] = 0;
@@ -179,7 +184,7 @@
return buf;
}
}
- return 0;
+ return nil;
}
static int
@@ -194,7 +199,7 @@
break;
}
}
- if(!memcmp(p, s, strlen(s))){+ if(memcmp(p, s, strlen(s)) == 0){memmove(p, e, confend - e);
confend -= e - p;
*confend = 0;
@@ -225,45 +230,37 @@
inblock = 0;
Loop:
while(readline(f, line) > 0){- if(*line == 0 || strchr("#;=", *line))+ if(*line == 0 || strchr("#;=", *line) != nil)continue;
if(*line == '['){- inblock = memcmp("[common]", line, 8);+ inblock = memcmp("[common]", line, 8) != 0;continue;
}
- if(!memcmp("boot", line, 5)){+ if(memcmp("boot", line, 5) == 0){nowait=1;
break;
}
- if(!memcmp("wait", line, 5)){+ if(memcmp("wait", line, 5) == 0){nowait=0;
continue;
}
- if(!memcmp("show", line, 5)){- for(p = BOOTARGS; p < confend; p++){- if(*p == '\n')
- print(crnl);
- else
- putc(*p);
- }
+ if(memcmp("show", line, 5) == 0){+ print(BOOTARGS);
continue;
}
- if(!memcmp("clear", line, 5)){- if(line[5] == 0){- print("ok");- print(crnl);
+ if(memcmp("clear", line, 5) == 0){+ if(line[5] == '\0'){+ print("ok\n");goto Clear;
- } else if(line[5] == ' ' && delconf(line+6)){- print("ok");- print(crnl);
- }
+ } else if(line[5] == ' ' && delconf(line+6))
+ print("ok\n");continue;
}
- if(inblock || (p = strchr(line, '=')) == nil)
+ if(inblock != 0 || (p = strchr(line, '=')) == nil)
continue;
*p++ = 0;
delconf(line);
- if(!memcmp("apm", line, 3)){+ if(memcmp("apm", line, 3) == 0){ apmconf('0' - line[3]);continue;
}
@@ -272,28 +269,25 @@
memmove(confend, line, n = strlen(line)); confend += n;
*confend++ = '=';
memmove(confend, p, n = strlen(p)); confend += n;
- *confend = 0;
-
- print(s); print(crnl);
-
*confend++ = '\n';
*confend = 0;
+ print(s);
}
kern = getconf("bootfile=", path);- if(f){+ if(f != nil){close(f);
- f = 0;
+ f = nil;
- if(kern && (nowait==0 || timeout(1000)))
+ if(kern != nil && (nowait==0 || timeout(1000)))
goto Loop;
}
- if(!kern){- print("no bootfile\r\n");+ if(kern == nil){+ print("no bootfile\n");goto Loop;
}
- while(p = strchr(kern, '!'))
+ while((p = strchr(kern, '!')) != nil)
kern = p+1;
return kern;
@@ -333,7 +327,7 @@
memset(a, 0, 20);
apm(id);
- if(memcmp(a, "APM", 4))
+ if(memcmp(a, "APM", 4) != 0)
return;
s = confend;
@@ -346,10 +340,10 @@
addconfx(" di=", 4, *((ushort*)(a+10))); addconfx(" esi=", 8, *((ulong*)(a+16)));- print(s); print(crnl);
-
*confend++ = '\n';
*confend = 0;
+
+ print(s);
}
static void
@@ -392,11 +386,10 @@
if(confend == s)
return;
- *confend = 0;
- print(s); print(crnl);
-
*confend++ = '\n';
*confend = 0;
+
+ print(s);
}
static ulong
@@ -414,7 +407,7 @@
Exec ex;
while(a20() < 0)
- print("a20 enable failed\r\n");+ print("a20 enable failed\n");if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
return "bad header";
@@ -448,8 +441,7 @@
close(f);
unload();
- print("boot");- print(crnl);
+ print("boot\n");jump(e);
--
⑨