LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-03-2011, 08:14 AM   #1
serialcek
LQ Newbie
 
Registered: May 2011
Posts: 6

Rep: Reputation: Disabled
Question Programming Linux terminal


Hello everyone!
First of all sorry for my bad English.

I'm trying make a program Linux terminal in C.
I want that in this my terminal people can be able to to chose Windows,Linux or Mac commands to write..
When they run my program it will ask them which input method they wanna use (Linux, Windows, Mac) and then if they choose Mac they will be able to write Mac commands in terminal which runs in Linux and the commands will be recognized.

I'm trying to do some terminal emulator which works in linux.
All I got for now is a program which simulate the Linux terminal which means that it works only for linux commands.
The problem is that I didn't write it so I need some help to understand everything in the code.

Here can zoo download the code:
http://www.mediafire.com/?kp7f1y03827jgvf

I'm sorry for the comments in Slovene. If anyone need the translated comments I will translate then.

So in this my code I don't understand why it has to be compiled with this words:
gcc -Wall -ansi -pedantic -o fsh main.c

What does the ansi and pedantic mean?
And the other thing in line 151:

execvp(*exec_argv, exec_argv);

Is this the way that we run the command that the user wrote?
Is execvp the function that run our command?

That's for now all..
Thx
 
Old 08-03-2011, 11:36 AM   #2
tinyTux
Member
 
Registered: Mar 2011
Location: Extended Memory
Distribution: Gentoo
Posts: 64

Rep: Reputation: 9
Quote:
Originally Posted by serialcek View Post
Hello everyone!
First of all sorry for my bad English.

I'm trying make a program Linux terminal in C.
I want that in this my terminal people can be able to to chose Windows,Linux or Mac commands to write..
When they run my program it will ask them which input method they wanna use (Linux, Windows, Mac) and then if they choose Mac they will be able to write Mac commands in terminal which runs in Linux and the commands will be recognized.

I'm trying to do some terminal emulator which works in linux.
All I got for now is a program which simulate the Linux terminal which means that it works only for linux commands.
The problem is that I didn't write it so I need some help to understand everything in the code.

Here can zoo download the code:
http://www.mediafire.com/?kp7f1y03827jgvf

I'm sorry for the comments in Slovene. If anyone need the translated comments I will translate then.

So in this my code I don't understand why it has to be compiled with this words:
gcc -Wall -ansi -pedantic -o fsh main.c

What does the ansi and pedantic mean?
And the other thing in line 151:

execvp(*exec_argv, exec_argv);

Is this the way that we run the command that the user wrote?
Is execvp the function that run our command?

That's for now all..
Thx
I think you should reconsider the value of your project goals. For starters, there are already lots of Linux terminal emulators out there, so I don't see why you need to recreate this functionality. As far as the Mac commands -- well, Mac OSX will give you a bash shell by default, so what is to be ported? The only thing left to do then is to create a Windows (MS-DOS) terminal emulated in Linux: I don't think anyone has done that before, though I can't imagine why anyone would want to use DOS-style commands instead of what is available in Linux shells.

Anyway, the answers to all your questions are documented in the Linux man pages: enter man 1 gcc for the gcc switches and man 3 exec for the execvp information.
 
Old 08-03-2011, 12:12 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by serialcek View Post
execvp(*exec_argv, exec_argv);

Is this the way that we run the command that the user wrote?
Is execvp the function that run our command?
It's substantially more complicated than that, especially if your shell allows processes to execute in the background. For one, execvp will terminate the calling process and replace it with the program being called. Additionally, many commands you call in a normal shell are actually built into the shell, further complicating things.

There aren't really Linux, OS X, and Windows "commands", per se, aside from what's built into *nix shells vs. what's built into DOS (or whatever Windows uses these days). There's the syntax of the interpreter and there are the programs available for execution on the system. In *nix the terminal is separate from the shell; a terminal emulator operates a pseudoterminal in the way the shell instructs it to. You don't want to get involved in writing a terminal emulator as it doesn't pertain to your objectives.

I haven't looked at the link you posted, but if you want to understand writing a shell you should look at the manpages (in 2 and 3 only) for fork, pipe, dup2, execvp, setpgrp, tcsetpgrp, termios, waitpid, fcntl, stat, putenv, getenv, signal, and kill, to name a few. That doesn't even include interacting with the user. This just gives you an idea of what you're up against; to learn to write a shell you should find a good tutorial then consult the glibc manual. As tinyTux suggested, however, writing a shell might not be what you're looking for.
Kevin Barry

Last edited by ta0kira; 08-03-2011 at 12:13 PM.
 
Old 08-03-2011, 01:49 PM   #4
serialcek
LQ Newbie
 
Registered: May 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thx for yours answers..
First I will answer why I wanna write this..the answer is school
So I'm gonna read some of the man pages you suggested.. but yes as I wrote I will have to do this project so I will probably write here again
Thx again for now
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pseudo terminal programming Alien_Hominid Programming 5 01-20-2008 04:19 AM
Basic Linux Programming Question (QT terminal control) Boffy Programming 5 09-09-2004 12:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration