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

📄 cplex.c

📁 linux 下的源代码分析阅读器 red hat公司新版
💻 C
📖 第 1 页 / 共 3 页
字号:
/*Copyright (c) 2000, 2001, Red Hat, Inc.This file is part of Source-Navigator.Source-Navigator is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public License as publishedby the Free Software Foundation; either version 2, or (at your option)any later version.Source-Navigator is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith Source-Navigator; see the file COPYING.  If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330, Boston,MA 02111-1307, USA.*/#include <ctype.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <sys/stat.h>#include <errno.h>#include <fcntl.h>#include <tcl.h>#ifdef __MSVC__#include <io.h>#endif#include "limits.h"#ifndef WIN32#include <unistd.h>#include <sys/param.h>#endif /* WIN32 */#include <tcl.h>#include "cpdefines.h"#include "cplex.h"#include "cpkeyw.h"#include "sn.h"#include "longstr.h"/* Valid debugging macros for this file:         #define TRACE*/#define my_isxdigit(x) (isxdigit(x))#define my_isdigit(x) (isdigit(x))#define my_isalnum(x) (isalnum(x))extern Tcl_Encoding encoding;static int yyeof;/* # define input() ( yyleng++, yycharno++, yychar = *yyptr++ ) *//* # define unput() ( yyleng--, yycharno--, yyptr-- ) */# define input() ( yyleng++, yycharno++, *yyptr ? (yychar = *yyptr++): (yyeof++, yychar = '\0' ))# define unput() ( yyleng--, yycharno--, *yyptr ? --yyptr : ( yyeof ? (--yyeof,yyptr) : --yyptr ))#ifdef rigo# define input() (yyleng++,(yychar=yygetc())=='\n'?(yylineno++,(yycharnoprev=yycharno),(yycharno=0),yychar):(yycharno++,yychar))# define unput() (((yyleng--,(*--yyptr))=='\n')?(yylineno--,(yycharno=yycharnoprev)):yycharno--)# define yygetc() ((yyptr[0]=='\r' && yyptr[1]!='\n') ? *yyptr++ = '\n' : *yyptr++ )#endif# define d_TokenReturn(x) \   { \      Token_t Token = f_TokenCreate(); \      Token->lex          = x; \      Token->sString.text = yytext; \      Token->sString.leng = yyleng; \      Token->lineno_beg   = yylineno_beg; \      Token->charno_beg   = yycharno_beg; \      Token->lineno_end   = yylineno; \      Token->charno_end   = yycharno; \      token_in_line_count++; \      return Token; \   }#define LEX_MODE_NORMAL  0#define LEX_MODE_PP      1#define LEX_MODE_INCLUDE 2extern FILE *hig_fp;static int lex_mode;static int token_in_line_count;int yylineno;int yycharno;static Tcl_DString yybuf;static unsigned char *yyptr;static Token_t TokenUnput;extern int f_ReadFile( int fd );extern Token_t f_TokenInput( void );extern void f_TokenUnput( Token_t Token );extern Param_t f_ParamCreate( void );extern Token_t f_ParamToken( int *pbContinue );extern void f_ParamFree( Param_t Param );extern Token_t f_ParameterPosition( Param_t Param, int position );extern int f_IsMacro( Token_t Token, Macro_t *pMacro );extern Token_t f_TokenMacroInput( Token_t Token, int *pmacro );extern Token_t f_TokenSpecMacroInput( int *pmacro );extern Token_t f_Preprocessor( void );extern void f_FileTokenPrint( Token_t Token );extern Token_t yylex( void ){   int macro;   Token_t Token;   while( True )   {      Token = f_TokenInput();      if( Token->lex == SN_IDENTIFIER )      {         Token = f_TokenMacroInput( Token, &macro );         if( Token == 0 )   /* 24.11.97 rigo */         {            continue;         }      }      else      {         macro = False;      }#ifdef TRACE      f_FileTokenPrint( Token );#endif      return Token;   }}extern intf_ReadFile (int fd){  static Tcl_Encoding ascii = NULL;  unsigned char buf[8192];  struct stat filestats;  static int first = 1;  int i =0, nbytes;  Tcl_DString tmpBuf;    if( fstat( fd, &filestats ))    {      perror( "fstat error" );      return 1;    }    if (first)     {      Tcl_DStringInit(&yybuf);      first = 0;    }  if (ascii == NULL && encoding != NULL)    {      /* We never free this, but this lives for the life of the program	 anyway. */      if ((ascii = Tcl_GetEncoding(NULL, "ascii")) == NULL)	{	  printf("Could not locate ASCII Tcl encoding\n");	  return 3;	}    }    Tcl_DStringInit(&tmpBuf);  Tcl_DStringFree(&yybuf);    while ((nbytes = read(fd, buf, sizeof(buf))) > 0)    {      /* Only do this translation if the `-e' option is given. */      if (encoding != NULL)	{	  Tcl_DString intermediate;	  	  Tcl_DStringInit(&intermediate);	  	  /* Translate to Tcl intermediate form. */	  Tcl_ExternalToUtfDString(encoding, buf, nbytes, &intermediate);	  	  /* Translate to ASCII. */	  Tcl_UtfToExternalDString(ascii,				   Tcl_DStringValue(&intermediate),				   Tcl_DStringLength(&intermediate),				   &tmpBuf);  	  Tcl_DStringAppend(&yybuf, Tcl_DStringValue(&tmpBuf), Tcl_DStringLength(&tmpBuf));   	  Tcl_DStringFree(&tmpBuf);   	  Tcl_DStringFree(&intermediate);	}       else	{  	  Tcl_DStringAppend(&yybuf, buf, nbytes);	}    }    if (nbytes < 0)    {      perror("read");      return 3;    }    yyptr = Tcl_DStringValue(&yybuf);    yyeof = 0;  yylineno = 1;  yycharno = 0;  token_in_line_count = 0;  lex_mode = LEX_MODE_NORMAL;    return 0;}extern Token_t f_TokenInput( void ){   register unsigned char *yytext;   register int yyleng;   register int yychar;   int yycharprev;   int yylineno_beg;   int yycharno_beg;   if( TokenUnput )   {      Token_t Token = TokenUnput;      TokenUnput = 0;      return Token;   }   while( 1 )   {      yytext = yyptr;      yyleng = 0;      yylineno_beg = yylineno;      yycharno_beg = yycharno;      input();/* printf( "yychar: %d\n", yychar ); */      switch( yychar )      {      case '0':      case '1':      case '2':      case '3':      case '4':      case '5':      case '6':      case '7':      case '8':      case '9':         if( yychar == '0' && ( input() == 'X' || yychar == 'x' ))         {   /* hexa nummer */            while( my_isxdigit( input()))            {            }            if( yychar == 'l' || yychar == 'L' )            {               d_TokenReturn( SN_LONGconstant )            }            else if( yychar == 'u' || yychar == 'U' )            {               d_TokenReturn( SN_INTEGERconstant )            }            else            {               unput();               d_TokenReturn( SN_INTEGERconstant )            }         }         else         {            int bFloat = False;            unput();            while( my_isdigit( input()))            {            }            if( yychar == '.' )            {               bFloat = True;               while( my_isdigit( input()))               {               }            }            if( yychar == 'E' || yychar == 'e' )            {               bFloat = True;               input();               if( yychar == '+' || yychar == '-' )               {               }               else               {                  unput();               }               while( my_isdigit( input()))               {               }               if( yychar == '.' )               {                  while( my_isdigit( input()))                  {                  }               }            }            if( yychar == 'l' || yychar == 'L' )            {               if( bFloat ) d_TokenReturn( SN_FLOATINGconstant )               else         d_TokenReturn( SN_LONGconstant )            }            else if( yychar == 'u' || yychar == 'U' )            {               if( bFloat ) d_TokenReturn( SN_FLOATINGconstant )               else         d_TokenReturn( SN_INTEGERconstant )            }            else            {               unput();               if( bFloat ) d_TokenReturn( SN_FLOATINGconstant )               else         d_TokenReturn( SN_INTEGERconstant )            }         }      case 'a':      case 'b':      case 'c':      case 'd':      case 'e':      case 'f':      case 'g':      case 'h':      case 'i':      case 'j':      case 'k':      case 'l':      case 'm':      case 'n':      case 'o':      case 'p':      case 'q':      case 'r':      case 's':      case 't':      case 'u':      case 'x':      case 'y':      case 'v':      case 'w':      case 'z':      case 'A':      case 'B':      case 'C':      case 'D':      case 'E':      case 'F':      case 'G':      case 'H':      case 'I':      case 'J':      case 'K':      case 'L':      case 'M':      case 'N':      case 'O':      case 'P':      case 'Q':      case 'R':      case 'S':      case 'T':      case 'U':      case 'X':      case 'Y':      case 'V':      case 'W':      case 'Z':      case '_':      case '$':         {            register int ihash = 0;            register int j = 0;            int keyword;            int is_cpp;            token_in_line_count++;            do            {               if( j++ < 6 && ihash < HASH_MAX )               {                  ihash += c_hash[ (int) yychar ];               }            }            while( my_isalnum( input()) || yychar == '_' || yychar == '$' );            unput();            if( ihash < HASH_MAX &&                LexKeyWordTab[ihash].leng == yyleng &&                strncmp( LexKeyWordTab[ihash].pcName, (char *)yytext, yyleng ) == 0 )            {               Token_t Token = f_TokenCreate();               if( hig_fp )               {                  fprintf( hig_fp                         ,"%d key %d.%d %d.%d\n"                         , PAF_HIGH                         , yylineno_beg                         , yycharno_beg                         , yylineno                         , yycharno                         );               }               keyword = LexKeyWordTab[ihash].wLexId;               is_cpp  = LexKeyWordTab[ihash].is_cpp;               Token->lex          = SN_IDENTIFIER;               Token->keyword      = keyword;               Token->is_cpp       = is_cpp;               Token->sString.text = yytext;               Token->sString.leng = yyleng;               Token->lineno_beg   = yylineno_beg;               Token->charno_beg   = yycharno_beg;               Token->lineno_end   = yylineno;               Token->charno_end   = yycharno;               return Token;            }#ifdef rigo            if( Paf_IsSkip && (*Paf_IsSkip)((char *)yytext, yyleng ))            {               if( hig_fp )               {                  fprintf( hig_fp                         ,"%d rem %d.%d %d.%d\n"                         , PAF_HIGH                         , yylineno_beg                         , yycharno_beg                         , yylineno                         , yycharno                         );               }               break;   /* skipping identifier */            }            else#endif            {               Token_t Token = f_TokenCreate();               keyword = 0;               is_cpp  = 0;               Token->lex          = SN_IDENTIFIER;               Token->keyword      = keyword;               Token->is_cpp       = is_cpp;               Token->sString.text = yytext;               Token->sString.leng = yyleng;               Token->lineno_beg   = yylineno_beg;               Token->charno_beg   = yycharno_beg;               Token->lineno_end   = yylineno;               Token->charno_end   = yycharno;               return Token;            }         }         break;      case ' ':      case '\t':         break;      case '\r':         input();         if( yychar != '\n' )         {            unput();         }         goto newline;         break;      case '\n':newline:         yylineno++;         yycharno = 0;         if( lex_mode == LEX_MODE_PP )         {            token_in_line_count = -1;            d_TokenReturn( SN_NEWLINE )         }         else         {            token_in_line_count = 0;         }         break;      case '\\':  /* folytatosor */         input();         if( yychar == '\r' )         {            input();            if( yychar != '\n' )            {               unput();            }            yylineno++;            yycharno = 0;         }         else if( yychar == '\n' )         {            yylineno++;            yycharno = 0;         }         break;      case '"':         while( input())         {            if( yychar == '\\' )            {/* A \ utani karaktert lenyeljuk.   Ha \ utan cr+lf jon, akkor midkettot lenyeljuk */               input();               if( yychar == '\r' )               {                  input();                  if( yychar != '\n' )                  {                     unput();                  }                  yylineno++;                  yycharno = 0;               }               else if( yychar == '\n' )               {                  yylineno++;

⌨️ 快捷键说明

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