2 * Copyright (C) 2006 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
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.
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.
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.
22 #include "ui-fileops.h"
36 #include "main-defines.h"
38 #include "filefilter.h"
42 #include "secure-save.h"
45 *-----------------------------------------------------------------------------
46 * generic file information and manipulation routines (public)
47 *-----------------------------------------------------------------------------
52 void print_term(gboolean err, const gchar *text_utf8)
56 text_l = g_locale_from_utf8(text_utf8, -1, nullptr, nullptr, nullptr);
59 fputs((text_l) ? text_l : text_utf8, stderr);
63 fputs((text_l) ? text_l : text_utf8, stdout);
65 if(command_line && command_line->ssi)
66 secure_fputs(command_line->ssi, (text_l) ? text_l : text_utf8);
70 static void encoding_dialog(const gchar *path)
72 static gboolean warned_user = FALSE;
78 if (warned_user) return;
82 bf = getenv("G_BROKEN_FILENAMES");
84 string = g_string_new(_("One or more filenames are not encoded with the preferred locale character set.\n"));
85 g_string_append_printf(string, _("Operations on, and display of these files with %s may not succeed.\n"), PACKAGE);
86 g_string_append(string, "\n");
87 g_string_append(string, _("If your filenames are not encoded in utf-8, try setting the environment variable G_BROKEN_FILENAMES=1\n"));
89 g_string_append_printf(string, _("It appears G_BROKEN_FILENAMES is set to %s\n"), bf);
91 g_string_append(string, _("It appears G_BROKEN_FILENAMES is not set\n"));
92 g_string_append(string, "\n");
93 g_string_append_printf(string, _("The locale appears to be set to \"%s\"\n(set by the LANG environment variable)\n"), (lc) ? lc : "undefined");
94 if (lc && (strstr(lc, "UTF-8") || strstr(lc, "utf-8")))
97 name = g_convert(path, -1, "UTF-8", "ISO-8859-1", nullptr, nullptr, nullptr);
98 string = g_string_append(string, _("\nPreferred encoding appears to be UTF-8, however the file:\n"));
99 g_string_append_printf(string, "\"%s\"\n", (name) ? name : _("[name not displayable]"));
101 if (g_utf8_validate(path, -1, nullptr))
102 g_string_append_printf(string, _("\"%s\" is encoded in valid UTF-8."), (name) ? name : _("[name not displayable]"));
104 g_string_append_printf(string, _("\"%s\" is not encoded in valid UTF-8."), (name) ? name : _("[name not displayable]"));
105 g_string_append(string, "\n");
109 gd = generic_dialog_new(_("Filename encoding locale mismatch"),
110 "locale warning", nullptr, TRUE, nullptr, nullptr);
111 generic_dialog_add_button(gd, GQ_ICON_CLOSE, _("Close"), nullptr, TRUE);
113 generic_dialog_add_message(gd, GQ_ICON_DIALOG_WARNING,
114 _("Filename encoding locale mismatch"), string->str, TRUE);
116 gtk_widget_show(gd->dialog);
118 g_string_free(string, TRUE);
121 #if GQ_DEBUG_PATH_UTF8
122 gchar *path_to_utf8_debug(const gchar *path, const gchar *file, gint line)
124 gchar *path_to_utf8(const gchar *path)
128 GError *error = nullptr;
130 if (!path) return nullptr;
132 utf8 = g_filename_to_utf8(path, -1, nullptr, nullptr, &error);
135 #if GQ_DEBUG_PATH_UTF8
136 log_printf("%s:%d: Unable to convert filename to UTF-8:\n%s\n%s\n", file, line, path, error->message);
138 log_printf("Unable to convert filename to UTF-8:\n%s\n%s\n", path, error->message);
141 encoding_dialog(path);
145 /* just let it through, but bad things may happen */
146 utf8 = g_strdup(path);
152 #if GQ_DEBUG_PATH_UTF8
153 gchar *path_from_utf8_debug(const gchar *utf8, const gchar *file, gint line)
155 gchar *path_from_utf8(const gchar *utf8)
159 GError *error = nullptr;
161 if (!utf8) return nullptr;
163 path = g_filename_from_utf8(utf8, -1, nullptr, nullptr, &error);
166 #if GQ_DEBUG_PATH_UTF8
167 log_printf("%s:%d: Unable to convert filename to locale from UTF-8:\n%s\n%s\n", file, line, utf8, error->message);
169 log_printf("Unable to convert filename to locale from UTF-8:\n%s\n%s\n", utf8, error->message);
175 /* if invalid UTF-8, text probably still in original form, so just copy it */
176 path = g_strdup(utf8);
182 /* first we try the HOME environment var, if that doesn't work, we try g_get_homedir(). */
183 const gchar *homedir()
185 static gchar *home = nullptr;
188 home = path_to_utf8(getenv("HOME"));
191 home = path_to_utf8(g_get_home_dir());
193 DEBUG_1("Home directory: %s", home);
198 static gchar *xdg_dir_get(const gchar *key, const gchar *fallback)
200 gchar *dir = getenv(key);
202 if (!dir || dir[0] == '\0')
204 return g_build_filename(homedir(), fallback, NULL);
207 DEBUG_1("Got xdg %s: %s", key, dir);
209 return path_to_utf8(dir);
212 const gchar *xdg_data_home_get()
214 static const gchar *xdg_data_home = nullptr;
216 if (xdg_data_home) return xdg_data_home;
218 xdg_data_home = xdg_dir_get("XDG_DATA_HOME", ".local/share");
220 return xdg_data_home;
223 const gchar *xdg_config_home_get()
225 static const gchar *xdg_config_home = nullptr;
227 if (xdg_config_home) return xdg_config_home;
229 xdg_config_home = xdg_dir_get("XDG_CONFIG_HOME", ".config");
231 return xdg_config_home;
234 const gchar *xdg_cache_home_get()
236 static const gchar *xdg_cache_home = nullptr;
238 if (xdg_cache_home) return xdg_cache_home;
240 xdg_cache_home = xdg_dir_get("XDG_CACHE_HOME", ".cache");
242 return xdg_cache_home;
245 const gchar *get_rc_dir()
247 static gchar *rc_dir = nullptr;
249 if (rc_dir) return rc_dir;
253 rc_dir = g_build_filename(xdg_config_home_get(), GQ_APPNAME_LC, NULL);
257 rc_dir = g_build_filename(homedir(), GQ_RC_DIR, NULL);
263 const gchar *get_collections_dir()
265 static gchar *collections_dir = nullptr;
267 if (collections_dir) return collections_dir;
271 collections_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_COLLECTIONS_DIR, NULL);
275 collections_dir = g_build_filename(get_rc_dir(), GQ_COLLECTIONS_DIR, NULL);
278 return collections_dir;
281 const gchar *get_trash_dir()
283 static gchar *trash_dir = nullptr;
285 if (trash_dir) return trash_dir;
289 trash_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_TRASH_DIR, NULL);
293 trash_dir = g_build_filename(get_rc_dir(), GQ_TRASH_DIR, NULL);
299 const gchar *get_window_layouts_dir()
301 static gchar *window_layouts_dir = nullptr;
303 if (window_layouts_dir) return window_layouts_dir;
307 window_layouts_dir = g_build_filename(xdg_config_home_get(), GQ_APPNAME_LC, GQ_WINDOW_LAYOUTS_DIR, NULL);
311 window_layouts_dir = g_build_filename(get_rc_dir(), GQ_WINDOW_LAYOUTS_DIR, NULL);
314 return window_layouts_dir;
317 gboolean stat_utf8(const gchar *s, struct stat *st)
322 if (!s) return FALSE;
323 sl = path_from_utf8(s);
324 ret = (stat(sl, st) == 0);
330 gboolean lstat_utf8(const gchar *s, struct stat *st)
335 if (!s) return FALSE;
336 sl = path_from_utf8(s);
337 ret = (lstat(sl, st) == 0);
343 gboolean isname(const gchar *s)
347 return stat_utf8(s, &st);
350 gboolean isfile(const gchar *s)
354 return (stat_utf8(s, &st) && S_ISREG(st.st_mode));
357 gboolean isdir(const gchar *s)
361 return (stat_utf8(s, &st) && S_ISDIR(st.st_mode));
364 gboolean islink(const gchar *s)
368 return (lstat_utf8(s, &st) && S_ISLNK(st.st_mode));
371 gint64 filesize(const gchar *s)
375 if (!stat_utf8(s, &st)) return 0;
379 time_t filetime(const gchar *s)
383 if (!stat_utf8(s, &st)) return 0;
387 gboolean filetime_set(const gchar *s, time_t tval)
389 gboolean ret = FALSE;
396 ut.actime = ut.modtime = tval;
398 sl = path_from_utf8(s);
399 ret = (utime(sl, &ut) == 0);
406 gboolean is_readable_file(const gchar *s)
408 if (!s || !s[0] || !isfile(s)) return FALSE;
409 return access_file(s, R_OK);
412 gboolean access_file(const gchar *s, gint mode)
417 if (!s || !s[0]) return FALSE;
419 sl = path_from_utf8(s);
420 ret = (access(sl, mode) == 0);
426 gboolean unlink_file(const gchar *s)
431 if (!s) return FALSE;
433 sl = path_from_utf8(s);
434 ret = (unlink(sl) == 0);
440 #pragma GCC diagnostic push
441 #pragma GCC diagnostic ignored "-Wunused-function"
442 gboolean symlink_utf8_unused(const gchar *source, const gchar *target)
448 if (!source || !target) return FALSE;
450 sl = path_from_utf8(source);
451 tl = path_from_utf8(target);
453 ret = (symlink(sl, tl) == 0);
460 #pragma GCC diagnostic pop
462 gboolean mkdir_utf8(const gchar *s, gint mode)
467 if (!s) return FALSE;
469 sl = path_from_utf8(s);
470 ret = (mkdir(sl, mode) == 0);
475 gboolean rmdir_utf8(const gchar *s)
480 if (!s) return FALSE;
482 sl = path_from_utf8(s);
483 ret = (rmdir(sl) == 0);
489 gboolean copy_file_attributes(const gchar *s, const gchar *t, gint perms, gint mtime)
494 gboolean ret = FALSE;
496 if (!s || !t) return FALSE;
498 sl = path_from_utf8(s);
499 tl = path_from_utf8(t);
501 if (stat(sl, &st) == 0)
507 /* set the dest file attributes to that of source (ignoring errors) */
511 ret = chown(tl, st.st_uid, st.st_gid);
512 /* Ignores chown errors, while still doing chown
513 (so root still can copy files preserving ownership) */
515 if (chmod(tl, st.st_mode) < 0) {
517 if (stat(tl, &st2) != 0 || st2.st_mode != st.st_mode) {
523 tb.actime = st.st_atime;
524 tb.modtime = st.st_mtime;
525 if (mtime && utime(tl, &tb) < 0) ret = FALSE;
534 /* paths are in filesystem encoding */
535 static gboolean hard_linked(const gchar *a, const gchar *b)
540 if (stat(a, &sta) != 0 || stat(b, &stb) != 0) return FALSE;
542 return (sta.st_dev == stb.st_dev &&
543 sta.st_ino == stb.st_ino);
546 static void fclose_safe(FILE *fp)
551 gboolean copy_file(const gchar *s, const gchar *t)
557 std::unique_ptr<gchar, decltype(&g_free)> sl{path_from_utf8(s), g_free};
558 std::unique_ptr<gchar, decltype(&g_free)> tl{path_from_utf8(t), g_free};
560 if (hard_linked(sl.get(), tl.get()))
565 /* Do not dereference absolute symlinks, but copy them "as is".
566 * For a relative symlink, we don't know how to properly change it when
567 * copied/moved to another dir to keep pointing it to same target as
568 * a relative symlink, so we turn it into absolute symlink using
569 * realpath() instead. */
570 auto copy_symlink = [](const gchar *sl, const gchar *tl) -> gboolean
573 if (!lstat_utf8(sl, &st) && S_ISLNK(st.st_mode))
581 link_target = static_cast<gchar *>(g_malloc(st.st_size + 1));
582 i = readlink(sl, link_target, st.st_size);
586 return FALSE; // try a "normal" copy
588 link_target[st.st_size] = '\0';
590 if (link_target[0] != G_DIR_SEPARATOR) // if it is a relative symlink
594 const gchar *lastslash = strrchr(sl, G_DIR_SEPARATOR);
595 gint len = lastslash - sl + 1;
597 absolute = static_cast<gchar *>(g_malloc(len + st.st_size + 1));
598 strncpy(absolute, sl, len);
599 strcpy(absolute + len, link_target);
601 link_target = absolute;
604 realPath = realpath(link_target, nullptr);
606 if (realPath != nullptr) // successfully resolved into an absolute path
609 link_target = g_strdup(realPath);
612 else // could not get absolute path, got some error instead
615 return FALSE; // so try a "normal" copy
619 if (stat_utf8(tl, &st)) unlink(tl); // first try to remove directory entry in destination directory if such entry exists
621 gint success = (symlink(link_target, tl) == 0);
627 if (copy_symlink(sl.get(), tl.get()))
632 // if symlink did not succeed, continue on to try a copy procedure
633 std::unique_ptr<FILE, decltype(&fclose_safe)> fi{fopen(sl.get(), "rb"), fclose_safe};
639 /* First we write to a temporary file, then we rename it on success,
640 and attributes from original file are copied */
641 std::unique_ptr<gchar, decltype(&g_free)> randname{g_strconcat(tl.get(), ".tmp_XXXXXX", NULL), g_free};
647 fd = g_mkstemp(randname.get());
653 std::unique_ptr<FILE, decltype(&fclose_safe)> fo{fdopen(fd, "wb"), fclose_safe};
659 while ((b = fread(buf, sizeof(gchar), sizeof(buf), fi.get())) && b != 0)
661 if (fwrite(buf, sizeof(gchar), b, fo.get()) != b)
663 unlink(randname.get());
668 if (rename(randname.get(), tl.get()) < 0) {
669 unlink(randname.get());
673 return copy_file_attributes(s, t, TRUE, TRUE);
676 gboolean move_file(const gchar *s, const gchar *t)
682 if (!s || !t) return FALSE;
684 sl = path_from_utf8(s);
685 tl = path_from_utf8(t);
686 if (rename(sl, tl) < 0)
688 /* this may have failed because moving a file across filesystems
689 was attempted, so try copy and delete instead */
694 /* err, now we can't delete the source file so return FALSE */
709 gboolean rename_file(const gchar *s, const gchar *t)
715 if (!s || !t) return FALSE;
717 sl = path_from_utf8(s);
718 tl = path_from_utf8(t);
719 ret = (rename(sl, tl) == 0);
726 gchar *get_current_dir()
731 pathl = g_get_current_dir();
732 path8 = path_to_utf8(pathl);
738 void string_list_free(GList *list)
740 g_list_free_full(list, g_free);
743 GList *string_list_copy(const GList *list)
745 GList *new_list = nullptr;
746 auto work = const_cast<GList *>(list);
752 path = static_cast<gchar *>(work->data);
755 new_list = g_list_prepend(new_list, g_strdup(path));
758 return g_list_reverse(new_list);
761 gchar *unique_filename(const gchar *path, const gchar *ext, const gchar *divider, gboolean pad)
767 if (!divider) divider = "";
769 unique = g_strconcat(path, ext, NULL);
770 while (isname(unique))
775 unique = g_strdup_printf("%s%s%03d%s", path, divider, n, ext);
779 unique = g_strdup_printf("%s%s%d%s", path, divider, n, ext);
793 #pragma GCC diagnostic push
794 #pragma GCC diagnostic ignored "-Wunused-function"
795 gchar *unique_filename_simple_unused(const gchar *path)
801 if (!path) return nullptr;
803 name = filename_from_path(path);
804 if (!name) return nullptr;
806 ext = registered_extension_from_path(name);
810 unique = unique_filename(path, nullptr, "_", TRUE);
816 base = remove_extension_from_path(path);
817 unique = unique_filename(base, ext, "_", TRUE);
823 #pragma GCC diagnostic pop
825 const gchar *filename_from_path(const gchar *path)
829 if (!path) return nullptr;
831 base = strrchr(path, G_DIR_SEPARATOR);
832 if (base) return base + 1;
837 gchar *remove_level_from_path(const gchar *path)
841 if (!path) return g_strdup("");
843 base = strrchr(path, G_DIR_SEPARATOR);
844 /* Take account of a file being in the root ( / ) folder - ensure the returned value
845 * is at least one character long */
846 if (base) return g_strndup(path, (strlen(path)-strlen(base)) == 0 ? 1 : (strlen(path)-strlen(base)));
851 gboolean file_extension_match(const gchar *path, const gchar *ext)
856 if (!path) return FALSE;
857 if (!ext) return TRUE;
863 return (p > e && g_ascii_strncasecmp(path + p - e, ext, e) == 0);
866 gchar *remove_extension_from_path(const gchar *path)
868 const gchar *reg_ext;
870 if (!path) return nullptr;
872 reg_ext = registered_extension_from_path(path);
874 return g_strndup(path, strlen(path) - (reg_ext == nullptr ? 0 : strlen(reg_ext)));
877 void parse_out_relatives(gchar *path)
886 while (path[s] != '\0')
888 if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.')
890 /* /. occurrence, let's see more */
893 if (path[p] == G_DIR_SEPARATOR || path[p] == '\0')
895 /* /./ or /., just skip this part */
900 if (path[p] == '.' && (path[p+1] == G_DIR_SEPARATOR || path[p+1] == '\0'))
902 /* /../ or /.., remove previous part, ie. /a/b/../ becomes /a/ */
905 while (path[t] != G_DIR_SEPARATOR && t > 0) t--;
910 if (s != t) path[t] = path[s];
915 if (t == 0 && path[t] == G_DIR_SEPARATOR) t++;
916 if (t > 1 && path[t-1] == G_DIR_SEPARATOR) t--;
920 gboolean file_in_path(const gchar *name)
926 gboolean ret = FALSE;
928 if (!name) return FALSE;
929 path = g_strdup(getenv("PATH"));
930 if (!path) return FALSE;
931 namel = path_from_utf8(name);
935 while (p < l && !ret)
939 while (path[e] != ':' && path[e] != '\0') e++;
942 f = g_build_filename(path + p, namel, NULL);
943 if (isfile(f)) ret = TRUE;
953 gboolean recursive_mkdir_if_not_exists(const gchar *path, mode_t mode)
955 if (!path) return FALSE;
959 gchar *npath = g_strdup(path);
965 if (p[0] == G_DIR_SEPARATOR || p[0] == '\0')
977 DEBUG_1("creating sub dir:%s", npath);
978 if (!mkdir_utf8(npath, mode))
980 log_printf("create dir failed: %s\n", npath);
986 if (!end) p[0] = G_DIR_SEPARATOR;
995 /* does filename utf8 to filesystem encoding first */
996 gboolean md5_get_digest_from_file_utf8(const gchar *path, guchar digest[16])
1001 pathl = path_from_utf8(path);
1002 success = md5_get_digest_from_file(pathl, digest);
1009 gchar *md5_text_from_file_utf8(const gchar *path, const gchar *error_text)
1011 std::unique_ptr<gchar, decltype(&g_free)> pathl{path_from_utf8(path), g_free};
1013 auto md5_text = md5_get_string_from_file(pathl.get());
1015 return md5_text ? md5_text : g_strdup(error_text);
1018 /* Download web file
1023 GCancellable *cancellable;
1026 GtkWidget *progress;
1031 static void web_file_async_ready_cb(GObject *source_object, GAsyncResult *res, gpointer data)
1033 GError *error = nullptr;
1034 auto web = static_cast<WebData *>(data);
1035 gchar *tmp_filename;
1037 if (!g_cancellable_is_cancelled(web->cancellable))
1039 generic_dialog_close(web->gd);
1042 if (g_file_copy_finish(G_FILE(source_object), res, &error))
1044 tmp_filename = g_file_get_parse_name(web->tmp_g_file);
1045 g_free(tmp_filename);
1046 layout_set_path(web->lw, g_file_get_path(web->tmp_g_file));
1050 file_util_warning_dialog(_("Web file download failed"), error->message, GQ_ICON_DIALOG_ERROR, nullptr);
1053 g_object_unref(web->tmp_g_file);
1054 web->tmp_g_file = nullptr;
1055 g_object_unref(web->cancellable);
1056 g_object_unref(web->web_file);
1059 static void web_file_progress_cb(goffset current_num_bytes, goffset total_num_bytes, gpointer data)
1061 auto web = static_cast<WebData *>(data);
1063 if (!g_cancellable_is_cancelled(web->cancellable))
1065 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(web->progress), static_cast<gdouble>(current_num_bytes) / total_num_bytes);
1069 static void download_web_file_cancel_button_cb(GenericDialog *, gpointer data)
1071 auto web = static_cast<WebData *>(data);
1073 g_cancellable_cancel(web->cancellable);
1076 gboolean download_web_file(const gchar *text, gboolean minimized, gpointer data)
1079 auto lw = static_cast<LayoutWindow *>(data);
1081 GError *error = nullptr;
1084 gboolean ret = FALSE;
1086 FileFormatClass format_class;
1088 scheme = g_uri_parse_scheme(text);
1089 if (g_strcmp0("http", scheme) == 0 || g_strcmp0("https", scheme) == 0)
1091 format_class = filter_file_get_class(text);
1093 if (format_class == FORMAT_CLASS_IMAGE || format_class == FORMAT_CLASS_RAWIMAGE || format_class == FORMAT_CLASS_VIDEO || format_class == FORMAT_CLASS_DOCUMENT)
1095 tmp_dir = g_dir_make_tmp("geeqie_XXXXXX", &error);
1098 log_printf("Error: could not create temporary file n%s\n", error->message);
1099 g_error_free(error);
1105 web = g_new0(WebData, 1);
1108 web->web_file = g_file_new_for_uri(text);
1110 base = g_strdup(g_file_get_basename(web->web_file));
1111 web->tmp_g_file = g_file_new_for_path(g_build_filename(tmp_dir, base, NULL));
1113 web->gd = generic_dialog_new(_("Download web file"), "download_web_file", nullptr, TRUE, download_web_file_cancel_button_cb, web);
1115 message = g_strconcat(_("Downloading "), base, NULL);
1116 generic_dialog_add_message(web->gd, GQ_ICON_DIALOG_INFO, message, nullptr, FALSE);
1118 web->progress = gtk_progress_bar_new();
1119 gq_gtk_box_pack_start(GTK_BOX(web->gd->vbox), web->progress, FALSE, FALSE, 0);
1120 gtk_widget_show(web->progress);
1123 gtk_window_iconify(GTK_WINDOW(web->gd->dialog));
1126 gtk_widget_show(web->gd->dialog);
1127 web->cancellable = g_cancellable_new();
1128 g_file_copy_async(web->web_file, web->tmp_g_file, G_FILE_COPY_OVERWRITE, G_PRIORITY_LOW, web->cancellable, web_file_progress_cb, web, web_file_async_ready_cb, web);
1146 gboolean rmdir_recursive(GFile *file, GCancellable *cancellable, GError **error)
1148 g_autoptr(GFileEnumerator) enumerator = nullptr;
1150 enumerator = g_file_enumerate_children(file, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, nullptr);
1152 while (enumerator != nullptr)
1156 if (!g_file_enumerator_iterate(enumerator, nullptr, &child, cancellable, error))
1158 if (child == nullptr)
1160 if (!rmdir_recursive(child, cancellable, error))
1164 return g_file_delete(file, cancellable, error);
1168 * @brief Retrieves the internal scale factor that maps from window coordinates to the actual device pixels
1170 * @returns scale factor
1176 LayoutWindow *lw = nullptr;
1179 return gtk_widget_get_scale_factor(lw->window);
1181 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */