File: charname.c

package info (click to toggle)
recode 3.4.1-11
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,560 kB
  • ctags: 622
  • sloc: ansic: 10,572; perl: 339; makefile: 317; lisp: 243; sh: 173; lex: 165; awk: 127; sed: 10
file content (90 lines) | stat: -rw-r--r-- 2,372 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Conversion of files between different charsets and usages.
   Copyright (C) 1993 Free Software Foundation, Inc.
   Francois Pinard <pinard@iro.umontreal.ca>, 1993.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "recode.h"

#include "charname.h"

/*--------------------------------------------------------------------.
| Return a statically allocated full charname associated with a given |
| SYMBOL, or NULL if not found.					      |
`--------------------------------------------------------------------*/

char *
symbol_to_charname (const char *symbol)
{
  static char result[MAX_CHARNAME_LENGTH + 1];
  int first;
  int last;
  int middle;
  int value;
  const char *in;
  char *out;
  const char *cursor;

  /* Find the symbol by binary searching the charname table.  */

  first = 0;
  last = NUMBER_OF_CHARNAMES;
  while (first < last)
    {
      middle = (first + last) / 2;
      value = strcmp (charname[middle].symbol, symbol);
      if (value < 0)
	first = middle + 1;
      else if (value > 0)
	last = middle;
      else
	break;
    }

  /* If the symbol has not been found, return the NULL string.  */

  if (first >= last)
    return NULL;

  /* Else, construct the resulting charname.  */

  out = NULL;
  for (in = charname[middle].crypted; *in; in++)
    {

      /* Decrypt the next word.  */

      value = *(const unsigned char *) in - 1;
      if (value >= NUMBER_OF_SINGLES)
	value = (NUMBER_OF_SINGLES + 255 * (value - NUMBER_OF_SINGLES)
		 + *(const unsigned char *) ++in - 1);

      /* Copy it.  */

      if (out)
	*out++ = ' ';
      else
	out = result;

      for (cursor = word[value]; *cursor; cursor++)
	*out++ = *cursor;
    }

  /* Return the result.  */

  *out = '\0';
  return result;
}