Oracle Solaris Studio 12.2: C ユーザーガイド

8.2.8.1 例 1: 定数をプリプロセッサシンボルに変更する

たとえば、定数 100 をプリプロセッサシンボル MAXSIZE に変更するとします。6 番目のメニュー項目「Change this text string」を選択して \100 と入力します。1 の前にはバックスラッシュを加えて、cscope のメニュー項目番号を意味する 1 と区別します。Return キーを押すと cscope は新しい文字列を聞いてくるので、MAXSIZE と入力します。

cscope 関数: 文字列の変更


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 は、指定された文字列を含む行を表示します。どの行の文字列を変更するかが選択されるまで入力待ちになります。

cscope 関数: 変更行に対するプロンプト


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

リストの 1、2、3 行目 (ソースファイル内の行番号はそれぞれ 4、26、8 行目) に含まれる定数 100 は、MAXSIZE に変更すべきだとわかります。さらに、read.c0100 (4 行目) と err.c100.0 (5 行目) は変更すべきではないこともわかります。次の単一キーコマンドを使用して、変更したい行を選択します。

表 8–3 変更する行を選択するコマンド

1-9

変更対象の行をマークしたり、マークを削除する 

*

すべての表示行を変更対象としてマークしたり、マークを削除する 

スペース 

次画面のリストを表示する 

+

次画面のリストを表示する 

前画面のリストを表示する 

a

すべての行を変更対象としてマークする 

^d

マークされた行を変更して終了する 

Esc

マークされた行を変更しないで終了する 

この場合、12、および 3 を入力します。入力した番号は画面上には表示されません。代わりに cscope は各行の行番号のあとに > (右不等号) を表示することによって、変更箇所を示します。

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; /* get percentage */

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 は変更後の各行を表示し、作業の継続を促します。

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 文を追加します。

cscope 関数: シェルへの一時移行


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;                                        /* get percentage */

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 を入力してシェルを終了させます。