--- asdbget.c.orig	Wed Feb  9 12:17:36 2000
+++ asdbget.c	Wed Feb  9 19:44:26 2000
@@ -66,17 +66,27 @@
 typedef struct field_tag field_t;
 
 
+#ifdef USE_LIB5250
+static char shortopts[] = "F:o:O:p:R:u:m:";
+#else
 static char shortopts[] = "F:o:O:p:R:u:";
+#endif /* USE_LIB5250 */
+
 #ifdef HAVE_GETOPT_LONG
 static struct option longopts[] =
   {
     { "output",		  1,	0,    'o' },
     { "password",	  1,    0,    'p' },
     { "user",		  1,    0,    'u' },
+#ifdef USE_LIB5250
+    { "map",		  1,    0,    'm' },
+#endif /* USE_LIB5250 */
     { NULL }
   };
 #endif
 
+#ifndef USE_LIB5250
+
 static char e2a[256] =
   {
    ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
@@ -97,12 +107,15 @@
    '0','1','2','3','4','5','6','7','8','9','0',' ',' ',' ',' ',' '
   };
 
+#endif /* USE_LIB5250
+
   /* Command-line options */
 static char *opt_output = NULL;
 static char *opt_user =	NULL;
 static char *opt_password = "asdbgetuser@";
 static char *opt_host = NULL;
 static char *opt_file = NULL;
+static char *opt_map  = NULL;
 
 static field_t *fields = NULL;	  /* List of fields. */
 static FILE *outf = NULL;	  /* Output file. */
@@ -127,6 +140,7 @@
 syntax ()
 {
 #ifdef HAVE_GETOPT_LONG
+#ifdef USE_LIB5250
   printf ("asdbget - Get and Translate AS/400 Database Files via FTP.\n\
 Syntax:\n\
   asdbget [options] HOST FILE\n\
@@ -135,8 +149,32 @@
   --output, -o OFILE            Specify output file (default: stdout).\n\
   --password, -p PASS           Specify the login password (default: %s).\n\
   --user, -u UNAME              Specify the login user (default: %s).\n\
-\n", opt_password, opt_user);
+  --map,  -m MAP                Specify the EBCDIC/ASCII Map (default: %s).\n\
+  \n", opt_password, opt_user, "en");
+#else /* USE_LIB5250 */
+  printf ("asdbget - Get and Translate AS/400 Database Files via FTP.\n\
+Syntax:\n\
+  asdbget [options] HOST FILE\n\
+\n\
+Options:\n\
+  --output, -o OFILE            Specify output file (default: stdout).\n\
+  --password, -p PASS           Specify the login password (default: %s).\n\
+  --user, -u UNAME              Specify the login user (default: %s).\n\
+  \n", opt_password, opt_user);
+#endif /* USE_LIB5250 */
 #else
+#ifdef USE_LIB5250
+  printf ("asdbget - Get and Translate AS/400 Database Files via FTP.\n\
+Syntax:\n\
+  asdbget [options] HOST FILE\n\
+\n\
+Options:\n\
+  -o OFILE                      Specify output file (default: stdout).\n\
+  -p PASS                       Specify the login password (default: %s).\n\
+  -u UNAME                      Specify the login user (default: %s).\n\
+  -m MAP                        Specify the EBCDIC/ASCII Map (default: %s).\n\
+\n", opt_password, opt_user, "en");
+#else /* USE_LIB5250 */
   printf ("asdbget - Get and Translate AS/400 Database Files via FTP.\n\
 Syntax:\n\
   asdbget [options] HOST FILE\n\
@@ -146,6 +184,7 @@
   -p PASS                       Specify the login password (default: %s).\n\
   -u UNAME                      Specify the login user (default: %s).\n\
 \n", opt_password, opt_user);
+#endif /* USE_LIB5250 */
 #endif
   exit (1);
 }
@@ -236,20 +275,34 @@
 
   /* WHFLDI */
   for (i = 0; i < 10; i++)
+#ifdef USE_LIB5250 
+    field->name[i] = tn5250_ebcdic2ascii(buf[129+i]);
+#else
     field->name[i] = e2a [buf[129+i]];
+#endif /* USE_LIB5250 */
+
   field->name[10] = 0;
   for (i = 9; i > 0 && field->name[i] == ' '; i--)
     field->name[i] = 0;
 
   /* WHFTXT */
   for (i = 0; i < 50; i++)
+#ifdef USE_LIB5250 
+    field->desc[i] = tn5250_ebcdic2ascii(buf[168+i]);
+#else
     field->desc[i] = e2a [buf[168+i]];
+#endif /* USE_LIB5250 */
+
   field->desc[50] = 0;
   for (i = 49; i > 0 && field->desc[i] == ' '; i--)
     field->desc[i] = 0;
 
   /* WHFLDT */
+#ifdef USE_LIB5250 
+  field->type = tn5250_ebcdic2ascii(buf[321]);
+#else
   field->type = e2a [buf[321]];
+#endif /* USE_LIB5250 */
   field->buffer_length = signed2int (buf + 159, 5);
   field->precision = signed2int (buf + 166, 2);
   field->is_key = 0;
@@ -361,10 +414,30 @@
 	      while (data[l-1] == 0x40 && l > 0)
 		l--;
 	      for (i = 0; i < l; i++)
+#ifdef USE_LIB5250 
+		*ptr++ = tn5250_ebcdic2ascii(data[i]);
+#else
 		*ptr++ = e2a[data[i]];
+#endif /* USE_LIB5250 */
 	      break;
 
+	    case 'Z': /* Timestamp fields */
+	      if (iter->length != 26) {
+		fprintf(stderr, "invalid TimeStamp len %d/26", iter->length);
+		assert (0);
+	      }
+
+	      for (i = 0; i < iter->length; i++)
+#ifdef USE_LIB5250
+		*ptr++ = tn5250_ebcdic2ascii(data[i]);
+#else
+		*ptr++ = e2a[data[i]];
+#endif /* USE_LIB5250 */
+	    
+	      break;
+ 
 	    default:
+	      fprintf(stderr, "unknown type %c", (char)iter->type);
 	      assert (0);
 	    }
 	  *ptr = 0;
@@ -405,10 +478,22 @@
 	  opt_user = optarg;
 	  break;
 
+#ifdef USE_LIB5250
+	case 'm':
+	  opt_map = optarg;
+	  break;
+#endif /* USE_LIB5250 */
+
 	default:
 	  syntax ();
 	}
     }
+#ifdef USE_LIB5250 
+  if (opt_map)
+    tn5250_settransmap(opt_map);
+  else
+    tn5250_settransmap("en");
+#endif /* USE_LIB5250 */
 
   if (optind >= argc)
     syntax ();
