4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
43 #define ERR_NOTROOT "You must be \"root\" for %s to execute properly."
45 static void usage(void);
46 static int docmd(char *cmd
, char *file
, char *input
);
49 main(int argc
, char *argv
[])
54 *keyword
, /* keyword = install || remove */
55 *input
, /* sed input file */
57 *srcfile
, /* sed data file */
58 *destfile
; /* target file to be updated */
62 (void) setlocale(LC_ALL
, "");
64 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
65 #define TEXT_DOMAIN "SYS_TEST"
67 (void) textdomain(TEXT_DOMAIN
);
69 prog
= set_prog_name(argv
[0]);
72 progerr(gettext(ERR_NOTROOT
), prog
);
85 if ((fp
= fopen(srcfile
, "r")) == NULL
) {
86 progerr(gettext("unable to open %s"), srcfile
);
90 input
= tempnam(NULL
, "sedinp");
91 if ((fpout
= fopen(input
, "w")) == NULL
) {
92 progerr(gettext("unable to open %s"), input
);
97 while (fgets(line
, LSIZE
, fp
)) {
98 for (pt
= line
; isspace(*pt
); /* void */)
102 if (*pt
== COMMAND
) {
104 break; /* no more lines to read */
105 pt
= strtok(pt
+1, " \t\n");
107 progerr(gettext("null token after '!'"));
110 flag
= (strcmp(pt
, keyword
) ? 0 : 1);
111 } else if (flag
== 1) { /* bug # 1083359 */
112 (void) fputs(line
, fpout
);
115 (void) fclose(fpout
);
117 if (docmd(cmd
, destfile
, input
)) {
118 progerr(gettext("command failed <%s>"), cmd
);
122 (void) unlink(input
);
127 docmd(char *cmd
, char *file
, char *input
)
132 tempout
= tempnam(NULL
, "temp1");
136 (void) sprintf(command
, "%s -f %s <%s >%s", cmd
, input
, file
, tempout
);
140 (void) sprintf(command
, "cp %s %s", tempout
, file
);
144 (void) unlink(tempout
);
152 (void) fprintf(stderr
, gettext("usage: %s cmd keyword src dest\n"),