home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / fontutils-0.6 / tfm / tfm_header.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-13  |  2.8 KB  |  93 lines

  1. /* tfm_header.c: deal with the TFM header bytes.
  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 "tfm.h"
  22.  
  23.  
  24. /* Set the header in TFM_INFO according to the string S.  */
  25.    
  26. void
  27. tfm_set_header (string s, tfm_global_info_type *tfm_info)
  28. {
  29.   string spec;
  30.  
  31.   /* If S is empty, we have nothing more to do.  */
  32.   if (s == NULL || *s == 0)
  33.     return;
  34.   
  35.   /* Parse the specification string.  */
  36.   for (spec = strtok (s, ","); spec != NULL; spec = strtok (NULL, ","))
  37.     {
  38.       string header_item;
  39.       string value_string = strchr (spec, ':');
  40.       
  41.       if (value_string == NULL)
  42.         FATAL1 ("TFM headers look like `<header-item>:<value>', not `%s'",
  43.              spec);
  44.  
  45.       header_item = substring (spec, 0, value_string - spec - 1);
  46.  
  47.       /* Advance past the `:'.  */
  48.       value_string++;
  49.       
  50.       if (STREQ (header_item, "checksum"))
  51.         {
  52.           if (!integer_ok (value_string))
  53.             FATAL1 ("%s: Invalid integer constant (for checksum)",
  54.                     value_string);
  55.         TFM_CHECKSUM (*tfm_info) = atoi (value_string);
  56.     }
  57.  
  58.       else if (STREQ (header_item, "designsize"))
  59.     {
  60.           if (!float_ok (value_string))
  61.             FATAL1 ("%s: Invalid floating-point constant (for designsize)",
  62.             value_string);
  63.           tfm_set_design_size (atof (value_string), tfm_info);
  64.         }
  65.  
  66.       else if (STREQ (header_item, "codingscheme"))
  67.     {
  68.           unsigned length = strlen (value_string);
  69.       
  70.           if (strchr (value_string, '(') != NULL
  71.           || strchr (value_string, ')') != NULL)
  72.             FATAL1 ("Your coding scheme `%s' may not contain parentheses",
  73.                     value_string);
  74.         
  75.           if (length > TFM_MAX_CODINGSCHEME_LENGTH)
  76.             WARNING3 ("Your coding scheme `%s' of length %d will be \
  77. truncated to %d", value_string, length, TFM_MAX_CODINGSCHEME_LENGTH);
  78.       
  79.       TFM_CODING_SCHEME (*tfm_info) = xstrdup (value_string);
  80.         }
  81.     }
  82. }
  83.  
  84. /* Set the design and font size of TFM_INFO to DESIGN_SIZE.  */
  85.  
  86. void
  87. tfm_set_design_size (real design_size, tfm_global_info_type *tfm_info)
  88. {
  89.   TFM_CHECK_DESIGN_SIZE (design_size);
  90.   TFM_DESIGN_SIZE (*tfm_info) = design_size;
  91.   tfm_set_fontsize (tfm_info);
  92. }
  93.