List:Internals« Previous MessageNext Message »
From:sasha Date:December 25 2001 5:43pm
Subject:bk commit into 4.0 tree
View as plain text  
Below is the list of changes that have just been committed into a
4.0 repository of sasha. When sasha does a push, they will be propogated to 
the main repository and within 24 hours after the push to the public repository. 
For information on how to access the public repository
see http://www.mysql.com/doc/I/n/Installing_source_tree.html

ChangeSet@stripped, 2001-12-25 10:42:53-07:00, sasha@stripped
  some work on mysql_install

  BitKeeper/etc/ignore
    1.100 01/12/25 10:42:16 sasha@stripped +1 -0
    Added extra/mysql_install to the ignore list

  extra/Makefile.am
    1.8 01/12/25 10:42:16 sasha@stripped +1 -1
    added mysql_install

  extra/mysql_install.c
    1.2 01/12/25 10:42:16 sasha@stripped +194 -2
    implemented ask_user()

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	sasha
# Host:	mysql.sashanet.com
# Root:	/reiser-data/mysql-4.0-stable

--- 1.7/extra/Makefile.am	Fri Jan  5 15:04:14 2001
+++ 1.8/extra/Makefile.am	Tue Dec 25 10:42:16 2001
@@ -18,7 +18,7 @@
 LDADD =			@CLIENT_EXTRA_LDFLAGS@ ../mysys/libmysys.a \
 			../dbug/libdbug.a ../strings/libmystrings.a
 bin_PROGRAMS =		replace comp_err perror resolveip my_print_defaults \
-resolve_stack_dump
+resolve_stack_dump mysql_install
 
 OMIT_DEPENDENCIES =	pthread.h stdio.h __stdio.h stdlib.h __stdlib.h math.h\
 			__math.h time.h __time.h unistd.h __unistd.h types.h \

--- 1.99/BitKeeper/etc/ignore	Mon Dec 17 14:24:50 2001
+++ 1.100/BitKeeper/etc/ignore	Tue Dec 25 10:42:16 2001
@@ -447,3 +447,4 @@
 vio/viotest-ssl
 sql-bench/test-transactions
 libmysqld/sql_do.cc
+extra/mysql_install

--- 1.1/extra/mysql_install.c	Wed Dec 12 18:55:33 2001
+++ 1.2/extra/mysql_install.c	Tue Dec 25 10:42:16 2001
@@ -21,7 +21,7 @@
 #define INSTALL_VERSION "1.0"
 
 #define DONT_USE_RAID
-#include <global.h>
+#include <my_global.h>
 #include <m_ctype.h>
 #include <my_sys.h>
 #include <m_string.h>
@@ -29,13 +29,195 @@
 #include <errno.h>
 #include <getopt.h>
 
+#define ANSWERS_CHUNCK 32
+
+int have_gui=0;
+
 struct option long_options[] =
 {
-  {"help", no_argument, 0, 'h'},
+  {"help", no_argument, 0, '?'},
   {"version", no_argument, 0, 'V'},
   {0, 0,0,0}
 };
 
