Exemple #1
0
static void
UpdateIndex(PLStream *pls, FPOS_T cp_offset)
{
    PLmDev *dev = (PLmDev *) pls->dev;
    FILE *file = pls->OutFile;

/* Update file index.  Right now only number of pages. */
/* The ordering here is critical */

    if (dev->index_offset > 0) {
	pldebug("UpdateIndex (plmeta.c)",
		"Location: %d, seeking to: %d\n",
		(int) cp_offset, (int) dev->lp_offset);

	if (pl_fsetpos(file, &dev->index_offset)) {
	    sprintf(buffer, "UpdateIndex (plmeta.c): fsetpos to index_offset (%d) failed",
		    (int) dev->index_offset);
	    plexit(buffer);
	}
	plm_wr( pdf_wr_header(pls->pdfs, "pages") );
	plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->page) );

	pldebug("UpdateIndex (plmeta.c)",
		"Location: %d, seeking to: %d\n",
		(int) dev->lp_offset, (int) cp_offset);

	if (pl_fsetpos(file, &cp_offset)) {
	    sprintf(buffer, "UpdateIndex (plmeta.c): fsetpos to cp_offset (%d) failed",
		    (int) cp_offset);
	    plexit(buffer);
	}
    }
}
Exemple #2
0
void
plD_line_plm(PLStream *pls, short x1, short y1, short x2, short y2)
{
    PLmDev *dev = (PLmDev *) pls->dev;
    U_CHAR c;
    U_SHORT xy[4];

    /* dbug_enter("plD_line_plm"); */

    /* Failsafe check */

#ifdef DEBUG
    if (x1 < dev->xmin || x1 > dev->xmax ||
	x2 < dev->xmin || x2 > dev->xmax ||
	y1 < dev->ymin || y1 > dev->ymax ||
	y2 < dev->ymin || y2 > dev->ymax) {

	pldebug("plD_line_plm",
		"coordinates out of bounds -- \nActual: (%i,%i), (%i,%i) Bounds: (%i,%i,%i,%i)\n", 
		x1, y1, x2, y2, dev->xmin, dev->xmax, dev->ymin, dev->ymax);
    }
#endif

/* If continuation of previous line send the LINETO command, which uses
   the previous (x,y) point as it's starting location.  This results in a
   storage reduction of not quite 50%, since the instruction length for
   a LINETO is 5/9 of that for the LINE command, and given that most
   graphics applications use this command heavily.

   Still not quite as efficient as tektronix format since we also send the
   command each time (so shortest command is 25% larger), but a lot easier
   to implement than the tek method.  
 */
    if (x1 == dev->xold && y1 == dev->yold) {

	c = (U_CHAR) LINETO;
	plm_wr( pdf_wr_1byte(pls->pdfs, c) );

	xy[0] = x2;
	xy[1] = y2;
	plm_wr( pdf_wr_2nbytes(pls->pdfs, xy, 2) );
    }
    else {
	c = (U_CHAR) LINE;
	plm_wr( pdf_wr_1byte(pls->pdfs, c) );

	xy[0] = x1;
	xy[1] = y1;
	xy[2] = x2;
	xy[3] = y2;
	plm_wr( pdf_wr_2nbytes(pls->pdfs, xy, 4) );
    }
    dev->xold = x2;
    dev->yold = y2;
}
Exemple #3
0
void
plOpenFile(PLStream *pls)
{
    int i = 0, count = 0;
    size_t len;
    char line[256];

    while (pls->OutFile == NULL) {

/* Setting pls->FileName = NULL forces creation of a new family member */
/* You should also free the memory associated with it if you do this */

	if (pls->family && pls->BaseName != NULL)
	    plP_getmember(pls);

/* Prompt if filename still not known */

	if (pls->FileName == NULL) {
	    do {
		fprintf(stdout, "Enter graphics output file name: ");
		fgets(line, sizeof(line), stdin);
		len = strlen(line);
		if (len)
		    len--;
		line[len] = '\0';	/* strip new-line */
		count++;		/* count zero entries */
	    } while (!len && count < MAX_NUM_TRIES);
	    plP_sfnam(pls, line);
	}

/* If name is "-", send to stdout */

	if ( ! strcmp(pls->FileName, "-")) {
	    pls->OutFile = stdout;
	    pls->output_type = 1;
	    break;
	}

/* Need this here again, for prompted family initialization */

	if (pls->family && pls->BaseName != NULL)
	    plP_getmember(pls);

	if (i++ > 10)
	    plexit("Too many tries.");

	if ((pls->OutFile = fopen(pls->FileName, "wb+")) == NULL)
	    fprintf(stderr, "Can't open %s.\n", pls->FileName);
	else
	    pldebug("plOpenFile", "Opened %s\n", pls->FileName);
    }
}
Exemple #4
0
static void PrintLocation(PLStream *pls, char *tag)
{
    int isfile = (pls->output_type == 0);
    if (isfile) {
	FILE *file = pls->OutFile;
	FPOS_T current_offset;

	if (pl_fgetpos(file, &current_offset))
	    plexit("PrintLocation (plmeta.c): fgetpos call failed");

	pldebug(tag, "at offset %d in file %s\n",
		(int) current_offset, pls->FileName);
    }
}
Exemple #5
0
int
plFindName(char *p)
{
    int n;
    char buf[1024], *cp;
    /*extern int errno;*/			/* pmr: redundant */
    struct stat sbuf;

    pldebug("plFindName", "Trying to find %s\n", p);
    while ((n = readlink(p, buf, 1024)) > 0) {
	pldebug("plFindName", "Readlink read %d chars at: %s\n", n, p);
	if (buf[0] == '/') {
	/* Link is an absolute path */

	    strncpy(p, buf, n);
	    p[n] = '\0';
	    pldebug("plFindName", "Link is absolute: %s\n", p);
	}
	else {
	/* Link is relative to its directory; make it absolute */

	    cp = 1 + strrchr(p, '/');
	    strncpy(cp, buf, n);
	    cp[n] = '\0';
	    pldebug("plFindName",
		    "Link is relative: %s\n\tTotal path:%s\n", cp, p);
	}
    }

/* This macro not defined on the NEC SX-3 */

#ifdef SX
#define S_ISREG(mode)   (mode & S_IFREG)
#endif

/* SGI machines return ENXIO instead of EINVAL Dubois 11/92 */

    if (errno == EINVAL || errno == ENXIO) {
	pldebug("plFindName", "%s may be the one...\n", p);
	if ((stat(p, &sbuf) == 0) && S_ISREG(sbuf.st_mode)) {
	    pldebug("plFindName", "%s is a regular file\n", p);
	    return (access(p, X_OK));
	}
    }
    pldebug("plFindName", "%s found but is not executable\n", p);
    return (errno ? errno : -1);
}
Exemple #6
0
/*
 * Plot an individual vector
 */
