1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/WSHELL.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,119 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* William's Shell!
1.19 +* Simple Directory Lister, from the GNU C help file
1.20 +*
1.21 +*
1.22 +*/
1.23 +
1.24 +
1.25 +
1.26 +#include <stddef.h>
1.27 +#include <stdio.h>
1.28 +#include <sys/types.h>
1.29 +#include <dirent.h>
1.30 +
1.31 +int
1.32 +dir (void)
1.33 +{
1.34 + DIR *dp;
1.35 + struct dirent *ep;
1.36 +
1.37 + dp = opendir ("./");
1.38 + if (dp != NULL)
1.39 + {
1.40 + while (ep = readdir (dp))
1.41 + puts (ep->d_name);
1.42 + (void) closedir (dp);
1.43 + }
1.44 + else
1.45 + puts ("Couldn't open the directory.");
1.46 +
1.47 + return 0;
1.48 +}
1.49 +/**
1.50 +@SYMTestCaseID SYSLIB-STDLIB-CT-1114
1.51 +@SYMTestCaseDesc Tests for command shell behaviour
1.52 +@SYMTestPriority High
1.53 +@SYMTestActions Tests for command shell behaviour
1.54 +@SYMTestExpectedResults Test must not fail
1.55 +@SYMREQ REQ0000
1.56 +*/
1.57 +/* A silly shell-like thing */
1.58 +
1.59 +#include <stdlib.h> /* definition of exit() */
1.60 +#include <stdio.h>
1.61 +#include <errno.h>
1.62 +#include <string.h>
1.63 +
1.64 +#include <unistd.h> /* for getcwd */
1.65 +#include <sys/stat.h> /* for mkdir */
1.66 +
1.67 +int main(int argc, char*argv[])
1.68 + {
1.69 + char cmd[80];
1.70 + char path[MAXPATHLEN+1];
1.71 + int x;
1.72 +
1.73 + for(;;)
1.74 + {
1.75 + printf("%s> ", getcwd(path,sizeof(path)));
1.76 + x = scanf("%80s%s", cmd, path);
1.77 +
1.78 + if (x!=2)
1.79 + {
1.80 + printf("\nerror\n");
1.81 + continue;
1.82 + }
1.83 +
1.84 + if (strcmp(cmd,"exit")==0)
1.85 + break;
1.86 + else
1.87 + if (strcmp(cmd,"ver")==0)
1.88 + {
1.89 + printf("DOS version 3.30\n");
1.90 + continue;
1.91 + }
1.92 + else
1.93 + if (strcmp(cmd,"dir")==0)
1.94 + {
1.95 + dir();
1.96 + continue;
1.97 + }
1.98 + else
1.99 + if (strcmp(cmd,"date")==0)
1.100 + {
1.101 + time_t now=time(0);
1.102 + printf("%s",ctime(&now));
1.103 + continue;
1.104 + }
1.105 + else
1.106 + if (strcmp(cmd,"cd")==0)
1.107 + x = chdir(path);
1.108 + else
1.109 + if (strcmp(cmd,"mkdir")==0)
1.110 + x = mkdir(path, 0x777);
1.111 + else
1.112 + if (strcmp(cmd,"rmdir")==0)
1.113 + x = rmdir(path);
1.114 + else
1.115 + {
1.116 + printf("Unrecognised command >%s<\n", cmd);
1.117 + continue;
1.118 + }
1.119 + if (x!=0)
1.120 + perror(path);
1.121 + }
1.122 + }
1.123 \ No newline at end of file