annotate itemlist.c @ 34:9426f9eaf3d7 noffle

[svn] Change output of "noffle -a all" to standard mailbox format.
author enz
date Mon, 01 May 2000 10:23:31 +0100
parents 526a4c34ee2e
children 8e972daaeab9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
1 /*
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
2 itemlist.c
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
3
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
4 $Id: itemlist.c 32 2000-04-29 14:45:56Z enz $
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
5 */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
6
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
7 #include "itemlist.h"
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
8 #include <ctype.h>
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
9 #include <string.h>
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
10 #include <stdlib.h>
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
11 #include "common.h"
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
12 #include "log.h"
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
13
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
14 struct ItemList
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
15 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
16 char *list;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
17 char *separators;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
18 char *next;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
19 size_t count;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
20 };
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
21
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
22 /* Make a new item list. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
23 ItemList *
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
24 new_Itl( const char *list, const char *separators )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
25 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
26 ItemList * res;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
27 char *p;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
28 Bool inItem;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
29
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
30 res = (ItemList *) malloc( sizeof( ItemList ) );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
31 if ( res == NULL )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
32 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
33 Log_err( "Malloc of ItemList failed." );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
34 exit( EXIT_FAILURE );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
35 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
36
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
37 res->list = (char *) malloc( strlen(list) + 2 );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
38 if ( res->list == NULL )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
39 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
40 Log_err( "Malloc of ItemList.list failed." );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
41 exit( EXIT_FAILURE );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
42 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
43 strcpy( res->list, list );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
44
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
45 if ( ( res->separators = strdup( separators ) ) == NULL )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
46 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
47 Log_err( "Malloc of ItemList.separators failed." );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
48 exit( EXIT_FAILURE );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
49 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
50
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
51 res->count = 0;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
52 res->next = res->list;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
53
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
54 /* Separate items into strings and have final zero-length string. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
55 for( p = res->list, inItem = FALSE; *p != '\0'; p++ )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
56 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
57 Bool isSep = ( strchr( separators, p[ 0 ] ) != NULL );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
58
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
59 if ( inItem )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
60 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
61 if ( isSep )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
62 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
63 p[ 0 ] = '\0';
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
64 inItem = FALSE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
65 res->count++;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
66 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
67 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
68 else
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
69 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
70 if ( ! isSep )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
71 inItem = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
72 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
73 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
74 if ( inItem )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
75 res->count++;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
76 p[ 1 ] = '\0';
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
77 return res;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
78 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
79
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
80 /* Delete an item list. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
81 void
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
82 del_Itl( ItemList *self )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
83 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
84 if ( self == NULL )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
85 return;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
86 free( self->list );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
87 free( self->separators );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
88 free( self );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
89 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
90
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
91 /* Get first item. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
92 const char *
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
93 Itl_first( ItemList *self )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
94 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
95 self->next = self->list;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
96 return Itl_next( self );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
97 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
98
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
99 /* Get next item or NULL. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
100 const char *
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
101 Itl_next( ItemList *self )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
102 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
103 const char *res = self->next;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
104
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
105 if ( res[ 0 ] == '\0' )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
106 return NULL;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
107
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
108 while ( strchr( self->separators, res[ 0 ] ) != NULL )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
109 res++;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
110
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
111 if ( res[ 0 ] == '\0' && res[ 1 ] == '\0' )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
112 return NULL;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
113
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
114 self->next += strlen( res ) + 1;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
115 return res;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
116 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
117
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
118 /* Get count of items in list. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
119 size_t
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
120 Itl_count( const ItemList *self )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
121 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
122 return self->count;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
diff changeset
123 }