From 98f0d21ed8b091c7d09448addf3ce2b1b0e99ee6 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sat, 10 Nov 2012 06:54:00 +0200 Subject: [PATCH] removed debug output --- src/main.c | 2 +- src/pnpty.c | 44 ++++++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/main.c b/src/main.c index e2b283b..371cb83 100644 --- a/src/main.c +++ b/src/main.c @@ -344,7 +344,7 @@ static int cmdSMS (PnPty *pd, int argc, char *argv[]) { free(res); res = NULL; // - fprintf(stderr, "[%s]\n", msg); + //fprintf(stderr, "[%s]\n", msg); if (pnptySendSMSCommand(pd, argv[1], msg) < 0) { fprintf(stderr, "ERROR: SMS\n"); goto error; } } // diff --git a/src/pnpty.c b/src/pnpty.c index 9db9cfd..bf4e9ab 100644 --- a/src/pnpty.c +++ b/src/pnpty.c @@ -21,6 +21,10 @@ #include +//#define dlog(...) fprintf(stderr, __VA_ARGS) +#define dlog(...) + + //////////////////////////////////////////////////////////////////////////////// struct PnPty { int fd; @@ -214,7 +218,7 @@ char *pnptySendCommandVA (PnPty *pt, const char *fmt, va_list args) { return NULL; } // - fprintf(stderr, "sending: [%s]\n", s); + dlog("sending: [%s]\n", s); strcat(s, "\r"); sz = write(pt->fd, s, strlen(s)); if (buf != s) free(buf); @@ -249,13 +253,13 @@ char *pnptySendCommandVA (PnPty *pt, const char *fmt, va_list args) { } // msg = strerror(errno); - fprintf(stderr, "rd: %d; [%s]\n", rd, msg); + dlog("rd: %d; [%s]\n", rd, msg); free(buf); fprintf(stderr, "ERROR!\n"); return NULL; } if (buf[bufpos] == 0) buf[bufpos] = ' '; - //fprintf(stderr, "rd=%d; char=%d (%c)\n", rd, (unsigned char)(buf[bufpos]), (buf[bufpos] >= 32 && buf[bufpos] != 128 ? buf[bufpos] : '.')); + //dlog("rd=%d; char=%d (%c)\n", rd, (unsigned char)(buf[bufpos]), (buf[bufpos] >= 32 && buf[bufpos] != 128 ? buf[bufpos] : '.')); ++bufpos; // if (buf[bufpos-1] == '\n') { @@ -271,7 +275,7 @@ char *pnptySendCommandVA (PnPty *pt, const char *fmt, va_list args) { } // if (bufpos > 1 && buf[bufpos-2] == '\r') buf[(--bufpos)-1] = '\n'; - fprintf(stderr, "===\n%s===\n", buf); + dlog("===\n%s===\n", buf); buf[bufpos-1] = 0; if ((lastn = strrchr(buf, '\n')) == NULL) lastn = buf; else ++lastn; // @@ -285,7 +289,7 @@ char *pnptySendCommandVA (PnPty *pt, const char *fmt, va_list args) { buf[0] = 0; } trimemptylines(buf); - //fprintf(stderr, "===\n%s===\n", buf); + //dlog("===\n%s===\n", buf); break; } // @@ -298,7 +302,7 @@ char *pnptySendCommandVA (PnPty *pt, const char *fmt, va_list args) { } // if (err || strcmp(lastn, "ERROR") == 0) { - //fprintf(stderr, "===\n%s===\n", buf); + //dlog("===\n%s===\n", buf); buf[bufpos-1] = '\n'; memmove(buf+1, buf, strlen(buf)+1); buf[0] = '\1'; @@ -309,7 +313,7 @@ char *pnptySendCommandVA (PnPty *pt, const char *fmt, va_list args) { } } // - //fprintf(stderr, "DONE\n"); + //dlog("DONE\n"); return buf; } // @@ -345,7 +349,7 @@ static int skipLine (PnPty *pt, int dump) { } // msg = strerror(errno); - fprintf(stderr, "rd: %d; [%s]\n", rd, msg); + dlog("rd: %d; [%s]\n", rd, msg); fprintf(stderr, "ERROR!\n"); return -1; } @@ -368,7 +372,7 @@ int pnptySendSMSCommand (PnPty *pt, const char *number, const char *str) { int sz; // if (setNonBlock(pt->fd, 0) < 0) return -1; - //fprintf(stderr, "pnptySendSMSCommand: sending CMGS for '%s'\n", number); + //dlog("pnptySendSMSCommand: sending CMGS for '%s'\n", number); if ((sz = write(pt->fd, cmd0, strlen(cmd0))) < 0) return -1; if ((sz = write(pt->fd, number, strlen(number))) < 0) return -1; if ((sz = write(pt->fd, cmd1, strlen(cmd1))) < 0) return -1; @@ -377,7 +381,7 @@ int pnptySendSMSCommand (PnPty *pt, const char *number, const char *str) { if (setNonBlock(pt->fd, 1) < 0) return -1; // if (skipLine(pt, 0) < 0) return -1; - //fprintf(stderr, "reading '> '...\n"); + //dlog("reading '> '...\n"); reppos = 0; while (reppos < 2) { int rd; @@ -391,28 +395,28 @@ int pnptySendSMSCommand (PnPty *pt, const char *number, const char *str) { } // msg = strerror(errno); - fprintf(stderr, "rd: %d; [%s]\n", rd, msg); + dlog("rd: %d; [%s]\n", rd, msg); fprintf(stderr, "ERROR!\n"); return -1; } ++reppos; } // - //fprintf(stderr, "REP: '%c%c'\n", repbuf[0], repbuf[1]); + //dlog("REP: '%c%c'\n", repbuf[0], repbuf[1]); // if (repbuf[0] != '>' || repbuf[1] != ' ') { // invalid answer; read till EOL and return error - fprintf(stderr, "REP: '%c%c'\n", repbuf[0], repbuf[1]); + dlog("REP: '%c%c'\n", repbuf[0], repbuf[1]); skipLine(pt, 1); return -1; } // now send text - //fprintf(stderr, "sending text...\n"); + //dlog("sending text...\n"); if (setNonBlock(pt->fd, 0) < 0) return -1; if ((sz = write(pt->fd, str, strlen(str))) < 0) return -1; if ((sz = write(pt->fd, ctrlz, strlen(ctrlz))) < 0) return -1; // now read 'OK' - //fprintf(stderr, "reading reply...\n"); + //dlog("reading reply...\n"); if (setNonBlock(pt->fd, 1) < 0) return -1; if (skipLine(pt, 0) < 0) return -1; // skip echoed str reppos = 0; @@ -428,11 +432,11 @@ int pnptySendSMSCommand (PnPty *pt, const char *number, const char *str) { } // msg = strerror(errno); - fprintf(stderr, "rd: %d; [%s]\n", rd, msg); + dlog("rd: %d; [%s]\n", rd, msg); fprintf(stderr, "ERROR!\n"); return -1; } - //fprintf(stderr, "%c (%d)\n", (repbuf[reppos] > ' ' && repbuf[reppos] < 127 ? repbuf[reppos] : '.'), (unsigned int)(repbuf[reppos])); + //dlog("%c (%d)\n", (repbuf[reppos] > ' ' && repbuf[reppos] < 127 ? repbuf[reppos] : '.'), (unsigned int)(repbuf[reppos])); // here we should receive "+CMGS: 87" or so if (reppos == 0 && repbuf[0] != '+') { skipLine(pt, 1); @@ -440,13 +444,13 @@ int pnptySendSMSCommand (PnPty *pt, const char *number, const char *str) { } /* if (reppos == 0 && (repbuf[0] == '\n' || repbuf[0] == '\r')) { - fprintf(stderr, "%d skipped...\n", repbuf[0]); + dlog("%d skipped...\n", repbuf[0]); continue; // skip all newlines } */ if (repbuf[reppos] == '\n') { repbuf[reppos+1] = 0; - //fprintf(stderr, "SMSREP: %s", repbuf); + //dlog("SMSREP: %s", repbuf); if (strncmp(repbuf, "+CMGS: ", 7) != 0) { fprintf(stderr, "SMSERR: %s", repbuf); return -1; @@ -455,7 +459,7 @@ int pnptySendSMSCommand (PnPty *pt, const char *number, const char *str) { } if (reppos < sizeof(repbuf)-2) ++reppos; } - //fprintf(stderr, "SMS COMPLETE!\n"); + //dlog("SMS COMPLETE!\n"); skipLine(pt, 1); // this MUST be "OK"; we should check it, but... // return 0; -- 2.11.4.GIT