なぜ Ambiguous set command がでてしまう?

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
えいえい
記事: 13
登録日時: 9年前

なぜ Ambiguous set command がでてしまう?

#1

投稿記事 by えいえい » 9年前

お世話になります。
gdbでデバックしようと考え
set コマンドが上手く使えないです。
以下のケースだとAmbiguous set command "e=1": .になってしまい、
値が変更できないです。何が足りないのでしょうか?

(gdb) next
288 e=1;
(gdb) next
287 e=e+1;
(gdb) set e=1
Ambiguous set command "e=1": .

288行目 287行目参照

コード:

#include <iostream>

#include <curses.h>

#include <string.h>

#include <stdio.h>
#include <locale.h>
//#include <malloc.h>

const int CTRL_B = 0X02;
const int CTRL_D = 0X04;
const int CTRL_F = 0X06;
const int CTRL_H = 0X08;
const int CTRL_Q = 0X11;
const int CTRL_U = 0X15;

//エディットボックスクラス
//編集バッファ
//  先頭アドレス :buf
//  入力可能文字数:width
//  バッファのサイズ:width + 1 ('\0'が必要)
//  バッファ上の入力位置 :col
//  画面上の座標  :home_x + col

class EditBox {
public:	
    int home_x;             //ホーム座標
    //long home_x;
    int home_y;
    //long home_y;
    char label[20];         //編集領域の左に表示するラベル
    
    char *buf;              //編集バッファ
    int col;                //buf上の次の入力位置
    int label_x;            //ラベルの先頭
                            //編集領域の先頭はhome_x
    int width;              //最大入力可能文字数
    
    void cls();
    void empty();
    void inschar(int e);
    void bschar();
    void delchar();
    void moveleft();
    void moveright();
    
//public:
    EditBox(int x, int y, char *l, int w);
    ~EditBox();
    void show();
    void setfocus();
    char *get_text();
    void handle_event(int e);
};

//ラベルと編集領域の初期化
//  (x,y) :ラベルの位置
//  1     :ラベルに表示する文字列
//  w     :編集領域の文字数
EditBox::EditBox(int x, int y, char *l, int w)
{
    // ラベルの初期化
    label_x = x;
    
    strcpy(label, l);
    
    //編集領域の初期化
    home_x = x + (int)strlen(l) + 2;
    home_y = y;
    width = w;
    col = 0;
    
    buf = new char[width + 1];
    *buf = '\0';
    
}

EditBox::~EditBox()
{
    delete [] buf;
}

//編集領域をスペースでクリアする
//バッファには手をつけない
void EditBox::cls()
{
    attrset(WA_UNDERLINE);
    move(home_y,home_x);
    for(int i = 0; i < width; i++ )
        addch(' ');
    refresh();
}

//編集領域を表示領域、バッファともに空にする
void EditBox::empty()
{
    cls();
    *buf = '\0';
    col = 0;
    move(home_y,home_x);
}


//エディットボックスを表示する
void EditBox::show()
{
    attrset(WA_NORMAL);
    move(home_y, label_x);
    addstr(label);
    attrset(WA_UNDERLINE);
    cls();

}

//フォーカスを得たときの処理
void EditBox::setfocus()
{
    move(home_y, home_x);
    attrset(WA_UNDERLINE);
    refresh();
}

//現在のテキストを返す
char *EditBox::get_text()
{
    return buf;
}

