ngspice/src/frontend/com_hardcopy.c

213 lines
5.5 KiB
C
Raw Normal View History

#include "ngspice/config.h"
#include <stdio.h>
#include "ngspice/ngspice.h"
#include "ngspice/defines.h"
#include "ngspice/bool.h"
#include "ngspice/wordlist.h"
#include "ngspice/cpdefs.h"
#include "ngspice/fteinput.h"
#include "ngspice/ftedev.h"
#include "ngspice/ftedbgra.h"
#include "plotting/plotit.h"
#include "plotting/graphdb.h"
#include "plotting/graf.h"
2010-10-15 20:11:11 +02:00
#include "../misc/mktemp.h"
#include "arg.h"
#include "display.h"
#include "com_hardcopy.h"
src/Makefile.am src/help.c src/main.c src/circuit/Makefile.am src/circuit/ifnewuid.c src/frontend/Makefile.am src/frontend/aspice.c src/frontend/circuits.h src/frontend/com_display.c src/frontend/com_hardcopy.c src/frontend/commands.c src/frontend/commands.h src/frontend/cpitf.c src/frontend/debugcom.c src/frontend/device.c src/frontend/diff.c src/frontend/display.c src/frontend/dotcards.c src/frontend/fourier.c src/frontend/inp.c src/frontend/inpcom.c src/frontend/linear.c src/frontend/misccoms.c src/frontend/mw_coms.c src/frontend/nutinp.c src/frontend/options.c src/frontend/outitf.c src/frontend/parse.c src/frontend/postcoms.c src/frontend/postsc.c src/frontend/rawfile.c src/frontend/resource.c src/frontend/runcoms.c src/frontend/runcoms2.c src/frontend/shyu.c src/frontend/spec.c src/frontend/spiceif.c src/frontend/subckt.c src/frontend/vectors.c src/frontend/where.c src/frontend/plotting/Makefile.am src/frontend/plotting/agraf.c src/frontend/plotting/graf.c src/frontend/plotting/plotcurv.c src/frontend/plotting/plotit.c src/frontend/plotting/x11.c src/frontend/plotting/xgraph.c src/include/Makefile.am src/maths/cmaths/cmath4.c src/misc/terminal.c src/misc/terminal.h src/parser/cshpar.c src/parser/front.c src/parser/front.h src/parser/history.c src/parser/history.h src/parser/modify.c src/parser/var2.c src/parser/var2.h src/parser/variable.c: Refactoring of frontend code. * src/include/ftehelp.h src/include/variable.h: Moved into frontend directory. * src/include/cpdefs.h src/include/cpextern.h src/include/ftedefs.h src/include/plot.h: Updates.
2000-06-27 18:09:02 +02:00
#include "variable.h"
/* hardcopy file plotargs, or 'hardcopy file' -- with no other args
* this prompts the user for a window to dump to a plot file. XXX no
* it doesn't. */
void
com_hardcopy(wordlist *wl)
{
char *fname;
char buf[BSIZE_SP], device[BSIZE_SP];
bool tempf = FALSE;
char *devtype;
2007-11-28 18:29:28 +01:00
#if defined(SYSTEM_PLOT5LPR) || defined(SYSTEM_PSLPR)
char format[513];
2007-11-28 18:29:28 +01:00
#endif
int printed;
int hc_button;
int foundit;
if (!cp_getvar("hcopydev", CP_STRING, device))
*device = '\0';
if (wl) {
2009-11-29 16:09:13 +01:00
hc_button = 0;
fname = wl->wl_word;
wl = wl->wl_next;
} else {
2009-11-29 16:09:13 +01:00
hc_button = 1;
fname = smktemp("hc");
tempf = TRUE;
}
if (!cp_getvar("hcopydevtype", CP_STRING, buf)) {
2009-11-29 16:09:13 +01:00
devtype = "postscript";
} else {
devtype = buf;
}
/* enable screen plot selection for these display types */
foundit = 0;
2009-11-29 16:09:13 +01:00
// PushGraphContext(currentgraph);
2009-11-29 16:09:13 +01:00
#ifdef HAS_WINDOWS
if (!wl && hc_button) {
char* psfname;
GRAPH *tempgraph;
if (DevSwitch(devtype)) return;
2009-11-29 16:09:13 +01:00
tempgraph = CopyGraph(currentgraph);
/* change .tmp to .ps */
2010-05-30 19:17:50 +02:00
psfname = strchr(fname, '.');
if(psfname)
{
*(psfname + 1) = 'p';
*(psfname + 2) = 's';
*(psfname + 3) = '\0';
}
else
{
fname=realloc(fname,strlen(fname)+4);
strcat(fname,".ps");
}
tempgraph->devdep = fname;
if (NewViewport(tempgraph)) {
2009-11-29 16:09:13 +01:00
DevSwitch(NULL);
return;
}
gr_resize(tempgraph);
gr_redraw(tempgraph);
DestroyGraph(tempgraph->graphid);
DevSwitch(NULL);
foundit = 1;
}
#endif
2009-11-29 16:09:13 +01:00
#ifndef X_DISPLAY_MISSING
if (!wl && hc_button) {
2009-11-29 16:09:13 +01:00
REQUEST request;
RESPONSE response;
GRAPH *tempgraph;
request.option = click_option;
Input(&request, &response);
if (response.option == error_option) return;
2009-11-29 16:09:13 +01:00
if (response.reply.graph) {
if (DevSwitch(devtype)) return;
tempgraph = CopyGraph(response.reply.graph);
tempgraph->devdep = fname;
if (NewViewport(tempgraph)) {
DevSwitch(NULL);
return;
}
2010-01-17 20:06:03 +01:00
/* save current graphics context */
PushGraphContext(currentgraph);
currentgraph = tempgraph;
/* some operations in gr_resize, gr_redraw, and DevSwitch
will be done on currentgraph, not only on tempgraph */
2009-11-29 16:09:13 +01:00
gr_resize(tempgraph);
gr_redraw(tempgraph);
2010-01-17 20:06:03 +01:00
DevSwitch(NULL);
/* retrieve current graphics context */
PopGraphContext();
2009-11-29 16:09:13 +01:00
DestroyGraph(tempgraph->graphid);
foundit = 1;
}
}
2009-11-29 16:09:13 +01:00
#endif
2009-11-29 16:09:13 +01:00
/* save current graphics context, because plotit() will create a new
currentgraph */
PushGraphContext(currentgraph);
2009-11-29 16:09:13 +01:00
if (!foundit) {
2009-11-29 16:09:13 +01:00
if (!wl) {
2011-07-17 18:40:34 +02:00
char *buf2;
2009-11-29 16:09:13 +01:00
outmenuprompt("which variable ? ");
2011-07-17 18:40:34 +02:00
buf2 = prompt(cp_in);
if (!buf2)
2009-11-29 16:09:13 +01:00
return;
2012-07-27 21:36:15 +02:00
wl = wl_cons(buf2, NULL);
2009-11-29 16:09:13 +01:00
wl = process(wl);
}
if (DevSwitch(devtype)) return;
2011-04-28 17:59:36 +02:00
if (!wl || !plotit(wl, fname, NULL)) {
2009-11-29 16:09:13 +01:00
printf("com_hardcopy: graph not defined\n");
DevSwitch(NULL); /* remember to switch back */
return;
}
DevSwitch(NULL);
}
printed = 0;
if (*device) {
#ifdef SYSTEM_PLOT5LPR
2009-11-29 16:09:13 +01:00
if (!strcmp(devtype, "plot5") || !strcmp(devtype, "MFB")) {
if (!cp_getvar("lprplot5", CP_STRING, format))
2009-11-29 16:09:13 +01:00
strcpy(format, SYSTEM_PLOT5LPR);
(void) sprintf(buf, format, device, fname);
fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device);
(void) system(buf);
printed = 1;
}
#endif
#ifdef SYSTEM_PSLPR
2009-11-29 16:09:13 +01:00
if (!printed && !strcmp(devtype, "postscript")) {
/* note: check if that was a postscript printer XXX */
if (!cp_getvar("lprps", CP_STRING, format))
2009-11-29 16:09:13 +01:00
strcpy(format, SYSTEM_PSLPR);
(void) sprintf(buf, format, device, fname);
fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device);
(void) system(buf);
printed = 1;
}
#endif
}
if (!printed) {
2009-11-29 16:09:13 +01:00
if (!strcmp(devtype, "plot5")) {
fprintf(cp_out,
"The file \"%s\" may be printed with the Unix \"plot\" command,\n",
fname);
2009-11-29 16:09:13 +01:00
fprintf(cp_out,
"\tor by using the '-g' flag to the Unix lpr command.\n");
} else if (!strcmp(devtype, "postscript")) {
fprintf(cp_out,
"\nThe file \"%s\" may be printed on a postscript printer.\n",
fname);
} else if (!strcmp(devtype, "MFB")) {
fprintf(cp_out,
"The file \"%s\" may be printed on a MFB device.\n",
fname);
}
}
if (tempf && *device)
(void) unlink(fname);
/* restore previous graphics context by retrieving the previous currentgraph */
PopGraphContext();
return;
}