File: likes.cpp

package info (click to toggle)
swi-prolog-packages 5.0.1-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 50,688 kB
  • ctags: 25,904
  • sloc: ansic: 195,096; perl: 91,425; cpp: 7,660; sh: 3,046; makefile: 2,750; yacc: 843; awk: 14; sed: 12
file content (72 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*  $Id: likes.cpp,v 1.1 2000/06/09 14:46:39 jan Exp $

    Part of SWI-Prolog
    Designed and implemented by Jan Wielemaker

    Copyright (C) 1999 SWI, University of Amsterdam. All rights reserved.
*/


#include "SWI-cpp.h"
#include <iostream.h>

/* Usage:

   likes			prints who likes what
   likes x			prints what is liked by x
   likes x y			Test whether x likes y
   likes -happy			See who is happy

   Compile using:

   plld -o likes -ld g++ -goal true likes.cpp likes.pl
*/

int
body(int argc, char **argv)
{ if ( argc == 1 )
  { if ( strcmp(argv[0], "-happy") == 0 )
    { PlTermv av(1);			/* likes - happy */

      cout << "Happy people:" << endl;
      PlQuery q("happy", av);
      while( q.next_solution() )
	cout << "\t" << (char *)av[0] << endl;
    } else
    { PlTermv av(2);

      cout << argv[0] << " likes:" << endl;
      av[0] = argv[0];
      PlQuery q("likes", av);
      while( q.next_solution() )
	cout << "\t" << (char *)av[1] << endl;
    }
  } else if ( argc == 2 )
  { PlTermv av(2);

    av[0] = argv[0];
    av[1] = argv[1];
    if ( PlCall("likes", av) )
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  } else
    cout << "Usage: likes x [y] or likes -happy" << endl;

  return 0;
}


int
main(int argc, char **argv)
{ PlEngine e(argv[0]);

  try 
  { return body(argc-1, argv+1);
  } catch ( PlException &ex )
  { cerr << (char *) ex << endl;
    exit(1);
  }
}