Esempio n. 1
0
File: teach.c Progetto: guoyu07/TCPL
main()
{
    courseDB course;

    course = ReadDataBase();
    ProcessCourse(course);
}
Esempio n. 2
0
short InitRPC(char *PathEntry)
{
	lasterror = 0;
	USHORT i;
	short j,size;
	char str[100],buf[100];
	char *ptr;
	char Path[50];
	struct hostent *host;
	unsigned long l;

	WORD wVersionRequested;  
	WSADATA wsaData; 
	
	if (!strlen(PathEntry)) 
	{
		//printf("No database path specified\n");
		return database_not_loaded;
	}
	
	wVersionRequested = MAKEWORD(2,0); 
 
	if(WSAStartup(wVersionRequested, &wsaData)!=0) return 1; 
 
    /* Tell the user that we couldn't find a useable */ 
    /* winsock.dll.     */ 

	strcpy(Path,PathEntry);strcat(Path,"/");

	//printf("Initializing RPC-linksoftware\n");

	sendBuffer=(char *)malloc(NOD_BUF_SIZE);
	if (sendBuffer==NULL) return out_of_memory;

	sprintf(RPCModElems[0].ColName,"%seqpmod.csv",Path);
	size=GetDataBaseSize(RPCModElems[0].ColName);
	if (size>=0) sprintf(str,"Reading EQPMOD.CSV : %d lines",size);
	else sprintf(str,"Reading EQPMOD.CSV : %s",erlst[abs(size)]);
	//printf("%s\n",str);
	RPCMod=NULL;
	if (size>0)
	{
		RPCMod=(RPCModStruct *)malloc(sizeof(RPCModStruct)*size);
		if (RPCMod==NULL) return out_of_memory;
		ptr=(char *)RPCMod;
		for (i=0;i<sizeof(RPCModStruct)*size;i++) ptr[i]=0;
		RPCModElems[1].Address=RPCMod[0].EqpName;
		RPCModElems[2].Address=RPCMod[0].StatName;
		RPCModElems[3].Address=RPCMod[0].GlobalCom;
		RPCModElems[4].Address=&RPCMod[0].Weight;
		RPCNumEqpsRead=ReadDataBase(RPCModElems);
		if (RPCNumEqpsRead<0) return database_not_loaded;
	}
	else RPCNumEqpsRead=0;

	sprintf(RPCFecElems[0].ColName,"%sfecaddr.csv",Path);
	size=GetDataBaseSize(RPCFecElems[0].ColName);
	if (size>=0) sprintf(str,"Reading FECADDR.CSV : %d lines",size);
	else sprintf(str,"Reading FECADDR.CSV : %s",erlst[abs(size)]);
	//printf("%s\n",str);
	if (size<0) return abs(size);
	RPCFec=(RPCFecStruct *)malloc(sizeof(RPCFecStruct)*size);
	if (RPCFec==NULL) return out_of_memory;
	ptr=(char *)RPCFec;
	for (i=0;i<sizeof(RPCFecStruct)*size;i++) ptr[i]=0;
	RPCFecElems[1].Address=RPCFec[0].Name;
	RPCFecElems[2].Address=RPCFec[0].Node;
	RPCFecElems[3].Address=RPCFec[0].Network;
	RPCFecElems[4].Address=RPCFec[0].IP;
	RPCFecElems[5].Address=&RPCFec[0].Prot;
	RPCNumFecsRead=ReadDataBase(RPCFecElems);
	if (RPCNumFecsRead<0) return database_not_loaded;

	FecAccessCount=(char *)malloc(size+1);
	if (FecAccessCount==NULL) return out_of_memory;
	FecLastAccess=(time_t *)malloc((size+1)*sizeof(time_t));
	if (FecLastAccess==NULL) return out_of_memory;
	for (i=0;i<RPCNumFecsRead;i++)
	{
			FecAccessCount[i]=0;
			FecLastAccess[i]=0;
	}

	for (i=0;i<RPCNumFecsRead;i++)
	{
		if (strlen(RPCFec[i].IP))
		{
			strcpy((char *)str,RPCFec[i].IP);
			l=inet_addr(str);
			if (l==-1)
			{
			   //printf("Trying by name\n");
			   host=gethostbyname(str);
			   if (host!=NULL) memcpy(RPCFec[i].IP,host->h_addr,sizeof(unsigned long));
			   else
			   {
				sprintf(buf,"Cannot find %s IP-address",str);
				//printf("%s\n",buf);
			   }
			}
			else *(unsigned long *)RPCFec[i].IP=l;
			/*printf("%X\n",*(unsigned long *)RPCFec[i].IP);*/
		}
		else for (j=0;j<sizeof(long);j++) RPCFec[i].IP[j]=0;
	}

	sprintf(RPCDataElems[0].ColName,"%seqpnames.csv",Path);
	size=GetDataBaseSize(RPCDataElems[0].ColName);
	if (size>=0) sprintf(str,"Reading EQPNAMES.CSV : %d lines",size);
	else sprintf(str,"Reading EQPNAMES.CSV : %s",erlst[abs(size)]);
	//printf("%s\n",str);
	if (size<0) return abs(size);
	RPCData=(RPCDataStruct *)malloc(sizeof(RPCDataStruct)*size);
	if (RPCData==NULL) return out_of_memory;
	ptr=(char *)RPCData;
	for (i=0;i<sizeof(RPCDataStruct)*size;i++) ptr[i]=0;
	RPCDataElems[1].Address=RPCData[0].FecName;
	RPCDataElems[2].Address=RPCData[0].FullName;
	RPCDataElems[3].Address=RPCData[0].EqName;
	RPCDataElems[4].Address=&RPCData[0].EqNumber;
	RPCNumRecsRead=ReadDataBase(RPCDataElems);
	if (RPCNumRecsRead<0) return database_not_loaded;

	//printf("Initialization terminated.\n");

	return 0;
}