~pac72/ubuntu/lucid/ddd/devel

« back to all changes in this revision

Viewing changes to ddd/session.C

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Schepler
  • Date: 2004-07-22 03:49:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040722034937-cysl08t1jvba4jrx
Tags: 1:3.3.9-3
USERINFO has been renamed to USERINFO.txt; adjust debian/rules code
to match, to get correct information on the About DDD dialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: session.C,v 1.59 2001/04/26 11:08:07 zeller Exp $ -*- C++ -*-
 
1
// $Id$ -*- C++ -*-
2
2
// DDD session management
3
3
 
4
4
// Copyright (C) 1997 Technische Universitaet Braunschweig, Germany.
28
28
// or send a mail to the DDD developers <ddd@gnu.org>.
29
29
 
30
30
char session_rcsid[] = 
31
 
    "$Id: session.C,v 1.59 2001/04/26 11:08:07 zeller Exp $";
32
 
 
33
 
#ifdef __GNUG__
34
 
#pragma implementation
35
 
#endif
 
31
    "$Id$";
36
32
 
37
33
#include "session.h"
38
34
 
48
44
#include <signal.h>             // kill()
49
45
#include <string.h>             // strerror()
50
46
#include <errno.h>
51
 
#include <fstream.h>
 
47
#include <fstream>
52
48
#include <pwd.h>
53
49
 
54
50
#include "AppData.h"
158
154
        return session_base_dir() + "/" + session;
159
155
}
160
156
 
161
 
string session_file(const string& session, const string& base)
 
157
string session_file(const string& session, const char *base)
162
158
{
163
159
    return session_dir(session) + "/" + base;
164
160
}
170
166
 
171
167
class StreamAction {
172
168
private:
173
 
    ostream& stream;
 
169
    std::ostream& stream;
174
170
    string action;
175
171
    bool ok;
176
172
 
177
173
public:
178
 
    StreamAction(ostream& os, const string& c)
 
174
    StreamAction(std::ostream& os, const string& c)
179
175
        : stream(os), action(c), ok(true)
180
176
    {
181
177
        stream << action << "...\n";
192
188
    }
193
189
};
194
190
 
195
 
static int makedir(const string& name, ostream& msg, bool user_only = false)
 
191
static int makedir(const string& name, std::ostream& msg, bool user_only = false)
196
192
{
197
193
    StreamAction action(msg, "Creating " + quote(name + "/"));
198
194
 
211
207
    return ret;
212
208
}
213
209
 
214
 
static void copy(const string& from_name, const string& to_name, ostream& msg)
 
210
static void copy(const string& from_name, const string& to_name, std::ostream& msg)
215
211
{
216
212
    FILE *from = fopen(from_name.chars(), "r");
217
213
    if (from == 0)
258
254
    if (temporary)
259
255
    {
260
256
        const string s1 = session_tmp_flag(session); 
261
 
        ofstream os(s1.chars());
 
257
        std::ofstream os(s1.chars());
262
258
        os << "This session will be deleted unless saved explicitly.\n";
263
259
    }
264
260
    else
269
265
}
270
266
 
271
267
// Create DDD state directory
272
 
static void create_session_state_dir(ostream& msg)
 
268
static void create_session_state_dir(std::ostream& msg)
273
269
{
274
270
    // Create or find state directory
275
271
    if (!is_directory(session_state_dir()) && 
293
289
}
294
290
 
295
291
// Create session directory
296
 
void create_session_dir(const string& session, ostream& msg)
 
292
void create_session_dir(const string& session, std::ostream& msg)
297
293
{
298
294
    // Create state directory
299
295
    create_session_state_dir(msg);
316
312
// Same, but issue messages in status line
317
313
void create_session_dir(const string& session)
318
314
{
319
 
    ostrstream messages;
 
315
    std::ostringstream messages;
320
316
    create_session_dir(session, messages);
321
317
    string msg(messages);
322
 
    while (msg != "")
 
318
    while (!msg.empty())
323
319
    {
324
320
        string line = msg.before('\n');
325
321
        set_status(line);
340
336
    string lock_file = session_lock_file(session);
341
337
 
342
338
    {
343
 
        ifstream is(lock_file.chars());
 
339
        std::ifstream is(lock_file.chars());
344
340
        if (!is.bad())
345
341
        {
346
342
            string version;
355
351
                   >> info.uid
356
352
                   >> info.username;
357
353
 
358
 
                if (info.username == "")
 
354
                if (info.username.empty())
359
355
                {
360
356
                    // DDD 3.0.90 and earlier do not save the user name
361
357
                    info.username = itostring(info.uid);
379
375
        else
380
376
            username = itostring(getuid());
381
377
 
382
 
        ofstream os(lock_file.chars());
 
378
        std::ofstream os(lock_file.chars());
383
379
        os << DDD_NAME "-" DDD_VERSION
384
380
           << " " << fullhostname()
385
381
           << " " << getpid()
396
392
{
397
393
    string lock_file = session_lock_file(session);
398
394
 
399
 
    ifstream is(lock_file.chars());
 
395
    std::ifstream is(lock_file.chars());
400
396
    if (!is.bad())
401
397
    {
402
398
        // There is a lock -- check whether it's ours
433
429
    char **files = glob_filename(mask.chars());
434
430
    if (files == (char **)0)
435
431
    {
436
 
        cerr << mask << ": glob failed\n";
 
432
        std::cerr << mask << ": glob failed\n";
437
433
    }
438
434
    else if (files == (char **)-1)
439
435
    {
548
544
            value = DEFAULT_SESSION;
549
545
 
550
546
        Widget text_w = XmSelectionBoxGetChild(dialog, XmDIALOG_TEXT);
551
 
        XmTextSetString(text_w, CONST_CAST(char *,value.chars()));
 
547
        XmTextSetString(text_w, XMST(value.chars()));
552
548
    }
553
549
 
554
550
    // Update delete button
565
561
 
566
562
    XtSetArg(args[arg], XmNautoUnmanage, False); arg++;
567
563
    Widget dialog = 
568
 
        verify(XmCreateSelectionDialog(find_shell(parent), CONST_CAST(char *,name), args, arg));
 
564
        verify(XmCreateSelectionDialog(find_shell(parent), XMST(name), args, arg));
569
565
 
570
566
    Delay::register_shell(dialog);
571
567
 
748
744
 
749
745
    set_sensitive(may_kill_w, set);
750
746
    set_sensitive(may_gcore_w, set && gdb->type() == GDB &&
751
 
                   string(app_data.get_core_command) != "");
 
747
                   !string(app_data.get_core_command).empty());
752
748
#if HAVE_PTRACE_DUMPCORE
753
749
    set_sensitive(may_ptrace_w, set && gdb->type() == GDB);
754
750
#else
755
 
    set_sensitive(may_ptrace_w, False);
 
751
    set_sensitive(may_ptrace_w, false);
756
752
#endif
757
753
}
758
754
 
832
828
 
833
829
    ProgramInfo info;
834
830
    bool have_data = 
835
 
        info.running || (info.core != NO_GDB_ANSWER && info.core != "");
 
831
        info.running || (info.core != NO_GDB_ANSWER && !info.core.empty());
836
832
    XmToggleButtonSetState(dump_core_w, have_data, True);
837
833
    set_sensitive(dump_core_w, info.running);
838
834
    SetGCoreSensitivityCB();
979
975
    const _XtString shortcuts = 0;
980
976
    switch (gdb->type())
981
977
    {
 
978
    case BASH: shortcuts = XtNbashDisplayShortcuts; break;
 
979
    case DBG:  shortcuts = XtNdbgDisplayShortcuts;  break;
 
980
    case DBX:  shortcuts = XtNdbxDisplayShortcuts;  break;
982
981
    case GDB:  shortcuts = XtNgdbDisplayShortcuts;  break;
983
 
    case DBX:  shortcuts = XtNdbxDisplayShortcuts;  break;
984
 
    case XDB:  shortcuts = XtNxdbDisplayShortcuts;  break;
985
982
    case JDB:  shortcuts = XtNjdbDisplayShortcuts;  break;
 
983
    case PERL: shortcuts = XtNperlDisplayShortcuts; break;
986
984
    case PYDB: shortcuts = XtNpydbDisplayShortcuts; break;
987
 
    case PERL: shortcuts = XtNperlDisplayShortcuts; break;
 
985
    case XDB:  shortcuts = XtNxdbDisplayShortcuts;  break;
988
986
    }
989
987
 
990
988
    display_shortcuts = get_resource(db, shortcuts, XtCDisplayShortcuts);
991
989
 
992
990
    switch (gdb->type())
993
991
    {
 
992
    case BASH:
 
993
        app_data.bash_display_shortcuts = display_shortcuts.chars();
 
994
        break;
 
995
    case DBG:  
 
996
         app_data.dbg_display_shortcuts  = display_shortcuts.chars(); 
 
997
        break;
 
998
    case DBX:
 
999
        app_data.dbx_display_shortcuts  = display_shortcuts.chars();
 
1000
        break;
994
1001
    case GDB:
995
1002
        app_data.gdb_display_shortcuts  = display_shortcuts.chars();
996
1003
        break;
997
 
    case DBX:
998
 
        app_data.dbx_display_shortcuts  = display_shortcuts.chars();
999
 
        break;
1000
 
    case XDB:
1001
 
        app_data.xdb_display_shortcuts  = display_shortcuts.chars();
1002
 
        break;
1003
1004
    case JDB:
1004
1005
        app_data.jdb_display_shortcuts  = display_shortcuts.chars();
1005
1006
        break;
1009
1010
    case PERL:
1010
1011
        app_data.perl_display_shortcuts = display_shortcuts.chars();
1011
1012
        break;
 
1013
    case XDB:
 
1014
        app_data.xdb_display_shortcuts  = display_shortcuts.chars();
 
1015
        break;
1012
1016
    }
1013
1017
    update_user_buttons();
1014
1018
 
1025
1029
    string settings;
1026
1030
    switch (gdb->type())
1027
1031
    {
 
1032
    case BASH:
 
1033
        settings = get_resource(db, XtNbashSettings, XtCSettings);
 
1034
        break;
 
1035
 
 
1036
    case DBG:
 
1037
        settings = get_resource(db, XtNdbgSettings, XtCSettings);
 
1038
        break;
 
1039
 
 
1040
    case DBX:
 
1041
        settings = get_resource(db, XtNdbxSettings, XtCSettings);
 
1042
        break;
 
1043
 
1028
1044
    case GDB:
1029
1045
        settings = get_resource(db, XtNgdbSettings, XtCSettings);
1030
1046
        break;
1031
1047
 
1032
 
    case DBX:
1033
 
        settings = get_resource(db, XtNdbxSettings, XtCSettings);
1034
 
        break;
1035
 
 
1036
1048
    case XDB:
1037
1049
        settings = get_resource(db, XtNxdbSettings, XtCSettings);
1038
1050
        break;
1048
1060
    case PERL:
1049
1061
        settings = get_resource(db, XtNperlSettings, XtCSettings);
1050
1062
        break;
 
1063
 
1051
1064
    }
1052
1065
    init_session(restart, settings, app_data.source_init_commands);
1053
1066
 
1078
1091
    settings = get_settings(gdb->type());
1079
1092
    switch (gdb->type())
1080
1093
    {
 
1094
    case BASH:
 
1095
        app_data.perl_settings = settings.chars();
 
1096
        break;
 
1097
 
 
1098
    case DBG:
 
1099
        app_data.dbg_settings = settings.chars();
 
1100
        break;
 
1101
 
 
1102
    case DBX:
 
1103
        app_data.dbx_settings = settings.chars();
 
1104
        break;
 
1105
 
1081
1106
    case GDB:
1082
1107
        app_data.gdb_settings = settings.chars();
1083
1108
        break;
1084
1109
 
1085
 
    case DBX:
1086
 
        app_data.dbx_settings = settings.chars();
1087
 
        break;
1088
 
 
1089
 
    case XDB:
1090
 
        app_data.xdb_settings = settings.chars();
1091
 
        break;
1092
 
 
1093
1110
    case JDB:
1094
1111
        app_data.jdb_settings = settings.chars();
1095
1112
        break;
1096
1113
 
 
1114
    case PERL:
 
1115
        app_data.perl_settings = settings.chars();
 
1116
        break;
 
1117
 
1097
1118
    case PYDB:
1098
1119
        app_data.pydb_settings = settings.chars();
1099
1120
        break;
1100
1121
 
1101
 
    case PERL:
1102
 
        app_data.perl_settings = settings.chars();
 
1122
    case XDB:
 
1123
        app_data.xdb_settings = settings.chars();
1103
1124
        break;
1104
1125
    }
1105
1126
 
1372
1393
 
1373
1394
    arg = 0;
1374
1395
    MString msg = rm(text);
1375
 
    if (text != "")
 
1396
    if (!text.empty())
1376
1397
    {
1377
1398
        XtSetArg(args[arg], XmNmessageString, msg.xmstring()); arg++;
1378
1399
    }
1379
 
    dialog = verify(XmCreateQuestionDialog(find_shell(w), CONST_CAST(char *,name),
 
1400
    dialog = verify(XmCreateQuestionDialog(find_shell(w), XMST(name),
1380
1401
                                           args, arg));
1381
1402
    Delay::register_shell(dialog);
1382
1403
    XtAddCallback(dialog, XmNokCallback,     yes, XtPointer(token));