void wheel2(const char *fn, int nres, char *resnm[], real rot0, char *title) { const real fontsize = 14; const real gray = 0.9; const real fontasp = 0.45; const int angle = 9; const real fontwidth = fontsize*fontasp; t_psdata out; int i, slen; real ring, inner, outer; real xc, yc, box; inner = 60.0; slen = 0; for (i = 0; (i < nres); i++) { slen = std::max(slen, static_cast<int>(strlen(resnm[i]))); } fprintf(stderr, "slen = %d\n", slen); ring = slen*fontwidth; outer = inner+ring; box = (1+(nres / (2*angle)))*outer; out = ps_open(fn, 0, 0, 2.0*box, 2.0*box); xc = box; yc = box; ps_font(out, efontHELV, 1.5*fontsize); ps_translate(out, xc, yc); ps_color(out, 0, 0, 0); if (title) { ps_ctext(out, 0, -fontsize*1.5/2.0, title, eXCenter); } ps_font(out, efontHELV, fontsize); ps_rotate(out, rot0); for (i = 0; (i < nres); ) { if ((i % 5) == 4) { ps_color(out, gray, gray, 1.0); ps_fillarcslice(out, 0, 0, inner, outer, -angle, angle); ps_color(out, 0, 0, 0); } ps_arcslice(out, 0, 0, inner, outer, -angle, angle); ps_ctext(out, inner+fontwidth, -fontsize/2.0, resnm[i], eXLeft); ps_rotate(out, -2*angle); i++; if ((i % (2*angle)) == 0) { inner = outer; outer += ring; } } ps_close(out); }
static void dump_it(t_manager *man) { t_psdata ps; ps = ps_open("view.ps", 0, 0, man->molw->wd.width, man->molw->wd.height); ps_draw_mol(ps, man); ps_close(ps); }
int pcpverify(char *infile, char *sigfile, char *id, int detach) { FILE *in = NULL; FILE *sigfd = NULL; pcp_pubkey_t *pub = NULL; if(infile == NULL) in = stdin; else { if((in = fopen(infile, "rb")) == NULL) { fatal(ptx, "Could not open input file %s\n", infile); goto errv1; } } if(sigfile != NULL) { if((sigfd = fopen(sigfile, "rb")) == NULL) { fatal(ptx, "Could not open signature file %s\n", sigfile); goto errv1; } } if(id != NULL) pub = pcphash_pubkeyexists(ptx, id); Pcpstream *pin = ps_new_file(in); if(detach) { Pcpstream *psigfd = ps_new_file(sigfd); pub = pcp_ed_detachverify_buffered(ptx, pin, psigfd, pub); ps_close(psigfd); } else pub = pcp_ed_verify_buffered(ptx, pin, pub); ps_close(pin); if(pub != NULL) fprintf(stderr, "Signature verified (signed by %s <%s>).\n", pub->owner, pub->mail); errv1: return 1; }
int array_print(char *filename, char *xtitle, char *ytitle, char *bottom, int nacross, int ndown, int col0, int row0, int nskip, int ncskip, int maxrow, int maxcol, float **data, double zmin, double zmax, double tlo, double thi, int type) { float xx, yy; xx = (float)ndown; yy = (float)(nacross / ncskip); my_plot_file = fopen(filename, "w"); if (my_plot_file == NULL) { return -1; } ps_begin(0.0, 0.0, xx, yy, 10., 7.); ps_replot(data, col0, row0, nskip, ncskip, maxrow, maxcol, nacross, ndown, zmin, zmax, type); ps_boxit(tlo, thi, 0.0, yy, zmin, zmax, xtitle, ytitle, bottom, type); ps_close(); return 0; }
int main(int argc, char* argv[]) { HPSCRIPTVM v; PSInteger retval = 0; #if defined(_MSC_VER) && defined(_DEBUG) _CrtSetAllocHook(MemAllocHook); #endif v=ps_open(1024); ps_setprintfunc(v,printfunc,errorfunc); ps_pushroottable(v); psstd_register_bloblib(v); psstd_register_iolib(v); psstd_register_systemlib(v); psstd_register_mathlib(v); psstd_register_stringlib(v); psstd_register_exutillib(v); //aux library //sets error handlers psstd_seterrorhandlers(v); //gets arguments switch(getargs(v,argc,argv,&retval)) { case _INTERACTIVE: Interactive(v); break; case _DONE: case _ERROR: default: break; } ps_close(v); #if defined(_MSC_VER) && defined(_DEBUG) _getch(); _CrtMemDumpAllObjectsSince( NULL ); #endif return retval; }
void plot_phi(char *fn,rvec box,int natoms,rvec x[],real phi[]) { t_psdata eps; real phi_max,rr,gg,bb,fac,dx,x0,y0; real offset; int i; phi_max=phi[0]; rr=gg=bb=0.0; for(i=0; (i<natoms); i++) phi_max=max(phi_max,fabs(phi[i])); if (phi_max==0.0) { fprintf(stderr,"All values zero, see .out file\n"); return; } offset=20.0; fac=15.0; #ifdef DEBUG fprintf(stderr,"Scaling box by %g\n",fac); #endif eps=ps_open(fn,0,0, (real)(fac*box[XX]+2*offset),(real)(fac*box[YY]+2*offset)); ps_translate(eps,offset,offset); ps_color(eps,0,0,0); ps_box(eps,1,1,(real)(fac*box[XX]-1),(real)(fac*box[YY]-1)); dx=0.15*fac; for(i=0; (i<natoms); i++) { rr=gg=bb=1.0; if (phi[i] < 0) gg=bb=(1.0+(phi[i]/phi_max)); else rr=gg=(1.0-(phi[i]/phi_max)); rr=rgbset(rr); gg=rgbset(gg); bb=rgbset(bb); ps_color(eps,rr,gg,bb); x0=fac*x[i][XX]; y0=fac*x[i][YY]; ps_fillbox(eps,(real)(x0-dx),(real)(y0-dx),(real)(x0+dx),(real)(y0+dx)); } ps_close(eps); }
void utility_tools(long val) #endif { FILE *fd ; #if defined(SGI_GL) && defined(GL_NASA) long val = g_get_choice_val( ap, &choices[3] ) ; #endif switch( val ) { case CHOICE_UTIL_PS: /* Open PS file */ ps_open( "radiosity.ps" ) ; /* Change the view */ ps_setup_view( DFLT_VIEW_ROT_X, (float)disp_crnt_view_y, DFLT_VIEW_DIST, DFLT_VIEW_ZOOM) ; /* And redraw */ ps_display_scene( disp_fill_mode, disp_patch_switch, disp_mesh_switch, disp_interaction_switch, 0 ) ; /* Close */ ps_close() ; break ; case CHOICE_UTIL_STAT_CRT: print_statistics( stdout, 0 ) ; break ; case CHOICE_UTIL_STAT_FILE: if( (fd = fopen( "radiosity_stat", "w" )) == 0 ) { perror( "radiosity_stat" ) ; break ; } print_statistics( fd, 0 ) ; fclose( fd ) ; break ; case CHOICE_UTIL_CLEAR_RAD: clear_radiosity(0) ; } }
void wheel(const char *fn, int nres, char *resnm[], int r0, real rot0, char *title) { const real fontsize = 16; const real gray = 0.9; const real fontasp = 0.6; const real fontwidth = fontsize*fontasp; t_psdata out; int i, sl, slen; real ring, inner, outer; real xc, yc, box; gmx_bool *bPh; char **rnms; char sign; inner = 75.0; slen = 0; snew(rnms, nres); for (i = 0; (i < nres); i++) { snew(rnms[i], 256); sl = std::strlen(resnm[i]); sign = resnm[i][sl-1]; if ((sign == '+') || (sign == '-')) { resnm[i][sl-1] = '\0'; } sprintf(rnms[i], "%s-%d", resnm[i], i+r0); if ((sign == '+') || (sign == '-')) { sl = std::strlen(rnms[i]); rnms[i][sl] = sign; rnms[i][sl+1] = '\0'; } slen = std::max(slen, static_cast<int>(std::strlen(rnms[i]))); } ring = (2+slen)*fontwidth; outer = inner+ring; box = inner*1.5+(1+(nres / 18))*ring; bPh = bPhobics(nres, resnm); out = ps_open(fn, 0, 0, 2.0*box, 2.0*box); xc = box; yc = box; ps_font(out, efontHELV, 1.5*fontsize); ps_translate(out, xc, yc); if (title) { ps_ctext(out, 0, -fontsize*1.5/2.0, title, eXCenter); } ps_font(out, efontHELV, fontsize); ps_rotate(out, rot0); for (i = 0; (i < nres); ) { if (bPh[i]) { ps_color(out, gray, gray, gray); ps_fillarcslice(out, 0, 0, inner, outer, -10, 10); ps_color(out, 0, 0, 0); } ps_arcslice(out, 0, 0, inner, outer, -10, 10); ps_ctext(out, inner+fontwidth, -fontsize/2.0, rnms[i], eXLeft); ps_rotate(out, -100); i++; if ((i % 18) == 0) { inner = outer; outer += ring; } } ps_close(out); }
void ps_mat(char *outf,int nmat,t_matrix mat[],t_matrix mat2[], bool bFrame,bool bDiag,bool bFirstDiag, bool bTitle,bool bTitleOnce,bool bYonce,int elegend, real size,real boxx,real boxy,char *m2p,char *m2pout, int mapoffset) { char *libm2p; char buf[256],*legend; t_psdata out; t_psrec psrec,*psr; int W,H; int i,j,x,y,col,leg=0; real x0,y0,xx; real w,h,dw,dh; int nmap1=0,nmap2=0,leg_nmap; t_mapping *map1=NULL,*map2=NULL,*leg_map; bool bMap1,bNextMap1,bDiscrete; libm2p = m2p ? strdup(libfn(m2p)) : m2p; get_params(libm2p,m2pout,&psrec); psr=&psrec; if (psr->X.major <= 0 ) tick_spacing((mat[0].flags & MAT_SPATIAL_X) ? mat[0].nx + 1 : mat[0].nx, mat[0].axis_x, psr->X.offset, 'X', &(psr->X.major), &(psr->X.minor) ); if (psr->X.minor <= 0 ) psr->X.minor = psr->X.major / 2; if (psr->Y.major <= 0) tick_spacing((mat[0].flags & MAT_SPATIAL_Y) ? mat[0].ny + 1 : mat[0].ny, mat[0].axis_y, psr->Y.offset, 'Y', &(psr->Y.major), &(psr->Y.minor) ); if (psr->Y.minor <= 0) psr->Y.minor = psr->Y.major / 2; if (boxx>0) { psr->xboxsize=boxx; psr->yboxsize=boxx; } if (boxy>0) psr->yboxsize=boxy; if (psr->xboxsize==0) { psr->xboxsize = size/mat[0].nx; printf("Set the x-size of the box to %.3f\n",psr->xboxsize); } if (psr->yboxsize==0) { psr->yboxsize = size/mat[0].nx; printf("Set the y-size of the box to %.3f\n",psr->yboxsize); } nmap1=0; for (i=0; (i<nmat); i++) if (mat[i].nmap>nmap1) { nmap1=mat[i].nmap; map1=mat[i].map; leg=i+1; } if (leg!=1) printf("Selected legend of matrix # %d for display\n",leg); if (mat2) { nmap2=0; for (i=0; (i<nmat); i++) if (mat2[i].nmap>nmap2) { nmap2=mat2[i].nmap; map2=mat2[i].map; leg=i+1; } if (leg!=1) printf("Selected legend of matrix # %d for second display\n",leg); } if ( (mat[0].legend[0]==0) && psr->legend ) strcpy(mat[0].legend, psr->leglabel); bTitle = bTitle && mat[nmat-1].title[0]; bTitleOnce = bTitleOnce && mat[nmat-1].title[0]; psr->bTitle = bTitle; psr->bTitleOnce = bTitleOnce; psr->bYonce = bYonce; /* Set up size of box for nice colors */ box_dim(nmat,mat,mat2,psr,elegend,bFrame,&w,&h,&dw,&dh); /* Set up bounding box */ W=w+dw; H=h+dh; /* Start box at */ x0=dw; y0=dh; x = W+psr->xoffs; y = H+psr->yoffs; if (bFrame) { x += 5*DDD; y += 4*DDD; } out=ps_open(outf,0,0,x,y); ps_linewidth(out,psr->linewidth); ps_init_rgb_box(out,psr->xboxsize,psr->yboxsize); ps_init_rgb_nbox(out,psr->xboxsize,psr->yboxsize); ps_translate(out,psr->xoffs,psr->yoffs); if (bFrame) { ps_comment(out,"Here starts the BOX drawing"); draw_boxes(out,x0,y0,w,nmat,mat,psr); } for(i=0; (i<nmat); i++) { if (bTitle || (bTitleOnce && i==nmat-1) ) { /* Print title, if any */ ps_rgb(out,BLACK); ps_strfont(out,psr->titfont,psr->titfontsize); if (!mat2 || (strcmp(mat[i].title,mat2[i].title) == 0)) strcpy(buf,mat[i].title); else sprintf(buf,"%s / %s",mat[i].title,mat2[i].title); ps_ctext(out,x0+w/2,y0+box_height(&(mat[i]),psr)+psr->titfontsize, buf,eXCenter); } sprintf(buf,"Here starts the filling of box #%d",i); ps_comment(out,buf); for(x=0; (x<mat[i].nx); x++) { int nexty; int nextcol; xx=x0+x*psr->xboxsize; ps_moveto(out,xx,y0); y=0; bMap1 = (!mat2 || (x<y || (x==y && bFirstDiag))); if ((bDiag) || (x!=y)) col = mat[i].matrix[x][y]; else col = -1; for(nexty=1; (nexty<=mat[i].ny); nexty++) { bNextMap1 = (!mat2 || (x<nexty || (x==nexty && bFirstDiag))); /* TRUE: upper left -> map1 */ /* FALSE: lower right -> map2 */ if ((nexty==mat[i].ny) || (!bDiag && (x==nexty))) nextcol = -1; else nextcol=mat[i].matrix[x][nexty]; if ( (nexty==mat[i].ny) || (col!=nextcol) || (bMap1!=bNextMap1) ) { if (col >= 0) if (bMap1) ps_rgb_nbox(out,&(mat[i].map[col].rgb),nexty-y); else ps_rgb_nbox(out,&(mat2[i].map[col].rgb),nexty-y); else ps_moverel(out,0,psr->yboxsize); y=nexty; bMap1=bNextMap1; col=nextcol; } } } y0+=box_height(&(mat[i]),psr)+box_dh(psr)+box_dh_top(IS_ONCE,psr); } if (psr->X.lineatzero || psr->Y.lineatzero) { /* reset y0 for first box */ y0=dh; ps_comment(out,"Here starts the zero lines drawing"); draw_zerolines(out,x0,y0,w,nmat,mat,psr); } if (elegend!=elNone) { ps_comment(out,"Now it's legend time!"); ps_linewidth(out,psr->linewidth); if ( mat2==NULL || elegend!=elSecond ) { bDiscrete = mat[0].bDiscrete; legend = mat[0].legend; leg_nmap = nmap1; leg_map = map1; } else { bDiscrete = mat2[0].bDiscrete; legend = mat2[0].legend; leg_nmap = nmap2; leg_map = map2; } if (bDiscrete) leg_discrete(out,psr->legfontsize,DDD,legend, psr->legfontsize,psr->legfont,leg_nmap,leg_map); else { if ( elegend!=elBoth ) leg_continuous(out,x0+w/2,w/2,DDD,legend, psr->legfontsize,psr->legfont,leg_nmap,leg_map, mapoffset); else leg_bicontinuous(out,x0+w/2,w,DDD,mat[0].legend,mat2[0].legend, psr->legfontsize,psr->legfont,nmap1,map1,nmap2,map2); } ps_comment(out,"Were there, dude"); } ps_close(out); }
int pcpsign(char *infile, char *outfile, char *passwd, int z85, int detach) { FILE *in = NULL; FILE *out = NULL; pcp_key_t *secret = NULL; secret = pcp_find_primary_secret(); if(secret == NULL) { fatal(ptx, "Could not find a secret key in vault %s!\n", vault->filename); goto errs1; } if(infile == NULL) in = stdin; else { if((in = fopen(infile, "rb")) == NULL) { fatal(ptx, "Could not open input file %s\n", infile); goto errs1; } } if(outfile == NULL) out = stdout; else { if((out = fopen(outfile, "wb+")) == NULL) { fatal(ptx, "Could not open output file %s\n", outfile); goto errs1; } } char *passphrase; if(passwd == NULL) { pcp_readpass(ptx, &passphrase, "Enter passphrase to decrypt your secret key", NULL, 1, NULL); } else { passphrase = smalloc(strlen(passwd)+1); memcpy(passphrase, passwd, strlen(passwd)+1); } secret = pcpkey_decrypt(ptx, secret, passphrase); sfree(passphrase); if(secret == NULL) goto errs1; Pcpstream *pin = ps_new_file(in); Pcpstream *pout = ps_new_file(out); size_t sigsize; if(detach == 1) sigsize = pcp_ed_detachsign_buffered(pin, pout, secret); else sigsize = pcp_ed_sign_buffered(ptx, pin, pout, secret, z85); ps_close(pin); ps_close(pout); if(sigsize == 0) goto errs1; fprintf(stderr, "Signed %"FMT_SIZE_T" bytes successfully\n", (SIZE_T_CAST)sigsize); return 0; errs1: return 1; }
int main(int argc, char *argv[]) { int pctlfd; int pstatusfd; char procname[PROCSIZE]; char *command; char *rdb_commands = NULL; pid_t cpid; pstatus_t pstatus; sysset_t sysset; int c; int error = 0; long oper; struct iovec piov[2]; extern FILE *yyin; command = argv[0]; while ((c = getopt(argc, argv, "f:")) != EOF) switch (c) { case 'f': rdb_commands = optarg; break; case '?': break; } if (error || (optind == argc)) { (void) printf("usage: %s [-f file] executable " "[executable arguments ...]\n", command); (void) printf("\t-f command file\n"); exit(1); } /* * set up for tracing the child. */ init_proc(); /* * create a child to fork and exec from. */ if ((cpid = fork()) == 0) { (void) execv(argv[optind], &argv[optind]); perr(argv[1]); } if (cpid == -1) /* fork() failure */ perr(command); /* * initialize libelf */ if (elf_version(EV_CURRENT) == EV_NONE) { (void) fprintf(stderr, "elf_version() failed: %s\n", elf_errmsg(0)); exit(1); } /* * initialize librtld_db */ if (rd_init(RD_VERSION) != RD_OK) { (void) fprintf(stderr, "librtld_db::rd_init() failed: version " "submitted: %d\n", RD_VERSION); exit(1); } /* rd_log(1); */ /* * Child should now be waiting after the successful * exec. */ (void) snprintf(procname, PROCSIZE, "/proc/%d/ctl", EC_SWORD(cpid)); (void) printf("parent: %d child: %d child procname: %s\n", EC_SWORD(getpid()), EC_SWORD(cpid), procname); if ((pctlfd = open(procname, O_WRONLY)) < 0) { perror(procname); (void) fprintf(stderr, "%s: can't open child %s\n", command, procname); exit(1); } /* * wait for child process. */ oper = PCWSTOP; piov[0].iov_base = (caddr_t)&oper; piov[0].iov_len = sizeof (oper); if (writev(pctlfd, piov, 1) == -1) perr("PCWSTOP"); /* * open /proc/<cpid>/status */ (void) snprintf(procname, PROCSIZE, "/proc/%d/status", EC_SWORD(cpid)); if ((pstatusfd = open(procname, O_RDONLY)) == -1) perr(procname); if (read(pstatusfd, &pstatus, sizeof (pstatus)) == -1) perr("status read failed"); /* * Make sure that it stopped where we expected. */ while ((pstatus.pr_lwp.pr_why == PR_SYSEXIT) && (pstatus.pr_lwp.pr_what == SYS_execve)) { long pflags = 0; if (!(pstatus.pr_lwp.pr_reg[R_PS] & ERRBIT)) { /* successfull exec(2) */ break; } oper = PCRUN; piov[1].iov_base = (caddr_t)&pflags; piov[1].iov_len = sizeof (pflags); if (writev(pctlfd, piov, 2) == -1) perr("PCRUN1"); oper = PCWSTOP; if (writev(pctlfd, piov, 1) == -1) perr("PCWSTOP"); if (read(pstatusfd, &pstatus, sizeof (pstatus)) == -1) perr("status read failed"); } premptyset(&sysset); oper = PCSEXIT; piov[1].iov_base = (caddr_t)&sysset; piov[1].iov_len = sizeof (sysset); if (writev(pctlfd, piov, 2) == -1) perr("PIOCSEXIT"); /* * Did we stop where we expected ? */ if ((pstatus.pr_lwp.pr_why != PR_SYSEXIT) || (pstatus.pr_lwp.pr_what != SYS_execve)) { long pflags = 0; (void) fprintf(stderr, "Didn't catch the exec, why: %d " "what: %d\n", pstatus.pr_lwp.pr_why, pstatus.pr_lwp.pr_what); oper = PCRUN; piov[1].iov_base = (caddr_t)&pflags; piov[1].iov_len = sizeof (pflags); if (writev(pctlfd, piov, 2) == -1) perr("PCRUN2"); exit(1); } (void) ps_init(pctlfd, pstatusfd, cpid, &proch); if (rdb_commands) { if ((yyin = fopen(rdb_commands, "r")) == NULL) { (void) printf("unable to open %s for input\n", rdb_commands); perr("fopen"); } } else { proch.pp_flags |= FLG_PP_PROMPT; rdb_prompt(); } (void) yyparse(); if (proch.pp_flags & FLG_PP_PACT) { long pflags = PRCFAULT; (void) printf("\ncontinuing the hung process...\n"); pctlfd = proch.pp_ctlfd; (void) ps_close(&proch); oper = PCRUN; piov[1].iov_base = (caddr_t)&pflags; piov[1].iov_len = sizeof (pflags); if (writev(pctlfd, piov, 2) == -1) perr("PCRUN2"); (void) close(pctlfd); } return (0); }