'-f' flag is working now.
[mdsms.git] / mdsms.c
diff --git a/mdsms.c b/mdsms.c
index 48eb8f5..39a9c03 100644 (file)
--- a/mdsms.c
+++ b/mdsms.c
@@ -5,6 +5,18 @@ static char rcsid[] ATTR_UNUSED = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.7  1999/07/29 14:39:38  short
+ * '-f' flag is working now.
+ *
+ * Revision 1.6  1999/07/28 10:46:37  short
+ * Removed strict converting/checking of symbol characters to '?'.
+ *
+ * Revision 1.5  1999/07/19 10:02:51  short
+ * Removed '\xXY' chars for compatibility with Digital UNIX vendor "cc".
+ *
+ * Revision 1.4  1999/07/14 01:01:11  short
+ * Termios made compatible with Digital UNIX 4.0, cfset[io]speed() missing.
+ *
  * Revision 1.3  1999/06/03 11:46:41  short
  * Logging (--log) implemented.
  *
@@ -84,7 +96,7 @@ static size_t bodylen;
 static char *devicename; /* path stripped */
 static char lockreal[512],locked;
 
-static struct termios restios;
+static struct termios restios,tios;
 static char restios_yes;
 static FILE *logf;
 
@@ -712,18 +724,19 @@ static char *pdudata;
 
 static inline unsigned char charconv(char c,size_t offs)
 {
-       if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')) return(c);
        switch (c) {
                case '@': return(0);
                case '$': return(2);
-               case '"': return(96);
-               case ' ':
-                       return(c);
                case 0: assert(0);
+               default:
+                       return(c&0x7F);
                }
+#if 0
+       if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')) return(c);
        error("Can't convert character '%c' (0x%02X) at offs %d (0-based), substituted '?'",
                c,(unsigned char)c,offs);
        return('?');
+#endif
 }
 
 static inline void genpdu(void)
@@ -787,7 +800,6 @@ char *s,*finame;
 FILE *fin;
 int i;
 unsigned fatal=0;
-struct termios tios;
 
        if ((s=strrchr((pname=*argv),'/'))) pname=s+1;
        atexit(cleanup);
@@ -825,19 +837,28 @@ char *buf=malloc(l+50);
                finame=body;
                body=NULL;
                }
-       else fin=stdin;
+       else {
+               finame=NULL;
+               fin=stdin;
+               }
        if (!body) {
                readbody=0;
-               if (verbose>=1)
-                       error("\nPlease enter the SMS text body, end with EOF (ctrl-D):");
+               if (!finame) {
+                       if (verbose>=1)
+                               error("\nPlease enter the SMS text body, end with EOF (ctrl-D):");
+                       }
+               else {
+                       if (!(fin=fopen(finame,"rt")))
+                               error("!Can't open data file \"%s\" for r/o: %m",finame);
+                       }
                chk(body=malloc(BODYLOAD));
                bodylen=fread(body,1,BODYLOAD,fin);
                if (bodylen==-1)
                        error("!Error reading stream \"%s\": %m",(finame?finame:"<stdin>"));
-               }
-       if (fin!=stdin) {
-               chkfclose(fin,finame);
-               free(finame);
+               if (finame) {
+                       chkfclose(fin,finame);
+                       free(finame);
+                       }
                }
 
        for (i=0;i<NELEM(numarg);i++) {
@@ -902,19 +923,22 @@ time_t start,end;
        memset(tios.c_cc,_POSIX_VDISABLE,sizeof(tios.c_cc));
        tios.c_cc[VTIME]=0;
        tios.c_cc[VMIN ]=1;
+           cfsetispeed(&tios,B19200);
+       if (cfsetospeed(&tios,B19200)|cfsetispeed(&tios,B19200))
+               error("Error setting termios baudrate on device: %m");
        if (tcflush(devfd,TCIOFLUSH))
                error("Error flushing termios (TCIOFLUSH) on device: %m");
        if (tcsetattr(devfd,TCSANOW,&tios))
-               error("!Unable to set initial termios device settings");
+               error("!Unable to set initial termios device settings: %m");
 
        signal(SIGALRM,(RETSIGTYPE (*)(int))sigalarm);
        do {
-               devcmd("",NULL,"\r\nAT\x1A");
+               devcmd("",NULL,"\r\nAT\032");
                devcmd(NULL,NULL,"\r\nAT");
                smscset();
                devcmd(NULL,NULL,"\r\nAT+CMGF=0");
                devcmd("\n> ",NULL,"\r\nAT+CMGS=%d",(strlen(pdusmsc)+strlen(pdudata))/2);
-               if (!(s=devcmd(NULL,"\n+CMGS:","!%s%s\x1A",pdusmsc,pdudata))) retrying();
+               if (!(s=devcmd(NULL,"\n+CMGS:","!%s%s\032",pdusmsc,pdudata))) retrying();
                } while (!s);
        while (isspace(*s)) s++;
        if (verbose>=1) error("\nMessage successfuly sent with MR: %s",s);