static void FreeKuroLyric(KuroLyric *lyric) { KuroWord *word; GList *wordList; guint i, length; if(!lyric) return; /* Foreach the word glist */ length = g_list_length(lyric->word); for(i=0;i<length; i++){ wordList = g_list_nth(lyric->word, i); if(wordList->data == NULL) continue; word = (KuroWord*)wordList->data; ZFREE(word); } g_string_free(lyric->words, TRUE); g_list_free(lyric->word); ZFREE(lyric); }
void FreeConvertTask(void) { ZFREE(ConvertTask.PreObjID); freeMetaTrack(&(ConvertTask.TrackMeta)); FreeItem(&(ConvertTask.CurEncodeItem)); ZFREE(ConvertTask.UpdateItem.objID); ZFREE(ConvertTask.UpdateItem.ptrAudioFormat); ZFREE(ConvertTask.UpdateItem.ptrWavPath); ZFREE(ConvertTask.UpdateItem.ptrEncPath); ZFREE(ConvertTask.DiscAudioSrcPath); ZFREE(ConvertTask.DiscEncodePath); }
void array_clear(ARRAY A) { unsigned i ; ANODE *p, *q ; if (A->type == AY_SPLIT) { for(i = 0; i < A->size; i++) cell_destroy((CELL*)A->ptr+i) ; zfree(A->ptr, A->limit * sizeof(CELL)) ; } else if (A->type & AY_STR) { DUAL_LINK *table = (DUAL_LINK*) A->ptr ; for(i=0; (unsigned) i <= A->hmask; i++) { p = table[i].slink ; while(p) { q = p ; p = q->slink ; free_STRING(q->sval) ; cell_destroy(&q->cell) ; ZFREE(q) ; } } zfree(A->ptr, (A->hmask+1)*sizeof(DUAL_LINK)) ; } else if (A->type & AY_INT) { DUAL_LINK *table = (DUAL_LINK*) A->ptr ; for(i=0; (unsigned) i <= A->hmask; i++) { p = table[i].ilink ; while(p) { q = p ; p = q->ilink ; cell_destroy(&q->cell) ; ZFREE(q) ; } } zfree(A->ptr, (A->hmask+1)*sizeof(DUAL_LINK)) ; } memset(A, 0, sizeof(*A)) ; }
/* final code relocation set_code() as in set concrete */ void set_code(void) { /* set the main code which is active_code */ if (end_code_p || code_offset > 1) { int gl_offset = code_offset; if (NR_flag) code2op(OL_GL_NR, _HALT); else code2op(OL_GL, _HALT); *main_code_p = active_code; main_start = code_shrink(main_code_p, &main_size); next_label = main_start + gl_offset; execution_start = main_start; } else { /* only BEGIN */ zfree(code_base, INST_BYTES(PAGESZ)); code_base = 0; ZFREE(main_code_p); } /* set the END code */ if (end_code_p) { active_code = *end_code_p; code2op(_EXIT0, _HALT); *end_code_p = active_code; end_start = code_shrink(end_code_p, &end_size); } /* set the BEGIN code */ if (begin_code_p) { active_code = *begin_code_p; if (main_start) code2op(_JMAIN, _HALT); else code2op(_EXIT0, _HALT); *begin_code_p = active_code; begin_start = code_shrink(begin_code_p, &begin_size); execution_start = begin_start; } if (!execution_start) { /* program had functions but no pattern-action bodies */ execution_start = begin_start = (INST *) zmalloc(2 * sizeof(INST)); execution_start[0].op = _EXIT0; execution_start[1].op = _HALT; } }
/* shrinks executable code that's done to its final size */ INST * code_shrink(CODEBLOCK * p, size_t *sizep) { size_t oldsize = INST_BYTES(p->limit - p->base); size_t newsize = INST_BYTES(p->ptr - p->base); INST *retval; *sizep = newsize; retval = (INST *) zrealloc(p->base, oldsize, newsize); TRACE(("code_shrink old %p %lu, new %p %lu\n", p->base, oldsize, retval, newsize)); ZFREE(p); return retval; }
/* patch all break and continues for one loop */ void BC_clear(INST * B_address, INST * C_address) { register BC *p, *q; INST *source; if (error_state) return; p = bc_top; /* pop down to the mark node */ while (p->type) { source = code_base + p->source_offset; source->op = (int) ((p->type == 'B' ? B_address : C_address) - source); q = p; p = p->link; ZFREE(q); } /* remove the mark node */ bc_top = p->link; ZFREE(p); }
static FCALL_REC * first_pass(FCALL_REC * p) { FCALL_REC dummy; register FCALL_REC *q = &dummy; /* trails p */ q->link = p; while (p) { if (!p->callee->code) { /* callee never defined */ compile_error("function %s never defined", p->callee->name); /* delete p from list */ q->link = p->link; /* don't worry about freeing memory, we'll exit soon */ } /* note p->arg_list starts with last argument */ else if (!p->arg_list /* nothing to do */ || (!p->arg_cnt_checked && !arg_cnt_ok(p->callee, p->arg_list))) { q->link = p->link; /* delete p */ /* the ! arg_list case is not an error so free memory */ ZFREE(p); } else { /* keep p and set call_start */ q = p; switch (p->call_scope) { case SCOPE_MAIN: p->call_start = main_start; break; case SCOPE_BEGIN: p->call_start = begin_start; break; case SCOPE_END: p->call_start = end_start; break; case SCOPE_FUNCT: p->call_start = p->call->code; break; } } p = q->link; } return dummy.link; }
void list_dl_clear(list_dl_s *list) { list_dl_node_s *node = list->head_sentinel.next; while(node->next != NULL) { list_dl_node_s *tmp = node; node = node->next; ZFREE(tmp, list_dl_node_s); } list->head_sentinel.next = (list_dl_node_s*)&list->tail_sentinel; list->size = 0; }
/* * Dispose of the button memory */ void button_free(void) { button_backup *next; while (button_backups) { next = button_backups->next; if (button_backups->buttons) { button_mouse *bttn = button_backups->buttons, *bnext; while (bttn) { bnext = bttn->next; if (bttn->label) (void)string_free(bttn->label); FREE(bttn); bttn = bnext; } button_backups->buttons = NULL; } if (button_backups->buttons_1d) { FREE(button_backups->buttons_1d); } FREE(button_backups); button_backups = next; } button_backups = NULL; if (button_stack) { button_mouse *bttn = button_stack, *bnext; while (bttn) { bnext = bttn->next; if (bttn->label) (void)string_free(bttn->label); FREE(bttn); bttn = bnext; } button_stack = NULL; } if (button_1d_list) { ZFREE(button_1d_list); } button_num = 0; button_1d_start_x = 0; button_1d_start_y = 0; button_1d_length = 0; button_1d_num = 0; mouse_press = 0; }
static void clear_aloop_stack(ALOOP_STATE * top) { ALOOP_STATE *q; do { while (top->ptr < top->limit) { free_STRING(*top->ptr); top->ptr++; } if (top->base < top->limit) { zfree(top->base, (unsigned) (top->limit - top->base) * sizeof(STRING *)); } q = top; top = q->link; ZFREE(q); } while (top); }
int emptyPlaylist () { PZDQUEUE vQ = &g_imageView.playList; PIMAGE_NODE varNode = NULL; PZDNODE next = NULL; if (vQ == NULL) return -1; ZUtilStartQScan (vQ); next = ZUtilGetQHead (vQ); while ((varNode = (PIMAGE_NODE) ZUtilGetNextQNodeEx (&next))) { ZUtilRemoveNodeFromScan (vQ, &varNode->next); deleteImageNode (varNode); ZFREE (varNode); } ZUtilStopQScan (vQ); return 0; }
/* patch a jump on the jmp_stack */ void patch_jmp(INST * target) { register JMP *p; register INST *source; /* jmp starts here */ if (!error_state) { #ifdef DEBUG if (!jmp_top) bozo("jmp stack underflow"); #endif p = jmp_top; jmp_top = p->link; source = p->source_offset + code_base; source->op = (int) (target - source); ZFREE(p); } }
void array_load( ARRAY A, size_t cnt) { CELL *cells ; /* storage for A[1..cnt] */ size_t i ; /* index into cells[] */ if (A->type != AY_SPLIT || A->limit < (unsigned) cnt) { array_clear(A) ; A->limit = (unsigned) ( (cnt & (size_t) ~3) + 4 ) ; A->ptr = zmalloc(A->limit*sizeof(CELL)) ; A->type = AY_SPLIT ; } else { for(i=0; (unsigned) i < A->size; i++) cell_destroy((CELL*)A->ptr + i) ; } cells = (CELL*) A->ptr ; A->size = cnt ; if (cnt > MAX_SPLIT) { SPLIT_OV *p = split_ov_list ; SPLIT_OV *q ; split_ov_list = (SPLIT_OV*) 0 ; i = MAX_SPLIT ; while( p ) { cells[i].type = C_MBSTRN ; cells[i].ptr = (PTR) p->sval ; q = p ; p = q->link ; ZFREE(q) ; i++ ; } cnt = MAX_SPLIT ; } for(i=0; i < cnt; i++) { cells[i].type = C_MBSTRN ; cells[i].ptr = split_buff[i] ; } }
void FreeKuroLRC(KuroLRC *lrc) { int i, length; GList *list = NULL; KuroLyric *lyric = NULL; if(!lrc) return; /* Foreach the lyric glist */ length = g_list_length(lrc->lyric); for(i=0; i<length; i++) { list = g_list_nth(lrc->lyric, i); if(list->data == NULL) continue; lyric = (KuroLyric*)list->data; FreeKuroLyric(lyric); } g_list_free(lrc->lyric); ZFREE(lrc); }
bool list_dl_remove(list_dl_s *list, const void *data) { list_dl_node_s *node = list->head_sentinel.next; while(node->next != NULL) { if(data == node->data) { node->prev->next = node->next; node->next->prev = node->prev; list->size--; ZFREE(node, list_dl_node_s); return TRUE; } node = node->next; } return NULL; }
unsigned code_pop(INST * target) { register MC *p; unsigned len; int target_offset; if (error_state) return 0; #ifdef DEBUG if (!mc_top) bozo("mc underflow"); #endif p = mc_top; mc_top = p->link; len = p->len; while (target + len >= code_warn) { target_offset = (int) (target - code_base); code_grow(); target = code_base + target_offset; } if (len) { memcpy(target, p->code, len * sizeof(INST)); zfree(p->code, len * sizeof(INST)); } if (p->scope != NO_SCOPE) { target_offset = (int) (target - code_base); relocate_resolve_list(p->scope, p->move_level, p->fbp, p->offset, len, target_offset - p->offset); } ZFREE(p); code_move_level--; return len; }
bool list_dl_remove_matching(list_dl_s *list, result_callback_function *match, void *args) { list_dl_node_s *node = list->head_sentinel.next; while(node->next != NULL) { ya_result ret = match(node->data, args); if(ret != 0) { node->prev->next = node->next; node->next->prev = node->prev; list->size--; ZFREE(node, list_dl_node_s); return TRUE; } node = node->next; } return NULL; }
void inflate_blocks_reset( inflate_blocks_statef *s, z_streamp z, uLongf *c) { if (c != Z_NULL) *c = s->check; if (s->mode == BTREE || s->mode == DTREE) ZFREE(z, s->sub.trees.blens); if (s->mode == CODES) inflate_codes_free(s->sub.decode.codes, z); s->mode = TYPE; #ifdef DEFL64 s->treetype = 0; #endif s->bitk = 0; s->bitb = 0; s->read = s->write = s->window; if (s->checkfn != Z_NULL) z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0); Tracev((stderr, "inflate: blocks reset\n")); }
void resolve_fcalls(void) { register FCALL_REC *p, *old_list, *new_list; int progress; /* a flag */ old_list = first_pass(resolve_list); new_list = (FCALL_REC *) 0; progress = 0; while (1) { if (!old_list) { /* flop the lists */ old_list = new_list; if (!old_list /* nothing left */ || !progress /* can't do any more */ ) return; new_list = (FCALL_REC *) 0; progress = 0; } p = old_list; old_list = p->link; if ((p->arg_list = call_arg_check(p->callee, p->arg_list, p->call_start))) { /* still have work to do , put on new_list */ progress |= check_progress; p->link = new_list; new_list = p; } else { /* done with p */ progress = 1; ZFREE(p); } } }
static void xfr_input_stream_close(input_stream *is) { xfr_input_stream_data *data = (xfr_input_stream_data*)is->data; if(data->need_cleanup_tsig) { log_err("TSIG has not been cleared"); data->need_cleanup_tsig = FALSE; } output_stream_close(&data->pipe_stream_output); input_stream_close(&data->pipe_stream_input); free(data->first_soa_record); #ifdef DEBUG memset(data, 0xfe, sizeof(xfr_input_stream_data)); #endif ZFREE(data, xfr_input_stream_data); // used to be leaked ? input_stream_set_void(is); }
int CleanTheDirtyTrack(char *SrcPath, int nIsDeleteSrc) { int nRetVal = ZAPP_FAILED; char *DiscEncodePath = NULL; if(SrcPath == NULL) { return nRetVal; } DiscEncodePath = calloc(sizeof(char), (strlen(SrcPath)+BUF_64_BITS)); ENCODE_AUDIO_TYPE eAudioType; eAudioType = GetAudioType(ConvertTask.CurEncodeItem.ptrAudioFormat); switch(eAudioType) { case MP3_AUDIO: BuildConvertingPath(SrcPath, AUDIO_MP3_EXT, DiscEncodePath); break; case AAC_AUDIO: BuildConvertingPath(SrcPath, AUDIO_AAC_EXT, DiscEncodePath); break; case FLAC_AUDIO: BuildConvertingPath(SrcPath, AUDIO_FLAC_EXT, DiscEncodePath); break; default: break; } if(nIsDeleteSrc) { remove(SrcPath); } remove(DiscEncodePath); ZFREE(DiscEncodePath); nRetVal = ZAPP_SUCCESS; return nRetVal; }
static void ParseKuroLyric(KuroLyric *lyric, const gchar *buf, regex_t *regexLyric) { regmatch_t matches[LYRICS_REGMATCH_LEN]; gchar tmpArray[BUF_128]; KuroWord *word = NULL; KuroWord *wordPrev = NULL; GList *list = NULL; gint index; guint offset = 0; if(!buf) return; index = 0; while(index != -1) { if(regexec(regexLyric, &buf[index], LYRICS_REGMATCH_LEN, matches, 0)==REG_NOMATCH) { //ZInfo1(DBG_INIT,"Not match!!!"); //artist or title lyric->words = g_string_append(lyric->words, &buf[index]); /* Remove the last one */ list = g_list_last(lyric->word); if(list != NULL) { lyric->word = g_list_remove_link(lyric->word, list); ZFREE(list->data); g_list_free_1(list); } return; } /* Create new lyrics */ word = (KuroWord*)malloc(sizeof(KuroWord)); word->ms.start = -1; word->ms.end = -1; word->offset = 0; word->length = 0; /* words->ms.start */ memset(tmpArray, 0, BUF_128); strncpy(tmpArray, &buf[index+matches[1].rm_so], matches[1].rm_eo-matches[1].rm_so); word->ms.start = String2Ms(tmpArray); /* words->word */ memset(tmpArray, 0, BUF_128); strncpy(tmpArray, &buf[index+matches[2].rm_so], matches[2].rm_eo-matches[2].rm_so); word->offset = offset; word->length = matches[2].rm_eo-matches[2].rm_so; offset += word->length; lyric->words = g_string_append(lyric->words, tmpArray); if(wordPrev != NULL) wordPrev->ms.end = word->ms.start; /* append to list */ lyric->word = g_list_append(lyric->word, word); wordPrev = word; if(matches[3].rm_so != -1) { index += matches[3].rm_so; } else { index = -1; } } }
/* user called close() on input file */ void FINclose(FIN * fin) { FINsemi_close(fin); ZFREE(fin); }
void pw_pgsql_exit(void) { ZFREE(server); ZFREE(port_s); port = -1; ZFREE(user); ZFREE(pw); ZFREE(db); ZFREE(crypto); ZFREE(sqlreq_getpw); ZFREE(sqlreq_getuid); ZFREE(sql_default_uid); ZFREE(sqlreq_getgid); ZFREE(sql_default_gid); ZFREE(sqlreq_getdir); #ifdef QUOTAS ZFREE(sqlreq_getqta_fs); ZFREE(sqlreq_getqta_sz); #endif #ifdef RATIOS ZFREE(sqlreq_getratio_ul); ZFREE(sqlreq_getratio_dl); #endif #ifdef THROTTLING ZFREE(sqlreq_getbandwidth_ul); ZFREE(sqlreq_getbandwidth_dl); #endif }
void processInsertEncode(IXML_Document * persXmlDoc,U32 * InserID) { int i, numPending; IXML_NodeList *nodeList; char *xmlBuff; char * xmlBuff2; IXML_Node *node; U32 tempId; char persFile[128]; INSERT_PENDING sInsertP;/* for InsertPending table */ ENC_PENDING sEncodeP; U32 affectedDiscId = 0; U32 prevDiscId; int b_updated = 0; sprintf(persFile, ZRIP_OLD_TASKFILE); /* first test if have rip interupt */ if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "WavPending")) != NULL){ if ((numPending = ixmlNodeList_length(nodeList)) != 0){ if (numPending != 1){ goto funcOut; } if ((node = ixmlNodeList_item(nodeList, 0)) != NULL){ if ((xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId")) != NULL){ sscanf(xmlBuff,"%x",&affectedDiscId); xmlBuff2=ixmlElement_getAttribute((IXML_Element *)node, TOTAL_FRMTAG); if(xmlBuff2) { sInsertP.uCDID = affectedDiscId; sInsertP.ptrFrames = strdup(xmlBuff2); InsertPendingTask(INSERTPENDING, &sInsertP); ZFREE(sInsertP.ptrFrames); /* Insert in to database */ } if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){ ZError(DBG_ZRIP, "Failed to remove <WavPending>"); } else{ b_updated = 1; } } } } ixmlNodeList_free(nodeList); } /* second test if have EncPending */ if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "EncPending")) == NULL){ goto funcOut; } if ((numPending = ixmlNodeList_length(nodeList)) == 0){ ixmlNodeList_free(nodeList); goto funcOut; } prevDiscId = 0; node = NULL; for (i = 0; i < numPending; i++){ if ((node = ixmlNodeList_item(nodeList, i)) == NULL){ continue; } xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId"); if (!xmlBuff){ continue; } sscanf(xmlBuff,"%x",&tempId); if (affectedDiscId == tempId){ continue; } /* getAudioFormat */ xmlBuff = NULL; xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "AudioFormat"); if (!xmlBuff){ continue; } else{ sEncodeP.ptrAudioFormat = strdup(xmlBuff); } if(strncasecmp(xmlBuff, AUDIO_MP3_TYPE, 3) == 0) { sEncodeP.ptrFormatCfg = strdup("128"); } else sEncodeP.ptrFormatCfg = strdup("0"); /* getpbject */ xmlBuff = NULL; xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "objid"); if (!xmlBuff){ ZFREE(sEncodeP.ptrAudioFormat); ZFREE(sEncodeP.ptrFormatCfg); continue; } else{ sEncodeP.objID = strdup(xmlBuff); } InsertPendingTask(ENCPENDING,&sEncodeP); ZFREE(sEncodeP.ptrAudioFormat); ZFREE(sEncodeP.ptrFormatCfg); ZFREE(sEncodeP.objID); /* insert database */ } for (i = 0; i < numPending; i++){ if ((node = ixmlNodeList_item(nodeList, i)) == NULL){ continue; } if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){ ZError(DBG_ZRIP, "Failed to remove <WavPending>"); } } /* remove all child */ b_updated = 1; ixmlNodeList_free(nodeList); funcOut: if ( affectedDiscId){ /* delete no use */ *InserID = affectedDiscId; } if ( b_updated && ixmlUpdateDocument(persXmlDoc, persFile) == -1){ dprintf("Unable to write file path->%s", persFile); } return; }
void execute(INST * cdp, /* code ptr, start execution here */ CELL *sp, /* eval_stack pointer */ CELL *fp) /* frame ptr into eval_stack for user defined functions */ { /* some useful temporaries */ CELL *cp; int t; unsigned tu; /* save state for array loops via a stack */ ALOOP_STATE *aloop_state = (ALOOP_STATE *) 0; /* for moving the eval stack on deep recursion */ CELL *old_stack_base = 0; CELL *old_sp = 0; #ifdef DEBUG CELL *entry_sp = sp; #endif int force_exit = (end_start == 0); if (fp) { /* we are a function call, check for deep recursion */ if (sp > stack_danger) { /* change stacks */ old_stack_base = stack_base; old_sp = sp; stack_base = (CELL *) zmalloc(sizeof(CELL) * EVAL_STACK_SIZE); stack_danger = stack_base + DANGER; sp = stack_base; /* waste 1 slot for ANSI, actually large model msdos breaks in RET if we don't */ #ifdef DEBUG entry_sp = sp; #endif } else old_stack_base = (CELL *) 0; } while (1) { TRACE(("execute %s sp(%ld:%s)\n", da_op_name(cdp), (long) (sp - stack_base), da_type_name(sp))); switch ((cdp++)->op) { /* HALT only used by the disassemble now ; this remains so compilers don't offset the jump table */ case _HALT: case _STOP: /* only for range patterns */ #ifdef DEBUG if (sp != entry_sp + 1) bozo("stop0"); #endif return; case _PUSHC: inc_sp(); cellcpy(sp, (cdp++)->ptr); break; case _PUSHD: inc_sp(); sp->type = C_DOUBLE; sp->dval = *(double *) (cdp++)->ptr; break; case _PUSHS: inc_sp(); sp->type = C_STRING; sp->ptr = (cdp++)->ptr; string(sp)->ref_cnt++; break; case F_PUSHA: cp = (CELL *) cdp->ptr; if (cp != field) { if (nf < 0) split_field0(); if (!(cp >= NF && cp <= LAST_PFIELD)) { /* it is a real field $1, $2 ... If it is greater than $NF, we have to make sure it is set to "" so that (++|--) and g?sub() work right */ t = field_addr_to_index(cp); if (t > nf) { cp->type = C_STRING; cp->ptr = (PTR) & null_str; null_str.ref_cnt++; } } } /* fall thru */ case _PUSHA: case A_PUSHA: inc_sp(); sp->ptr = (cdp++)->ptr; break; case _PUSHI: /* put contents of next address on stack */ inc_sp(); cellcpy(sp, (cdp++)->ptr); break; case L_PUSHI: /* put the contents of a local var on stack, cdp->op holds the offset from the frame pointer */ inc_sp(); cellcpy(sp, fp + (cdp++)->op); break; case L_PUSHA: /* put a local address on eval stack */ inc_sp(); sp->ptr = (PTR) (fp + (cdp++)->op); break; case F_PUSHI: /* push contents of $i cdp[0] holds & $i , cdp[1] holds i */ inc_sp(); if (nf < 0) split_field0(); cp = (CELL *) cdp->ptr; t = (cdp + 1)->op; cdp += 2; if (t <= nf) cellcpy(sp, cp); else { /* an unset field */ sp->type = C_STRING; sp->ptr = (PTR) & null_str; null_str.ref_cnt++; } break; case NF_PUSHI: inc_sp(); if (nf < 0) split_field0(); cellcpy(sp, NF); break; case FE_PUSHA: if (sp->type != C_DOUBLE) cast1_to_d(sp); tu = d_to_index(sp->dval); if (tu && nf < 0) split_field0(); sp->ptr = (PTR) field_ptr((int) tu); if ((int) tu > nf) { /* make sure it is set to "" */ cp = (CELL *) sp->ptr; cell_destroy(cp); cp->type = C_STRING; cp->ptr = (PTR) & null_str; null_str.ref_cnt++; } break; case FE_PUSHI: if (sp->type != C_DOUBLE) cast1_to_d(sp); tu = d_to_index(sp->dval); if (nf < 0) split_field0(); if ((int) tu <= nf) { cellcpy(sp, field_ptr((int) tu)); } else { sp->type = C_STRING; sp->ptr = (PTR) & null_str; null_str.ref_cnt++; } break; case AE_PUSHA: /* top of stack has an expr, cdp->ptr points at an array, replace the expr with the cell address inside the array */ cp = array_find((ARRAY) (cdp++)->ptr, sp, CREATE); cell_destroy(sp); sp->ptr = (PTR) cp; break; case AE_PUSHI: /* top of stack has an expr, cdp->ptr points at an array, replace the expr with the contents of the cell inside the array */ cp = array_find((ARRAY) (cdp++)->ptr, sp, CREATE); cell_destroy(sp); cellcpy(sp, cp); break; case LAE_PUSHI: /* sp[0] is an expression cdp->op is offset from frame pointer of a CELL which has an ARRAY in the ptr field, replace expr with array[expr] */ if (fp != 0) { cp = array_find((ARRAY) fp[(cdp++)->op].ptr, sp, CREATE); cell_destroy(sp); cellcpy(sp, cp); } break; case LAE_PUSHA: /* sp[0] is an expression cdp->op is offset from frame pointer of a CELL which has an ARRAY in the ptr field, replace expr with & array[expr] */ if (fp != 0) { cp = array_find((ARRAY) fp[(cdp++)->op].ptr, sp, CREATE); cell_destroy(sp); sp->ptr = (PTR) cp; } break; case LA_PUSHA: /* cdp->op is offset from frame pointer of a CELL which has an ARRAY in the ptr field. Push this ARRAY on the eval stack */ if (fp != 0) { inc_sp(); sp->ptr = fp[(cdp++)->op].ptr; } break; case SET_ALOOP: { ALOOP_STATE *ap = ZMALLOC(ALOOP_STATE); size_t vector_size; ap->var = (CELL *) sp[-1].ptr; ap->base = ap->ptr = array_loop_vector((ARRAY) sp->ptr, &vector_size); ap->limit = ap->base + vector_size; sp -= 2; /* push onto aloop stack */ ap->link = aloop_state; aloop_state = ap; cdp += cdp->op; } break; case ALOOP: { ALOOP_STATE *ap = aloop_state; if (ap != 0 && (ap->ptr < ap->limit)) { cell_destroy(ap->var); ap->var->type = C_STRING; ap->var->ptr = (PTR) * ap->ptr++; cdp += cdp->op; } else { cdp++; } } break; case POP_AL: { /* finish up an array loop */ ALOOP_STATE *ap = aloop_state; if (ap != 0) { aloop_state = ap->link; while (ap->ptr < ap->limit) { free_STRING(*ap->ptr); ap->ptr++; } if (ap->base < ap->limit) { zfree(ap->base, ((unsigned) (ap->limit - ap->base) * sizeof(STRING *))); } ZFREE(ap); } } break; case _POP: cell_destroy(sp); sp--; break; case _ASSIGN: /* top of stack has an expr, next down is an address, put the expression in *address and replace the address with the expression */ /* don't propagate type C_MBSTRN */ if (sp->type == C_MBSTRN) check_strnum(sp); sp--; cell_destroy(((CELL *) sp->ptr)); cellcpy(sp, cellcpy(sp->ptr, sp + 1)); cell_destroy(sp + 1); break; case F_ASSIGN: /* assign to a field */ if (sp->type == C_MBSTRN) check_strnum(sp); sp--; field_assign((CELL *) sp->ptr, sp + 1); cell_destroy(sp + 1); cellcpy(sp, (CELL *) sp->ptr); break; case _ADD_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; if (cp->type != C_DOUBLE) cast1_to_d(cp); #ifdef SW_FP_CHECK /* specific to V7 and XNX23A */ clrerr(); #endif cp->dval += (sp--)->dval; #ifdef SW_FP_CHECK fpcheck(); #endif sp->type = C_DOUBLE; sp->dval = cp->dval; break; case _SUB_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; if (cp->type != C_DOUBLE) cast1_to_d(cp); #ifdef SW_FP_CHECK clrerr(); #endif cp->dval -= (sp--)->dval; #ifdef SW_FP_CHECK fpcheck(); #endif sp->type = C_DOUBLE; sp->dval = cp->dval; break; case _MUL_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; if (cp->type != C_DOUBLE) cast1_to_d(cp); #ifdef SW_FP_CHECK clrerr(); #endif cp->dval *= (sp--)->dval; #ifdef SW_FP_CHECK fpcheck(); #endif sp->type = C_DOUBLE; sp->dval = cp->dval; break; case _DIV_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; if (cp->type != C_DOUBLE) cast1_to_d(cp); #ifdef NOINFO_SIGFPE CHECK_DIVZERO(sp->dval); #endif #ifdef SW_FP_CHECK clrerr(); #endif cp->dval /= (sp--)->dval; #ifdef SW_FP_CHECK fpcheck(); #endif sp->type = C_DOUBLE; sp->dval = cp->dval; break; case _MOD_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; if (cp->type != C_DOUBLE) cast1_to_d(cp); #ifdef NOINFO_SIGFPE CHECK_DIVZERO(sp->dval); #endif cp->dval = fmod(cp->dval, (sp--)->dval); sp->type = C_DOUBLE; sp->dval = cp->dval; break; case _POW_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; if (cp->type != C_DOUBLE) cast1_to_d(cp); cp->dval = pow(cp->dval, (sp--)->dval); sp->type = C_DOUBLE; sp->dval = cp->dval; break; /* will anyone ever use these ? */ case F_ADD_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; cast1_to_d(cellcpy(&tc, cp)); #ifdef SW_FP_CHECK clrerr(); #endif tc.dval += (sp--)->dval; #ifdef SW_FP_CHECK fpcheck(); #endif sp->type = C_DOUBLE; sp->dval = tc.dval; field_assign(cp, &tc); break; case F_SUB_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; cast1_to_d(cellcpy(&tc, cp)); #ifdef SW_FP_CHECK clrerr(); #endif tc.dval -= (sp--)->dval; #ifdef SW_FP_CHECK fpcheck(); #endif sp->type = C_DOUBLE; sp->dval = tc.dval; field_assign(cp, &tc); break; case F_MUL_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; cast1_to_d(cellcpy(&tc, cp)); #ifdef SW_FP_CHECK clrerr(); #endif tc.dval *= (sp--)->dval; #ifdef SW_FP_CHECK fpcheck(); #endif sp->type = C_DOUBLE; sp->dval = tc.dval; field_assign(cp, &tc); break; case F_DIV_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; cast1_to_d(cellcpy(&tc, cp)); #ifdef NOINFO_SIGFPE CHECK_DIVZERO(sp->dval); #endif #ifdef SW_FP_CHECK clrerr(); #endif tc.dval /= (sp--)->dval; #ifdef SW_FP_CHECK fpcheck(); #endif sp->type = C_DOUBLE; sp->dval = tc.dval; field_assign(cp, &tc); break; case F_MOD_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; cast1_to_d(cellcpy(&tc, cp)); #ifdef NOINFO_SIGFPE CHECK_DIVZERO(sp->dval); #endif tc.dval = fmod(tc.dval, (sp--)->dval); sp->type = C_DOUBLE; sp->dval = tc.dval; field_assign(cp, &tc); break; case F_POW_ASG: if (sp->type != C_DOUBLE) cast1_to_d(sp); cp = (CELL *) (sp - 1)->ptr; cast1_to_d(cellcpy(&tc, cp)); tc.dval = pow(tc.dval, (sp--)->dval); sp->type = C_DOUBLE; sp->dval = tc.dval; field_assign(cp, &tc); break; case _ADD: sp--; if (TEST2(sp) != TWO_DOUBLES) cast2_to_d(sp); #ifdef SW_FP_CHECK clrerr(); #endif sp[0].dval += sp[1].dval; #ifdef SW_FP_CHECK fpcheck(); #endif break; case _SUB: sp--; if (TEST2(sp) != TWO_DOUBLES) cast2_to_d(sp); #ifdef SW_FP_CHECK clrerr(); #endif sp[0].dval -= sp[1].dval; #ifdef SW_FP_CHECK fpcheck(); #endif break; case _MUL: sp--; if (TEST2(sp) != TWO_DOUBLES) cast2_to_d(sp); #ifdef SW_FP_CHECK clrerr(); #endif sp[0].dval *= sp[1].dval; #ifdef SW_FP_CHECK fpcheck(); #endif break; case _DIV: sp--; if (TEST2(sp) != TWO_DOUBLES) cast2_to_d(sp); #ifdef NOINFO_SIGFPE CHECK_DIVZERO(sp[1].dval); #endif #ifdef SW_FP_CHECK clrerr(); #endif sp[0].dval /= sp[1].dval; #ifdef SW_FP_CHECK fpcheck(); #endif break; case _MOD: sp--; if (TEST2(sp) != TWO_DOUBLES) cast2_to_d(sp); #ifdef NOINFO_SIGFPE CHECK_DIVZERO(sp[1].dval); #endif sp[0].dval = fmod(sp[0].dval, sp[1].dval); break; case _POW: sp--; if (TEST2(sp) != TWO_DOUBLES) cast2_to_d(sp); sp[0].dval = pow(sp[0].dval, sp[1].dval); break; case _NOT: /* evaluates to 0.0 or 1.0 */ reswitch_1: switch (sp->type) { case C_NOINIT: sp->dval = 1.0; break; case C_DOUBLE: sp->dval = sp->dval != 0.0 ? 0.0 : 1.0; break; case C_FIELDWIDTHS: case C_STRING: sp->dval = string(sp)->len ? 0.0 : 1.0; free_STRING(string(sp)); break; case C_STRNUM: /* test as a number */ sp->dval = sp->dval != 0.0 ? 0.0 : 1.0; free_STRING(string(sp)); break; case C_MBSTRN: check_strnum(sp); goto reswitch_1; default: bozo("bad type on eval stack"); } sp->type = C_DOUBLE; break; case _TEST: /* evaluates to 0.0 or 1.0 */ reswitch_2: switch (sp->type) { case C_NOINIT: sp->dval = 0.0; break; case C_DOUBLE: sp->dval = sp->dval != 0.0 ? 1.0 : 0.0; break; case C_FIELDWIDTHS: case C_STRING: sp->dval = string(sp)->len ? 1.0 : 0.0; free_STRING(string(sp)); break; case C_STRNUM: /* test as a number */ sp->dval = sp->dval != 0.0 ? 1.0 : 0.0; free_STRING(string(sp)); break; case C_MBSTRN: check_strnum(sp); goto reswitch_2; default: bozo("bad type on eval stack"); } sp->type = C_DOUBLE; break; case _UMINUS: if (sp->type != C_DOUBLE) cast1_to_d(sp); sp->dval = -sp->dval; break; case _UPLUS: if (sp->type != C_DOUBLE) cast1_to_d(sp); break; case _CAT: { size_t len1, len2; char *str1, *str2; STRING *b; sp--; if (TEST2(sp) != TWO_STRINGS) cast2_to_s(sp); str1 = string(sp)->str; len1 = string(sp)->len; str2 = string(sp + 1)->str; len2 = string(sp + 1)->len; b = new_STRING0(len1 + len2); memcpy(b->str, str1, len1); memcpy(b->str + len1, str2, len2); free_STRING(string(sp)); free_STRING(string(sp + 1)); sp->ptr = (PTR) b; break; } case _PUSHINT: inc_sp(); sp->type = (short) (cdp++)->op; break; case _BUILTIN: case _PRINT: sp = (*(PF_CP) (cdp++)->ptr) (sp); break; case _POST_INC: cp = (CELL *) sp->ptr; if (cp->type != C_DOUBLE) cast1_to_d(cp); sp->type = C_DOUBLE; sp->dval = cp->dval; cp->dval += 1.0; break; case _POST_DEC: cp = (CELL *) sp->ptr; if (cp->type != C_DOUBLE) cast1_to_d(cp); sp->type = C_DOUBLE; sp->dval = cp->dval; cp->dval -= 1.0; break; case _PRE_INC: cp = (CELL *) sp->ptr; if (cp->type != C_DOUBLE) cast1_to_d(cp); sp->dval = cp->dval += 1.0; sp->type = C_DOUBLE; break; case _PRE_DEC: cp = (CELL *) sp->ptr; if (cp->type != C_DOUBLE) cast1_to_d(cp); sp->dval = cp->dval -= 1.0; sp->type = C_DOUBLE; break; case F_POST_INC: cp = (CELL *) sp->ptr; cellcpy(&tc, cp); cast1_to_d(&tc); sp->type = C_DOUBLE; sp->dval = tc.dval; tc.dval += 1.0; field_assign(cp, &tc); break; case F_POST_DEC: cp = (CELL *) sp->ptr; cellcpy(&tc, cp); cast1_to_d(&tc); sp->type = C_DOUBLE; sp->dval = tc.dval; tc.dval -= 1.0; field_assign(cp, &tc); break; case F_PRE_INC: cp = (CELL *) sp->ptr; cast1_to_d(cellcpy(sp, cp)); sp->dval += 1.0; field_assign(cp, sp); break; case F_PRE_DEC: cp = (CELL *) sp->ptr; cast1_to_d(cellcpy(sp, cp)); sp->dval -= 1.0; field_assign(cp, sp); break; case _JMP: cdp += cdp->op; break; case _JNZ: /* jmp if top of stack is non-zero and pop stack */ if (test(sp)) cdp += cdp->op; else cdp++; cell_destroy(sp); sp--; break; case _JZ: /* jmp if top of stack is zero and pop stack */ if (!test(sp)) cdp += cdp->op; else cdp++; cell_destroy(sp); sp--; break; case _LJZ: /* special jump for logical and */ /* this is always preceded by _TEST */ if (sp->dval == 0.0) { /* take jump, but don't pop stack */ cdp += cdp->op; } else { /* pop and don't jump */ sp--; cdp++; } break; case _LJNZ: /* special jump for logical or */ /* this is always preceded by _TEST */ if (sp->dval != 0.0) { /* take jump, but don't pop stack */ cdp += cdp->op; } else { /* pop and don't jump */ sp--; cdp++; } break; /* the relation operations */ /* compare() makes sure string ref counts are OK */ case _EQ: t = compare(--sp); sp->type = C_DOUBLE; sp->dval = t == 0 ? 1.0 : 0.0; break; case _NEQ: t = compare(--sp); sp->type = C_DOUBLE; sp->dval = t ? 1.0 : 0.0; break; case _LT: t = compare(--sp); sp->type = C_DOUBLE; sp->dval = t < 0 ? 1.0 : 0.0; break; case _LTE: t = compare(--sp); sp->type = C_DOUBLE; sp->dval = t <= 0 ? 1.0 : 0.0; break; case _GT: t = compare(--sp); sp->type = C_DOUBLE; sp->dval = t > 0 ? 1.0 : 0.0; break; case _GTE: t = compare(--sp); sp->type = C_DOUBLE; sp->dval = t >= 0 ? 1.0 : 0.0; break; case _MATCH0: /* does $0 match, the RE at cdp? */ inc_sp(); if (field->type >= C_STRING) { sp->type = C_DOUBLE; sp->dval = (REtest(string(field)->str, string(field)->len, cast_to_re((cdp++)->ptr)) ? 1.0 : 0.0); break /* the case */ ; } else { cellcpy(sp, field); /* and FALL THRU */ } case _MATCH1: /* does expr at sp[0] match RE at cdp */ if (sp->type < C_STRING) cast1_to_s(sp); t = REtest(string(sp)->str, string(sp)->len, cast_to_re((cdp++)->ptr)); free_STRING(string(sp)); sp->type = C_DOUBLE; sp->dval = t ? 1.0 : 0.0; break; case _MATCH2: /* does sp[-1] match sp[0] as re */ cast_to_RE(sp); if ((--sp)->type < C_STRING) cast1_to_s(sp); t = REtest(string(sp)->str, string(sp)->len, cast_to_re((sp + 1)->ptr)); free_STRING(string(sp)); no_leaks_re_ptr((sp + 1)->ptr); sp->type = C_DOUBLE; sp->dval = t ? 1.0 : 0.0; break; case A_LENGTH: sp--; sp->type = C_DOUBLE; sp->dval = (double) (((ARRAY) ((sp + 0)->ptr))->size); break; case A_TEST: /* entry : sp[0].ptr-> an array sp[-1] is an expression we compute (expression in array) */ sp--; cp = array_find((sp + 1)->ptr, sp, NO_CREATE); cell_destroy(sp); sp->type = C_DOUBLE; sp->dval = (cp != (CELL *) 0) ? 1.0 : 0.0; break; case A_DEL: /* sp[0].ptr -> array sp[-1] is an expr delete array[expr] */ array_delete(sp->ptr, sp - 1); cell_destroy(sp - 1); sp -= 2; break; case DEL_A: /* free all the array at once */ array_clear(sp->ptr); sp--; break; /* form a multiple array index */ case A_CAT: sp = array_cat(sp, (cdp++)->op); break; case _EXIT: if (sp->type != C_DOUBLE) cast1_to_d(sp); exit_code = d_to_i(sp->dval); sp--; /* fall thru */ case _EXIT0: if (force_exit) mawk_exit(exit_code); cdp = end_start; force_exit = 1; /* makes sure next exit exits */ if (begin_start) { free_codes("BEGIN", begin_start, begin_size); begin_start = 0; begin_size = 0; } if (main_start) { free_codes("MAIN", main_start, main_size); main_start = 0; main_size = 0; } sp = eval_stack - 1; /* might be in user function */ CLEAR_ALOOP_STACK(); /* ditto */ break; case _JMAIN: /* go from BEGIN code to MAIN code */ free_codes("BEGIN", begin_start, begin_size); begin_start = 0; begin_size = 0; cdp = main_start; break; case _OMAIN: if (!main_fin) open_main(); restart_label = cdp; cdp = next_label; break; case _NEXT: /* next might be inside an aloop -- clear stack */ CLEAR_ALOOP_STACK(); cdp = next_label; break; case _NEXTFILE: /* nextfile might be inside an aloop -- clear stack */ CLEAR_ALOOP_STACK(); FINsemi_close(main_fin); cdp = next_label; break; case OL_GL: { char *p; size_t len; if (!(p = FINgets(main_fin, &len))) { if (force_exit) mawk_exit(0); cdp = end_start; zfree(main_start, main_size); main_start = (INST *) 0; force_exit = 1; } else { set_field0(p, len); cdp = restart_label; rt_nr++; rt_fnr++; } } break; /* two kinds of OL_GL is a historical stupidity from working on a machine with very slow floating point emulation */ case OL_GL_NR: { char *p; size_t len; if (!(p = FINgets(main_fin, &len))) { if (force_exit) mawk_exit(0); cdp = end_start; zfree(main_start, main_size); main_start = (INST *) 0; force_exit = 1; } else { set_field0(p, len); cdp = restart_label; if (TEST2(NR) != TWO_DOUBLES) cast2_to_d(NR); NR->dval += 1.0; rt_nr++; FNR->dval += 1.0; rt_fnr++; } } break; case _RANGE: /* test a range pattern: pat1, pat2 { action } entry : cdp[0].op -- a flag, test pat1 if on else pat2 cdp[1].op -- offset of pat2 code from cdp cdp[2].op -- offset of action code from cdp cdp[3].op -- offset of code after the action from cdp cdp[4] -- start of pat1 code */ #define FLAG cdp[0].op #define PAT2 cdp[1].op #define ACTION cdp[2].op #define FOLLOW cdp[3].op #define PAT1 4 if (FLAG) /* test against pat1 */ { execute(cdp + PAT1, sp, fp); t = test(sp + 1); cell_destroy(sp + 1); if (t) FLAG = 0; else { cdp += FOLLOW; break; /* break the switch */ } } /* test against pat2 and then perform the action */ execute(cdp + PAT2, sp, fp); FLAG = test(sp + 1); cell_destroy(sp + 1); cdp += ACTION; break; /* function calls */ case _RET0: inc_sp(); sp->type = C_NOINIT; /* fall thru */ case _RET: #ifdef DEBUG if (sp != entry_sp + 1) bozo("ret"); #endif if (old_stack_base) /* reset stack */ { /* move the return value */ cellcpy(old_sp + 1, sp); cell_destroy(sp); zfree(stack_base, sizeof(CELL) * EVAL_STACK_SIZE); stack_base = old_stack_base; stack_danger = old_stack_base + DANGER; } /* return might be inside an aloop -- clear stack */ CLEAR_ALOOP_STACK(); return; case _CALL: /* cdp[0] holds ptr to "function block" cdp[1] holds number of input arguments */ { FBLOCK *fbp = (FBLOCK *) (cdp++)->ptr; int a_args = (cdp++)->op; /* actual number of args */ CELL *nfp = sp - a_args + 1; /* new fp for callee */ CELL *local_p = sp + 1; /* first local argument on stack */ char *type_p = 0; /* pts to type of an argument */ if (fbp->nargs) type_p = fbp->typev + a_args - 1; /* create space for locals */ t = fbp->nargs - a_args; /* t is number of locals */ while (t > 0) { t--; sp++; type_p++; sp->type = C_NOINIT; if ((type_p) != 0 && (*type_p == ST_LOCAL_ARRAY)) sp->ptr = (PTR) new_ARRAY(); } execute(fbp->code, sp, nfp); /* cleanup the callee's arguments */ /* putting return value at top of eval stack */ if ((type_p != 0) && (sp >= nfp)) { cp = sp + 1; /* cp -> the function return */ do { if (*type_p == ST_LOCAL_ARRAY) { if (sp >= local_p) { array_clear(sp->ptr); ZFREE((ARRAY) sp->ptr); } } else { cell_destroy(sp); } type_p--; sp--; } while (sp >= nfp); cellcpy(++sp, cp); cell_destroy(cp); } else sp++; /* no arguments passed */ } break; default: bozo("bad opcode"); } } }
void *ConvertThread(void *ctxt) { int nIsDir = 0; ENCODE_AUDIO_TYPE eAudioType; for(;;) { if(ConvertTask.nItemCount == 0) { break; } /*get encode item from the global var.*/ if((ConvertTask.eItemStatus == ITEM_INIT) &&(ConvertTask.CurEncodeItem.objID) &&(ConvertTask.CurEncodeItem.ptrAudioFormat) &&(ConvertTask.CurEncodeItem.ptrFormatCfg) ) { ZLock(&(ConvertTask.TaskItemLock)); ConvertTask.eThreadStatus = THREAD_START; ConvertTask.eItemStatus = ITEM_ENCODING; /*get the track path throught check the loacal database.*/ initMetaTrack(&(ConvertTask.TrackMeta)); /* Updated by Ke tao 2008-12-12*/ ZDBRipFindTrackMetadata(ConvertTask.ptrDBHandle, ConvertTask.CurEncodeItem.objID, &(ConvertTask.TrackMeta)); if(!ZUtilIsFilePresent(ConvertTask.TrackMeta.path, &nIsDir) || nIsDir || !checkExt(ConvertTask.TrackMeta.path, "wav")) /*if the track path isn't exists, as the normal quit*/ { DeletePendingTask(ENCPENDING, &ConvertTask.CurEncodeItem); ConvertTask.eItemStatus = ITEM_ENCODED; ConvertTask.eThreadStatus = THREAD_FINISHED; freeMetaTrack(&(ConvertTask.TrackMeta)); ZUnlock(&(ConvertTask.TaskItemLock)); continue; } ZFREE(ConvertTask.DiscAudioSrcPath); ZFREE(ConvertTask.DiscEncodePath); ConvertTask.DiscAudioSrcPath = strdup(ConvertTask.TrackMeta.path); ConvertTask.DiscEncodePath = calloc(sizeof(char), (strlen(ConvertTask.DiscAudioSrcPath)+BUF_64_BITS)); freeMetaTrack(&(ConvertTask.TrackMeta)); ZUnlock(&(ConvertTask.TaskItemLock)); } else { sleep(1); continue; } /*convert audio file to the eAudioType type.*/ eAudioType = GetAudioType(ConvertTask.CurEncodeItem.ptrAudioFormat); ConvertTask.eThreadStatus = THREAD_RUNNING; if(ConvertAudio(eAudioType, &ConvertTask.CurEncodeItem, ConvertTask.DiscAudioSrcPath, ConvertTask.DiscEncodePath) == ZAPP_FAILED) { ZLock(&(ConvertTask.TaskItemLock)); DeletePendingTask(ENCPENDING, &(ConvertTask.CurEncodeItem)); ConvertTask.eItemStatus = ITEM_ENCODED; ConvertTask.eThreadStatus = THREAD_FINISHED; ZFREE(ConvertTask.DiscAudioSrcPath); ZFREE(ConvertTask.DiscEncodePath); ZUnlock(&(ConvertTask.TaskItemLock)); continue; } /*write ID3 tag according the database.*/ if((eAudioType == MP3_AUDIO)||(eAudioType == FLAC_AUDIO)) { initMetaTrack(&(ConvertTask.TrackMeta)); /* Updated by Ke Tao 2008-12-12 */ ZDBRipFindTrackMetadata(ConvertTask.ptrDBHandle, ConvertTask.CurEncodeItem.objID, &(ConvertTask.TrackMeta)); WriteID3Tag(ConvertTask.DiscEncodePath, &(ConvertTask.TrackMeta)); freeMetaTrack(&(ConvertTask.TrackMeta)); } /*set update task to the zriptask database's updatapending table.*/ ZLock(&(ConvertTask.TaskItemLock)); ZFREE(ConvertTask.UpdateItem.objID); ZFREE(ConvertTask.UpdateItem.ptrAudioFormat); ZFREE(ConvertTask.UpdateItem.ptrWavPath); ZFREE(ConvertTask.UpdateItem.ptrEncPath); ConvertTask.UpdateItem.objID = strdup(ConvertTask.CurEncodeItem.objID); ConvertTask.UpdateItem.ptrAudioFormat = strdup(ConvertTask.CurEncodeItem.ptrAudioFormat); ConvertTask.UpdateItem.ptrWavPath = strdup(ConvertTask.DiscAudioSrcPath); ConvertTask.UpdateItem.ptrEncPath = strdup(ConvertTask.DiscEncodePath); InsertPendingTask(UPDATEPENDING, &(ConvertTask.UpdateItem)); /*Delete task to the zriptask database's EncPending table.*/ DeletePendingTask(ENCPENDING, &ConvertTask.CurEncodeItem); ConvertTask.eItemStatus = ITEM_ENCODED; ConvertTask.eThreadStatus = THREAD_FINISHED; ZUnlock(&(ConvertTask.TaskItemLock)); } return NULL; }
void FreeItem(PENC_PENDING ptrEncodeItem) { ZFREE(ptrEncodeItem->objID); ZFREE(ptrEncodeItem->ptrAudioFormat); ZFREE(ptrEncodeItem->ptrFormatCfg); }
int seq_read_fasta(SEQ *seq) { int b, c; charvec_t shdr = charvec_INIT(ckrealloc,ckfree); charvec_t sseq = charvec_INIT(ckrealloc,ckfree); if (feof(seq->fp) || ferror(seq->fp)) return 0; if (seq->count > 0) { if (seq->flags & SEQ_IS_SUBRANGE) { return 0; } else { seq->from = 1; seq->slen = -1; /* will be computed below */ } } if (seq->header) ZFREE(seq->header); if (seq->seq) ZFREE(seq->seq); seq->offset = ftell(seq->fp); /* --- header --- */ c = getnwc(seq->fp); if (c == '>') { while (c != '\n' && c != EOF) { char_append(&shdr, c); c = getc(seq->fp); } } else { un_getc(c, seq->fp); } if (ferror(seq->fp)) Fatalfr("seq_read(%s)", seq->fname); char_append(&shdr, 0); seq->header = shdr.a; seq->hlen = shdr.len; /* --- seq --- */ b = '\n'; c = getnwc(seq->fp); while ((c != EOF) && !(b == '\n' && c == '>')) { switch (nfasta_ctype[c]) { case Nfasta_nt: char_append(&sseq, c); break; case Nfasta_ws: /* skip space */ break; case Nfasta_amb: if (seq->flags & SEQ_ALLOW_AMB) { char_append(&sseq, c); break; } /* FALLTHRU */ default: fatalf("non-DNA character '%c' in sequence '%s'", c, seq->fname); break; } b = c; c = getc(seq->fp); } un_getc(c, seq->fp); if (ferror(seq->fp)) Fatalfr("seq_read(%s)", seq->fname); /* check conformance */ if (SEQ_LEN(seq) == -1) { char_append(&sseq, 0); charvec_fit(&sseq); seq->seq = (uchar*)sseq.a; seq->slen = sseq.len; if (seq->slen > 0) --seq->slen; /* don't include '\0' */ } else { charvec_t ssub = charvec_INIT(ckrealloc,ckfree); int i; if (SEQ_FROM(seq) < 1 || (int)sseq.len < SEQ_FROM(seq) || SEQ_TO(seq) < 1 || (int)sseq.len < SEQ_TO(seq) || SEQ_TO(seq) < SEQ_FROM(seq)) fatalf("range [%d,%d] incommensurate with sequence [%d,%d]", SEQ_FROM(seq), SEQ_TO(seq), 1, sseq.len); for (i = SEQ_FROM(seq); i <= SEQ_TO(seq); ++i) char_append(&ssub, sseq.a[i-1]); char_append(&ssub, 0); charvec_fini(&sseq); seq->seq = (uchar*)ssub.a; } seq->flags = seq->flags &~ SEQ_IS_REVCOMP; if (seq->flags & SEQ_DO_REVCOMP) { (void)seq_revcomp_inplace(seq); } if (seq->flags & SEQ_HAS_MASK) { (void)seq_mask_inplace(seq); } seq->count++; return 1; }
/***************************************************************************** ** ** FUNCTION NAME: main ** ** FUNCTION INPUTS: ** ** ** FUNCTION DESCRIPTION ** The program is convert the file which is the rip leave the audio file. ** ** FUNCTION OUTPUTS: ** ** HISTORY: ** ** 2008-6-30 HChen Created. ** ***************************************************************************** */ int main(int argc, char *argv[]) { int nCurrConvertNum = 0; int nTotalTrackNum = 0; int nCodePercent = 0; int nPreNumPending = 0; int nNumPending = 0; DATA_CHANGED_STATUS eDataChange = DATA_UNKNOWN; RegisterSignal(); LowItsPriority("Convert", "+19"); Initialize(); zripUpgare(); for(;;) { /*get the first record from db*/ ZLock(&(ConvertTask.TaskItemLock)); nNumPending = GetFirstTaskItemFromDB(&(ConvertTask.CurEncodeItem)); ConvertTask.nItemCount = nNumPending; ZUnlock(&(ConvertTask.TaskItemLock)); /*report update. why use at there(in order to handle the last record)*/ HandleUpdatePendingTask(); /*if no record, then exit*/ if(nNumPending == 0) { ZLockClose(&(ConvertTask.TaskItemLock)); ZDBClose(ConvertTask.ptrDBHandle); ZUtilStopThread(&(ConvertTask.ConverThread)); ZFREE(gObjID); FreeConvertTask(); exit(0); } /*if the first's objid of the db not equal the converting objid, then kill the convert thread.*/ /*in other word, the record of the db was deleted by other programm.*/ if((ConvertTask.eThreadStatus == THREAD_RUNNING) &&(ConvertTask.eItemStatus == ITEM_ENCODING) &&(gObjID != NULL)&&(ConvertTask.CurEncodeItem.objID != NULL) &&(strcmp(gObjID, ConvertTask.CurEncodeItem.objID))) { KillConvertProcess(); CleanTheDirtyTrack(ConvertTask.DiscAudioSrcPath, 1);/*clear all track, include the src track*/ goto Out; } else { /*the acctracknum and the numpending overlap one node, so minus 1*/ /*calculate the convert percent*/ if(ConvertTask.nAccTrackNum == 0 || nNumPending == 0) { nTotalTrackNum = ConvertTask.nAccTrackNum + nNumPending; } else { nTotalTrackNum = ConvertTask.nAccTrackNum + nNumPending - 1; } nCurrConvertNum = ConvertTask.nAccTrackNum; nCodePercent = (nCurrConvertNum*100)/nTotalTrackNum; /*Judge the data change.*/ if(nPreNumPending != nNumPending) { nPreNumPending = nNumPending; eDataChange = DATA_CHANGED; } if((ConvertTask.PreObjID != NULL) && (gObjID != NULL)) { if(strcmp(ConvertTask.PreObjID, gObjID)) { ZFREE(ConvertTask.PreObjID); ConvertTask.PreObjID = strdup(gObjID); eDataChange = DATA_CHANGED; } } /*Data changed, then report progress and update.*/ if(eDataChange == DATA_CHANGED) { eDataChange = DATA_UNKNOWN; ReportConvertProgress(nTotalTrackNum, nCurrConvertNum, nCodePercent, gObjID); } } Out: sleep(3); } return 0; }