source: projects/specs/trunk/f/file/file-5.05-jtext.patch @ 2730

Revision 2730, 9.7 KB checked in by Takemikaduchi, 13 years ago (diff)

rebuild package

  • file-5.05/src/Makefile.am

    old new  
    44 
    55bin_PROGRAMS = file 
    66 
    7 AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"' 
     7AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"' -DDETECT_JAPANESE 
    88AM_CFLAGS = @WARNINGS@ 
    99 
    1010libmagic_la_SOURCES = magic.c apprentice.c softmagic.c ascmagic.c \ 
    11         encoding.c compress.c is_tar.c readelf.c print.c fsmagic.c \ 
     11        encoding.c compress.c is_tar.c readelf.c print.c jcode.c fsmagic.c \ 
    1212        funcs.c file.h names.h patchlevel.h readelf.h tar.h apptype.c \ 
    1313        file_opts.h elfclass.h mygetopt.h cdf.c cdf_time.c readcdf.c cdf.h 
    1414libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0 
  • file-5.05/src/encoding.c

    old new FILE_RCSID("@(#)$File: encoding.c,v 1.5  
    4242#include <string.h> 
    4343#include <memory.h> 
    4444#include <stdlib.h> 
    45  
     45#include "jcode.h" 
    4646 
    4747private int looks_ascii(const unsigned char *, size_t, unichar *, size_t *); 
    4848private int looks_utf8_with_BOM(const unsigned char *, size_t, unichar *, 
    protected int 
    6868file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, unichar **ubuf, size_t *ulen, const char **code, const char **code_mime, const char **type) 
    6969{ 
    7070        size_t mlen; 
    71         int rv = 1, ucs_type; 
     71        int rv = 1, ucs_type, jcode; 
    7272        unsigned char *nbuf = NULL; 
    7373 
    7474        mlen = (nbytes + 1) * sizeof(nbuf[0]); 
    file_encoding(struct magic_set *ms, cons 
    8383        } 
    8484 
    8585        *type = "text"; 
    86         if (looks_ascii(buf, nbytes, *ubuf, ulen)) { 
     86        jcode = detect_kcode(buf, nbytes, *ubuf, ulen); 
     87        if (jcode == ASCII) { 
    8788                DPRINTF(("ascii %" SIZE_T_FORMAT "u\n", *ulen)); 
    8889                *code = "ASCII"; 
    8990                *code_mime = "us-ascii"; 
     91        } else if (jcode == JIS) { 
     92                DPRINTF(("jis %" SIZE_T_FORMAT "u\n", *ulen)); 
     93                *code = "7-bit JIS [ESC$B, ESC(B]"; 
     94                *code_mime = "jis"; 
     95        } else if (jcode == SJIS){ 
     96                DPRINTF(("sjis %" SIZE_T_FORMAT "u\n", *ulen)); 
     97                *code = "SJIS"; 
     98                *code_mime = "sjis"; 
     99        } else if (jcode == EUC){ 
     100                DPRINTF(("euc %" SIZE_T_FORMAT "u\n", *ulen)); 
     101                *code = "EUC"; 
     102                *code_mime = "euc-jp"; 
     103        } else if (jcode == EUCORSJIS){ 
     104                DPRINTF(("euc or sjis %" SIZE_T_FORMAT "u\n", *ulen)); 
     105                *code = "EUC or SJIS"; 
     106                *code_mime = "unknown"; 
    90107        } else if (looks_utf8_with_BOM(buf, nbytes, *ubuf, ulen) > 0) { 
    91108                DPRINTF(("utf8/bom %" SIZE_T_FORMAT "u\n", *ulen)); 
    92109                *code = "UTF-8 Unicode (with BOM)"; 
  • new file file-5.05/src/jcode.c

    - +  
     1/* 
     2jcode.c: Kanji-code detect routing by Jun Nishii <jun@vinelinux.org> 
     3                          modified by Ryoichi INAGAKI <inagaki@vinelinux.org> 
     4 */ 
     5#include <stdio.h> 
     6#include <unistd.h> 
     7#include <signal.h> 
     8#include <sys/types.h> 
     9#include <sys/wait.h> 
     10#include <jcode.h> 
     11 
     12typedef unsigned long unichar; 
     13 
     14#define F 0   /* character never appears in text */ 
     15#define T 1   /* character appears in plain ASCII text */ 
     16#define I 2   /* character appears in ISO-8859 text */ 
     17#define X 3   /* character appears in non-ISO extended ASCII (Mac, IBM PC) */ 
     18#define J 4   /* character appears in JIS or plain ASCII */ 
     19#define S 5   /* character appears in SJIS */ 
     20#define E 6   /* character appears in EUC */ 
     21#define O 7   /* character appears in EUC or SJIS */ 
     22 
     23#define ESC           27 
     24 
     25static char jp_chars1[256] = { 
     26        F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F,  /* 0x0X */ 
     27        F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F,  /* 0x1X */ 
     28        T, J, J, J, J, J, J, J, J, J, J, J, J, J, J, J,  /* 0x2X */ 
     29        J, J, J, J, J, J, J, J, J, J, J, J, J, J, J, J,  /* 0x3X */ 
     30        J, J, J, J, J, J, J, J, J, J, J, J, J, J, J, J,  /* 0x4X */ 
     31        J, J, J, J, J, J, J, J, J, J, J, J, J, J, J, J,  /* 0x5X */ 
     32        J, J, J, J, J, J, J, J, J, J, J, J, J, J, J, J,  /* 0x6X */ 
     33        J, J, J, J, J, J, J, J, J, J, J, J, J, J, J, F,  /* 0x7X */ 
     34        /*            NEL                            */ 
     35        X, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,  /* 0x8X */ 
     36        S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,  /* 0x9X */ 
     37        I, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E,  /* 0xaX */ 
     38        E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E,  /* 0xbX */ 
     39        E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E,  /* 0xcX */ 
     40        E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, E,  /* 0xdX */ 
     41        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,  /* 0xeX */ 
     42        E, E, E, E, E, E, E, E, E, E, E, E, E, E, E, I   /* 0xfX */ 
     43}; 
     44 
     45static char jp_chars2[256] = { 
     46        /*                  BEL BS HT LF    FF CR    */ 
     47        F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F,  /* 0x0X */ 
     48        /*                              ESC          */ 
     49        F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F,  /* 0x1X */ 
     50        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x2X */ 
     51        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x3X */ 
     52        S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,  /* 0x4X */ 
     53        S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,  /* 0x5X */ 
     54        S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,  /* 0x6X */ 
     55        S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, F,  /* 0x7X */ 
     56        /*            NEL                            */ 
     57        S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,  /* 0x8X */ 
     58        S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,  /* 0x9X */ 
     59        S, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,  /* 0xaX */ 
     60        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,  /* 0xbX */ 
     61        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,  /* 0xcX */ 
     62        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,  /* 0xdX */ 
     63        O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,  /* 0xeX */ 
     64        O, O, O, O, O, O, O, O, O, O, O, O, O, E, E, I   /* 0xfX */ 
     65}; 
     66 
     67 
     68int 
     69check_asc_jis(buf, nbytes, ubuf, ulen) 
     70        const unsigned char *buf; 
     71        size_t nbytes; 
     72        unichar *ubuf; 
     73        size_t *ulen; 
     74{ 
     75        size_t i; 
     76        int jflag; 
     77 
     78        *ulen = 0; jflag=0; 
     79 
     80        for (i = 0; i < nbytes; i++) { 
     81                int t = jp_chars1[buf[i]]; 
     82 
     83                if (t != T && t != J ) 
     84                        return 0; 
     85 
     86                if (buf[i] == ESC && i+2<nbytes) { 
     87                  if ((buf[i+1]=='$' && buf[i+2]=='B')|| 
     88                      (buf[i+1]=='$' && buf[i+2]=='@')) jflag=1; 
     89                } 
     90 
     91                ubuf[(*ulen)++] = buf[i]; 
     92        } 
     93 
     94        if (jflag==1) return JIS; 
     95        else return ASCII; 
     96} 
     97 
     98int 
     99check_sjis(buf, nbytes, ubuf, ulen) 
     100        const unsigned char *buf; 
     101        size_t nbytes; 
     102        unichar *ubuf; 
     103        size_t *ulen; 
     104{ 
     105        size_t i; 
     106        int jflag; 
     107 
     108        *ulen = 0; 
     109        jflag = ASCII; 
     110        for (i = 0; i < nbytes; i++) { 
     111                int t = jp_chars1[buf[i]]; 
     112 
     113                if (t != T && t != J && t != S && t!= O) 
     114                        return 0; 
     115 
     116                if (t == S && i<nbytes-1){ 
     117                  ubuf[(*ulen)++] = buf[i]; 
     118                  ++i; 
     119                  t=jp_chars2[buf[i]]; 
     120                  if(t != S && t != O ) return 0; 
     121                  jflag=SJIS; 
     122                } else if (t == O && i<nbytes-1){ 
     123                  ubuf[(*ulen)++] = buf[i]; 
     124                  ++i; 
     125                  t=jp_chars2[buf[i]]; 
     126                  if( t == S ){ jflag=SJIS; } 
     127                  else if( t == O ){ if(jflag==ASCII) jflag=EUCORSJIS; } 
     128                  else return 0; 
     129                } 
     130 
     131                ubuf[(*ulen)++] = buf[i]; 
     132        } 
     133#ifdef Z 
     134        if (jflag==SJIS) {ckfputs("SJIS text", stdout); return SJIS;} 
     135        if (jflag==EUCORSJIS) {ckfputs("EUCorSJIS", stdout); return EUCORSJIS;} 
     136#else 
     137        if (jflag==SJIS) {return SJIS;} 
     138        if (jflag==EUCORSJIS) {return EUCORSJIS;} 
     139#endif 
     140} 
     141 
     142int 
     143check_euc(buf, nbytes, ubuf, ulen) 
     144        const unsigned char *buf; 
     145        size_t nbytes; 
     146        unichar *ubuf; 
     147        size_t *ulen; 
     148{ 
     149        size_t i; 
     150        int jflag; 
     151 
     152        *ulen = 0; 
     153        jflag = ASCII; 
     154 
     155        for (i = 0; i < nbytes; i++) { 
     156                int t = jp_chars1[buf[i]]; 
     157 
     158                if (t != T && t != J && t != E && t!= O) 
     159                        return 0; 
     160 
     161                if (t == E && i<nbytes-1){ 
     162                  ubuf[(*ulen)++] = buf[i]; 
     163                  ++i; 
     164                  t= jp_chars2[buf[i]]; 
     165                  if( t != E && t != O) return 0; 
     166                  jflag=EUC; 
     167                } else if (t == O && i<nbytes-1){ 
     168                  ubuf[(*ulen)++] = buf[i]; 
     169                  ++i; 
     170                  t=jp_chars2[buf[i]]; 
     171                  if( t == E ){ jflag=EUC; } 
     172                  else if( t == O ){ if(jflag==ASCII) jflag=EUCORSJIS; } 
     173                  else return 0; 
     174                } 
     175 
     176                ubuf[(*ulen)++] = buf[i]; 
     177        } 
     178#ifdef Z 
     179        if (jflag==EUC) {ckfputs("EUC text", stdout); return EUC;} 
     180        if (jflag==EUCORSJIS) {ckfputs("EUCorSJIS", stdout); return EUCORSJIS;} 
     181#else 
     182        if (jflag==EUC) { return EUC;} 
     183        if (jflag==EUCORSJIS) {return EUCORSJIS;} 
     184#endif 
     185} 
     186 
     187int 
     188detect_kcode(buf, nbytes, ubuf, ulen) 
     189        const unsigned char *buf; 
     190        size_t nbytes; 
     191        unichar *ubuf; 
     192        size_t *ulen; 
     193{ 
     194  int ret; 
     195  ret=check_asc_jis(buf, nbytes, ubuf, ulen); 
     196  if(ret==ASCII) return ASCII; 
     197  if(ret==JIS) return JIS; 
     198 
     199  ret=check_sjis(buf, nbytes, ubuf, ulen); 
     200  if(ret==SJIS) return SJIS; 
     201  if(ret==EUCORSJIS) return EUCORSJIS; 
     202  ret=check_euc(buf, nbytes, ubuf, ulen); 
     203  if(ret==EUC) return EUC; 
     204  if(ret==EUCORSJIS) return EUCORSJIS; 
     205} 
  • new file file-5.05/src/jcode.h

    - +  
     1/* 
     2 jcode.h - for jcode.c by Jun Nishii <jun@vinelinux.org> 
     3              modified by Ryoichi INAGAKI <inagaki@vinelinux.org> 
     4 */ 
     5 
     6#define ASCII         1 
     7#define JIS           2 
     8#define EUC           3 
     9#define SJIS          4 
     10#define EUCORSJIS     5 
     11 
     12extern int detect_kcode (const unsigned char *, size_t, unichar *, size_t *); 
     13extern int looks_jis (const unsigned char *, size_t, unichar *, size_t *); 
     14extern int looks_sjis (const unsigned char *, size_t, unichar *, size_t *); 
     15extern int looks_euc (const unsigned char *, size_t, unichar *, size_t *); 
  • file-5.05/src/names.h

    old new  
    135135        {"/*",          L_C, 2 },       /* must precede "The", "the", etc. */ 
    136136        {"#include",    L_C, 2 }, 
    137137        {"char",        L_C, 2 }, 
    138         {"The",         L_ENG, 2 }, 
    139         {"the",         L_ENG, 2 }, 
    140138        {"double",      L_C, 1 }, 
    141139        {"extern",      L_C, 2 }, 
    142140        {"float",       L_C, 1 }, 
Note: See TracBrowser for help on using the repository browser.