⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lexi.c

📁 代码格式化工具。 其实就是linux下indent的windows版本。
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Copyright (c) 1994, Joseph Arceneaux.  All rights reserved * * Copyright (c) 1992, Free Software Foundation, Inc.  All rights reserved. * * Copyright (c) 1985 Sun Microsystems, Inc. Copyright (c) 1980 The Regents * of the University of California. Copyright (c) 1976 Board of Trustees of * the University of Illinois. All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that * the above copyright notice and this paragraph are duplicated in all such * forms and that any documentation, advertising materials, and other * materials related to such distribution and use acknowledge that the * software was developed by the University of California, Berkeley, the * University of Illinois, Urbana, and Sun Microsystems, Inc.  The name of * either University or Sun Microsystems may not be used to endorse or * promote products derived from this software without specific prior written * permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. *//* Here we have the token scanner for indent.  It scans off one token and * puts it in the global variable "token".  It returns a code, indicating the * type of token scanned. */#include "sys.h"#include <ctype.h>#if defined (HAVE_UNISTD_H)#include <unistd.h>#endif#include <string.h>#include "indent.h"#include "globs.h"RCSTAG_CC ("$Id: lexi.c,v 1.37 2002/08/04 17:08:41 david Exp $");/* Stuff that needs to be shared with the rest of indent. Documented in * indent.h.  */char *token;char *token_end;#define alphanum 1#define opchar 3typedef struct templ{  char     * rwd;  rwcodes_ty rwcode;} templ_ty;/* Pointer to a vector of keywords specified by the user.  */static templ_ty *user_specials = 0;/* Allocated size of user_specials.  */static unsigned int user_specials_max;/* Index in user_specials of the first unused entry.  */static unsigned int user_specials_idx;char chartype[] ={    /* this is used to facilitate the decision of     * what type (alphanumeric, operator) each     * character is */#ifndef CHARSET_EBCDIC  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 3, 0, 0, 1, 3, 3, 0,  0, 0, 3, 3, 0, 3, 0, 3,  1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 0, 0, 3, 3, 3, 3,  0, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 0, 0, 0, 3, 1,  0, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 0, 3, 0, 3, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,#else				/* CHARSET_EBCDIC *//* * The following table was generated by the program given at the end */  0, 0, 0, 0, 0, 0, 0, 0,	/*|........| */  0, 0, 0, 0, 0, 0, 0, 0,	/*|........| */  0, 0, 0, 0, 0, 0, 0, 0,	/*|........| */  0, 0, 0, 0, 0, 0, 0, 0,	/*|........| */  0, 0, 0, 0, 0, 0, 0, 0,	/*|........| */  0, 0, 0, 0, 0, 0, 0, 0,	/*|........| */  0, 0, 0, 0, 0, 0, 0, 0,	/*|........| */  0, 0, 0, 0, 0, 0, 0, 0,	/*|........| */  0, 0, 0, 0, 0, 0, 0, 0,	/*| .......| */  0, 0, 0, 0, 3, 0, 3, 3,	/*|..`.<(+|| */  3, 0, 0, 0, 0, 0, 0, 0,	/*|&.......| */  0, 0, 3, 1, 3, 0, 0, 0,	/*|..!$*);.| */  3, 3, 0, 0, 0, 0, 0, 0,	/*|-/......| */  0, 0, 3, 0, 3, 1, 3, 3,	/*|..^,%_>?| */  0, 0, 0, 0, 0, 0, 0, 0,	/*|........| */  0, 0, 0, 0, 0, 0, 3, 0,	/*|..:#@'="| */  0, 1, 1, 1, 1, 1, 1, 1,	/*|.abcdefg| */  1, 1, 0, 0, 0, 0, 0, 0,	/*|hi......| */  0, 1, 1, 1, 1, 1, 1, 1,	/*|.jklmnop| */  1, 1, 0, 0, 0, 0, 0, 0,	/*|qr......| */  0, 0, 1, 1, 1, 1, 1, 1,	/*|..stuvwx| */  1, 1, 0, 0, 0, 0, 0, 0,	/*|yz......| */  0, 0, 0, 0, 0, 0, 0, 0,	/*|........| */  0, 0, 0, 0, 0, 0, 0, 0,	/*|...[\]..| */  0, 1, 1, 1, 1, 1, 1, 1,	/*|.ABCDEFG| */  1, 1, 0, 0, 0, 0, 0, 0,	/*|HI......| */  0, 1, 1, 1, 1, 1, 1, 1,	/*|.JKLMNOP| */  1, 1, 0, 0, 0, 0, 0, 0,	/*|QR......| */  0, 0, 1, 1, 1, 1, 1, 1,	/*|..STUVWX| */  1, 1, 0, 0, 0, 0, 0, 0,	/*|YZ......| */  1, 1, 1, 1, 1, 1, 1, 1,	/*|01234567| */  1, 1, 0, 0, 0, 0, 0, 3,	/*|89.{.}.~| */#endif				/* CHARSET_EBCDIC */};/* * The table above was generated by the following program from * the ASCII version of the chartype[] array above, where the * unsigned char os_toascii[] array can be found in the source * for the Apache Web Server version 1.3.x, in the directories... *  src/os/bs2000/ebcdic.c    for the SIEMENS BS2000 mainframes, *  src/os/tpf/ebcdic.c       for the IBM TPF server line. * The following table was created for BS2000 EBCDIC character set, * but the few non-zero places should be compatible with IBM's EBCDIC. */#if 0int main (void){    const int GAP = 8;    int i, j;    for (i = 0; i < 256; i += GAP)    {        printf ("  ");        for (j = 0; j < GAP; ++j)	{            printf ("%d, ", chartype[os_toascii[i + j]]);	}                printf (" /*|");                for (j = 0; j < GAP; ++j)	{            printf ("%c", isprint (i + j) ? (i + j) : '.');	}                printf ("|*/\n");    }    return 0;}#endif/* Include code generated by gperf */#ifdef __GNUC____inline#endiftempl_ty *is_reserved (register const char *str, register unsigned int len);#include "gperf.c"/* Include code generated by gperf for C++ keyword set */#undef MIN_HASH_VALUE		/* remove old defs */#undef MAX_HASH_VALUE#undef TOTAL_KEYWORDS#undef MIN_WORD_LENGTH#undef MAX_WORD_LENGTH#ifdef __GNUC____inline#endiftempl_ty *is_reserved_cc (register const char *str, register unsigned int len);#include "gperf-cc.c"codes_ty lexi (void){    int             unary_delim;/* this is set to 1 if the current token                                 * forces a following operator to be unary */    static codes_ty last_code;	/* the last token type returned */    static int      l_struct;   /* set to 1 if the last token was 'struct' */    static int      l_enum;	/* set to 1 if the last token was `enum' */    codes_ty        code;	/* internal code to be returned */    char            qchar;      /* the delimiter character for a string */    static int      count;	/* debugging counter */    count++;    unary_delim = false;        /* tell world that this token started in column 1 iff the last     * thing scanned was nl */        parser_state_tos->col_1       = parser_state_tos->last_nl;    parser_state_tos->last_saw_nl = parser_state_tos->last_nl;    parser_state_tos->last_nl     = false;    if (buf_ptr >= buf_end)    {        fill_buffer ();    }    if (*buf_ptr == ' ' || *buf_ptr == TAB )    {        parser_state_tos->col_1 = false;        skip_buffered_space(); /* adjusts buf_ptr */    }    /* INCREDIBLY IMPORTANT WARNING!!!     *     * Note that subsequent calls to `fill_buffer ()' may switch `buf_ptr'     * to a different buffer.  Thus when `token_end' gets set later, it     * may be pointing into a different buffer than `token'. */        token = buf_ptr;    /* Scan an alphanumeric token */        if ((!((buf_ptr[0] == 'L') &&           ((buf_ptr[1] == '"') || (buf_ptr[1] == '\''))) &&         (chartype[0xff & (int) *buf_ptr] == alphanum)) ||        ((buf_ptr[0] == '.') && isdigit (buf_ptr[1])))    {        /* we have a character or number */        templ_ty *p;        if (isdigit (*buf_ptr) ||            ((buf_ptr[0] == '.') && isdigit (buf_ptr[1])))	{            int seendot = 0, seenexp = 0;            if ((*buf_ptr == '0') && ((buf_ptr[1] == 'x') || (buf_ptr[1] == 'X')))	    {                buf_ptr += 2;                while (isxdigit (*buf_ptr))		{                    buf_ptr++;		}	    }            else                while (1)                {                    if (*buf_ptr == '.')                    {                        if (seendot)                        {                            break;                        }                        else                        {                            seendot++;                        }                    }                    buf_ptr++;                                        if (!isdigit (*buf_ptr) && *buf_ptr != '.')                    {                        if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp)                        {                            break;                        }                        else                        {                            seenexp++;                            seendot++;                            buf_ptr++;                            if (*buf_ptr == '+' || *buf_ptr == '-')                            {                                buf_ptr++;                            }                        }                    }                }            if (*buf_ptr == 'F' || *buf_ptr == 'f' || *buf_ptr == 'i' || *buf_ptr == 'j')            {                buf_ptr++;            }            else	    {                while (*buf_ptr == 'U' || *buf_ptr == 'u' || *buf_ptr == 'L' || *buf_ptr == 'l')                {                    buf_ptr++;                }	    }	}        else            while (chartype[0xff & (int) *buf_ptr] == alphanum)            {			/* copy it over */                buf_ptr++;                if (buf_ptr >= buf_end)                {                    fill_buffer ();                }            }        token_end = buf_ptr;        if (token_end - token == 13 && !strncmp (token, "__attribute__", 13))	{            last_code = decl;            parser_state_tos->last_u_d = true;            return (attribute);	}        skip_buffered_space(); /* adjusts buf_ptr */        /* Handle operator declarations. */        if (token_end - token == 8 && !strncmp (token, "operator", 8))        {            while (chartype[0xff & (int) *buf_ptr] == opchar)	    {                buf_ptr++;                                if (buf_ptr >= buf_end)                {                    fill_buffer ();                }	    }            token_end = buf_ptr;            skip_buffered_space(); /* adjusts buf_ptr */            	}        parser_state_tos->its_a_keyword = false;        parser_state_tos->sizeof_keyword = false;        /* if last token was 'struct', then this token should be treated           as a declaration */        if (l_struct)	{            l_struct = false;            last_code = ident;            parser_state_tos->last_u_d = true;                        if (parser_state_tos->last_token == cpp_operator)            {                return overloaded;            }            return (decl);	}        /* Operator after indentifier is binary */        parser_state_tos->last_u_d = false;        last_code = ident;        /* Check whether the token is a reserved word.  Use perfect hashing... */                if (settings.c_plus_plus)        {            p = is_reserved_cc (token, token_end - token);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -