Debian Codegraph @

tests/c-hello/hello.c

raw symbols SCIP
1 #include "hello.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 Bool hello_print_message(const char *message)
7 {
8 printf("Hello: %s\n", message);
9 return 0;
10 }
11
12 double hello_sum(double x, double y)
13 {
14 return x + y;
15 }
16
17
18 struct _HelloFoo
19 {
20 int refcount;
21 char *data;
22 };
23
24 HelloFoo*
25 hello_foo_new(void)
26 {
27 HelloFoo *foo;
28 foo = (HelloFoo *) malloc(sizeof(HelloFoo));
29 foo->refcount = 1;
30 foo->data = NULL;
31 return foo;
32 }
33
34 HelloFoo*
35 hello_foo_new_from_data(const char *data)
36 {
37 HelloFoo* foo;
38
39 foo = hello_foo_new();
40 hello_foo_set_data(foo, data);
41 return foo;
42 }
43
44 HelloFoo*
45 hello_foo_new_with_spaces (int num_spaces)
46 {
47 int i;
48 HelloFoo *foo;
49 foo = hello_foo_new();
50 foo->data = malloc(num_spaces + 1);
51 for (i = 0; i < num_spaces; i++)
52 foo->data[i] = ' ';
53 foo->data[i] = '\0';
54 return foo;
55 }
56
57 void
58 hello_foo_ref(HelloFoo *foo)
59 {
60 foo->refcount++;
61 }
62
63 void
64 hello_foo_unref(HelloFoo *foo)
65 {
66 if (--foo->refcount > 0)
67 return;
68
69 if (foo->data)
70 free(foo->data);
71 free(foo);
72 }
73
74 void
75 hello_foo_set_data(HelloFoo *foo,
76 const char *data)
77 {
78 if (foo->data)
79 free(foo->data);
80 foo->data = strdup(data);
81 }
82
83 const char *
84 hello_foo_get_data(HelloFoo *foo)
85 {
86 return foo->data;
87 }
88
89 const HelloFoo* hello_foo_get_self (HelloFoo *foo)
90 {
91 return foo;
92 }
93
94 int hello_get_hash (const HelloFoo *foo)
95 {
96 if (foo)
97 {
98 return (int) (long) foo;
99 } else {
100 return -1;
101 }
102 }
103