Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Programming

Journal RLiegh's Journal: bleah, porgramming

Over the years I've found myself using the GUI (usually GNOME) a lot more. Even so, there are a few apps I prefer to use the CLI versions of; mostly ftp, irc (bitchx) and ...bittorrent.

However, typing out "btdownloadcurses blah" gets to be tedious; so I thought about shortening it to just 'bt', through an alias or something. Then I realised this would be a perfect thing to break out my (amazingly) meager porgramming skills for.

So, I figured it shouldn't be too hard to write a simple program which checks to see if there's at least two arguments (the name of the program, and an additional argument) and if there is, start an instance of btdownloadcurses out on the argument.

It took me 3 hours to figure out which exec to use (execl, execvp, execlp, etc), including discovering that I need to set a path and figuring out how to set one. I was finally able to spawn an instance of btdownloadcurses with the following code:

#include stdio.h>
#include unistd.h>
#include string.h> //slashcode freaks out on the includes, so I deliberately typo'd for readability

int main(int argc, char *argv[])
{
char torr[4096];
int lenny;
const char *p_envp[] = {"PATH=/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/sbin:/sbin","TERM=vt220",0};
lenny=strlen(argv[1]+1); //room for NULL
                if(argc > 1)
                {
                                memcpy(torr,argv[1],lenny);
                                printf("%s\n",torr); //debugging, lol
                                execle("/usr/bin/btdownloadcurses", "btdownloadcurses ",torr,0,p_envp);
                }
                return 0;
}

However, though it would run the bittorrent client, it would still crash for reasons which are largely unknown to me.

So, in the end I said "fuck it" and went with a shell script:

#!/bin/sh
btdownloadcurses $1

lol C.

On the uphand, I think I've just popped my struct cherry on this program, even though the p_envp struct is a direct ripoff of a program on page 354 of Linux Programming 2nd Edition.

This discussion has been archived. No new comments can be posted.

bleah, porgramming

Comments Filter:

The key elements in human thinking are not numbers but labels of fuzzy sets. -- L. Zadeh

Working...