| 1194 | // format file, as indicated by the -oc switch. |
| 1195 | |
| 1196 | flag FOutputCalendarFile(void) |
| 1197 | { |
| 1198 | char sz[cchSzMax]; |
| 1199 | CONST char *pch; |
| 1200 | FILE *file = NULL; |
| 1201 | int i, iMax, mon, day, yea; |
| 1202 | real tim; |
| 1203 | flag fRet = fFalse; |
| 1204 | CI *pci, ciT; |
| 1205 | |
| 1206 | if (us.fNoWrite) |
| 1207 | goto LDone; |
| 1208 | file = fopen(is.szFileOut, "w"); // Create and open the file for output. |
| 1209 | if (file == NULL) { |
| 1210 | sprintf(sz, "ICalendar file '%s' can not be created.", is.szFileOut); |
| 1211 | PrintError(sz); |
| 1212 | goto LDone; |
| 1213 | } |
| 1214 | |
| 1215 | GetTimeNow(&mon, &day, &yea, &tim, 0, 0); |
| 1216 | fprintf(file, "BEGIN:VCALENDAR\n"); |
| 1217 | fprintf(file, "VERSION:2.0\n"); |
| 1218 | fprintf(file, "PRODID:astrolog.org\n"); |
| 1219 | fprintf(file, "CALSCALE:GREGORIAN\n"); |
| 1220 | |
| 1221 | iMax = Max(is.cci, 1); |
| 1222 | for (i = 0; i < iMax; i++) { |
| 1223 | pci = iMax <= 1 ? &ciMain : &is.rgci[i]; |
| 1224 | if (!FBetween(pci->yea, -999, 9999)) { |
| 1225 | PrintWarning("Can't save this chart to iCalendar format because the " |
| 1226 | "Year field is more than 4 characters long."); |
| 1227 | goto LDone; |
| 1228 | } |
| 1229 | fprintf(file, "BEGIN:VEVENT\n"); |
| 1230 | pch = FSzSet(pci->nam) ? pci->nam : "Astrolog chart"; |
| 1231 | fprintf(file, "SUMMARY:%s\n", pch); |
| 1232 | fprintf(file, "DESCRIPTION:%s\\nhttp://www.astrolog.org/astrolog.htm\n", |
| 1233 | pch); |
| 1234 | fprintf(file, "LOCATION:%s\n", |
| 1235 | FSzSet(pci->loc) ? pci->loc : "Default location"); |
| 1236 | ciT = *pci; ciT.tim += rSmall; |
| 1237 | AdjustTimeZone(&ciT, 0, 0); |
| 1238 | sprintf(sz, "%04d%02d%02dT%02d%02d%02dZ", |
| 1239 | ciT.yea, ciT.mon, ciT.day, (int)ciT.tim, (int)(RFract(ciT.tim)*60.0), |
| 1240 | (int)(RFract(ciT.tim)*3600.0) % 60); |
| 1241 | fprintf(file, "DTSTART:%s\n", sz); |
| 1242 | fprintf(file, "DTEND:%s\n", sz); |
| 1243 | sprintf(sz, "%04d%02d%02dT%02d%02d%02dZ", |
| 1244 | yea, mon, day, (int)tim, (int)(RFract(tim)*60.0), |
| 1245 | (int)(RFract(tim)*3600.0) % 60); |
| 1246 | fprintf(file, "DTSTAMP:%s\n", sz); |
| 1247 | fprintf(file, "UID:astrolog.org_%s_%d\n", sz, i); |
| 1248 | fprintf(file, "URL:http://www.astrolog.org/astrolog.htm\n"); |
| 1249 | fprintf(file, "END:VEVENT\n"); |
| 1250 | } |
| 1251 | fprintf(file, "END:VCALENDAR\n"); |
| 1252 | |
| 1253 | fRet = fTrue; |
no test coverage detected