📄 dna1.cc
字号:
//--------------------------------------------------------------------------//// dna1.cc //// Latest revision: 05-06-2000 //// Copyright (C) 2000 by Thomas J. Nelson //// All rights reserved. ////--------------------------------------------------------------------------//#include "dna.h"extern Globals g;const int LABEL_LENGTH = 128;const int COMMAND_LENGTH = 128;//--------------------------------------------------------------------------//// initialize_globals ////--------------------------------------------------------------------------//void initialize_globals(void){ char *ptr=NULL; char tempstring[1024]; g.dialogdone=0; strcpy(g.version, "1.1.0"); strcpy(g.nomemory,"Insufficient memory"); g.main_xsize = 600; g.main_ysize = 720; g.xsize = g.main_xsize - 16 - 154; g.ysize = g.main_ysize - 16 - 24; g.getout=0; // Flag for 'cancel' g.key_ascii=0; g.key_alt=0; g.state=NORMAL; g.key_ctrl=0; g.key_shift=0; g.signif = 5; // Significant digits to display g.font = new char[256]; strcpy(g.font,"fixed"); strcpy(g.filename,"Untitled"); g.want_messages = 1; g.printer_device = 1; strcpy(g.printer_command,"lpr -P "); strcpy(g.printer_name,"/dev/lp2"); strcpy(g.printer_file,"dna.print"); g.rows = 1000; g.cols = 50; g.graph_active = 0; g.autoupdate=1; g.touched=0; g.mask = Button1MotionMask | // Click & Drag PointerMotionMask | // Mouse movement ButtonPressMask | ButtonReleaseMask; //// $HOME/.dna for dna.ini, formats in Bourne //// $home/.dna in tcsh ptr = getenv("HOME"); if(ptr!=NULL) strcpy(g.homedir, ptr); else { ptr = getenv("home"); if(ptr!=NULL) strcpy(g.homedir, ptr); else { strcpy(g.homedir, g.startdir); fprintf(stderr,"Unable to determine home directory in __FILE__ line __LINE__\n"); } } strcat(g.homedir,"/.dna"); printf("Home directory %s\n",g.homedir); sprintf(tempstring,"%s/dna.ini", g.homedir); if(access(tempstring, F_OK)) // If directory does not exist, create it mkdir(g.homedir, 0755); //// Program-specific globals g.cs = 0; // current sequence g.sequence_mode = DNA; // 0=protein 1=dna g.editing = 1; g.mask = ExposureMask | // Resize/unhide KeyPressMask | // Keyboard ButtonPressMask | // Click ButtonReleaseMask | // Unclick Button1MotionMask | // Click & Drag StructureNotifyMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask; // Mouse movement g.doc = new Document[MAXSEQUENCES+1]; g.alignsize = 0; g.save_format = SCREEN; g.matrix_set1 = 0; g.matrix_set2 = 1; g.touched = 0; //// This must be last - can override above settings readsettings(); }//--------------------------------------------------------------------------//// initialize_data ////--------------------------------------------------------------------------//void initialize_data(void){ int j,k; int bytesperpixel = (g.bitsperpixel+7)/8; g.stringbufr_1d = (uchar*)malloc(200*200*sizeof(uchar)*bytesperpixel); if(g.stringbufr_1d==0) { fprintf(stderr,"%s for stringbufr_1d\n",g.nomemory); exit(1); } g.stringbufr = make_2d_alias(g.stringbufr_1d, 200*bytesperpixel, 200); memset(g.stringbufr_1d, g.bcolor, 200*200*g.off[g.bitsperpixel]); int ximage_bpp = g.bitsperpixel; if(g.sparse_packing && ximage_bpp==32) ximage_bpp=24; g.stringbufr_ximage = createximage(200,200, g.bitsperpixel, g.stringbufr_1d); for(k=0;k<MAXSEQUENCES;k++) { g.doc[k].text = NULL; g.doc[k].filename = NULL; g.doc[k].comment = new char*[MAXCOMMENTS]; for(j=0; j<MAXCOMMENTS; j++)g.doc[k].comment[j]=NULL; init_editor(k); }}//-------------------------------------------------------------------//// execute //// execute a command from menu or a macro. This method is better than//// having a separate callback for each menu item because it makes it //// to use macros. ////-------------------------------------------------------------------//int execute(char *command, int noofargs, char **arg){ int j,k,status=OK; char o[256]; g.getout=0; int e=0; // flag if something was executed for(k=0,j=0;k<=(int)strlen(command);k++) { switch(command[k]) // Clean up command if from menu { case '.': // If abbreviation case '_': // If underscore case ' ': break; default : o[j++] = tolower(command[k]); o[j]=0; } } //// The commands (in alphabetical order) if(strcmp(o, "align")==SAME){ e=1; align();} if(strcmp(o, "close")==SAME){ e=1; close();} if(strcmp(o, "comments")==SAME){ e=1; comments();} if(strcmp(o, "config")==SAME){ e=1; configure();} if(strcmp(o, "compare")==SAME){ e=1; analyze();} if(strcmp(o, "dna")==SAME) { e=1; toggle_sequence_mode(); } if(strcmp(o, "down")==SAME){ e=1; down();} if(strcmp(o, "edit")==SAME){ e=1; edit();} if(strcmp(o, "left")==SAME){ e=1; left();} if(strcmp(o, "nextframe")==SAME){ e=1; nextframe();} if(strcmp(o, "null")==SAME) { e=1; unpush_null_buttons(); return ABORT; //// Break out so g.getout isnt reset } if(strcmp(o, "offset1")==SAME) { e=1; set_offset(0); } if(strcmp(o, "offset2")==SAME) { e=1; set_offset(1); } if(strcmp(o, "prevframe")==SAME){ e=1; prevframe();} if(strcmp(o, "print")==SAME){ e=1; printsequence();} if(strcmp(o, "read")==SAME){ e=1; readsequence();} if(strcmp(o, "quit")==SAME){ e=1; quitcb(0,0,0);} if(strcmp(o, "reverse")==SAME){ e=1; reverse();} if(strcmp(o, "right")==SAME){ e=1; right();} if(strcmp(o, "save")==SAME){ e=1; save();} if(strcmp(o, "select")==SAME){ e=1; g.cs = -1+clickbox("Sequence no.",g.cs+1,1,MAXSEQUENCES,null,0);} if(strcmp(o, "statistics")==SAME){ e=1; statistics();} if(strcmp(o, "translate")==SAME){ e=1; translate(1);} if(strcmp(o, "up")==SAME){ e=1; up();} if(strcmp(o, "undo")==SAME){ e=1; undo();} g.getout=0; if(e==0) status=UNKNOWN; return status;}//--------------------------------------------------------------------//// itoa //// Convert integer to string. ////--------------------------------------------------------------------//char *itoa(int value, char *str, int radix){ switch(radix) { #ifdef MSDOS case 2: sprintf(str, "%b",value); break;#endif case 8: sprintf(str, "%o",value); break; case 10: sprintf(str, "%d",value); break; case 16: sprintf(str, "%x",value); break; default: perror("Error converting string"); exit(1); } return(str);}//--------------------------------------------------------------------//// ltoa //// Convert long integer to string. ////--------------------------------------------------------------------//char *ltoa(long int value, char *str, int radix){ return itoa((int)value, str, radix); }//-----------------------------------------------------------------------//// gcvt //// convert double to a string with signif significant digits. //// use our own gcvt because the linux one is totally screwed up. ////-----------------------------------------------------------------------//char *gcvt(double val, int signif, char *buf){ buf=buf; val=val;signif=signif; char gtemp[128]; char format[32]; sprintf(format,"%c.%dg",'%',g.signif); sprintf(buf, format, val); strcpy(gtemp, buf); return buf;}//-------------------------------------------------------------------//// null - do nothing funcs for clickbox(), plot(), etc. ////-------------------------------------------------------------------//void null(int a){ a=a; }void null(int a[10]){ a[0]=a[0]; }void null(double a){ a=a; }void null(void){}void null(dialoginfo *a, int b, int c, int d){ a=a; b=b; c=c; d=d; }//-------------------------------------------------------------------//// between - returns 1 if a is between b and c ////-------------------------------------------------------------------//int between(int a,int b,int c){ if((a>=b)&&(a<=c))return(1); else return(0);}//-------------------------------------------------------------------//// between - returns 1 if a is between b and c ////-------------------------------------------------------------------//int between(double a, double b, double c){ if((a>=b)&&(a<=c))return(1); else return(0);}//-------------------------------------------------------------------//// stringtohex //// converts a string to integer assuming the string is a hex value. ////-------------------------------------------------------------------//int stringtohex(char* string){ int k; char c; int answer = 0; for(k=0;k<(int)strlen(string);k++) { answer <<= 4; c = string[k]; if((c>='0')&&(c<='9')) answer += c-'0'; if((c>='A')&&(c<='F')) answer += c-'A'+10; if((c>='a')&&(c<='f')) answer += c-'a'+10; } return answer;}//-------------------------------------------------------------------//// path - strips path from filename and returns the path name. ////-------------------------------------------------------------------//void path(char *pathname, char *path){ int k,hit=0; char tempstring[FILENAMELENGTH]; strcpy(tempstring,pathname); for(k=strlen(tempstring);k>0;k--) { if((tempstring[k]=='/')||(tempstring[k]=='\\')) { tempstring[k+1]=0; hit=1; break; } } if(hit) strcpy(path,tempstring); return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -