1: # include   <pv.h>
   2: # include   <ingres.h>
   3: # include   <aux.h>
   4: # include   <func.h>
   5: # include   <opsys.h>
   6: # ifdef xV7_UNIX
   7: # include   <sys/timeb.h>
   8: # endif xV7_UNIX
   9: # include   <sccs.h>
  10: # include   <errors.h>
  11: 
  12: SCCSID(@(#)save.c	8.3	2/8/85)
  13: 
  14: extern  short   tTdbu[];
  15: extern  int save();
  16: extern  int null_fn();
  17: 
  18: struct fn_def SaveFn =
  19: {
  20:     "SAVE",
  21:     save,
  22:     null_fn,        /* initialization function */
  23:     null_fn,
  24:     NULL,
  25:     0,
  26:     tTdbu,
  27:     100,
  28:     'Z',
  29:     0
  30: };
  31: /*
  32: **  SAVE RELATION UNTIL DATE
  33: **
  34: **	This function arranges to save a named relation until a
  35: **	specified date.
  36: **
  37: **	Parameters:		(pv_type is PV_STR for all of them)
  38: **	0 -- relation name
  39: **	1 -- month (1 -> 12 or "jan" -> "dec" or a variety of other codes)
  40: **	2 -- day (1 -> 31)
  41: **	3 -- year (1970 -> ?)
  42: **
  43: **	Uses trace flag 44
  44: **	Uses error messages 56xx
  45: */
  46: 
  47: int DmSize[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  48: 
  49: save(parmc, parmv)
  50: int parmc;
  51: PARM    parmv[];
  52: {
  53:     long        date;
  54:     register int    i;
  55:     extern DESC Reldes;
  56:     TID     tid;
  57:     extern char *Usercode;
  58:     struct relation relk, relt;
  59:     int     day, month, year;
  60: # ifdef xV7_UNIX
  61:     struct timeb    timeb;
  62: # else xV7_UNIX
  63:     extern int  timezone;   /* defined by ctime(3) */
  64: # endif xV7_UNIX
  65:     extern int  dysize();   /* ditto */
  66: 
  67:     /*
  68: 	**  Validate parameters.
  69: 	**
  70: 	**	According to my pocket calculator, a 31 bit number will
  71: 	**	hold 70 years of accuracy -- hence the 2035 cutoff.  If
  72: 	**	this code is still around in 2035, I apologize in
  73: 	**	advance.
  74: 	*/
  75: 
  76:     year = atoi(parmv[3].pv_val.pv_str);
  77:     if (year < 1970 || year > 2035)
  78:         return (error(BADYEAR, parmv[3].pv_val.pv_str, 0)); /* bad year */
  79:     if (monthcheck(parmv[1].pv_val.pv_str, &month))
  80:         return (error(BADMONTH, parmv[1].pv_val.pv_str, 0));    /* bad month */
  81:     day = atoi(parmv[2].pv_val.pv_str);
  82:     if (day < 1 || day > monthsize(--month, year))
  83:         return (error(BADDAY, parmv[2].pv_val.pv_str, 0));  /* bad day */
  84: 
  85:     /* convert date */
  86:     /* "date" will be # of days from 1970 for a while */
  87:     date = 0;
  88: 
  89:     /* do year conversion */
  90:     for (i = 1970; i < year; i++)
  91:     {
  92:         date += dysize(i);
  93:     }
  94: 
  95:     /* do month conversion */
  96:     for (i = 0; i < month; i++)
  97:         date += DmSize[i];
  98:     /* once again, allow for leapyears */
  99:     if (month >= 2 && year % 4 == 0 && year % 100 != 0)
 100:         date += 1;
 101: 
 102:     /* do day conversion */
 103:     date += day - 1;
 104: 
 105:     /* we now convert date to be the # of hours since 1970 */
 106:     date *= 24;
 107: 
 108:     /* do daylight savings computations */
 109:     /*  <<<<< none now >>>>> */
 110: 
 111:     /* convert to seconds */
 112:     date *= 60 * 60;
 113: 
 114:     /* adjust to local time */
 115: # ifdef xV7_UNIX
 116:     ftime(&timeb);
 117:     date += ((long) timeb.timezone) * 60;
 118: # else xV7_UNIX
 119:     date += timezone;
 120: # endif xV7_UNIX
 121: 
 122: #	ifdef xZTR1
 123:     if (tTf(45, 1))
 124:         printf("%s", ctime(&date));
 125: #	endif
 126: 
 127:     /* let's check and see if the relation exists */
 128:     opencatalog("relation", OR_WRITE);
 129:     clearkeys(&Reldes);
 130:     setkey(&Reldes, &relk, parmv[0].pv_val.pv_str, RELID);
 131:     setkey(&Reldes, &relk, Usercode, RELOWNER);
 132:     if (getequal(&Reldes, &relk, &relt, &tid))
 133:     {
 134:         return (error(RELNOTFOUND, parmv[0].pv_val.pv_str, 0)); /* relation not found */
 135:     }
 136: 
 137:     /* check that it is not a system catalog */
 138:     if (relt.relstat & S_CATALOG)
 139:         return (error(NOSAVESYSREL, parmv[0].pv_val.pv_str, 0));    /* cannot save sys rel */
 140:     /* got it; lets change the date */
 141:     relt.relsave = date;
 142: 
 143: #	ifdef xZTR2
 144:     if (tTf(45, 2))
 145:     {
 146:         printup(&Reldes, &relt);
 147:     }
 148: #	endif
 149: 
 150:     if ((i = replace(&Reldes, &tid, &relt, 0)) < 0)
 151:         syserr("SAVE: replace %d", i);
 152: 
 153:     /* that's all folks.... */
 154:     return (0);
 155: }
 156: /*
 157: **  MONTHCHECK
 158: */
 159: 
 160: struct monthtab
 161: {
 162:     char    *code;
 163:     int month;
 164: };
 165: 
 166: struct monthtab Monthtab[] =
 167: {
 168:     "jan",      1,
 169:     "feb",      2,
 170:     "mar",      3,
 171:     "apr",      4,
 172:     "may",      5,
 173:     "jun",      6,
 174:     "jul",      7,
 175:     "aug",      8,
 176:     "sep",      9,
 177:     "oct",      10,
 178:     "nov",      11,
 179:     "dec",      12,
 180:     "january",  1,
 181:     "february", 2,
 182:     "march",    3,
 183:     "april",    4,
 184:     "june",     6,
 185:     "july",     7,
 186:     "august",   8,
 187:     "september",    9,
 188:     "october",  10,
 189:     "november", 11,
 190:     "december", 12,
 191:     0
 192: };
 193: 
 194: monthcheck(input, output)
 195: char    *input;
 196: int *output;
 197: {
 198:     register struct monthtab    *p;
 199:     int             month;
 200: 
 201:     /* month can be an integer, or an alphanumeric code */
 202:     month = atoi(input);
 203:     if (month != 0)
 204:     {
 205:         *output = month;
 206:         return (month < 1 || month > 12);
 207:     }
 208:     for (p = Monthtab; p->code; p++)
 209:     {
 210:         if (sequal(input, p->code))
 211:         {
 212:             *output = p->month;
 213:             return (0);
 214:         }
 215:     }
 216:     return (1);
 217: }
 218: /*
 219: **  MONTHSIZE -- determine size of a particular month
 220: */
 221: 
 222: monthsize(month, year)
 223: int month;
 224: int year;
 225: {
 226:     register int    size;
 227:     extern int  dysize();   /* defined in ctime */
 228: 
 229:     size = DmSize[month];
 230:     if (month == 1 && dysize(year) == 366)
 231:         /* This is February of a leap year */
 232:         size++;
 233: 
 234:     return (size);
 235: 
 236: }

Defined functions

monthcheck defined in line 194; used 1 times
  • in line 79
monthsize defined in line 222; used 1 times
  • in line 82
save defined in line 49; used 2 times

Defined variables

DmSize defined in line 47; used 2 times
Monthtab defined in line 166; used 1 times
SaveFn defined in line 18; never used

Defined struct's

monthtab defined in line 160; used 4 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1084
Valid CSS Valid XHTML 1.0 Strict