diff options
author | Karl Berry <karl@freefriends.org> | 2016-04-05 22:50:13 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-04-05 22:50:13 +0000 |
commit | 52e905992c395638cf339bcd463c71b197fc03b9 (patch) | |
tree | 88970c53454646c3953c29970ee9c81762b0f019 /Build/source/texk/xdvik/exit-handlers.c | |
parent | b56b320b5e2515160073fa1b469514002688fe11 (diff) |
import xdvik-22.87.03
git-svn-id: svn://tug.org/texlive/trunk@40253 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/xdvik/exit-handlers.c')
-rw-r--r-- | Build/source/texk/xdvik/exit-handlers.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/Build/source/texk/xdvik/exit-handlers.c b/Build/source/texk/xdvik/exit-handlers.c index 79a0629a973..0b34fdc2f45 100644 --- a/Build/source/texk/xdvik/exit-handlers.c +++ b/Build/source/texk/xdvik/exit-handlers.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004 Stefan Ulrich + * Copyright (c) 2004-2015 Stefan Ulrich and the xdvik development team * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -34,19 +34,27 @@ static struct exit_list { exit_procedure proc; void *arg; + struct exit_list *next; } *exit_procs = NULL; -static size_t exit_procs_size = 0; - void register_exit_handler(exit_procedure proc, void *arg) { - size_t idx = exit_procs_size; - exit_procs_size++; - exit_procs = xrealloc(exit_procs, sizeof *exit_procs * exit_procs_size); - exit_procs[idx].proc = proc; - exit_procs[idx].arg = arg; + struct exit_list *ep; + + /* first check for duplicates (needed because of remove_tmp_dvi_file) */ + for (ep = exit_procs; ep != NULL; ep = ep->next) { + if (ep->proc == proc && ep->arg == arg) + return; + } + + ep = xmalloc(sizeof *ep); + ep->proc = proc; + ep->arg = arg; + ep->next = exit_procs; + exit_procs = ep; } +#if 0 /* This is currently unused. */ void unregister_exit_handler(exit_procedure proc) { size_t i; @@ -58,14 +66,21 @@ void unregister_exit_handler(exit_procedure proc) } } } +#endif void call_exit_handlers(void) { - size_t i; - for (i = 0; i < exit_procs_size; i++) { - if (exit_procs[i].proc) - exit_procs[i].proc(exit_procs[i].arg); + struct exit_list *ep; + + for (ep = exit_procs; ep != NULL; ep = ep->next) { + ep->proc(ep->arg); /* fprintf(stderr, "calling exit proc %lu\n", (unsigned long)i); */ } - free(exit_procs); + + /* free them */ + while (exit_procs != NULL) { + ep = exit_procs; + exit_procs = exit_procs->next; + free(ep); + } } |