static void plotBP(char* sequence, short* structure) { int i; int length; float lx, ly; float arcx, arcy, rad; length = (int)strlen(sequence) ; setlinestyle(SOLID); setcolor(BLACK); for(i = 0; i<length; i++) { if(structure[i] > i) { lx = structure[i] - i + 1; //drawline((i+0.5)*CELLSIZE, length*CELLSIZE/2 - 1, (i + 0.5)*CELLSIZE, (length+lx)*CELLSIZE/2 -1); flushinput(); //drawline((structure[i]-0.5)*CELLSIZE, length*CELLSIZE/2-1,(structure[i]-0.5)*CELLSIZE, (length+lx)*CELLSIZE/2 -1); flushinput(); //drawline((i+0.5)*CELLSIZE, (length+lx)*CELLSIZE/2-1, (structure[i]-0.5)*CELLSIZE, (length+lx)*CELLSIZE/2-1); arcx = (i + structure[i] )/2.0 * CELLSIZE; arcy = length*CELLSIZE/2 -1; rad = (structure[i] - 1 - i )/2.0 *CELLSIZE; drawarc(arcx, arcy, rad, 0, -180.0); flushinput(); } } }
void PlotRna(char* seqName, char* sequence, short* structure, char* filename, float score) { /*A:red, U: Green, G:Blue, C:Yellow*/ int i, j; int length; int sizex, sizey; fname = filename; length = (int)strlen(sequence) ; sizex = length; sizey = length; /*printf("here......length %d\n",length);*/ drawInit(length, length, seqName, filename, score); /* print out stems */ int st, stp; char* c = (char*)malloc(sizeof(char)*1000); i = 0; j = 0; while(i < length) { while(i < length && (structure[i] == 0 || structure[i] < i)) i++; st = i; while(i < length && (structure[i]-1 == structure[i+1])) i++; stp = i; if (i >= length) break; sprintf(c, "%d-%d; %d-%d ",st+1, stp+1, structure[stp],structure[st]); i++; j++; if ((j%2) == 1) drawtext (sizex*CELLSIZE/4,sizey*CELLSIZE/10.0+((int)(j/2)+1)*CELLSIZE*sizey/30,c,1.0e6); else drawtext (sizex*CELLSIZE/2,sizey*CELLSIZE/10.0+((int)(j/2))*CELLSIZE*sizey/30,c,1.0e6); flushinput(); } for(i=0; i<length; i++) { if(sequence[i] == 'A' || sequence[i] == 'a') setcolor(RED); else if(sequence[i] == 'U'|| sequence[i] == 'u' || sequence[i] == 'T' || sequence[i] == 't') setcolor(GREEN); else if(sequence[i] == 'G' || sequence[i] == 'g') setcolor(BLUE); else if(sequence[i] == 'C' || sequence[i] == 'c') setcolor(YELLOW); else setcolor(BLACK); fillrect((i+0.2)*CELLSIZE, (sizey/2 - 0.8)*CELLSIZE, (i+0.8)*CELLSIZE, (sizey/2 - 0.2)*CELLSIZE); flushinput(); } plotBP(sequence, structure); close_postscript(); close_graphics(); }
static void drawInit( int sizex, int sizey, char* seqName, char* filename, float score) { int i,k=0; int x,y; char* c; c =(char*)malloc(sizeof(char)*1000); /* initialize display */ init_graphics("RNA"); /* still picture drawing allows user to zoom, etc. */ init_world (0.,0.,CELLSIZE*sizex,CELLSIZE*sizey); //event_loop(button_press, drawscreen); /* animation section */ clearscreen(); init_postscript(filename); clearscreen(); sprintf(c, "%s%s%s%d%s%f%s", "RNA: ", seqName, ", length = ", sizex, ", energy = ",-score/1000.0, " kal/mol"); //printf(" output string is %s\n",c); update_message("RNA secondary structure"); flushinput(); drawtext (sizex*CELLSIZE/2,sizey*CELLSIZE/10,c,1.0e6); flushinput(); setcolor (BLACK); setlinewidth(1); setlinestyle (SOLID); for (i=0;i<=sizex;i++) { drawline (i*CELLSIZE,(sizey/2-1)*CELLSIZE,i*CELLSIZE,CELLSIZE*sizey/2); flushinput(); } drawline(0,(sizey/2-1)*CELLSIZE, sizex*CELLSIZE, CELLSIZE*(sizey/2-1)); drawline(0,sizey*CELLSIZE/2, sizex*CELLSIZE, CELLSIZE*sizey/2); flushinput(); free(c); }
void update_screen (int priority, char *msg, enum pic_type pic_on_screen_val, boolean crit_path_button_enabled) { /* Updates the screen if the user has requested graphics. The priority * * value controls whether or not the Proceed button must be clicked to * * continue. Saves the pic_on_screen_val to allow pan and zoom redraws. */ if (!show_graphics) /* Graphics turned off */ return; /* If it's the type of picture displayed has changed, set up the proper * * buttons. */ if (pic_on_screen != pic_on_screen_val) { if (pic_on_screen_val == PLACEMENT && pic_on_screen == NO_PICTURE) { create_button ("Window", "Toggle Nets", toggle_nets); } else if (pic_on_screen_val == ROUTING && pic_on_screen == PLACEMENT) { create_button ("Toggle Nets", "Toggle RR", toggle_rr); create_button ("Toggle RR", "Congestion", toggle_congestion); if (crit_path_button_enabled) create_button ("Congestion", "Crit. Path", highlight_crit_path); } else if (pic_on_screen_val == PLACEMENT && pic_on_screen == ROUTING) { destroy_button ("Toggle RR"); destroy_button ("Congestion"); if (crit_path_button_enabled) destroy_button ("Crit. Path"); } } /* Save the main message. */ strncpy (default_message, msg, BUFSIZE); pic_on_screen = pic_on_screen_val; update_message (msg); drawscreen(); if (priority >= gr_automode) { event_loop(highlight_blocks, drawscreen); } else { flushinput(); } }
char *xmodemTransmit(int fnbr) { unsigned char xbuff[X_BUF_SIZE]; unsigned char packetno = 1; int i, c, len = 0; int retry; // first establish communication with the remote while(1) { for( retry = 0; retry < 16; ++retry) { if ((c = _inbyte((DLY_1S)<<1)) >= 0) { switch (c) { case NAK: // start sending goto start_trans; case CAN: if ((c = _inbyte(DLY_1S)) == CAN) { MMputchar(ACK); flushinput(); return "Cancelled by remote"; } break; default: break; } } } MMputchar(CAN); MMputchar(CAN); MMputchar(CAN); flushinput(); return "Remote did not respond"; // no sync // send a packet while(1) { start_trans: memset (xbuff, 0, X_BUF_SIZE); // start with an empty buffer xbuff[0] = SOH; // copy the header xbuff[1] = packetno; xbuff[2] = ~packetno; for(len = 0; len < 128 && !MMfeof(fnbr); len++) { xbuff[len + 3] = MMfgetc(fnbr); // copy the data into the packet } if (len > 0) { unsigned char ccks = 0; for (i = 3; i < X_BLOCK_SIZE+3; ++i) { ccks += xbuff[i]; } xbuff[X_BLOCK_SIZE+3] = ccks; // now send the block for (retry = 0; retry < MAXRETRANS && !MMAbort; ++retry) { // send the block for (i = 0; i < X_BLOCK_SIZE+4 && !MMAbort; ++i) { MMputchar(xbuff[i]); } // check the response if ((c = _inbyte(DLY_1S)) >= 0 ) { switch (c) { case ACK: ++packetno; goto start_trans; case CAN: // canceled by remote MMputchar(ACK); flushinput(); return "Cancelled by remote"; break; case NAK: // receiver got a corrupt block default: break; } } } // too many retrys... give up MMputchar(CAN); MMputchar(CAN); MMputchar(CAN); flushinput(); return "Too many errors in transmission"; } // finished sending - send end of text else { for (retry = 0; retry < 10; ++retry) { MMputchar(EOT); if ((c = _inbyte((DLY_1S)<<1)) == ACK) break; } flushinput(); if(c == ACK) return ""; return "Error closing communications"; } } } }
char *xmodemReceive(int fnbr) { unsigned char xbuff[X_BUF_SIZE]; unsigned char *p; unsigned char trychar = NAK; //'C'; unsigned char packetno = 1; int i, c; int retry, retrans = MAXRETRANS; // first establish communication with the remote while(1) { for( retry = 0; retry < 16; ++retry) { if(trychar) MMputchar(trychar); if ((c = _inbyte((DLY_1S)<<1)) >= 0) { switch (c) { case SOH: goto start_recv; case EOT: flushinput(); MMputchar(ACK); return ""; // no more data case CAN: flushinput(); MMputchar(ACK); return "Cancelled by remote"; break; default: break; } } } flushinput(); MMputchar(CAN); MMputchar(CAN); MMputchar(CAN); return "Remote did not respond"; // no sync start_recv: trychar = 0; p = xbuff; *p++ = SOH; for (i = 0; i < (X_BLOCK_SIZE+3); ++i) { if ((c = _inbyte(DLY_1S)) < 0) goto reject; *p++ = c; } if (xbuff[1] == (unsigned char)(~xbuff[2]) && (xbuff[1] == packetno || xbuff[1] == (unsigned char)packetno-1) && check(&xbuff[3], X_BLOCK_SIZE)) { if (xbuff[1] == packetno) { for(i = 0 ; i < X_BLOCK_SIZE ; i++) MMfputc(xbuff[i + 3], fnbr); ++packetno; retrans = MAXRETRANS+1; } if (--retrans <= 0) { flushinput(); MMputchar(CAN); MMputchar(CAN); MMputchar(CAN); return "Too many errors in transmission"; } MMputchar(ACK); continue; } reject: flushinput(); MMputchar(NAK); } }
int xmodem_get(unsigned char *dest, int destsz) { unsigned char xbuff[1030]; /* 1024 for XModem 1k + 3 head chars + 2 crc + nul */ unsigned char *p; int bufsz, crc = 0; unsigned char trychar = 'C'; unsigned char packetno = 1; int i, c, len = 0; int retry, retrans = MAXRETRANS; for (;;) { for ( retry = 0; retry < 160; ++retry) { if (trychar) { putchar(trychar); // sleep(0x008f0000); } if ((c = try_getc((DLY_1S)<<1)) >= 0) { switch (c) { case SOH: bufsz = 128; goto start_recv; case STX: bufsz = 1024; goto start_recv; case EOT: flushinput(); putchar(ACK); return len; /* normal end */ case CAN: if ((c = try_getc(DLY_1S)) == CAN) { flushinput(); putchar(ACK); return -1; /* canceled by remote */ } break; default: break; } } } if (trychar == 'C') { trychar = NAK; continue; } flushinput(); putchar(CAN); putchar(CAN); putchar(CAN); return -2; /* sync error */ start_recv: if (trychar == 'C') crc = 1; trychar = 0; p = xbuff; *p++ = c; for (i = 0; i < (bufsz+(crc?1:0)+3); ++i) { if ((c = try_getc(DLY_1S)) < 0) goto reject; *p++ = c; } if (xbuff[1] == (unsigned char)(~xbuff[2]) && (xbuff[1] == packetno || xbuff[1] == (unsigned char)packetno-1) && check(crc, &xbuff[3], bufsz)) { if (xbuff[1] == packetno) { unsigned int count = destsz - len; if (count > bufsz) count = bufsz; if (count > 0) { //memcpy (&dest[len], &xbuff[3], count); _writer(&xbuff[3], count); len += count; } ++packetno; retrans = MAXRETRANS+1; } if (--retrans <= 0) { flushinput(); putchar(CAN); putchar(CAN); putchar(CAN); return -3; /* too many retry error */ } putchar(ACK); continue; } reject: flushinput(); putchar(NAK); } }
void event_loop (void (*act_on_button) (float x, float y), void (*drawscreen) (void)) { /* The program's main event loop. Must be passed a user routine * * drawscreen which redraws the screen. It handles all window resizing * * zooming etc. itself. If the user clicks a button in the graphics * * (toplevel) area, the act_on_button routine passed in is called. */ XEvent report; int bnum; float x, y; #define OFF 1 #define ON 0 turn_on_off (ON); while (1) { XNextEvent (display, &report); switch (report.type) { case Expose: #ifdef VERBOSE printf("Got an expose event.\n"); printf("Count is: %d.\n",report.xexpose.count); printf("Window ID is: %d.\n",report.xexpose.window); #endif if (report.xexpose.count != 0) break; if (report.xexpose.window == menu) drawmenu(); else if (report.xexpose.window == toplevel) drawscreen(); else if (report.xexpose.window == textarea) draw_message(); break; case ConfigureNotify: top_width = report.xconfigure.width; top_height = report.xconfigure.height; update_transform(); #ifdef VERBOSE printf("Got a ConfigureNotify.\n"); printf("New width: %d New height: %d.\n",top_width,top_height); #endif break; case ButtonPress: #ifdef VERBOSE printf("Got a buttonpress.\n"); printf("Window ID is: %d.\n",report.xbutton.window); #endif if (report.xbutton.window == toplevel) { x = XTOWORLD(report.xbutton.x); y = YTOWORLD(report.xbutton.y); act_on_button (x, y); } else { /* A menu button was pressed. */ bnum = which_button(report.xbutton.window); #ifdef VERBOSE printf("Button number is %d\n",bnum); #endif button[bnum].ispressed = 1; drawbut(bnum); XFlush(display); /* Flash the button */ button[bnum].fcn(bnum, drawscreen); button[bnum].ispressed = 0; drawbut(bnum); if (button[bnum].fcn == proceed) { turn_on_off(OFF); flushinput (); return; /* Rather clumsy way of returning * * control to the simulator */ } } break; } } }
void typeline(bc *bc, char *preload,int echocr) { int i=0,j; int code; int backcount=0; char linesave[LINESIZE],ch; int linesin; char ref; int xdelta; char *p1,*p2; char token[128]; char *fake; int scrollback; int startx, starty; char spaces[256], *zerospaces; char *tail; int oldlen; memset(spaces, ' ', sizeof(spaces)); zerospaces = spaces + sizeof(spaces)-1; *zerospaces = 0; top: tail=""; startx = bc->txpos; starty = bc->typos; xdelta=0; linesin=bc->hcount>HISTSIZE ? HISTSIZE : bc->hcount; strcpy(bc->debline, preload); i=strlen(bc->debline); tprintf(bc, preload); ref=0; fake=0; scrollback=0; while(!(bc->flags & (BF_CCHIT | BF_QUIT))) { if(!fake) { SDL_Delay(10); scaninput(bc); code=takedown(bc); //if(code=='q' + MYALTED) exit(0); // alt-q } else { code=*fake++; if(!code) {fake=0;continue;} } if(code==-1) continue; if(code==MYPAGEUP || code==(MYPAGEUP|MYSHIFTED)) { if(code==MYPAGEUP) ++scrollback; else scrollback+=bc->tysize; scrollback=showhistory(bc, scrollback); continue; } else if(code==MYPAGEDOWN || code==(MYPAGEDOWN|MYSHIFTED)) { if(code==MYPAGEDOWN) --scrollback; else scrollback-=bc->tysize; if(scrollback<0) scrollback=0; scrollback=showhistory(bc, scrollback); if(scrollback) continue; else ++ref; } if(code==9 || code==4) { j=0; while(i+xdelta-j>0) { ch=bc->debline[i+xdelta-j-1]; if(!isalpha(ch) && !isdigit(ch) && ch!='_' && ch!='.') break; ++j; } p1=token; while(j) *p1++=bc->debline[i+xdelta-j--]; *p1=0; if(*token) { if(code==9) fake=complete(token); else { cr(bc); listall(token); ref=1; } } } else if(code==0x7f) { if(!xdelta) continue; p1=bc->debline+i+xdelta; p2=p1+1; while((*p1++=*p2++)); --i; ++xdelta; ++ref; } else if(code==MYLEFT) { if(i+xdelta>0) {--xdelta;++ref;} } else if(code==MYRIGHT) { if(xdelta<0) {++xdelta;++ref;} } else if(code==MYUP) { if(backcount<linesin) { if(!backcount) memcpy(linesave,bc->debline,LINESIZE); ++backcount; oldlen = strlen(bc->debline); memcpy(bc->debline, bc->debhist+LINESIZE*((bc->hcount-backcount) & (HISTSIZE-1)), LINESIZE); oldlen -= strlen(bc->debline); if(oldlen>0) tail=zerospaces-oldlen; xdelta=0; } ++ref; } else if(code==MYDOWN) { if(backcount) { --backcount; oldlen = strlen(bc->debline); if(!backcount) memcpy(bc->debline,linesave,LINESIZE); else memcpy(bc->debline,bc->debhist+LINESIZE*((bc->hcount-backcount) & (HISTSIZE-1)),LINESIZE); oldlen -= strlen(bc->debline); if(oldlen>0) tail=zerospaces-oldlen; xdelta=0; } ++ref; } else if(code>=0 && code<128) { if(code==8) { if(i+xdelta) { --i; p1=bc->debline+i+xdelta; p2=p1+1; while((*p1++=*p2++)); ++ref; } else continue; } else if(code==CR) { if(echocr) cr(bc); break; } else if(code>=0x20 && i<bc->txsize-1 && i<sizeof(bc->debline)-1) { p2=bc->debline+i; p1=p2+1; j=1-xdelta; while(j--) *p1--=*p2--; *p1=code; ++ref; } else continue; } if(ref) { if(scrollback) scrollback=showhistory(bc, 0); i=strlen(bc->debline); tprintf(bc, "\033%dx\033%dy%s %s\033%dx\033%dy", startx, starty, bc->debline, tail, i+xdelta+startx, starty); tail=""; ref=0; } } if(bc->flags & BF_CCHIT) { flushinput(bc); if(!(bc->flags & BF_RUNNING)) { bc->flags &= ~BF_CCHIT; preload=""; tprintf(bc, "\n"); goto top; } } if(i) { memcpy(bc->debhist+LINESIZE*(bc->hcount & (HISTSIZE-1)),bc->debline,LINESIZE); ++bc->hcount; } }