Back to index

lightning-sunbird  0.9+nobinonly
Functions
pango-utils.h File Reference
#include <stdio.h>
#include <glib.h>
#include "pango-types.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * pangolite_trim_string (const char *str)
 pangolite_trim_string: : a string
char ** pangolite_split_file_list (const char *str)
 pangolite_split_file_list: : a comma separated list of filenames
gint pangolite_read_line (FILE *stream, GString *str)
 pangolite_read_line: : a stdio stream : #GString buffer into which to write the result
gboolean pangolite_skip_space (const char **pos)
 pangolite_skip_space: : in/out string position
gboolean pangolite_scan_word (const char **pos, GString *out)
 pangolite_scan_word: : in/out string position : a #GString into which to write the result
gboolean pangolite_scan_string (const char **pos, GString *out)
 pangolite_scan_string: : in/out string position : a #GString into which to write the result
gboolean pangolite_scan_int (const char **pos, int *out)
char * pangolite_config_key_get (const char *key)
 pangolite_config_key_get: : Key to look up, in the form "SECTION/KEY".
const char * pangolite_get_sysconf_subdirectory (void)
const char * pangolite_get_lib_subdirectory (void)

Function Documentation

char* pangolite_config_key_get ( const char *  key)

pangolite_config_key_get: : Key to look up, in the form "SECTION/KEY".

Look up a key in the pangolite config database (pseudo-win.ini style, read from $sysconfdir/pangolite/pangoliterc, ~/.pangoliterc, and getenv (PANGO_RC_FILE).)

Return value: the value, if found, otherwise NULL. The value is a newly-allocated string and must be freed with g_free().

Definition at line 673 of file pango-utils.c.

