4 static int readln(int fd, char *buf, int buflen)
9 while ((i < buflen) && ((ret = read(fd, buf, 1)) > 0)) {
29 static inline char *killwhite(char *inbuf)
33 while(buf && ((*buf==' ') || (*buf=='\t'))) /* skip leading whitespace */
38 static inline char *nextwhite(char *inbuf)
51 int parsescriptline2(struct aim_session_t *sess, struct aim_conn_t **scriptconn, char *buf)
57 case '#': /* comment */
60 aim_conn_kill(sess, scriptconn);
62 case 'd': /* disconnect */
63 aim_conn_kill(sess, scriptconn);
67 case 'e': /* print to stderr */
68 buf = nextwhite(buf)+1;
69 fprintf(stderr, "%s\n", buf);
71 case 'm': /* message */
74 buf = nextwhite(buf)+1;
75 sn = strsep(&buf, "/");
76 msg = strsep(&buf, "/");
77 sendimtoclient(sess, aim_getconn_type(sess, AIM_CONN_TYPE_BOS), sn, 0, msg);
81 buf = nextwhite(buf)+1;
82 printf("sleeping for %d seconds\n", atoi(buf));
86 printf("unknown script command %c\n", buf[0]);
92 int parsescriptline(struct aim_session_t *sess, struct aim_conn_t **conn)
95 if (readln((*conn)->fd, buf, 255) > 0)
96 return parsescriptline2(sess, conn, buf);
98 aim_conn_kill(sess, conn);