/[mailutils]/mailutils/mail/msgset.y
ViewVC logotype

Diff of /mailutils/mail/msgset.y

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by polak, Sun Dec 29 12:52:07 2002 UTC revision 1.15 by gray, Tue Jan 14 14:44:41 2003 UTC
# Line 1  Line 1 
1  /* GNU Mailutils -- a suite of utilities for electronic mail  /* GNU Mailutils -- a suite of utilities for electronic mail
2     Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.     Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3    
4     GNU Mailutils program is free software; you can redistribute it and/or modify     GNU Mailutils is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2, or (at your option)     the Free Software Foundation; either version 2, or (at your option)
7     any later version.     any later version.
8    
9     GNU Mailutils program is distributed in the hope that it will be useful,     GNU Mailutils is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.     GNU General Public License for more details.
13    
14     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
15     along with GNU Mailutils program; if not, write to the Free Software     along with GNU Mailutils; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
17    
18  %{  %{
# Line 50  static int select_deleted __P ((message_ Line 50  static int select_deleted __P ((message_
50  int yyerror __P ((const char *));  int yyerror __P ((const char *));
51  int yylex  __P ((void));  int yylex  __P ((void));
52    
53    static int msgset_flags = MSG_NODELETED;
54  static msgset_t *result;  static msgset_t *result;
55  %}  %}
56    
# Line 114  msgset   : msgexpr Line 115  msgset   : msgexpr
115           ;           ;
116    
117  msgexpr  : msgspec  msgexpr  : msgspec
118               {
119                 $$ = $1;
120                 if (check_set (&$$))
121                   YYABORT;
122               }
123           | '{' msgset '}'           | '{' msgset '}'
124             {             {
125               $$ = $2;               $$ = $2;
# Line 331  yylex() Line 337  yylex()
337  }  }
338    
339  int  int
340  msgset_parse (const int argc, char **argv, msgset_t **mset)  msgset_parse (const int argc, char **argv, int flags, msgset_t **mset)
341  {  {
342    int rc;    int rc;
343    xargc = argc;    xargc = argc;
344    xargv = argv;    xargv = argv;
345      msgset_flags = flags;
346    cur_ind = 1;    cur_ind = 1;
347    cur_p = NULL;    cur_p = NULL;
348    result = NULL;    result = NULL;
349    rc = yyparse ();    rc = yyparse ();
350    if (rc == 0)    if (rc == 0)
351      *mset = result;      {
352          if (result == NULL)
353            {
354              util_noapp ();
355              rc = 1;
356            }
357          else
358            *mset = result;
359        }
360    return rc;    return rc;
361  }  }
362    
# Line 362  msgset_free (msgset_t *msg_set) Line 377  msgset_free (msgset_t *msg_set)
377      }      }
378  }  }
379    
380    size_t
381    msgset_count (msgset_t *set)
382    {
383      size_t count = 0;
384      for (; set; set = set->next)
385        count++;
386      return count;
387    }
388    
389  /* Create a message set consisting of a single msg_num and no subparts */  /* Create a message set consisting of a single msg_num and no subparts */
390  msgset_t *  msgset_t *
391  msgset_make_1 (int number)  msgset_make_1 (int number)
392  {  {
393    msgset_t *mp;    msgset_t *mp;
394    
395      if (number == 0)
396        return NULL;
397    mp = xmalloc (sizeof (*mp));    mp = xmalloc (sizeof (*mp));
398    mp->next = NULL;    mp->next = NULL;
399    mp->npart = 1;    mp->npart = 1;
# Line 674  select_deleted (message_t msg, void *clo Line 700  select_deleted (message_t msg, void *clo
700    return strcmp (xargv[0], "undelete") == 0 ? rc : !rc;    return strcmp (xargv[0], "undelete") == 0 ? rc : !rc;
701  }  }
702    
703    int
704    check_set (msgset_t **pset)
705    {
706      int flags = msgset_flags;
707      int rc = 0;
708      
709      if (msgset_count (*pset) == 1)
710        flags ^= MSG_SILENT;
711      if (flags & MSG_NODELETED)
712        {
713          msgset_t *p = *pset, *prev = NULL;
714          msgset_t *delset = NULL;
715    
716          while (p)
717            {
718              msgset_t *next = p->next;
719              if (util_isdeleted (p->msg_part[0]))
720                {
721                  if ((flags & MSG_SILENT)
722                      && prev != NULL
723                      && next != NULL)
724                    {
725                      /* Mark subset as deleted */
726                      p->next = delset;
727                      delset = p;
728                      /* Remove it from the set */
729                      if (prev)
730                        prev->next = next;
731                      else
732                        *pset = next;
733                    }
734                  else
735                    {
736                      util_error (_("%lu: Inappropriate message (has been deleted)"),
737                                  (unsigned long) p->msg_part[0]);
738                      /* Delete entire set */
739                      delset = *pset;
740                      *pset = NULL;
741                      rc = 1;
742                      break;
743                    }
744                }
745              else
746                prev = p;
747              p = next;
748            }
749    
750          if (delset)
751            msgset_free (delset);
752    
753          if (!*pset)
754            rc = 1;
755        }
756    
757      return rc;
758    }
759    
760  #if 0  #if 0
761  void  void
762  msgset_print (msgset_t *mset)  msgset_print (msgset_t *mset)

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26