Chinaunix首页 | 论坛 | 博客
  • 博客访问: 91271140
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: C/C++

2008-04-17 20:30:42

作者:pals

//SimpSed.h
#
ifndef SIMP_SED
#define SIMP_SED

#include <stdio.h>
//#include

#include "SedScript.h"

#define PATTERN_SPACE_SIZE 0x100000
#define HOLD_SPACE_SIZE 0x100000
#define LINE_SIZE 0x100

#define MSG_FILE_NOT_OPEN "Cannot open file %s.\n"

typedef struct TSimpSed {

    FILE *_file;
    int _lineNumber;
    char _line[LINE_SIZE];
    char *_holdSpace;
    char *_patternSpace;
    SedScript *scriptList;

    void (*parseScript)(struct TSimpSed *self, char *script);
    void (*runScript)(struct TSimpSed *self);
    
    /** sed commands, such as x,d,h,g,p and so on. */
    int (*next)(struct TSimpSed *self);
// n, returns -1, 0, 1

    int (*nextA)(struct TSimpSed *self);
// N, returns -1, 0, 1

    void (*exchange)(struct TSimpSed *self);
// x

    void (*delete)(struct TSimpSed *self);
// d

    void (*hold)(struct TSimpSed *self);
// h

    void (*holdA)(struct TSimpSed *self);
// H

    void (*get)(struct TSimpSed *self);
// g

    void (*getA)(struct TSimpSed *self);
// G

    void (*print)(struct TSimpSed *self);
// p

    
    void (*destroy)(struct TSimpSed *self);
    
    
// public..

    void (*exec)(struct TSimpSed *, char *script, char *fileName);
} SimpSed;    

SimpSed getSed();

#endif

//SedScript.h
#
ifndef SED_SCRIPT
#define SED_SCRIPT

#include "SedAddress.h"

// CMD Types

#define SED_CMD_PRINT 1
#define SED_CMD_NEXT 2
#define SED_CMD_NEXTA 3
#define SED_CMD_HOLD 4
#define SED_CMD_HOLDA 5
#define SED_CMD_GET 6
#define SED_CMD_GETA 7
#define SED_CMD_DELETE 8
#define SED_CMD_EXCHANGE 9

typedef struct TSedScript {
        
        SedAddress address;
        char cmd;
        char *params;
        
        int (*getCmdType)(struct TSedScript *self);
} SedScript;

SedScript getSedScript(char *address, char cmd, char *params);

#endif

//SedAddress.h
#
ifndef SED_ADDRESS
#define SED_ADDRESS

// ADDR TYPES ( $ not included )

#define SED_ADDR_NUMBER 1
#define SED_ADDR_NUMBER_RANGE 2
#define SED_ADDR_PATTERN 3
#define SED_ADDR_PATTERN_RANGE 4

typedef struct TSedAddress {
        
        int type;
        int startLine;
        int stopLine;
        char *startPattern;
        char *stopPattern;
        int rangeFlag;
        
        int (*inRange)(struct TSedAddress *self);
} SedAddress;

SedAddress getSedAddress(char *addr);

#endif

阅读(506) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~