ksh: remove BRACE_EXPAND

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ksh: remove BRACE_EXPAND

Anton Lindqvist-2
Hi,
Looks like all variants of ksh in the tree is compiled with BRACE_EXPAND
defined, therefore remove it. No binary change. While here, fix an endif
typo.

Comments? OK?

Index: config.h
===================================================================
RCS file: /cvs/src/bin/ksh/config.h,v
retrieving revision 1.17
diff -u -p -r1.17 config.h
--- config.h 5 Jan 2018 15:44:31 -0000 1.17
+++ config.h 11 Jan 2018 22:10:58 -0000
@@ -11,9 +11,6 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
-/* Include brace-expansion? */
-#define BRACE_EXPAND 1
-
 /* Include any history? */
 #define HISTORY 1
 
Index: emacs.c
===================================================================
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.82
diff -u -p -r1.82 emacs.c
--- emacs.c 8 Jan 2018 13:01:31 -0000 1.82
+++ emacs.c 11 Jan 2018 22:10:58 -0000
@@ -2132,4 +2132,4 @@ x_lastcp(void)
  return (xlp);
 }
 
-#endif /* EDIT */
+#endif /* EMACS */
Index: eval.c
===================================================================
RCS file: /cvs/src/bin/ksh/eval.c,v
retrieving revision 1.57
diff -u -p -r1.57 eval.c
--- eval.c 6 Jan 2018 16:28:58 -0000 1.57
+++ eval.c 11 Jan 2018 22:10:58 -0000
@@ -56,9 +56,7 @@ static void globit(XString *, char **, c
 static char *maybe_expand_tilde(char *, XString *, char **, int);
 static char   *tilde(char *);
 static char   *homedir(char *);
-#ifdef BRACE_EXPAND
 static void alt_expand(XPtrV *, char *, char *, char *, int);
-#endif
 
 /* compile and expand word */
 char *
@@ -180,10 +178,8 @@ expand(char *cp, /* input word */
  f &= ~DOGLOB;
  if (Flag(FMARKDIRS))
  f |= DOMARKDIRS;
-#ifdef BRACE_EXPAND
  if (Flag(FBRACEEXPAND) && (f & DOGLOB))
  f |= DOBRACE_;
-#endif /* BRACE_EXPAND */
 
  Xinit(ds, dp, 128, ATEMP); /* init dest. string */
  type = XBASE;
@@ -563,15 +559,12 @@ expand(char *cp, /* input word */
 
  *dp++ = '\0';
  p = Xclose(ds, dp);
-#ifdef BRACE_EXPAND
  if (fdo & DOBRACE_)
  /* also does globbing */
  alt_expand(wp, p, p,
     p + Xlength(ds, (dp - 1)),
     fdo | (f & DOMARKDIRS));
- else
-#endif /* BRACE_EXPAND */
- if (fdo & DOGLOB)
+ else if (fdo & DOGLOB)
  glob(p, wp, f & DOMARKDIRS);
  else if ((f & DOPAT) || !(fdo & DOMAGIC_))
  XPput(*wp, p);
@@ -628,7 +621,6 @@ expand(char *cp, /* input word */
  *dp++ = MAGIC;
  }
  break;
-#ifdef BRACE_EXPAND
  case OBRACE:
  case ',':
  case CBRACE:
@@ -638,7 +630,6 @@ expand(char *cp, /* input word */
  *dp++ = MAGIC;
  }
  break;
-#endif /* BRACE_EXPAND */
  case '=':
  /* Note first unquoted = for ~ */
  if (!(f & DOTEMP_) && !saw_eq) {
@@ -1221,7 +1212,6 @@ homedir(char *name)
  return ap->val.s;
 }
 
-#ifdef BRACE_EXPAND
 static void
 alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
 {
@@ -1296,4 +1286,3 @@ alt_expand(XPtrV *wp, char *start, char
  }
  return;
 }
-#endif /* BRACE_EXPAND */
Index: main.c
===================================================================
RCS file: /cvs/src/bin/ksh/main.c,v
retrieving revision 1.86
diff -u -p -r1.86 main.c
--- main.c 5 Jan 2018 15:44:31 -0000 1.86
+++ main.c 11 Jan 2018 22:10:58 -0000
@@ -226,9 +226,7 @@ main(int argc, char *argv[])
  * brace expansion, so set this before setting up FPOSIX
  * (change_flag() clears FBRACEEXPAND when FPOSIX is set).
  */
-#ifdef BRACE_EXPAND
  Flag(FBRACEEXPAND) = 1;
-#endif /* BRACE_EXPAND */
 
  /* set posix flag just before environment so that it will have
  * exactly the same effect as the POSIXLY_CORRECT environment
Index: misc.c
===================================================================
RCS file: /cvs/src/bin/ksh/misc.c,v
retrieving revision 1.65
diff -u -p -r1.65 misc.c
--- misc.c 6 Jan 2018 16:28:58 -0000 1.65
+++ misc.c 11 Jan 2018 22:10:58 -0000
@@ -121,9 +121,7 @@ const struct option sh_options[] = {
  * entries MUST match the order of sh_flag F* enumerations in sh.h.
  */
  { "allexport", 'a', OF_ANY },
-#ifdef BRACE_EXPAND
  { "braceexpand",  0, OF_ANY }, /* non-standard */
-#endif
  { "bgnice",  0, OF_ANY },
  { NULL, 'c',    OF_CMDLINE },
  { "csh-history",  0, OF_ANY }, /* non-standard */
@@ -301,10 +299,7 @@ change_flag(enum sh_flag f,
  setgroups(1, &gid);
  setresuid(ksheuid, ksheuid, ksheuid);
  } else if (f == FPOSIX && newval) {
-#ifdef BRACE_EXPAND
- Flag(FBRACEEXPAND) = 0
-#endif /* BRACE_EXPAND */
- ;
+ Flag(FBRACEEXPAND) = 0;
  }
  /* Changing interactive flag? */
  if (f == FTALKING) {
Index: sh.h
===================================================================
RCS file: /cvs/src/bin/ksh/sh.h,v
retrieving revision 1.68
diff -u -p -r1.68 sh.h
--- sh.h 6 Jan 2018 16:28:58 -0000 1.68
+++ sh.h 11 Jan 2018 22:10:58 -0000
@@ -132,9 +132,7 @@ extern const struct option sh_options[];
  */
 enum sh_flag {
  FEXPORT = 0, /* -a: export all */
-#ifdef BRACE_EXPAND
  FBRACEEXPAND, /* enable {} globbing */
-#endif
  FBGNICE, /* bgnice */
  FCOMMAND, /* -c: (invocation) execute specified command */
  FCSHHISTORY, /* csh-style history enabled */

Reply | Threaded
Open this post in threaded view
|

Re: ksh: remove BRACE_EXPAND

Jeremie Courreges-Anglas-2
On Sat, Jan 13 2018, Anton Lindqvist <[hidden email]> wrote:
> Hi,
> Looks like all variants of ksh in the tree is compiled with BRACE_EXPAND
> defined, therefore remove it. No binary change. While here, fix an endif
> typo.
>
> Comments? OK?

ok jca@

I have a diff to remove EDIT and HISTORY too.

--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply | Threaded
Open this post in threaded view
|

ksh: unifdef HISTORY/EDIT

Jeremie Courreges-Anglas-2
On Sun, Jan 14 2018, Jeremie Courreges-Anglas <[hidden email]> wrote:

> On Sat, Jan 13 2018, Anton Lindqvist <[hidden email]> wrote:
>> Hi,
>> Looks like all variants of ksh in the tree is compiled with BRACE_EXPAND
>> defined, therefore remove it. No binary change. While here, fix an endif
>> typo.
>>
>> Comments? OK?
>
> ok jca@
>
> I have a diff to remove EDIT and HISTORY too.

Building ksh without EMACS/VI/EDIT/HISTORY failed (not a new problem) so
let's get rid of EDIT and HISTORY to make the code more readable.  I'm
not touching other defines in config.h because they cost almost nothing
and I have another plan for DEFAULT_ENV.

ok?


Index: c_ksh.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/c_ksh.c,v
retrieving revision 1.56
diff -u -p -r1.56 c_ksh.c
--- c_ksh.c 6 Jan 2018 16:28:58 -0000 1.56
+++ c_ksh.c 14 Jan 2018 16:59:17 -0000
@@ -1384,9 +1384,7 @@ const struct builtin kshbuiltins [] = {
  {"+command", c_command},
  {"echo", c_print},
  {"*=export", c_typeset},
-#ifdef HISTORY
  {"+fc", c_fc},
-#endif /* HISTORY */
  {"+getopts", c_getopts},
  {"+jobs", c_jobs},
  {"+kill", c_kill},
Index: config.h
===================================================================
RCS file: /d/cvs/src/bin/ksh/config.h,v
retrieving revision 1.18
diff -u -p -r1.18 config.h
--- config.h 14 Jan 2018 16:04:21 -0000 1.18
+++ config.h 14 Jan 2018 16:59:17 -0000
@@ -11,9 +11,6 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
-/* Include any history? */
-#define HISTORY 1
-
 /* Strict POSIX behaviour? */
 /* #undef POSIXLY_CORRECT */
 
@@ -24,15 +21,8 @@
  * End of configuration stuff for PD ksh.
  */
 
-#if defined(EMACS) || defined(VI)
-# define EDIT
-#else
-# undef EDIT
+#if !defined(EMACS) && !defined(VI)
+# error "Define either EMACS or VI."
 #endif
-
-/* Editing implies history */
-#if defined(EDIT) && !defined(HISTORY)
-# define HISTORY
-#endif /* EDIT */
 
 #endif /* CONFIG_H */
Index: edit.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/edit.c,v
retrieving revision 1.61
diff -u -p -r1.61 edit.c
--- edit.c 6 Jan 2018 16:28:58 -0000 1.61
+++ edit.c 14 Jan 2018 16:59:17 -0000
@@ -6,7 +6,6 @@
  */
 
 #include "config.h"
-#ifdef EDIT
 
 #include <sys/ioctl.h>
 #include <sys/stat.h>
@@ -910,4 +909,3 @@ x_escape(const char *s, size_t len, int
 
  return (rval);
 }
-#endif /* EDIT */
Index: exec.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/exec.c,v
retrieving revision 1.70
diff -u -p -r1.70 exec.c
--- exec.c 27 Dec 2017 13:02:57 -0000 1.70
+++ exec.c 14 Jan 2018 16:59:17 -0000
@@ -1239,7 +1239,6 @@ herein(const char *content, int sub)
  return fd;
 }
 
-#ifdef EDIT
 /*
  * ksh special - the select command processing section
  * print the args in column form - assuming that we can
@@ -1365,7 +1364,6 @@ pr_list(char *const *ap)
 
  return n;
 }
-#endif /* EDIT */
 
 /*
  * [[ ... ]] evaluation routines
Index: history.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/history.c,v
retrieving revision 1.78
diff -u -p -r1.78 history.c
--- history.c 6 Jan 2018 16:28:58 -0000 1.78
+++ history.c 14 Jan 2018 16:59:17 -0000
@@ -25,8 +25,6 @@
 
 #include "sh.h"
 
-#ifdef HISTORY
-
 static void history_write(void);
 static FILE *history_open(void);
 static void history_load(Source *);
@@ -856,25 +854,3 @@ hist_finish(void)
 {
  history_close();
 }
-
-#else /* HISTORY */
-
-/* No history to be compiled in: dummy routines to avoid lots more ifdefs */
-void
-init_histvec(void)
-{
-}
-void
-hist_init(Source *s)
-{
-}
-void
-hist_finish(void)
-{
-}
-void
-histsave(int lno, const char *cmd, int dowrite)
-{
- errorf("history not enabled");
-}
-#endif /* HISTORY */
Index: lex.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/lex.c,v
retrieving revision 1.77
diff -u -p -r1.77 lex.c
--- lex.c 6 Jan 2018 16:28:58 -0000 1.77
+++ lex.c 14 Jan 2018 16:59:17 -0000
@@ -1086,14 +1086,13 @@ getsc_line(Source *s)
  ksh_tmout_state = TMOUT_READING;
  alarm(ksh_tmout);
  }
-#ifdef EDIT
  if (have_tty && (0
-# ifdef VI
+#ifdef VI
     || Flag(FVI)
-# endif /* VI */
-# ifdef EMACS
+#endif /* VI */
+#ifdef EMACS
     || Flag(FEMACS) || Flag(FGMACS)
-# endif /* EMACS */
+#endif /* EMACS */
     )) {
  int nread;
 
@@ -1102,10 +1101,7 @@ getsc_line(Source *s)
  nread = 0;
  xp[nread] = '\0';
  xp += nread;
- }
- else
-#endif /* EDIT */
- {
+ } else {
  if (interactive) {
  pprompt(prompt, 0);
  } else
@@ -1153,7 +1149,6 @@ getsc_line(Source *s)
  shf_fdclose(s->u.shf);
  s->str = NULL;
  } else if (interactive) {
-#ifdef HISTORY
  char *p = Xstring(s->xs, xp);
  if (cur_prompt == PS1)
  while (*p && ctype(*p, C_IFS) && ctype(*p, C_IFSWS))
@@ -1162,7 +1157,6 @@ getsc_line(Source *s)
  s->line++;
  histsave(s->line, s->str, 1);
  }
-#endif /* HISTORY */
  }
  if (interactive)
  set_prompt(PS2);
Index: lex.h
===================================================================
RCS file: /d/cvs/src/bin/ksh/lex.h,v
retrieving revision 1.20
diff -u -p -r1.20 lex.h
--- lex.h 6 Jan 2018 16:28:58 -0000 1.20
+++ lex.h 14 Jan 2018 16:59:17 -0000
@@ -105,14 +105,11 @@ extern YYSTYPE yylval; /* result from y
 extern struct ioword *heres[HERES], **herep;
 extern char ident[IDENT+1];
 
-#ifdef HISTORY
-# define HISTORYSIZE 500 /* size of saved history */
+#define HISTORYSIZE 500 /* size of saved history */
 
 extern char   **history; /* saved commands */
 extern char   **histptr; /* last history item */
 extern uint32_t histsize; /* history size */
-
-#endif /* HISTORY */
 
 int yylex(int);
 void yyerror(const char *, ...)
Index: main.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/main.c,v
retrieving revision 1.87
diff -u -p -r1.87 main.c
--- main.c 14 Jan 2018 16:04:21 -0000 1.87
+++ main.c 14 Jan 2018 16:59:17 -0000
@@ -69,9 +69,7 @@ int builtin_flag;
 char *current_wd;
 int current_wd_size;
 
-#ifdef EDIT
 int x_cols = 80;
-#endif /* EDIT */
 
 /*
  * shell initialization
@@ -94,9 +92,7 @@ static const char *initcoms [] = {
   "stop=kill -STOP",
   "autoload=typeset -fu",
   "functions=typeset -f",
-#ifdef HISTORY
   "history=fc -l",
-#endif /* HISTORY */
   "integer=typeset -i",
   "nohup=nohup ",
   "local=typeset",
@@ -249,12 +245,12 @@ main(int argc, char *argv[])
  /* Set edit mode to emacs by default, may be overridden
  * by the environment or the user.  Also, we want tab completion
  * on in vi by default. */
-#if defined(EDIT) && defined(EMACS)
+#if defined(EMACS)
  change_flag(FEMACS, OF_SPECIAL, 1);
-#endif /* EDIT && EMACS */
-#if defined(EDIT) && defined(VI)
+#endif /* EMACS */
+#if defined(VI)
  Flag(FVITABCOMPLETE) = 1;
-#endif /* EDIT && VI */
+#endif /* VI */
 
  /* import environment */
  if (environ != NULL)
@@ -367,11 +363,9 @@ main(int argc, char *argv[])
  i = Flag(FMONITOR) != 127;
  Flag(FMONITOR) = 0;
  j_init(i);
-#ifdef EDIT
  /* Do this after j_init(), as tty_fd is not initialized 'til then */
  if (Flag(FTALKING))
  x_init();
-#endif
 
  l = genv->loc;
  l->argv = make_argv(argc - (argi - 1), &argv[argi - 1]);
Index: misc.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/misc.c,v
retrieving revision 1.66
diff -u -p -r1.66 misc.c
--- misc.c 14 Jan 2018 16:04:21 -0000 1.66
+++ misc.c 14 Jan 2018 16:59:17 -0000
@@ -270,27 +270,25 @@ change_flag(enum sh_flag f,
  if (what != OF_CMDLINE && newval != oldval)
  j_change();
  } else
-#ifdef EDIT
  if (0
-# ifdef VI
+#ifdef VI
     || f == FVI
-# endif /* VI */
-# ifdef EMACS
+#endif /* VI */
+#ifdef EMACS
     || f == FEMACS || f == FGMACS
-# endif /* EMACS */
+#endif /* EMACS */
    )
  {
  if (newval) {
-# ifdef VI
+#ifdef VI
  Flag(FVI) = 0;
-# endif /* VI */
-# ifdef EMACS
+#endif /* VI */
+#ifdef EMACS
  Flag(FEMACS) = Flag(FGMACS) = 0;
-# endif /* EMACS */
+#endif /* EMACS */
  Flag(f) = newval;
  }
  } else
-#endif /* EDIT */
  /* Turning off -p? */
  if (f == FPRIVILEGED && oldval && !newval) {
  gid_t gid = getgid();
Index: sh.h
===================================================================
RCS file: /d/cvs/src/bin/ksh/sh.h,v
retrieving revision 1.69
diff -u -p -r1.69 sh.h
--- sh.h 14 Jan 2018 16:04:21 -0000 1.69
+++ sh.h 14 Jan 2018 16:59:17 -0000
@@ -338,18 +338,14 @@ extern int builtin_flag; /* flags of cal
 extern char *current_wd;
 extern int current_wd_size;
 
-#ifdef EDIT
 /* Minimum required space to work with on a line - if the prompt leaves less
  * space than this on a line, the prompt is truncated.
  */
-# define MIN_EDIT_SPACE 7
+#define MIN_EDIT_SPACE 7
 /* Minimum allowed value for x_cols: 2 for prompt, 3 for " < " at end of line
  */
-# define MIN_COLS (2 + MIN_EDIT_SPACE + 3)
+#define MIN_COLS (2 + MIN_EDIT_SPACE + 3)
 extern int x_cols; /* tty columns */
-#else
-# define x_cols 80 /* for pr_menu(exec.c) */
-#endif
 
 /* These to avoid bracket matching problems */
 #define OPAREN '('
@@ -451,7 +447,6 @@ void init_histvec(void);
 void hist_init(Source *);
 void hist_finish(void);
 void histsave(int, const char *, int);
-#ifdef HISTORY
 int c_fc(char **);
 void sethistcontrol(const char *);
 void sethistsize(int);
@@ -462,7 +457,6 @@ int findhist(int, int, const char *, int
 int findhistrel(const char *);
 char  **hist_get_newest(int);
 
-#endif /* HISTORY */
 /* io.c */
 void errorf(const char *, ...)
     __attribute__((__noreturn__, __format__ (printf, 1, 2)));
Index: var.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/var.c,v
retrieving revision 1.63
diff -u -p -r1.63 var.c
--- var.c 6 Jan 2018 16:28:58 -0000 1.63
+++ var.c 14 Jan 2018 16:59:17 -0000
@@ -97,15 +97,11 @@ initvar(void)
  { "PATH", V_PATH },
  { "POSIXLY_CORRECT", V_POSIXLY_CORRECT },
  { "TMPDIR", V_TMPDIR },
-#ifdef HISTORY
  { "HISTCONTROL", V_HISTCONTROL },
  { "HISTFILE", V_HISTFILE },
  { "HISTSIZE", V_HISTSIZE },
-#endif /* HISTORY */
-#ifdef EDIT
  { "EDITOR", V_EDITOR },
  { "VISUAL", V_VISUAL },
-#endif /* EDIT */
  { "MAIL", V_MAIL },
  { "MAILCHECK", V_MAILCHECK },
  { "MAILPATH", V_MAILPATH },
@@ -933,13 +929,11 @@ getspec(struct tbl *vp)
  setint(vp, (long) (rand() & 0x7fff));
  vp->flag |= SPECIAL;
  break;
-#ifdef HISTORY
  case V_HISTSIZE:
  vp->flag &= ~SPECIAL;
  setint(vp, (long) histsize);
  vp->flag |= SPECIAL;
  break;
-#endif /* HISTORY */
  case V_OPTIND:
  vp->flag &= ~SPECIAL;
  setint(vp, (long) user_opt.uoptind);
@@ -991,7 +985,6 @@ setspec(struct tbl *vp)
  tmpdir = str_save(s, APERM);
  }
  break;
-#ifdef HISTORY
  case V_HISTCONTROL:
  sethistcontrol(str_val(vp));
  break;
@@ -1003,8 +996,6 @@ setspec(struct tbl *vp)
  case V_HISTFILE:
  sethistfile(str_val(vp));
  break;
-#endif /* HISTORY */
-#ifdef EDIT
  case V_VISUAL:
  set_editmode(str_val(vp));
  break;
@@ -1026,7 +1017,6 @@ setspec(struct tbl *vp)
  x_cols = l;
  }
  break;
-#endif /* EDIT */
  case V_MAIL:
  mbset(str_val(vp));
  break;
@@ -1086,11 +1076,9 @@ unsetspec(struct tbl *vp)
  case V_MAILPATH:
  mpset(NULL);
  break;
-#ifdef HISTORY
  case V_HISTCONTROL:
  sethistcontrol(NULL);
  break;
-#endif
  case V_LINENO:
  case V_MAILCHECK: /* at&t ksh leaves previous value in place */
  case V_RANDOM:


--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE