File: update_groups.C

package info (click to toggle)
peruser 4b33-10
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,944 kB
  • ctags: 1,064
  • sloc: cpp: 22,397; perl: 2,733; makefile: 345; sh: 335
file content (50 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdlib.h>
#include <stdio.h>

#include "npfile.h"
#include "npstringarray.h"
#include "npgroup.h"
#include "npnode.h"

int NP_Node::update_groups( NP_Stringarray& array )
{
   clear();

   int total = array.get_total();
   if ( !total )
      return 0;
   
   if (( groups = ( NP_Group **)calloc( total, sizeof *groups )) == NULL )
   {
      perror( "calloc" );
      exit( 1 );
   }

   NP_Group **pointer = groups;
   for( int i = 0; i < total; ++i )
   {
      if (( *pointer = new NP_Group( name, ( char *)array[ i ] )) == NULL )
      {
         perror( "new" );
         exit( 1 );
      }

      ++total_groups;

      int messages, unseen, requested, headers;
      if ( ( *pointer )->get_stats( &messages, &unseen, &requested, &headers ))
      {
         snprintf( error_message, sizeof error_message, "NP_Node: "
                   "update_groups(): %s", ( *pointer )->get_error() );
         return 1;
      }
      
      total_messages += messages;
      total_unseen += unseen;
      total_requested += requested;
      total_headers += headers;
      ++pointer;
   }
   
      return 0;
}