| version 1.1.1.1, 2013/07/22 08:44:29 | version 1.1.1.2, 2021/03/17 00:39:23 | 
| Line 100 | Line 100 | 
 | u_char              exact:1;        /* true if this is an exact match */ | u_char              exact:1;        /* true if this is an exact match */ | 
 | union { | union { | 
 | struct cm_exact { | struct cm_exact { | 
| char    *pat;                   /* exact string to match */ | char *pat;                   /* exact string to match */ | 
 | u_short *fail;                  /* failure function */ | u_short *fail;                  /* failure function */ | 
 | u_int   matched;                /* number of chars matched so far */ | u_int   matched;                /* number of chars matched so far */ | 
 | }         exact; | }         exact; | 
| Line 178 | Line 178 | 
 | { NOTHING,  CMD_NOTHING,    1, 1 }, | { NOTHING,  CMD_NOTHING,    1, 1 }, | 
 | }; | }; | 
 |  |  | 
| #define CHAT_NUM_COMMANDS     (sizeof(gCmds) / sizeof(*gCmds)) | #define CHAT_NUM_COMMANDS     ((int)(sizeof(gCmds) / sizeof(*gCmds))) | 
 |  |  | 
 | /* | /* | 
 | * INTERNAL FUNCTIONS | * INTERNAL FUNCTIONS | 
| Line 191 | Line 191 | 
 | static void   ChatCancel(ChatInfo c, const char *set); | static void   ChatCancel(ChatInfo c, const char *set); | 
 | static int    ChatGoto(ChatInfo c, const char *label); | static int    ChatGoto(ChatInfo c, const char *label); | 
 | static void   ChatCall(ChatInfo c, const char *label); | static void   ChatCall(ChatInfo c, const char *label); | 
| static void   ChatLog(ChatInfo c, int code, const char *string); | static void   ChatLog(ChatInfo c, const char *string); | 
 | static void   ChatPrint(ChatInfo c, const char *string); | static void   ChatPrint(ChatInfo c, const char *string); | 
 | static void   ChatReturn(ChatInfo c, int seek); | static void   ChatReturn(ChatInfo c, int seek); | 
 | static void   ChatRun(ChatInfo c); | static void   ChatRun(ChatInfo c); | 
| Line 214 | Line 214 | 
 | static int    ChatVarExtract(const char *string, | static int    ChatVarExtract(const char *string, | 
 | char *buf, int max, int strict); | char *buf, int max, int strict); | 
 |  |  | 
| static void   ChatFreeMatch(ChatInfo c, ChatMatch match); | static void   ChatFreeMatch(ChatMatch match); | 
| static void   ChatFreeTimer(ChatInfo c, ChatTimer timer); | static void   ChatFreeTimer(ChatTimer timer); | 
 | static int    ChatMatchChar(struct cm_exact *ex, char ch); | static int    ChatMatchChar(struct cm_exact *ex, char ch); | 
 | static int    ChatMatchRegex(ChatInfo c, regex_t *reg, const char *input); | static int    ChatMatchRegex(ChatInfo c, regex_t *reg, const char *input); | 
 | static void   ChatSetMatchVars(ChatInfo c, int exact, const char *input, ...); | static void   ChatSetMatchVars(ChatInfo c, int exact, const char *input, ...); | 
| static void   ChatComputeFailure(ChatInfo c, struct cm_exact *ex); | static void   ChatComputeFailure(struct cm_exact *ex); | 
 |  |  | 
| static int    ChatDecodeTime(ChatInfo c, char *string, u_int *secsp); | static int    ChatDecodeTime(ChatInfo c, const char *string, u_int *secsp); | 
 | static int    ChatSetBaudrate(ChatInfo c, const char *new); | static int    ChatSetBaudrate(ChatInfo c, const char *new); | 
 | static char   *ChatExpandString(ChatInfo c, const char *string); | static char   *ChatExpandString(ChatInfo c, const char *string); | 
 |  |  | 
 | static char   *ChatReadLine(ChatInfo c); | static char   *ChatReadLine(ChatInfo c); | 
| static int    ChatParseLine(ChatInfo c, char *line, char *av[], int max); | static int    ChatParseLine(char *line, char *av[], int max); | 
 | static int    ChatSeekToLabel(ChatInfo c, const char *label); | static int    ChatSeekToLabel(ChatInfo c, const char *label); | 
 | static void   ChatDumpBuf(ChatInfo c, const char *buf, | static void   ChatDumpBuf(ChatInfo c, const char *buf, | 
 | int len, const char *fmt, ...); | int len, const char *fmt, ...); | 
| Line 360  ChatRead(int type, void *cookie) | Line 360  ChatRead(int type, void *cookie) | 
 | { | { | 
 | ChatInfo      const c = (ChatInfo) cookie; | ChatInfo      const c = (ChatInfo) cookie; | 
 | ChatMatch     match; | ChatMatch     match; | 
| int           nread, lineBufLen; | size_t        lineBufLen; | 
|  | int             nread; | 
 | char          ch; | char          ch; | 
 | Link          const l = (Link) c->arg; | Link          const l = (Link) c->arg; | 
 |  |  | 
 | /* Sanity */ | /* Sanity */ | 
 |  |  | 
 | assert(c->state == CHAT_WAIT); | assert(c->state == CHAT_WAIT); | 
 |  | (void)type; | 
 |  |  | 
 | /* Process one byte at a time */ | /* Process one byte at a time */ | 
 |  |  | 
