VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /usr/share/emscripten/tests/poppler/poppler/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/emscripten/tests/poppler/poppler/NameToCharCode.cc
//========================================================================
//
// NameToCharCode.cc
//
// Copyright 2001-2003 Glyph & Cog, LLC
//
//========================================================================

#include <config.h>

#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif

#include <string.h>
#include "goo/gmem.h"
#include "NameToCharCode.h"

//------------------------------------------------------------------------

struct NameToCharCodeEntry {
  char *name;
  CharCode c;
};

//------------------------------------------------------------------------

NameToCharCode::NameToCharCode() {
  int i;

  size = 31;
  len = 0;
  tab = (NameToCharCodeEntry *)gmallocn(size, sizeof(NameToCharCodeEntry));
  for (i = 0; i < size; ++i) {
    tab[i].name = NULL;
  }
}

NameToCharCode::~NameToCharCode() {
  int i;

  for (i = 0; i < size; ++i) {
    if (tab[i].name) {
      gfree(tab[i].name);
    }
  }
  gfree(tab);
}

void NameToCharCode::add(char *name, CharCode c) {
  NameToCharCodeEntry *oldTab;
  int h, i, oldSize;

  // expand the table if necessary
  if (len >= size / 2) {
    oldSize = size;
    oldTab = tab;
    size = 2*size + 1;
    tab = (NameToCharCodeEntry *)gmallocn(size, sizeof(NameToCharCodeEntry));
    for (h = 0; h < size; ++h) {
      tab[h].name = NULL;
    }
    for (i = 0; i < oldSize; ++i) {
      if (oldTab[i].name) {
	h = hash(oldTab[i].name);
	while (tab[h].name) {
	  if (++h == size) {
	    h = 0;
	  }
	}
	tab[h] = oldTab[i];
      }
    }
    gfree(oldTab);
  }

  // add the new name
  h = hash(name);
  while (tab[h].name && strcmp(tab[h].name, name)) {
    if (++h == size) {
      h = 0;
    }
  }
  if (!tab[h].name) {
    tab[h].name = copyString(name);
  }
  tab[h].c = c;

  ++len;
}

CharCode NameToCharCode::lookup(char *name) {
  int h;

  h = hash(name);
  while (tab[h].name) {
    if (!strcmp(tab[h].name, name)) {
      return tab[h].c;
    }
    if (++h == size) {
      h = 0;
    }
  }
  return 0;
}

int NameToCharCode::hash(char *name) {
  char *p;
  unsigned int h;

  h = 0;
  for (p = name; *p; ++p) {
    h = 17 * h + (int)(*p & 0xff);
  }
  return (int)(h % size);
}

VaKeR 2022