zoukankan      html  css  js  c++  java
  • 电子词典相关头文件里面的定义和声明

    整个电子词典是分块做的:包含的Dic_Server.c,Dic_Client.c,db.c,query.c,xprtcl.c,dict.h,xprtcl.h,dict.txt(单词文件)

    下面是dict.h代码:(汪老师的代码,这里做调试用)

    /*
    * (C) Copyright 2014
    * http://www.farsight.com.cn/
    * http://nj.hqyj.com/
    *
    * This program is distributed in the purpose for training only
    * and hope that it will be useful, but WITHOUT ANY WARRANTY;
    * without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    *
    * Revision history
    * ------------------------------------------------------
    * 20150116 unicornx initial draft
    * 20150311 unicornx moved _DEBUG to makefile
    */
    /*
    * common header file
    */
    #ifndef _DICT_H_
    #define _DICT_H_

    #ifdef _DEBUG
    #define dprintf printf
    #else
    #define dprintf(format, ...) ((void)0)
    #endif /*_DEBUG */

    #endif /* _DICT_H_ */

    下面是xprtcl.h里面的声明程序,非常重要,在老师的程序上加了一个结构体成员,其他没有改动:

    /*
    * (C) Copyright 2014
    * http://www.farsight.com.cn/
    * http://nj.hqyj.com/
    *
    * This program is distributed in the purpose for training only
    * and hope that it will be useful, but WITHOUT ANY WARRANTY;
    * without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    *
    * Revision history
    * ------------------------------------------------------
    * 20140928 unicornx initial archived
    */
    /* sample codes for on-line dictionary project */
    #ifndef _XPROTOCOL_H_
    #define _XPROTOCOL_H_

    #include <inttypes.h> /* for uint16_t */

    #define MAXLEN_PASSWD 15
    typedef struct xp_req_register {
    char passwd[MAXLEN_PASSWD + 1];
    } xp_req_reqister_t, xp_req_login_t;

    #define MAXLEN_WORD 31
    typedef struct xp_req_query {
    char word[MAXLEN_WORD + 1];
    } xp_req_query_t;

    #define MAXLEN_TEXT 300
    typedef struct xp_rpl_query {
    char text[MAXLEN_TEXT];
    } xp_rpl_query_t;

    #define MAXLEN_TIME 19
    typedef struct xp_rpl_history {
    char word[MAXLEN_WORD + 1];
    char time[MAXLEN_TIME + 1];
    } xp_rpl_history_t;

    #define MAXLEN_USRNAME 15

    #define REQ_Register 0x0001
    #define REQ_Login 0x0002
    #define REQ_Logout 0x0003
    #define REQ_Query 0x0004
    #define REQ_History 0x0005
    #define REQ_QUIT 0x0006
    #define REQ_ERR_QUIT 0x0007

    #define RPL_Register 0x8001
    #define RPL_Login 0x8002
    #define RPL_Query 0x8004
    #define RPL_History 0x8005

    #define RC_SUCCESS (uint16_t)0
    #define RC_EREGISTER (uint16_t)1
    #define RC_EQUERYHIS (uint16_t)2
    #define RC_EQHISEND (uint16_t)3 /* End Of Reply for Query of HIStory */
    #define RC_LOGINED (uint16_t)4
    /* define more error code ...... */

    /* use uint16_t instead of short to make sure codes portable */
    typedef struct xp_hdr {
    char usrname[MAXLEN_USRNAME + 1];
    uint16_t cmd_type; /* in network byte order */
    uint16_t ret_code; /* in network byte order, only used in reply */
    } xp_hdr_t;

    typedef union xp_data {
    xp_req_reqister_t req_register;
    xp_req_login_t req_login;
    xp_req_query_t req_query;

    xp_rpl_query_t rpl_query;
    xp_rpl_history_t rpl_history;
    } xp_data_t;

    typedef struct xprotocol {
    xp_hdr_t hdr;
    xp_data_t word_data;
    xp_data_t data;

    } xprotocol_t;

    int xp_send(int , xprotocol_t *);
    ssize_t xp_recv(int, xprotocol_t *);


    #endif /* _XPROTOCOL_H_ */

  • 相关阅读:
    如何应对“需求不确定型项目”?
    Python virtualenv安装库报错SSL: CERTIFICATE_VERIFY_FAILED
    R语言之——字符串处理函数
    你看那个人他像一条狗
    BZOJ 3744: Gty的妹子序列 [分块]
    BZOJ 3731 3731: Gty的超级妹子树 [树上size分块 !]
    BZOJ 3720: Gty的妹子树 [树上size分块]
    BZOJ 4129: Haruna’s Breakfast [树上莫队 分块]
    SPOJ COT2 Count on a tree II [树上莫队]
    【WC2013】糖果公园 [树上莫队]
  • 原文地址:https://www.cnblogs.com/cnlg/p/4366937.html
Copyright © 2011-2022 走看看