Re: I'm a C++ programmer, and Relf's X.CPP is good.

From: Stefaan A Eeckels (tengo_at_DELETEMEecc.lu)
Date: 09/25/04

  • Next message: Mike: "not really lisp, but is there a lispish way?"
    Date: Sat, 25 Sep 2004 03:14:08 +0200
    
    

    On Fri, 24 Sep 2004 17:06:53 -0700
    Mike Cox <mikecoxlinux@yahoo.com> wrote:

    > Stefaan A Eeckels wrote:
    >
    > > On Fri, 24 Sep 2004 13:46:37 -0700
    > > Mike Cox <mikecoxlinux@yahoo.com> wrote:
    > >
    > >> I've developed my hm command (pronounced "home")*, I've modified a
    > >> Linux kernel mouse driver* to support Microsoft Wireless Optical mice
    > >>with tilt wheel technology. I use emacs and extend it with LISP. I
    > >>know my stuff. And with this authority, I have to say that I see
    > >>nothing wrong with Jeff Relf's X.CPP.
    > >
    > > <snip drivel>
    > >
    > >> 1. Do a groups.google search for the code to both my mouse driver
    > >> modification and my "hm" command.
    > >
    > > I don't know why you wrote 'hm', as the 'cd' command without
    > > parameters will take you back to your home dir :-).
    > >
    > > But as you insist in positioning yourself as an expert, I had a
    > > look at your so-called C++ code, and, to be quite candid, it stinks,
    > > and it doesn't compile either.
    > >
    > > This is the thing I located:
    > >
    > > | /*
    > > | (c) 2004 Mike Cox. Released under the GNU GPL License.
    > > | email: mikecoxlinux@yahoo.com
    > > | web: www.geocities.com/mikecoxlinux/
    > > |
    > > | ****** Home Version 2 ******
    > > | The "hm" (shortened from home) command takes you to
    > > | your home directory if you've been wandering far and
    > > | don't want to type so much.
    > > |
    > > | Just type "hm" at the shell, and you're immediatly
    > > | transported to /home/yourusername/
    > >
    > >
    > >

    > The version I was at was version 3.0.

    If you don't want old versions to be found, then post accurate
    references. This was the first result that came up, your home
    page is empty, and I cannot be expected to know what version
    your program is at.

    > The thread title is
    > called""hm" command posted without formattin errors." Type that in
    > google groups. But you don't have too since I'm going to post the code
    > here. Here is the full version:

    It still doesn't compile:

    blinky~/Stuff[180] g++ -o hm home.cpp
    home.cpp: In function `void recall_path(int, char **)':
    home.cpp:90: implicit declaration of function `int fopen(...)'
    home.cpp:90: assignment to `FILE *' from `int' lacks a cast
    home.cpp:93: implicit declaration of function `int fclose(...)'

    That's normal seeing you forgot to include stdio.h

    home.cpp: In function `void set_path(int, char **)':
    home.cpp:108: implicit declaration of function `int islower(...)'

    That's normal because you forgot to include ctype.h

    home.cpp:110: implicit declaration of function `int
    get_current_dir_name(...)'

    That's normal because get_current_dir_name is not prototyped unless
    you define __GNU_SOURCE (portable code, this).

    home.cpp:110: passing `int' to argument 1 of `write_path(char *, char)'
    lacks a cast home.cpp: In function `void write_path(char *, char)':
    home.cpp:146: assignment to `FILE *' from `int' lacks a cast
    home.cpp:155: implicit declaration of function `int fputs(...)'

    Let's have a look if you've managed to come up with something
    else than forks and pipes...

    > void go_home()
    > {
    >
    > uid_t hm_usr;
    > struct passwd* hm_ps;
    >
    > hm_usr = getuid();
    > hm_ps = getpwuid(hm_usr);
    >
    > if(!hm_ps){
    > std::cout<<"Error: Go Home Failed. \n ";
    > exit(1);
    > }
    > chdir(hm_ps->pw_dir);
    > execl(hm_ps->pw_shell,hm_ps->pw_shell,(const char*) NULL);
    >
    > }

    And what do you think this does? Hint - it executes a new
    copy of the shell, it does not change the current directory
    in the user's login shell.

    > if(islower(argv[2][0])){
    > if(argc == 3){
    > write_path(get_current_dir_name(),argv[2][0]);
    > }else if(argv[3][0] == '/'){ write_path(argv[3], argv[2][0]);
    > }else{ std::cout<<"Error: Not a valid directory name.\n";
    > }
    > ...
    > void write_path(char* hm_path, char hm_buf )
    > {
    > ....
    > /* Turn hm_buf into a string */
    > char b[2];
    > b[0] = hm_buf;
    > b[1] = '\0';

    How stupid can one be? Why do you take a character from a
    string only to turn into a string again? Just pass the original
    string.

    > FILE* o;
    > o =fopen(hm_name, "a");
    > /* Turn hm_buf into a string */
    > char b[2];
    > b[0] = hm_buf;
    > b[1] = '\0';
    > /* Put the buffer and path into the file. */
    > //there is a bug in that it doesn't check to see if buffer
    > //exists already. Ideas on a fix would be helpful. 2 or more
    > //same buffers are possible. :-(.
    > fputs(b, o);
    > fputs(" ", o);
    > fputs(hm_path, o);
    > fputs("\n", o);
    > /* close file and delete memory */
    > fclose(o);

    You didn't notice that not only does this not check that the
    buffer is already in the file, it blightly overwrites
    the file starting at byte #0.

    Don't bother to fix this program, just toss it and buy
    a book. I suggest "Beginning Linux Programming" from
    Wrox Press. Work through it slowly, and there might be
    some hope left for you.

    I decided to make your cruft compile (by adding the required
    #include files and a #define _GNU_SOURCE), to show you what it
    does:

    blinky~/Stuff[191] g++ -o hm home.cpp
    blinky~/Stuff[192] ./hm
    blinky~[101] exit
    exit
    blinky~/Stuff[193]

    See? It created a new instance of the shell. If you use this
    command several times to so-called go to your home directory,
    you'll end up with umpteen instances of your shell.

    You cannot change to your home directory through an external
    command. It simply cannot be done, just forget it. As I said
    in my previous post, "cd" takes you back to your home
    directory. If you don't like the name, just alias it to hm:

    blinky~/Stuff[193] alias hm cd
    blinky~/Stuff[194] hm
    blinky~[195] pwd
    /home/sae
    blinky~[196]

    Now how difficult was that?

    You, sir, are NOT a C++ programmer. The paragraph below is
    so ridiculous it's almost sad:

    > I've developed my hm command (pronounced "home")*, I've modified a Linux
    > kernel mouse driver* to support Microsoft Wireless Optical mice with
    > tilt wheel technology. I use emacs and extend it with LISP. I know my
    > stuff. And with this authority, I have to say that I see nothing wrong
    > with Jeff Relf's X.CPP.

    You don't know your stuff, and worse, you don't know you don't
    know it. And everything is wrong with Jeff Relf's X.CPP. It's even
    worse than your code (at least yours has a semblance of formatting and
    comments).

    Now please leave comp.unix.programmer alone.

    -- 
    Stefaan
    -- 
    "What is stated clearly conceives easily."  -- Inspired sales droid
    

  • Next message: Mike: "not really lisp, but is there a lispish way?"

    Relevant Pages

    • Re: Im a C++ programmer, and Relfs X.CPP is good.
      ... >> and it doesn't compile either. ... home.cpp:93: implicit declaration of function `int fclose' ... You cannot change to your home directory through an external ...
      (comp.unix.programmer)
    • Re: Need help with wrong source code of encryption program
      ... > is a Dos encryption/decryption program written in C, ... When i give the correct password, the program says the password is ... encnew.cpp:97: implicit declaration of function `int _splitpath(.. ...
      (comp.programming)
    • Re: GCC difference in size of long int on Suse SLES9 / Suse Professional 10.0
      ... The kernel uses printf() with 'long int', ... I can't compile 'on-the-fly'. ... clashing with the hardware and any libs that you interact with. ... platform types build up their own int types. ...
      (comp.os.linux.development.apps)
    • Re: non-static context
      ... public MyStatic(int length, int width) { ... Within the MyStatic constructor method, a local variable named area is ... This version of class MyStatic won't compile. ...
      (comp.lang.java.help)
    • Re: new order doubt
      ... Warning test2.c: 8 no type specified. ... Defaulting to int ... Tests probably come in several different types: this should compile ... Even Microsoft has problems with this obscure rules. ...
      (comp.lang.c)