+/* For now, not much exciting here, but we'll add more once
+   we add GUI support
+ */
+typedef struct
+{
+  FILE* out;
+  FILE* in;
+  const char* question;
+  int default_ind;
+  DYNAMIC_ARRAY answers;
+} QUESTION_WIDGET;
+
+static void usage();
+static void die(const char* fmt, ...);
+static void print_version(void);
+static char get_answer_char(int ans_ind);
+static int ask_user(const char* question,int default_ind, ...);
+static void add_answer(QUESTION_WIDGET* w, const char* ans);
+static void display_question(QUESTION_WIDGET* w);
+static int init_question_widget(QUESTION_WIDGET* w, const char* question,
+				int default_ind);
+static void end_question_widget(QUESTION_WIDGET* w);
+static int get_answer(QUESTION_WIDGET* w);
+static char answer_from_char(char c);
+static void invalid_answer(QUESTION_WIDGET* w);
+
+enum {IMODE_STANDARD=0,IMODE_CUSTOM,IMODE_UPGRAGE} install_mode
+ = IMODE_STANDARD;
+
+static char get_answer_char(int ans_ind)
+{
+  return 'a' + ans_ind;
+}
+
+static void invalid_answer(QUESTION_WIDGET* w)
+{
+  if (!have_gui)
+  {
+    fprintf(w->out, "ERROR: invalid answer, try again...\a\n");
+  }
+}
+
+static char answer_from_char(char c)
+{
+  return c - 'a';
+}
+
+static void die(const char* fmt, ...)
+{
+  va_list args;
+  va_start(args, fmt);
+  fprintf(stderr, "%s: ", my_progname);
+  vfprintf(stderr, fmt, args);
+  fprintf(stderr, "\n");
+  va_end(args);
+  exit(1);
+}
+
+static void display_question(QUESTION_WIDGET* w)
+{
+  if (!have_gui)
+  {
+    uint i,num_answers=w->answers.elements;
+    DYNAMIC_ARRAY* answers = &w->answers;
+    fprintf(w->out,"\n%s\n\n",w->question);
+    
+    for (i=0; i<num_answers; i++)
+    {
+      char* ans;
+      get_dynamic(answers,(gptr)&ans,i);
+      fprintf(w->out,"%c - %s\n",get_answer_char(i),ans);
+    }
+    fprintf(w->out,"q - Abort Install/Upgrade\n\n");
+  }
+}
+
+static void add_answer(QUESTION_WIDGET* w, const char* ans)
+{
+  insert_dynamic(&w->answers,(gptr)&ans);
+}
+
+static int init_question_widget(QUESTION_WIDGET* w, const char* question,
+			       int default_ind)
+{
+  if (have_gui)
+  {
+    w->in = w->out = 0;
+  }
+  else
+  {
+    w->out = stdout;
+    w->in = stdin;
+  }
+  w->question = question;
+  w->default_ind = default_ind;
+  if (init_dynamic_array(&w->answers,sizeof(char*),
+			 ANSWERS_CHUNCK,ANSWERS_CHUNCK))
+    die("Out of memory");
+  return 0;
+}
+
+static void end_question_widget(QUESTION_WIDGET* w)
+{
+  delete_dynamic(&w->answers);
+}
+
+static int get_answer(QUESTION_WIDGET* w)
+{
+  if (!have_gui)
+  {
+    char buf[32];
+    int ind;
+    char c;
+    if (!fgets(buf,sizeof(buf),w->in))
+      die("Failed fgets on input stream");
+    switch ((c=tolower(*buf)))
+    {
+    case '\n':
+      return w->default_ind;
+    case 'q':
+      die("Install/Upgrade aborted");
+    default:
+      ind = answer_from_char(c);
+      if (ind >= 0 && ind < (int)w->answers.elements)
+	return ind;
+    }
+  }
+  return -1;
+}
+
+static int ask_user(const char* question,int default_ind, ...)
+{
+  va_list args;
+  char* opt;
+  QUESTION_WIDGET w;
+  int ans;
+  
+  va_start(args,default_ind);
+  init_question_widget(&w,question,default_ind);
+  for (;(opt=va_arg(args,char*));)
+  {
+    add_answer(&w,opt);
+  }
+  for (;;)
+  {
+    display_question(&w);
+    if ((ans = get_answer(&w)) >= 0)
+      break;
+    invalid_answer(&w);
+  }
+  end_question_widget(&w);
+  va_end(args);
+  return ans;
+}
+
+static int parse_args(int argc, char **argv)
+{
+  int c, option_index = 0;
+
+  while((c = getopt_long(argc, argv, "?V",
+			 long_options, &option_index)) != EOF)
+    {
+      switch(c)
+	{
+	case 'V':
+	  print_version();
+	  exit(0);
+	case '?':
+	  usage();
+	  exit(0);
+	default:
+	  usage();
+	  exit(1);
+	}
+    }
+  return 0;
+}
+
 static void print_version(void)
 {
   printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,INSTALL_VERSION,
@@ -55,6 +237,16 @@
   -V, --version            Output version information and exit.\n");
 }
 
+int main(int argc, char** argv)
+{
+  MY_INIT(argv[0]);
+  parse_args(argc,argv);
+  install_mode = ask_user("Please select install/upgrade mode",
+			  install_mode, "Standard Install",
+			  "Custom Install", "Upgrade",0);
+  printf("mode=%d\n", install_mode);
+  return 0;
+}
 
 
 
Thread
bk commit into 4.0 treesasha25 Dec