diff options
| author | Abdellah El Morabit <nsrddyn@gmail.com> | 2025-01-31 19:45:59 +0100 |
|---|---|---|
| committer | Abdellah El Morabit <nsrddyn@gmail.com> | 2025-01-31 19:45:59 +0100 |
| commit | 7edc3ede1e7c17dd26040520c65765ef4ed8e782 (patch) | |
| tree | f3d630373dbe0570d265b9c01b550b60bdd361de /main.c | |
| parent | e3e66120708e814b118ea7061cf57d9426f86032 (diff) | |
working on some basic commands like listing the current directory and get the pid of a process, following the APUE
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 61 |
1 files changed, 39 insertions, 22 deletions
@@ -1,34 +1,51 @@ #include <stdio.h> #include <stdlib.h> + + #include <string.h> #include <ctype.h> -#include <stdbool.h> + #include <readline/readline.h> -int main() { - const bool RUNNING = true; - char *COMMAND_HISTORY; - COMMAND_HISTORY = (char *)malloc(sizeof(char)); +// import files for reading the current directory +#include "apue.c" +#include <dirent.h> - // RUNNING THE PROGRAM ON AN ENDLESS LOOP - // BREAKS WHEN USER ENTERS EXIT - while(RUNNING) { - char *TEMP = ""; +#define true 1 +#define false 0 + +void err_quit(char * str) { + printf("%s", str); +} +void err_sys(char * str) { + printf("%s", str); +} - scanf("%s", &TEMP); - for (int i = 0; (TEMP + i) != "/0"; i++) - { - tolower(TEMP[0]); - } +void PROCESS_PID(char *string) { - if (TEMP == "exit") { - printf("exited successfully"); - } - else { - strcpy(&TEMP, (COMMAND_HISTORY)); - printf("%s",COMMAND_HISTORY); - } + printf("PID %ld\n", (long)getpid()); +} + +void LIST_CURRENT_DIRECTORY(int argc, char *argv[]) +{ + DIR *dp; + struct dirent *dirp; + if (argc != 2) + err_quit("usage: ls directory_name"); + if ((dp = opendir(argv[1])) == NULL) + err_sys( argv[1]); + while ((dirp = readdir(dp)) != NULL) + printf("%s\n", dirp->d_name); + closedir(dp); +} + + +int main(int argc, char *argv[]) { + + printf("succefully started the program"); + // RUNNING THE PROGRAM ON AN ENDLESS LOOP + // BREAKS WHEN USER ENTERS EXIT + // ReSharper disable once CppDFAEndlessLoop - } return 0; } |
