From:	ADVAX::"mcnc!VM1.NoDak.EDU!gih900%SAO.AARNET.EDU.AU" 31-MAY-1991 05:28:15.83
To:	Multiple recipients of list ANU-NEWS <ANU-NEWS@NDSUVM1>
CC:	
Subj:	Rebuilding the item indexed file from scratch Part 2/2

Received: by ADVAX.DECnet (utk-mail11 v1.5) ; Fri, 31 May 91 05:25:58 EDT
Received:  from mcnc by ge-dab.GE.COM (5.61/GE-DAB 1.15) with UUCP
	id AA12174 for ; Fri, 31 May 91 03:47:34 -0400
Received: from VM1.NoDak.EDU by mcnc.mcnc.org (5.59/MCNC/3-21-91)
	id AA00272; Fri, 31 May 91 02:07:50 -0400
	for ARISIA.DNET.ge.com!EVERHART
Message-Id: <9105310607.AA00272@mcnc.mcnc.org>
Received: from NDSUVM1.BITNET by VM1.NoDak.EDU (IBM VM SMTP R1.2.1MX) with BSMTP id 9394; Fri, 31 May 91 01:05:34 CDT
Received: from NDSUVM1.BITNET by NDSUVM1.BITNET (Mailer R2.07) with BSMTP id
 2414; Fri, 31 May 91 01:05:32 CDT
Date:         Fri, 31 May 91 01:11:33 GMT
Reply-To: mcnc!VM1.NoDak.EDU!gih900%SAO.AARNET.EDU.AU
Sender: ANU-NEWS Discussion <ANU-NEWS@VM1.NoDak.EDU>
Comments:     Warning -- original Sender: tag was news@NEWSHOST.ANU.EDU.AU
From: mcnc!VM1.NoDak.EDU!gih900%SAO.AARNET.EDU.AU
Subject:      Rebuilding the item indexed file from scratch Part 2/2
To: Multiple recipients of list ANU-NEWS <ANU-NEWS@NDSUVM1>
 
And here's part 2 of the rebuild code:...
 
