/* Copyright (C) 2017-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: hbindex.ctr */ /** @file hbindex.c The hbindex module. */ #line 59 "hbindex.ctr" #include "dk3all.h" #include "htmlbook.h" #line 67 "hbindex.ctr" int hbindex_compare(void const *l, void const *r, int cr) { hb_index_entry_t const *pl; hb_index_entry_t const *pr; int back = 0; #line 77 "hbindex.ctr" if(l) { if(r) { pl = (hb_index_entry_t const *)l; switch(cr) { case 1: { back = dk3str_casecmp(pl->tx, (dkChar const *)r); } break; default: { pr = (hb_index_entry_t const *)r; back = dk3str_casecmp(pl->tx, pr->tx); if(0 == back) { #if VERSION_BEFORE_20140423 if(pl->fn) { if(pr->fn) { back = dk3str_fncmp(pl->fn, pr->fn); } else back = 1; } else { if(pr->fn) back = -1; } #else if (pl->no) { if (pr->no) { if ((pl->no)->objno > (pr->no)->objno) { back = 1; } else { if ((pr->no)->objno > (pl->no)->objno) { back = -1; } } } else back = 1; } else { if (pr->no) back = -1; } #endif } if(0 == back) { if(pl->an) { if(pr->an) { back = dk3str_cmp(pl->an, pr->an); } else back = 1; } else { if(pr->an) back = -1; else { if(pl->ul > pr->ul) { back = 1; } else { if(pl->ul < pr->ul) { back = -1; } } } } } } break; } if(-1 > back) { back = -1; } if( 1 < back) { back = 1; } } else { back = 1; } } else { if(r) { back = -1; } } #line 142 "hbindex.ctr" return back; } void hbindex_delete(hb_index_entry_t *pi) { #line 151 "hbindex.ctr" if(pi) { #line 153 "hbindex.ctr" #line 154 "hbindex.ctr" #line 155 "hbindex.ctr" #line 156 "hbindex.ctr" pi->no = NULL; dk3_release(pi->tx); dk3_release(pi->fn); dk3_release(pi->an); pi->ul = 0UL; dk3_delete(pi); } #line 163 "hbindex.ctr" } hb_index_entry_t * hbindex_new( dkChar const *tx, dkChar const *fn, dkChar const *an, unsigned long const ul, dk3_app_t *app, hb_node_t *nptr ) { hb_index_entry_t *back = NULL; /* New index entry */ int ok = 0; #line 179 "hbindex.ctr" if((tx) && (fn)) { back = dk3_new_app(hb_index_entry_t,1,app); if(back) { back->no = nptr; back->tx = NULL; back->fn = NULL; back->an = NULL; back->ul = ul; back->tx = dk3str_dup_app(tx,app); back->fn = dk3str_dup_app(fn,app); if((back->tx) && (back->fn)) { ok = 1; if(an) { back->an = dk3str_dup_app(an,app); if(!(back->an)) { ok = 0; } } } if(!(ok)) { hbindex_delete(back); back = NULL; } } } #line 202 "hbindex.ctr" return back; } int hb_index_write_anchor(hb_job_t *job, hb_index_entry_t *in) { int back = 0; #line 212 "hbindex.ctr" if((job) && (in)) { back = 1; if(in->an) { if(!hbhtml_url_output_for_text(job, in->an)) { back = 0; } } else { #if DK3_SIZEOF_LONG > 4 fprintf(job->of, "hb_i%016lx", in->ul); #else fprintf(job->of, "hb_i%08lx", in->ul); #endif } } #line 226 "hbindex.ctr" return back; }