~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/default.cc

Added some special case code for directory handling on solaris.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/****************************************************************************
17
17
 Add all options from files named "group".cnf from the default_directories
33
33
 --print-defaults         ; Print the modified command line and exit
34
34
****************************************************************************/
35
35
 
36
 
#include <config.h>
 
36
#include "config.h"
37
37
 
38
 
#include <drizzled/internal/my_sys.h>
39
 
#include <drizzled/internal/m_string.h>
40
 
#include <drizzled/charset_info.h>
41
 
#include <drizzled/typelib.h>
 
38
#include "drizzled/internal/my_sys.h"
 
39
#include "drizzled/internal/m_string.h"
 
40
#include "drizzled/charset_info.h"
42
41
#include <drizzled/configmake.h>
43
42
#include <drizzled/gettext.h>
44
43
 
45
 
#include <drizzled/cached_directory.h>
 
44
#include "drizzled/cached_directory.h"
46
45
 
47
46
#ifdef HAVE_SYS_STAT_H
48
47
# include <sys/stat.h>
288
287
  if (!option)
289
288
    return 0;
290
289
 
291
 
  if (ctx->group->find_type(const_cast<char*>(group_name), 3))
 
290
  if (find_type((char *)group_name, ctx->group, 3))
292
291
  {
293
292
    if (!(tmp= (char *)ctx->alloc->alloc_root(strlen(option) + 1)))
294
293
      return 1;
400
399
{
401
400
  DYNAMIC_ARRAY args;
402
401
  TYPELIB group;
 
402
  bool found_print_defaults= 0;
403
403
  uint32_t args_used= 0;
404
404
  int error= 0;
405
405
  memory::Root alloc(512);
464
464
    Check if we wan't to see the new argument list
465
465
    This options must always be the last of the default options
466
466
  */
 
467
  if (*argc >= 2 && !strcmp(argv[0][1],"--print-defaults"))
 
468
  {
 
469
    found_print_defaults=1;
 
470
    --*argc; ++*argv;                           /* skip argument */
 
471
  }
 
472
 
467
473
  if (*argc)
468
474
    memcpy(res+1+args.elements, *argv + 1, (*argc-1)*sizeof(char*));
469
475
  res[args.elements+ *argc]=0;                  /* last null */
472
478
  *argv= static_cast<char**>(res);
473
479
  *(memory::Root*) ptr= alloc;                  /* Save alloc root for free */
474
480
  delete_dynamic(&args);
475
 
 
 
481
  if (found_print_defaults)
 
482
  {
 
483
    int i;
 
484
    printf("%s would have been started with the following arguments:\n",
 
485
           **argv);
 
486
    for (i=1 ; i < *argc ; i++)
 
487
      printf("%s ", (*argv)[i]);
 
488
    puts("");
 
489
    exit(0);
 
490
  }
476
491
  return(error);
477
492
 
478
493
 err:
937
952
    }
938
953
  }
939
954
  puts("\nThe following options may be given as the first argument:\n\
 
955
  --print-defaults      Print the program argument list and exit\n\
940
956
  --no-defaults         Don't read default options from any options file\n\
941
957
  --defaults-file=#     Only read default options from the given file #\n\
942
958
  --defaults-extra-file=# Read this file after the global files are read");
946
962
  This extra complexity is to avoid declaring 'rc' if it won't be
947
963
  used.
948
964
*/
949
 
static void add_directory(const char* dir)
950
 
{
951
 
  array_append_string_unique(dir, default_directories, array_elements(default_directories));
952
 
}
953
 
 
954
 
static void add_common_directories()
955
 
{
956
 
  const char *env= getenv("DRIZZLE_HOME"); 
957
 
  if (env) 
958
 
    add_directory(env); 
959
 
  // Placeholder for --defaults-extra-file=<path>
960
 
  add_directory(""); 
961
 
}
 
965
#define ADD_DIRECTORY(DIR)  (void) array_append_string_unique((DIR), default_directories, \
 
966
                             array_elements(default_directories))
 
967
 
 
968
#define ADD_COMMON_DIRECTORIES() \
 
969
  do { \
 
970
    const char *env; \
 
971
    if ((env= getenv("DRIZZLE_HOME"))) \
 
972
      ADD_DIRECTORY(env); \
 
973
    /* Placeholder for --defaults-extra-file=<path> */ \
 
974
    ADD_DIRECTORY(""); \
 
975
  } while (0)
 
976
 
962
977
 
963
978
/**
964
979
  Initialize default directories for Unix
975
990
static void init_default_directories(void)
976
991
{
977
992
  memset(default_directories, 0, sizeof(default_directories));
978
 
  add_directory("/etc/");
979
 
  add_directory("/etc/drizzle/");
980
 
  add_directory(SYSCONFDIR);
981
 
  add_common_directories();
982
 
  add_directory("~/");
 
993
  ADD_DIRECTORY("/etc/");
 
994
  ADD_DIRECTORY("/etc/drizzle/");
 
995
  ADD_DIRECTORY(SYSCONFDIR);
 
996
  ADD_COMMON_DIRECTORIES();
 
997
  ADD_DIRECTORY("~/");
983
998
}
984
999
 
985
1000
} /* namespace internal */