int main(int argc, char **argv){ /* Read program options */ while(1){ static struct option long_options[]= { {"verbose", no_argument, &_DEBUG, 1}, {"debug", no_argument, &_DEBUG, 1}, {"help", no_argument, 0, 'h'}, {"read", required_argument, 0, 'r'}, {"write", required_argument, 0, 'w'}, {"sync", required_argument, 0, 's'}, {0, 0, 0, 0} }; int option_index = 0; int c = getopt_long(argc, argv, "hs:w:r:", long_options, &option_index); if (c == -1) { break; } switch(c) { case 'v': _DEBUG = 1; break; case 'h': Print_Help(); break; case 'r': DEVICE = atoi(optarg); Read_RTC(); break; case 'w': DEVICE = atoi(optarg); Write_RTC(); break; case 's': DEVICE = atoi(optarg); Sync_RTC(); break; case '?': break; default: break; } } return 0; }
/**********************************************************************//** *************************************************************************/ int main(int argc, char** argv) { // If no arguments have been passed, print the help text and quit if (argc==1) { Print_Help() ; return 0 ; } // Define the optional arguments struct option longopts[5] ; getoptions(longopts) ; // Parse the options std::map<std::string, double> options = parseoptions(argc, argv, longopts) ; // If no valid options were given, quit if (options.empty()) return 0 ; // Create a map to store the results std::map<std::string, double> results ; results["ra"] = 0.0 ; results["dec"] = 0.0 ; // Convert the coordinates CECoordinates::Galactic2CIRS(options["glon"]*DD2R, options["glat"]*DD2R, &results["ra"], &results["dec"], CEDate(options["juliandate"])) ; // Print the results PrintResults(options, results) ; return 0 ; }
/**********************************************************************//** *************************************************************************/ std::map<std::string, double> parseoptions(int argc, char** argv, const struct option* longopts) { // Setup the default parameters std::map<std::string, double> options = defaultoptions() ; int c; while (1) { /* getopt_long stores the option index here. */ int option_index = 0; c = getopt_long (argc, argv, "hL:B:j:", longopts, &option_index); /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 0: /* If this option set a flag, do nothing else now. */ if (longopts[option_index].flag != 0) break; // Set the option options[longopts[option_index].name] = std::stod(optarg) ; break; case 'h': // Print the help message and quit Print_Help() ; return std::map<std::string, double>() ; case 'L': options["glon"] = std::stod(optarg) ; break; case 'B': options["glat"] = std::stod(optarg) ; break; case 'j': options["juliandate"] = std::stod(optarg) ; break; case '?': /* getopt_long already printed an error message. */ break; default: break ; } } return options ; }
EFI_STATUS EFIAPI //UefiMain ( // IN EFI_HANDLE ImageHandle, // IN EFI_SYSTEM_TABLE *SystemTable // ) ShellAppMain ( IN UINTN Argc, IN CHAR16 **Argv ) { EFI_STATUS Status; //ST = SystemTable; //BS = SystemTable->BootServices; ST = gST; BS = gBS; // InitializeLib (ImageHandle, SystemTable); Status = ParseCommandLine(Argc, Argv); if (EFI_ERROR(Status)) { Print(L"Wrong parameters usage!\n"); return Status; } if (GO_PRINT_HELP) { Print_Help(); } if (GO_PRINT_MENU) Print_Menu(); if (GO_PRINT_TEXT) { Print(L"Do text dump here!\n"); } return EFI_SUCCESS; }
//atrapa todos las operaciones del tipo 'commands', ver en help inline void Catch_Commands(std::string& text){ if( text.empty() ) text=" "; { //paso todo a minusculas poruqe es key-insensitive std::string aux = text; for( int i=0; i < text.length() ;i++ ){ aux[i]= tolower(aux[i]); } if( aux == "exit" ){ exit(0); } if( aux == "help" ){ Print_Help(); _getch(); text = " "; } if( aux.find("help",0) != std::string::npos ){ std::string com = aux.substr(aux.find(" ",0)+1); if( com == "sin" ){ std::cout<<"Calcula el seno de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "sinh" ){ std::cout<<"Calcula el seno hiperbolico de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "cos" ){ std::cout<<"Calcula el coseno de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "cosh" ){ std::cout<<"Calcula el coseno hiperbolico de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "tan" ){ std::cout<<"Calcula la tangente de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "tanh" ){ std::cout<<"Calcula la tangente hiperbolica de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "log10" ){ std::cout<<"Calcula el logaritmo base diez de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "log" ){ std::cout<<"Calcula el logaritmo natural de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "sqrt" ){ std::cout<<"Calcula la raiz cuadrada de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "abs" ){ std::cout<<"Calcula el valor absoluto de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "exp" ){ std::cout<<"Calucla la exponencial de un valor x, ya sea matricial o escalar\n"; text=" "; return; } if( com == "floor" ){ std::cout<<"Calcula el piso de un valor x, ie su aproximacion mas cercana al numero k\nnatural mas pequeno que este, puede operar en matrices o escalares\n"; text=" "; return; } if( com == "ceil" ){ std::cout<<"Calcula el techo de un valor x, ie su aproximacion mas cercana al numero k\nnatural mas grande que este, puede operar en matrices o escalares\n"; text=" "; return; } if( com == "asin" ){ std::cout<<"Calcula el arco seno, inversa del seno, de un valor x,\nya sea matricial o escalar\n"; text=" "; return; } if( com == "acos" ){ std::cout<<"Calcula el arco coseno, inversa del coseno, de un valor x,\nya sea matricial o escalar\n"; text=" "; return; } if( com == "atan" ){ std::cout<<"Calcula el arco tangente, inversa de la tangente, de un valor x,\nya sea matricial escalar\n"; text=" "; return; } if( com == "size" ){ std::cout<<"Muestra las dimensiones del resultado de una expresion con el formato:\n\tFilas/Columna\n"; text=" "; return; } if( com == "cross" ){ std::cout<<"Calcula el producto cruz de los vectores a y b. Las condiciones son:\n\ta) Tener ambos una dimensión de 3 componentes\n\tb) Ser ambos vectores fila o vectores columna\n"; text=" "; return; } if( com == "round" ){ std::cout<<"Redondea un valor x, ie su aproximacion mas cercana al numero k\nnatural mas cercano a este, puede operar en matrices o escalares\n"; text=" "; return; } if( com == "trapz" ){ std::cout<<"Calcula el area de la funcion definida por los vectores x e y,\nie integra la función definida por esos dos vectores.\nSiendo el rango de x desde a a b\n"; text=" "; return; } if( com == "der1" ){ std::cout<<"La primera derivada de la funcion definida por los vectores x e y\ncon respecto a x\n"; text=" "; return; } if( com == "der2" ){ std::cout<<"La segunda derivada de la funcion definida por los vectores x e y\ncon respecto a x\n"; text=" "; return; } if( com == "der3" ){ std::cout<<"La tercera derivada de la funcion definida por los vectores x e y\ncon respecto a x\n"; text=" "; return; } if( com == "der4" ){ std::cout<<"La cuarta derivada de la funcion definida por los vectores x e y\ncon respecto a x\n"; text=" "; return; } if( com == "rand" ){ std::cout<<"Genera una matriz con valores aleatorios de la dimension que especifiquen\nlos argumentos con el formato Filas/Columnas\n"; text=" "; return; } if( com == "det" ){ std::cout<<"Calcula el determinante de la matriz X.\nLa unica condicion es que X debe ser cuadrada\n"; text=" "; return; } if( com == "ones" ){ std::cout<<"Genera una matriz llena de unos de la dimension que especifiquen\nlos argumentos con el formato Filas/Columnas\n"; text=" "; return; } if( com == "zeros" ){ std::cout<<"Genera una matriz llena de ceros de la dimension que especifiquen\nlos argumentos con el formato Filas/Columnas\n"; text=" "; return; } if( com == "inv" ){ std::cout<<"Calcula la inversa de la matriz X.\nLas condiciones son:\n\ta) Que X sea cuadrada\n\tb) Que el determinante de X sea distinto de 0\n"; text=" "; return; } if( com == "gauss" ){ std::cout<<"Calcula la matriz gausseada, ie llevada a su forma escalonada\n"; text=" "; return; } if( com == "res" ){ std::cout<<"Resuleve el sistema lineal, la ultima columna de la matriz\nse considera la columna de condiciones\n"; text=" "; return; } if( com == "adj" ){ std::cout<<"Calcula la matriz adjunta. La única condición es que la matriz sea cuadrada\n"; text=" "; return; } if( com == "gaussv" ){ std::cout<<"Realiza todos los pasos necesarios para llevar la matriz X a su forma gauseada.\nMuestra un paso y espera que el usuario presione una tecla para continuar\ncon el proceso.\nAl final muestra un resumen de todas las operaciones realizadas\n"; text=" "; return; } if( com == "plot" ){ std::cout<<"Abre el programa graficador, CrapGraph, y dibuja la funcion que se le haya\npasado como parametro. La funcion se forma con sus valores independientes x,\nprimer parametro, y sus valores dependientes y, segundo parametro.\nCondiciones:\n\ta) Tanto x como y deben ser vectores (no pueden ser puntos,\n\t no se grafican puntos)\n\tb) También x e y deben tener igual cantidad de componentes\n\tc) Si esta permitido que x sea un vector fila e y columna y viceversa\n"; text=" "; return; } std::cout<<"No existe el comando "<<com<<std::endl; text=" "; return; } if( aux == "error_log" ){ std::ifstream errors; errors.open("error_log.txt"); if( !errors.is_open() ){ std::cout<<"No se puede acceder al log de errores. Esta seguro que esta en su lugar?\n"; std::cerr<<"IMPOSIBLE ACCESO PARA LECTURA DE ESTE ARCHIVO\n"; } std::cout<<'\n'; std::string line; while( !errors.eof() ){ std::getline(errors,line,'\n'); std::cout<<line; std::cout<<'\n'; } text = " "; } int pos = aux.find(" "); if( aux.substr( 0 , pos) == "clear" ){ std::string var = aux.substr( ++pos , aux.length() ); VarList_MD[var]=0; VarList_MD.erase(VarList_MD.find(var)); text = " "; } } }
int main(int argc, char **argv){ // Set I2C bus DEVICE = 2; // /dev/i2c-2 Olinuxino A20 micro, change if other board or i2c port used /* Read program options */ while(1){ static struct option long_options[]= { {"verbose", no_argument, &_DEBUG, 1}, {"debug", no_argument, &_DEBUG, 1}, {"relays?", no_argument,0,'r'}, {"adc", required_argument,0,'a'}, {"id", no_argument,0,'i'}, {"getport", no_argument,0,'g'}, {"getlat", no_argument,0,'G'}, {"setrelays", required_argument,0,'S'}, {"setoutputs", required_argument,0,'o'}, {"settris", required_argument,0,'t'}, {"setpullups", required_argument,0,'p'}, {"switchon", required_argument,0,'s'}, {"switchoff", required_argument,0,'n'}, {"firmware",no_argument,0,'f'}, {"help", no_argument,0,'h'}, {"busscan", no_argument,0,'F'}, {"setaddress", required_argument,0,'x'}, {"setfactory", no_argument,0,'X'}, {0, 0, 0, 0} }; int option_index = 0; int c = getopt_long(argc, argv, "s:t:a:igGrp:o:S:n:fhx:bX?", long_options, &option_index); unsigned int value; if (c == -1) { break; } switch(c) { case 'v': _DEBUG = 1; break; case 'h': Print_Help(); break; case 'S': value = atoi(optarg); Relay(value); break; case 's': value = atoi(optarg); RelayOn(value); break; case 'o': value = atoi(optarg); SetGPIO(value); break; case 'n': value = atoi(optarg); RelayOff(value); break; case 'b': DEVICE = atoi(optarg); break; case 'a': value = atoi(optarg); ReadADC(value); break; case 'g': ReadGPIO(); break; case 'G': ReadLAT(); break; case 'F': BusScan(); break; case 'i': ReadID(); break; case 'X': Set_Factory(); break; case 'r': ReadRelays(); break; case 't': value = atoi(optarg); Set_TRIS(value); break; case 'x': value = atoi(optarg); Set_Address(value); break; case 'p': value = atoi(optarg); Set_PU(value); break; case 'f': ReadSV(); break; default: // Print_Help(); break; } } return 0; }