static void parse_link_line (ParsingData *data) { char *from, *to, *old_from; GList *zone_list; /* We must have 3 fields for a Link. */ if (data->num_fields != 3) { fprintf (stderr, "%s:%i: Invalid Rule line - %i fields.\n%s\n", data->filename, data->line_number, data->num_fields, data->line); exit (1); } from = data->fields[LINK_FROM]; to = data->fields[LINK_TO]; #if 0 printf ("LINK FROM: %s\tTO: %s\n", from, to); #endif #if CREATE_SYMLINK { int len = strnlen(to,254); int dirs = 0; int i; for (i = 0; i < len; i++) { dirs += to[i] == '/' ? 1 : 0; } if (dirs >= 0) { char rel_from[255]; char to_dir[255]; char to_path[255]; if (dirs == 0) { sprintf(rel_from, "%s.ics", from); } else if (dirs == 1) { sprintf(rel_from, "../%s.ics", from); } else if (dirs == 2) { sprintf(rel_from, "../../%s.ics", from); } else { return; } sprintf(to_path, "%s/%s.ics", VzicOutputDir, to); strncpy(to_dir, to_path, 254); ensure_directory_exists(dirname(to_dir)); //printf("Creating symlink from %s to %s\n", rel_from, to_path); symlink(rel_from, to_path); } } #else if (g_hash_table_lookup_extended (data->link_data, from, (gpointer) &old_from, (gpointer) &zone_list)) { from = old_from; } else { from = g_strdup (from); zone_list = NULL; } zone_list = g_list_prepend (zone_list, g_strdup (to)); g_hash_table_insert (data->link_data, from, zone_list); #endif }
int main (int argc, char *argv[]) { int i; char directory[PATHNAME_BUFFER_SIZE]; char filename[PATHNAME_BUFFER_SIZE]; GHashTable *zones_hash; /* * Command-Line Option Parsing. */ for (i = 1; i < argc; i++) { /* * User Options. */ /* --pure: Output the perfect VCALENDAR data, which Outlook won't parse as it has problems with certain iCalendar constructs. */ if (!strcmp (argv[i], "--pure")) VzicPureOutput = TRUE; /* --output-dir: specify where to output all the files beneath. The default is the current directory. */ else if (argc > i + 1 && !strcmp (argv[i], "--output-dir")) VzicOutputDir = argv[++i]; /* --url-prefix: Used as the base for the TZURL property in each VTIMEZONE. The default is to not output TZURL properties. */ else if (argc > i + 1 && !strcmp (argv[i], "--url-prefix")) { int length; VzicUrlPrefix = argv[++i]; /* remove the trailing '/' if there is one */ length = strlen (VzicUrlPrefix); if (VzicUrlPrefix[length - 1] == '/') VzicUrlPrefix[length - 1] = '\0'; } else if (argc > i + 1 && !strcmp (argv[i], "--olson-dir")) { VzicOlsonDir = argv[++i]; } /* * Debugging Options. */ /* --dump: Dump the Rule and Zone data that we parsed from the Olson timezone files. This is used to test the parsing code. */ else if (!strcmp (argv[i], "--dump")) VzicDumpOutput = TRUE; /* --dump-changes: Dumps a list of times when each timezone changed, and the new local time offset from UTC. */ else if (!strcmp (argv[i], "--dump-changes")) VzicDumpChanges = TRUE; /* --no-rrules: Don't output RRULE properties in the VTIMEZONEs. Instead it will just output RDATEs for each year up to a certain year. */ else if (!strcmp (argv[i], "--no-rrules")) VzicNoRRules = TRUE; /* --no-rdates: Don't output multiple RDATEs in a single VTIMEZONE component. Instead they will be output separately. */ else if (!strcmp (argv[i], "--no-rdates")) VzicNoRDates = TRUE; else usage (); } /* * Create any necessary directories. */ ensure_directory_exists (VzicOutputDir); if (VzicDumpOutput) { /* Create the directories for the dump output, if they don't exist. */ sprintf (directory, "%s/ZonesVzic", VzicOutputDir); ensure_directory_exists (directory); sprintf (directory, "%s/RulesVzic", VzicOutputDir); ensure_directory_exists (directory); } if (VzicDumpChanges) { /* Create the directory for the changes output, if it doesn't exist. */ sprintf (directory, "%s/ChangesVzic", VzicOutputDir); ensure_directory_exists (directory); } /* * Convert the Olson timezone files. */ convert_olson_file ("africa"); convert_olson_file ("antarctica"); convert_olson_file ("asia"); convert_olson_file ("australasia"); convert_olson_file ("europe"); convert_olson_file ("northamerica"); convert_olson_file ("southamerica"); /* These are backwards-compatability and weird stuff. */ #if 0 convert_olson_file ("backward"); convert_olson_file ("etcetera"); convert_olson_file ("leapseconds"); convert_olson_file ("pacificnew"); convert_olson_file ("solar87"); convert_olson_file ("solar88"); convert_olson_file ("solar89"); #endif /* This doesn't really do anything and it messes up vzic-dump.pl so we don't bother. */ #if 0 convert_olson_file ("factory"); #endif /* This is old System V stuff, which we don't currently support since it uses 'min' as a Rule FROM value which messes up our algorithm, making it too slow and use too much memory. */ #if 0 convert_olson_file ("systemv"); #endif /* Output the timezone names and coordinates in a zone.tab file, and the translatable strings to feed to gettext. */ if (VzicDumpZoneNamesAndCoords) { sprintf (filename, "%s/zone.tab", VzicOlsonDir); zones_hash = parse_zone_tab (filename); dump_time_zone_names (VzicTimeZoneNames, VzicOutputDir, zones_hash); } return 0; }
int main(int argc, char* argv[]) { icalarray *zones; icaltimezone *zone; char *zone_directory, *zone_subdirectory, *zone_filename, *location; char output_directory[PATHNAME_BUFFER_SIZE]; char filename[PATHNAME_BUFFER_SIZE]; FILE *fp; int i; int skipping = TRUE; /* * Command-Line Option Parsing. */ for (i = 1; i < argc; i++) { /* --dump-changes: Dumps a list of times when each timezone changed, and the new local time offset from UTC. */ if (!strcmp (argv[i], "--dump-changes")) VzicDumpChanges = TRUE; else usage (); } zones = icaltimezone_get_builtin_timezones (); ensure_directory_exists (directory); for (i = 0; i < zones->num_elements; i++) { zone = icalarray_element_at (zones, i); location = icaltimezone_get_location (zone); #if 0 /* Use this to start at a certain zone. */ if (skipping && strcmp (location, "America/Boise")) continue; #endif skipping = FALSE; /* Use this to only output data for certain timezones. */ #if 0 if (strcmp (location, "America/Cancun") && strcmp (location, "Asia/Baku") && strcmp (location, "Asia/Nicosia") && strcmp (location, "Asia/Novosibirsk") && strcmp (location, "Asia/Samarkand") && strcmp (location, "Asia/Tashkent") && strcmp (location, "Asia/Tbilisi") && strcmp (location, "Asia/Yerevan") && strcmp (location, "Australia/Broken_Hill") && strcmp (location, "Europe/Simferopol") && strcmp (location, "Europe/Tallinn") && strcmp (location, "Europe/Zaporozhye") ) continue; #endif #if 0 printf ("%s\n", location); #endif parse_zone_name (location, &zone_directory, &zone_subdirectory, &zone_filename); sprintf (output_directory, "%s/%s", directory, zone_directory); ensure_directory_exists (output_directory); sprintf (filename, "%s/%s", output_directory, zone_filename); if (zone_subdirectory) { sprintf (output_directory, "%s/%s/%s", directory, zone_directory, zone_subdirectory); ensure_directory_exists (output_directory); sprintf (filename, "%s/%s", output_directory, zone_filename); } fp = fopen (filename, "w"); if (!fp) { fprintf (stderr, "Couldn't create file: %s\n", filename); exit (1); } /* We can run 2 different tests - output all changes for each zone, or test against mktime()/localtime(). Should have a command-line option or something. */ if (VzicDumpChanges) icaltimezone_dump_changes (zone, CHANGES_MAX_YEAR, fp); else dump_local_times (zone, fp); if (ferror (fp)) { fprintf (stderr, "Error writing file: %s\n", filename); exit (1); } fclose (fp); } return 0; }