]> Nishi Git Mirror - serenade.git/commitdiff
do not use readline
authornishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Sat, 27 Apr 2024 00:32:05 +0000 (00:32 +0000)
committernishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Sat, 27 Apr 2024 00:32:05 +0000 (00:32 +0000)
git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@60 0f02c867-ac3d-714e-8a88-971ba1f6efcf

Serenade/main.c

index 0321f7d103ea0803f61940c520fefe3ebeae68a2..2b4ba962824b820b159387f4512a446162d6c44d 100644 (file)
 
 extern bool is_repl;
 
+int run_command(const char* cmd){
+       if(strcmp(cmd, ":quit") == 0){
+               return 1;
+       }else{
+               fprintf(stderr, "Unknown command\n");
+               return 0;
+       }
+}
+
 int main(int argc, char** argv) {
        int i;
        bool loaded = false;
@@ -134,9 +143,11 @@ int main(int argc, char** argv) {
                                        br--;
                                }
                        }
-                       if(strcmp(line, ":quit") == 0) {
+                       if(line[0] == ':'){
+                               int st = run_command(line);
                                free(line);
-                               break;
+                               if(st != 0) break;
+                               continue;
                        }
                        char* tmp = str;
                        str = sn_strcat(tmp, line);
@@ -151,8 +162,13 @@ int main(int argc, char** argv) {
                        free(line);
 #else
                        if(cbuf[0] == '\n') {
-                               if(strcmp(str, ":quit") == 0) {
-                                       break;
+                               if(str[0] == ':'){
+                                       int st = run_command(str);
+                                       free(str);
+                                       str = malloc(1);
+                                       str[0] = 0;
+                                       if(st != 0) break;
+                                       continue;
                                }
                                if(br == 0 && strlen(str) > 0) {
                                        sn_eval(sn, str, strlen(str));
@@ -182,7 +198,9 @@ int main(int argc, char** argv) {
                        }
 #endif
                }
+#ifdef HAS_READLINE_SUPPORT
                write_history(".serenade_history");
+#endif
                free(str);
                sn_interpreter_free(sn);
        }