bool YumShell::install(void (*progress)(int)) { FILE *fp; char line[LINEMAX]; list<string>::const_iterator i; string install_command("yum"); string install_root(" --installroot="); install_root += _rootdir; install_command = install_command + install_root + " -c /etc/yum_livecd.conf -y install"; for(i=_pkgs.begin(); i!=_pkgs.end(); i++) { install_command += " \"" + *i +"\""; } /* int j; for (j=1, i=_pkgs.begin(); i!=_pkgs.end(); j++, i++) { progress(j); cout << *i << endl; } */ //cout << "install_command: " << install_command << endl; if (_pkgs.empty()) { _errstr = "no package to install"; return true; } if ((fp = popen(install_command.c_str(), "r")) == NULL) { _errstr = "install command failed"; return false; } while (fgets(line, LINEMAX, fp)) { if (strncmp(line, "Running Transaction\n", LINEMAX) == 0) { break; } } while (fgets(line, LINEMAX, fp)) { if (strncmp(line, "\n", LINEMAX) == 0) { break; } int index = 0; double num = 0; //XXX rewrite with atoi while (line[index]!='[' && line[index]!='\n') { index++; } if (line[index] != '[') { continue; } while ((line[index]<'0') || (line[index]>'9')) { index++; } /* while (line[index]!='/') { num = num * 10 + (line[index] - '0'); index++; } */ char tmp_num[LINEMAX]; int start = 0; while (line[index]!='/') { tmp_num[start++] = line[index++]; } tmp_num[start] = '\0'; num = atoi(tmp_num); num = _progmin + (_progmax - _progmin) * num / _pkgs.size(); if(progress) { progress(num); } // not need to call sleep, use I/O block for spinning, just like event triger :) //sleep(1); } pclose(fp); return true; }
init_system() { int strain (), ptrain (), tall (), test_pattern (), reset_weights(); int get_unames(), set_lgrain(), cycle(), newstart(); int change_lrate(), change_crate(), set_follow_mode(); epsilon_menu = SETCONFMENU; init_weights(); install_command("strain", strain, BASEMENU,(int *) NULL); install_command("ptrain", ptrain, BASEMENU,(int *) NULL); install_command("tall", tall, BASEMENU,(int *) NULL); install_command("test", test_pattern, BASEMENU,(int *) NULL); install_command("cycle", cycle, BASEMENU,(int *) NULL); install_command("reset",reset_weights,BASEMENU,(int *)NULL); install_command("newstart",newstart,BASEMENU,(int *)NULL); install_command("unames", get_unames, GETMENU,(int *) NULL); install_command("patterns", get_pattern_pairs, GETMENU,(int *) NULL); install_var("lflag", Int,(int *) & lflag, 0, 0, SETPCMENU); install_var("lgrain", String, (int *) grain_string,0, 0,NOMENU); install_command("lgrain",set_lgrain,SETMODEMENU,(int *) NULL); install_var("follow", Int, (int *) & follow,0, 0,NOMENU); install_command("follow",set_follow_mode,SETMODEMENU,(int *) NULL); install_var("cascade", Int,(int *) & cascade, 0, 0, SETMODEMENU); install_var("nepochs", Int,(int *) & nepochs, 0, 0, SETPCMENU); install_var("ncycles", Int,(int *) & ncycles, 0, 0, SETPCMENU); install_var("epochno", Int,(int *) & epochno, 0, 0, SETSVMENU); install_var("patno", Int,(int *) & patno, 0, 0, SETSVMENU); install_var("cycleno", Int,(int *) & cycleno, 0, 0, SETSVMENU); init_pattern_pairs(); install_var("tss", Float,(int *) & tss, 0, 0, SETSVMENU); install_var("pss", Float,(int *) & pss, 0, 0, SETSVMENU); install_var("gcor", Float,(int *) & gcor, 0, 0, SETSVMENU); install_var("momentum", Float,(int *) &momentum,0,0,SETPARAMMENU); install_var("mu", Float,(int *) &mu,0,0,SETPARAMMENU); install_command("lrate", change_lrate, SETPARAMMENU, (int *) NULL); install_command("crate", change_crate, SETPARAMMENU, (int *) NULL); install_var("lrate", Float,(int *) & lrate, 0, 0, NOMENU); install_var("crate", Float,(int *) & crate, 0, 0, NOMENU); install_var("ecrit", Float,(int *) & ecrit, 0, 0, SETPCMENU); install_var("tmax", Float,(int *) & tmax, 0, 0, SETPARAMMENU); }