| Line 497  ChatTimeout(int type, void *cookie) | Line 499  ChatTimeout(int type, void *cookie) | 
 | /* Sanity */ | /* Sanity */ | 
 |  |  | 
 | assert(c->state == CHAT_WAIT); | assert(c->state == CHAT_WAIT); | 
|  | (void)type; | 
 | /* Locate timer in list */ | /* Locate timer in list */ | 
 |  |  | 
 | for (tp = &c->timers; *tp != timer; tp = &(*tp)->next); | for (tp = &c->timers; *tp != timer; tp = &(*tp)->next); | 
| Line 559  ChatRun(ChatInfo c) | Line 561  ChatRun(ChatInfo c) | 
 |  |  | 
 | /* Parse out line */ | /* Parse out line */ | 
 |  |  | 
| ac = ChatParseLine(c, line, av, CHAT_MAX_ARGS); | ac = ChatParseLine(line, av, CHAT_MAX_ARGS); | 
 | Freee(line); | Freee(line); | 
 |  |  | 
 | /* Do command */ | /* Do command */ | 
| Line 733  ChatDoCmd(ChatInfo c, int ac, char *av[]) | Line 735  ChatDoCmd(ChatInfo c, int ac, char *av[]) | 
 | break; | break; | 
 |  |  | 
 | case CMD_LOG: | case CMD_LOG: | 
| ChatLog(c, 0, av[1]); | ChatLog(c, av[1]); | 
 | break; | break; | 
 |  |  | 
 | case CMD_RETURN: | case CMD_RETURN: | 
