Пример #1
0
void InitEd()
{
#ifdef Win32
    DefaultFileName = R_tmpnam("Redit", R_TempDir);
#else
    DefaultFileName = R_tmpnam(NULL, R_TempDir);
#endif
}
Пример #2
0
int attribute_hidden
Rstd_ShowFiles(int nfile,		/* number of files */
	       const char **file,		/* array of filenames */
	       const char **headers,	/* the `headers' args of file.show.
					   Printed before each file. */
	       const char *wtitle,	/* title for window
					   = `title' arg of file.show */
	       Rboolean del,	/* should files be deleted after use? */
	       const char *pager)		/* pager to be used */

{
/*
	This function can be used to display the named files with the
	given titles and overall title.	 On GUI platforms we could
	use a read-only window to display the result.  Here we just
	make up a temporary file and invoke a pager on it.
*/

    int c, i, res;
    char *filename;
    FILE *fp, *tfp;
    char buf[1024];

    if (nfile > 0) {
	if (pager == NULL || strlen(pager) == 0) pager = "more";
	filename = R_tmpnam(NULL, R_TempDir); /* mallocs result */
	if ((tfp = R_fopen(filename, "w")) != NULL) {
	    for(i = 0; i < nfile; i++) {
		if (headers[i] && *headers[i])
		    fprintf(tfp, "%s\n\n", headers[i]);
		errno = 0; /* some systems require this */
		/* File expansion is now done in file.show(), but
		   left here in case other callers assumed it */
		if ((fp = R_fopen(R_ExpandFileName(file[i]), "r"))
		    != NULL) {
		    while ((c = fgetc(fp)) != EOF)
			fputc(c, tfp);
		    fprintf(tfp, "\n");
		    fclose(fp);
		    if(del)
			unlink(R_ExpandFileName(file[i]));
		}
		else
		    fprintf(tfp, _("Cannot open file '%s': %s\n\n"),
			    file[i], strerror(errno));
	    }
	    fclose(tfp);
	}
	snprintf(buf, 1024, "'%s' < '%s'", pager, filename); //might contain spaces
	res = R_system(buf);
	unlink(filename);
	free(filename);
	return (res != 0);
    }
    return 1;
}