Skip to content

Commit 309203e

Browse files
committed
new function for replace and dynamic prompt
add new lib for strings , with str replace function and evaluate prompt from the input
1 parent 4ad24be commit 309203e

File tree

16 files changed

+157
-47
lines changed

16 files changed

+157
-47
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.o

.vscode/launch.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "gcc - Build and debug active file",
9+
"type": "cppdbg",
10+
"request": "launch",
11+
"program": "${fileDirname}/${fileBasenameNoExtension}",
12+
"args": [],
13+
"stopAtEntry": false,
14+
"cwd": "${fileDirname}",
15+
"environment": [],
16+
"externalConsole": false,
17+
"MIMode": "gdb",
18+
"setupCommands": [
19+
{
20+
"description": "Enable pretty-printing for gdb",
21+
"text": "-enable-pretty-printing",
22+
"ignoreFailures": true
23+
}
24+
],
25+
"preLaunchTask": "C/C++: gcc build active file",
26+
"miDebuggerPath": "/usr/bin/gdb"
27+
}
28+
]
29+
}

.vscode/tasks.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"tasks": [
3+
{
4+
"type": "cppbuild",
5+
"label": "C/C++: gcc build active file",
6+
"command": "/usr/bin/gcc",
7+
"args": [
8+
"-g",
9+
"${file}",
10+
"-o",
11+
"${fileDirname}/${fileBasenameNoExtension}"
12+
],
13+
"options": {
14+
"cwd": "${fileDirname}"
15+
},
16+
"problemMatcher": [
17+
"$gcc"
18+
],
19+
"group": {
20+
"kind": "build",
21+
"isDefault": true
22+
},
23+
"detail": "Task generated by Debugger."
24+
}
25+
],
26+
"version": "2.0.0"
27+
}

Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
lash: lash.c
2-
$(CC) -o lash builtin.c lash.c history.c prompt.c input.c -Wall -Wextra -pedantic -std=c99
1+
CC=gcc
2+
CFLAGS=-I.
3+
DEPS = lash.h builtin.h prompt.h history.h input.h ./lib/string/strlib.h
4+
OBJ = lash.o builtin.o prompt.o history.o input.o ./lib/string/strlib.o
5+
6+
%.o: %.c $(DEPS)
7+
$(CC) -c -o $@ $< $(CFLAGS)
8+
9+
lash: $(OBJ)
10+
$(CC) -o $@ $^ $(CFLAGS)
11+
12+
13+
.PHONY: clean
14+
15+
clean:
16+
rm -f *.o

a.out

Whitespace-only changes.

basics.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef unsigned long int uint64;
6464
*a[] = { __VA_ARGS__,NULL}, \
6565
**ss=a; \
6666
while((s=*ss++)) \
67-
while((*s)&&(++offset<(int)sizeof(buf))) \
67+
while((*s)&&((++offset)<(int)sizeof(buf))) \
6868
*bp++=*s++; \
6969
if (offset!=sizeof(buf))*bp=0; \
7070
}while(0)
@@ -89,15 +89,4 @@ typedef unsigned long int uint64;
8989
* is even and odd for number
9090
*/
9191
#define IS_EVEN( num ) (!IS_ODD( (num) ))
92-
#define IS_ODD( num ) ((num) & 1)
93-
94-
/*
95-
* Swap integers
96-
*/
97-
//void swap (int *a,int *b)
98-
//{
99-
//int temp;
100-
//temp = *a;
101-
//*a = *b;
102-
//*b = temp;
103-
//}
92+
#define IS_ODD( num ) ((num) & 1)

builtin.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
#include "basics.h"
44
#include "builtin.h"
55

6+
67
/*
78
* builtin function
89
*/
9-
extern char *builtin_str[] = {
10+
char *builtin_str[] = {
1011
"cd",
1112
"help",
1213
"exit"
1314
};
1415

1516
/*
16-
* some pointer to builtin functions
17+
* List of builtin commands, followed by their corresponding functions.
1718
*/
18-
extern int (*builtin_func[]) (char **) = {
19+
int (*builtin_func[]) (char **) = {
1920
&lash_cd,
2021
&lash_help,
2122
&lash_exit
@@ -42,7 +43,8 @@ int lash_cd(char **args)
4243
int lash_help(char **args)
4344
{
4445
int i;
45-
printl("modified and improved lsh by pms (parsa mahmoudy sahebi , parsa011 :D)");
46+
printl("Stephen Brennan's lash");
47+
printl("modified and improved by pms (parsa mahmoudy sahebi , parsa011 :D)");
4648
printl("Type program names and arguments, and hit enter.");
4749
printl("The following are built in:");
4850

history.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

lash

232 Bytes
Binary file not shown.

lash.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
int main(int argc,char **arcv)
1212
{
1313
// load config file
14-
set_prompt("> ");
14+
set_prompt("%d > ");
1515
showpath = TRUE;
1616
// Run loop
1717
lash_loop();
@@ -42,11 +42,9 @@ void lash_loop(void)
4242
*/
4343
char *lash_read_line()
4444
{
45-
int bufsize = lash_RL_BUFSIZE, c;
45+
int bufsize = LASH_RL_BUFSIZE, c;
4646
int position = 0;
4747
char *buffer = malloc(sizeof(char) * bufsize);
48-
49-
check_alloc(buffer);
5048

5149
// If we hit EOF, replace it with a null character and return.
5250
while (TRUE) {
@@ -61,9 +59,8 @@ char *lash_read_line()
6159

6260
// If we have exceeded the buffer, reallocate.
6361
if (position >= bufsize){
64-
bufsize += lash_RL_BUFSIZE;
62+
bufsize += LASH_RL_BUFSIZE;
6563
buffer = realloc(buffer,bufsize);
66-
check_alloc(buffer);
6764
}
6865
}
6966

@@ -74,20 +71,20 @@ char *lash_read_line()
7471
*/
7572
char **lash_split_line(char *line)
7673
{
77-
int bufsize = lash_TOK_BUFSIZE, position = 0;
74+
int bufsize = LASH_TOK_BUFSIZE, position = 0;
7875
char **tokens = malloc(bufsize * sizeof(char*));
7976
char *token;
8077

81-
token = strtok(line,lash_TOK_DELIM);
78+
token = strtok(line,LASH_TOK_DELIM);
8279
// i have to write a tokenizer for \ / and ....
8380
while (token != NULL){
8481
tokens[position++] = token;
8582

8683
if (position >= bufsize){
87-
bufsize += lash_TOK_BUFSIZE;
84+
bufsize += LASH_TOK_BUFSIZE;
8885
tokens = realloc(tokens,bufsize * sizeof(char*));
8986
}
90-
token = strtok(NULL, lash_TOK_DELIM);
87+
token = strtok(NULL, LASH_TOK_DELIM);
9188
}
9289
tokens[position] = NULL;
9390
return tokens;

0 commit comments

Comments
 (0)