bkruse: trunk r1396 - in /trunk: ./ tools/ztscan.c

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


Author: bkruse
Date: Mon Aug 20 16:11:37 2007
New Revision: 1396

URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=1396
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:
    trunk/   (props changed)
    trunk/tools/ztscan.c

Propchange: trunk/
------------------------------------------------------------------------------
--- branch-1.4-merged (original)
+++ branch-1.4-merged Mon Aug 20 16:11:37 2007
@@ -1,1 +1,1 @@
-/branches/1.4:1-1291,1293,1298-1300,1326,1332,1336-1338,1342,1346,1349,1356,1359,1362,1381,1384
+/branches/1.4:1-1291,1293,1298-1300,1326,1332,1336-1338,1342,1346,1349,1356,1359,1362,1381,1384,1395

Modified: trunk/tools/ztscan.c
URL: http://svn.digium.com/view/asterisk-gui/trunk/tools/ztscan.c?view=diff&rev=1396&r1=1395&r2=1396
==============================================================================
--- trunk/tools/ztscan.c (original)
+++ trunk/tools/ztscan.c Mon Aug 20 16:11:37 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