/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "numdate.p" */ #include /*numdatep, bfile,*/ /* numdate: convert tomdate format to a single number Dr. Thomas D. Schneider National Institutes of Health National Cancer Institute Center for Cancer Research Nanobiology Program Molecular Information Theory Group Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu (use only if first address fails) http://www.ccrnp.ncifcrf.gov/~toms/ */ /* end of program */ /* begin module version */ #define version 1.02 /* of numdate.p 2007 Jan 08 2007 Jan 08, 1.02: daydate function 2007 Jan 07, 1.01: write result 2007 Jan 07, 1.00: origin, functional read */ #define updateversion 1.00 /* defines lowest acceptable current parameter file */ Static jmp_buf _JL1; /* end module version */ /* begin module describe.numdate */ /* name numdate: convert tomdate format to a single number synopsis numdate(input: in, numdatep: in, bfile: out, output: out) files input: a tomdate bfile: not used numdatep: parameters to control the program. The file must contain the following parameters, one per line: parameterversion: The version number of the program. This allows the user to be warned if an old parameter file is used. Currently not used. output: messages to the user description The tomdate format is year, month, day, hour, minute, second compressed and in that order: 2007Jan07.15:14:42 This program converts the date to a real number. examples documentation see also {tomdate script} author Thomas Dana Schneider bugs technical notes */ /* end module describe.numdate */ /* var numdatep, (* file used by this program *) bfile: text; (* file used by this program *) */ /* begin module halt */ Static Void halt() { /* stop the program. the procedure performs a goto to the end of the program. you must have a label: label 1; declared, and also the end of the program must have this label: 1: end. examples are in the module libraries. this is the only goto in the delila system. */ printf(" program halt.\n"); longjmp(_JL1, 1); } /* end module halt version = 'delmod 6.16 84 mar 12 tds/gds'; */ /* begin module fail */ Static Void fail() { printf("PARSE FAILED\n"); halt(); } #define debugging false /* are we to give debugging messages? */ typedef Char monthtype[3]; /* end module fail */ /* (* begin module daydate *) procedure daydate(month: integer): integer; (* convert month to days of the year *) begin end; (* end module daydate *) */ /* begin module numdate.themain */ Static Void themain() { /*(var numdatep, bfile: text)*/ /* the main procedure of the program */ /* parameterversion: real; (* parameter version number *) totalseconds: real; (* computed number *) */ long year; /* year */ Char c; /* a character read */ monthtype monthstring; /* month as three characters */ /* month: integer; (* month as an integer *) */ long monthday = -1; /* month as days into the year */ long day; /* day of month */ long hour; /* hour of day */ long minute; /* minute of hour */ long second; /* second of minute */ double days; /* total days */ double hours; /* total hours */ double minutes; /* total minutes */ double seconds; /* total seconds */ /*zzz*/ if (debugging) printf("numdate %4.2f\n", version); /* reset(numdatep); readln(numdatep, parameterversion); if round(100*parameterversion) < round(100*updateversion) then begin writeln(output, 'You have an old parameter file!'); halt end; */ if (P_eof(stdin)) /* can't handle */ fail(); /* example input: 2007Jan07.15:14:42 */ scanf("%ld", &year); if (debugging) printf("%ld\n", year); *monthstring = getchar(); monthstring[1] = getchar(); monthstring[2] = getchar(); if (monthstring[0] == '\n') monthstring[0] = ' '; if (monthstring[1] == '\n') monthstring[1] = ' '; if (monthstring[2] == '\n') monthstring[2] = ' '; if (debugging) printf("%.3s\n", monthstring); /* month := -1; if monthstring = 'Jan' then month := 0; if monthstring = 'Feb' then month := 1; if monthstring = 'Mar' then month := 2; if monthstring = 'Apr' then month := 3; if monthstring = 'May' then month := 4; if monthstring = 'Jun' then month := 5; if monthstring = 'Jul' then month := 6; if monthstring = 'Aug' then month := 7; if monthstring = 'Sep' then month := 8; if monthstring = 'Oct' then month := 9; if monthstring = 'Nov' then month := 10; if monthstring = 'Dec' then month := 11; if month = -1 then fail; (* can't handle *) */ if (!strncmp(monthstring, "Jan", sizeof(monthtype))) /* 31 days */ monthday = 0; if (!strncmp(monthstring, "Feb", sizeof(monthtype))) /* 28 days */ monthday = 31; if (!strncmp(monthstring, "Mar", sizeof(monthtype))) /* 31 days */ monthday = 59; if (!strncmp(monthstring, "Apr", sizeof(monthtype))) /* 30 days */ monthday = 90; if (!strncmp(monthstring, "May", sizeof(monthtype))) /* 31 days */ monthday = 120; if (!strncmp(monthstring, "Jun", sizeof(monthtype))) /* 30 days */ monthday = 151; if (!strncmp(monthstring, "Jul", sizeof(monthtype))) /* 31 days */ monthday = 181; if (!strncmp(monthstring, "Aug", sizeof(monthtype))) /* 31 days */ monthday = 212; if (!strncmp(monthstring, "Sep", sizeof(monthtype))) /* 30 days */ monthday = 243; if (!strncmp(monthstring, "Oct", sizeof(monthtype))) /* 31 days */ monthday = 273; if (!strncmp(monthstring, "Nov", sizeof(monthtype))) /* 30 days */ monthday = 304; if (!strncmp(monthstring, "Dec", sizeof(monthtype))) /* 31 days */ monthday = 334; if (monthday == -1) /* can't handle */ fail(); scanf("%ld", &day); if (debugging) printf("%ld\n", day); c = getchar(); if (c == '\n') c = ' '; if (c != '.') fail(); scanf("%ld", &hour); if (debugging) printf("%ld\n", hour); c = getchar(); if (c == '\n') c = ' '; if (c != ':') fail(); scanf("%ld", &minute); if (debugging) printf("%ld\n", minute); c = getchar(); if (c == '\n') c = ' '; if (c != ':') fail(); scanf("%ld", &second); if (debugging) printf("%ld\n", second); /* totalseconds := second + (60 * minute + (60 * hour + (24 * day + (12 * month) + (365 * year) ) ) ) ; */ days = year * 365.25 + monthday + day; hours = days * 24 + hour; /*zzz*/ minutes = hours * 60 + minute; seconds = minutes * 60 + second; printf("%ld\n", (long)floor(seconds + 0.5)); } #undef debugging /* end module numdate.themain */ main(argc, argv) int argc; Char *argv[]; { /*(numdatep, bfile)*/ PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; themain(); _L1: exit(EXIT_SUCCESS); } /* End. */