sl@0: /*
sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description:
sl@0: * William's Shell!
sl@0: * Simple Directory Lister, from the GNU C help file 
sl@0: * 
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: 
sl@0: #include <stddef.h>
sl@0: #include <stdio.h>
sl@0: #include <sys/types.h>
sl@0: #include <dirent.h>
sl@0: 
sl@0: int
sl@0: dir (void)
sl@0: {
sl@0:   DIR *dp;
sl@0:   struct dirent *ep;
sl@0: 
sl@0:   dp = opendir ("./");
sl@0:   if (dp != NULL)
sl@0:     {
sl@0:       while (ep = readdir (dp))
sl@0:         puts (ep->d_name);
sl@0:       (void) closedir (dp);
sl@0:     }
sl@0:   else
sl@0:     puts ("Couldn't open the directory.");
sl@0: 
sl@0:   return 0;
sl@0: }
sl@0: /**
sl@0: @SYMTestCaseID          SYSLIB-STDLIB-CT-1114
sl@0: @SYMTestCaseDesc	    Tests for command shell behaviour
sl@0: @SYMTestPriority 	    High
sl@0: @SYMTestActions  	    Tests for command shell behaviour
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMREQ                 REQ0000
sl@0: */		
sl@0: /* A silly shell-like thing */
sl@0: 
sl@0: #include <stdlib.h>	/* definition of exit() */
sl@0: #include <stdio.h>
sl@0: #include <errno.h>
sl@0: #include <string.h>
sl@0: 
sl@0: #include <unistd.h>	/* for getcwd */
sl@0: #include <sys/stat.h>	/* for mkdir */
sl@0: 
sl@0: int main(int argc, char*argv[])
sl@0: 	{
sl@0: 	char cmd[80];
sl@0: 	char path[MAXPATHLEN+1];
sl@0: 	int x;
sl@0: 
sl@0: 	for(;;) 
sl@0: 		{
sl@0: 		printf("%s> ", getcwd(path,sizeof(path)));
sl@0: 		x = scanf("%80s%s", cmd, path);
sl@0: 
sl@0: 		if (x!=2)
sl@0: 			{
sl@0: 			printf("\nerror\n");
sl@0: 			continue;
sl@0: 			}
sl@0: 
sl@0: 		if (strcmp(cmd,"exit")==0) 
sl@0: 			break;
sl@0: 		else
sl@0: 		if (strcmp(cmd,"ver")==0) 
sl@0: 			{
sl@0: 			printf("DOS version 3.30\n");
sl@0: 			continue;
sl@0: 			}
sl@0: 		else
sl@0: 		if (strcmp(cmd,"dir")==0) 
sl@0: 			{
sl@0: 			dir();
sl@0: 			continue;
sl@0: 			}
sl@0: 		else
sl@0: 		if (strcmp(cmd,"date")==0) 
sl@0: 			{
sl@0: 			time_t now=time(0);
sl@0: 			printf("%s",ctime(&now));
sl@0: 			continue;
sl@0: 			}
sl@0: 		else
sl@0: 		if (strcmp(cmd,"cd")==0) 
sl@0: 			x = chdir(path);
sl@0: 		else
sl@0: 		if (strcmp(cmd,"mkdir")==0) 
sl@0: 			x = mkdir(path, 0x777);
sl@0: 		else
sl@0: 		if (strcmp(cmd,"rmdir")==0) 
sl@0: 			x = rmdir(path);
sl@0: 		else
sl@0: 			{
sl@0: 			printf("Unrecognised command >%s<\n", cmd);
sl@0: 			continue;
sl@0: 			}
sl@0: 		if (x!=0)
sl@0: 			perror(path);
sl@0: 		}
sl@0: 	}