|
|
1.1 ! root 1: ! 2: /* collect and interpret runtime options for showimg, ! 3: * ! 4: * 8/12/86 Bill Wyatt ! 5: * ! 6: * Also opens the display, since to set up certain color ! 7: * options, the display must be accessible. ! 8: */ ! 9: ! 10: #include <stdio.h> ! 11: #include <X/Xlib.h> ! 12: ! 13: #include "shimg.h" ! 14: #include "shopt.h" ! 15: ! 16: short gray_bits[16] = { ! 17: 0xaaaa, 0x5555, 0xaaaa, 0x5555, ! 18: 0xaaaa, 0x5555, 0xaaaa, 0x5555, ! 19: 0xaaaa, 0x5555, 0xaaaa, 0x5555, ! 20: 0xaaaa, 0x5555, 0xaaaa, 0x5555}; ! 21: ! 22: shgetopt(argc, argv, maininfo, colorinfo, imageinfo) ! 23: int argc; ! 24: char *argv[]; ! 25: struct windmain *maininfo; ! 26: struct colorwind *colorinfo; ! 27: struct imagewind *imageinfo; ! 28: { ! 29: Color cdef; ! 30: char *option, *border_color, *back_color; ! 31: int i, strcmp(), atoi(); ! 32: char *index(); ! 33: ! 34: ! 35: if ((option = XGetDefault(argv[0],"BorderWidth")) != NULL) ! 36: maininfo->frame.bdrwidth = atoi(option); ! 37: else maininfo->frame.bdrwidth = 0; ! 38: ! 39: if ((border_color = XGetDefault(argv[0],"Border")) == NULL) ! 40: border_color = XGetDefault(argv[0],"BorderColor"); ! 41: ! 42: back_color = XGetDefault(argv[0],"Background"); ! 43: ! 44: ! 45: for (i = 1; i < argc; i++) { ! 46: if (argv[i][0] == '=') { ! 47: maininfo->geometry = argv[i]; ! 48: continue; ! 49: } ! 50: if (index(argv[i], ':') != NULL) { /* host:display */ ! 51: maininfo->display = argv[i]; ! 52: continue; ! 53: } ! 54: if (strcmp(argv[i], "-bw") == 0 || ! 55: strcmp(argv[i], "-border") == 0) { /* border width */ ! 56: if (++i >= argc) usage(argv[0]); ! 57: maininfo->frame.bdrwidth = atoi(argv[i]); ! 58: continue; ! 59: } ! 60: if (strcmp(argv[i], "-bd") == 0 || ! 61: strcmp(argv[i], "-color") == 0) { /* border color */ ! 62: if (++i >= argc) usage(argv[0]); ! 63: border_color = argv[i]; ! 64: continue; ! 65: } ! 66: if(strcmp(argv[i], "-bg") == 0 || ! 67: strcmp(argv[i], "background") == 0) { /* background color */ ! 68: if(++i >= argc) usage(argv[0]); ! 69: back_color = argv[i]; ! 70: continue; ! 71: } ! 72: if (strcmp(argv[i], "-p") == 0 || ! 73: strcmp(argv[i], "-planes") == 0) { /* # of planes */ ! 74: if (++i >= argc) usage(argv[0]); ! 75: colorinfo->nplanes = ! 76: (atoi(argv[i]) > 8) ? 8 : atoi(argv[i]); ! 77: continue; ! 78: } ! 79: if (strcmp(argv[i],"-n") == 0 || ! 80: strcmp(argv[i],"-neg") == 0) { /* negative map */ ! 81: imageinfo->VOP_Flags |= VOP_Inverse; ! 82: continue; ! 83: } ! 84: if (strcmp(argv[i],"-rgb") == 0) { /* manipulate RGB */ ! 85: /* rgbmap++; */ ! 86: imageinfo->VOP_Flags &= ~(VOP_GrayScale); ! 87: imageinfo->VOP_Flags |= VOP_RGB; ! 88: continue; ! 89: } ! 90: if(strcmp(argv[i],"-skip") == 0 || ! 91: strcmp(argv[i],"-sk") == 0) { /* skip header */ ! 92: if(++i >= argc) usage(argv[0]); ! 93: imageinfo->headskip = atoi(argv[i]); ! 94: if(imageinfo->headskip < 0) usage(argv[0]); ! 95: continue; ! 96: } ! 97: if(strcmp(argv[i],"-nrows") == 0 || ! 98: strcmp(argv[i],"-nr") == 0) { /* explicit set */ ! 99: if(++i >= argc) usage(argv[0]); ! 100: imageinfo->nrows = atoi(argv[i]); ! 101: if(imageinfo->nrows <= 0) usage(argv[0]); ! 102: continue; ! 103: } ! 104: if(strcmp(argv[i],"-ncols") == 0 || ! 105: strcmp(argv[i],"-nc") == 0) { /* explicit set */ ! 106: if(++i >= argc) usage(argv[0]); ! 107: imageinfo->ncols = atoi(argv[i]); ! 108: if(imageinfo->ncols <= 0) usage(argv[0]); ! 109: continue; ! 110: } ! 111: if(strcmp(argv[i],"-sqrt") == 0 || ! 112: strcmp(argv[i],"-sq") == 0) { /* sqrt scaling */ ! 113: imageinfo->SOP_Flags = SOP_Sqrt; ! 114: continue; ! 115: } ! 116: if(strcmp(argv[i],"-test") == 0 || ! 117: strcmp(argv[i],"-t") == 0) { /* test gray scale*/ ! 118: imageinfo->calibration++; ! 119: continue; ! 120: } ! 121: if(strcmp(argv[i],"-saturate") == 0 || /* set sat. lev.*/ ! 122: strcmp(argv[i],"-sat") == 0) { ! 123: if(++i >= argc) usage(argv[0]); ! 124: if((imageinfo->pmax = atoi(argv[i])) > 16383) ! 125: usage(argv[0]); ! 126: continue; ! 127: } ! 128: if(strcmp(argv[i],"-threshold") == 0 || /* set thresh lev.*/ ! 129: strcmp(argv[i],"-thr") == 0) { ! 130: if(++i >= argc) usage(argv[0]); ! 131: if((imageinfo->pmin = atoi(argv[i])) < -16383) ! 132: usage(argv[0]); ! 133: continue; ! 134: } ! 135: if(strcmp(argv[i],"-fits") == 0) { /* select fits file*/ ! 136: imageinfo->fitsflag = 1; ! 137: continue; ! 138: } ! 139: if(strcmp(argv[i],"-dfits") == 0) { /* select disk fits file*/ ! 140: imageinfo->fitsflag = 2; ! 141: continue; ! 142: } ! 143: ! 144: #ifdef XRAY ! 145: /* added by egm */ ! 146: if(strcmp(argv[i],"-ein") ==0 ){ ! 147: if(++i >= argc) usage(argv[0]); ! 148: imageinfo->iy = atoi(argv[i]); ! 149: if(++i >= argc) usage(argv[0]); ! 150: imageinfo->iz = atoi(argv[i]); ! 151: if(++i >= argc) usage(argv[0]); ! 152: imageinfo->zoom = atoi(argv[i]); ! 153: if(++i >= argc) usage(argv[0]); ! 154: imageinfo->energy = atoi(argv[i]); ! 155: imageinfo->ein = 1; ! 156: imageinfo->ncols = 512; ! 157: imageinfo->nrows = 512; ! 158: continue; ! 159: } ! 160: ! 161: if(strcmp(argv[i],"-ros") ==0 ){ ! 162: if(++i >= argc) usage(argv[0]); ! 163: imageinfo->iy = atoi(argv[i]); ! 164: if(++i >= argc) usage(argv[0]); ! 165: imageinfo->iz = atoi(argv[i]); ! 166: if(++i >= argc) usage(argv[0]); ! 167: imageinfo->zoom = atoi(argv[i]); ! 168: imageinfo->ros = 1; ! 169: imageinfo->ncols = 512; ! 170: imageinfo->nrows = 512; ! 171: continue; ! 172: } ! 173: /* end of egm code */ ! 174: #endif ! 175: ! 176: if (argv[i][0] == '-') usage(argv[0]); ! 177: imageinfo->filename = argv[i]; ! 178: } ! 179: ! 180: ! 181: /* do some consistency checks on selected options */ ! 182: if(imageinfo->headskip > 0 && ! 183: (imageinfo->nrows == 0 || imageinfo->ncols == 0)) usage(argv[0]); ! 184: ! 185: if((imageinfo->pmax == -3000 && imageinfo->pmin != 70000) || ! 186: (imageinfo->pmin == 70000 && imageinfo->pmax != -3000)) ! 187: usage(argv[0]); ! 188: ! 189: if(imageinfo->fitsflag != 0 && ! 190: (imageinfo->headskip > 0 || imageinfo->nrows != 0 || ! 191: imageinfo->ncols != 0)) ! 192: usage(argv[0]); ! 193: ! 194: if (!XOpenDisplay(maininfo->display)) { ! 195: perror(argv[0]); ! 196: exit(1); ! 197: } ! 198: ! 199: if (border_color && DisplayCells() > 2 && ! 200: XParseColor(border_color, &cdef) && XGetHardwareColor(&cdef)) ! 201: maininfo->frame.border = XMakeTile(cdef.pixel); ! 202: else if (border_color && strcmp(border_color, "black") == 0) ! 203: maininfo->frame.border = BlackPixmap; ! 204: else if (border_color && strcmp(border_color, "white") == 0) ! 205: maininfo->frame.border = WhitePixmap; ! 206: else ! 207: maininfo->frame.border = XMakePixmap (XStoreBitmap (16, 16, gray_bits), ! 208: BlackPixel, WhitePixel); ! 209: ! 210: if (back_color && DisplayCells() > 2 && ! 211: XParseColor(back_color, &cdef) && XGetHardwareColor(&cdef)) ! 212: maininfo->frame.background = XMakeTile(cdef.pixel); ! 213: else if (back_color && strcmp(back_color, "white") == 0) ! 214: maininfo->frame.background = WhitePixmap; ! 215: else ! 216: maininfo->frame.background = BlackPixmap; ! 217: ! 218: return; ! 219: } ! 220: ! 221: ! 222: usage (program) ! 223: char *program; ! 224: { ! 225: fprintf(stderr,"usage: %s [ options ] filename\n",program); ! 226: fprintf(stderr," where options are one or more of:\n"); ! 227: fprintf(stderr," [host:display] [=geom] [-bw] [-bd] [-bg]\n"); ! 228: fprintf(stderr," [-planes #] [-rgb] [-neg] [-sqrt]\n"); ! 229: fprintf(stderr," [-skip # -nrows # -ncols #]\n"); ! 230: fprintf(stderr," [-saturate # -threshold #]\n"); ! 231: fprintf(stderr," [-fits] [ -dfits ]\n"); ! 232: exit(1); ! 233: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.