Ejemplo n.º 1
0
//Accept command line arguments
//Determine from second command line argument which procedure to perform
int main(int argc, char* argv[])
{
	char* fileSuffix;
	char* inisearch;
	char* command;
	char* argv2[] = {"", "", ""};

	INILoadManager(argv[argc-1]);

	if(argc == 3) 
	{
		if(strcmp(argv[1], "read") == 0)
		{
			PatchReaderMain(argv[2]);
		}
		else if(strcmp(argv[1], "write") == 0)
		{
			PatchWriterMain(argv);
		}
		else if(strcmp(argv[1], "split") == 0)
		{
			PatchSplitMain(argv[2]);
		}
		else if(strcmp(argv[1], "version") == 0)
		{
			VersionMain(argv[2], 1);
		}
		else if(strcmp(argv[1], "hijack") == 0)
		{
			HijackMain(argv[2]);
		}
		else
		{
			PrintMenu();
		}
	}
	else if(argc == 2)
	{
		//Possible drag & drop here or file association.
		//search in INI for that suffix to see which command to perform
		fileSuffix = GetFileSuffix(argv[1]);
		inisearch = str_join("fileassociations", ":", fileSuffix);
		command = INIGetString(inisearch);
		free(inisearch);

		argv2[0] = argv[0];
		argv2[1] = command;
		argv2[2] = argv[1];

		main(3, argv2);
	}
	else 
	{
		PrintMenu();
	}

	INIDestroyManager();

	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
/************************************************************************
DoApplicationTasks

This is the main application code that executes upon each power on and
wake up. It handles displaying a menu of choices while updating the
current date/time display on the serial port. If the user presses the
RB0/INT0 button, the application will exit and Deep Sleep mode will be
entered by the main() function above.

Parameters:     None
Return:         None
Side Effects:   None
 ************************************************************************/
void DoApplicationTasks(void) {
    unsigned char exit = 0;

    PrintMenu();

    LATDbits.LATD7 = 1; // turn on LED
    PIE1bits.RC1IE = 1; // enable USART receive interrupt (for Sleep wakeup)
    RB0ReleasedWait();

    // Enter IDLE mode on Sleep() instruction. Idle mode is used here so
    // that the Timer 0 and UART can continue operating while the
    // processor is powered down.
    OSCCONbits.IDLEN = 1;
    while (exit == 0) {
        // wait for user to make a selection
        EnableINT0();
        EnableRTCCAlarmEverySecond();
        RCSTA1bits.CREN = 0; // reset UART continuous receive to avoid overrun state
        RCSTA1bits.CREN = 1;
        Sleep();

        while (DataRdy1USART()) {
            switch (Read1USART()) {
            case '1':
                RTCCFGbits.RTCEN ^= 1;
                PrintMenu();
                break;

            case '2':
                SetDate();
                PrintMenu();
                break;

            case '3':
                SetTime();
                PrintMenu();
                break;

            case '4':
                exit = 1;
                break;
            }
        }

        if (RTCCFGbits.RTCEN) {
            PrintRTCC();
        }

        if (INTCONbits.INT0IF) {
            printf("\r\nRB0/INT0 power down requested.");
            exit = 1;
        }
    }

    DisableRTCCAlarm();
    printf("\r\n");
    LATDbits.LATD7 = 0; // turn off LED
}
Ejemplo n.º 3
0
void menuCases(int *input){
  
  switch(currentMenu){
    
  case 0:
    
    switch(*input){
    
    case 1:
      currentMenu = 1;
      PrintTempTable();
      while(readKeypad()!=11){};
      PrintMenu();
      break;
      
    case 2:
      temporary = findLight();
      sprintf(buffer,"%d \0",temporary);
      Print("Sun at",33,6);
      Print(buffer,33,7);
      break;
      
    case 3:
      Clear_Display();
      Print("Set high value:", 1, 2);
      Print("Press # to confirm", 1, 14);
      maxLimit = maxMinLimit(2);
      Print("Set low value: ", 1, 4);
      lowLimit = maxMinLimit(4);
      PrintMenu();
      break;
    case 6:
      if(fastMode == 1){
        fastMode = 60;
        while(readKeypad() != 0) {}
        Print("FM (off)", 32, 13);
        break;
      }
      else{
        fastMode = 1;
        while(readKeypad() != 0) {}
        Print("FM (on) ", 32, 13);
        break;
      }
    }
    
  case 1:
    
    switch(*input){
    case 11:
      currentMenu = 0;
      PrintMenu();
    }
  }
}
Ejemplo n.º 4
0
// Implementation: called when read has completed.
void ConsoleUI::RunL()
{
    TKeyCode kc = con_->KeyCode();
    pj_bool_t reschedule = PJ_TRUE;

    switch (kc) {
    case 'w':
	    snd_stop();
	    CActiveScheduler::Stop();
	    reschedule = PJ_FALSE;
	    break;
    case 'a':
    	snd_start(PJMEDIA_DIR_CAPTURE_PLAYBACK);
	break;
    case 't':
    	snd_start(PJMEDIA_DIR_CAPTURE);
	break;
    case 'p':
    	snd_start(PJMEDIA_DIR_PLAYBACK);
    break;
    case 'd':
    	snd_stop();
	break;
    default:
	    PJ_LOG(3,(THIS_FILE, "Keycode '%c' (%d) is pressed",
		      kc, kc));
	    break;
    }

    PrintMenu();

    if (reschedule)
	Run();
}
Ejemplo n.º 5
0
//---------------------------------------------------------------
//INSERTION POINT FOR MAIN FUNCTION
int main() {
    
    Pathfinder MazeSolver;
    bool bSolveMazeStatus = true;
    
    do {
        
        //PRINTS MENU TO SCREEN
        PrintMenu();
        
        //PROGRAM USER SELECTS DESIRED MENU OPTION
        //(and also validates the user input)
        int MenuSelection = SelectMainMenuOption();
        
        //PROGRAM CARRIES OUT SELECTED OPTION
        CarryOutMenuSelection(MazeSolver, bSolveMazeStatus, MenuSelection);
        
        /*
         *  --- SPECIAL NOTE ---
         *
         *  AFTER THE PROGRAM HAS FINISHED WITH ITS OPERATION,
         *  IT WILL THEN AUTOMATICALLY REPRINT THE MENU
         *  AND REQUEST A NEW DESIRED SELECTION.
         *  THE USER MUST MANUALLY SELECT "EXIT" (OPTION 5) TO LEAVE PROGRAM.
         *
         */
        
    } while (bSolveMazeStatus);
    
    
    return 0;
}
Ejemplo n.º 6
0
int main()
{
	Bank bank;
	int choice;

	while(1)
	{
		system("cls");
		PrintMenu();
		cout << "선택 : ";
		cin >> choice;

		switch( choice)
		{
		case MAKE:		bank.MakeAccount();		break;
		case DEPOSIT:	bank.Deposit();			break;
		case WITHDRAW:	bank.Withdraw();			break;
		case INQUIRE:	bank.Inquire();			break;
		case EXIT:		return 0;
		default:
			cout << "잘못된 메뉴 입력 " << endl;
			break;
		}
		system("pause");
	}
	return 0;
}
Ejemplo n.º 7
0
void InfoPage::Process()
{
  while (!m_bStop)
  {
    PrintMenu();
    int i;
    static char buff[200] = "";
    scanf("%d %s", &i, buff); 

    if (i == 0) {
      exit(0);
    }
    
    std::map<int, std::pair<InfoPageble*, CStdString> >::iterator iter;
    iter = pages.find(i);
    if (iter != pages.end()) {
      CStdString page;
      CStdString params(buff);
      page.reserve(10000);
      iter->second.first->GetInfoPage(&page, params);
      printf("%s\n", page.c_str());      
    } else {
      printf("Page not found\n");      
    }
  }
}
Ejemplo n.º 8
0
int main()
{
	Init();
	PrintMenu();
	DoTestLoop();
	
	return 0;
}
/**
 * Run the navigational loop
 *
 * @return Number on exit. 0 for no errors.
 */
int Run()
{
    int sel;
    int arr_length = 0;
    Car ** car_array = (Car **) malloc(10 * sizeof(struct Car *));

    // While true
    while(true) {

        // Print the menu and get a selection
        sel = PrintMenu();

        // Next step depends on the selection made
        switch(sel) {

            // User chose 1
            case 1:
                printf("You selected \"Print the cars array\"\n\n");
                print_cars_array(car_array, &arr_length);
                break;

            // User chose 2
            case 2:
                printf("You selected \"Insert the car records into a sorted array\"\n\n");
                insert_sorted_array(car_array, &arr_length);
                break;

            // User chose 3
            case 3:
                printf("You selected \"Sort cars by year\"\n\n");
                sort_cars_by_year(car_array, &arr_length);

                break;

            // User chose 4
            case 4:
                printf("You selected \"Print duplicates\"\n\n");
                print_duplicates(car_array, &arr_length);
                break;

            // User chose 5
            case 5:
                printf("You selected \"Exit\"\n\n");

                // Return here, with no erros, to exit the function.
                // Clean up will be next
                return 0;

            // User chose soomething not on the menu
            default:
                printf("Please enter a valid number from the menu!\n\n");
                break;
        }

    printf("--------------------\n");

    }
}
Ejemplo n.º 10
0
void setup()
{
    Serial.begin (115200);

    Serial.println("============");
    Serial.println("CA SAMPLE");
    Serial.println("============");
    PrintMenu();
}
Ejemplo n.º 11
0
static void DoTestLoop()
{
	int nTesterIndex = 0;

#if 0
	while(1)
	{
		printf("\n\n输入测试用例编号 [0为退出] :");
		scanf("%d", &nTesterIndex); 
		if (nTesterIndex == 0)
		{
			return;
		}
		
		if ((nTesterIndex <0) || (nTesterIndex > g_FuncCount))
		{
			printf("输入有误,请重试\n");
			continue;
		}
		else
		{
			printf("\n");
			if (testcase1[nTesterIndex-1].TestFunc)
			{
				testcase1[nTesterIndex-1].TestFunc();
			}
		}
	}
#else
	while(1)
	{
		printf("input your choice:");
		scanf("%d", &nTesterIndex); 
		if (nTesterIndex == 0)
		{
			Test_Flow_ExitTest();
			return;
		}
		
		if ((nTesterIndex <0) || (nTesterIndex > g_FuncCount))
		{
			printf("input invalid, repress.\n");
			continue;
		}
		else
		{
			if (testcase2[nTesterIndex-1].TestFunc)
			{
				testcase2[nTesterIndex-1].TestFunc();
			}
			PrintMenu();
		}
	}
#endif
}
Ejemplo n.º 12
0
 int main(){
  SystemInit();
  setup();
  adcSetup();
  Init_Display();
  timerSetup();
  tempMeasure();    
  updateDegrees();
  setupInterupts(5);
  lightMeasure();
  pwmSetup();
  setupInterupts(1000);
  PrintMenu();
  *PWM_CDTYUPD = 1800;
  int input;
  while(nInterupts < 500){}
  while(1){
    if(nInterupts >= 500){
      tempMeasure();
      nInterupts = 0;
    }
    updateDegrees();
    Print(floatToChar, 33,1); //Skriv ut temperatur
    
    if(value > maxLimit){
      Print("ALARM", 32, 3);
      Print("TOO HOT ", 32,4);
    }
    else if(value < lowLimit){
      Print("  ALARM", 32, 3);
      Print("TOO COLD", 32,4);
    }
    else if(value >lowLimit || value<maxLimit){
      Print("        ", 32, 3);
      Print("        ", 32, 4);
    }
    if(tempCount >= fastMode){
      updateDegrees();
      delay(60);
      if(tempFlag == 1){
        tempCalc();
        tempCount = 0;
        tempFlag = 0;
      }
    }
    
    input = readKeypad();
    if(buttonPressed == 1){
      buttonPressed = 0;
      menuCases(&input);
    }
  }
}
Ejemplo n.º 13
0
int main( void )
{
	Node* List    = NULL;

	int select=-1;

	DataAllDelete(&List);
	LoadingData(&List);

	do
	{
		select=PrintMenu(&List);

		switch(select)
		{
		case 1:
			DataAdd(&List);
			break;
		case 2:
			DataEdit(&List);
			break;
		case 3:
			DataDelete(&List);
			break;
		case 4:
			DataSearch(&List);
			break;
		case 5:
			DataPrint(&List);
			break;
		case 6:
			DataAllPrint(&List);
			break;
		case 7:
			SavingData(&List);
			break;
		case 8:
			DataAllDelete(&List);
			LoadingData(&List);
			break;
		case 9:
			printf(" 프로그램을 종료합니다.\n");
			printf("\n");
			break;
		default:
			break;
		}
	}while(select !=9);

	return 0;
}
Ejemplo n.º 14
0
int app_main()
{
    if (app_init() != PJ_SUCCESS)
        return -1;

    // Run the UI
    ConsoleUI *con = new ConsoleUI(console);

    con->Run();

    PrintMenu();
    CActiveScheduler::Start();

    delete con;

    app_fini();
    return 0;
}
Ejemplo n.º 15
0
void PrintSubMenu() {
  int input = 5;

  // 1. print contents
  PrintSubContents();

  // 2. handle input
  
//  cin >> input;

  while(input != EXIT) {
    switch(input) {
      case 0: // return to main menu
        PrintMenu();
        break;
      case 1: // buy stuff
        break;
    }

    // Refresh(&GameScreen);

  }

}
Ejemplo n.º 16
0
int main(int argc, char *argv[])
{
	int Index = 0;
	int Arg = 1;
	char *VirtualCard = NULL;
	BCAS::Manager::Abstract *Card;

	argc--;
	while (argc > 0) {
		if (strcmp(argv[Arg], "-virtual") == 0) {
			if (argc == 1) {
				printf("Missing file parameter.\n");
				return 1;
			}	
			VirtualCard = _strdup(argv[++Arg]);
			argc--;
		} else if (strcmp(argv[Arg], "-reader") == 0) {
			if (argc == 1) {
				printf("Missing file parameter.\n");
				return 1;
			}
			Index = atoi(argv[++Arg]);
			argc--;
		} else if (strcmp(argv[Arg], "-list") == 0) {
			Index = -1;
		} else {
			printf("Invalid parameter: %s\n", argv[Arg]);
			return 1;
		}
		Arg++;
		argc--;
	}

	if (VirtualCard == NULL) {
		SCARDCONTEXT Ctx;
		LONG Result;
		char *Reader = NULL;

		Result = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &Ctx);

		if (Result != SCARD_S_SUCCESS) {
			printf("Failed to establish context, error: %08x\n", Result);
			return 1;
		}

		DWORD Count = SCARD_AUTOALLOCATE;
		LPTSTR Readers = NULL;

		Result = SCardListReaders(Ctx, NULL, (LPTSTR)&Readers, &Count);
		if (Result != SCARD_S_SUCCESS) {
			if (Result == SCARD_E_NO_READERS_AVAILABLE)
				printf("No card readers available.\n");
			else
				printf("Failed to list card readers, error: %08x\n", Result);
			SCardReleaseContext(Ctx);
			return 1;
		}

		LPTSTR R = Readers;
		Count = 0;
		while (*R != 0) {
			if (Index == Count) {
				Reader = _strdup(R);
				break;
			} else if (Index == -1) {
				printf("Reader %d: %s\n", Count, R);
			}
			R += strlen(R) + 1;
			Count++;
		}
		SCardFreeMemory(Ctx, Readers);

		if (Reader == NULL) {
			if (Index != -1)
				printf("Cannot find a reader at index %d\n", Index);
			SCardReleaseContext(Ctx);
			return 1;
		}
		BCAS::Manager::Card *RealCard = new BCAS::Manager::Card;
		RealCard->SetReader(Reader);
		Card = RealCard;
	} else {
		BCAS::Manager::Virtual *Dump = new BCAS::Manager::Virtual;
		Dump->SetReader(VirtualCard);
		Card = Dump;
	}

	BCAS::Keys::RegisterAll();

	Card->Init();
	BCAS::Manager::Ops *Ops = new BCAS::Manager::Ops;
	Ops->SetCard(Card);

	BCAS::Manager::Manager *Mgr = new BCAS::Manager::Manager(Ops);

	bool Quit = false;
	u16 Date;
	SYSTEMTIME Time;

	GetSystemTime(&Time);
	Date = ConvertDateToMJD(Time.wYear, Time.wMonth & 0xff, Time.wDay & 0xff) + 7;

	while (!Quit) {
		bool NewCard = false;
		bool HasCard;
		u16 Expiry;

		HasCard = Card->WaitForEvent(NewCard);
		if (NewCard == true) {
			Mgr->PrintCardInformation(CardType);
			if (CardType == kType_INVALID)
				break;
			PrintMenu();
			continue;
		}
		if (HasCard == false) {
			if (_kbhit()) {
				int Selection = _getch();
				if (Selection == 27) {
					break;
				}
				if (Selection == 0)
					_getch();
			}
			continue;
		}

		int Key = _getch();
		switch (Key) {
		case 27:
				Quit = true;
				break;

		case 0:
			Key = _getch();
			switch (Key) {
			case 59:
				Mgr->DumpMode();
				break;
			case 60:
				Mgr->PrintEntitlements();
				break;
			case 61:
				Mgr->PrintEmail();
				break;
			case 62:
				DateState = (DateState + 1) % 7;
				switch (DateState) {
				case 0:
					Expiry = 7;
					break;
				case 1:
					Expiry = 15;
					break;
				case 2:
					Expiry = 30;
					break;
				case 3:
					Expiry = 90;
					break;
				case 4:
					Expiry = 180;
					break;
				case 5:
					Expiry = 365 * 2;
					break;
				case 6:
					break;
				}
				if (DateState != 6) {
					GetSystemTime(&Time);
					Date = ConvertDateToMJD(Time.wYear, Time.wMonth & 0xff, Time.wDay & 0xff) + Expiry;
				} else {
					Date = 0xffff;
				}
				break;

			default:
				printf("%d\n", Key);
				break;
			}
			break;

		// UpdateTiers
		case 49:
			Mgr->AddEntitlement(BCAS::Keys::KEYSET_WOWOW, Date);
			break;
		case 50:
			Mgr->AddEntitlement(BCAS::Keys::KEYSET_STARCHANNELHD, Date);
			break;
		case 51:
			Mgr->AddEntitlement(BCAS::Keys::KEYSET_E2_110CS, Date);
			break;
		case 52:
			Mgr->AddEntitlement(BCAS::Keys::KEYSET_SAFETYNET, Date);
			break;
		case 53:
			Mgr->AddEntitlement(BCAS::Keys::KEYSET_NHK, Date);
			break;

		// InvalidateTiers
		case 113:
			Mgr->InvalidateEntitlement(BCAS::Keys::KEYSET_WOWOW);
			break;
		case 119:
			Mgr->InvalidateEntitlement(BCAS::Keys::KEYSET_STARCHANNELHD);
			break;
		case 101:
			Mgr->InvalidateEntitlement(BCAS::Keys::KEYSET_E2_110CS);
			break;
		case 114:
			Mgr->InvalidateEntitlement(BCAS::Keys::KEYSET_SAFETYNET);
			break;
		case 116:
			Mgr->InvalidateEntitlement(BCAS::Keys::KEYSET_NHK);
			break;

		// DeleteEmail
		case 97:
			Mgr->DeleteEmail(BCAS::Keys::KEYSET_WOWOW);
			break;
		case 115:
			Mgr->DeleteEmail(BCAS::Keys::KEYSET_STARCHANNELHD);
			break;
		case 100:
			Mgr->DeleteEmail(BCAS::Keys::KEYSET_E2_110CS);
			break;
		case 102:
			Mgr->DeleteEmail(BCAS::Keys::KEYSET_SAFETYNET);
			break;
		case 103:
			Mgr->DeleteEmail(BCAS::Keys::KEYSET_NHK);
			break;
		case 104:
			Mgr->DeleteEmail(BCAS::Keys::KEYSET_EMAIL);
			break;

		// ActivateTrial
		case 122:
			Mgr->ActivateTrial(BCAS::Keys::KEYSET_WOWOW, false, Date);
			Mgr->ActivateTrial(BCAS::Keys::KEYSET_WOWOW, true, Date);
			break;
		case 120:
			Mgr->ActivateTrial(BCAS::Keys::KEYSET_STARCHANNELHD, false, Date);
			Mgr->ActivateTrial(BCAS::Keys::KEYSET_STARCHANNELHD, true, Date);
			break;
		case 99:
			Mgr->ActivateTrial(BCAS::Keys::KEYSET_E2_110CS, false, Date);
			Mgr->ActivateTrial(BCAS::Keys::KEYSET_E2_110CS, true, Date);
			break;
		case 118:
			Mgr->ActivateTrial(BCAS::Keys::KEYSET_SAFETYNET, false, Date);
			Mgr->ActivateTrial(BCAS::Keys::KEYSET_SAFETYNET, true, Date);
			break;
		case 98:
			Mgr->ActivateTrial(BCAS::Keys::KEYSET_NHK, false, Date);
			Mgr->ActivateTrial(BCAS::Keys::KEYSET_NHK, true, Date);
			break;

		default:
			printf("%d\n", Key);
			break;
		}

		if (!Quit)
			PrintMenu();
	}

	return 0;
}
Ejemplo n.º 17
0
void main(int argc, char *argv[]){
	char keypress = START;
	int ch=0;
	int moves=0;
	char mc[10];

	set_graphics(VGA_320X200X256);

	PrintArrow(80, 105);

	do{	//Game loop
		PrintBorder();
		PrintMenu();
		keypress = (char)getch();

		if(keypress == QUIT){
			keypress = START;					//special condition so that it will not exit on Q press at menu
		}else if(keypress == UP || keypress == UP2){
			Erase(80, 120, 15, 15);
			PrintArrow(80, 105);
			ch = 0;
		}else if(keypress == DOWN || keypress == DOWN2){
			Erase(80, 100, 15, 15);
			PrintArrow(80, 125);
			ch = 1;
		}else if(keypress == ENTER || keypress == SPACE){
			switch(ch){
				case 0:
						EraseAll();
						NewGame(board);
						do{	//Inside-the-game loop
							PrintInstructions(180, 30);
							PrintBoard(30, 30);										//* Always prints update version of board at coordinates
							PrintBorder();														//* Always prints border
							sprintf(mc, "%d", moves);
							Erase(55, 175, 150, 15);
							write_text("Moves: ", 55, 175, WHITE, 0);
							write_text(mc, 120, 175, WHITE, 0);
							ShowHint();

							keypress=(char)getch();

							if(keypress == UP || keypress == UP2){
								//Erase(15, 15, 150, 150);
								MovePiece(keypress);
								moves++;
							}else if(keypress == LEFT || keypress == LEFT2){
								//Erase(15, 15, 150, 150);
								MovePiece(keypress);
								moves++;
							}else if(keypress == RIGHT || keypress == RIGHT2){
								//Erase(15, 15, 150, 150);
								MovePiece(keypress);
								moves++;
							}else if(keypress == DOWN || keypress == DOWN2){
								//Erase(15, 15, 150, 150);
								MovePiece(keypress);
								moves++;
							}else if(keypress == QUIT){
								Erase(55, 175, 150, 15);
								write_text("Really exit? Y/N", 55, 175, WHITE, 0);
								do{
									keypress=(char)getch();
									if(keypress == YES){
										moves = 0;
										keypress = QUIT;
										break;
									}else if(keypress == NO){
										keypress = YES;
										Erase(55, 175, 150, 15);
										break;
									}
								}while(1);
							}else{
								Erase(55, 175, 150, 15);
								write_text("Invalid button!", 55, 175, WHITE, 0);
							}
							if(CheckWin(board)){
								EraseAll();
								write_text("You win!", 125, 85, WHITE, 0);
								moves = 0;
								keypress = QUIT;
							}
						}while(keypress != QUIT);
						EraseAll();
						PrintArrow(80, 105);
						keypress = START;
						break;
				case 1: keypress = QUIT;
						break;
				default: break;
			}
		}
		
	}while(keypress != QUIT);
	
	set_graphics(VGA_TEXT80X25X16);
	clrscr();
}
Ejemplo n.º 18
0
void MenuHandler(){
	short nArgs;
	int selectedNode;
	node * network = NULL;
	statistics * stats = NULL;
	char option, buffer[BUFFER_SIZE], arg1[BUFFER_SIZE], garbageDetector[BUFFER_SIZE];
	
	if(executeAtStart){
		network = ReadNetwork(path);
		if(network != NULL){
			stats = GetStatistics(network);
			PrintStatistics(stats);
			PrintExecutionTime();
			FreeEverything(network, stats);
			return;
		}
		else return;
	}
	
	// printing menu
	PrintMenu();
	printf("Please select an option\n");
	
	while(TRUE){
		// gets user commands and arguments
		printf("-> ");
		fgets (buffer, BUFFER_SIZE, stdin);
		nArgs = sscanf(buffer, "%c %s %s", &option, arg1, garbageDetector);
		
		// selects function based on user option
		////////// load
		if(option == 'f' && nArgs == 2){
			if(network != NULL) free(network);
			network = ReadNetwork(arg1);
			if(network != NULL) printf("Network loaded from file\n");
		}
		////////// route
		else if(option == 'r' && nArgs == 2) {
			if(network != NULL){
				selectedNode = atoi(arg1);
				if(selectedNode <= numberOfNodes && selectedNode > 0){
					results = FindRoutesToNode(network, selectedNode);
					PrintRoutingTable(network);
				}
				else printf("Please select valid node\n");
			}
			else printf("Please load a network first\n");
		}
		///////// statistics
		else if(option == 's' && nArgs == 1){
			if(network != NULL){
				stats = GetStatistics(network);
				PrintStatistics(stats);
				PrintExecutionTime();
			}
			else printf("Please load a network first\n");
		} 
		//////// others
		else if(option == 'h' && nArgs == 1) PrintMenu();
		else if(option == 'q' && nArgs == 1){
			FreeEverything(network, stats);
			printf("Project by: Diogo Salgueiro 72777 and Ricardo Ferro 72870\n");
			printf("Goodbye!\n");
			return;
		}
		else printf("Invalid command\n");
		
	}
};
Ejemplo n.º 19
0
//-----------------------------------------------------------------------------
// Function:    PrintMenu
// Purpose:     Prints a menu, retrieves the user selection, calls the handler, loops.
//              Returns when "Quit" is selected from the menu
// Parameters:  None
//
void RunMenu()
{
    HRESULT hr;
    WCHAR wzBuff[INPUT_BUFSIZE];
    int nInput;

    // Continuously show the menu to user and respond to their request
    //
    while (TRUE)
    {
        PrintMenu();

        fflush(stdin);
        hr = StringCbGets(wzBuff, sizeof(wzBuff));

        if (FAILED(hr))
        {
            wprintf (L"Invalid input, expected a number between 1 and 25 or Q to quit.\n");
            continue;
        }

        if  ((wcsncmp(wzBuff, L"Q", INPUT_BUFSIZE) == 0) || (wcsncmp(wzBuff, L"q", INPUT_BUFSIZE) == 0))
        {
            // break out of while loop.
            //
            break;
        }

        // since wtoi can't distinguish between 0 and an error, note that valid values start at 1, not 0    
        nInput = _wtoi(wzBuff);
        if (nInput < 1  || nInput > 25)
        {
            printf ("Invalid input, expected a number between 1 and 25 or Q to quit.\n");
            continue;
        }

        switch (nInput)
        {
            case 1:
                SignIn();
                break;

            case 2:
                SignOut();
                break;

            case 3:
                SignInOptions();
                break;

            case 4:
                SetEndpointName();
                break;

            case 5:
                GetEndpointName();
                break;

            case 6:
                DisplayEndpointInformation();
                break;

            case 7:
                EnumeratePeopleNearMe();
                break;

            case 8:
                AddEndpointAsContact();
                break;

            case 9:
                ExportContact();
                break;

            case 10:
                ParseContact();
                break;
            
            case 11:
                ImportContact();
                break;
            
            case 12:
                DeleteContact();
                break;

            case 13:
                EnumContacts();
                break;
            
            case 14:
                SetWatching();
                break;

            case 15:
                SetWatchPermissions();
                break;

            case 16:
                GetPresenceInformation();
                break;
                    
            case 17:
                SetPresenceInformation();
                break;

            case 18:
                SubscribeEndpointData();
                break;

            case 19:
                UnsubscribeEndpointData();
                break;

            case 20:
                PublishEndpointObject();
                break;

            case 21:
                DeleteEndpointObject();
                break;
                                    
            case 22:
                RegisterApplication();
                break;

            case 23:
                UnregisterApplication();
                break;

            case 24:
                DisplayApplicationRegistrations();
                break;

            case 25:
                SendInvite();
                break;

            default:
                wprintf(L"Invalid selection.\n");
                break;

        }

        //Pause so that our output doesn't scroll
        //off the screen before the user gets a change to
        //read it.
         wprintf(L"\n\nPress <ENTER> to continue.\n");
        fflush(stdin);
        (void)StringCbGets(wzBuff, sizeof(wzBuff));
    }
}
Ejemplo n.º 20
0
void loop()
{
    char buffer[5] = {0};
    size_t len;
    if (Serial.available() > 0)
    {
        GetData(buffer, sizeof(buffer), &len);
        if (0 >= len)
        {
            Serial.println("i/p err");
            return;
        }
        switch (toupper(buffer[0]))
        {
            case 'M': // menu
                PrintMenu();
                break;

            case 'Q': // quit
                Serial.println("quit");
                return;

            case 'I': // Initialize interface
                Initialize();
                break;

            case 'S': // start listening server
                StartListeningServer();
                break;

            case 'D': // start discovery server
                StartDiscoveryServer();
                break;

            case 'R': // send request
                SendRequest();
                break;

            case 'E': //send request to all
                SendRequestAll();
                break;
            case 'B': // send notification
                SendNotification();
                break;
            case 'G': // Get network info
                GetNetworkInfo();
                break;

            case 'N': // select network
                SelectNetwork();
                break;

            case 'X': // unselect network
                UnselectNetwork();
                break;

            case 'H': // handle request response
                HandleRequestResponse();
                break;

            case 'T': // handle request response
                Terminate();
                break;

            default:
                Serial.println("wrong menu");
                break;
        }
    }
    //1:Add check for startserver before calling below api
    if (g_isLeSelected)
    {
        HandleRequestResponse();
    }
    delay(1000);
}
Ejemplo n.º 21
0
//-------------------------------------------------------------
int main(int argc,char *argv[])
{

    // diagnostic mode goes here
#ifdef diag

        printf("Diagnostic mode\n");

        try
            {

        CCircuit *Cir = new CCircuit();
        Cir->LoadAMSModel("G:\\programy\\multi_dim\\gc_analyser\\bin\\example_2d.vhdla");
        Cir->ListElements();
        Cir->ExportToMatlab("G:\\programy\\multi_dim\\gc_analyser\\bin\\outcome2d.m");
        Cir->Solve("G:\\programy\\multi_dim\\gc_analyser\\bin\\outcome2d.SN");
        Cir->ListBlocks(stdout);
        delete Cir;
    }
        catch (gcError *e)
          {
            fprintf(stdout,"%s\n",e->msg);
           }
          catch (...)
          {
            fprintf(stdout,"An unhandled exception occured\n");
          }


	return 0;
#endif
	fprintf(stdout,"\nGC analyser version: %d\n",VERSION_NR);
	fprintf(stdout,"\n MULTI DIMENSIONAL \n");
	fprintf(stdout,"-----------------------------\n");    	
	fflush(stdout);
	
	inputfile[0] = 0x00;
	outputfile[0] = 0x00;
	paramfile[0] = 0x00;

	switch (argc)
	{
		case 1: PrintMenu(); break;

		case 3: 
		{
			if (strcmp(argv[1],"SN") == 0) 
			{
				strncpy(inputfile,argv[2],strlen(argv[2]));
				option = 1;
			}		

            if (strcmp(argv[1],"MAT") == 0)
            {
				strncpy(inputfile,argv[2],strlen(argv[2]));
                option = 2;
            }

			break;
		}
		/*
		case 4:
		{
			if (strcmp(argv[1],"AMS") == 0) 
			{
				strncpy(inputfile,argv[2],strlen(argv[2]));
				strncpy(paramfile,argv[3],strlen(argv[3]));
				option = 3;
				break;
			}

            if (strcmp(argv[1],"SP") == 0)
            {
                strncpy(inputfile,argv[2],strlen(argv[2]));
                strncpy(paramfile,argv[3],strlen(argv[3]));
                option = 4;
                break;
            }
		
		}
		*/
		default: 
		{
			fprintf(stdout,"Invalid syntax\n");
			fflush(stdout);
			option = 0;
			break;
		}
	} // end of switch 
	
	try
	{
		CCircuit *Cir = new CCircuit();
                if (option)
                {

                    if(Cir->LoadAMSModel(inputfile))
                    {
                        fprintf(stdout,"An error occured during block file analysis. Program will terminate.");
                        fflush(stdout);
                        delete Cir;
                        exit(2);
                    }
                }

	switch(option)
	{
		case 0: // do nothing
		{
			break;
		}
		case 1: // compute SN solution
		{
				Cir->ListElements();
				outputfile[0] = 0x00;
				gc_strcpy(outputfile,MAX_FILE_PATH,inputfile);	
				if (strlen(outputfile) > 4) outputfile[strlen(outputfile)-4] = 0x00;
				gc_strncat(outputfile,MAX_FILE_PATH,(char *)".sn",4);
                time_t seconds;
                seconds = time(NULL);
				Cir->Solve(outputfile);
				Cir->ListBlocks(stdout);
                fprintf(stdout,"Finished in %ld seconds\n",time(NULL)-seconds);
			break;
		}
		case 2: // export to Matlab script 
		{
			outputfile[0] = 0x00;
			gc_strcpy(outputfile,200,inputfile);	
			if (strlen(outputfile) > 4) outputfile[strlen(outputfile)-4] = 0x00;
			gc_strncat(outputfile,200,(char *)".m",3);			
			fprintf(stdout,"\nExporting to Matlab file: %s\n",outputfile);
			Cir->ListElements();			
			Cir->ExportToMatlab(outputfile);
			break;
		}
		/*
		case 3: // export to VHDL-AMS
		{
			if (strlen(paramfile) < 1)
			{
				fprintf(stdout,"Enter parameter file name:");
				fflush(stdout);
				#ifdef UNIX			
					scanf("%s",paramfile);
				#else
					scanf_s("%s",paramfile);			
				#endif
			}

			if (!gc_FileExists(paramfile))
			{
				fprintf(stdout,"Unable to access file %s",paramfile);
				return -1;
			}

			outputfile[0] = 0x00;
			gc_strcpy(outputfile,MAX_FILE_PATH,inputfile);	
			if (strlen(outputfile) > 4) outputfile[strlen(outputfile)-4] = 0x00;
			gc_strncat(outputfile,MAX_FILE_PATH,(char *)".vhdla",7);			
			fprintf(stdout,"\nExporting to VHDL-AMS file: %s\n",outputfile);
			fflush(stdout);
                        Cir->SortElements();
                        Cir->LoadParams(paramfile);                        
                        Cir->ExportToVHDLAMS(outputfile);
                        break;
		}

                case 4:  // export to HSpice model
                {

                        if (!gc_FileExists(paramfile))
                        {
                                fprintf(stdout,"Unable to access file %s",paramfile);
                                return -1;
                        }

                        outputfile[0] = 0x00;

                        gc_strcpy(outputfile,MAX_FILE_PATH,inputfile);
                        if (strlen(outputfile) > 4) outputfile[strlen(outputfile)-4] = 0x00;
                        gc_strncat(outputfile,MAX_FILE_PATH,(char *)".sp",4);

                        fprintf(stdout,"\nExporting to HSpice file: %s\n",outputfile);

                        fflush(stdout);

                        Cir->SortElements();
                        Cir->LoadParams(paramfile);                        
                        Cir->ExportToHSpice(outputfile);
                        break;
                }
		*/
		default:
		{
			fprintf(stdout,"Unknown option\n");
			fflush(stdout);
			break;
		}

	}// end for switch option 
	
        delete Cir;

	}
        catch (gcError *e)
           {
            fprintf(stdout,"%s\n",e->msg);
           }
          catch (...)
          {
            fprintf(stdout,"An unhandled exception occured\n");
          }


	return RESULT_OK;
}
Ejemplo n.º 22
0
int main(int argc, char *argv[])
{
   NODEPTR headBone = NULL, tailBone = NULL;
   NODEPTR headUser = NULL, tailUser = NULL;
   NODEPTR headSystem = NULL, tailSystem = NULL;
   NODEPTR headTrain = NULL, tailTrain = NULL; 
   NODEPTR curr = NULL, choice = NULL;
   LIST *boneyard, *user, *system, *train;
   FILE *ifp;
   int numDom, menu, turn = CONTINUE, status;
   int player = CONTINUE;
   
   /* check for correct number of arguments */
   if(argc != 3)
   {
      /* print message to standard error */
      fprintf(stderr, "incorrect number of arguments.\n");
      fprintf(stderr, "enter a.out, name of file, and number of starting\n");
      fprintf(stderr, "dominoes.\n");

      exit(-1);
   }

   int handSize = atoi(argv[2]);
   char *fileName = argv[1];
   
   ifp = fopen(fileName, "r");

   /* check if the file opened correctly */
   if(ifp  == NULL)
   {
      fprintf(stderr, "%s is incorrect\n", fileName);

      exit (-2);
   }

   /* makes sure num dominoes is positive */
   if(atoi(argv[2]) <= 0)
   {
      /* print message to standard error */
      fprintf(stderr, "number of dominoes must be positive\n");

      exit(-3);
   }

   /* gather necessary memory for the LIST structs */
   boneyard = (LIST *) malloc(sizeof(LIST));

   if(boneyard == NULL)
   {
      fprintf(stderr, "Out of Memory - boneyard\n");

      exit(-6);
   }

   user = (LIST *) malloc(sizeof(LIST));

   if(user == NULL)
   {
      fprintf(stderr, "Out of Memory - user\n");

      exit(-7);
   }

   system   = (LIST *) malloc(sizeof(LIST));

   if(system == NULL)
   {
      fprintf(stderr, "Out of Memory - system\n");
   
      exit(-8);
   }

   train    = (LIST *) malloc(sizeof(LIST));

   if(train == NULL)
   {
      fprintf(stderr, "Out of Memory - train\n");
      
      exit(-9);
   }

   /* point the head and tail to the list struct */
   boneyard->head = headBone;
   boneyard->tail = tailBone;
   boneyard->nrNodes = 0; 
   
   user->head = headUser;
   user->tail = tailUser;
   headUser = user->head;
   tailUser = user->head;
   user->nrNodes = 0;

   system->head = headSystem;
   system->tail = tailSystem;
   system->nrNodes = 0;

   train->head = headTrain;
   train->tail = tailTrain;
   train->nrNodes = 0;
      
   /* Creates the boneyard which holds all dominoes in the beginning */
   numDom = CreateBoneyard(boneyard, ifp);
  
   /* calculates max hand size for game of dominoes */
   if(handSize >= (numDom - 1) / 2)
   {
      fprintf(stderr, "%d is too large for number of dominoes\n", handSize);
      fprintf(stderr, "largest number of dominoes is %d\n", (numDom - 1) / 2);

      exit(-4);
   }

   /* prints greeting to the user */
   PrintGreeting();
   
   /* prints program instructions */
   PrintInstructions();
   
   /* gives the user a linked list of dominoes */
   DealUser(boneyard, user, handSize);
   
   /* gives the system a linked list of dominoes */
   DealSystem(boneyard, system, handSize);
   /* takes the first node from the boneyard to be used as the train */
   curr = boneyard->head;
   boneyard->head = boneyard->head->next;
   InsertLeft(train, curr);
  
   /* prints the menu for user interface */
   PrintMenu();

 
   /* Game Loop */  
   while(player == CONTINUE)
   {
      /* player turn loop */
      while(turn != OVER)
      {
	 printf("The train (%d): ", train->nrNodes);
	 PrintList(train->head);
	 printf("\n\n");
	 
	 printf("Your turn...(enter six for menu)\n");	 
	 menu = GetValidInt(); /* int used for menu nav */
	 
	 switch(menu)
	 {
	    case PRINTDOMINO:
	       printf("Your Dominoes: ");
	       PrintList(user->head);
	       printf("\n");
	       turn = CONTINUE; /* print domino doesnt use up your turn */
	       break;
	    case INSERTLEFT:
	       /* selects a domino to play */
	       choice = SelectDominoLeft(train, user);
	       if(choice != NULL)
	       {
		  InsertLeft(train, choice);
		  turn = OVER;
	       } else {
		  turn = CONTINUE; /* if can't play, turn isnt lost */
	       }
	       break;
	    case INSERTRIGHT:
	       /* selects a domino to play */
	       choice = SelectDominoRight(train, user);
	       if(choice != NULL)
	       {
		  choice->next = NULL;
		  InsertRight(train, choice);
		 
		  turn = OVER;
	       } else {
		  turn = CONTINUE;
	       }
	       break;
	    case DRAWDOMINO:
	       /* checks if boneyard is empty */
	       if(IsEmpty(boneyard->head) == FALSE)
	       {
		  status = CheckDomino(train, user, USER);
		  if(status == TRUE)
		  {
		     DrawDomino(user, boneyard);
		     turn = OVER;
		  } else {
		     printf("\nYou had a domino to play\n\n");
		     turn = CONTINUE;
		  }
		  
	       } else {
		  printf("Boneyard is empty\n");
	       }
	       break;
	    case PASSTURN:
	       /* checks if you can play a domino and for empty boneyard */
	       if(CheckDomino(train, user, USER) == TRUE && 
		  IsEmpty(boneyard->head) == TRUE)
	       {
		  printf("\nuser passes his turn\n");
		  turn = OVER;
	       } else 
		  if(IsEmpty(boneyard->head) == FALSE)
		  {
		     printf("\nCant pass, you can draw from the boneyard\n\n");
		     turn = CONTINUE;
		  } else {
		     printf("Can't pass you still have a domino to play");
		  }
	       break;
	    case PRINTMENU:
	       PrintMenu();
	       turn = CONTINUE; 
	       break;
	    case QUIT:
	       turn = OVER;
	       player = QUIT;
	       break;
	    default:
	       printf("Dios Mios!!, esta numero no existan!!!\n");
	       break;
	 }
	 /* checks if player ran out of dominoes */
	 if(IsEmpty(user->head) == TRUE)
	 {
	    player = WIN;
	 } 
      }
      
      turn = CONTINUE;
      
      printf("The Train: ");
      PrintList(train->head);
      printf("\n");

      /* computers turn */
      if(player == CONTINUE)
      {
	 printf("System's Hand: ");
	 PrintList(system->head);
	 printf("\n");
	 printf("\nSystem's turn...");

	 /* tries to play a domino for the system */
	 if(CheckDomino(train, system, SYSTEM) == FALSE)
	 {
	    system->nrNodes--;
	    printf("System has %d dominoes left\n\n", system->nrNodes);
	 } else 
	    if(IsEmpty(boneyard->head) == FALSE) /* tries to draw domino */
	    {
	       DrawDomino(system, boneyard);
	       printf("System drew a domino from the boneyard\n");
	       printf("System has %d dominoes left\n\n", system->nrNodes);
	    } else {
	       /* last passes if can do neither of the above */
	       printf("System has passed this turn\n");
	       printf("System has %d dominoes left\n\n", system->nrNodes);
	    }
	 
	 /* checks for empty hand */
	 if(IsEmpty(system->head) == TRUE)
	 {
	    player = LOSE;
	 }
	 
      }
   }

   if(player == WIN)
   {
      printf("Player Wins!\n");
      /* destroys all linked lists */
      DestroyList(user);
      DestroyList(boneyard);
      DestroyList(system);
      DestroyList(train);
   } else 
      if(player == LOSE)
      {
	 /* destroys all linked lists */
	 printf("System Wins! You Lose!");
	 DestroyList(user);
	 DestroyList(boneyard);
	 DestroyList(system);
	 DestroyList(train);
      } else {
	 /* destroys all linked lists */
	 printf("Hope you had a good game, Play again soon!\n");
	 DestroyList(user);
         DestroyList(boneyard);
         DestroyList(system);
         DestroyList(train);
      }

   return 0;
}
Ejemplo n.º 23
0
void ProcessMenu( void )
{

    BYTE        c;
    BYTE        i;

    // Get the key value.
    c = ConsoleGet();
    ConsolePut( c );
    switch (c)
    {
        case '1':
            ConsolePutROMString((ROM char * const)"\r\n1=ENABLE_ALL 2=ENABLE PREV 3=ENABLE SCAN 4=DISABLE: ");
            while( !ConsoleIsGetReady());
        	c = ConsoleGet();
        	ConsolePut(c);
        	switch(c)
        	{
        		case '1':
        		    MiApp_ConnectionMode(ENABLE_ALL_CONN);
        		    break;
        		
        		case '2':
        		    MiApp_ConnectionMode(ENABLE_PREV_CONN);
        		    break;
        		    
        		case '3':
        		    MiApp_ConnectionMode(ENABLE_ACTIVE_SCAN_RSP);
        		    break;
        		    
        		case '4':
        		    MiApp_ConnectionMode(DISABLE_ALL_CONN);
        		    break;
        		
        	    default:
        	        break;	
            }
            break;
            
        case '2':
            Printf("\r\nFamily Tree: ");
            for(i = 0; i < NUM_COORDINATOR; i++)
            {
                PrintChar(FamilyTree[i]);
                Printf(" ");
            }
            break;
            
        case '3':
            Printf("\r\nMy Routing Table: ");
            for(i = 0; i < NUM_COORDINATOR/8; i++)
            {
                PrintChar(RoutingTable[i]);
            }
            Printf("\r\nNeighbor Routing Table: ");
            for(i = 0; i < NUM_COORDINATOR; i++)
            {
                BYTE j;
                for(j = 0; j < NUM_COORDINATOR/8; j++)
                {
                    PrintChar(NeighborRoutingTable[i][j]);
                }
                Printf(" ");
            }
            break;
            
        case '4':
            {   
                WORD_VAL tempShortAddr;
                Printf("\r\n1=Broadcast 2=Unicast Connection 3=Unicast Addr: ");
                while( !ConsoleIsGetReady());
            	c = ConsoleGet();
            	ConsolePut(c);
            	
    	        MiApp_FlushTx();
    	        MiApp_WriteData('T');
    	        MiApp_WriteData('e');
    	        MiApp_WriteData('s');
    	        MiApp_WriteData('t');
    	        MiApp_WriteData(0x0D);
    	        MiApp_WriteData(0x0A);
        	    switch(c)
        	    {
            	    case '1':
            	        MiApp_BroadcastPacket(FALSE);
            	        TxNum++;
            	        break;
            	        
            	    case '2':
            	        Printf("\r\nConnection Index: ");
            	        while( !ConsoleIsGetReady());
            	        c = GetHexDigit();
                        MiApp_UnicastConnection(c, FALSE);
                        TxNum++;
                        break;
                        
                    case '3':
                        Printf("\r\n1=Long Address 2=Short Address: ");
                        while( !ConsoleIsGetReady());
                    	c = ConsoleGet();
                    	ConsolePut(c);
                    	switch(c)
                    	{
                        	case '1':
                        	    Printf("\r\nDestination Long Address: ");
                        	    for(i = 0; i < MY_ADDRESS_LENGTH; i++)
                        	    {
                            	    tempLongAddress[MY_ADDRESS_LENGTH-1-i] = GetMACByte();
                            	}
                            	MiApp_UnicastAddress(tempLongAddress, TRUE, FALSE);
                            	TxNum++;
                            	break;
                        	
                        	case '2':
                        	    Printf("\r\nDestination Short Address: ");
                        	    tempLongAddress[1] = GetMACByte();
                        	    tempLongAddress[0] = GetMACByte();
                        	    MiApp_UnicastAddress(tempLongAddress, FALSE, FALSE);
                        	    TxNum++;
                        	    break;
                        	
                        	default:
                        	    break;
                        }
                        break;
                        
                    default:
                        break;
            	}
            }
            LCDTRXCount(TxNum, RxNum);
            break;
            
        case '5':
            {
                Printf("\r\nMSB of the Coordinator: ");
                i = GetMACByte();
                Printf("\r\nSet MSB of this Node's Parent: ");
                FamilyTree[i] = GetMACByte();
            }
            break;
            
        case '6':
            {
                Printf("\r\nSet my Routing Table: ");
                for(i = 0; i < NUM_COORDINATOR/8; i++)
                {
                    RoutingTable[i] = GetMACByte();
                    Printf(" ");
                }
            }
            break;
            
        case '7':
            {
                BYTE j;
                
                Printf("\r\nNode Number: ");
                i = GetMACByte();
                Printf("\r\nContent of Neighbor Routing Table: ");
                for(j = 0; j < NUM_COORDINATOR/8; j++)
                {
                    NeighborRoutingTable[i][j] = GetMACByte();
                    Printf(" ");
                }
            }
            break;
        
        case '8':
            {
                MiApp_InitChannelHopping(0xFFFFFFFF);
            }
            break;    
        
        
        case '9':
            {
                Printf("\r\nSocket: ");
                PrintChar(MiApp_EstablishConnection(0xFF, CONN_MODE_INDIRECT));
            }
            break;
        
        
        case 'z':
        case 'Z':
            {
                DumpConnection(0xFF);
            }    
        
        default:
            break;
    }
    PrintMenu();
}