It compiles, but when pressing "Захаваць(Ctrl-S)" i got a segfault. The 
save_cb function don't even start. Segfault is before it. I modified it a 
little so in "pwd_cb" function there was a save->y(...) call and I also got a 
segfault.
I reposted it to "fltk.bugs" because there a few people answered me.

"#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/Button.h>
#include <fltk/Input.h>
#include <fltk/SecretInput.h>

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>

using namespace fltk;
using namespace std;

Window * win;
Button * quit;
Button * save;
SecretInput * pwd;
Input * a[20];
Input * b[20];
Input * c[20];


string * pwd_right;
char * n_of_3s;

void save_cb(Widget *  , void *  ){
        ofstream pwd_file("passs.flpm");
        string c_a, c_b, c_c;

        if(pwd_file.is_open()){
                for(char i = 0; i <= *n_of_3s; i++){
                        c_a = a[i]->value();
                        if(c_a == ""){
                                c_a = "\\";
                        }else{
                                for(int i = 0; i <= c_a.length(); i++){
                                        if (c_a[i] == *" "){
                                                for(int i2 = (c_a.length() + 
2); i2 >= (i + 2); i2--){
                                                        c_a[i] = c_a[i2-2];
                                                }
                                        }
                                        c_a[i] = *"/";
                                        c_a[i+1] = *"/";
                                        c_a[i+2] = *"/";
                                }
                        }
                        c_b = b[i]->value();
                        if(c_b == ""){
                                c_b = "\\";
                        }else{
                                for(int i = 0; i <= c_b.length(); i++){
                                        if (c_b[i] == *" "){
                                                for(int i2 = (c_b.length() + 
2); i2 >= (i + 2); i2--){
                                                        c_b[i] = c_b[i2-2];
                                                }
                                        }
                                        c_b[i] = *"/";
                                        c_b[i+1] = *"/";
                                        c_b[i+2] = *"/";
                                }
                        }
                        c_c = c[i]->value();
                        if(c_c == ""){
                                c_c = "\\";
                        }else{
                                for(int i = 0; i <= c_c.length(); i++){
                                        if (c_c[i] == *" "){
                                                for(int i2 = (c_c.length() + 
2); i2 >= (i + 2); i2--){
                                                        c_c[i] = c_c[i2-2];
                                                }
                                        }
                                        c_c[i] = *"/";
                                        c_c[i+1] = *"/";
                                        c_c[i+2] = *"/";
                                }
                        }
                        pwd_file << *pwd_right << '\n';

                        pwd_file << c_a << ' ' << c_b << ' ' << c_c << '\n';
                }
                pwd_file.close();
        }
        exit(0);
}

void pwd_cb(Widget *  , void *  ){
        ifstream pwd_file("passs.flpm");
        string c_a, c_b, c_c;

        pwd_right = new string;
        n_of_3s = new char;
        pwd_file >> *pwd_right;
        if ((*pwd_right == pwd->value())&&(pwd_file.is_open())){
                delete pwd;
                win->resize(win->w(), win->h() - 24);
                win->redraw();
                quit->y(quit->y() - 24);
                quit->redraw();
                for(short i = 1; i<=20, !(pwd_file.eof()); i++){
                        c_a="";
                        pwd_file >> c_a;
                        c_b="";
                        pwd_file >> c_b;
                        c_c="";
                        pwd_file >> c_c;
                        if((c_a == "")&&(c_b == "")&&(c_c == "")){
                                break;
                        }
                        win->resize(win->w(), win->h() + 24);
                        //win->redraw();
                        quit->y(quit->y() + 24);
                        quit->redraw();
                        win->begin();
                                a[i] = new Input(0, i*24-24, 266, 24);
                                b[i] = new Input(266, i*24-24, 266, 24);
                                c[i] = new Input(532, i*24-24, 268, 24);
                        win->end();
                        if(c_a == "\\"){
                                a[i]->value("");
                        }else{
                                for(int i = 0; i <= c_a.length(); i++){
                                        if((c_a[i] == *"/")&&(c_a[i+1] == 
*"/")&&(c_a[i+2] == *"/")){
                                                c_a[i] = *" ";
                                                for(int i2 = (i + 1); i2 <= 
(c_a.length() - 2); i2++){
                                                        c_a[i2] = c_a[i2+2];
                                                }
                                        }
                                }
                                a[i]->value(c_a.c_str());
                        }
                        if(c_b == "\\"){
                                b[i]->value("");
                        }else{
                                for(int i = 0; i <= c_b.length(); i++){
                                        if((c_b[i] == *"/")&&(c_b[i+1] == 
*"/")&&(c_b[i+2] == *"/")){
                                                c_b[i] = *" ";
                                                for(int i2 = (i + 1); i2 <= 
(c_b.length() - 2); i2++){
                                                        c_b[i2] = c_b[i2+2];
                                                }
                                        }
                                }
                                b[i]->value(c_b.c_str());
                        }
                        if(c_c == "\\"){
                                c[i]->value("");
                        }else{
                                for(int i = 0; i <= c_c.length(); i++){
                                        if((c_c[i] == *"/")&&(c_c[i+1] == 
*"/")&&(c_c[i+2] == *"/")){
                                                c_c[i] = *" ";
                                                for(int i2 = (i + 1); i2 <= 
(c_c.length() - 2); i2++){
                                                        c_c[i2] = c_c[i2+2];
                                                }
                                        }
                                }
                                c[i]->value(c_c.c_str());
                        }
                        *n_of_3s++;
                }
        pwd_file.close();
        *n_of_3s /= 2;
        quit->w(400);
        quit->x(400);
        //cout << *n_of_3s;
        win->begin();
                save = new Button(0, (*n_of_3s) * 24, 400, 24, 
"Захаваць(Alt-&S)");
        win->end();
        save->callback(save_cb);
        }
}

void quit_cb(Widget *  , void *  ){
        exit(0);
}

int main(){
win = new Window(800, 48, "fl_pm v. 0.31");
win->begin();
        quit = new Button(0, 24, 800, 24, "Выйсьці");
        pwd = new SecretInput(100, 0, 700, 24, "Галоўны пароль:");
win->end();
pwd->callback(pwd_cb);
pwd->when(WHEN_ENTER_KEY);
quit->callback(quit_cb);
quit->when(WHEN_RELEASE);

win->show();
return run();
}"

Sorry for long code and my English.
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to