[BACK]Return to internat.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / file

Annotation of src/usr.bin/file/internat.c, Revision 1.1

1.1     ! millert     1: /*     $OpenBSD: file.c,v 1.4 1997/01/15 23:42:26 millert Exp $        */
        !             2:
        !             3: #include <string.h>
        !             4: #include <sys/types.h>
        !             5:
        !             6: #include "file.h"
        !             7:
        !             8: #define F 0
        !             9: #define T 1
        !            10:
        !            11: /*
        !            12:  * List of characters that look "reasonable" in international
        !            13:  * language texts.  That's almost all characters :), except a
        !            14:  * few in the control range of ASCII (all the known international
        !            15:  * charactersets share the bottom half with ASCII).
        !            16:  */
        !            17: static char maybe_internat[256] = {
        !            18:        F, F, F, F, F, F, F, F, T, T, T, T, T, T, F, F,  /* 0x0X */
        !            19:        F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F,  /* 0x1X */
        !            20:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x2X */
        !            21:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x3X */
        !            22:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x4X */
        !            23:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x5X */
        !            24:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x6X */
        !            25:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, F,  /* 0x7X */
        !            26:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x8X */
        !            27:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x9X */
        !            28:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0xaX */
        !            29:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0xbX */
        !            30:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0xcX */
        !            31:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0xdX */
        !            32:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0xeX */
        !            33:        T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T   /* 0xfX */
        !            34: };
        !            35:
        !            36: /* Maximal length of a line we consider "reasonable". */
        !            37: #define MAXLINELEN 300
        !            38:
        !            39: int
        !            40: internatmagic(buf, nbytes)
        !            41:        unsigned char *buf;
        !            42:        int nbytes;
        !            43: {
        !            44:        int i;
        !            45:        unsigned char *cp;
        !            46:
        !            47:        nbytes--;
        !            48:
        !            49:        /* First, look whether there are "unreasonable" characters. */
        !            50:        for (i = 0, cp = buf; i < nbytes; i++, cp++)
        !            51:                if (!maybe_internat[*cp])
        !            52:                        return 0;
        !            53:
        !            54:        /*
        !            55:         * Now, look whether the file consists of lines of
        !            56:         * "reasonable" length.
        !            57:         */
        !            58:
        !            59:        for (i = 0; i < nbytes;) {
        !            60:                cp = memchr(buf, '\n', nbytes - i);
        !            61:                if (cp == NULL) {
        !            62:                        /* Don't fail if we hit the end of buffer. */
        !            63:                        if (i + MAXLINELEN >= nbytes)
        !            64:                                break;
        !            65:                        else
        !            66:                                return 0;
        !            67:                }
        !            68:                if (cp - buf > MAXLINELEN)
        !            69:                        return 0;
        !            70:                i += (cp - buf + 1);
        !            71:                buf = cp + 1;
        !            72:        }
        !            73:        ckfputs("International language text", stdout);
        !            74:        return 1;
        !            75: }