boolean Phonic::charEv( char code ) { switch ( code ) { #ifdef INTERN_CONSOLE case 'v': // input a volume level console.getByte( CONSTR("vol"), &this->vol ); setVol( vol ); break; #endif #ifdef CONSOLE_OUTPUT case chrInfo: // display object info to console super::charEv( chrInfo ); console.infoByte( CONSTR("vol"), vol ); break; #endif case '!': // reset super::charEv('!'); // perform generic reset 1st setVol( 255 ); // full volume break; default: return super::charEv( code ); } return true; }
/*-------------------------------------------------------------------------- NAME DFPIopen -- open/reopen file for palette interface USAGE int32 DFPIopen(filename,acc_mode) char *filename; IN: name of HDF file intn acc_mode; IN: type of access to open file with RETURNS HDF file handle on success, FAIL on failure. DESCRIPTION Open/reopen a file for the DFP interface to work with. GLOBAL VARIABLES Refset, Readref, Lastfile COMMENTS, BUGS, ASSUMPTIONS This is a hook for someday providing more efficient ways to reopen a file, to avoid re-reading all the headers EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ PRIVATE int32 DFPIopen(const char *filename, intn acc_mode) { CONSTR(FUNC, "DFPIopen"); int32 file_id; int32 ret_value = SUCCEED; /* use reopen if same file as last time - more efficient */ if (HDstrncmp(Lastfile, filename, DF_MAXFNLEN) || (acc_mode == DFACC_CREATE)) { /* treat create as different file */ if ((file_id = Hopen(filename, acc_mode, 0)) == FAIL) HGOTO_ERROR(DFE_BADOPEN, FAIL); Refset = 0; /* no ref to get set for this file */ Readref = 0; } /* end if */ else if ((file_id = Hopen(filename, acc_mode, 0)) == FAIL) HGOTO_ERROR(DFE_BADOPEN, FAIL); /* remember filename, so reopen may be used next time if same file */ HDstrncpy(Lastfile, filename, DF_MAXFNLEN); ret_value = (file_id); done: if(ret_value == FAIL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end DFPIopen() */
/****************************************************************************** NAME HULcreate_list - Create a linked list DESCRIPTION Creates a linked list. The list may either be sorted or un-sorted, based on the comparison function. RETURNS Returns a pointer to the list if successful and NULL otherwise *******************************************************************************/ list_head_t *HULcreate_list(HULfind_func_t find_func /* IN: object comparison function */ ) { CONSTR(FUNC, "HULcreate_list"); /* for HERROR */ list_head_t *ret_value=NULL; /* ptr to the linked list "head" node */ HEclear(); /* Allocate the head information */ if((ret_value=(list_head_t *)HDcalloc(1,sizeof(list_head_t)))==NULL) HGOTO_ERROR(DFE_NOSPACE, NULL); /* Set the counter */ ret_value->count=0; /* Store the creation flags, etc */ if(find_func==NULL) ret_value->flags=HUL_UNSORTED_LIST; else ret_value->flags=HUL_SORTED_LIST; ret_value->cmp_func=find_func; done: if(ret_value == NULL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end HULcreate_list() */
int main(void){ NumPrinter *p1, *p2, *p3, *p4, *p5; mutex_t * mut = mutex_new(); CONSTR(mut); p1 = num_pr_new(1); p2 = num_pr_new(2); p3 = num_pr_new(3); p4 = num_pr_new(4); p5 = num_pr_new(5); printStart(p1); printStart(p2); printStart(p3); printStart(p4); printStart(p5); getchar(); printer_free(p1); printer_free(p2); printer_free(p3); printer_free(p4); printer_free(p5); DESTR(); }
/****************************************************************************** NAME HULadd_node - Adds an object to a linked-list DESCRIPTION Adds an object to the linked list. If the list is sorted, the comparison function is used to determine where to insert the node, otherwise it is inserted at the head of the list. RETURNS Returns SUCCEED/FAIL. *******************************************************************************/ intn HULadd_node(list_head_t *lst, /* IN: list to modify */ VOIDP obj /* IN: object to add to the list */ ) { CONSTR(FUNC, "HULadd_node"); /* for HERROR */ node_info_t *new_node; /* new node to insert into the list */ intn ret_value=SUCCEED; /* return value */ HEclear(); if(lst==NULL || obj==NULL) HGOTO_ERROR(DFE_ARGS,FAIL); /* Allocate & initialize the new node */ if((new_node=HULIget_list_node())==NULL) HGOTO_ERROR(DFE_NOSPACE,FAIL); new_node->obj_ptr=obj; if(((lst->flags)&HUL_SORTED_LIST)!=0) { /* insert node into a sorted list */ node_info_t *curr_node, /* current node while walking through list */ *prev_node; /* previous node in the list */ prev_node=NULL; curr_node=lst->node_list; while(curr_node!=NULL) { if(lst->cmp_func(curr_node->obj_ptr,new_node->obj_ptr)>=0) { /* 'curr_node' object is greater than or equal to 'new_node' */ new_node->next=curr_node; if(prev_node==NULL) lst->node_list=new_node; else prev_node->next=new_node; HGOTO_DONE(SUCCEED); /* Break out of the loop */ } /* end if */ prev_node=curr_node; curr_node=curr_node->next; } /* end while */ /* Walked off the list, so append to last node */ if(prev_node==NULL) lst->node_list=new_node; else prev_node->next=new_node; } /* end if */ else { /* insert node into an un-sorted list */ new_node->next=lst->node_list; lst->node_list=new_node; } /* end else */ done: if(ret_value == FAIL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end HULadd_node() */
/* NAME HDgettagsname -- return a text name of a tag USAGE char * HDgettagsname(tag) uint16 tag; IN: tag of element to find RETURNS Descriptive text or NULL DESCRIPTION Map a tag to a dynamically allocated text name of it. Checks for special elements now. --------------------------------------------------------------------------- */ char * HDgettagsname(uint16 tag) { CONSTR(FUNC, "HDgettagsname"); /* for HERROR */ char *ret = NULL; intn i; if (SPECIALTAG(tag)) ret = (char *) HDstrdup("Special "); tag = BASETAG(tag); for (i = 0; i < (intn)(sizeof(tag_descriptions) / sizeof(tag_descript_t)); i++) if (tag_descriptions[i].tag == tag) { if (ret == NULL) ret = (char *) HDstrdup(tag_descriptions[i].name); else { char *t; t = (char *) HDmalloc(HDstrlen(ret) + HDstrlen(tag_descriptions[i].name) + 2); if (t == NULL) { HDfree(ret); HRETURN_ERROR(DFE_NOSPACE, NULL) } /* end if */ HDstrcpy(t, ret); HDstrcat(t, tag_descriptions[i].name); HDfree(ret); ret = t; } /* end else */ } /* end if */
/****************************************************************************** NAME HULnext_node - Get the next object in a linked-list DESCRIPTION Returns the next object in a linked-list by walking through the list RETURNS Returns a pointer to the next object found in the list, or NULL on failure. *******************************************************************************/ VOIDP HULnext_node(list_head_t *lst /* IN: list to search */ ) { CONSTR(FUNC, "HULnext_node"); /* for HERROR */ VOIDP ret_value=NULL; /* default return value */ HEclear(); if(lst==NULL) HGOTO_ERROR(DFE_ARGS,NULL); if(lst->curr_node!=NULL) { lst->curr_node=lst->curr_node->next; if(lst->curr_node!=NULL) HGOTO_DONE(lst->curr_node->obj_ptr); } /* end if */ done: if(ret_value == NULL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end HULnext_node() */
/****************************************************************************** NAME HULIget_list_node - Gets a list node DESCRIPTION Either gets an list node from the free list (if there is one available) or allocate a node. RETURNS Returns list node ptr if successful and NULL otherwise *******************************************************************************/ static node_info_t *HULIget_list_node(void) { CONSTR(FUNC, "HULIget_list_node"); /* for HERROR */ node_info_t *ret_value=NULL; HEclear(); if(node_free_list!=NULL) { ret_value=node_free_list; node_free_list=node_free_list->next; } /* end if */ else { if((ret_value=(node_info_t *)HDmalloc(sizeof(node_info_t)))==NULL) HGOTO_ERROR(DFE_NOSPACE, NULL); } /* end else */ done: if(ret_value == NULL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end HULIget_list_node() */
/****************************************************************************** NAME HULsearch_node - Search for an object in a linked-list DESCRIPTION Locate an object in a linked list using a key and comparison function. RETURNS Returns a pointer to the object found in the list, or NULL on failure. *******************************************************************************/ VOIDP HULsearch_node(list_head_t *lst, /* IN: list to search */ HULsearch_func_t srch_func, /* IN: function to use to find node */ VOIDP key /* IN: key of object to search for */ ) { CONSTR(FUNC, "HULsearch_node"); /* for HERROR */ node_info_t *curr_node; /* current node we are on */ VOIDP ret_value=NULL; /* default return value */ HEclear(); if(lst==NULL || srch_func==NULL || key==NULL) HGOTO_ERROR(DFE_ARGS,NULL); curr_node=lst->node_list; while(curr_node!=NULL) { if(srch_func(curr_node->obj_ptr,key)==1) HGOTO_DONE(curr_node->obj_ptr); } /* end while */ done: if(ret_value == NULL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end HULsearch_node() */
/*-------------------------------------------------------------------------- NAME HCIcszip_encode -- Encode data from a buffer into SZIP compressed data USAGE int32 HCIcszip_encode(info,length,buf) compinfo_t *info; IN: the info about the compressed element int32 length; IN: number of bytes to store from the buffer const uint8 *buf; OUT: buffer to get the bytes from RETURNS Returns SUCCEED or FAIL DESCRIPTION Common code called to encode SZIP data into a file. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ PRIVATE int32 HCIcszip_encode(compinfo_t * info, int32 length, const uint8 *buf) { CONSTR(FUNC, "HCIcszip_encode"); #ifdef H4_HAVE_SZIP_ENCODER int bytes_per_pixel; comp_coder_szip_info_t *szip_info; /* ptr to SZIP info */ int32 buffer_size; if (SZ_encoder_enabled() == 0) HRETURN_ERROR(DFE_NOENCODER, FAIL); szip_info = &(info->cinfo.coder_info.szip_info); if (szip_info->szip_state == SZIP_INIT) { /* Need to initialize */ bytes_per_pixel = (szip_info->bits_per_pixel + 7) >> 3; if (bytes_per_pixel == 3) bytes_per_pixel = 4; buffer_size = szip_info->pixels * bytes_per_pixel; if ((szip_info->buffer = HDmalloc(buffer_size)) == NULL) HRETURN_ERROR(DFE_NOSPACE, FAIL); szip_info->buffer_size = buffer_size; szip_info->buffer_pos = 0; szip_info->szip_state = SZIP_RUN; }
/****************************************************************************** NAME HULdestroy_list - Destroys a linked list DESCRIPTION Destroys a linked list created by HULcreate_list(). This function walks through the list and frees all the nodes, then frees the list head. Note: this function does not (currently) free the objects in the nodes, it just leaves 'em hanging. RETURNS Returns SUCCEED/FAIL. *******************************************************************************/ intn HULdestroy_list(list_head_t *lst /* IN: list to destroy */ ) { CONSTR(FUNC, "HULdestroy_list"); /* for HERROR */ node_info_t *curr_node, /* current node while walking through list */ *next_node; /* next node in the list */ intn ret_value=SUCCEED; /* return value */ HEclear(); if(lst==NULL) HGOTO_ERROR(DFE_ARGS,FAIL); /* Chuck the list */ curr_node=lst->node_list; while(curr_node!=NULL) { next_node=curr_node->next; HULIrelease_list_node(curr_node); curr_node=next_node; } /* end while */ /* Chuck the list-head */ HDfree(lst); done: if(ret_value == FAIL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end HULdestroy_list() */
boolean Osc::charEv( char code ) { switch ( code ) { #ifdef INTERN_CONSOLE case 'd': // set detuning amount console.getSByte( CONSTR("detune"), &this->detune ); setDetune( detune ); break; case 'f': // input an ideal frequency { double newFreq; if ( console.getDouble( CONSTR("freq"), &newFreq ) ) setFreq( newFreq ); break; } #endif #ifdef CONSOLE_OUTPUT case chrInfo: // display object info to console super::charEv( code ); case chrInLnfo: // display object info inline to console console.infoDouble( CONSTR("freq"), realFreq() ); console.infoInt( CONSTR("detune"), detune ); break; #endif case '!': // perform a reset super::charEv('!'); setDetune(0); extFactor = 1.0; break; default: return super::charEv( code ); } return true; }
/****************************************************************************** NAME HULIrelease_list_node - Releases a list node DESCRIPTION Puts a list node into the free list RETURNS No return value *******************************************************************************/ static void HULIrelease_list_node(node_info_t *nod) { #ifdef LATER CONSTR(FUNC, "HULIrelease_list_node"); /* for HERROR */ #endif /* LATER */ /* Insert the node at the beginning of the free list */ nod->next=node_free_list; node_free_list=nod; } /* end HULIrelease_list_node() */
void ardutouch_info() { console.newlntab(); console.infoStr( CONSTR( "Version" ), CONSTR( LIBRARY_VERSION ) ); console.newlntab(); console.infoDouble( CONSTR("audioRate"), audioRate ); console.infoDouble( CONSTR("dynaRate"), dynaRate ); console.newlntab(); console.infoByte( CONSTR("bufSz"), audioBufSz ); console.infoByte( CONSTR("numBufs"), NUMBUFS ); console.infoByte( CONSTR("bufsPerDyna"), bufsPerDyna ); console.newlntab(); console.infoDouble( CONSTR("scanRate"), scanRate ); console.infoInt( CONSTR("bufsPerScan"), bufsPerScan ); console.newprompt(); }
/*-------------------------------------------------------------------------- NAME HCPmstdio_endaccess -- Close the compressed data element USAGE intn HCPendaccess(access_rec) accrec_t *access_rec; IN: the access record of the data element RETURNS Returns SUCCEED or FAIL DESCRIPTION Close the compressed data element and free modelling info. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ intn HCPmstdio_endaccess(accrec_t * access_rec) { CONSTR(FUNC, "HCPmstdio_endaccess"); compinfo_t *info; /* information on the special element */ intn ret; info = (compinfo_t *) access_rec->special_info; if ((ret = (*(info->cinfo.coder_funcs.endaccess)) (access_rec)) == FAIL) HRETURN_ERROR(DFE_CODER, FAIL); return (ret); } /* HCPmstdio_endaccess() */
/*--------------------------------------------------------------------------*/ void CVector3D::normalize() { CALL Treal len = length(); if (!NMath::CMath::isEqualZero(len)) len = CONSTR(1.0) / len; else len = 1.0; m_X *= len; m_Y *= len; m_Z *= len; }
/*-------------------------------------------------------------------------- NAME DFPputpal -- Write palette to file USAGE intn DFPputpal(filename,palette,overwrite,filemode) char *filename; IN: name of HDF file void * palette; IN: ptr to the buffer retrieve the palette from intn overwrite; IN: whether to (1) overwrite last palette written, or (0) write it as a fresh palette char *filemode; IN: if "a" append palette to file, "w" create new file RETURNS SUCCEED on success, FAIL on failure. DESCRIPTION Stores a palette in an HDF file, with options for creating new file or appending, and overwriting last palette written. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS To overwrite, the filename must be the same as for the previous call. EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ intn DFPputpal(const char *filename, const void * palette, intn overwrite, const char *filemode) { CONSTR(FUNC, "DFPputpal"); int32 file_id; intn ret_value = SUCCEED; HEclear(); if (!palette) HGOTO_ERROR(DFE_ARGS, FAIL); if (overwrite && HDstrcmp(filename, Lastfile)) HGOTO_ERROR(DFE_BADCALL, FAIL); file_id = DFPIopen(filename, (*filemode == 'w') ? DFACC_CREATE : DFACC_WRITE); if (file_id == FAIL) HGOTO_ERROR(DFE_BADOPEN, FAIL); /* if we want to overwrite, Lastref is the ref to write. If not, if Writeref is set, we use that ref. If not we get a fresh ref. The ref to write is placed in Lastref */ if (!overwrite) Lastref = (uint16) (Writeref ? Writeref : Htagnewref(file_id,DFTAG_IP8)); if (Lastref == 0) HGOTO_ERROR(DFE_NOREF, FAIL); Writeref = 0; /* don't know ref to write after this */ /* write out palette */ if (Hputelement(file_id, DFTAG_IP8, Lastref, (const uint8 *) palette, (int32) 768) < 0) { ret_value = (HDerr(file_id)); goto done; } /* Check for the tag/ref before creating it willy-nilly */ if(Hexist(file_id,DFTAG_LUT,Lastref)==FAIL) Hdupdd(file_id, DFTAG_LUT, Lastref, DFTAG_IP8, Lastref); ret_value = (Hclose(file_id)); done: if(ret_value == FAIL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end DFPputpal() */
/* NAME HDflush -- flush the HDF file USAGE intn HDflush(fid) int32 fid; IN: file ID RETURNS SUCCEED / FAIL DESCRIPTION Force the system to flush the HDF file stream This should be primarily used for debugging The MAC does not really support fflush() so this r outine just returns SUCCEED always on a MAC w/o really doing anything. ---------------------------------------------------------------------------*/ intn HDflush(int32 file_id) { CONSTR(FUNC, "HDflush"); /* for HERROR */ filerec_t *file_rec; file_rec = HAatom_object(file_id); if (BADFREC(file_rec)) HRETURN_ERROR(DFE_ARGS, FAIL); HI_FLUSH(file_rec->file); return SUCCEED; } /* HDflush */
/*-------------------------------------------------------------------------- NAME HCPmstdio_inquire -- Inquire information about the access record and data element. USAGE int32 HCPmstdio_inquire(access_rec,pfile_id,ptag,pref,plength,poffset,pposn, paccess,pspecial) accrec_t *access_rec; IN: the access record of the data element int32 *pfile_id; OUT: ptr to file id uint16 *ptag; OUT: ptr to tag of information uint16 *pref; OUT: ptr to ref of information int32 *plength; OUT: ptr to length of data element int32 *poffset; OUT: ptr to offset of data element int32 *pposn; OUT: ptr to position of access in element int16 *paccess; OUT: ptr to access mode int16 *pspecial; OUT: ptr to special code RETURNS Returns SUCCEED or FAIL DESCRIPTION Inquire information about the access record and data element. [Currently a NOP]. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ int32 HCPmstdio_inquire(accrec_t * access_rec, int32 *pfile_id, uint16 *ptag, uint16 *pref, int32 *plength, int32 *poffset, int32 *pposn, int16 *paccess, int16 *pspecial) { CONSTR(FUNC, "HCPmstdio_inquire"); compinfo_t *info; /* information on the special element */ int32 ret; info = (compinfo_t *) access_rec->special_info; if ((ret = (*(info->cinfo.coder_funcs.inquire)) (access_rec, pfile_id, ptag, pref, plength, poffset, pposn, paccess, pspecial)) == FAIL) HRETURN_ERROR(DFE_CODER, FAIL); return (ret); } /* HCPmstdio_inquire() */
/*--------------------------------------------------------------------------*/ Treal CVector3D::normalizeLength() { CALL Treal len = length(); Treal factor; if (!NMath::CMath::isEqualZero(len)) factor = CONSTR(1.0) / len; else factor = 1.0; m_X *= factor; m_Y *= factor; m_Z *= factor; return len; }
int DFgetcomp(int32 file_id, uint16 tag, uint16 ref, uint8 *image, int32 xdim, int32 ydim, uint16 scheme) { CONSTR(FUNC, "DFgetcomp"); uint8 *buffer; uint8 *in; uint8 *out; int32 cisize, crowsize, buflen, bufleft; /* bufleft: bytes left in buffer */ int32 i; int32 totalread; int32 n; int32 aid; if (!HDvalidfid(file_id) || !tag || !ref || xdim <= 0 || ydim <= 0 || !image) HRETURN_ERROR(DFE_ARGS, FAIL); /* put this call up here instead of in switch statement, to make the */ /* code easier to follow */ if (scheme == DFTAG_JPEG5 || scheme == DFTAG_GREYJPEG5 || scheme==DFTAG_JPEG || scheme==DFTAG_GREYJPEG) return (DFCIunjpeg(file_id, tag, ref, (VOIDP) image, xdim, ydim, (int16)scheme)); /* Only do this stuff for non-JPEG compressed images */ aid = Hstartread(file_id, tag, ref); if (aid == FAIL) HRETURN_ERROR(DFE_NOMATCH, FAIL); if (Hinquire(aid, (int32 *) NULL, (uint16 *) NULL, (uint16 *) NULL, &cisize, (int32 *) NULL, (int32 *) NULL, (int16 *) NULL, (int16 *) NULL) == FAIL) return FAIL; switch (scheme) { case DFTAG_RLE: crowsize = xdim * 121 / 120 + 128; /* max size of a row */ buffer = (uint8 *) HDmalloc((uint32) cisize); if (!buffer) { buffer = (uint8 *) HDmalloc((uint32) crowsize); if (!buffer) { Hendaccess(aid); HRETURN_ERROR(DFE_NOSPACE, FAIL) } /* end if */ buflen = crowsize; } /* end if */
boolean VoxSynth::charEv( char code ) { #ifdef INTERN_CONSOLE // push voice by # if ( code >= '0' && code < '0'+numVox ) { console.pushMode( vox[code-'0'] ); return true; } #endif switch( code ) { #ifdef INTERN_CONSOLE case '#': { char ith = console.getDigit( CONSTR("v#"), numVox-1 ); if ( ith >= 0 ) console.pushMode( vox[ith] ); break; } #endif case '!': super::charEv( code ); for ( byte i = 0; i < numVox; i++ ) vox[i]->reset(); break; case '.': // mute case '<': // unmute { byte chnlVol = ( code == '.' ? 0 : vol ); for ( byte i = 0; i < numVox; i++ ) vox[i]->setGlobVol( chnlVol ); } default: return super::charEv( code ); } return true; }
/*-------------------------------------------------------------------------- NAME HCPmstdio_read -- Read in a portion of data from a compressed data element. USAGE int32 HCPmstdio_read(access_rec,length,data) accrec_t *access_rec; IN: the access record of the data element int32 length; IN: the number of bytes to read void * data; OUT: the buffer to place the bytes read RETURNS Returns the number of bytes read or FAIL DESCRIPTION Read in a number of bytes from a compressed data element, using stdio functionality. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ int32 HCPmstdio_read(accrec_t * access_rec, int32 length, void * data) { CONSTR(FUNC, "HCPmstdio_read"); compinfo_t *info; /* information on the special element */ int32 ret; info = (compinfo_t *) access_rec->special_info; /* adjust model position */ info->minfo.model_info.stdio_info.pos += length; if ((ret = (*(info->cinfo.coder_funcs.read)) (access_rec, length, data)) == FAIL) HRETURN_ERROR(DFE_CODER, FAIL); return (ret); } /* HCPmstdio_read() */
/*-------------------------------------------------------------------------- NAME HCPmstdio_seek -- Seek to offset within the data element USAGE int32 HCPmstdio_seek(access_rec,offset,origin) accrec_t *access_rec; IN: the access record of the data element int32 offset; IN: the offset in bytes from the origin specified intn origin; IN: the origin to seek from [UNUSED!] RETURNS Returns SUCCEED or FAIL DESCRIPTION Seek to a position with a compressed data element. The 'origin' calculations have been taken care of at a higher level, it is an un-used parameter. The 'offset' is used as an absolute offset because of this. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ int32 HCPmstdio_seek(accrec_t * access_rec, int32 offset, int origin) { CONSTR(FUNC, "HCPmstdio_seek"); compinfo_t *info; /* information on the special element */ int32 ret; info = (compinfo_t *) access_rec->special_info; /* set the offset */ info->minfo.model_info.stdio_info.pos = offset; if ((ret = (*(info->cinfo.coder_funcs.seek)) (access_rec, offset, origin)) == FAIL) HRETURN_ERROR(DFE_CODER, FAIL); return (ret); } /* HCPmstdio_seek() */
/* NAME HDf2cstring -- convert a Fortran string to a C string USAGE char * HDf2cstring(fdesc, len) _fcd fdesc; IN: Fortran string descriptor intn len; IN: length of Fortran string RETURNS Pointer to the C string if success, else NULL DESCRIPTION Chop off trailing blanks off of a Fortran string and move it into a newly allocated C string. It is up to the user to free this string. ---------------------------------------------------------------------------*/ char * HDf2cstring(_fcd fdesc, intn len) { CONSTR(FUNC, "HDf2cstring"); /* for HERROR */ char *cstr, *str; int i; str = _fcdtocp(fdesc); /* This should be equivalent to the above test -QAK */ for(i=len-1; i>=0 && !isgraph((int)str[i]); i--) /*EMPTY*/; cstr = (char *) HDmalloc((uint32) (i + 2)); if (!cstr) HRETURN_ERROR(DFE_NOSPACE, NULL); cstr[i + 1] = '\0'; HDmemcpy(cstr,str,i+1); return cstr; } /* HDf2cstring */
/*-------------------------------------------------------------------------- NAME HCPmstdio_stread -- start read access for compressed file USAGE int32 HCPmstdio_stread(access_rec) accrec_t *access_rec; IN: the access record of the data element RETURNS Returns SUCCEED or FAIL DESCRIPTION Start read access on a compressed data element using the stdio modeling scheme. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ int32 HCPmstdio_stread(accrec_t * access_rec) { CONSTR(FUNC, "HCPmstdio_stread"); compinfo_t *info; /* information on the special element */ info = (compinfo_t *) access_rec->special_info; /* set the offset */ info->minfo.model_info.stdio_info.pos = 0; #ifdef TESTING printf("%s(): info=%p\n", FUNC, info); #endif if ((*(info->cinfo.coder_funcs.stread)) (access_rec) == FAIL) HRETURN_ERROR(DFE_CODER, FAIL); return (SUCCEED); } /* HCPmstdio_stread() */
/*-------------------------------------------------------------------------- NAME HCIcszip_init -- Initialize a SZIP compressed data element. USAGE int32 HCIcszip_init(access_rec) accrec_t *access_rec; IN: the access record of the data element RETURNS Returns SUCCEED or FAIL DESCRIPTION Common code called by HCIcszip_staccess and HCIcszip_seek GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ PRIVATE int32 HCIcszip_init(accrec_t * access_rec) { CONSTR(FUNC, "HCIcszip_init"); compinfo_t *info; /* special element information */ comp_coder_szip_info_t *szip_info; /* ptr to SZIP info */ intn ret_value = SUCCEED; #ifdef H4_HAVE_LIBSZ /* Sanity check to make certain that we haven't drifted out of date with * the mask options from the SZIP ricehdf.h header */ assert(H4_SZ_ALLOW_K13_OPTION_MASK==SZ_ALLOW_K13_OPTION_MASK); assert(H4_SZ_CHIP_OPTION_MASK==SZ_CHIP_OPTION_MASK); assert(H4_SZ_EC_OPTION_MASK==SZ_EC_OPTION_MASK); assert(H4_SZ_LSB_OPTION_MASK==SZ_LSB_OPTION_MASK); assert(H4_SZ_MSB_OPTION_MASK==SZ_MSB_OPTION_MASK); assert(H4_SZ_NN_OPTION_MASK==SZ_NN_OPTION_MASK); assert(H4_SZ_RAW_OPTION_MASK==SZ_RAW_OPTION_MASK); #endif info = (compinfo_t *) access_rec->special_info; if (Hseek(info->aid, 0, DF_START) == FAIL) /* seek to beginning of element */ HGOTO_ERROR(DFE_SEEKERROR, FAIL); szip_info = &(info->cinfo.coder_info.szip_info); /* Initialize SZIP state information */ szip_info->szip_state = SZIP_INIT; /* start in initial state */ if (szip_info->buffer_size != 0) { szip_info->buffer_size = 0; /* offset into the file */ if (szip_info->buffer != NULL) { HDfree(szip_info->buffer); szip_info->buffer = NULL; } } szip_info->offset = 0; /* offset into the file */ szip_info->szip_dirty=SZIP_CLEAN; done: return(ret_value); } /* end HCIcszip_init() */
/*-------------------------------------------------------------------------- NAME HCPmstdio_write -- Write out a portion of data from a compressed data element. USAGE int32 HCPwrite(access_rec,length,data) accrec_t *access_rec; IN: the access record of the data element int32 length; IN: the number of bytes to write void * data; IN: the buffer to retrieve the bytes written RETURNS Returns the number of bytes written or FAIL DESCRIPTION Write out a number of bytes to a compressed data element. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ int32 HCPmstdio_write(accrec_t * access_rec, int32 length, const void * data) { CONSTR(FUNC, "HCPmstdio_write"); compinfo_t *info; /* information on the special element */ int32 ret; info = (compinfo_t *) access_rec->special_info; /* adjust model position */ info->minfo.model_info.stdio_info.pos += length; #ifdef TESTING printf("%s(): before function ptr call func_ptr=%p\n", FUNC, info->cinfo.coder_funcs.write); #endif if ((ret = (*(info->cinfo.coder_funcs.write)) (access_rec, length, data)) == FAIL) HRETURN_ERROR(DFE_CODER, FAIL); #ifdef TESTING printf("%s(): after function ptr call, ret=%d\n",FUNC,(int)ret); #endif return (ret); } /* HCPmstdio_write() */
/****************************************************************************** NAME HULremove_node - Removes an object from a linked-list DESCRIPTION Remove an object from a linked list. The key and comparison function are provided locate the object to delete. RETURNS Returns a pointer to the object deleted from the list, or NULL on failure. *******************************************************************************/ VOIDP HULremove_node(list_head_t *lst, /* IN: list to modify */ HULsearch_func_t srch_func, /* IN: function to use to find node to remove */ VOIDP key /* IN: object to add to the list */ ) { CONSTR(FUNC, "HULremove_node"); /* for HERROR */ node_info_t *curr_node, /* current node we are on */ *prev_node; /* previous node we looked at */ VOIDP ret_value=NULL; /* default return value */ HEclear(); if(lst==NULL || srch_func==NULL || key==NULL) HGOTO_ERROR(DFE_ARGS,NULL); prev_node=NULL; curr_node=lst->node_list; while(curr_node!=NULL) { if(srch_func(curr_node->obj_ptr,key)==1) { if(prev_node==NULL) lst->node_list=curr_node->next; else prev_node->next=curr_node->next; ret_value=curr_node->obj_ptr; HULIrelease_list_node(curr_node); break; } /* end if */ } /* end while */ done: if(ret_value == NULL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end HULremove_node() */
/*-------------------------------------------------------------------------- NAME DFPreadref -- set ref # of palette to read next USAGE intn DFPreadref(filename,ref) char *filename; IN: name of HDF file uint16 ref; IN: ref # of palette to read next RETURNS SUCCEED on success, FAIL on failure. DESCRIPTION Sets the ref # of the next palette to read from a file GLOBAL VARIABLES Refset COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ intn DFPreadref(const char *filename, uint16 ref) { CONSTR(FUNC, "DFPreadref"); int32 file_id; int32 aid; intn ret_value = SUCCEED; HEclear(); if ((file_id = DFPIopen(filename, DFACC_READ)) == FAIL) HGOTO_ERROR(DFE_BADOPEN, FAIL); aid = Hstartread(file_id, DFTAG_IP8, ref); if (aid == FAIL) { aid = Hstartread(file_id, DFTAG_LUT, ref); if (aid == FAIL) { ret_value = (HDerr(file_id)); goto done; } } /* end if */ Hendaccess(aid); Refset = ref; ret_value = (Hclose(file_id)); done: if(ret_value == FAIL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end DFPreadref() */