ssize_t
read(int d, void* buf, size_t sz)
{
  fprintf(stderr, "[%d] reading %zu bytes from %d...\n", (int)getpid(), sz, d);
  assert(readf != NULL);
  return readf(d, buf, sz);
}
//A test file to test the library functions written
int main()
{
    int n,err=0;
    prints("Write the integer n:");
    n = readi(&err);
    if(err!=ERR)
    {
        prints("The integer read is : ");
        printi(n);
    }
    else
    {
        prints("Wrong Input\n");
    }
    float x;

    prints("\nEnter the decimal number: ");
    err = readf(&x);
    if(err==OK)
    {
        prints("The floating number is :");
        printd(x);
    }
    else
    {
        prints("Wrong Input\n");
    }
    prints("\n");
    return 0;
}
Exemple #3
0
Node::Node(const Block &blk) { // notice here
    char* mem = (char*)malloc(BLOCK_SIZE);
    memcpy(mem, blk.data, BLOCK_SIZE);
    
    isleaf = mem[0]; isroot = mem[1];
    
    mem += 2*sizeof(char);
    int pSize = readi(mem), kSize = readi(mem), typeId = readi(mem), strLen = readi(mem);
    
    //system("pause");
    
    int p = 0;
    
    for( int i = 0; i < pSize; i++ ) {
        p = readi(mem);
        P.push_back(p);
    }
    
    
    for( int i = 0; i < kSize; i++ ) {
        AttrType k;
        
        if( typeId == 0 ) { // int
            k = AttrType(readi(mem));
        }
        else if( typeId == 1 ) { // float
            k = AttrType(readf(mem));
        }
        else if( typeId == 2 ) { // string
            k = AttrType(reads(mem, strLen));
        }
        
        K.push_back(k);
    }
}
int main (int argc, char *argv[])
{
	readf(fp);
	pthread_t pro, con;
	long t1=1, t2=2;

	// Initialize the mutex and condition variables
	pthread_mutex_init(&count_mutex, NULL);	
	pthread_cond_init(&condc, NULL);
	pthread_cond_init(&condp, NULL);

	// Create the threads
	pthread_create(&con, NULL, consumer, (void *)t1);
	pthread_create(&pro, NULL, producer, (void *)t2);

	// Wait for the threads to finish
	pthread_join(con, NULL);
	pthread_join(pro, NULL);

	// Cleanup
	pthread_mutex_destroy(&count_mutex);
	pthread_cond_destroy(&condc);
	pthread_cond_destroy(&condp);
	pthread_exit(NULL);

}
Exemple #5
0
int main(int argc,char* argv[])
{
    FILE *fIN=NULL;
    FILE *fOUT=NULL;
    if(processArgs(argc,argv,&fIN,&fOUT))
        readf(fIN);
    return 0;
}
Exemple #6
0
bool_t pack_read_dir(restable_t *rt)
{
	char ident[PACK_HEADER_IDENT_SIZE];
	uint32_t offset;
	uint32_t size;
	uint32_t number;
	uint32_t i;

	if (readf(rt->file, "c4l4l4", ident, &offset, &size) != OK)
	{
		fprintf(stderr, "pack_read_dir: Can't read header.\n");
		return FALSE;
	}
	if (strncmp(ident, PACK_IDENT, PACK_HEADER_IDENT_SIZE) != 0)
	{
		fprintf(stderr, "pack_read_dir: Wrong ident.\n");
		return FALSE;
	}	
	if (size % PACK_ENTRY_SIZE != 0)
	{
		fprintf(stderr, "pack_read_dir: Wrong size.\n");
		return FALSE;
	}
	number = size / PACK_ENTRY_SIZE;
	if (rt_set_number(rt, number) == FALSE)
	{
		fprintf(stderr, "pack_read_dir: Can't resize entries.\n");
		return FALSE;
	}
	fseek(rt->file, offset, SEEK_SET);
	for(i = 0; i < rt->number; i++)
	{
		if (readf(rt->file, "s56l4l4",
			&(rt->entries[i].name),
			&(rt->entries[i].offset),
			&(rt->entries[i].size)) != OK)
		{
			fprintf(stderr, "pack_read_dir: Can't read entry #%u.\n", i);
			return FALSE;
		}
		rt->entries[i].compressed = rt->entries[i].size;
	}
	return TRUE;
}
Exemple #7
0
bool_t is_dat(restable_t *rt)
{
	uint32_t dir_zero;

	if (readf(rt->file, "c8b4", NULL, &dir_zero) != OK)
		return FALSE;
	if (dir_zero != 0)
		return FALSE;
	return TRUE;
}
Exemple #8
0
bool_t is_grp(restable_t *rt)
{
	char ident[GRP_HEADER_IDENT_SIZE];

	if (readf(rt->file, "c4", ident) != OK)
		return FALSE;
	if (strncmp(ident, GRP_IDENT, GRP_HEADER_IDENT_SIZE) != 0)
		return FALSE;
	return TRUE;
}
Exemple #9
0
int gtxt (LINEDESC *ptr)
{
	seekf ((long) ptr->Seekaddr * 8, Scr); /* position to start of file */
	/*
	 * rounded Seekaddr to 8 byte sections, giving larger
	 * buffer space for text (*8)
	 */

	return (readf (Txt, (int) ptr->Lineleng, Scr) - 1);
}
Exemple #10
0
bool_t gob_read_dir(restable_t *rt)
{
	char ident[GOB_HEADER_IDENT_SIZE];
	uint32_t number;
	uint32_t offset;
	size_t i;

	if (readf(rt->file, "c4l4", ident, &offset) != OK)
	{
		fprintf(stderr, "gob_read_dir: Can't read header.\n");
		return FALSE;
	}
	if (strncmp(ident, GOB_IDENT, GOB_HEADER_IDENT_SIZE) != 0)
	{
		fprintf(stderr, "gob_read_dir: Wrong ident.\n");
		return FALSE;
	}
	fseek(rt->file, offset, SEEK_SET);
	if (readf(rt->file, "l4", &number) != OK)
	{
		fprintf(stderr, "gob_read_dir: Can't read number of entries.\n");
		return FALSE;
	}
	if (rt_set_number(rt, number) == FALSE)
	{
		fprintf(stderr, "gob_read_dir: Can't resize entries.\n");
		return FALSE;
	}
	for(i = 0; i < rt->number; i++)
	{
		if (readf(rt->file, "l4l4s13",
				&(rt->entries[i].offset),
				&(rt->entries[i].size),
				&(rt->entries[i].name)) != OK)
		{
			fprintf(stderr, "gob_read_dir: Can't read entry #%u.\n", i);
			return FALSE;
		}
		rt->entries[i].compressed = rt->entries[i].size;
	}
	return TRUE;
}
void read_user_cars(struct player *splayer)
{
	char file[255];
	strcpy(file, RootDir);
	strcat(file, "data/RCGarage/");
	strcat(file, splayer->UName);
	strcat(file, ".txt");


	HANDLE fff;
	WIN32_FIND_DATA fd;
	fff = FindFirstFile(file, &fd);
	if (fff == INVALID_HANDLE_VALUE)
	{
		out << "Can't find " << file << endl;
		strcpy(splayer->cars[0].car, "XFG");
		splayer->cars[0].tuning = 0;
		splayer->cars[0].dist = 0;
		save_user_cars(splayer);
	}
	else
	{
		ifstream readf (file, ios::in);
		int i=0;
		while (readf.good())
		{
			char str[128];
			readf.getline(str, 128);

			if (strlen(str) > 0)
			{
				char *car;
				char *tun;
				char *dis;

				car = strtok(str, ";");
				tun = strtok(NULL, ";");
				dis = strtok(NULL, ";");

				strcpy(splayer->cars[i].car, car);
				splayer->cars[i].tuning = atoi(tun);
				splayer->cars[i].dist = atoi(dis);

				i++;
			}
		}
	}
	FindClose(fff);





}
void read_car()
{

	char file[255];
	strcpy(file, RootDir);
	//strcat(file, "misc/mysql.cfg");
	strcat(file, "misc/cars.txt");

	HANDLE fff;
	WIN32_FIND_DATA fd;
	fff = FindFirstFile(file, &fd);
	if (fff == INVALID_HANDLE_VALUE)
	{
		out << "Can't find " << file << endl;
		return;
	}
	FindClose(fff);

	ifstream readf (file, ios::in);

	int i = 0;
	while (readf.good())
	{
		char str[128];
		readf.getline(str, 128);
		if (strlen(str) > 0)
		{

			if (strstr(str, "//")) {}
			else
			{
				char * number;
				char * car;
				char * cash;
				number = strtok (str, ";");
				car = strtok (NULL, ";");
				cash = strtok (NULL, ";");

				i = atoi(number);
				memset(&ginfo.car[i], 0, sizeof(struct cars));
				ginfo.car[i].id = i;
				strcpy(ginfo.car[i].car, car);
				ginfo.car[i].cash =atoi(cash);
				ginfo.car[i].sell= ginfo.car[i].cash*8/10;
			}


		} // if strlen > 0
	} //while readf.good()

	readf.close();
}
Exemple #13
0
bool_t is_pack(restable_t *rt)
{
	char ident[PACK_HEADER_IDENT_SIZE];
	uint32_t size;

	if (readf(rt->file, "c4c4l4", ident, NULL, &size) != OK)
		return FALSE;
	if (strncmp(ident, PACK_IDENT, PACK_HEADER_IDENT_SIZE) != 0)
		return FALSE;
	if (size % PACK_ENTRY_SIZE != 0)
		return FALSE;
	return TRUE;
}
Exemple #14
0
bool_t grp_read_dir(restable_t *rt)
{
	char ident[GRP_HEADER_IDENT_SIZE];
	uint32_t number;
	uint32_t offset;
	size_t i;

	if (readf(rt->file, "c12l4", ident, &number) != OK)
	{
		fprintf(stderr, "grp_read_dir: Can't read header.\n");
		return FALSE;
	}
	if (strncmp(ident, GRP_IDENT, GRP_HEADER_IDENT_SIZE) != 0)
	{
		fprintf(stderr, "grp_read_dir: Wrong ident.\n");
		return FALSE;
	}
	if (rt_set_number(rt, number) == FALSE)
	{
		fprintf(stderr, "grp_read_dir: Can't resize entries.\n");
		return FALSE;
	}
	offset = GRP_HEADER_SIZE + GRP_ENTRY_SIZE * number;
	for(i = 0; i < rt->number; i++)
	{
		if (readf(rt->file, "s12l4",
			&(rt->entries[i].name),
			&(rt->entries[i].size)) != OK)
		{
			fprintf(stderr, "grp_read_dir: Can't read entry #%u.\n", i);
			return FALSE;
		}
		rt->entries[i].compressed = rt->entries[i].size;
		rt->entries[i].offset = offset;
		offset += rt->entries[i].size;
	}
	return TRUE;
}
Exemple #15
0
int main()
{
	float x;
	int y;
	prints("Enter a floating point number :");
	if(!readf(&x))
		printd(x);
	else
		prints("Invalid floating point number!");
	prints("\nEnter an integer :");
	if(!readi(&y))
		printi(y);
	else
		prints("Invalid integer!");
	prints("\n");
	return 0;
}
Exemple #16
0
int do_show(u8 * file){
	s8 fd, ret ; u32 i ;
	struct fnode fn;
	u32 size;
	u8 buff[1025];

	if (!check_for_args(SHOW,1)) return 1;
	fd=openf(file,O_READ);
	if ( fd == -1){
		vd_puts("CANNOT OPEN THE FILE\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}

	ret = finfo(fd,&fn);
	if ( ret == -1){
		vd_puts("CANNOT OPEN THE FILE\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}
	size=fn.size;
	while(size){
		ret = readf(fd,buff,(size < 1024 ? size : 1024));
		if ( ret == -1){
			vd_puts("CANNOT  READ THE FILE\n");
					errormessage(geterror());
					fl_clean();
			return 1;
		}
		buff[(size < 1024 ? size : 1024)]=0 ;
		for(i = 0 ; i < (size < 1024 ? size : 1024) ; ++i )
			if ( buff[i] == 10 || buff[i] == 13) buff[i] = '\n';
		vd_puts( buff);
		vd_puts("\n");
		if (size >= 1024)
		    size-=1024 ;
		else
			size=0;
	}
	closef(fd);
	fl_clean();
	return 0;
}
Exemple #17
0
void Node::resetByBlock(const Block &blk) {
    char* mem = (char*)malloc(BLOCK_SIZE);
    memcpy(mem, blk.data, BLOCK_SIZE);
    
    isleaf = mem[0]; isroot = mem[1];
    
    mem += 2*sizeof(char);
    int pSize = readi(mem), kSize = readi(mem), typeId = readi(mem), strLen = readi(mem);
    
    //system("pause");
    
    std::vector<AttrType>::iterator iter_K=K.begin();
    for ( ;iter_K!=K.end();) iter_K=K.erase(iter_K);
    
    std::vector<int>::iterator iter_P=P.begin();
    for ( ;iter_P!=P.end();) iter_P=P.erase(iter_P);
    
    int p = 0;
    
    for( int i = 0; i < pSize; i++ ) {
        p = readi(mem);
        P.push_back(p);
    }
    
    
    for( int i = 0; i < kSize; i++ ) {
        AttrType k;
        
        if( typeId == 0 ) { // int
            k = AttrType(readi(mem));
        }
        else if( typeId == 1 ) { // float
            k = AttrType(readf(mem));
        }
        else if( typeId == 2 ) { // string
            k = AttrType(reads(mem, strLen));
        }
        
        K.push_back(k);
    }
}
Exemple #18
0
int main()
{
 
  int a1,epa1=1,nca1;
  prints("enter two integer numbers\n");
  while(epa1)
  {
  a1=readi(&epa1);
  if(epa1) prints("invalid... Please reenter\n");
  }
   int a2,epa2=1,nca2;
  while(epa2)
  {
  a2=readi(&epa2);
  if(epa2) prints("invalid... Please reenter\n");
  }
  
  
  prints("enterd number are:");
  nca1=printi(a1);
  //prints("\nnumber of character printed in above integer is :");
  //printi(nca1);
  prints("\t");
  
  nca2=printi(a2);
  //prints("\nnumber of character printed in above integer is :");
  //printi(nca2);
  prints("\n");
  
  prints("sum of enterd number is:\t");
  printi(a1+a2);
    prints("\n");
  
  float b1;
  int epb1=1,ncb1;
  prints("enter two floating point numbers\n");
   while(epb1){
  epb1=readf(&b1);
  if(epb1)  prints("invalid... Please reenter\n");
  }
 
  float b2;
  int epb2=1,ncb2;
   while(epb2){
  epb2=readf(&b2);
  if(epb2)  prints("invalid... Please reenter\n");
  }
  
  
  prints("enterd number are:\t");
  ncb1=printd(b1);  
  //prints("\nnumber of character printed in above float  is :");
  //printi(ncb1);
  prints("\t");
  
  
  //prints("enterd number is:\n");
  ncb2=printd(b2);  
  //prints("\nnumber of character printed in above float  is :");
  //printi(ncb2);
  prints("\n");

  prints("sum of enterd number is:");
  printd(b1+b2);
    prints("\n");
    
    int ncs;
   prints("product  of both sum is:");
   ncs=printd((a1+a2)*(b1+b2));
   prints("\n");
   prints("number of character printed in above product is :");
   printi(ncs);
   prints("\n");

  return 0;
}
void RCCore::case_btc ()
{
//    pthread_mutex_lock (&RCmutex);
	struct IS_BTC *pack_btc = (struct IS_BTC*)insim->get_packet();

	//cout << (int)pack_btc->ClickID << endl;
	int i;
	for (i=0; i < MAX_PLAYERS; i++)
	{
		if (players[i].UCID == pack_btc->UCID)
		{

			char day[3];
			char month[3];
			char year[3];
			SYSTEMTIME sm;
			GetLocalTime(&sm);
			itoa(sm.wDay, day, 10);
			itoa(sm.wMonth, month, 10);
			itoa(sm.wYear, year, 10);
			char log[255];
			strcpy(log, RootDir);
			strcat(log, "logs/shop/shop");
			strcat(log, "(");
			strcat(log, day);
			strcat(log, ".");
			strcat(log, month);
			strcat(log, ".");
			strcat(log, year);
			strcat(log, ").txt");

			if (pack_btc->ClickID<=32)
			{
				players[i].BID2 =  pack_btc->ClickID;

				if (players[i].Action == 1) // send
				{
					struct IS_BTN pack_btn;
					memset(&pack_btn, 0, sizeof(struct IS_BTN));
					pack_btn.Size = sizeof(struct IS_BTN);
					pack_btn.Type = ISP_BTN;
					pack_btn.ReqI = players[i].UCID;              // Must be non-zero, I'll just use UCID
					pack_btn.UCID = players[i].UCID;              // UCID of the player that will receive the button
					pack_btn.BStyle = 16 + ISB_CLICK;                 // Dark frame for window title
					pack_btn.TypeIn = 16;
					pack_btn.L = 116;
					pack_btn.T = 13;
					pack_btn.W = 34;
					pack_btn.H = 5;
					pack_btn.ClickID = 36;
					strcpy(pack_btn.Text, msg->message[players[i].lang_id][1000]);
					insim->send_packet(&pack_btn);

					pack_btn.TypeIn = 64-24-14;
					pack_btn.L = 116;
					pack_btn.T += 6;
					pack_btn.W = 34;
					pack_btn.H = 5;
					pack_btn.ClickID = 37;
					strcpy(pack_btn.Text, msg->message[players[i].lang_id][1001]);
					insim->send_packet(&pack_btn);

					// cop buttons
					if (players[i].cop != 0)
					{
						pack_btn.BStyle = 32 + ISB_CLICK;
						pack_btn.TypeIn = 2;
						pack_btn.L = 116;
						pack_btn.T += 6;
						pack_btn.W = 34;
						pack_btn.H = 5;
						pack_btn.ClickID = 38;
						strcpy(pack_btn.Text, msg->message[players[i].lang_id][1002]);
						insim->send_packet(&pack_btn);

						pack_btn.BStyle = 32 + ISB_CLICK;
						pack_btn.TypeIn = 2;
						pack_btn.L = 116;
						pack_btn.T += 6;
						pack_btn.W = 34;
						pack_btn.H = 5;
						pack_btn.ClickID = 39;
						strcpy(pack_btn.Text, msg->message[players[i].lang_id][1003]);
						insim->send_packet(&pack_btn);

						pack_btn.BStyle = 32 + ISB_CLICK;
						pack_btn.TypeIn = 0;
						pack_btn.L = 116;
						pack_btn.T += 6;
						pack_btn.W = 34;
						pack_btn.H = 5;
						pack_btn.ClickID = 40;
						strcpy(pack_btn.Text, msg->message[players[i].lang_id][1004]);
						insim->send_packet(&pack_btn);

						pack_btn.BStyle = 32 + ISB_CLICK;
						pack_btn.TypeIn = 0;
						pack_btn.L = 116;
						pack_btn.T += 6;
						pack_btn.W = 34;
						pack_btn.H = 5;
						pack_btn.ClickID = 41;
						strcpy(pack_btn.Text, msg->message[players[i].lang_id][1005]);
						insim->send_packet(&pack_btn);
					}
				}
			}
			if (pack_btc->ClickID==34)
			{
				for (int j=0; j<50; j++)
					send_bfn(players[i].UCID, j);
				Sleep(100);
			}

			if (pack_btc->ClickID==40)
			{

				for (int g=0; g<MAX_PLAYERS; g++)
				{
					if  (players[i].BID2 == players[g].BID)
					{
						if (players[g].Pogonya == 0)
						{
							players[g].Pogonya = 1;
							int worktime = time(&stime);
							players[g].WorkTime = worktime+60*6;
							strcpy(players[g].PogonyaReason, msg->message[players[g].lang_id][1006]);
							char Text[96];
							strcpy(Text, "/msg ^2| ");
							//strcat(Text, players[i].PName);
							strcat(Text, msg->message[players[g].lang_id][1007]);
							strcat(Text, players[g].PName);
							send_mst(Text);
						}
						break;
					}
				}
			}
			if (pack_btc->ClickID==41)
			{

				for (int g=0; g<MAX_PLAYERS; g++)
				{
					if  (players[i].BID2 == players[g].BID)
					{
						if (players[g].Pogonya != 0)
						{
							players[g].Pogonya = 0;
							send_bfn(players[g].UCID, 210);
							char Text[96];
							strcpy(Text, "/msg ^2| ");
							//strcat(Text, players[i].PName);
							strcat(Text, msg->message[players[g].lang_id][1008]);
							strcat(Text, players[g].PName);
							send_mst(Text);
						}
						break;
					}
				}
			}


			for (int g=50; g< 70; g++)
			{
				if (g == pack_btc->ClickID)
				{
					cout << players[i].UName << "come in to shop and \n";
					if (players[i].Shop == 1)
					{
						//strcat(players[i].Cars, ginfo.car[g-50].car);
						//strcat(players[i].Cars, " ");
						bank->players[i].Cash -= ginfo.car[g-50].cash;
						bank->BankFond += ginfo.car[g-50].cash;
						cout << "buy car - " << ginfo.car[g-50].car << endl;




						ofstream readf (log, ios::app);
						readf << sm.wHour << ":" << sm.wMinute << ":" << sm.wSecond << " " <<  players[i].UName << " buy car " << ginfo.car[g-50].car << endl;
						readf.close();

						for ( int j=0; j<MAX_CARS; j++)
						{
							if (strlen(players[i].cars[j].car) == 0)
							{
								strcpy(players[i].cars[j].car, ginfo.car[g-50].car);
								players[i].cars[j].tuning=0;
								players[i].cars[j].dist=0;
								break;
							}

						}



						for (int j=40; j<200; j++)
							send_bfn(pack_btc->UCID, j);

						players[i].Shop = 1;
						btn_shop(&players[i]);
					}
					if (players[i].Shop == 2)
					{
						if (strcmp(players[i].CName, ginfo.car[g-50].car)!=0)
						{
							cout << "sell car - " << ginfo.car[g-50].car << endl;



							ofstream readf (log, ios::app);

							readf << sm.wHour << ":" << sm.wMinute << ":" << sm.wSecond << ":" << sm.wMilliseconds << " " <<  players[i].UName << " sell car " << ginfo.car[g-50].car << endl;


							/*string Cars;
							Cars += players[i].Cars;
							cout << Cars << endl;
							Cars.replace(Cars.find(ginfo.car[g-50].car), 4, "");
							cout << Cars << endl;

							strcpy(players[i].Cars, Cars.c_str());*/
							// readf << "DEBAG:" << bank->players[i].Cash << endl;
						   // bank->players[i].Cash += ginfo.car[g-50].sell;
						   // bank->BankFond -= ginfo.car[g-50].sell;

							//readf << "DEBAG:" << bank->players[i].Cash << endl;
							//cout << players[i].Cars << endl;
							readf.close();
							for ( int j=0; j<MAX_CARS; j++)
							{
								if (strcmp(players[i].cars[j].car, ginfo.car[g-50].car) == 0)
								{
									strcpy(players[i].cars[j].car, "");
									players[i].cars[j].tuning=0;
									players[i].cars[j].dist=0;
									break;
								}

							}


							for (int j=40; j<200; j++)
								send_bfn(pack_btc->UCID, j);

							players[i].Shop = 2;
							btn_shop(&players[i]);
						}
						else
						{
							send_mtc(players[i].UCID, msg->message[players[i].lang_id][1009]);
						}
					}
					break;
				} // if g == clickId
			} // for g



			if (pack_btc->ClickID == 71)
			{
				if (players[i].Shop == 3)
				{

					players[i].CTune += 1;
					bank->players[i].Cash -= 5000;
					bank->BankFond += 5000;


					ofstream readf (log, ios::app);
					readf << sm.wHour << ":" << sm.wMinute << ":" << sm.wSecond << " " <<  players[i].UName << " buy ECU "<< endl;
					readf.close();

					for (int j=40; j<200; j++)
						send_bfn(pack_btc->UCID, j);

					players[i].Shop = 3;
					btn_shop(&players[i]);
				}
				if (players[i].Shop == 4)
				{

					players[i].CTune -= 1;
					bank->players[i].Cash += 5000*8/10;
					bank->BankFond -= 5000*8/10;

					ofstream readf (log, ios::app);
					readf << sm.wHour << ":" << sm.wMinute << ":" << sm.wSecond << " " <<  players[i].UName << " sell ECU "<< endl;
					readf.close();

					for (int j=40; j<200; j++)
						send_bfn(pack_btc->UCID, j);

					players[i].Shop = 4;
					btn_shop(&players[i]);
				}
			}
			if (pack_btc->ClickID == 72)
			{
				if (players[i].Shop == 3)
				{

					players[i].CTune += 2;
					bank->players[i].Cash -= 10000;
					bank->BankFond += 10000;


					ofstream readf (log, ios::app);
					readf << sm.wHour << ":" << sm.wMinute << ":" << sm.wSecond << " " <<  players[i].UName << " buy Turbo "<< endl;
					readf.close();

					for (int j=40; j<200; j++)
						send_bfn(pack_btc->UCID, j);

					players[i].Shop = 3;
					btn_shop(&players[i]);
				}
				if (players[i].Shop == 4)
				{

					players[i].CTune -= 2;
					bank->players[i].Cash += 10000*8/10;
					bank->BankFond -= 10000*8/10;


					ofstream readf (log, ios::app);
					readf << sm.wHour << ":" << sm.wMinute << ":" << sm.wSecond << " " <<  players[i].UName << " sell Turbo "<< endl;
					readf.close();

					for (int j=40; j<200; j++)
						send_bfn(pack_btc->UCID, j);

					players[i].Shop = 4;
					btn_shop(&players[i]);
				}
			}
			if (pack_btc->ClickID == 73)
			{
				if (players[i].Shop == 3)
				{

					players[i].CTune += 8;
					bank->players[i].Cash -= 20000;
					bank->BankFond += 20000;


					ofstream readf (log, ios::app);
					readf << sm.wHour << ":" << sm.wMinute << ":" << sm.wSecond << " " <<  players[i].UName << " buy ABS "<< endl;
					readf.close();

					for (int j=40; j<159; j++)
						send_bfn(pack_btc->UCID, j);

					players[i].Shop = 3;
					btn_shop(&players[i]);
				}
				if (players[i].Shop == 4)
				{

					players[i].CTune -= 8;
					bank->players[i].Cash += 20000*8/10;
					bank->BankFond -= 20000*8/10;


					ofstream readf (log, ios::app);
					readf << sm.wHour << ":" << sm.wMinute << ":" << sm.wSecond << " " <<  players[i].UName << " sell ABS "<< endl;
					readf.close();

					for (int j=40; j<159; j++)
						send_bfn(pack_btc->UCID, j);

					players[i].Shop = 4;
					btn_shop(&players[i]);
				}
			}


			if (pack_btc->ClickID == 151)
			{
				for (int j=40; j<159; j++)
					send_bfn(pack_btc->UCID, j);
				players[i].Shop = 1;
				btn_shop(&players[i]);
			}
			if (pack_btc->ClickID == 152)
			{
				for (int j=40; j<159; j++)
					send_bfn(pack_btc->UCID, j);
				players[i].Shop = 2;
				btn_shop(&players[i]);
			}

			if (pack_btc->ClickID == 154)
			{
				for (int j=40; j<159; j++)
					send_bfn(pack_btc->UCID, j);
				players[i].Shop = 3;
				btn_shop(&players[i]);
			}
			if (pack_btc->ClickID == 155)
			{
				for (int j=40; j<159; j++)
					send_bfn(pack_btc->UCID, j);
				players[i].Shop = 4;
				btn_shop(&players[i]);
			}

			if (pack_btc->ClickID == 149)
			{
				for (int j=159; j>0; j--)
				{
					send_bfn(pack_btc->UCID, j);
					Sleep(10);
				}
			}

			if (pack_btc->ClickID == 103)
			{
				for (int j=0; j<50; j++)
					send_bfn(pack_btc->UCID, 100+j);
				btn_info(&players[i], 1);
			}

			if (pack_btc->ClickID == 104)
			{
				for (int j=0; j<50; j++)
					send_bfn(pack_btc->UCID, 100+j);

				btn_info(&players[i], 2);
			}

			if (pack_btc->ClickID == 105)
			{
				for (int j=0; j<50; j++)
					send_bfn(pack_btc->UCID, 100+j);

				btn_info(&players[i], 3);
			}
			if (pack_btc->ClickID == 106)
			{
				for (int j=0; j<50; j++)
					send_bfn(pack_btc->UCID, 100+j);

				btn_info(&players[i], 4);
			}


			if (pack_btc->ClickID == 200)
			{
				for (int j=0; j<5; j++)
					send_bfn(pack_btc->UCID, 200+j);
			}

			break;
		} // if UCID
	}// for
	pthread_mutex_unlock (&RCmutex);
	Sleep(100);
}
int
play (dspdev_t * dsp, int fd, big_t * datamark, big_t bsize, double total_time,
      double constant, readfunc_t * readf, decoders_queue_t * dec, seekfunc_t * seekf)
{
#define EXITPLAY(code) \
  do { \
    ossplay_free (buf); \
    ossplay_free (verbose_meta); \
    clear_update (); \
    ioctl (dsp->fd, SNDCTL_DSP_HALT_OUTPUT, NULL); \
    errno = 0; \
    return (code); \
  } while (0)

  big_t rsize = bsize;
  big_t filesize = *datamark;
  ssize_t outl;
  unsigned char * buf, * obuf, contflag = 0;
  decoders_queue_t * d;
  verbose_values_t * verbose_meta = NULL;

  buf = (unsigned char *)ossplay_malloc (bsize);

  if (verbose)
    {
      verbose_meta = setup_verbose (dsp->format,
                              format2bits(dsp->format) * dsp->channels *
                              dsp->speed / 8.0, total_time);
      if (seek_time == 0) print_play_verbose_info (NULL, 0, verbose_meta);
    }

  *datamark = 0;

  while (*datamark < filesize)
    {
      if (eflag) EXITPLAY (eflag);

      rsize = bsize;
      if (rsize > filesize - *datamark) rsize = filesize - *datamark;

      if ((seek_time != 0) && (seekf != NULL))
        {
          errors_t ret;

          ret = seekf (fd, datamark, filesize, constant, rsize, dsp->channels,
                       dec->metadata);
          if (ret == E_OK)
            {
              if (verbose)
                {
                  verbose_meta->secs = (double)seek_time;
                  verbose_meta->next_sec = (double)seek_time;
                  print_play_verbose_info (NULL, 0, verbose_meta);
                }
              seek_time = 0;
              continue;
            }
          else if (ret == SEEK_CONT_AFTER_DECODE) contflag = 1;
          else EXITPLAY (ret);
        }

      if ((outl = readf (fd, buf, rsize, dec->metadata)) <= 0)
        {
          if (errno) perror_msg ("read");
          if ((filesize != BIG_SPECIAL) && (*datamark < filesize) && (!eflag))
            {
              print_msg (NOTIFYM, "Sound data ended prematurely!\n");
            }
          EXITPLAY (eflag);
        }
      *datamark += outl;

      if (contflag)
        {
          contflag = 0;
          continue;
        }

      obuf = buf; d = dec;
      do
        {
          outl = d->decoder (&(d->outbuf), obuf, outl, d->metadata);
          obuf = d->outbuf;
          d = d->next;
        }
      while (d != NULL);

      if (verbose) print_play_verbose_info (obuf, outl, verbose_meta);
      if (write (dsp->fd, obuf, outl) == -1)
        {
          if ((errno == EINTR) && (eflag)) EXITPLAY (eflag);
          ossplay_free (buf);
          perror_msg ("audio write");
          exit (E_DECODE);
        }
    }

  ossplay_free (buf);
  ossplay_free (verbose_meta);
  clear_update ();
  return 0;
}
/* ................................ MAIN ............................. */
int      main         (void)
{
FILE     *Fptr[2];
int      iprint, printint, iloop;
double   T, TINITIAL,TFINAL,INTEGSTP,abserr,relerr,_printint;
double   VAR[2];

/* Open input and output files */
for(iloop=0;  iloop<=1;  iloop++)
  {
  char fileName[256];
  if( !iloop ) strcpy(fileName, "PendulumDynamics.in");
  else sprintf(fileName, "PendulumDynamics.%d", iloop);
  if( (Fptr[iloop] = fopen(fileName, iloop ? "w" : "r")) == NULL)
    {printf("Error: unable to open file %s\n", fileName);  exit(0);}
  }
 
/* Read top of input file */
for(iloop=0;  iloop<6;  iloop++) pgets(Fptr[0],NULL);

/* Read values of constants from input file */
readf(Fptr[0],&g,&i,&l,&m,NULL);

/* Read the initial value of each variable from input file */
readf(Fptr[0],&omega,&theta,NULL);

/* Read integration parameters from input file */
readf(Fptr[0],&TINITIAL,&TFINAL,&INTEGSTP,&_printint,&abserr,&relerr,NULL);
printint = (int)_printint;

/* Write heading(s) to output file(s) */
fprintf(stdout,  "%% FILE: PendulumDynamics.1\n%%\n");
fprintf(stdout,  "%%     omega          theta            k              p         longoutput\n"
                 "%% (radian/sec)     (radian)       (joules)       (joules)        (UNITS)\n\n" );
fprintf(Fptr[1], "%% FILE: PendulumDynamics.1\n%%\n");
fprintf(Fptr[1], "%%     omega          theta            k              p         longoutput\n"
                 "%% (radian/sec)     (radian)       (joules)       (joules)        (UNITS)\n\n" );

/* Unit conversions */
  Pi       = 3.141592653589793;
  DEGtoRAD = Pi/180.0;
  RADtoDEG = 180.0/Pi;

/* Evaluate constants */
  z[8] = g*m;
  z[15] = g*l*m;

/* Initialize time, print counter, variables array for integrator */
  T      = TINITIAL;
  iprint = 0;
  VAR[0] = omega;
  VAR[1] = theta;

/* Initalize numerical integrator, with call to eqns1 at T=TINITIAL */
kutta(eqns1, 2, VAR, &T, INTEGSTP, abserr, relerr, 0);

/* Numerically integrate; print results */
while(1)
  {
  if( TFINAL>=TINITIAL && T+.01*INTEGSTP>=TFINAL) iprint=-7;
  if( TFINAL<=TINITIAL && T+.01*INTEGSTP<=TFINAL) iprint=-7;
  if( iprint <= 0 )
    {
    output(Fptr, T);
    if( iprint == -7 ) break;
    iprint = printint;
    }
  if( !kutta(eqns1, 2, VAR, &T, INTEGSTP, abserr, relerr, 2) )
    {
    output(Fptr, T);
    for(iloop=0;  iloop<=1;  iloop++)
      fputs( "\n\tError: Numerical integration failed to converge\n",
              iloop ? Fptr[iloop]:stdout);
    break;
    }
  iprint--;
  }

/* Inform user of input and output filename(s) */
puts( "\n Input is in the file PendulumDynamics.in" );
puts( "\n Output is in the file PendulumDynamics.1" );
puts( "\n The output quantities and associated files are listed in file "
      "PendulumDynamics.dir\n" );
return 0;
}
 void main()
 {
	clrscr();
	int i,ch,n,res;
	char a,an,pass[6];
	cout<<"\t********** T H E   H Y A T T   R E S I D E N C Y **********\n";
	cout<<"\t----------------------------------------------------------------------------------\n";
	gotoxy(30,13);
	cout<<"Enter password\t";
	for(i=0;i<5;i++)
	{

		pass[i]=getch();
		cout<<'*';
	}
	pass[5]='\0';
	getch();

	if(strcmp(pass,"hyatt")==0)
	{
		gotoxy(32,15);
		cout<<"PASSWORD ACCEPTED";
		getch();
		do
		{
			clrscr();
			cout<<"\t********** T H E   H Y A T T   R E S I D E N C Y **********\n";
			cout<<"\t----------------------------------------------------------------------------------\n";

			cout<<"\n1.Get Information ";
			cout<<"\n2.Get Details about Rooms";
			cout<<"\n3.Get details for a particular room";
			cout<<"\n4.Book a Room";
			cout<<"\n5.Edit information for a particular room";
			cout<<"\n6.Check out And Print Bill";
			cout<<"\n7.Count the present Number of rooms booked";
			cout<<"\n8.Exit the program";
			cout<<"\nPls. Enter the Choice\t";
			cin>>ch;

			switch(ch)
			{
				case 1 : details();
					break;

				case 2 : readf();
					break;

				case 3: cout<<"search details according to-\na.name \nb.roomno ";
					a=getch();
					switch(a)
					{
						case 'a':namesearch();
							break;
						case 'b':roomnosearch();
							break;
					 }
					break;

				case 4 : create();
					 break;


				case 5 : cout<<"\nenter the value of room number to edit the info..\t";
						cin>>n;
					 edit(n);
					 break;

				case 6 : cout<<"\nEnter the room number you want to check out\t";
						cin>>n;
					 chkout(n);
					 break;

				case 7 : res=count();
					 cout<<res;
					 break;

				case 8 : exit(0);
					 break;

	}
	cout<<"\nDo You Want to go to main menu..\t";
	an=getch();

	}while(an=='y'||an=='Y');
	}
Exemple #23
0
int main (int argc, char *argv[])
{
    struct parms parms;
    struct timeval start;
    int i, rank, size, ncy, cyc;
    int  freq[5]={PHI,P,V,C};
    double *data, *phi0, *kr, *r, *dr, *phit, *dphi;
    double telp, time, tcyc, havg, vavg, delh;
    char *wkdir=0;
    char input[64]={"init/input.dat"};
    char phichek[64]={"init/phi.chk"};
    //char phii[Nimob][64];
    //for (i = 0; i < Nimob; i++){
    //    sprintf(phii[i],"data/phi%d.",(i+1));
    //}
    char phii[64] = {"data/phi."};
    char p[64] = {"data/p."};
    char vx[64] = {"data/vx."};
    char vy[64] = {"data/vy."};
    char vz[64] = {"data/vz."};
    char c[64] = {"data/c."};
    char avname[64]={"data/avg."};
    char fname[64];
    FILE *fileptr;

    if (argc > 1) cyc = atoi(argv[1]);
    if (argc > 2) wkdir = argv[2];

    winit(&start);
    // MPI Initialization
    MPI_Init(&argc,&argv);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    parms.rank = rank; parms.size = size;

    parms.V0 = 0;
    parms.nsten = (2*Dim)+1;
    parms.Nvar = Dim + 3;
    nameinput(fname, input, wkdir);
    fileptr = fopen(fname, "r");            // Read input data
    fscanf(fileptr, "%*s %*s %*s %*s %*s %*s %*s");
    fscanf(fileptr, "%d %lf %lf %lf %lf %lf %lf", &ncy, &parms.Re, &parms.Pe, &parms.Da, &parms.pow, &parms.dx, &parms.dt);
    fclose(fileptr);

    // Reading the initial porosity profile
#ifdef SEED
    char phseed[64] = {"init/phi.dat-seed"};
    filename(fname, phseed, wkdir, parms);
#endif
#ifndef SEED
    char phinit[64] = {"init/phi.dat"};
    filename(fname, phinit, wkdir, parms);
#endif
    fileptr = fopen(fname, "r");
    fscanf(fileptr, "%5d %5d %5d %5d %5d %5d %lf", &parms.Nx, &parms.Ny, &parms.nx, &parms.ny, &parms.Nz, &parms.cyc, &parms.t);
    fclose(fileptr);

    // 2D Domain decomposition
    parms = mapping(parms);
    parms.N = (parms.nx*parms.ny*parms.Nz);
    
    // Initialize pointers
    phi0 = (double *) calloc(parms.N, sizeof(double));
    data = (double *) calloc(parms.N*parms.Nvar, sizeof(double));
    dphi = (double *) calloc(parms.N, sizeof(double));
    phit = (double *) calloc(parms.N, sizeof(double));
    kr = (double *) calloc(parms.N, sizeof(double));
    r = (double *) calloc(parms.N, sizeof(double));
    dr = (double *) calloc(parms.N, sizeof(double));

    // Create Spiral indexing
    int *sp = spiral(parms);

    readf(fname, phi0, parms);                  // Read from the input porosity profile
    writedata(phi0, data, 0, 0, parms);        // Write the input porosity to pointer "data" @ 0

    for(i = 0; i < parms.N; i++){
        data[(i*parms.Nvar)+Dim+2] = 1.0;      // Initialize c = 1.0
        kr[i] = 1.0;
    }
    erode(data, kr, r, dr, sp, parms);              // Intial fields
    parms.V0 = avgf(data, 2, parms);

    if (cyc > 0){
        parms.cyc = cyc;
        filename(fname, phichek, wkdir, parms);
        readb(fname, phi0, parms);
    }

    writedata(phi0, data, 0, 0, parms);        // Write the input porosity to pointer "data" @ 0
    telp = wtime(&start);
    time = telp;
    if (parms.rank == 0){
        fprintf(stdout, "Initialization; elapsed time: % .3e\n\n", telp);
    }
    while (parms.cyc <= ncy){

        erode(data, kr, r, dr, sp, parms);
        havg = avgf(data, 0, parms);
        vavg = avgf(data, 2, parms);
        vavg = vavg*parms.Ny;
        delh = havg - parms.havg;
        parms.havg = havg;
        if (parms.rank == 0){
            filename(fname, avname, wkdir, parms);
            fileptr = fopen(fname, "w");
            if (parms.cyc == 0) fprintf(fileptr, " cycle   time       havg       qavg       delh\n");
            fprintf(fileptr, "%5d % .3e % .3e % .3e % .3e\n", parms.cyc, parms.t, havg, vavg, delh);
            fclose(fileptr);
        }
        //for (i = 0; i < Nimob; i++){
        //    filename(fname, phii[i], wkdir, parms);    // Write data files
        //    writef(fname, data, i, parms, freq[0]);
        //}
        filename(fname, phii, wkdir, parms);    // Write data files
        writef(fname, data, 0, parms, freq[0]);
        filename(fname, p, wkdir, parms);
        writef(fname, data, 1, parms, freq[1]);
        filename(fname, vx, wkdir, parms);
        writef(fname, data, 2, parms, freq[2]);
        filename(fname, vy, wkdir, parms);
        writef(fname, data, 3, parms, freq[2]);
        filename(fname, vz, wkdir, parms);
        writef(fname, data, 4, parms, freq[2]);
        filename(fname, c, wkdir, parms);
        writef(fname, data, Dim+2, parms, freq[3]);

        // Calculate erosion during dt
        double dt = parms.dt/parms.Da;
#ifdef EULER
        for (i = 0; i < parms.N; i++)
            dphi[i] = r[i]*dt;
#endif

#ifdef MIDPT
        for (i = 0; i < parms.N; i++){
            phit[i] = phi0[i] + 0.5*r[i]*dt;
        }
        writedata(phit, data, 0, 0, parms);
        erode (data, kr, r, dr, sp, parms);
        for (i = 0; i < parms.N; i++)
            dphi[i] = r[i]*dt;
#endif

#ifdef RK4
        for (i = 0; i < parms.N; i++){
            phit[i] = phi0[i] + 0.5*r[i]*dt;
            dphi[i] = r[i]*dt/6.0;
        }
        writedata(phit, data, 0, 0, parms);
        erode (data, kr, r, dr, sp, parms);
        for (i = 0; i < parms.N; i++){
            phit[i] = phi0[i] + 0.5*r[i]*dt;
            dphi[i]+= r[i]*dt/3.0;
        }
        writedata(phit, data, 0, 0, parms);
        erode (data, kr, r, dr, sp, parms);
        for (i = 0; i < parms.N; i++){
            phit[i] = phi0[i] + r[i]*dt;
            dphi[i]+= r[i]*dt/3.0;
        }
        writedata(phit, data, 0, 0, parms);
        erode (data, kr, r, dr, sp, parms);
        for (i = 0; i < parms.N; i++)
            dphi[i]+= r[i]*dt/6.0;
#endif

        // Update height profile
        for (i = 0; i < parms.N; i++){
            phi0[i] += dphi[i];
#ifdef APLIM
            if (phi0[i] >= AMAX){
                phi0[i] = AMAX;
                kr[i] = 0.0;
            }
#endif
        }
        
        writedata(phi0, data, 0, 0, parms);

        telp = wtime(&start);
        tcyc = time;
        time += telp;
        tcyc = time - tcyc;
        if (parms.rank == 0){
            fprintf(stdout, "Cycle %6d;   cycle time: % .3e  total time: % .3e\n\n", parms.cyc, tcyc, time);
        }
        parms.cyc++;
        parms.t += parms.dt;

#if CHEK > 0
        if ((parms.cyc-1)%CHEK == 0){
            filename(fname, phichek, wkdir, parms);
            writeb(fname, data, 0, parms);            /* Checkpoint aperture */
        }
#endif
    }
    // Free memory
    free(phit); free(r); free(dr); free(kr);
    free (dphi); free(phi0);
    free(data); free(sp);
    // Finalize MPI
    MPI_Finalize();
    return (0);
}
Exemple #24
0
bool_t dat_read_dir(restable_t *rt)
{
	uint32_t number;
	uint32_t zero;
	dat_t dat;
	uint32_t i;
	uint32_t j;

	if (readf(rt->file, "b4c4b4c4",
		&number,
		NULL,
		&zero,
		NULL) != OK)
	{
		fprintf(stderr, "dat_read_dir: Can't read header.\n");
		return FALSE;
	}
	if (zero != 0)
	{
		fprintf(stderr, "dat_read_dir: Wrong DAT-file.\n");
		return FALSE;
	}
	dat_init(&dat);
	if (dat_set_numpaths(&dat, number) == FALSE)
		return FALSE;

	for(i = 0; i < dat.numpaths; i++)
	{
		if (readf(rt->file, "sp", &(dat.paths[i].name)) != OK)
		{
			fprintf(stderr, "dat_read_dir: Can't read path name #%u.\n", i);
			dat_free(&dat);
			return FALSE;
		}
	}
	for(i = 0; i < dat.numpaths; i++)
	{
		if (readf(rt->file, "b4c12",
			&(dat.paths[i].numfiles),
			NULL) != OK)
		{
			fprintf(stderr, "dat_read_dir: Can't read entry.\n");
			dat_free(&dat);
			return FALSE;
		}
		number = dat.numfiles;
		if (dat_set_numfiles(&dat, dat.numfiles + dat.paths[i].numfiles) == FALSE)
		{
			dat_free(&dat);
			return FALSE;
		}
		for(j = 0; j < dat.paths[i].numfiles; j++)
		{
			if (readf(rt->file, "spb4b4b4b4",
				&(dat.files[number + j].name),
				&(dat.files[number + j].compression),
				&(dat.files[number + j].offset),
				&(dat.files[number + j].size),
				&(dat.files[number + j].compressed)) != OK)
			{
				dat_free(&dat);
				return FALSE;
			}
			dat.files[number + j].path = i;
		}
	}
	if (dat_to_rt(rt, &dat) == FALSE)
	{
		dat_free(&dat);
		return FALSE;
	}
	/*dat_print(&dat);*/
	dat_free(&dat);
	return TRUE;
}
Exemple #25
0
int process_file(void){

  int fd;
  int n;
  struct nids_data_st nids_data;
  int status;

  if(g.opt_inputfile == NULL)
    fd = fileno(stdin);
  else{
    fd = open(g.opt_inputfile, O_RDONLY);
    if(fd == -1)
      log_err_open(g.opt_inputfile);
    else
      g.fd = fd;
  }

  status = dcnids_read_header(fd, g.opt_skipcount, &nids_data.nids_header);
  if(status != 0){
    if(g.opt_inputfile != NULL)
      log_warnx("Error reading nids header from %s", g.opt_inputfile);
  
    if(status == -1)
      log_err(1, "Error reading file.");
    else
      log_errx(1, "Error reading file. Short file.");
  }

  if(dcnids_verify_wmoawips_header(nids_data.nids_header.buffer) != 0)
    log_errx(1, "Invalid wmo header.");

  if(dcnids_decode_header(&nids_data.nids_header) != 0)
    log_errx(1, "Invalid pdb header; maybe a zlib compressed header.");

  /*
   * Decode the polygon data.
   */

  n = nids_data.nids_header.m_msglength - NIDS_HEADER_SIZE;
  if(n <= 0)
    log_errx(1, "Corrupt file header.");

  nids_data.data = malloc(n);
  if(nids_data.data == NULL)
    log_err(1, "Cannot load data in memory");

  nids_data.data_size = n;
  n = readf(fd, nids_data.data, nids_data.data_size);
  if(n == -1)
    log_err(1, "Error from read()");     
  else if((unsigned int)n != nids_data.data_size){
    log_errx(1, "File is corrupt (short)");
  }

  (void)close(fd);
  g.fd = -1;

  nids_decode_data(&nids_data);

  /* Output data */

  if(g.opt_output_dir != NULL){
    if(chdir(g.opt_output_dir) != 0)
      log_err(1, "Cannot chdir to %s", g.opt_output_dir);
  }

  if(g.opt_csv != 0)
    nids_csv_write(&nids_data);

  if((g.opt_shp != 0) || (g.opt_shx != 0))
    nids_shp_write(&nids_data);

  if(g.opt_dbf != 0)
    nids_dbf_write(&nids_data);

  if(g.opt_info != 0)
    nids_info_write(&nids_data);

  return(0);
}
Exemple #26
0
static int process_file(void){

  struct dcgini_st dcg;
  int status = 0;
  int fd;
  int n;

  /* Initialize */
  dcg.pdb.buffer_size = NESDIS_WMO_HEADER_SIZE + NESDIS_PDB_SIZE;

  if(g.opt_inputfile == NULL)
    fd = fileno(stdin);
  else{
    fd = open(g.opt_inputfile, O_RDONLY);
    if(fd == -1)
      log_err_open(g.opt_inputfile);
    else
      g.fd = fd;
  }

  status = read_nesdis_pdb(fd, &dcg.pdb);

  if(status == -1)
    log_err(1, "Error from read_nesdis_pdb()");
  else if(status == 1)
    log_errx(1, "Error from read_nesdis_pdb(). File short.");
  else if(status == 2)
    log_errx(1, "Error from read_nesdis_pdb(). File has invalid wmo header");
  
  /*
   * Read the data once and for all. Use readf() in case the input comes
   * from a pipe.
   */
  dcg.ginidata.data_size = dcg.pdb.linesize * dcg.pdb.numlines;
  dcg.ginidata.data = malloc(dcg.ginidata.data_size);
  if(dcg.ginidata.data == NULL)
    log_err(1, "Cannot load data in memory.");

  n = readf(fd, dcg.ginidata.data, dcg.ginidata.data_size);
  if(n == -1)
    log_err(1, "Error reading from file");
  else if((size_t)n != dcg.ginidata.data_size)
    log_errx(1, "Error reading from file. File is corrupt (short)");
    
  (void)close(fd);
  g.fd = -1;
      
  /*
   * Fill out point data - This function must be called unconditionally,
   * even if other data formats besised shp, csv, are needed, in order
   * to initalize properly the projection transformations and the
   * bounding box.
   */
  status = dcgini_transform_data(&dcg);

  if((status == 0) && (g.opt_asc != 0))
    status = dcgini_regrid_data_asc(&dcg, g.opt_llur_str, g.opt_llur_str_diff);

  if(status != 0)
    return(status);

  /* Output the data */

  if(g.opt_output_dir != NULL){
    status = chdir(g.opt_output_dir);
    if(status != 0)
      log_err(1, "Cannot chdir to %s", g.opt_output_dir);
  }

  if((g.opt_shp != 0) || (g.opt_shx != 0))
    gini_shp_write(&dcg);

  if(g.opt_dbf != 0)
    gini_dbf_write(&dcg);

  if(g.opt_info != 0)
    gini_info_write(&dcg);

  if(g.opt_csv != 0)
    gini_csv_write(&dcg);

  if(g.opt_asc != 0)
    gini_asc_write(&dcg);
  
  return(0);
}
Exemple #27
0
int do_cp(u8 * src , u8 * dst){
	s8 sfd,dfd,ret ;
		u32 retlba;
	struct fnode fn;
	u32 size;
	u8 buff[1024];
	if (!check_for_args(CP,2)) return 1;
	sfd=openf(src,O_READ);
	if ( sfd == -1){
		vd_puts("COULD NOT OPEN SOURCE FILE\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}
	dfd = openf(dst, O_RW);
	if ( dfd == -1){
		retlba  = creatf(dst , 064);
		if (retlba  == NO_LBA){
			vd_puts("COULD NOT OPEN  OR CREATE THE DESTINATION FILE\n");
						errormessage(geterror());
						fl_clean();
					return 0;
			   }
		   dfd = openf(dst,O_RW);
	}

	ret = finfo(sfd, &fn);
	if (ret == -1){
		vd_puts("HAD PROBLEMS WITH GETTING INFO  OF SOURCE FILE\n");
				 errormessage(geterror());
		closef(sfd);
		closef(dfd);
				fl_clean();
		return 1;
	}
	size = fn.size;
		while (size ){
			ret = readf(sfd  , buff,  (size < 1024  ?  size  :  1024));
			if ( ret == -1){
				vd_puts("ERRROR OCCURED IN READING SOURCE FILE\n");
						errormessage(geterror());
				closef(sfd);
				closef(dfd);
						fl_clean();
				return 1;
			}
			ret = writef(dfd, buff , (size < 1024  ?  size  :  1024));
			if (ret == -1){
				vd_puts("ERROR IN WRITE  DELETING THE FILE\n");
					   errormessage(geterror());
				closef(sfd);
				closef(dfd);
				unlinkf(dst);
						 fl_clean();
				return 1;
			}
				if (size >= 1024){
						size-=1024;
				}else
						size=0;

		}
		fl_clean();
	return 0;
}