From:	ADVAX::"mcnc!VM1.NoDak.EDU!GIH900%SAO.AARNET.EDU.AU" "Geoff Huston" 18-JUN-1990 23:37:16.23
To:	Multiple recipients of list ANU-NEWS <ANU-NEWS@NDSUVM1>
CC:	
Subj:	Re: Problem with 6.0 initialization

Received: by ADVAX.DECnet (utk-mail11 v1.5) ; Mon, 18 Jun 90 23:37:47 EDT
Received:  from mcnc by ge-dab.GE.COM (5.61/GE-DAB 1.12) with UUCP
	id AA11954 for everhart; Mon, 18 Jun 90 23:37:27 -0400
Received: from VM1.NoDak.EDU by mcnc.mcnc.org (5.59/MCNC/5-16-88)
	id AA07546; Mon, 18 Jun 90 23:23:53 EDT
Message-Id: <9006190323.AA07546@mcnc.mcnc.org>
Received: from NDSUVM1.BITNET by VM1.NoDak.EDU (IBM VM SMTP R1.2.1MX) with BSMTP id 3413; Mon, 18 Jun 90 22:23:33 CDT
Received: from NDSUVM1.BITNET by NDSUVM1.BITNET (Mailer R2.07) with BSMTP id
 3402; Mon, 18 Jun 90 22:23:31 CDT
Date:         Tue, 19 Jun 90 13:22:16 GMT
Reply-To: Geoff Huston <mcnc!VM1.NoDak.EDU!GIH900%SAO.AARNET.EDU.AU>
Sender: ANU-NEWS Discussion <ANU-NEWS@VM1.NoDak.EDU>
From: Geoff Huston <mcnc!VM1.NoDak.EDU!GIH900%SAO.AARNET.EDU.AU>
Subject:      Re: Problem with 6.0 initialization
X-To:         anu-news@vm1.nodak.edu
To: Multiple recipients of list ANU-NEWS <ANU-NEWS@NDSUVM1>
 
>I am continuing to look at the problem of NEWS (in client-only mode) seems not
>to initialize to the correct point. Whenever I enter NEWS, I end up in a
>DIR/ALL with the pointer pointing to group 123.
>
>I ran newsdbg and I think the problem is in NEWSRC.C in the routine
>read_reg_file(). The comments imply that it is looking for a completely
>different format than actually exists.
>
>The first line of my NEWSRC file is:
>~winken 3~0 news.software.anu-news 1302^3
>
>NEWSFILES.C correctly reads in the first line and interperts the server name
>and protocol, but doesn't deal with the rest of the line.
>
>read_reg_file() then re-reads the line and tries to get a class. There is none
>in this case, but that doesn't make a difference. read_reg_file() scans for a
>"~" which should be the beginning of the class field. But in this case, the
>tilde is the first character of the record.
>
>read_reg_file() then null terminates the string at the tilde and loads the
>remainder of the line into n_class_name. This results in garbage in
>n_class_name and kills the entire inline. From there on, everything is down the
>drain. But if it did continue to read, it would read in the old_dir_lev and
>then systime (always 0), new_name, and new_ci (which I assume are the time, the
>newsgroup and the article pointer). Except it would mess up again because the
>server, protocol, and an tildes would still be in the inline.
>
>I'm not much of a C programmer, but does this make any sense to anyone?
 
it may still give problems..
 
heres an alternative code for read_reg_file() (NEWSRC.C)
 
Geoff Huston
 
----------%<-----%<-----------------------------------
 
/*
 *  read_reg_file
 *  reg_context
 *
 *  Read the register text file and fill out the ga array
 *
 *  register file format:
 *  line 1: <reg/new time in hex digits>
 *  line n: <newsgroup name>: (prio) [unread,topnum] <item numbers>
 *
 *          <item numbers> ::= n      single item
 *                             <n     all up to item n (incl n)
 *                             |n1=n2   range from n1 to n2 (incl)
 *          space char separates <item numbers>
 *
 *  reg_context finishes re-establishing the old news context
 *  (The separation into a second procedure is necessary as there is
 *  a call to init_screen after read_reg_file is invoked)
 */
 
