Esempio n. 1
0
void listAllCars() {

    printf("Listing all the cars!\n");
    printf("-----------------------------------------\n");

    int idx = 0;
    Car car;
    FILE *fd = fopen("cars.db","r");
    
    while(fd && 1) {
        fseek(fd,sizeof(Car)*idx,SEEK_SET);
        size_t numRead = fread(&car,sizeof(Car),1,fd);
        
        if (numRead == 0) {
            break;
        } else {
            printCar(&car);
        }
        idx++;

    }

    printf("\nFinished!\n\n");
    
    fclose(fd); 

}
Esempio n. 2
0
void printList(Car *car, int n) {
	int i;
	for (i = 0; i<n; i++) {
		printCar(&car[i]);
		printf("\n");
	}
}
Esempio n. 3
0
void EDIRemoveCarFromContext(CONTEXT context, CAR * oldCar)
{
	for (uint i = 0, length = context->nbCars; i < length; ++i)
	{
		if(context->cars[i]->ID == oldCar->ID)
		{
#ifdef DEBUG_BUILD
			printf("\nFlushing car from array: current ptr %p (size %u)\n", context->cars, context->nbCars);
			printCar(oldCar);
#endif
			context->cars = (CAR **) removeItemAtIndexFromArray((void **) context->cars, context->nbCars--, i);
#ifdef DEBUG_BUILD
			printf("Resized: new ptr %p (size %u)\n\n", context->cars, context->nbCars);
#endif
			
			if(oldCar->context.section == SECTION_NODE)
				GET_CAR_NODE(context->EDI.node, oldCar->context.index, oldCar->context.onLeftRoad) = NULL;
			else
				GET_CAR((&context->EDI.externalRoads[oldCar->context.section]), false, oldCar->context.index, oldCar->context.onLeftRoad) = NULL;
			
			crushCar(oldCar);
			break;
		}
	}
}
Esempio n. 4
0
//vypise auta danej farby
void printCarsByColor(Car *car, int n, Color color) {
	for (n - 1; n >= 0; n--) {
		if (car[n].color == color) {
			printCar(&car[n]);
			printf("\n");
		}
	}
}
Esempio n. 5
0
//vypise auta ktore jazdia na benzin
void printPetrolCars(Car *car, int n) {
	for (n - 1; n >= 0; n--) {
		if (car[n].fuel == 'B') {
			printCar(&car[n]);
			printf("\n");
		}
	}
}
Esempio n. 6
0
// vypise zoznam aut, kde datum evidencie je v lete …t.z. mesiace jun, jul, august
void printListSummer(Car *car, int n) {
	for (n - 1; n >= 0; n--) {
		if (car[n].evidDate.month >= JUN && car[n].evidDate.month <= AUG) {
			printCar(&car[n]);
			printf("\n");
		}
	}
}
Esempio n. 7
0
// vypise auta ktore maju rok vyroby medzi dvoma zadanymi hodnotami - vcitane nich
void printListBetwenYesrs(Car *car, int n, int beginYear, int endyear) {
	for (n - 1; n >= 0; n--) {
		if (car[n].year >= beginYear && car[n].year <= endyear) {
			printCar(&car[n]);
			printf("\n");
		}
	}
}
Esempio n. 8
0
bool findCarBySPZ(Car *car, int n, char *spz) {
	int i;
	for (i = 0; i < n; i++) {
		if (strcmp(car[i].licansePlate, spz) == 0) {
			printCar(&car[i]);
			printf("\n");
			return true;
		}
	}

	printf("NO CAR WITH %s PLATE\n", spz);
	return false;
}
Esempio n. 9
0
void readCar(int idx) {
    Car car;
    FILE *fd = fopen("cars.db","r+");
    fseek(fd,sizeof(Car)*idx,SEEK_SET);
    size_t numRead = fread(&car,sizeof(Car),1,fd);
    if (numRead == 1) {
        printCar(&car);    
    } else {
        printf("Wasn't able to find idx %i in car data\n", idx);
    }
    
    fclose(fd); 
    
}
Esempio n. 10
0
void writeCar(DatabaseInfo *info, Car* car) {

    printf("\nAdding .. ");
    printCar(car);

    FILE *fd = fopen("cars.db","r+");
    if (fd == NULL) {
        fd = fopen("cars.db","w+");
    }
    fseek(fd,sizeof(Car)*info->size,SEEK_SET);
    fwrite(car,sizeof(Car),1,fd);
    fclose(fd);

    // Update database info
    info->size++;
    writeDatabaseInfo(info);
}
Esempio n. 11
0
void searchCarByYear(short year) {

    int idx =0;
    Car car;
    FILE *fd = fopen("cars.db","r");
    
    while(1) {
        fseek(fd,sizeof(Car)*idx,SEEK_SET);
        size_t numRead = fread(&car,sizeof(Car),1,fd);
        
        if (numRead == 0) {
            printf("Search finished at idx %i\n", idx);
            break;
        } else if (car.year > year) {
            printf("Found ..");
            printCar(&car);
        }

        idx++;
    }
    fclose(fd); 

}
Esempio n. 12
0
void searchCarByMake(char *carMake) {

    int idx =0;
    Car car;
    FILE *fd = fopen("cars.db","r");
    
    while(1) {
        fseek(fd,sizeof(Car)*idx,SEEK_SET);
        size_t numRead = fread(&car,sizeof(Car),1,fd);
        
        if (numRead == 0) {
            printf("Search finished at idx %i\n", idx);
            break;
        } else if (strstr(car.make,carMake) != NULL) {
            printf("Found ..");
            printCar(&car);
        }

        idx++;
    }
    fclose(fd); 

}
Esempio n. 13
0
void show_calendar(bool input, int x_axis = 14, int y_axis = 10) {
	// Calendar
	wcal = newwin(12, 52, y_axis, x_axis);
	wbkgd(wcal, COLOR_PAIR(4));

	// Get current date and print the calendar
	time_t rawtime = time(NULL);
	tm now;
	localtime_s(&now, &rawtime);

	// Applies the changes if the user select to change the month / year
	if (selected_mon != 0 && selected_year != 0) {
		now.tm_year = selected_year - 1900;
		now.tm_mon = selected_mon - 1;
	}

	// Variables
	int nmon = 1, nyear = 1900;

	// Print out the calendar
	printCar(nyear + now.tm_year, now.tm_mon + nmon);

	// Window border
	box(wcal, 0, 0);

	// Draw the window and its contents
	wrefresh(wcal);

	// Loop to manage user inputs
	if (input == true) {
		int key;
		while (1) {
			key = getch();

			// Pressed enter
			if (key == 13) {
				selected_mon = now.tm_mon + nmon;
				selected_year = nyear + now.tm_year;
				erase();
				titlebar();
				refresh();
				menu();
			}

			// Pressed q to exit
			if (key == 113 || key == 81) {
				exit(0);
			}

			// Pressed left key and change to a month before current month
			if (key == 260) {
				nmon--;
				if (now.tm_mon + nmon == 0) {
					nmon = 12 - now.tm_mon;
					nyear--;
				}
				werase(wcal);
				printCar(nyear + now.tm_year, now.tm_mon + nmon);
				box(wcal, 0, 0);
				wrefresh(wcal);
			}

			// Pressed right key and change the month next after current month
			if (key == 261) {
				nmon++;
				if (now.tm_mon + nmon >= 13) {
					nmon = 1 - now.tm_mon;
					nyear++;
				}
				werase(wcal);
				printCar(nyear + now.tm_year, now.tm_mon + nmon);
				box(wcal, 0, 0);
				wrefresh(wcal);
			}
		}
	}
}
Esempio n. 14
0
bool EDIProcessCarInNode(CONTEXT context, uint posInLine, bool isLeft, uint _currentSession)
{
	CAR * currentCar = GET_CAR_NODE(context->EDI.node, posInLine, isLeft);
	if(!EDICarShouldMove(currentCar, _currentSession))
		return false;
	else
		currentCar->context.session = _currentSession;
	
	//Okay, start processing
	const uint oldPosInLine = posInLine++;
	
	if(currentCar->context.onLeftRoad)
	{
		while(EDIIsSlotReservedForExternalRing(posInLine))
			++posInLine;
	}
	
	posInLine %= NB_SLOTS_NODE;
	
	const bool inLastQuarter = EDIIsCarInQuarterBeforeExit(currentCar->context.index, currentCar->direction), isInFrontOfExit = EDIIsCarInFrontOfExit(oldPosInLine & 0xff, currentCar->direction);
	bool wantToGoToLeft = !inLastQuarter, gotOut = false;
	const CAR backupCar = *currentCar;
	
	//So, in the node, there is couple of scenarios:
	//	1. We just entered, we try to get in the internal road (shorter, 4 less slots than the external ring)
	//	2. We try to get in the external road when getting in the last quarter to get out easily
	//	3. We are in front of the exit
	//		1. We are in the external road, we just get out
	//		2. We are still in the internal road, we try really hard to get out
	//		3. If the road is really too crowded, or the exit unavailable, ¯\_(ツ)_/¯, we make one more turn
	
	if(isInFrontOfExit && isLeft && EDIIsNodeSlotAvailableFullCheck(context->EDI.node, oldPosInLine, wantToGoToLeft))
	{
#ifdef DEBUG_BUILD
		printf("[%d]: Successfully steared toward the external ring\n", currentCar->ID);
#endif
	}
	
	else if(isInFrontOfExit && !isLeft && EDIIsExternalSlotAvailable(&context->EDI.externalRoads[currentCar->direction], false, NB_SLOTS_BORDER - 1, EDIIsCarOnLastStepExit(oldPosInLine & 0xff, currentCar->direction)))
	{
		//\o/
#ifdef DEBUG_BUILD
		printf("[%d]: Successfully got out of the ring\n", currentCar->ID);
#endif
		gotOut = true;
	}
	
	//Perfect case?
	else if(EDIIsNodeSlotAvailableFullCheck(context->EDI.node, posInLine, wantToGoToLeft))
	{
		//ᕕ( ᐛ )ᕗ
#ifdef DEBUG_BUILD
		printf("[%d]: Successfully went to our optimal goal\n", currentCar->ID);
#endif
	}
	
	//Can we go forward, even on the wrong line?
	else if(EDIIsNodeSlotAvailableFullCheck(context->EDI.node, posInLine, !wantToGoToLeft))
	{
		wantToGoToLeft = !wantToGoToLeft;
#ifdef DEBUG_BUILD
		printf("[%d]: Changing line forward\n", currentCar->ID);
#endif
	}

	//No space to go forward, but can we change line?
	else if(EDIIsNodeSlotAvailableFullCheck(context->EDI.node, oldPosInLine, wantToGoToLeft))
	{
		posInLine = oldPosInLine;
#ifdef DEBUG_BUILD
		printf("[%d]: Changing line\n", currentCar->ID);
#endif
	}

	//Nope :(
	else
	{
		return true;
	}
	
	if(gotOut)
	{
		currentCar->context.index = NB_SLOTS_BORDER - 1;
		currentCar->context.section = currentCar->direction;
		currentCar->context.onLeftRoad = EDIIsCarOnLastStepExit(oldPosInLine & 0xff, currentCar->direction);
		
		EDI_EXT_ROAD * section = &context->EDI.externalRoads[currentCar->direction];
		
		if(!EDITransitionCars(&GET_CAR_NODE(context->EDI.node, oldPosInLine, isLeft), &GET_CAR(section, false, currentCar->context.index, currentCar->context.onLeftRoad)))
			currentCar->context = backupCar.context;
		else
			context->rendering.sorted = false;
	}
	else
	{
		currentCar->context.index = posInLine & 0xff;
		currentCar->context.onLeftRoad = wantToGoToLeft;
		
		updateNodeData(currentCar);
		
		if(!EDITransitionCars(&GET_CAR_NODE(context->EDI.node, oldPosInLine, isLeft), &GET_CAR_NODE(context->EDI.node, currentCar->context.index, wantToGoToLeft)))
			currentCar->context = backupCar.context;
		else
			context->rendering.sorted = false;
	}
	
#ifdef DEBUG_BUILD
	printCar(currentCar);
#endif

	return false;
}