main.c (9890ff8357a674572254e0be06b175a1e8eab4b0) | main.c (8aafd47d0dbabbca4365c9565fbe0e051e7346dd) |
---|---|
1/* 2 * stub main for testing Ficl 3 * $Id: main.c,v 1.2 2010/09/10 09:01:28 asau Exp $ 4 */ 5/* 6 * Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 7 * All rights reserved. 8 * --- 28 unchanged lines hidden (view full) --- 37 * SUCH DAMAGE. 38 */ 39 40#include <stdio.h> 41#include <stdlib.h> 42#include <unistd.h> 43#include <termios.h> 44#include <sys/errno.h> | 1/* 2 * stub main for testing Ficl 3 * $Id: main.c,v 1.2 2010/09/10 09:01:28 asau Exp $ 4 */ 5/* 6 * Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 7 * All rights reserved. 8 * --- 28 unchanged lines hidden (view full) --- 37 * SUCH DAMAGE. 38 */ 39 40#include <stdio.h> 41#include <stdlib.h> 42#include <unistd.h> 43#include <termios.h> 44#include <sys/errno.h> |
45#include <err.h> |
|
45 46#include <ficl.h> 47#include <ficlplatform/emu.h> 48#include <libtecla.h> 49 50#define LINELEN 1024 51#define HISTORY 2048 52 --- 42 unchanged lines hidden (view full) --- 95 96 if (ioctl(1, TIOCGWINSZ, &ws) != -1) { 97 if (ws.ws_col) 98 cols = ws.ws_col; 99 if (ws.ws_row) 100 rows = ws.ws_row; 101 } 102 | 46 47#include <ficl.h> 48#include <ficlplatform/emu.h> 49#include <libtecla.h> 50 51#define LINELEN 1024 52#define HISTORY 2048 53 --- 42 unchanged lines hidden (view full) --- 96 97 if (ioctl(1, TIOCGWINSZ, &ws) != -1) { 98 if (ws.ws_col) 99 cols = ws.ws_col; 100 if (ws.ws_row) 101 rows = ws.ws_row; 102 } 103 |
103 clearenv(); 104 asprintf(&buffer, "%d", cols); 105 setenv("screen-#cols", buffer, 1); | 104 (void) clearenv(); 105 if (asprintf(&buffer, "%d", cols) < 0) 106 err(EXIT_FAILURE, NULL); 107 (void) setenv("screen-#cols", buffer, 1); |
106 free(buffer); | 108 free(buffer); |
107 asprintf(&buffer, "%d", rows); 108 setenv("screen-#rows", buffer, 1); | 109 if (asprintf(&buffer, "%d", rows) < 0) 110 err(EXIT_FAILURE, NULL); 111 (void) setenv("screen-#rows", buffer, 1); |
109 free(buffer); 110 111 if (getenv("prompt") == NULL) | 112 free(buffer); 113 114 if (getenv("prompt") == NULL) |
112 setenv("prompt", "${interpret}", 1); | 115 (void) setenv("prompt", "${interpret}", 1); |
113 if (getenv("interpret") == NULL) | 116 if (getenv("interpret") == NULL) |
114 setenv("interpret", "ok", 1); | 117 (void) setenv("interpret", "ok", 1); |
115 116 if ((vm = bf_init("", NULL)) == NULL) | 118 119 if ((vm = bf_init("", NULL)) == NULL) |
117 return (ENOMEM); | 120 err(EXIT_FAILURE, NULL); |
118 returnValue = ficlVmEvaluate(vm, ".ver cr quit"); 119 120 /* 121 * load files specified on command-line 122 */ 123 if (argc > 1) { | 121 returnValue = ficlVmEvaluate(vm, ".ver cr quit"); 122 123 /* 124 * load files specified on command-line 125 */ 126 if (argc > 1) { |
124 asprintf(&buffer, ".( loading %s ) cr include %s\n cr", 125 argv[1], argv[1]); | 127 if (asprintf(&buffer, ".( loading %s ) cr include %s\n cr", 128 argv[1], argv[1]) < 0) 129 err(EXIT_FAILURE, NULL); |
126 returnValue = ficlVmEvaluate(vm, buffer); 127 free(buffer); 128 } 129 130 if ((gl = new_GetLine(LINELEN, HISTORY)) == NULL) { 131 bf_fini(); | 130 returnValue = ficlVmEvaluate(vm, buffer); 131 free(buffer); 132 } 133 134 if ((gl = new_GetLine(LINELEN, HISTORY)) == NULL) { 135 bf_fini(); |
132 return (ENOMEM); | 136 err(EXIT_FAILURE, NULL); |
133 } 134 135 while (returnValue != FICL_VM_STATUS_USER_EXIT) { 136 if ((buffer = gl_get_line(gl, prompt(), NULL, -1)) == NULL) 137 break; 138 returnValue = bf_run(buffer); 139 } 140 141 gl = del_GetLine(gl); 142 bf_fini(); | 137 } 138 139 while (returnValue != FICL_VM_STATUS_USER_EXIT) { 140 if ((buffer = gl_get_line(gl, prompt(), NULL, -1)) == NULL) 141 break; 142 returnValue = bf_run(buffer); 143 } 144 145 gl = del_GetLine(gl); 146 bf_fini(); |
143 return (returnValue); | 147 if (returnValue != FICL_VM_STATUS_USER_EXIT) 148 return (EXIT_FAILURE); 149 return (EXIT_SUCCESS); |
144} | 150} |