QNX conversion to UTF files

We have a file created in the Windows environment and are sending (via
ftp) to the QNX4 environment. The problem occurs when the data in the
file (which is to be displayed graphically) contains french characters.

How do you convert a file from non UTF format to UTF format?

Doug Rixmann <rixmannd@rdsdata.com> wrote:
: We have a file created in the Windows environment and are sending (via
: ftp) to the QNX4 environment. The problem occurs when the data in the
: file (which is to be displayed graphically) contains french characters.
: How do you convert a file from non UTF format to UTF format?

I wrote this utility 4 years ago which does this. It may not even
compile anymore, but should give you some ideas (use the PxTranslate
library). Invoke as “trans cp1252 utffile” (since you say
“Windows” the source document is probably in cp1250 or cp1252).

#include <mbstring.h>
#include <stdio.h>
#include <stdlib.h>
#include <photon/PxProto.h>

int main(int argc, char *argv[])
{
struct PxTransCtrl *trans;
char *code, *utf;
int srclen, dstlen, buf;

if (argc < 2) {
fprintf(stderr, “specify translation charset\n”);
return(1);
}
if ((trans = PxTranslateSet(NULL, argv[1])) == NULL) {
fprintf(stderr, “unknown translation charset ‘%s’\n”, argv[1]);
return(1);
}
buf = (argc > 2) ? atoi(argv[2]) : 256;
if ((code = malloc(buf)) == NULL || (utf = malloc(buf * MB_LEN_MAX)) == NULL) {
fprintf(stderr, “unable to allocate %d-byte translation buffers\n”, buf);
return(1);
}

while ((srclen = fread(code, sizeof(char), buf, stdin))) {
if ((dstlen = PxTranslateStateToUTF(trans, code, srclen, NULL, utf, buf * MB_LEN_MAX)) == -1) {
fprintf(stderr, “invalid encoding sequence\n”);
return(1);
}
fwrite(utf, dstlen, sizeof(char), stdout);
}

return(0);
}