www.pudn.com > 医学算法.rar > sbs.c
#include/* sbs - display two images side by side Malcolm Slaney Purdue University W. Lafayette, IN. 47907 December 10, 1981 */ /* syntax: sbs [options] file1 file2 VARIABLES DEFAULT n: size of image 64 of: output file pic FLAGS DEFAULT -d: split picture along diagonal on -h: split picture horizontally off -v: split picture vertically off */ int n = 64; /* size of pictures. */ char *ofn = "pic"; /* default output file name */ char *f1n, *f2n; int method = 1; /* Where to split the pictures */ char *table[] = { "n", "of", 0 }; FILE *f1, *f2, *output; char black[2048]; /* Uninitialized for black lines */ char line1[2048], line2[2048]; main(argc,argv) int argc; char **argv; { register int i,j; int band; char cc, *command; command = argv[0]; while(++argv && --argc > 2){ if(**argv == '-')while(cc = *++*argv)switch(cc){ case 'd': method = 1; break; case 'h': method = 2; break; case 'v': method = 3; break; default: fprintf(stderr,"bad flag: -%c\n",cc); exit(1); }else switch(comm(*argv)){ case 1: /* n */ n =atoi(*argv+2); if (n>2048){ fprintf(stderr,"%s: n is too large.\n", command); exit(5); } break; case 2: /* of */ ofn = *argv+2; break; } } if (argc != 2){ fprintf(stderr,"syntax: %s [n=64] [of=pic] file1 file2\n", command); exit(2); } f1=fopen(f1n= *argv,"r"); if (!f1){ fprintf(stderr,"%s: Can't open %s for reading.\n", command,*argv); exit(3); } argv++; f2=fopen(f2n= *argv,"r"); if (!f2){ fprintf(stderr,"%s: Can't open %s for reading.\n", command,*argv); exit(3); } output=fopen(ofn,"w"); if (!output){ fprintf(stderr,"%s: Can't open %s for reading.\n", command,ofn); exit(3); } band = n/40; for (i=0;i =n/2+band) fwrite(line2,n,1,output); else fwrite(black,n,1,output); break; case 3: fwrite(line1,n/2-band,1,output); fwrite(black,band*2,1,output); fwrite(line2+n/2+2*band,n/2-band,1,output); break; default: fprintf(stderr,"%s: Fatal Error, Woops.\n", command); } } } min(a,b) int a,b;{ return(ab?a:b); } comm(s) char *s; { register int i,j,r; for(i=0;table[i];i++){ for(j=0;(r=table[i][j]) == s[j] && r;j++); if(r == 0 && s[j] == '=' && s[j+1] )return(i+1); } fprintf(stderr,"bad option: %s\n",s); exit(1); return(0); }