/* Write ONE line of npix pixels of a check-image. */ void writecheck(checkstruct *check, PIXTYPE *data, int w) { if (check->type == CHECK_APERTURES || check->type == CHECK_SUBPSFPROTOS || check->type == CHECK_SUBPCPROTOS || check->type == CHECK_PCOPROTOS || check->type == CHECK_SUBPROFILES) { memcpy((PIXTYPE *)check->pix + w*(check->y++), data, w*sizeof(PIXTYPE)); return; } else if (check->type == CHECK_SUBOBJECTS) { int i; PIXTYPE *pixt; pixt = check->line; for (i=w; i--; data++) *(pixt++) = (*data>-BIG)? *data:0.0; data = check->line; } if (bswapflag) swapbytes(data, sizeof(PIXTYPE), w); QFWRITE(data, w*sizeof(PIXTYPE), check->file, check->filename); if (bswapflag) /*-- Put the buffer back to its original state */ swapbytes(data, sizeof(PIXTYPE), w); return; }
void _GR_swap64(GR_int64 *h) { GRX_ENTER(); swapbytes(((GR_int8 *)h) , ((GR_int8 *)h)+7); swapbytes(((GR_int8 *)h)+1, ((GR_int8 *)h)+6); swapbytes(((GR_int8 *)h)+2, ((GR_int8 *)h)+5); swapbytes(((GR_int8 *)h)+3, ((GR_int8 *)h)+4); GRX_LEAVE(); }
/* Autor: RD */ void memWrite(i8086core *core, i808616BitAdr adr, unsigned short val, unsigned char w, int reg) //schreibt 16/8bit (abhängig von w) aus dem Speicher { doSegmentOverride(core,reg); core->mem[i8086GetSegRegister_fast(core,reg,1)+adr]=val; if (w) core->mem[i8086GetSegRegister_fast(core,reg,1)+adr+1]=swapbytes(val); }
static void accel_timeout_handler(void* p_context) { update_xyz(xyz); ble_acc_accel_level_update(&m_acc, swapbytes(xyz[1])); uart_put_dec32bit((uint32_t)xyz[1]); UNUSED_PARAMETER(p_context); simple_uart_putstring((const uint8_t*) "acc\r\n"); }
static void swap_data(SCAN *s) { int i; for (i=0; i<s->NChannel; i++) { swapbytes((char *)&(s->c[i]), sizeof(float)); } }
Cardinal Urm__SwapRGMCallbackDesc (RGMCallbackDescPtr callb_desc, RGMWidgetRecordPtr widget_rec) { Cardinal ndx; /* inner loop index */ RGMResourceDescPtr res_desc; /* resource description literal */ char err_msg[300]; swapbytes( callb_desc->validation ); swapbytes( callb_desc->count ); swapbytes( callb_desc->annex ); swapbytes( callb_desc->unres_ref_count ); for (ndx=0 ; ndx < callb_desc->count ; ndx++) { #ifdef WORD64 swap4bytes( callb_desc->item[ndx].cb_item.routine ); swap4bytes( callb_desc->item[ndx].cb_item.rep_type ); #else swap2bytes( callb_desc->item[ndx].cb_item.routine ); swap2bytes( callb_desc->item[ndx].cb_item.rep_type ); #endif switch (callb_desc->item[ndx].cb_item.rep_type) { case MrmRtypeInteger: case MrmRtypeBoolean: swapbytes( callb_desc->item[ndx].cb_item.datum.ival ); break; case MrmRtypeSingleFloat: swapbytes( callb_desc->item[ndx].cb_item.datum.ival ); _MrmOSIEEEFloatToHost((float *) &(callb_desc->item[ndx].cb_item.datum.ival)); case MrmRtypeNull: break; case MrmRtypeResource: swapbytes( callb_desc->item[ndx].cb_item.datum.offset ); res_desc = (RGMResourceDesc *) ((char *)widget_rec + callb_desc->item[ndx].cb_item.datum.offset); Urm__SwapRGMResourceDesc( res_desc ); /* flag this resource as needing further byte swapping */ res_desc->cvt_type |= MrmResourceUnswapped; break; default: swapbytes( callb_desc->item[ndx].cb_item.datum.offset ); sprintf(err_msg, _MrmMMsg_0021, callb_desc->item[ndx].cb_item.rep_type, ndx); return Urm__UT_Error ("Urm__SwapRGMCallbackDesc", err_msg, NULL, NULL, MrmFAILURE) ; break; } } return MrmSUCCESS; }
void getreg(int idx) { unsigned char mac[20]; unsigned char pmk[32]; if(!(idx & 1)) { picoread(CORE_OFF | (idx << 6) | 0x28, mac, 20); memcpy(fpga[idx].mac0, mac, 20); } else { picoread(CORE_OFF | (idx << 6) | 0x28, mac, 20); swapbytes(pmk, fpga[idx ^ 1].mac0, 20); swapbytes(pmk + 20, mac, 12); if(hdr_version == 1) dictfile_v1_found(pmk, fpga[idx].passphrase); else dictfile_v2_found(pmk, fpga[idx].passphrase); } fpga[idx].set = 0; }
Cardinal Urm__SwapRGMResourceDesc (RGMResourceDescPtr res_desc) { IDBridDesc *idb_rid_ptr; swapbytes( res_desc->size ); swapbytes( res_desc->annex1 ); if ( res_desc->type == URMrRID ) { idb_rid_ptr = (IDBridDesc *)&(res_desc->key.id); #ifdef WORD64 swap4bytes( idb_rid_ptr->internal_id.map_rec ); swap4bytes( idb_rid_ptr->internal_id.res_index ); #else swap2bytes( idb_rid_ptr->internal_id.map_rec ); swap2bytes( idb_rid_ptr->internal_id.res_index ); #endif } return MrmSUCCESS; }
void getreg(int idx) { unsigned char mac[20]; unsigned char pmk[32]; if(!(idx & 1)) { picomemread(piconum, CORE_OFF | (idx << 6) | 0x28, mac, 20); memcpy(fpga[idx].mac0, mac, 20); } else { picomemread(piconum, CORE_OFF | (idx << 6) | 0x28, mac, 20); swapbytes(pmk, fpga[idx ^ 1].mac0, 20); swapbytes(pmk + 20, mac, 12); dictfile_found(pmk, fpga[idx].passphrase); } // for(i = 0; i < 20; i++) // printf("%02x ", mac[i]); // printf("\n"); fpga[idx].set = 0; }
//___________________________________________________________________________________ void GetOneRecord(FILE *fp, double &T, double wv[128]) // reads one record and goes to the next record { int bigendianFlag = bigendianMachine(); // NT TT record __int64 qwTimeStamp, qwTimeStamp0; long dwParams[10]; short snData[128]; fread(&qwTimeStamp0, sizeof(char), 8, fp); fread(dwParams, sizeof(char), 40, fp); fread(snData , sizeof(char), 256, fp); if(bigendianFlag) { // convert from NT(little endian) to Sun (big endian) qwTimeStamp = swapbytes(qwTimeStamp0); if(qwTimeStamp > TIMESTAMP_MAX) { mexPrintf(" ERROR: timestamp is too large to fit in a double!\n"); mexPrintf(" Converted timestamps MAY or MAY NOT be valid - proceed with care! \n"); } T = (double) qwTimeStamp/100.0/10000; for (int j = 0; j<4; j++) for(int k = 0; k<32; k++) wv[j + 4*k] = (double) swapbytes(snData[j + 4*k]); } else { // don't convert, just copy qwTimeStamp = qwTimeStamp0; if(qwTimeStamp > TIMESTAMP_MAX) { mexPrintf(" ERROR: timestamp is too large to fit in a double!\n"); mexPrintf(" Converted timestamps MAY or MAY NOT be valid - proceed with care! \n"); } T = (double) qwTimeStamp/100.0/10000; for (int j = 0; j<4; j++) for(int k = 0; k<32; k++) wv[j + 4*k] = (double) snData[j + 4*k]; } }
int make_mcr1(int fd) { int ret, count, i, fd1, offset; unsigned char b[256*4]; printf("making MCR1...\n"); fd1 = open(mcr_filename, O_RDONLY); if (fd1 < 0) { perror(mcr_filename); return -1; } count = 0; offset = part_offset("MCR1"); printf("offset %o\n", offset); while (1) { ret = read(fd1, b, 256*4); if (ret <= 0) break; #ifndef NEED_SWAP swapbytes((unsigned int *)b); #endif /* MCR1 start XXX */ write_block(fd, offset/*021*/+count, b); count++; if (ret < 256*4) break; } printf("%d blocks\n", count); return 0; }
void addreg(SHA1_CACHE *cache, unsigned char *digest, char *passphrase) { unsigned long addr; SHA_CTX *ictx, *octx; char mac[20]; static int fpga_idx = 0; ictx = (SHA_CTX *)cache->k_ipad; octx = (SHA_CTX *)cache->k_opad; swapbytes(mac, digest, 20); fpga_idx = findreg(fpga_idx); if(fpga_idx == -1) { printf("fpga_idx == -1\n"); exit(0); } addr = CORE_OFF | (fpga_idx << 6); addr += picowrite(addr, &ictx->h0, 20); addr += picowrite(addr, &octx->h0, 20); addr += picowrite(addr, mac, 20); memcpy(fpga[fpga_idx].passphrase, passphrase, 64); fpga[fpga_idx].set = 1; if(fpga_idx == (FPGA_MAX - FPGA_DIFF)) { if(!fpga_read) { startfpga(); fpga_read = 1; } fpga_idx = 0; } else if((fpga_idx % FPGA_BITS) == (FPGA_CORES - 1)) fpga_idx += FPGA_DIFF; else fpga_idx++; }
static void swap_header(SCAN *s) { int i; /* Swapping of Slength, NChannel, and ScanNo is already done in get_drp() */ /* swapbytes((char *)&(s->Slength), sizeof(short)); */ /* swapbytes((char *)&(s->NChannel), sizeof(short)); */ swapbytes((char *)&(s->Ctrl), sizeof(short)); /* swapbytes((char *)&(s->ScanNo), sizeof(short)); */ swapbytes((char *)&(s->SubScan), sizeof(short)); swapbytes((char *)&(s->Year), sizeof(short)); swapbytes((char *)&(s->Month), sizeof(short)); swapbytes((char *)&(s->Day), sizeof(short)); swapbytes((char *)&(s->UTHour), sizeof(short)); swapbytes((char *)&(s->UTMin), sizeof(short)); swapbytes((char *)&(s->UTSec), sizeof(short)); swapbytes((char *)&(s->STHour), sizeof(short)); swapbytes((char *)&(s->STMin), sizeof(short)); swapbytes((char *)&(s->STSec), sizeof(short)); swapbytes((char *)&(s->CSystem), sizeof(short)); swapbytes((char *)&(s->ObsMode), sizeof(short)); swapbytes((char *)&(s->Backend), sizeof(short)); swapbytes((char *)&(s->Frontend), sizeof(short)); swapbytes((char *)&(s->MapX), sizeof(short)); swapbytes((char *)&(s->MapY), sizeof(short)); swapbytes((char *)&(s->JulDate), sizeof(long)); swapbytes((char *)&(s->AirTemp), sizeof(float)); swapbytes((char *)&(s->Pressure), sizeof(float)); swapbytes((char *)&(s->Humidity), sizeof(float)); swapbytes((char *)&(s->Equinox), sizeof(float)); swapbytes((char *)&(s->EquiNow), sizeof(float)); swapbytes((char *)&(s->Longitude), sizeof(float)); swapbytes((char *)&(s->Latitude), sizeof(float)); swapbytes((char *)&(s->Long2000), sizeof(float)); swapbytes((char *)&(s->Lat2000), sizeof(float)); swapbytes((char *)&(s->LMapOff), sizeof(float)); swapbytes((char *)&(s->BMapOff), sizeof(float)); swapbytes((char *)&(s->Azimuth), sizeof(float)); swapbytes((char *)&(s->Elevation), sizeof(float)); swapbytes((char *)&(s->AzOffset), sizeof(float)); swapbytes((char *)&(s->ElOffset), sizeof(float)); swapbytes((char *)&(s->AzMapOff), sizeof(float)); swapbytes((char *)&(s->ElMapOff), sizeof(float)); swapbytes((char *)&(s->AzPointg), sizeof(float)); swapbytes((char *)&(s->ElPointg), sizeof(float)); swapbytes((char *)&(s->AzErrAve), sizeof(float)); swapbytes((char *)&(s->ElErrAve), sizeof(float)); swapbytes((char *)&(s->AzErrRms), sizeof(float)); swapbytes((char *)&(s->ElErrRms), sizeof(float)); swapbytes((char *)&(s->GalLong), sizeof(float)); swapbytes((char *)&(s->GalLat), sizeof(float)); swapbytes((char *)&(s->VHel), sizeof(float)); swapbytes((char *)&(s->VLsr), sizeof(float)); swapbytes((char *)&(s->Axial), sizeof(float)); swapbytes((char *)&(s->Shift), sizeof(float)); swapbytes((char *)&(s->VTilt), sizeof(float)); swapbytes((char *)&(s->HTilt), sizeof(float)); swapbytes((char *)&(s->Tcal), sizeof(float)); swapbytes((char *)&(s->Tsys), sizeof(float)); swapbytes((char *)&(s->Trec), sizeof(float)); swapbytes((char *)&(s->Tau), sizeof(float)); swapbytes((char *)&(s->dBl), sizeof(float)); swapbytes((char *)&(s->IntTime), sizeof(float)); swapbytes((char *)&(s->RefCorr), sizeof(float)); swapbytes((char *)&(s->ParAngle), sizeof(float)); swapbytes((char *)&(s->PosAngle), sizeof(float)); swapbytes((char *)&(s->StepX), sizeof(float)); swapbytes((char *)&(s->StepY), sizeof(float)); swapbytes((char *)&(s->Bandwidth), sizeof(double)); swapbytes((char *)&(s->RestFreq), sizeof(double)); swapbytes((char *)&(s->SkyFreq), sizeof(double)); swapbytes((char *)&(s->FirstIF), sizeof(double)); swapbytes((char *)&(s->FreqThrow), sizeof(double)); swapbytes((char *)&(s->FreqRes), sizeof(double)); swapbytes((char *)&(s->VSource), sizeof(double)); swapbytes((char *)&(s->VelRes), sizeof(double)); for (i=0; i<10; i++) swapbytes((char *)&(s->work[i]), sizeof(float)); for (i=0; i<31; i++) swapbytes((char *)&(s->flag[i]), sizeof(short)); }
/* initialize check-image (for subsequent writing). */ void reinitcheck(picstruct *field, checkstruct *check) { wcsstruct *wcs; char *buf; int i, ival; size_t padsize; double dval; ULONG *ptri; PIXTYPE *ptrf; /* Inherit the field FITS header */ check->fitsheadsize = field->tab->headnblock*FBSIZE; QMEMCPY(field->tab->headbuf, check->fitshead, char, check->fitsheadsize); check->y = 0; /* Neutralize possible scaling factors */ dval = 1.0;fitswrite(check->fitshead, "BSCALE ", &dval, H_FLOAT, T_DOUBLE); dval = 0.0;fitswrite(check->fitshead, "BZERO ", &dval, H_FLOAT, T_DOUBLE); ival = 1;fitswrite(check->fitshead, "BITSGN ", &ival, H_INT, T_LONG); if (field->tab->compress_type != COMPRESS_NONE) fitswrite(check->fitshead, "IMAGECOD", (void*)"NONE", H_STRING, T_STRING); fitswrite(check->fitshead, "ORIGIN ", (void*)BANNER, H_STRING, T_STRING); switch(check->type) { case CHECK_IDENTICAL: case CHECK_BACKGROUND: case CHECK_FILTERED: case CHECK_SUBTRACTED: ival = -32; fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); check->width = field->width; check->height = field->height; check->npix = field->npix; QMALLOC(ptrf, PIXTYPE, check->width); check->pix = (void *)ptrf; QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); free(check->fitshead); break; case CHECK_BACKRMS: case CHECK_SUBOBJECTS: ival = -32; fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); check->width = field->width; check->height = field->height; check->npix = field->npix; QMALLOC(ptrf, PIXTYPE, check->width); check->pix = (void *)ptrf; QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); free(check->fitshead); /*---- Allocate memory for replacing the blanked pixels by 0 */ if (!check->line) QMALLOC(check->line, PIXTYPE, field->width); break; case CHECK_OBJECTS: case CHECK_APERTURES: case CHECK_SUBPSFPROTOS: case CHECK_PSFPROTOS: case CHECK_SUBPCPROTOS: case CHECK_PCPROTOS: case CHECK_PCOPROTOS: case CHECK_SUBPROFILES: case CHECK_PROFILES: case CHECK_PATTERNS: ival = -32; fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); check->width = field->width; check->height = field->height; check->npix = field->npix; check->overlay = 30*field->backsig; QCALLOC(ptrf, PIXTYPE, check->npix); check->pix = (void *)ptrf; QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); free(check->fitshead); break; case CHECK_SEGMENTATION: ival = 32; fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); check->width = field->width; check->height = field->height; check->npix = field->npix; QCALLOC(ptri, ULONG, check->npix); check->pix = (void *)ptri; QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); free(check->fitshead); break; case CHECK_ASSOC: ival = -32; fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); check->width = field->width; check->height = field->height; check->npix = field->npix; QMALLOC(ptrf, PIXTYPE, check->npix); check->pix = (void *)ptrf; /*---- Initialize the pixmap to IEEE NaN */ memset(ptrf, 0xFF, check->npix*sizeof(LONG)); QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); free(check->fitshead); break; case CHECK_MINIBACKGROUND: case CHECK_MINIBACKRMS: ival = -32; fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); check->width = field->nbackx; fitswrite(check->fitshead, "NAXIS1 ", &check->width, H_INT, T_LONG); check->height = field->nbacky; fitswrite(check->fitshead, "NAXIS2 ", &check->height, H_INT, T_LONG); /*---- Scale the WCS information if present */ if ((wcs=field->wcs)) { dval = wcs->cdelt[0]*field->backw; fitswrite(check->fitshead, "CDELT1 ", &dval, H_EXPO, T_DOUBLE); dval = wcs->cdelt[1]*field->backh; fitswrite(check->fitshead, "CDELT2 ", &dval, H_EXPO, T_DOUBLE); dval = (wcs->crpix[0]-0.5)/field->backw + 0.5; fitswrite(check->fitshead, "CRPIX1 ", &dval, H_EXPO, T_DOUBLE); dval = (wcs->crpix[1]-0.5)/field->backh + 0.5; fitswrite(check->fitshead, "CRPIX2 ", &dval, H_EXPO, T_DOUBLE); dval = wcs->cd[0]*field->backw; fitswrite(check->fitshead, "CD1_1 ", &dval, H_EXPO, T_DOUBLE); dval = wcs->cd[1]*field->backh; fitswrite(check->fitshead, "CD1_2 ", &dval, H_EXPO, T_DOUBLE); dval = wcs->cd[wcs->naxis]*field->backw; fitswrite(check->fitshead, "CD2_1 ", &dval, H_EXPO, T_DOUBLE); dval = wcs->cd[wcs->naxis+1]*field->backh; fitswrite(check->fitshead, "CD2_2 ", &dval, H_EXPO, T_DOUBLE); } check->npix = check->width*check->height; QMALLOC(ptrf, PIXTYPE, check->npix); check->pix = (void *)ptrf; if (check->type==CHECK_MINIBACKRMS) memcpy(check->pix, field->sigma, check->npix*sizeof(float)); else memcpy(check->pix, field->back, check->npix*sizeof(float)); QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); free(check->fitshead); if (bswapflag) swapbytes(check->pix, sizeof(float), (int)check->npix); QFWRITE(check->pix,check->npix*sizeof(float),check->file, check->filename); /*---- Put the buffer back to its original state */ if (bswapflag) swapbytes(check->pix, sizeof(float), (int)check->npix); free(check->pix); QCALLOC(buf, char, FBSIZE); padsize = (FBSIZE -((check->npix*sizeof(PIXTYPE))%FBSIZE))% FBSIZE; if (padsize) QFWRITE (buf, padsize, check->file, check->filename); free(buf); break; case CHECK_MAPSOM: ival = -32; fitswrite(check->fitshead, "BITPIX ", &ival, H_INT, T_LONG); check->width = field->width; check->height = field->height; check->npix = field->npix; QMALLOC(ptrf, PIXTYPE, check->npix); check->pix = (void *)ptrf; for (i=check->npix; i--;) *(ptrf++) = -10.0; QFWRITE(check->fitshead,check->fitsheadsize,check->file,check->filename); free(check->fitshead); break; default: error(EXIT_FAILURE, "*Internal Error* in ", "reinitcheck()!"); } return; }
int get_drp(char *scanname, FDATA *fd) { int h, d, swapped=0; SCAN *s = &OnScan; XSCAN *x = &XScan; FILE *fp; string buf; void send_line(); double rta(float); char *GetRAStr(double), *GetDECStr(double); char *GetLongStr(double), *GetLatStr(double); int CheckDataSize(int); fp = fopen(scanname, "r"); if (!fp) { sprintf(buf, "Couldn't find DRP file '%s'.", scanname); send_line(buf); return -1; } #ifdef DEBUG printf("File %s opened.\n", scanname); #endif h = fread((char *)s, 1, HEADER, fp); if (h != HEADER) { sprintf(buf, "Error while reading header of DRP file '%s'.", scanname); send_line(buf); fclose(fp); return -1; } #ifdef DEBUG printf("Header (%d) read.\n", h); printf("NChannel=%d\n", s->NChannel); printf("ScanNo=%d\n", s->ScanNo); printf("SLength=%d\n", s->Slength); #endif if (s->NChannel <= 0 || s->ScanNo < 0) { sprintf(buf, "Strange header: ScanNo=%d, NChan=%d, Slength=%d.", s->ScanNo, s->NChannel, s->Slength); send_line(buf); swapbytes((char *)&(s->NChannel), sizeof(short)); swapbytes((char *)&(s->ScanNo), sizeof(short)); swapbytes((char *)&(s->Slength), sizeof(short)); #ifdef DEBUG printf("Byte swapped values:\n"); printf("NChannel=%d\n", s->NChannel); printf("ScanNo=%d\n", s->ScanNo); printf("SLength=%d\n", s->Slength); #endif sprintf(buf, "Let's try byte swapping: NChannel now becomes %d.", s->NChannel); send_line(buf); if (s->NChannel > 0 && s->ScanNo >= 0 && s->Slength > 0) { /* Let's try byteswapping */ send_line("This looks better. Let's go with swapped bytes."); swapped = 1; swap_header(s); } else { /* Give up on this scan */ send_line("It doesn't look better. Can't read this."); fclose(fp); return -1; } } #ifdef DEBUG printf("Need swapping? (1=yes) %d.\n", swapped); #endif if (CheckDataSize(s->NChannel) < s->NChannel) { sprintf(buf, "Error while allocating memory, NChan=%d.", s->NChannel); send_line(buf); fclose(fp); return -1; } #ifdef DEBUG printf("NChannel=%d.\n", s->NChannel); #endif if (s->Slength != (short)DRPVERSION) { if (s->Slength == HEADER + 2*s->NChannel) { /* old DRP scan, correct position for offsets */ s->Longitude -= s->LMapOff/cos(s->Latitude); s->Latitude -= s->BMapOff; } s->Slength = DRPVERSION; /* indicate DRP version */ sprintf(buf, "Detecting old DRP format in '%s' -- converting.", scanname); send_line(buf); } s->Name[11] = '\0'; s->Project[3] = '\0'; s->Observer[15] = '\0'; s->Program[15] = '\0'; s->Molecule[17] = '\0'; SetCSystemFromDRP(s); if (!fd) { fclose(fp); return 0; } d = fread((char *)s->c, sizeof(float), s->NChannel, fp); if (d != s->NChannel) { sprintf(buf, "Error (%d != %d) while reading data of DRP file '%s'.", d, s->NChannel, scanname); send_line(buf); fclose(fp); return -1; } fclose(fp); if (swapped) swap_data(s); x->NChannel = s->NChannel; DRP2FD(s, x, fd); if (fd->coordType == COORD_TYPE_GAL) { sprintf(buf, "DRP (%s: %s %s %5.1f,%5.1f) scan %d read.\n", fd->sname, GetLongStr(fd->x0), GetLatStr(fd->y0), fd->xoff, fd->yoff, fd->sno); } else { sprintf(buf, "DRP (%s: %s %s %5.1f,%5.1f) scan %d read.\n", fd->sname, GetRAStr(fd->x0), GetDECStr(fd->y0), fd->xoff, fd->yoff, fd->sno); } send_line(buf); return 0; }
/* * Process formated input containing registry data adding keys to the * registry */ static void input_process(void) { /* Read and add keys */ char *name; char type[100]; unsigned char *data; int namelen, datalen; int nameidx, typeidx, dataidx = 0; enum {SNAME = 1000, STYPE, REG_BINARY2, REG_SZ_BACK, REG_SZ_HEX, REG_SZ_HEX2} state; int c; DWORD typeval; int hexcount; name = malloc(namelen = 32); data = malloc(datalen = 32); state = SNAME; nameidx = 0; line = 1; while ((c = getchar()) != EOF) { if (dataidx >= datalen) data = realloc(data, datalen *= 2); switch (state) { case SNAME: if (nameidx >= namelen) name = realloc(name, namelen *= 2); if (c == field_sep) { name[nameidx++] = '\0'; state = STYPE; typeidx = 0; } else if (c == '\n') { fprintf(stderr, "Missing type in line %d\n", line); exit(1); } else name[nameidx++] = c; break; case STYPE: if (c == field_sep) { type[typeidx++] = '\0'; dataidx = 0; if (!nameval(types, sizeof(types) / sizeof(struct s_nameval), type, &typeval)) { fprintf(stderr, "Line %d: Unrecognized type name\n", line); exit(1); } state = typeval; } else if (c == '\n') { fprintf(stderr, "Line %d: missing data\n", line); exit(1); } else type[typeidx++] = c; break; case REG_BINARY: case REG_DWORD: case REG_QWORD: case REG_LINK: case REG_RESOURCE_LIST: case REG_FULL_RESOURCE_DESCRIPTOR: case REG_RESOURCE_REQUIREMENTS_LIST: if (c == '\n') { switch (typeval) { case REG_DWORD: if (dataidx != 4) { fprintf(stderr, "Line :%d: not a four byte DWORD\n", line); exit(1); } swapbytes(data, dataidx); break; case REG_DWORD_BIG_ENDIAN: if (dataidx != 4) { fprintf(stderr, "Line :%d: not a four byte REG_DWORD_BIG_ENDIAN\n", line); exit(1); } break; case REG_QWORD: if (dataidx != 8) { fprintf(stderr, "Line :%d: not an eight byte QWORD\n", line); exit(1); } swapbytes(data, dataidx); break; } addkey: addkey(name, typeval, data, dataidx); nameidx = 0; state = SNAME; line++; break; } else if (isspace(c)) break; data[dataidx] = hexval((unsigned char)c) << 4; state = REG_BINARY2; break; case REG_BINARY2: data[dataidx++] |= hexval((unsigned char)c); state = REG_BINARY; break; case REG_SZ: case REG_MULTI_SZ: case REG_EXPAND_SZ: if (c == '\n') { data[dataidx] = '\0'; goto addkey; } else if (c == '\\') state = REG_SZ_BACK; else data[dataidx++] = c; break; case REG_SZ_BACK: switch (c) { case '\\': data[dataidx++] = '\\'; break; case 'a': data[dataidx++] = '\a'; break; case 'b': data[dataidx++] = '\b'; break; case 'f': data[dataidx++] = '\f'; break; case 't': data[dataidx++] = '\t'; break; case 'r': data[dataidx++] = '\r'; break; case 'n': data[dataidx++] = '\n'; break; case 'v': data[dataidx++] = '\v'; break; case '0': data[dataidx++] = '\0'; break; case 'x': state = REG_SZ_HEX; hexcount = 0; break; } state = REG_SZ; break; case REG_SZ_HEX: data[dataidx] = hexval((unsigned char)c) << 4; state = REG_SZ_HEX2; break; case REG_SZ_HEX2: data[dataidx++] |= hexval((unsigned char)c); state = REG_SZ; break; case REG_NONE: if (c == '\n') goto addkey; else { fprintf(stderr, "Line %d: Unexpected data\n", line); exit(1); } default: assert(0); } } }
unsigned Urm__SwapValidation (unsigned validation) { swapbytes(validation); return validation; }
/* Autor: RD */ void memWriteWord(i8086core *core, i808616BitAdr adr, unsigned short val, int reg) //schreibt ein Word an Adresse adr in den Speicher { doSegmentOverride(core,reg); core->mem[i8086GetSegRegister_fast(core,reg,1)+adr]=val; core->mem[i8086GetSegRegister_fast(core,reg,1)+adr+1]=swapbytes(val); }
Cardinal Idb__BM_SwapRecordBytes (IDBRecordBufferPtr buffer) { /* * Local variables */ Cardinal ndx; /* loop index */ IDBDummyRecordPtr idb_record; /* pointer to the generic IDB record */ IDBRecordHeaderPtr idb_header; /* pointer to hdr w/type and record # */ IDBHeaderRecordPtr header_rec; /* pointer to record type IDBrtHeader */ IDBHeaderHdrPtr header_hdr; /* pointer to the header in the header */ IDBIndexLeafRecordPtr leaf_rec; /* pointer to record type IDBrtIndexLeaf */ IDBIndexNodeRecordPtr node_rec; /* pointer to record type IDBrtIndexNode */ IDBridMapRecordPtr ridmap_rec; /* pointer to record type IDBrtRIDMap */ IDBDataRecordPtr data_rec; /* pointer to record type IDBrtData */ char err_msg[300] ; if ( ! Idb__BM_Valid(buffer) ) return Urm__UT_Error("Idb__BM_MarkActivity", _MrmMMsg_0002, NULL, NULL, MrmNOT_VALID) ; /* load pointers to the record and record header */ idb_record = (IDBDummyRecordPtr) buffer->IDB_record ; idb_header = (IDBRecordHeaderPtr)&idb_record->header ; /* swap the remaining record entries in IDBRecordHeader */ swapbytes( idb_header->record_type ) ; swapbytes( idb_header->record_num ) ; /* * Swap IDB record items based on record type */ switch ( idb_header->record_type ) { case IDBrtHeader: header_rec = (IDBHeaderRecordPtr)buffer->IDB_record ; header_hdr = (IDBHeaderHdrPtr)&header_rec->header_hdr ; /* swap the HeaderHdr first */ swapbytes( header_hdr->index_root ); swapbytes( header_hdr->num_indexed ); swapbytes( header_hdr->num_RID ); /* VAR check */ #ifdef WORD64 swap4bytes( header_hdr->next_RID.internal_id.map_rec ); swap4bytes( header_hdr->next_RID.internal_id.res_index ); #else swap2bytes( header_hdr->next_RID.internal_id.map_rec ); swap2bytes( header_hdr->next_RID.internal_id.res_index ); #endif swapbytes( header_hdr->last_record ); swapbytes( header_hdr->last_data_record ); for( ndx=0 ; ndx < URMgVecSize ; ndx++) swapbytes(header_hdr->group_counts[ndx]); for( ndx=0 ; ndx < IDBrtVecSize ; ndx++) swapbytes(header_hdr->rt_counts[ndx]); /* now swap the rest of the header */ /* VAR check */ for( ndx=0 ; ndx < IDBHeaderRIDMax ; ndx++) { swap2bytes(header_rec->RID_pointers[ndx].internal_id.rec_no); swap2bytes(header_rec->RID_pointers[ndx].internal_id.item_offs); } swapbytes( header_rec->num_entry ); swapbytes( header_rec->last_entry ); swapbytes( header_rec->free_ptr ); swapbytes( header_rec->free_count ); break; case IDBrtIndexLeaf: leaf_rec = (IDBIndexLeafRecordPtr)buffer->IDB_record ; swapbytes( leaf_rec->leaf_header.parent ); swapbytes( leaf_rec->leaf_header.index_count ); swapbytes( leaf_rec->leaf_header.heap_start ); swapbytes( leaf_rec->leaf_header.free_bytes ); for( ndx=0 ; ndx < leaf_rec->leaf_header.index_count ; ndx++ ) { swapbytes( leaf_rec->index[ndx].index_stg ); swap2bytes( leaf_rec->index[ndx].data.internal_id.rec_no ); swap2bytes( leaf_rec->index[ndx].data.internal_id.item_offs ); } break; case IDBrtIndexNode: node_rec = (IDBIndexNodeRecordPtr)buffer->IDB_record ; swapbytes( node_rec->node_header.parent ); swapbytes( node_rec->node_header.index_count ); swapbytes( node_rec->node_header.heap_start ); swapbytes( node_rec->node_header.free_bytes ); for( ndx=0 ; ndx < node_rec->node_header.index_count ; ndx++ ) { swapbytes( node_rec->index[ndx].index_stg ); swap2bytes( node_rec->index[ndx].data.internal_id.rec_no ); swap2bytes( node_rec->index[ndx].data.internal_id.item_offs ); swapbytes( node_rec->index[ndx].LT_record ); swapbytes( node_rec->index[ndx].GT_record ); } break; case IDBrtRIDMap: ridmap_rec = (IDBridMapRecordPtr)buffer->IDB_record ; ndx = 0; while ( (ndx < IDBridPtrVecMax) && (ridmap_rec->pointers[ndx].internal_id.rec_no != 0) ) { swap2bytes( ridmap_rec->pointers[ndx].internal_id.rec_no ); swap2bytes( ridmap_rec->pointers[ndx].internal_id.item_offs ); ndx++; } break; case IDBrtData: data_rec = (IDBDataRecordPtr)buffer->IDB_record ; swapbytes( data_rec->data_header.num_entry ); swapbytes( data_rec->data_header.last_entry ); swapbytes( data_rec->data_header.free_ptr ); swapbytes( data_rec->data_header.free_count ); break; default: sprintf(err_msg, _MrmMMsg_0020, idb_header->record_num, idb_header->record_type); return Urm__UT_Error ("Idb__BM_SwapRecordBytes", err_msg, NULL, NULL, MrmFAILURE) ; } return MrmSUCCESS ; }
void _GR_swap16(GR_int16 *w) { GRX_ENTER(); swapbytes((GR_int8 *)w, ((GR_int8 *)w)+1); GRX_LEAVE(); }
void _GR_swap32(GR_int32 *l) { GRX_ENTER(); swapbytes(((GR_int8 *)l) , ((GR_int8 *)l)+3); swapbytes(((GR_int8 *)l)+1, ((GR_int8 *)l)+2); GRX_LEAVE(); }
int convert(char *from, char *todir) { char to[80]; char fromdir[80]; char fromdosname[14]; char fromname[14]; int doad; char sec[256]; int i,o; byte flags,reclen; word secs; struct xmodemtype { char tifiles[8]; word secsused; byte flags; byte recspersec; byte eof; byte reclen; word fixrecs; byte unused[127-14+1]; } xmod; struct fdrstruc fdr; if (!fiadordoad(from,&doad,fromdir,fromdosname)) { printf("%s is an invalid filename.\n",from); return 1; } if (doad) { printf("It doesn't make sense to convert files from a disk image, since these\n" "are already in V9t9 format.\n"); exit(1); } i=open(from,O_RDONLY|O_BINARY); if (i==-1) { printf("Couldn't open %s!\n",from); return 1; } if (read(i,&xmod,128)!=128) { close(i); printf("%s: invalid TIFILES file (too short)\n",from); return 1; } if (memcmp(xmod.tifiles+1,"TIFILES",7)) { if (!assume) { printf("%s doesn't appear to be a TIFILES file.\n" "Assume DIS/FIX 128 format (y/n)?\n"); if (!getyesorno()) { close(i); return 1; } } xmod.secsused=swapbytes(filelength(i)/256); xmod.flags=0; xmod.eof=filelength(i)%256; xmod.reclen=80; xmod.fixrecs=swapbytes(xmod.secsused*2-(xmod.eof ? 1 : 0)); } dos2ti(fromdosname,fromname); strcpy(to,todir); strcat(to,fromname); if (verbose) printf("Converting %s to %s...\n",from,to); if (tiexists(to)) { if (verify) { printf("%s already exists. Overwrite (y/n)? \n",to); if (!getyesorno()) return 1; } } if (!createti(to,fdr.flags,fdr.reclen,&o)) { printf("Couldn't create %s!\n",to); return 1; } memset(&fdr,0,128); memcpy(fdr.name,fromname,10); fdr.flags=xmod.flags; fdr.recspersec=xmod.recspersec; /* if (xmod.reclen!=0) fdr.recspersec=256/xmod.reclen; else fdr.recspersec=0;*/ fdr.secsused=xmod.secsused; fdr.eof=xmod.eof; fdr.reclen=xmod.reclen; fdr.fixrecs=swapbytes(xmod.fixrecs); memcpy(&tifiles[o].fdr,&fdr,128); tifiles[o].fdr.secsused=0; secs=swapbytes(fdr.secsused); while (secs) { if (read(i,sec,256)!=256) { printf("Read error on %s!\n",from); return 1; } if (!writenewtiblock(o,sec)) { printf("%s: device probably full\n",todir); close(i); closeti(o); deleteti(to); return retry; } secs--; } closeti(o); close(i); return 1; }
int make_labl(int fd) { printf("making LABL...\n"); memset((char *)buffer, 0, sizeof(buffer)); /* * try to look like a Trident T-300 */ cyls = 815; heads = 19; blocks_per_track = 17; buffer[0] = str4("LABL"); /* label LABL */ buffer[1] = 1; /* version = 1 */ buffer[2] = cyls; /* # cyls */ buffer[3] = heads; /* # heads */ buffer[4] = blocks_per_track; /* # blocks */ buffer[5] = heads*blocks_per_track; /* heads*blocks */ buffer[6] = str4("MCR1"); /* name of micr part */ buffer[7] = str4("LOD1"); /* name of load part */ if (use_lod2) { buffer[7] = str4("LOD2"); /* name of load part */ } { int i, count; int p = 0200; count = 0; for (i = 0; parts[i].name; i++) count++; printf("%d partitions\n", i); buffer[p++] = count; /* # of partitions */ buffer[p++] = 7; /* words / partition */ for (i = 0; i < count; i++) { unsigned long n; char *pn = parts[i].name; printf("%s, start %o, size %o\n", pn, parts[i].start, parts[i].size); n = str4(pn); buffer[p++] = n; buffer[p++] = parts[i].start; buffer[p++] = parts[i].size; buffer[p++] = str4(" "); buffer[p++] = str4(" "); buffer[p++] = str4(" "); buffer[p++] = str4(" "); } } //#define LABEL_PAD_CHAR '\200' #define LABEL_PAD_CHAR '\0' /* pack brand text - offset 010, 32 bytes */ memset((char *)&buffer[010], LABEL_PAD_CHAR, 32); /* pack text label - offset 020, 32 bytes */ memset((char *)&buffer[020], ' ', 32); memcpy((char *)&buffer[020], "CADR diskmaker image", 21); /* comment - offset 030, 32 bytes */ memset((char *)&buffer[030], LABEL_PAD_CHAR, 32); strcpy((char *)&buffer[030], mcr_filename); printf("comment: '%s'\n", mcr_filename); #ifdef NEED_SWAP swapbytes(buffer); #endif write(fd, buffer, 256*4); }
Cardinal Idb__BM_GetRecord (IDBFile file_id, IDBRecordNumber record, IDBRecordBufferPtr *buffer_return) { /* * Local variables */ Cardinal result ; /* function results */ int ndx ; /* loop index */ IDBRecordBufferPtr curbuf ; /* current buffer being examined */ unsigned char *buf_src; /* tmp pointer to location in uid buffer */ /* * If buffer pool is unallocated, get a buffer (which WILL allocate it), * and read the record into that. Else see if the record is already in * memory, and return it if so. If the record is not found, get a buffer * to read it into. We exit this if statement with a buffer ready for * the read operation. */ if ( idb__buffer_pool_vec == NULL ) { result = Idb__BM_GetBuffer (file_id, buffer_return) ; if ( result != MrmSUCCESS ) return result ; } else { for ( ndx=0,curbuf=idb__buffer_pool_vec ; ndx<idb__buffer_pool_size ; ndx++,curbuf++ ) { if ( (curbuf->cur_file==file_id) && (curbuf->IDB_record->header.record_num==record) ) { *buffer_return = curbuf ; Idb__BM_MarkActivity (*buffer_return) ; return MrmSUCCESS ; } } result = Idb__BM_GetBuffer (file_id, buffer_return) ; if ( result != MrmSUCCESS ) return result ; } /* * Read the record into the buffer. */ if ( file_id->in_memory ) { buf_src = file_id->uid_buffer + (record-1)*IDBRecordSize; UrmBCopy(buf_src, (*buffer_return)->IDB_record, IDBRecordSize); result = MrmSUCCESS; } else result = Idb__FU_GetBlock(file_id->lowlevel_id, record, (char*)(*buffer_return)->IDB_record) ; if ( result != MrmSUCCESS ) return Urm__UT_Error ("Idb__BM_GetRecord", _MrmMMsg_0003, file_id, NULL, result) ; file_id->get_count++ ; /* * Validate the record, this is the first routine that is called to read * from a newly opened file. If the byte order is different, we find it * here. */ if ( (*buffer_return)->IDB_record->header.validation != IDBRecordHeaderValid ) { swapbytes( (*buffer_return)->IDB_record->header.validation ); if ((*buffer_return)->IDB_record->header.validation == IDBRecordHeaderValid) { /* must be a file needing byte swapping */ file_id->byte_swapped = TRUE; Idb__BM_SwapRecordBytes (*buffer_return); Idb__BM_MarkActivity (*buffer_return); return MrmSUCCESS ; } /* byte swapping has done no good, return error */ return Urm__UT_Error("Idb__BM_GetRecord", _MrmMMsg_0005, file_id, NULL, MrmNOT_VALID) ; } /* * Record successfully read */ Idb__BM_MarkActivity (*buffer_return) ; return MrmSUCCESS ; }
/* Finish current check-image. */ void reendcheck(picstruct *field, checkstruct *check) { char *buf; size_t padsize; padsize = 0; /* To avoid gcc -Wall warnings */ switch(check->type) { case CHECK_MINIBACKGROUND: case CHECK_MINIBACKRMS: return; case CHECK_IDENTICAL: case CHECK_BACKGROUND: case CHECK_BACKRMS: case CHECK_FILTERED: case CHECK_SUBTRACTED: free(check->pix); free(check->line); check->line = NULL; padsize = (FBSIZE -((check->npix*sizeof(PIXTYPE))%FBSIZE)) % FBSIZE; break; case CHECK_OBJECTS: case CHECK_APERTURES: case CHECK_SUBPSFPROTOS: case CHECK_PSFPROTOS: case CHECK_SUBPCPROTOS: case CHECK_PCPROTOS: case CHECK_PCOPROTOS: case CHECK_SUBPROFILES: case CHECK_PROFILES: case CHECK_ASSOC: case CHECK_PATTERNS: if (bswapflag) swapbytes(check->pix, sizeof(PIXTYPE), (int)check->npix); QFWRITE(check->pix,check->npix*sizeof(PIXTYPE), check->file,check->filename); free(check->pix); padsize = (FBSIZE-((check->npix*sizeof(PIXTYPE))%FBSIZE)) % FBSIZE; break; case CHECK_SEGMENTATION: if (bswapflag) swapbytes(check->pix, sizeof(ULONG), (int)check->npix); QFWRITE(check->pix,check->npix*sizeof(ULONG), check->file,check->filename); free(check->pix); padsize = (FBSIZE -((check->npix*sizeof(ULONG))%FBSIZE)) % FBSIZE; break; case CHECK_SUBOBJECTS: { int y; for (y=field->ymin; y<field->ymax; y++) writecheck(check, &PIX(field, 0, y), field->width); free(check->pix); free(check->line); check->line = NULL; padsize = (FBSIZE -((check->npix*sizeof(PIXTYPE))%FBSIZE)) % FBSIZE; break; } case CHECK_MAPSOM: if (bswapflag) swapbytes(check->pix, sizeof(PIXTYPE), (int)check->npix); QFWRITE(check->pix,check->npix*sizeof(PIXTYPE), check->file,check->filename); free(check->pix); padsize = (FBSIZE -((check->npix*sizeof(USHORT))%FBSIZE)) % FBSIZE; break; default: error(EXIT_FAILURE, "*Internal Error* in ", "endcheck()!"); } QCALLOC(buf, char, FBSIZE); if (padsize) QFWRITE (buf, padsize, check->file, check->filename); free(buf); return; }
/****** save_tab ************************************************************** PROTO void save_tab(catstruct *cat, tabstruct *tab) PURPOSE Save a FITS table. INPUT pointer to the catalog structure, pointer to the table structure. OUTPUT -. NOTES -. AUTHOR E. Bertin (IAP & Leiden observatory) VERSION 09/09/2003 ***/ void save_tab(catstruct *cat, tabstruct *tab) { catstruct *tabcat; keystruct *key; tabstruct *keytab; KINGSIZE_T tabsize; KINGLONG size; int b,j,k,o, nbytes,nkey,nobj,spoonful, tabflag, larrayin,larrayout; char *buf, *inbuf, *outbuf, *fptr,*ptr; int esize; /* Make the table parameters reflect its content*/ update_tab(tab); /* The header itself*/ tabflag = save_head(cat, tab)==RETURN_OK?1:0; /* Allocate memory for the output buffer */ tabsize = 0; tabcat = NULL; /* to satisfy gcc -Wall */ inbuf = NULL; /* to satisfy gcc -Wall */ if (tabflag) { /*-- If segment is a binary table, save it row by row */ QMALLOC(outbuf, char, (larrayout = tab->naxisn[0])); nkey = tab->nkey; tabsize = larrayin = 0; for (j=tab->nseg; j--;) { update_tab(tab); /*---- Scan keys to find the reference tab and other things*/ keytab = NULL; key = tab->key; for (k=nkey; k--; key = key->nextkey) if (!key->ptr) { keytab = key->tab; tabcat = keytab->cat; } /*---- If table contains some keys with no ptrs, we have to access a file */ if (keytab) { QMALLOC(inbuf, char, (larrayin = keytab->naxisn[0])); if (open_cat(tabcat, READ_ONLY) != RETURN_OK) error(EXIT_FAILURE, "*Error*: Cannot access ", tabcat->filename); QFSEEK(tabcat->file, keytab->bodypos, SEEK_SET, tabcat->filename); } nobj = tab->naxisn[1]; for (o=0; o<nobj; o++) { if (keytab) QFREAD(inbuf, larrayin, tabcat->file, tabcat->filename); fptr = outbuf; for (k=nkey; k--; key = key->nextkey) { nbytes = key->nbytes; ptr = key->ptr? (char *)key->ptr+nbytes*o:inbuf+key->pos; for (b=nbytes; b--;) *(fptr++) = *(ptr++); if (bswapflag) if (key->ptr) { esize = t_size[key->ttype]; swapbytes(fptr-nbytes, esize, nbytes/esize); } } QFWRITE(outbuf, larrayout, cat->file, cat->filename); } if (keytab) { free(inbuf); if (close_cat(tabcat) != RETURN_OK) error(EXIT_FAILURE, "*Error*: Problem while closing", tabcat->filename); } tabsize += tab->tabsize; tab = tab->nexttab; } free(outbuf); } else {
static void dd_in(void) { ssize_t n; for (;;) { if (cpy_cnt && (st.in_full + st.in_part) >= cpy_cnt) return; /* * Zero the buffer first if sync; if doing block operations * use spaces. */ if (ddflags & C_SYNC) { if (ddflags & (C_BLOCK|C_UNBLOCK)) (void)memset(in.dbp, ' ', in.dbsz); else (void)memset(in.dbp, 0, in.dbsz); } n = read(in.fd, in.dbp, in.dbsz); if (n == 0) { in.dbrcnt = 0; return; } /* Read error. */ if (n < 0) { /* * If noerror not specified, die. POSIX requires that * the warning message be followed by an I/O display. */ if (!(ddflags & C_NOERROR)) err(1, "%s", in.name); warn("%s", in.name); summary(); /* * If it's not a tape drive or a pipe, seek past the * error. If your OS doesn't do the right thing for * raw disks this section should be modified to re-read * in sector size chunks. */ if (!(in.flags & (ISPIPE|ISTAPE)) && lseek(in.fd, (off_t)in.dbsz, SEEK_CUR)) warn("%s", in.name); /* If sync not specified, omit block and continue. */ if (!(ddflags & C_SYNC)) continue; /* Read errors count as full blocks. */ in.dbcnt += in.dbrcnt = in.dbsz; ++st.in_full; /* Handle full input blocks. */ } else if (n == in.dbsz) { in.dbcnt += in.dbrcnt = n; ++st.in_full; /* Handle partial input blocks. */ } else { /* If sync, use the entire block. */ if (ddflags & C_SYNC) in.dbcnt += in.dbrcnt = in.dbsz; else in.dbcnt += in.dbrcnt = n; ++st.in_part; } /* * POSIX states that if bs is set and no other conversions * than noerror, notrunc or sync are specified, the block * is output without buffering as it is read. */ if (ddflags & C_BS) { out.dbcnt = in.dbcnt; dd_out(1); in.dbcnt = 0; continue; } if (ddflags & C_SWAB) { if ((n = in.dbrcnt) & 1) { ++st.swab; --n; } swapbytes(in.dbp, n); } in.dbp += in.dbrcnt; (*cfunc)(); } }
Cardinal Urm__SwapRGMWidgetRecord(RGMWidgetRecordPtr widget_rec) { /* * Local variables */ RGMArgListDescPtr arg_list; /* pointer to widget arglist */ RGMChildrenDescPtr child_list; /* pointer to the widgets children */ RGMResourceDescPtr res_desc; /* resource description literal */ RGMCallbackDescPtr callb_desc; /* pointer to a callback decriptor */ Cardinal ndx; /* loop index */ IDBridDesc *idb_rid_ptr; void *offset; /* generic offset pointer */ char err_msg[300]; /* Swap the main part of the widget record */ swapbytes( widget_rec->size ); swapbytes( widget_rec->access ); swapbytes( widget_rec->lock ); swapbytes( widget_rec->type ); swapbytes( widget_rec->name_offs ); swapbytes( widget_rec->class_offs ); swapbytes( widget_rec->arglist_offs ); swapbytes( widget_rec->children_offs ); swapbytes( widget_rec->comment_offs ); swapbytes( widget_rec->creation_offs ); swapbytes( widget_rec->variety ); swapbytes( widget_rec->annex ); /* handle the argument list */ if (widget_rec->arglist_offs > 0) { arg_list = (RGMArgListDesc *) ((char *)widget_rec + widget_rec->arglist_offs); swapbytes( arg_list->count ); swapbytes( arg_list->extra ); for ( ndx=0 ; ndx<arg_list->count ; ndx++ ) { swapbytes( arg_list->args[ndx].tag_code ); swapbytes( arg_list->args[ndx].stg_or_relcode.tag_offs ); swapbytes( arg_list->args[ndx].arg_val.rep_type ); switch( arg_list->args[ndx].arg_val.rep_type ) { case MrmRtypeInteger: case MrmRtypeBoolean: swapbytes( arg_list->args[ndx].arg_val.datum.ival ); break; case MrmRtypeSingleFloat: swapbytes( arg_list->args[ndx].arg_val.datum.ival ); _MrmOSIEEEFloatToHost((float *) &(arg_list->args[ndx].arg_val.datum.ival)); default: swapbytes( arg_list->args[ndx].arg_val.datum.offset ); break; } offset = ((char *)widget_rec+ arg_list->args[ndx].arg_val.datum.offset); switch( arg_list->args[ndx].arg_val.rep_type ) { /* these are immediate, do nothing special */ case MrmRtypeInteger: case MrmRtypeBoolean: case MrmRtypeSingleFloat: break; /* these are offsets into the file, handle them specially */ case MrmRtypeCallback: callb_desc = (RGMCallbackDesc * )offset; Urm__SwapRGMCallbackDesc( callb_desc, widget_rec ); break; case MrmRtypeResource: res_desc = (RGMResourceDesc *)offset; Urm__SwapRGMResourceDesc( res_desc ); /* flag this resource as needing further byte swapping */ res_desc->cvt_type |= MrmResourceUnswapped; break; case MrmRtypeHorizontalInteger: case MrmRtypeVerticalInteger: case MrmRtypeHorizontalFloat: case MrmRtypeVerticalFloat: case MrmRtypeChar8: case MrmRtypeChar8Vector: case MrmRtypeCString: case MrmRtypeCStringVector: case MrmRtypeFloat: case MrmRtypePixmapImage: case MrmRtypePixmapDDIF: case MrmRtypeNull: case MrmRtypeAddrName: case MrmRtypeIconImage: case MrmRtypeFont: case MrmRtypeFontList: case MrmRtypeColor: case MrmRtypeColorTable: case MrmRtypeAny: case MrmRtypeTransTable: case MrmRtypeClassRecName: case MrmRtypeIntegerVector: case MrmRtypeXBitmapFile: case MrmRtypeCountedVector: case MrmRtypeKeysym: case MrmRtypeWideCharacter: case MrmRtypeFontSet: sprintf(err_msg,_MrmMMsg_0022, arg_list->args[ndx].arg_val.rep_type); return Urm__UT_Error ("Urm__SwapRGMWidgetRecord", err_msg, NULL, NULL, MrmFAILURE) ; break; } } } /* handle the child list */ if (widget_rec->children_offs > 0) { child_list = (RGMChildrenDesc *) ((char *)widget_rec + widget_rec->children_offs); swapbytes( child_list->count ); swapbytes( child_list->unused1 ); swapbytes( child_list->annex1 ); for ( ndx=0 ; ndx<child_list->count ; ndx++ ) { swapbytes( child_list->child[ndx].annex1 ); if (child_list->child[ndx].type == URMrRID ) { idb_rid_ptr = (IDBridDesc *)&(child_list->child[ndx].key.id); #ifdef WORD64 swap4bytes( idb_rid_ptr->internal_id.map_rec ); swap4bytes( idb_rid_ptr->internal_id.res_index ); #else swap2bytes( idb_rid_ptr->internal_id.map_rec ); swap2bytes( idb_rid_ptr->internal_id.res_index ); #endif } else swapbytes( child_list->child[ndx].key.index_offs ); } } /* handle the creation callback, if any */ if (widget_rec->creation_offs > 0) { callb_desc = (RGMCallbackDesc * ) ((char *)widget_rec + widget_rec->creation_offs); Urm__SwapRGMCallbackDesc( callb_desc, widget_rec ); } return MrmSUCCESS ; }
int scan(char *filename) { struct tifile *ff; int handle; longint fdrtotalbytes; longint totalbytes; longint databytes; struct fdrstruc *fdr; char name[14]; word oldsize; struct ftime ftime; byte type,len; SAY printf("Scanning file %s\n",filename); if (!openti(filename,&handle)) { tierror(filename); return 0; } ff=&tifiles[handle]; getftime(ff->doshandle,&ftime); // Check FDR structure. fdr=&ff->fdr; type=fdr->flags; len=fdr->reclen; if (!validatename(fdr->name)) { if (fix) { getname(fdr->name,name); memcpy(fdr->name,name+2,10); } } if (!(type&F_PROGRAM) && len==0) { printf("Invalid record length (0)\n"); if (fix) { if (fdr->recspersec==1) len=255; // good guess for xxx/FIX else if (fdr->recspersec>1) len=256/fdr->recspersec; // very approx else len=80; // pure guess // For fixed files, we can tell what the record size is: // * EOF offset is exact multiple // * (256*secsused-EOF)/fixrecs is almost it if (!(type&F_VARIABLE) && fdr->fixrecs) { len=(256L*(swapbytes(fdr->secsused)+1)-fdr->eof) / fdr->fixrecs; if (fdr->eof) while (len%fdr->eof) len--; } if (!len) len=80; printf("\tAssume %d bytes?\n",len); if (getyesorno()) fdr->reclen=len; } } fdrtotalbytes=tigetfilesize(handle); totalbytes=tigetrealfilesize(handle); if ((fdrtotalbytes+255)/256!=totalbytes/256) { printf("File size mismatch in %s\n",filename); printf("TI Emulator! v5.0- probably made this error.\n"); if (fix) { if ((type&F_VARIABLE) && !(type&F_PROGRAM)) // xxx/VAR { fdr->fixrecs=totalbytes/256; fdr->secsused=swapbytes(fdr->fixrecs); } else if (type&F_PROGRAM) // program { // On a program file, most likely the FDR is // correct while the filesize is wrong. Sheesh! // if (fdrtotalbytes<totalbytes) if (!ff->doad) trunc(handle,swapbytes(fdr->secsused)); else ; else { fdr->secsused=swapbytes(totalbytes/256); fdr->eof=totalbytes&255; } } else if (!(type&F_VARIABLE)) // xxx/FIX { // reclen is assumed to be legal from above // oldsize=fdr->secsused; fdr->secsused=swapbytes( (fdr->fixrecs+fdr->recspersec-1)/fdr->recspersec); if (oldsize==fdr->secsused && !ff->doad) trunc(handle,swapbytes(oldsize)); } } } if (fix) { // printf("Fixing...\n"); if (!writetifdr(handle)) printf("Error! Couldn't write header!\n"); else setftime(ff->doshandle,&ftime); } closeti(handle); return 1; }
/* siehe PDFs für genauere Beschreibung */ i808616BitAdr decodeMemAdr(i8086core *core, char modrm, signed short disp) { char mod; char rm; i8086SingleRegister bx; i8086SingleRegister si; i8086SingleRegister di; i8086SingleRegister bp; i808616BitAdr adr; signed char disp8; unsigned short disp16; signed short offset; disp16=swapbytes(disp); disp8=(signed char) (disp >> 8);; mod=getBitSnipped(modrm,7,2); rm=getBitSnipped(modrm,2,3); i8086GetRegisterRef(&bx, core, 1, i8086_REG_BX); i8086GetRegisterRef(&si, core, 1, i8086_REG_SI); i8086GetRegisterRef(&di, core, 1, i8086_REG_DI); i8086GetRegisterRef(&bp, core, 1, i8086_REG_BP); if (mod==0 && rm==6) { adr=disp16; } else { switch (mod) { case 0: offset=0; break; case 1: offset=disp8; break; case 2: offset=disp16; break; } switch (rm) { case 0: adr= bx.x+si.x+offset; break; case 1: adr= bx.x+di.x+offset; break; case 2: adr= bp.x+si.x+offset; if (core->miscData.segoverride==-1) core->miscData.segoverride=i8086_REG_SS; break; case 3: adr= bp.x+di.x+offset; if (core->miscData.segoverride==-1) core->miscData.segoverride=i8086_REG_SS; break; case 4: adr= si.x+offset; break; case 5: adr= di.x+offset; break; case 6: adr= bp.x+offset; if (core->miscData.segoverride==-1) core->miscData.segoverride=i8086_REG_SS; break; case 7: adr= bx.x+offset; break; } } return adr; }