[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
nls
- To: tech_(_at_)_openbsd_(_dot_)_org
- Subject: nls
- From: Theo de Raadt <deraadt_(_at_)_theos_(_dot_)_com>
- Date: Fri, 26 Apr 1996 05:51:15 -0600
I did the nls/fprintf/strerror/sprintf optimization we talked about a
few days ago.... I'm a little amazed that the difference is this low:
# du /bin
BEFORE: 5433 /bin
AFTER: 5417 /bin
Hmm. Not nearly as much as I expected... I guess printf & friends are
a natural part of just about any program these days..
Don't know if I'll commit the change... it isn't very
pretty. opinions?
Index: string/__strerror.c
===================================================================
RCS file: /cvs/src/lib/libc/string/__strerror.c,v
retrieving revision 1.2
diff -b -c -r1.2 __strerror.c
*** __strerror.c 1996/01/29 02:04:11 1.2
--- __strerror.c 1996/04/26 11:19:19
***************
*** 50,55 ****
--- 50,57 ----
#include <stdio.h>
#include <string.h>
+ extern char *__itoa __P((int num));
+
/*
* Since perror() is not allowed to change the contents of strerror()'s
* static buffer, both functions supply their own buffers to the
***************
*** 79,88 ****
#endif
} else {
#ifdef NLS
! sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), errnum);
#else
! sprintf(buf, UPREFIX, errnum);
#endif
}
#ifdef NLS
--- 81,106 ----
#endif
} else {
#ifdef NLS
! char *errstr = (char *)catgets(catd, 1, 0xffff, UPREFIX);
#else
! char *errstr = UPREFIX;
#endif
+ char *p1 = buf;
+ int once = 1;
+
+ while (*errstr) {
+ if (once && errstr[0] == '%') {
+ if (errstr[1] == 'u' || errstr[1] == 'd') {
+ *p1 = '\0';
+ strcat(p1, __itoa(errnum));
+ p1 = p1 + strlen(p1);
+ once = 0;
+ errstr += 2;
+ }
+ } else
+ *p1++ = *errstr++;
+ }
+ *p1 = '\0';
}
#ifdef NLS
Index: nls/msgcat.c
===================================================================
RCS file: /cvs/src/lib/libc/nls/msgcat.c,v
retrieving revision 1.1.1.1
diff -b -c -r1.1.1.1 msgcat.c
*** msgcat.c 1995/10/18 08:42:05 1.1.1.1
--- msgcat.c 1996/04/26 11:15:11
***************
*** 283,292 ****
* Internal routines
*/
/* Note that only malloc failures are allowed to return an error */
#define ERRNAME "Message Catalog System"
! #define CORRUPT() {fprintf(stderr, "%s: corrupt file.\n", ERRNAME); return(0);}
! #define NOSPACE() {fprintf(stderr, "%s: no more memory.\n", ERRNAME); return(NLERR);}
static nl_catd loadCat( catpath, type)
__const char *catpath;
--- 283,324 ----
* Internal routines
*/
+ void
+ err2(s1, s2)
+ char *s1, *s2;
+ {
+ char buf[1024];
+
+ strcpy(buf, s1);
+ strcat(buf, s2);
+ strcat(buf, ".\n");
+ write(2, buf, strlen(buf));
+ }
+
+ char *
+ __itoa(num)
+ int num;
+ {
+ static char ret[12];
+ char *p = &ret[sizeof(ret)-1];
+ unsigned int x = num;
+
+ *p = '\0';
+ if (num < 0)
+ x = -num;
+ while (x) {
+ *--p = '0' + (x % 10);
+ x /= 10;
+ }
+ if (num < 0)
+ *--p = '-';
+ return (p);
+ }
+
/* Note that only malloc failures are allowed to return an error */
#define ERRNAME "Message Catalog System"
! #define CORRUPT() {err2(ERRNAME, ": corrupt file"); return(0);}
! #define NOSPACE() {err2(ERRNAME, ": no more memory"); return(NLERR);}
static nl_catd loadCat( catpath, type)
__const char *catpath;
***************
*** 298,303 ****
--- 330,336 ----
MCMsgT *msg;
long i, j;
off_t nextSet;
+ char errbuf[64];
cat = (MCCatT *) malloc(sizeof(MCCatT));
if (!cat) return(NLERR);
***************
*** 314,327 ****
if (strncmp(header.magic, MCMagic, MCMagicLen) != 0) CORRUPT();
if (header.majorVer != MCMajorVer) {
! fprintf(stderr, "%s: %s is version %d, we need %d.\n", ERRNAME,
! catpath, header.majorVer, MCMajorVer);
return(0);
}
if (header.numSets <= 0) {
! fprintf(stderr, "%s: %s has %d sets!\n", ERRNAME, catpath,
! header.numSets);
return(0);
}
--- 347,368 ----
if (strncmp(header.magic, MCMagic, MCMagicLen) != 0) CORRUPT();
if (header.majorVer != MCMajorVer) {
! strcpy(errbuf, ": ");
! strcat(errbuf, catpath);
! strcat(errbuf, " is version ");
! strcat(errbuf, __itoa(header.majorVer));
! strcat(errbuf, ", we need ");
! strcat(errbuf, __itoa(MCMajorVer));
! err2(ERRNAME, errbuf);
return(0);
}
if (header.numSets <= 0) {
! strcpy(errbuf, ": ");
! strcat(errbuf, catpath);
! strcat(errbuf, " has ");
! strcat(errbuf, __itoa(header.numSets));
! err2(ERRNAME, errbuf);
return(0);
}
***************
*** 389,396 ****
set->invalid = False;
return(1);
}
-
-
-
-
-
--- 430,432 ----
Visit your host, monkey.org