Back to index

lightning-sunbird  0.9+nobinonly
copycluster.c
Go to the documentation of this file.
00001 /* -*- Mode: C -*-
00002   ======================================================================
00003   FILE: copycluster.c
00004   CREATOR: eric 15 January 2000
00005   
00006   $Id: copycluster.c,v 1.15 2002/07/16 10:04:08 acampi Exp $
00007   $Locker:  $
00008     
00009  (C) COPYRIGHT 2000 Eric Busboom
00010  http://www.softwarestudio.org
00011 
00012  The contents of this file are subject to the Mozilla Public License
00013  Version 1.0 (the "License"); you may not use this file except in
00014  compliance with the License. You may obtain a copy of the License at
00015  http://www.mozilla.org/MPL/
00016  
00017  Software distributed under the License is distributed on an "AS IS"
00018  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00019  the License for the specific language governing rights and
00020  limitations under the License.
00021  
00022  The Original Code is eric. The Initial Developer of the Original
00023  Code is Eric Busboom
00024 
00025 
00026  ======================================================================*/
00027 
00028 #include <stdio.h> /* for printf */
00029 #include <errno.h>
00030 #include <string.h> /* For strerror */
00031 #include <signal.h> /* for signal */
00032 #include <unistd.h> /* for alarm */
00033 #include <stdlib.h> /* for exit */
00034 
00035 #include "ical.h"
00036 #include "icalss.h"
00037 
00038 static void sig_alrm(int i){
00039     fprintf(stderr,"Could not get lock on file\n");
00040     exit(1);
00041 }
00042 /* This program copies a file that holds iCal components to an other file. */
00043 
00044 
00045 void usage(char* arg0) {
00046     printf("usage: %s cluster-file1 cluster-file2\n",arg0);
00047 }
00048 
00049 int main(int c, char *argv[]){
00050 
00051     icalset *clusterin, *clusterout;
00052     icalcomponent *itr;
00053     int count=0;
00054     int tostdout = 0;
00055 
00056     if(c < 2 || c > 3){
00057        usage(argv[0]);
00058        exit(1);
00059     }
00060 
00061     if (c == 2){
00062        tostdout = 1;
00063     }
00064 
00065 
00066     /*icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL);*/
00067 
00068     signal(SIGALRM,sig_alrm);
00069 
00070     alarm(10);
00071     clusterin = icalfileset_new(argv[1]);
00072     alarm(0);
00073 
00074     if (clusterin == 0){
00075        printf("Could not open input cluster \"%s\"\n",argv[1]);
00076        if(icalerrno!= ICAL_NO_ERROR){
00077           printf("Error: %s\n",icalerror_strerror(icalerrno));
00078         }
00079        exit(1);
00080     }
00081 
00082     if (!tostdout){
00083         alarm(10);
00084        clusterout = icalfileset_new(argv[2]);
00085        alarm(0);
00086        if (clusterout == 0){
00087            printf("Could not open output cluster \"%s\"\n",argv[2]);
00088            exit(1);
00089        }
00090     }
00091 
00092 
00093     for (itr = icalset_get_first_component(clusterin);
00094         itr != 0;
00095         itr = icalset_get_next_component(clusterin)){
00096 
00097         icalerror_set_error_state(ICAL_BADARG_ERROR, ICAL_ERROR_NONFATAL);
00098        icalrestriction_check(itr);
00099         icalerror_set_error_state(ICAL_BADARG_ERROR, ICAL_ERROR_DEFAULT);
00100 
00101        if (itr != 0){
00102 
00103            if(tostdout){
00104 
00105               printf("--------------\n%s\n",icalcomponent_as_ical_string(itr));
00106 
00107            } else {
00108 
00109               icalfileset_add_component(clusterout,
00110                                      icalcomponent_new_clone(itr));
00111            }
00112            
00113            count++;
00114 
00115        } else {
00116            printf("Got NULL component");
00117        }
00118     }
00119 
00120 
00121     printf("Transfered %d components\n",count);
00122 
00123     icalset_free(clusterin);
00124 
00125     if (!tostdout){
00126        icalfileset_mark(clusterout);
00127        icalset_free(clusterout);
00128     }
00129 
00130      return 0;
00131 }
00132 
00133