home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / BASH_112.ZIP / BASH-112.TAR / bash-1.12 / flags.c < prev    next >
C/C++ Source or Header  |  1991-12-29  |  7KB  |  229 lines

  1. /* flags.c -- Everything about flags except the `set' command.  That
  2.    is in builtins.c */
  3.  
  4. /* Copyright (C) 1987,1989 Free Software Foundation, Inc.
  5.  
  6. This file is part of GNU Bash, the Bourne Again SHell.
  7.  
  8. Bash is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free
  10. Software Foundation; either version 1, or (at your option) any later
  11. version.
  12.  
  13. Bash is distributed in the hope that it will be useful, but WITHOUT ANY
  14. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License along
  19. with Bash; see the file COPYING.  If not, write to the Free Software
  20. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  21.  
  22. /* Flags hacking. */
  23.  
  24. #include "config.h"
  25. #include "flags.h"
  26. #include "general.h"
  27. #include "quit.h"
  28.  
  29. /* **************************************************************** */
  30. /*                                    */
  31. /*            The Standard Sh Flags.                */
  32. /*                                    */
  33. /* **************************************************************** */
  34.  
  35. /* Non-zero means automatically mark variables which are modified or created
  36.    as auto export variables. */
  37. int mark_modified_vars = 0;
  38.  
  39. /* Non-zero causes asynchronous job notification.  Otherwise, job state
  40.    notification only takes place just before a primary prompt is printed. */
  41. int asynchronous_notification = 0;
  42.  
  43. /* Non-zero means exit immediately if a command exits with a non-zero
  44.    exit status. */
  45. int exit_immediately_on_error = 0;
  46.  
  47. /* Non-zero means disable filename globbing. */
  48. int disallow_filename_globbing = 0;
  49.  
  50. /* Non-zero means to locate and remember function commands as functions are
  51.    defined.  Function commands are normally located when the function is
  52.    executed. */
  53. int locate_commands_in_functions = 0;
  54.  
  55. /* Non-zero means that all keyword arguments are placed into the environment
  56.    for a command, not just those that appear on the line before the command
  57.    name. */
  58. int place_keywords_in_env = 0;
  59.  
  60. /* Non-zero means read commands, but don't execute tham.  This is useful
  61.    for debugging shell scripts that should do something hairy and possibly
  62.    desctructive. */
  63. int read_but_dont_execute = 0;
  64.  
  65. /* Non-zero means end of file is after one command. */
  66. int just_one_command = 0;
  67.  
  68. /* Non-zero means don't overwrite existing files while doing redirections. */
  69. int noclobber = 0;
  70.  
  71. /* Non-zero means trying to get the value of $i where $i is undefined
  72.    causes an error, instead of a null substitution. */
  73. int unbound_vars_is_error = 0;
  74.  
  75. /* Non-zero means type out input lines after you read them. */
  76. int echo_input_at_read = 0;
  77.  
  78. /* Non-zero means type out the command definition after reading, but
  79.    before executing. */
  80. int echo_command_at_execute = 0;
  81.  
  82. /* Non-zero means turn off the job control features. */
  83. int jobs_m_flag = 0;
  84.  
  85. /* Non-zero means this shell is interactive, even if running under a
  86.    pipe. */
  87. int forced_interactive = 0;
  88.  
  89. /* **************************************************************** */
  90. /*                                    */
  91. /*             Non-Standard Flags Follow Here.            */
  92. /*                                    */
  93. /* **************************************************************** */
  94.  
  95.  
  96. /* Non-zero means do lexical scoping in the body of a FOR command. */
  97. int lexical_scoping = 0;
  98.  
  99. /* Non-zero means no such thing as invisible variables. */
  100. int no_invisible_vars = 0;
  101.  
  102. /* Non-zero means don't look up or remember command names in a hash table, */
  103. int hashing_disabled = 0;
  104.  
  105. /* Non-zero means that we are doing history expansion.  The default.
  106.    This means !22 gets the 22nd line of history. */
  107. int history_expansion = 1;
  108.  
  109. /* **************************************************************** */
  110. /*                                    */
  111. /*            The Flags ALIST.                */
  112. /*                                    */
  113. /* **************************************************************** */
  114.  
  115. struct flags_alist shell_flags[] = {
  116.  
  117.   /* Standard sh flags. */
  118.   { "a", &mark_modified_vars },
  119. #if defined (JOB_CONTROL)
  120.   { "b", &asynchronous_notification },
  121. #endif /* JOB_CONTROL */
  122.   { "e", &exit_immediately_on_error },
  123.   { "f", &disallow_filename_globbing },
  124.   { "h", &locate_commands_in_functions }, /* Oh, yeah, good mnemonic. */
  125.   { "i", &forced_interactive },
  126.   { "k", &place_keywords_in_env },
  127.   { "n", &read_but_dont_execute },
  128.   { "t", &just_one_command },
  129.   { "u", &unbound_vars_is_error },
  130.   { "v", &echo_input_at_read },
  131.   { "x", &echo_command_at_execute },
  132.   { "C", &noclobber },
  133.  
  134. #if defined (JOB_CONTROL)
  135.   { "m", &jobs_m_flag },
  136. #endif
  137.  
  138.   /* New flags that control non-standard things. */
  139.   { "l", &lexical_scoping },
  140.   { "I", &no_invisible_vars },
  141.  
  142.   /* I want `h', but locate_commands_in_functions has it.  Great. */
  143.   { "d", &hashing_disabled },
  144.  
  145.   /* Once again, we don't have the right mnemonic. */
  146.   { "H", &history_expansion },
  147.  
  148.   {(char *)NULL, (int *)NULL}
  149. };
  150.  
  151.  
  152. int *
  153. find_flag (name)
  154.      char *name;
  155. {
  156.   int i = 0;
  157.   while (shell_flags[i].name) {
  158.     if (strcmp (shell_flags[i].name, name) == 0)
  159.       return (shell_flags[i].value);
  160.     i++;
  161.   }
  162.   return ((int *)FLAG_ERROR);
  163. }
  164.  
  165. /* Change the state of a flag, and return it's original value, or return
  166.    FLAG_ERROR if there is no flag called NAME.  ON_OR_OFF should be one
  167.    of FLAG_ON or FLAG_OFF. */
  168.  
  169. /* With FLAG being a character. */
  170. change_flag_char (flag, on_or_off)
  171.      int flag;
  172.      int on_or_off;
  173. {
  174.   char name[2];
  175.   name[0] = flag; name[1] = '\0';
  176.   return (change_flag (name, on_or_off));
  177. }
  178.  
  179. /* With FLAG being a string. */
  180. change_flag (flag, on_or_off)
  181.   char *flag;
  182.   int on_or_off;
  183. {
  184.   int *value = find_flag (flag);
  185.   int old_value;
  186.  
  187.   if (value == (int *)FLAG_ERROR) return (FLAG_ERROR);
  188.   else old_value = *value;
  189.  
  190.   if (on_or_off == FLAG_ON)
  191.     *value = 1;
  192.   else
  193.     {
  194.       if (on_or_off == FLAG_OFF)
  195.     *value = 0;
  196.       else
  197.     return (FLAG_ERROR);
  198.     }
  199.  
  200. #if defined (JOB_CONTROL)
  201.   /* Special hack for the -m flag. */
  202.   if (value == &jobs_m_flag)
  203.     {
  204.       extern set_job_control ();
  205.       set_job_control (on_or_off == '-');
  206.     }
  207. #endif /* JOB_CONTROL */
  208.     
  209.   return (old_value);
  210. }
  211.  
  212. /* Return a string which is the names of all the currently
  213.    set shell flags. */
  214. char *
  215. which_set_flags ()
  216. {
  217.   char *temp =
  218.     (char *)xmalloc (1 + sizeof (shell_flags) / (2 * sizeof (char *)));
  219.  
  220.   int index, string_index = 0;
  221.  
  222.   for (index = 0; shell_flags[index].name; index++)
  223.     if (*(shell_flags[index].value))
  224.       temp[string_index++] = *(shell_flags[index].name);
  225.  
  226.   temp[string_index] = '\0';
  227.   return (temp);
  228. }
  229.