gnome-control-center/archiver/util.c

114 lines
2.4 KiB
C
Raw Normal View History

/* -*- mode: c; style: linux -*- */
/* util.c
2001-01-12 14:40:26 +00:00
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Written by Bradford Hovinen (hovinen@ximian.com)
*
* 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., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
/* Read a fixed-digit number from a string, advancing the string
* pointer. Return TRUE if the extraction was successful, FALSE if
* there was no number to extract or if the number was too short.
*/
gboolean
extract_number (char **str, int *number, int digits)
{
char buf[64];
if (!isdigit (**str)) return FALSE;
if (digits > 63) digits = 63;
strncpy (buf, *str, digits);
buf[digits] = '\0';
*number = atoi (buf);
if (strlen (buf) < digits) return FALSE;
*str += digits;
return TRUE;
}
struct tm *
parse_date (char *str)
{
struct tm *date;
gboolean ok;
gint value;
ok = extract_number (&str, &value, 4);
if (!ok) return NULL;
date = g_new (struct tm, 1);
Make backend_id const 2001-09-07 Bradford Hovinen <hovinen@ximian.com> * archiver-client.c (location_client_store_xml): Make backend_id const * util.c (parse_date): Set the time zone (parse_date): Initialize tm_isdst * archiver-client.c (location_client_store_xml): Call ConfigArchiver_Location_storageComplete when done (location_client_store_xml): Don't try to save the XML file if there was an error getting the storage filename * location.c (location_storage_complete): Implement (impl_ConfigArchiver_Location_storageComplete): Implement * config-log.c (config_log_get_backend_id_for_id): Make return value const 2001-09-04 Bradford Hovinen <hovinen@ximian.com> * location.c (location_get_storage_filename): Notify listeners that new rollback data is available * bonobo-config-archiver.c (new_rollback_cb): Implement (bonobo_config_archiver_new): Connect above to event source * location.c (location_store): (location_init): Construct an event source and add its interface * Makefile.am (INCLUDES): Remove -DDEFAULTS_DIR 2001-09-03 Bradford Hovinen <hovinen@ximian.com> * bonobo-config-archiver.c (bonobo_config_archiver_new): Accept complete moniker as an argument; do the parsing here * archiver-client.c (location_client_load_rollback_data): Adjust time from mktime according to time zone information * bonobo-moniker-archiver.c (is_leap_year): (mod_date_by_str): Implement (parse_name): Use correct math for computing offsets * bonobo-config-archiver.c (bonobo_config_archiver_new): Don't print an error message if the parent moniker is bad (bonobo_config_archiver_new): Remove debugging messages * archiver-client.c (location_client_load_rollback_data): Make date and backend_id const * bonobo-moniker-archiver.c (archiverdb_resolve): Determine date from moniker and pass to bonobo_config_archiver_new * bonobo-config-archiver.c (bonobo_config_archiver_new): Accept date structure as argument
2001-09-12 15:30:41 +00:00
date->tm_isdst = 0;
date->tm_year = value - 1900;
date->tm_mon = 11;
date->tm_mday = 31;
date->tm_hour = 23;
date->tm_min = 59;
date->tm_sec = 59;
if (extract_number (&str, &value, 2))
date->tm_mon = value - 1;
else
return date;
if (extract_number (&str, &value, 2))
date->tm_mday = value;
else
return date;
if (extract_number (&str, &value, 2))
date->tm_hour = value;
else
return date;
if (extract_number (&str, &value, 2))
date->tm_min = value;
else
return date;
if (extract_number (&str, &value, 2))
date->tm_sec = value;
#ifdef __USE_BSD
Make backend_id const 2001-09-07 Bradford Hovinen <hovinen@ximian.com> * archiver-client.c (location_client_store_xml): Make backend_id const * util.c (parse_date): Set the time zone (parse_date): Initialize tm_isdst * archiver-client.c (location_client_store_xml): Call ConfigArchiver_Location_storageComplete when done (location_client_store_xml): Don't try to save the XML file if there was an error getting the storage filename * location.c (location_storage_complete): Implement (impl_ConfigArchiver_Location_storageComplete): Implement * config-log.c (config_log_get_backend_id_for_id): Make return value const 2001-09-04 Bradford Hovinen <hovinen@ximian.com> * location.c (location_get_storage_filename): Notify listeners that new rollback data is available * bonobo-config-archiver.c (new_rollback_cb): Implement (bonobo_config_archiver_new): Connect above to event source * location.c (location_store): (location_init): Construct an event source and add its interface * Makefile.am (INCLUDES): Remove -DDEFAULTS_DIR 2001-09-03 Bradford Hovinen <hovinen@ximian.com> * bonobo-config-archiver.c (bonobo_config_archiver_new): Accept complete moniker as an argument; do the parsing here * archiver-client.c (location_client_load_rollback_data): Adjust time from mktime according to time zone information * bonobo-moniker-archiver.c (is_leap_year): (mod_date_by_str): Implement (parse_name): Use correct math for computing offsets * bonobo-config-archiver.c (bonobo_config_archiver_new): Don't print an error message if the parent moniker is bad (bonobo_config_archiver_new): Remove debugging messages * archiver-client.c (location_client_load_rollback_data): Make date and backend_id const * bonobo-moniker-archiver.c (archiverdb_resolve): Determine date from moniker and pass to bonobo_config_archiver_new * bonobo-config-archiver.c (bonobo_config_archiver_new): Accept date structure as argument
2001-09-12 15:30:41 +00:00
date->tm_zone = "GMT";
date->tm_gmtoff = 0;
#endif
Make backend_id const 2001-09-07 Bradford Hovinen <hovinen@ximian.com> * archiver-client.c (location_client_store_xml): Make backend_id const * util.c (parse_date): Set the time zone (parse_date): Initialize tm_isdst * archiver-client.c (location_client_store_xml): Call ConfigArchiver_Location_storageComplete when done (location_client_store_xml): Don't try to save the XML file if there was an error getting the storage filename * location.c (location_storage_complete): Implement (impl_ConfigArchiver_Location_storageComplete): Implement * config-log.c (config_log_get_backend_id_for_id): Make return value const 2001-09-04 Bradford Hovinen <hovinen@ximian.com> * location.c (location_get_storage_filename): Notify listeners that new rollback data is available * bonobo-config-archiver.c (new_rollback_cb): Implement (bonobo_config_archiver_new): Connect above to event source * location.c (location_store): (location_init): Construct an event source and add its interface * Makefile.am (INCLUDES): Remove -DDEFAULTS_DIR 2001-09-03 Bradford Hovinen <hovinen@ximian.com> * bonobo-config-archiver.c (bonobo_config_archiver_new): Accept complete moniker as an argument; do the parsing here * archiver-client.c (location_client_load_rollback_data): Adjust time from mktime according to time zone information * bonobo-moniker-archiver.c (is_leap_year): (mod_date_by_str): Implement (parse_name): Use correct math for computing offsets * bonobo-config-archiver.c (bonobo_config_archiver_new): Don't print an error message if the parent moniker is bad (bonobo_config_archiver_new): Remove debugging messages * archiver-client.c (location_client_load_rollback_data): Make date and backend_id const * bonobo-moniker-archiver.c (archiverdb_resolve): Determine date from moniker and pass to bonobo_config_archiver_new * bonobo-config-archiver.c (bonobo_config_archiver_new): Accept date structure as argument
2001-09-12 15:30:41 +00:00
return date;
}
2001-08-20 15:47:57 +00:00
struct tm *
dup_date (const struct tm *date)
{
struct tm *date1;
date1 = g_new (struct tm, 1);
memcpy (date1, date, sizeof (struct tm));
return date1;
}