Ejemplo n.º 1
0
static void SwapTag(TAG* pTag)
{
	swapw((LPWORD)&pTag->tagno);
	swapw((LPWORD)&pTag->type);
	swapl((LPDWORD)&pTag->length);
	swapl((LPDWORD)&pTag->value);
}
Ejemplo n.º 2
0
static int ariadne_open(struct net_device *dev)
{
    volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
    u_short in;
    u_long version;
    int i;

    /* Reset the LANCE */
    in = lance->Reset;

    /* Stop the LANCE */
    lance->RAP = CSR0;		/* PCnet-ISA Controller Status */
    lance->RDP = STOP;

    /* Check the LANCE version */
    lance->RAP = CSR88;		/* Chip ID */
    version = swapw(lance->RDP);
    lance->RAP = CSR89;		/* Chip ID */
    version |= swapw(lance->RDP)<<16;
    if ((version & 0x00000fff) != 0x00000003) {
	printk("ariadne_open: Couldn't find AMD Ethernet Chip\n");
	return -EAGAIN;
    }
    if ((version & 0x0ffff000) != 0x00003000) {
	printk("ariadne_open: Couldn't find Am79C960 (Wrong part number = %ld)\n",
	       (version & 0x0ffff000)>>12);
	return -EAGAIN;
    }
Ejemplo n.º 3
0
static Errcode read_next_dirent(Tiff_file *tf, Dirent *entry)
/*****************************************************************************
 * load a directory entry (tag, count, type, offset) from the current ifd.
 ****************************************************************************/
{
	if (Success != fseek(tf->file, tf->off_ifd_cur, SEEK_SET))
		return pj_errno_errcode();

	if (1 != fread(entry, sizeof(*entry), 1, tf->file))
		return pj_errno_errcode();

	if (tf->swap_bytes)
		{
		swapw(&entry->tag);
		swapw(&entry->type);
		swapd(&entry->count);
		if (entry->type == TYPE_SHORT && entry->count <= 2)
			{
			swapw(&entry->value.word);
			if (entry->count == 2)
				swapw(((char *)(&entry->value.word))+2);
			}
		else
			swapd(&entry->value.dword);
		}

	return Success;
}
Ejemplo n.º 4
0
unsigned sys_display(struct FAB *fab)
{
    struct XABDAT *xab = fab->fab$l_xab;

    struct HEAD *head = ifi_table[fab->fab$w_ifi]->wcf_fcb->head;
    unsigned short *pp = (unsigned short *) head;
    struct IDENT *id = (struct IDENT *) (pp + head->fh2$b_idoffset);
    int ifi_no = fab->fab$w_ifi;
    if (ifi_no == 0 || ifi_no >= IFI_MAX) return RMS$_IFI;
    fab->fab$l_alq = swapw(head->fh2$w_recattr.fat$l_hiblk);
    fab->fab$b_bks = head->fh2$w_recattr.fat$b_bktsize;
    fab->fab$w_deq = head->fh2$w_recattr.fat$w_defext;
    fab->fab$b_fsz = head->fh2$w_recattr.fat$b_vfcsize;
    fab->fab$w_gbc = head->fh2$w_recattr.fat$w_gbc;
    fab->fab$w_mrs = head->fh2$w_recattr.fat$w_maxrec;
    fab->fab$b_org = head->fh2$w_recattr.fat$b_rtype & 0xf0;
    fab->fab$b_rfm = head->fh2$w_recattr.fat$b_rtype & 0x0f;
    fab->fab$b_rat = head->fh2$w_recattr.fat$b_rattrib;
    while (xab != NULL) {
        switch (xab->xab$b_cod) {
            case XAB$C_DAT:
                memcpy(&xab->xab$q_bdt,&id->fi2$q_bakdate,sizeof(struct TIME));
                memcpy(&xab->xab$q_cdt,&id->fi2$q_credate,sizeof(struct TIME));
                memcpy(&xab->xab$q_edt,&id->fi2$q_expdate,sizeof(struct TIME));
                memcpy(&xab->xab$q_rdt,&id->fi2$q_revdate,sizeof(struct TIME));
                xab->xab$w_rvn = id->fi2$w_revision;
                break;
            case XAB$C_FHC:{
                    struct XABFHC *fhc = (struct XABFHC *) xab;
                    fhc->xab$b_atr = head->fh2$w_recattr.fat$b_rattrib;
                    fhc->xab$b_bkz = head->fh2$w_recattr.fat$b_bktsize;
                    fhc->xab$w_dxq = head->fh2$w_recattr.fat$w_defext;
                    fhc->xab$l_ebk = swapw(head->fh2$w_recattr.fat$l_efblk);
                    fhc->xab$w_ffb = head->fh2$w_recattr.fat$w_ffbyte;
                    if (fhc->xab$l_ebk == 0) {
                        fhc->xab$l_ebk = fab->fab$l_alq;
                        if (fhc->xab$w_ffb == 0) fhc->xab$l_ebk++;
                    }
                    fhc->xab$w_gbc = head->fh2$w_recattr.fat$w_gbc;
                    fhc->xab$l_hbk = swapw(head->fh2$w_recattr.fat$l_hiblk);
                    fhc->xab$b_hsz = head->fh2$w_recattr.fat$b_vfcsize;
                    fhc->xab$w_lrl = head->fh2$w_recattr.fat$w_maxrec;
                    fhc->xab$w_verlimit = head->fh2$w_recattr.fat$w_versions;
                }
                break;
            case XAB$C_PRO:{
                    struct XABPRO *pro = (struct XABPRO *) xab;
                    pro->xab$w_pro = head->fh2$w_fileprot;
                    memcpy(&pro->xab$l_uic,&head->fh2$l_fileowner,4);
                }
        }
        xab = xab->xab$l_nxt;
    }

    return 1;
}
Ejemplo n.º 5
0
unsigned accessfile(struct VCB * vcb,struct fiddef * fid,struct FCB **fcbadd,
                    unsigned wrtflg)
{
    register struct FCB *fcb;
    unsigned create = sizeof(struct FCB);
    register unsigned fileno = (fid->fid$b_nmx << 16) + fid->fid$w_num;
#ifdef DEBUG
    printf("Accessing file (%d,%d,%d)\n",(fid->fid$b_nmx << 16) +
           fid->fid$w_num,fid->fid$w_seq,fid->fid$b_rvn);
#endif
    if (fileno < 1) return SS$_BADPARAM;
    if (wrtflg && ((vcb->status & VCB_WRITE) == 0)) return SS$_WRITLCK;
    if (fid->fid$b_rvn > 1) fileno |= ((fid->fid$b_rvn - 1) << 24);
    fcb = cachesearch((void *) &vcb->fcb,fileno,0,NULL,NULL,&create);
    if (fcb == NULL) return SS$_INSFMEM;
    /* If not found make one... */
    if (create == 0) {
        fcb->cache.status |= 0x100;     /* For debugging! */
        fcb->rvn = fid->fid$b_rvn;
        if (fcb->rvn == 0 && vcb->devices > 1) fcb->rvn = 1;
        fcb->vcb = vcb;
        fcb->wcb = NULL;
        fcb->headvioc = NULL;
        fcb->vioc = NULL;
        fcb->cache.objmanager = fcbmanager;
    }
    if (wrtflg) {
        if (fcb->headvioc != NULL && (fcb->cache.status & CACHE_WRITE) == 0) {
            deaccesshead(fcb->headvioc,NULL,0);
            fcb->headvioc = NULL;
        }
        fcb->cache.status |= CACHE_WRITE;
    }
    if (fcb->headvioc == NULL) {
        register unsigned sts;
        if (vcb->idxboot != NULL) {
            *fcbadd = fcb;
            fcb->hiblock = 32767;       /* guess at indexf.sys file size */
            fcb->highwater = 0;
            fcb->head = vcb->idxboot;   /* Load bootup header */
        }
        sts = accesshead(vcb,fid,&fcb->headvioc,&fcb->head,&fcb->modmask,wrtflg);
        if (sts & 1) {
            fcb->hiblock = swapw(fcb->head->fh2$w_recattr.fat$l_hiblk);
            if (fcb->head->fh2$b_idoffset > 39) {
                fcb->highwater = fcb->head->fh2$l_highwater;
            } else {
                fcb->highwater = 0;
            }
        } else {
            fcb->cache.objmanager = NULL;
            cacheuntouch(&fcb->cache,0,0);
            cachefree(&fcb->cache);
            return sts;
        }
    }
    *fcbadd = fcb;
    return SS$_NORMAL;
}
Ejemplo n.º 6
0
void		motReadWord (
LPFILEBUF	ifd,	/* control block */
WORD FAR	*w)
{
    if (FileRead (ifd, (LPTR) w, sizeof (WORD)) != sizeof (WORD))
	ifd->err = -1;
    swapw (w);
}
Ejemplo n.º 7
0
void		motWriteWord (
LPFILEBUF	ofd,	/* control block */
WORD		w)
{
    swapw (&w);
    if (FileWrite (ofd, (LPTR) &w, sizeof (WORD)) != sizeof (WORD))
	ofd->err = -1;
}
Ejemplo n.º 8
0
unsigned accesshead(struct VCB *vcb,struct fiddef *fid,
                    struct VIOC **vioc,struct HEAD **headbuff,
                    unsigned *modmask,unsigned wrtflg)
{
    register unsigned sts;
    register struct VCBDEV *vcbdev;
    register unsigned idxblk = fid->fid$w_num + (fid->fid$b_nmx << 16) - 1;
    if (fid->fid$b_rvn > vcb->devices) return SS$_NOSUCHFILE;
    if (fid->fid$b_rvn < 2) {
        vcbdev = vcb->vcbdev;
    } else {
        vcbdev = &vcb->vcbdev[fid->fid$b_rvn - 1];
    }
    if (vcbdev->dev == NULL) return SS$_NOSUCHFILE;
    if (wrtflg && ((vcb->status & VCB_WRITE) == 0)) return SS$_WRITLCK;
#ifdef DEBUG
    printf("Accessing header (%d,%d,%d)\n",(fid->fid$b_nmx << 16) +
           fid->fid$w_num,fid->fid$w_seq,fid->fid$b_rvn);
#endif
    idxblk += vcbdev->home.hm2$w_ibmapvbn + vcbdev->home.hm2$w_ibmapsize;
    if (idxblk >= swapw(vcbdev->idxfcb->head->fh2$w_recattr.fat$l_efblk)) return SS$_NOSUCHFILE;
    sts = accesschunk(vcbdev->idxfcb,idxblk,vioc,(char **) headbuff,
                      NULL,wrtflg ? 1 : 0,modmask);
    if (sts & 1) {
        register struct HEAD *head = *headbuff;
        if (checksum((u_word *) head) != head->fh2$w_checksum) {
#ifdef DEBUG
            printf("Accesshead checksum %d != %d\n",checksum((u_word *) head),head->fh2$w_checksum);
#endif
            sts = SS$_NOSUCHFILE;
        } else {
            if (head->fh2$w_fid.fid$w_num != fid->fid$w_num ||
                head->fh2$w_fid.fid$b_nmx != fid->fid$b_nmx ||
                head->fh2$w_fid.fid$w_seq != fid->fid$w_seq ||
                (head->fh2$w_fid.fid$b_rvn != fid->fid$b_rvn &&
                 head->fh2$w_fid.fid$b_rvn != 0)) {
#ifdef DEBUG
                printf("Accesshead fileid doesn't match %d %d %d\n",
                       fid->fid$w_num,fid->fid$w_seq,fid->fid$b_rvn);
#endif
                sts = SS$_NOSUCHFILE;
            } else {
                if (head->fh2$b_idoffset < 38 ||
                    head->fh2$b_idoffset > head->fh2$b_mpoffset ||
                    head->fh2$b_mpoffset > head->fh2$b_acoffset ||
                    head->fh2$b_acoffset > head->fh2$b_rsoffset ||
                    head->fh2$b_map_inuse > (head->fh2$b_acoffset - head->fh2$b_mpoffset)) {
#ifdef DEBUG
                    printf("Accesshead areas incorrect\n");
#endif
                    sts = SS$_NOSUCHFILE;
                }
            }
        }
        if ((sts & 1) == 0) deaccesschunk(*vioc,0,0);
    }
    return sts;
}
Ejemplo n.º 9
0
void SetNextWord(LPWORD *lplpWord, WORD w)
{
// Set the WORD and increment the pointer.
	**lplpWord = w;
#ifdef _MAC
	swapw(*lplpWord);
#endif
	(*lplpWord)++;	
}
Ejemplo n.º 10
0
static void ariadne_init_ring(struct net_device *dev)
{
	struct ariadne_private *priv = netdev_priv(dev);
	volatile struct lancedata *lancedata = (struct lancedata *)dev->mem_start;
	int i;

	netif_stop_queue(dev);

	priv->tx_full = 0;
	priv->cur_rx = priv->cur_tx = 0;
	priv->dirty_tx = 0;

	/* Set up TX Ring */
	for (i = 0; i < TX_RING_SIZE; i++) {
		volatile struct TDRE *t = &lancedata->tx_ring[i];
		t->TMD0 = swloww(ARIADNE_RAM +
				 offsetof(struct lancedata, tx_buff[i]));
		t->TMD1 = swhighw(ARIADNE_RAM +
				  offsetof(struct lancedata, tx_buff[i])) |
			TF_STP | TF_ENP;
		t->TMD2 = swapw((u_short)-PKT_BUF_SIZE);
		t->TMD3 = 0;
		priv->tx_ring[i] = &lancedata->tx_ring[i];
		priv->tx_buff[i] = lancedata->tx_buff[i];
		netdev_dbg(dev, "TX Entry %2d at %p, Buf at %p\n",
			   i, &lancedata->tx_ring[i], lancedata->tx_buff[i]);
	}

	/* Set up RX Ring */
	for (i = 0; i < RX_RING_SIZE; i++) {
		volatile struct RDRE *r = &lancedata->rx_ring[i];
		r->RMD0 = swloww(ARIADNE_RAM +
				 offsetof(struct lancedata, rx_buff[i]));
		r->RMD1 = swhighw(ARIADNE_RAM +
				  offsetof(struct lancedata, rx_buff[i])) |
			RF_OWN;
		r->RMD2 = swapw((u_short)-PKT_BUF_SIZE);
		r->RMD3 = 0x0000;
		priv->rx_ring[i] = &lancedata->rx_ring[i];
		priv->rx_buff[i] = lancedata->rx_buff[i];
		netdev_dbg(dev, "RX Entry %2d at %p, Buf at %p\n",
			   i, &lancedata->rx_ring[i], lancedata->rx_buff[i]);
	}
}
Ejemplo n.º 11
0
WORD GetNextWord(LPWORD *lplpWord)
{
// Get the next WORD and increment the pointer.
#ifdef _MAC
	swapw(*lplpWord);
#endif	
	WORD w = **lplpWord;
	(*lplpWord)++;
	return w;
}
Ejemplo n.º 12
0
/* evnt_emu() - evnt_multi() using an EMU structure.
 *-----------------------------------------------------------------------
 * The caller only need fill in those fields which apply to the events
 * awaited.  Caller needn't swap the words of the e_time field:
 * the binding swaps it on the way in and unswaps it on the way out.
 */
UWORD
evnt_emu(EMU *ep)
{
	void *ii = apb[2];
	void *io = apb[3];
	long t = ep->time;
	apb[2] = &ep->flags;
	apb[3] = &ep->events;
	addr_in[0] = &ep->msg;
	ep->time = swapw(t);
	aes(EVNT_MULTI);
	ep->time = t;
	apb[2] = ii;
	apb[3] = io;
	return ep->events;
}
Ejemplo n.º 13
0
void CreateNewLicense(PLICENSEINFO pLicenseInfo)
{
    int i;
    if (!pLicenseInfo) return;
    
//  pLicenseInfo->bLicenseCount = DEFAULT_LIC_COUNT;
//  pLicenseInfo->bApp = DEF_APP_COUNT;
	pLicenseInfo->bNull = 0;
    pLicenseInfo->bChecksum = 0;
    pLicenseInfo->wTickCount = (WORD)GetTickCount();
#ifdef _MAC
	swapw(&pLicenseInfo->wTickCount);
#endif	
    for (i = 0; i < sizeof(LICENSEINFO) - 1; i++)
        pLicenseInfo->bChecksum ^= ((LPBYTE)pLicenseInfo)[i];
}
Ejemplo n.º 14
0
unsigned sys_get(struct RAB *rab)
{
    char delim,*buffer,*output;
    unsigned cpylen,reclen,block,blocks,offset,eofblk;
    unsigned endflg,rfm,sts;
    struct VIOC *vioc;
    struct FCB *fcb = ifi_table[rab->rab$l_fab->fab$w_ifi]->wcf_fcb;

    rfm = rab->rab$l_fab->fab$b_rfm;
    if (rfm == FAB$C_STM || rfm == FAB$C_STMCR || rfm == FAB$C_STMLF) {
        delim = 1;
        if (rfm == FAB$C_STMLF) {
            delim = '\n';
        } else {
            if (rfm == FAB$C_STMCR) delim = '\r';
        }
        reclen = rab->rab$w_usz;
    } else {
        delim = 0;
        if (rfm == FAB$C_FIX) {
            reclen = rab->rab$l_fab->fab$w_mrs;
        }
    }

    offset = rab->rab$w_rfa[2] + rab->rab$w_rsz;
    block = (rab->rab$w_rfa[1] << 16) + rab->rab$w_rfa[0];
    if (block == 0 && offset == 0) {
        block = 1;
    } else {
        if (rab->rab$b_rac != RAB$C_RFA) {
            if (delim) {
                offset++;
            } else {
                if (rfm == FAB$C_VAR) {
                    offset += 2;
                } else {
                    if (rfm == FAB$C_VFC) offset += 2 + rab->rab$l_fab->fab$b_fsz;
                }
                if (offset & 1) offset++;
                if (rab->rab$l_fab->fab$b_rat & FAB$M_BLK) offset = (offset + 511) / 512 * 512;
            }
            block += offset / 512;
        }
    }
    rab->rab$w_rfa[0] = block & 0xffff;
    rab->rab$w_rfa[1] = block >> 16;
    rab->rab$w_rfa[2] = offset = offset % 512;


    eofblk = swapw(fcb->head->fh2$w_recattr.fat$l_efblk);
    if (block > eofblk || (block == eofblk &&
                           offset >= fcb->head->fh2$w_recattr.fat$w_ffbyte)) return RMS$_EOF;
    sts = accesschunk(fcb,block,&vioc,&buffer,&blocks,0,NULL);
    if ((sts & 1) == 0) return sts;

    if (rfm == FAB$C_VAR || rfm == FAB$C_VFC) {
        unsigned short *lenptr = (unsigned short *) (buffer + offset);
        reclen = *lenptr;
        offset += 2;
    }
#ifdef DEBUG
    printf("Block %d Offset %d Reclen %d Eofblk %d\n",block,offset,reclen,eofblk);
#endif

    if (reclen > rab->rab$w_usz) {
        sts = deaccesschunk(vioc,0,0);
        return RMS$_RTB;
    }
    endflg = 0;
    if (block + reclen / 512 >= eofblk) {
        unsigned remaining = (eofblk - block) * 512 - offset +
           fcb->head->fh2$w_recattr.fat$w_ffbyte;
        if (remaining < reclen) {
            reclen = remaining;
            endflg = 1;
        }
    }
    cpylen = 0;
    output = rab->rab$l_ubf;
    while (cpylen < reclen) {
        unsigned seglen = blocks * 512 - offset;
        if (seglen > reclen - cpylen) seglen = reclen - cpylen;
        if (delim) {
            char *inptr = buffer + offset;
            if (delim != 1) {
                while (seglen-- > 0) {
                    char ch = *inptr++;
                    if (ch == delim) {
                        reclen = cpylen;
                        break;
                    }
                    if (cpylen++ < reclen) {
                        *output++ = ch;
                    } else {
                        sts = RMS$_RTB;
                        reclen = cpylen;
                        break;
                    }
                }
            } else {
                while (seglen-- > 0) {
                    char ch = *inptr++;
                    if (ch != 0 || cpylen > 0) {
                        if (ch == '\f' || ch == '\v' || ch == '\n' || ch == '\r') {
                            reclen = cpylen;
                        } else {
                            if (cpylen++ < reclen) {
                                *output++ = ch;
                            } else {
                                sts = RMS$_RTB;
                                reclen = cpylen;
                                break;
                            }
                        }
                    }
                }
            }
            if (cpylen == reclen && endflg) break;
        } else {
            if (rfm == FAB$C_VFC) {
                unsigned fsz = rab->rab$l_fab->fab$b_fsz;
                if (fsz > seglen) fsz = seglen;
                if (cpylen < fsz) {
                    fsz = fsz - cpylen;
                    if (rab->rab$l_rhb) memcpy(rab->rab$l_rhb + cpylen,buffer + offset,fsz);
                    cpylen += fsz;
                    offset += fsz;
                    seglen -= fsz;
                }
            }
            memcpy(output,buffer + offset,seglen);
            output += seglen;
            cpylen += seglen;
        }
        if (cpylen < reclen) {
            sts = deaccesschunk(vioc,0,0);
            block += blocks;
            if (block > eofblk) return RMS$_EOF;
            sts = accesschunk(fcb,block,&vioc,&buffer,&blocks,0,NULL);
            if ((sts & 1) == 0) return sts;
            offset = 0;
        }
    }
    if (rfm == FAB$C_VFC) {
        rab->rab$w_rsz = cpylen - rab->rab$l_fab->fab$b_fsz;;
    } else {
        rab->rab$w_rsz = cpylen;
    }
    deaccesschunk(vioc,0,1);
    return sts;
}
Ejemplo n.º 15
0
LPCTHEADER ReadCTHeader(CFile *pTheFile, LPSTR lpFileName, BITMAP_ERROR_CODE *pErr)
   { 
   BOOL        fRet = FALSE;
   LPCTHEADER  lpTH;
   BYTE        Buff[15];
   BYTE        tmp;
   WORD        wtmp;

   *pErr = BEC_errNone;
   if (!(lpTH = (LPCTHEADER)Alloc((long)sizeof(CTHEADER))))
       {
	   *pErr = BEC_errMemory;
	   return(NULL);
	   }

   // Clear out all the header data
   clr( (LPTR)lpTH, sizeof(CTHEADER));

TRY
	{
	if (pTheFile->Read ((LPTR)&lpTH->FileName, 80) != 80) /* read FileName */
	   goto BadRead;
   lpTH->FileName[80] = 0;
	if (pTheFile->Read ((LPTR)&wtmp, 2) != 2) /* read File Type */
	   goto BadRead;
   if (wtmp != CT_TYPE)
	   goto BadRead;

  	pTheFile->Seek (1024, CFile::begin);
	if (pTheFile->Read ((LPTR)&tmp, 1) != 1) /* read Unit of measurement */
	   goto BadRead;
   lpTH->Units = tmp;
	if (pTheFile->Read ((LPTR)&tmp, 1) != 1) /* read Unit of measurement */
	   goto BadRead;
   lpTH->NumColSep = tmp;
	if (pTheFile->Read ((LPTR)&lpTH->ColSepMask, 2) != 2) /* read Unit of measurement */
	   goto BadRead;
	swapw (&lpTH->ColSepMask);
	if (pTheFile->Read ((LPTR)Buff, 14) != 14) /* read Unit of measurement */
	   goto BadRead;
   Buff[14] = 0;
   lpTH->Height = atof((const char *)Buff);
	if (pTheFile->Read ((LPTR)Buff, 14) != 14) /* read Unit of measurement */
	   goto BadRead;
   Buff[14] = 0;
   lpTH->Width = atof((const char *)Buff);
	if (pTheFile->Read ((LPTR)Buff, 12) != 12) /* read Unit of measurement */
	   goto BadRead;
   Buff[12] = 0;
   lpTH->Lines = atol((const char *)Buff);
	if (pTheFile->Read ((LPTR)Buff, 12) != 12) /* read Unit of measurement */
	   goto BadRead;
   Buff[12] = 0;
   lpTH->Pixels = atol((const char *)Buff);
	if (pTheFile->Read ((LPTR)&tmp, 1) != 1) /* read Unit of measurement */
	   goto BadRead;
   lpTH->Orientation = tmp;

   if (!(lpTH->ColSepMask & 0x000F))   // make sure at lease on of the CMYK
	   goto BadRead;                       // channel do exist
      
   if (lpTH->Units)   // inches
      lpTH->Resolution = (int)(lpTH->Pixels / lpTH->Width);
   else                 // mm
      lpTH->Resolution = (int)(lpTH->Pixels * 25.4 / lpTH->Width);
   if (lpTH->Pixels & 1) // odd pixels
      lpTH->ChannelSize = lpTH->Pixels + 1;
   else
      lpTH->ChannelSize = lpTH->Pixels;

   lpTH->LineSize = lpTH->ChannelSize * lpTH->NumColSep;

   if (lpTH->NumColSep > 4)
      lpTH->NumColSep = 4;

	if (!AllocLines( &lpTH->lpCTLine, 1, lpTH->LineSize, 1))
		{
		*pErr = BEC_errMemory;
		goto Exit;
		}

   fRet = TRUE;
	goto Exit;
	}
CATCH_ALL(e)
	{
	goto BadRead;
	}
END_CATCH_ALL
BadRead:
	*pErr = BEC_errFileRead;
Exit:
   if (!fRet)
	   {
	   FreeCTHeader(lpTH);
      lpTH = NULL;
	   }
	return(lpTH);
   }
Ejemplo n.º 16
0
    /* Set the Transmit Descriptor Ring Pointer */
    lance->RAP = CSR30;		/* Base Address of Transmit Ring */
    lance->RDP = swloww(ARIADNE_RAM+offsetof(struct lancedata, tx_ring));
    lance->RAP = CSR31;		/* Base Address of transmit Ring */
    lance->RDP = swhighw(ARIADNE_RAM+offsetof(struct lancedata, tx_ring));

    /* Set the Receive Descriptor Ring Pointer */
    lance->RAP = CSR24;		/* Base Address of Receive Ring */
    lance->RDP = swloww(ARIADNE_RAM+offsetof(struct lancedata, rx_ring));
    lance->RAP = CSR25;		/* Base Address of Receive Ring */
    lance->RDP = swhighw(ARIADNE_RAM+offsetof(struct lancedata, rx_ring));

    /* Set the Number of RX and TX Ring Entries */
    lance->RAP = CSR76;		/* Receive Ring Length */
    lance->RDP = swapw(((u_short)-RX_RING_SIZE));
    lance->RAP = CSR78;		/* Transmit Ring Length */
    lance->RDP = swapw(((u_short)-TX_RING_SIZE));

    /* Enable Media Interface Port Auto Select (10BASE-2/10BASE-T) */
    lance->RAP = ISACSR2;	/* Miscellaneous Configuration */
    lance->IDP = ASEL;

    /* LED Control */
    lance->RAP = ISACSR5;	/* LED1 Status */
    lance->IDP = PSE|XMTE;
    lance->RAP = ISACSR6;	/* LED2 Status */
    lance->IDP = PSE|COLE;
    lance->RAP = ISACSR7;	/* LED3 Status */
    lance->IDP = PSE|RCVE;
Ejemplo n.º 17
0
LPPALETTE ReadPalette( LPSTR lpFileName, BOOL bCombine )
/************************************************************************/
{
    int ifh;		/* file handle( unbuffered) */
    FILEBUF ifd;		/* file descriptor( buffered) */
    short i, iColors;
    VERSIONINFO version;
    RECINFO rec;
    LPTR lpByte;
    LPWORD lpWord;
    LPLONG lpLong;
    BYTE Previous;
    BOOL bError;
    FNAME szName;
    LPPALETTE lpHeadPalette, lpPalette, lpBigPalette;

    /* open the palette file */
    if ( ( ifh = _lopen( lpFileName, OF_READ)) < 0 )
    {
        Message( IDS_EOPEN, lpFileName);
        return( NULL );
    }

    /* create a buffered stream to speed access */
    FileFDOpenRdr( &ifd, ifh, (LPTR)LineBuffer[0], 16*1024);

// read palette version
    version.Length = sizeof(version.Number);
    version.Type = PALFILE_VERSION;
    FileRead(&ifd, (LPTR)&version, sizeof(version));
#ifdef _MAC
    swapw(&version.Length);
    swapw(&version.Number);
#endif
    if (ifd.err ||
            version.Type != PALFILE_VERSION ||
            version.Length != sizeof(version.Number) ||
            version.Number > CURRENT_VERSION)
    {
        Message(IDS_INVALIDPALETTE, lpFileName);
        _lclose(ifh);
        return(NULL);
    }
    rec.Type = 0;
    lpHeadPalette = NULL;
    lpPalette = NULL;
    bError = NO;
    while (!bError && !ifd.err && rec.Type != PALFILE_END)
    {
        Previous = rec.Type;
        FileRead(&ifd, (LPTR)&rec, sizeof(RECINFO));
#ifdef _MAC
        swapw(&rec.Length);
#endif
        if (ifd.err)
            break;
        switch (rec.Type)
        {
        case PALFILE_VERSION:
            bError = YES;
            break;
        case PALFILE_COUNT:
            lpByte = Alloc((long)rec.Length);
            FileRead(&ifd, lpByte, rec.Length);
            FreeUp(lpByte);
            break;
        case PALFILE_COLORS:
            if (!lpPalette)
            {
                bError = YES;
                break;
            }
            lpWord = (LPWORD)Alloc((long)rec.Length);
            if (!lpWord)
            {
                Message (IDS_EMEMALLOC);
                bError = YES;
                break;
            }
            FileRead(&ifd, (LPTR)lpWord, rec.Length);
            if (ifd.err)
            {
                FreeUp((LPTR)lpWord);
                break;
            }
#ifdef _MAC
            swapw(lpWord);
#endif
            iColors = *lpWord;
            if ((iColors * sizeof(COLOR) + sizeof(WORD)) != rec.Length)
            {
                FreeUp((LPTR)lpWord);
                bError = YES;
                break;
            }
            lpPalette->iColors = iColors;
            if (!iColors)
            {
                FreeUp((LPTR)lpWord);
                break;
            }
            lpLong = (LPLONG)(lpWord+1);
            lpPalette->lpColorInfo =
                (LPCOLORINFO)Alloc((long)(sizeof(COLORINFO)*iColors));
            if (!lpPalette->lpColorInfo)
            {
                Message(IDS_EMEMALLOC);
                FreeUp((LPTR)lpWord);
                bError = YES;
                break;
            }
            for (i = 0; i < iColors; ++i)
            {
                LPVOID lp = &lpPalette->lpColorInfo[i].rgb;

#ifdef _MAC
                swapl((LPDWORD)lp);
#endif

                CopyRGB(lpLong+i, lp);
                SetColorInfo(
                    &lpPalette->lpColorInfo[i],
                    &lpPalette->lpColorInfo[i],
                    CS_RGB);
            }

            FreeUp((LPTR)lpWord);
            break;
        case PALFILE_NAME:
            if (Previous == PALFILE_NAME)
            {
                bError = YES;
                break;
            }
            if (lpPalette)
            {
                lpHeadPalette = LinkPalette(lpHeadPalette, lpPalette);
                lpPalette = NULL;
            }
            rec.Length = bound(rec.Length, 0, MAX_FNAME_LEN);
            FileRead(&ifd, (LPTR)szName, rec.Length);
            if (ifd.err)
                break;
            lpPalette = NewPalette(szName);
            if (!lpPalette)
            {
                Message (IDS_EMEMALLOC);
                bError = YES;
                break;
            }
            break;
        case PALFILE_GROUP:
            if (!lpPalette || (rec.Length != sizeof(lpPalette->dwGroup)))
            {
                bError = YES;
                break;
            }
            FileRead(&ifd, (LPTR)&lpPalette->dwGroup, rec.Length);
#ifdef _MAC
            swapl((LPDWORD)(&lpPalette->dwGroup));
#endif
            break;
        case PALFILE_LABELS:
            if (!lpPalette)
            {
                bError = YES;
                break;
            }
            lpPalette->lpLabels = Alloc((long)rec.Length);
            if (!lpPalette->lpLabels)
            {
                Message (IDS_EMEMALLOC);
                bError = YES;
                break;
            }
            lpPalette->LabelsLength = rec.Length;
            FileRead(&ifd, lpPalette->lpLabels, rec.Length);
            break;
        case PALFILE_FORMAT:
            if (!lpPalette || (rec.Length > MAX_STR_LEN))
            {
                bError = YES;
                break;
            }
            FileRead(&ifd, (LPTR)lpPalette->szFormat, rec.Length);
            break;
        case PALFILE_END:
            if (lpPalette)
            {
                lpHeadPalette = LinkPalette(lpHeadPalette, lpPalette);
                lpPalette = NULL;
            }
            break;
        default:
            bError = YES;
            break;
        }
    }
    _lclose(ifh);
    if (lpPalette)
    {
        if (lpPalette->lpColorInfo)
            FreeUp((LPTR)lpPalette->lpColorInfo);
        if (lpPalette->lpLabels)
            FreeUp((LPTR)lpPalette->lpLabels);
        FreeUp((LPTR)lpPalette);
    }
    if (ifd.err || bError || rec.Type != PALFILE_END || lpPalette)
    {
        Message(IDS_INVALIDPALETTE, lpFileName);
        FreeUpPalette(lpHeadPalette);
        return(NULL);
    }

    if ( !bCombine || !lpHeadPalette )
        return( lpHeadPalette );

    if ( !(lpBigPalette = CombinePalettes(lpHeadPalette)) )
        Message (IDS_EMEMALLOC);
    FreeUpPalette(lpHeadPalette);
    return( lpBigPalette );
}
Ejemplo n.º 18
0
static int ariadne_rx(struct net_device *dev)
{
	struct ariadne_private *priv = netdev_priv(dev);
	int entry = priv->cur_rx % RX_RING_SIZE;
	int i;

	/* If we own the next entry, it's a new packet. Send it up */
	while (!(lowb(priv->rx_ring[entry]->RMD1) & RF_OWN)) {
		int status = lowb(priv->rx_ring[entry]->RMD1);

		if (status != (RF_STP | RF_ENP)) {	/* There was an error */
			/* There is a tricky error noted by
			 * John Murphy <*****@*****.**> to Russ Nelson:
			 * Even with full-sized buffers it's possible for a
			 * jabber packet to use two buffers, with only the
			 * last correctly noting the error
			 */
			/* Only count a general error at the end of a packet */
			if (status & RF_ENP)
				dev->stats.rx_errors++;
			if (status & RF_FRAM)
				dev->stats.rx_frame_errors++;
			if (status & RF_OFLO)
				dev->stats.rx_over_errors++;
			if (status & RF_CRC)
				dev->stats.rx_crc_errors++;
			if (status & RF_BUFF)
				dev->stats.rx_fifo_errors++;
			priv->rx_ring[entry]->RMD1 &= 0xff00 | RF_STP | RF_ENP;
		} else {
			/* Malloc up new buffer, compatible with net-3 */
			short pkt_len = swapw(priv->rx_ring[entry]->RMD3);
			struct sk_buff *skb;

			skb = dev_alloc_skb(pkt_len + 2);
			if (skb == NULL) {
				netdev_warn(dev, "Memory squeeze, deferring packet\n");
				for (i = 0; i < RX_RING_SIZE; i++)
					if (lowb(priv->rx_ring[(entry + i) % RX_RING_SIZE]->RMD1) & RF_OWN)
						break;

				if (i > RX_RING_SIZE - 2) {
					dev->stats.rx_dropped++;
					priv->rx_ring[entry]->RMD1 |= RF_OWN;
					priv->cur_rx++;
				}
				break;
			}


			skb_reserve(skb, 2);	/* 16 byte align */
			skb_put(skb, pkt_len);	/* Make room */
			skb_copy_to_linear_data(skb,
						(const void *)priv->rx_buff[entry],
						pkt_len);
			skb->protocol = eth_type_trans(skb, dev);
			netdev_dbg(dev, "RX pkt type 0x%04x from %pM to %pM data 0x%08x len %d\n",
				   ((u_short *)skb->data)[6],
				   skb->data + 6, skb->data,
				   (int)skb->data, (int)skb->len);

			netif_rx(skb);
			dev->stats.rx_packets++;
			dev->stats.rx_bytes += pkt_len;
		}

		priv->rx_ring[entry]->RMD1 |= RF_OWN;
		entry = (++priv->cur_rx) % RX_RING_SIZE;
	}

	priv->cur_rx = priv->cur_rx % RX_RING_SIZE;

	/* We should check that at least two ring entries are free.
	 * If not, we should free one and mark stats->rx_dropped++
	 */

	return 0;
}
Ejemplo n.º 19
0
Errcode read_tiftags(Tiff_file *tf)
/*****************************************************************************
 * load all the tags in an ifd, save the data we care about along the way.
 *	after reading everything in the ifd, this routine attempts to fudge in
 *	any data that was missing (eg, strip offsets, strip bytecounts).  it also
 *	verifies that the required fields were present (our idea of required
 *	fields, not tiff's idea.  we require image width and height; we can fake
 *	just about anything else.)
 ****************************************************************************/
{
	Errcode err;
	short	entry_count;
	Dirent	entry;
	int 	bps_count;

	/*
	 * plug in default values for things we care about...
	 */

	tf->width = 0;
	tf->height = 0;
	tf->longest_strip = 0;
	tf->strips_per_image = 0;
	tf->planar_configuration = 1;
	tf->rows_per_strip = 0x7fffffff;
	tf->samples_per_pixel = 1;
	tf->bits_per_sample[0] = 1;
	tf->bits_per_sample[1] = 0;
	tf->bits_per_sample[2] = 0;
	tf->compression = CMPRS_NONE;
	tf->photometric = PHMET_GREY_0ISBLACK;
	tf->min_sample_value = 0;
	tf->max_sample_value = 0;	/* default will be calc'd later if needed */

	/*
	 * the saved offset of the next ifd becomes the offset to the current
	 * ifd.  we seek to that location (just in case), and load the count
	 * of entries in the ifd, which will be used as a loop counter.
	 */

	tf->off_ifd_start = tf->off_ifd_cur = tf->off_ifd_next;
	if (Success != fseek(tf->file, tf->off_ifd_cur, SEEK_SET))
		return pj_errno_errcode();
	if (1 != fread(&entry_count, sizeof(entry_count), 1, tf->file))
		return pj_errno_errcode();
	SWAPW(&entry_count);
	tf->off_ifd_cur += sizeof(entry_count);

	/*
	 * loop through all the entries (tags) in the ifd, storing off the data
	 * we care about into our own structure as we go.
	 */

	while (entry_count--)
		{
		if (Success != (err = read_next_dirent(tf, &entry)))
			return err;

		switch (entry.tag)
			{

			case TAG_IMAGE_WIDTH:

				tf->width = entry.value.word;
				break;

			case TAG_IMAGE_LENGTH:

				tf->height = entry.value.word;
				break;

			case TAG_BITS_PER_SAMPLE:

				bps_count = entry.count;
				switch (entry.count)
					{
					case 1:
						tf->bits_per_sample[0] = entry.value.word;
						if (tf->bits_per_sample[0] > 8)
							return Err_wrong_type;
						break;
					case 3:
						if (Success != fseek(tf->file, entry.value.offset, SEEK_SET))
							return pj_errno_errcode();
						if (3 != fread(tf->bits_per_sample, sizeof(short), 3, tf->file))
							return Err_truncated;
						if (tf->swap_bytes)
							{
							swapw(&tf->bits_per_sample[0]);
							swapw(&tf->bits_per_sample[1]);
							swapw(&tf->bits_per_sample[2]);
							}
						if (tf->bits_per_sample[0] != 8 ||
							tf->bits_per_sample[1] != 8 ||
							tf->bits_per_sample[2] != 8 )
							return Err_wrong_type;
						break;
					default:
						return Err_wrong_type;
					}
				break;

			case TAG_COMPRESSION:

				tf->compression = entry.value.uword;
				break;

			case TAG_PHOTOMETRIC_INTERP:

				tf->photometric = entry.value.word;
				break;

			case TAG_STRIP_OFFSETS:
			case TAG_SHORT_STRIP_OFFSETS:	/* Aldus private tag 32768 */

				if (Success != (err = read_strip_offsets(tf, entry.value.offset,
									entry.type, entry.count)))
					return err;
				break;

			case TAG_SAMPLES_PER_PIXEL:

				tf->samples_per_pixel = entry.value.word;
				switch (tf->samples_per_pixel)
					{
					case 1:
						if (tf->photometric == PHMET_RGB)
							return Err_format;
						break;
					case 3:
						tf->photometric = PHMET_RGB;	/* force RGB interp */
						break;
					default:
						return Err_wrong_type;
					}
				break;

			case TAG_ROWS_PER_STRIP:

				tf->rows_per_strip =
					(entry.type == TYPE_SHORT) ? entry.value.word : entry.value.dword;
				break;

			case TAG_STRIP_BYTE_COUNTS:

				if (Success != (err = read_strip_bytecounts(tf, entry.value.offset,
									entry.type, entry.count)))
					return err;
				break;

			case TAG_MIN_SAMPLE_VALUE:
			case TAG_MAX_SAMPLE_VALUE:
				/* we ignore these fields and calc values below.
				 * we use the min/max values to calculate greyscale
				 * pallete entries, but on the advice of of the TIFF 5.0
				 * doc ('these values should not affect the visual display
				 * of the data, they are for statistical purposes only'),
				 * we use 2**bits_per_sample instead of max_sample_value.
				 */
				 break;

			case TAG_PLANAR_CONFIG:

				tf->planar_configuration = entry.value.word;
				break;

			case TAG_COLORMAP:

				if (Success != (err = read_color_map(tf, entry.value.offset, entry.count)))
					return err;
				break;

			default:
				break;
			}
		tf->off_ifd_cur += sizeof(entry);
		}

	/*
	 * read the offset to the next ifd; we may need it for multi-image file
	 */

	if (Success != fseek(tf->file, tf->off_ifd_cur, SEEK_SET))
		return pj_errno_errcode();
	if (1 != fread(&tf->off_ifd_next, sizeof(tf->off_ifd_next), 1, tf->file))
		return Err_truncated;
	SWAPD(&tf->off_ifd_next);

	/*
	 * if we have RGB data but we only got one bits_per_sample value,
	 * propogate it to the other two entries in the array.
	 * calculate the total pixel depth.
	 */

	if (tf->photometric == PHMET_RGB && bps_count != 3)
		{
		tf->bits_per_sample[1] = tf->bits_per_sample[0];
		tf->bits_per_sample[2] = tf->bits_per_sample[0];
		}

	tf->pixel_depth = tf->bits_per_sample[0] +
					  tf->bits_per_sample[1] +
					  tf->bits_per_sample[2];

	/*
	 * calculate max_sample_value as (2**bits_per_sample)-1...
	 */

	if (tf->max_sample_value == 0)
		tf->max_sample_value = (0x01 << tf->bits_per_sample[0]) - 1;

	/*
	 * hmmm.  it seems some tif files don't have strip bytecount entries.
	 * we'll see symptoms of that here if the longest strip size is zero
	 * after reading all the tags.	when this occurs, we call a routine
	 * to calculate the byte counts.  the routine does some sanity checking
	 * and will return an error if the counts look totally unreasonable.
	 */

	if (tf->longest_strip == 0)
		if (Success != (err = calc_strip_bytecounts(tf)))
			return err;

	/*
	 * all entries in this ifd have been dealt with, make sure we have
	 * the minimum required data to run the rest of the program...
	 *	 checking strips_per_image ensures that we got strip offsets.
	 *	 checking longest_strip ensures we got (or calc'd) strip bytecounts.
	 */

	 if (tf->width == 0 ||
		 tf->height == 0 ||
		 tf->strips_per_image == 0 ||
		 tf->longest_strip == 0)
		return Err_format;


	return Success;
}