//1文字挿入
void EditBox::inschar(int e)
{
    char *p;
    int e1, e2 ;
    
    if (e > 0x7f) {  //漢字の場合
        if (strlen(buf) >= width - 1) {
            beep();
            return;
        }
        else {
            //後ろからコピーして空き領域を作る
            p = buf + strlen(buf); // pは\0を指す
            while (p >= (buf + col)) {
                *(p + 2) = *p;
                p--;
                
            }
            e1 = (e >> 8);
            e2 = (e & 0xff);
            buf[col++] = e1;
            buf[col++] = e2;
        }
    }
    else {      //ASCIIの場合
        if (strlen(buf) >= width) {
            beep();
            return;
        }
        else {
            //後ろからコピーして空き領域を作る
            p = buf + strlen(buf); // pは\0を指す
            
            while (p >= (buf + col)) {
                *(p+1) = *p;
                p--;
            }
            buf[col++] = e;
        }
        move(home_y,home_x);
        addstr(buf);
        move(home_y,home_x + col);
        
    }
    
}
    //カーソル上の一文字を削除
    void EditBox::delchar()
    {
        char *p;
        
        if (col >= strlen(buf)){  //バッファの右端にいるとき削除できない
            beep();
            return;
        }
        if (buf[col] & 0x80) {  //漢字
            p = buf + col + 2;
            while (*p) {
                *(p - 2) = *p;
                p++;
            }
            *(p - 2) = '\0';
        }
        else {  //ASCII
            p = buf + col + 1;
            while (*p) {
                *(p - 1) = *p;
                p++;
            }
            *(p - 1) = '\0';
        }
        cls(); //ひらがなを正しく消すには一度refreshする
        move(home_y,home_x);
        addstr(buf);
        move(home_y,home_x + col);
    }
        
// 左の1文字を削除
    void EditBox::bschar()
    {
        if (col <= 0) //バッファの左端にいるときは移動できない
            beep();
        else{
                moveleft();
                delchar();
        }
    }
    
// 左に移動
    void EditBox::moveleft()
    {
        if (col <= 0 )  //バッファの左端にいるときは移動できない
            beep();
        else if (buf[--col] & 0x80) {  //漢字
            --col;
            move(home_y, home_x + col);
        }
        else  // ASCII
            move(home_y, home_x + col);
    }
    
    
    
// 右に移動
    void EditBox::moveright()
    {
        if (!buf[col] )       //最後の文字の右にいるときは移動できない
            beep();
        else if (buf[col++] & 0x80) {  //漢字
            col++;
            move(home_y, home_x + col);
        }
        else  // ASCII
            move(home_y, home_x + col);
    }

//エディットボックスのイベントハンドラ
    void EditBox::handle_event(int e)
    {
        if (e == CTRL_B)
            moveleft();
        else if (e == CTRL_F)
            moveright();
        else if (e == CTRL_H)  //左文字削除
            bschar();
        else if (e == CTRL_D)  //カーソル上の文字削除
            delchar();
        else if (e == CTRL_U)  //編集領域を空にする
            empty();
        else if (e < 0x20)   //その他のコントロール。。。
            beep();
        else                   //1文字挿入追加
            inschar(e);
        refresh();
    }

    //キー入力を行う
    //漢字の場合は2バイトにして返す
    //上位バイトが0ならASCIIコード
    //半角2バイト文字には非対応
    int getevent()
    {
        int c,c2;
        
        if ((c = getchar()) > 0x7f) {
            c2 = getchar();
            return (c << 8) | c2;
        }
        else
            return c;
        
    }


    int main()
    {
        int e,z ;
        e=1;
        e=e+1;
        setlocale(LC_ALL,"");
        initscr();      //cursesの使用開始
        noecho();       //キー入力時に表示しない
        raw();          //rawモードにする
        
        EditBox eb(10, 5, "文字列編集1" , 10);
        eb.show();
        eb.setfocus();
        
        e=z+1;
        //イベントの検出と配送
        while ((e = getevent()) != CTRL_Q)
            eb.handle_event(e);
        
        //入力結果の表示
        move(7, 10);
        attrset(WA_NORMAL);
        addstr("編集結果    :   ");
        attrset(WA_UNDERLINE);
        addstr(eb.get_text());
        move (11, 10);
        attrset(WA_REVERSE);
        addstr("何かキーを押すと終了");
        
        refresh();
        getchar();
        
        endwin();
        
        return 0 ;
    }

アバター
みけCAT
記事: 6734
登録日時: 14年前
住所: 千葉県
連絡を取る:

Re: なぜ Ambiguous set command がでてしまう?

#2

投稿記事 by みけCAT » 9年前

「gdb set」でググった結果、varが足りない気がしました。
Debugging with GDB - 実行処理の変更
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

えいえい
記事: 13
登録日時: 9年前

Re: なぜ Ambiguous set command がでてしまう?

#3

投稿記事 by えいえい » 9年前

できました、ありがとうございます。
結構なやみました。よかったです。

閉鎖

“C言語何でも質問掲示板” へ戻る