home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
p
/
pktxl31.zip
/
PKTXL.C
< prev
next >
Wrap
Text File
|
1992-05-22
|
22KB
|
1,146 lines
/* PKTXL.C Översättning av PKT-filer mellan olika teckenuppsättningar. */
/* (c) 1989, 1990 Nils Hammar */
/* VMS is a trademark of Digital Equipment Corporation. */
/* FOSSIL is a Fido-Opus-Seadog .... */
/* The program may be used by anyone, as long as the source of the program
is declared. If the source is used in commercial programs, the
information about the source must be included in the documentation.
This program is primary written for Microsoft C 6.00, but should be
possible to implement in other environments with minor efforts.
*/
/* This program is currently only possible to compile under
Microsoft C. It is possible to use Turbo C, but then the program
will not allow wildcards in the input filenames.
*/
/* This declaration allows the case conversion to be customized.
Do not customize characters 'A' to 'Z'. It is possible to add
characters too.
*/
#define VERSION "3.1"
#define UPPERCASE "ÉABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖÜÆÇÑ"
#define LOWERCASE "éabcdefghijklmnopqrstuvwxyzåäöüæçñ"
#define INCL_DOS
#include <os2.h>
#include <stdio.h>
#ifdef __TURBOC__
#include <dos.h>
#include <stdlib.h>
#else
#ifdef MSDOS
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#else
#include <curses.h>
#endif /* MSDOS */
#endif /* __TURBOC__ */
#include <time.h>
#include <string.h>
#include <malloc.h>
#include <direct.h>
#include <time.h>
#ifndef __TURBOC__
#ifndef MSDOS
#include <unistd.h>
#endif /* MSDOS */
#endif /* __TURBOC__ */
int direntry(struct FILEINFO *, char *, int);
void dtidkonv(unsigned int, unsigned int, char *);
unsigned char transchar(unsigned char, int, int);
int xlatetexts(FILE *, FILE *, int, int);
int dirlist(char *, char *);
void xlatefile(char *, char*, int, int);
int space(int, int);
int trema(int, int);
int dollar(int, int);
int cedilla(int, int);
int minus(int, int);
int dot(int, int);
int slash(int, int);
int caret(int, int);
int greek(int, int);
int trademark(int, int);
int subcompstr(char *, char *);
void addkludge(FILE *, int);
void upper(char *, char *);
int identify(char *);
typedef struct
{
unsigned int orignode, destnode, year, month, day, hour, minute,
second, baud, idcode, orignet, destnet;
unsigned char pcode, serialno, password[20];
unsigned int origzone, destzone;
unsigned char filler[8];
} packheader;
typedef struct
{
unsigned int idcode, orignode, destnode, orignet, destnet,
attribute, cost;
} packmessage;
struct FILEINFO
{
char rsvd[21];
char attr;
unsigned int time;
unsigned int date;
long size;
char name[13];
char nill;
};
packmessage packmsg;
packheader packhd;
int opt, nolf, nosoft;
/* On the following lines is it possible to customize the translation
of the national language characters.
Current translation is for Swedish terminals.
Observe that \ must be typed \\ which will make some confusion.
The only line that have to be modified is the 7-bit line.
The other lines are fixed. All places with a blank means no
translation.
Here follows some translation tables for 7-bit.
These translations is for CodePage 437, which will give some
problems with some languages.
*/
unsigned char *teckenset[11]={
/* 7-bit Swedish charset */
"}{|][\\~^@` # ",
/* 8-bit IBM-PC */
"åäöÅÄÖüÜÉéÇçâàêëèïî æÆôòûùÿ¢£¥ƒáíóúñÑ∞°ß#₧",
/* 8-bit ISO 8859 */
"σΣ÷┼─╓ⁿ▄╔Θ╟τΓαΩδΦ∩ε∞µ╞⌠≥√∙²óúÑ ßφ≤·±╤≈░▀# ",
/* 8-bit MacIntosh */
"îèÜüÇàƒåâÄé ëêÉæÅòöô╛«Öÿ₧¥╪óú┤─çÆù£û ░íº# ",
/* 7-bit French charset (one char excluded.) */
" { \\ @ } | [ # ",
/* 7-bit German charset (one char excluded.) */
" {| [\\}] ~# ",
/* 7-bit English (British) charset */
" # ",
/* 7-bit Danish charset (Not really. CP437 does not
support Danish characters, we use the Swedish ones) */
"} |] \\ {[ # ",
/* 7-bit Italian charset */
" ] { } ~ | ` [ # ",
/* 7-bit Spanish charset (Not fully translated
due to the CP437 limitations.) */
" |\\ #",
/* 7-bit Japanese charset */
" \\ "},
/* "åäöÅÄÖüÜÉéÇçâàêëèïî æÆôòûùÿ¢£¥ƒáíóúñÑ∞°ß#₧", */
/* Umlaut is a special character conversion which is often used
in germany. This conversion is not always the best, but
it will make the texts more readable if converting from
"wrong" character set. */
*umlaut[43]={
"aa", "ae", "oe", "AA", "AE", "OE", "ue", "UE", "E", "e",
"C", "c", "a", "a", "e", "e", "e", "i", "i", "i", "ae", "AE",
"o", "o", "u", "u", "ye", "c", "L", "Y", "f", "a", "i", "o",
"u", "n", "N", "", "", "ss", "#", "Pt"};
int main(argc, argv)
int argc;
char *argv[];
{
char tmp[160],
*sortarea,
inmail[160],
tmp1[160],
tmp2[160],
outmail[160],
indir[160],
args[20][160],
*env;
int i, n, z, j, fromcharset, tocharset;
long tid1, tid2;
fprintf(stderr, "\n\nPKTXL - Packet translator version ");
fprintf(stderr, VERSION);
fprintf(stderr, "\n(C) 1990,1991,1992 Nils Hammar\n");
fprintf(stderr, "Free to use in non-commercial applications.\n\n");
if (argc < 5)
{
printf("Syntax : PKTXL infile outfile fromcharset tocharset\n");
exit(9);
}
opt=0; /* != 0 if a new charset kludge is added. */
nolf=0; /* != 0 if all LF chars is to be removed. */
nosoft=0; /* != 0 if all SoftCR is to be removed. */
i=0;
while(i<20) *args[i++]=0;
i=1;
j=1;
while(i<=argc)
{
if (*argv[i] != '-')
{
strcpy(args[j], argv[i]);
j++;
}
upper(tmp1, argv[i]);
if (subcompstr("-KLUDGE", tmp1) == 0) opt=-1;
if (subcompstr("-NOLF", tmp1) == 0) nolf=-1;
if (subcompstr("-NOSOFT", tmp1) == 0) nosoft=-1;
if (subcompstr("-K", tmp1) == 0) opt=-1;
if (subcompstr("-L", tmp1) == 0) nolf=-1;
if (subcompstr("-S", tmp1) == 0) nosoft=-1;
i++;
}
time(&tid1);
strcpy(inmail, args[1]);
strcpy(indir, inmail);
/* Check environment area for configuration parameters. */
env=getenv("PKTXL");
if (env != NULL)
{
i=0;
while(*(env + i) != 0)
{
if (subcompstr("-KLUDGE", (env + i)) == 0) opt=-1;
if (subcompstr("-NOLF", (env + i)) == 0) nolf=-1;
if (subcompstr("-NOSOFT", (env + i)) == 0) nosoft=-1;
i++;
}
}
if (opt != 0)
printf("Replacing character set kludge\n");
else
printf("Removing character set kludge\n");
if (nolf != 0)
printf("Removing LF\n");
else
printf("Leaving LF:s unchanged\n");
if (nosoft != 0)
printf("Removing SoftCR\n");
else
printf("Leaving SoftCR:s unchanged\n");
n=strlen(inmail);
while(n > 0 && *(indir + n) != '\\') n--;
if (n != 0) *(indir + n + 1)=0;
else *indir=0;
/* if (*(inmail+n-1) != '\\')
{
*(inmail+n)='\\';
*(inmail+n+1)=0;
} */
strcpy(outmail, args[2]);
n=strlen(outmail);
if (*(outmail+n-1)!='\\')
{
*(outmail+n)='\\';
*(outmail+n+1)=0;
}
fromcharset=atoi(args[3]);
tocharset=atoi(args[4]);
if (fromcharset < 0 || fromcharset > 10)
{
printf("Illegal from character set.\n");
exit(9);
}
if (tocharset < -1 || tocharset > 10)
{
printf("Illegal to character set.\n");
exit(9);
}
printf("Translation from character set %d to character set %d\n",
fromcharset, tocharset);
printf("Input files in : %s\n", indir);
printf("Output files in : %s\n", outmail);
/* Ladda texter. */
#ifdef MSDOS
sortarea=halloc(65535L, sizeof(char));
#else
sortarea=calloc(65535L, sizeof(char));
#endif
strcpy(tmp, inmail);
n=dirlist(tmp, sortarea);
printf("Files = %d\n", n);
for(j=0;j<n;j++)
{
i=0;
z=0;
strcpy(tmp, (sortarea + j*45));
/* printf("File(%d)=\"%s\"\n", j, tmp); */
while(*(tmp + i) > ' ')
{
/* Om det är ett bibliotek. */
if (*tmp == ' ') z=1;
i++;
}
*(tmp+i)=0;
sprintf(tmp1, "%s%s", indir, tmp);
sprintf(tmp2, "%s%s", outmail, tmp);
if (strlen(tmp) > 0 && z == 0)
{
printf("Converts from file \"%s\" to file \"%s\"\n",
tmp1, tmp2);
xlatefile(tmp1, tmp2, fromcharset, tocharset);
}
}
#ifdef MSDOS
hfree(sortarea);
#else
free(sortarea);
#endif
time(&tid2);
printf("Execution time %ld seconds\n", tid2-tid1);
return(0);
}
/* Compare the first part of 'string' with 'compval' */
int subcompstr(compval, string)
char *compval, *string;
{
int i;
if (strlen(compval) > strlen(string)) return(-1);
i=0;
while( *(compval + i) == *(string + i) && *(compval + i) != 0) i++;
if (*(compval + i) == 0) return(0);
return(1);
}
/* Convert lower case to upper case. */
void upper(outbuff, inbuff)
char *outbuff, *inbuff;
{
char upcase[256], lowcase[256];
int i;
strcpy(upcase, UPPERCASE);
strcpy(lowcase, LOWERCASE);
while(*inbuff != 0)
{
i=0;
while(*(lowcase + i) != *inbuff && *(lowcase + i) !=0) i++;
if (*(lowcase + i) !=0) *outbuff=*(upcase + i);
else *outbuff=*inbuff;
outbuff++;
inbuff++;
}
*outbuff=0;
}
/* Convert DOS time to ISO text format. (YYYY-MM-DD HH:MM:SS) */
void dtidkonv(tid, dat, uttid)
unsigned int tid, dat;
char *uttid;
{
unsigned int yr, mon, day, hr, min, sec, tdat, ttid;
tdat=dat;
ttid=tid;
yr=tdat/512;
tdat=tdat-yr*512;
mon=tdat/32;
day=tdat-mon*32;
hr=ttid/2048;
ttid=ttid-hr*2048;
min=ttid/32;
sec=(ttid-min*32)*2;
sprintf(uttid, "%4d-%02d-%02d %02d:%02d:%02d",
yr+1980, mon, day, hr, min, sec);
}
#ifndef OS2
/* Lägg till strängen srcs till strängen apps samt returnera det nya
strängslutet */
char *appst(register char *apps, register char *srcs)
{
while( *srcs != 0)
{
*(apps++) = *(srcs++);
}
return( apps);
}
int direntry(dta, name, times)
struct FILEINFO *dta;
char *name;
int times;
{
union REGS r;
r.x.dx = FP_OFF(dta);
r.h.ah = 0x1a;
intdos (&r, &r);
r.x.bx = 0;
r.x.cx = ~0x08;
r.x.dx = FP_OFF(name);
r.x.si = 0;
r.x.di = 0;
if (times == 0)
{
r.h.ah = 0x4e;
intdos (&r, &r);
dta->nill = '\0';
if (r.x.cflag != 0)
{
dta->name[0] = '\0';
return (1);
}
return (0);
}
else
{
r.h.ah = 0x4f;
intdos (&r, &r);
dta->nill = '\0';
if (r.x.cflag != 0)
{
dta->name[0] = '\0';
return (1);
}
return (0);
}
}
int sort_function(const void * a, const void * b)
{
return(strcmp(a, b));
}
int dirlist(namn, sortarea)
char *namn, *sortarea;
{
struct FILEINFO dta[1];
char slask[30], tmp[30];
int z, i, j, n;
i=0;
j=0;
z=direntry(dta, namn, i);
if (z != 0) printf("No directory.\n");
strcpy(sortarea, "");
while (z == 0)
{
if (strcmp(dta->name, ".") != 0 &&
strcmp(dta->name, "..") != 0 &&
('É' != *dta->name ||
(dta->attr & 16) == 0))
{
dtidkonv(dta->time, dta->date, slask);
strcpy(tmp, dta->name);
n=0;
while(*(tmp+n) != 0) n++;
while(n<13)
{
*(tmp+n)=' ';
n++;
*(tmp+n)=0;
}
if ((dta->attr & 16) != 0)
sprintf((sortarea + j*45), " Filarea %s", tmp);
else
sprintf((sortarea + j*45),"%s%9ld %s",
tmp, dta->size, slask);
j++;
strcpy((sortarea + j*45), "");
}
i++;
z=direntry(dta, namn, i);
}
#ifdef __TURBOC__
qsort(sortarea, j, 45, sort_function);
#else
qsort(sortarea, j, 45, strcmp);
#endif
return(j);
}
#else
int dirlist(namn, sortarea)
char *namn, *sortarea;
{
char path[80];
unsigned count=1;
int rc, j;
struct _FILEFINDBUF buff;
unsigned short handle=0xffff;
rc=DosFindFirst(namn, &handle, 0x0000, &buff,
sizeof(buff), &count, 0L);
if (rc)
{
if (rc == 18)
{
DosFindClose(handle);
return(0);
}
printf("Error in the directory handling.\n");
exit(9);
}
j=0;
if ((buff.attrFile & 0x0010) != 0)
{
sprintf(sortarea, " Filarea %s", buff.achName);
}
else
{
sprintf(sortarea,"%s%9ld %02d-%02d-%02d %02d:%02d",
buff.achName, buff.cbFile,
buff.fdateLastWrite.year,
buff.fdateLastWrite.month,
buff.fdateLastWrite.day,
buff.ftimeLastWrite.hours,
buff.ftimeLastWrite.minutes);
}
/* printf("%s\n", sortarea); */
j++;
while(TRUE)
{
rc=DosFindNext(handle, &buff, sizeof(buff), &count);
if (rc)
{
if (rc == 18)
{
DosFindClose(handle);
qsort(sortarea, j, 45, strcmp);
return(j);
}
perror("Fel i hanteringen.\n");
exit(9);
}
if ((buff.attrFile & 0x0010) != 0)
{
sprintf((sortarea + j*45), " Filarea %s",
buff.achName);
}
else
{
sprintf((sortarea + j*45),
"%s%9ld %02d-%02d-%02d %02d:%02d",
buff.achName, buff.cbFile,
buff.fdateLastWrite.year,
buff.fdateLastWrite.month,
buff.fdateLastWrite.day,
buff.ftimeLastWrite.hours,
buff.ftimeLastWrite.minutes);
}
/* printf("%s\n", (sortarea+j*45)); */
j++;
}
}
#endif
unsigned char transchar(c, from, to)
unsigned char c;
int from, to;
{
int i;
unsigned char cx;
i=0;
while (*(teckenset[from] + i) != c && *(teckenset[from] + i) != 0) i++;
/* If translating to the "umlaut" multi-byte format. */
if (to < 0)
{
if (*(teckenset[from] + i) == c &&
*(teckenset[from] + i) != ' ')
return((unsigned char)(i+1));
return(0);
}
if (*(teckenset[from] + i) == c && *(teckenset[from] + i) != ' ')
return(*(teckenset[to] + i));
cx=c;
return(cx);
}
void addkludge(g1, tocharset)
FILE *g1;
int tocharset;
{
fputc(1, g1);
switch (tocharset)
{
case -1 : fputs("CHARSET: UMLAUT", g1);
break;
case 0 : fputs("CHRS: SWEDISH 1", g1);
break;
case 1 : fputs("CHRS: IBMPC 2", g1);
break;
case 2 : fputs("CHRS: LATIN-1 2", g1);
break;
case 3 : fputs("CHRS: MAC 2", g1);
break;
case 4 : fputs("CHRS: FRENCH 1", g1);
break;
case 5 : fputs("CHRS: GERMAN 1", g1);
break;
case 6 : fputs("CHRS: UK 1", g1);
break;
case 7 : fputs("CHARSET: NORWEG 1", g1);
break;
case 8 : fputs("CHRS: ITALIAN 1", g1);
break;
case 9 : fputs("CHRS: SPANISH 1", g1);
break;
case 10 : fputs("CHARSET: JAPANESE", g1);
break;
}
fputc(13, g1);
}
int identify(id)
char *id;
{
char ident[80];
int fromcharset;
/* This routine checks the identifier even it it was lower case. */
upper(ident, id);
if (subcompstr("ISO-11", ident) == 0)
fromcharset=0;
if (subcompstr("SWEDISH", ident) == 0)
fromcharset=0;
if (subcompstr("FINNISH", ident) == 0)
fromcharset=0;
if (subcompstr("CP437", ident) == 0)
fromcharset=1;
if (subcompstr("IBM", ident) == 0)
fromcharset=1;
if (subcompstr("PC-8", ident) == 0)
fromcharset=1;
if (subcompstr("ISO 8859-1", ident) == 0)
fromcharset=2;
if (subcompstr("ISO8859-1", ident) == 0)
fromcharset=2;
if (subcompstr("ISO LATIN-1", ident) == 0)
fromcharset=2;
if (subcompstr("LATIN-1", ident) == 0)
fromcharset=2;
if (subcompstr("ISO-6", ident) == 0)
fromcharset=2;
if (subcompstr("AMIGA", ident) == 0)
fromcharset=2;
if (subcompstr("I51", ident) == 0)
fromcharset=2;
if (subcompstr("MAC", ident) == 0)
fromcharset=3;
if (subcompstr("FRENCH", ident) == 0)
fromcharset=4;
if (subcompstr("ISO-69", ident) == 0)
fromcharset=4;
if (subcompstr("GERMAN", ident) == 0)
fromcharset=5;
if (subcompstr("ISO-21", ident) == 0)
fromcharset=5;
if (subcompstr("BRITISH", ident) == 0)
fromcharset=6;
if (subcompstr("UK", ident) == 0)
fromcharset=6;
if (subcompstr("ISO-60", ident) == 0)
fromcharset=7;
if (subcompstr("DANISH", ident) == 0)
fromcharset=7;
if (subcompstr("NORWEG", ident) == 0)
fromcharset=7;
if (subcompstr("ITALIAN", ident) == 0)
fromcharset=8;
if (subcompstr("SPANISH", ident) == 0)
fromcharset=9;
if (subcompstr("JAPAN", ident) == 0)
fromcharset=10;
return(fromcharset);
}
int xlatetexts(f, g1, fromcharset, tocharset)
FILE *f, *g1;
int fromcharset, tocharset;
{
int c, n, c1, i, i0, j, k, characters, noout;
unsigned char *textarea, ident[80], output[160];
/* Check if the file is a type-2 file. */
if (packmsg.idcode != 0x0002)
{
printf("Idcode : %d\n", packmsg.idcode);
printf("Illegal packet type\n");
return(1);
}
#ifdef MSDOS
textarea=halloc(65535L, sizeof(char));
#else
textarea=calloc(65535L, sizeof(char));
#endif
fwrite((char *) &packmsg, sizeof(packmsg), 1, g1);
/* The header field is not translated. */
/* Date. */
while((c=fgetc(f)) > 0) fputc(c, g1);
fputc(0, g1);
/* To user: */
while((c=fgetc(f)) > 0) fputc(c, g1);
fputc(0, g1);
/* From user: */
while((c=fgetc(f)) > 0) fputc(c, g1);
fputc(0, g1);
/* Subject:
This line is only translated to an equally sized format.
*/
while((c=fgetc(f)) > 0)
{
c1=c;
if (fromcharset >= 0 && tocharset >= 0)
c1=(int)transchar((unsigned char) c,
fromcharset, tocharset);
fputc(c1, g1);
}
fputc(0, g1);
/* Start with reading in the text as is in a buffer. */
n=0;
i=0;
while((c=fgetc(f)) != 0)
{
*(textarea + i++)=(unsigned char)c;
}
*(textarea+i)=0;
characters=i+1;
i=0;
k=1;
i0=0;
if (subcompstr("AREA:", textarea) == 0)
{
k=0;
/* printf("Area: found!\n"); */
}
while(i < characters)
{
noout=0;
c=*(textarea + i);
/* if (k < 2)
{
printf("%c", c);
if (c == 13) printf("\n");
}
*/
if (k == 1 && c != 10 &&
tocharset >= -1 && tocharset <= 10 &&
fromcharset >= 0 && fromcharset <= 10)
{
if (opt != 0)
{
addkludge(g1, tocharset);
fputc(1, g1);
fputs("XL: ", g1);
fputs(VERSION, g1);
fputc(13, g1);
}
/* printf("*Kludges*\n"); */
k=2;
}
/* Kludges översätts inte. */
if (c == 1)
{
n=1;
/* Check both the CHARSET and the CHRS kludge. Since
they can contain almost the same information, they may be
handled with the same identification function.
*/
/* Check the CHARSET kludge. */
if (subcompstr("CHARSET", (textarea + i + 1)) == 0)
{
i=i+8;
j=0;
while(*(textarea + i) == ':' ||
*(textarea + i) == ' ')
{
i++;
}
while(*(textarea + i) != 13 &&
*(textarea + i) != 0)
{
*(ident + j)=*(textarea + i);
i++;
j++;
}
*(ident + j)=0;
printf("Old CHARSET: %s\n", ident);
j=identify(ident);
if (j>-10) fromcharset=j;
n=0;
i++;
c=*(textarea + i);
if (c == 10)
{
i++;
c=*(textarea + i);
}
i--;
noout=-1;
}
/* Check the CHRS kludge. */
if (subcompstr("CHRS", (textarea + i + 1)) == 0)
{
i=i+5;
j=0;
while(*(textarea + i) == ':' ||
*(textarea + i) == ' ')
{
i++;
}
while(*(textarea + i) != 13 &&
*(textarea + i) != 0)
{
*(ident + j)=*(textarea + i);
i++;
j++;
}
*(ident + j)=0;
printf("Old CHRS: %s\n", ident);
j=identify(ident);
if (j>-10) fromcharset=j;
n=0;
i++;
c=*(textarea + i);
if (c == 10)
{
i++;
c=*(textarea + i);
}
i--;
noout=-1;
}
/* Check the I51 kludge. */
if (subcompstr("I51", (textarea + i + 1)) == 0 &&
fromcharset >= 0)
{
i=i+4;
fromcharset=2;
c=*(textarea + i);
if (c == 13)
{
i++;
c=*(textarea + i);
}
if (c == 10)
{
i++;
c=*(textarea + i);
}
i--;
noout=-1;
}
}
/* Återställning till översättning vid HARD CR. */
if (c == 13)
{
n=0;
j=0;
if (k == 0) k=1;
}
c1=c;
/* If translation was allowed, we are translating the text now. */
if (n == 0) c=(int)transchar((unsigned char)c,
fromcharset, tocharset);
/* If we are translating byte by byte to a non-"umlaut" format
we only write the character returned by the translation routine.
Otherwise the character is an index to the umlaut table.
*/
if (noout == 0 && (c1 != 10 || nolf == 0) &&
(c1 != 0x8d || nosoft == 0))
{
if (tocharset >= 0 || n != 0)
{
output[i0]=(unsigned char)c;
i0++;
/* fputc(c, g1); */
}
else
{
if (c == 0)
{
output[i0]=(unsigned char)c1;
i0++;
/* fputc(c1, g1); */
}
else
{
strcat((output + i0), umlaut[c-1]);
i0=i0+strlen(umlaut[c-1]);
/* fputs(umlaut[c-1], g1); */
}
}
if (i0 > 120 || c == 13)
{
fwrite(output, sizeof(char), i0, g1);
i0=0;
}
}
i++;
}
if (i0 > 0) fwrite(output, sizeof(char), i0, g1);
#ifdef MSDOS
hfree(textarea);
#else
free(textarea);
#endif
return(0);
}
void xlatefile(filnamn1, filnamn2, fromcharset, tocharset)
char *filnamn1, *filnamn2;
int fromcharset, tocharset;
{
FILE *f, *g1;
char tmp[80];
int z;
#ifdef MSDOS
if ((g1=fopen(filnamn2, "wb")) == NULL)
#else
if ((g1=fopen(filnamn2, "w")) == NULL)
#endif
{
sprintf(tmp, "Can't open file %s for writing", filnamn2);
perror(tmp);
return;
}
#ifdef MSDOS
if ((f=fopen(filnamn1, "rb")) == NULL)
#else
if ((f=fopen(filnamn1, "r")) == NULL)
#endif
{
sprintf(tmp, "Can't open file %s for reading", filnamn1);
perror(tmp);
fclose(g1);
return;
}
fseek(f, 0L, SEEK_SET);
if (fread((char *) &packhd, sizeof(packheader), 1, f) != 0)
{
printf("PKT-file created at node : %d/%d\n",
packhd.orignet, packhd.orignode);
if (packhd.idcode != 0x0002)
{
printf("Unknown packet type\n");
fclose(f);
fclose(g1);
return;
}
fwrite((char *) &packhd, sizeof(packheader), 1, g1);
z=0;
while(fread((char *) &packmsg, sizeof(packmsg), 1, f) != 0
&& z==0)
{
z=xlatetexts(f, g1, fromcharset, tocharset);
}
/* Terminate file with extra 0x00:s */
fputc(0, g1);
fputc(0, g1);
fputc(0, g1);
}
fclose(f);
fclose(g1);
}