Fix #912: "overwrite files"-window outside screen
[geeqie.git] / src / ui_utildlg.c
1 /*
2  * Copyright (C) 2004 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 #endif
25 #include "intl.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <sys/types.h>
31 #include <gtk/gtk.h>
32
33 #include <gdk/gdkkeysyms.h> /* for keyboard values */
34
35 #include "main.h"
36 #include "ui_utildlg.h"
37
38 #include "filedata.h"
39 #include "rcfile.h"
40 #include "ui_fileops.h"
41 #include "ui_misc.h"
42 #include "ui_pathsel.h"
43 #include "ui_tabcomp.h"
44 #include "window.h"
45
46 /*
47  *-----------------------------------------------------------------------------
48  * generic dialog
49  *-----------------------------------------------------------------------------
50  */
51
52 typedef struct _DialogWindow DialogWindow;
53 struct _DialogWindow
54 {
55         gint x;
56         gint y;
57         gint w;
58         gint h;
59         gchar *title;
60         gchar *role;
61 };
62
63 static GList *dialog_windows = NULL;
64
65 static void generic_dialog_save_window(const gchar *title, const gchar *role, gint x, gint y, gint h, gint w)
66 {
67         GList *work;
68
69         work = g_list_first(dialog_windows);
70         while (work)
71                 {
72                 DialogWindow *dw = work->data;
73                 if (g_strcmp0(dw->title ,title) == 0 && g_strcmp0(dw->role, role) == 0)
74                         {
75                         dw->x = x;
76                         dw->y = y;
77                         dw->w = w;
78                         dw->h = h;
79                         return;
80                         }
81                 work = work->next;
82                 }
83
84         DialogWindow *dw = g_new0(DialogWindow, 1);
85         dw->title = g_strdup(title);
86         dw->role = g_strdup(role);
87         dw->x = x;
88         dw->y = y;
89         dw->w = w;
90         dw->h = h;
91
92         dialog_windows = g_list_append(dialog_windows, dw);
93 }
94
95 static gboolean generic_dialog_find_window(const gchar *title, const gchar *role, gint *x, gint *y, gint *h, gint *w)
96 {
97         GList *work;
98
99         work = g_list_first(dialog_windows);
100         while (work)
101                 {
102                 DialogWindow *dw = work->data;
103
104                 if (g_strcmp0(dw->title,title) == 0 && g_strcmp0(dw->role, role) == 0)
105                         {
106                         *x = dw->x;
107                         *y = dw->y;
108                         *w = dw->w;
109                         *h = dw->h;
110                         return TRUE;
111                         }
112                 work = work->next;
113                 }
114         return FALSE;
115 }
116
117 void generic_dialog_close(GenericDialog *gd)
118 {
119         gchar *ident_string;
120         gchar *full_title;
121         gchar *actual_title;
122         gint x, y, h, w;
123
124         gdk_window_get_root_origin(gtk_widget_get_window (gd->dialog), &x, &y);
125         w = gdk_window_get_width(gtk_widget_get_window (gd->dialog));
126         h = gdk_window_get_height(gtk_widget_get_window (gd->dialog));
127
128         /* The window title is modified in window.c: window_new()
129          * by appending the string " - Geeqie"
130          */
131         ident_string = g_strconcat(" - ", GQ_APPNAME, NULL);
132         full_title = g_strdup(gtk_window_get_title(GTK_WINDOW(gd->dialog)));
133         actual_title = strndup(full_title, g_strrstr(full_title, ident_string) - full_title);
134
135         generic_dialog_save_window(actual_title, gtk_window_get_role(GTK_WINDOW(gd->dialog)), x, y, w, h);
136
137         gtk_widget_destroy(gd->dialog);
138         g_free(gd);
139         g_free(ident_string);
140         g_free(full_title);
141         g_free(actual_title);
142 }
143
144 static void generic_dialog_click_cb(GtkWidget *widget, gpointer data)
145 {
146         GenericDialog *gd = data;
147         void (*func)(GenericDialog *, gpointer);
148         gboolean auto_close;
149
150         func = g_object_get_data(G_OBJECT(widget), "dialog_function");
151         auto_close = gd->auto_close;
152
153         if (func) func(gd, gd->data);
154         if (auto_close) generic_dialog_close(gd);
155 }
156
157 static gboolean generic_dialog_default_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
158 {
159         GenericDialog *gd = data;
160
161         if (event->keyval == GDK_KEY_Return && gtk_widget_has_focus(widget)
162             && gd->default_cb)
163                 {
164                 gboolean auto_close;
165
166                 auto_close = gd->auto_close;
167                 gd->default_cb(gd, gd->data);
168                 if (auto_close) generic_dialog_close(gd);
169
170                 return TRUE;
171                 }
172         return FALSE;
173 }
174
175 void generic_dialog_attach_default(GenericDialog *gd, GtkWidget *widget)
176 {
177         if (!gd || !widget) return;
178         g_signal_connect(G_OBJECT(widget), "key_press_event",
179                          G_CALLBACK(generic_dialog_default_key_press_cb), gd);
180 }
181
182 static gboolean generic_dialog_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
183 {
184         GenericDialog *gd = data;
185         gboolean auto_close = gd->auto_close;
186
187         if (event->keyval == GDK_KEY_Escape)
188                 {
189                 if (gd->cancel_cb)
190                         {
191                         gd->cancel_cb(gd, gd->data);
192                         if (auto_close) generic_dialog_close(gd);
193                         }
194                 else
195                         {
196                         if (auto_close) generic_dialog_click_cb(widget, data);
197                         }
198                 return TRUE;
199                 }
200         return FALSE;
201 }
202
203 static gboolean generic_dialog_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data)
204 {
205         GenericDialog *gd = data;
206         gboolean auto_close;
207
208         auto_close = gd->auto_close;
209
210         if (gd->cancel_cb) gd->cancel_cb(gd, gd->data);
211         if (auto_close) generic_dialog_close(gd);
212
213         return TRUE;
214 }
215
216 static void generic_dialog_show_cb(GtkWidget *widget, gpointer data)
217 {
218         GenericDialog *gd = data;
219         if (gd->cancel_button)
220                 {
221                 gtk_box_reorder_child(GTK_BOX(gd->hbox), gd->cancel_button, -1);
222                 }
223
224         g_signal_handlers_disconnect_by_func(G_OBJECT(widget),
225                                              G_CALLBACK(generic_dialog_show_cb), gd);
226 }
227
228 gboolean generic_dialog_get_alternative_button_order(GtkWidget *widget)
229 {
230         GtkSettings *settings;
231         GObjectClass *klass;
232         gboolean alternative_order = FALSE;
233
234         settings = gtk_settings_get_for_screen(gtk_widget_get_screen(widget));
235         klass = G_OBJECT_CLASS(GTK_SETTINGS_GET_CLASS(settings));
236         if (g_object_class_find_property(klass, "gtk-alternative-button-order"))
237                 {
238                 g_object_get(settings, "gtk-alternative-button-order", &alternative_order, NULL);
239                 }
240
241         return alternative_order;
242 }
243
244 GtkWidget *generic_dialog_add_button(GenericDialog *gd, const gchar *stock_id, const gchar *text,
245                                      void (*func_cb)(GenericDialog *, gpointer), gboolean is_default)
246 {
247         GtkWidget *button;
248         gboolean alternative_order;
249
250         button = pref_button_new(NULL, stock_id, text, FALSE,
251                                  G_CALLBACK(generic_dialog_click_cb), gd);
252
253         gtk_widget_set_can_default(button, TRUE);
254         g_object_set_data(G_OBJECT(button), "dialog_function", func_cb);
255
256         gtk_container_add(GTK_CONTAINER(gd->hbox), button);
257
258         alternative_order = generic_dialog_get_alternative_button_order(gd->hbox);
259
260         if (is_default)
261                 {
262                 gtk_widget_grab_default(button);
263                 gtk_widget_grab_focus(button);
264                 gd->default_cb = func_cb;
265
266                 if (!alternative_order) gtk_box_reorder_child(GTK_BOX(gd->hbox), button, -1);
267                 }
268         else
269                 {
270                 if (!alternative_order) gtk_box_reorder_child(GTK_BOX(gd->hbox), button, 0);
271                 }
272
273         gtk_widget_show(button);
274
275         return button;
276 }
277
278 /**
279  * @brief 
280  * @param gd 
281  * @param icon_stock_id 
282  * @param heading 
283  * @param text 
284  * @param expand Used as the "expand" and "fill" parameters in the eventual call to gtk_box_pack_start() 
285  * @returns 
286  * 
287  * 
288  */
289 GtkWidget *generic_dialog_add_message(GenericDialog *gd, const gchar *icon_stock_id,
290                                       const gchar *heading, const gchar *text, gboolean expand)
291 {
292         GtkWidget *hbox;
293         GtkWidget *vbox;
294         GtkWidget *label;
295
296         hbox = pref_box_new(gd->vbox, expand, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
297         if (icon_stock_id)
298                 {
299                 GtkWidget *image;
300
301                 image = gtk_image_new_from_stock(icon_stock_id, GTK_ICON_SIZE_DIALOG);
302 #if GTK_CHECK_VERSION(3,16,0)
303                 gtk_widget_set_halign(GTK_WIDGET(image), GTK_ALIGN_CENTER);
304                 gtk_widget_set_valign(GTK_WIDGET(image), GTK_ALIGN_START);
305 #else
306                 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0);
307 #endif
308                 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
309                 gtk_widget_show(image);
310                 }
311
312         vbox = pref_box_new(hbox, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE);
313         if (heading)
314                 {
315                 label = pref_label_new(vbox, heading);
316                 pref_label_bold(label, TRUE, TRUE);
317 #if GTK_CHECK_VERSION(3,16,0)
318                 gtk_label_set_xalign(GTK_LABEL(label), 0.0);
319                 gtk_label_set_yalign(GTK_LABEL(label), 0.5);
320 #else
321                 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
322 #endif
323                 }
324         if (text)
325                 {
326                 label = pref_label_new(vbox, text);
327 #if GTK_CHECK_VERSION(3,16,0)
328                 gtk_label_set_xalign(GTK_LABEL(label), 0.0);
329                 gtk_label_set_yalign(GTK_LABEL(label), 0.5);
330 #else
331                 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
332 #endif
333                 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
334                 }
335
336         return vbox;
337 }
338
339 void generic_dialog_windows_load_config(const gchar **attribute_names, const gchar **attribute_values)
340 {
341         DialogWindow *dw =  g_new0(DialogWindow, 1);
342         gchar *title = NULL;
343         gchar *role = NULL;
344         gint x = 0;
345         gint y = 0;
346         gint w = 0;
347         gint h = 0;
348
349         while (*attribute_names)
350                 {
351                 const gchar *option = *attribute_names++;
352                 const gchar *value = *attribute_values++;
353                 if (READ_CHAR_FULL("title", title)) continue;
354                 if (READ_CHAR_FULL("role", role)) continue;
355                 if (READ_INT_FULL("x", x)) continue;
356                 if (READ_INT_FULL("y", y)) continue;
357                 if (READ_INT_FULL("w", w)) continue;
358                 if (READ_INT_FULL("h", h)) continue;
359
360                 log_printf("unknown attribute %s = %s\n", option, value);
361                 }
362
363         if (title && title[0] != 0)
364                 {
365                 dw->title = g_strdup(title);
366                 dw->role = g_strdup(role);
367                 dw->x = x;
368                 dw->y = y;
369                 dw->w = w;
370                 dw->h = h;
371
372                 dialog_windows = g_list_append(dialog_windows, dw);
373                 }
374 }
375
376 void generic_dialog_windows_write_config(GString *outstr, gint indent)
377 {
378         GList *work;
379
380         if (options->save_dialog_window_positions && dialog_windows)
381                 {
382                 WRITE_NL(); WRITE_STRING("<%s>", "dialogs");
383                 indent++;
384
385                 work = g_list_first(dialog_windows);
386                 while (work)
387                         {
388                         DialogWindow *dw = work->data;
389                         WRITE_NL(); WRITE_STRING("<window ");
390                         write_char_option(outstr, indent + 1, "title", dw->title);
391                         write_char_option(outstr, indent + 1, "role", dw->role);
392                         WRITE_INT(*dw, x);
393                         WRITE_INT(*dw, y);
394                         WRITE_INT(*dw, w);
395                         WRITE_INT(*dw, h);
396                         WRITE_STRING("/>");
397                         work = work->next;
398                         }
399                 indent--;
400                 WRITE_NL(); WRITE_STRING("</%s>", "dialogs");
401
402                 dialog_windows = NULL;
403                 }
404 }
405
406 static void generic_dialog_setup(GenericDialog *gd,
407                                  const gchar *title,
408                                  const gchar *role,
409                                  GtkWidget *parent, gboolean auto_close,
410                                  void (*cancel_cb)(GenericDialog *, gpointer), gpointer data)
411 {
412         GtkWidget *vbox;
413         gint x, y, w, h;
414         GtkWidget *scrolled;
415
416         gd->auto_close = auto_close;
417         gd->data = data;
418         gd->cancel_cb = cancel_cb;
419
420         gd->dialog = window_new(GTK_WINDOW_TOPLEVEL, role, NULL, NULL, title);
421         DEBUG_NAME(gd->dialog);
422         gtk_window_set_type_hint(GTK_WINDOW(gd->dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
423
424         if (options->save_dialog_window_positions)
425                 {
426                 if (generic_dialog_find_window(title, role, &x, &y, &w, &h))
427                         {
428                         gtk_window_set_default_size(GTK_WINDOW(gd->dialog), w, h);
429                         gtk_window_move(GTK_WINDOW(gd->dialog), x, y);
430                         }
431                 }
432
433         if (parent)
434                 {
435                 GtkWindow *window = NULL;
436
437                 if (GTK_IS_WINDOW(parent))
438                         {
439                         window = GTK_WINDOW(parent);
440                         }
441                 else
442                         {
443                         GtkWidget *top;
444
445                         top = gtk_widget_get_toplevel(parent);
446                         if (GTK_IS_WINDOW(top) && gtk_widget_is_toplevel(top)) window = GTK_WINDOW(top);
447                         }
448
449                 if (window) gtk_window_set_transient_for(GTK_WINDOW(gd->dialog), window);
450                 }
451
452         g_signal_connect(G_OBJECT(gd->dialog), "delete_event",
453                          G_CALLBACK(generic_dialog_delete_cb), gd);
454         g_signal_connect(G_OBJECT(gd->dialog), "key_press_event",
455                          G_CALLBACK(generic_dialog_key_press_cb), gd);
456
457         gtk_window_set_resizable(GTK_WINDOW(gd->dialog), TRUE);
458         gtk_container_set_border_width(GTK_CONTAINER(gd->dialog), PREF_PAD_BORDER);
459
460         scrolled = gtk_scrolled_window_new(NULL, NULL);
461         gtk_scrolled_window_set_propagate_natural_height(GTK_SCROLLED_WINDOW(scrolled), TRUE);
462         gtk_scrolled_window_set_propagate_natural_width(GTK_SCROLLED_WINDOW(scrolled), TRUE);
463         vbox = gtk_vbox_new(FALSE, PREF_PAD_BUTTON_SPACE);
464         gtk_container_add(GTK_CONTAINER(scrolled), vbox);
465         gtk_container_add(GTK_CONTAINER(gd->dialog), scrolled);
466         gtk_widget_show(scrolled);
467         gtk_widget_show(vbox);
468
469         gd->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP);
470         gtk_box_pack_start(GTK_BOX(vbox), gd->vbox, TRUE, TRUE, 0);
471         gtk_widget_show(gd->vbox);
472
473         gd->hbox = gtk_hbutton_box_new();
474         gtk_button_box_set_layout(GTK_BUTTON_BOX(gd->hbox), GTK_BUTTONBOX_END);
475         gtk_box_set_spacing(GTK_BOX(gd->hbox), PREF_PAD_BUTTON_GAP);
476         gtk_box_pack_start(GTK_BOX(vbox), gd->hbox, FALSE, FALSE, 0);
477         gtk_widget_show(gd->hbox);
478
479         if (gd->cancel_cb)
480                 {
481                 gd->cancel_button = generic_dialog_add_button(gd, GTK_STOCK_CANCEL, NULL, gd->cancel_cb, TRUE);
482                 }
483         else
484                 {
485                 gd->cancel_button = NULL;
486                 }
487
488         if (generic_dialog_get_alternative_button_order(gd->hbox))
489                 {
490                 g_signal_connect(G_OBJECT(gd->dialog), "show",
491                                  G_CALLBACK(generic_dialog_show_cb), gd);
492                 }
493
494         gd->default_cb = NULL;
495 }
496
497 GenericDialog *generic_dialog_new(const gchar *title,
498                                   const gchar *role,
499                                   GtkWidget *parent, gboolean auto_close,
500                                   void (*cancel_cb)(GenericDialog *, gpointer), gpointer data)
501 {
502         GenericDialog *gd;
503
504         gd = g_new0(GenericDialog, 1);
505         generic_dialog_setup(gd, title, role,
506                              parent, auto_close, cancel_cb, data);
507         return gd;
508 }
509 /*
510  *-----------------------------------------------------------------------------
511  * simple warning dialog
512  *-----------------------------------------------------------------------------
513  */
514
515 static void warning_dialog_ok_cb(GenericDialog *gd, gpointer data)
516 {
517         /* no op */
518 }
519
520 GenericDialog *warning_dialog(const gchar *heading, const gchar *text,
521                               const gchar *icon_stock_id, GtkWidget *parent)
522 {
523         GenericDialog *gd;
524
525         gd = generic_dialog_new(heading, "warning", parent, TRUE, NULL, NULL);
526         generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, warning_dialog_ok_cb, TRUE);
527
528         generic_dialog_add_message(gd, icon_stock_id, heading, text, TRUE);
529
530         gtk_widget_show(gd->dialog);
531
532         return gd;
533 }
534
535 /*
536  *-----------------------------------------------------------------------------
537  * generic file ops dialog routines
538  *-----------------------------------------------------------------------------
539  */
540
541 void file_dialog_close(FileDialog *fdlg)
542 {
543         file_data_unref(fdlg->source_fd);
544         g_free(fdlg->dest_path);
545         if (fdlg->source_list) filelist_free(fdlg->source_list);
546
547         generic_dialog_close(GENERIC_DIALOG(fdlg));
548 }
549
550 FileDialog *file_dialog_new(const gchar *title,
551                             const gchar *role,
552                             GtkWidget *parent,
553                             void (*cancel_cb)(FileDialog *, gpointer), gpointer data)
554 {
555         FileDialog *fdlg = NULL;
556
557         fdlg = g_new0(FileDialog, 1);
558
559         generic_dialog_setup(GENERIC_DIALOG(fdlg), title,
560                              role, parent, FALSE,
561                              (gpointer)cancel_cb, data);
562
563         return fdlg;
564 }
565
566 GtkWidget *file_dialog_add_button(FileDialog *fdlg, const gchar *stock_id, const gchar *text,
567                                   void (*func_cb)(FileDialog *, gpointer), gboolean is_default)
568 {
569         return generic_dialog_add_button(GENERIC_DIALOG(fdlg), stock_id, text,
570                                          (gpointer)func_cb, is_default);
571 }
572
573 static void file_dialog_entry_cb(GtkWidget *widget, gpointer data)
574 {
575         FileDialog *fdlg = data;
576         g_free(fdlg->dest_path);
577         fdlg->dest_path = remove_trailing_slash(gtk_entry_get_text(GTK_ENTRY(fdlg->entry)));
578 }
579
580 static void file_dialog_entry_enter_cb(const gchar *path, gpointer data)
581 {
582         GenericDialog *gd = data;
583
584         file_dialog_entry_cb(NULL, data);
585
586         if (gd->default_cb) gd->default_cb(gd, gd->data);
587 }
588
589 void file_dialog_add_path_widgets(FileDialog *fdlg, const gchar *default_path, const gchar *path,
590                                   const gchar *history_key, const gchar *filter, const gchar *filter_desc)
591 {
592         GtkWidget *tabcomp;
593         GtkWidget *list;
594
595         if (fdlg->entry) return;
596
597         tabcomp = tab_completion_new_with_history(&fdlg->entry, NULL,
598                   history_key, -1, file_dialog_entry_enter_cb, fdlg);
599         gtk_box_pack_end(GTK_BOX(GENERIC_DIALOG(fdlg)->vbox), tabcomp, FALSE, FALSE, 0);
600         generic_dialog_attach_default(GENERIC_DIALOG(fdlg), fdlg->entry);
601         gtk_widget_show(tabcomp);
602
603         if (path && path[0] == G_DIR_SEPARATOR)
604                 {
605                 fdlg->dest_path = g_strdup(path);
606                 }
607         else
608                 {
609                 const gchar *base;
610
611                 base = tab_completion_set_to_last_history(fdlg->entry);
612
613                 if (!base) base = default_path;
614                 if (!base) base = homedir();
615
616                 if (path)
617                         {
618                         fdlg->dest_path = g_build_filename(base, path, NULL);
619                         }
620                 else
621                         {
622                         fdlg->dest_path = g_strdup(base);
623                         }
624                 }
625
626         list = path_selection_new_with_files(fdlg->entry, fdlg->dest_path, filter, filter_desc);
627         path_selection_add_select_func(fdlg->entry, file_dialog_entry_enter_cb, fdlg);
628         gtk_box_pack_end(GTK_BOX(GENERIC_DIALOG(fdlg)->vbox), list, TRUE, TRUE, 0);
629         gtk_widget_show(list);
630
631         gtk_widget_grab_focus(fdlg->entry);
632         if (fdlg->dest_path)
633                 {
634                 gtk_entry_set_text(GTK_ENTRY(fdlg->entry), fdlg->dest_path);
635                 gtk_editable_set_position(GTK_EDITABLE(fdlg->entry), strlen(fdlg->dest_path));
636                 }
637
638         g_signal_connect(G_OBJECT(fdlg->entry), "changed",
639                          G_CALLBACK(file_dialog_entry_cb), fdlg);
640 }
641
642 void file_dialog_add_filter(FileDialog *fdlg, const gchar *filter, const gchar *filter_desc, gboolean set)
643 {
644         if (!fdlg->entry) return;
645         path_selection_add_filter(fdlg->entry, filter, filter_desc, set);
646 }
647
648 void file_dialog_clear_filter(FileDialog *fdlg)
649 {
650         if (!fdlg->entry) return;
651         path_selection_clear_filter(fdlg->entry);
652 }
653
654 void file_dialog_sync_history(FileDialog *fdlg, gboolean dir_only)
655 {
656         if (!fdlg->dest_path) return;
657
658         if (!dir_only ||
659             (dir_only && isdir(fdlg->dest_path)) )
660                 {
661                 tab_completion_append_to_history(fdlg->entry, fdlg->dest_path);
662                 }
663         else
664                 {
665                 gchar *buf = remove_level_from_path(fdlg->dest_path);
666                 tab_completion_append_to_history(fdlg->entry, buf);
667                 g_free(buf);
668                 }
669 }
670 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */