APUE Learning Example Source Code
guowenxue
2020-04-14 57fc480a7da7811d55957b4e21d1f7390f6c5e37
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
!_TAG_FILE_FORMAT    2    /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED    1    /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR    Darren Hiebert    /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME    Exuberant Ctags    //
!_TAG_PROGRAM_URL    http://ctags.sourceforge.net    /official site/
!_TAG_PROGRAM_VERSION    5.9~svn20110310    //
BUFSIZE    tlv_sample.c    21;"    d    file:
CHARS_PER_LINE    logger.c    334;"    d    file:
CHARS_PER_LINE    tlv_sample.c    156;"    d    file:
CRC_ITU_T_H    crc-itu-t.h    14;"    d
DBG_LOG_FILE    logger.h    35;"    d
DEFAULT_TIME_FORMAT    logger.h    40;"    d
FILENAME_LEN    logger.h    32;"    d
FLAG_LOGGER_CONSOLE    logger.h    63;"    d
FLAG_LOGGER_FILE    logger.h    64;"    d
FLAG_LOGGER_LEVEL_OPT    logger.h    61;"    d
LINELEN    logger.c    333;"    d    file:
LINELEN    tlv_sample.c    155;"    d    file:
LOG_FILE_LINE    logger.h    92;"    d
LOG_LEVEL_DEBUG    logger.h    /^    LOG_LEVEL_DEBUG,                  \/*  Debug Level "Debug" *\/$/;"    e    enum:__anon1
LOG_LEVEL_DISB    logger.h    /^    LOG_LEVEL_DISB = 0,               \/*  Disable "Debug" *\/$/;"    e    enum:__anon1
LOG_LEVEL_ERROR    logger.h    /^    LOG_LEVEL_ERROR,                  \/*  Debug Level "ERROR" *\/$/;"    e    enum:__anon1
LOG_LEVEL_FATAL    logger.h    /^    LOG_LEVEL_FATAL,                  \/*  Debug Level "Fatal" *\/$/;"    e    enum:__anon1
LOG_LEVEL_INFO    logger.h    /^    LOG_LEVEL_INFO,                   \/*  Debug Level "Information" *\/$/;"    e    enum:__anon1
LOG_LEVEL_MAX    logger.h    /^    LOG_LEVEL_MAX,$/;"    e    enum:__anon1
LOG_LEVEL_NRML    logger.h    /^    LOG_LEVEL_NRML,                   \/*  Debug Level "Normal" *\/$/;"    e    enum:__anon1
LOG_LEVEL_TRACE    logger.h    /^    LOG_LEVEL_TRACE,                  \/*  Debug Level "Trace" *\/$/;"    e    enum:__anon1
LOG_LEVEL_WARN    logger.h    /^    LOG_LEVEL_WARN,                   \/*  Debug Level "warnning" *\/$/;"    e    enum:__anon1
LOG_ROLLBACK_NONE    logger.h    38;"    d
LOG_ROLLBACK_SIZE    logger.h    37;"    d
LOG_TIME_FMT    logger.c    24;"    d    file:
LOG_VERSION_STR    logger.h    29;"    d
MAGIC_CRC    crc-itu-t.h    16;"    d
MAX_LOG_MESSAGE_LEN    logger.h    41;"    d
OFF    tlv_sample.c    18;"    d    file:
ON    tlv_sample.c    19;"    d    file:
PACK_HEADER    tlv_sample.c    30;"    d    file:
PID_ASCII_SIZE    proc.h    18;"    d
PRECISE_TIME_FACTOR    logger.c    16;"    d    file:
TAG_CAMERA    tlv_sample.c    /^    TAG_CAMERA,$/;"    e    enum:__anon2    file:
TAG_LED    tlv_sample.c    /^    TAG_LED,$/;"    e    enum:__anon2    file:
TAG_LOGON    tlv_sample.c    /^    TAG_LOGON=1,$/;"    e    enum:__anon2    file:
TLV_FIXED_SIZE    tlv_sample.c    41;"    d    file:
TLV_MIN_SIZE    tlv_sample.c    44;"    d    file:
_LOGGER_H_    logger.h    15;"    d
_PROC_H_    proc.h    15;"    d
_curOffset    logger.c    /^        long _curOffset = ftell(logger->fp);$/;"    l
act    logger.c    /^    struct sigaction act;$/;"    l
argp    logger.c    /^    va_list argp;$/;"    l
args    proc.c    /^    va_list             args;$/;"    l
buf    logger.c    /^    char buf[MAX_LOG_MESSAGE_LEN];$/;"    l
buf    tlv_sample.c    /^    char          buf[BUFSIZE];$/;"    l
bytes    tlv_sample.c    /^    int           bytes;$/;"    l
bytes_to_ushort    crc-itu-t.c    /^unsigned short bytes_to_ushort(unsigned char *bytes, int len)$/;"    f    signature:(unsigned char *bytes, int len)
bytes_to_ushort    crc-itu-t.h    /^extern unsigned short bytes_to_ushort(unsigned char *bytes, int len);$/;"    p    signature:(unsigned char *bytes, int len)
c    logger.c    /^            unsigned char c = buf[idx];$/;"    l
c    tlv_sample.c    /^            unsigned char c = data[idx];$/;"    l
check_and_rollback    logger.c    /^static void check_and_rollback(void)$/;"    f    file:    signature:(void)
check_daemon_running    proc.c    /^int check_daemon_running(const char *pid_file)$/;"    f    signature:(const char *pid_file)
check_daemon_running    proc.h    /^extern int check_daemon_running(const char *pid_file);$/;"    p    signature:(const char *pid_file)
chmod    proc.c    /^        (void)chmod(ipc_dir, mode); $/;"    p    file:
cmd    logger.c    /^            char cmd[512];$/;"    l
cmd    proc.c    /^    char                cmd[256];$/;"    l
cp_install_proc_signal    proc.c    /^void cp_install_proc_signal(void)$/;"    f    signature:(void)
cp_install_proc_signal    proc.h    /^extern void cp_install_proc_signal(void);$/;"    p    signature:(void)
cp_printout    logger.c    /^static void cp_printout(char *level, char *fmt, va_list argp)$/;"    f    file:    signature:(char *level, char *fmt, va_list argp)
cp_printout_line    logger.c    /^static void cp_printout_line(char *level, char *fmt, char *file, int line, va_list argp)$/;"    f    file:    signature:(char *level, char *fmt, char *file, int line, va_list argp)
cp_proc_sighandler    proc.c    /^void cp_proc_sighandler(int sig)$/;"    f    signature:(int sig)
crc16    tlv_sample.c    /^    unsigned short      crc16 = 0;$/;"    l
crc16    tlv_sample.c    /^    unsigned short      crc16;$/;"    l
crc_itu_t    crc-itu-t.c    /^unsigned short crc_itu_t(unsigned short crc, const unsigned char *buffer, unsigned int len)$/;"    f    signature:(unsigned short crc, const unsigned char *buffer, unsigned int len)
crc_itu_t    crc-itu-t.h    /^extern unsigned short crc_itu_t(unsigned short magic_crc, const unsigned char *buffer, unsigned int len);$/;"    p    signature:(unsigned short magic_crc, const unsigned char *buffer, unsigned int len)
crc_itu_t_byte    crc-itu-t.h    /^static inline unsigned short crc_itu_t_byte(unsigned short crc, const unsigned char data)$/;"    f    signature:(unsigned short crc, const unsigned char data)
crc_itu_t_table    crc-itu-t.c    /^const unsigned short crc_itu_t_table[256] = {$/;"    v
crc_itu_t_table    crc-itu-t.h    /^extern const unsigned short  crc_itu_t_table[256];$/;"    x
daemonize    proc.c    /^void daemonize(int nochdir, int noclose)$/;"    f    signature:(int nochdir, int noclose)
daemonize    proc.h    /^extern void daemonize(int nochdir, int noclose);$/;"    p    signature:(int nochdir, int noclose)
data_len    tlv_sample.c    /^    int                 data_len = 0;$/;"    l
done    proc.c    /^    int                 done; $/;"    l
dump_buf    tlv_sample.c    /^void dump_buf(char *data, int len)$/;"    f    signature:(char *data, int len)
dump_buf    tlv_sample.c    /^void dump_buf(char *data, int len);$/;"    p    file:    signature:(char *data, int len)
exec_system_cmd    proc.c    /^void exec_system_cmd(const char *format, ...)$/;"    f    signature:(const char *format, ...)
exec_system_cmd    proc.h    /^extern void exec_system_cmd(const char *format, ...);$/;"    p    signature:(const char *format, ...)
f    proc.c    /^    FILE *f; $/;"    l
fStatBuf    proc.c    /^    struct stat      fStatBuf;$/;"    l
fStatBuf    proc.c    /^    struct stat fStatBuf; $/;"    l
fStatBuf    proc.c    /^    struct stat fStatBuf;$/;"    l
fclose    proc.c    /^        (void)fclose(f); $/;"    p    file:
fd    proc.c    /^    int fd = -1; $/;"    l
fd    proc.c    /^    int retval, fd; $/;"    l
fgets    proc.c    /^        (void)fgets(pid_ascii, PID_ASCII_SIZE, f); $/;"    p    file:
file    logger.h    /^    char               file[FILENAME_LEN];$/;"    m    struct:logger_s    access:public
filemode    logger.c    /^    char *filemode;$/;"    l
flag    logger.h    /^    unsigned char      flag;$/;"    m    struct:logger_s    access:public
fp    logger.h    /^    FILE               *fp;$/;"    m    struct:logger_s    access:public
g_signal    proc.c    /^proc_signal_t     g_signal={0};$/;"    v
g_signal    proc.h    /^extern proc_signal_t     g_signal;$/;"    x
get_daemon_pid    proc.c    /^pid_t get_daemon_pid(const char *pid_file)$/;"    f    signature:(const char *pid_file)
get_daemon_pid    proc.h    /^extern pid_t get_daemon_pid(const char *pid_file);$/;"    p    signature:(const char *pid_file)
hc    logger.c    /^    char hc[4];$/;"    l
hc    tlv_sample.c    /^    char hc[4];$/;"    l
i    crc-itu-t.c    /^    int              i = 0;$/;"    l
i    crc-itu-t.c    /^    int            i = 0;$/;"    l
i    proc.c    /^    int i; $/;"    l
idx    logger.c    /^    int idx;$/;"    l
idx    tlv_sample.c    /^    int idx;$/;"    l
ipc_dir    proc.c    /^    char ipc_dir[64] = { 0 }; $/;"    l
ldx    logger.c    /^        int ldx = idx % CHARS_PER_LINE;$/;"    l
level    logger.h    /^    int                level;$/;"    m    struct:logger_s    access:public
line_done    logger.c    /^    short line_done = 1;$/;"    l
line_done    tlv_sample.c    /^    short line_done = 1;$/;"    l
lit    logger.c    /^    char lit[CHARS_PER_LINE + 2];$/;"    l
lit    tlv_sample.c    /^    char lit[CHARS_PER_LINE + 1];$/;"    l
local    logger.c    /^    struct tm *local;$/;"    l
log_dbg    logger.h    105;"    d
log_dbg    logger.h    97;"    d
log_err    logger.h    100;"    d
log_err    logger.h    108;"    d
log_fatal    logger.h    101;"    d
log_fatal    logger.h    109;"    d
log_info    logger.h    104;"    d
log_info    logger.h    96;"    d
log_nrml    logger.h    106;"    d
log_nrml    logger.h    98;"    d
log_rollback_size    logger.c    /^static unsigned long log_rollback_size = LOG_ROLLBACK_NONE;$/;"    v    file:
log_signal_handler    logger.c    /^static void log_signal_handler(int sig)$/;"    f    file:    signature:(int sig)
log_str    logger.c    /^char *log_str[LOG_LEVEL_MAX + 1] = { "", "F", "E", "W", "N", "D", "I", "T", "M" };$/;"    v
log_str    logger.h    /^extern char *log_str[];$/;"    x
log_trace    logger.h    103;"    d
log_trace    logger.h    95;"    d
log_warn    logger.h    107;"    d
log_warn    logger.h    99;"    d
logger    logger.c    /^static logger_t *logger = NULL;$/;"    v    file:
logger_banner    logger.c    /^static void logger_banner(char *prefix)$/;"    f    file:    signature:(char *prefix)
logger_close    logger.c    /^void logger_close(void)$/;"    f    signature:(void)
logger_close    logger.h    /^extern void logger_close(void);$/;"    p    signature:(void)
logger_dump    logger.c    /^void logger_dump(int level, char *buf, int len)$/;"    f    signature:(int level, char *buf, int len)
logger_dump    logger.h    /^extern void logger_dump(int level, char *buf, int len);$/;"    p    signature:(int level, char *buf, int len)
logger_init    logger.c    /^int logger_init(logger_t *log, char *log_file, int level, int log_size)$/;"    f    signature:(logger_t *log, char *log_file, int level, int log_size)
logger_init    logger.h    /^extern int  logger_init(logger_t *logger, char *filename, int level, int log_size);$/;"    p    signature:(logger_t *logger, char *filename, int level, int log_size)
logger_line    logger.c    /^void logger_line(int level, char *file, int line, char *fmt, ...)$/;"    f    signature:(int level, char *file, int line, char *fmt, ...)
logger_line    logger.h    /^extern void logger_line(int level, char *file, int line, char *fmt, ...);$/;"    p    signature:(int level, char *file, int line, char *fmt, ...)
logger_min    logger.c    /^void logger_min(int level, char *fmt, ...)$/;"    f    signature:(int level, char *fmt, ...)
logger_min    logger.h    /^extern void logger_min(int level, char *fmt, ...);$/;"    p    signature:(int level, char *fmt, ...)
logger_open    logger.c    /^int logger_open(void)$/;"    f    signature:(void)
logger_open    logger.h    /^extern int  logger_open(void);$/;"    p    signature:(void)
logger_raw    logger.c    /^void logger_raw(const char *fmt, ...)$/;"    f    signature:(const char *fmt, ...)
logger_raw    logger.h    /^extern void logger_raw(const char *fmt, ...);$/;"    p    signature:(const char *fmt, ...)
logger_reopen    logger.c    /^int logger_reopen(void)$/;"    f    signature:(void)
logger_reopen    logger.h    /^extern int  logger_reopen(void);$/;"    p    signature:(void)
logger_s    logger.h    /^typedef struct logger_s$/;"    s
logger_s::file    logger.h    /^    char               file[FILENAME_LEN];$/;"    m    struct:logger_s    access:public
logger_s::flag    logger.h    /^    unsigned char      flag;$/;"    m    struct:logger_s    access:public
logger_s::fp    logger.h    /^    FILE               *fp;$/;"    m    struct:logger_s    access:public
logger_s::level    logger.h    /^    int                level;$/;"    m    struct:logger_s    access:public
logger_s::size    logger.h    /^    int                size;$/;"    m    struct:logger_s    access:public
logger_set_time_format    logger.h    /^extern void logger_set_time_format(char *time_format);$/;"    p    signature:(char *time_format)
logger_str    logger.c    /^void logger_str(int level, const char *msg)$/;"    f    signature:(int level, const char *msg)
logger_str    logger.h    /^extern void logger_str(int level, const char *msg);$/;"    p    signature:(int level, const char *msg)
logger_t    logger.h    /^} logger_t;$/;"    t    typeref:struct:logger_s
logger_term    logger.c    /^void logger_term(void)$/;"    f    signature:(void)
logger_term    logger.h    /^extern void logger_term(void);$/;"    p    signature:(void)
main    tlv_sample.c    /^int main(int argc, char **argv)$/;"    f    signature:(int argc, char **argv)
mode    proc.c    /^    int mode = S_IROTH | S_IXOTH | S_IRGRP | S_IXGRP | S_IRWXU;$/;"    l
now    logger.c    /^    struct timeval now;$/;"    l
ofset    tlv_sample.c    /^    int                 ofset = 0; \/* index position for the buf *\/$/;"    l
pack_len    tlv_sample.c    /^    int                 pack_len = 0;$/;"    l
pack_len    tlv_sample.c    /^    int                 pack_len = TLV_FIXED_SIZE+1; \/* Only 1 byte data *\/$/;"    l
packtlv_led    tlv_sample.c    /^int packtlv_led(char *buf, int size, int cmd)$/;"    f    signature:(char *buf, int size, int cmd)
packtlv_led    tlv_sample.c    /^int packtlv_led(char *buf, int size, int cmd);$/;"    p    file:    signature:(char *buf, int size, int cmd)
packtlv_logon    tlv_sample.c    /^int packtlv_logon(char *buf, int size, char *pwd)$/;"    f    signature:(char *buf, int size, char *pwd)
packtlv_logon    tlv_sample.c    /^int packtlv_logon(char *buf, int size, char *pwd);$/;"    p    file:    signature:(char *buf, int size, char *pwd)
pid    proc.c    /^        char pid[PID_ASCII_SIZE]; $/;"    l
pid    proc.c    /^        pid_t pid = -1; $/;"    l
pid    proc.c    /^    pid_t            pid = -1; $/;"    l
pid    proc.c    /^    pid_t pid; $/;"    l
pid_ascii    proc.c    /^        char pid_ascii[PID_ASCII_SIZE]; $/;"    l
print_char    logger.c    /^static char *print_char =$/;"    v    file:
print_char    tlv_sample.c    /^static char *print_char =$/;"    v    file:
prn    logger.c    /^    char prn[LINELEN];$/;"    l
prn    tlv_sample.c    /^    char prn[LINELEN];$/;"    l
proc_signal_s    proc.h    /^typedef struct proc_signal_s$/;"    s
proc_signal_s::signal    proc.h    /^    int       signal;$/;"    m    struct:proc_signal_s    access:public
proc_signal_s::stop    proc.h    /^    unsigned  stop;     \/* 0: Not term  1: Stop  *\/$/;"    m    struct:proc_signal_s    access:public
proc_signal_s::threads    proc.h    /^    int       threads;  \/* threads counter *\/$/;"    m    struct:proc_signal_s    access:public
proc_signal_t    proc.h    /^}  proc_signal_t;$/;"    t    typeref:struct:proc_signal_s
rc    logger.c    /^    int rc = 0;$/;"    l
rc    logger.c    /^    int rc;$/;"    l
rc    tlv_sample.c    /^    int rc;$/;"    l
record_daemon_pid    proc.c    /^int record_daemon_pid(const char *pid_file)$/;"    f    signature:(const char *pid_file)
record_daemon_pid    proc.h    /^extern int record_daemon_pid(const char *pid_file);$/;"    p    signature:(const char *pid_file)
retVal    proc.c    /^    int retVal = -1; $/;"    l
retval    proc.c    /^    int        retval = 0;$/;"    l
retval    proc.c    /^    int retval, fd; $/;"    l
set_daemon_running    proc.c    /^int set_daemon_running(const char *pid_file)$/;"    f    signature:(const char *pid_file)
set_daemon_running    proc.h    /^extern int set_daemon_running(const char *pid_file);$/;"    p    signature:(const char *pid_file)
sigact    proc.c    /^    struct sigaction sigact, sigign;$/;"    l
sigign    proc.c    /^    struct sigaction sigact, sigign;$/;"    l
signal    proc.h    /^    int       signal;$/;"    m    struct:proc_signal_s    access:public
size    crc-itu-t.c    /^    int              size  = sizeof (unsigned short);$/;"    l
size    logger.h    /^    int                size;$/;"    m    struct:logger_s    access:public
stop    proc.h    /^    unsigned  stop;     \/* 0: Not term  1: Stop  *\/$/;"    m    struct:proc_signal_s    access:public
stop_daemon_running    proc.c    /^int stop_daemon_running(const char *pid_file)$/;"    f    signature:(const char *pid_file)
stop_daemon_running    proc.h    /^extern int stop_daemon_running(const char *pid_file);$/;"    p    signature:(const char *pid_file)
thread_attr    proc.c    /^    pthread_attr_t thread_attr; $/;"    l
thread_body    proc.h    /^typedef void *(* thread_body) (void *thread_arg);$/;"    t
thread_start    proc.c    /^int thread_start(pthread_t * thread_id, thread_body worker_func, void *thread_arg)$/;"    f    signature:(pthread_t * thread_id, thread_body worker_func, void *thread_arg)
thread_start    proc.h    /^extern int thread_start(pthread_t * thread_id, thread_body worker_func, void *thread_arg);$/;"    p    signature:(pthread_t * thread_id, thread_body worker_func, void *thread_arg)
thread_stop    proc.c    /^void thread_stop(char *prompt)$/;"    f    signature:(char *prompt)
thread_stop    proc.h    /^extern void thread_stop(char *prompt);$/;"    p    signature:(char *prompt)
threads    proc.h    /^    int       threads;  \/* threads counter *\/$/;"    m    struct:proc_signal_s    access:public
timestr    logger.c    /^    char timestr[256];$/;"    l
ushort_to_bytes    crc-itu-t.c    /^int ushort_to_bytes(unsigned char *bytes, unsigned short val)$/;"    f    signature:(unsigned char *bytes, unsigned short val)
ushort_to_bytes    crc-itu-t.h    /^extern int ushort_to_bytes(unsigned char *bytes, unsigned short val);$/;"    p    signature:(unsigned char *bytes, unsigned short val)
val    crc-itu-t.c    /^    unsigned short val = 0;$/;"    l