Skip to content

Commit 7f69bea

Browse files
committed
Simple echoeing prompt, with added compatibility for windows users.
1 parent 8a83454 commit 7f69bea

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

.prompt.c.swp

12 KB
Binary file not shown.

prompt

8.59 KB
Binary file not shown.

prompt.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
/**
5+
* @file prompt.c
6+
* @author Advait Raykar
7+
* @date Mon Dec 11 22:30:02 IST 2017
8+
* @brief Promp file for the 'Peasant' dialect of lisp.
9+
*/
10+
11+
/*Preprocessors for when run on a Windows machine*/
12+
#ifdef _WIN32
13+
#include <string.h>
14+
15+
static char buffer[2048];
16+
17+
18+
/*Function to substitute the readline function in windows*/
19+
char *readline(char *prompt){
20+
fputs(prompt, stdout);
21+
fgets(buffer, 2048, stdin);
22+
char *cpy = malloc(strlen(buffer)+1);
23+
strcpy(cpy, buffer);
24+
cpy[strlen(buffer)-1]='\0';
25+
return cpy;
26+
}
27+
28+
/*Fake add_history funtion for windows*/
29+
void add_history(char *dummy){}
30+
31+
/*Otherwise include the following for nix systems*/
32+
#else
33+
#include <editline/readline.h>
34+
#include <editline/history.h>
35+
#endif
36+
37+
int main(int argc, char** argv){
38+
/*Print Version and Exit information*/
39+
puts("Peasant Lisp Version 0.1");
40+
puts("Press ctrl+c to exit\n");
41+
42+
while(1){
43+
char* input = readline("Peasant> ");
44+
45+
add_history(input);
46+
printf("You just input %s\n", input);
47+
/*Input has to be freed as for all inputs
48+
* same pointer is used
49+
*/
50+
free(input);
51+
}
52+
return 0;
53+
}

0 commit comments

Comments
 (0)