Unix programming & CLA

This is a discussion on Unix programming & CLA within the C++ Programming forums, part of the General Programming Boards category; As a point of "style" I'm wondering how any of you unix programmers out there handle command-line arguments in your ...

  1. #1
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391

    Unix programming & CLA

    As a point of "style" I'm wondering how any of you unix programmers out there handle command-line arguments in your program.

    Especially, I want to know what approach is taken when a particular argument shouldn't execute the main body of the program (like displaying the program manual), here's what I typically do in that situation:

    ( written in semi-pseudo code ):
    Code:
    int main( int argc, char *argv[] ){
    
        bool exec_prog = 1;
    
        if( manual-argument-is-found ){
    
            display_manual();
            exec_prog = 0;
        }
    
        if( exec_prog ){
    
            // None of this will happen if specific argument was found
        }
    
        return 0;
    }
    I've never dabbled in multi-threaded programs (in fact I don't have any idea how that works).

    Are separate threads even applicable here?

    Thoughts?
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,648
    >> Are separate threads even applicable here?
    For argument processing - I'd say no.

    A lot of *nix apps use getopt() to process the command line.
    http://www.gnu.org/software/libtool/...bc/Getopt.html

    Personally, I just return from main() after printing a usage message - as a result of missing command line parameters or a "-help, -?" parameter.

    gg

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    you could have a look at boost::program_options. I use it and find it pretty convenient. It is also able to handle options from config files or both together.

  4. #4
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Thank you guys.

    I'll have a look at those.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Boost.Program_Options is definitely the way to go. An adorable little library.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to program in unix
    By Cpro in forum Linux Programming
    Replies: 21
    Last Post: 02-12-2008, 09:54 AM
  2. Setting up a Unix box
    By @nthony in forum Tech Board
    Replies: 6
    Last Post: 07-22-2007, 10:22 PM
  3. UNIX (Linux, BSD, etc) Programming :: UNIX
    By kuphryn in forum Linux Programming
    Replies: 6
    Last Post: 04-01-2004, 07:44 PM
  4. Unix Sockets
    By prvindia in forum Linux Programming
    Replies: 5
    Last Post: 03-11-2003, 08:16 AM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 07:37 AM

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