static void
plP_plotvect(PLFLT x, PLFLT y, PLFLT u, PLFLT v, PLFLT scale) {
	
    PLFLT uu, vv, px0, py0, dpx, dpy;
    PLINT *a_x, *a_y;
    int j;

    uu = scale*u;
    vv = scale*v;

    if(uu == 0.0 && vv == 0.0) return;

    if (((a_x = (PLINT *)malloc(sizeof(PLINT)*(plsc->arrow_npts)))==NULL)||
        ((a_y = (PLINT *)malloc(sizeof(PLINT)*(plsc->arrow_npts)))==NULL))
        {
          plexit("plP_plotvect: Insufficient memory");
        }

    px0 = plP_wcpcx(x);
    py0 = plP_wcpcy(y);

    pldebug("plP_plotvect", "%f %f %d %d\n",x,y,px0,py0);

    dpx = plP_wcpcx(x + 0.5*uu) - px0;
    dpy = plP_wcpcy(y + 0.5*vv) - py0;

    /* transform arrow -> a */

    for (j = 0; j < plsc->arrow_npts; j++) {
        a_x[j] = (PLINT)(plsc->arrow_x[j] * dpx - plsc->arrow_y[j] * dpy + px0);
	a_y[j] = (PLINT)(plsc->arrow_x[j] * dpy + plsc->arrow_y[j] * dpx + py0);
    }

    /* draw the arrow */
    plP_draphy_poly(a_x,a_y,plsc->arrow_npts);
    if (plsc->arrow_fill) {
	plP_plfclp(a_x, a_y, plsc->arrow_npts, plsc->clpxmi, plsc->clpxma,
	plsc->clpymi, plsc->clpyma, plP_fill);
    }

    free((void *)a_x);
    free((void *)a_y);

}
Exemple #7
0
static void
plbuf_control(PLStream *pls, U_CHAR c)
{
    static U_CHAR c_old = 0;

    dbug_enter("plbuf_control");

    switch ((int) c) {

    case INITIALIZE:
	rdbuf_init(pls);
	break;

    case EOP:
	rdbuf_eop(pls);
	break;

    case BOP:
	rdbuf_bop(pls);
	break;

    case CHANGE_STATE:
	rdbuf_state(pls);
	break;

    case LINE:
	rdbuf_line(pls);
	break;

    case POLYLINE:
	rdbuf_polyline(pls);
	break;

    case ESCAPE:
	rdbuf_esc(pls);
	break;

    default:
      pldebug("plbuf_control", "Unrecognized command %d, previous %d\n", c, c_old);
    }
    c_old = c;
}
Exemple #8
0
PDFstrm *
plLibOpenPdfstrm(const char *fn)		/* pmr: const */
{
    PDFstrm *file;
    char *fs = NULL, *dn = NULL;

#ifndef WIN32
    /* EMBOSS additions to avoid need for PLPLOT_LIB */
    static const char *prefix = PREFIX;
    static const char *top    = EMBOSS_TOP;
    
    if(!strcmp(prefix,"/usr/local"))
    {
        plGetName(prefix, "share/EMBOSS", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;

        plGetName(top, "plplot/lib", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;
    }
    else
    {
        plGetName(prefix, "share/EMBOSS", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;
    }
    /* End of EMBOSS additions */
#endif

/****   search build tree               ****/

    if (plInBuildTree() == 1) {
      plGetName(BUILD_DIR, "data", fn, &fs);

      if ((file = pdf_fopen(fs, "rb")) != NULL)
        goto done;
    }

/****	search PLPLOT_LIB_ENV = $(EPLPLOT_LIB)	****/

#if defined(PLPLOT_LIB_ENV)
    if ((dn = getenv(PLPLOT_LIB_ENV)) != NULL) {
        plGetName(dn, "", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;

        fprintf(stderr, PLPLOT_LIB_ENV"=\"%s\"\n", dn); /* what IS set? */
    }
#endif  /* PLPLOT_LIB_ENV */

/****	search current directory	****/

    if ((file = pdf_fopen(fn, "rb")) != NULL)
        goto done;

/****	search PLPLOT_HOME_ENV/lib = $(EPLPLOT_HOME)/lib	****/

#if defined (PLPLOT_HOME_ENV)
    if ((dn = getenv(PLPLOT_HOME_ENV)) != NULL) {
        plGetName(dn, "lib", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;
        fprintf(stderr, PLPLOT_HOME_ENV"=\"%s\"\n",dn); /* what IS set? */
    }
#endif  /* PLPLOT_HOME_ENV/lib */

/**** 	search installed location	****/

#if defined (DATA_DIR)
    plGetName(DATA_DIR, "", fn, &fs);

    if ((file = pdf_fopen(fs, "rb")) != NULL)
        goto done;
#endif  /* DATA_DIR */

/**** 	search hardwired location	****/

#ifdef PLLIBDEV
    plGetName(PLLIBDEV, "", fn, &fs);

    if ((file = pdf_fopen(fs, "rb")) != NULL)
	goto done;
#endif	/* PLLIBDEV */

#ifdef macintosh
    file = plMacLibOpen(fn);
    if (file != NULL)
        goto done;
#endif /* macintosh */

    if (plplotLibDir != NULL) {
	plGetName(plplotLibDir, "", fn, &fs);
	if ((file = pdf_fopen(fs, "rb")) != NULL)
	    goto done;

    }

/**** 	not found, give up 	****/
    pldebug("plLibOpenPdfstr", "File %s not found.\n", fn);
    return NULL;

 done:
    /* pldebug("plLibOpenPdfstr", "Found file %s\n", fs); */
    free_mem(fs);
    return (file);
}
Exemple #9
0
SHPHandle
OpenShapeFile( const char *fn )
{
    SHPHandle file;
    char      *fs = NULL, *dn = NULL;
#ifdef HAVE_SAHOOKS
    SAHooks   sHooks;

    SASetupDefaultHooks( &sHooks );
    sHooks.Error = CustomErrors;
#else
    // Using ancient version of shapelib without SAHooks or SHPOpenLL.
    // For this case live with the misleading "Unable to open" error
    // messages.
    // int sHooks;
#define SHPOpenLL( a, b, c )    SHPOpen( a, b )
#endif

//***   search build tree               ***

    if ( plInBuildTree() == 1 )
    {
        plGetName( SOURCE_DIR, "data", fn, &fs );

        if ( ( file = SHPOpenLL( fs, "rb", &sHooks ) ) != NULL )
            goto done;
    }

//***	search PLPLOT_LIB_ENV = $(PLPLOT_LIB)	***

#if defined ( PLPLOT_LIB_ENV )
    if ( ( dn = getenv( PLPLOT_LIB_ENV ) ) != NULL )
    {
        plGetName( dn, "", fn, &fs );

        if ( ( file = SHPOpenLL( fs, "rb", &sHooks ) ) != NULL )
            goto done;
        fprintf( stderr, PLPLOT_LIB_ENV "=\"%s\"\n", dn ); // what IS set?
    }
#endif  // PLPLOT_LIB_ENV

//***	search current directory	***

    if ( ( file = SHPOpenLL( fn, "rb", &sHooks ) ) != NULL )
    {
        pldebug( "OpenShapeFile", "Found file %s in current directory.\n", fn );
        free_mem( fs );
        return ( file );
    }

//***	search PLPLOT_HOME_ENV/lib = $(PLPLOT_HOME)/lib	***

#if defined ( PLPLOT_HOME_ENV )
    if ( ( dn = getenv( PLPLOT_HOME_ENV ) ) != NULL )
    {
        plGetName( dn, "lib", fn, &fs );

        if ( ( file = SHPOpenLL( fs, "rb", &sHooks ) ) != NULL )
            goto done;
        fprintf( stderr, PLPLOT_HOME_ENV "=\"%s\"\n", dn ); // what IS set?
    }
#endif  // PLPLOT_HOME_ENV/lib

//***   search installed location	***

#if defined ( DATA_DIR )
    plGetName( DATA_DIR, "", fn, &fs );

    if ( ( file = SHPOpenLL( fs, "rb", &sHooks ) ) != NULL )
        goto done;
#endif  // DATA_DIR

//***   search hardwired location	***

#ifdef PLLIBDEV
    plGetName( PLLIBDEV, "", fn, &fs );

    if ( ( file = SHPOpenLL( fs, "rb", &sHooks ) ) != NULL )
        goto done;
#endif  // PLLIBDEV

//***   not found, give up      ***
    pldebug( "OpenShapeFile", "File %s not found.\n", fn );
    free_mem( fs );
    return NULL;

done:
    pldebug( "OpenShapeFile", "SHPOpen successfully opened two files with basename %s\n", fs );
    free_mem( fs );
    return ( file );
}
Exemple #10
0
PDFstrm *
plLibOpenPdfstrm(char *fn)
{
    PDFstrm *file;
    char *fs = NULL, *dn = NULL;

/****   search build tree               ****/

    if (plInBuildTree() == 1) {
      plGetName(BUILD_DIR, "data", fn, &fs);

      if ((file = pdf_fopen(fs, "rb")) != NULL)
        goto done;
    }

/****	search PLPLOT_LIB_ENV = $(PLPLOT_LIB)	****/

#if defined(PLPLOT_LIB_ENV)
    if ((dn = getenv(PLPLOT_LIB_ENV)) != NULL) {
        plGetName(dn, "", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;

        fprintf(stderr, PLPLOT_LIB_ENV"=\"%s\"\n", dn); /* what IS set? */
    }
#endif  /* PLPLOT_LIB_ENV */

/****	search current directory	****/

    if ((file = pdf_fopen(fn, "rb")) != NULL)
        goto done;

/****	search PLPLOT_HOME_ENV/lib = $(PLPLOT_HOME)/lib	****/

#if defined (PLPLOT_HOME_ENV)
    if ((dn = getenv(PLPLOT_HOME_ENV)) != NULL) {
        plGetName(dn, "lib", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;
        fprintf(stderr, PLPLOT_HOME_ENV"=\"%s\"\n",dn); /* what IS set? */
    }
#endif  /* PLPLOT_HOME_ENV/lib */

/**** 	search installed location	****/

#if defined (DATA_DIR)
    plGetName(DATA_DIR, "", fn, &fs);

    if ((file = pdf_fopen(fs, "rb")) != NULL)
        goto done;
#endif  /* DATA_DIR */

/**** 	search hardwired location	****/

#ifdef PLLIBDEV
    plGetName(PLLIBDEV, "", fn, &fs);

    if ((file = pdf_fopen(fs, "rb")) != NULL)
	goto done;
#endif	/* PLLIBDEV */

#ifdef macintosh
    file = plMacLibOpen(fn);
    if (file != NULL)
        goto done;
#endif /* macintosh */

    if (plplotLibDir != NULL) {
	plGetName(plplotLibDir, "", fn, &fs);
	if ((file = pdf_fopen(fs, "rb")) != NULL)
	    goto done;

    }

/**** 	not found, give up 	****/
    pldebug("plLibOpenPdfstr", "File %s not found.\n", fn);
    return NULL;

 done:
    pldebug("plLibOpenPdfstr", "Found file %s\n", fs);
    free_mem(fs);
    return (file);
}
Exemple #11
0
static void
UpdatePrevPagehdr(PLStream *pls)
{
    PLmDev *dev = (PLmDev *) pls->dev;
    FILE *file = pls->OutFile;
    FPOS_T cp_offset=0;

    fflush(file);

/* Determine where we are */

    if (pl_fgetpos(file, &cp_offset))
	plexit("plD_bop_plm: fgetpos call failed");

/* Seek back to previous page header. */

    if (dev->lp_offset > 0) {
	FPOS_T fwbyte_offset=0;

	pldebug("UpdatePrevPagehdr 1 (plmeta.c)",
		"Location: %d, seeking to: %d\n",
		(int) cp_offset, (int) dev->lp_offset);

    /* The forward byte offset is located exactly 7 bytes after the BOP */
	fwbyte_offset = dev->lp_offset + 7;
	if (pl_fsetpos(file, &fwbyte_offset)) {
	    sprintf(buffer, "UpdatePrevPagehdr (plmeta.c): fsetpos to fwbyte_offset (%d) failed",
		    (int) fwbyte_offset);
	    plexit(buffer);
	}

    /* DEBUG: verify current location */

#ifdef DEBUG
	if (pl_fgetpos(file, &fwbyte_offset))
	    plexit("UpdatePrevPagehdr (plmeta.c): fgetpos call failed");

	pldebug("UpdatePrevPagehdr 2 (plmeta.c)",
		"Now at: %d, to write: %d\n", 
		(int) fwbyte_offset, (int) cp_offset);
#endif

    /* Write forward byte offset into previous page header. */

	plm_wr( pdf_wr_4bytes(pls->pdfs, (U_LONG) cp_offset) );
	fflush(file);

    /* DEBUG: move back to before the write & read it to verify */

#ifdef DEBUG
	if (pl_fsetpos(file, &fwbyte_offset)) {
	    sprintf(buffer, "UpdatePrevPagehdr (plmeta.c): fsetpos to fwbyte_offset (%d) failed",
		    (int) fwbyte_offset);
	    plexit(buffer);
	}
	{
	    U_LONG read_offset;
	    plm_rd(pdf_rd_4bytes(pls->pdfs, &read_offset));
	    pldebug("UpdatePrevPagehdr 3 (plmeta.c)",
		    "Value read as: %d\n", read_offset);
	}
#endif

    /* Return to current page offset */

	if (pl_fsetpos(file, &cp_offset)) {
	    sprintf(buffer, "UpdatePrevPagehdr (plmeta.c): fsetpos to cp_offset (%d) failed",
		    (int) cp_offset);
	    plexit(buffer);
	}
    }
}