remove trailing spaces properly!
[spider.git] / src / client.c
index b50514fa618f47bb0895bbdb61977ac1c43d0402..fb7e5c137ccd12711061bf054882eb8f193a4e05 100644 (file)
@@ -44,7 +44,9 @@
 #define MAXPATHLEN 256
 #endif
 
+#define DEFPACLEN 128
 #define MAXPACLEN 236
+
 #define DBUF 1
 #define DMSG 2
 
@@ -84,15 +86,27 @@ char echo = 1;                                      /* echo characters on stdout from stdin */
 char int_tabs = 0;                             /* interpret tabs -> spaces */
 char *root = "/spider";         /* root of data tree, can be overridden by DXSPIDER_ROOT  */
 int timeout = 60;                              /* default timeout for logins and things */
-int paclen = 128;                              /* default buffer size for outgoing packets */
+int paclen = DEFPACLEN;                        /* default buffer size for outgoing packets */
 int tabsize = 8;                               /* default tabsize for text messages */
 
 myregex_t iscallreg[] = {              /* regexes to determine whether this is a reasonable callsign */
        {
-               "^[A-Z]+[0-9]+[A-Z]+", 0
+               "^[A-Z]+[0-9]+[A-Z]+[1-9]?$", 0
+       },
+       {
+               "^[0-9]+[A-Z]+[0-9]+[A-Z]+[1-9]?$", 0
+       },
+       {
+               "^[A-Z]+[0-9]+[A-Z]+[1-9]?-[1-9]$", 0
+       },
+       {
+               "^[0-9]+[A-Z]+[0-9]+[A-Z]+[1-9]?-[1-9]$", 0
        },
        {
-               "^[0-9]+[A-Z]+[0-9]+[A-Z]+", 0
+               "^[A-Z]+[0-9]+[A-Z]+[1-9]?-1[0-5]$", 0
+       },
+       {
+               "^[0-9]+[A-Z]+[0-9]+[A-Z]+[1-9]?-1[0-5]$", 0
        },
        {
                0, 0
@@ -198,6 +212,10 @@ void send_text(fcb_t *f, char *s, int l)
                f->obuf = mp = cmsg_new(paclen+1, f->sort, f);
        }
 
+       /* ignore trailing spaces  */
+       while (l > 0 &&isspace(s[l-1]))
+               --l;
+
        for (p = s; p < s+l; ) {
                if (mp->inp >= mp->data + paclen) {
                        flush_text(f);
@@ -488,6 +506,11 @@ lerr:
                nl = '\n';
                echo = 1;
        }
+
+       /* this is kludgy, but hey so is the rest of this! */
+       if (!eq(connsort, "ax25") && paclen == DEFPACLEN) {
+               paclen = MAXPACLEN;
+       }
 }
 
 void connect_to_node()
@@ -707,9 +730,11 @@ main(int argc, char *argv[])
                }
                buf[r] = 0;
                call = strupper(buf);
-               if (!iscallsign(call)) {
-                       die("Sorry, %s isn't a valid callsign", buf);
-               }
+       }
+
+       /* check the callsign */
+       if (!iscallsign(call)) {
+               die("Sorry, %s isn't a valid callsign", call);
        }
        
        /* connect up stdin */