-+-+-+-+-+-+-+-+ START OF PART 2 -+-+-+-+-+-+-+-+
X    `7D while (*p);
X  *l = '\0';
X
X  if (!strcmp(locstr,"TODAY")) `7B
X    time(&ctime);
X    stm = localtime(&ctime);
X    return(ctime - (stm->tm_sec + (stm->tm_min * 60) + (stm->tm_hour * 3600)
V));
X    `7D
X  if (!strcmp(locstr,"YESTERDAY")) `7B
X    time(&ctime);
X    stm = localtime(&ctime);
X    return(ctime - (stm->tm_sec + (stm->tm_min * 60) + (stm->tm_hour * 3600)
V + DAY_SECS));
X    `7D
X  if (!strcmp(locstr,"TOMORROW")) `7B
X    time(&ctime);
X    stm = localtime(&ctime);
X    return(ctime - (stm->tm_sec + (stm->tm_min * 60) + (stm->tm_hour * 3600)
V) + DAY_SECS);
X    `7D
X  locstr_dsc.dsc$w_length = strlen(locstr);
X  if (!(sys$bintim(&locstr_dsc,vdate) & 1)) return(0);
X  else return(cvt_date(vdate));
X`7D
X`0C
X/*
X *  parse_usenet_date
X *
X *  Convert a Unix date string to a time value.
X */
X
Xstatic int gmt_offset_set = 0,
X    gmt_offset = 0;
X
Xint gmt_to_local(filt_date)
X  int filt_date;
X`7B
X  char *cp,
X       news_gmt_offset`5B256`5D;
X  int sign = 1,
X      hr,mn,se;
X
X  if (!gmt_offset_set) `7B
X    if (cp = getenv("NEWS_GMT_OFFSET")) `7B
X      strcpy(news_gmt_offset,cp);
X      strip_compress_lower(news_gmt_offset);
X      cp = news_gmt_offset;
X      if (*cp == '-') `7B
X        sign = -1;
X        ++cp;
X        `7D
X      else if (*cp == '+') ++cp;
X      hr = mn = se = 0;
X      if (sscanf(cp,"%d:%d:%d",&hr,&mn,&se) > 0) `7B
X        gmt_offset = (60 * 60 * hr) + (60 * mn) + se;
X        gmt_offset *= sign;
X        `7D
X      `7D
X    else gmt_offset_set = 1;
X    `7D
X  return(filt_date + gmt_offset);
X`7D
X
Xint local_to_gmt(local_date)
X  int local_date;
X`7B
X  if (!gmt_offset_set) gmt_to_local(0);
X  return(local_date - gmt_offset);
X`7D
X`0C
Xint parse_usenet_date(s)
X  char *s;
X`7B
X  char *cp, mon`5B80`5D, pdate`5B15`5D;
X  int dom = 0, yr = 0, hr = 0, mn = 0, sc = 0, cvttime;
X
X  if (!s `7C`7C !*s) return(0);
X  if (cp = strchr(s,',')) s = ++cp;
X  while (isspace(*s)) s++;
X  *mon = '\0';
X  if (isdigit(*s)) `7B
X    sscanf(s,"%d %s %d %d:%d:%d",&dom,mon,&yr,&hr,&mn,&sc);
X    yr += 1900;
X    `7D
X  else sscanf(s,"%*s %s %d %d:%d:%d %d",mon,&dom,&hr,&mn,&sc,&yr);
X
X  if (!dom `7C`7C !yr `7C`7C !*(cp = mon)) return(0);
X  if ((dom <= 0) `7C`7C (dom >= 32)) return(0);
X  if ((yr < 1989) `7C`7C (yr > 2020)) return(0);
X  if (strlen(mon) > 10) return(0);
X  if ((hr < 0) `7C`7C (hr > 23)) return(0);
X  if ((mn < 0) `7C`7C (mn > 59)) return(0);
X  if ((sc < 0) `7C`7C (sc > 59)) return(0);
X
X  while (*cp) `7B *cp = toupper(*cp); ++cp; `7D
X  sprintf(pdate,"%d-%s-%d %d:%d:%d",dom,mon,yr,hr,mn,sc);
X  if ((cvttime = cvt_date_val(pdate)) && substrcmp(s,"GMT"))
X    return(gmt_to_local(cvttime));
X  return(cvttime);
X`7D
X/*
X *  substrcmp
X *
X *  return 1 if the second arg is a substring of the first arg
X */
X
Xint substrcmp(s,sub)
X  char *s,
X       *sub;
X`7B
X  char *cp = s;
X  int i, bl = strlen(sub), sl = strlen(s);
X
X  for (i = 0; i <= (sl - bl); ++i)
X    if (!strncmp(&s`5Bi`5D,sub,bl)) return(i+1);
X  return(0);
X`7D
X`0C
X/*
X *  strip_compress_lower
X *
X *  Strip off leading and trailing blanks, convert all whitespace to a singl
Ve
X *  space, and convert all alphas to lower case.
X */
X
Xvoid strip_compress_lower(s)
X  char *s;
X`7B
X  char *start = s,
X       *r = s;
X
X  while (*s) `7B
X    if (isgraph(*s)) *r++ =tolower(*s);
X    else if ((r > start) && (*(r-1) != ' ')) *r++ = ' ';
X    s++;
X    `7D
X  if ((r > start) && (*(r-1) == ' ')) --r;
X  *r = '\0';
X`7D
X`0C
Xvoid close_index_file()
X`7B
X  sys$close(&itmfab);
X`7D
X`0C
Xvoid close_group_file()
X`7B
X  sys$close(&grpfab);
X`7D
$ CALL UNPACK REBUILD_ITEM_FILE.C;21 1247174660
$ v=f$verify(v)
$ EXIT
