Skip to content

Commit

Permalink
Simplify xxx_is_same() functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Chorbadzhiyski committed Jan 31, 2015
1 parent f69e34f commit 45e7e99
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 17 deletions.
6 changes: 4 additions & 2 deletions cat.c
Expand Up @@ -185,8 +185,10 @@ void ts_cat_dump(struct ts_cat *cat) {

int ts_cat_is_same(struct ts_cat *cat1, struct ts_cat *cat2) {
if (cat1 == cat2) return 1; // Same
if ((!cat1 && cat2) || (cat1 && !cat2)) return 0; // Not same (one is NULL)
return ts_section_is_same(cat1->section_header, cat2->section_header);
if (cat1 && cat2)
return ts_section_is_same(cat1->section_header, cat2->section_header);
else
return 0;
}

enum CA_system ts_get_CA_sys(uint16_t CA_id) {
Expand Down
6 changes: 4 additions & 2 deletions eit.c
Expand Up @@ -310,6 +310,8 @@ void ts_eit_dump(struct ts_eit *eit) {

int ts_eit_is_same(struct ts_eit *eit1, struct ts_eit *eit2) {
if (eit1 == eit2) return 1; // Same
if ((!eit1 && eit2) || (eit1 && !eit2)) return 0; // Not same (one is NULL)
return ts_section_is_same(eit1->section_header, eit2->section_header);
if (eit1 && eit2)
return ts_section_is_same(eit1->section_header, eit2->section_header);
else
return 0;
}
6 changes: 4 additions & 2 deletions nit.c
Expand Up @@ -294,6 +294,8 @@ void ts_nit_dump(struct ts_nit *nit) {

int ts_nit_is_same(struct ts_nit *nit1, struct ts_nit *nit2) {
if (nit1 == nit2) return 1; // Same
if ((!nit1 && nit2) || (nit1 && !nit2)) return 0; // Not same (one is NULL)
return ts_section_is_same(nit1->section_header, nit2->section_header);
if (nit1 && nit2)
return ts_section_is_same(nit1->section_header, nit2->section_header);
else
return 0;
}
6 changes: 4 additions & 2 deletions pat.c
Expand Up @@ -231,6 +231,8 @@ void ts_pat_dump(struct ts_pat *pat) {

int ts_pat_is_same(struct ts_pat *pat1, struct ts_pat *pat2) {
if (pat1 == pat2) return 1; // Same
if ((!pat1 && pat2) || (pat1 && !pat2)) return 0; // Not same (one is NULL)
return ts_section_is_same(pat1->section_header, pat2->section_header);
if (pat1 && pat2)
return ts_section_is_same(pat1->section_header, pat2->section_header);
else
return 0;
}
6 changes: 4 additions & 2 deletions pmt.c
Expand Up @@ -295,6 +295,8 @@ void ts_pmt_dump(struct ts_pmt *pmt) {

int ts_pmt_is_same(struct ts_pmt *pmt1, struct ts_pmt *pmt2) {
if (pmt1 == pmt2) return 1; // Same
if ((!pmt1 && pmt2) || (pmt1 && !pmt2)) return 0; // Not same (one is NULL)
return ts_section_is_same(pmt1->section_header, pmt2->section_header);
if (pmt1 && pmt2)
return ts_section_is_same(pmt1->section_header, pmt2->section_header);
else
return 0;
}
9 changes: 6 additions & 3 deletions privsec.c
Expand Up @@ -87,9 +87,12 @@ struct ts_privsec *ts_privsec_push_packet(struct ts_privsec *privsec, uint8_t *t

int ts_privsec_is_same(struct ts_privsec *p1, struct ts_privsec *p2) {
if (p1 == p2) return 1; // Same
if ((!p1 && p2) || (p1 && !p2)) return 0; // Not same (one is NULL)
if (p1->section_header->section_length != p1->section_header->section_length) return 0; // Not same
return memcmp(p1->section_header->section_data, p2->section_header->section_data, p1->section_header->section_length) == 0;
if (p1 && p2) {
if (p1->section_header->section_length != p2->section_header->section_length) return 0; // Not same
return memcmp(p1->section_header->section_data, p2->section_header->section_data, p1->section_header->section_length) == 0;
} else {
return 0;
}
}

void ts_privsec_dump(struct ts_privsec *privsec) {
Expand Down
6 changes: 4 additions & 2 deletions sdt.c
Expand Up @@ -267,6 +267,8 @@ void ts_sdt_dump(struct ts_sdt *sdt) {

int ts_sdt_is_same(struct ts_sdt *sdt1, struct ts_sdt *sdt2) {
if (sdt1 == sdt2) return 1; // Same
if ((!sdt1 && sdt2) || (sdt1 && !sdt2)) return 0; // Not same (one is NULL)
return ts_section_is_same(sdt1->section_header, sdt2->section_header);
if (sdt1 && sdt2)
return ts_section_is_same(sdt1->section_header, sdt2->section_header);
else
return 0;
}
6 changes: 4 additions & 2 deletions tdt.c
Expand Up @@ -234,6 +234,8 @@ void ts_tdt_dump(struct ts_tdt *tdt) {

int ts_tdt_is_same(struct ts_tdt *tdt1, struct ts_tdt *tdt2) {
if (tdt1 == tdt2) return 1; // Same
if ((!tdt1 && tdt2) || (tdt1 && !tdt2)) return 0; // Not same (one is NULL)
return ts_section_is_same(tdt1->section_header, tdt2->section_header);
if (tdt1 && tdt2)
return ts_section_is_same(tdt1->section_header, tdt2->section_header);
else
return 0;
}

0 comments on commit 45e7e99

Please sign in to comment.