2 * stub main for testing Ficl
3 * $Id: main.c,v 1.2 2010/09/10 09:01:28 asau Exp $
6 * Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
9 * Get the latest Ficl release at http://ficl.sourceforge.net
11 * I am interested in hearing from anyone who uses Ficl. If you have
12 * a problem, a success story, a defect, an enhancement request, or
13 * if you would like to contribute to the Ficl release, please
14 * contact me by email at the address above.
16 * L I C E N S E and D I S C L A I M E R
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 #include <sys/errno.h>
47 #include <ficlplatform/emu.h>
56 static char prompt
[20]; /* probably too large, but well... */
57 char *pr
, *p
, *cp
, *ev
;
60 if ((cp
= getenv("prompt")) == NULL
)
65 if ((*p
== '$') && (*(p
+1) == '{')) {
66 for (cp
= p
+ 2; (*cp
!= 0) && (*cp
!= '}'); cp
++)
72 n
= sprintf(prompt
+n
, "%s", ev
);
79 if (prompt
[n
- 1] != ' ')
87 main(int argc
, char **argv
)
94 int cols
= 80, rows
= 24;
96 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1) {
104 asprintf(&buffer
, "%d", cols
);
105 setenv("COLUMNS", buffer
, 1);
107 asprintf(&buffer
, "%d", rows
);
108 setenv("LINES", buffer
, 1);
111 if (getenv("prompt") == NULL
)
112 setenv("prompt", "${interpret}", 1);
113 if (getenv("interpret") == NULL
)
114 setenv("interpret", "ok", 1);
116 if ((vm
= bf_init("", NULL
)) == NULL
)
118 returnValue
= ficlVmEvaluate(vm
, ".ver .( " __DATE__
" ) cr quit");
121 * load files specified on command-line
124 asprintf(&buffer
, ".( loading %s ) cr include %s\n cr",
126 returnValue
= ficlVmEvaluate(vm
, buffer
);
130 if ((gl
= new_GetLine(LINELEN
, HISTORY
)) == NULL
) {
135 while (returnValue
!= FICL_VM_STATUS_USER_EXIT
) {
136 if ((buffer
= gl_get_line(gl
, prompt(), NULL
, -1)) == NULL
)
138 returnValue
= bf_run(buffer
);
141 gl
= del_GetLine(gl
);
143 return (returnValue
);