Integrate flite into aoview directly. Fix great circle computation.
[fw/altos] / aoview / aoview_util.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #include "aoview.h"
19
20 char *
21 aoview_fullname (char *dir, char *file)
22 {
23         char    *new;
24         int     dlen = strlen (dir);
25         int     flen = strlen (file);
26         int     slen = 0;
27
28         if (dir[dlen-1] != '/')
29                 slen = 1;
30         new = malloc (dlen + slen + flen + 1);
31         if (!new)
32                 return 0;
33         strcpy(new, dir);
34         if (slen)
35                 strcat (new, "/");
36         strcat(new, file);
37         return new;
38 }
39
40 char *
41 aoview_basename(char *file)
42 {
43         char *b;
44
45         b = strrchr(file, '/');
46         if (!b)
47                 return file;
48         return b + 1;
49 }
50
51 int
52 aoview_mkdir(char *dir)
53 {
54         char    *slash;
55         char    *d;
56         char    *part;
57
58         d = dir;
59         for (;;) {
60                 slash = strchr (d, '/');
61                 if (!slash)
62                         slash = d + strlen(d);
63                 if (!*slash)
64                         break;
65                 part = strndup(dir, slash - dir);
66                 if (!access(part, F_OK))
67                         if (mkdir(part, 0777) < 0)
68                                 return -errno;
69                 free(part);
70                 d = slash + 1;
71         }
72         return 0;
73 }
74
75 GtkTreeViewColumn *
76 aoview_add_plain_text_column (GtkTreeView *view, const gchar *title, gint model_column, gint width)
77 {
78         GtkCellRenderer *renderer;
79         GtkTreeViewColumn *column;
80
81         renderer = gtk_cell_renderer_text_new ();
82         g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL);
83         g_object_set(renderer, "width-chars", width, NULL);
84         column = gtk_tree_view_column_new_with_attributes (title, renderer,
85                                                            "text", model_column,
86                                                            NULL);
87         gtk_tree_view_column_set_resizable (column, FALSE);
88         gtk_tree_view_append_column (view, column);
89
90         return column;
91 }