xref: /titanic_44/usr/src/tools/cscope-fast/edit.c (revision 6dfee4834394825da35b977ca71cdc965bc7b6a4)
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 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright (c) 1999 by Sun Microsystems, Inc.
28  * All rights reserved.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 /*
34  *	cscope - interactive C symbol cross-reference
35  *
36  *	file editing functions
37  */
38 
39 #include <curses.h>	/* KEY_BREAK and refresh */
40 #include <libgen.h>
41 #include <stdio.h>
42 #include "global.h"
43 
44 
45 /* edit this displayed reference */
46 
47 void
48 editref(int i)
49 {
50 	char	file[PATHLEN + 1];	/* file name */
51 	char	linenum[NUMLEN + 1];	/* line number */
52 
53 	/* verify that there is a references found file */
54 	if (refsfound == NULL) {
55 		return;
56 	}
57 	/* get the selected line */
58 	seekline(i + topline);
59 
60 	/* get the file name and line number */
61 	if (fscanf(refsfound, "%s%*s%s", file, linenum) == 2) {
62 		edit(file, linenum);	/* edit it */
63 	}
64 	seekline(topline);	/* restore the line pointer */
65 }
66 
67 /* edit all references */
68 
69 void
70 editall(void)
71 {
72 	char	file[PATHLEN + 1];	/* file name */
73 	char	linenum[NUMLEN + 1];	/* line number */
74 	int	c;
75 
76 	/* verify that there is a references found file */
77 	if (refsfound == NULL) {
78 		return;
79 	}
80 	/* get the first line */
81 	seekline(1);
82 
83 	/* get each file name and line number */
84 	while (fscanf(refsfound, "%s%*s%s%*[^\n]", file, linenum) == 2) {
85 		edit(file, linenum);	/* edit it */
86 		if (editallprompt == YES) {
87 			putmsg("Type ^D to stop editing all lines, "
88 			    "or any other character to continue: ");
89 			if ((c = mygetch()) == EOF || c == ctrl('D') ||
90 			    c == ctrl('Z') || c == KEY_BREAK) {
91 				/* needed for interrupt on first time */
92 				(void) refresh();
93 				break;
94 			}
95 		}
96 	}
97 	seekline(topline);
98 }
99 
100 /* call the editor */
101 
102 void
103 edit(char *file, char *linenum)
104 {
105 	char	msg[MSGLEN + 1];	/* message */
106 	char	plusnum[NUMLEN + 2];	/* line number option */
107 	char	*s;
108 
109 	(void) sprintf(msg, "%s +%s %s", editor, linenum, file);
110 	putmsg(msg);
111 	(void) sprintf(plusnum, "+%s", linenum);
112 
113 	/* if this is the more or page commands */
114 	if (strcmp(s = basename(editor), "more") == 0 ||
115 	    strcmp(s, "page") == 0) {
116 		/*
117 		 * get it to pause after displaying a file smaller
118 		 * than the screen length
119 		 */
120 		(void) execute(editor, editor, plusnum, file, "/dev/null",
121 		    (char *)NULL);
122 	} else {
123 		(void) execute(editor, editor, plusnum, file, (char *)NULL);
124 	}
125 }
126