navit
0.5.3-trunk
|
#include <stdlib.h>
#include <glib.h>
#include <ctype.h>
#include <stdarg.h>
#include <time.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include "util.h"
#include "debug.h"
#include "config.h"
Data Structures | |
struct | spawn_process_info |
Enumerations | |
enum | parse_state { parse_state_whitespace , parse_state_numeric , parse_state_alpha } |
Parser states for parse_for_systematic_comparison() . More... | |
Functions | |
void | strtoupper (char *dest, const char *src) |
void | strtolower (char *dest, const char *src) |
unsigned int | uint_sqrt (unsigned int n) |
Fast compute of square root for unsigned ints. More... | |
int | navit_utf8_strcasecmp (const char *s1, const char *s2) |
static void | strtrim (char *s) |
Trims all leading and trailing whitespace characters from a string. More... | |
char * | str_escape (enum escape_mode mode, const char *in) |
Escape special characters from a string. More... | |
char * | strncpy_unescape (char *dest, const char *src, size_t n) |
Copy a string from src to dest , unescaping characters. More... | |
static char * | parse_for_systematic_comparison (const char *s) |
Parses a string for systematic comparison. More... | |
int | compare_name_systematic (const char *s1, const char *s2) |
Compares two name_systematic strings. More... | |
static void | hash_callback (gpointer key, gpointer value, gpointer user_data) |
GList * | g_hash_to_list (GHashTable *h) |
static void | hash_callback_key (gpointer key, gpointer value, gpointer user_data) |
GList * | g_hash_to_list_keys (GHashTable *h) |
gchar * | g_strconcat_printf (gchar *buffer, gchar *fmt,...) |
Appends a formatted string and appends it to an existing one. More... | |
int | g_utf8_strlen_force_link (gchar *buffer, int max) |
void | square_shape_str (char *s) |
Optimizes the format of a string, adding carriage returns so that when displayed, the result text zone is roughly as wide as high. More... | |
unsigned int | iso8601_to_secs (char *iso8601) |
Converts an ISO 8601-style time string into epoch time. More... | |
time_t | mkgmtime (struct tm *pt) |
Converts a tm structure to time_t More... | |
time_t | iso8601_to_time (char *iso8601) |
Converts an ISO 8601-style time string into time_t . More... | |
char * | time_to_iso8601 (time_t time) |
Converts time to ISO8601 format. More... | |
char * | current_to_iso8601 (void) |
Outputs local system time in ISO 8601 format. More... | |
char * | shell_escape (char *arg) |
static char * | spawn_process_compose_cmdline (char **argv) |
struct spawn_process_info * | spawn_process (char **argv) |
int | spawn_process_check_status (struct spawn_process_info *pi, int block) |
void | spawn_process_info_free (struct spawn_process_info *pi) |
void | spawn_process_init () |
void | get_compass_direction (char *buffer, int angle, int mode) |
Get printable compass direction from an angle. More... | |
enum parse_state |
Parser states for parse_for_systematic_comparison()
.
Enumerator | |
---|---|
parse_state_whitespace | |
parse_state_numeric | |
parse_state_alpha |
int compare_name_systematic | ( | const char * | s1, |
const char * | s2 | ||
) |
Compares two name_systematic strings.
A name_systematic string is typically used for road reference numbers (A 4, I-51, SP526). This function performs a fuzzy comparison: Each string is broken down into numeric and non-numeric parts. Then both strings are compared part by part. The following rules apply:
s1
and s2
is returned. equals
'42'`. Partial matches are currently determined by determining each part of one string with each part of the other. Each part of one string that is matched by at least one part of the other increases the score. Order is currently not taken into account, i.e. ‘'42A’and
'A-42A'are both considered full (not partial) matches for
'A42'`. Future versions may change this.
s1 | The first string |
s2 | The second string |
MAX_MISMATCH
indicates a complete mismatch; values in between indicate partial matches (lower values correspond to better matches). References dbg, elements, lvl_debug, MAX_MISMATCH, parse_for_systematic_comparison(), and s1.
Referenced by traffic_location_match_attributes(), traffic_point_match_attributes(), and traffic_point_match_segment_attributes().
char* current_to_iso8601 | ( | void | ) |
Outputs local system time in ISO 8601 format.
References time_to_iso8601().
Referenced by main(), vehicle_demo_position_attr_get(), and vehicle_log_gpx().
GList* g_hash_to_list | ( | GHashTable * | h | ) |
References hash_callback().
Referenced by graphics_free().
GList* g_hash_to_list_keys | ( | GHashTable * | h | ) |
References hash_callback_key().
gchar* g_strconcat_printf | ( | gchar * | buffer, |
gchar * | fmt, | ||
... | |||
) |
Appends a formatted string and appends it to an existing one.
Usage is similar to the familiar C functions that take a format string and a variable argument list.
Return value is a concatenation of buffer
(unless it is NULL) and fmt
, with the remaining arguments inserted into fmt
.
buffer | An existing string, can be null and will be freed by this function |
fmt | A format string (will not be altered) |
Referenced by attr_to_text_ext(), flags_to_text(), generate_navitintrospectxml(), gui_internal_append_attr(), gui_internal_cmd_img(), gui_internal_onclick(), request_navit_route_export_geojson(), traffic_traff_android_set_selection(), and vehicle_log_gpx().
int g_utf8_strlen_force_link | ( | gchar * | buffer, |
int | max | ||
) |
References max.
void get_compass_direction | ( | char * | buffer, |
int | angle, | ||
int | mode | ||
) |
Get printable compass direction from an angle.
This function supports three different modes:
In mode 0, the angle in degrees is output as a string.
In mode 1, the angle is output as a cardinal direction (N, SE etc.).
In mode 2, the angle is output in analog clock notation (6 o'clock).
buffer | Buffer to hold the result string (up to 5 characters, including the terminating null character, may be required) |
angle | The angle to convert |
mode | The conversion mode, see description |
Referenced by gui_internal_cmd_pois_item(), and model_poi().
|
static |
References value.
Referenced by g_hash_to_list().
|
static |
References key.
Referenced by g_hash_to_list_keys().
unsigned int iso8601_to_secs | ( | char * | iso8601 | ) |
Converts an ISO 8601-style time string into epoch time.
iso8601 | Time in ISO 8601 format. |
References startup::pos.
Referenced by navit_layout_switch(), osd_text_format_attr(), and tracking_update().
time_t iso8601_to_time | ( | char * | iso8601 | ) |
Converts an ISO 8601-style time string into time_t
.
References dbg, lvl_debug, mkgmtime(), and startup::pos.
Referenced by time_new().
time_t mkgmtime | ( | struct tm * | pt | ) |
Converts a tm
structure to time_t
Returns the value of type time_t
that represents the UTC time described by the tm
structure pointed to by pt
(which may be modified).
This function performs the reverse translation that gmtime()
does. As this functionality is absent in the standard library, it is emulated by calling mktime()
, converting its output into both GMT and local time, comparing the results and calling mktime()
again with an input adjusted for the offset in the opposite direction. This ensures maximum portability.
The values of the tm_wday
and tm_yday
members of pt
are ignored, and the values of the other members are interpreted even if out of their valid ranges (see struct tm
). For example, tm_mday
may contain values above 31, which are interpreted accordingly as the days that follow the last day of the selected month.
A call to this function automatically adjusts the values of the members of pt
if they are off-range or—in the case of tm_wday
and tm_yday
—if their values are inconsistent with the other members.
References dbg, and lvl_debug.
Referenced by iso8601_to_time().
int navit_utf8_strcasecmp | ( | const char * | s1, |
const char * | s2 | ||
) |
References dbg, lvl_debug, and s1.
Referenced by contains_suffix(), and search_list_get_result().
|
static |
Parses a string for systematic comparison.
This is a helper function for compare_name_systematic()
.
The string is broken down into numeric and non-numeric parts. Whitespace characters are discarded unless they are surrounded by string characters, in which case the whole unit is treated as one string part. All strings are converted to lowercase and leading zeroes stripped from numbers.
s | The string to parse |
References c, dbg, lvl_debug, parse_state_alpha, parse_state_numeric, parse_state_whitespace, part, and strtrim().
Referenced by compare_name_systematic().
char* shell_escape | ( | char * | arg | ) |
Escape and quote string for shell
in | arg string to escape |
Referenced by spawn_process_compose_cmdline().
struct spawn_process_info* spawn_process | ( | char ** | argv | ) |
Call external program
in | argv NULL terminated list of parameters, zeroeth argument is program name |
References argv, dbg, exit, lvl_debug, lvl_error, spawn_process_info::pid, spawn_process_compose_cmdline(), and spawn_process_info::status.
Referenced by speechd_say().
int spawn_process_check_status | ( | struct spawn_process_info * | pi, |
int | block | ||
) |
Check external program status
in | *pi pointer to spawn_process_info structure |
in | block =0 do not block =1 block until child terminated |
References dbg, lvl_debug, lvl_error, spawn_process_info::pid, and spawn_process_info::status.
Referenced by speechd_say().
|
static |
References argv, and shell_escape().
Referenced by spawn_process().
void spawn_process_info_free | ( | struct spawn_process_info * | pi | ) |
Referenced by speechd_destroy(), and speechd_say().
void spawn_process_init | ( | void | ) |
Referenced by main_init().
void square_shape_str | ( | char * | s | ) |
Optimizes the format of a string, adding carriage returns so that when displayed, the result text zone is roughly as wide as high.
[in,out] | s | The string to proces (will be modified by this function, but length will be unchanged) |
References c, dbg, lvl_debug, and uint_sqrt().
Referenced by navit_populate_search_results_map().
char* str_escape | ( | enum escape_mode | mode, |
const char * | in | ||
) |
Escape special characters from a string.
mode | The escape mode that needs to be enabled (see enum escape_mode) |
in | The string to escape |
References dbg, escape_mode_html, escape_mode_html_amp, escape_mode_html_apos, escape_mode_html_gt, escape_mode_html_lt, escape_mode_html_quote, escape_mode_quote, escape_mode_string, and lvl_debug.
Referenced by gui_internal_append_attr(), gui_internal_cmd_escape(), gui_internal_cmd_img(), gui_internal_onclick(), and write_former_destinations().
char* strncpy_unescape | ( | char * | dest, |
const char * | src, | ||
size_t | n | ||
) |
Copy a string from src
to dest
, unescaping characters.
[out] | dest | The location where to store the unescaped string |
[in] | src | The source string to copy (and to unescape) |
n | The maximum amount of bytes copied into dest. Warning: If there is no null byte among the n bytes written to dest, the string placed in dest will not be null-terminated. |
dest
References startup::dest.
Referenced by attr_from_line().
void strtolower | ( | char * | dest, |
const char * | src | ||
) |
References startup::dest.
Referenced by espeak_new(), file_process_headers(), gui_internal_search(), qt5_espeak_init_language(), search_list_country_new(), and svg_debug_image_new().
void strtoupper | ( | char * | dest, |
const char * | src | ||
) |
Navit, a modular navigation system. Copyright (C) 2005-2008 Navit Team
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
References startup::dest.
|
static |
Trims all leading and trailing whitespace characters from a string.
Whitespace characters are all up to and including 0x20.
This function operates in-place, i.e. s
will be modified.
s | The string to trim |
Referenced by parse_for_systematic_comparison().
char* time_to_iso8601 | ( | time_t | time | ) |
Converts time to ISO8601 format.
The caller is responsible for freeing the return value of this function when it is no longer needed.
time | The time, as returned by time() and related functions |
Referenced by current_to_iso8601(), traffic_dump_messages_to_xml(), and traffic_message_dump_to_stderr().
unsigned int uint_sqrt | ( | unsigned int | n | ) |
Fast compute of square root for unsigned ints.
n | The input number |
References p.
Referenced by draw_shape(), and square_shape_str().