Example #1
0
int main(int argc, char* argv[])
{
    date_t tempDate;
    long startAbs, endAbs;
    char *envStr;
    int envArgc;
    char *envArgv[40];		/* this should be big enough */

    progname = argv[0];

    set_default_city();
    if ((envStr = getenv(ENV_OPTS)) && strcmp(envStr, ""))
    {
        int i;

        tokenize(envStr, &envArgc, envArgv);
        for (i = 1; i < argc; i++)	/* append argv onto envArgv  */
            envArgv[envArgc++] = argv[i];
        handleArgs(envArgc, envArgv);
    }
    else
        handleArgs(argc, argv);

    tempDate.yy = theYear;
    if (theYear < (hebrewDates_sw ? 3761 : 1))
        die("Sorry, hebcal can only handle dates in the common era.", "");

    switch (rangeType)
    {
    case TODAY:
        printHebDates_sw = 1;
        tempDate.dd = theDay;
        tempDate.mm = theMonth;
        tempDate.yy = theYear;
        startAbs = endAbs = greg2abs(tempDate);
        break;
    case DAY:
        printHebDates_sw = 1;
        tempDate.dd = theDay;
        tempDate.mm = theMonth;
        tempDate.yy = theYear;
        if (hebrewDates_sw)
            startAbs = endAbs = hebrew2abs(tempDate);
        else
            startAbs = endAbs = greg2abs(tempDate);
        break;
    case MONTH:
        tempDate.dd = 1;
        tempDate.mm = theMonth;
        tempDate.yy = theYear;
        if (hebrewDates_sw)
        {
            startAbs = hebrew2abs(tempDate);
            tempDate.dd = max_days_in_heb_month(tempDate.mm, tempDate.yy);
            endAbs = hebrew2abs(tempDate);
        }
        else
        {
            startAbs = greg2abs(tempDate);
            tempDate.dd = MonthLengths[LEAP(theYear)][theMonth];
            endAbs = greg2abs(tempDate);
        }
        break;

    case YEAR:
        if (hebrewDates_sw)
        {
            tempDate.dd = 1;
            tempDate.mm = TISHREI;
            tempDate.yy = theYear;
            startAbs = hebrew2abs(tempDate);
	    /* start yearly calendar with the day before RH (i.e. Erev
	     * Rosh Hashanah)
	     */
	    startAbs--;

            tempDate.yy += numYears;
            endAbs = hebrew2abs(tempDate) - 1;
        }
        else
        {
            tempDate.dd = 1;
            tempDate.mm = JAN;
            tempDate.yy = theYear;
            startAbs = greg2abs(tempDate);

            tempDate.yy += numYears;
            endAbs = greg2abs(tempDate) - 1;
        }
        break;

    default:
        die("Oh, NO! internal error #17q!", "");
        /* this is dead code, but it silences some uninitialized variable 
           warnings in gcc   */
        startAbs = endAbs =0;
    }

    tempDate = abs2hebrew(startAbs);
    if (ok_to_run)
    {
        init_holidays(tempDate.yy);	/* load the holiday array */
        main_calendar(startAbs, endAbs);

        return 0;			/* success!  Kol hakavod to thorough programmers */
    }
    else
        return 1;
}
Example #2
0
int tester(char argvcity[40]) {
	FILE* f;
	char line[999];
	int lncnt = 0;
	char* lineitems[1000];
	char* parsurl[1000];
	char* parscityNC[1000];
	int b;

	// check for dbfile before doing anything
	f = fopen(db_file, "r");

	if (f == NULL) {
		printf("error reading db file: %s\n", db_file);
		return(1);
	}

	// read lines from db file. tokenize. then remove trailing space from string
	while (fgets(line, sizeof(line) - 1, f) != NULL) {
		lineitems[lncnt] = malloc(strlen(line) + 1);
		strcpy(lineitems[lncnt], line);
		lineitems[lncnt][strcspn(lineitems[lncnt], "\n")] = 0;	
	
		parsurl[lncnt]=strtok(lineitems[lncnt], ",");
		parscityNC[lncnt]=strtok(NULL, ",");
	
		parscityNC[lncnt][strlen(parscityNC[lncnt]) - 1] = '\0';
		lncnt++;
	}
	fclose(f);

	// list if -l flag is set
	if (l == 1) {
		for (b = 0; b < lncnt; b++) {
			printf("%s\n", parscityNC[b]);
		}
		printf("\nNum of cities: %d\n", lncnt);
		return(0);
	}	

	// see if there is a match
	int a;
	char newstring[40];

	// must strip capital letters out from argv0
	strcpy(newstring, argvcity);

	for (a = 0; newstring[a]; a++) {
		newstring[a] = tolower(newstring[a]);
	} 

	// now check for matching string and proceed to curl function
	int c;
	char citytopass[20];
	char urltopass[80];

	for (c = 0; c < lncnt; c++) {
		if (strcmp(newstring, parscityNC[c]) == 0) {
			strcpy(citytopass, parscityNC[c]);
			strcpy(urltopass, parsurl[c]);
		
			// if setting default		
			if (d == 1) {
				if (set_default_city(citytopass) != 0) {
					return(1);
				}
			}	
			// proceed to curl function to download xml file
			if (curl_func(citytopass, urltopass) == 0)
				return(0);
			else
				return(1);
		}
	}
	// otherwise no matching city/string
	printf("no match. try woc -l for city list\n");
	return(1);
}