1/* BEGIN LICENSE BLOCK
2 * Version: CMPL 1.1
3 *
4 * The contents of this file are subject to the Cisco-style Mozilla Public
5 * License Version 1.1 (the "License"); you may not use this file except
6 * in compliance with the License.  You may obtain a copy of the License
7 * at www.eclipse-clp.org/license.
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11 * the License for the specific language governing rights and limitations
12 * under the License.
13 *
14 * The Original Code is  The ECLiPSe Constraint Logic Programming System.
15 * The Initial Developer of the Original Code is  Cisco Systems, Inc.
16 * Portions created by the Initial Developer are
17 * Copyright (C) 1997-2006 Cisco Systems, Inc.  All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * END LICENSE BLOCK */
22
23/*
24 * ECLiPSe LIBRARY MODULE
25 *
26 * $Id: eg_c_main.c,v 1.1 2008/06/30 17:43:53 jschimpf Exp $
27 *
28 *
29 * IDENTIFICATION:	minimain.c
30 *
31 * AUTHOR:		Joachim Schimpf
32 * AUTHOR:		Stefano Novello
33 *
34 * CONTENTS:		name/arity
35 *
36 * DESCRIPTION:
37 *	Example of minimal main useing external embed interface.
38 */
39
40#include	"eclipse.h"
41
42
43main(int argc, char **argv)
44{
45    char 	*s;
46    dident	writeln,read,garbage_collect;
47    ec_ref Vars,X;
48    pword ans;
49
50    ec_init();
51
52    Vars = ec_ref_create(ec_nil());
53    ec_exec_string("writeln(\"hello world: \"),read(X)",Vars);
54    if (PSUCCEED == ec_var_lookup(Vars,"X",&ans) &&
55    	PSUCCEED == ec_get_string(ans,&s))
56	printf("Answer was %s\n",s);
57
58    ec_ref_destroy(Vars);
59
60    writeln = ec_did("writeln",1);
61    read = ec_did("read",1);
62    garbage_collect = ec_did("garbage_collect",0);
63
64    X = ec_ref_create_newvar();
65
66    /* writeln("hello again: ") */
67    ec_post_goal(ec_term(writeln, ec_string("hello again: ")));
68    /* read(X) */
69    ec_post_goal(ec_term(read, ec_ref_get(X)));
70    /* garbage_collect */
71    ec_post_goal(ec_atom(garbage_collect));
72
73    ec_resume1(0); /* pwords not in ec_ref are lost here */
74
75    /* writeln(X) */
76    ec_post_goal(ec_term(writeln, ec_ref_get(X)));
77    ec_resume1(0);
78
79    ec_ref_destroy(X);
80
81    ec_cleanup();
82    exit(0);
83}
84
85