bkruse: branch asterisknow r1397 - in /branches/asterisknow: ./ tools/ztscan.c

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Mon Aug 20 16:12:20 CDT 2007


Author: bkruse
Date: Mon Aug 20 16:12:19 2007
New Revision: 1397

URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=1397
Log:
Merged revisions 1395 via svnmerge from 
https://origsvn.digium.com/svn/asterisk-gui/branches/1.4

........
r1395 | bkruse | 2007-08-20 16:10:50 -0500 (Mon, 20 Aug 2007) | 8 lines

Some More Chanes for ztscan:

[1] Added capability to pass the file pointer to readline.
[2] Added readline's helper function "trim".
[3] Made the check for totalchans <23 and >32 instead of != 24 and != 31.
[4] Added the ability to see if ztscan.conf already existed, if it did
not previously exist, then we set isnew = 1 for the GUI to see.

........

Modified:
    branches/asterisknow/   (props changed)
    branches/asterisknow/tools/ztscan.c

Propchange: branches/asterisknow/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Aug 20 16:12:19 2007
@@ -1,1 +1,1 @@
-/branches/1.4:1-1296,1316,1326,1332,1336-1338,1342,1346,1356,1362,1381,1384
+/branches/1.4:1-1296,1316,1326,1332,1336-1338,1342,1346,1356,1362,1381,1384,1395

Modified: branches/asterisknow/tools/ztscan.c
URL: http://svn.digium.com/view/asterisk-gui/branches/asterisknow/tools/ztscan.c?view=diff&rev=1397&r1=1396&r2=1397
==============================================================================
--- branches/asterisknow/tools/ztscan.c (original)
+++ branches/asterisknow/tools/ztscan.c Mon Aug 20 16:12:19 2007
@@ -39,16 +39,22 @@
 #include <zaptel/zaptel.h>
 #include <zaptel/tonezone.h>
 #endif
+#define CONFIG_FILE "/etc/asterisk/ztscan.conf"
 
 static int debug = 0;
-
+static char *filename = CONFIG_FILE;
+static char *cf;
 static int ctl = -1;
+static int lineno = 0;
+static int isnew = -1;
 
 /* Great, now for the ztscan specific functions and vars */
 
 int scanspans();
 int show_help();
 static char *getalarms(int span, int secondround);
+static char *readline();
+static void trim(char *buf);
 char *facs[] = { "esf,b8zs", "d4,ami", "cas,ami", "ccs,hdb3", "ccs,crc4,hdb3", 0};
 static ZT_SPANINFO s[ZT_MAX_SPANS];
 
@@ -59,6 +65,32 @@
 {
 	printf("Usage: ztscan\tDesc: Scans for spans, then writes them to ztscan.conf, for the GUI to parse and setup\n");
 	return 0;
+}
+
+/* Helper function for readline */
+static void trim(char *buf)
+{
+	/* Trim off trailing spaces, tabs, etc */
+	while(strlen(buf) && (buf[strlen(buf) -1] < 33))
+		buf[strlen(buf) -1] = '\0';
+}
+
+/* Basic function used to parse files. */
+static char *readline(FILE *conf)
+{
+	static char buf[256];
+	char *c;
+	do {
+		if (!fgets(buf, sizeof(buf), conf)) 
+			return NULL;
+		/* Strip comments */
+		c = strchr(buf, '#');
+		if (c)
+			*c = '\0';
+		trim(buf);
+		lineno++;
+	} while (!strlen(buf));
+	return buf;
 }
 
 /* Function that accesses returns the information about a specific span, using /dev/zap/ctl ioctl */
@@ -78,7 +110,7 @@
 		return NULL;
 	}
 	/* If this is not a digital card, skip it. */
-	if(s[span].totalchans != 24 || s[span].totalchans != 31) 
+	if(s[span].totalchans <= 23 || s[span].totalchans >= 32) 
 		return NULL;
 
 	strcpy(alarms, "");
@@ -120,7 +152,8 @@
 	int res = -1;
 	int hasgeneral = 0;
 	char *ret;
-	FILE *conf = fopen("/etc/asterisk/ztscan.conf", "w");
+	FILE *conf_check = fopen(CONFIG_FILE, "r");
+	FILE *conf = fopen(CONFIG_FILE, "w");
 	s[span].spanno = span;
 
 	if(!ctl) {
@@ -135,6 +168,10 @@
 		return 0;
 	}
 
+	if(!conf_check) {
+		/* ztscan.conf did not previously exist.  */
+		isnew = 1;
+	}
 	if(!conf) {
 		printf("cannot open config file /etc/asterisk/ztscan.conf for writing\n");
 		exit(1);
@@ -145,7 +182,7 @@
 		ret = getalarms(x, 0);	
 		if(ret) {
 			if(hasgeneral != 1) {
-				fprintf(conf, "[general]\ntotalspans=%d\ncontinue=yes\n\n", s[x].totalspans);
+				fprintf(conf, "[general]\ntotalspans=%d\ncontinue=yes\nisnew=%s\n", s[x].totalspans, (isnew == 1) ? "yes" : "no");
 				hasgeneral++;
 			}
 




More information about the asterisk-gui-commits mailing list