Print this page
9718 update mandoc to 1.14.4
   1 /*      $Id: tag.c,v 1.18 2017/02/17 14:31:52 schwarze Exp $ */
   2 /*
   3  * Copyright (c) 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
   4  *
   5  * Permission to use, copy, modify, and distribute this software for any
   6  * purpose with or without fee is hereby granted, provided that the above
   7  * copyright notice and this permission notice appear in all copies.
   8  *
   9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16  */
  17 #include "config.h"
  18 
  19 #include <sys/types.h>
  20 
  21 #include <signal.h>


 196         struct tag_entry        *entry;
 197         size_t                   i;
 198         unsigned int             slot;
 199 
 200         if (tag_files.tfd <= 0)
 201                 return;
 202         stream = fdopen(tag_files.tfd, "w");
 203         entry = ohash_first(&tag_data, &slot);
 204         while (entry != NULL) {
 205                 if (stream != NULL && entry->prio >= 0)
 206                         for (i = 0; i < entry->nlines; i++)
 207                                 fprintf(stream, "%s %s %zu\n",
 208                                     entry->s, tag_files.ofn, entry->lines[i]);
 209                 free(entry->lines);
 210                 free(entry);
 211                 entry = ohash_next(&tag_data, &slot);
 212         }
 213         ohash_delete(&tag_data);
 214         if (stream != NULL)
 215                 fclose(stream);



 216 }
 217 
 218 void
 219 tag_unlink(void)
 220 {
 221         pid_t    tc_pgid;
 222 
 223         if (tag_files.tcpgid != -1) {
 224                 tc_pgid = tcgetpgrp(tag_files.ofd);
 225                 if (tc_pgid == tag_files.pager_pid ||
 226                     tc_pgid == getpgid(0) ||
 227                     getpgid(tc_pgid) == -1)
 228                         (void)tcsetpgrp(tag_files.ofd, tag_files.tcpgid);
 229         }
 230         if (*tag_files.ofn != '\0')
 231                 unlink(tag_files.ofn);
 232         if (*tag_files.tfn != '\0')
 233                 unlink(tag_files.tfn);
 234 }
 235 
   1 /*      $Id: tag.c,v 1.19 2018/02/23 16:47:10 schwarze Exp $ */
   2 /*
   3  * Copyright (c) 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
   4  *
   5  * Permission to use, copy, modify, and distribute this software for any
   6  * purpose with or without fee is hereby granted, provided that the above
   7  * copyright notice and this permission notice appear in all copies.
   8  *
   9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16  */
  17 #include "config.h"
  18 
  19 #include <sys/types.h>
  20 
  21 #include <signal.h>


 196         struct tag_entry        *entry;
 197         size_t                   i;
 198         unsigned int             slot;
 199 
 200         if (tag_files.tfd <= 0)
 201                 return;
 202         stream = fdopen(tag_files.tfd, "w");
 203         entry = ohash_first(&tag_data, &slot);
 204         while (entry != NULL) {
 205                 if (stream != NULL && entry->prio >= 0)
 206                         for (i = 0; i < entry->nlines; i++)
 207                                 fprintf(stream, "%s %s %zu\n",
 208                                     entry->s, tag_files.ofn, entry->lines[i]);
 209                 free(entry->lines);
 210                 free(entry);
 211                 entry = ohash_next(&tag_data, &slot);
 212         }
 213         ohash_delete(&tag_data);
 214         if (stream != NULL)
 215                 fclose(stream);
 216         else
 217                 close(tag_files.tfd);
 218         tag_files.tfd = -1;
 219 }
 220 
 221 void
 222 tag_unlink(void)
 223 {
 224         pid_t    tc_pgid;
 225 
 226         if (tag_files.tcpgid != -1) {
 227                 tc_pgid = tcgetpgrp(tag_files.ofd);
 228                 if (tc_pgid == tag_files.pager_pid ||
 229                     tc_pgid == getpgid(0) ||
 230                     getpgid(tc_pgid) == -1)
 231                         (void)tcsetpgrp(tag_files.ofd, tag_files.tcpgid);
 232         }
 233         if (*tag_files.ofn != '\0')
 234                 unlink(tag_files.ofn);
 235         if (*tag_files.tfn != '\0')
 236                 unlink(tag_files.tfn);
 237 }
 238