home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
stg_v4.lzh
/
gdesc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-11
|
7KB
|
366 lines
#include <stdio.h>
#include <module.h>
#include ".../device.h"
#define ERR (-1)
#define T_DEC 1
#define T_HEX 2
#define T_STR 3
#define T_YN 4
#define T_MSG 0xFF
extern int errno;
char acName[BUFSIZ];
char acBuf[BUFSIZ];
mod_dev *psDesc;
mod_driver *psDriver;
char *pcTemp;
unsigned long lTemp;
int iUseDef=0;
int hFile;
mod_dev *modlink();
mod_dev *modload();
mod_dev *make_module();
typedef unsigned char B;
typedef unsigned short W;
typedef unsigned long L;
struct sConf
{
B ct_type;
B ct_size;
W ct_offset;
L ct_default;
char ct_desc[24];
} *psConf;
isdesc(s)
char *s;
{
while (*s && *s!='.') s++;
if (!*s) return(0);
s++;
while (*s && *s>='0' && *s<='9') s++;
if (*s) return(0);
return(1);
}
long
udec(s)
char *s;
{
long v=0;
while (*s)
{
v*=10;
if (*s>='0' && *s<='9')
v+=*s-'0';
s++;
}
return(v);
}
long
uhex(s)
char *s;
{
long v=0;
while (*s)
{
v<<=4;
if (*s>='0' && *s<='9')
v+=*s-'0';
if (toupper(*s)>='A' && toupper(*s)<='F')
v+=toupper(*s)-'A'+10;
s++;
}
return(v);
}
input(psConf)
struct sConf *psConf;
{
char *pField;
L value;
if (!psConf->ct_type)
return(0);
if (psConf->ct_type==T_MSG)
{
printf("%s\n",&psConf->ct_size);
return(0);
}
if (psConf->ct_offset==0xFFFF)
pField=(char*)psDesc+0x30;
else if (psConf->ct_offset>0xFF00)
pField=(char*)psDesc+0x30+(~psConf->ct_offset&0x00FF);
else
pField=(char*)psDesc+psDesc->_mdevcon+psConf->ct_offset;
if (!iUseDef) goto try_again;
switch (psConf->ct_type&0x7F)
{
case T_STR: /* no string defaults */
break;
case T_DEC:
case T_HEX:
case T_YN:
switch (psConf->ct_size)
{
case 1:
*(B*)pField=psConf->ct_default&0x000000FF;
break;
case 2:
*(W*)pField=psConf->ct_default&0x0000FFFF;
break;
case 4:
*(L*)pField=psConf->ct_default;
break;
}
}
try_again:
switch (psConf->ct_type&0x7F)
{
case T_DEC:
switch (psConf->ct_size)
{
case 1:
sprintf(acBuf,"%8u",*(B*)pField);
break;
case 2:
sprintf(acBuf,"%8u",*(W*)pField);
break;
case 4:
sprintf(acBuf,"%8lu",*(L*)pField);
break;
}
break;
case T_HEX:
switch (psConf->ct_size)
{
case 1:
sprintf(acBuf," %2X",*(B*)pField);
break;
case 2:
sprintf(acBuf," %04X",*(W*)pField);
break;
case 4:
sprintf(acBuf,"%08lX",*(L*)pField);
break;
}
break;
case T_STR:
strncpy(acBuf,(char*)pField,psConf->ct_size);
*(acBuf+psConf->ct_size)=0;
while (strlen(acBuf)<8) strcat(acBuf," ");
break;
case T_YN:
if (*(B*)pField)
strcpy(acBuf,"Yes ");
else
strcpy(acBuf,"No ");
break;
default:
strcpy(acBuf,"ERROR");
}
if (psConf->ct_type&0x80)
{
printf("%-24s : %s\n",psConf->ct_desc,acBuf);
*acBuf=0;
}
else
{
printf("%-24s [%s] : ",psConf->ct_desc,acBuf);
if ((psConf->ct_type&0x7F)==2) printf("$");
gets(acBuf);
}
if (*acBuf)
{
if ((psConf->ct_type&0x7F)==4)
{
*(B*)pField=*acBuf&1;
}
else if ((psConf->ct_type&0x7F)==3)
{
if (strlen(acBuf)>psConf->ct_size) goto try_again;
if (!strcmp(acBuf," ")) *acBuf=0;
strncpy((char*)pField,acBuf,psConf->ct_size);
}
else
{
switch (psConf->ct_type&0x7f)
{
case 1:
value=udec(acBuf);
break;
case 2:
value=uhex(acBuf);
break;
}
switch (psConf->ct_size)
{
case 1:
if (value>0x000000FF) goto try_again;
*(B*)pField=value;
break;
case 2:
if (value>0x0000FFFF) goto try_again;
*(W*)pField=value;
break;
case 4:
*(L*)pField=value;
break;
}
}
}
}
main(argc,argv)
char **argv;
{
if (*++argv)
{
if (isdesc(*argv))
{
psDesc=(mod_dev*)modlink(*argv,0);
if ((int)psDesc==ERR)
{
psDesc=(mod_dev*)modload(*argv,0);
if ((int)psDesc==ERR)
psDesc=0;
}
}
else
{
psDriver=(mod_driver*)modlink(*argv,0);
if ((int)psDriver==ERR)
{
psDriver=(mod_driver*)modload(*argv,0);
if ((int)psDriver==ERR)
{
if (psDesc) munlink(psDesc);
exit(errno);
}
}
}
}
if (psDesc)
{
pcTemp=(char *)psDesc+psDesc->_mpdev;
printf("Loading driver module: %s\n",pcTemp);
psDriver=(mod_driver*)modlink(pcTemp,0);
if ((int)psDriver==ERR)
{
psDriver=(mod_driver*)modload(pcTemp,0);
if ((int)psDriver==ERR)
{
if (psDesc) munlink(psDesc);
exit(errno);
}
}
}
if (!psDriver)
{
printf("Enter driver module: ");
gets(acBuf);
psDriver=(mod_driver*)modlink(acBuf,0);
if ((int)psDriver==ERR)
{
psDriver=(mod_driver*)modload(acBuf,0);
if ((int)psDriver==ERR)
{
if (psDesc) munlink(psDesc);
exit(errno);
}
}
}
if (!psDesc)
{
ta_desc:
if (*argv)
{
strcpy(acBuf,*argv);
}
else
{
printf("Enter descriptor module: ");
gets(acBuf);
}
if (!isdesc(acBuf))
{
printf("Descriptor module name must have numeric extension\n");
goto ta_desc;
}
psDesc=(mod_dev*)modlink(acBuf,0);
if ((int)psDesc==ERR)
{
psDesc=(mod_dev*)modload(acBuf,0);
if ((int)psDesc==ERR)
{
psDesc=(mod_dev*)make_module(acBuf,0xA0,(MA_REENT<<8)+1,0x777,(MT_DATA<<8)+0,0);
if ((int)psDesc==ERR)
{
if (psDriver) munlink(psDriver);
exit(errno);
}
psDesc->_mfmgr=0x68;
strcpy((char*)psDesc+0x68,"Scf");
psDesc->_mpdev=0x70;
strcpy((char*)psDesc+0x70,(char*)psDriver+psDriver->_mh._mname);
psDesc->_mdevcon=0x80;
psDesc->_mport=0;
iUseDef=1;
printf("Using default settings\n");
}
}
}
printf("\n");
pcTemp=(char*)psDriver+psDriver->_mexec+0x0E;
psConf=(struct sConf*)( (char*)psDriver+*(W*)pcTemp );
if (*(W*)pcTemp) while (psConf->ct_type==T_MSG) input(psConf++);
if (*(W*)pcTemp && psConf->ct_type && psConf->ct_offset!=0xFFFF)
input("\x02\x04\xFF\xFF\x00\x00\x00\x00Device address");
if (!*(W*)pcTemp)
input("\x04\x01\x00\x00\x00\x00\x00\x00Network device?");
if (*(W*)pcTemp) while (psConf->ct_type) input(psConf++);
_setcrc(psDesc);
strcpy((char*)psDesc+0x70,(char*)psDriver+psDriver->_mh._mname);
hFile=creat((char*)psDesc+psDesc->_mh._mname,0x07);
if (hFile!=ERR)
{
write(hFile,psDesc,psDesc->_mh._msize);
close(hFile);
}
munlink(psDesc);
munlink(psDriver);
}