1 /* 2 * Copyright (c) 1982, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Edward Wang at The University of California, Berkeley. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)wwterminfo.c 8.1 (Berkeley) 06/06/93"; 13 #endif /* not lint */ 14 15 #ifdef TERMINFO 16 17 #include "ww.h" 18 #include <stdio.h> 19 #include <paths.h> 20 #include "local.h" 21 22 /* 23 * Terminfo support 24 * 25 * Written by Brian Buhrow 26 * 27 * Subsequently modified by Edward Wang 28 */ 29 30 /* 31 * Initialize the working terminfo directory 32 */ 33 wwterminfoinit() 34 { 35 FILE *fp; 36 char buf[2048]; 37 38 /* make the directory */ 39 (void) sprintf(wwterminfopath, "%swwinXXXXXX", _PATH_TMP); 40 mktemp(wwterminfopath); 41 if (mkdir(wwterminfopath, 0755) < 0 || 42 chmod(wwterminfopath, 00755) < 0) { 43 wwerrno = WWE_SYS; 44 return -1; 45 } 46 (void) setenv("TERMINFO", wwterminfopath, 1); 47 /* make a termcap entry and turn it into terminfo */ 48 (void) sprintf(buf, "%s/cap", wwterminfopath); 49 if ((fp = fopen(buf, "w")) == NULL) { 50 wwerrno = WWE_SYS; 51 return -1; 52 } 53 (void) fprintf(fp, "%sco#%d:li#%d:%s\n", 54 WWT_TERMCAP, wwncol, wwnrow, wwwintermcap); 55 (void) fclose(fp); 56 (void) sprintf(buf, 57 "cd %s; %s cap >info 2>/dev/null; %s info >/dev/null 2>&1", 58 wwterminfopath, _PATH_CAPTOINFO, _PATH_TIC); 59 (void) system(buf); 60 return 0; 61 } 62 63 /* 64 * Delete the working terminfo directory at shutdown 65 */ 66 wwterminfoend() 67 { 68 69 switch (vfork()) { 70 case -1: 71 /* can't really do (or say) anything about errors */ 72 return -1; 73 case 0: 74 execl(_PATH_RM, _PATH_RM, "-rf", wwterminfopath, 0); 75 return -1; 76 default: 77 return 0; 78 } 79 } 80 81 #endif /* TERMINFO */ 82