po: Update German man pages translation
[dpkg.git] / lib / dpkg / trignote.c
blob957e80859af380af55d7d393902c58f782eb9e21
1 /*
2 * libdpkg - Debian packaging suite library routines
3 * trignote.c - trigger note handling
5 * Copyright © 2007 Canonical Ltd
6 * Written by Ian Jackson <ijackson@chiark.greenend.org.uk>
7 * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
9 * This is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 #include <config.h>
24 #include <compat.h>
26 #include <string.h>
28 #include <dpkg/dpkg.h>
29 #include <dpkg/dpkg-db.h>
30 #include <dpkg/pkg.h>
31 #include <dpkg/pkg-list.h>
32 #include <dpkg/dlist.h>
33 #include <dpkg/triglib.h>
36 * Note: This is also called from fields.c where *pend is a temporary!
38 * trig is not copied!
40 bool
41 trig_note_pend_core(struct pkginfo *pend, const char *trig)
43 struct trigpend *tp;
45 for (tp = pend->trigpend_head; tp; tp = tp->next)
46 if (strcmp(tp->name, trig) == 0)
47 return false;
49 tp = nfmalloc(sizeof(*tp));
50 tp->name = trig;
51 tp->next = pend->trigpend_head;
52 pend->trigpend_head = tp;
54 return true;
58 * trig is not copied!
60 * @retval true For done.
61 * @retval false For already noted.
63 bool
64 trig_note_pend(struct pkginfo *pend, const char *trig)
66 if (!trig_note_pend_core(pend, trig))
67 return false;
69 if (pend->trigaw.head)
70 pkg_set_status(pend, PKG_STAT_TRIGGERSAWAITED);
71 else
72 pkg_set_status(pend, PKG_STAT_TRIGGERSPENDING);
74 return true;
78 * Note: This is called also from fields.c where *aw is a temporary
79 * but pend is from pkg_hash_find()!
81 * @retval true For done.
82 * @retval false For already noted.
84 bool
85 trig_note_aw(struct pkginfo *pend, struct pkginfo *aw)
87 struct trigaw *ta;
89 /* We search through aw's list because that's probably shorter. */
90 for (ta = aw->trigaw.head; ta; ta = ta->sameaw.next)
91 if (ta->pend == pend)
92 return false;
94 ta = nfmalloc(sizeof(*ta));
95 ta->aw = aw;
96 ta->pend = pend;
97 ta->samepend_next = pend->othertrigaw_head;
98 pend->othertrigaw_head = ta;
99 LIST_LINK_TAIL_PART(aw->trigaw, ta, sameaw);
101 return true;
104 static struct pkg_list *trig_awaited_pend_head;
106 void
107 trig_awaited_pend_enqueue(struct pkginfo *pend)
109 struct pkg_list *tp;
111 for (tp = trig_awaited_pend_head; tp; tp = tp->next)
112 if (tp->pkg == pend)
113 return;
115 pkg_list_prepend(&trig_awaited_pend_head, pend);
118 void
119 trig_awaited_pend_foreach(trig_awaited_pend_foreach_func *func)
121 struct pkg_list *tp;
123 for (tp = trig_awaited_pend_head; tp; tp = tp->next)
124 if (!tp->pkg->trigpend_head)
125 func(tp->pkg);
128 void
129 trig_awaited_pend_free(void)
131 pkg_list_free(trig_awaited_pend_head);
132 trig_awaited_pend_head = NULL;