/* strcompare - compare strings */ LOCAL LVAL strcompare(int fcn, int icase) { int start1,end1,start2,end2,ch1,ch2; unsigned char *p1,*p2; LVAL str1,str2; /* get the strings */ str1 = xlgastring(); str2 = xlgastring(); /* get the substring specifiers */ getbounds(str1,k_1start,k_1end,&start1,&end1); getbounds(str2,k_2start,k_2end,&start2,&end2); /* setup the string pointers */ p1 = &getstring(str1)[start1]; p2 = &getstring(str2)[start2]; /* compare the strings */ for (; start1 < end1 && start2 < end2; ++start1,++start2) { ch1 = *p1++; ch2 = *p2++; if (icase) { if (isupper(ch1)) ch1 = tolower(ch1); if (isupper(ch2)) ch2 = tolower(ch2); } if (ch1 != ch2) switch (fcn) { case '<': return (ch1 < ch2 ? fix(start1) : NIL); case 'L': return (ch1 <= ch2 ? fix(start1) : NIL); case '=': return (NIL); case '#': return (fix(start1)); case 'G': return (ch1 >= ch2 ? fix(start1) : NIL); case '>': return (ch1 > ch2 ? fix(start1) : NIL); } } /* check the termination condition */ switch (fcn) { case '<': return (start1 >= end1 && start2 < end2 ? fix(start1) : NIL); case 'L': return (start1 >= end1 ? fix(start1) : NIL); case '=': return (start1 >= end1 && start2 >= end2 ? s_true : NIL); case '#': return (start1 >= end1 && start2 >= end2 ? NIL : fix(start1)); case 'G': return (start2 >= end2 ? fix(start1) : NIL); case '>': return (start2 >= end2 && start1 < end1 ? fix(start1) : NIL); } return NIL; /* Normally shouldn't happen */ }
/* search for string within a string */ LVAL xstrsearch(void) { int start,end,pat_len,str_len; unsigned char *pat,*str,*patptr,*strptr,*patend; LVAL str1,str2; /* get the strings */ str1 = xlgastring(); /* the pat */ str2 = xlgastring(); /* the string */ /* get the substring specifiers */ getbounds(str2, k_start, k_end, &start, &end); /* setup the string pointers */ pat = getstring(str1); str = &getstring(str2)[start]; pat_len = getslength(str1) - 1; str_len = end - start; patend = pat + pat_len; for (; pat_len <= str_len; str_len--) { patptr = pat; strptr = str; /* two outcomes: (1) no match, goto step (2) match, return */ while (patptr < patend) { if (*patptr++ != *strptr++) goto step; } /* compute match index */ return cvfixnum(str - getstring(str2)); step: str++; } /* no match */ return NIL; }
/* changecase - change case */ LOCAL LVAL changecase(int fcn, int destructive) { unsigned char *srcp,*dstp; int start,end,len,ch,i; LVAL src,dst; /* get the string */ src = xlgastring(); /* get the substring specifiers */ getbounds(src,k_start,k_end,&start,&end); len = getslength(src) - 1; /* make a destination string */ dst = (destructive ? src : new_string(len+1)); /* setup the string pointers */ srcp = getstring(src); dstp = getstring(dst); /* copy the source to the destination */ for (i = 0; i < len; ++i) { ch = *srcp++; if (i >= start && i < end) switch (fcn) { case 'U': if (islower(ch)) ch = toupper(ch); break; case 'D': if (isupper(ch)) ch = tolower(ch); break; } *dstp++ = ch; } *dstp = '\0'; /* return the new string */ return (dst); }
static void mtl_con(int *cnt, size_t hasuform, char *uform, Miscellaneous *miscell, int *tl_yychar) { char c; c = tl_Getchar(cnt, hasuform, uform); if (c == '_') { miscell->dp_taliro_param.LTL = 0; miscell->TimeCon = getbounds(cnt, hasuform, uform, miscell, tl_yychar); } else { miscell->TimeCon = miscell->zero2inf; tl_UnGetchar(cnt); } }
void pivot(wrkspace *w,vind tree,vind k0,vind k1,vind nv,vind u,vind t,vind minvi,vind maxvi,bool revord) { double crt,ind,acptbound(-NOBND); bool success; vind vi; sbset *prevsbset,*st; sbstlist::iterator ptprevsbset; subsetdata *curdata; // assert(k0 > k1); if (revord) vi = p-u+1; else vi = u; curdata = w->subsetat(k1+1).getdatap(); if (curdata->spdcupd()) acptbound = getbounds(pcrttp,minvi,maxvi); else if (pcrttp == MINIMZ ) acptbound *= -1; if (k1 == 0) success = w->pivot(vi,0,k0,0,acptbound); else success = w->pivot(vi,t,k0,k1,acptbound); if (success) curdata->allowpivot(); if (nv < mindim || nv > maxdim || !success) return; #ifdef COUNTING ++cntg; #endif crt = curdata->criterion(); ind = curdata->indice(); if (pcrttp == MAXIMZ && crt < lbnd[nv-mindim]) return; // Check if new subset is better than any of the if (pcrttp == MINIMZ && crt > ubnd[nv-mindim]) return; // sets in current best set list for this dimension getactv(w,tree,k1,nv); st = csbset(nv,actv,crt,ind); psbstlist curlist = bsts[nv-mindim]; if (sbsetcnt[nv-mindim] == ms) { // Remove and discard worst subset saved prevsbset = *(ptprevsbset=curlist->begin()); curlist->erase(ptprevsbset); dsbset(prevsbset); } else sbsetcnt[nv-mindim]++; curlist->insert(st); // Insert new subset in best sets list if (sbsetcnt[nv-mindim] == ms) { if (pcrttp == MAXIMZ) lbnd[nv-mindim] = (*curlist->begin())->crt(); else ubnd[nv-mindim] = (*curlist->begin())->crt(); } return; }
boolean Graphic31::grasp (const Event& e, Tool31& tool) { ToolState& ts = tool.toolstate(); ts._init = e; ts._last = e; getbounds(ts._l, ts._b, ts._r, ts._t); if (tool.tool() == Tool31::scale) { Coord lx, ly; Coord cx, cy; lx = e.pointer_x(); ly = e.pointer_y(); cx = (ts._l + ts._r)/2.0; cy = (ts._b + ts._t)/2.0; scale( Math::abs((lx-cx)*2.0/(ts._r-ts._l)), Math::abs((ly-cy)*2.0/(ts._t-ts._b)), cx, cy ); } return true; }
void Graphic31::align (Alignment falign, Graphic31* moved, Alignment malign) { float fx0, fy0, fx1, fy1, mx0, my0, mx1, my1, dx = 0, dy = 0; getbounds(fx0, fy0, fx1, fy1); moved->getbounds(mx0, my0, mx1, my1); switch (falign) { case BottomLeft: case CenterLeft: case TopLeft: case Left: dx = fx0; break; case BottomCenter: case Center: case TopCenter: case HorizCenter: dx = (fx0 + fx1 + 1)/2; break; case BottomRight: case CenterRight: case TopRight: case Right: dx = fx1 + 1; break; } switch (falign) { case BottomLeft: case BottomCenter: case BottomRight: case Bottom: dy = fy0; break; case CenterLeft: case Center: case CenterRight: case VertCenter: dy = (fy0 + fy1 + 1)/2; break; case TopLeft: case TopCenter: case TopRight: case Top: dy = fy1 + 1; break; } switch (malign) { case BottomLeft: case CenterLeft: case TopLeft: case Left: dx -= mx0; break; case BottomCenter: case Center: case TopCenter: case HorizCenter: dx -= (mx0 + mx1 + 1)/2; break; case BottomRight: case CenterRight: case TopRight: case Right: dx -= (mx1 + 1); break; } switch (malign) { case BottomLeft: case BottomCenter: case BottomRight: case Bottom: dy -= my0; break; case CenterLeft: case Center: case CenterRight: case VertCenter: dy -= (my0 + my1 + 1)/2; break; case TopLeft: case TopCenter: case TopRight: case Top: dy -= (my1 + 1); break; } if (dx != 0 || dy != 0) { Transformer parents; moved->parentXform(parents); parents.Invert(); parents.Transform(0.0, 0.0, fx0, fy0); parents.Transform(dx, dy, mx0, my0); moved->translate(mx0-fx0, my0-fy0); } }
static void DoFile(const char *savedir, const char *device) { static char *buf = NULL; struct partinfo dpart; struct kerneldumpheader kdhf, kdhl; off_t mediasize, dumpsize, firsthd, lasthd, dmpcnt; FILE *info, *fp, *fpkern; mode_t oumask; int fd, fdinfo, fdkernin, error, wl; int nr, nw, hs, he = 0; int bounds, status; u_int sectorsize; bounds = getbounds(); dmpcnt = 0; mediasize = 0; status = STATUS_UNKNOWN; if (buf == NULL) { buf = malloc(BUFFERSIZE); if (buf == NULL) { syslog(LOG_ERR, "%m"); return; } } if (verbose) printf("checking for kernel dump on device %s\n", device); fd = open(device, O_RDWR); if (fd < 0) { syslog(LOG_ERR, "%s: %m", device); return; } bzero(&dpart, sizeof(dpart)); error = ioctl(fd, DIOCGPART, &dpart); if (error) { syslog(LOG_ERR, "couldn't find media and/or sector size of %s: %m", device); goto closefd; } mediasize = dpart.media_size; sectorsize = dpart.media_blksize; if (verbose) { printf("mediasize = %lld\n", (long long)mediasize); printf("sectorsize = %u\n", sectorsize); } lasthd = mediasize - sectorsize; lseek(fd, lasthd, SEEK_SET); error = read(fd, &kdhl, sizeof kdhl); if (error != sizeof kdhl) { syslog(LOG_ERR, "error reading last dump header at offset %lld in %s: %m", (long long)lasthd, device); goto closefd; } if (memcmp(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic)) { if (verbose) printf("magic mismatch on last dump header on %s\n", device); status = STATUS_BAD; if (force == 0) goto closefd; if (memcmp(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof kdhl.magic) == 0) { if (verbose) printf("forcing magic on %s\n", device); memcpy(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic); } else { syslog(LOG_ERR, "unable to force dump - bad magic"); goto closefd; } } if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); status = STATUS_BAD; if (force == 0) goto closefd; } nfound++; if (clear) goto nuke; if (kerneldump_parity(&kdhl)) { syslog(LOG_ERR, "parity error on last dump header on %s", device); nerr++; status = STATUS_BAD; if (force == 0) goto closefd; } dumpsize = dtoh64(kdhl.dumplength); firsthd = lasthd - dumpsize - sizeof kdhf; lseek(fd, firsthd, SEEK_SET); error = read(fd, &kdhf, sizeof kdhf); if (error != sizeof kdhf) { syslog(LOG_ERR, "error reading first dump header at offset %lld in %s: %m", (long long)firsthd, device); nerr++; goto closefd; } if (verbose >= 2) { printf("First dump headers:\n"); printheader(stdout, &kdhf, device, bounds, -1); printf("\nLast dump headers:\n"); printheader(stdout, &kdhl, device, bounds, -1); printf("\n"); } if (memcmp(&kdhl, &kdhf, sizeof kdhl)) { syslog(LOG_ERR, "first and last dump headers disagree on %s", device); nerr++; status = STATUS_BAD; if (force == 0) goto closefd; } else { status = STATUS_GOOD; } if (checkfor) { printf("A dump exists on %s\n", device); close(fd); exit(0); } if (kdhl.panicstring[0]) syslog(LOG_ALERT, "reboot after panic: %s", kdhl.panicstring); else syslog(LOG_ALERT, "reboot"); if (verbose) printf("Checking for available free space\n"); if (!check_space(savedir, dumpsize)) { nerr++; goto closefd; } writebounds(bounds + 1); /* * Write kernel file. */ fdkernin = open(getbootfile(), O_RDONLY, 0); if (fdkernin < 0) { syslog(LOG_ERR, "%s: %m", getbootfile()); } if (compress) { sprintf(buf, "kern.%d.gz", bounds); fpkern = zopen(buf, "w"); } else { sprintf(buf, "kern.%d", bounds); fpkern = fopen(buf, "w"); } if (fpkern == NULL) { syslog(LOG_ERR, "%s: %m", buf); close(fdkernin); } syslog(LOG_NOTICE, "writing %skernel to %s", compress ? "compressed " : "", buf); while ((nr = read(fdkernin, buf, sizeof(buf))) > 0) { nw = fwrite(buf, 1, nr, fpkern); if (nw != nr) { syslog(LOG_ERR, "kern.%d: %m", bounds); syslog(LOG_WARNING, "WARNING: kernel may be incomplete"); exit(1); } } if (nr < 0) { syslog(LOG_ERR, "%s: %m", getbootfile()); syslog(LOG_WARNING, "WARNING: kernel may be incomplete"); exit(1); } fclose(fpkern); close(fdkernin); sprintf(buf, "info.%d", bounds); /* * Create or overwrite any existing dump header files. */ fdinfo = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fdinfo < 0) { syslog(LOG_ERR, "%s: %m", buf); nerr++; goto closefd; } oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file.*/ if (compress) { sprintf(buf, "vmcore.%d.gz", bounds); fp = zopen(buf, "w"); } else { sprintf(buf, "vmcore.%d", bounds); fp = fopen(buf, "w"); } if (fp == NULL) { syslog(LOG_ERR, "%s: %m", buf); close(fdinfo); nerr++; goto closefd; } (void)umask(oumask); info = fdopen(fdinfo, "w"); if (info == NULL) { syslog(LOG_ERR, "fdopen failed: %m"); nerr++; goto closefd; } if (verbose) printheader(stdout, &kdhl, device, bounds, status); printheader(info, &kdhl, device, bounds, status); fclose(info); syslog(LOG_NOTICE, "writing %score to %s", compress ? "compressed " : "", buf); while (dumpsize > 0) { wl = BUFFERSIZE; if (wl > dumpsize) wl = dumpsize; nr = read(fd, buf, wl); if (nr != wl) { if (nr == 0) syslog(LOG_WARNING, "WARNING: EOF on dump device"); else syslog(LOG_ERR, "read error on %s: %m", device); nerr++; goto closeall; } if (compress) { nw = fwrite(buf, 1, wl, fp); } else { for (nw = 0; nw < nr; nw = he) { /* find a contiguous block of zeroes */ for (hs = nw; hs < nr; hs += BLOCKSIZE) { for (he = hs; he < nr && buf[he] == 0; ++he) /* nothing */ ; /* is the hole long enough to matter? */ if (he >= hs + BLOCKSIZE) break; } /* back down to a block boundary */ he &= BLOCKMASK; /* * 1) Don't go beyond the end of the buffer. * 2) If the end of the buffer is less than * BLOCKSIZE bytes away, we're at the end * of the file, so just grab what's left. */ if (hs + BLOCKSIZE > nr) hs = he = nr; /* * At this point, we have a partial ordering: * nw <= hs <= he <= nr * If hs > nw, buf[nw..hs] contains non-zero data. * If he > hs, buf[hs..he] is all zeroes. */ if (hs > nw) if (fwrite(buf + nw, hs - nw, 1, fp) != 1) break; if (he > hs) if (fseeko(fp, he - hs, SEEK_CUR) == -1) break; } } if (nw != wl) { syslog(LOG_ERR, "write error on vmcore.%d file: %m", bounds); syslog(LOG_WARNING, "WARNING: vmcore may be incomplete"); nerr++; goto closeall; } if (verbose) { dmpcnt += wl; printf("%llu\r", (unsigned long long)dmpcnt); fflush(stdout); } dumpsize -= wl; } if (verbose) printf("\n"); if (fclose(fp) < 0) { syslog(LOG_ERR, "error on vmcore.%d: %m", bounds); nerr++; goto closeall; } nsaved++; if (verbose) printf("dump saved\n"); nuke: if (clear || !keep) { if (verbose) printf("clearing dump header\n"); memcpy(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof kdhl.magic); lseek(fd, lasthd, SEEK_SET); error = write(fd, &kdhl, sizeof kdhl); if (error != sizeof kdhl) syslog(LOG_ERR, "error while clearing the dump header: %m"); } close(fd); return; closeall: fclose(fp); closefd: close(fd); }
static void DoFile(const char *savedir, const char *device) { xo_handle_t *xostdout, *xoinfo; static char infoname[PATH_MAX], corename[PATH_MAX], linkname[PATH_MAX]; static char *buf = NULL, *temp = NULL; struct kerneldumpheader kdhf, kdhl; off_t mediasize, dumpsize, firsthd, lasthd; FILE *info, *fp; mode_t oumask; int fd, fdinfo, error; int bounds, status; u_int sectorsize, xostyle; int istextdump; bounds = getbounds(); mediasize = 0; status = STATUS_UNKNOWN; xostdout = xo_create_to_file(stdout, XO_STYLE_TEXT, 0); if (xostdout == NULL) { syslog(LOG_ERR, "%s: %m", infoname); return; } if (maxdumps > 0 && bounds == maxdumps) bounds = 0; if (buf == NULL) { buf = malloc(BUFFERSIZE); if (buf == NULL) { syslog(LOG_ERR, "%m"); return; } } if (verbose) printf("checking for kernel dump on device %s\n", device); fd = open(device, (checkfor || keep) ? O_RDONLY : O_RDWR); if (fd < 0) { syslog(LOG_ERR, "%s: %m", device); return; } error = ioctl(fd, DIOCGMEDIASIZE, &mediasize); if (!error) error = ioctl(fd, DIOCGSECTORSIZE, §orsize); if (error) { syslog(LOG_ERR, "couldn't find media and/or sector size of %s: %m", device); goto closefd; } if (verbose) { printf("mediasize = %lld\n", (long long)mediasize); printf("sectorsize = %u\n", sectorsize); } if (sectorsize < sizeof(kdhl)) { syslog(LOG_ERR, "Sector size is less the kernel dump header %zu", sizeof(kdhl)); goto closefd; } lasthd = mediasize - sectorsize; if (temp == NULL) { temp = malloc(sectorsize); if (temp == NULL) { syslog(LOG_ERR, "%m"); return; } } if (lseek(fd, lasthd, SEEK_SET) != lasthd || read(fd, temp, sectorsize) != (ssize_t)sectorsize) { syslog(LOG_ERR, "error reading last dump header at offset %lld in %s: %m", (long long)lasthd, device); goto closefd; } memcpy(&kdhl, temp, sizeof(kdhl)); istextdump = 0; if (strncmp(kdhl.magic, TEXTDUMPMAGIC, sizeof kdhl) == 0) { if (verbose) printf("textdump magic on last dump header on %s\n", device); istextdump = 1; if (dtoh32(kdhl.version) != KERNELDUMP_TEXT_VERSION) { syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); status = STATUS_BAD; if (force == 0) goto closefd; } } else if (memcmp(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic) == 0) { if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); status = STATUS_BAD; if (force == 0) goto closefd; } } else { if (verbose) printf("magic mismatch on last dump header on %s\n", device); status = STATUS_BAD; if (force == 0) goto closefd; if (memcmp(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof kdhl.magic) == 0) { if (verbose) printf("forcing magic on %s\n", device); memcpy(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic); } else { syslog(LOG_ERR, "unable to force dump - bad magic"); goto closefd; } if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); status = STATUS_BAD; if (force == 0) goto closefd; } } nfound++; if (clear) goto nuke; if (kerneldump_parity(&kdhl)) { syslog(LOG_ERR, "parity error on last dump header on %s", device); nerr++; status = STATUS_BAD; if (force == 0) goto closefd; } dumpsize = dtoh64(kdhl.dumplength); firsthd = lasthd - dumpsize - sectorsize; if (lseek(fd, firsthd, SEEK_SET) != firsthd || read(fd, temp, sectorsize) != (ssize_t)sectorsize) { syslog(LOG_ERR, "error reading first dump header at offset %lld in %s: %m", (long long)firsthd, device); nerr++; goto closefd; } memcpy(&kdhf, temp, sizeof(kdhf)); if (verbose >= 2) { printf("First dump headers:\n"); printheader(xostdout, &kdhf, device, bounds, -1); printf("\nLast dump headers:\n"); printheader(xostdout, &kdhl, device, bounds, -1); printf("\n"); } if (memcmp(&kdhl, &kdhf, sizeof(kdhl))) { syslog(LOG_ERR, "first and last dump headers disagree on %s", device); nerr++; status = STATUS_BAD; if (force == 0) goto closefd; } else { status = STATUS_GOOD; } if (checkfor) { printf("A dump exists on %s\n", device); close(fd); exit(0); } if (kdhl.panicstring[0] != '\0') syslog(LOG_ALERT, "reboot after panic: %*s", (int)sizeof(kdhl.panicstring), kdhl.panicstring); else syslog(LOG_ALERT, "reboot"); if (verbose) printf("Checking for available free space\n"); if (!check_space(savedir, dumpsize, bounds)) { nerr++; goto closefd; } writebounds(bounds + 1); saved_dump_remove(bounds); snprintf(infoname, sizeof(infoname), "info.%d", bounds); /* * Create or overwrite any existing dump header files. */ fdinfo = open(infoname, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fdinfo < 0) { syslog(LOG_ERR, "%s: %m", infoname); nerr++; goto closefd; } oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file.*/ if (compress) { snprintf(corename, sizeof(corename), "%s.%d.gz", istextdump ? "textdump.tar" : "vmcore", bounds); fp = zopen(corename, "w"); } else { snprintf(corename, sizeof(corename), "%s.%d", istextdump ? "textdump.tar" : "vmcore", bounds); fp = fopen(corename, "w"); } if (fp == NULL) { syslog(LOG_ERR, "%s: %m", corename); close(fdinfo); nerr++; goto closefd; } (void)umask(oumask); info = fdopen(fdinfo, "w"); if (info == NULL) { syslog(LOG_ERR, "fdopen failed: %m"); nerr++; goto closeall; } xostyle = xo_get_style(NULL); xoinfo = xo_create_to_file(info, xostyle, 0); if (xoinfo == NULL) { syslog(LOG_ERR, "%s: %m", infoname); nerr++; goto closeall; } xo_open_container_h(xoinfo, "crashdump"); if (verbose) printheader(xostdout, &kdhl, device, bounds, status); printheader(xoinfo, &kdhl, device, bounds, status); xo_close_container_h(xoinfo, "crashdump"); xo_flush_h(xoinfo); xo_finish_h(xoinfo); fclose(info); syslog(LOG_NOTICE, "writing %score to %s/%s", compress ? "compressed " : "", savedir, corename); if (istextdump) { if (DoTextdumpFile(fd, dumpsize, lasthd, buf, device, corename, fp) < 0) goto closeall; } else { if (DoRegularFile(fd, dumpsize, buf, device, corename, fp) < 0) goto closeall; } if (verbose) printf("\n"); if (fclose(fp) < 0) { syslog(LOG_ERR, "error on %s: %m", corename); nerr++; goto closefd; } symlinks_remove(); if (symlink(infoname, "info.last") == -1) { syslog(LOG_WARNING, "unable to create symlink %s/%s: %m", savedir, "info.last"); } if (compress) { snprintf(linkname, sizeof(linkname), "%s.last.gz", istextdump ? "textdump.tar" : "vmcore"); } else { snprintf(linkname, sizeof(linkname), "%s.last", istextdump ? "textdump.tar" : "vmcore"); } if (symlink(corename, linkname) == -1) { syslog(LOG_WARNING, "unable to create symlink %s/%s: %m", savedir, linkname); } nsaved++; if (verbose) printf("dump saved\n"); nuke: if (!keep) { if (verbose) printf("clearing dump header\n"); memcpy(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof(kdhl.magic)); memcpy(temp, &kdhl, sizeof(kdhl)); if (lseek(fd, lasthd, SEEK_SET) != lasthd || write(fd, temp, sectorsize) != (ssize_t)sectorsize) syslog(LOG_ERR, "error while clearing the dump header: %m"); } xo_close_container_h(xostdout, "crashdump"); xo_finish_h(xostdout); close(fd); return; closeall: fclose(fp); closefd: close(fd); }
/* * Updates the background objects as necessary. Removes existing ones, * and then looks at the interface and builds new ones. */ void UpdateBackgroundObjects ( WindowObjectType *wo, int potIndex ) { MetObjectType *mot, *mlist[MAXMETOBJS]; int i, count, nmaps; char mapfile[GEMPAKSTRING]; char mapname[GEMPAKSTRING]; char *latinc, *loninc, *lblinc; char line_color[GEMPAKSTRING]; char line_type[GEMPAKSTRING]; char line_width[GEMPAKSTRING]; char sysM [] = "M"; float lat1, lat2, lon1, lon2, latdiff; double fminscale, fmaxscale; char *minscale, *maxscale; Widget stateW; BooleanType stateChanged; GuiMapBackgroundDialogType *mbg; GuiLatLonGridDialogType *llg; PixmapObjectType *po, *ppo; llg = GetGuiLatLonGridDialog(); mbg = GetGuiMapBackgroundDialog(); po = wo->pixmapObjects[potIndex]; /* * First, decide if we need to rebuild the background objects. If there * are no MAP class objects, or if the backgrounds * dialog info has changed, then we will build new ones. */ nmaps = 0; for ( i = 0; i < po->numMetObjects; i++ ) { mot = po->metObjects [i]; if ( GetMetObjectClass ( mot->type ) == MAP ) nmaps++; } stateChanged =( GetLatLonGridChangeState (llg) || GetMapListChangeState (mbg) ); if ( nmaps == 0 || stateChanged ) RemoveBackgroundObjects( po ); else return; /* * Get the latitude range of the current window */ if ( (getbounds ( sysM, &lat1, &lon1, &lat2, &lon2 )) == 0 ) latdiff = -9999; else latdiff = (float) fabs (lat2 - lat1); count = 0; /* * Loop over all the map objects. See if any are turned on. If so, * check the scale range and add them if they are in the right scale. */ for ( i = 0; i < mbg->nmaps; i++ ) { if ( XmToggleButtonGetState ( GetMapListOnToggleW(mbg,i)) ) { maxscale = XmTextGetString( GetMapListMaxScaleW(mbg,i)); minscale = XmTextGetString( GetMapListMinScaleW(mbg,i)); fmaxscale = atof ( maxscale); fminscale = atof ( minscale); XtFree ( maxscale); XtFree ( minscale); if ( ( fmaxscale <= 0.0 ) || ( latdiff >= fminscale && latdiff <= fmaxscale) ) { strcpy ( mapfile, mbg->path[i] ); strcpy ( mapname, mbg->name[i].string ); sprintf ( line_color, "%d", GetMapListLineColor(mbg,i)); sprintf ( line_type, "%d", GetMapListLineType(mbg,i)); sprintf ( line_width, "%d", GetMapListLineWidth(mbg,i)); mlist[count] = (MetObjectType *) MakeMapObject( mapname, mapfile, line_color, line_type, line_width); count++; } } } /* * Add a lat/lon grid */ if ( XmToggleButtonGetState ( GetLatLonGridStateW (llg) )) { latinc = XmTextGetString ( GetLatIncrementW (llg) ); loninc = XmTextGetString ( GetLonIncrementW (llg) ); lblinc = XmTextGetString ( GetLatLonGridLabelIncW(llg) ); sprintf ( line_color, "%d", GetLatLonGridColor (llg)); sprintf ( line_type, "%d", GetLatLonGridType (llg)); sprintf ( line_width, "%d", GetLatLonGridWidth (llg)); mlist[count] = (MetObjectType *) MakeLatLonGridObject( latinc, loninc, lblinc, line_color, line_type, line_width); XtFree ( latinc ); XtFree ( loninc ); XtFree ( lblinc ); count++; } /* * Add all the created objects in as background objects */ AddMapBackgroundObjects ( po, count, mlist ); /* * Since we have new maps, set all the drawn flags of all the metObjects * in this pixmapObject false so that they will be redrawn. */ SetPixmapObjectDrawnFlag ( po, False ); /* * Reset the change state of the map and lat/lon dialogs for the last * pixmap */ if ( potIndex == wo->numPixmapObjects - 1 ) { SetLatLonGridChangeState ( llg, False); SetMapListChangeState ( mbg, False); } }
int getimagecoords ( PixmapObjectType *po, char *incoords, float *x, float *y, float *ix, float *iy ) { int xleft, ytop, xrght, ybot; int iret, np = 1; int i, overlayClass; char Lcoords [] = "L", Vcoords [] = "V"; float xout, yout; float xl, yb, xr, yt; AnyImageObjectType *iot; MetObjectType *mo; if ( strlen (incoords) != 1 ) return (0); /* * Get the intermediate linear (L) coordinate bounds. If not defined, * (as in the case of a cross section image) get the view coords. */ iret = getbounds ( Lcoords, &xl, &yb, &xr, &yt ); /* * Transform the input coordinate to L coords */ convertcoords ( incoords, Lcoords, x, y, &xout, &yout, strlen(incoords), strlen(Lcoords)); /* * If po is defined, get the image size from the first image */ if ( po != NULL ) { for ( i = 0; i < po->numMetObjects; i++ ) { mo = po->metObjects[i]; overlayClass = GetMetObjectClass( mo->type ); if ( overlayClass == IMAGE || overlayClass == BACKGROUND ) { iot = (AnyImageObjectType *) mo->metObjectContent; xleft = iot->imgCmn.imleft; ytop = iot->imgCmn.imtop; xrght = iot->imgCmn.imrght; ybot = iot->imgCmn.imbot; break; } } } /* * Otherwise, get the image size from the gempak image common block */ else { xleft = getimgcomint ( "imleft", strlen("imleft") ); ytop = getimgcomint ( "imtop", strlen("imtop") ); xrght = getimgcomint ( "imrght", strlen("imrght") ); ybot = getimgcomint ( "imbot", strlen("imbot") ); } /* * Determine the image coordinates */ *ix = ( xleft + (xout - xl) * (xrght - xleft) / (xr - xl) ); *iy = ( ytop + (yout - yt) * (ybot- ytop) / (yb - yt) ); return (1); }