Example #1
0
void searchItem(LinkedList<Item> *listOfItems)
{
	Node<Item> *tmp = listOfItems->mHead;
	
	if (tmp == NULL) {
		cout << "No clubs in data.\n";
		return;
	}
	
	bool valid = false;
	string name;
	
	do {
		cout	<< "Please enter the name of the item:\n\n"
				<< "Item: ";
		getline(cin, name);
		valid = validateStr(name);
		if (!valid) cout << "Invalid input...\n";
	} while (!valid);
	
	cout << "\nItems for '" << name << "':\n\n";
	
	int quantity = 0;
	
	while (tmp != NULL) //Check the entire list for the club's items
	{
		if (tmp->mData.getName() == name)
		{
			//When an item of the club is found, it is displayed to the console
			cout << tmp->mData.getName() << endl;
			quantity++;
			tmp = tmp->mNext;
		}
		else
		{
			//If an item does not belong to a club, the loop just moves to the next item listed
			tmp = tmp->mNext;
		}
	}
	
	if (quantity <= 0) {
		cout << "No items found.";
	}

	cout << endl;
	
	pause();
}
Example #2
0
static int updateProcess( pid_t pid ) {
	ProcessInfo	*ps;
	int		fd;
	char		buf[BUFSIZE];
	prpsinfo_t	psinfo;
	struct passwd	*pw;
	register double newCentStamp,timeDiff, usDiff,usTime;
	struct timeval tv;

	if( (ps = findProcessInList( pid )) == NULL ) {
		if( (ps = (ProcessInfo *) malloc( sizeof( ProcessInfo )))
				== NULL ) {
			print_error( "cannot malloc()\n" );
			return( -1 );
		}
		ps->pid = pid;
		ps->userName = NULL;
		ps->alive = 0;

		gettimeofday(&tv, 0);
		ps->centStamp = (double)tv.tv_sec * 100.0 + (double)tv.tv_usec / 10000.0;

		push_ctnr( ProcessList, ps );
		bsort_ctnr( ProcessList, processCmp );
	}

	sprintf( buf, "%s/pinfo/%ld", PROCDIR, pid );
	if( (fd = open( buf, O_RDONLY )) < 0 ) {
		/* process terminated */
		return( -1 );
	}



	if( ioctl(fd,PIOCPSINFO,&psinfo) < 0) {
		print_error( "cannot read psinfo from \"%s\"\n", buf );
		close( fd );
		return( -1 );
	}
	close( fd );

	ps->ppid = psinfo.pr_ppid;
	ps->uid = psinfo.pr_uid;
	ps->gid = psinfo.pr_gid;

	pw = getpwuid( psinfo.pr_uid );
	if( ps->userName != NULL )
		free( ps->userName );
	ps->userName = strdup( pw->pw_name );

	strncpy (ps->State,lwpStateName( psinfo ),8);
        ps->State[7]='\0';


	ps->Prio = psinfo.pr_pri;

	gettimeofday(&tv, 0);
	newCentStamp = (double)tv.tv_sec * 100.0 + (double) tv.tv_usec / 10000.0;
	usTime = (double) psinfo.pr_time.tv_sec * 100.0 + (double)psinfo.pr_time.tv_nsec / 10000000.0;

	timeDiff = newCentStamp - ps->centStamp;
	usDiff = usTime - ps->Time;

	if ((timeDiff > 0.0) && (usDiff >= 0.0))
	{
		ps->Load = (usDiff / timeDiff) * 100.0;
		/* During startup we get bigger loads since the time diff
		* cannot be correct. So we force it to 0. */
		ps->Load = (ps->Load > 100.0) ? 0.0 : ps->Load;
	}
	else
		ps->Load = 0.0;

	ps->centStamp = newCentStamp;
	ps->Time = usTime;

	ps->Size = (psinfo.pr_size * pagesz)/KBYTES;
	ps->RSSize = (psinfo.pr_rssize * pagesz)/KBYTES;

	strncpy(ps->Command,psinfo.pr_fname,PRCOMSIZ);
        ps->Command[PRCOMSIZ-1]='\0';

	strncpy(ps->CmdLine,psinfo.pr_psargs,PRARGSZ);
        ps->CmdLine[PRARGSZ-1]='\0';

	validateStr( ps->Command );
	validateStr( ps->CmdLine );

	ps->alive = 1;
	return( 0 );
}