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

Defined functions

monthcheck defined in line 185; used 1 times
  • in line 72
monthsize defined in line 215; used 1 times
  • in line 74
save defined in line 50; used 4 times

Defined variables

Dmsize declared in line 46; defined in line 38; never used
Monthtab defined in line 157; used 1 times

Defined struct's

monthtab defined in line 151; used 4 times

Defined macros

Dmsize defined in line 45; used 3 times
Last modified: 1995-02-04
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1035
Valid CSS Valid XHTML 1.0 Strict