| Line 916  ChatAddMatch(ChatInfo c, int exact, const char *set, | Line 918  ChatAddMatch(ChatInfo c, int exact, const char *set, | 
 | if (exact) { | if (exact) { | 
 | match->u.exact.pat = pat; | match->u.exact.pat = pat; | 
 | match->u.exact.matched = 0; | match->u.exact.matched = 0; | 
| ChatComputeFailure(c, &match->u.exact); | ChatComputeFailure(&match->u.exact); | 
 | } else { | } else { | 
 | int         errcode; | int         errcode; | 
 | char        errbuf[100]; | char        errbuf[100]; | 
| Line 991  ChatCancel(ChatInfo c, const char *set0) | Line 993  ChatCancel(ChatInfo c, const char *set0) | 
 | for (mp = &c->matches; (match = *mp) != NULL; ) { | for (mp = &c->matches; (match = *mp) != NULL; ) { | 
 | if (all || !strcmp(match->set, set)) { | if (all || !strcmp(match->set, set)) { | 
 | *mp = match->next; | *mp = match->next; | 
| ChatFreeMatch(c, match); | ChatFreeMatch(match); | 
 | } else | } else | 
 | mp = &match->next; | mp = &match->next; | 
 | } | } | 
| Line 1001  ChatCancel(ChatInfo c, const char *set0) | Line 1003  ChatCancel(ChatInfo c, const char *set0) | 
 | for (tp = &c->timers; (timer = *tp) != NULL; ) { | for (tp = &c->timers; (timer = *tp) != NULL; ) { | 
 | if (all || !strcmp(timer->set, set)) { | if (all || !strcmp(timer->set, set)) { | 
 | *tp = timer->next; | *tp = timer->next; | 
| ChatFreeTimer(c, timer); | ChatFreeTimer(timer); | 
 | } else | } else | 
 | tp = &timer->next; | tp = &timer->next; | 
 | } | } | 
| Line 1125  ChatReturn(ChatInfo c, int seek) | Line 1127  ChatReturn(ChatInfo c, int seek) | 
 | for (mp = &c->matches; (match = *mp) != NULL; ) { | for (mp = &c->matches; (match = *mp) != NULL; ) { | 
 | if (--match->frameDepth < 0) { | if (--match->frameDepth < 0) { | 
 | *mp = match->next; | *mp = match->next; | 
| ChatFreeMatch(c, match); | ChatFreeMatch(match); | 
 | } else | } else | 
 | mp = &match->next; | mp = &match->next; | 
 | } | } | 
 | for (tp = &c->timers; (timer = *tp) != NULL; ) { | for (tp = &c->timers; (timer = *tp) != NULL; ) { | 
 | if (--timer->frameDepth < 0) { | if (--timer->frameDepth < 0) { | 
 | *tp = timer->next; | *tp = timer->next; | 
| ChatFreeTimer(c, timer); | ChatFreeTimer(timer); | 
 | } else | } else | 
 | tp = &timer->next; | tp = &timer->next; | 
 | } | } | 
| Line 1143  ChatReturn(ChatInfo c, int seek) | Line 1145  ChatReturn(ChatInfo c, int seek) | 
 | */ | */ | 
 |  |  | 
 | static void | static void | 
| ChatLog(ChatInfo c, int code, const char *string) | ChatLog(ChatInfo c, const char *string) | 
 | { | { | 
 | char  *exp_string; | char  *exp_string; | 
 | Link  const l = (Link) c->arg; | Link  const l = (Link) c->arg; | 
| Line 1199  ChatWrite(int type, void *cookie) | Line 1201  ChatWrite(int type, void *cookie) | 
 | int           nw; | int           nw; | 
 | Link          const l = (Link) c->arg; | Link          const l = (Link) c->arg; | 
 |  |  | 
 | /* Write as much as we can */ |  | 
 |  |  | 
 | assert(c->out != NULL && c->outLen > 0); | assert(c->out != NULL && c->outLen > 0); | 
 |  | (void)type; | 
 |  |  | 
 |  | /* Write as much as we can */ | 
 | if ((nw = write(c->fd, c->out, c->outLen)) < 0) { | if ((nw = write(c->fd, c->out, c->outLen)) < 0) { | 
 | if (errno == EAGAIN) | if (errno == EAGAIN) | 
 | return; | return; | 
| Line 1375  ChatVarExtract(const char *string, char *buf, int max, | Line 1378  ChatVarExtract(const char *string, char *buf, int max, | 
 | */ | */ | 
 |  |  | 
 | static void | static void | 
| ChatFreeMatch(ChatInfo c, ChatMatch match) | ChatFreeMatch(ChatMatch match) | 
 | { | { | 
 | Freee(match->set); | Freee(match->set); | 
 | Freee(match->label); | Freee(match->label); | 
| Line 1393  ChatFreeMatch(ChatInfo c, ChatMatch match) | Line 1396  ChatFreeMatch(ChatInfo c, ChatMatch match) | 
 | */ | */ | 
 |  |  | 
 | static void | static void | 
| ChatFreeTimer(ChatInfo c, ChatTimer timer) | ChatFreeTimer(ChatTimer timer) | 
 | { | { | 
 | EventUnRegister(&timer->event); | EventUnRegister(&timer->event); | 
 | Freee(timer->set); | Freee(timer->set); | 
| Line 1580  ChatSetMatchVars(ChatInfo c, int exact, const char *in | Line 1583  ChatSetMatchVars(ChatInfo c, int exact, const char *in | 
 | static int | static int | 
 | ChatMatchChar(struct cm_exact *ex, char ch) | ChatMatchChar(struct cm_exact *ex, char ch) | 
 | { | { | 
| const int     len = strlen(ex->pat); | const u_int     len = strlen(ex->pat); | 
 |  |  | 
 | /* Account for zero length pattern string -- match on next input char */ | /* Account for zero length pattern string -- match on next input char */ | 
 | if (len == 0) | if (len == 0) | 
| Line 1640  ChatMatchRegex(ChatInfo c, regex_t *reg, const char *i | Line 1643  ChatMatchRegex(ChatInfo c, regex_t *reg, const char *i | 
 | */ | */ | 
 |  |  | 
 | static void | static void | 
| ChatComputeFailure(ChatInfo c, struct cm_exact *ex) | ChatComputeFailure(struct cm_exact *ex) | 
 | { | { | 
 | const int     len = strlen(ex->pat); | const int     len = strlen(ex->pat); | 
 | int           i, j, k; | int           i, j, k; | 
| Line 1662  ChatComputeFailure(ChatInfo c, struct cm_exact *ex) | Line 1665  ChatComputeFailure(ChatInfo c, struct cm_exact *ex) | 
 | */ | */ | 
 |  |  | 
 | static int | static int | 
| ChatDecodeTime(ChatInfo c, char *string, u_int *secsp) | ChatDecodeTime(ChatInfo c, const char *string, u_int *secsp) | 
 | { | { | 
 | u_long        secs; | u_long        secs; | 
 | char          *secstr, *mark; | char          *secstr, *mark; | 
| Line 1695  ChatReadLine(ChatInfo c) | Line 1698  ChatReadLine(ChatInfo c) | 
 | */ | */ | 
 |  |  | 
 | static int | static int | 
| ChatParseLine(ChatInfo c, char *line, char *av[], int max) | ChatParseLine(char *line, char *av[], int max) | 
 | { | { | 
 | return ParseLine(line, av, max, 1); | return ParseLine(line, av, max, 1); | 
 | } | } |