Search
Search
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int i = 0;
char *p;
while (p != NULL)
tok[i++] = p;
tok[i] = NULL;
{
int fh, count = 0, i = 0, j = 0;
fh = open(fn, O_RDONLY);
if (fh == -1)
return;
switch (op)
buff[j++] = c;
if (c == '\n')
buff[j] = '\0';
j = 0;
i++;
if (strstr(buff, pattern))
break;
}
break;
buff[j++] = c;
if (c == '\n')
buff[j] = '\0';
j = 0;
p = buff;
count++;
p++;
break;
buff[j++] = c;
if (c == '\n')
buff[j] = '\0';
j = 0;
i++;
if (strstr(buff, pattern))
break;
default:
printf("Invalid option\n");
break;
close(fh);
int main()
int pid;
while (1)
printf("myshell$ ");
make_toks(buff, args);
if (strcmp(args[0], "search") == 0)
else
pid = fork();
if (pid > 0)
else if (pid == 0)
execvp(args[0], args);
perror("execvp failed");
exit(EXIT_FAILURE);
else
perror("fork failed");
return 0;
}
List
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
int i = 0;
char *p;
while (p != NULL)
tok[i++] = p;
tok[i] = NULL;
}
DIR *dp;
int dc = 0, fc = 0;
dp = opendir(dn);
if (dp == NULL)
perror("opendir");
return;
switch (op)
case 'f':
if (entry->d_type == DT_REG)
printf("%s\n", entry->d_name);
break;
case 'n':
break;
case 'i':
if (entry->d_type == DT_REG)
break;
default:
printf("Invalid option\n");
break;
closedir(dp);
int main()
int pid;
while (1)
printf("myshell$ ");
make_toks(buff, args);
if (strcmp(args[0], "list") == 0)
list(args[2], args[1][0]);
else
pid = fork();
if (pid > 0)
else if (pid == 0)
execvp(args[0], args);
else
return 0;
}
Count
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int i = 0;
char *p;
while (p != NULL)
tok[i++] = p;
tok[i] = NULL;
{
int fh, cc = 0, wc = 0, lc = 0;
char c;
int in_word = 0;
fh = open(fn, O_RDONLY);
if (fh == -1)
return;
cc++;
if (in_word)
wc++;
in_word = 0;
if (c == '\n')
lc++;
else
{
in_word = 1;
if (in_word)
wc++;
close(fh);
switch (op)
case 'c':
break;
case 'w':
break;
case 'l':
break;
default:
printf("Invalid option. Use 'c' for characters, 'w' for words, or 'l' for lines.\n");
break;
int main()
{
int pid;
while (1)
printf("myshell$ ");
if (strcmp(args[0], "count") == 0)
else
count(args[2], args[1][0]);
else
else if (pid == 0)
printf("Bad command.\n");
else
printf("Fork failed.\n");
return 0;
Typeline
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int i = 0;
char *p;
while (p != NULL)
tok[i++] = p;
tok[i] = NULL;
int fh, i, j, n;
char c;
fh = open(fn, O_RDONLY);
if (fh == -1)
return;
if (strcmp(op, "a") == 0)
printf("%c", c);
close(fh);
return;
n = atoi(op);
if (n > 0)
i = 0;
printf("%c", c);
if (c == '\n')
i++;
if (i == n)
break;
}
else if (n < 0)
i = 0;
if (c == '\n')
i++;
lseek(fh, 0, SEEK_SET);
j = 0;
if (c == '\n')
j++;
if (j == i + n)
break;
{
printf("%c", c);
close(fh);
int main()
int pid;
while (1)
printf("myshell$ ");
if (strcmp(args[0], "typeline") == 0)
}
else
typeline(args[2], args[1]);
else
if (pid > 0)
else if (pid == 0)
printf("Bad command.\n");
else
printf("Fork failed.\n");
}
return 0;