Beispiel #1
0
void printVersion()
{
	if (cfg.version)
	{
		printAbout();
		exit(EXIT_SUCCESS);
	}
}
Beispiel #2
0
void comandos(tTabla tabla, char comando){
    switch (comando) {
        case 'b':
            backupTable(tabla);
            break;
        case 'v':
            setTable(tabla);
            break;
        case 'a':
            printHelp();
            break;
        case 'c':
            printAbout();
            break;
    }
}
Beispiel #3
0
static void inputCommand(void)
{
	char command[20];

	printf("Type 'help' to see help\n\n");

	while (true) {
		fgets(command, 20, stdin);

		if (command[strlen(command) - 1] == '\n') {
			command[strlen(command) - 1] = '\0';
		}

		if (_stricmp(command, "about") == 0) {
			printAbout();
		} else if (_stricmp(command, "help") == 0) {
			printHelp();
		} else if (_stricmp(command, "log on") == 0) {
			g_RPCServer.SetLogOn(true);
		} else if (_stricmp(command, "log off") == 0) {
			g_RPCServer.SetLogOn(false);
		} else if (_stricmp(command, "list") == 0) {
			printList();
		} else if (_stricmp(command, "quit") == 0) {
			if (g_MountProg.GetMountNumber() == 0) {
				break;
			} else {
				printConfirmQuit();
				fgets(command, 20, stdin);

				if (command[0] == 'y' || command[0] == 'Y') {
					break;
				}
			}
		} else if (_stricmp(command, "refresh") == 0) {
			g_MountProg.Refresh();
		} else if (_stricmp(command, "reset") == 0) {
			g_RPCServer.Set(PROG_NFS, NULL);
		} else if (strcmp(command, "") != 0) {
			printf("Unknown command: '%s'\n", command);
			printf("Type 'help' to see help\n");
		}
	}
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    std::vector<std::vector<std::string>> pPaths;
    char *pPath = NULL;
	bool pathFile = false;

    WSADATA wsaData;

    printAbout();

    if (argc < 2) {
        pPath = strrchr(argv[0], '\\');
        pPath = pPath == NULL ? argv[0] : pPath + 1;
        printUsage(pPath);
        return 1;
    }
  
    g_nUID = g_nGID = 0;
    g_bLogOn = true;
    g_sFileName = NULL;

    for (int i = 1; i < argc; i++) {//parse parameters
        if (_stricmp(argv[i], "-id") == 0) {
            g_nUID = atoi(argv[++i]);
            g_nGID = atoi(argv[++i]);
        } else if (_stricmp(argv[i], "-log") == 0) {
            g_bLogOn = _stricmp(argv[++i], "off") != 0;           
        } else if (_stricmp(argv[i], "-pathFile") == 0) {
            g_sFileName = argv[++i];

			if (g_MountProg.SetPathFile(g_sFileName) == false) {
                printf("Can't open file %s.\n", g_sFileName);
                return 1;
			} else {
				g_MountProg.Refresh();
				pathFile = true;
			}
        } else if (i == argc - 2) {
            pPath = argv[argc - 2];  //path is before the last parameter

            char *pCurPathAlias = argv[argc - 1]; //path alias is the last parameter

            if (pPath != NULL || pCurPathAlias != NULL) {
                std::vector<std::string> pCurPaths;
                pCurPaths.push_back(std::string(pPath));
                pCurPaths.push_back(std::string(pCurPathAlias));
                pPaths.push_back(pCurPaths);
            }

            break;
        } else if (i == argc - 1) {
            char *pPath = argv[argc - 1];  //path is the last parameter

            if (pPath != NULL) {
                char curPathAlias[MAXPATHLEN];
                strcpy_s(curPathAlias, pPath);
                char *pCurPathAlias = curPathAlias;

                std::vector<std::string> pCurPaths;
                pCurPaths.push_back(std::string(pPath));
                pCurPaths.push_back(std::string(pCurPathAlias));
                pPaths.push_back(pCurPaths);
            }

            break;
        }
    }

    HWND console = GetConsoleWindow();

    if (g_bLogOn == false && IsWindow(console)) {
        ShowWindow(console, SW_HIDE); // hides the window
    }

	if (pPaths.size() <= 0 && !pathFile) {
        printf("No paths to mount\n");
        return 1;
    }

    WSAStartup(0x0101, &wsaData);
    start(pPaths);
    WSACleanup();

    return 0;
}
Beispiel #5
0
int main(int argc, char **argv) {
	if (argc == 1) {
		printHelp(argv, false);
		return 0;
	}
	
	std::string command = argv[1];
	if (command == "-dv" || command == "--deltav") {
		if (argc >= 5) {
			DeltaVCalculator dvCalc;
			float result = dvCalc.Calculate (argc, argv);
			printf("%f\n", result);
			return 0;
		}
		else {
			printf("Error: invalid syntax\n");
			printf("Δv syntax: -dv  [isp] [total mass] [fuel mass 1] [fuel mass 2] [fuel mass 3]...\n");
			return 0;
		}
	}
	if (command == "-twr" || command == "--thrust-to-weight") {
		if (argc >= 4) {
			TWRCalculator twrCalc;
			float result = twrCalc.Calculate (argc, argv);
			printf("%f\n", result);
			return 0;
		}
		else {
			printf("Error: invalid syntax\n");
			printf("TWR syntax: -twr [total mass] [thrust 1] [thrust 2] [thrust 3]...\n");
			return 0;
		}
	}
	if (command == "-isp" || command == "--specific-impulse") {
		if (argc >= 3 && ((argc-1) % 2) != 0) {
			IspCalculator ispCalc;
			float result = ispCalc.Calculate (argc, argv);
			printf("%f\n", result);
			return 0;
		}
		else {
			printf("Error: invalid syntax\n");
			printf("ISP syntax: -isp [thrust 1] [isp 1] [thrust 2] [isp 2]...\n");
			return 0;
		}
	}
	if (command == "-tdv" || command == "--true-deltav") {
		if (argc >= 6) {
			TrueDeltaVCalculator tdvCalc;
			float result = tdvCalc.Calculate (argc, argv);
			printf("%f\n", result);
			return 0;
		}
		else {
			printf("Error: invalid syntax\n");
			printf("True Δv syntax: -tdv [atmIsp] [vacIsp] [escapeDv] [total mass] [fuel mass 1] [fuel mass 2]...\n");
			return 0;
		}
	}
	if (command == "-cpu" || command == "--convert-propellant-units") {
		if (argc >= 3) {
			float result = 0;
			for (int i = 2; i < argc; i++) {
				result += atof(argv[i]) / 200;
			}
			printf("%f\n", result);
			return 0;
		}
		else {
			printf("Error: invalid syntax\n");
			printf("Conversion syntax: -cpu [propellant units]\n");
			return 0;
		}
	}
	if (command == "-fm" || command == "--fuel-mass") {
		if (argc == 8) {
			FuelMassCalculator fmCalc;
			float result = fmCalc.Calculate (argc, argv);
			printf("%f\n", result);
			return 0;
		}
		else {
			printf("Error: invalid syntax\n");
			printf("Fuel mass syntax: -fm [Δv] [isp] [numEngines] [massEngine] [massPayload] [fullEmptyRatio]\n");
			return 0;
		}
	}
	if (command == "-ts" || command == "--time-split") {
		if (argc == 4) {
			if (atoi(argv[3]) >= 60) {
				printf("Error: invalid number of seconds\n");
				return 0;
			}
			double wseconds = ((atof(argv[2])*60) + atof(argv[3])) / 120;
			double minutes = 0;
			double seconds = modf (wseconds, &minutes) * 60;
			
			printf("%.0fm%.1fs\n", minutes, seconds);
			return 0;
		}
		else if (argc == 3) {
			if (atoi(argv[2]) >= 60) {
				printf("Error: invalid number of seconds\n");
				return 0;
			}
			double seconds = atof(argv[2]) / 2;
			printf("%.1fs\n", seconds);
			return 0;
		}
		else {
			printf("Error: invalid syntax\n");
			printf("Time split syntax: -ts [min] [s]\n");
			return 0;
		}
	}
	if (command == "-h" || command == "--help") {
		printHelp(argv, true);
		return 0;
	}
	if (command == "-a" || command == "--about") {
		printAbout(argv, version);
		return 0;
	}
	
	printf("Error: invalid option specified\n");
	return 0;
}
Beispiel #6
0
int main(int argc, char *argv[])
{
	char *pPath;
	char m_pPathAlias[MAXPATHLEN];
	char *pPathAlias;
	WSADATA wsaData;
	
	printAbout();
	if (argc < 2)
	{
		pPath = strrchr(argv[0], '\\');
		pPath = pPath == NULL? argv[0] : pPath + 1;
		printUsage(pPath);
		return 1;
	}

	/*if (argc == 2) {
		pPath = argv[argc - 1];  //path is the last parameter
		if (*pPath == '"')
			++pPath;  //remove head "
		if (*(pPath + strlen(pPath) - 1) == '"')
			*(pPath + strlen(pPath) - 1) = '\0';  //remove tail "
		if (pPath[0] == '.' && pPath[1] == '\0') {
			static char path1[MAXPATHLEN];
			getcwd(path1, MAXPATHLEN);
			pPath = path1;
		}
		else if (pPath[1] != ':' || !((pPath[0] >= 'A' && pPath[0] <= 'Z') || (pPath[0] >= 'a' && pPath[0] <= 'z')))  //check path format
		{
			printf("Path format is incorrect.\n");
			printf("Please use a full path such as C:\\work");
			return 1;
		}
		strncpy(m_pPathAlias, pPath, sizeof(m_pPathAlias) - 1);
		m_pPathAlias[1] = m_pPathAlias[0];  //transform mount path to Windows format
		m_pPathAlias[0] = '/';
		for (size_t i = 2; i < strlen(pPath); i++)
			if (m_pPathAlias[i] == '\\')
				m_pPathAlias[i] = '/';
		m_pPathAlias[strlen(pPath)] = '\0';
		pPathAlias = m_pPathAlias;
	}
	else if (argc == 3) {
		pPath = argv[argc - 2];  //path is before the last parameter
		if (*pPath == '"')
			++pPath;  //remove head "
		if (*(pPath + strlen(pPath) - 1) == '"')
			*(pPath + strlen(pPath) - 1) = '\0';  //remove tail "
		if (pPath[0] == '.' && pPath[1] == '\0') {
			static char path1[MAXPATHLEN];
			getcwd(path1, MAXPATHLEN);
			pPath = path1;
		}
		else if (pPath[1] != ':' || !((pPath[0] >= 'A' && pPath[0] <= 'Z') || (pPath[0] >= 'a' && pPath[0] <= 'z')))  //check path format
		{
			printf("Path format is incorrect.\n");
			printf("Please use a full path such as C:\\work");
			return 1;
		}

		pPathAlias = argv[argc - 1]; //path alias is the last parameter
		if (*pPathAlias == '"')
			++pPathAlias;  //remove head "
		if (*(pPathAlias + strlen(pPathAlias) - 1) == '"')
			*(pPathAlias + strlen(pPathAlias) - 1) = '\0';  //remove tail "
		if (pPathAlias[0] != '/')  //check path alias format
		{
			printf("Path alias format is incorrect.\n");
			printf("Please use a path like /exports\n");
			return 1;
		}
	}*/

	g_nUID = g_nGID = 0;
	g_bLogOn = true;
	for (int i = 1; i < argc; i++)  //parse parameters
	{
		if (stricmp(argv[i], "-id") == 0)
		{
			g_nUID = atoi(argv[++i]);
			g_nGID = atoi(argv[++i]);
		}
		else if (stricmp(argv[i], "-log") == 0)
		{
			g_bLogOn = stricmp(argv[++i], "off") != 0;
		}
		else if (i==argc - 2) {
			pPath = argv[argc - 2];  //path is before the last parameter
			if (*pPath == '"')
				++pPath;  //remove head "
			if (*(pPath + strlen(pPath) - 1) == '"')
				*(pPath + strlen(pPath) - 1) = '\0';  //remove tail "
			if (pPath[0] == '.' && pPath[1] == '\0') {
				static char path1[MAXPATHLEN];
				getcwd(path1, MAXPATHLEN);
				pPath = path1;
			}
			else if (pPath[1] != ':' || !((pPath[0] >= 'A' && pPath[0] <= 'Z') || (pPath[0] >= 'a' && pPath[0] <= 'z')))  //check path format
			{
				printf("Path format is incorrect.\n");
				printf("Please use a full path such as C:\\work");
				return 1;
			}

			pPathAlias = argv[argc - 1]; //path alias is the last parameter
			if (*pPathAlias == '"')
				++pPathAlias;  //remove head "
			if (*(pPathAlias + strlen(pPathAlias) - 1) == '"')
				*(pPathAlias + strlen(pPathAlias) - 1) = '\0';  //remove tail "
			if (pPathAlias[0] != '/')  //check path alias format
			{
				printf("Path alias format is incorrect.\n");
				printf("Please use a path like /exports\n");
				return 1;
			}
			break;
		}
		else if (i==argc - 1) {
			pPath = argv[argc - 1];  //path is the last parameter
			if (*pPath == '"')
				++pPath;  //remove head "
			if (*(pPath + strlen(pPath) - 1) == '"')
				*(pPath + strlen(pPath) - 1) = '\0';  //remove tail "
			if (pPath[0] == '.' && pPath[1] == '\0') {
				static char path1[MAXPATHLEN];
				getcwd(path1, MAXPATHLEN);
				pPath = path1;
			}
			else if (pPath[1] != ':' || !((pPath[0] >= 'A' && pPath[0] <= 'Z') || (pPath[0] >= 'a' && pPath[0] <= 'z')))  //check path format
			{
				printf("Path format is incorrect.\n");
				printf("Please use a full path such as C:\\work");
				return 1;
			}
			strncpy(m_pPathAlias, pPath, sizeof(m_pPathAlias) - 1);
			m_pPathAlias[1] = m_pPathAlias[0];  //transform mount path to Windows format
			m_pPathAlias[0] = '/';
			for (size_t i = 2; i < strlen(pPath); i++)
				if (m_pPathAlias[i] == '\\')
					m_pPathAlias[i] = '/';
			m_pPathAlias[strlen(pPath)] = '\0';
			pPathAlias = m_pPathAlias;
			break;
		}
	}

	WSAStartup(0x0101, &wsaData);
	printf("Starting, path is: %s, path alias is: %s\n", pPath, pPathAlias);
	start(pPath, pPathAlias);
	WSACleanup();
	return 0;
}
Beispiel #7
0
void menu()
{	
	int selectedMenuItem;
	char varPassword[MAXPASSWORDSIZE] = {""};
	char varReservedWords[MAXRESERVEDWORDS][16];
	char varSavedPasswords[MAXRESERVEDWORDS][16];

	do
	{
		selectedMenuItem = selectMenu(varPassword, varReservedWords, varSavedPasswords);
		

		switch(selectedMenuItem)
		{
			// 1 menu item, Verify password 
			case 0:
				system("cls");

				printframe(28, 2, 49,6, 2);
				setCursorPosition(31,4);
				

				scanf("%s",varPassword);
				//fgets(varPassword, MAXPASSWORDSIZE, stdin);
				fflush(stdin);

				readReservedWords(varReservedWords, MAXRESERVEDWORDS);
				readSavedPasswords(varSavedPasswords,MAXRESERVEDWORDS);
				verifyPW(varPassword, varReservedWords, MAXRESERVEDWORDS,varSavedPasswords,MAXRESERVEDWORDS,true);


				setCursorPosition(20,24);
				system("pause");
				break;

			// 2 menu item, Generate password
			case 1:
				system("cls");

				//setCursorPosition(20,17);
				readReservedWords(varReservedWords, MAXRESERVEDWORDS);
				readSavedPasswords(varSavedPasswords,MAXRESERVEDWORDS);
				generatePW(varPassword, MAXPASSWORDSIZE, varReservedWords, MAXRESERVEDWORDS, varSavedPasswords,MAXRESERVEDWORDS);

				
				printPasswordIfExists(varPassword, MAXPASSWORDSIZE, varReservedWords, MAXRESERVEDWORDS, varSavedPasswords,MAXRESERVEDWORDS);
								
				setCursorPosition(20,24);
				system("pause");
				break;

			// 3 menu item,  Save password
			case 2:
				system("cls");

				readReservedWords(varReservedWords, MAXRESERVEDWORDS);
				readSavedPasswords(varSavedPasswords,MAXRESERVEDWORDS);

				printPasswordIfExists(varPassword, MAXPASSWORDSIZE, varReservedWords, MAXRESERVEDWORDS, varSavedPasswords,MAXRESERVEDWORDS);

				if ((savePasswordchar(varPassword,varReservedWords,MAXRESERVEDWORDS,varSavedPasswords,MAXRESERVEDWORDS)) == 1)
				{
					setCursorPosition(30,21);
					printColouredText("The password is saved successfully.",4);
				}
				else
				{
					setCursorPosition(30,21);
					printColouredText("We can't save the password.",3);
				}

				setCursorPosition(20,24);
				system("pause");
				break;

			// 4 menu item, About
			case 3:
				system("cls");

				printAbout();

				setCursorPosition(20,24);
				system("pause");
				break;
		}
	}
	while (selectedMenuItem != LASTMENUITEM);

}
Beispiel #8
0
int main(void)
{
  CURL *curl_handle;
  CURLcode res;
  
  char *townName = (char *) secure_malloc(1);
  char readKeyBoard_char=' ';
  size_t townName_size=1;
  int choice=TOWN_NAME;
  char *name_validity_pointer=NULL;
  int query_strin_Size=strlen(initValue_queryValue)+1;
  char *query_string=(char *)secure_malloc(query_strin_Size);
  
  struct MemoryStruct chunk;
  

  secure_strcpy(query_string,initValue_queryValue);
  
  ////////////////////////////////begin big while LOOP
          while(1)
        {
            
            
			switch(choice)
            {

            case PRINT_TEMPERATURE:
                system("cls");
                print_temp(chunk.memory);
				printf("\nPress anything to go back..");
                _getch();
                break;
            case PRINT_HUMIDITY:
                system("cls");
                print_humidity(chunk.memory);
                printf("\nPress anything to back..");
                _getch();
                break;
            case TOWN_NAME:
                 name_validity_pointer= NULL;
				 while(name_validity_pointer==NULL){
								
							  
							  chunk.memory =(char*) secure_malloc(1);  /* will be grown as needed by the realloc above */ 
							  chunk.size = 0;    /* no data at this point */ 
 							  curl_global_init(CURL_GLOBAL_ALL);
 							  /* init the curl session */ 
							  curl_handle = curl_easy_init();
							  /* specify URL to get */ 
							  printf("\nplease enter townName:");
							  
							  if(townName)
								  {
									  free(townName);
							          townName=NULL;
							      }
							 							  
							  townName_size=1;
							  readKeyBoard_char=' ';
							  townName=(char *) secure_malloc(1);
							  							 
							while(1)
							  {
								  readKeyBoard_char=_getch();
								  if((int)readKeyBoard_char == ASCII_Code_ENTER)
									  break;
								  printf("%c",readKeyBoard_char);
								  townName[townName_size-1]=readKeyBoard_char;
								  townName[townName_size]='\0';
								  townName_size++;
								  townName=(char *) realloc(townName,townName_size+1);

							  }
							  townName[townName_size]='\0';

							  secure_strcpy(query_string,initValue_queryValue);
							  query_strin_Size = strlen(initValue_queryValue)+townName_size+strlen(lastPart_queryValue)+1;
							  query_string=(char *) realloc(query_string,query_strin_Size);
							  
							  strcat_s(query_string,townName_size,townName);
							  strcat_s(query_string,strlen(lastPart_queryValue),lastPart_queryValue);
							  query_string[query_strin_Size]='\0';
							  
							  curl_easy_setopt(curl_handle, CURLOPT_URL, query_string);
							  /* send all data to this function  */ 
							  curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
							  /* we pass our 'chunk' struct to the callback function */ 
							  curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
							  /* some servers don't like requests that are made without a user-agent
								 field, so we provide one */ 
							  curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
							  /* get it! */ 
							  res = curl_easy_perform(curl_handle);
							  /* check for errors */ 
							  if(res != CURLE_OK) {
								fprintf(stderr, "Connection to the server failed: %s\n",	curl_easy_strerror(res));
							  }
							  else {
								/*
								 * Now, our chunk.memory points to a memory block that is chunk.size
								 * bytes big and contains the remote file.*/
								
								name_validity_pointer=strstr(chunk.memory,"Error: Not found city");
								if(name_validity_pointer!=NULL)
									{

										printf("please enter a valid town name ,you have entered %s\n",townName);
										free_dynamicVar(chunk.memory);
										name_validity_pointer=NULL;
					
									}
								else{
										
										name_validity_pointer = (char *) !NULL;
	
									}
							  }
						  
	

					  }
				 printf("\nThe town name %s is accepted",townName);
				 Sleep(SECOND);
					break;
            case ABOUT_APPLICATION:
                system("cls");
                printAbout();
				printf("\nPress anything to back..");
                _getch();
                break;
            case EXIT:
                printf("Please enter any key to exit the Weather Application..");
				_getch();
                break;

            }
			if(choice == EXIT) 
				break;
			system("cls");
            printf("Welcome to Embedded Weather Station !\n");
            printf("************The Menu ***************\n");
            printf("1) Consult the temperature\n");
            printf("2) Consult the humidity\n");
            printf("3) change the town's name\n");
            printf("4) About the application\n");
            printf("5) exit the application\n");
            printf("\nPlease enter a valid choice: (between 1 and 5):");

			choice = DEFAULT;
			choice = (int)_getch() - ASCII_Code_0;
            while((choice < PRINT_TEMPERATURE) || (choice > EXIT))
            {
				choice=(int)getchar()-ASCII_Code_0;
				
			}
        }
    
  ///////////////////////////////end big while
	 /* cleanup curl stuff */ 
  curl_easy_cleanup(curl_handle);
  free_dynamicVar(chunk.memory);
  free_dynamicVar(query_string);
  /* we're done with libcurl, so clean it up */ 
  curl_global_cleanup();

  return 0;
}
void about(){
	printAbout();
}