I dont want this


 
Thread Tools Search this Thread
Top Forums Programming I dont want this
# 1  
Old 05-18-2005
I dont want this

Im creating a sort of shell, for my cybercafe
This will restrict my clients from accessing unwanted materials
so im programming a similar bash to
1. to meet my goals
2. to learn new things.

im creating it in C,
please have a look at the attachement.

i wish to avoid having a blank space when Enter is pressed.
i want it to react as bash does.
is there any means to catch the enter key before changing line?
I dont want this-snapshot5png
# 2  
Old 05-18-2005
Could you paste the code that you are using for this?
# 3  
Old 05-18-2005
C,

This is a sample code that I wrote on a HP-UX 11.11 system. This prints a prompt and takes input. It does not act on the input, except when it receives exit - it exits.

Code:
#include<stdio.h>

int main() {
        char argarray[80];
        while(1) {
                fprintf(stdout,"! ");
                fgets(argarray,80,stdin);
                argarray[strlen(argarray)-1]='\0';
                if(!strcmp(argarray,"exit")){
                        break;
                }
                /*fprintf(stdout,"%s was input.\n",argarray);*/
        }
        exit(0);
}

You can uncomment the fprintf in the end to echo what was input.

Last edited by blowtorch; 05-18-2005 at 04:51 PM.. Reason: clarifications
# 4  
Old 05-18-2005
im REwriting it at the moment,
AT THIS STAGE:
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

struct stat s;

main() {

char c[100];
int desc,length_c;
char * _tmp =".myAI~";

desc = open( _tmp , O_CREAT | O_RDWR , 500 );
if ( desc < 0 ) {
perror("myAI ");
exit(0);
}

if (fork()==0) {
system("clear");
do {

printf("myAI\\>§ ");
scanf("%s",c);

length_c=strlen(c);
lseek(desc,0,sizeof(char));
write (desc,c,length_c);

/*
if (strcmp("machine",c)==0) {
system("echo $USER@`hostname`");
system("echo kernel : `uname -r`");
system("kde-config --version | grep KDE");
}
else */if (strcmp("exit",c)==0) {
exit(1);
}
else printf("myAI: %s : command not found\n",c);

} while (c!=NULL);
exit(1);
}
wait(NULL);
}

THATS FOR SURE IT WONT WORK;
its only to give your an idea where i am
# 5  
Old 05-18-2005
Quote:
man scanf
...
...
scanf() cannot read a null string.
...
I think that this is where your problem lies. You can replace the scanf with the fgets that I am using in the code that I have posted in this thread.
# 6  
Old 05-18-2005
Thanks it works.
at this stage im here Smilie

Code:
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

struct stat s;

main() {

 char c[100];
 int tmp_desc,length_c;
 char * _tmp = ".myAI~";
 char * _myAIrc = ".myAIrc";


 tmp_desc = open( _tmp , O_CREAT | O_RDWR , 500 );
 if ( tmp_desc < 0 ) {
    perror("myAI ");
    exit(0);
 }
 
 if (fork()==0) {
   system("clear");
   while(1) {
	
	fprintf(stdout,"!"); 
	fgets(c,100,stdin);
	c[strlen(c)-1]='\0';	
	length_c=strlen(c);
	lseek(tmp_desc,0,sizeof(char));
//	write (tmp_desc,c,length_c);
	
	/*
	if (strcmp("machine",c)==0) {
    	   system("echo $USER@`hostname`");
	   system("echo kernel : `uname -r`");
	   system("kde-config --version | grep KDE");
	}
	else */if(!strcmp(c,"exit")){
                        exit(0);
                }
	else printf("%s command not found\n",c);
	
   } while (c!=NULL);
	exit(1);
 }
 wait(NULL);
 
}

# 7  
Old 05-19-2005
FWIW - there are restricted shells available.

It's fun to learn C I guess, except that http://freshmeat.net has 750+ unix shell projects. Because every CS major everywhere has to write one for a project. You can learn from what other folks did instead of completely re-inventing the wheel.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Ubuntu

Dont Allow Exitting from a Script

Hello, I wrote a script and disabled Ctrl+C using trap ' ' 2 For security, I cannot allow users to exit the script on their own for then they would have access to the command prompt. Are there any other cases that I need to cover? Thank you. I'm new to scripting. (6 Replies)
Discussion started by: fzivkovi
6 Replies

2. UNIX for Dummies Questions & Answers

i dont know how to solve this error

can while do make aloop as do while in c language ? (1 Reply)
Discussion started by: teefa
1 Replies

3. Shell Programming and Scripting

i dont know where problem!!

okthanksi solve it :) (1 Reply)
Discussion started by: dream23
1 Replies

4. Shell Programming and Scripting

ls | grep (i dont know what to put here)

Dear users, I googled for a while, but i have got a lot of different answers regarding a simple unix command. lets say there are a lot of files in a directory. How can i list the files in a directory whose file types is "text"? Thank you in advance (4 Replies)
Discussion started by: kevincobain2000
4 Replies

5. Shell Programming and Scripting

Dont what this sed expression does

I am new to unix and have come across the sed expression but not sure what its doing. Can someone please tell me whats happening in the sed command below? (2 Replies)
Discussion started by: 5211171
2 Replies

6. Shell Programming and Scripting

deleting rows that dont have ....

Hi I posted earlier. This is sorta similar but I want to delete rows that dont have R, T, Y or U. Nam1 RTYU Nam2 RRTT Nam3 RYTU Nam4 IRTT So the output would look like this? Nam1 RTYU Nam2 RRTT Nam3 RYTU too many problems thanks (3 Replies)
Discussion started by: kylle345
3 Replies

7. UNIX for Dummies Questions & Answers

script dont' break out

I have concurrent manager stop and check to verify all the process are stopped BUT even after all the process are stopped query script continues to run without break out. # stop the concurrent manager $COMMON_TOP/admin/scripts/$CONTEXT_NAME/adstpall.sh $DB_USER/$DB_PSWD # check if the... (1 Reply)
Discussion started by: Paul.S
1 Replies

8. Shell Programming and Scripting

dont't find right regex

I have a string which contains following information: <SZ.T><P ALIGN="CENTER"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="+3">Bundesregierung nimmt sich dicke Deutsche vor</FONT></P></SZ.T> <SZ.UT><P ALIGN="CENTER"><FONT SIZE="+1"><I> Seehofer und Schmidt planen Kampagne gegen... (3 Replies)
Discussion started by: trek
3 Replies

9. What is on Your Mind?

dont understand

i'm trying to learn unix and i posted a question and what i was typing from school. i can't figure it out. how am i supposed to learn , when i get shutdown by an admin. for posting a homework question. doesn't make any sense. its a dumb rule. thanks for helping (4 Replies)
Discussion started by: AtomJ22
4 Replies
Login or Register to Ask a Question