Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: C (gcc) code for copying with progress bar (cp clone)

  1. #1
    Join Date
    Feb 2007
    Beans
    863

    C (gcc) code for copying with progress bar (cp clone)

    Hello,

    I would like to know whether it has been released a C (gcc) code for copying with progress bar (cp clone). In the book of Dennis, there is one example that does CP. A progress might be not so complicated to be made.

    Would you eventually know a code?

    Kind regards

  2. #2
    Join Date
    May 2008
    Location
    UK
    Beans
    1,447
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: C (gcc) code for copying with progress bar (cp clone)

    Quote Originally Posted by honeybear View Post
    Hello,

    I would like to know whether it has been released a C (gcc) code for copying with progress bar (cp clone). In the book of Dennis, there is one example that does CP. A progress might be not so complicated to be made.

    Would you eventually know a code?

    Kind regards
    This raises all sorts of questions :

    1) Which graphical framework (GTK, TK, KBE etc etc).
    2) You do know that gcc is just a compiler, which is very different from C which is a language.
    3) Is this home work ?
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

  3. #3
    Join Date
    Sep 2012
    Location
    UK
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: C (gcc) code for copying with progress bar (cp clone)

    Quote Originally Posted by Tony Flury View Post
    This raises all sorts of questions :

    1) Which graphical framework (GTK, TK, KBE etc etc).
    2) You do know that gcc is just a compiler, which is very different from C which is a language.
    3) Is this home work ?
    If its a simple Command line app then you could calculate what percentage of the file you have downloaded in a loop and print something, '*' example, for every 5% of the download.

    Simple enough?

    I won't give the code but it should give you enough of clue to work it out.

    If its not home work then we need to know which graphical framework.

  4. #4
    Join Date
    Feb 2009
    Beans
    504
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: C (gcc) code for copying with progress bar (cp clone)

    It's not an exact cp clone, but there is a program called pv in the repositories that can be inserted into a pipeline to display a progress bar on the terminal.

  5. #5
    Join Date
    Jun 2011
    Location
    United Kingdom
    Beans
    Hidden!
    Distro
    Lubuntu Development Release

    Re: C (gcc) code for copying with progress bar (cp clone)

    So...if there's an example in the "book of Dennis", then why not learn from /rip off that one?

  6. #6
    Join Date
    Feb 2007
    Beans
    863

    Re: C (gcc) code for copying with progress bar (cp clone)

    Ah guys, so much replies, and so much no content for some.

    Surely a console based cp way, since cp is nothing else than cp:

    whereis cp


    A simple possible starting point is here. So there are many ways to make cool cp looking with a great progress bar.

    Simply that's probably not the right place, forum, public,... about C coding maybe...

    I wanted to exchange about some possible codes. well

    Code:
    #include <stdio.h>
    #include <assert.h>
    #include <stdlib.h>
    
    #define MAXLINE 10 // in the book this is 1000
    
    void copy(char to[], char from[])
    {
        int i;
    
        i = 0;
        while((to[i] = from[i]) != '\0')
            ++i;
    }
    
    int main(int argc, char *argv[])
    {
        int i;
    
        // use heap memory as many modern systems do
        char *line = malloc(MAXLINE);
        char *longest = malloc(MAXLINE);
    
        assert(line != NULL && longest != NULL && "memory error");
    
        // initialize it but make a classic "off by one" error
        for(i = 0; i < MAXLINE; i++) {
            line[i] = 'a';
        }
    
        // cause the defect
        copy(longest, line);
    
        free(line);
        free(longest);
    
        return 0;
    }

    with another layer with sthg similar to such as this:

    Code:
    #include <stdio.h>
    
    int  main(void)
    {
    
    char *tu="*";
    int i;
    
    for(i=0;i<=100;i++) {
    
            printf("[%s %d", tu,i); printf("\r");
    
            fflush(stdout);
    
            usleep(1000);
            }
    }
    Last edited by honeybear; January 24th, 2013 at 09:01 PM.

  7. #7
    Join Date
    Feb 2007
    Beans
    863

    Re: C (gcc) code for copying with progress bar (cp clone)

    A C code with a progress bar is a thing which is very easy to make. Since 80s it must exsits, but google does not pop it up. In 50 lines, one can make a void. I will do one in few weeks for you guys.

  8. #8
    Join Date
    Nov 2008
    Location
    Maine
    Beans
    1,125
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: C (gcc) code for copying with progress bar (cp clone)

    The cp command had a progress bar. I used to see it on some fedora 3 computers I had ages ago.
    it was a little animation formatted with == signs and pipes and slashes.

    it would kinda look like this, and the number of = sings would progress over time / copy percentage.
    I haven't seen it in modern versions but i assumed its just an option that I had set up in older linux versions.

    my understanding of scripting is that things like animations detract from my computer doing what I asked it to do.
    Code:
    #!/bin/bash
    for i in `seq 0 10`
    do 
    	clear
    	echo "=--"
    	sleep 0.3
    	clear
    	echo "=/"
    	sleep 0.3
    	clear
    	echo "=|"
    	sleep 0.3
    	clear
    	echo "=\""
    
    done
    ~Conradin~

  9. #9
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    6,055

    Re: C (gcc) code for copying with progress bar (cp clone)

    Quote Originally Posted by jwbrase View Post
    It's not an exact cp clone, but there is a program called pv in the repositories that can be inserted into a pipeline to display a progress bar on the terminal.
    +1

    pv is doing this

    copy
    Code:
    pv < bigfile.orig > bigfile.copy
    compress
    Code:
    pv < bigfile.orig | gzip > bigfile.copy.gz
    But this is simpler than cp (not managing wild cards or preserving permissions like cp -p etc)
    Last edited by sudodus; March 5th, 2013 at 05:59 PM. Reason: 1. code-boxes; 2. added gz extension after compression

  10. #10
    Join Date
    Feb 2007
    Beans
    863

    Re: C (gcc) code for copying with progress bar (cp clone)

    Quote Originally Posted by sudodus View Post
    +1

    pv is doing this

    copy
    Code:
    pv < bigfile.orig > bigfile.copy
    compress
    Code:
    pv < bigfile.orig | gzip > bigfile.copy.gz
    But this is simpler than cp (not managing wild cards or preserving permissions like cp -p etc)
    I dont like pv that much. It is kinda hacky and not so much reliable.

    I have no time to make it, but soon or later, I will release a new CP with this progress bar. I need only 3-4 hours, but I cannot find it.

    (oh, I forgot, I code under C mostly. So it will be in C)

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •