Index: chan_zap.c
===================================================================
--- chan_zap.c	(revision 30744)
+++ chan_zap.c	(working copy)
@@ -110,7 +110,7 @@
 #endif
 
 #if !defined(ZT_SIG_EM_E1) || (defined(HAVE_LIBPRI) && !defined(ZT_SIG_HARDHDLC))
-#error "Your zaptel is too old.  please update"
+#error "Your zaptel is too old.  Please update"
 #endif
 
 #ifndef ZT_TONEDETECT
@@ -203,7 +203,7 @@
 
 static char language[MAX_LANGUAGE] = "";
 static char musicclass[MAX_MUSICCLASS] = "";
-static char progzone[10]= "";
+static char progzone[10] = "";
 
 static int usedistinctiveringdetection = 0;
 static int distinctiveringaftercid = 0;
@@ -311,7 +311,7 @@
 static int pritimers[PRI_MAX_TIMERS];
 #endif
 static int pridebugfd = -1;
-static char pridebugfilename[1024]="";
+static char pridebugfilename[1024] = "";
 #endif
 
 /*! \brief Wait up to 16 seconds for first digit (FXO logic) */
@@ -323,7 +323,7 @@
 /*! \brief How long to wait for an extra digit, if there is an ambiguous match */
 static int matchdigittimeout = 3000;
 
-static int usecnt =0;
+static int usecnt = 0;
 AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 
 /*! \brief Protect the interface list (of zt_pvt's) */
@@ -353,7 +353,7 @@
 AST_MUTEX_DEFINE_STATIC(monlock);
 
 /*! \brief This is the thread for the monitor which checks for input on the channels
-   which are not currently in use.  */
+   which are not currently in use. */
 static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 static int restart_monitor(void);
@@ -366,21 +366,24 @@
 static inline int zt_get_event(int fd)
 {
 	int j;
-	if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
+	if (ioctl(fd, ZT_GETEVENT, &j) == -1)
+		return -1;
 	return j;
 }
 
 /*! \brief Avoid the silly zt_waitevent which ignores a bunch of events */
 static inline int zt_wait_event(int fd)
 {
-	int i,j=0;
+	int i, j = 0;
 	i = ZT_IOMUX_SIGEVENT;
-	if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
-	if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
+	if (ioctl(fd, ZT_IOMUX, &i) == -1)
+		return -1;
+	if (ioctl(fd, ZT_GETEVENT, &j) == -1)
+		return -1;
 	return j;
 }
 
-/*! Chunk size to read -- we use 20ms chunks to make things happy.  */
+/*! Chunk size to read -- we use 20ms chunks to make things happy. */
 #define READ_SIZE 160
 
 #define MASK_AVAIL		(1 << 0)	/*!< Channel available for PRI use */
@@ -742,7 +745,7 @@
 			usleep(1);
 			ast_mutex_lock(&pvt->lock);
 		}
-	} while(res);
+	} while (res);
 	/* Then break the poll */
 	pthread_kill(pri->master, SIGURG);
 	return 0;
@@ -895,7 +898,7 @@
 	int bs;
 	int x;
 	isnum = 1;
