Beispiel #1
0
int write_file(char *file_name, Boolean update_recent)
{
    FILE	   *fp;

    if (!ok_to_write(file_name, "SAVE"))
	return (-1);

    if ((fp = fopen(file_name, "wb")) == NULL) {
	file_msg("Couldn't open file %s, %s", file_name, strerror(errno));
	beep();
	return (-1);
    }
    num_object = 0;
    if (write_objects(fp)) {
	file_msg("Error writing file %s, %s", file_name, strerror(errno));
	beep();
	exit (2);
	return (-1);
    }
    if (!update_figs)
	put_msg("%d object(s) saved in \"%s\"", num_object, file_name);

    /* update the recent list if caller desires */
    if (update_recent)
	update_recent_list(file_name);

    return (0);
}
Beispiel #2
0
int
read_tif(char *filename, int filetype, F_pic *pic)
{
	char	 buf[2*PATH_MAX+40],pcxname[PATH_MAX];
	FILE	*tiftopcx;
	int	 stat;

	/* make name for temp output file */
	sprintf(pcxname, "%s/%s%06d.pix", TMPDIR, "xfig-pcx", getpid());

	/* make command to convert tif to pnm then to pcx into temp file */
	/* for some reason, tifftopnm requires a file and can't work in a pipe */
	sprintf(buf, "tifftopnm %s 2> /dev/null | ppmtopcx > %s 2> /dev/null",
		filename, pcxname);
	if ((tiftopcx = popen(buf,"w" )) == 0) {
	    file_msg("Cannot open pipe to tifftopnm or ppmtopcx\n");
	    /* remove temp file */
	    unlink(pcxname);
	    return FileInvalid;
	}
	/* close pipe */
	pclose(tiftopcx);
	if ((tiftopcx = fopen(pcxname, "rb")) == NULL) {
	    file_msg("Can't open temp output file\n");
	    /* remove temp file */
	    unlink(pcxname);
	    return FileInvalid;
	}
	/* now call read_pcx to read the pcx file */
	stat = read_pcx(tiftopcx, filetype, pic);
	pic->pic_cache->subtype = T_PIC_TIF;
	/* remove temp file */
	unlink(pcxname);
	return stat;
}
Beispiel #3
0
/* make the full path from ~/partialpath */
void parseuserpath(char *path, char *longpath)
{
    char	  *p;
    struct passwd *who;

    /* this user's home */
    if (strlen(path)==1 || path[1]=='/') {
	strcpy(longpath,getenv("HOME"));
	if (strlen(path)==1)		/* nothing after the ~, we have the full path */
		return;
	strcat(longpath,&path[1]);	/* append the rest of the path */
	return;
    }
    /* another user name after ~ */
    strcpy(longpath,&path[1]);
    p=strchr(longpath,'/');
    if (p)
	    *p='\0';
    who = getpwnam(longpath);
    if (!who) {
	file_msg("No such user: %s",longpath);
	strcpy(longpath,path);
    } else {
	strcpy(longpath,who->pw_dir);
	p=strchr(path,'/');
	if (p)
		strcat(longpath,p);	/* attach stuff after the / */
    }
}
Beispiel #4
0
void
do_print(Widget w)
{
	char	   *printer_val;
	char	   *param_val;
	char	    cmd[255],cmd2[255];
	char	   *c1;
	char	    backgrnd[10], grid[80];

	/* don't print if in the middle of drawing/editing */
	if (check_action_on())
		return;

	if (emptyfigure_msg(print_msg) && !batch_exists)
		return;

	/* create popup panel if not already there so we have all the
	   resources necessary (e.g. printer name etc.) */
	if (!print_popup) 
		create_print_panel(w);

	/* get the magnification into appres.magnification */
	get_magnif();

	/* update the figure size (magnification * bounding_box) */
	print_update_figure_size();

	printer_val = panel_get_value(printer_text);
	param_val = panel_get_value(param_text);

	/* get grid params and assemble into fig2dev parm */
	get_grid_spec(grid, print_grid_minor_text, print_grid_major_text);

	if (batch_exists) {
	    gen_print_cmd(cmd,batch_file,printer_val,param_val);
	    if (system(cmd) != 0)
		file_msg("Error during PRINT");
	    /* clear the batch file and the count */
	    do_clear_batch(w);
	} else {
	    strcpy(cmd, param_val);
	    /* see if the user wants the filename in the param list (%f) */
	    if (!strstr(cur_filename,"%f")) {	/* don't substitute if the filename has a %f */
		while (c1=strstr(cmd,"%f")) {
		    strcpy(cmd2, c1+2);		/* save tail */
		    strcpy(c1, cur_filename);	/* change %f to filename */
		    strcat(c1, cmd2);		/* append tail */
		}
	    }
	    /* make a #rrggbb string from the background color */
	    make_rgb_string(export_background_color, backgrnd);
	    print_to_printer(printer_val, backgrnd, appres.magnification,
				print_all_layers, bound_active_layers, grid, cmd);
	}
}
Beispiel #5
0
int
change_directory(char *path)
{
    if (path == NULL || *path == '\0')
	return 0;
    if (chdir(path) == -1) {
	file_msg("Can't go to directory %s, : %s", path, strerror(errno));
	return 1;
    }
    return 0;
}
Beispiel #6
0
int x_fontnum(int psflag, int fnum)
{
    int x_font;

    if ((psflag && fnum >= NUM_FONTS) || (!psflag && fnum >= NUM_LATEX_FONTS)) {
	file_msg("Illegal font number, using font 0");
	fnum = 0;
    }
    x_font = (psflag ?  ps_fontinfo[fnum + 1].xfontnum :
			latex_fontinfo[fnum].xfontnum);
    return x_font;
}
Beispiel #7
0
void launch_viewer(char *filename, char *message, char *viewer)
{
	/* turn off Compose key LED */
	setCompLED(0);

	/* first check if the file is installed */
	if (!check_docfile(filename)){
	    if (errno == ENOENT) {
                file_msg("%s is not installed, please install package xfig-doc.",filename);
            } else {
                file_msg("System error: %s on file %s",strerror(errno),filename);
            }
            beep();
            return;
	}
	/* now replace the %f in the browser command with the filename and add the "&" */
	browsecommand = build_command(viewer, filename);
	put_msg(message);
	system(browsecommand);
	free(browsecommand);
}
Beispiel #8
0
void
do_print_batch(Widget w)
{
	FILE	   *infp,*outfp;
	char	    tmp_exp_file[PATH_MAX];
	char	    str[255];
	char	    backgrnd[10], grid[80];
   int       fd;

	if (writing_batch || emptyfigure_msg(print_msg))
		return;

	/* set lock so we don't come here while still writing a file */
	/* this could happen if the user presses the button too fast */
	writing_batch = True;

	/* make a temporary name to write this figure to */
	snprintf(tmp_exp_file, sizeof(tmp_exp_file), "%s/xfig-exp.XXXXXX",
		TMPDIR);

	if (batch_exists != True) {
		/* make a temporary name to write the batch stuff to */
		sprintf(batch_file, "%s/xfig-batch.XXXXXX", TMPDIR);
		if ((fd = mkstemp(batch_file)) == -1) {
			file_msg("Error creating temporary file");
			return;
		}
		close(fd);
		batch_exists = True;
	}
	if (!print_popup) 
		create_print_panel(w);

	/* get magnification into appres.magnification */
	get_magnif();

	/* update the figure size (magnification * bounding_box) */
	print_update_figure_size();

	/* make a #rrggbb string from the background color */
	make_rgb_string(export_background_color, backgrnd);

	if ((fd = mkstemp(tmp_exp_file)) == -1) {
		file_msg("Error creating temporary file");
		return;
	}
	close(fd);

	/* get grid params and assemble into fig2dev parm */
	get_grid_spec(grid, print_grid_minor_text, print_grid_major_text);

	print_to_file(tmp_exp_file, "ps", appres.magnification, 0, 0, backgrnd,
				NULL, False, print_all_layers, bound_active_layers, 0, False, grid, appres.overlap);
	put_msg("Appending to batch file \"%s\" (%s mode) ... done",
		    batch_file, appres.landscape ? "LANDSCAPE" : "PORTRAIT");
	app_flush();		/* make sure message gets displayed */

	/* now append that to the batch file */
	if ((infp = fopen(tmp_exp_file, "rb")) == NULL) {
		file_msg("Error during PRINT - can't open temporary file to read");
		return;
		}
	if ((outfp = fopen(batch_file, "ab")) == NULL) {
		file_msg("Error during PRINT - can't open print file to append");
		return;
		}
	while (fgets(str,255,infp) != NULL)
		(void) fputs(str,outfp);
	fclose(infp);
	fclose(outfp);
	unlink(tmp_exp_file);
	/* count this batch figure */
	num_batch_figures++ ;
	/* and update the label widget */
	update_batch_count();
	/* we're done */
	writing_batch = False;
}
Beispiel #9
0
static int
parse_printcap(char **names)
{
    FILE   *printcap;
    char    str[300];
    int     i,j,k,len;
    int     printers;
    Boolean comment;
    Boolean dudprinter;

    if ((printcap=fopen(PRINTCAP,"r"))==NULL)
	return 0;
    printers = 0;
    while (!feof(printcap)) {
	if (fgets(str, sizeof(str), printcap) == NULL)
	    break;
	len = strlen(str);
	comment = False;
	/* get rid of newline */
	str[--len] = '\0';
	/* check for comments */
	for (i=0; i<len; i++) {
	    if (str[i] == '#') {
		comment = True;
		break;
	    }
	    if (str[i] != ' ' && str[i] != '\t')
		break;
	}
	/* skip comment */
	if (comment)
	    continue;
	/* skip blank line */
	if (i==len)
	    continue;
	/* get printer name */
	for (j=i; j<len; j++) {
	    if (str[j] == '|' || str[j] == ':' || str[j] == ' ')
		break;
	}
	str[j] = '\0';
        /* Check for empty printer name or duplicate name */
        dudprinter = True;
        for (k=0; k<j; k++) {
            if(str[k] !=' ' && str[k] != '\t')
               dudprinter = False;
        }
        if(printers > 0) {
            for (k=0; k<printers; k++) {
                if(strncmp(names[k],&str[i],j-i+1) == 0)
                    dudprinter = True;
            }
        }
        if (dudprinter == True)
            continue;
	if (printers >= MAX_PRINTERS) {
	    file_msg("Maximum number of printers (%d) exceeded in %s",MAX_PRINTERS,PRINTCAP);
	    break;
	}
	if ((names[printers] = new_string(j-i)) == NULL) {
	    file_msg("Out of memory while getting printer names");
	    fclose(printcap);
	    break;
	}
	strncpy(names[printers],&str[i],j-i+1);
	printers++;
	for (j=len-1; j>0; j--) {
	    if (str[j] == ' ' || str[j] == '\t')
		continue;
	    /* found the next entry, break */
	    if (str[j] != '\\')
		break;
	    /* this line has \ at the end, read the next line and check it */
	    if (fgets(str, sizeof(str), printcap) == NULL)
		break;
	    /* set length to ignore newline */
	    len = strlen(str)-1;
	    /* force loop to start over */
	    j=len;
	}
    }
    fclose(printcap);
    return printers;
}
Beispiel #10
0
Boolean
captureImage(Widget window, char *filename)  	/* returns True on success */
              
               
{
    unsigned char	Red[MAX_COLORMAP_SIZE],
			Green[MAX_COLORMAP_SIZE],
			Blue[MAX_COLORMAP_SIZE];
    int      		numcols;
    int      		captured;
    int      		width, height;
    Boolean		status;

    FILE		*pngfile;
    int			 type;

    if (!ok_to_write(filename, "EXPORT") )
	return(False);

    /* unmap the xfig windows, capture a png then remap our windows */

    XtUnmapWidget(tool);
    XtUnmapWidget(window);
    app_flush();

    /* capture the screen area */
    status = getImageData(&width, &height, &type, &numcols, Red, Green, Blue);

    /* make sure server is ungrabbed if we're debugging */
    app_flush();
    /* map our windows again */
    XtMapWidget(tool);
    XtMapWidget(window);

    if ( status == False ) {
	put_msg("Nothing Captured.");
	app_flush();
	captured = False;
    } else {
	/* encode the image and write to the file */
	put_msg("Writing screenshot to PNG file...");

	app_flush();

	if ((pngfile = fopen(filename,"wb"))==0) {
	    file_msg("Cannot open PNG file %s for writing",filename);
	    put_msg("Cannot open PNG file %s for writing",filename);
	    captured = False;
	} else {
	    /* write the png file */
	    if (!write_png(pngfile, data, type, Red, Green, Blue, numcols, width, height))
		file_msg("Problem writing PNG file from screen capture");
	    fclose(pngfile);
	    captured = True;
	}

	free(data);
   }

   return ( captured );
}
Beispiel #11
0
static Boolean
getImageData(int *w, int *h, int *type, int *nc, unsigned char *Red, unsigned char *Green, unsigned char *Blue)
{
    XColor	colors[MAX_COLORMAP_SIZE];
    int		colused[MAX_COLORMAP_SIZE];
    int		mapcols[MAX_COLORMAP_SIZE];
    int		red, green, blue;
    int		red_mask, green_mask, blue_mask;
    int		red_shift, green_shift, blue_shift;

    int		x, y, width, height;
    Window	cw;
    static	XImage *image;

    int		i, j;
    int		numcols;
    int		bytes_per_pixel, bit_order, byte_order;
    int		byte_inc;
    int		pix;
    unsigned char *iptr, *rowptr, *dptr;

    sleep(1);   /* in case he'd like to click on something */
    beep();	/* signal user */
    if ( selectedRootArea( &x, &y, &width, &height, &cw ) == False )
	return False;

    image = XGetImage(tool_d, XDefaultRootWindow(tool_d),
				 x, y, width, height, AllPlanes, ZPixmap);
    if (!image || !image->data) {
	file_msg("Cannot capture %dx%d area - memory problems?",
							width,height);
	return False;
    }


    /* if we get here we got an image! */
    *w = width = image->width;
    *h = height = image->height;

    if (tool_vclass == TrueColor) {
	*type = IMAGE_RGB;
	bytes_per_pixel = 3;
    } else {
	/* PseudoColor, get color table */
	*type = IMAGE_PALETTE;
	bytes_per_pixel = 1;
	numcols = getCurrentColors(XDefaultRootWindow(tool_d), colors);
	if ( numcols <= 0 ) {  /* ought not to get here as capture button
			    should not appear for these displays */
	    file_msg("Cannot handle a display without a colormap.");
	    XDestroyImage( image );
	    return False;
	}
    }

    iptr = rowptr = (unsigned char *) image->data;
    dptr = data = (unsigned char *) malloc(height*width*bytes_per_pixel);
    if ( !dptr ) {
	file_msg("Insufficient memory to convert image.");
	XDestroyImage(image);
	return False;
    }
     
    if (tool_vclass == TrueColor) {
	byte_order = image->byte_order;			/* MSBFirst or LSBFirst */
	bit_order = image->bitmap_bit_order;		/* MSBFirst or LSBFirst */
	red_mask = image->red_mask;
	green_mask = image->green_mask;
	blue_mask = image->blue_mask;
	/* find how many bits we need to shift values */
	red_shift = rshift(red_mask);
	green_shift = rshift(green_mask);
	blue_shift = rshift(blue_mask);
	switch (image->bits_per_pixel) {
	    case 8: byte_inc = 1;
		    break;
	    case 16: byte_inc = 2;
		    break;
	    case 24: byte_inc = 3;
		    break;
	    case 32: byte_inc = 4;
		    break;
	    default: byte_inc = 4;
		    break;
	}

	for (i=0; i<image->height; i++) {
	    for (j=0; j<image->width; j++) {
		if (byte_order == MSBFirst) {
		    switch (byte_inc) {
			case 1:
				pix =  (unsigned char) *iptr;
				break;
			case 2: 
				pix =  (unsigned short) (*iptr << 8);
				pix += (unsigned char) *(iptr+1);
				break;
			case 3:
				pix =  (unsigned int) (*(iptr) << 16);
				pix += (unsigned short) (*(iptr+1) << 8);
				pix += (unsigned char) (*(iptr+2));
				break;
			case 4:
				pix =  (unsigned int) (*(iptr) << 24);
				pix += (unsigned int) (*(iptr+1) << 16);
				pix += (unsigned short) (*(iptr+2) << 8);
				pix += (unsigned char) (*(iptr+3));
				break;
		    }
		} else {
		    /* LSBFirst */
		    switch (byte_inc) {
			case 1:
				pix =  (unsigned char) *iptr;
				break;
			case 2: 
				pix =  (unsigned char) *iptr;
				pix += (unsigned short) (*(iptr+1) << 8);
				break;
			case 3:
				pix =  (unsigned char) *iptr;
				pix += (unsigned short) (*(iptr+1) << 8);
				pix += (unsigned int) (*(iptr+2) << 16);
				break;
			case 4:
				pix =  (unsigned char) *iptr;
				pix += (unsigned short) (*(iptr+1) << 8);
				pix += (unsigned int) (*(iptr+2) << 16);
				pix += (unsigned int) (*(iptr+3) << 24);
				break;
		    }
		} /* if (byte_order ...) */

		/* increment pixel pointer */
		iptr += byte_inc;

		/* now extract the red, green and blue values using the masks and shifting */

		red   = (pix & red_mask) >> red_shift;
		green = (pix & green_mask) >> green_shift;
		blue  = (pix & blue_mask) >> blue_shift;
		/* store in output data */
		*(dptr++) = (unsigned char) red;
		*(dptr++) = (unsigned char) green;
		*(dptr++) = (unsigned char) blue;
	    } /* for (j=0; j<image->width ... */

	    /* advance to next scanline row */
	    rowptr += image->bytes_per_line;
	    iptr = rowptr;
	} /* for (i=0; i<image->height ... */

    } else if (tool_cells > 2) { 
Beispiel #12
0
void remap_imagecolors(void)
{
    int		    i;

    /* if monochrome, return */
    if (tool_cells <= 2 || appres.monochrome)
	return;

    npixels = 0;

    /* first see if there are enough colorcells for all image colors */
    usenet = False;

    /* see if the total number of colors will fit without using the neural net */
    ncolors = count_colors();
    if (ncolors == 0)
	return;

    put_msg(REMAP_MSG);
    set_temp_cursor(wait_cursor);
    app_flush();

    if (ncolors > appres.max_image_colors) {
	if (appres.DEBUG) 
		fprintf(stderr,"More colors (%d) than allowed (%d), using neural net\n",
				ncolors,appres.max_image_colors);
	ncolors = appres.max_image_colors;
	usenet = True;
    }

    /* if this is the first image, allocate the number of colorcells we need */
    if (num_oldcolors != ncolors) {
	if (num_oldcolors != -1) {
	    unsigned long   pixels[MAX_USR_COLS];
	    for (i=0; i<num_oldcolors; i++)
		pixels[i] = image_cells[i].pixel;
	    if (tool_vclass == PseudoColor)
		XFreeColors(tool_d, tool_cm, pixels, num_oldcolors, 0);
	}
	alloc_imagecolors(ncolors);
	/* hmm, we couldn't get that number of colors anyway; use the net, Luke */
	if (ncolors > avail_image_cols) {
	    usenet = True;
	    if (appres.DEBUG) 
		fprintf(stderr,"More colors (%d) than available (%d), using neural net\n",
				ncolors,avail_image_cols);
	}
	num_oldcolors = avail_image_cols;
	if (avail_image_cols < 2 && ncolors >= 2) {
	    file_msg("Cannot allocate even 2 colors for pictures");
	    reset_cursor();
	    num_oldcolors = -1;
	    reset_cursor();
	    put_msg(REMAP_MSG2);
	    app_flush();
	    return;
	}
    }
    reset_cursor();

    if (usenet) {
	int	stat;
	int	mult = 1;

	/* check if user pressed cancel button (in file preview) */
	if (check_cancel())
	    return;

	/* count total number of pixels in all the pictures */
	npixels = count_pixels();

	/* check if user pressed cancel button */
	if (check_cancel())
	    return;

	/* initialize the neural network */
	/* -1 means can't alloc memory, -2 or more means must have that many times
		as many pixels */
	set_temp_cursor(wait_cursor);
	if ((stat=neu_init(npixels)) <= -2) {
	    mult = -stat;
	    npixels *= mult;
	    /* try again with more pixels */
	    stat = neu_init2(npixels);
	}
	if (stat == -1) {
	    /* couldn't alloc memory for network */
	    fprintf(stderr,"Can't alloc memory for neural network\n");
	    reset_cursor();
	    put_msg(REMAP_MSG2);
	    app_flush();
	    return;
	}
	/* now add all pixels to the samples */
	for (i=0; i<mult; i++)
	    add_all_pixels();

	/* make a new colortable with the optimal colors */
	avail_image_cols = neu_clrtab(avail_image_cols);

	/* now change the color cells with the new colors */
	/* clrtab[][] is the colormap produced by neu_clrtab */
	for (i=0; i<avail_image_cols; i++) {
	    image_cells[i].red   = (unsigned short) clrtab[i][N_RED] << 8;
	    image_cells[i].green = (unsigned short) clrtab[i][N_GRN] << 8;
	    image_cells[i].blue  = (unsigned short) clrtab[i][N_BLU] << 8;
	}
	YStoreColors(tool_cm, image_cells, avail_image_cols);
	reset_cursor();

	/* check if user pressed cancel button */
	if (check_cancel())
	    return;

	/* get the new, mapped indices for the image colormap */
	remap_image_colormap();
    } else {
	/*
	 * Extract the RGB values from the image's colormap and allocate
	 * the appropriate X colormap entries.
	 */
	scol = 0;	/* global color counter */
	set_temp_cursor(wait_cursor);
	extract_cmap();
	for (i=0; i<scol; i++) {
	    image_cells[i].flags = DoRed|DoGreen|DoBlue;
	}
	YStoreColors(tool_cm, image_cells, scol);
	scol = 0;	/* global color counter */
	readjust_cmap();
	if (appres.DEBUG) 
	    fprintf(stderr,"Able to use %d colors without neural net\n",scol);
	reset_cursor();
    }
    put_msg(REMAP_MSG2);
    app_flush();
}
Beispiel #13
0
int get_directory(char *direct)
{

#ifdef HAVE_GETCWD
    extern char	   *getcwd(char *, size_t);

    if (getcwd(direct, PATH_MAX) == NULL) {	/* get current working dir */
	file_msg("Can't get current directory");
	beep();
#else
    extern char	   *getwd();

    if (getwd(direct) == NULL) {		/* get current working dir */
	file_msg("%s", direct);			/* err msg is in direct var */
	beep();
#endif
	*direct = '\0';
	return 0;
    }
    return 1;
}

#ifndef S_IWUSR
#define S_IWUSR 0000200
#endif /* S_IWUSR */

#ifndef S_IWGRP
#define S_IWGRP 0000020
#endif /* S_IWGRP */

#ifndef S_IWOTH
#define S_IWOTH 0000002
#endif /* S_IWOTH */

int
ok_to_write(char *file_name, char *op_name)
{
    struct stat	    file_status;
    char	    string[180];

    if (stat(file_name, &file_status) == 0) {	/* file exists */
	if (file_status.st_mode & S_IFDIR) {
	    put_msg("\"%s\" is a directory", file_name);
	    beep();
	    return 0;
	}
	if (file_status.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) {
	    /* writing is permitted by SOMEONE */
	    if (access(file_name, W_OK)) {
		put_msg("Write permission for \"%s\" is denied", file_name);
		beep();
		return 0;
	    } else {
		if (warnexist) {
		    sprintf(string, "\"%s\" already exists.\nDo you want to overwrite it?", file_name);
		    if (popup_query(QUERY_YESNO, string) != RESULT_YES) {
			put_msg("%s cancelled", op_name);
			return 0;
		    }
		} else {
		    return 1;
		}
	    }
	} else {
	    put_msg("\"%s\" is read only", file_name);
	    beep();
	    return 0;
	}
    } else {
	if (errno != ENOENT)
	    return 0;		/* file does exist but stat fails */
    }

    return  1;
}

/* for systems without basename() (e.g. SunOS 4.1.3) */
/* strip any path from filename */

char *
xf_basename(char *filename)
{
    char	   *p;
    if (filename == NULL || *filename == '\0')
	return filename;
    if (p=strrchr(filename,'/')) {
	return ++p;
    } else {
	return filename;
    }
}
Beispiel #14
0
void 
spell_check(void)
{
  char	  filename[PATH_MAX];
  char	 *cmd;
  char	  str[300];
  FILE	 *fp;
  int	  len, i;
  Boolean done = FALSE;
  static int lines = 0;

  /* turn off Compose key LED */
  setCompLED(0);

  put_msg("Spell checking...");

  /* free any strings from the previous spelling */
  for (i=0; i<lines; i++) {
    free(miss_word_list[i]);
    miss_word_list[i] = 0;
  }
  lines = 0;

  sprintf(filename, "%s/xfig-spell.%d", TMPDIR, (int)getpid());
  fp = fopen(filename, "w");
  if (fp == NULL) {
    file_msg("Can't open temporary file: %s: %s\n", filename, strerror(errno));
  } else {
    /* locate all text objects and write them to file fp */
    write_text_from_compound(fp, &objects);
    fclose(fp);

    /* replace the %f in the spellcheckcommand with the filename to check */
    cmd = build_command(appres.spellcheckcommand, filename);
    /* "spell %f", "ispell -l < %f | sort -u" or equivalent */
    fp = popen(cmd, "r");
    if (fp != NULL) {
      while (fgets(str, sizeof(str), fp) != NULL) {
        len = strlen(str);
        if (str[len - 1] == '\n') 
	    str[len - 1] = '\0';
	/* save the word in the list */
        miss_word_list[lines] = my_strdup(str);
        lines++;
	if (lines >= MAX_MISSPELLED_WORDS)
	    break;
      }
      if (pclose(fp) == 0) 
	  done = TRUE;
    }
    unlink(filename);

    /* put up the panel to show the results */
    popup_spell_check_panel(miss_word_list, lines);

    if (!done) 
	show_spell_msg("Can't exec \"%s\": %s", cmd, strerror(errno));
    else if (lines == 0) 
	show_spell_msg("No misspelled words found");
    else if (lines >= MAX_MISSPELLED_WORDS)
	show_spell_msg("%d (limit) misspelled words found. There may be more.",
				lines);
    else
	show_spell_msg("%d misspelled words found", lines);

    /* free command string allocated by build_command() */
    free(cmd);
  }

  if (!done) {
	show_spell_msg("Spell check: Internal error");
	beep();
  }
  /* make recheck button sensitive */
  XtSetSensitive(recheck_button, True);
}
Beispiel #15
0
void
DoChangeDir(char *dir)
{
    char	   *p;
    char	    ndir[PATH_MAX];

    
    if (browse_up) {
	strcpy(ndir, cur_browse_dir);
    } else if (file_up) {
	strcpy(ndir, cur_file_dir);
    } else if (export_up) {
	strcpy(ndir, cur_export_dir);
    }
    if (dir != NULL && dir[0] != '/') { /* relative path, prepend current dir */
	if (dir[strlen(dir) - 1] == '/')
	    dir[strlen(dir) - 1] = '\0';
	if (strcmp(dir, "..")==0) {	/* Parent directory. */
	    if (*ndir == '\0')
		return;			/* no current directory, */
					/* can't do anything unless absolute path */
	    p = strrchr(ndir, '/');
	    *p = EOS;
	    if (ndir[0] == EOS)
		strcpy(ndir, "/");
	} else if (strcmp(dir, ".")!=0) {
	    if (strcmp(ndir, "/"))	/* At the root already */
		strcat(ndir, "/");
	    strcat(ndir, dir);
	}
    } else {
	strcpy(ndir, dir);		/* abs path copy to ndir */
    }
    if (change_directory(ndir) != 0 ) {
	return;				/* some problem, return */
    } else if (MakeFileList(ndir, dirmask, &dirlist, &filelist) == False) {
	file_msg("Unable to list directory %s", ndir);
	return;
    }

    FirstArg(XtNstring, ndir);
    /* update the current directory and file/dir list widgets */
    if (browse_up) {
	SetValues(browse_dir);
	strcpy(cur_browse_dir,ndir);	/* update global var */
	XawTextSetInsertionPoint(browse_dir, strlen(ndir));
	NewList(browse_flist, filelist);
	NewList(browse_dlist, dirlist);
    } else if (file_up) {
	SetValues(file_dir);
	strcpy(cur_file_dir,ndir);	/* update global var */
	strcpy(cur_export_dir,ndir);	/* set export directory to file directory */
	XawTextSetInsertionPoint(file_dir, strlen(ndir));
	NewList(file_flist,filelist);
	NewList(file_dlist,dirlist);
    } else if (export_up) {
	SetValues(exp_dir);
	strcpy(cur_export_dir,ndir);	/* update global var */
	XawTextSetInsertionPoint(exp_dir, strlen(ndir));
	NewList(exp_flist, filelist);
	NewList(exp_dlist, dirlist);
    }
    CurrentSelectionName[0] = '\0';
}
Beispiel #16
0
void
create_dirinfo(Boolean file_exp, Widget parent, Widget below, Widget *ret_beside, Widget *ret_below, Widget *mask_w, Widget *dir_w, Widget *flist_w, Widget *dlist_w, int file_width, Boolean file_panel)
{
    Widget	    w,dir_alt,home;
    Widget	    file_viewport;
    Widget	    dir_viewport;
    XFontStruct	   *temp_font;
    int		    char_ht,char_wd;
    char	   *dir;

    dir_entry_cnt = NENTRIES;
    file_entry_cnt = NENTRIES;
    filelist = (char **) calloc(file_entry_cnt, sizeof(char *));
    dirlist = (char **) calloc(dir_entry_cnt, sizeof(char *));

    if (browse_up) {
	get_directory(cur_browse_dir);
	dir = cur_browse_dir;
    } else if (export_up) {
	get_directory(cur_export_dir);
	dir = cur_export_dir;
    } else {
	get_directory(cur_file_dir);
	dir = cur_file_dir;
    }

    if (file_up) {
	FirstArg(XtNlabel, "Fig files");
    } else {
	FirstArg(XtNlabel, "     Existing");
    }
    NextArg(XtNfromVert, below);
    NextArg(XtNborderWidth, 0);
    NextArg(XtNtop, XtChainTop);
    NextArg(XtNbottom, XtChainTop);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    w = XtCreateManagedWidget("file_alt_label", labelWidgetClass,
			      parent, Args, ArgCount);

    FirstArg(XtNfont, &temp_font);
    GetValues(w);
    char_ht = max_char_height(temp_font) + 2;
    char_wd = char_width(temp_font) + 2;

    /* make a viewport to hold the list widget of filenames */
    FirstArg(XtNallowVert, True);
    if (file_up) {
	/* for the file panel, put the viewport below the Alternatives label */
	NextArg(XtNfromVert, w);
	NextArg(XtNheight, char_ht * 15);	/* show first 15 filenames */
    } else {
	/* for the export or browse panel, put the viewport beside the Alternatives label */
	NextArg(XtNfromVert, below);
	NextArg(XtNfromHoriz, w);
	if (browse_up) {
	    NextArg(XtNheight, char_ht * 10);	/* show 10 lines for existing browse files */
	} else {
	    NextArg(XtNheight, char_ht * 4);	/* show 4 lines for existing export files */
	}
    }
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNwidth, file_width);
    NextArg(XtNtop, XtChainTop);		/* chain so the viewport resizes fully */
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainRight);
    file_viewport = XtCreateManagedWidget("vport", viewportWidgetClass,
					  parent, Args, ArgCount);

    /* label for filename mask */

    FirstArg(XtNlabel, "Filename Mask");
    NextArg(XtNborderWidth, 0);
    NextArg(XtNfromVert, file_viewport);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    w = XtCreateManagedWidget("mask_label", labelWidgetClass, 
				parent, Args, ArgCount);

    /* text widget for the filename mask */

    FirstArg(XtNeditType, XawtextEdit);
    NextArg(XtNleftMargin, 4);
    NextArg(XtNheight, char_ht * 2);
    NextArg(XtNscrollHorizontal, XawtextScrollWhenNeeded);
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNwidth, file_panel? F_FILE_WIDTH: E_FILE_WIDTH);
    NextArg(XtNfromHoriz, w);
    NextArg(XtNfromVert, file_viewport);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainRight);
    *mask_w = XtCreateManagedWidget("mask", asciiTextWidgetClass, 
					parent, Args, ArgCount);
    XtOverrideTranslations(*mask_w, XtParseTranslationTable(mask_text_translations));

    /* get the first directory listing */

    FirstArg(XtNstring, &dirmask);
    GetValues(*mask_w);
    if (MakeFileList(dir, dirmask, &dir_list, &file_list) == False)
	file_msg("No files in directory?");

    FirstArg(XtNlabel, "  Current Dir");
    NextArg(XtNborderWidth, 0);
    NextArg(XtNfromVert, *mask_w);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    w = XtCreateManagedWidget("dir_label", labelWidgetClass,
			      parent, Args, ArgCount);

    FirstArg(XtNstring, dir);
    NextArg(XtNleftMargin, 4);
    NextArg(XtNinsertPosition, strlen(dir));
    NextArg(XtNheight, char_ht * 2);
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNscrollHorizontal, XawtextScrollWhenNeeded);
    NextArg(XtNeditType, XawtextEdit);
    NextArg(XtNfromVert, *mask_w);
    NextArg(XtNfromHoriz, w);
    NextArg(XtNwidth, file_panel? F_FILE_WIDTH: E_FILE_WIDTH);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainRight);
    *dir_w = XtCreateManagedWidget("dir_name", asciiTextWidgetClass,
				   parent, Args, ArgCount);

    XtOverrideTranslations(*dir_w, XtParseTranslationTable(dir_translations));

    /* directory alternatives */

    FirstArg(XtNlabel, "  Directories");
    NextArg(XtNborderWidth, 0);
    NextArg(XtNfromVert, *dir_w);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    dir_alt = XtCreateManagedWidget("dir_alt_label", labelWidgetClass,
			      parent, Args, ArgCount);

    /* put a Home button to the left of the list of directories */
    FirstArg(XtNlabel, "Home");
    NextArg(XtNfromVert, dir_alt);
    NextArg(XtNfromHoriz, dir_alt);
    NextArg(XtNhorizDistance, -(char_wd * 5));
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    home = XtCreateManagedWidget("home", commandWidgetClass, parent, Args, ArgCount);
    XtAddCallback(home, XtNcallback, GoHome, (XtPointer) NULL);

    /* put a button for showing/hiding hidden files below the Home button */

    FirstArg(XtNlabel, show_hidden? "Hide Hidden": "Show Hidden");
    NextArg(XtNfromVert, home);
    NextArg(XtNfromHoriz, dir_alt);
    NextArg(XtNhorizDistance, (int) -(char_wd * 10.5));
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    hidden = XtCreateManagedWidget("hidden", commandWidgetClass, 
				parent, Args, ArgCount);
    XtAddCallback(hidden, XtNcallback, ShowHidden, (XtPointer) NULL);

    FirstArg(XtNallowVert, True);
    NextArg(XtNforceBars, True);
    NextArg(XtNfromHoriz, dir_alt);
    NextArg(XtNfromVert, *dir_w);
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNwidth, file_panel? F_FILE_WIDTH: E_FILE_WIDTH);
    NextArg(XtNheight, char_ht * 5);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainRight);
    dir_viewport = XtCreateManagedWidget("dirvport", viewportWidgetClass,
					 parent, Args, ArgCount);

    FirstArg(XtNlist, file_list);
    /* for file panel use only one column */
    if (file_panel) {
	NextArg(XtNdefaultColumns, 1);
	NextArg(XtNforceColumns, True);
    }
    *flist_w = XtCreateManagedWidget("file_list_panel", figListWidgetClass,
				     file_viewport, Args, ArgCount);
    XtAddCallback(*flist_w, XtNcallback, FileSelected, (XtPointer) NULL);
    XtOverrideTranslations(*flist_w,
			   XtParseTranslationTable(list_panel_translations));

    FirstArg(XtNlist, dir_list);
    *dlist_w = XtCreateManagedWidget("dir_list_panel", figListWidgetClass,
				     dir_viewport, Args, ArgCount);
    XtOverrideTranslations(*dlist_w,
			   XtParseTranslationTable(list_panel_translations));

    XtAddCallback(*dlist_w, XtNcallback, DirSelected, (XtPointer) NULL);

    if (!actions_added) {
	XtAppAddActions(tool_app, actionTable, XtNumber(actionTable));
	actions_added = True;
    }

    FirstArg(XtNlabel, "Rescan");
    NextArg(XtNfromVert, dir_viewport);
    NextArg(XtNvertDistance, 15);
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNhorizDistance, 45);
    NextArg(XtNheight, 25);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    w = XtCreateManagedWidget("rescan", commandWidgetClass, parent,
			      Args, ArgCount);
    XtAddCallback(w, XtNcallback, CallbackRescan, (XtPointer) NULL);

    /* install accelerators so they can be used from each window */
    XtInstallAccelerators(parent, w);
    XtInstallAccelerators(*flist_w, parent);
    XtInstallAccelerators(*dlist_w, parent);

    *ret_beside = w;
    *ret_below = dir_viewport;

    return;
}