C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-09-2002, 03:37 PM   #1
Registered User
 
Join Date: Apr 2002
Posts: 4
builtin command

I am in the progress of creating a bash shell. I have created my own stand alone programs for ls, kill, ps etc etc. How do I incorporate them into my program? I've got two programs - one called <def.h> where all the definitions and globals are stored and the other one the main code, with the main function, getline function, parse function, execute function etc.

The only bit i'm confused about is the builtin command - can anyone explain it to me? This is what I've found on the web site - and I don't understand it :-(
builtin()
{
if (check("exit"))
exit (0);
else if (check("cd"))
return do_cd();
else if (check("history"))
return do_history();
else if (check("!"))
return do_repeat_connand();
else
return 0;
}

The do_cd() function can then extract a directory name from the line[] array and use the chdir() system call to make the change. For the ! and history commands, you need to modify the getline() function so that lines entered at the keyboard are stored as they are entered. The history command can then list all the commands in the store and the command can copy the appropriate stored command back into the line[] array. do_repeat_command() can then return a zero from builtin() so that line[] will be parsed as normal.

Do I need to specify the path of my program in the def.h??? How do I carry out my own script within the builtin command?!!!

Thanks in advanced.
J
jon21 is offline   Reply With Quote
Old 04-11-2002, 03:42 AM   #2
Registered User
 
Join Date: Mar 2002
Posts: 87
In the forkexec function you should see the following code.

Code:
execvp(ptr->av[0],ptr->av); 
exit(1);
If you use the execv function then u can execute ur own code, for example.

Code:
execv("cd.exe",ptr->av);
exit(1);
__________________
PuterPaul.co.uk - Portfolio site
pdstatha is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sort a simple linked list using swap-sort method JOCAAN C Programming 24 08-07-2009 11:48 AM
problem with "touch" command in c program Moony C Programming 10 08-01-2006 09:56 AM
Batch file programming year2038bug Tech Board 10 09-05-2005 03:30 PM
Ping problem bladerunner627 C++ Programming 12 02-02-2005 12:54 PM
exe files in -c- language enjoy C Programming 6 05-18-2004 04:36 PM


All times are GMT -6. The time now is 01:43 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22