📄 yspapi.c
字号:
sqlstm.sqpind = sqlstm.sqindv;
sqlstm.sqparm = sqlstm.sqharm;
sqlstm.sqparc = sqlstm.sqharc;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
if (sqlca.sqlcode < 0) sqlerror();
}
/* EXEC SQL COMMIT WORK; */
{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 8;
sqlstm.arrsiz = 3;
sqlstm.iters = (unsigned int )1;
sqlstm.offset = (unsigned int )78;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)0;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
if (sqlca.sqlcode < 0) sqlerror();
}
return(1);
}
/*
Read a line to a string from a file, "\n" is excluded.
return 1 if sucessful, 0 otherwise
Do not close the file.
*/
int myapi_ReadALinefromF( char *cALine,FILE *hTable )
{
char cChar='\0';
int i=0;
cALine[0] = '\0';
while( (cChar = fgetc( hTable )) != '\n' )
{
if( cChar == EOF ) return(0);
cALine[i++] = cChar;
if( i >= MAX_LINE_LEN ) i=0;
cALine[i] = '\0'; /* define the end of a string */
}
return(1);
}
/*Get the Time_Interval specified in the file and return it */
int GetTimeInterval(char* cType)
{
FILE *hTimeInterval;
char cLine[MAX_LINE_LEN+1], cCaption[100], cValue[21];
int iInterval, i;
char* pLine;
hTimeInterval = fopen( CONFIG_FILE_FOR_TIMEINTERVAL, "r" );
if( hTimeInterval == NULL )
{
ProcessError(LOG_ERROR, "GetTimeInterval: Cannot open file: ", CONFIG_FILE_FOR_TIMEINTERVAL);
return(DEFAULT_TIMEINTERVAL);
}
while( myapi_ReadALine( cLine, hTimeInterval ) )
{
if( cLine[0] == '#' ) continue;
if( cLine[0] == NULL ) continue;
pLine = cLine;
while( (*pLine == ' ') || (*pLine == '\t') ) pLine++;
i=0;
while( (*pLine != ' ') && (*pLine != '\t') && (*pLine != '\0') )
{
cCaption[i] = *pLine;
i++;
pLine++;
}
cCaption[i] = '\0';
if( strcmp( cCaption, cType ) == 0 ) /*Match*/
{
while( (*pLine == ' ') || (*pLine == '\t') ) pLine++;
if( *pLine == '\0' )
{
fclose(hTimeInterval);
return(DEFAULT_TIMEINTERVAL);
}
i=0;
while( (*pLine != ' ') && (*pLine != '\t') && (*pLine != '\0') )
{
cValue[i] = *pLine;
i++;
pLine++;
}
cValue[i] = '\0';
iInterval = atoi(cValue);
if(iInterval <= 0)
{
fclose(hTimeInterval);
return(DEFAULT_TIMEINTERVAL);
}
else
{
fclose(hTimeInterval);
return(iInterval);
}
}
else
continue;
}
fclose( hTimeInterval );
return(DEFAULT_TIMEINTERVAL);
}
/*Read a line to a string from a file, \n is excluded.
return 1 if sucessful, 0 otherwise
Do not close the file.*/
int myapi_ReadALine( char* cLine, FILE* hTable )
{
char cChar;
int i=0;
cLine[0] = '\0';
while( (cChar = fgetc( hTable )) != '\n' )
{
if( cChar == EOF ) return(0);
cLine[i++] = cChar;
if( i >= MAX_LINE_LEN ) i=0;
cLine[i] = '\0';
}
return(1);
}
/*Get the local sbh specified in the file and return it*/
/* the bsbh will be got from table t_bsbh , not from a file!
int GetBSBH(void)
{
FILE *hbsbh;
char cLine[MAX_LINE_LEN+1];
int iInterval;
hbsbh = fopen( CONFIG_FILE_FOR_BSBH, "r" );
if( hbsbh == NULL )
{
return(DEFAULT_BSBH);
}
while( myapi_ReadALinefromF( cLine, hbsbh ) )
{
if( cLine[0] == '#' ) continue;
if( cLine[0] == NULL )continue;
iInterval = atoi( cLine );
if(iInterval <= 0)
{
return(DEFAULT_BSBH);
}
else
return(iInterval);
}
fclose( hbsbh );
return(0);
}
*/
int GetBSBH(void)
{
int iInterval;
char bsbh[3];
/* EXEC SQL SELECT BSBH INTO :bsbh FROM T_BSBH; */
{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 8;
sqlstm.arrsiz = 3;
sqlstm.stmt = "select BSBH into :b0 from T_BSBH ";
sqlstm.iters = (unsigned int )1;
sqlstm.offset = (unsigned int )92;
sqlstm.selerr = (unsigned short)1;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)0;
sqlstm.sqhstv[0] = (unsigned char *)bsbh;
sqlstm.sqhstl[0] = (unsigned int )3;
sqlstm.sqindv[0] = ( short *)0;
sqlstm.sqharm[0] = (unsigned int )0;
sqlstm.sqphsv = sqlstm.sqhstv;
sqlstm.sqphsl = sqlstm.sqhstl;
sqlstm.sqpind = sqlstm.sqindv;
sqlstm.sqparm = sqlstm.sqharm;
sqlstm.sqparc = sqlstm.sqharc;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
if (sqlca.sqlcode < 0) sqlerror();
}
iInterval = atoi( bsbh );
return( iInterval );
}
/* change the int varible to the string */
void itoa(long The_int_data, char* The_out_string, int j)
{
char exch_str[12];
char a;
int i=0, n, the_mod;
The_out_string[0]='\0';
/* if the int varible is zero, then ...*/
if (The_int_data==0)
{
exch_str[0]='0';
exch_str[1]='\0';
strcat( The_out_string, exch_str);
for(n=1;n<j-1;n++)
The_out_string[n]=' ';
The_out_string[n]='\0';
return;
}
while(1)
{
the_mod = The_int_data%10;
exch_str[i] = (char )(the_mod+48);
exch_str[i+1] = '\0';
i++;
/* change the last digit to char */
if((The_int_data = (The_int_data/10))<10)
{
exch_str[i] = (char)(The_int_data+48);
exch_str[i+1] = '\0';
break;
}
}
/* overtrun the order */
for(n=0;n<=i;n++)
The_out_string[n] = exch_str[i-n];
for(n=i+1;n<j-1;n++)
The_out_string[n]=' ';
The_out_string[n]='\0';
}
/* change the float varible to string, the parameter 'm' is the decimal */
void ftoa(float The_float_data, char *The_out_string, int m, int j)
{
float dot_data;
long The_int_body, The_int_data;
int k=10;
int i=1,n;
char First_string[8], End_string[8], dot[2],whole_string[10];
The_out_string[0]='\0';
dot[0]='.';
dot[1]='\0';
/* if the float equl to zero ,then ... */
if (The_float_data==0)
{
if (m==0)
{
First_string[0]='0';
First_string[1]='\0';
strcat(The_out_string, First_string);
for(n=1;n<j-1;n++)
The_out_string[n]=' ';
The_out_string[n]='\0';
return;
}
First_string[0]='0';
First_string[1]='\0';
strcat(The_out_string, First_string);
strcat(The_out_string, dot);
for(n=0;n<m;n++)
End_string[n]='0';
End_string[n]='\0';
strcat(The_out_string, End_string);
for(n=m+2;n<j-1;n++)
The_out_string[n]=' ';
The_out_string[n]='\0';
return;
}
/* change the float to long varible */
for(n=1;n<m;n++)
k = 10*k;
if( (The_float_data*k-(int)(The_float_data*k))<0.5 )
The_int_body = (int)(The_float_data*k);
else
The_int_body = (int)(The_float_data*k)+1;
/* calculate the digit of the long varible */
The_int_data = The_int_body;
while(1)
{
if((The_int_data = (The_int_data/10))<10)
break;
i++;
}
i++;
itoa(The_int_body, whole_string, i);
/* if the float varible smaller than 1, then ... */
if (The_float_data< 1 )
{
First_string[0]='0';
First_string[1]='\0';
strcat(The_out_string, First_string);
strcat(The_out_string, dot);
strcat(The_out_string, whole_string);
for(n=i+2;n<j-1;n++)
The_out_string[n]=' ';
The_out_string[n]='\0';
return;
}
/*change the varible to the First_string and End_string seperate by the dot */
for(n=0;n<i-m;n++)
First_string[n]=whole_string[n];
First_string[n]='\0';
for(n=0;n<m;n++)
End_string[n]=whole_string[i-m+n];
End_string[n]='\0';
strcat( The_out_string, First_string );
strcat( The_out_string, dot );
strcat( The_out_string, End_string );
for(n=i+1;n<j-1;n++)
The_out_string[n]=' ';
The_out_string[n]='\0';
}
/** get sbh from bkdh **/
void getsbh(char *bkdh,char *tempstring)
{
tempstring[0]=bkdh[0];
if ( bkdh[1]!='-' )
{
tempstring[1]=bkdh[1];
tempstring[2]='\0';
}
else
tempstring[1]='\0';
}
/** add ' ' to format a string to a appointed length **/
void str_format(char *str,int n)
{
int i;
for( i=0;i<n;i++ )
{
if(str[i]=='\0')
break;
}
if( i==n )
str[i-1]='\0';
for( ;i<n-1;i++ )
{
str[i]=' ';
}
str[n-1]='\0';
}
int MQBKSend( void )
{
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -