ICU-1220 if --canon is used with -L, --list-transliterators, print only

one name per line (makes grepping very easy).
Ensure that we can handle transliterators names of arbitrary length (as
big as memory will allow).

X-SVN-Rev: 7398
This commit is contained in:
Yves Arrouye 2002-01-07 21:05:30 +00:00
parent 4cd24e1a9f
commit b2b5b7ff96
2 changed files with 45 additions and 6 deletions

View file

@ -74,6 +74,9 @@ or
.BR "\-\-default-code" ,
the list of encodings is produced in a format compatible with
.BR convrtrs.txt (5).
If used with
.BR "\-L\fP, \fB\-\-list\-transliterators" ,
print only one transliterator name per line.
.TP
.BI "\-x" " transliterator"
Run the transcoded Unicode data through the given

View file

@ -30,6 +30,7 @@
#include <stdlib.h>
#include "cmemory.h"
#include "cstring.h"
// This is the UConverter headerfile
#include "unicode/ucnv.h"
@ -217,18 +218,53 @@ static int printConverters(const char *pname, const char *lookfor, int canon)
}
// Print all available transliterators
static int printTransliterators(const char *pname) {
static int printTransliterators(const char *pname, int canon) {
int32_t numtrans = utrans_countAvailableIDs(), i;
char buf[512];
int buflen = 512;
char *buf = (char *) uprv_malloc(buflen);
char staticbuf[512];
char sepchar = canon ? '\n' : ' ';
if (!buf) {
buf = staticbuf;
buflen = sizeof(staticbuf);
}
for (i = 0; i < numtrans; ++i) {
utrans_getAvailableID(i, buf, sizeof(buf));
int32_t len = utrans_getAvailableID(i, buf, buflen);
if (len >= buflen -1) {
if (buf != staticbuf) {
buflen <<= 1;
if (buflen < len) {
buflen = len + 64;
}
buf = (char *) uprv_realloc(buf, buflen);
if (!buf) {
buf = staticbuf;
buflen = sizeof(staticbuf);
}
}
utrans_getAvailableID(i, buf, buflen);
if (len >= buflen) {
uprv_strcpy(buf + buflen - 4, "...");
}
}
printf("%s", buf);
if (i < numtrans - 1) {
putchar(' ');
putchar(sepchar);
}
}
if (sepchar != '\n') {
putchar('\n');
}
if (buf != staticbuf) {
uprv_free(buf);
}
return 0;
}
@ -521,7 +557,7 @@ int main(int argc, char** argv)
if (printConvs || printName) {
return printConverters(pname, printName, printCanon) ? 2 : 0;
} else if (printTranslits) {
return printTransliterators(pname) ? 3 : 0;
return printTransliterators(pname, printCanon) ? 3 : 0;
}
if (fromcpage==0 && tocpage==0)