summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pttbbs/common/sys/string.c21
-rw-r--r--pttbbs/include/cmsys.h259
-rw-r--r--pttbbs/mbbsd/ordersong.c2
3 files changed, 152 insertions, 130 deletions
diff --git a/pttbbs/common/sys/string.c b/pttbbs/common/sys/string.c
index 80dda509..da35cfea 100644
--- a/pttbbs/common/sys/string.c
+++ b/pttbbs/common/sys/string.c
@@ -90,6 +90,27 @@ strip_blank(char *cbuf, const char *buf)
return 0;
}
+int
+reduce_blank(char *cbuf, const char *buf) {
+ char *obuf = cbuf;
+ int need_remove;
+ for (need_remove = 1; *buf; buf++) {
+ if (isascii(*buf) && isblank(*buf)) {
+ if (need_remove)
+ continue;
+ need_remove = 1;
+ } else {
+ need_remove = 0;
+ }
+ *cbuf++ = *buf;
+ }
+ // in the end, remove trailing spaces.
+ if (cbuf > obuf && *(cbuf-1) == ' ')
+ cbuf --;
+ *cbuf = 0;
+ return 0;
+}
+
static const char EscapeFlag[] = {
/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0,
diff --git a/pttbbs/include/cmsys.h b/pttbbs/include/cmsys.h
index 17f9fbe6..b64e18b1 100644
--- a/pttbbs/include/cmsys.h
+++ b/pttbbs/include/cmsys.h
@@ -42,101 +42,102 @@ typedef time_t time4_t;
#endif
/* crypt.c */
-extern char *fcrypt(const char *key, const char *salt);
+char *fcrypt(const char *key, const char *salt);
/* daemon.c */
-extern int daemonize(const char * pidfile, const char * logfile);
+int daemonize(const char * pidfile, const char * logfile);
/* file.c */
-extern off_t dashs(const char *fname);
-extern time4_t dasht(const char *fname);
-extern time4_t dashc(const char *fname);
-extern int dashl(const char *fname);
-extern int dashf(const char *fname);
-extern int dashd(const char *fname);
-extern int copy_file_to_file(const char *src, const char *dst);
-extern int copy_file_to_dir(const char *src, const char *dst);
-extern int copy_dir_to_dir(const char *src, const char *dst);
-extern int copy_file(const char *src, const char *dst);
-extern int Rename(const char *src, const char *dst);
-extern int Copy(const char *src, const char *dst);
-extern int CopyN(const char *src, const char *dst, int n);
-extern int AppendTail(const char *src, const char *dst, int off);
-extern int Link(const char *src, const char *dst);
-extern int HardLink(const char *src, const char *dst);
-extern int Mkdir(const char *path);
-extern int OpenCreate(const char *path, int flags);
-extern int file_count_line(const char *file);
-extern int file_append_line(const char *file, const char *string); // does not append "\n"
-extern int file_append_record(const char *file, const char *key); // will append "\n"
-extern int file_exist_record(const char *file, const char *key);
-extern int file_find_record(const char *file, const char *key);
-extern int file_delete_record(const char *file, const char *key, int case_sensitive);
+off_t dashs(const char *fname);
+time4_t dasht(const char *fname);
+time4_t dashc(const char *fname);
+int dashl(const char *fname);
+int dashf(const char *fname);
+int dashd(const char *fname);
+int copy_file_to_file(const char *src, const char *dst);
+int copy_file_to_dir(const char *src, const char *dst);
+int copy_dir_to_dir(const char *src, const char *dst);
+int copy_file(const char *src, const char *dst);
+int Rename(const char *src, const char *dst);
+int Copy(const char *src, const char *dst);
+int CopyN(const char *src, const char *dst, int n);
+int AppendTail(const char *src, const char *dst, int off);
+int Link(const char *src, const char *dst);
+int HardLink(const char *src, const char *dst);
+int Mkdir(const char *path);
+int OpenCreate(const char *path, int flags);
+int file_count_line(const char *file);
+int file_append_line(const char *file, const char *string); // does not append "\n"
+int file_append_record(const char *file, const char *key); // will append "\n"
+int file_exist_record(const char *file, const char *key);
+int file_find_record(const char *file, const char *key);
+int file_delete_record(const char *file, const char *key, int case_sensitive);
/* lock.c */
-extern void PttLock(int fd, int start, int size, int mode);
+void PttLock(int fd, int start, int size, int mode);
/* net.c */
-extern uint32_t ipstr2int(const char *ip);
-extern int tobind (const char *addr);
-extern int tobindex (const char *addr, int qlen, int (*setsock)(int), int do_listen);
-extern int toconnect(const char *addr);
-extern int toconnectex(const char *addr, int timeout);
-extern int toread (int fd, void *buf, int len);
-extern int towrite (int fd, const void *buf, int len);
-extern int torecv (int fd, void *buf, int len, int flag);
-extern int tosend (int fd, const void *buf, int len, int flag);
-extern int send_remote_fd(int tunnel, int fd);
-extern int recv_remote_fd(int tunnel, const char *tunnel_path);
+uint32_t ipstr2int(const char *ip);
+int tobind (const char *addr);
+int tobindex (const char *addr, int qlen, int (*setsock)(int), int do_listen);
+int toconnect(const char *addr);
+int toconnectex(const char *addr, int timeout);
+int toread (int fd, void *buf, int len);
+int towrite (int fd, const void *buf, int len);
+int torecv (int fd, void *buf, int len, int flag);
+int tosend (int fd, const void *buf, int len, int flag);
+int send_remote_fd(int tunnel, int fd);
+int recv_remote_fd(int tunnel, const char *tunnel_path);
/* sort.c */
-extern int cmp_int(const void *a, const void *b);
-extern int cmp_int_desc(const void * a, const void * b);
-extern int *intbsearch(int key, const int *base0, int nmemb);
-extern unsigned int *uintbsearch(const unsigned int key, const unsigned int *base0, const int nmemb);
+int cmp_int(const void *a, const void *b);
+int cmp_int_desc(const void * a, const void * b);
+int *intbsearch(int key, const int *base0, int nmemb);
+unsigned int *uintbsearch(const unsigned int key, const unsigned int *base0, const int nmemb);
/* string.h */
-extern void str_lower(char *t, const char *s);
-extern int str_starts_with(const char *str, const char *prefix);
-extern int str_case_starts_with(const char *str, const char *prefix);
-extern void trim(char *buf);
-extern void chomp(char *src);
-extern int strlen_noansi(const char *s);
-extern int strat_ansi(int count, const char *s);
-extern int strip_blank(char *cbuf, const char *buf);
-extern int strip_ansi(char *buf, const char *str, enum STRIP_FLAG flag);
-extern void strip_nonebig5(unsigned char *str, int maxlen);
-extern int invalid_pname(const char *str);
-extern int is_number(const char *p);
-extern char * qp_encode (char *s, size_t slen, const char *d, const char *tocode);
-extern unsigned StringHash(const char *s);
+void str_lower(char *t, const char *s);
+int str_starts_with(const char *str, const char *prefix);
+int str_case_starts_with(const char *str, const char *prefix);
+void trim(char *buf);
+void chomp(char *src);
+int strlen_noansi(const char *s);
+int strat_ansi(int count, const char *s);
+int strip_blank(char *cbuf, const char *buf);
+int reduce_blank(char *cbuf, const char *buf);
+int strip_ansi(char *buf, const char *str, enum STRIP_FLAG flag);
+void strip_nonebig5(unsigned char *str, int maxlen);
+int invalid_pname(const char *str);
+int is_number(const char *p);
+char * qp_encode (char *s, size_t slen, const char *d, const char *tocode);
+unsigned StringHash(const char *s);
/* DBCS utilities */
-extern int DBCS_RemoveIntrEscape(unsigned char *buf, int *len);
-extern int DBCS_NextStatus(char c, int prev_status);
-extern int DBCS_Status(const char *dbcstr, int pos);
-extern void DBCS_safe_trim(char *dbcstr);
-extern char * DBCS_strcasestr(const char* pool, const char *ptr);
-extern int DBCS_strncasecmp(const char *s1, const char *s2, size_t len);
+int DBCS_RemoveIntrEscape(unsigned char *buf, int *len);
+int DBCS_NextStatus(char c, int prev_status);
+int DBCS_Status(const char *dbcstr, int pos);
+void DBCS_safe_trim(char *dbcstr);
+char * DBCS_strcasestr(const char* pool, const char *ptr);
+int DBCS_strncasecmp(const char *s1, const char *s2, size_t len);
#define HAVE_DBCS_STRCASESTR
#define HAVE_DBCS_STRNCASECMP
-extern size_t str_iconv(
+size_t str_iconv(
const char *fromcode, /* charset of source string */
const char *tocode, /* charset of destination string */
const char *src, /* source string */
size_t srclen, /* source string length */
char *dst, /* destination string */
size_t dstlen);
-extern void str_decode_M3(char *str);
+void str_decode_M3(char *str);
/* time.c */
-extern int is_leap_year(int year);
-extern int getHoroscope(int m, int d);
-extern const char* Cdate(const time4_t *clock);
-extern const char* Cdatelite(const time4_t *clock);
-extern const char* Cdatedate(const time4_t * clock);
-extern const char * Cdate_md(const time4_t * clock);
-extern const char * Cdate_mdHM(const time4_t * clock);
-extern const char * Cdate_mdHMS(const time4_t * clock);
+int is_leap_year(int year);
+int getHoroscope(int m, int d);
+const char* Cdate(const time4_t *clock);
+const char* Cdatelite(const time4_t *clock);
+const char* Cdatedate(const time4_t * clock);
+const char * Cdate_md(const time4_t * clock);
+const char * Cdate_mdHM(const time4_t * clock);
+const char * Cdate_mdHMS(const time4_t * clock);
#ifdef TIMET64
struct tm* localtime4(const time4_t *);
@@ -152,26 +153,26 @@ extern const char * Cdate_mdHMS(const time4_t * clock);
#define ctime4_r(a) ctime_r(a)
#endif
-extern int log_filef(const char *fn, int flag, const char *fmt,...) GCC_CHECK_FORMAT(3,4);
-extern int log_file(const char *fn, int flag, const char *msg);
+int log_filef(const char *fn, int flag, const char *fmt,...) GCC_CHECK_FORMAT(3,4);
+int log_file(const char *fn, int flag, const char *msg);
/* record.c */
-extern int get_num_records(const char *fpath, size_t size);
-extern int get_records_keep(const char *fpath, void *rptr, size_t size, int id, size_t number, int *fd);
-extern int get_records(const char *fpath, void *rptr, size_t size, int id, size_t number);
+int get_num_records(const char *fpath, size_t size);
+int get_records_keep(const char *fpath, void *rptr, size_t size, int id, size_t number, int *fd);
+int get_records(const char *fpath, void *rptr, size_t size, int id, size_t number);
#define get_record(fpath, rptr, size, id) get_records(fpath, rptr, size, id, 1)
#define get_record_keep(fpath, rptr, size, id, fd) get_records_keep(fpath, rptr, size, id, 1, fd)
-extern int apply_record(const char *fpath, int (*fptr) (void *item, void *optarg), size_t size, void *arg);
-extern int append_record(const char *fpath, const void *record, size_t size);
-extern int delete_records(const char *fpath, size_t size, int id, size_t num);
-extern int substitute_record(const char *fpath, const void *rptr, size_t size, int id);
+int apply_record(const char *fpath, int (*fptr) (void *item, void *optarg), size_t size, void *arg);
+int append_record(const char *fpath, const void *record, size_t size);
+int delete_records(const char *fpath, size_t size, int id, size_t num);
+int substitute_record(const char *fpath, const void *rptr, size_t size, int id);
#define delete_record(fpath, size, id) delete_records(fpath, size, id, 1)
typedef int (*record_callback_t)(const void *ptr1, const void *ptr2);
-extern int substitute_record2(const char *fpath,
+int substitute_record2(const char *fpath,
const void *srcptr, const void *destptr,
size_t size, int id,
record_callback_t cb_can_substitue);
-extern int delete_record2(const char *fpath, const void *rptr, size_t size,
+int delete_record2(const char *fpath, const void *rptr, size_t size,
int id, record_callback_t cb_can_substitue);
/* vector.c */
@@ -183,19 +184,19 @@ struct Vector {
bool constant;
};
-extern void Vector_init(struct Vector *self, const int size);
-extern void Vector_init_const(struct Vector *self, char * base, const int length, const int size);
-extern void Vector_delete(struct Vector *self);
-extern void Vector_clear(struct Vector *self, const int size);
-extern int Vector_length(const struct Vector *self);
-extern void Vector_resize(struct Vector *self, const int length);
-extern void Vector_add(struct Vector *self, const char *name);
-extern const char* Vector_get(const struct Vector *self, const int idx);
-extern int Vector_MaxLen(const struct Vector *list, const int offset, const int count);
-extern int Vector_match(const struct Vector *src, struct Vector *dst, const int key, const int pos);
-extern void Vector_sublist(const struct Vector *src, struct Vector *dst, const char *tag);
-extern int Vector_remove(struct Vector *self, const char *name);
-extern int Vector_search(const struct Vector *self, const char *name);
+void Vector_init(struct Vector *self, const int size);
+void Vector_init_const(struct Vector *self, char * base, const int length, const int size);
+void Vector_delete(struct Vector *self);
+void Vector_clear(struct Vector *self, const int size);
+int Vector_length(const struct Vector *self);
+void Vector_resize(struct Vector *self, const int length);
+void Vector_add(struct Vector *self, const char *name);
+const char* Vector_get(const struct Vector *self, const int idx);
+int Vector_MaxLen(const struct Vector *list, const int offset, const int count);
+int Vector_match(const struct Vector *src, struct Vector *dst, const int key, const int pos);
+void Vector_sublist(const struct Vector *src, struct Vector *dst, const char *tag);
+int Vector_remove(struct Vector *self, const char *name);
+int Vector_search(const struct Vector *self, const char *name);
/* vbuf.c */
typedef struct VBUF {
@@ -214,40 +215,40 @@ typedef struct VBUF {
#define vbuf_space(v) ((size_t)((v)->capacity - vbuf_size(v)))
#define vbuf_peek(v) (vbuf_is_empty(v) ? EOF : (unsigned char)(*v->head))
// buffer management
-extern void vbuf_new (VBUF *v, size_t szbuf);
-extern void vbuf_delete(VBUF *v);
-extern void vbuf_attach(VBUF *v, char *buf, size_t szbuf);
-extern void vbuf_detach(VBUF *v);
-extern void vbuf_clear (VBUF *v);
+void vbuf_new (VBUF *v, size_t szbuf);
+void vbuf_delete(VBUF *v);
+void vbuf_attach(VBUF *v, char *buf, size_t szbuf);
+void vbuf_detach(VBUF *v);
+void vbuf_clear (VBUF *v);
// data accessing
-extern int vbuf_getblk(VBUF *v, void *p, size_t sz); // get data from vbuf, return true/false
-extern int vbuf_putblk(VBUF *v, const void *p, size_t sz); // put data into vbuf, return true/false
-extern int vbuf_peekat(VBUF *v, int i); // peek at given index, EOF(-1) if invalid index
-extern int vbuf_pop (VBUF *v); // pop one byte from vbuf, EOF(-1) if buffer empty
-extern int vbuf_add (VBUF *v, char c); // append one byte into vbuf, return true/false
-extern void vbuf_popn (VBUF *v, size_t n); // pop (remove) n bytes from vbuf
+int vbuf_getblk(VBUF *v, void *p, size_t sz); // get data from vbuf, return true/false
+int vbuf_putblk(VBUF *v, const void *p, size_t sz); // put data into vbuf, return true/false
+int vbuf_peekat(VBUF *v, int i); // peek at given index, EOF(-1) if invalid index
+int vbuf_pop (VBUF *v); // pop one byte from vbuf, EOF(-1) if buffer empty
+int vbuf_add (VBUF *v, char c); // append one byte into vbuf, return true/false
+void vbuf_popn (VBUF *v, size_t n); // pop (remove) n bytes from vbuf
// search and test
-extern int vbuf_strchr(VBUF *v, char c); // index of first location of c, otherwise EOF(-1)
+int vbuf_strchr(VBUF *v, char c); // index of first location of c, otherwise EOF(-1)
// vector of C-style NULL terminated strings
-extern char* vbuf_getstr(VBUF *v, char *s, size_t sz); // get a string from vbuf, return NULL if empty
-extern int vbuf_putstr(VBUF *v, const char *s); // put a string to vbuf (with NUL), return true/false
-extern char *vbuf_cstr (VBUF *v); // return flattern (unwrap) buffer and pad NUL, or NULL if empty.
+char* vbuf_getstr(VBUF *v, char *s, size_t sz); // get a string from vbuf, return NULL if empty
+int vbuf_putstr(VBUF *v, const char *s); // put a string to vbuf (with NUL), return true/false
+char *vbuf_cstr (VBUF *v); // return flattern (unwrap) buffer and pad NUL, or NULL if empty.
#define VBUF_RWSZ_ALL (0) // r/w until buffer full
#define VBUF_RWSZ_MIN (-1) // r/w for minimal try (do not block for more)
// following APIs take VBUF_RWSZ_* in their sz parameter.
-extern ssize_t vbuf_read (VBUF *v, int fd, ssize_t sz); // read from fd to vbuf
-extern ssize_t vbuf_write(VBUF *v, int fd, ssize_t sz); // write from vbuf to fd
-extern ssize_t vbuf_send (VBUF *v, int fd, ssize_t sz, int flags);
-extern ssize_t vbuf_recv (VBUF *v, int fd, ssize_t sz, int flags);
+ssize_t vbuf_read (VBUF *v, int fd, ssize_t sz); // read from fd to vbuf
+ssize_t vbuf_write(VBUF *v, int fd, ssize_t sz); // write from vbuf to fd
+ssize_t vbuf_send (VBUF *v, int fd, ssize_t sz, int flags);
+ssize_t vbuf_recv (VBUF *v, int fd, ssize_t sz, int flags);
// write from vbuf to writer (writer should return -1 for EOF/error, 0 for EAGAIN)
-extern ssize_t vbuf_general_write(VBUF *v, ssize_t sz, void *ctx,
+ssize_t vbuf_general_write(VBUF *v, ssize_t sz, void *ctx,
ssize_t (writer)(struct iovec[2], void *ctx));
// read from reader to vbuf (reader should return -1 for EOF/error, 0 for EAGAIN)
-extern ssize_t vbuf_general_read (VBUF *v, ssize_t sz, void *ctx,
+ssize_t vbuf_general_read (VBUF *v, ssize_t sz, void *ctx,
ssize_t (reader)(struct iovec[2], void *ctx));
/* telnet.c */
@@ -282,24 +283,24 @@ struct TelnetCtx {
};
typedef struct TelnetCtx TelnetCtx;
-extern TelnetCtx *telnet_create_context(void);
-extern void telnet_free_context (TelnetCtx *ctx);
+TelnetCtx *telnet_create_context(void);
+void telnet_free_context (TelnetCtx *ctx);
-extern void telnet_ctx_init (TelnetCtx *ctx, const struct TelnetCallback *callback, int fd);
-extern void telnet_ctx_send_init_cmds(TelnetCtx *ctx);
+void telnet_ctx_init (TelnetCtx *ctx, const struct TelnetCallback *callback, int fd);
+void telnet_ctx_send_init_cmds(TelnetCtx *ctx);
-extern void telnet_ctx_set_cc_arg (TelnetCtx *ctx, void *arg);
-extern void telnet_ctx_set_write_arg (TelnetCtx *ctx, void *arg);
-extern void telnet_ctx_set_resize_arg(TelnetCtx *ctx, void *arg);
-extern void telnet_ctx_set_ayt_arg (TelnetCtx *ctx, void *arg);
-extern void telnet_ctx_set_ttype_arg (TelnetCtx *ctx, void *arg);
+void telnet_ctx_set_cc_arg (TelnetCtx *ctx, void *arg);
+void telnet_ctx_set_write_arg (TelnetCtx *ctx, void *arg);
+void telnet_ctx_set_resize_arg(TelnetCtx *ctx, void *arg);
+void telnet_ctx_set_ayt_arg (TelnetCtx *ctx, void *arg);
+void telnet_ctx_set_ttype_arg (TelnetCtx *ctx, void *arg);
-extern ssize_t telnet_process (TelnetCtx *ctx, unsigned char *buf, ssize_t size);
+ssize_t telnet_process (TelnetCtx *ctx, unsigned char *buf, ssize_t size);
#ifdef CONVERT
/* utf8.c */
-extern int ucs2utf(uint16_t ucs2, uint8_t *utf8);
-extern int utf2ucs(uint8_t *utf8, uint16_t *pucs);
+int ucs2utf(uint16_t ucs2, uint8_t *utf8);
+int utf2ucs(uint8_t *utf8, uint16_t *pucs);
/* big5.c */
extern const uint16_t b2u_table[];
diff --git a/pttbbs/mbbsd/ordersong.c b/pttbbs/mbbsd/ordersong.c
index b4e146e0..5ae7f769 100644
--- a/pttbbs/mbbsd/ordersong.c
+++ b/pttbbs/mbbsd/ordersong.c
@@ -102,7 +102,7 @@ do_order_song(void)
do {
getdata(21, 0, "想要要對他(她)說..:", say, sizeof(say), DOECHO);
- strip_blank(say, say);
+ reduce_blank(say, say);
if (!say[0]) {
bell();
mvouts(22, 0, "請重新輸入想說的內容");