Article View: gnu.emacs.bug
Article #99613bug and fix in the format function (doprnt.c)
From: Scott D Kalter
Date: Fri, 27 Jul 1990 21:56
Date: Fri, 27 Jul 1990 21:56
74 lines
2720 bytes
2720 bytes
GNU Emacs 18.55.0 on ata (berkeley-unix)
Sun OS 4.1
Sun4c
eval: (format "%-20s" "hello")
returns: "hello"
SHOULD
return: "hello " <-- note padding on right
The problem is in doprnt.c where code is written to right justify
strings with space padding to the left but the code to left justify
with space padding to the right has been left out. Here is a diff for
a potential solution (minimally tested):
----------------------------------------------------------------
[ata]sdk> rcsdiff -c -r1.1 -r1.3 doprnt.c
===================================================================
RCS file: RCS/doprnt.c,v
retrieving revision 1.1
retrieving revision 1.3
diff -c -r1.1 -r1.3
*** /usr/tmp/aaaa01833 Fri Jul 27 14:52:22 1990
--- /usr/tmp/baaa01833 Fri Jul 27 14:52:22 1990
***************
*** 83,89 ****
/* Copy string into final output, truncating if no room. */
doit:
tem = strlen (string);
! minlen -= tem;
while (minlen > 0 && bufsize > 0)
{
*bufptr++ = ' ';
--- 83,97 ----
/* Copy string into final output, truncating if no room. */
doit:
tem = strlen (string);
!
! /* BEGIN modifications to get left justification working */
! #define ABS(x) ((x) < 0 ? -(x) : (x))
! if (ABS(minlen) <= tem)
! minlen = 0;
! else
! minlen += (minlen>0) ? -tem : tem;
! /* END mods */
!
while (minlen > 0 && bufsize > 0)
{
*bufptr++ = ' ';
***************
*** 95,100 ****
--- 103,116 ----
strncpy (bufptr, string, tem);
bufptr += tem;
bufsize -= tem;
+ /* BEGIN modifications to get left justification working */
+ while (minlen < 0 && bufsize > 0)
+ {
+ *bufptr++ = ' ';
+ bufsize--;
+ minlen++;
+ }
+ /* END mods for left justification */
continue;
case 'c':
----------------------------------------------------------------
Scott Kalter <sdk@twinsun.com>
Chris Houser <chris@twinsun.com>
Dorab Patel <dorab@twinsun.com>
Technical Details
Message-ID:
<9007272156.AA01837@ata.twinsun.com>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!twinsun.com!sdkShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fb2f1,8043ab810d2450d6,start X-Google-Attributes: gidfb2f1,public X-Google-ArrivalTime: 1990-07-27 14:56:56 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!twinsun.com!sdk From: sdk@twinsun.com (Scott D Kalter) Newsgroups: gnu.emacs.bug Subject: bug and fix in the format function (doprnt.c) Message-ID: <9007272156.AA01837@ata.twinsun.com> Date: 27 Jul 90 21:56:56 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 74 Posted: Fri Jul 27 22:56:56 1990