Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1 from andrewnix/master
Solucion en C++
  • Loading branch information
12meses12katas committed Apr 9, 2012
2 parents 42fe10a + 0edd325 commit 95d14bb
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
101 changes: 101 additions & 0 deletions andrewnix/headerKataArgs.hpp
@@ -0,0 +1,101 @@
/*
* Autor: Andres F. Cardenas (Andrewnix)
* This program, is write on C++, is a parser command-line.
* This is the header file, contains the functions that use main cpp
*/

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

const string L = "-l";
const string P = "-p";
const string D = "-d";

void imprimirInfo(bool *, string *, string *);
void setPort(char **, int, int, string *);
void setLoggin(char **, int, int, bool *);
void setDirectory(char **, int, int, string *);

// Esta funcion imprime la informacion legiblemente
// this function print the info legibly
void printInfo(bool *loggin, string *port, string *dir)
{
if (*loggin == false)
{
cout << "Loggin: false" << endl;
}

else if (*loggin == true)
{
cout << "Loggin: true" << endl;
}

cout << "Port: " << *port << endl;
cout << "Directory: " << *dir << endl;
}

// Esta funcion asigna el valor adecuado a loggin
// this function assign the value suitable to loggin
void setLoggin(char **argv, int i, int argc, bool *loggin)
{
if (argv[i] == L)
{
if (argv[argc-1] == L)
{
*loggin = false;
}
else if (argv[i+1] != P && argv[i+1] != D && (atoi(argv[i+1])) > 0)
{
*loggin = true;
}
else
{
*loggin = false;
}
}
}

// Esta funcion asigna el valor adecuado a port
// this function assign the value suitable to port
void setPort(char **argv, int i, int argc, string *port)
{
if (argv[i] == P)
{
if (argv[argc-1] == P)
{
*port = "0";
}
else if (argv[i+1] != L && argv[i+1] != D && (atoi(argv[i+1])) > 0)
{
*port = argv[i+1];
}
else
{
*port = "0";
}
}
}

// Esta funcion asigna el valor adecuado a dir
// this function assign the value suitable to dir
void setDirectory(char **argv, int i, int argc, string *dir)
{
if (argv[i] == D)
{
if (argv[argc-1] == D)
{
*dir = "";
}
else if (argv[i+1] != P && argv[i+1] != L)
{
*dir = argv[i+1];
}
else
{
*dir = "";
}
}
}
25 changes: 25 additions & 0 deletions andrewnix/main.cpp
@@ -0,0 +1,25 @@
/*
* Autor: Andres F. Cardenas (Andrewnix)
* This program, is write on C++, is a parser command-line.
*/

#include <string>
#include "headerKataArgs.hpp"

int main(int argc, char **argv)
{
bool loggin = false;
string port = "0";
string dir = "";

for(int i = 0; i < argc; ++i)
{
setLoggin(argv, i, argc, &loggin);
setPort(argv, i, argc, &port);
setDirectory(argv, i, argc, &dir);
}

printInfo(&loggin, &port, &dir);

return 0;
}

0 comments on commit 95d14bb

Please sign in to comment.