#include #include #include #include #include #include #include #include "xterminals.m" int main (int argc, char *argv[]) { int nbfile; bool gzipped; SSTRING intro; bool sync; glocal.gzipped = false; glocal.nbfile = 100; glocal.sync = false; int ret = (argc, argv, "xterminals"); fprintf (stderr ,"visualuntar [ options ] tar-file\n" " Untar a file with a progress bar\n" "\n" " --gzipped\n" " The file is a gzipped tar file\n" " --intro text\n" " Some introduction text to present in the dialog\n" " --nbfile N\n" " Number of file in the tar file, if known\n" " Used to scale the progress bar\n"); int ret = -1; if (strcmp(opt,"--gzipped")==0){ glocal.gzipped = true; ret = 0; }else if (strcmp(opt,"--sync")==0){ glocal.sync = true; ret = 0; }else if (strcmp(opt,"--intro")==0){ glocal.intro.setfrom (val); ret = 1; }else if (strcmp(opt,"--nbfile")==0){ glocal.nbfile = atoi(val); ret = 1; } return ret; int ret = -1; if (argc != 1){ usage(); }else{ const char *file = argv[0]; dialog_clear(); DIALOG dia; int nofile = 0; dia.newf_gauge ("",nofile,glocal.nbfile); char cwd[PATH_MAX]; if (getcwd(cwd,sizeof(cwd))!=NULL){ SSTRING tmp; tmp.setfromf ("tar %cxvf %s" ,glocal.gzipped ? 'z' : ' ',file); POPENUSER pop (tmp.get()); if (pop.isok()){ int nof = 0; SSTRINGS errs; while (1){ dia.show (file,glocal.intro.get(),help_nil,nof,0); diagui_flush(); if (pop.wait(100)< 0) break; char line[PATH_MAX]; while (pop.readout (line,sizeof(line)-1)!=-1){ nofile++; if (glocal.sync){ dia.reload(); dia.show (file,glocal.intro.get(),help_nil,nof,0); diagui_flush(); } } while (pop.readerr (line,sizeof(line)-1)!=-1){ fprintf (stderr,"%s\n",line); errs.add (new SSTRING (line)); } while (nofile > glocal.nbfile) nofile -= glocal.nbfile; dia.reload(); } ret = pop.getstatus(); if (errs.getnb()!=0){ dialog_textbox (MSG_U(E_SOMEERRORS,"Some errors"),errs); } }else{ fprintf (stderr,"Can't exec command %s\n",tmp.get()); } } } return ret; return ret; }