xref: /illumos-gate/usr/src/cmd/diff/diff.h (revision d2b76ef7)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*d2b76ef7SAndy Fiddaman /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
40*d2b76ef7SAndy Fiddaman /*
41*d2b76ef7SAndy Fiddaman  * Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
42*d2b76ef7SAndy Fiddaman  */
43*d2b76ef7SAndy Fiddaman 
447c478bd9Sstevel@tonic-gate #ifndef	_DIFF_H
457c478bd9Sstevel@tonic-gate #define	_DIFF_H
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
487c478bd9Sstevel@tonic-gate extern "C" {
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Output format options
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate int	opt;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #define	D_NORMAL	0	/* Normal output */
587c478bd9Sstevel@tonic-gate #define	D_EDIT		-1	/* Editor script out */
597c478bd9Sstevel@tonic-gate #define	D_REVERSE	1	/* Reverse editor script */
607c478bd9Sstevel@tonic-gate #define	D_CONTEXT	2	/* Diff with context */
617c478bd9Sstevel@tonic-gate #define	D_IFDEF		3	/* Diff with merged #ifdef's */
627c478bd9Sstevel@tonic-gate #define	D_NREVERSE	4	/* Reverse ed script with numbered */
637c478bd9Sstevel@tonic-gate 				/* lines and no trailing . */
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * Constant declarations
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate #define	HALFMASK	0xf
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	prints(s)	fputs(s, stdout)
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #define	MAX_CONTEXT	128
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * diff - directory comparison
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate #define	d_flags	d_ino
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	ONLY	1		/* Only in this directory */
807c478bd9Sstevel@tonic-gate #define	SAME	2		/* Both places and same */
817c478bd9Sstevel@tonic-gate #define	DIFFER	4		/* Both places and different */
827c478bd9Sstevel@tonic-gate #define	DIRECT	8		/* Directory */
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate struct dir {
857c478bd9Sstevel@tonic-gate 	ulong_t		d_ino;
867c478bd9Sstevel@tonic-gate 	int16_t		d_reclen;
877c478bd9Sstevel@tonic-gate 	int16_t		d_namlen;
887c478bd9Sstevel@tonic-gate 	char		*d_entry;
897c478bd9Sstevel@tonic-gate };
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  * type definitions
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate struct cand {
977c478bd9Sstevel@tonic-gate 	int x;
987c478bd9Sstevel@tonic-gate 	int y;
997c478bd9Sstevel@tonic-gate 	int pred;
1007c478bd9Sstevel@tonic-gate } cand;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate struct line {
1037c478bd9Sstevel@tonic-gate 	int serial;
1047c478bd9Sstevel@tonic-gate 	int value;
1057c478bd9Sstevel@tonic-gate } *file[2], line;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * The following struct is used to record change information when
1097c478bd9Sstevel@tonic-gate  * doing a "context" diff.  (see routine "change" to understand the
1107c478bd9Sstevel@tonic-gate  * highly mneumonic field names)
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate struct context_vec {
1137c478bd9Sstevel@tonic-gate 	int	a;	/* start line in old file */
1147c478bd9Sstevel@tonic-gate 	int	b;	/* end line in old file */
1157c478bd9Sstevel@tonic-gate 	int	c;	/* start line in new file */
1167c478bd9Sstevel@tonic-gate 	int	d;	/* end line in new file */
1177c478bd9Sstevel@tonic-gate };
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * Algorithm related options
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate int bflag = 0;
1247c478bd9Sstevel@tonic-gate int tflag = 0;
1257c478bd9Sstevel@tonic-gate int wflag = 0;
1267c478bd9Sstevel@tonic-gate int iflag = 0;
127*d2b76ef7SAndy Fiddaman int qflag = 0;
1287c478bd9Sstevel@tonic-gate int rflag = 0;
1297c478bd9Sstevel@tonic-gate int lflag = 0;
1307c478bd9Sstevel@tonic-gate int sflag = 0;
1317c478bd9Sstevel@tonic-gate int hflag = 0;
1327c478bd9Sstevel@tonic-gate int uflag = 0;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * Variables for D_IFDEF option.
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate int wantelses = 0;	/* used with D_IFDEF */
1387c478bd9Sstevel@tonic-gate char *ifdef1, *ifdef2;  /* hold the ifdef strings */
1397c478bd9Sstevel@tonic-gate char *endifname;
1407c478bd9Sstevel@tonic-gate int inifdef = 0;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * Variables for -C (-c) context option.
1447c478bd9Sstevel@tonic-gate  */
1457c478bd9Sstevel@tonic-gate int context = 0;	/* number of lines specfied with the C flag */
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate char *empty = "";	/* the empty string */
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate char **diffargv;	/* keep track of argv for diffdir */
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate char start[256];	/* specify where to start, used with -S */
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate FILE *input[2];		/* two input files */
1547c478bd9Sstevel@tonic-gate int  len[2];
1557c478bd9Sstevel@tonic-gate struct line *sfile[2];  /* shortened by pruning common prefix and suffix */
1567c478bd9Sstevel@tonic-gate int  slen[2];
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate struct stat stb1;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate /*
1617c478bd9Sstevel@tonic-gate  * Input file names.
1627c478bd9Sstevel@tonic-gate  * With diffdir, file1 and file2 are allocated BUFSIZ space,
1637c478bd9Sstevel@tonic-gate  * and padded with a '/', and then efile0 and efile1 point after
1647c478bd9Sstevel@tonic-gate  * the '/'.
1657c478bd9Sstevel@tonic-gate  */
1667c478bd9Sstevel@tonic-gate char	*file1, *file2, *efile1, *efile2;
1677c478bd9Sstevel@tonic-gate struct	stat stb1, stb2;
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * input_file1 and input_file2 are to display
1717c478bd9Sstevel@tonic-gate  * the filenames in the output
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate char	*input_file1, *input_file2;
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate char pr[] = "/usr/bin/pr";
1767c478bd9Sstevel@tonic-gate char diff[] = "/usr/bin/diff";
1777c478bd9Sstevel@tonic-gate char diffh[] = "/usr/lib/diffh";
1787c478bd9Sstevel@tonic-gate int status = 2;
1797c478bd9Sstevel@tonic-gate int anychange = 0;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate struct	context_vec	*context_vec_start,
1827c478bd9Sstevel@tonic-gate 			*context_vec_end,
1837c478bd9Sstevel@tonic-gate 			*context_vec_ptr;
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate char tempfile[2][16];	/* used when comparing against std input */
1867c478bd9Sstevel@tonic-gate 			/* or char special devices */
1877c478bd9Sstevel@tonic-gate int whichtemp;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate #endif
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate #endif	/* _DIFF_H */
194