8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / tools / cscope-fast / edit.c
blob740960e156c761204b23bb99ee20681b2d6a012d
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1999 by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI"
34 * cscope - interactive C symbol cross-reference
36 * file editing functions
39 #include <curses.h> /* KEY_BREAK and refresh */
40 #include <libgen.h>
41 #include <stdio.h>
42 #include "global.h"
45 /* edit this displayed reference */
47 void
48 editref(int i)
50 char file[PATHLEN + 1]; /* file name */
51 char linenum[NUMLEN + 1]; /* line number */
53 /* verify that there is a references found file */
54 if (refsfound == NULL) {
55 return;
57 /* get the selected line */
58 seekline(i + topline);
60 /* get the file name and line number */
61 if (fscanf(refsfound, "%s%*s%s", file, linenum) == 2) {
62 edit(file, linenum); /* edit it */
64 seekline(topline); /* restore the line pointer */
67 /* edit all references */
69 void
70 editall(void)
72 char file[PATHLEN + 1]; /* file name */
73 char linenum[NUMLEN + 1]; /* line number */
74 int c;
76 /* verify that there is a references found file */
77 if (refsfound == NULL) {
78 return;
80 /* get the first line */
81 seekline(1);
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;
97 seekline(topline);
100 /* call the editor */
102 void
103 edit(char *file, char *linenum)
105 char msg[MSGLEN + 1]; /* message */
106 char plusnum[NUMLEN + 2]; /* line number option */
107 char *s;
109 (void) sprintf(msg, "%s +%s %s", editor, linenum, file);
110 putmsg(msg);
111 (void) sprintf(plusnum, "+%s", linenum);
113 /* if this is the more or page commands */
114 if (strcmp(s = basename(editor), "more") == 0 ||
115 strcmp(s, "page") == 0) {
117 * get it to pause after displaying a file smaller
118 * than the screen length
120 (void) execute(editor, editor, plusnum, file, "/dev/null",
121 (char *)NULL);
122 } else {
123 (void) execute(editor, editor, plusnum, file, (char *)NULL);