Creating a commandline

This is a discussion on Creating a commandline within the C++ Programming forums, part of the General Programming Boards category; I want to make something, kind of like the Windows commandline thing. Such as, the program will have a number ...

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    Creating a commandline

    I want to make something, kind of like the Windows commandline thing. Such as, the program will have a number of recognized commands such as 'log' or 'run'. This is for learning purposes, so I don't care if these commands exist already. How exactly do I check if the command is recognized or if the parameter after it, is valid. For example, I type 'run blah', this will not be valid. But how can this be checked? Also, how do I define the commands like 'run' or 'log'?
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    First, you use a tokenizer. This splits up the input line into individual strings eg. "foo bar baz" -> "foo", "bar", "baz".

    Now it is trivial to see if the command is supported. The Q&D way is to just hunt for it in a list of valid commands. Or you could get fancy and use a hash.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    903
    Edit: Nevermind.
    Last edited by Desolation; 10-01-2006 at 09:36 PM.

  4. #4
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Ugh...I can see this turning into a scripting engine type setup. A tokenizer is a lexer correct?
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    More precisely it is a rather dumb scanner, and scanners -- especially one for your needs -- are simple to write.
    Last edited by zx-1; 10-01-2006 at 10:14 PM.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 10:38 AM
  2. Help creating lists of pointers
    By The_Kingpin in forum C Programming
    Replies: 2
    Last Post: 12-11-2004, 08:10 PM
  3. my own commandline parser function
    By scrappy in forum C Programming
    Replies: 7
    Last Post: 08-22-2003, 03:57 AM
  4. problems creating a linked list
    By jamjar in forum C Programming
    Replies: 5
    Last Post: 10-23-2002, 06:50 AM
  5. Creating an Code-template in Visual C++
    By yerrel in forum C++ Programming
    Replies: 1
    Last Post: 06-10-2002, 12:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21