?? expfix.c
字號:
/*
-- Copyright 1994, Oracle Taiwan Inc., All Rights Reserved.
--
-- Program to modify the language id in Oracle7 export file.
--
-- Version 1.01.04, Mar 20, 1994, James Ko, Oracle Taiwan.
-- Add ZHS16CGB231280 (id 850) for China.
--
-- Version 1.01.03, Feb 09, 1994, James Ko, Oracle Taiwan.
-- Change langinfo struct to static for declaration.
-- Bypass compiler complains on this.
--
-- Version 1.01.02, Dec 29, 1994, James Ko, Oracle Taiwan.
-- Change print out of charset symbol in the loop.
--
-- Version 1.01.01, Dec 29, 1994, James Ko, Oracle Taiwan.
-- Add ASCII lang_id and character set into lang_info
-- to support the reverse of export file from BIG5 to
-- ASCII.
--
-- Version 1.00.01, Nov 04, 1994, Richard Lin, Oracle Taiwan.
-- Tested OK on real export file.
--
-- Version 0.01, Beta, Nov 03, 1994. James Ko, Oracle Taiwan.
--
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define BUF_SIZE 1024
#define LNAME_SIZE 32
main( argc, argv )
char *argv[];
int argc;
{
FILE *inf, *outf;
long fsize;
int size;
int langid;
int loop, last, count;
int iosize = BUF_SIZE;
int buf_size = BUF_SIZE;
char buf[BUF_SIZE];
char langname[LNAME_SIZE];
char ofname[256];
struct langdef {
int id;
char *name;
char *ext;
} *langptr;
static struct langdef langinfo[] = {
1, "US7ASCII", ".ascii",
850, "ZHS16CGB231280", ".cgb",
860, "ZHT32EUC", ".euc",
861, "ZHT32SOPS", ".sops",
862, "ZHT16DBT", ".dbt",
863, "ZHT32TRIS", ".tris",
865, "ZHT16BIG5", ".big5"
};
printf("\n\nOracle7 Export File Charset Fix Utility, V1.01.04\n");
loop = sizeof(langinfo) / sizeof(struct langdef);
if ( argc < 2 ) {
printf("\nUsage: %s dump_file_name language_id\n\n", argv[0]);
printf("Valid language id - ");
for ( count = 0, langptr = &langinfo[0];
count < loop; count++, langptr++ ) {
printf("%s ", langptr->name);
}
printf("\n\n");
exit(1);
}
/*
-- Map langguage_name to id and append ext to output file name
*/
strcpy(ofname, argv[1]);
strncpy(langname, argv[2], LNAME_SIZE);
for ( count = 0; count < strlen(langname); count++ ) {
langname[count] = (char) toupper(langname[count]);
}
for ( count = 0, langptr = &langinfo[0];
count < loop; count++, langptr++ ) {
if ( strcmp(langptr->name, langname) == 0 ) {
langid = langptr->id;
strcat(ofname, langptr->ext);
break;
}
}
if ( count == loop ) {
printf("\n\nInvalid language ID, program terminated\n");
exit(3);
}
printf("\n\nOutput file name %s,", ofname);
/*
-- Open files
*/
if ( (inf = fopen (argv[1], "r")) == NULL ) {
printf("\n\nOpen file %s error, program terminated\n", argv[1]);
exit(1);
}
if ( (outf = fopen (ofname, "w+")) == NULL ) {
printf("\n\nOpen file %s error, program terminated\n", ofname);
exit(1);
}
/*
-- Get input file size and rewind it
*/
fseek(inf, 0L, 2);
fsize = ftell(inf);
printf(" size is %d bytes.\n\n", fsize);
rewind(inf);
loop = fsize / buf_size;
last = fsize % buf_size;
for ( count = 0; count < loop; count++ ) {
if ( (size = fread (buf, 1, iosize, inf)) == iosize ) {
/*
-- Update the language id, it is at the 2nd and 3rd byte
*/
if ( count == 0 ) {
buf[1] = langid / 256;
buf[2] = langid % 256;
}
if ( (size = fwrite (buf, 1, iosize, outf)) != iosize ) {
printf("\n\nFile write error, program terminated!\n");
printf("Expected size %d, real size %d\n", iosize, size);
exit(2);
}
} else {
printf("\n\nFile read error, program terminated!\n");
printf("Expected size %d, real size %d\n", iosize, size);
exit(1);
}
}
if ( (iosize = last) != 0 ) {
if ( (size = fread (buf, 1, iosize, inf)) != iosize ) {
printf("\n\nFile read error, program terminated!\n");
printf("Expected size %d, real size %d\n", iosize, size);
exit(1);
}
if ( (size = fwrite (buf, 1, iosize, outf)) != iosize ) {
printf("\n\nFile write error, program terminated!\n");
printf("Expected size %d, real size %d\n", iosize, size);
exit(2);
}
}
fclose(inf);
fclose(outf);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -