r561 - in trunk: . utils utils/spell vim7/debian

Stefano Zacchiroli zack at costa.debian.org
Thu Mar 30 16:57:28 UTC 2006


Author: zack
Date: 2006-03-30 16:57:27 +0000 (Thu, 30 Mar 2006)
New Revision: 561

Added:
   trunk/utils/
   trunk/utils/spell/
   trunk/utils/spell/Makefile
   trunk/utils/spell/install-vim-spell-file.c
   trunk/utils/spell/mkvimspell.sh
Removed:
   trunk/vim7/debian/spell/
Modified:
   trunk/vim7/debian/changelog
Log:
- moved stuff related to debian-specific support for vimspell out of the vim7
  dir, since it is still work in progress ...
- added a proof-of-concept setgid installer (not yet thorougly screened)



Property changes on: trunk/utils/spell
___________________________________________________________________
Name: svn:ignore
   + install-vim-spell-file


Added: trunk/utils/spell/Makefile
===================================================================
--- trunk/utils/spell/Makefile	2006-03-30 15:41:32 UTC (rev 560)
+++ trunk/utils/spell/Makefile	2006-03-30 16:57:27 UTC (rev 561)
@@ -0,0 +1,5 @@
+all: install-vim-spell-file
+%: %.c
+	gcc -Wall -pedantic -o $@ $<
+clean:
+	rm -f install-vim-spell-file

Added: trunk/utils/spell/install-vim-spell-file.c
===================================================================
--- trunk/utils/spell/install-vim-spell-file.c	2006-03-30 15:41:32 UTC (rev 560)
+++ trunk/utils/spell/install-vim-spell-file.c	2006-03-30 16:57:27 UTC (rev 561)
@@ -0,0 +1,141 @@
+/* Install Vim spell files under a system-wide directory (SPELLDIR).
+ * Should be executable by users, and will run setgid of a group with
+ * write permissions on SPELLDIR.
+ *
+ * Copyright (C) 2006: Stefano Zacchiroli <zack at debian.org>
+ * License: GUN GPL Version 2 or above
+ * $Id$
+ */
+
+#include <fcntl.h>
+#include <libgen.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+/* destination dir for Vim spell files. No trailing slash. */
+#define SPELLDIR "/var/cache/vim/spell"
+
+#define FALSE 0
+#define TRUE  1
+#define CPBUFSIZ 4096
+
+int chksuffix(char *s, char *suffix)
+{
+	char *suff;
+
+	if ((suff = rindex(s, '.')) == NULL)
+		return(FALSE);
+	if (strcmp(suff, suffix) != 0)
+		return(FALSE);
+	return(TRUE);
+}
+
+int safe_spellfile(char *fname)
+{
+	struct stat s_tmp;
+
+	if (! (stat(fname, &s_tmp) == 0 && S_ISREG(s_tmp.st_mode))) {
+		fprintf(stderr, "'%s': no such regular file\n", fname);
+		fflush(stderr);
+		return(FALSE);
+	}
+	if (! (chksuffix(fname, ".spl") || chksuffix(fname, ".sug")
+				|| chksuffix(fname, ".vim"))) {
+		fprintf(stderr, "%s: invalid file name (must end with '.{spl,sug,vim}')\n",
+				fname);
+		fflush(stderr);
+		return(FALSE);
+	}
+	/* XXX additional checks can be implemented here ... */
+	return(TRUE);
+}
+
+int copyfile(char *src, char *dst)
+{
+	FILE *src_f = NULL;
+	FILE *dst_f = NULL;
+	int bytes;
+	int rc = 0;
+	char buf[CPBUFSIZ];
+
+	if ((src_f = fopen(src, "r")) == NULL) {
+		fprintf(stderr, "can't open '%s' for reading\n", src);
+		rc = -1;
+	}
+	if (rc == 0 && (dst_f = fopen(dst, "w")) == NULL) {
+		fprintf(stderr, "can't open '%s' for writing\n", dst);
+		rc = -1;
+	}
+
+	while (rc == 0 && ! feof(src_f)) {
+		bytes = fread((void *) buf, 1, CPBUFSIZ, src_f);
+		if (ferror(src_f)) {
+			fprintf(stderr, "error while reading from '%s'\n", src);
+			rc = -1;
+			continue;
+		}
+		if (fwrite((void *) buf, 1, bytes, dst_f) < bytes) {
+			fprintf(stderr, "error while writing to '%s'\n", dst);
+			rc = -1;
+			continue;
+		}
+	}
+
+	if (src_f != NULL)
+		fclose(src_f);
+	if (dst_f != NULL)
+		fclose(dst_f);
+
+	fflush(stderr);
+	return(rc);
+}
+
+int main (int argc, char **argv)
+{
+	int i, size;
+	int rc = 0;
+	char *tmp, *bname;
+	char dest[PATH_MAX];
+
+	char *usage = "\nUsage: install-vim-spell-file FILE ...\n\
+\n\
+ Installs Vim spell files under %s\n\
+ Files must end with one of the suffixes: .spl, .sug, .vim\n\
+\n";
+
+	umask(02);
+	if (argc <= 1 || strcmp(argv[1], "-h") == 0
+			|| strcmp(argv[1], "--help") == 0) {
+		fprintf(stderr, usage, SPELLDIR);
+		exit(1);
+	}
+
+	for (i = 1; i < argc; i++) {
+		if (!safe_spellfile(argv[i]))
+			continue;
+
+		/* argv[i] is (apparently) safe, proceed ... */
+		if ((tmp = strdup(argv[i])) == NULL) {
+			fprintf(stderr, "out of memory\n");
+			exit(2);
+		}
+		bname = basename(tmp);
+		size = snprintf(dest, PATH_MAX, "%s/%s", SPELLDIR, bname);
+		if (size < 0 || size > PATH_MAX) {
+			fprintf(stderr, "can't create destination path\n");
+			exit(2);
+		}
+		free(tmp);
+		if (copyfile(argv[i], dest) != 0) {
+			fprintf(stderr, "error while installing '%s'\n", dest);
+			fflush(stderr);
+		}
+	}
+
+	exit(rc);
+}
+


Property changes on: trunk/utils/spell/install-vim-spell-file.c
___________________________________________________________________
Name: svn:keywords
   + Id

Copied: trunk/utils/spell/mkvimspell.sh (from rev 559, trunk/vim7/debian/spell/mkvimspell.sh)

Modified: trunk/vim7/debian/changelog
===================================================================
--- trunk/vim7/debian/changelog	2006-03-30 15:41:32 UTC (rev 560)
+++ trunk/vim7/debian/changelog	2006-03-30 16:57:27 UTC (rev 561)
@@ -36,8 +36,6 @@
       133_filetype.vim.diff, 142_filetype.vim.diff, 153_filetype.vim.diff,
       154_svn.vim.diff, 156_scripts.vim.diff, 158_python.vim.diff,
       301_xxd.c.diff, 303_option.c.diff, 305_term.c.diff
-  * Added script debian/spell/mkvimspell.sh, it generates Vim spell files from
-    (Debian's) MySpell dictionaries.
 
   [ Matthijs Mohlmann ]
   * Updated debsources syntax file.




More information about the pkg-vim-maintainers mailing list