void Buffer::append( const char * s, uint l, bool f ) { int r = Z_OK; bool progress = true; switch ( filter ) { case Compressing: zs->avail_in = l; zs->next_in = (Bytef*)s; while ( zs->avail_in && progress && r == Z_OK ) { zs->next_out = (Bytef*)buffer; zs->avail_out = bufsiz; r = ::deflate( zs, Z_NO_FLUSH ); if ( zs->avail_out < bufsiz ) append2( buffer, bufsiz - zs->avail_out ); else progress = false; } if ( f ) { zs->next_out = (Bytef*)buffer; zs->avail_out = bufsiz; r = ::deflate( zs, Z_SYNC_FLUSH ); if ( zs->avail_out < bufsiz ) append2( buffer, bufsiz - zs->avail_out ); } if ( zs->avail_in ) { // should not happen } break; case Decompressing: zs->avail_in = l; zs->next_in = (Bytef*)s; while ( zs->avail_in && progress && r == Z_OK ) { zs->next_out = (Bytef*)buffer; zs->avail_out = bufsiz; r = ::inflate( zs, Z_SYNC_FLUSH ); if ( zs->avail_out < bufsiz ) append2( buffer, bufsiz - zs->avail_out ); else progress = false; } break; case None: append2( s, l ); break; } }
int_list append2(int_list lst1, int_list lst2) { if (lst1 != NULL) { append2(lst1->list_tail, lst2); EAX = cons(lst1->list_head,EAX); } else EAX = lst2; }
int_list dec_to_bin2(int n){ int_list EBX; int quotient, remainder; if(n ==0) EAX = NULL;//empty list else { //quotient = n/2; //or shift right one bit quotient = n >> 1; dec_to_bin2(quotient); EBX = EAX; remainder = n%2; // or shift right and check carry flag cons2(remainder, NULL); //returns result in EAX append2(EBX, EAX); //returns result in EAX } }
static void xbt_log_layout_format_dynamic(xbt_log_layout_t l, xbt_log_event_t ev, const char *fmt, xbt_log_appender_t app) { xbt_strbuff_t buff = xbt_strbuff_new(); char tmpfmt[50]; int precision = -1; int length = -1; char *q = l->data; char *tmp; char *tmp2; while (*q != '\0') { if (*q == '%') { q++; handle_modifier: switch (*q) { case '\0': fprintf(stderr, "Layout format (%s) ending with %%\n", (char *) l->data); abort(); case '%': xbt_strbuff_append(buff, "%"); break; case 'n': /* platform-dependant line separator (LOG4J compliant) */ xbt_strbuff_append(buff, "\n"); break; case 'e': /* plain space (SimGrid extension) */ xbt_strbuff_append(buff, " "); break; case '.': /* precision specifyier */ q++; sscanf(q, "%d", &precision); q += (precision>9?2:1); goto handle_modifier; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* length modifier */ sscanf(q, "%d", &length); q += (length>9?2:1); goto handle_modifier; case 'c': /* category name; LOG4J compliant should accept a precision postfix to show the hierarchy */ append_string(ev->cat->name); break; case 'p': /* priority name; LOG4J compliant */ append_string(xbt_log_priority_names[ev->priority]); break; case 'h': /* host name; SimGrid extension */ append_string(gras_os_myname()); break; case 't': /* thread name; LOG4J compliant */ append_string(xbt_thread_self_name()); break; case 'P': /* process name; SimGrid extension */ append_string(xbt_procname()); break; case 'i': /* process PID name; SimGrid extension */ append_int((*xbt_getpid) ()); break; case 'F': /* file name; LOG4J compliant */ append_string(ev->fileName); break; case 'l': /* location; LOG4J compliant */ append2("%s:%d", ev->fileName, ev->lineNum); precision = -1; /* Ignored */ break; case 'L': /* line number; LOG4J compliant */ append_int(ev->lineNum); break; case 'M': /* method (ie, function) name; LOG4J compliant */ append_string(ev->functionName); break; case 'b': /* backtrace; called %throwable in LOG4J */ case 'B': /* short backtrace; called %throwable{short} in LOG4J */ #if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE) { xbt_ex_t e; int i; e.used = backtrace((void **) e.bt, XBT_BACKTRACE_SIZE); e.bt_strings = NULL; e.msg = NULL; e.remote = 0; xbt_backtrace_current(&e); if (*q == 'B') { append_string(e.bt_strings[2] + 8); } else { for (i = 2; i < e.used; i++) { append_string(e.bt_strings[i] + 8); xbt_strbuff_append(buff, "\n"); } } xbt_ex_free(e); } #else append_string("(no backtrace on this arch)"); #endif break; case 'd': /* date; LOG4J compliant */ append_double(gras_os_time()); break; case 'r': /* application age; LOG4J compliant */ append_double(gras_os_time() - format_begin_of_time); break; case 'm': /* user-provided message; LOG4J compliant */ tmp2 = bvprintf(fmt, ev->ap_copy); append_string(tmp2); free(tmp2); break; default: fprintf(stderr, ERRMSG, *q, (char *) l->data); abort(); } q++; } else { char tmp2[2]; tmp2[0] = *(q++); tmp2[1] = '\0'; xbt_strbuff_append(buff, tmp2); } } app->do_append(app, buff->data); xbt_strbuff_free(buff); }