{
  g_return_val_if_fail (key != NULL, NULL);
  
  read_config ();

  return g_strdup (g_hash_table_lookup (config_hash, key));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 703 of file pango-utils.c.

{
#ifdef G_OS_WIN32
  static gchar *result = NULL;

  if (result == NULL)
    result = g_win32_get_package_installation_subdirectory
      ("pangolite", g_strdup_printf ("pangolite-%s.dll", PANGO_VERSION), "lib\\pangolite");

  return result;
  // Open to any other way of doing this
  // Bottomline : need to provide path to pangolite libraries
  // Currently set to dist/bin - Open to other locations
#else
  char *tmp = getenv("MOZILLA_FIVE_HOME");
  return tmp;
  /*  return "/home/prabhath/PROJ/opt/lib"; */
#endif
}

Here is the caller graph for this function:

Definition at line 683 of file pango-utils.c.

{
#ifdef G_OS_WIN32
  static gchar *result = NULL;

  if (result == NULL)
    result = g_win32_get_package_installation_subdirectory
      ("pangolite", g_strdup_printf ("pangolite-%s.dll", PANGO_VERSION), "etc\\pangolite");

  return result;
  // Am open to any other way of doing this
  // Bottomline : need to provide path to pango.modules
  /* Currently set to dist/bin - Am open to other location */
#else
  char *tmp = getenv("MOZILLA_FIVE_HOME");
  return tmp;
#endif
}

Here is the caller graph for this function:

gint pangolite_read_line ( FILE stream,
GString *  str 
)

pangolite_read_line: : a stdio stream : #GString buffer into which to write the result

Read an entire line from a file into a buffer. Lines may be delimited with '
', '', '
', or '
'. The delimiter is not written into the buffer. Text after a '#' character is treated as a comment and skipped. '\' can be used to escape a # character. '\' proceding a line delimiter combines adjacent lines. A '\' proceding any other character is ignored and written into the output buffer unmodified.

Return value: 0 if the stream was already at an EOF character, otherwise the number of lines read (this is useful for maintaining a line number counter which doesn't combine lines with )

Definition at line 215 of file pango-utils.c.

{
  gboolean quoted = FALSE;
  gboolean comment = FALSE;
  int n_read = 0;
  int lines = 1;
  
  flockfile (stream);

  g_string_truncate (str, 0);
  
  while (1)
    {
      int c;
      
      c = getc_unlocked (stream);

      if (c == EOF)
       {
         if (quoted)
           g_string_append_c (str, '\\');
         
         goto done;
       }
      else
       n_read++;

      if (quoted)
       {
         quoted = FALSE;
         
         switch (c)
           {
           case '#':
             g_string_append_c (str, '#');
             break;
           case '\r':
           case '\n':
             {
              int next_c = getc_unlocked (stream);

              if (!(next_c == EOF ||
                    (c == '\r' && next_c == '\n') ||
                    (c == '\n' && next_c == '\r')))
                ungetc (next_c, stream);

              lines++;
              
              break;
             }
           default:
             g_string_append_c (str, '\\');            
             g_string_append_c (str, c);
           }
       }
      else
       {
         switch (c)
           {
           case '#':
             comment = TRUE;
             break;
           case '\\':
             if (!comment)
              quoted = TRUE;
             break;
           case '\n':
             {
              int next_c = getc_unlocked (stream);

              if (!(c == EOF ||
                    (c == '\r' && next_c == '\n') ||
                    (c == '\n' && next_c == '\r')))
                ungetc (next_c, stream);

              goto done;
             }
           default:
             if (!comment)
              g_string_append_c (str, c);
           }
       }
    }

 done:

  funlockfile (stream);

  return (n_read > 0) ? lines : 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean pangolite_scan_int ( const char **  pos,
int out 
)

Definition at line 459 of file pango-utils.c.

{
  int i = 0;
  char buf[32];
  const char *p = *pos;

  while (isspace (*p))
    p++;
  
  if (*p < '0' || *p > '9')
    return FALSE;

  while ((*p >= '0') && (*p <= '9') && i < sizeof(buf))
    {
      buf[i] = *p;
      i++;
      p++;
    }

  if (i == sizeof(buf))
    return FALSE;
  else
    buf[i] = '\0';

  *out = atoi (buf);

  return TRUE;
}
gboolean pangolite_scan_string ( const char **  pos,
GString *  out 
)

pangolite_scan_string: : in/out string position : a #GString into which to write the result

Scan a string into a #GString buffer. The string may either be a sequence of non-white-space characters, or a quoted string with '"'. Instead a quoted string, '"' represents a literal quote. Leading white space outside of quotes is skipped.

Return value: FALSE if a parse error occured.

Definition at line 383 of file pango-utils.c.

{
  const char *p = *pos;
  
  while (isspace (*p))
    p++;

  if (!*p)
    return FALSE;
  else if (*p == '"')
    {
      gboolean quoted = FALSE;
      g_string_truncate (out, 0);

      p++;

      while (TRUE)
       {
         if (quoted)
           {
             int c = *p;
             
             switch (c)
              {
              case '\0':
                return FALSE;
              case 'n':
                c = '\n';
                break;
              case 't':
                c = '\t';
                break;
              }
             
             quoted = FALSE;
             g_string_append_c (out, c);
           }
         else
           {
             switch (*p)
              {
              case '\0':
                return FALSE;
              case '\\':
                quoted = TRUE;
                break;
              case '"':
                p++;
                goto done;
              default:
                g_string_append_c (out, *p);
                break;
              }
           }
         p++;
       }
    done:
      ;
    }
  else
    {
      g_string_truncate (out, 0);

      while (*p && !isspace (*p))
       {
         g_string_append_c (out, *p);
         p++;
       }
    }

  *pos = p;

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean pangolite_scan_word ( const char **  pos,
GString *  out 
)

pangolite_scan_word: : in/out string position : a #GString into which to write the result

Scan a word into a #GString buffer. A word consists of [A-Za-z_] followed by zero or more [A-Za-z_0-9] Leading white space is skipped.

Return value: FALSE if a parse error occured.

Definition at line 340 of file pango-utils.c.

{
  const char *p = *pos;

  while (isspace (*p))
    p++;
  
  if (!((*p >= 'A' && *p <= 'Z') ||
       (*p >= 'a' && *p <= 'z') ||
       *p == '_'))
    return FALSE;

  g_string_truncate (out, 0);
  g_string_append_c (out, *p);
  p++;

  while ((*p >= 'A' && *p <= 'Z') ||
        (*p >= 'a' && *p <= 'z') ||
        (*p >= '0' && *p <= '9') ||
        *p == '_')
    {
      g_string_append_c (out, *p);
      p++;
    }

  *pos = p;

  return TRUE;
}

Here is the caller graph for this function:

gboolean pangolite_skip_space ( const char **  pos)

pangolite_skip_space: : in/out string position

Skips 0 or more characters of white space.

Return value: FALSE if skipping the white space leaves the position at a '\0' character.

Definition at line 316 of file pango-utils.c.

{
  const char *p = *pos;
  
  while (isspace (*p))
    p++;

  *pos = p;

  return !(*p == '\0');
}

Here is the caller graph for this function:

char** pangolite_split_file_list ( const char *  str)

pangolite_split_file_list: : a comma separated list of filenames

Split a G_SEARCHPATH_SEPARATOR-separated list of files, stripping white space and subsituting ~/ with $HOME/

Return value: a list of strings to be freed with g_strfreev()

Definition at line 149 of file pango-utils.c.

{
  int i = 0;
  int j;
  char **files;

  files = g_strsplit (str, G_SEARCHPATH_SEPARATOR_S, -1);

  while (files[i])
    {
      char *file = pangolite_trim_string (files[i]);

      /* If the resulting file is empty, skip it */
      if (file[0] == '\0')
       {
         g_free(file);
         g_free (files[i]);
         
         for (j = i + 1; files[j]; j++)
           files[j - 1] = files[j];
         
         files[j - 1] = NULL;

         continue;
       }
#ifndef G_OS_WIN32
      /* '~' is a quite normal and common character in file names on
       * Windows, especially in the 8.3 versions of long file names, which
       * still occur and then. Also, few Windows user are aware of the
       * Unix shell convention that '~' stands for the home directory,
       * even if they happen to have a home directory.
       */
      if (file[0] == '~' && file[1] == G_DIR_SEPARATOR)
       {
         char *tmp = g_strconcat (g_get_home_dir(), file + 1, NULL);
         g_free (file);
         file = tmp;
       }
#endif
      g_free (files[i]);
      files[i] = file;
       
      i++;
    }

  return files;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* pangolite_trim_string ( const char *  str)

pangolite_trim_string: : a string

Trim leading and trailing whitespace from a string.

Return value: A newly allocated string that must be freed with g_free()

Definition at line 123 of file pango-utils.c.

{
  int len;

  g_return_val_if_fail (str != NULL, NULL);
  
  while (*str && isspace (*str))
    str++;

  len = strlen (str);
  while (len > 0 && isspace (str[len-1]))
    len--;

  return g_strndup (str, len);
}

Here is the caller graph for this function: