~ubuntu-branches/ubuntu/oneiric/yacas/oneiric

« back to all changes in this revision

Viewing changes to proteus/browse.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gopal Narayanan
  • Date: 2002-04-23 13:50:51 UTC
  • Revision ID: james.westby@ubuntu.com-20020423135051-bbd6ov4orr8eufmw
Tags: upstream-1.0.51
ImportĀ upstreamĀ versionĀ 1.0.51

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 - Title with file currently loaded
 
4
 - status line
 
5
 - buttons for next/previous error.
 
6
 */
 
7
 
 
8
#include <FL/Fl.H>
 
9
#include <FL/Fl_Select_Browser.H>
 
10
#include <FL/Fl_Double_Window.H>
 
11
#include <FL/Fl_Button.H>
 
12
#include <FL/Fl_Input.H>
 
13
#include <stdio.h>
 
14
#include <string.h>
 
15
#include <errno.h>
 
16
#include <stdlib.h>
 
17
#include <FL/Fl_Box.H>
 
18
 
 
19
Fl_Window *w=NULL;
 
20
Fl_Select_Browser *showBrowser;
 
21
Fl_Select_Browser *selectBrowser;
 
22
Fl_Box *fileNameLabel;
 
23
Fl_Box *statusLabel;
 
24
char curfname[512];
 
25
char* theErrStr=NULL;
 
26
char* theFileName=NULL;
 
27
 
 
28
char* fullDir = NULL;
 
29
void select_cb(Fl_Widget* o, void*)
 
30
{
 
31
    /*
 
32
        printf("callback, selection = %d, event_clicks = %d\n",
 
33
           ((Fl_Browser*)o)->value(), Fl::event_clicks());
 
34
           printf("Text is: %s\n",selectBrowser->text(((Fl_Browser*)o)->value()));
 
35
           */
 
36
    int selectLine = ((Fl_Browser*)o)->value();
 
37
    const char* origTxt = selectBrowser->text(selectLine);
 
38
    const char* endStr = "(-1) : ";
 
39
    char* txt = (char*)malloc(strlen(origTxt)+1+strlen(endStr));
 
40
    strcpy(txt,origTxt);
 
41
    strcat(txt,endStr);
 
42
    char* ptr = txt;
 
43
    while (*ptr != '(')ptr++;
 
44
    *ptr = '\0';
 
45
    ptr++;
 
46
    char* num = ptr;
 
47
    while (*ptr != ')')ptr++;
 
48
    *ptr = '\0';
 
49
    ptr++;
 
50
    int errorLine = atoi(num);
 
51
 
 
52
    if (errorLine<0)
 
53
    {
 
54
//        printf("Not an error line\n");
 
55
        goto END;
 
56
    }
 
57
 
 
58
    curfname[0] = '\0';
 
59
    if (fullDir)
 
60
    {
 
61
        strcat(curfname,fullDir);
 
62
    }
 
63
    strcat(curfname,txt);
 
64
 
 
65
    
 
66
    if (!showBrowser->load(curfname))
 
67
    {
 
68
        printf("Can't load %s, %s\n", curfname, strerror(errno));
 
69
        goto END;
 
70
        return;
 
71
    }
 
72
 
 
73
    {
 
74
        while (*ptr != ':')ptr++;
 
75
        ptr++;
 
76
        char* erstr = ptr;
 
77
        txt[strlen(origTxt)] = '\0';
 
78
        if (theErrStr)
 
79
        {
 
80
            free(theErrStr);
 
81
        }
 
82
        theErrStr = strdup(erstr);
 
83
        statusLabel->label(theErrStr);
 
84
    }
 
85
    if (theFileName)
 
86
    {
 
87
        free(theFileName);
 
88
    }
 
89
    theFileName = strdup(txt);
 
90
    fileNameLabel->label(theFileName);
 
91
    w->redraw();
 
92
    showBrowser->position(errorLine);
 
93
    showBrowser->select(errorLine);
 
94
END:
 
95
    free(txt);
 
96
}
 
97
 
 
98
 
 
99
int main(int argc, char **argv)
 
100
{
 
101
    if (argc<2) return 0;
 
102
    const char* fname;
 
103
    fname = argv[1];
 
104
 
 
105
    if (argc>=2)
 
106
    {
 
107
        fullDir = argv[2];
 
108
    }
 
109
 
 
110
    Fl_Window window(400,400,"Error browser");
 
111
    w = &window;
 
112
    fileNameLabel = new Fl_Box(FL_NO_BOX,10,0,400,20,"");
 
113
    fileNameLabel->align(FL_ALIGN_CENTER);
 
114
    
 
115
    showBrowser = new Fl_Select_Browser(0,20,400,200-20,0);
 
116
    showBrowser->type(FL_HOLD_BROWSER);
 
117
    
 
118
    selectBrowser = new Fl_Select_Browser(0,200,400,200-20,0);
 
119
    //selectBrowser->type(FL_HOLD_BROWSER);
 
120
    selectBrowser->callback(select_cb);
 
121
    if (!selectBrowser->load(fname))
 
122
    {
 
123
        printf("Can't load %s, %s\n", fname, strerror(errno));
 
124
        exit(1);
 
125
    }
 
126
 
 
127
    statusLabel = new Fl_Box(FL_NO_BOX,10,400-20,400,20,"Status line");
 
128
//    statusLabel->align(FL_ALIGN_LEFT);
 
129
 
 
130
    selectBrowser->position(0);
 
131
    window.resizable(showBrowser);
 
132
    window.resizable(selectBrowser);
 
133
 
 
134
    window.show(1,argv);
 
135
    return Fl::run();
 
136
}
 
137