1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 23 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 24 /* All Rights Reserved */ 25 26 27 /* 28 * Copyright (c) 1997, by Sun Microsystems, Inc. 29 * All rights reserved. 30 */ 31 32 /*LINTLIBRARY*/ 33 34 #include <stdio.h> 35 #include <string.h> 36 #include <stdlib.h> 37 #include <sys/types.h> 38 #include "libadm.h" 39 40 void 41 puthelp(FILE *fp, char *defmesg, char *help) 42 { 43 char *tmp; 44 size_t n; 45 46 tmp = NULL; 47 if (help == NULL) { 48 /* use default message since no help was provided */ 49 help = defmesg ? defmesg : "No help available."; 50 } else if (defmesg != NULL) { 51 n = strlen(help); 52 if (help[0] == '~') { 53 /* prepend default message */ 54 tmp = calloc(n+strlen(defmesg)+1, sizeof (char)); 55 (void) strcpy(tmp, defmesg); 56 (void) strcat(tmp, "\n"); 57 ++help; 58 (void) strcat(tmp, help); 59 help = tmp; 60 } else if (n && (help[n-1] == '~')) { 61 /* append default message */ 62 tmp = calloc(n+strlen(defmesg)+2, sizeof (char)); 63 (void) strcpy(tmp, help); 64 tmp[n-1] = '\0'; 65 (void) strcat(tmp, "\n"); 66 (void) strcat(tmp, defmesg); 67 help = tmp; 68 } 69 } 70 (void) puttext(fp, help, ckindent, ckwidth); 71 (void) fputc('\n', fp); 72 if (tmp) 73 free(tmp); 74 } 75