📄 gatepars.c
字号:
/**********************************************************************************************
*
* $ProjectName: X:/SIPROJ/VOIP/HOST/WIN_NT/DEMOS/Samples.rel4/Dm3/iplink/project.pj $
* $ProjectRevision: 1.8 $
* $Label$
* $Revision: 1.7 $ - $Date: 2001/12/24 13:31:25 $
*
**********************************************************************************************/
/* The DEMO H files are needed in this order: */
#include <libdbg.h>
#include "gatestrc.h"
#include "gatepars.h"
#include "gatevars.h"
unsigned char stage = 0;
int line = 0;
long firstSession=1;
long lastSession=1;
unsigned char firstBoard = 0;
unsigned char lastBoard = 0;
/****************************************************/
/* */
/* DEFINITION OF GLOBAL FUNCTIONS */
/* */
/****************************************************/
/*****FUNCTION***************************************************
* NAME : gateConfiguration
* DESCRIPTION : Static function to read .cfg file to fill in
* Session
* INPUT : config file name
* OUTPUT : None
* RETURNS : 1 - success, 0 - fail
* CAUTIONS : None
****************************************************************/
int gateConfiguration(char *cfgFile)
{
/* see IPTpars.c for parsing routines */
FILE *handler;
int err;
char buf1[IPT_MAX_STRING];
line = 0;
handler = fopen(cfgFile,"rt"); /* opens configuration file */
if(handler == NULL) {
/* cfg file not found */
printf("\tConfiguration file not exist: %s\n",cfgFile);
return (FUNCFAIL);
}
while(1) {
/* Read configuration file line by line, and interpret line */
line++;
if(fgets( buf1, IPT_MAX_STRING, handler ) == NULL ) {
if( feof(handler)) {
break;
} else {
printf("\tError reading configuration file: line %d\n",line);
return(FUNCFAIL);
}
}
/* remark in configuration file */
if((buf1[0] == '#') || (buf1[0] == '*') || (buf1[0] == ';')) {
continue;
}
err = parse_line(buf1); /* Interpret line */
if(err < 0) {
/* Configuration line bad structure */
fclose(handler);
if(err == -1) {
printf("\tIllegal command in configuration file: line %d",line);
}
printf("\n\tError with parsing of line:\n\t%s\n",buf1);
return (FUNCFAIL);
}
} /* end while 1 parsing lines */
fclose(handler);
if((stage != 0) ) {
/* brackets not closed illegal file structure */
printf("%s","\tIllegal end of .cfg file. \n");
return(FUNCFAIL);
}
return(FUNCSUCCESS);
} /* Function GetConfiguration */
/****************************************************/
/* */
/* DECLARATIONTION OF LOCAL FUNCTIONS */
/* */
/****************************************************/
/*******************************************************************
* NAME : ut_aschex(msg)
*DESCRIPTION : Utility to convert ascii hex characters to binary.
* INPUT : msg = Pointer to ascii string.
* OUTPUT : None.
* RETURNS : Binary value of msg.
* CAUTIONS : None.
*******************************************************************/
static long ut_aschex(char *msg)
{
long i=0;
while(*msg != '\0') {
i = (i<<4) + (*msg)-0x30;
if(*msg>='a') {
i -= 0x20;
}
if(*msg>='A') {
i -= 7;
}
msg++;
}
return(i);
}
/*******************************************************************
* NAME : ut_asnum(msg)
*DESCRIPTION : Utility to convert ascii characters to binary.
* INPUT : msg = Pointer to ascii string.
* OUTPUT : None.
* RETURNS : Binary value of msg.
* CAUTIONS : None.
*******************************************************************/
static long ut_asnum(char *msg)
{
long i=0;
while(*msg != '\0') {
if((*msg < '0') || (*msg > '9')) {
return(-1);
}
i = (i * 10) + (*msg)-0x30;
msg++;
}
return(i);
}
/****************************************************************
* NAME : skip
* DESCRIPTION : Gets line of data file, and converts text to numbers
* Input line may be of the form:
* TITLE = 5 7 aaaa
* Skip() deals only with second half of line (5 7 aaaa etc.)
*
* If looking for string only vnum is 0 and *n is useless
* If looking for value vnum is 1 and *name is useless
*
* INPUT : Data line, array of integers which will be returned,
* expected number of variables in text, string to be returned.
* OUTPUT :
* RETURNS : Number of elements found in line.
* CAUTIONS :
****************************************************************/
static int skip(int equal,char *p,long *n,int vnum,char *name)
{
char p2[IPT_MAX_STRING]; /* maximum 30 chars to get */
int i;
int j=-1;
/* Check if using = sign */
if(equal) {
/* move to right of = sign */
while((*p) && (*p != '=')) {
p++;
}
if((*p == '\0') || (*p == '\n') || (*p == '\r')) {
/* empty line */
return(0);
}
p++;
}
/* catch vnum number of values */
for(j = 0; j < vnum; j++) {
/* skip white space */
while((*p) && ((*p == ' ') || (*p == '\t') || (*p == '-'))) {
p++;
}
if((*p == '\0') || (*p == '\n') || (*p == '\r')) {
return(j);
}
/* start collecting */
i = 0;
while((*p) && (*p != '-') && (*p != '\r') && (*p != '\n') && (*p != ' ') && (*p != '\t')) {
p2[i] = *p;
i++;
p++;
}
/* add ascii zero */
p2[i] = '\0';
/* convert */
if((p2[0] == '0') && (p2[1] == 'x')) { /* hexa value */
n[j] = ut_aschex((char *)(&(p2[2])));
} else {
n[j] = ut_asnum((char *)(&(p2[0])));
}
}
/* return appropriate values */
if(!equal) {
return(j);
}
while((*p) && (*p == ' ')) {
p++;
}
if((*p == '\0') || (*p == '\n') || (*p == '\r')) {
return(j);
}
/* build return string "name" */
while((*p) && (*p != '\r') && (*p != '\n')) {
*name = *p;
name++;
p++;
}
*name = '\0';
j++;
return(j);
}
/****************************************************************
* NAME : parse_line
* DESCRIPTION : Parses input line and interprets it.
* Way of parsing & interpreting determined according
* to structure of input line as may be seen in
* configuration file ( .cfg ).
* INPUT : Input line using *p pointer
* OUTPUT :
* RETURNS : less than zero on error
* CAUTIONS :
****************************************************************/
static int parse_line(char *p)
{
int rc; /* return code */
short maxCoders = 0; /* max Tx coders */
long ans[PARSE_MAX_NUM]; /* the value to right of = sign */
char lname[PARSE_MAX_STRING]; /* the string to right of = sign */
char name[PARSE_MAX_STRING];
int ii; /* counter for maxCoders */
int index; /* counter for session number */
while((*p) && ((*p == ' ') || (*p == '\t'))) {
p++;
}
if((*p == '\0') || (*p == '\n')) {
/* empty line */
return(0);
}
if((*p == '#') || (*p == '*') || (*p == ';')) {
/* Remark line */
return(0);
}
if( (stage == 1) || (stage == 3)){ /* Should be '{' */
/* After channel declaration "{" is expected */
if(*p == '{') {
stage++;
return(0);
} else {
printf("\nSyntax Error, '{' is expected;\n (line %d) - %s\n",line,p);
return(-2);
}
}
PDLlower(p);
/* next stage == 2 */
if(stage == 2) {
/* Get Calling Address
only the first 4 letters must match here */
if(strncmp(p,"destination",4) == 0) {
/* get this call string */
if((rc = skip(1,p,(long *)ans,0,(char *)name)) != 1) {
printf("\tIllegal configuration line %d:\n\t%s\n",line,p);
return(-1);
}
PDLupper(name);
strcpy(lname,name);
/* strcpy(lname,PDLupper(lname));*/
for(index = firstSession; index <= lastSession; index++) {
strcpy(Session[index].ConfigFileParm.destAddr,lname);
}
return (0);
}
/* Also get coder if there is one */
if(strncmp(p,"capability",5) == 0) {
stage = 3;
return(0);
}
/* Get Calling DISPLAY
only the first 4 letters must match here */
if(strncmp(p,"display",4) == 0) {
/* get this call string */
if((rc = skip(1,p,(long *)ans,0,(char *)lname)) != 1) {
return(-1);
}
for(index = firstSession; index <= lastSession; index++) {
strcpy(Session[index].ConfigFileParm.display,lname);
}
return (0);
}
/* Get UUI */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -