1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/* Copyright 1992 NEC Corporation, Tokyo, Japan.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of NEC
* Corporation not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. NEC Corporation makes no representations about the
* suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* NEC CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL NEC CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef lint
static char rcsid[]="@(#) 112.1 $Id: forcpp.c,v 1.2 2003/02/01 19:34:21 aida_s Exp $";
#endif
/*
* forcpp.c /lib/cpp ̤8ӥåȥɤݸ
* forcpp -7 < [in-file-name] > [out-file-name]
* -7
* -8
*/
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#if defined(__STDC__) || defined(SVR4)
#include <locale.h>
#endif
#include "ccompat.h"
#ifdef SVR4
extern char *gettxt();
#else
#define gettxt(x,y) (y)
#endif
char *hd = "0123456789abcdef";
/* #define ESC '@'*/
#define ESC 033
int
e2j()
{
unsigned c;
int kin = 0;
while ( (c = getchar()) != EOF ) {
if ( c & 0x80 ) {
if ( !kin ) {
putchar(ESC);
kin = 1;
};
putchar(hd[c>>4]);
putchar(hd[c&15]);
}
else {
if ( kin ) {
putchar(ESC);
kin = 0;
};
putchar(c);
};
};
}
int
j2e()
{
unsigned c;
int kin = 0;
while ( (c = getchar()) != EOF ) {
if ( c == ESC ) {
kin = 1 - kin;
}
else {
if ( kin ) {
char s[3];
s[0] = c;
s[1] = getchar();
s[2] = 0;
sscanf(s, "%x", &c);
}
putchar(c);
};
};
}
void catch(sig)
int sig;
{
fprintf(stderr, gettxt("cannacmd:18", "Dictionary format error.\n"));
exit(1);
}
int
main(n, args)
int n;
char *args[];
{
(void)signal(SIGSEGV, catch);
#ifdef SIGBUS
(void)signal(SIGBUS, catch);
#endif
#if defined(__STDC__) || defined(SVR4)
(void)setlocale(LC_ALL,"");
#endif
#ifdef __EMX__
_fsetmode(stdout, "b");
#endif
if( n == 1 ) { /* ޥ̾λ */
fprintf(stderr, gettxt("cannacmd:19", "Usage: forcpp -7 < [file],\n forcpp -8 < [file]\n"));
exit( -1 );
}
if( !strcmp(args[1], "-7"))
e2j();
else if( !strcmp(args[1], "-8"))
j2e();
else
fprintf(stderr, gettxt("cannacmd:20", "Usage: forcpp -7 < [file],\n forcpp -8 < [file]\n"));
exit(0);
}
|