📄 installd.c
字号:
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string.h>
#define P_QUOTA '"'
int send_object; /* The number of sending telegram */
int stat_objmap; /* The bytes of station NO. and object mapping */
int stat_number; /* The station number sended */
int buffer_size; /* The size of receiving buffer */
int packet_size; /* The size of sending packet */
int max_sockets; /* The maxium number of sockets */
int echo_port; /* The port NO. of TCP/IP communication */
int interval_time; /* The time of program puse(SEC.) */
int lastno_time; /* The time of sending telegram last no */
int port_baud; /* The baud of port communication */
int port_databit; /* The data bits (7 or 8) */
int port_stopbit; /* The stop bits (1 or 2) */
int sems_key; /* The sem set key that it is using to get sem set */
int sem_number; /* The number of sem in the sem set */
int sleeping_time; /* The time of process sleeping */
char i_buffer[50]; /* The i_buffer for any input */
char i_ibuf[50]; /* The i_ibuf for integer parameter */
char post_office[50]; /* The post office name who is receiving telegram */
char tel_address[10]; /* The telegram address who is receiving telegram */
char tel_prefix0[4]; /* The prefix of received telegram from post office */
char tel_prefix1[4]; /* The prefix of received telegram from post office */
char tel_prefix2[4]; /* The prefix of received telegram from post office */
char man_prefix0[4]; /* The prefix of received telegram from keyboard */
char new_prefix0[4]; /* The prefix of sending telegram via NFCNET */
char device_name[50]; /* The device name used communication */
char verify_mode[2]; /* The mode of verifing in communication */
char server_name[50]; /* The server name in netware */
char user_name[50]; /* The user name in netware */
char user_pass[50]; /* The password of user in netware */
char volume_name[50]; /* The volume name in netware */
char user_directory[100];/* The user directory in netware */
char mount_point[50]; /* The NFS mount point in univell */
char copy_to_targ[2]; /* The imm copy mark */
int rec_mode; /* The mode of receiving telegram from postoffice */
char *pib,*pii,*p0,*p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8,*p9,*p10,*p11,*p12,*p13,*p14;
void strtoup(char *strp);
void strtolo(char *strp);
void find_def_a(char *para_name, char *para_value);
void ask_nfcnet(void);
void mk_nfcnet_dir(void);
void mk_nfcnet_h(void);
void mk_exec(void);
void mk_copy(void);
void mk_runprog(void);
void chg_mode(void);
main(void)
{
ask_nfcnet();
mk_nfcnet_h();
mk_nfcnet_dir();
mk_exec();
mk_runprog();
mk_copy();
chg_mode();
}
void strtoup(char *strp)
{ int s_length,i,ich;
s_length=strlen(strp);
if(s_length != 0)
for(i=0;i<s_length;i++)
{ ich=*(strp+i);
*(strp+i)=toupper(ich);
}
}
void strtolo(char *strp)
{ int s_length,i,ich;
s_length=strlen(strp);
if(s_length != 0)
for(i=0;i<s_length;i++)
{ ich=*(strp+i);
*(strp+i)=tolower(ich);
}
}
void find_def_a(char *para_name, char *para_value)
{ FILE *fnfc;
char i_buf[128];
char *para_cmp;
char *pp0;
int para_size;
*para_value=0;
if((fnfc=fopen("nfcnet.h","r"))!=NULL)
{ while(!feof(fnfc))
{ fgets(i_buf,128,fnfc);
para_cmp=strstr(i_buf,para_name);
if(para_cmp!=NULL)
{ pp0=i_buf+21;
strcpy(para_value,pp0);
para_size=strlen(para_value);
*(para_value+para_size-1)=0;
para_size=strlen(para_value);
if(*(para_value+para_size-1)=='"')
*(para_value+para_size-1)=0;
if(*para_value=='"')
strcpy(para_value,para_value+1);
break;
}
}
close(fnfc);
}
}
void ask_nfcnet(void)
{ int i,j,statusx;
char c_key[10];
char first_ins[2];
/*
* To initial the variable buffer .
*/
while(1)
{ for(i=0;i<50;i++)i_buffer[i]=0;
for(i=0;i<50;i++)i_ibuf[i]=0;
for(i=0;i<50;i++)post_office[i]=0;
for(i=0;i<10;i++)tel_address[i]=0;
for(i=0;i<4; i++)tel_prefix0[i]=0;
for(i=0;i<4; i++)tel_prefix1[i]=0;
for(i=0;i<4; i++)tel_prefix2[i]=0;
for(i=0;i<4; i++)man_prefix0[i]=0;
for(i=0;i<4; i++)new_prefix0[i]=0;
for(i=0;i<50;i++)device_name[i]=0;
for(i=0;i<2; i++)verify_mode[i]=0;
for(i=0;i<50;i++)server_name[i]=0;
for(i=0;i<50;i++)user_name[i]=0;
for(i=0;i<50;i++)user_pass[i]=0;
for(i=0;i<50;i++)volume_name[i]=0;
for(i=0;i<100;i++)user_directory[i]=0;
for(i=0;i<50;i++)mount_point[i]=0;
for(i=0;i<2;i++)copy_to_targ[i]=0;
for(i=0;i<2;i++)first_ins[i]=0;
rec_mode=-10;
pib=&i_buffer[0];
pii=&i_ibuf[0];
p0=&post_office[0];
p1=&tel_address[0];
p2=&tel_prefix0[0];
p3=&tel_prefix1[0];
p4=&tel_prefix2[0];
p5=&man_prefix0[0];
p6=&new_prefix0[0];
p7=&device_name[0];
p8=&verify_mode[0];
p9=&server_name[0];
p10=&user_name[0];
p11=&user_pass[0];
p12=&volume_name[0];
p13=&user_directory[0];
p14=&mount_point[0];
while(copy_to_targ[0]!='Y' && copy_to_targ[0]!='N')
{ printf("? Copy to target directory immediately(Y/N) [C] ");
gets(copy_to_targ); strtoup(copy_to_targ);
}
while(rec_mode!= 1 && rec_mode!= 0 &&
rec_mode!=-1 && rec_mode!=-2)
{ printf("? The REC_mode (1 tele/0 dirc/-1 netw/-2 nfs) [I] ");
gets(pii);
if(strlen(pii)==0)continue;
sscanf(pii,"%d",&rec_mode);
}
while(first_ins[0]!='Y' && first_ins[0]!='N')
{ printf("? Are you first install(Y/N) [C] ");
gets(first_ins); strtoup(first_ins);
}
if(first_ins[0]=='Y')
{ if(rec_mode==1 || rec_mode== 0)system("cp nfcnet01.bck nfcnet.h");
if(rec_mode==-1|| rec_mode==-2)system("cp nfcnet02.bck nfcnet.h");
}
find_def_a("P_POSTOFFICE",pib);
while(strlen(p0)==0)
{ printf("? Post office name(D: %s)[s] ",pib);
gets(p0); strtoup(p0);
if(strlen(p0)==0)strcpy(p0,pib); }
find_def_a("P_TELEADDR",pib);
while(strlen(p1)==0)
{ printf("? Telegram address(D: %s)[s] ",pib);
gets(p1); strtoup(p1);
if(strlen(p1)==0)strcpy(p1,pib); }
find_def_a("P_TELFIX1",pib);
while(strlen(p2)==0)
{ printf("? Telegram prefix(1st)(D: %s)[s] ",pib);
gets(p2); strtoup(p2);
if(strlen(p2)==0)strcpy(p2,pib); }
find_def_a("P_TELFIX2",pib);
printf("? Telegram prefix(2nd)(D: %s)[s] ",pib);
gets(p3); strtoup(p3);
if(strlen(p3)==0)strcpy(p3,pib);
find_def_a("P_TELFIX3",pib);
printf("? Telegram prefix(3th)(D: %s)[s] ",pib);
gets(p4); strtoup(p4);
if(strlen(p4)==0)strcpy(p4,pib);
find_def_a("P_MANFIX1",pib);
while(strlen(p5)==0)
{ printf("? Manual_I tele prefix(D: %s)[s] ",pib);
gets(p5); strtoup(p5);
if(strlen(p5)==0)strcpy(p5,pib); }
find_def_a("P_NEWFIX1",pib);
while(strlen(p6)==0)
{ printf("? New sending prefix(D: %s)[s] ",pib);
gets(p6); strtoup(p6);
if(strlen(p6)==0)strcpy(p6,pib); }
find_def_a("P_DEVNAME",pib);
if(rec_mode==1 || rec_mode==0)
{ while(strlen(p7)==0)
{ printf("? Device name(D: %s)[s] ",pib);
gets(p7); strtolo(p7);
if(strlen(p7)==0)strcpy(p7,pib); }
find_def_a("P_VERMODE",pib);
while(strlen(p8)==0)
{ printf("? Verify mode(O|E|N)(D: %s)[s] ",pib);
gets(p8); strtoup(p8);
if(strlen(p8)==0)strcpy(p8,pib); }
find_def_a("P_PORTBAUD",pib);
sscanf(pib+1,"%d",&port_baud);
printf("? The baud of communication(D: %d bps)[I] ",port_baud);
gets(pii);
if(strlen(pii)==0)sscanf(pib+1,"%d",&port_baud);
else sscanf(pii,"%d",&port_baud);
find_def_a("P_DATABIT",pib);
sscanf(pib+2,"%d",&port_databit);
printf("? The data bits of the device(D: %d bit)[I] ",port_databit);
gets(pii);
if(strlen(pii)==0)sscanf(pib+2,"%d",&port_databit);
else sscanf(pii,"%d",&port_databit);
find_def_a("P_STOPBIT",pib);
sscanf(pib,"%d",&port_stopbit);
printf("? The stop bits of the device(D: %d bit)[I] ",port_stopbit);
gets(pii);
if(strlen(pii)==0)sscanf(pib,"%d",&port_stopbit);
else sscanf(pii,"%d",&port_stopbit);
}
if(rec_mode==-1 || rec_mode==-2)
{ statusx=system("/bin/nlist");
find_def_a("P_SERVER",pib);
while(strlen(p9)==0)
{ printf("? Server name(D: %s)[S] ",pib);
gets(p9); strtolo(p9);
if(strlen(p9)==0)strcpy(p9,pib); }
find_def_a("P_USERNAME",pib);
while(strlen(p10)==0)
{ printf("? User name(D: %s)[S] ",pib);
gets(p10); strtolo(p10);
if(strlen(p10)==0)strcpy(p10,pib); }
find_def_a("P_PASSWORD",pib);
while(strlen(p11)==0)
{ printf("? User password(D: %s)[S] ",pib);
gets(p11); strtolo(p11);
if(strlen(p11)==0)strcpy(p11,pib); }
find_def_a("P_VOLUME",pib);
while(strlen(p12)==0)
{ printf("? Volume name(D: %s)[S] ",pib);
gets(p12); strtolo(p12);
if(strlen(p12)==0)strcpy(p12,pib); }
find_def_a("P_DIRECTORY",pib);
while(strlen(p13)==0)
{ printf("? User directory(D: %s)[S] ",pib);
gets(p13); strtolo(p13);
if(strlen(p13)==0)strcpy(p13,pib); }
find_def_a("P_MOUNTPT",pib);
while(strlen(p14)==0)
{ printf("? Mount point(D: %s)[S] ",pib);
gets(p14); strtolo(p14);
if(strlen(p14)==0)strcpy(p14,pib); }
}
find_def_a("P_SENDOBJ",pib);
sscanf(pib,"%d",&send_object);
printf("? The object number of S/R(D: %d)[I] ",send_object);
gets(pii);
if(strlen(pii)==0)sscanf(pib,"%d",&send_object);
else sscanf(pii,"%d",&send_object);
stat_objmap=5; j=send_object;
for(;;) { stat_objmap++; j=j-8; if(j<=0)break;}
find_def_a("P_STTNUMB",pib);
sscanf(pib,"%d",&stat_number);
printf("? The station number of sended(D: %d)[I] ",stat_number);
gets(pii);
if(strlen(pii)==0)sscanf(pib,"%d",&stat_number);
else sscanf(pii,"%d",&stat_number);
for(;;)
{
find_def_a("P_SIZEBUF",pib);
sscanf(pib,"%d",&buffer_size);
printf("? The size of pack buffer(D: %d)[I] ",buffer_size);
gets(pii);
if(strlen(pii)==0)sscanf(pib,"%d",&buffer_size);
else sscanf(pii,"%d",&buffer_size);
if(buffer_size>=512){break;}
else{ printf("The size of buffer must be >=512 !\n");}
}
for(;;)
{
find_def_a("P_SIZEPACK",pib);
sscanf(pib,"%d",&packet_size);
printf("? The size of packet(D: %d)[I] ",packet_size);
gets(pii);
if(strlen(pii)==0)sscanf(pib,"%d",&packet_size);
else sscanf(pii,"%d",&packet_size);
if((packet_size<=512)&&(packet_size>=64)){break;}
else{ printf("The size of packet must be >=64 && <=512 !\n");}
}
find_def_a("P_MAXSOCKET",pib);
sscanf(pib,"%d",&max_sockets);
printf("? The max_number of sockets(D: %d)[I] ",max_sockets);
gets(pii);
if(strlen(pii)==0)sscanf(pib,"%d",&max_sockets);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -