pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r4005 - in trunk/pingus: . src src/util


From: grumbel at BerliOS
Subject: [Pingus-CVS] r4005 - in trunk/pingus: . src src/util
Date: Wed, 4 Nov 2009 02:04:29 +0100

Author: grumbel
Date: 2009-11-04 02:04:18 +0100 (Wed, 04 Nov 2009)
New Revision: 4005

Added:
   trunk/pingus/src/pingus/
   trunk/pingus/src/util/command_line.cpp
   trunk/pingus/src/util/command_line.hpp
   trunk/pingus/src/util/command_line_generic.cpp
   trunk/pingus/src/util/command_line_generic.hpp
Removed:
   trunk/pingus/src/command_line.cpp
   trunk/pingus/src/command_line.hpp
   trunk/pingus/src/command_line_generic.cpp
   trunk/pingus/src/command_line_generic.hpp
Modified:
   trunk/pingus/SConstruct
   trunk/pingus/src/pingus_main.cpp
Log:
Move utility classes to util/ directory


Modified: trunk/pingus/SConstruct
===================================================================
--- trunk/pingus/SConstruct     2009-11-04 00:59:16 UTC (rev 4004)
+++ trunk/pingus/SConstruct     2009-11-04 01:04:18 UTC (rev 4005)
@@ -30,8 +30,8 @@
 'src/collider.cpp', 
 'src/collision_map.cpp', 
 'src/collision_mask.cpp',
-'src/command_line.cpp',
-'src/command_line_generic.cpp',
+'src/util/command_line.cpp',
+'src/util/command_line_generic.cpp',
 'src/config_manager.cpp', 
 'src/credits.cpp', 
 'src/debug.cpp', 

Deleted: trunk/pingus/src/command_line.cpp
===================================================================
--- trunk/pingus/src/command_line.cpp   2009-11-04 00:59:16 UTC (rev 4004)
+++ trunk/pingus/src/command_line.cpp   2009-11-04 01:04:18 UTC (rev 4005)
@@ -1,96 +0,0 @@
-/*
-**  ClanLib SDK
-**  Copyright (c) 1997-2005 The ClanLib Team
-**
-**  This software is provided 'as-is', without any express or implied
-**  warranty.  In no event will the authors be held liable for any damages
-**  arising from the use of this software.
-**
-**  Permission is granted to anyone to use this software for any purpose,
-**  including commercial applications, and to alter it and redistribute it
-**  freely, subject to the following restrictions:
-**
-**  1. The origin of this software must not be misrepresented; you must not
-**     claim that you wrote the original software. If you use this software
-**     in a product, an acknowledgment in the product documentation would be
-**     appreciated but is not required.
-**  2. Altered source versions must be plainly marked as such, and must not be
-**     misrepresented as being the original software.
-**  3. This notice may not be removed or altered from any source distribution.
-**
-**  Note: Some of the libraries ClanLib may link to may have additional
-**  requirements or restrictions.
-**
-**  File Author(s):
-**
-**    Magnus Norddahl
-**    (if your name is missing here, please add it)
-*/
-
-#include "command_line.hpp"
-#include "command_line_generic.hpp"
-
-CommandLine::CommandLine()
-{
-       impl = new CommandLine_Generic();
-}
-
-CommandLine::~CommandLine()
-{
-       delete impl;
-}
-
-void CommandLine::parse_args(int argc, char** argv)
-{
-       impl->parse_args(argc, argv);
-}
-
-void CommandLine::print_help()
-{
-       impl->print_help();
-}
-
-void CommandLine::set_help_indent(int i)
-{
-       impl->set_help_indent(i);
-}
-
-void CommandLine::add_usage(const std::string& usage)
-{
-       impl->add_usage(usage);
-}
-
-void CommandLine::add_doc(const std::string& doc)
-{
-       impl->add_doc(doc);
-}
-
-void CommandLine::add_group(const std::string& grouptopic)
-{
-       impl->add_group(grouptopic);
-}
-
-void CommandLine::add_option(
-       int key, 
-       const std::string& long_option, 
-       const std::string& argument,
-       const std::string& help,
-       bool visible)
-{
-       impl->add_option(key, long_option, argument, help, visible);
-}
-
-bool CommandLine::next()
-{
-       return impl->next();
-}
-
-int CommandLine::get_key()
-{
-       return impl->get_key();
-}
-
-std::string CommandLine::get_argument()
-{
-       return impl->get_argument();
-}

Deleted: trunk/pingus/src/command_line.hpp
===================================================================
--- trunk/pingus/src/command_line.hpp   2009-11-04 00:59:16 UTC (rev 4004)
+++ trunk/pingus/src/command_line.hpp   2009-11-04 01:04:18 UTC (rev 4005)
@@ -1,157 +0,0 @@
-/*
-**  ClanLib SDK
-**  Copyright (c) 1997-2005 The ClanLib Team
-**
-**  This software is provided 'as-is', without any express or implied
-**  warranty.  In no event will the authors be held liable for any damages
-**  arising from the use of this software.
-**
-**  Permission is granted to anyone to use this software for any purpose,
-**  including commercial applications, and to alter it and redistribute it
-**  freely, subject to the following restrictions:
-**
-**  1. The origin of this software must not be misrepresented; you must not
-**     claim that you wrote the original software. If you use this software
-**     in a product, an acknowledgment in the product documentation would be
-**     appreciated but is not required.
-**  2. Altered source versions must be plainly marked as such, and must not be
-**     misrepresented as being the original software.
-**  3. This notice may not be removed or altered from any source distribution.
-**
-**  Note: Some of the libraries ClanLib may link to may have additional
-**  requirements or restrictions.
-**
-**  File Author(s):
-**
-**    Magnus Norddahl
-**    (if your name is missing here, please add it)
-*/
-
-//! clanCore="System"
-//! header=core.h
-
-#ifndef HEADER_COMMAND_LINE_HPP
-#define HEADER_COMMAND_LINE_HPP
-
-#if _MSC_VER > 1000
-#pragma once
-#endif
-
-#include <string>
-#include <vector>
-
-class CommandLine_Generic;
-
-//: Helper class to parse command line arguments
-//- !group=Core/System!
-//- !header=core.h!
-//- <p>The CommandLine class helps to parse command line arguments, namely
-//- the argc/argv pair that you get from main(). CommandLine mimics
-//- getopt_long() behaviour as closely as possible, while providing a
-//- cleaner interface and a few additional features, like automatic
-//- generation of '--help' output. CommandLine can parse long arguments
-//- in the following styles:</p>
-//-
-//- <p>program --file FILENAME<br>
-//- program --file=FILENAME</p>
-//-
-//- <p>Short arguments are handled like this:</p>
-//-
-//- <p>program -f FILENAME</p>
-//-
-//- <p>Concatenating short arguments is also supported, so that:</p>
-//- 
-//- <p>program -f -a -b FILENAME</p>
-//-
-//- <p>is equivalent to:</p>
-//-
-//- <p>program -fab FILENAME</p>
-//-
-//- <p>Non-option arguments (aka rest arguments) are supported as well:</p>
-//-
-//- <p>program SOMEFILE SOMEOTHERFILE ...</p>
-//- 
-//- <p>To avoid ambiguity when a filename starts with '-' CommandLine stops
-//- parsing arguments after the first encounter of a '--', so in</p>
-//-
-//- <p>program -f -b -- -f -b</p>
-//-
-//- <p>In the above example the first '-f -b' options are treated as
-//- normal while the ones after the '--' are treated as rest arguments
-//- (aka filenames in most programs).</p>
-class CommandLine
-{
-//! Construction:
-public:
-       CommandLine();
-
-       ~CommandLine();
-
-//! Attributes:
-public:
-       enum
-       {
-               REST_ARG  = -2
-       };
-
-       //: Return the key of the current option
-       int get_key();
-
-       //: Return the argument to the current option
-       std::string get_argument();
-
-//! Operations:
-public:
-       //: Change the indention used for the help message, default is 18
-       void set_help_indent(int i);
-
-       //: Add a usage line to the help output, usage is for example
-       //: "[OPTIONS]... FILE", the program name will get appended
-       //: automatically
-       void add_usage(const std::string& usage);
-
-       //: Adds extra documentation to the help output, should only be
-       //: used at the beginning or at the end, to
-       void add_doc(const std::string& doc);
-       
-       //: Starts a new group of options, the grouptopic gets printed
-       //: above the group of options in the print_help() output
-       void add_group(const std::string& grouptopic);
-  
-       //: Adds a option to the parser
-       //param key: a letter for a short-option or a numeric value
-       //param key: larger than 255 that identifies the option
-       //param long_option: the long name of this option or "" if non
-       //param long_option: should be used for this option
-       //param argument: the type of the argument that this option
-       //param argument: requires (i.e. FILE, SIZE, WIDTH, etc.) or "" if no 
argument is
-       //param argument: required
-       //param help: the help string for this option
-       //param visible: true if the option should be listed in the help
-       //param visible: output, false will not list it in the help output 
which might
-       //param visible: be usefull for cheat-options or backward-compability 
options
-       //param visible: than would only clutter the help output
-       void add_option(
-               int key,
-               const std::string& long_option, 
-               const std::string& argument,
-               const std::string& help,
-               bool visible = true);
-       
-       //: Parse the options arcording to the options added with
-       //: add_option(), result of the parsing is accessible via
-       //: next() and get_key()/get_argument()
-       void parse_args(int argc, char** argv);
-
-       //: Print the help output, normaly done via a --help option
-       void print_help();
-
-       //: Goto the next option
-       bool next();
-
-//! Implementation:
-private:
-       CommandLine_Generic* impl;
-};
-
-#endif

