たとえば、定数 100 をプリプロセッサシンボル MAXSIZE に変更するとします。6 番目のメニュー項目「Change this text string」を選択して、¥100 と入力します。1 の前にはバックスラッシュを加えて、cscope のメニュー項目番号を意味する 1 と区別します。Return キーを押すと cscope は新しい文字列を聞いてくるので、MAXSIZE と入力します。
cscope Press the ? key for help Find this C symbol: Find this global definition: Find functions called by this function: Find functions calling this function: Find this text string: Change this text string: ¥100 Find this egrep pattern: Find this file: Find files #including this file: To: MAXSIZE
cscope は、指定された文字列を含む行を表示します。どの行の文字列を変更するかが選択されるまで入力待ちになります。
Change "100" to "MAXSIZE"
File Line
1 init.c 4 char s[100];
2 init.c 26 for (i = 0; i < 100; i++)
3 find.c 8 if (c < 100) {
4 read.c 12 f = (bb & 0100);
5 err.c 19 p = total/100.0; /* 百分率にする */
Find this C symbol:
Find this global definition:
Find functions called by this function:
Find functions calling this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:
Select lines to change (press the ? key for help):
リストの 1、2、3 行目 (ソースファイル内の行番号はそれぞれ 4、26、8 行目) に含まれる定数 100 は、MAXSIZE に変更すべきだとわかります。また、read.c 内の 0100 と err.c 内の 100.0 (リストの 4、 5 行目) は、変更すべきでないこともわかります。変更する行を指定するには、以下の単一キーコマンドを使用します。
表 4-3 変更行選択コマンド|
1-9 |
変更行をマークまたはマーク解除する |
|
* |
表示されている行をすべて変更対象としてマークまたはマーク解除する |
|
スペース |
次画面のリストを表示する |
|
+ |
次画面のリストを表示する |
|
- |
前画面のリストを表示する |
|
a |
すべての行を変更対象としてマークする |
|
^d |
マークされた行を変更して終了する |
|
Esc |
マークされた行を変更しないで終了する |
この場合、1、2、および 3 を入力します。入力した番号は画面上には表示されません。代わりに各行の行番号の後に > (右不等号) を表示することによって、変更箇所を示します。
Change "100" to "MAXSIZE"
File Line
1>init.c 4 char s[100];
2>init.c 26 for (i = 0; i < 100; i++)
3>find.c 8 if (c < 100) {
4 read.c 12 f = (bb & 0100);
5 err.c 19 p = total/100.0; /* 百分率にする */
Find this C symbol:
Find this global definition:
Find functions called by this function:
Find functions calling this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:
Select lines to change (press the ? key for help):
ここで、^d を入力して選択行を変更します。cscope は変更後の各行を表示し、作業の継続を促します。
Changed lines:
char s[MAXSIZE];
for (i = 0; i < MAXSIZE; i++)
if (c < MAXSIZE) {
Press the RETURN key to continue:
このプロンプトに対して Return キーを押すと、cscope は画面を書き換えて変更行を指定する前の画面に戻ります。
次に新しいシンボル MAXSIZE の #define 文を追加します。#define 文を追加するヘッダーファイルは、現在表示されている行の参照元ファイルの中にはありません。したがって、! と入力してシェルに入る必要があります。シェルプロンプトが画面の一番下に現れます。あとは、エディタを起動して #define 文を追加します。
Text string: 100
File Line
1 init.c 4 char s[100];
2 init.c 26 for (i = 0; i < 100; i++)
3 find.c 8 if (c < 100) {
4 read.c 12 f = (bb & 0100);
5 err.c 19 p = total/100.0; /* 百分率にする */
Find this C symbol:
Find this global definition:
Find functions called by this function:
Find functions calling this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:
$ vi defs.h
cscope セッションへ戻るには、エディタを終了し、^d を入力してシェルを終了させます。