/[pspp]/pspp/src/vars-atr.c
ViewVC logotype

Diff of /pspp/src/vars-atr.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by blp, Tue Mar 1 08:16:16 2005 UTC revision 1.17 by blp, Sat Mar 12 01:08:33 2005 UTC
# Line 28  Line 28 
28  #include "expressions/public.h"  #include "expressions/public.h"
29  #include "file-handle.h"  #include "file-handle.h"
30  #include "hash.h"  #include "hash.h"
31    #include "lexer.h"
32  #include "misc.h"  #include "misc.h"
33  #include "str.h"  #include "str.h"
34  #include "value-labels.h"  #include "value-labels.h"
# Line 230  is_user_missing (const union value *val, Line 231  is_user_missing (const union value *val,
231    abort ();    abort ();
232  }  }
233    
234    /* Returns true if NAME is an acceptable name for a variable,
235       false otherwise.  If ISSUE_ERROR is true, issues an
236       explanatory error message on failure. */
237    bool
238    var_is_valid_name (const char *name, bool issue_error)
239    {
240      size_t length, i;
241      
242      assert (name != NULL);
243    
244      length = strlen (name);
245      if (length < 1)
246        {
247          if (issue_error)
248            msg (SE, _("Variable names must be at least 1 character long."));
249          return false;
250        }
251      else if (length > MAX_VAR_NAME_LEN)
252        {
253          if (issue_error)
254            msg (SE, _("Variable name %s exceeds %d-character limit."),
255                 (int) MAX_VAR_NAME_LEN);
256          return false;
257        }
258    
259      for (i = 0; i < length; i++)
260        if (!CHAR_IS_IDN (name[i]))
261          {
262            if (issue_error)
263              msg (SE, _("Character `%c' (in %s) may not appear in "
264                         "a variable name."),
265                   name);
266            return false;
267          }
268            
269      if (!CHAR_IS_ID1 (name[0]))
270        {
271          if (issue_error)
272            msg (SE, _("Character `%c' (in %s), may not appear "
273                       "as the first character in a variable name."), name);
274          return false;
275        }
276    
277      if (lex_id_to_token (name, strlen (name)) != T_ID)
278        {
279          if (issue_error)
280            msg (SE, _("%s may not be used as a variable name because it "
281                       "is a reserved word."), name);
282          return false;
283        }
284    
285      return true;
286    }
287    
288  /* A hsh_compare_func that orders variables A and B by their  /* A hsh_compare_func that orders variables A and B by their
289     names. */     names. */
290  int  int

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26