read_reg_file()
{
  char *inline,
       *itm_list,
       new_name[128],
       *old_dir_typ;
  int systime,
      f_itm,
      l_itm,
      g = 0,
      i,
      ca_i = 1,
      new_cg;
  GRP_PTR l_ga,
          *ca;
 
  ca = (GRP_PTR *) malloc((ga_size + 1) * (sizeof *ca));
 
  for (g = 1; g <= ga_size ; ++g) {
    ga[g]->grp_flags &= ~NEWS_M_OLDGROUP;
    }
 
  *profile_dirstr = '\0';
  profile_display_lines = profile_display_postmark = nntp_anu_news_server;
  if (newsrc) {
    fseek(newsrc,0,0);
    }
  else {
    if (!(newsrc = fopen(news_register,"r","mbc=40"))) {
      FILE *fpold;
      char buff[512];
      if (fpold = fopen("SYS$LOGIN:NEWS_GROUPS.REGISTER","r","mbc=40")) {
        newsrc = fopen(news_register,"w","mbc=40");
        while (fgets(buff,512,fpold)) fputs(buff,newsrc);
        fclose(fpold);
        fclose(newsrc); newsrc = 0;
        if (!(newsrc = fopen(news_register,"r","mbc=40"))) return(0);
        while (!delete("SYS$LOGIN:NEWS_GROUPS.REGISTER"));
        }
      else {
        sysprv();
        if (!(newsrc = fopen("NEWS_MANAGER:NEWSRC.TEMPLATE","r","mbc=40"))) {
          nosysprv();
          return(0);
          }
        nosysprv();
        }
      }
    }
 
  if (!(inline = fgetl(newsrc))) return(0);
 
  old_dir_lev = 0;
  if (old_dir_typ = strchr(inline,'\n')) *old_dir_typ = '\0';
 
        /* previous class name is stored as "@classname" as last
           field of the first line of the register file */
  *n_class_name = '\0';
  if (old_dir_typ = strchr(inline,'@')) {
    *old_dir_typ++ = '\0';
    strcpy(n_class_name,old_dir_typ);
    lower_case(n_class_name);
    }
 
  if (old_dir_typ = strchr(inline,'^')) {
    *old_dir_typ++ = '\0';
    if (sscanf(old_dir_typ,"%d",&old_dir_lev) != 1) old_dir_lev = 0;
    }
 
  /* now remove the optional ~nntp info~ field at the start of the line */
  if (*inline == '~') {
    ++inline;
    if (inline = strchr(inline,'~')) ++inline;
    }
 
  if ((new_vals = sscanf(inline,"%X %s %d",&systime,new_name,&new_ci)) >= 1)
 sys_reg_time = systime;
  while (inline = fgetl(newsrc)) {
    if (!strcmp(inline,"MARKLIST\n")) {
      mark_read(newsrc);
      break;
      }
    if (!strcmp(inline,"KILLLIST\n")) {
      kill_read(newsrc);
      break;
      }
    if (!strcmp(inline,"PROFILE\n")) {
      profile_read(newsrc);
      break;
      }
    if (itm_list = strchr(inline,'\n')) *itm_list = '\0';
    if (itm_list = strchr(inline,':')) {
      *itm_list++ = '\0';
      itm_list++;
      }
    if (!(g = ga_exact_name(inline))) continue;
    l_ga = ga[g];
    if (!(l_ga->grp_flags & NEWS_M_OLDGROUP)) {
      if (ca_i <= ga_size) ca[ca_i++] = l_ga;
      }
    l_ga->grp_flags |= NEWS_M_OLDGROUP;   /* flag this newsgroup as not new! */
 
    if (!curr_g) curr_g = g;
    if ((itm_list) && (*itm_list == '(')) {
      if (*++itm_list == '-') l_ga->grp_reg = 0;
      else {
        f_itm = 0;
        sscanf(itm_list,"%d",&f_itm);
        if (f_itm > 255) f_itm = 255;
        l_ga->grp_reg = f_itm;
        }
      itm_list = strchr(itm_list,')');
      itm_list += 2;
      }
    else l_ga->grp_reg = NEWGROUP_REG;
 
    if ((itm_list) && (*itm_list == '{')) {
      char *cp1, *cp2;
 
      ++itm_list;
      if (cp1 = strchr(itm_list,'}')) *cp1 = '\0';
      do {
        if (cp2 = strchr(itm_list,',')) *cp2++ = '\0';
        if (!*itm_list) break;
        add_class_member(itm_list,l_ga->grp_num);
        } while (itm_list = cp2);
      if (cp1) itm_list = cp1 + 2;
      }
 
    if ((itm_list) && (*itm_list == '[')) {
      f_itm = l_itm = 0;
      sscanf(itm_list,"[%d,%d]",&f_itm,&l_itm);
      itm_list = strchr(itm_list,']');
      itm_list += 2;
      }
    else {
      f_itm = l_ga->grp_count;
      l_itm = l_ga->grp_topnum;
      }
 
    if (!l_ga->grp_count) {
      l_ga->grp_unread = 0;
      continue;
      }
 
    strcpy((l_ga->grp_reg_text = (char *) malloc(strlen(itm_list) +
 1)),itm_list);
    l_ga->grp_unread = f_itm + (l_ga->grp_topnum - l_itm);
    if (l_ga->grp_unread > l_ga->grp_count) l_ga->grp_unread = l_ga->grp_count;
    }
  fclose(newsrc); newsrc = 0;
  if ((new_vals >= 2) && (new_cg = ga_exact_name(new_name))) curr_g = new_cg;
  else new_vals = 2;
  set_level(1);
 
  if (profile_filter && !reorder_groups) {
    ca_i = 1;
    for (g = 1; g <= ga_size ; ++g) {
      if ((ga[g]->grp_flags & NEWS_M_OLDGROUP) && (ca_i <= ga_size))
        ca[ca_i++] = l_ga;
      }
    }
 
  for (g = 1; g <= ga_size ; ++g) {
    if (   include_all_groups
        && !(ga[g]->grp_flags & NEWS_M_OLDGROUP)
        && (ca_i <= ga_size))
      ca[ca_i++] = l_ga;
    if (ga[g]->grp_flags & NEWS_M_LOCAL)
      add_class_member("$LOCAL",ga[g]->grp_num);
    else
      add_class_member("$NET",ga[g]->grp_num);
    }
 
  if (profile_filter || reorder_groups) {
    for (g = 1; g <= ga_size ; ++g) {
      if (g < ca_i) ga[g] = ca[g];
      }
    ga_size = ca_i - 1;
    }
 
  sysprv();
  if (newsrc = fopen("NEWS_MANAGER:NEWS.CLASSES","r")) {
    char class[132], *cp, *cp2, *cp3;
    while (inline = fgetl(newsrc)) {
      if (cp = strchr(inline,'#')) *cp = '\0';
      if (cp = strchr(inline,'\n')) *cp = '\0';
      strip_compress_lower(inline);
      if (!strlen(inline)) continue;
      if (!(cp = strchr(inline,' '))) continue;
      *cp++ = '\0';
      if (*inline == '$') strcpy(class,inline);
      else {
        strcpy(class,"$");
        strcat(class,inline);
        }
      if (!strcmp(class,"$local") || !strcmp(class,"$net")) continue;
      cp2 = cp;
      while (cp2) {
        cp3 = cp2;
        while (isgraph(*cp3) && (*cp3 != ',')) ++cp3;
        if (*cp3) *cp3++ = '\0';
        else cp3 = 0;
        for (g = 1; g <= ga_size ; ++g) {
          if (wild_match(ga[g]->grp_name,cp2))
            add_class_member(class,ga[g]->grp_num);
          }
        cp2 = cp3;
        }
      }
    fclose(newsrc); newsrc = 0;
    }
  nosysprv();
  return(0);
}
