Implemented RTS/CTS handshaking (-C/--rtscts vs. -x/--xonxoff)
[mdsms.git] / mdsms.c
diff --git a/mdsms.c b/mdsms.c
index a630131..ccd9d5c 100644 (file)
--- a/mdsms.c
+++ b/mdsms.c
@@ -316,7 +316,8 @@ static const struct option longopts[]={
 {"file"    ,0,0,'f'},
 {"verbose" ,0,0,'v'},
 {"help"    ,0,0,'h'},
-{"version" ,0,0,'V'}};
+{"version" ,0,0,'V'},
+{NULL      ,0,0,0  }};
 
 static void processargs(int argp,char **args,const char *from);
 
@@ -1256,19 +1257,19 @@ long size;
 
 #define WORD(n) (((unsigned char)buf[(n)])|(((unsigned char)buf[(n)+1])<<8))
 
-       if (!(f=fopen(logoname,"rb")))
-               error(_("^!Cannot open ring file \"%s\" for r/o"),logoname);
-       if ((size=getfilesize(f,logoname))==-1)
+       if (!(f=fopen(ringname,"rb")))
+               error(_("^!Cannot open ring file \"%s\" for r/o"),ringname);
+       if ((size=getfilesize(f,ringname))==-1)
                error(_("!File size determination is essential to continue operation"));
        if (size<0x103)
                error(_("!File \"%s\" size %ld too small (must >=0x103)! Is it .000 file?"),
-                       logoname,size);
+                       ringname,size);
        if (fseek(f,0x100,SEEK_SET))
-               error(_("^Seeking error on \"%s\", ignoring"),logoname);
+               error(_("^Seeking error on \"%s\", ignoring"),ringname);
        size-=0x100;
        if (size<=BIN1_PAYLOAD) {
                if ((got=fread(bin1+7,1,size,f))!=size)
-                       error(_("^Read error on \"%s\", wanted %ld, got %d"),logoname,size,got);
+                       error(_("^Read error on \"%s\", wanted %ld, got %d"),ringname,size,got);
                error(_("\nSending ring tone \"%s\" as single SMS (size %ld, max %d)"),
                        ringname,size,BIN1_PAYLOAD);
                nokiaprep(bin1,7+size);
@@ -1289,12 +1290,12 @@ long size;
                        binn[11]=fragn;
                        want=MIN(size,BINN_PAYLOAD);
                        if ((got=fread(binn+12,1,want,f))!=want)
-                               error(_("^Read error on \"%s\", wanted %d, got %d"),logoname,want,got);
+                               error(_("^Read error on \"%s\", wanted %d, got %d"),ringname,want,got);
                        nokiaprep(binn,12+want);
                        size-=want;
                        }
                }
-       chkfclose(f,logoname);
+       chkfclose(f,ringname);
 #undef WORD
 }
 
@@ -1703,7 +1704,7 @@ int inb,outb,xb;
                if (pdu[1]==ADDR_INT) *s++='+';
                else {
                        if (pdu[1]!=ADDR_NAT)
-                               error(_("Unknown address type 0x%02X of %s, ignoring in PDU: %s"),_("SMSC"),pdu[1],pduline); return;
+                               error(_("Unknown address type 0x%02X of %s, ignoring in PDU: %s"),pdu[1],_("SMSC"),pduline); return;
                        }
                if (teldecode(s,pdu+2,2*(*pdu-1)-((pdu[1+(*pdu)]&0xF0)==0xF0)))
                        error(_("Some digits unrecognized in %s \"%s\", ignoring in PDU: %s"),_("SMSC"),receive_smsc,pduline);
@@ -1722,7 +1723,7 @@ int inb,outb,xb;
        if (*pdup==ADDR_INT) *s++='+';
        else {
                if (*pdup!=ADDR_NAT)
-                       error(_("Unknown address type 0x%02X of %s, ignoring in PDU: %s"),_("originating number"),*pdup,pduline); return;
+                       error(_("Unknown address type 0x%02X of %s, ignoring in PDU: %s"),*pdup,_("originating number"),pduline); return;
                }
        pdup++;
        if (teldecode(s,pdup,oalen))
@@ -1752,9 +1753,9 @@ int inb,outb,xb;
 size_t udl1,udlb1;
 
                udlb1=pdue-pdup;
-               udl1=(udlb*8)/7;
+               udl1=(udlb1*8)/7;
                error(_("PDU data length (%d/7->%d/8) longer than data (%d), cut to %d/7->%d/8: %s"),
-                       udl,udlb,pdue-pdup,pduline);
+                       udl,udlb,pdue-pdup,udl1,udlb1,pduline);
                udl=udl1; udlb=udlb1;
                }
        else
@@ -1808,6 +1809,7 @@ int i,cmgf=-1 /* GCC happiness */;
 unsigned fatal=0;
 speed_t portbaud=0 /* GCC happiness */;
 enum modenum argsmode;
+unsigned parts=0;
 
        if ((s=strrchr((pname=*argv),'/'))) pname=s+1;
 
@@ -2029,11 +2031,12 @@ struct hexdata *hd;
 
                                restore="\r\nAT+CSMP=17,,0,0";
                                devcmd(NULL,NULL,"\r\nAT+CSMP=81,,0,245");
-                               devcmd("\n> ",NULL,"\r\nAT+CMGS=\"%s\"",phone);
                                while ((hd=hexdata)) {
+                                       devcmd("\n> ",NULL,"\r\nAT+CMGS=\"%s\"",phone);
                                        if (!(s=devcmd(NULL,"\n+CMGS:","!~%s\032",hd->data))) break;
-                                       hexdata=hd->next;
+                                       if ((hexdata=hd->next)) pushargstack_one(s,0);
                                        free(hd);
+                                       parts++;
                                        }
                                } break;
                        case MODE_RECEIVE:
@@ -2079,10 +2082,13 @@ struct hexdata *hd;
                        }
                if (!s) { retrying(); goto retryall; }
 
-       while (isspace(*s)) s++;
-       if (verbose>=1) error(_("\nMessage successfuly sent with MR (Message Reference): %s"),s);
+       pushargstack_one(s,0); s=NULL;
+       if (verbose>=1) while ((s=nextargstack())) {
+               while (isspace(*s)) s++;
+               error(_("\nMessage successfuly sent with MR (Message Reference): %s"),s);
+               }
        devcmd(NULL,NULL,"\r\nAT");
 
-       logmsg(_("SMS sent (after %d retries), message reference: %s"),retrycnt,s);
+       logmsg(_("SMS sent (after %d retries), %d part(s)"),retrycnt,parts);
        return(EXIT_SUCCESS);
 }