/* * Find the EXTERNAL command which matches the given name 'param'. If there is * more than one possibility, make a popup menu of the matching commands and * allow the user to select one. Return the selected command. */ static char *lookup_external(char *param, int only_overriders) { int pass, num_disabled, num_matched, num_choices, cur_choice; size_t length = 0; char *cmdbuf = NULL; char **actions = 0; char **choices = 0; lynx_list_item_type *ptr = 0; for (pass = 0; pass < 2; pass++) { num_disabled = 0; num_matched = 0; num_choices = 0; for (ptr = externals; ptr != 0; ptr = ptr->next) { if (match_item_by_name(ptr, param, only_overriders)) { ++num_matched; CTRACE((tfp, "EXTERNAL: '%s' <==> '%s'\n", ptr->name, param)); if (no_externals && !ptr->always_enabled && !only_overriders) { ++num_disabled; } else { if (pass == 0) { length++; } else if (pass != 0) { cmdbuf = format_command(ptr->command, param); if (length > 1) { actions[num_choices] = cmdbuf; choices[num_choices] = format_command(ptr->menu_name, param); } } num_choices++; } } } if (length > 1) { if (pass == 0) { actions = typecallocn(char *, length + 1); choices = typecallocn(char *, length + 1); if (actions == 0 || choices == 0) outofmem(__FILE__, "lookup_external"); } else { actions[num_choices] = 0; choices[num_choices] = 0; } }
int HTLoadRules ARGS1(CONST char *, filename) { FILE * fp = fopen(filename, "r"); char line[LINE_LENGTH+1]; if (!fp) { CTRACE(stderr, "HTRules: Can't open rules file %s\n", filename); return -1; /* File open error */ } for(;;) { if (!fgets(line, LINE_LENGTH+1, fp)) break; /* EOF or error */ (void) HTSetConfiguration(line); } fclose(fp); return 0; /* No error or syntax errors ignored */ }
/* Create a chunk with a certain allocation unit and ensured size ** -------------- */ PUBLIC HTChunk * HTChunkCreate2 ARGS2 (int,grow, size_t, needed) { HTChunk * ch = typecalloc(HTChunk); if (ch == NULL) outofmem(__FILE__, "HTChunkCreate2"); HTChunkInit (ch, grow); if (needed > 0) { ch->allocated = needed-1 - ((needed-1) % ch->growby) + ch->growby; /* Round up */ CTRACE((tfp, "HTChunkCreate2: requested %d, allocate %d\n", (int) needed, ch->allocated)); ch->data = typecallocn(char, ch->allocated); if (!ch->data) outofmem(__FILE__, "HTChunkCreate2 data"); }
PRIVATE int HTCloseGzFile ARGS1( gzFile, gzfp) { int gzres; if (gzfp == NULL) return 0; gzres = gzclose(gzfp); if (TRACE) { if (gzres == Z_ERRNO) { perror("gzclose "); } else if (gzres != Z_OK) { CTRACE((tfp, "gzclose : error number %d\n", gzres)); } } return(gzres); }
HTStyleSheet *HTStyleSheetWrite(HTStyleSheet *self, NXStream * stream) { int numStyles = 0; HTStyle *style; for (style = self->styles; style; style = style->next) numStyles++; NXPrintf(stream, "%d\n", numStyles); CTRACE((tfp, "StyleSheet: Writing %d styles\n", numStyles)); for (style = self->styles; style; style = style->next) { NXPrintf(stream, "%s ", style->name); (void) HTStyleWrite(style, stream); } return self; }
static void jthread_set_wait_monitor(jobject monitor) { vm_thread_t vm_thread = jthread_self_vm_thread(); assert(vm_thread); jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread; if (!jvmti_thread) { // nothing to do return; } CTRACE(("TM: set wait monitor: %x", monitor)); int disable_count = hythread_reset_suspend_disable(); jvmti_thread->wait_monitor = vm_thread->jni_env->NewGlobalRef(monitor); hythread_set_suspend_disable(disable_count); } // jthread_set_wait_monitor
BufferMapper* BufferManager::map(DataBuffer& buffer) { bool ret; BufferMapper* mapper; CTRACE(); Mutex::Autolock _l(mLock); //try to get mapper from pool mapper = mBufferPool->getMapper(buffer.getKey()); if (mapper) { // increase mapper ref count mapper->incRef(); return mapper; } // create a new buffer mapper and add it to pool do { VLOGTRACE("new buffer, will add it"); mapper = createBufferMapper(buffer); if (!mapper) { ELOGTRACE("failed to allocate mapper"); break; } ret = mapper->map(); if (!ret) { ELOGTRACE("failed to map"); delete mapper; mapper = NULL; break; } ret = mBufferPool->addMapper(buffer.getKey(), mapper); if (!ret) { ELOGTRACE("failed to add mapper"); break; } // increase mapper ref count mapper->incRef(); return mapper; } while (0); // error handling if (mapper) { mapper->unmap(); delete mapper; } return NULL; }
static void _check_cb(UNUSED EV_P_ UNUSED ev_check *w, UNUSED int revents) { int npending; npending = ev_pending_count(the_loop); #ifdef TRACE_VERBOSE CTRACE("ev_pending_count=%d", npending); #endif if (npending <= 0) { //CTRACE("Breaking loop? ..."); //ev_break(the_loop, EVBREAK_ALL); } timecounter_now = (uint64_t)(ev_now(the_loop) * 1000000000.); //CTRACE("revents=%08x", revents); }
static void test0(void) { int res; struct sigaction act = { .sa_flags = SA_SIGINFO, }; UNUSED mrkthr_ctx_t *cli; //mrkthr_ctx_t *srv; sigemptyset(&(act.sa_mask)); act.sa_sigaction = (void (*)(int, siginfo_t *, void *))sigterm_handler; sigaction(SIGTERM, &act, NULL); sigaction(SIGINT, &act, NULL); mrkthr_init(); shutdown_timer_ctx = mrkthr_new("tm", shut_me_down, 0); //CTRACE(); //if (pipe(read_pipe) != 0) { // FAIL("pipe"); //} //CTRACE(); //if (pipe(write_pipe) != 0) { // FAIL("pipe"); //} //CTRACE(); //srv = mrkthr_spawn("qwe", qwe, 2, read_pipe[0], write_pipe[1]); //cli = mrkthr_spawn("asd", asd, 2, write_pipe[0], read_pipe[1]); cli = mrkthr_spawn("bar", bar, 0); res = mrkthr_loop(); mrkthr_fini(); CTRACE("res=%d", res); }
/* Match maintype to any MIME type starting with maintype, * for example: image/gif should match image */ PRIVATE int half_match ARGS2(char *,trial_type, char *,target) { char *cp = strchr(trial_type, '/'); /* if no '/' or no '*' */ if (!cp || *(cp+1) != '*') return 0; CTRACE((tfp, "HTFormat: comparing %s and %s for half match\n", trial_type, target)); /* main type matches */ if (!strncmp(trial_type, target, (cp-trial_type)-1)) return 1; return 0; }
PRIVATE void syntax_error ARGS3(FILE *, fp, char *, msg, LexItem, lex_item) { char buffer[41]; int cnt = 0; int ch; while ((ch = getc(fp)) != EOF && ch != '\n') if (cnt < 40) buffer[cnt++] = ch; buffer[cnt] = (char)0; CTRACE(tfp, "%s %d before: '%s'\nHTGroup.c: %s (got %s)\n", "HTGroup.c: Syntax error in rule file at line", HTlex_line, buffer, msg, lex_verbose(lex_item)); HTlex_line++; }
int mrkthr_wait_for_read(int fd) { int res; UNUSED ev_item_t *ev, *ev1; ev = ev_io_item_get(fd, EV_READ); //ev_io_set(&ev->ev.io, fd, EV_READ); me->pdata.ev = ev; /* * check if there is another thread waiting for the same event. */ if (ev->ev.io.data == NULL) { ev->ev.io.data = me; } else if (ev->ev.io.data != me) { /* * in this case we are not allowed to wait for this event, * sorry. */ me->co.rc = MRKTHR_CO_RC_SIMULTANEOUS; return -1; } #ifdef TRACE_VERBOSE CTRACE(FBBLUE("starting ev_io %d/%s"), ev->ev.io.fd, EV_STR(ev->ev.io.events)); #endif ev_io_start(the_loop, &ev->ev.io); /* wait for an event */ me->co.state = CO_STATE_READ; res = yield(); ev1 = ev_io_item_get(fd, EV_READ); assert(ev == ev1); assert(ev->ev.io.data == me); ev->ev.io.data = NULL; me->pdata.ev = NULL; return res; }
int psbWsbmDestroyTTMBuffer(void * buf) { CTRACE(); if(!buf) { ETRACE("invalid ttm buffer"); return -EINVAL; } /*FIXME: should I unmap this buffer object first?*/ wsbmBOUnmap((struct _WsbmBufferObject *)buf); wsbmBOUnreference((struct _WsbmBufferObject **)&buf); XTRACE(); return 0; }
bool DisplayPlane::initialize(uint32_t bufferCount) { CTRACE(); if (bufferCount < MIN_DATA_BUFFER_COUNT) { WLOGTRACE("buffer count %d is too small", bufferCount); bufferCount = MIN_DATA_BUFFER_COUNT; } // create buffer cache, adding few extra slots as buffer rendering is async // buffer could still be queued in the display pipeline such that they // can't be unmapped] mCacheCapacity = bufferCount; mDataBuffers.setCapacity(bufferCount); mActiveBuffers.setCapacity(MIN_DATA_BUFFER_COUNT); mInitialized = true; return true; }
/* * Put the AddHrefs in a list. It can be used for indexing to * present special filetypes through a CGI. */ PUBLIC void HTAddHref ARGS2(char *, url, char *, type_templ) { HTHrefNode * node; if (!url || !type_templ) return; node = (HTHrefNode*)calloc(1,sizeof(HTHrefNode)); if (!node) outofmem(__FILE__, "HTAddHref"); if (url) StrAllocCopy(node->href_url, url); if (type_templ) StrAllocCopy(node->type_templ, type_templ); if (!hrefs) hrefs = HTList_new(); HTList_addObject(hrefs, (void*)node); CTRACE(stderr, "AddHref..... %s => URL=\"%s\" \n",type_templ,url); }
/* * Pop the previous filename, link and line number from the history list. */ void LYpop(DocInfo *doc) { if (nhist > 0) { clean_extra_history(); nhist--; LYFreeDocInfo(doc); *doc = HDOC(nhist); #ifdef DISP_PARTIAL /* assume we pop the 'doc' to show it soon... */ LYSetNewline(doc->line); /* reinitialize */ #endif /* DISP_PARTIAL */ CTRACE((tfp, "LYpop[%d]: address:%s\n title:%s\n", nhist, doc->address, doc->title)); } }
static int _shutdown(UNUSED int argc, UNUSED void **argv) { if (run_thread != NULL) { (void)mrkthr_set_interrupt_and_join(run_thread); run_thread = NULL; } if (monitor_thread != NULL) { (void)mrkthr_set_interrupt_and_join(monitor_thread); monitor_thread = NULL; } /* cleanup */ if (host != NULL) { free(host); host = NULL; } port = 0; if (user != NULL) { free(user); user = NULL; } if (password != NULL) { free(password); password = NULL; } if (vhost != NULL) { free(vhost); vhost = NULL; } if (exchange != NULL) { free(exchange); exchange = NULL; } if (routing_key != NULL) { free(routing_key); routing_key = NULL; } mrkthr_shutdown(); CTRACE("...shutdown OK"); return 0; }
/** * Exit a monitor. * * Exit a monitor, and if the owning count is zero, release it. * * @param[in] mon_ptr a monitor to be exited * @return 0 on success, <br>HYTHREAD_ILLEGAL_MONITOR_STATE if the current thread does not own the monitor * * @see hythread_monitor_exit_using_threadId, hythread_monitor_enter, hythread_monitor_enter_using_threadId */ IDATA VMCALL hythread_monitor_exit(hythread_monitor_t mon_ptr) { IDATA status = TM_ERROR_NONE; assert(mon_ptr->recursion_count >= 0); if (mon_ptr->owner != tm_self_tls) { CTRACE(("exit TM_ERROR_ILLEGAL_STATE owner: %d self: %d, rec: %d\n", mon_ptr->owner ? mon_ptr->owner->thread_id : 0, tm_self_tls->thread_id, mon_ptr->recursion_count)); return TM_ERROR_ILLEGAL_STATE; } if (mon_ptr->recursion_count == 0) { mon_ptr->owner = NULL; status = port_mutex_unlock(&mon_ptr->mutex); } else { mon_ptr->recursion_count--; } assert(status == TM_ERROR_NONE); return status; }
/* Create a chunk with a certain allocation unit and ensured size * -------------- */ HTChunk *HTChunkCreate2(int grow, size_t needed) { HTChunk *ch = typecalloc(HTChunk); if (ch == NULL) outofmem(__FILE__, "HTChunkCreate2"); HTChunkInit(ch, grow); if (needed > 0) { /* Round up */ ch->allocated = (int) (needed - 1 - ((needed - 1) % ch->growby) + (unsigned) ch->growby); CTRACE((tfp, "HTChunkCreate2: requested %d, allocate %u\n", (int) needed, (unsigned) ch->allocated)); ch->data = typecallocn(char, (unsigned) ch->allocated); if (!ch->data) outofmem(__FILE__, "HTChunkCreate2 data"); }
/* Add object to START of list (so it is pointed to by the head). */ void HTList_addObject(HTList *me, void *newObject) { HTList *newNode; if (me) { if ((newNode = typeMalloc(HTList)) == NULL) outofmem(__FILE__, "HTList_addObject"); newNode->object = newObject; newNode->next = me->next; me->next = newNode; } else { CTRACE((tfp, "HTList: Trying to add object %p to a nonexisting list\n", newObject)); } return; }
static BOOLEAN message_has_content(const char *filename, BOOLEAN *nonspaces) { FILE *fp; char *buffer = NULL; BOOLEAN in_headers = TRUE; *nonspaces = FALSE; if (!filename || (fp = fopen(filename, "r")) == NULL) { CTRACE((tfp, "Failed to open file %s for reading!\n", NONNULL(filename))); return FALSE; } while (LYSafeGets(&buffer, fp) != NULL) { char *cp = buffer; char firstnonblank = '\0'; LYTrimNewline(cp); for (; *cp; cp++) { if (!firstnonblank && isgraph(UCH(*cp))) { firstnonblank = *cp; } else if (!isspace(UCH(*cp))) { *nonspaces = TRUE; } } if (firstnonblank && firstnonblank != '>') { if (!in_headers) { LYCloseInput(fp); FREE(buffer); return TRUE; } } if (!firstnonblank) { in_headers = FALSE; } } FREE(buffer); LYCloseInput(fp); return FALSE; }
static char *suggested_filename(DocInfo *newdoc) { char *sug_filename = 0; int rootlen; /* * Load the suggested filename string. - FM */ if (HText_getSugFname() != 0) StrAllocCopy(sug_filename, HText_getSugFname()); /* must be freed */ else StrAllocCopy(sug_filename, newdoc->address); /* must be freed */ /* * Strip suffix for compressed-files, if present. */ if (HTCompressFileType(sug_filename, ".", &rootlen) != cftNone) sug_filename[rootlen] = '\0'; CTRACE((tfp, "suggest %s\n", sug_filename)); return sug_filename; }
/* Append a list to another. * * If successful, the second list will become empty but not freed. */ HTList *HTList_appendList(HTList *start, HTList *tail) { HTList *temp = start; if (!start) { CTRACE((tfp, "HTList: Trying to append list %p to a nonexisting list\n", (void *) tail)); return NULL; } if (!(tail && tail->next)) return start; while (temp->next) temp = temp->next; temp->next = tail->next; tail->next = NULL; /* tail is now an empty list */ return start; }
/* * Find the EXTERNAL command which matches the given name 'param'. If there is * more than one possibility, make a popup menu of the matching commands and * allow the user to select one. Return the selected command. */ PRIVATE char *lookup_external ARGS2( char *, param, BOOL, only_overriders) { int pass, num_disabled, num_matched, num_choices, cur_choice; int length = 0; char *cmdbuf = NULL; char **choices = 0; lynx_list_item_type *ptr = 0; for (pass = 0; pass < 2; pass++) { num_disabled = 0; num_matched = 0; num_choices = 0; for (ptr = externals; ptr != 0; ptr = ptr->next) { if (match_item_by_name(ptr, param, only_overriders)) { ++num_matched; CTRACE((tfp, "EXTERNAL: '%s' <==> '%s'\n", ptr->name, param)); if (no_externals && !ptr->always_enabled && !only_overriders) { ++num_disabled; } else { if (pass == 0) { length++; } else if (pass != 0) { cmdbuf = format_command(ptr->command, param); if (length > 1) choices[num_choices] = cmdbuf; } num_choices++; } } } if (length > 1) { if (pass == 0) { choices = typecallocn(char *, length + 1); } else { choices[num_choices] = 0; } }
/* Create a filter stack ** --------------------- ** ** If a wildcard match is made, a temporary HTPresentation ** structure is made to hold the destination format while the ** new stack is generated. This is just to pass the out format to ** MIME so far. Storing the format of a stream in the stream might ** be a lot neater. ** */ PUBLIC HTStream * HTStreamStack ARGS4( HTFormat, rep_in, HTFormat, rep_out, HTStream*, sink, HTParentAnchor*, anchor) { HTPresentation temp; HTPresentation *match; HTStream *result; CTRACE((tfp, "HTFormat: Constructing stream stack for %s to %s\n", HTAtom_name(rep_in), HTAtom_name(rep_out))); /* don't return on WWW_SOURCE some people might like * to make use of the source!!!! LJM */ #if 0 if (rep_out == WWW_SOURCE || rep_out == rep_in) return sink; /* LJM */ #endif if (rep_out == rep_in) { result = sink; } else if ((match = HTFindPresentation(rep_in, rep_out, &temp))) { if (match == &temp) { CTRACE((tfp, "StreamStack: Using %s\n", HTAtom_name(temp.rep_out))); } else { CTRACE((tfp, "StreamStack: found exact match: %s\n", HTAtom_name(match->rep))); } result = (*match->converter)(match, anchor, sink); } else { result = NULL; } if (TRACE) { if (result && result->isa && result->isa->name) { CTRACE((tfp, "StreamStack: Returning \"%s\"\n", result->isa->name)); } else if (result) { CTRACE((tfp, "StreamStack: Returning *unknown* stream!\n")); } else { CTRACE((tfp, "StreamStack: Returning NULL!\n")); CTRACE_FLUSH(tfp); /* a crash may be imminent... - kw */ } } return result; }
bool TTMBufferMapper::map() { void *wsbmBufferObject = 0; buffer_handle_t handle; void *virtAddr; uint32_t gttOffsetInPage; CTRACE(); handle = getHandle(); bool ret = mWsbm.wrapTTMBuffer((int64_t)handle, &wsbmBufferObject); if (ret == false) { ETRACE("failed to map TTM buffer"); return false; } // TODO: review this later ret = mWsbm.waitIdleTTMBuffer(wsbmBufferObject); if (ret == false) { ETRACE("failed to wait ttm buffer idle"); return false; } virtAddr = mWsbm.getCPUAddress(wsbmBufferObject); gttOffsetInPage = mWsbm.getGttOffset(wsbmBufferObject); if (!gttOffsetInPage || !virtAddr) { WTRACE("offset = %#x, addr = %p.", gttOffsetInPage, virtAddr); return false; } // update parameters mBufferObject = wsbmBufferObject; mGttOffsetInPage = gttOffsetInPage; mCpuAddress = virtAddr; mSize = 0; return true; }
void HTAssocList_add(HTAssocList *alist, const char *name, const char *value) { HTAssoc *assoc; if (alist) { if (!(assoc = (HTAssoc *) malloc(sizeof(HTAssoc)))) outofmem(__FILE__, "HTAssoc_add"); assoc->name = NULL; assoc->value = NULL; if (name) StrAllocCopy(assoc->name, name); if (value) StrAllocCopy(assoc->value, value); HTList_addObject(alist, (void *) assoc); } else { CTRACE((tfp, "HTAssoc_add: ERROR: assoc list NULL!!\n")); } }
/* Read a stylesheet from a typed stream * ------------------------------------- * * Reads a style sheet from a stream. If new styles have the same names * as existing styles, they replace the old ones without changing the ids. */ #ifdef NEXT_SUPRESS /* Only on the NeXT */ HTStyleSheet *HTStyleSheetRead(HTStyleSheet *self, NXStream * stream) { int numStyles; int i; HTStyle *style; char styleName[80]; NXScanf(stream, " %d ", &numStyles); CTRACE((tfp, "Stylesheet: Reading %d styles\n", numStyles)); for (i = 0; i < numStyles; i++) { NXScanf(stream, "%s", styleName); style = HTStyleNamed(self, styleName); if (!style) { style = HTStyleNewNamed(styleName); (void) HTStyleSheetAddStyle(self, style); } (void) HTStyleRead(style, stream); if (TRACE) HTStyleDump(style); } return self; }
HTStyle *HTStyleForRun(HTStyleSheet *self, NXRun * run) { HTStyle *scan; HTStyle *best = 0; int bestMatch = 0; NXTextStyle *rp = run->paraStyle; for (scan = self->styles; scan; scan = scan->next) if (scan->paragraph == run->paraStyle) return scan; /* Exact */ for (scan = self->styles; scan; scan = scan->next) { NXTextStyle *sp = scan->paragraph; if (sp) { int match = 0; if (sp->indent1st == rp->indent1st) match = match + 1; if (sp->indent2nd == rp->indent2nd) match = match + 2; if (sp->lineHt == rp->lineHt) match = match + 1; if (sp->numTabs == rp->numTabs) match = match + 1; if (sp->alignment == rp->alignment) match = match + 3; if (scan->font == run->font) match = match + 10; if (match > bestMatch) { best = scan; bestMatch = match; } } } CTRACE((tfp, "HTStyleForRun: Best match for style is %d out of 18\n", bestMatch)); return best; }
/* PUBLIC HTAA_makeProtectionTemplate() * CREATE A PROTECTION TEMPLATE FOR THE FILES * IN THE SAME DIRECTORY AS THE GIVEN FILE * (Used by server if there is no fancier way for * it to tell the client, and by browser if server * didn't send WWW-ProtectionTemplate: field) * ON ENTRY: * docname is the document pathname (from URL). * * ON EXIT: * returns a template matching docname, and other files * files in that directory. * * E.g. /foo/bar/x.html => /foo/bar/ * * ^ * Space only to prevent it from * being a comment marker here, * there really isn't any space. */ char *HTAA_makeProtectionTemplate(const char *docname) { char *ctemplate = NULL; char *slash = NULL; if (docname) { StrAllocCopy(ctemplate, docname); slash = strrchr(ctemplate, '/'); if (slash) slash++; else slash = ctemplate; *slash = '\0'; StrAllocCat(ctemplate, "*"); } else StrAllocCopy(ctemplate, "*"); CTRACE((tfp, "make_template: made template `%s' for file `%s'\n", ctemplate, docname)); return ctemplate; }