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