Component index
Section index

Component copyfile


Search

	/*
	    copyfile is used to copy file with some interactivity.
	*/
	<mod>
	static void sample_copyfile()
	{
	    // We create a test file /tmp/toto.old
	    <call savefile>("/tmp/toto.old",false);
	    <f dowrite>
	        for (int i=0; i<100000; i++){
	            fputs ("hello alalallllllllllllllllllllllllaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",fout);
	        }
	        return 0;
	    </f>
	    <f end>
	        // All functags do have defaults
	        <call copyfile>("/tmp/toto.old","/tmp/toto.new");
	        </call>
	
	        // We produce a progress bar in ascii
	        <glocal>
	            int pound_shown;
	        </glocal>
	        glocal.pound_shown = 0;
	        <call copyfile>("/tmp/toto.old","/tmp/toto.new");
	        <f fail>
	            fprintf (stderr,"Some error: %s\n",details);
	        </f>
	        <f progress>
	            // We put a pound for every 100 kbytes copied
	            int nbpound = sofar/(100*1024);
	            for (; glocal.pound_shown < nbpound; glocal.pound_shown++){
	                fputc ('#',stdout);
	            }
	        </f>
	        </call>
	        fputc ('\n',stdout);
	
	        // A progress bar in gui mode. We quit if more than 1meg is copied
	        <glocal>
	            DIALOG dia;
	            int gauge;
	        </glocal>
	        glocal.gauge = 0;
	        glocal.dia.newf_gauge ("Copying",glocal.gauge,100);
	        int nof = 0;
	        glocal.dia.show ("Copy files","",help_nil,nof,0);
	        <call copyfile>("/tmp/toto.old","/tmp/toto.new");
	        <f progress>
	            glocal.gauge = sofar*100/size;
	            glocal.dia.reload();
	            diagui_flush();
	            end = sofar > 1024*1024;
	        </f>
	        </call>
	        xconf_notice ("Done");
	    </f>
	    </call>
	}
	</mod>