Read in the HadronZoo data file global.country.dat which provides a mapping of two letter country codes to country names. This file is expected to be in the HadronZoo data directory $HADRONZOO/data which is supplied as a part of the HadronZoo Suite download. Arguments: None

Return TypeFunction nameArguments
hzEcodeInitCountryCodes(void)

Declared in file: hzIpaddr.h
Defined in file : hzIpaddr.cpp

Function Logic:

0:START 1:fd 2:unknown 3:Return hzerr(E_INITFAIL,Cannot initialize shared memory segment (deltaCountryCodes)\n) 4:items items pCC_buf 5:unknown 6:Return hzerr(E_INITFAIL,Could not map Shared memory segment. Errno %d,errno) 7:items pShort s_CC_max items s_CC_offsets items pShort s_CC_buffer items 8:unknown 9:n 10:s_CC_div n s_CC_start items 11:Return rc

Function body:

hzEcode InitCountryCodes (void)
{
   //  Category: Internet
   //  
   //  Read in the HadronZoo data file global.country.dat which provides a mapping of two letter country codes to country names. This file is expected to be in
   //  the HadronZoo data directory $HADRONZOO/data which is supplied as a part of the HadronZoo Suite download.
   //  
   //  Arguments: None
   //  
   //  Returns: E_NODATA If the Country code source could not be established
   //     E_NOTFOUND If the Country code file does not exist
   //     E_OPENFAIL If the Country code file could not be opened
   //     E_READFAIL If the Country code file could not be read
   //     E_FORMAT If the Country code file does not have the expected format
   //     E_OK  If the Country code tables were initialized
   _hzfunc(__func__) ;
   ifstream    is ;        //  Input stream
   FSTAT       fs ;        //  File status
   char*       pCC_buf ;   //  Shared mem segment
   uint16_t*   pShort ;    //  Offsets in mem segment
   uint32_t    n ;         //  Buffer iterator
   int32_t     fd ;        //  Shered mem 'file descriptor'
   hzEcode     rc = E_OK ; //  Return code
    fd = shm_open("deltaCountryCodes", O_RDONLY, 0);
   if (fd < 0)
       return hzerr(E_INITFAIL, "Cannot initialize shared memory segment (deltaCountryCodes)\n") ;
   fstat(fd, &fs);
    threadLog("Set fd to %d\n", fd) ;
   pCC_buf = (char*) mmap(0,fs.st_size, PROT_READ, MAP_SHARED, fd, 0);
   if (!pCC_buf)
       return hzerr(E_INITFAIL, "Could not map Shared memory segment. Errno %d", errno) ;
   threadLog("Country codes mem at %p, size is %d\n", pCC_buf, fs.st_size) ;
   pShort = (uint16_t*) pCC_buf ;
   s_CC_max = *pShort++ ;
   threadLog("Total codes %d\n", s_CC_max) ;
   s_CC_offsets = pShort ;
   threadLog("Offsets at %p\n", s_CC_offsets) ;
   pShort += s_CC_max ;
   s_CC_buffer = (char*) pShort ;
   threadLog("Buffer at %p\n", s_CC_buffer) ;
   for (n = 2; n <&eq; s_CC_max ; n *= 2);
   s_CC_div = n / 2;
   s_CC_start = n - 1;
   threadLog("Total codes %d (div %d start %d)\n\n", s_CC_max, s_CC_div, s_CC_start) ;
   /*
   **  for (n = 0 ; n < s_CC_max ; n++)
   **    threadLog("%s -> %s (%d)\n", s_CC_buffer + s_CC_offsets[n], s_CC_buffer + s_CC_offsets[n] + 3, s_CC_offsets[n]) ;
   **      */
   return rc ;
}