home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / lib / charspec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-19  |  1.7 KB  |  64 lines

  1. /* charspec.c: parse a character code or name.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include <ctype.h>
  22. #include "charspec.h"
  23. #include "encoding.h"
  24.  
  25.  
  26. charcode_type
  27. xparse_charspec (string spec, encoding_info_type *enc)
  28. {
  29.   int code;
  30.   
  31.   /* It's an error to call this with SPEC == NULL or the empty string.  */
  32.   assert (spec != NULL && *spec);
  33.  
  34.   if (isdigit (*spec))
  35.     code = xparse_charcode (spec);
  36.  
  37.   else if (enc == NULL)
  38.     {
  39.       /* If ENC is null, and SPEC is longer than a single character, we
  40.          don't know what to do.  */
  41.       if (spec[1] != 0)
  42.     FATAL1 ("%s: Unparseable character specification", spec);
  43.       else
  44.         code = *spec;
  45.     }
  46.  
  47.   else
  48.     {
  49.       int code = encoding_number (*enc, spec);
  50.  
  51.       /* If SPEC is not in the encoding, and it's one character long,
  52.          just use its value as a C integer.  */
  53.       if (code == -1)
  54.         {
  55.           if (spec[1] == 0)
  56.             code = spec[0];
  57.           else
  58.             FATAL1 ("%s: Undefined character name", spec);
  59.     }
  60.     }
  61.   
  62.   return (charcode_type) code;
  63. }
  64.