RetroBSD

2.11BSD operating system for microcontrollers
It is currently Tue Dec 18, 2018 2:47 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Feb 01, 2016 6:53 am 

Joined: Mon Feb 01, 2016 5:34 am
Posts: 6
Today, I want to use expr(1), but I can't get correct result.

For example
Code:
# uname -a
2.11BSD pic32 2.11BSD 2.11 BSD Unix for PIC32, revision G488 build 2:      Compiled 2016-02-01 by mutoh@mutoubushinokonpyuta.local:      /Users/mutoh/work/BSD/retrobsd/sys/pic32/max32  pic32
# expr 1 + 1
00 00 9c 00 00 00 04 00 00 00 40 00 00 00 80 00


I think to fix this problem, use patch below:
Code:
% git diff src/cmd/expr.y
diff --git a/src/cmd/expr.y b/src/cmd/expr.y
index 0b81aca..32c892f 100644
--- a/src/cmd/expr.y
+++ b/src/cmd/expr.y
@@ -132,7 +132,7 @@ char *arith(op, r1, r2) char *r1, *r2;
     case REM: i1 = i1 % i2; break;
     }
     rv = malloc(16);
-    sprintf(rv, "%D", i1);
+    sprintf(rv, "%ld", i1);
     return rv;
 }
 


Top
 Profile  
 
PostPosted: Tue Mar 15, 2016 5:01 am 

Joined: Mon Feb 01, 2016 5:34 am
Posts: 6
I find what is the real problem.

At many implementation of printf, it have format string "%D" which equal to "%ld".
This is undocumented function.

So, real fix is below:
Quote:
diff --git a/src/libc/stdio/doprnt.c b/src/libc/stdio/doprnt.c
index b1885bb..6ac58ea 100644
--- a/src/libc/stdio/doprnt.c
+++ b/src/libc/stdio/doprnt.c
@@ -171,20 +171,8 @@ reswitch: switch (c = *fmt++) {
break;

case 'D':
- s = va_arg (ap, const unsigned char*);
- if (! width)
- width = 16;
- if (sharpflag)
- padding = ':';
- while (width--) {
- c = *s++;
- PUTC (mkhex (c >> 4));
- PUTC (mkhex (c));
- if (width)
- PUTC (padding);
- }
- break;
-
+ lflag=1;
+ /*FALLTHROUGH*/
case 'd':
case 'i':
ul = lflag ? va_arg (ap, long) : va_arg (ap, int);


How about this fix?


Top
 Profile  
 
PostPosted: Tue Mar 15, 2016 5:56 am 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1091
Hi mutoh,

Nice piece of work :).

I wonder what 'D' is useful for?

And how to leave the feature available but make expr work correctly.

Serge is a pretty clever guy. I bet he had that feature in for some pretty good reason?

The feature doesn't seem to be in the LiteBSD sources.

Lots of fun :).

Wiz


Top
 Profile  
 
PostPosted: Tue Mar 15, 2016 7:21 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Years back there has been a significant :) effort provided in order to implement double precision floating point into retrobsd. We messed with printf too. Not sure the latest builds do include the fixes.
So be careful when using fp math, for example.

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission