Препроцессор языка СИ

Загрузить архив:
Файл: 240-1513.zip (167kb [zip], Скачиваний: 27) скачать

                        ‹¡®àâ®à­ï à¡®â 1

‡¤­¨¥:

      ®áâநâì «¥ªá¨ç¥áª¨© ­«¨§â®à (᪭¥à), ª®â®àë© ¡ã¤¥â ¢

¤«ì­¥©è¥¬ ¨á¯®«ì§®¢âìáï ¯à¨ à§¡®à¥ HTML-¤®ªã¬¥­â®¢.

’¥ªá⠯ணବë:

#include

#include

#include

#include

#include "parserhtm_cnst.h"

#include "parserhtm_glob.h"

#include "parserhtm_tokn.h"

#include "parserhtm_err.h"

#include "parse.h"

#pragma hdrstop

extern YYSTYPE yylval;

enum {TEXT=0, PRE, KEYWORD, ATTR, AVALUE, IN_QUOTE};

char *states [ 6] = {"TEXT", "PRE", "KEYWORD", "ATTR", "AVALUE", "IN_QUOTE"};

char *tktypes[10] = {"_OpenTag", "_CloseTag", "_EndTag", "_C_KEYWORD",

     "_S_KEYWORD", "_A_KEYWORD", "_V_KEYWORD", "_NUM",

     "_IDENTIFIER", "_QUOTED_ATTR"};

/* text, preformatted text, HTML KEYWORD, attribute KEYWORD, */

/* attribute value KEYWORD                          */

int in_close   = FALSE;

int in_open    = FALSE;

int opened_par = FALSE;

int state     = TEXT;

int old_state = TEXT;

int cUKSZ = 0;

int USE_BUFFER = FALSE;

int lex_buff_size = 0;

typedef struct {

   int      tktyp;

   char tkval[NMSZ];

} tbuff;

tbuff lex_buff[5];

intc;

intlineno;

long charno;

long f_size;

inticm;

    /* !!!!!! */

char comment[CMSZ];

    /* !!!!!! */

typedef struct {

    char name[TKSZ];

    int  kw_token;

    int  in_paragraph;

} kw_table;

/********** functions declarations ************/

void fixfile(FILE *, char*);

intnextchar(FILE *, FILE *);

void nlproc (FILE *);

intbsearch (char *, kw_table *, int);

intnexttok (char *);

void lexinit();

intyylex();

/**********************************************/

/* Possible KEYWORDS - directives */

kw_table keyword_table[KWSZ] = {


                                - 2 -

    {"A",       _C_KEYWORD, TRUE},

    // ...

    {"WBR",    _S_KEYWORD, TRUE}

};

/* Possible KEYWORDS - attributes */

kw_table attr_table[ATSZ] = {

    {"ALIGN",         _A_KEYWORD },

    // ...

    {"WRAP",          _A_KEYWORD }

};

/* Possible KEYWORDS - attribute's values */

kw_table aval_table[AVSZ] = {

    {"ABSBOTTOM",   _V_KEYWORD },

    // ...

    {"_top",          _V_KEYWORD }

};

/*

* ä㭪樨

*/

/*

* ”ã­ªæ¨ï ¡¨­à­®£® ¯®¨áª ¨¬¥­¨ ¢ â¡«¨æ¥ ¨¬¥­. ‚®§¢àé¥â ¨­¤¥ªá

* ­©¤¥­­®£® í«¥¬¥­â ¢ ¬áᨢ¥ ¨«¨ -1, ¥á«¨ ­¨ç¥£® ­¥ ­è«.

* Œáᨢ á®á⮨⠨§ §¯¨á¥© á ¯®«ï¬¨ : áâப®¢®© ASCII/Z-ª®­áâ­âë -

* ª«î祢®£® á«®¢ HTML ¨ int'®¢áª®£® ⨯ í⮣® KEYWORD'

*/

int bsearch( char word[], kw_table word_table[], int tbsize)

{

int low, high, middle;

int i;

low = 0;

high = tbsize - 1;

while (low <= high) {

    middle = (low + high) / 2;

    i = strcmp(word, word_table[middle].name);

    if (i < 0) {

      high = middle - 1;

    } else if (i > 0) {

      low = middle + 1;

    } else {

      return (middle);

    }

}

return (-1);

}

int nexttok(char *val)

{

register int i, i2;

char tokenvalue[NMSZ];

int c1, tokentype, tokenend;

i = 0;

while (isspace(c)) /* c is always one char ahead */ {

      if (c == 'n') nlproc(listfp);

      if (state == PRE) {

      tokenvalue[0] = c; tokenvalue[1] = '