/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "timep2c.p" */ #include /* timep2c: test time on the p2c translator/compiler Dr. Thomas D. Schneider National Cancer Institute Laboratory of Experimental and Computational Biology Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu http://www.lecb.ncifcrf.gov/~toms/ */ /* the end of the program */ /* begin module version */ #define version 1.30 /* p2c: timep2c.p, line 91: * Warning: Symbol 'DATETIMEARRAY' is not defined [221] */ /* of timep2c.p 2002 Oct 9 2002 Oct 9, 1.30: make link to module.p 2001 Jan 2, 1.29: upgrade readdatetime 2000 Oct 11, 1.26: upgrade documentation and timeseed 2000 Oct 9, 1.25: remove alpha and namelength 2000 Oct 3, 1.24: adjust getdatetime documentation 2000 Oct 2, 1.23: fix version number output 2000 Jul 25, 1.22: upgrade documentation 2000 Jul 23, 1.20: change name from cdatemod to timep2c 1999 Dec 13, 1.19: last previous change 1999 Mar 4: upgraded to new datetimearray origin from unixmod 1996 july 25 */ /* end module version */ /* begin module describe.timep2c */ /* name timep2c: test time on the p2c translator/compiler synopsis timep2c(output: out) files output: where the date and time will appear. description The time function returned by various computers is different. Show the time function to figure out how to modify the getdatetime procedure. This program contains routines for obtaining the date and time for Delila programs compiled with the p2c translater and the gcc compiler. examples Times should look like this: 1980/06/09 18:49:11 ye mo da ho mi se documentation moddef, delman.describe.module see also {The module program, used to transfer the modules is:} module.p delman.describe.delmod, moddef, delman.describe.module delmod.p, y2k.p {Related date/time programs:} timegpc.p timesun.p {General discussion on compiling Delila programs:} http://www.lecb.ncifcrf.gov/~toms/delila.html#How.To.Compile author Tom Schneider bugs none known technical notes */ /* end module describe.timep2c */ /* begin module package.datetime */ /* ************************************************************************ */ /* begin module getdatetime */ Static Void getdatetime(adatetime) long *adatetime; { /* Get the date and time into a single array from the system clock. adatetime contains the date: 1980/06/09 18:49:11 ye mo da ho mi se (year, month, day, hour, minute, second) This version works after translation of the pascal by p2c to C and then compiling with gcc. */ Char adate[11], atime[11]; /* adate, atime: alfa; (* ie, packed array[1..10] of char; *) This old method won't work, since the last digit gets cut off! */ Char month[3]; long index; /* index for times */ /* 1 12345678901 adate[13-DEC-1999] atime[17:39:44.00] */ VAXdate(adate); VAXtime(atime); /* writeln(output,'br: adate[',adate,'] atime[',atime,']'); */ /* transfer the year */ for (index = 1; index <= 4; index++) { (*adatetime)[index] = adate[index+6]; /* p2c: timep2c.p, line 123: Warning: Index on a non-array variable [287] */ } (*adatetime)[5] = "/"; /* p2c: timep2c.p, line 124: Warning: Index on a non-array variable [287] */ for (index = 4; index <= 6; index++) month[index-4] = adate[index-1]; if (!strncmp(month, "JAN", 3)) { (*adatetime)[6] = "0"; /* p2c: timep2c.p, line 126: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "1"; /* p2c: timep2c.p, line 126: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "FEB", 3)) { (*adatetime)[6] = "0"; /* p2c: timep2c.p, line 127: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "2"; /* p2c: timep2c.p, line 127: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "MAR", 3)) { (*adatetime)[6] = "0"; /* p2c: timep2c.p, line 128: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "3"; /* p2c: timep2c.p, line 128: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "APR", 3)) { (*adatetime)[6] = "0"; /* p2c: timep2c.p, line 129: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "4"; /* p2c: timep2c.p, line 129: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "MAY", 3)) { (*adatetime)[6] = "0"; /* p2c: timep2c.p, line 130: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "5"; /* p2c: timep2c.p, line 130: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "JUN", 3)) { (*adatetime)[6] = "0"; /* p2c: timep2c.p, line 131: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "6"; /* p2c: timep2c.p, line 131: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "JUL", 3)) { (*adatetime)[6] = "0"; /* p2c: timep2c.p, line 132: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "7"; /* p2c: timep2c.p, line 132: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "AUG", 3)) { (*adatetime)[6] = "0"; /* p2c: timep2c.p, line 133: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "8"; /* p2c: timep2c.p, line 133: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "SEP", 3)) { (*adatetime)[6] = "0"; /* p2c: timep2c.p, line 134: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "9"; /* p2c: timep2c.p, line 134: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "OCT", 3)) { (*adatetime)[6] = "1"; /* p2c: timep2c.p, line 135: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "0"; /* p2c: timep2c.p, line 135: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "NOV", 3)) { (*adatetime)[6] = "1"; /* p2c: timep2c.p, line 136: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "1"; /* p2c: timep2c.p, line 136: Warning: Index on a non-array variable [287] */ } else if (!strncmp(month, "DEC", 3)) { (*adatetime)[6] = "1"; /* p2c: timep2c.p, line 137: Warning: Index on a non-array variable [287] */ (*adatetime)[7] = "2"; /* p2c: timep2c.p, line 137: Warning: Index on a non-array variable [287] */ } (*adatetime)[8] = "/"; /* p2c: timep2c.p, line 138: Warning: Index on a non-array variable [287] */ for (index = 7; index <= 8; index++) { (*adatetime)[index+2] = adate[index-7]; /* p2c: timep2c.p, line 139: Warning: Index on a non-array variable [287] */ } /* replace blanks with spaces in dates */ if ((*adatetime)[6] == " ") { /* p2c: timep2c.p, line 142: Warning: Index on a non-array variable [287] */ (*adatetime)[6] = "0"; /* p2c: timep2c.p, line 142: Warning: Index on a non-array variable [287] */ } if ((*adatetime)[9] == " ") { /* p2c: timep2c.p, line 143: Warning: Index on a non-array variable [287] */ (*adatetime)[9] = "0"; /* p2c: timep2c.p, line 143: Warning: Index on a non-array variable [287] */ } (*adatetime)[11] = " "; /* p2c: timep2c.p, line 145: Warning: Index on a non-array variable [287] */ for (index = 10; index <= 17; index++) { (*adatetime)[index+2] = atime[index-10]; /* p2c: timep2c.p, line 146: Warning: Index on a non-array variable [287] */ } for (index = 20; index <= datetimearraylength + 2; index++) { /* p2c: timep2c.p, line 147: * Warning: Symbol 'DATETIMEARRAYLENGTH' is not defined [221] */ (*adatetime)[index] = " "; /* p2c: timep2c.p, line 147: Warning: Index on a non-array variable [287] */ } } /* p2c: timep2c.p, line 152: * Warning: Symbol 'DATETIMEARRAY' is not defined [221] */ /* end module getdatetime version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module readdatetime */ Static Void readdatetime(thefile, adatetime) _TEXT *thefile; long *adatetime; { /* read the date and time from the file */ long index; /* to the udatetime */ /* the following is an unpacked date time array, to avoid reading into a packed array. reading into a packed array is not transportable */ /* p2c: timep2c.p, line 158: * Warning: Symbol 'DATETIMEARRAYLENGTH' is not defined [221] */ Char udatetime[datetimearraylength]; for (index = 0; index < datetimearraylength; index++) { udatetime[index] = getc(thefile->f); if (udatetime[index] == '\n') udatetime[index] = ' '; } /* p2c: timep2c.p, line 160: * Warning: Symbol 'DATETIMEARRAYLENGTH' is not defined [221] */ /* p2c: timep2c.p, line 161: * Warning: Bad argument types for PACK/UNPACK [325] */ pack(udatetime, 1, *adatetime); if ((*adatetime)[3] == "/" && (*adatetime)[12] == ":") printf(" old datetime (only 2 year digits) read: %*ld\n", (int)datetimearraylength, *adatetime); /* p2c: timep2c.p, line 162: Warning: Index on a non-array variable [287] */ /* p2c: timep2c.p, line 162: Warning: Index on a non-array variable [287] */ /* p2c: timep2c.p, line 164: * Warning: Symbol 'DATETIMEARRAYLENGTH' is not defined [221] */ /* if (adatetime[3]<>'/') or (adatetime[12]<>':') then begin writeln(output,' bad date time read: ',adatetime:1); halt end; for index:=18 to datetimearraylength do adatetime[index]:=' ' */ } /* p2c: timep2c.p, line 178: * Warning: Symbol 'DATETIMEARRAY' is not defined [221] */ /* end module readdatetime version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module writedatetime */ Static Void writedatetime(thefile, adatetime) _TEXT *thefile; long adatetime; { /* expand the date and time out and print in the file */ long index; /* index of datetime */ for (index = 1; index <= datetimearraylength; index++) fprintf(thefile->f, "%12ld", adatetime[index]); /* p2c: timep2c.p, line 183: * Warning: Symbol 'DATETIMEARRAYLENGTH' is not defined [221] */ /* p2c: timep2c.p, line 183: Warning: Index on a non-array variable [287] */ } /* end module writedatetime version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module timeseed */ Static Void addtoseed(seed, power, c) double *seed, *power; Char c; { /* add the digit represented by c to the seed at the power position */ long n; /* the character represented by c */ *power /= 10; /* writeln(output,'addtoseed, c = ',c); writeln(output,'addtoseed, ord(c) = ',ord(c)); */ switch (c) { case ' ': printf("timeseed: error in datetime\n"); _Escape(0); break; case '0': n = 0; break; case '1': n = 1; break; case '2': n = 2; break; case '3': n = 3; break; case '4': n = 4; break; case '5': n = 5; break; case '6': n = 6; break; case '7': n = 7; break; case '8': n = 8; break; case '9': n = 9; break; } /*writeln(output,'timeseed number is [',n:1,']'); (@ debug */ *seed += *power * n; } /* addtoseed */ /* p2c: timep2c.p, line 218: * Warning: Symbol 'DATETIMEARRAY' is not defined [221] */ Static Void makeseed(adatetime, seed) long adatetime; double *seed; { /* convert adatetime to a real number in seed, reversed order */ double power = 1.0; /* a digit of the seed such as 0.01 */ *seed = 0.0; /* p2c: timep2c.p, line 225: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[19]); /* p2c: timep2c.p, line 226: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[18]); /* : */ /* p2c: timep2c.p, line 228: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[16]); /* p2c: timep2c.p, line 229: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[15]); /* : */ /* p2c: timep2c.p, line 231: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[13]); /* p2c: timep2c.p, line 232: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[12]); /* */ /* p2c: timep2c.p, line 234: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[10]); /* p2c: timep2c.p, line 235: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[9]); /* / */ /* p2c: timep2c.p, line 237: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[7]); /* p2c: timep2c.p, line 238: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[6]); /* / */ /* p2c: timep2c.p, line 240: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[4]); /* p2c: timep2c.p, line 241: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[3]); } /* p2c: timep2c.p, line 244: * Warning: Symbol 'DATETIMEARRAY' is not defined [221] */ Static Void orderseed(adatetime, seed) long adatetime; double *seed; { /* convert adatetime to a real number in seed, normal order */ double power = 1.0; /* a digit of the seed such as 0.01 */ *seed = 0.0; /* p2c: timep2c.p, line 251: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[3]); /* p2c: timep2c.p, line 252: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[4]); /* p2c: timep2c.p, line 253: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[6]); /* p2c: timep2c.p, line 254: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[7]); /* / */ /* p2c: timep2c.p, line 256: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[9]); /* p2c: timep2c.p, line 257: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[10]); /* / */ /* p2c: timep2c.p, line 259: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[12]); /* p2c: timep2c.p, line 260: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[13]); /* */ /* p2c: timep2c.p, line 262: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[15]); /* p2c: timep2c.p, line 263: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[16]); /* : */ /* p2c: timep2c.p, line 265: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[18]); /* p2c: timep2c.p, line 266: Warning: Index on a non-array variable [287] */ addtoseed(seed, &power, adatetime[19]); } Static Void timeseed(seed) double *seed; { /* read the computer date and time. reverse the order of the digits and put a decimal point in front. this gives a fraction between zero and one that varies quite quickly, and is always unique (if the computer has sufficient accuracy). it is to be used as a seed to a random number generator. */ /* p2c: timep2c.p, line 276: * Warning: Symbol 'DATETIMEARRAY' is not defined [221] */ extern long adatetime; /* a date and time */ getdatetime(&adatetime); /* writeln(output,'timeseed: adatetime: ',adatetime); */ makeseed(adatetime, seed); } /* timeseed */ /* p2c: timep2c.p, line 287: * Warning: Symbol 'DATETIMEARRAY' is not defined [221] */ /* end module timeseed version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module limitdate */ Static Void limitdate(a, b, c, d, limitdatetime) Char a, b, c, d; long limitdatetime; { /* test whether the current time is before the limit. If it is later, halt the program */ long adatetime; /* a date and time */ double Dday; /* the critical day */ double now; /* this very moment */ getdatetime(&adatetime); orderseed(adatetime, &now); if (limitdatetime[1] != " " || limitdatetime[2] != " " || limitdatetime[3] != " " || limitdatetime[4] != " ") _Escape(0); /* p2c: timep2c.p, line 299: Warning: Index on a non-array variable [287] */ /* p2c: timep2c.p, line 300: Warning: Index on a non-array variable [287] */ /* p2c: timep2c.p, line 301: Warning: Index on a non-array variable [287] */ /* p2c: timep2c.p, line 302: Warning: Index on a non-array variable [287] */ limitdatetime[1] = a; /* p2c: timep2c.p, line 304: Warning: Index on a non-array variable [287] */ limitdatetime[2] = b; /* p2c: timep2c.p, line 305: Warning: Index on a non-array variable [287] */ limitdatetime[3] = c; /* p2c: timep2c.p, line 306: Warning: Index on a non-array variable [287] */ limitdatetime[4] = d; /* p2c: timep2c.p, line 307: Warning: Index on a non-array variable [287] */ orderseed(limitdatetime, &Dday); /* writeln(output,'now: ',now:20:8); writeln(output,'Dday: ',Dday:20:8); */ if (now > Dday) _Escape(0); /* writeln(output,'This program expired on ',limitdatetime); leave no clues */ } /* end module limitdate version = 'cdatemod.p 1.19 1999Dec13'; */ /* ************************************************************************ */ /* end module package.datetime version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module datetime.const */ main(argc, argv) int argc; Char *argv[]; { /* p2c: timep2c.p, line 329: * Warning: Expected BEGIN, found 'datetimearraylength' [227] */ /* length of dataarray for dates, It is just long enough to include the 4 digit year - solving the year 2000 problem: 1980/06/09 18:49:11 123456789 123456789 1 2 */ /* end module datetime.const version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module datetime.type */ /* array for dates */ /* end module datetime.type version = 'cdatemod.p 1.19 1999Dec13'; */ /* begin module timep2c.var */ /* this is a global variable for use in the running of timep2cs */ /* end module timep2c.var */ /* begin module timep2c.halt */ /* halt the program and notify the user. the module name is not the standard one so that this procedure will not be transfered when timep2c is used as a modlib. this avoids the possibility of transfering an obsolete halt module into a main module library unknowingly. */ PASCAL_MAIN(argc, argv); printf(" program halt.\n"); goto _L1; /* p2c: timep2c.p: Note: Deleting unreachable code [255] */ } /* p2c: timep2c.p, line 364: * Warning: Junk at end of input file ignored [277] */ /* end module timep2c.halt */ /* begin module testdatetimep2c */ /* End. */