/* Delete the character at the current cursor position and * shuffle down the rest of the line. * The cursor doesn't move. * The non-blank length is correctly maintained. */ void dldelete(displine *line) { char *p; char linebuf[MAXWIDTH+1]; /* Rebuild whole line here. */ getrange(line, linebuf, 1, line->wcur_col-1); for (p = linebuf ; *p != '\000' ; p++); /* p pts to end of line. */ getrange(line, p, line->wcur_col+1, line->wwidth); setadline(line, linebuf); }
void cmdGetI2C(uint8_t argc, char** argv) { if(argc == 3) { int val = i2cRead(getint(&argv[1]), getint(&argv[2])); printf_P(PSTR("Read: %d (0x%02x)\n"), val, val); } else if(argc == 4) { uint8_t minBit, maxBit; int val = i2cRead(getint(&argv[1]), getint(&argv[2])); getrange(argv[3], &minBit, &maxBit); if(maxBit < minBit) { uint8_t tmp = maxBit; maxBit = minBit; minBit = tmp; } val >>= minBit; val &= (1 << (maxBit - minBit + 1)) - 1; printf_P(PSTR("Read: %d (0x%02x)\n"), val, val); }
void httpfilereadproc(void*) { Block *b; threadsetname("httpfilereadproc"); for(;;){ b = recvp(httpchan); if(b == nil) continue; if(getrange(b) == nil) sysfatal("getrange: %r"); sendp(finishchan, b); } }
void nnsql_getrange(void* hstmt, long* pmin, long* pmax) { yystmt_t* yystmt = hstmt; range_t r; r = getrange(hstmt, yystmt->srchtree); if( !r.flag ) { *pmin = 1UL; *pmax = MAX_SIGNED_LONG; } else { *pmin = r.min; *pmax = r.max; } }
/* Insert the given character at the current cursor position. * Do nothing if the line would become too long. * Do nothing if the character is not printable. * The cursor moves to the right one column, provided it doesn't * move past dl_max_col. */ void dlinsert(displine *line, key k) { char restbuf[MAXWIDTH+1]; /* Char from cursor to end. */ char insbuf[2]; /* Char to insert. */ if (line->dl_length >= line->wwidth) return; if (!printable(k)) return; getrange(line, restbuf, line->wcur_col, line->wwidth); insbuf[0] = k; insbuf[1] = '\000'; setrange(line, insbuf, line->wcur_col, line->wcur_col); setrange(line, restbuf, line->wcur_col+1, line->wwidth); dlright(line); }
bool redis_string::getrange(const char* key, int start, int end, string& buf) { return getrange(key, strlen(key), start, end, buf); }
int main (int argc, char *argv[]) { FILE *imgfp; /* input file */ FILE *outfp; /* output file */ /*************/ /* image i/o */ /*************/ char *ptr, string[MAXL], program[MAXL], command[MAXL]; char imgroot[MAXL], imgfile[MAXL], ifhfile[MAXL]; char mskroot[MAXL], mskfile[MAXL]; char tmproot[MAXL], tmpfile[MAXL]; char trailer[MAXL] = "", outroot[MAXL], outfile[MAXL], recfile[MAXL]; /***************/ /* computation */ /***************/ float *imgv, *imgr, *imgm; float v, frac, t, del2v, dmin; float fndex[3], x[3], w[3], dvdx[3], d2vdx2[3]; float ctneg = 0.0, ctpos = 0.0; float vtneg = 0.0, vtpos = 0.0; float srad = 0.0, orad = 0; int ix, iy, iz, dim, nx, ny, nz; int c, i, j, k, l, jmin; int isbig, isbigm; char control = '\0'; /**************/ /* peak lists */ /**************/ EXTREMUM *ppos, *pneg, *pall, *pallN, ptmp[1]; int mpos = 0, mneg = 0, npos = 0, nneg = 0, nall, nallN, Nvoxcrit = 1; int npos0, npos1, npos2; int nneg0, nneg1, nneg2; /*********/ /* flags */ /*********/ int mask = 0; int status = 0; int debug = 0; int quiet = 0; int forceblur = 0; printf ("%s\n", rcsid); if (!(ptr = strrchr (argv[0], '/'))) ptr = argv[0]; else ptr++; strcpy (program, ptr); /******************************/ /* get command line arguments */ /******************************/ for (k = 0, i = 1; i < argc; i++) { if (*argv[i] == '-') { strcpy (command, argv[i]); ptr = command; while (c = *ptr++) switch (c) { case 'q': quiet++; break; case 'F': forceblur++; break; case 's': srad = atof (ptr); *ptr = '\0'; break; case 'd': dthresh = atof (ptr); *ptr = '\0'; break; case 'n': ntop = atoi (ptr); *ptr = '\0'; break; case 'N': Nvoxcrit = atoi (ptr); *ptr = '\0'; break; case 'o': orad = atof (ptr); *ptr = '\0'; break; case '@': control = *ptr++; *ptr = '\0'; break; case 'c': getrange (ptr, &ctneg, &ctpos); *ptr = '\0'; break; case 'v': getrange (ptr, &vtneg, &vtpos); *ptr = '\0'; break; case 'm': getroot (ptr, mskroot); mask++; *ptr = '\0'; break; case 'a': strncpy (trailer, ptr, MAXL - 1); *ptr = '\0'; break; } } else switch (k) { case 0: getroot (argv[i], imgroot); k++; break; } } if (k < 1) { printf ("Usage: %s <file_4dfp>\n", program); printf (" e.g., %s grand_average_222[.4dfp.img] -s10\n", program); printf ("\toption\n"); printf ("\t-s<flt>\tpreblur with hard sphere kernel of specified radius\n"); printf ("\t-n<int>\tlimit initial pos and neg peak list lengths (default=%d)\n", NTOP); printf ("\t-c<flt>[to<flt>] specify sign inverted curvature thresholds (default none)\n"); printf ("\t-v<flt>[to<flt>] specify peak value thresholds (default none)\n"); printf ("\t-d<flt>\tconsolidate extremum pairs closer than specified distance\n"); printf ("\t-o<flt>\toutput a fidl compatible 4dfp format ROI file with regions of specified radius\n"); printf ("\t-m<str>\tapply named mask file to output ROIs\n"); printf ("\t-N<int>\tspecify output ROI minimum voxel count (default = 1)\n"); printf ("\t-a<str>\tappend specified string to ROI output filename\n"); printf ("\t-q\tquiet mode (suppress rec file listing)\n"); printf ("\t-F\tforce preblur image creation even if hsphere_4dfp result exists\n"); printf ("\t-@<b|l>\toutput big or little endian (default input endian)\n"); printf ("N.B.:\toperations controlled by options -s, -n, -c, -v, -d, -o, -m, -N are applied serially in listed order\n"); printf ("N.B.:\tall distances are in mm\n"); printf ("N.B.:\toption -s<flt> creates a blurred image by invoking hsphere_4dfp\n"); printf ("N.B.:\toption -F is intended for use in iterative scripts and has no effect absent -s<flt>\n"); exit (1); } /************/ /* read ifh */ /************/ sprintf (imgfile, "%s.4dfp.img", imgroot); if (srad > 0.0) { sprintf (tmproot, "%s_%.0fmm", imgroot, srad); } else { strcpy (tmproot, imgroot); } sprintf (tmpfile, "%s.4dfp.img", tmproot); sprintf (ifhfile, "%s.4dfp.ifh", imgroot); fprintf (stdout, "Reading: %s\n", ifhfile); if (Getifh (ifhfile, &imgifh)) errr (program, ifhfile); isbig = strcmp (imgifh.imagedata_byte_order, "littleendian"); if (!control) control = (isbig) ? 'b' : 'l'; printf ("image dimensions \t%10d%10d%10d%10d\n", imgifh.matrix_size[0], imgifh.matrix_size[1], imgifh.matrix_size[2], imgifh.matrix_size[3]); printf ("image mmppix \t%10.6f%10.6f%10.6f\n", imgifh.mmppix[0], imgifh.mmppix[1], imgifh.mmppix[2]); printf ("image center \t%10.4f%10.4f%10.4f\n", imgifh.center[0], imgifh.center[1], imgifh.center[2]); printf ("image orientation\t%10d\n", imgifh.orientation); /********************************************************************/ /* check that optionally specified mask is dimensionally consistent */ /********************************************************************/ if (mask) { sprintf (mskfile, "%s.4dfp.img", mskroot); sprintf (ifhfile, "%s.4dfp.ifh", mskroot); fprintf (stdout, "Reading: %s\n", ifhfile); if (Getifh (ifhfile, &mskifh)) errr (program, ifhfile); isbigm = strcmp (mskifh.imagedata_byte_order, "littleendian"); status = imgifh.orientation - mskifh.orientation; for (k = 0; k < 3; k++) { status |= imgifh.matrix_size[k] - mskifh.matrix_size[k]; status |= (fabs ((double) (imgifh.mmppix[k] - mskifh.mmppix[k])) > 0.0001); } if (status) { fprintf (stderr, "%s: %s %s dimension mismatch\n", program, imgroot, mskroot); exit (-1); } } dim = 1; for (k = 0; k < 3; k++) dim *= imgifh.matrix_size[k]; if (!(imgv = (float *) malloc (dim * sizeof (float)))) errm (program); if (!(imgr = (float *) malloc (dim * sizeof (float)))) errm (program); if (!(imgm = (float *) malloc (dim * sizeof (float)))) errm (program); nx = imgifh.matrix_size[0]; ny = imgifh.matrix_size[1]; nz = imgifh.matrix_size[2]; /*****************************************/ /* virtual flip instead of x4dfp2ecat () */ /*****************************************/ vrtflip_ (&imgifh.orientation, imgifh.matrix_size, imgifh.center, imgifh.mmppix, centerr, mmppixr); printf ("atlas mmppix \t%10.6f%10.6f%10.6f\n", mmppixr[0], mmppixr[1], mmppixr[2]); printf ("atlas center \t%10.4f%10.4f%10.4f\n", centerr[0], centerr[1], centerr[2]); /****************************************************/ /* read filtered image or create using hpshere_4dfp */ /****************************************************/ if (forceblur || access (tmpfile, R_OK)) { sprintf (command, "hsphere_4dfp %s %.4f", imgfile, srad); printf ("%s\n", command); if (system (command)) errw (program, tmpfile); } printf ("Reading: %s\n", tmpfile); if (!(imgfp = fopen (tmpfile, "rb")) || eread (imgv, dim, isbig, imgfp) || fclose (imgfp)) errr (program, tmpfile); /************************************************************************************************/ /* intial extremum memory allocation (realloc on unassigned pointer => unpredictable core dump) */ /************************************************************************************************/ if (!(ppos = (EXTREMUM *) malloc ((mpos = MSIZE) * sizeof (EXTREMUM)))) errm (program); if (!(pneg = (EXTREMUM *) malloc ((mneg = MSIZE) * sizeof (EXTREMUM)))) errm (program); /*******************/ /* compile extrema */ /*******************/ printf ("peak value thresholds %10.4f to %10.4f\n", vtneg, vtpos); printf ("peak curvature thresholds %10.4f to %10.4f\n", ctneg, ctpos); printf ("compiling extrema slice"); for (iz = 1; iz < imgifh.matrix_size[2] - 1; iz++) {printf (" %d", iz + 1); fflush (stdout); for (iy = 1; iy < imgifh.matrix_size[1] - 1; iy++) { for (ix = 1; ix < imgifh.matrix_size[0] - 1; ix++) { i = ix + nx*(iy + ny*iz); dvdx[0] = 0.5*(-imgv[i - 1] + imgv[i + 1]); dvdx[1] = 0.5*(-imgv[i - nx] + imgv[i + nx]); dvdx[2] = 0.5*(-imgv[i - nx*ny] + imgv[i + nx*ny]); d2vdx2[0] = -2.0*imgv[i] + imgv[i - 1] + imgv[i + 1]; d2vdx2[1] = -2.0*imgv[i] + imgv[i - nx] + imgv[i + nx]; d2vdx2[2] = -2.0*imgv[i] + imgv[i - nx*ny] + imgv[i + nx*ny]; for (k = 0; k < 3; k++) w[k] = -dvdx[k] / d2vdx2[k]; for (del2v = k = 0; k < 3; k++) del2v += d2vdx2[k] / (mmppixr[k] * mmppixr[k]); fndex[0] = (float) (ix + 1) + w[0]; fndex[1] = (float) (iy + 1) + w[1]; fndex[2] = (float) (iz + 1) + w[2]; for (k = 0; k < 3; k++) x[k] = fndex[k] * mmppixr[k] - centerr[k]; if (imgv[i] > 0.0 && del2v <= -ctpos && imgv[i] > imgv[i - 1] && imgv[i] > imgv[i + 1] && imgv[i] > imgv[i - nx] && imgv[i] > imgv[i + nx] && imgv[i] > imgv[i - nx*ny] && imgv[i] > imgv[i + nx*ny]) { imgvalx_ (imgv, &nx, &ny, &nz, centerr, mmppixr, x, &t, &l); if (l < 1) {printf ("undefined imgvalx point\n"); continue;} if (t < vtpos) continue; if (mpos <= npos) { mpos += MSIZE; if (!(ppos = (EXTREMUM *) realloc (ppos, mpos * sizeof (EXTREMUM)))) errm (program); } for (k = 0; k < 3; k++) ppos[npos].x[k] = x[k]; ppos[npos].v = t; ppos[npos].del2v = del2v; ppos[npos].weight = 1.0; ppos[npos].nvox = ppos[npos].killed = 0; npos++; } if (imgv[i] < 0.0 && del2v >= -ctneg && imgv[i] < imgv[i - 1] && imgv[i] < imgv[i + 1] && imgv[i] < imgv[i - nx] && imgv[i] < imgv[i + nx] && imgv[i] < imgv[i - nx*ny] && imgv[i] < imgv[i + nx*ny]) { imgvalx_ (imgv, &nx, &ny, &nz, centerr, mmppixr, x, &t, &l); if (l < 1) {printf ("undefined imgvalx point\n"); continue;} if (t > vtneg) continue; if (mneg <= nneg) { mneg += MSIZE; if (!(pneg = (EXTREMUM *) realloc (pneg, mneg * sizeof (EXTREMUM)))) errm (program); } for (k = 0; k < 3; k++) pneg[nneg].x[k] = x[k]; pneg[nneg].v = t; pneg[nneg].del2v = del2v; pneg[nneg].weight = 1.0; pneg[nneg].nvox = pneg[nneg].killed = 0; nneg++; } }}} printf ("\n"); fflush (stdout); printf ("before sorting npos=%d nneg=%d\n", npos, nneg); npos0 = npos; nneg0 = nneg; qsort ((void *) ppos, npos, sizeof (EXTREMUM), pcompare); qsort ((void *) pneg, nneg, sizeof (EXTREMUM), pcompare); printf ("positive peaks\n"); ntot = 0; peaklist (stdout, ppos, npos, 0); npos1 = ntot; if (dthresh > 0.0) consolidate (ppos, npos); printf ("negative peaks\n"); ntot = 0; peaklist (stdout, pneg, nneg, 0); nneg1 = ntot; if (dthresh > 0.0) consolidate (pneg, nneg); printf ("final peak list\n"); ntot = 0; peaklist (stdout, ppos, npos, 0); peaklist (stdout, pneg, nneg, 0); /********************************************/ /* combine positive and negative peak lists */ /********************************************/ if (!(pall = (EXTREMUM *) malloc (ntot * sizeof (EXTREMUM)))) errm (program); nall = 0; for (npos2 = i = 0; i < ntop && i < npos; i++) if (!ppos[i].killed) {pall[nall++] = ppos[i]; npos2++;} for (nneg2 = i = 0; i < ntop && i < nneg; i++) if (!pneg[i].killed) {pall[nall++] = pneg[i]; nneg2++;} assert (ntot == nall); free (ppos); free (pneg); if (orad == 0.0) goto DONE; /***************************/ /* create output ROI image */ /***************************/ printf ("Reading: %s\n", imgfile); if (!(imgfp = fopen (imgfile, "rb")) || eread (imgv, dim, isbig, imgfp) || fclose (imgfp)) errr (program, imgfile); if (mask) { printf ("Reading: %s\n", mskfile); if (!(imgfp = fopen (mskfile, "rb")) || eread (imgm, dim, isbigm, imgfp) || fclose (imgfp)) errr (program, mskfile); } /****************************/ /* count voxels in each ROI */ /****************************/ for (iz = 0; iz < imgifh.matrix_size[2]; iz++) { for (iy = 0; iy < imgifh.matrix_size[1]; iy++) { for (ix = 0; ix < imgifh.matrix_size[0]; ix++) { i = ix + nx*(iy + ny*iz); fndex[0] = (float) (ix + 1); fndex[1] = (float) (iy + 1); fndex[2] = (float) (iz + 1); for (k = 0; k < 3; k++) ptmp[0].x[k] = fndex[k]*mmppixr[k] - centerr[k]; dmin = 1.e6; for (j = 0; j < nall; j++) { t = (float) pdist (ptmp, pall + j); if (t < dmin) { jmin = j; dmin = t; } } k = !mask || (fabs (imgm[i]) > 1.e-37); if (k && (dmin < orad)) pall[jmin].nvox++; }}} /*******************************/ /* apply voxel count criterion */ /*******************************/ for (i = 0; i < ntot; i++) if (pall[i].nvox < Nvoxcrit) pall[i].killed = 1; if (!(pallN = (EXTREMUM *) malloc (ntot * sizeof (EXTREMUM)))) errm (program); for (nallN = i = 0; i < ntot; i++) if (!pall[i].killed) pallN[nallN++] = pall[i]; free (pall); printf ("creating ROI slice"); for (iz = 0; iz < imgifh.matrix_size[2]; iz++) {printf (" %d", iz + 1); fflush (stdout); for (iy = 0; iy < imgifh.matrix_size[1]; iy++) { for (ix = 0; ix < imgifh.matrix_size[0]; ix++) { i = ix + nx*(iy + ny*iz); imgr[i] = 0.0; fndex[0] = (float) (ix + 1); fndex[1] = (float) (iy + 1); fndex[2] = (float) (iz + 1); for (k = 0; k < 3; k++) ptmp[0].x[k] = fndex[k]*mmppixr[k] - centerr[k]; dmin = 1.e6; for (j = 0; j < nallN; j++) { t = (float) pdist (ptmp, pallN + j); if (t < dmin) { jmin = j; dmin = t; } } k = !mask || (fabs (imgm[i]) > 1.e-37); if (k && (dmin < orad)) imgr[i] = jmin + 2; }}} printf ("\n"); fflush (stdout); if (!(ptr = strrchr (imgroot, '/'))) ptr = imgroot; else ptr++; if (strlen (trailer)) { sprintf (outroot, "%s_ROI_%s", ptr, trailer); } else { sprintf (outroot, "%s_ROI", ptr); } sprintf (outfile, "%s.4dfp.img", outroot); printf ("Writing: %s\n", outfile); if (!(outfp = fopen (outfile, "wb")) || ewrite (imgr, dim, control, outfp) || fclose (outfp)) errw (program, outfile); /********************************************/ /* output ROI ifh and make analyze hdr file */ /********************************************/ if (Writeifh (program, outfile, &imgifh, control)) errw (program, outroot); sprintf (outfile, "%s.4dfp.ifh", outroot); if (!(outfp = fopen (outfile, "a"))) errw (program, outfile); for (i = 0; i < nallN; i++) { fprintf (outfp, "region names\t:= %-5droi_%+03d_%+03d_%+03d%10d\n", i, nint (pallN[i].x[0]), nint (pallN[i].x[1]), nint (pallN[i].x[2]), pallN[i].nvox); } fclose (outfp); /********************/ /* make analyze hdr */ /********************/ sprintf (command, "ifh2hdr %s -r%d", outroot, nallN + 1); printf ("%s\n", command); status |= system (command); /******************/ /* output ROI rec */ /******************/ sprintf (outfile, "%s.4dfp.img", outroot); startrece (outfile, argc, argv, rcsid, control); sprintf (recfile, "%s.rec", outfile); if (!(outfp = fopen (recfile, "a"))) errw (program, recfile); fprintf (outfp, "Peak value thresholds %10.4f to %10.4f\n", vtneg, vtpos); fprintf (outfp, "Peak curvature thresholds %10.4f to %10.4f\n", ctneg, ctpos); fprintf (outfp, "Peak counts before sorting pos=%d neg=%d\n", npos0, nneg0); fprintf (outfp, "Peak counts after sorting pos=%d neg=%d\n", npos1, nneg1); fprintf (outfp, "Peak counts after %.4f mm threshold consolidation pos=%d neg=%d\n", dthresh, npos2, nneg2); ntot = 0; peaklist (outfp, pallN, nallN, 1); free (pallN); fprintf (outfp, "N.B.: indices count from 1 and include orientation specific 4dfptoanalyze flips\n"); fclose (outfp); catrec (tmpfile); if (mask) catrec (mskfile); endrec (); sprintf (command, "brec %s -2", recfile); if (!quiet) system (command); DONE: free (imgv); free (imgr); free (imgm); exit (status); }
int main (int argc, char *argv[]) { FILE *imgfp, *datfp; char imgroot[MAXL], imgfile[MAXL], gfcfile[MAXL], ifhfile[MAXL]; char outroot[MAXL], outfile[MAXL], datfile[MAXL], volfile[MAXL], recfile[MAXL]; char program[MAXL], string[MAXL], command[MAXL], *ptr; int isbig; char control = '\0'; IFH ifh; UCHAR ix, iy, iz; XYZN xyzn; int iv, iv0, jv, imgdim[3]; int ir, jr, nn; int c, i, j, k, m, n; double dela, delg, u1; float vmin, vmax, fwhm = 0., alpha = ALPHA, *img_orig=NULL; float maxfac = 0.0; /**************/ /* gain field */ /**************/ int norder = NORDER, nterm = NTERM; int niter = 0, limiter = LIMITER; int eight = 8; /* field length for call to powstring_ () */ float a[NTERM], /* polynomial coefficients */ a0[NTERM]; float drms, diffcrit = DIFFCRIT; float u1gfc[MAXR]; double sum0, sum, q, t; /*********/ /* flags */ /*********/ int test = 0; int status = 0; int debug = 0; int gfreeze = 0; int verbose = 0; int negdef = 0; if (!(ptr = strrchr (argv[0], '/'))) ptr = argv[0]; else ptr++; strcpy (program, ptr); /************************/ /* process command line */ /************************/ for (k = 0, i = 1; i < argc; i++) if (*argv[i] == '-') { strcpy (string, argv[i]); ptr = string; while (c = *ptr++) switch (c) { case 'v': verbose++; break; case 'n': negdef++; break; case 'g': gfreeze++; break; case '@': control = *ptr++; *ptr = '\0'; break; case 'b': g_bandwidth = atof (ptr); *ptr = '\0'; break; case 'p': fwhm = atof (ptr); *ptr = '\0'; break; case 'e': diffcrit = atof (ptr); *ptr = '\0'; break; case 'i': g_sigma = atof (ptr); *ptr = '\0'; break; case 'l': limiter = atoi (ptr); *ptr = '\0'; break; case 'm': g_mr = atoi (ptr); *ptr = '\0'; break; case 's': g_sconst = atof (ptr); *ptr = '\0'; break; case 'z': g_zthresh = atof (ptr); *ptr = '\0'; break; case 'M': maxfac = atof (ptr); *ptr = '\0'; break; case 'r': getrange (ptr, &g_gfc_thresh, &g_gfc_ceil); *ptr = '\0'; break; } } else switch (k) { case 0: getroot (argv[i], imgroot); k++; break; } if (k < 1) { fprintf (stderr, "Usage:\t%s <imgroot>\n", program); fprintf (stderr, " e.g.,\t%s vc1440_mpr_n4_111_t88.4dfp\n", program); /*??*/ fprintf (stderr, "\toption\n"); fprintf (stderr, "\t-g freeze initial gain field\n"); fprintf (stderr, "\t-n force negative definite quadratic gain field\n"); fprintf (stderr, "\t-v verbose mode\n"); fprintf (stderr, "\t-p<flt> pre-blur by specified FWHM in mm\n"); fprintf (stderr, "\t-b<flt>\tspecify bandwidth in intensity units (default=%.1f)\n", BANDWIDTH); fprintf (stderr, "\t-e<flt>\tspecify drms convergence criterion (default=%f)\n", DIFFCRIT); fprintf (stderr, "\t-i<flt>\tspecify sigma (default=%f)\n", SIGMA); fprintf (stderr, "\t-l<int>\tspecify iteration limit (default=%d)\n", LIMITER); fprintf (stderr, "\t-m<flt>\tspecify gfc computation region count (default=%d)\n", MR); fprintf (stderr, "\t-s<flt>\tspecify space constant in mm (default=%f)\n", SCONST); fprintf (stderr, "\t-z<flt>\tspecify background threshold (default=%.1f)\n", ZTHRESH); fprintf (stderr, "\t-M<flt>\tspecify maximum correction factor\n"); fprintf (stderr, "\t-r<flt>[to<flt>]\tspecify gfc range (default=%.1fto%.1f)\n", GFC_THRESH, GFC_CEIL); exit (1); } /*******************************************/ /* read/initialize gain field coefficients */ /*******************************************/ sprintf (gfcfile, "%s.4dfp.gfc", imgroot); if (imgfp = fopen (gfcfile, "r")) { printf ("Reading: %s\n", gfcfile); for (k = 0; k < nterm; k++) fscanf (imgfp, "%f", a + k); fclose (imgfp); } else { a[0] = 1.0; for (k = 1; k < nterm; k++) a[k] = 0.0; } for (k = 0; k < nterm; k++) fprintf (stdout, "%8.4f", a[k]); fprintf (stdout, "\n"); /******************************/ /* get input image dimensions */ /******************************/ if (Getifh (imgroot, &ifh) != 0) errr (program, imgroot); isbig = strcmp (ifh.imagedata_byte_order, "littleendian"); if (!control) control = (isbig) ? 'b' : 'l'; for (k = 0; k < 3; k++) g_voxdim[k] = ifh.scaling_factor[k]; if (debug) printf ("%10.6f%10.6f%10.6f\n", g_voxdim[0], g_voxdim[1], g_voxdim[2]); g_dimension = ((g_xdim = ifh.matrix_size[0]) *(g_ydim = ifh.matrix_size[1]) *(g_zdim = ifh.matrix_size[2])); /************************************************/ /* check image index limits against XYZN typedef */ /*************************************************/ if (g_xdim > MAXD || g_ydim > MAXD || g_zdim > MAXD) { fprintf (stderr, "%s: %s dimension exceeds %d\n", program, imgroot, MAXD); exit (-1); } if (ifh.number_of_bytes_per_pixel != 4) { printf ("%s: cannot process %d bytes per pixel", program, ifh.number_of_bytes_per_pixel); exit (-1); } /************/ /* allocate */ /************/ if (!(g_img1 = (float *) malloc (g_dimension * sizeof (float))) || !(g_img0 = (float *) malloc (g_dimension * sizeof (float))) || !(g_imgg = (float *) malloc (g_dimension * sizeof (float))) || !(g_imgo = (short *) calloc (g_dimension, sizeof (short))) || !(g_imgb = (UCHAR *) calloc (g_dimension, sizeof (UCHAR)))) errm (program); sprintf (imgfile, "%s.4dfp.img", imgroot); printf ("Reading: %s\n", imgfile); if (!(imgfp = fopen (imgfile, "rb")) || eread (g_img0, g_dimension, isbig, imgfp) || fclose (imgfp)) errr (program, imgfile); /******************/ /* pre-blur image */ /******************/ if (!gfreeze && fwhm > 0) { if (!(img_orig = (float *) malloc (g_dimension * sizeof (float)))) errm (program); /*************************************/ /* img_orig will hold original image */ /*************************************/ memcpy (img_orig, g_img0, g_dimension*sizeof(float)); memcpy (g_img1, g_img0, g_dimension*sizeof(float)); printf ("blur FWHM = %.2f mm\n", fwhm); imgdim[0] = g_xdim; imgdim[1] = g_ydim; imgdim[2] = g_zdim; imgblur3d_ (&fwhm, &alpha, g_voxdim, g_img1, imgdim, g_img0); /* g_img1 returned unusable */ /************************************************************************/ /* g_img0 now points to blurred image to be used in further computation */ /************************************************************************/ } /*******************/ /* compute outroot */ /*******************/ if (ptr = strrchr (imgroot, '/')) ptr++; else ptr = imgroot; getroot (ptr, outroot); /*********************/ /* apply initial gfc */ /*********************/ evalgain3d_ (g_imgg, &g_xdim, &g_ydim, &g_zdim, &norder, a); for (sum = sum0 = i = 0; i < g_dimension; i++) { sum0 += g_img0[i]; sum += (g_img1[i] = g_img0[i]/g_imgg[i]); } for (i = 0; i < g_dimension; i++) g_img1[i] *= (sum0/sum); if (gfreeze) goto WRITE; /****************/ /* open datfile */ /****************/ sprintf (datfile, "%s_gfc.dat", outroot); if (!(datfp = fopen (datfile, "a"))) errw (program, datfile); powstring_ (&norder, &eight, string); fprintf (datfp, "#\t%s\n", string); fprintf (datfp, "%d\t", niter); for (k = 0; k < nterm; k++) fprintf (datfp, "%8.4f", a[k]); fprintf (datfp, "%8.4f\n", 0.0); fflush (datfp); /***********************/ /* clear region buffer */ /***********************/ memset (&g_region, '\0', MAXR * sizeof (REGION)); iv0 = ir = 0; /***************************/ /* find contiguous regions */ /***************************/ CONTIG: while (ir < MAXR) { for (iv = iv0; iv < g_dimension; iv++) if (!g_imgo[iv]) break; if (iv == g_dimension) break; iv0 = iv; g_imgo[iv] = ir + 1; g_region[ir].u1 = (floor (g_img1[iv] / g_bandwidth) + 0.5) * g_bandwidth; k = iv; j = g_dimension; j /= g_zdim; iz = k / j; k -= iz * j; j /= g_ydim; iy = k / j; k -= iy * j; j /= g_xdim; ix = k / j; k -= ix * j; xyzn.ix = ix; xyzn.iy = iy; xyzn.iz = iz; xyzn.nn = 0; assign (ir, xyzn); do { m = g_region[ir].ne++; iv = g_region[ir].xyzn[m].ix + g_xdim*(g_region[ir].xyzn[m].iy + g_ydim*g_region[ir].xyzn[m].iz); for (j = 0; j < 6; j++) { xyzn = g_region[ir].xyzn[m]; switch (j) { case 0: k = -1; if (xyzn.ix < 1) continue; xyzn.ix--; break; case 1: k *= -1; if (xyzn.ix > g_xdim - 2) continue; xyzn.ix++; break; case 2: k *= -g_xdim; if (xyzn.iy < 1) continue; xyzn.iy--; break; case 3: k *= -1; if (xyzn.iy > g_ydim - 2) continue; xyzn.iy++; break; case 4: k *= -g_ydim; if (xyzn.iz < 1) continue; xyzn.iz--; break; case 5: k *= -1; if (xyzn.iz > g_zdim - 2) continue; xyzn.iz++; break; } jv = iv + k; if (g_imgo[jv] || g_img0[jv] < g_zthresh) continue; dela = g_img1[jv] - g_region[ir].u1; if (fabs (dela) < 0.5 * g_bandwidth) { g_imgo[jv] = ir + 1; assign (ir, xyzn); } } if (verbose && !(g_region[ir].count % 1000)) { xyzn = g_region[ir].xyzn[m]; printf ("checkr0: region=%4d unexa=%8d coords=%4d%4d%4d u1=%8.2f\n", ir, g_region[ir].count - m, xyzn.ix, xyzn.iy, xyzn.iz, g_region[ir].u1); } } while (g_region[ir].count > g_region[ir].ne); if (g_region[ir].count == 1) { iv = g_region[ir].xyzn[0].ix + g_xdim*(g_region[ir].xyzn[0].iy + g_ydim*g_region[ir].xyzn[0].iz); g_imgo[iv] = -1; g_region[ir].count = g_region[ir].ne = 0; } else { ir++; } } /************************/ /* sort regions by size */ /************************/ qsort ((void *) g_region, ir, sizeof (REGION), rcompare); if (ir == MAXR) { if (verbose) printf ("ir %d -> %d iv0=%10d ivmax=%d\n", ir, MAXR/2, iv0, g_dimension); while (--ir > MAXR/2) { for (m = 0; m < g_region[ir].count; m++) { xyzn = g_region[ir].xyzn[m]; iv = xyzn.ix + g_xdim*(xyzn.iy + g_ydim*xyzn.iz); g_imgo[iv] = 0; } g_region[ir].count = g_region[ir].ne = 0; } goto CONTIG; } g_nr = ir; for (ir = g_nr; ir < MAXR; ir++) if (g_region[ir].xyzn) free (g_region[ir].xyzn); test = 1; ITER: getmean (); /* analyze g_img1 */ getxyzn0 (); /* analyze g_img1 */ /********************/ /* reassign regions */ /********************/ for (i = 0; i < g_dimension; i++) g_imgo[i] = 0; printf ("total number of regions %d\n", g_nr); for (ir = 0; ir < g_nr; ir++) { g_region[ir].ne = g_region[ir].count = 0; if (g_region[ir].u1 < g_gfc_thresh || g_region[ir].u1 > g_gfc_ceil) continue; assign (ir, g_region[ir].xyzn0); do { m = g_region[ir].ne++; xyzn = g_region[ir].xyzn[m]; iv = xyzn.ix + g_xdim*(xyzn.iy + g_ydim*xyzn.iz); for (j = 0; j < 6; j++) { xyzn = g_region[ir].xyzn[m]; switch (j) { case 0: k = -1; if (xyzn.ix < 1) continue; xyzn.ix--; break; case 1: k *= -1; if (xyzn.ix > g_xdim - 2) continue; xyzn.ix++; break; case 2: k *= -g_xdim; if (xyzn.iy < 1) continue; xyzn.iy--; break; case 3: k *= -1; if (xyzn.iy > g_ydim - 2) continue; xyzn.iy++; break; case 4: k *= -g_ydim; if (xyzn.iz < 1) continue; xyzn.iz--; break; case 5: k *= -1; if (xyzn.iz > g_zdim - 2) continue; xyzn.iz++; break; } jv = iv + k; if (g_imgo[jv] || g_img0[jv] < g_zthresh) continue; dela = g_img1[jv] - g_region[ir].u1; delg = g_sconst * (g_img1[jv] - g_img1[iv]) / g_voxdim[j/2]; if (sqrt (dela*dela + delg*delg) < g_sigma*g_bandwidth) { g_imgo[jv] = ir + 1; assign (ir, xyzn); } } if (verbose && !(g_region[ir].count % 1000)) { xyzn = g_region[ir].xyzn[m]; printf ("checkr1: region=%4d unexa=%8d coords=%4d%4d%4d u1=%8.2f\n", ir, g_region[ir].count - m, xyzn.ix, xyzn.iy, xyzn.iz, g_region[ir].u1); } } while (g_region[ir].count > g_region[ir].ne); } getmean (); getxyzn0 (); /* analyze g_img1 */ listreg (stdout); if (g_region[0].u1 < g_bandwidth) { fprintf (stderr, "%s: algorithmic failure\n", program); exit (-1); } if (++niter > limiter || !test) goto COUNT; fprintf (stdout, "%s: iteration %d\n", program, niter); /***************/ /* compute gfc */ /***************/ for (ir = 0; ir < g_nr; ir++) u1gfc[ir] = g_region[ir].u1; for (k = 0; k < nterm; k++) a0[k] = a[k]; fitgain3dd_ (g_img0, &g_xdim, &g_ydim, &g_zdim, g_imgo, u1gfc, &g_mr, &norder, a, &drms); if (negdef) fnegdef_ (a); printf ("niter=%d drms=%.6f diffcrit=%.6f\n", niter, drms, diffcrit); fprintf (datfp, "%d\t", niter); for (k = 0; k < nterm; k++) fprintf (datfp, "%8.4f", a[k]); fprintf (datfp, "%8.4f\n", 100*drms); fflush (datfp); evalgain3d_ (g_imgg, &g_xdim, &g_ydim, &g_zdim, &norder, a); for (sum = i = 0; i < g_dimension; i++) sum += (g_img1[i] = g_img0[i]/g_imgg[i]); for ( i = 0; i < g_dimension; i++) g_img1[i] *= (sum0/sum); /********************/ /* convergence test */ /********************/ test = (drms > diffcrit); goto ITER; COUNT: fclose (datfp); /*******************/ /* count neighbors */ /*******************/ for (ir = 0; ir < g_nr; ir++) { for (g_nl = m = 0; m < g_region[ir].count; m++) { ix = g_region[ir].xyzn[m].ix; iy = g_region[ir].xyzn[m].iy; iz = g_region[ir].xyzn[m].iz; iv = ix + g_xdim*(iy + g_ydim*iz); nn = 0; k = -1; if (ix > 0) {if ((j = g_imgo[iv + k]) == ir + 1) nn++; else enter (j);} k *= -1; if (ix < g_xdim - 1) {if ((j = g_imgo[iv + k]) == ir + 1) nn++; else enter (j);} k *= -g_xdim; if (iy > 0) {if ((j = g_imgo[iv + k]) == ir + 1) nn++; else enter (j);} k *= -1; if (iy < g_ydim - 1) {if ((j = g_imgo[iv + k]) == ir + 1) nn++; else enter (j);} k *= -g_ydim; if (iz > 0) {if ((j = g_imgo[iv + k]) == ir + 1) nn++; else enter (j);} k *= -1; if (iz < g_zdim - 1) {if ((j = g_imgo[iv + k]) == ir + 1) nn++; else enter (j);} if (nn > g_region[ir].nnmax) g_region[ir].nnmax = nn; g_imgb[iv] = g_region[ir].xyzn[m].nn = nn; } if (verbose) { printf ("%5d%10d%10d%5d%2d |", ir, g_region[ir].count, k, j, g_region[ir].nnmax); for (i = 0; i < g_nl; i++) printf (" %d", g_list[i]); printf ("\n"); } } /*********************************/ /* write gain field coefficients */ /*********************************/ if (!(imgfp = fopen (gfcfile, "w"))) errw (program, gfcfile); printf ("Writing: %s\n", gfcfile); for (k = 0; k < nterm; k++) fprintf (imgfp, "%8.4f", a[k]); fprintf (imgfp, "\n"); fclose (imgfp); /*************************/ /* write corrected image */ /*************************/ WRITE: for (sum0 = sum = i = 0; i < g_dimension; i++) { if (!gfreeze && fwhm > 0) g_img0[i] = img_orig[i]; sum0 += g_img0[i]; q = 1./g_imgg[i]; t = (maxfac > 0.0) ? 2.*maxfac*tanh(.5*q/maxfac) : q; if (0) printf ("%10.6f %10.6f\n", q, t); sum += (g_img1[i] = g_img0[i]*t); } for (i = 0; i < g_dimension; i++) g_img1[i] *= (sum0/sum); vmin = FLT_MAX; vmax = -vmin; for (i = 0; i < g_dimension; i++) { if (g_img1[i] < vmin) vmin = g_img1[i]; if (g_img1[i] > vmax) vmax = g_img1[i]; } sprintf (outfile, "%s_gfc.4dfp.img", outroot); fprintf (stdout, "Writing: %s\n", outfile); if (!(imgfp = fopen (outfile, "wb")) || ewrite (g_img1, g_dimension, control, imgfp) || fclose (imgfp)) errw (program, outfile); /***************/ /* ifh and hdr */ /***************/ sprintf (ifhfile, "%s_gfc.4dfp.ifh", outroot); if (Writeifh (program, ifhfile, &ifh, control)) errw (program, ifhfile); sprintf (command, "ifh2hdr %s -r%.0f", ifhfile, vmax); system (command); /*******/ /* rec */ /*******/ startrece (outfile, argc, argv, g_rcsid, control); sprintf (string, "%s gain field coefficients\n", imgroot); printrec (string); powstring_ (&norder, &eight, string); printrec (string); for (k = 0; k < nterm; k++) {sprintf (string, "%8.4f", a[k]); printrec (string);} printrec ("\n"); if (!gfreeze) { sprintf (recfile, "%s_gfc.4dfp.img.rec", outroot); if (!(imgfp = fopen (recfile, "a"))) errw (program, recfile); listreg (imgfp); fclose (imgfp); } catrec (imgfile); endrec (); if (gfreeze) goto FREE; /*************************/ /* compute regions image */ /*************************/ for (i = 0; i < g_dimension; i++) g_img1[i] = 0; for (ir = 0; ir < g_mr; ir++) { for (m = 0; m < g_region[ir].count; m++) { xyzn = g_region[ir].xyzn[m]; iv = xyzn.ix + g_xdim*(xyzn.iy + g_ydim*xyzn.iz); g_img1[iv] = g_region[ir].u1; } } /******************************/ /* write processing QA images */ /******************************/ sprintf (volfile, "%s_gfc_vols.4dfp.img", outroot); printf ("Writing: %s\n", volfile); if (!(imgfp = fopen (volfile, "w"))) errw (program, volfile); /*****************/ /* regions image */ /*****************/ if (ewrite (g_img1, g_dimension, control, imgfp)) errw (program, volfile); /****************/ /* border image */ /****************/ for (i = 0; i < g_dimension; i++) g_img1[i] = g_imgb[i]; if (ewrite (g_img1, g_dimension, control, imgfp)) errw (program, volfile); /**************/ /* gain field */ /**************/ for (i = 0; i < g_dimension; i++) g_img1[i] = g_imgg[i]; if (ewrite (g_img1, g_dimension, control, imgfp)) errw (program, volfile); fclose (imgfp); /***************/ /* ifh and hdr */ /***************/ sprintf (ifhfile, "%s_gfc_vols.4dfp.ifh", outroot); ifh.matrix_size[3] = 3; if (Writeifh (program, ifhfile, &ifh, control)) errw (program, ifhfile); sprintf (string, "ifh2hdr %s -r%.0f", ifhfile, vmax); system (string); /*******/ /* rec */ /*******/ startrece (volfile, argc, argv, g_rcsid, control); sprintf (string, "%s_gfc QA (3 volumes)\n", imgroot); printrec (string); catrec (outfile); printrec ("Volume 1: regions\nVolume 2: border\nVolume 3: gain field\n"); endrec (); /************/ /* clean up */ /************/ FREE: free (g_img1); free (g_img0); free (g_imgg); free (g_imgo); free (g_imgb); if (img_orig) free (img_orig); for (ir = 0; ir < g_nr; ir++) free (g_region[ir].xyzn); exit (status); }
static void sinusrow (GimpDrawable *drawable) { gint i, j, k, channels; gint x1, y1, x2, y2; GimpPixelRgn rgn_in, rgn_out; guchar *inrow; guchar *outrow; /* guchar output[4]; */ /* Gets upper left and lower right coordinates, * and layers number in the image */ gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); channels = gimp_drawable_bpp (drawable->drawable_id); /* Initialises two PixelRgns, one to read original data, * and the other to write output data. That second one will * be merged at the end by the call to * gimp_drawable_merge_shadow() */ gimp_pixel_rgn_init (&rgn_in, drawable, x1, y1, x2 - x1, y2 - y1, FALSE, FALSE); gimp_pixel_rgn_init (&rgn_out, drawable, x1, y1, x2 - x1, y2 - y1, TRUE, TRUE); /* Initialise enough memory for inrow, outrow */ inrow = g_new (guchar, channels * (x2 - x1)); outrow = g_new (guchar, channels * (x2 - x1)); guchar minp[4],maxp[4]; getrange(drawable, minp, maxp, x1, x2, y1, y2); for (i = y1; i < y2; i++) { /* Get row i */ gimp_pixel_rgn_get_row (&rgn_in, inrow, x1, i, x2 - x1); for (j = x1; j < x2; j++) { /* For each layer, compute the average of the nine * pixels */ for (k = 0; k < channels; k++) { double angle = inrow[channels * (j - x1) + k], max=255; angle = M_2_PI * (angle / max ) ; outrow[channels * (j - x1) + k] = (guchar)(255*(1+sin(angle))/2); } } /*end for j each pixel of the row*/ gimp_pixel_rgn_set_row (&rgn_out, outrow, x1, i, x2 - x1); if (i % 10 == 0) gimp_progress_update ((gdouble) (i - x1) / (gdouble) (x2 - x1)); } /*end for i each row*/ g_free (inrow); g_free (outrow); /* Update the modified region */ gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_update (drawable->drawable_id, x1, y1, x2 - x1, y2 - y1); }
int main (int argc, char **argv) { /* * Get the program name. The program name is used as a prefix to * most error messages. */ Prog = Basename (argv[0]); (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); process_root_flag ("-R", argc, argv); #ifdef WITH_AUDIT audit_help_open (); #endif { int c; static struct option const longopts[] = { {"before", required_argument, NULL, 'b'}, {"clear", no_argument, NULL, 'C'}, {"help", no_argument, NULL, 'h'}, {"root", required_argument, NULL, 'R'}, {"set", no_argument, NULL, 'S'}, {"time", required_argument, NULL, 't'}, {"user", required_argument, NULL, 'u'}, {NULL, 0, NULL, '\0'} }; while ((c = getopt_long (argc, argv, "b:ChR:St:u:", longopts, NULL)) != -1) { switch (c) { case 'b': { unsigned long inverse_days; if (getulong (optarg, &inverse_days) == 0) { fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); exit (EXIT_FAILURE); } inverse_seconds = (time_t) inverse_days * DAY; bflg = true; break; } case 'C': { Cflg = true; break; } case 'h': usage (EXIT_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ break; case 'S': { Sflg = true; break; } case 't': { unsigned long days; if (getulong (optarg, &days) == 0) { fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); exit (EXIT_FAILURE); } seconds = (time_t) days * DAY; tflg = true; break; } case 'u': { const struct passwd *pwent; /* * The user can be: * - a login name * - numerical * - a numerical login ID * - a range (-x, x-, x-y) */ uflg = true; /* local, no need for xgetpwnam */ pwent = getpwnam (optarg); if (NULL != pwent) { umin = (unsigned long) pwent->pw_uid; has_umin = true; umax = umin; has_umax = true; } else { if (getrange (optarg, &umin, &has_umin, &umax, &has_umax) == 0) { fprintf (stderr, _("%s: Unknown user or range: %s\n"), Prog, optarg); exit (EXIT_FAILURE); } } break; } default: usage (EXIT_FAILURE); /*@notreached@*/break; } } if (argc > optind) { fprintf (stderr, _("%s: unexpected argument: %s\n"), Prog, argv[optind]); usage (EXIT_FAILURE); } if (Cflg && Sflg) { fprintf (stderr, _("%s: Option -C cannot be used together with option -S\n"), Prog); usage (EXIT_FAILURE); } if ((Cflg || Sflg) && !uflg) { fprintf (stderr, _("%s: Options -C and -S require option -u to specify the user\n"), Prog); usage (EXIT_FAILURE); } } lastlogfile = fopen (LASTLOG_FILE, (Cflg || Sflg)?"r+":"r"); if (NULL == lastlogfile) { perror (LASTLOG_FILE); exit (EXIT_FAILURE); } /* Get the lastlog size */ if (fstat (fileno (lastlogfile), &statbuf) != 0) { fprintf (stderr, _("%s: Cannot get the size of %s: %s\n"), Prog, LASTLOG_FILE, strerror (errno)); exit (EXIT_FAILURE); } if (Cflg || Sflg) update (); else print (); (void) fclose (lastlogfile); return EXIT_SUCCESS; }
int PLP_rangesweep() { char attr[NAMEMAXLEN], *line, *lineval; int lvp, first; int i, j, stat, npoints, result, xfield, lofield, hifield; double start, stop, xstart, f; double x, lo, hi, lastx, lastlo, lasthi; char *color, *legendlabel, *selectex; char oldcolor[COLORLEN]; TDH_errprog( "pl proc rangesweep" ); /* initialize */ xfield = -1; lofield = -1; hifield = -1; start = EDXlo; stop = EDXhi; xstart = EDXlo; color = "gray(0.9)"; legendlabel = ""; selectex = ""; /* get attributes.. */ first = 1; while( 1 ) { line = getnextattr( first, attr, &lvp ); if( line == NULL ) break; first = 0; lineval = &line[lvp]; if( strcmp( attr, "xfield" )==0 ) xfield = fref( lineval ) - 1; else if( strcmp( attr, "lofield" )==0 ) lofield = fref( lineval ) - 1; else if( strcmp( attr, "hifield" )==0 ) hifield = fref( lineval ) - 1; else if( strcmp( attr, "legendlabel" )==0 ) legendlabel = lineval; else if( strcmp( attr, "sweeprange" )==0 ) getrange( lineval, &start, &stop, 'x', EDXlo, EDXhi ); else if( strcmp( attr, "xstart" )==0 ) { xstart = Econv( X, lineval ); if( Econv_error() ) xstart = EDXlo; } else if( strcmp( attr, "select" )==0 ) selectex = lineval; else if( strcmp( attr, "color" )==0 ) color = lineval; else Eerr( 1, "attribute not recognized", attr ); } /* -------------------------- */ /* overrides and degenerate cases */ /* -------------------------- */ if( Nrecords < 1 ) return( Eerr( 17, "No data has been read yet w/ proc getdata", "" ) ); if( !scalebeenset() ) return( Eerr( 51, "No scaled plotting area has been defined yet w/ proc areadef", "" ) ); if( (lofield < 0 || lofield >= Nfields )) return( Eerr( 601, "lofield out of range", "" ) ); if( (hifield < 0 || hifield >= Nfields )) return( Eerr( 601, "hifield out of range", "" ) ); if( xfield >= Nfields ) return( Eerr( 601, "xfield out of range", "" ) ); /* -------------------------- */ /* now do the plotting work.. */ /* -------------------------- */ /* put all values into PLV array.. */ j = 0; f = xstart; for( i = 0; i < Nrecords; i++ ) { if( selectex[0] != '\0' ) { /* process against selection condition if any.. */ stat = do_select( selectex, i, &result ); if( stat != 0 ) { Eerr( stat, "Select error", selectex ); continue; } if( result == 0 ) continue; } /* X */ if( xfield < 0 ) { PLV[j] = f; f += 1.0; } else { PLV[j] = fda( i, xfield, X ); if( Econv_error() ) { conv_msg( i, xfield, "xfield" ); PLV[j] = NEGHUGE; } } j++; /* LO */ PLV[j] = fda( i, lofield, Y ); if( Econv_error() ) { conv_msg( i, lofield, "yfield" ); PLV[j] = NEGHUGE; /* continue; */ } j++; /* HI */ PLV[j] = fda( i, hifield, Y ); if( Econv_error() ) { conv_msg( i, hifield, "hifield" ); PLV[j] = NEGHUGE; /* continue; */ } j++; if( j >= PLVsize-3 ) { Eerr( 3579, "Too many points, sweep truncated (raise using -maxvector)", "" ); break; } } npoints = j / 3; /* draw the sweep.. */ /* ---------------- */ first = 1; lastlo = 0.0; lasthi = 0.0; lastx = 0.0; strcpy( oldcolor, Ecurcolor ); Ecolor( color ); for( i = 0; i < npoints; i++ ) { if( !first && (hi > (NEGHUGE+1) && lo > (NEGHUGE+1) && x > (NEGHUGE+1) && x < (PLHUGE-1) ) ) { lastlo = lo; lasthi = hi; lastx = x; } x = dat3d(i,0); lo = dat3d(i,1); hi = dat3d(i,2); /* fprintf( stderr, "[last: x=%g lo=%g hi=%g current: x=%g lo=%g hi=%g]", lastx, lastlo, lasthi, x, lo, hi ); */ /* skip bad values and places */ if( x < (NEGHUGE+1) || lo < (NEGHUGE+1) || hi < (NEGHUGE+1) ) { /* fprintf( stderr, "[skip]\n" ); */ continue; } /* if lo > hi reset so a new sweep can be started later.. */ if( lo > hi || x > (PLHUGE-1) ) { first = 1; /* fprintf( stderr, "[reset]\n" ); */ continue; } if( x < start ) { /* fprintf( stderr, "[too lo]\n" ); */ continue; /* out of range - lo */ } if( x > stop ) { /* out of range - hi */ /* fprintf( stderr, "[too hi]\n" ); */ break; } if( first ) { /* fprintf( stderr, "[First]\n" ); */ first = 0; continue; } if( !first ) { /* fprintf( stderr, "[Draw]\n" ); */ Emovu( x, lo ); Epathu( lastx, lastlo ); Epathu( lastx, lasthi ); Epathu( x, hi ); /* Ecolorfill( color ); */ /* using Efill scg 6/18/04 */ Efill(); continue; } } Ecolor( oldcolor ); if( legendlabel[0] != '\0' ) { PL_add_legent( LEGEND_COLOR, legendlabel, "", color, "", "" ); } return( 0 ); }
/* Fill the given character buffer with a null terminated string * corresponding to the part of the dline between the min and max * column positions. Trailing blanks are not removed. */ void dlgetvar(displine *line, char *buf) { getrange(line, buf, line->dl_min_col, line->dl_max_col); }
static range_t getrange(yystmt_t* yystmt, node_t* pnd) { range_t r = RANGE_ALL, r1, r2; node_t* tpnd = 0; leaf_t a, b; int flag = 0; if( !pnd ) return r; if( pnd->left && pnd->left->type == en_nt_attr && (pnd->left->value).iattr == en_article_num ) { r.flag = 1; switch( pnd->type ) { case en_nt_between: getleaf(yystmt, pnd->right->left, &a); getleaf(yystmt, pnd->right->right, &b); if( a.type == en_nt_null || b.type == en_nt_null ) break; r.min = RANGE_MIN(a.value.num, b.value.num); r.max = RANGE_MAX(a.value.num, b.value.num); break; case en_nt_in: EMPTY_RANGE(r); for(tpnd = pnd->right; tpnd; tpnd=tpnd->right) { getleaf(yystmt, tpnd, &a); if( a.type == en_nt_null ) continue; if( IS_EMPTY_RANGE(r) ) r.min = r.max = a.value.num; else { r.min = RANGE_MIN(r.min, a.value.num); r.max = RANGE_MAX(r.max, a.value.num); } } break; case en_nt_cmpop: getleaf(yystmt, pnd->right, &a); if( a.type == en_nt_null ) break; switch((pnd->value).cmpop) { case en_cmpop_eq: r.min = r.max = a.value.num; break; case en_cmpop_ne: r.min = (a.value.num + 1UL )%AREA; r.max = (a.value.num - 1UL + AREA)%AREA; break; case en_cmpop_gt: r.min = (a.value.num + 1UL)%AREA; break; case en_cmpop_lt: r.max = (a.value.num - 1UL + AREA)%AREA; r.min = (r.max)? 1UL:0UL; break; case en_cmpop_ge: r.min = a.value.num; break; case en_cmpop_le: r.max = a.value.num; r.min = (r.max)? 1UL:0UL; break; default: EMPTY_RANGE(r); break; } break; default: break; } return r; } if( pnd->type != en_nt_logop ) return r; switch( (pnd->value).logop ) { case en_logop_not: r1 = getrange(yystmt, pnd->right); if( r1.flag ) { r.min = (r1.max + 1UL)%AREA; r.max = (r1.min - 1UL + AREA)%AREA; } break; case en_logop_or: flag = 1; case en_logop_and: r1 = getrange(yystmt, pnd->left); r2 = getrange(yystmt, pnd->right); if( !(r1.flag || r2.flag ) ) break; if( r1.min > r1.max ) r1.max = r1.max + AREA; if( r2.min > r2.max ) r2.max = r2.max + AREA; if( flag ) r = range_or ( r1, r2 ); else r = range_and( r1, r2 ); break; default: EMPTY_RANGE(r); break; } return r; }
// TODO: group similar instructions like for non-thumb static int thumb_assemble(ArmOpcode *ao, const char *str) { int reg, j; ao->o = UT32_MAX; if (!strcmpnull (ao->op, "pop") && ao->a[0]) { ao->o = 0xbc; if (*ao->a[0]++=='{') { // XXX: inverse order? for (j=0; j<16; j++) { if (ao->a[j] && *ao->a[j]) { getrange (ao->a[j]); // XXX filter regname string reg = thumb_getreg (ao->a[j]); if (reg != -1) { if (reg<8) ao->o |= 1<<(8+reg); if (reg==8){ ao->o |= 1; } // else ignore... } } } } else ao->o |= getnum (ao->a[0])<<24; // ??? return 2; } else if (!strcmpnull (ao->op, "push") && ao->a[0]) { ao->o = 0xb4; if (*ao->a[0]++=='{') { for (j=0; j<16; j++) { if (ao->a[j] && *ao->a[j]) { getrange (ao->a[j]); // XXX filter regname string reg = thumb_getreg (ao->a[j]); if (reg != -1) { if (reg<8) ao->o |= 1<<(8+reg); if (reg==8) ao->o |= 1; // else ignore... } } } } else ao->o |= getnum (ao->a[0])<<24; // ??? return 2; } else if (!strcmpnull (ao->op, "ldmia")) { ao->o = 0xc8 + getreg (ao->a[0]); ao->o |= getlist(ao->opstr) << 8; return 2; } else if (!strcmpnull (ao->op, "stmia")) { ao->o = 0xc0 + getreg (ao->a[0]); ao->o |= getlist(ao->opstr) << 8; return 2; } else if (!strcmpnull (ao->op, "nop")) { ao->o = 0xbf; return 2; } else if (!strcmpnull (ao->op, "yield")) { ao->o = 0x10bf; return 2; } else if (!strcmpnull (ao->op, "udf")) { ao->o = 0xde; ao->o |= getnum (ao->a[0])<<8; return 2; } else if (!strcmpnull (ao->op, "wfe")) { ao->o = 0x20bf; return 2; } else if (!strcmpnull (ao->op, "wfi")) { ao->o = 0x30bf; return 2; } else if (!strcmpnull (ao->op, "sev")) { ao->o = 0x40bf; return 2; } else if (!strcmpnull (ao->op, "bkpt")) { ao->o = 0xbe; ao->o |= (0xff & getnum (ao->a[0]))<<8; return 2; } else #if 0 if (!strcmpnull (ao->op, "and")) { ao->o = 0x40; ao->o |= (0xff & getreg (ao->a[0])) << 8; ao->o |= (0xff & getreg (ao->a[1])) << 11; } else #endif if (!strcmpnull (ao->op, "svc")) { ao->o = 0xdf; ao->o |= (0xff & getnum (ao->a[0])) << 8; return 2; } else if (!strcmpnull (ao->op, "b") || !strcmpnull (ao->op, "b.n")) { //uncond branch : PC += 4 + (delta*2) int delta = getnum (ao->a[0]) - 4 - ao->off; if ((delta < -2048) || (delta > 2046) || (delta & 1)) { eprintf("branch out of range or not even\n"); return 0; } ut16 opcode = 0xe000 | ((delta / 2) & 0x7ff); //11bit offset>>1 ao->o = opcode >>8; ao->o |= (opcode & 0xff)<<8; // (ut32) ao->o holds the opcode in little-endian format !? return 2; } else
main() { int x, y, loop = 1, fact = 0; char instring[200], outstring[200], sub[200], vrb[200], rst[200], qwd[200]; char osub[200], ovrb[200], orst[200]; fam = 0; printf("Hello there. My name is Eliza and I was written by Mohan Embar.\n"); printf("Please type \"END\" to end this session.\n"); printf("I'm here to help you if I can. What seems to be the trouble?\n"); while (loop) { printf("\n"); gets(instring); printf("\n"); parse(instring); if (numwords == 0) { switch (x = randnum(2)) { case 1 : printf("Don't you have anything to say?\n"); break; case 2 : printf("Cat got your tongue?\n"); break; } continue; } if (!strcmp(s[1],"END")) { printf("Goodbye. Please come again.\n"); break; } agree(); if (bad_word()) printf(b_word_resp()); else if (naughty_word()) printf(n_word_resp()); else if (x = family()) { fam = x; printf(fam_resp()); strcpy(fam_member,s[fam]); } else if (sword("ALIKE",1)) printf(alike_resp()); else if (sword("ALWAYS",1)) printf(always_resp()); else if (sword("BECAUSE",1)) printf(because_resp()); else if (sword("YES",1)) printf(yes_resp()); else if (sword("NO",1) || sword("NOT",1)) printf(neg_resp()); else if (x = i_am()) { /* If occurrence of I AM x.. */ get_til_stop(x,outstring); /* Get I AM x .. into outstring */ printf(i_am_resp(),outstring); /* Print reponse for this */ } else if (real_quest() || (is_helper(s[1]) && is_sub_pronoun(s[2])) || sub_and_helper()) { if (real_quest()) { strcpy(qwd,s[1]); strcpy(vrb,s[2]); strcpy(sub,s[3]); get_til_stop(4,rst); } else if (is_helper(s[1]) && is_sub_pronoun(s[2])) { strcpy(vrb,s[1]); strcpy(sub,s[2]); get_til_stop(3,rst); strcpy(qwd,"YES"); } else if (sub_and_helper()) { x = find_helper(); y = search_back_sub(x); strcpy(vrb,s[x]); get_til_stop(x+1,rst); getrange(y,x-1,sub); strcpy(qwd,"NO"); } make_lower(qwd); if (strcmp(sub,"I")) make_lower(sub); make_lower(vrb); make_lower(rst); /* First do x verb y responses */ /* printf("\n*** %s\n",sub); */ if (!strcmp(sub," I") || !strcmp(sub,"I")) { printf(you_resp()); } else if (!strcmp(qwd,"no")) { /* Record this statement for later use. */ fact = 1; strcpy(osub,sub); strcpy(ovrb,vrb); strcpy(orst,rst); if (is_be(vrb) && !strcmp(sub," you") && (y = sad_word())) { getrange(y,y,outstring); x = randnum(5)+6; } else if (is_be(vrb) && (y = sad_word())) { getrange(y,y,outstring); x = randnum(2)+11; } else if (is_be(vrb)) x = randnum(6); else x = randnum(4); switch (x) { case 1 : printf("How do you feel about%s?\n",cnnv(sub)); break; case 2 : printf("Why %s%s%s?\n",vrb,sub,rst); break; case 3 : for (y=1;sub[y]=sub[y--];y=y+2); sub[0] = toupper(sub[0]); printf("%s %s%s?\n",sub,vrb,rst); break; case 4 : printf("Could you describe%s for me?\n",cnnv(sub)); break; case 5 : printf("What if%s were not%s?\n",sub,rst); break; case 6 : printf("Would you be happy if%s were not%s?\n",sub, rst); break; case 7 : printf("I'm sorry to hear that you are%s.\n",outstring); break; case 8 : printf("Do you think that coming here will help you not to be%s?\n",outstring); break; case 9 : printf("Let's talk about why you feel%s.\n",outstring); break; case 10 : printf("What happened that made you feel%s?\n",outstring); break; case 11 : printf("What could be the reason for your feeling%s?\n",outstring); break; case 12 : printf("What could cause%s to be%s?\n",cnnv(sub),outstring); break; case 13 : printf("If%s came here, would it help%s not to be%s?\n",sub,cnnv(sub),outstring); break; } } else if (!strcmp(sub,"you")) printf(you_know()); else if (!strcmp(qwd,"yes")) { x = randnum(8); switch (x) { case 1 : printf("You want to know if %s %s%s.\n",sub,vrb,rst); break; case 2 : printf("If %s %s%s, does that concern you?\n",sub,vrb,rst); break; case 3 : printf("What are the consequences if %s %s%s?\n",sub,vrb,rst); break; case 4 : printf("Why does %s concern you?\n",sub); break; case 5 : printf("Why are you thinking of %s?\n",cnnv(sub)); break; case 6 : printf("Tell me more about %s.\n",cnnv(sub)); break; case 7 : printf("To answer that, I'd need to know more about %s.\n",cnnv(sub)); break; case 8 : printf("What is the relationship between you and %s?\n",cnnv(sub)); break; case 9 : printf("Why don't you ask %s?\n",cnnv(sub)); break; } } else { x = randnum(8); switch (x) { case 1 : printf("You want to know %s %s %s%s.\n",qwd,sub,vrb,rst); break; case 2 : printf("If %s %s%s, does that concern you?\n",sub,vrb,rst); break; case 3 : printf("What are the consequences if %s %s%s?\n",sub,vrb,rst); break; case 4 : printf("Why does %s concern you?\n",sub); break; case 5 : printf("Why are you thinking of %s?\n",cnnv(sub)); break; case 6 : printf("Tell me more about %s.\n",cnnv(sub)); break; case 7 : printf("To answer that, I'd need to know more about %s.\n",cnnv(sub)); break; case 8 : printf("What is the relationship between you and %s?\n",cnnv(sub)); break; case 9 : printf("Why don't you ask %s?\n",cnnv(sub)); break; } } } else if (is_command()) printf(command_resp()); else if (vague_quest()) printf(question()); else if ((s[numwords][0] == '?') && !real_quest()) printf(question()); else if (x = sad_word()) { getrange(x,x,outstring); for (y=1;outstring[y]=outstring[y--];y=y+2); outstring[0] = toupper(outstring[0]); printf("%s?\n",outstring); } else if (x = can_spit_out()) { if (x<=(numwords-2) && is_sub_pronoun(s[x]) && (matches("NEED",s[x+1]) || matches("WANT",s[x+1]))) { get_til_stop(x+2,outstring); strcpy(sub,s[x]); if (strcmp(sub,"I")) make_lower(sub); if (strcmp(s[x],"I")) make_lower(s[x]); x = randnum(6); switch (x) { case 1 : printf("What would it mean to %s if %s got%s?\n",cnnv2(s[x]),sub,outstring); break; case 2 : printf("Would %s really be happy if %s got%s?\n",sub,sub,outstring); break; case 3 : printf("Why is getting%s so desirable?\n",outstring); break; case 4 : printf("Okay. Suppose %s got%s. Then what?\n",sub,outstring); break; case 5 : printf("Why is this important to %s?\n",cnnv2(sub)); break; case 6 : printf("What price would %s pay to achieve this?\n",sub); break; } } else { get_til_stop(x,outstring); outstring[1]=toupper(outstring[1]); printf("%s.\n",outstring+1); } } else if (fam) { make_lower(fam_member); printf(family_resp(),fam_member); fam = 0; } else if (fact && (randnum(5)==3)) { printf(old_fact(),osub,ovrb,orst); fact = 0; } else { printf(go_on()); } } }
long int printexon(List *Predexon,int *geneno,int *exonno, int *totlen,long int offset, long int startprint,long int stopprint,int *oktoprint,long int lastseen, FILE *outf, char *Name,int path,int *parentprint) { int frame; long int stoprange; exon *curexon=Predexon->predexon; switch(curexon->type) { case 0: if(curexon->start<startprint || curexon->start>=stopprint ) { *oktoprint=0;} else { *oktoprint=1;} if(*oktoprint) { if(gff) { if(*parentprint) { stoprange=getrange(Predexon,1); fprintf(outf,"%s\tGlimmerHMM\tmRNA\t%ld\t%ld\t.\t+\t.\tID=%s.path%d.gene%d;Name=%s.path%d.gene%d\n",Name,curexon->start+offset,stoprange+offset,Name,path,*geneno,Name,path,*geneno); *parentprint=0; } fprintf(outf,"%s\tGlimmerHMM\tCDS\t%ld\t%ld\t.\t+\t0\tID=%s.cds%d.%d;Parent=%s.path%d.gene%d;Name=%s.path%d.gene%d;Note=initial-exon\n",Name,curexon->start+offset,curexon->stop+offset,Name,*geneno,*exonno,Name,path,*geneno,Name,path,*geneno); } else { fprintf(outf,"%4d %4d + Initial %10ld %10ld %7d\n",*geneno,*exonno,curexon->start+offset,curexon->stop+offset,curexon->stop-curexon->start+1); } } *totlen+=curexon->stop-curexon->start+1; (*exonno)++; break; case 1: if(curexon->start<startprint) { *oktoprint=0;} if(*oktoprint) { if(gff) { if(*parentprint) { stoprange=getrange(Predexon,1); fprintf(outf,"%s\tGlimmerHMM\tmRNA\t%ld\t%ld\t.\t+\t.\tID=%s.path%d.gene%d;Name=%s.path%d.gene%d\n",Name,curexon->start+offset,stoprange+offset,Name,path,*geneno,Name,path,*geneno); *parentprint=0; } frame=(3-(*totlen)%3)%3; fprintf(outf,"%s\tGlimmerHMM\tCDS\t%ld\t%ld\t.\t+\t%d\tID=%s.cds%d.%d;Parent=%s.path%d.gene%d;Name=%s.path%d.gene%d;Note=internal-exon\n",Name,curexon->start+offset,curexon->stop+offset,frame,Name,*geneno,*exonno,Name,path,*geneno,Name,path,*geneno); } else { fprintf(outf,"%4d %4d + Internal %10ld %10ld %7d\n",*geneno,*exonno,curexon->start+offset,curexon->stop+offset,curexon->stop-curexon->start+1); } } *totlen+=curexon->stop-curexon->start+1; (*exonno)++; break; case 2: if(curexon->start<startprint) { *oktoprint=0;} if(*oktoprint) { if(gff) { if(*parentprint) { stoprange=getrange(Predexon,1); fprintf(outf,"%s\tGlimmerHMM\tmRNA\t%ld\t%ld\t.\t+\t.\tID=%s.path%d.gene%d;Name=%s.path%d.gene%d\n",Name,curexon->start+offset,stoprange+offset,Name,path,*geneno,Name,path,*geneno); *parentprint=0; } frame=(3-(*totlen)%3)%3; fprintf(outf,"%s\tGlimmerHMM\tCDS\t%ld\t%ld\t.\t+\t%d\tID=%s.cds%d.%d;Parent=%s.path%d.gene%d;Name=%s.path%d.gene%d;Note=final-exon\n",Name,curexon->start+offset,curexon->stop+offset,frame,Name,*geneno,*exonno,Name,path,*geneno,Name,path,*geneno); } else { fprintf(outf,"%4d %4d + Terminal %10ld %10ld %7d\n\n",*geneno,*exonno,curexon->start+offset,curexon->stop+offset,curexon->stop-curexon->start+1); } lastseen=curexon->stop; (*geneno)++; } *exonno=1;*totlen=0;*parentprint=1; break; case 3: if(curexon->start<startprint || curexon->start>=stopprint ) { *oktoprint=0;} else { *oktoprint=1;} if(*oktoprint) { if(gff) { if(*parentprint) { stoprange=getrange(Predexon,1); fprintf(outf,"%s\tGlimmerHMM\tmRNA\t%ld\t%ld\t.\t+\t.\tID=%s.path%d.gene%d;Name=%s.path%d.gene%d\n",Name,curexon->start+offset,stoprange+offset,Name,path,*geneno,Name,path,*geneno); *parentprint=0; } fprintf(outf,"%s\tGlimmerHMM\tCDS\t%ld\t%ld\t.\t+\t0\tID=%s.cds%d.%d;Parent=%s.path%d.gene%d;Name=%s.path%d.gene%d;Note=single-exon\n",Name,curexon->start+offset,curexon->stop+offset,Name,*geneno,*exonno,Name,path,*geneno,Name,path,*geneno); } else { fprintf(outf,"%4d %4d + Single %10ld %10ld %7d\n\n",*geneno,*exonno,curexon->start+offset,curexon->stop+offset,curexon->stop-curexon->start+1); } lastseen=curexon->stop; (*geneno)++; } *exonno=1;*totlen=0;*parentprint=1; break; case 4: if(curexon->start<startprint) { *oktoprint=0;} if(*oktoprint) { if(gff) { if(*parentprint) { stoprange=getrange(Predexon,-1); fprintf(outf,"%s\tGlimmerHMM\tmRNA\t%ld\t%ld\t.\t-\t.\tID=%s.path%d.gene%d;Name=%s.path%d.gene%d\n",Name,curexon->start+offset,stoprange+offset,Name,path,*geneno,Name,path,*geneno); *parentprint=0; } fprintf(outf,"%s\tGlimmerHMM\tCDS\t%ld\t%ld\t.\t-\t0\tID=%s.cds%d.%d;Parent=%s.path%d.gene%d;Name=%s.path%d.gene%d;Note=initial-exon\n",Name,curexon->start+offset,curexon->stop+offset,Name,*geneno,*exonno,Name,path,*geneno,Name,path,*geneno); } else { fprintf(outf,"%4d %4d - Initial %10ld %10ld %7d\n\n",*geneno,*exonno,curexon->start+offset,curexon->stop+offset,curexon->stop-curexon->start+1); } lastseen=curexon->stop; (*geneno)++; } *exonno=1;*totlen=0;*parentprint=1; break; case 5: *totlen+=curexon->stop-curexon->start+1; if(curexon->start<startprint) { *oktoprint=0;} if(*oktoprint) { if(gff) { if(*parentprint) { stoprange=getrange(Predexon,-1); fprintf(outf,"%s\tGlimmerHMM\tmRNA\t%ld\t%ld\t.\t-\t.\tID=%s.path%d.gene%d;Name=%s.path%d.gene%d\n",Name,curexon->start+offset,stoprange+offset,Name,path,*geneno,Name,path,*geneno); *parentprint=0; } frame=(*totlen)%3; fprintf(outf,"%s\tGlimmerHMM\tCDS\t%ld\t%ld\t.\t-\t%d\tID=%s.cds%d.%d;Parent=%s.path%d.gene%d;Name=%s.path%d.gene%d;Note=internal-exon\n",Name,curexon->start+offset,curexon->stop+offset,frame,Name,*geneno,*exonno,Name,path,*geneno,Name,path,*geneno); } else { fprintf(outf,"%4d %4d - Internal %10ld %10ld %7d\n",*geneno,*exonno,curexon->start+offset,curexon->stop+offset,curexon->stop-curexon->start+1); } } (*exonno)++; break; case 6: *totlen+=curexon->stop-curexon->start+1; if(curexon->start<startprint || curexon->start>=stopprint ) { *oktoprint=0;} else { *oktoprint=1;} if(*oktoprint) { if(gff) { if(*parentprint) { stoprange=getrange(Predexon,-1); fprintf(outf,"%s\tGlimmerHMM\tmRNA\t%ld\t%ld\t.\t-\t.\tID=%s.path%d.gene%d;Name=%s.path%d.gene%d\n",Name,curexon->start+offset,stoprange+offset,Name,path,*geneno,Name,path,*geneno); *parentprint=0; } frame=(*totlen)%3; fprintf(outf,"%s\tGlimmerHMM\tCDS\t%ld\t%ld\t.\t-\t%d\tID=%s.cds%d.%d;Parent=%s.path%d.gene%d;Name=%s.path%d.gene%d;Note=final-exon\n",Name,curexon->start+offset,curexon->stop+offset,frame,Name,*geneno,*exonno,Name,path,*geneno,Name,path,*geneno); } else { fprintf(outf,"%4d %4d - Terminal %10ld %10ld %7d\n",*geneno,*exonno,curexon->start+offset,curexon->stop+offset,curexon->stop-curexon->start+1); } } (*exonno)++; break; case 7: if(curexon->start<startprint || curexon->start>=stopprint ) { *oktoprint=0;} else { *oktoprint=1;} if(*oktoprint) { if(gff) { if(*parentprint) { stoprange=getrange(Predexon,-1); fprintf(outf,"%s\tGlimmerHMM\tmRNA\t%ld\t%ld\t.\t-\t.\tID=%s.path%d.gene%d;Name=%s.path%d.gene%d\n",Name,curexon->start+offset,stoprange+offset,Name,path,*geneno,Name,path,*geneno); *parentprint=0; } fprintf(outf,"%s\tGlimmerHMM\tCDS\t%ld\t%ld\t.\t-\t0\tID=%s.cds%d.%d;Parent=%s.path%d.gene%d;Name=%s.path%d.gene%d;Note=single-exon\n",Name,curexon->start+offset,curexon->stop+offset,Name,*geneno,*exonno,Name,path,*geneno,Name,path,*geneno); } else { fprintf(outf,"%4d %4d - Single %10ld %10ld %7d\n\n",*geneno,*exonno,curexon->start+offset,curexon->stop+offset,curexon->stop-curexon->start+1); } lastseen=curexon->stop; (*geneno)++; } *exonno=1;*totlen=0;*parentprint=1; break; } return(lastseen); }
// TODO: group similar instructions like for non-thumb static int thumb_assemble(ArmOpcode *ao, const char *str) { int reg, j; if (!strcmp (ao->op, "pop") && ao->a[0]) { ao->o = 0xbc; if (*ao->a[0]++=='{') { for (j=0; j<16; j++) { if (ao->a[j] && *ao->a[j]) { getrange (ao->a[j]); // XXX filter regname string reg = thumb_getreg (ao->a[j]); if (reg != -1) { if (reg<8) ao->o |= 1<<(8+reg); if (reg==8){ ao->o |= 1; } // else ignore... } } } } else ao->o |= getnum (ao->a[0])<<24; // ??? } else if (!strcmp (ao->op, "push") && ao->a[0]) { ao->o = 0xb4; if (*ao->a[0]++=='{') { for (j=0; j<16; j++) { if (ao->a[j] && *ao->a[j]) { getrange (ao->a[j]); // XXX filter regname string reg = thumb_getreg (ao->a[j]); if (reg != -1) { if (reg<8) ao->o |= 1<<(8+reg); if (reg==8) ao->o |= 1; // else ignore... } } } } else ao->o |= getnum (ao->a[0])<<24; // ??? } else if (!strcmp (ao->op, "ldmia")) { ao->o = 0xc8 + getreg (ao->a[0]); ao->o |= getlist(ao->opstr) << 8; } else if (!strcmp (ao->op, "stmia")) { ao->o = 0xc0 + getreg (ao->a[0]); ao->o |= getlist(ao->opstr) << 8; } else if (!strcmp (ao->op, "nop")) { ao->o = 0xbf; } else if (!strcmp (ao->op, "yield")) { ao->o = 0x10bf; } else if (!strcmp (ao->op, "wfe")) { ao->o = 0x20bf; } else if (!strcmp (ao->op, "wfi")) { ao->o = 0x30bf; } else if (!strcmp (ao->op, "sev")) { ao->o = 0x40bf; } else if (!strcmp (ao->op, "bkpt")) { ao->o = 0xbe; ao->o |= (0xff & getnum (ao->a[0]))<<8; } else if (!strcmp (ao->op, "and")) { ao->o = 0x40; ao->o |= (0xff & getreg (ao->a[0])) << 8; ao->o |= (0xff & getreg (ao->a[1])) << 11; } else if (!strcmp (ao->op, "svc")) { ao->o = 0xdf; ao->o |= (0xff & getnum (ao->a[0])) << 8; } else if (!strcmp (ao->op, "b") || !strcmp (ao->op, "b.n")) { ao->o = 0xe0; ao->o |= getnum (ao->a[0])<<8; } else if (!strcmp (ao->op, "bx")) { ao->o = 0x47; ao->o |= getreg (ao->a[0])<<11; } else if (!strcmp (ao->op, "bl")) { ao->o = 0x47; ao->o |= getnum (ao->a[0])<<8; // XXX: length = 4 } else if (*ao->op == 'b') { // conditional branch ao->o = 0xd0 | arm_opcode_cond (ao, 1); ao->o |= getnum (ao->a[0])<<8; } else if (!strcmp (ao->op, "mov")) { int reg = getreg (ao->a[1]); if (reg!=-1) { ao->o = 0x46; ao->o |= (getreg (ao->a[0]))<<8; ao->o |= reg<<11; } else { ao->o = 0x20; ao->o |= (getreg (ao->a[0])); ao->o |= (getnum (ao->a[1])&0xff)<<8; } } else if (!memcmp (ao->op, "ldr", 3)) { getrange (ao->a[1]); getrange (ao->a[2]); if (ao->op[3]=='h') { int a0 = getreg (ao->a[0]); int a1 = getreg (ao->a[1]); int a2 = getreg (ao->a[2]); if (a2 ==-1) { a2 = getnum (ao->a[2])/8; ao->o = 0x88; // | (8+(0xf & a0)); ao->o |= (7&a0)<<8; ao->o |= (7&a1)<<11; ao->o += (7&a2); } else return 0; } else if (ao->op[3]=='b') { int a0 = getreg (ao->a[0]); int a1 = getreg (ao->a[1]); int a2 = getreg (ao->a[2]); if (a2 ==-1) { a2 = getnum (ao->a[2])/8; ao->o = 0x78; // | (8+(0xf & a0)); ao->o |= (7&a0)<<8; ao->o |= (7&a1)<<11; ao->o |= (7&a2); } else return 0; } else { if (!strcmp (ao->a[1], "sp")) { // ldr r0, [sp, n] = a[r0-7][nn] if (getreg (ao->a[2]) == -1) { // ldr r0, [sp, n] ao->o = 0x98 + (0xf & getreg (ao->a[0])); ao->o |= (0xff & getnum (ao->a[2])/4)<<8; } else return 0; } else if (!strcmp (ao->a[1], "pc")) { // ldr r0, [pc, n] = 4[r0-8][nn*4] if (getreg (ao->a[2]) == -1) { ao->o = 0x40 | (8+(0xf & getreg (ao->a[0]))); ao->o |= (0xff & getnum (ao->a[2])/4)<<8; } else return 0; } else { // ldr r0, [rN, rN] = 58[7bits:basereg + 7bits:destreg] int a0 = getreg (ao->a[0]); int a1 = getreg (ao->a[1]); int a2 = getreg (ao->a[2]); ao->o = 0x58; // | (8+(0xf & a0)); ao->o |= (7&a0)<<8; ao->o |= (7&a1)<<11; ao->o |= (7&a2)<<14; } } } else if (!memcmp (ao->op, "str", 3)) { getrange (ao->a[1]); getrange (ao->a[2]); if (ao->op[3]=='h') { int a0 = getreg (ao->a[0]); int a1 = getreg (ao->a[1]); int a2 = getreg (ao->a[2]); if (a2 ==-1) { a2 = getnum (ao->a[2]); ao->o = 0x80; // | (8+(0xf & a0)); ao->o |= (7&a0)<<8; ao->o |= (7&a1)<<11; ao->o |= (7&(a2>>1)); } else return 0;
int exec_cmd(int under_glob, int under_until) { register int status; register char *p; int n; if((status = getrange()) <= ERROR) return( status ); status = ERROR9; switch( *lp++ ) { case 'i': laddr2 = prevln(laddr2); case 'a': status = append(laddr2, under_glob); break; case 'b': if(!under_glob && !under_until) status = branch(); break; case 'c': if((status = delete(laddr1, laddr2, SAVE)) == OK) status = append(prevln(laddr1), under_glob); break; case 'd': if((status = delete(laddr1, laddr2, SAVE)) == OK && nextln(curln) != 0) curln = nextln(curln); break; case 'e': if(lastln && dirty && *lp != 'e') { status = ERROR4; break; } if(*lp == 'e') ++lp; if(nladdrs == 0 && !under_glob && !under_until && (status = getfn()) == OK) { set_fn(curfile, lp); if(lastln != 0) delete(1, lastln, NOSAVE); num_delete_lines = 0; if((status = _read( lp, 0, 0)) == OK) { dirty = 0; if(lastln) curln = 1; } } lp = "\n"; break; case 'f': if(nladdrs == 0 && (status = getfn()) == OK) { set_fn(curfile, lp); putmsg(curfile); lp = "\n"; } change_state(CMD); break; case 'g': if(!under_glob) { if(*lp == '^') { ++lp; n = 0; } else n = 1; status = exec_glob(n, under_until); } break; case 'h': n = getint(); #ifndef __STDC__ while(n--) for(n1 = 0; n1 < 10; ++n1) time_slice(); #endif status = OK; break; case 'j': status = join(laddr2); break; case 'k': if((status = get_laddr_expr(&n)) == OK) status = kopy(n); break; case 'l': if(nladdrs == 0) status = learn(); break; case 'm': if((status = get_laddr_expr(&n)) == OK) status = move(n); break; case 'o': status = option(); break; case 'p': case 'P': status = prnt(laddr1, laddr2); break; case 'q': if(nladdrs==0 && !under_glob) { if((*lp=='\n' && !dirty) || *lp=='q' || lastln == 0) status = EOF; else status = ERROR4; } break; case 'r': if(!under_glob && !under_until && (status = getfn()) == OK) status = _read(lp, laddr2, 0); lp = "\n"; break; case 's': n = getint(); /* read occurance if present */ if((status=getpat()) == OK && (status=getsubst_str(tbuff)) == OK) status = substitute(tbuff, under_glob, n); break; case 't': case 'T': if(nladdrs == 0) status = translate(*(lp - 1) == 't'); break; case 'u': status = until(laddr1, laddr2, under_glob); break; case 'v': if(nladdrs <= 1) status = view(laddr1); break; case 'w': n = 0; if(*lp == 'w') { n |= 2; ++lp; } if(*lp == 'a') { n |= 1; ++lp; } if((status = getfn()) == OK) { if(nladdrs == 0) { if(curfile[0] == '\0') set_fn(curfile, lp); else { if((n & 2) == 0 && strcmp(curfile, lp) != 0) { for(p = lp ; *p ; ++p) if(*p == '$') goto ok; puterr(-19); lp = "\n"; break; } } ok: if((status = _write(lp, 1, lastln, n & 1, 0)) == OK) dirty = 0; } } else { status = _write(lp, laddr1, laddr2, n & 1, 0); } lp = "\n"; break; case 'x': if(!under_glob && !under_until && (status = getfn()) == OK) if(nladdrs == 0) status = exec_file(lp, under_glob, under_until); lp = "\n"; break; case 'y': status = yut(); break; case 'z': status = zap(); break; case '\n': --lp; /* put back newline for main */ if(laddr2 < 0 || laddr2 > lastln) status = lastln ? ERROR5 : OK; else { curln = laddr2; status = OK; } break; case ' ': case '\t': case CMD_CHAR: status = OK; break; case '=': dtoc(rbuff, laddr2); if(under_glob) prnt_screen(rbuff, 1); else putmsg(rbuff); status = OK; break; case '"': lp = "\n"; /* Ignore rest of line */ status = OK; break; case '!': if(escape_char == 0 || restrict_flag) { putmsg("Escape from ED inhibited"); status = NOTHING; } else status = exec_sys_cmd(under_glob, under_until); break; default: status = ERROR2; } return(status); }