Deleted: trunk/pingus/src/command_line_generic.cpp
===================================================================
--- trunk/pingus/src/command_line_generic.cpp   2009-11-04 00:59:16 UTC (rev 
4004)
+++ trunk/pingus/src/command_line_generic.cpp   2009-11-04 01:04:18 UTC (rev 
4005)
@@ -1,336 +0,0 @@
-/*
-**  ClanLib SDK
-**  Copyright (c) 1997-2005 The ClanLib Team
-**
-**  This software is provided 'as-is', without any express or implied
-**  warranty.  In no event will the authors be held liable for any damages
-**  arising from the use of this software.
-**
-**  Permission is granted to anyone to use this software for any purpose,
-**  including commercial applications, and to alter it and redistribute it
-**  freely, subject to the following restrictions:
-**
-**  1. The origin of this software must not be misrepresented; you must not
-**     claim that you wrote the original software. If you use this software
-**     in a product, an acknowledgment in the product documentation would be
-**     appreciated but is not required.
-**  2. Altered source versions must be plainly marked as such, and must not be
-**     misrepresented as being the original software.
-**  3. This notice may not be removed or altered from any source distribution.
-**
-**  Note: Some of the libraries ClanLib may link to may have additional
-**  requirements or restrictions.
-**
-**  File Author(s):
-**
-**    Magnus Norddahl
-**    (if your name is missing here, please add it)
-*/
-
-#include <iomanip>
-#include <iostream>
-#include <stdexcept>
-#include <stdio.h>
-
-#include "command_line_generic.hpp"
-
-
-#ifdef WIN32
-#define snprintf _snprintf
-#endif
-
-CommandLine_Generic::CommandLine_Generic()
-{
-  help_indent = 18;
-}
-
-void CommandLine_Generic::parse_args(int argc, char** argv)
-{
-  programm = argv[0];
-
-  for(int i = 1; i < argc; ++i) 
-    {
-      if (argv[i][0] == '-') 
-        {
-          if (argv[i][1] == '-') 
-            {
-              // We got a long option
-              if (argv[i][2] == '\0') { 
-                // Got a '--', so we stop evaluating arguments
-                ++i;
-                while(i < argc) 
-                  {
-                    read_option(CommandLine::REST_ARG, argv[i]);
-                    ++i;
-                  }
-              } 
-              else
-                {
-                  std::string opt = argv[i] + 2;
-                  std::string long_opt;
-                  std::string long_opt_arg;
-
-                  std::string::size_type pos = opt.find('=');
-
-                  if (pos != std::string::npos) 
-                    {
-                      long_opt = opt.substr(0, pos);
-                      long_opt_arg = opt.substr(pos+1);
-                    }
-                  else 
-                    {
-                      long_opt = opt;
-                    }
-
-                  // Long Option
-                  Option* option = lookup_long_option(long_opt);
-
-                  if (option) 
-                    {
-                      if (option->argument.empty()) 
-                        {
-                          read_option(option->key, "");
-                        } 
-                      else
-                        {
-                          if (pos != std::string::npos) 
-                            {
-                              read_option(option->key, long_opt_arg);
-                            }
-                          else
-                            {            
-                              if (i == argc - 1) 
-                                {
-                                  throw std::runtime_error("option '" + 
std::string(argv[i]) + "' requires an argument");
-                                }
-                              else 
-                                {
-                                  read_option(option->key, argv[i + 1]);
-                                  ++i;
-                                }
-                            }
-                        }
-                    }
-                  else
-                    {
-                      throw std::runtime_error("unrecognized option '" + 
std::string(argv[i]) + "'");
-                    }
-                }
-            } 
-          else 
-            {
-              // We got a short option
-              char* p = argv[i] + 1;
-          
-              if (*p != '\0') {
-                // Handle option chains
-                while (*p) 
-                  {
-                    // Short option(s)
-                    Option* option = lookup_short_option(*p);
-
-                    if (option) 
-                      {
-                        if (option->argument.empty()) 
-                          {
-                            read_option(option->key, "");
-                          } 
-                        else 
-                          {
-                            if (i == argc - 1 || *(p+1) != '\0') 
-                              {
-                                // No more arguments
-                                throw std::runtime_error("option requires an 
argument -- " + std::string(1, *p));
-                              }
-                            else
-                              {
-                                read_option(option->key, argv[i + 1]);
-                                ++i;
-                              }
-                          }
-                      } 
-                    else 
-                      {
-                        throw std::runtime_error("invalid option -- " + 
std::string(1, *p));
-                      }
-                    ++p; 
-                  }
-              } 
-              else
-                {
-                  read_option(CommandLine::REST_ARG, "-");
-                } 
-            }
-        } 
-      else
-        {
-          read_option(CommandLine::REST_ARG, argv[i]);
-        }
-    }
-
-  current_option = parsed_options.end();
-}
-
-CommandLine_Generic::Option *CommandLine_Generic::lookup_short_option(char 
short_option)
-{
-  for(Options::iterator i = options.begin(); i != options.end(); ++i)
-    {
-      if (i->key == short_option)
-        return &(*i);
-    }
-  return 0;
-}
-
-CommandLine_Generic::Option *CommandLine_Generic::lookup_long_option(const 
std::string& long_option)
-{
-  for(Options::iterator i = options.begin(); i != options.end(); ++i)
-    {
-      if (i->long_option == long_option)
-        return &*i;
-    }
-  return 0;
-}
-
-void CommandLine_Generic::read_option(int key, const std::string& argument)
-{
-  ParsedOption parsed_option;
-  
-  parsed_option.key = key;
-  parsed_option.argument = argument;
-
-  parsed_options.push_back(parsed_option);
-}
-
-void CommandLine_Generic::print_help()
-{
-  bool first_usage = true;
-  for(Options::iterator i = options.begin(); i != options.end(); ++i)
-    {
-      if (i->visible)
-        {
-          if (i->key == USAGE) 
-            {
-              if (first_usage) 
-                {
-                  std::cout << "Usage: " << programm << " " <<  i->help << 
std::endl; 
-                  first_usage = false;
-                }
-              else
-                {
-                  std::cout << "or:    " << programm << " " << i->help << 
std::endl; 
-                }
-            } 
-          else if (i->key == GROUP) 
-            {
-              if (i != options.begin())
-                std::cout << std::endl;
-              std::cout << i->help << std::endl;
-            }
-          else if (i->key == DOC) 
-            {
-              if (i != options.begin())
-                std::cout << std::endl;
-              std::cout << i->help << std::endl;
-            }
-          else 
-            {
-              char option[256]   = { 0 };
-              char argument[256] = { 0 };
-
-              if (i->key > 255 || i->key < 0)
-                snprintf(option, 256, "--%s", i->long_option.c_str());
-              else if (i->long_option.empty())
-                snprintf(option, 256, "-%c", char(i->key));
-              else
-                snprintf(option, 256, "-%c, --%s", char(i->key), 
i->long_option.c_str());
-
-              if (!i->argument.empty())
-                {
-                  if (i->long_option.empty())
-                    snprintf(argument, 256, " %s", i->argument.c_str());
-                  else
-                    snprintf(argument, 256, "=%s", i->argument.c_str());
-                }
-
-              std::cout << "  " 
-                        << std::setiosflags(std::ios::left) << 
std::setw(help_indent)
-                        << (std::string(option) + std::string(argument)) << 
std::setw(0)
-                        << " " << i->help << std::endl;
-            }
-        }
-    }
-  std::cout << std::endl;
-}
-
-void CommandLine_Generic::add_usage(const std::string& usage)
-{
-  Option option;
-
-  option.key          = USAGE;
-  option.help         = usage;
-  option.visible      = true;
-
-  options.push_back(option);   
-}
-
-void CommandLine_Generic::add_doc(const std::string& grouptopic)
-{
-  Option option;
-
-  option.key          = DOC;
-  option.help         = grouptopic;
-  option.visible      = true;
-
-  options.push_back(option);  
-}
-
-void CommandLine_Generic::add_group(const std::string& grouptopic)
-{
-  Option option;
-
-  option.key          = GROUP;
-  option.help         = grouptopic;
-  option.visible      = true;
-
-  options.push_back(option);  
-}
-
-void CommandLine_Generic::add_option(int key, 
-                                        const std::string& long_option, 
-                                        const std::string& argument,
-                                        const std::string& help,
-                                        bool visible)
-{
-  Option option;
-
-  option.key          = key;
-  option.help         = help;
-  option.long_option  = long_option;
-  option.argument     = argument;
-  option.visible      = visible;
-
-  options.push_back(option);
-}
-
-bool CommandLine_Generic::next()
-{
-  if (current_option == parsed_options.end()) 
-    {
-      (current_option = parsed_options.begin());
-      return current_option != parsed_options.end();
-    }
-  else
-    {
-      return (++current_option) != parsed_options.end();
-    }
-}
-
-int CommandLine_Generic::get_key()
-{
-  return current_option->key;
-}
-
-std::string CommandLine_Generic::get_argument()
-{
-  return current_option->argument;
-}

Deleted: trunk/pingus/src/command_line_generic.hpp
===================================================================
--- trunk/pingus/src/command_line_generic.hpp   2009-11-04 00:59:16 UTC (rev 
4004)
+++ trunk/pingus/src/command_line_generic.hpp   2009-11-04 01:04:18 UTC (rev 
4005)
@@ -1,111 +0,0 @@
-/*
-**  ClanLib SDK
-**  Copyright (c) 1997-2005 The ClanLib Team
-**
-**  This software is provided 'as-is', without any express or implied
-**  warranty.  In no event will the authors be held liable for any damages
-**  arising from the use of this software.
-**
-**  Permission is granted to anyone to use this software for any purpose,
-**  including commercial applications, and to alter it and redistribute it
-**  freely, subject to the following restrictions:
-**
-**  1. The origin of this software must not be misrepresented; you must not
-**     claim that you wrote the original software. If you use this software
-**     in a product, an acknowledgment in the product documentation would be
-**     appreciated but is not required.
-**  2. Altered source versions must be plainly marked as such, and must not be
-**     misrepresented as being the original software.
-**  3. This notice may not be removed or altered from any source distribution.
-**
-**  Note: Some of the libraries ClanLib may link to may have additional
-**  requirements or restrictions.
-**
-**  File Author(s):
-**
-**    Magnus Norddahl
-**    (if your name is missing here, please add it)
-*/
-
-#ifndef HEADER_COMMAND_LINE_GENERIC_HPP
-#define HEADER_COMMAND_LINE_GENERIC_HPP
-
-#if _MSC_VER > 1000
-#pragma once
-#endif
-
-#include <string>
-#include <vector>
-#include "command_line.hpp"
-
-class CommandLine_Generic
-{
-private:
-       int help_indent;
-
-       std::string programm;
-
-       struct Option 
-       {
-               int key;
-               std::string help;
-               std::string long_option;
-               std::string argument;
-               bool visible;
-       };
-  
-       typedef std::vector<Option> Options;
-       Options options;
-
-       struct ParsedOption
-       {
-               int key;
-               std::string argument;
-       };
-
-       typedef std::vector<ParsedOption> ParsedOptions;
-       ParsedOptions parsed_options;
-       ParsedOptions::iterator current_option;
-
-       enum
-       {
-               GROUP     = -3,
-               DOC       = -4,
-               USAGE     = -5
-       };
-
-public:  
-       CommandLine_Generic();
-
-       void set_help_indent(int i) { help_indent = i; }
-
-       void add_usage(const std::string& usage);
-       void add_doc(const std::string& doc);
-       void add_group(const std::string& grouptopic);
-  
-       void add_option(int key,
-                                                const std::string& 
long_option, 
-                                                const std::string& argument,
-                                                const std::string& help,
-                                                bool visible = true);
-
-       void parse_args(int argc, char** argv);
-       void print_help();
-  
-       bool next();
-       int get_key();
-       std::string get_argument();
-
-private:
-       void read_option(int id, const std::string& argument);
-
-       /** Find the Option structure that matches \a short_option */
-       Option* lookup_short_option(char short_option);
-
-       /** Find the Option structure that matches \a long_option */
-       Option* lookup_long_option (const std::string& long_option);
-};
-
-#endif
-
-/* EOF */

Modified: trunk/pingus/src/pingus_main.cpp
===================================================================
--- trunk/pingus/src/pingus_main.cpp    2009-11-04 00:59:16 UTC (rev 4004)
+++ trunk/pingus/src/pingus_main.cpp    2009-11-04 01:04:18 UTC (rev 4005)
@@ -55,7 +55,7 @@
 #include "gettext.h"
 #include "tinygettext/dictionary_manager.hpp"
 #include "tinygettext/log.hpp"
-#include "command_line.hpp"
+#include "util/command_line.hpp"
 
 #include "screen/screen_manager.hpp"
 #include "path_manager.hpp"

Copied: trunk/pingus/src/util/command_line.cpp (from rev 4002, 
trunk/pingus/src/command_line.cpp)

Copied: trunk/pingus/src/util/command_line.hpp (from rev 4002, 
trunk/pingus/src/command_line.hpp)

Copied: trunk/pingus/src/util/command_line_generic.cpp (from rev 4002, 
trunk/pingus/src/command_line_generic.cpp)

Copied: trunk/pingus/src/util/command_line_generic.hpp (from rev 4002, 
trunk/pingus/src/command_line_generic.hpp)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]