-	for (x=0;x<strlen(fn);x++) {
+	for (x = 0; x < strlen(fn); x++) {
 		if (!isdigit(fn[x])) {
 			isnum = 0;
 			break;
@@ -930,7 +933,7 @@
 
 static void zt_close(int fd)
 {
-	if(fd > 0)
+	if (fd > 0)
 		close(fd);
 }
 
@@ -963,7 +966,7 @@
 			} else 
 				ast_log(LOG_WARNING, "Unable to check buffer policy on channel %d\n", x);
 			if (ioctl(p->subs[x].zfd, ZT_CHANNO, &p->subs[x].chan) == 1) {
-				ast_log(LOG_WARNING,"Unable to get channel number for pseudo channel on FD %d\n",p->subs[x].zfd);
+				ast_log(LOG_WARNING, "Unable to get channel number for pseudo channel on FD %d\n", p->subs[x].zfd);
 				zt_close(p->subs[x].zfd);
 				p->subs[x].zfd = -1;
 				return -1;
@@ -1042,25 +1045,25 @@
 }
 
 static char *events[] = {
-		"No event",
-		"On hook",
-		"Ring/Answered",
-		"Wink/Flash",
-		"Alarm",
-		"No more alarm",
-		"HDLC Abort",
-		"HDLC Overrun",
-		"HDLC Bad FCS",
-		"Dial Complete",
-		"Ringer On",
-		"Ringer Off",
-		"Hook Transition Complete",
-		"Bits Changed",
-		"Pulse Start",
-		"Timer Expired",
-		"Timer Ping",
-		"Polarity Reversal",
-		"Ring Begin",
+	"No event",
+	"On hook",
+	"Ring/Answered",
+	"Wink/Flash",
+	"Alarm",
+	"No more alarm",
+	"HDLC Abort",
+	"HDLC Overrun",
+	"HDLC Bad FCS",
+	"Dial Complete",
+	"Ringer On",
+	"Ringer Off",
+	"Hook Transition Complete",
+	"Bits Changed",
+	"Pulse Start",
+	"Timer Expired",
+	"Timer Ping",
+	"Polarity Reversal",
+	"Ring Begin",
 };
 
 static struct {
@@ -1079,7 +1082,7 @@
 static char *alarm2str(int alarm)
 {
 	int x;
-	for (x=0;x<sizeof(alarms) / sizeof(alarms[0]); x++) {
+	for (x = 0; x < sizeof(alarms) / sizeof(alarms[0]); x++) {
 		if (alarms[x].alarm & alarm)
 			return alarms[x].name;
 	}
@@ -1101,14 +1104,14 @@
 	if (dialplan == -1) {
 		return("Dynamically set dialplan in ISDN");
 	}
-	return(pri_plan2str(dialplan));
+	return (pri_plan2str(dialplan));
 }
 #endif
 
 static char *zap_sig2str(int sig)
 {
 	static char buf[256];
-	switch(sig) {
+	switch (sig) {
 	case SIG_EM:
 		return "E & M Immediate";
 	case SIG_EMWINK:
@@ -1184,7 +1187,7 @@
 		if (!index) {
 			/* Real-side and pseudo-side both participate in conference */
 			zi.confmode = ZT_CONF_REALANDPSEUDO | ZT_CONF_TALKER | ZT_CONF_LISTENER |
-								ZT_CONF_PSEUDO_TALKER | ZT_CONF_PSEUDO_LISTENER;
+				ZT_CONF_PSEUDO_TALKER | ZT_CONF_PSEUDO_LISTENER;
 		} else
 			zi.confmode = ZT_CONF_CONF | ZT_CONF_TALKER | ZT_CONF_LISTENER;
 		zi.confno = p->confno;
@@ -1246,7 +1249,7 @@
 	/* Start out optimistic */
 	useslavenative = 1;
 	/* Update conference state in a stateless fashion */
-	for (x=0;x<3;x++) {
+	for (x = 0; x < 3; x++) {
 		/* Any three-way calling makes slave native mode *definitely* out
 		   of the question */
 		if ((p->subs[x].zfd > -1) && p->subs[x].inthreeway)
@@ -1255,7 +1258,7 @@
 	/* If we don't have any 3-way calls, check to see if we have
 	   precisely one slave */
 	if (useslavenative) {
-		for (x=0;x<MAX_SLAVES;x++) {
+		for (x = 0; x < MAX_SLAVES; x++) {
 			if (p->slaves[x]) {
 				if (slave) {
 					/* Whoops already have a slave!  No 
@@ -1304,7 +1307,7 @@
 
 	useslavenative = isslavenative(p, &slave);
 	/* Start with the obvious, general stuff */
-	for (x=0;x<3;x++) {
+	for (x = 0; x < 3; x++) {
 		/* Look for three way calls */
 		if ((p->subs[x].zfd > -1) && p->subs[x].inthreeway) {
 			conf_add(p, &p->subs[x], x, 0);
@@ -1315,7 +1318,7 @@
 	}
 	/* If we have a slave, add him to our conference now. or DAX
 	   if this is slave native */
-	for (x=0;x<MAX_SLAVES;x++) {
+	for (x = 0; x < MAX_SLAVES; x++) {
 		if (p->slaves[x]) {
 			if (useslavenative)
 				conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p));
@@ -1343,8 +1346,8 @@
 		}
 	}
 	if (!needconf) {
-		/* Nobody is left (or should be left) in our conference.  
-		   Kill it.  */
+		/* Nobody is left (or should be left) in our conference.
+		   Kill it. */
 		p->confno = -1;
 	}
 	ast_log(LOG_DEBUG, "Updated conferencing on %d, with %d conference users\n", p->channel, needconf);
@@ -1391,7 +1394,7 @@
 	if (p && p->echocancel && p->echotraining) {
 		x = p->echotraining;
 		res = ioctl(p->subs[SUB_REAL].zfd, ZT_ECHOTRAIN, &x);
-		if (res) 
+		if (res)
 			ast_log(LOG_WARNING, "Unable to request echo training on channel %d\n", p->channel);
 		else {
 			ast_log(LOG_DEBUG, "Engaged echo training on channel %d\n", p->channel);
@@ -1407,7 +1410,7 @@
 	if (p->echocancel) {
 		x = 0;
 		res = ioctl(p->subs[SUB_REAL].zfd, ZT_ECHOCANCEL, &x);
-		if (res) 
+		if (res)
 			ast_log(LOG_WARNING, "Unable to disable echo cancellation on channel %d\n", p->channel);
 		else
 			ast_log(LOG_DEBUG, "disabled echo cancellation on channel %d\n", p->channel);
@@ -1575,7 +1578,7 @@
 			ast_log(LOG_WARNING, "Unable to set audio mode on '%d'\n", p->channel);
 	}
 	res = ioctl(p->subs[SUB_REAL].zfd, ZT_CONFMUTE, &x);
-	if (res < 0) 
+	if (res < 0)
 		ast_log(LOG_WARNING, "zt confmute(%d) failed on channel %d: %s\n", muted, p->channel, strerror(errno));
 	return res;
 }
@@ -1657,7 +1660,7 @@
 		p->subs[SUB_REAL].linear = 0;
 		zt_setlinear(p->subs[SUB_REAL].zfd, 0);
 	}
-	while(p->cidpos < p->cidlen) {
+	while (p->cidpos < p->cidlen) {
 		res = write(p->subs[SUB_REAL].zfd, p->cidspill + p->cidpos, p->cidlen - p->cidpos);
 		if (res < 0) {
 			if (errno == EAGAIN)
@@ -1715,7 +1718,7 @@
 	int x, res, index,mysig;
 	char *c, *n, *l;
 #ifdef HAVE_LIBPRI
-	char *s=NULL;
+	char *s = NULL;
 #endif
 	char dest[256]; /* must be same length as p->dialdest */
 	ast_mutex_lock(&p->lock);
@@ -1748,9 +1751,10 @@
 	set_actual_gain(p->subs[SUB_REAL].zfd, 0, p->rxgain, p->txgain, p->law);
 
 	mysig = p->sig;
-	if (p->outsigmod) mysig = p->outsigmod;
+	if (p->outsigmod)
+		mysig = p->outsigmod;
 
-	switch(mysig) {
+	switch (mysig) {
 	case SIG_FXOLS:
 	case SIG_FXOGS:
 	case SIG_FXOKS:
@@ -1774,7 +1778,7 @@
 			}
 			/* Choose proper cadence */
 			if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
-				if (ioctl(p->subs[SUB_REAL].zfd, ZT_SETCADENCE, &cadences[p->distinctivering-1]))
+				if (ioctl(p->subs[SUB_REAL].zfd, ZT_SETCADENCE, &cadences[p->distinctivering - 1]))
 					ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s'\n", p->distinctivering, ast->name);
 				p->cidrings = cidrings[p->distinctivering - 1];
 			} else {
@@ -1783,7 +1787,6 @@
 				p->cidrings = p->sendcalleridafter;
 			}
 
-
 			/* nick@dccinc.com 4/3/03 mods to allow for deferred dialing */
 			c = strchr(dest, '/');
 			if (c)
@@ -2082,7 +2085,7 @@
 				pridialplan = PRI_LOCAL_ISDN;
  			}
  		}
- 		pri_sr_set_called(sr, c + p->stripmsd + dp_strip, pridialplan,  s ? 1 : 0);
+ 		pri_sr_set_called(sr, c + p->stripmsd + dp_strip, pridialplan, s ? 1 : 0);
 
 		ldp_strip = 0;
 		prilocaldialplan = p->pri->localdialplan - 1;
@@ -2098,7 +2101,7 @@
 			}
 		}
 		pri_sr_set_caller(sr, l ? (l + ldp_strip) : NULL, n, prilocaldialplan,
-				  p->use_callingpres ? ast->cid.cid_pres : (l ? PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN : PRES_NUMBER_NOT_AVAILABLE));
+			p->use_callingpres ? ast->cid.cid_pres : (l ? PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN : PRES_NUMBER_NOT_AVAILABLE));
 		pri_sr_set_redirecting(sr, ast->cid.cid_rdnis, p->pri->localdialplan - 1, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL);
 
 #ifdef SUPPORT_USERUSER
@@ -2109,9 +2112,9 @@
 			pri_sr_set_useruser(sr, useruser);
 #endif
 
-		if (pri_setup(p->pri->pri, p->call,  sr)) {
+		if (pri_setup(p->pri->pri, p->call, sr)) {
  			ast_log(LOG_WARNING, "Unable to setup call to %s (using %s)\n", 
- 						c + p->stripmsd + dp_strip, dialplan2str(p->pri->dialplan));
+ 				c + p->stripmsd + dp_strip, dialplan2str(p->pri->dialplan));
 			pri_rel(p->pri);
 			ast_mutex_unlock(&p->lock);
 			pri_sr_free(sr);
@@ -2130,12 +2133,12 @@
 {
 	struct zt_pvt *p = *pvt;
 	/* Remove channel from the list */
-	if(p->prev)
+	if (p->prev)
 		p->prev->next = p->next;
-	if(p->next)
+	if (p->next)
 		p->next->prev = p->prev;
 #ifdef WITH_SMDI
-	if(p->use_smdi)
+	if (p->use_smdi)
 		ASTOBJ_UNREF(p->smdi_iface, ast_smdi_interface_destroy);
 #endif
 	ast_mutex_destroy(&p->lock);
@@ -2251,7 +2254,7 @@
 static int pri_is_up(struct zt_pri *pri)
 {
 	int x;
-	for (x=0;x<NUM_DCHANS;x++) {
+	for (x = 0; x < NUM_DCHANS; x++) {
 		if (pri->dchanavail[x] == DCHAN_AVAILABLE)
 			return 1;
 	}
@@ -2273,7 +2276,7 @@
 
 static char *pri_order(int level)
 {
-	switch(level) {
+	switch (level) {
 	case 0:
 		return "Primary";
 	case 1:
@@ -2307,7 +2310,7 @@
 	int newslot = -1;
 	int x;
 	old = pri->pri;
-	for(x=0;x<NUM_DCHANS;x++) {
+	for (x = 0; x < NUM_DCHANS; x++) {
 		if ((pri->dchanavail[x] == DCHAN_AVAILABLE) && (newslot < 0))
 			newslot = x;
 		if (pri->dchans[x] == old) {
@@ -2469,7 +2472,6 @@
 		}
 	}
 
-
 	if (!p->subs[SUB_REAL].owner && !p->subs[SUB_CALLWAIT].owner && !p->subs[SUB_THREEWAY].owner) {
 		p->owner = NULL;
 		p->ringt = 0;
@@ -2555,7 +2557,7 @@
 		if (res < 0) {
 			ast_log(LOG_WARNING, "Unable to hangup line %s\n", ast->name);
 		}
-		switch(p->sig) {
+		switch (p->sig) {
 		case SIG_FXOGS:
 		case SIG_FXOLS:
 		case SIG_FXOKS:
@@ -2622,7 +2624,6 @@
 		restart_monitor();
 	}
 
-
 	p->callwaitingrepeat = 0;
 	p->cidcwexpire = 0;
 	p->oprmode = 0;
@@ -2658,7 +2659,7 @@
 static int zt_answer(struct ast_channel *ast)
 {
 	struct zt_pvt *p = ast->tech_pvt;
-	int res=0;
+	int res = 0;
 	int index;
 	int oldstate = ast->_state;
 	ast_setstate(ast, AST_STATE_UP);
@@ -2671,7 +2672,7 @@
 		ast_mutex_unlock(&p->lock);
 		return 0;
 	}
-	switch(p->sig) {
+	switch (p->sig) {
 	case SIG_FXSLS:
 	case SIG_FXSGS:
 	case SIG_FXSKS:
@@ -2697,10 +2698,10 @@
 	case SIG_FXOKS:
 		/* Pick up the line */
 		ast_log(LOG_DEBUG, "Took %s off hook\n", ast->name);
-		if(p->hanguponpolarityswitch) {
+		if (p->hanguponpolarityswitch) {
 			gettimeofday(&p->polaritydelaytv, NULL);
 		}
-		res =  zt_set_hook(p->subs[SUB_REAL].zfd, ZT_OFFHOOK);
+		res = zt_set_hook(p->subs[SUB_REAL].zfd, ZT_OFFHOOK);
 		tone_zone_play_tone(p->subs[index].zfd, -1);
 		p->dialing = 0;
 		if ((index == SUB_REAL) && p->subs[SUB_THREEWAY].inthreeway) {
@@ -2725,7 +2726,7 @@
 			pri_rel(p->pri);
 		} else {
 			ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
-			res= -1;
+			res = -1;
 		}
 		break;
 #endif
@@ -2746,7 +2747,7 @@
 	signed char *scp;
 	int x;
 	int index;
-	struct zt_pvt *p = chan->tech_pvt,*pp;
+	struct zt_pvt *p = chan->tech_pvt, *pp;
 	struct oprmode *oprmode;
 	
 
@@ -2756,7 +2757,7 @@
 		return -1;
 	}
 
-	switch(option) {
+	switch (option) {
 	case AST_OPTION_TXGAIN:
 		scp = (signed char *) data;
 		index = zt_get_index(chan, p, 0);
@@ -2800,7 +2801,8 @@
 		p->mate = 0;
 		if (!*cp) { /* turn it off */
 			ast_log(LOG_DEBUG, "Set option TDD MODE, value: OFF(0) on %s\n",chan->name);
-			if (p->tdd) tdd_free(p->tdd);
+			if (p->tdd)
+				tdd_free(p->tdd);
 			p->tdd = 0;
 			break;
 		}
@@ -2809,8 +2811,8 @@
 		zt_disable_ec(p);
 		/* otherwise, turn it on */
 		if (!p->didtdd) { /* if havent done it yet */
-			unsigned char mybuf[41000],*buf;
-			int size,res,fd,len;
+			unsigned char mybuf[41000], *buf;
+			int size, res, fd, len;
 			struct pollfd fds[1];
 
 			buf = mybuf;
@@ -2823,8 +2825,9 @@
 				return -1;
 			}
 			fd = p->subs[index].zfd;
-			while(len) {
-				if (ast_check_hangup(chan)) return -1;
+			while (len) {
+				if (ast_check_hangup(chan))
+					return -1;
 				size = len;
 				if (size > READ_SIZE)
 					size = READ_SIZE;
@@ -2837,7 +2840,8 @@
 					continue;
 				}
 				/* if got exception */
-				if (fds[0].revents & POLLPRI) return -1;
+				if (fds[0].revents & POLLPRI)
+					return -1;
 				if (!(fds[0].revents & POLLOUT)) {
 					ast_log(LOG_DEBUG, "write fd not ready on channel %d\n", p->channel);
 					continue;
@@ -2854,7 +2858,8 @@
 			p->didtdd = 1; /* set to have done it now */		
 		}
 		if (*cp == 2) { /* Mate mode */
-			if (p->tdd) tdd_free(p->tdd);
+			if (p->tdd)
+				tdd_free(p->tdd);
 			p->tdd = 0;
 			p->mate = 1;
 			break;
@@ -2945,7 +2950,7 @@
 	if (needlock) {
 		ast_mutex_lock(&master->lock);
 		if (slave) {
-			while(ast_mutex_trylock(&slave->lock)) {
+			while (ast_mutex_trylock(&slave->lock)) {
 				ast_mutex_unlock(&master->lock);
 				usleep(1);
 				ast_mutex_lock(&master->lock);
@@ -2953,7 +2958,7 @@
 		}
 	}
 	hasslaves = 0;
-	for (x=0;x<MAX_SLAVES;x++) {
+	for (x = 0; x < MAX_SLAVES; x++) {
 		if (master->slaves[x]) {
 			if (!slave || (master->slaves[x] == slave)) {
 				/* Take slave out of the conference */
@@ -2974,7 +2979,7 @@
 			conf_del(master->master, &master->subs[SUB_REAL], SUB_REAL);
 			conf_del(master, &master->master->subs[SUB_REAL], SUB_REAL);
 			hasslaves = 0;
-			for (x=0;x<MAX_SLAVES;x++) {
+			for (x = 0; x < MAX_SLAVES; x++) {
 				if (master->master->slaves[x] == master)
 					master->master->slaves[x] = NULL;
 				else if (master->master->slaves[x])
@@ -2999,7 +3004,7 @@
 		ast_log(LOG_WARNING, "Tried to link to/from NULL??\n");
 		return;
 	}
-	for (x=0;x<MAX_SLAVES;x++) {
+	for (x = 0; x < MAX_SLAVES; x++) {
 		if (!master->slaves[x]) {
 			master->slaves[x] = slave;
 			break;
@@ -3344,7 +3349,7 @@
 	if (p->owner == oldchan) {
 		p->owner = newchan;
 	}
-	for (x=0;x<3;x++)
+	for (x = 0; x < 3; x++)
 		if (p->subs[x].owner == oldchan) {
 			if (!x)
 				zt_unlink(NULL, p, 0);
@@ -3372,7 +3377,7 @@
 		printf("Res: %d, error: %s\n", res, strerror(errno));
 #endif						
 		if (res) {
-			switch(errno) {
+			switch (errno) {
 			case EBUSY:
 			case EINTR:
 				/* Wait just in case */
@@ -3502,8 +3507,8 @@
 			
 static struct ast_frame *zt_handle_event(struct ast_channel *ast)
 {
-	int res,x;
-	int index,mysig;
+	int res, x;
+	int index, mysig;
 	char *c;
 	struct zt_pvt *p = ast->tech_pvt;
 	pthread_t threadid;
@@ -3516,7 +3521,8 @@
 
 	index = zt_get_index(ast, p, 0);
 	mysig = p->sig;
-	if (p->outsigmod) mysig = p->outsigmod;
+	if (p->outsigmod)
+		mysig = p->outsigmod;
 	p->subs[index].f.frametype = AST_FRAME_NULL;
 	p->subs[index].f.subclass = 0;
 	p->subs[index].f.datalen = 0;
@@ -3574,7 +3580,7 @@
 		return &p->subs[index].f;
 	}
 
-	switch(res) {
+	switch (res) {
 #ifdef ZT_EVENT_EC_DISABLED
 		case ZT_EVENT_EC_DISABLED:
 			if (option_verbose > 2) 
@@ -3679,7 +3685,7 @@
 				}
 				break;
 			}
-			switch(p->sig) {
+			switch (p->sig) {
 			case SIG_FXOLS:
 			case SIG_FXOGS:
 			case SIG_FXOKS:
@@ -3709,7 +3715,7 @@
 						unsigned int mssinceflash;
 						/* Here we have to retain the lock on both the main channel, the 3-way channel, and
 						   the private structure -- not especially easy or clean */
-						while(p->subs[SUB_THREEWAY].owner && ast_mutex_trylock(&p->subs[SUB_THREEWAY].owner->lock)) {
+						while (p->subs[SUB_THREEWAY].owner && ast_mutex_trylock(&p->subs[SUB_THREEWAY].owner->lock)) {
 							/* Yuck, didn't get the lock on the 3-way, gotta release everything and re-grab! */
 							ast_mutex_unlock(&p->lock);
 							ast_mutex_unlock(&ast->lock);
@@ -3832,11 +3838,11 @@
 				p->dialing = 1;
 				return &p->subs[index].f;
 			}
-			switch(p->sig) {
+			switch (p->sig) {
 			case SIG_FXOLS:
 			case SIG_FXOGS:
 			case SIG_FXOKS:
-				switch(ast->_state) {
+				switch (ast->_state) {
 				case AST_STATE_RINGING:
 					zt_enable_ec(p);
 					zt_train_ec(p);
@@ -3956,7 +3962,7 @@
 			break;
 #ifdef ZT_EVENT_RINGBEGIN
 		case ZT_EVENT_RINGBEGIN:
-			switch(p->sig) {
+			switch (p->sig) {
 			case SIG_FXSLS:
 			case SIG_FXSGS:
 			case SIG_FXSKS:
@@ -4016,7 +4022,7 @@
 			}
 			/* Remember last time we got a flash-hook */
 			gettimeofday(&p->flashtime, NULL);
-			switch(mysig) {
+			switch (mysig) {
 			case SIG_FXOLS:
 			case SIG_FXOGS:
 			case SIG_FXOKS:
@@ -4217,7 +4223,7 @@
 		case ZT_EVENT_HOOKCOMPLETE:
 			if (p->inalarm) break;
 			if ((p->radio || (p->oprmode < 0))) break;
-			switch(mysig) {
+			switch (mysig) {
 			case SIG_FXSLS:  /* only interesting for FXS */
 			case SIG_FXSGS:
 			case SIG_FXSKS:
@@ -4275,14 +4281,14 @@
 			} 
 			/* Removed else statement from here as it was preventing hangups from ever happening*/
 			/* Added AST_STATE_RING in if statement below to deal with calling party hangups that take place when ringing */
-			if(p->hanguponpolarityswitch &&
+			if (p->hanguponpolarityswitch &&
 				(p->polarityonanswerdelay > 0) &&
 			       (p->polarity == POLARITY_REV) &&
 				((ast->_state == AST_STATE_UP) || (ast->_state == AST_STATE_RING)) ) {
                                 /* Added log_debug information below to provide a better indication of what is going on */
 				ast_log(LOG_DEBUG, "Polarity Reversal event occured - DEBUG 1: channel %d, state %d, pol= %d, aonp= %d, honp= %d, pdelay= %d, tv= %d\n", p->channel, ast->_state, p->polarity, p->answeronpolarityswitch, p->hanguponpolarityswitch, p->polarityonanswerdelay, ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) );
 			
-				if(ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) > p->polarityonanswerdelay) {
+				if (ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) > p->polarityonanswerdelay) {
 					ast_log(LOG_DEBUG, "Polarity Reversal detected and now Hanging up on channel %d\n", p->channel);
 					ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT);
 					p->polarity = POLARITY_IDLE;
@@ -4343,7 +4349,7 @@
 			if (p->owner && ast_bridged_channel(p->owner))
 				ast_moh_stop(ast_bridged_channel(p->owner));
 		}
-		switch(res) {
+		switch (res) {
 		case ZT_EVENT_ONHOOK:
 			zt_disable_ec(p);
 			if (p->owner) {
@@ -4749,7 +4755,7 @@
 	int res;
 	int fd;
 	fd = p->subs[index].zfd;
-	while(len) {
+	while (len) {
 		size = len;
 		if (size > (linear ? READ_SIZE * 2 : READ_SIZE))
 			size = (linear ? READ_SIZE * 2 : READ_SIZE);
@@ -4863,7 +4869,7 @@
 	index = zt_get_index(chan, p, 0);
 	ast_log(LOG_DEBUG, "Requested indication %d on channel %s\n", condition, chan->name);
 	if (index == SUB_REAL) {
-		switch(condition) {
+		switch (condition) {
 		case AST_CONTROL_BUSY:
 #ifdef HAVE_LIBPRI
 			if (p->priindication_oob && p->sig == SIG_PRI) {
@@ -5061,7 +5067,7 @@
 				ast_string_field_build(tmp, name, "Zap/pseudo-%d", ast_random());
 			else	
 				ast_string_field_build(tmp, name, "Zap/%d-%d", i->channel, y);
-			for (x=0;x<3;x++) {
+			for (x = 0; x < 3; x++) {
 				if ((index != x) && i->subs[x].owner && !strcasecmp(tmp->name, i->subs[x].owner->name))
 					break;
 			}
@@ -5222,7 +5228,7 @@
 {
 	int j;
 	zt_set_hook(p->subs[index].zfd, ZT_WINK);
-	for(;;)
+	for (;;)
 	{
 		   /* set bits of interest */
 		j = ZT_IOMUX_SIGEVENT;
@@ -5240,13 +5246,13 @@
 {
 	struct ast_channel *chan = data;
 	struct zt_pvt *p = chan->tech_pvt;
-	char exten[AST_MAX_EXTENSION]="";
-	char exten2[AST_MAX_EXTENSION]="";
+	char exten[AST_MAX_EXTENSION] = "";
+	char exten2[AST_MAX_EXTENSION] = "";
 	unsigned char buf[256];
 	char dtmfcid[300];
 	char dtmfbuf[300];
-	struct callerid_state *cs=NULL;
-	char *name=NULL, *number=NULL;
+	struct callerid_state *cs = NULL;
+	char *name = NULL, *number = NULL;
 	int distMatches;
 	int curRingData[3];
 	int receivedRingT;
@@ -5259,7 +5265,7 @@
 	int flags;
 	int i;
 	int timeout;
-	int getforward=0;
+	int getforward = 0;
 	char *s1, *s2;
 	int len = 0;
 	int res;
@@ -5275,14 +5281,14 @@
 	}
 	if (p->dsp)
 		ast_dsp_digitreset(p->dsp);
-	switch(p->sig) {
+	switch (p->sig) {
 #ifdef HAVE_LIBPRI
 	case SIG_PRI:
 		/* Now loop looking for an extension */
 		ast_copy_string(exten, p->exten, sizeof(exten));
 		len = strlen(exten);
 		res = 0;
-		while((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
+		while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
 			if (len && !ast_ignore_pattern(chan->context, exten))
 				tone_zone_play_tone(p->subs[index].zfd, -1);
 			else
@@ -5364,11 +5370,12 @@
 		if (!p->immediate)
 			/* Wait for the first digit (up to 5 seconds). */
 			res = ast_waitfordigit(chan, 5000);
-		else res = 0;
+		else
+			res = 0;
 		if (res > 0) {
 			/* save first char */
 			dtmfbuf[0] = res;
-			switch(p->sig) {
+			switch (p->sig) {
 			case SIG_FEATD:
 			case SIG_SF_FEATD:
 				res = my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
@@ -5431,7 +5438,7 @@
 				/* If we got the first digit, get the rest */
 				len = 1;
 				dtmfbuf[len] = '\0';
-				while((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, dtmfbuf, 1, p->cid_num)) {
+				while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, dtmfbuf, 1, p->cid_num)) {
 					if (ast_exists_extension(chan, chan->context, dtmfbuf, 1, p->cid_num)) {
 						timeout = matchdigittimeout;
 					} else {
@@ -5521,7 +5528,7 @@
 					if (!ast_strlen_zero(p->cid_num))
 						ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
 					else
-						if(*(s1 + 2))
+						if (*(s1 + 2))
 							ast_set_callerid(chan, s1 + 2, NULL, s1 + 2);
 					ast_copy_string(exten, s2 + 1, sizeof(exten));
 				} else
@@ -5538,7 +5545,7 @@
 				s1 = strsep(&stringp, "#");
 				s2 = strsep(&stringp, "#");
 				if (s2 && (*(s2 + 1) == '0')) {
-					if(*(s2 + 2))
+					if (*(s2 + 2))
 						ast_set_callerid(chan, s2 + 2, NULL, s2 + 2);
 				}
 				if (s1)	ast_copy_string(exten, s1, sizeof(exten));
@@ -5612,7 +5619,7 @@
 		   can use flash-hook as a "hold" feature */
 		if (p->subs[SUB_THREEWAY].owner) 
 			timeout = 999999;
-		while(len < AST_MAX_EXTENSION-1) {
+		while (len < AST_MAX_EXTENSION-1) {
 			/* Read digit unless it's supposed to be immediate, in which case the
 			   only answer is 's' */
 			if (p->immediate) 
@@ -5888,7 +5895,7 @@
 
 			time(&start);
 			ast_setstate(chan, AST_STATE_RING);
-			while(time(NULL) < start + 3) {
+			while (time(NULL) < start + 3) {
 				res = ast_waitfor(chan, 1000);
 				if (res) {
 					f = ast_read(chan);
@@ -5991,7 +5998,7 @@
 					zt_setlinear(p->subs[index].zfd, 0);
 					
 					/* First we wait and listen for the Caller*ID */
-					for(;;) {	
+					for (;;) {	
 						i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT;
 						if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i)))	{
 							ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
@@ -6082,7 +6089,7 @@
 						len = 0;
 						distMatches = 0;
 						/* Clear the current ring data array so we dont have old data in it. */
-						for (receivedRingT=0; receivedRingT < 3; receivedRingT++) {
+						for (receivedRingT = 0; receivedRingT < 3; receivedRingT++) {
 							curRingData[receivedRingT] = 0;
 						}
 						receivedRingT = 0;
@@ -6094,7 +6101,7 @@
 							ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
 						}
 		
-						for(;;) {	
+						for (;;) {	
 							i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT;
 							if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i)))	{
 								ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
@@ -6133,15 +6140,15 @@
 								}
 							}
 						}
-						if(option_verbose > 2)
+						if (option_verbose > 2)
 							/* this only shows up if you have n of the dring patterns filled in */
 							ast_verbose( VERBOSE_PREFIX_3 "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]);
 	
-						for (counter=0; counter < 3; counter++) {
+						for (counter = 0; counter < 3; counter++) {
 							/* Check to see if the rings we received match any of the ones in zapata.conf for this
 							channel */
 							distMatches = 0;
-							for (counter1=0; counter1 < 3; counter1++) {
+							for (counter1 = 0; counter1 < 3; counter1++) {
 								if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1]+10) && curRingData[counter1] >=
 								(p->drings.ringnum[counter].ring[counter1]-10)) {
 									distMatches++;
@@ -6151,7 +6158,7 @@
 								/* The ring matches, set the context to whatever is for distinctive ring.. */
 								ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context));
 								ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context));
-								if(option_verbose > 2)
+								if (option_verbose > 2)
 									ast_verbose( VERBOSE_PREFIX_3 "Distinctive Ring matched context %s\n",p->context);
 								break;
 							}
@@ -6184,7 +6191,7 @@
 				len = 0;
 				distMatches = 0;
 				/* Clear the current ring data array so we dont have old data in it. */
-				for (receivedRingT=0; receivedRingT < 3; receivedRingT++) {
+				for (receivedRingT = 0; receivedRingT < 3; receivedRingT++) {
 					curRingData[receivedRingT] = 0;
 				}
 				receivedRingT = 0;
@@ -6198,7 +6205,7 @@
 
 				/* Take out of linear mode for Caller*ID processing */
 				zt_setlinear(p->subs[index].zfd, 0);
-				for(;;) {	
+				for (;;) {	
 					i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT;
 					if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i)))	{
 						ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
@@ -6253,13 +6260,13 @@
 				}
 				if (distinctiveringaftercid == 1) {
 					/* Clear the current ring data array so we dont have old data in it. */
-					for (receivedRingT=0; receivedRingT < 3; receivedRingT++) {
+					for (receivedRingT = 0; receivedRingT < 3; receivedRingT++) {
 						curRingData[receivedRingT] = 0;
 					}
 					receivedRingT = 0;
-					if(option_verbose > 2)
+					if (option_verbose > 2)
 						ast_verbose( VERBOSE_PREFIX_3 "Detecting post-CID distinctive ring\n");
-					for(;;) {
+					for (;;) {
 						i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT;
 						if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i)))    {
 							ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
@@ -6300,21 +6307,21 @@
 					}
 				}
 				if (p->usedistinctiveringdetection == 1) {
-					if(option_verbose > 2)
+					if (option_verbose > 2)
 						/* this only shows up if you have n of the dring patterns filled in */
 						ast_verbose( VERBOSE_PREFIX_3 "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]);
 
-					for (counter=0; counter < 3; counter++) {
+					for (counter = 0; counter < 3; counter++) {
 						/* Check to see if the rings we received match any of the ones in zapata.conf for this
 						channel */
-						if(option_verbose > 2)
+						if (option_verbose > 2)
 							/* this only shows up if you have n of the dring patterns filled in */
 							ast_verbose( VERBOSE_PREFIX_3 "Checking %d,%d,%d\n",
 								p->drings.ringnum[counter].ring[0],
 								p->drings.ringnum[counter].ring[1],
 								p->drings.ringnum[counter].ring[2]);
 						distMatches = 0;
-						for (counter1=0; counter1 < 3; counter1++) {
+						for (counter1 = 0; counter1 < 3; counter1++) {
 							if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1]+10) && curRingData[counter1] >=
 							(p->drings.ringnum[counter].ring[counter1]-10)) {
 								distMatches++;
@@ -6324,7 +6331,7 @@
 							/* The ring matches, set the context to whatever is for distinctive ring.. */
 							ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context));
 							ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context));
-							if(option_verbose > 2)
+							if (option_verbose > 2)
 								ast_verbose( VERBOSE_PREFIX_3 "Distinctive Ring matched context %s\n",p->context);
 							break;
 						}
@@ -6394,7 +6401,7 @@
 	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 	/* Handle an event on a given channel for the monitor thread. */
-	switch(event) {
+	switch (event) {
 	case ZT_EVENT_NONE:
 	case ZT_EVENT_BITSCHANGED:
 		break;
@@ -6403,7 +6410,7 @@
 		if (i->inalarm) break;
 		if (i->radio) break;
 		/* Got a ring/answer.  What kind of channel are we? */
-		switch(i->sig) {
+		switch (i->sig) {
 		case SIG_FXOLS:
 		case SIG_FXOGS:
 		case SIG_FXOKS:
@@ -6495,21 +6502,22 @@
 		i->inalarm = 0;
 		ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", i->channel);
 		manager_event(EVENT_FLAG_SYSTEM, "AlarmClear",
-		              "Channel: %d\r\n", i->channel);
+			"Channel: %d\r\n", i->channel);
 		break;
 	case ZT_EVENT_ALARM:
 		i->inalarm = 1;
 		res = get_alarms(i);
 		ast_log(LOG_WARNING, "Detected alarm on channel %d: %s\n", i->channel, alarm2str(res));
 		manager_event(EVENT_FLAG_SYSTEM, "Alarm",
-		              "Alarm: %s\r\n"
-		              "Channel: %d\r\n",
-		              alarm2str(res), i->channel);
+			"Alarm: %s\r\n"
+			"Channel: %d\r\n",
+			alarm2str(res), i->channel);
 		/* fall thru intentionally */
 	case ZT_EVENT_ONHOOK:
-		if (i->radio) break;
+		if (i->radio)
+			break;
 		/* Back on hook.  Hang up. */
-		switch(i->sig) {
+		switch (i->sig) {
 		case SIG_FXOLS:
 		case SIG_FXOGS:
 		case SIG_FEATD:
@@ -6557,7 +6565,7 @@
 		}
 		break;
 	case ZT_EVENT_POLARITY:
-		switch(i->sig) {
+		switch (i->sig) {
 		case SIG_FXSLS:
 		case SIG_FXSKS:
 		case SIG_FXSGS:
@@ -6601,7 +6609,7 @@
 	}
 	ast_log(LOG_DEBUG, "Monitor starting...\n");
 #endif
-	for(;;) {
+	for (;;) {
 		/* Lock the interface list */
 		ast_mutex_lock(&iflock);
 		if (!pfds || (lastalloc != ifcount)) {
@@ -6619,7 +6627,7 @@
 		   zt_pvt that does not have an associated owner channel */
 		count = 0;
 		i = iflist;
-		while(i) {
+		while (i) {
 			if ((i->subs[SUB_REAL].zfd > -1) && i->sig && (!i->radio)) {
 				if (!i->owner && !i->subs[SUB_REAL].owner) {
 					/* This needs to be watched, as it lacks an owner */
@@ -6655,7 +6663,7 @@
 		lastpass = thispass;
 		thispass = time(NULL);
 		i = iflist;
-		while(i) {
+		while (i) {
 			if (thispass != lastpass) {
 				if (!found && ((i == last) || ((i == iflist) && !last))) {
 					last = i;
@@ -6828,7 +6836,7 @@
 	trunkgroup = pris[*span].mastertrunkgroup;
 	if (trunkgroup) {
 		/* Select a specific trunk group */
-		for (x=0;x<NUM_SPANS;x++) {
+		for (x = 0; x < NUM_SPANS; x++) {
 			if (pris[x].trunkgroup == trunkgroup) {
 				*span = x;
 				return 0;
@@ -6865,13 +6873,13 @@
 	int span;
 	int ospan=0;
 	int x,y;
-	for (x=0;x<NUM_SPANS;x++) {
+	for (x = 0; x < NUM_SPANS; x++) {
 		if (pris[x].trunkgroup == trunkgroup) {
 			ast_log(LOG_WARNING, "Trunk group %d already exists on span %d, Primary d-channel %d\n", trunkgroup, x + 1, pris[x].dchannels[0]);
 			return -1;
 		}
 	}
-	for (y=0;y<NUM_DCHANS;y++) {
+	for (y = 0; y < NUM_DCHANS; y++) {
 		if (!channels[y])	
 			break;
 		memset(&si, 0, sizeof(si));
@@ -6985,7 +6993,7 @@
 		}
 		ast_mutex_init(&tmp->lock);
 		ifcount++;
-		for (x=0;x<3;x++)
+		for (x = 0; x < 3; x++)
 			tmp->subs[x].zfd = -1;
 		tmp->channel = channel;
 	}
@@ -7063,8 +7071,8 @@
 						myswitchtype = PRI_SWITCH_GR303_TMC;
 					/* Make sure this isn't a d-channel */
 					matchesdchan=0;
-					for (x=0;x<NUM_SPANS;x++) {
-						for (y=0;y<NUM_DCHANS;y++) {
+					for (x = 0; x < NUM_SPANS; x++) {
+						for (y = 0; y < NUM_DCHANS; y++) {
 							if (pris[x].dchannels[y] == tmp->channel) {
 								matchesdchan = 1;
 								break;
@@ -7639,7 +7647,7 @@
 				return NULL;
 			}
 			res--;
-			for (x=0;x<NUM_SPANS;x++) {
+			for (x = 0; x < NUM_SPANS; x++) {
 				if (pris[x].trunkgroup == trunkgroup) {
 					pri = pris + x;
 					lock = &pri->lock;
@@ -7666,7 +7674,7 @@
 	/* Search for an unowned channel */
 	ast_mutex_lock(lock);
 	exit = p;
-	while(p && !tmp) {
+	while (p && !tmp) {
 		if (roundrobin)
 			round_robin[x] = p;
 #if 0
@@ -7784,7 +7792,7 @@
 {
 	struct zt_pvt *p;
 	p = pri->crvs;
-	while(p) {
+	while (p) {
 		if (p->channel == crv)
 			return p;
 		p = p->next;
@@ -7810,7 +7818,7 @@
 		span = pris[param.spanno - 1].prilogicalspan;
 	}
 
-	for (x=0;x<pri->numchans;x++) {
+	for (x = 0; x < pri->numchans; x++) {
 		if (pri->pvts[x] && (pri->pvts[x]->prioffset == channel) && (pri->pvts[x]->logicalspan == span)) {
 			principle = x;
 			break;
@@ -7835,8 +7843,9 @@
 		(pri->pvts[principle]->call == c))
 		return principle;
 	/* First, check for other bearers */
-	for (x=0;x<pri->numchans;x++) {
-		if (!pri->pvts[x]) continue;
+	for (x = 0; x < pri->numchans; x++) {
+		if (!pri->pvts[x])
+			continue;
 		if (pri->pvts[x]->call == c) {
 			/* Found our call */
 			if (principle != x) {
@@ -7870,7 +7879,7 @@
 	}
 	/* Now check for a CRV with no bearer */
 	crv = pri->crvs;
-	while(crv) {
+	while (crv) {
 		if (crv->call == c) {
 			/* This is our match...  Perform some basic checks */
 			if (crv->bearer)
@@ -7912,14 +7921,14 @@
 		ast_hangup(chan);
 		return NULL;
 	}
-	while((newms = ast_waitfor(chan, ms)) > 0) {
+	while ((newms = ast_waitfor(chan, ms)) > 0) {
 		f = ast_read(chan);
 		if (!f) {
 			/* Got hangup */
 			break;
 		}
 		if (f->frametype == AST_FRAME_CONTROL) {
-			switch(f->subclass) {
+			switch (f->subclass) {
 			case AST_CONTROL_ANSWER:
 				/* Launch the PBX */
 				ast_copy_string(chan->exten, pvt->pri->idleext, sizeof(chan->exten));
@@ -8036,7 +8045,7 @@
 {
 	do {
 		pri->resetpos++;
-	} while((pri->resetpos < pri->numchans) &&
+	} while ((pri->resetpos < pri->numchans) &&
 		 (!pri->pvts[pri->resetpos] ||
 		  pri->pvts[pri->resetpos]->call ||
 		  pri->pvts[pri->resetpos]->resetting));
@@ -8059,8 +8068,8 @@
 	ast_mutex_lock(&p->lock);
 	do {
 		redo = 0;
-		for (x=0;x<3;x++) {
-			while(p->subs[x].owner && ast_mutex_trylock(&p->subs[x].owner->lock)) {
+		for (x = 0; x < 3; x++) {
+			while (p->subs[x].owner && ast_mutex_trylock(&p->subs[x].owner->lock)) {
 				redo++;
 				ast_mutex_unlock(&p->lock);
 				usleep(1);
@@ -8178,8 +8187,8 @@
 		} else
 			ast_log(LOG_WARNING, "Idle dial string '%s' lacks '@context'\n", pri->idleext);
 	}
-	for(;;) {
-		for (i=0;i<NUM_DCHANS;i++) {
+	for (;;) {
+		for (i = 0; i < NUM_DCHANS; i++) {
 			if (!pri->dchannels[i])
 				break;
 			fds[i].fd = pri->fds[i];
@@ -8205,7 +8214,7 @@
 			nextidle = -1;
 			haveidles = 0;
 			activeidles = 0;
-			for (x=pri->numchans;x>=0;x--) {
+			for (x = pri->numchans; x >= 0; x--) {
 				if (pri->pvts[x] && !pri->pvts[x]->owner && 
 				    !pri->pvts[x]->call) {
 					if (haveidles < pri->minunused) {
@@ -8242,7 +8251,7 @@
 				   (activeidles > pri->minidle)) {
 				/* Mark something for hangup if there is something 
 				   that can be hungup */
-				for (x=pri->numchans;x>=0;x--) {
+				for (x = pri->numchans; x >= 0; x--) {
 					/* find a candidate channel */
 					if (pri->pvts[x] && pri->pvts[x]->owner && pri->pvts[x]->isidlecall) {
 						pri->pvts[x]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
@@ -8258,7 +8267,7 @@
 		}
 		/* Start with reasonable max */
 		lowest = ast_tv(60, 0);
-		for (i=0; i<NUM_DCHANS; i++) {
+		for (i = 0; i < NUM_DCHANS; i++) {
 			/* Find lowest available d-channel */
 			if (!pri->dchannels[i])
 				break;
@@ -8296,7 +8305,7 @@
 
 		ast_mutex_lock(&pri->lock);
 		if (!res) {
-			for (which=0;which<NUM_DCHANS;which++) {
+			for (which = 0; which < NUM_DCHANS; which++) {
 				if (!pri->dchans[which])
 					break;
 				/* Just a timeout, run the scheduler */
@@ -8305,7 +8314,7 @@
 					break;
 			}
 		} else if (res > -1) {
-			for (which=0;which<NUM_DCHANS;which++) {
+			for (which = 0; which < NUM_DCHANS; which++) {
 				if (!pri->dchans[which])
 					break;
 				if (fds[which].revents & POLLPRI) {
@@ -8339,7 +8348,7 @@
 				pri_dump_event(pri->dchans[which], e);
 			if (e->e != PRI_EVENT_DCHAN_DOWN)
 				pri->dchanavail[which] |= DCHAN_UP;
-			switch(e->e) {
+			switch (e->e) {
 			case PRI_EVENT_DCHAN_UP:
 				if (option_verbose > 1) 
 					ast_verbose(VERBOSE_PREFIX_2 "%s D-Channel on span %d up\n", pri_order(which), pri->span);
@@ -8356,7 +8365,7 @@
 				}
 				pri->resetting = 0;
 				/* Take the channels from inalarm condition */
-				for (i=0; i<pri->numchans; i++)
+				for (i = 0; i < pri->numchans; i++)
 					if (pri->pvts[i]) {
 						pri->pvts[i]->inalarm = 0;
 					}
@@ -8369,7 +8378,7 @@
 				if (!pri_is_up(pri)) {
 					pri->resetting = 0;
 					/* Hangup active channels and put them in alarm mode */
-					for (i=0; i<pri->numchans; i++) {
+					for (i = 0; i < pri->numchans; i++) {
 						struct zt_pvt *p = pri->pvts[i];
 						if (p) {
 							if (p->call) {
@@ -8414,7 +8423,7 @@
 				} else {
 					if (option_verbose > 2)
 						ast_verbose(VERBOSE_PREFIX_2 "Restart on requested on entire span %d\n", pri->span);
-					for (x=0;x < pri->numchans;x++)
+					for (x = 0; x < pri->numchans; x++)
 						if (pri->pvts[x]) {
 							ast_mutex_lock(&pri->pvts[x]->lock);
 							if (pri->pvts[x]->call) {
@@ -8444,7 +8453,7 @@
 							int digitlen = strlen(e->digit.digits);
 							char digit;
 							int i;					
-							for (i=0; i<digitlen; i++) {	
+							for (i = 0; i < digitlen; i++) {	
 								digit = e->digit.digits[i];
 								{
 									struct ast_frame f = { AST_FRAME_DTMF, digit, };
@@ -8472,7 +8481,7 @@
 							int digitlen = strlen(e->ring.callednum);
 							char digit;
 							int i;					
-							for (i=0; i<digitlen; i++) {	
+							for (i = 0; i < digitlen; i++) {	
 								digit = e->ring.callednum[i];
 								{
 									struct ast_frame f = { AST_FRAME_DTMF, digit, };
@@ -8635,7 +8644,7 @@
 							if (!ast_strlen_zero(e->ring.callingsubaddr)) {
 								pbx_builtin_setvar_helper(c, "CALLINGSUBADDR", e->ring.callingsubaddr);
 							}
-							if(e->ring.ani2 >= 0) {
+							if (e->ring.ani2 >= 0) {
 								snprintf(ani2str, 5, "%.2d", e->ring.ani2);
 								pbx_builtin_setvar_helper(c, "ANI2", ani2str);
 							}
@@ -8674,7 +8683,7 @@
 							ast_mutex_lock(&pri->lock);
 							if (c) {
 								char calledtonstr[10];
-								if(e->ring.ani2 >= 0) {
+								if (e->ring.ani2 >= 0) {
 									snprintf(ani2str, 5, "%d", e->ring.ani2);
 									pbx_builtin_setvar_helper(c, "ANI2", ani2str);
 								}
@@ -8741,7 +8750,7 @@
 						if (e->ringing.progress == 8) {
 #endif
 							/* Now we can do call progress detection */
-							if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
+							if (pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
 								/* RINGING detection isn't required because we got ALERTING signal */
 								ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features & ~DSP_PROGRESS_RINGING);
 								pri->pvts[chanpos]->dsp_features = 0;
@@ -8795,7 +8804,7 @@
 						if (e->proceeding.progress == 8) {
 #endif
 							/* Now we can do call progress detection */
-							if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
+							if (pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
 								ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
 								pri->pvts[chanpos]->dsp_features = 0;
 							}
@@ -8821,7 +8830,7 @@
 						if (e->proceeding.progress == 8) {
 #endif
 							/* Now we can do call progress detection */
-							if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
+							if (pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
 								ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
 								pri->pvts[chanpos]->dsp_features = 0;
 							}
@@ -8872,7 +8881,7 @@
 						/* We changed this so it turns on the DSP no matter what... progress or no progress.
 						 * By this time, we need DTMF detection and other features that were previously disabled
 						 * -- Matt F */
-						if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
+						if (pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
 							ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
 							pri->pvts[chanpos]->dsp_features = 0;
 						}
@@ -8930,7 +8939,7 @@
 							else if (pri->pvts[chanpos]->owner) {
 								/* Queue a BUSY instead of a hangup if our cause is appropriate */
 								pri->pvts[chanpos]->owner->hangupcause = e->hangup.cause;
-								switch(e->hangup.cause) {
+								switch (e->hangup.cause) {
 								case PRI_CAUSE_USER_BUSY:
 									pri->pvts[chanpos]->subs[SUB_REAL].needbusy =1;
 									break;
@@ -8994,7 +9003,7 @@
 							pri_hangup_all(pri->pvts[chanpos]->realcall, pri);
 						else if (pri->pvts[chanpos]->owner) {
 							pri->pvts[chanpos]->owner->hangupcause = e->hangup.cause;
-							switch(e->hangup.cause) {
+							switch (e->hangup.cause) {
 							case PRI_CAUSE_USER_BUSY:
 								pri->pvts[chanpos]->subs[SUB_REAL].needbusy =1;
 								break;
@@ -9074,7 +9083,7 @@
 					/* Sometime switches (e.g. I421 / British Telecom) don't give us the
 					   channel number, so we have to figure it out...  This must be why
 					   everybody resets exactly a channel at a time. */
-					for (x=0;x<pri->numchans;x++) {
+					for (x = 0; x < pri->numchans; x++) {
 						if (pri->pvts[x] && pri->pvts[x]->resetting) {
 							chanpos = x;
 							ast_mutex_lock(&pri->pvts[chanpos]->lock);
@@ -9132,7 +9141,7 @@
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
 						pri->pvts[chanpos]->setup_ack = 1;
 						/* Send any queued digits */
-						for (x=0;x<strlen(pri->pvts[chanpos]->dialdest);x++) {
+						for (x = 0;x < strlen(pri->pvts[chanpos]->dialdest); x++) {
 							ast_log(LOG_DEBUG, "Sending pending digit '%c'\n", pri->pvts[chanpos]->dialdest[x]);
 							pri_information(pri->pri, pri->pvts[chanpos]->call, 
 								pri->pvts[chanpos]->dialdest[x]);
@@ -9150,7 +9159,7 @@
 				} else {
 					struct ast_frame f = { AST_FRAME_CONTROL, };
 					ast_mutex_lock(&pri->pvts[chanpos]->lock);
-					switch(e->notify.info) {
+					switch (e->notify.info) {
 					case PRI_NOTIFY_REMOTE_HOLD:
 						f.subclass = AST_CONTROL_HOLD;
 						zap_queue_frame(pri->pvts[chanpos], &f, pri);
@@ -9181,7 +9190,7 @@
 	struct zt_spaninfo si;
 	int i;
 	
-	for (i=0;i<NUM_DCHANS;i++) {
+	for (i = 0; i < NUM_DCHANS; i++) {
 		if (!pri->dchannels[i])
 			break;
 		pri->fds[i] = open("/dev/zap/channel", O_RDWR, 0600);
@@ -9251,7 +9260,7 @@
 	pri->pri = pri->dchans[0];
 	pri->resetpos = -1;
 	if (ast_pthread_create(&pri->master, NULL, pri_dchannel, pri)) {
-		for (i=0;i<NUM_DCHANS;i++) {
+		for (i = 0; i < NUM_DCHANS; i++) {
 			if (!pri->dchannels[i])
 				break;
 			zt_close(pri->fds[i]);
@@ -9346,7 +9355,7 @@
 		ast_cli(fd, "No PRI running on span %d\n", span);
 		return RESULT_SUCCESS;
 	}
-	for (x=0;x<NUM_DCHANS;x++) {
+	for (x = 0; x < NUM_DCHANS; x++) {
 		if (pris[span-1].dchans[x])
 			pri_set_debug(pris[span-1].dchans[x], PRI_DEBUG_APDU | PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE);
 	}
@@ -9371,7 +9380,7 @@
 		ast_cli(fd, "No PRI running on span %d\n", span);
 		return RESULT_SUCCESS;
 	}
-	for (x=0;x<NUM_DCHANS;x++) {
+	for (x = 0; x < NUM_DCHANS; x++) {
 		if (pris[span-1].dchans[x])
 			pri_set_debug(pris[span-1].dchans[x], 0);
 	}
@@ -9394,7 +9403,7 @@
 		ast_cli(fd, "No PRI running on span %d\n", span);
 		return RESULT_SUCCESS;
 	}
-	for (x=0;x<NUM_DCHANS;x++) {
+	for (x = 0; x < NUM_DCHANS; x++) {
 		if (pris[span-1].dchans[x])
 			pri_set_debug(pris[span-1].dchans[x], (PRI_DEBUG_APDU | PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_STATE));
 	}
@@ -9460,7 +9469,7 @@
 		ast_cli(fd, "No PRI running on span %d\n", span);
 		return RESULT_SUCCESS;
 	}
-	for(x=0;x<NUM_DCHANS;x++) {
+	for (x = 0; x < NUM_DCHANS; x++) {
 		if (pris[span-1].dchannels[x]) {
 #ifdef PRI_DUMP_INFO_STR
 			char *info_str = NULL;
@@ -9490,10 +9499,10 @@
 	int count=0;
 	int debug=0;
 
-	for(span=0;span<NUM_SPANS;span++) {
+	for (span = 0; span < NUM_SPANS; span++) {
 	        if (pris[span].pri) {
-			for(x=0;x<NUM_DCHANS;x++) {
-				debug=0;
+			for (x = 0; x < NUM_DCHANS; x++) {
+				debug = 0;
 	        		if (pris[span].dchans[x]) {
 	        			debug = pri_get_debug(pris[span].dchans[x]);
 					ast_cli(fd, "Span %d: Debug: %s\tIntense: %s\n", span+1, (debug&PRI_DEBUG_Q931_STATE)? "Yes" : "No" ,(debug&PRI_DEBUG_Q921_RAW)? "Yes" : "No" );
@@ -9628,7 +9637,7 @@
 	struct zt_pvt *start;
 #ifdef HAVE_LIBPRI
 	int trunkgroup;
-	struct zt_pri *pri=NULL;
+	struct zt_pri *pri = NULL;
 	int x;
 #endif
 
@@ -9639,7 +9648,7 @@
 	if (argc == 4) {
 		if ((trunkgroup = atoi(argv[3])) < 1)
 			return RESULT_SHOWUSAGE;
-		for (x=0;x<NUM_SPANS;x++) {
+		for (x = 0; x < NUM_SPANS; x++) {
 			if (pris[x].trunkgroup == trunkgroup) {
 				pri = pris + x;
 				break;
@@ -9705,7 +9714,7 @@
 			return RESULT_SHOWUSAGE;
 		if ((trunkgroup < 1) || (channel < 1))
 			return RESULT_SHOWUSAGE;
-		for (x=0;x<NUM_SPANS;x++) {
+		for (x = 0; x < NUM_SPANS; x++) {
 			if (pris[x].trunkgroup == trunkgroup) {
 				pri = pris + x;
 				break;
@@ -9760,7 +9769,7 @@
 			ast_cli(fd, "Echo Cancellation: %d taps%s, currently %s\n", tmp->echocancel, tmp->echocanbridged ? "" : " unless TDM bridged", tmp->echocanon ? "ON" : "OFF");
 			if (tmp->master)
 				ast_cli(fd, "Master Channel: %d\n", tmp->master->channel);
-			for (x=0;x<MAX_SLAVES;x++) {
+			for (x = 0; x < MAX_SLAVES; x++) {
 				if (tmp->slaves[x])
 					ast_cli(fd, "Slave Channel: %d\n", tmp->slaves[x]->channel);
 			}
@@ -9816,13 +9825,13 @@
 static int handle_zap_show_cadences(int fd, int argc, char *argv[])
 {
 	int i, j;
-	for (i=0;i<num_cadence;i++) {
+	for (i = 0; i < num_cadence; i++) {
 		char output[1024];
 		char tmp[16], tmp2[64];
 		snprintf(tmp, sizeof(tmp), "r%d: ", i + 1);
 		term_color(output, tmp, COLOR_GREEN, COLOR_BLACK, sizeof(output));
 
-		for (j=0;j<16;j++) {
+		for (j = 0; j < 16; j++) {
 			if (cadences[i].ringcadence[j] == 0)
 				break;
 			snprintf(tmp, sizeof(tmp), "%d", cadences[i].ringcadence[j]);
@@ -9857,9 +9866,9 @@
 		ast_cli(fd, "No Zaptel interface found.\n");
 		return RESULT_FAILURE;
 	}
-	ast_cli(fd,FORMAT2, "Description", "Alarms","IRQ","bpviol","CRC4");
+	ast_cli(fd, FORMAT2, "Description", "Alarms", "IRQ", "bpviol", "CRC4");
 
-	for (span=1;span < ZT_MAX_SPANS;++span) {
+	for (span = 1; span < ZT_MAX_SPANS; ++span) {
 		s.spanno = span;
 		res = ioctl(ctl, ZT_SPANSTAT, &s);
 		if (res) {
@@ -9868,22 +9877,22 @@
 		alarms[0] = '\0';
 		if (s.alarms > 0) {
 			if (s.alarms & ZT_ALARM_BLUE)
-				strcat(alarms,"BLU/");
+				strcat(alarms, "BLU/");
 			if (s.alarms & ZT_ALARM_YELLOW)
 				strcat(alarms, "YEL/");
 			if (s.alarms & ZT_ALARM_RED)
 				strcat(alarms, "RED/");
 			if (s.alarms & ZT_ALARM_LOOPBACK)
-				strcat(alarms,"LB/");
+				strcat(alarms, "LB/");
 			if (s.alarms & ZT_ALARM_RECOVER)
-				strcat(alarms,"REC/");
+				strcat(alarms, "REC/");
 			if (s.alarms & ZT_ALARM_NOTOPEN)
 				strcat(alarms, "NOP/");
 			if (!strlen(alarms))
 				strcat(alarms, "UUU/");
 			if (strlen(alarms)) {
 				/* Strip trailing / */
-				alarms[strlen(alarms)-1]='\0';
+				alarms[strlen(alarms) - 1] = '\0';
 			}
 		} else {
 			if (s.numchans)
@@ -9945,7 +9954,7 @@
 static int zap_fake_event(struct zt_pvt *p, int mode)
 {
 	if (p) {
-		switch(mode) {
+		switch (mode) {
 			case TRANSFER:
 				p->fake_event = ZT_EVENT_WINKFLASH;
 				break;
@@ -9961,7 +9970,7 @@
 static struct zt_pvt *find_channel(int channel)
 {
 	struct zt_pvt *p = iflist;
-	while(p) {
+	while (p) {
 		if (p->channel == channel) {
 			break;
 		}
@@ -10065,7 +10074,7 @@
 		astman_send_error(s, m, "Channel does not have it's owner");
 		return 0;
 	}
-	for (i=0; i<strlen(number); i++) {
+	for (i = 0; i < strlen(number); i++) {
 		struct ast_frame f = { AST_FRAME_DTMF, number[i] };
 		zap_queue_frame(p, &f, NULL); 
 	}
@@ -10122,7 +10131,7 @@
 	struct zt_pvt *p, *pl;
 #ifdef HAVE_LIBPRI
 	int i;
-	for(i=0;i<NUM_SPANS;i++) {
+	for (i = 0; i < NUM_SPANS; i++) {
 		if (pris[i].master != AST_PTHREADT_NULL) 
 			pthread_cancel(pris[i].master);
 	}
@@ -10140,7 +10149,7 @@
 	ast_mutex_lock(&iflock);
 	/* Hangup all interfaces if they have an owner */
 	p = iflist;
-	while(p) {
+	while (p) {
 		if (p->owner)
 			ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
 		p = p->next;
@@ -10158,7 +10167,7 @@
 	ast_mutex_lock(&iflock);
 	/* Destroy all the interfaces and free their memory */
 	p = iflist;
-	while(p) {
+	while (p) {
 		/* Free any callerid */
 		if (p->cidspill)
 			free(p->cidspill);
@@ -10169,7 +10178,7 @@
 		p = p->next;
 		x++;
 		/* Free associated memory */
-		if(pl)
+		if (pl)
 			destroy_zt_pvt(&pl);
 		ast_verbose(VERBOSE_PREFIX_3 "Unregistered channel %d\n", x);
 	}
@@ -10177,7 +10186,7 @@
 	ifcount = 0;
 	ast_mutex_unlock(&iflock);
 #ifdef HAVE_LIBPRI		
-	for(i=0;i<NUM_SPANS;i++) {
+	for (i = 0; i < NUM_SPANS; i++) {
 		if (pris[i].master && (pris[i].master != AST_PTHREADT_NULL))
 			pthread_join(pris[i].master, NULL);
 		zt_close(pris[i].fds[i]);
@@ -10190,7 +10199,7 @@
 {
 #ifdef HAVE_LIBPRI		
 	int y;
-	for (y=0;y<NUM_SPANS;y++)
+	for (y = 0; y < NUM_SPANS; y++)
 		ast_mutex_destroy(&pris[y].lock);
 #endif
 	return __unload_module();
@@ -10232,14 +10241,14 @@
 	if (!reload) {
 		/* Process trunkgroups first */
 		v = ast_variable_browse(cfg, "trunkgroups");
-		while(v) {
+		while (v) {
 			if (!strcasecmp(v->name, "trunkgroup")) {
 				trunkgroup = atoi(v->value);
 				if (trunkgroup > 0) {
 					if ((c = strchr(v->value, ','))) {
 						i = 0;
 						memset(dchannels, 0, sizeof(dchannels));
-						while(c && (i < NUM_DCHANS)) {
+						while (c && (i < NUM_DCHANS)) {
 							dchannels[i] = atoi(c + 1);
 							if (dchannels[i] < 0) {
 								ast_log(LOG_WARNING, "D-channel for trunk group %d must be a postiive number at line %d of zapata.conf\n", trunkgroup, v->lineno);
@@ -10289,7 +10298,7 @@
 	}
 #endif
 	v = ast_variable_browse(cfg, "channels");
-	while(v) {
+	while (v) {
 		/* Create the interface list */
 		if (!strcasecmp(v->name, "channel")
 #ifdef HAVE_LIBPRI
@@ -10321,8 +10330,8 @@
 					ast_mutex_unlock(&iflock);
 					return -1;
 				}
-				c+=y;
-				for (y=0;y<NUM_SPANS;y++) {
+				c += y;
+				for (y = 0; y < NUM_SPANS; y++) {
 					if (pris[y].trunkgroup == trunkgroup) {
 						pri = pris + y;
 						break;
@@ -10337,7 +10346,7 @@
 			}
 #endif			
 			chan = strsep(&c, ",");
-			while(chan) {
+			while (chan) {
 				if (sscanf(chan, "%d-%d", &start, &finish) == 2) {
 					/* Range */
 				} else if (sscanf(chan, "%d", &start)) {
@@ -10359,7 +10368,7 @@
 					start = x;
 				}
 				if (cur_outsignalling < 0) cur_outsignalling = cur_signalling;
-				for (x=start;x<=finish;x++) {
+				for (x = start; x <= finish; x++) {
 #ifdef HAVE_LIBPRI
 					tmp = mkintf(x, cur_signalling, cur_outsignalling, cur_radio, pri, reload);
 #else					
@@ -10569,7 +10578,7 @@
 				ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno);
 			else
 				amaflags = y;
-		} else if(!reload){ 
+		} else if (!reload){ 
 			 if (!strcasecmp(v->name, "signalling")) {
 				cur_outsignalling = -1;
 				if (!strcasecmp(v->value, "em")) {
@@ -10821,7 +10830,7 @@
 			} else if (!strcasecmp(v->name, "resetinterval")) {
 				if (!strcasecmp(v->value, "never"))
 					resetinterval = -1;
-				else if( atoi(v->value) >= 60 )
+				else if (atoi(v->value) >= 60)
 					resetinterval = atoi(v->value);
 				else
 					ast_log(LOG_WARNING, "'%s' is not a valid reset interval, should be >= 60 seconds or 'never' at line %d\n",
@@ -10880,7 +10889,7 @@
 				}
 	
 				/* Ring cadences cannot be negative */
-				for (i=0;i<element_count;i++) {
+				for (i = 0; i < element_count; i++) {
 					if (c[i] == 0) {
 						ast_log(LOG_ERROR, "Ring or silence duration cannot be zero: %s\n", original_args);
 						cadence_is_ok = 0;
@@ -10910,7 +10919,7 @@
 				}
 	
 				/* Substitute our scanned cadence */
-				for (i=0;i<16;i++) {
+				for (i = 0; i < 16; i++) {
 					new_cadence.ringcadence[i] = c[i];
 				}
 	
@@ -11018,7 +11027,7 @@
 	ast_config_destroy(cfg);
 #ifdef HAVE_LIBPRI
 	if (!reload) {
-		for (x=0;x<NUM_SPANS;x++) {
+		for (x = 0; x < NUM_SPANS; x++) {
 			if (pris[x].pvts[0]) {
 				if (start_pri(pris + x)) {
 					ast_log(LOG_ERROR, "Unable to start D-channel on span %d\n", x + 1);
@@ -11041,11 +11050,11 @@
 #ifdef HAVE_LIBPRI
 	int y,i;
 	memset(pris, 0, sizeof(pris));
-	for (y=0;y<NUM_SPANS;y++) {
+	for (y = 0; y < NUM_SPANS; y++) {
 		ast_mutex_init(&pris[y].lock);
 		pris[y].offset = -1;
 		pris[y].master = AST_PTHREADT_NULL;
-		for (i=0;i<NUM_DCHANS;i++)
+		for (i = 0; i < NUM_DCHANS; i++)
 			pris[y].fds[i] = -1;
 	}
 	pri_set_error(zt_pri_error);
@@ -11055,9 +11064,8 @@
 #endif
 	res = setup_zap(0);
 	/* Make sure we can register our Zap channel type */
-	if(res) {
-	  return -1;
-	}
+	if (res)
+		return -1;
 	if (ast_channel_register(&zap_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel class 'Zap'\n");
 		__unload_module();
@@ -11117,31 +11125,30 @@
 	mybuf = buf;
 	if (p->mate) {
 		int codec = AST_LAW(p);
-		for (x=0;x<HEADER_MS;x++) {	/* 50 ms of Mark */
+		for (x = 0; x < HEADER_MS; x++) {	/* 50 ms of Mark */
 			PUT_CLID_MARKMS;
-			}
+		}
 		/* Put actual message */
-		for (x=0;text[x];x++)  {
+		for (x = 0; text[x]; x++) {
 			PUT_CLID(text[x]);
-			}
-		for (x=0;x<TRAILER_MS;x++) {	/* 5 ms of Mark */
+		}
+		for (x = 0; x < TRAILER_MS; x++) {	/* 5 ms of Mark */
 			PUT_CLID_MARKMS;
-			}
+		}
 		len = bytes;
 		buf = mybuf;
-	}
-	else {
-		len = tdd_generate(p->tdd,buf,text);
+	} else {
+		len = tdd_generate(p->tdd, buf, text);
 		if (len < 1) {
-			ast_log(LOG_ERROR, "TDD generate (len %d) failed!!\n",(int)strlen(text));
+			ast_log(LOG_ERROR, "TDD generate (len %d) failed!!\n", (int)strlen(text));
 			free(mybuf);
 			return -1;
 		}
 	}
-	memset(buf + len,0x7f,END_SILENCE_LEN);
+	memset(buf + len, 0x7f, END_SILENCE_LEN);
 	len += END_SILENCE_LEN;
 	fd = p->subs[index].zfd;
-	while(len) {
+	while (len) {
 		if (ast_check_hangup(c)) {
 			free(mybuf);
 			return -1;
@@ -11158,7 +11165,8 @@
 			continue;
 		}
 		  /* if got exception */
-		if (fds[0].revents & POLLPRI) return -1;
+		if (fds[0].revents & POLLPRI)
+			return -1;
 		if (!(fds[0].revents & POLLOUT)) {
 			ast_log(LOG_DEBUG, "write fd not ready on channel %d\n", p->channel);
 			continue;
