sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* William's Shell!
|
sl@0
|
16 |
* Simple Directory Lister, from the GNU C help file
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
#include <stddef.h>
|
sl@0
|
24 |
#include <stdio.h>
|
sl@0
|
25 |
#include <sys/types.h>
|
sl@0
|
26 |
#include <dirent.h>
|
sl@0
|
27 |
|
sl@0
|
28 |
int
|
sl@0
|
29 |
dir (void)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
DIR *dp;
|
sl@0
|
32 |
struct dirent *ep;
|
sl@0
|
33 |
|
sl@0
|
34 |
dp = opendir ("./");
|
sl@0
|
35 |
if (dp != NULL)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
while (ep = readdir (dp))
|
sl@0
|
38 |
puts (ep->d_name);
|
sl@0
|
39 |
(void) closedir (dp);
|
sl@0
|
40 |
}
|
sl@0
|
41 |
else
|
sl@0
|
42 |
puts ("Couldn't open the directory.");
|
sl@0
|
43 |
|
sl@0
|
44 |
return 0;
|
sl@0
|
45 |
}
|
sl@0
|
46 |
/**
|
sl@0
|
47 |
@SYMTestCaseID SYSLIB-STDLIB-CT-1114
|
sl@0
|
48 |
@SYMTestCaseDesc Tests for command shell behaviour
|
sl@0
|
49 |
@SYMTestPriority High
|
sl@0
|
50 |
@SYMTestActions Tests for command shell behaviour
|
sl@0
|
51 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
52 |
@SYMREQ REQ0000
|
sl@0
|
53 |
*/
|
sl@0
|
54 |
/* A silly shell-like thing */
|
sl@0
|
55 |
|
sl@0
|
56 |
#include <stdlib.h> /* definition of exit() */
|
sl@0
|
57 |
#include <stdio.h>
|
sl@0
|
58 |
#include <errno.h>
|
sl@0
|
59 |
#include <string.h>
|
sl@0
|
60 |
|
sl@0
|
61 |
#include <unistd.h> /* for getcwd */
|
sl@0
|
62 |
#include <sys/stat.h> /* for mkdir */
|
sl@0
|
63 |
|
sl@0
|
64 |
int main(int argc, char*argv[])
|
sl@0
|
65 |
{
|
sl@0
|
66 |
char cmd[80];
|
sl@0
|
67 |
char path[MAXPATHLEN+1];
|
sl@0
|
68 |
int x;
|
sl@0
|
69 |
|
sl@0
|
70 |
for(;;)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
printf("%s> ", getcwd(path,sizeof(path)));
|
sl@0
|
73 |
x = scanf("%80s%s", cmd, path);
|
sl@0
|
74 |
|
sl@0
|
75 |
if (x!=2)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
printf("\nerror\n");
|
sl@0
|
78 |
continue;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
if (strcmp(cmd,"exit")==0)
|
sl@0
|
82 |
break;
|
sl@0
|
83 |
else
|
sl@0
|
84 |
if (strcmp(cmd,"ver")==0)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
printf("DOS version 3.30\n");
|
sl@0
|
87 |
continue;
|
sl@0
|
88 |
}
|
sl@0
|
89 |
else
|
sl@0
|
90 |
if (strcmp(cmd,"dir")==0)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
dir();
|
sl@0
|
93 |
continue;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
else
|
sl@0
|
96 |
if (strcmp(cmd,"date")==0)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
time_t now=time(0);
|
sl@0
|
99 |
printf("%s",ctime(&now));
|
sl@0
|
100 |
continue;
|
sl@0
|
101 |
}
|
sl@0
|
102 |
else
|
sl@0
|
103 |
if (strcmp(cmd,"cd")==0)
|
sl@0
|
104 |
x = chdir(path);
|
sl@0
|
105 |
else
|
sl@0
|
106 |
if (strcmp(cmd,"mkdir")==0)
|
sl@0
|
107 |
x = mkdir(path, 0x777);
|
sl@0
|
108 |
else
|
sl@0
|
109 |
if (strcmp(cmd,"rmdir")==0)
|
sl@0
|
110 |
x = rmdir(path);
|
sl@0
|
111 |
else
|
sl@0
|
112 |
{
|
sl@0
|
113 |
printf("Unrecognised command >%s<\n", cmd);
|
sl@0
|
114 |
continue;
|
sl@0
|
115 |
}
|
sl@0
|
116 |
if (x!=0)
|
sl@0
|
117 |
perror(path);
|
sl@0
|
118 |
}
|
sl@0
|
119 |
} |