int Bprint(Biobuf *bb, char *fmt, ...) { va_list arg; int n, pcol; char *ip, *ep, *out; Biobufhdr *bp = &bb->_h; va_start(arg, fmt); ep = (char*)bp->ebuf; ip = ep + bp->ocount; pcol = printcol; out = doprint(ip, ep, fmt, arg); if(out >= ep-UTFmax-1) { Bflush(bb); ip = ep + bp->ocount; printcol = pcol; out = doprint(ip, ep, fmt, arg); if(out >= ep-UTFmax-1) { va_end(arg); return Beof; } } n = out-ip; bp->ocount += n; va_end(arg); return n; }
int main(void){ while(scanf("%d",&n)!=EOF){ first = 1, sign = '+'; if(n<0) sign = '-',n/=-1; if(n) doprint(8); for(i = 0; i < 8; i++){ readn(&n); if(n) doprint(7-i); } if(first) putchar('0'); putchar('\n'); } return 0; }
void task3(void * p) { while(1) { doprint("c"); taskYIELD(); } }
void task2(void * p) { while(1) { doprint("b"); taskYIELD(); } }
//Just a small example void task1(void * p) { while(1) { doprint("a"); taskYIELD(); } }
int nv_fprintf(NV_FILE * fd, char * format, ...) { int len, err; char linebuf[NV_LINELENGTH]; va_list a; va_start(a, format); err = vsprintf(linebuf, format, a); va_end(a); #else /* the non-STDARG version */ int nv_fprintf(NV_FILE * fd, char * format, int arg1) { int len, err; char linebuf[NV_LINELENGTH]; doprint(linebuf, NV_LINELENGTH, format, &arg1); #endif /* PRINTF_STDARG */ /* output string now in linebuf, rest of function is the same */ /* check for buffer overflow */ len = strlen(linebuf); if (len > NV_LINELENGTH) panic("nv_fprintf"); /* write formatted buffer to VF device */ err = vfwrite(linebuf, len, 1, fd); return err; }
void message(char *s, ...){ char buf[1024], *out; va_list arg; va_start(arg, s); out = doprint(buf, buf+sizeof(buf), s, arg); va_end(arg); *out='\0'; plinitlabel(msg, PACKN|FILLX, buf); pldraw(msg, &screen); }
int myprintf(const char *fmt, ...) { va_list ap; int ret = 0; va_start(ap, fmt); ret = doprint(fmt, ap); va_end(ap); return ret; }
int iprint(char *fmt, ...) { int n; va_list va; char buf[1024]; va_start(va, fmt); n = doprint(buf, buf+sizeof buf, fmt, va) - buf; va_end(va); write(1,buf,n); return 1; }
/*------------------------------------------------------------------------- * Function: slicendump * * Purpose: To dump the slice for each dimension * For example: prev_dims[2] = {5, 4}; cur_dims[2] = {7, 8} * This routine will dump data as follows: * {0, 3} to {0, 7} (1x4 elements) * {1, 3} to {0, 7} (1x4 elements) * {2, 3} to {0, 7} (1x4 elements) * {3, 3} to {0, 7} (1x4 elements) * {4, 3} to {0, 7} (1x4 elements) * {5, 0} to {6, 7} (2x8 elements) * * Return: Non-negative on success * Negative on failure * * Programmer: Vailin Choi; August 2010 * *------------------------------------------------------------------------- */ static herr_t slicendump(hid_t did, hsize_t *prev_dims, hsize_t *cur_dims, hsize_t *start, hsize_t *block, int rank, int subrank) { int i; /* Local index variable */ int ind; /* Index for the current rank */ herr_t ret_value = SUCCEED; /* Return value */ ind = rank - subrank; if((subrank - 1) > 0) { /* continue onto the next dimension */ for (i = 0; i < (hssize_t)MIN(prev_dims[ind], cur_dims[ind]); i++){ start[ind] = (hsize_t)i; if((ret_value = slicendump(did, prev_dims, cur_dims, start, block, rank, subrank-1)) < 0) goto done; } } /* this dimension remains the same or shrinking */ if(cur_dims[ind] <= prev_dims[ind]) goto done; /* select first the slice for the faster changing dimension */ /* select later the whole slice for the slower changing dimension */ start[ind] = prev_dims[ind]; block[ind] = cur_dims[ind] - prev_dims[ind]; for(i = ind + 1; i < rank; i++){ start[i] = 0; block[i] = cur_dims[i]; } /* Print the appended data */ ret_value = doprint(did, start, block, rank); done: return(ret_value); } /* slicendump() */
/* * log_vsignal * * Core logging function. Formats the diagnostic message and text * position (if possible), emits the message on stderr, and handles * the next step - incrementing the appropriate diagnostic counter * and possibly aborting. */ void log_vsignal (logctx_t ctx, textpos_t pos, statcode_t code, va_list ap) { char logbuf[256]; int len; unsigned int sev = stc_severity(code); if (sev == STC_K_FATAL) { ctx->logtoterm = 1; } if (ctx->listprintfn != 0 || ctx->logtoterm) { int fileno = textpos_fileno(pos); unsigned int lineno = textpos_lineno(pos); unsigned int colno = textpos_colnum(pos); if (ctx->linefetchfn != 0) { strdesc_t *curline = (*ctx->linefetchfn)(ctx->lfctx, fileno, lineno); if (curline != 0) { doprintsrc(ctx, curline->ptr, curline->len); if (curline->len < sizeof(logbuf) && colno < curline->len) { memset(logbuf, '.', colno); logbuf[colno] = '|'; doprint(ctx, logbuf, colno+1, !ctx->logsrctolst); } } } len = stc_msg_vformat(code, logbuf, sizeof(logbuf)-1, ap); doprint(ctx, logbuf, len, 0); if (pos != 0 && ctx->fetchfn != 0) { strdesc_t *fname = ctx->fetchfn(ctx->ffctx, fileno); if (fname != 0) { len = snprintf(logbuf, sizeof(logbuf)-1, "- at %-*.*s:%u:%u", fname->len, fname->len, fname->ptr, lineno, colno+1); if (len > 0) doprint(ctx, logbuf, len, 0); } } } switch (sev) { case STC_K_ERROR: ctx->errcount += 1; if (ctx->errcount < ctx->maxerrs) break; // Force this error message to the terminal ctx->logtoterm = 1; len = snprintf(logbuf, sizeof(logbuf)-1, "%%BLISS-F-TOOMANYERRS, " "maximum number of errors exceeded, aborting"); if (len > 0) doprint(ctx, logbuf, len, 0); // FALLTHROUGH case STC_K_FATAL: fflush(stderr); longjmp(ctx->retenv, 1); break; case STC_K_WARN: ctx->warncount += 1; break; case STC_K_INFO: ctx->infocount += 1; break; default: break; } } /* log_vsignal */
int main() { poc(); #ifdef INTELIB_DEBUG_COUNTERS int before = SExpression::object_counter; #endif try { TestSection("RefalExpressions"); TestSubsection("TextRepresentation"); { RfReference empty(new RfExpression); TESTTR("empty_rfexpr", empty, ""); TESTTR("empty_subexpr", R|~R, "()"); } TestSubsection("Construction"); { TESTTR("single", (R|99), "99"); TESTTR("plain", (R|1,2,3), "1 2 3"); TESTTR("not_plain", (R|1,(R|2), (R|3,4,(R|5,6),7),8), "1 (2) (3 4 (5 6) 7) 8"); TESTTR("with_call", (R|1, R<2, 3, 4>R, 5), "1 <2 3 4> 5"); TESTTR("just_a_call", (R<1,2,3,4>R), "<1 2 3 4>"); TESTTR("just_a_call_1", (R<1>R), "<1>"); TESTTR("just_a_call_2", (R<1,2>R), "<1 2>"); TESTTR("call_in_call", (R<1,2, R<3,4,R<5,6,7>R,8>R,9>R), "<1 2 <3 4 <5 6 7> 8> 9>"); TESTTR("multy_within_expr", (R|1,2,R<1,R<2,R<3,4>R>R>R,5), "1 2 <1 <2 <3 4>>> 5"); } TestSubsection("MultyCallConstructor"); { #if 0 TESTTR("x", (R<R<1), "<#<#1"); TESTTR("xx", (R<R<1, 2), "<#<#1 2"); TESTTR("xxx", (R<R<1, 2>R), "<#<1 2>"); #endif TESTTR("call_in_beginning_of_call", (R<R<1,2>R, 3>R), "<<1 2> 3>"); TESTTR("call_in_beginning_of_call_noclose", (R<R<1,2>R, 3), "<#<1 2> 3"); TESTTR("call_in_beginning_of_call2", (R<R<R<1,2>R, 3>R,4>R), "<<<1 2> 3> 4>"); TESTTR("call_in_beginning_of_call3", (R<R<R<1,2>R,3>R,4>R), "<<<1 2> 3> 4>"); TESTTR("multy_within_expr", (R|1,2,R<R<R<3,4>R>R>R,5), "1 2 <<<3 4>>> 5"); TESTTR("call_starts_with_subexpr", (R|0,R<R<(R|1,2,3),4>R>R,5), "0 <<(1 2 3) 4>> 5"); TESTTR("inner_call_of_one_symbol", (R<R<1>R>R), "<<1>>"); TESTTR("inner_call_of_one_symbol", (R|0,R<R<1>R>R,2), "0 <<1>> 2"); } TestSubsection("Strings decomposition"); { TESTTR("simple_char", (R|"a"), "\"a\""); TESTTR("char_shuffled", (R|1,"a",2), "1 \"a\" 2"); TESTTR("char_shuffled2", (R|"a",2,"b"), "\"a\" 2 \"b\""); TESTTR("char_shuffled3", (R|"a",2,3,"b"), "\"a\" 2 3 \"b\""); TESTTR("char_shuffled4", (R|"a",2,3,"bc"), "\"a\" 2 3 \"bc\""); TESTTR("char_shuffled4", (R|"ab",2,3,"bc"), "\"ab\" 2 3 \"bc\""); TESTTR("char_shuffled4", (R|"ab",(R|2,3),"bc"), "\"ab\" (2 3) \"bc\""); TESTTR("simple_strings", (R|"abcd","efgh","ijkl"), "\"abcdefghijkl\""); TESTTR("strings_in_a_call", (R<"abcd","efgh","ijkl">R), "<\"abcdefghijkl\">"); TESTTR("one_strings_in_many_calls", (R<R<R<"abcd">R>R>R), "<<<\"abcd\">>>"); } TestSubsection("Pairing"); { RfReference r((R|1,(R|2,(R|3,(R|4),5),6),7)); RfListItem *temp1 = r->GetFirst(), *temp2 = r->GetLast(); temp1 = temp1->next; temp2 = temp2->prev; for (int i=0; i<2; i++) { TESTB("paired_lr", temp1->pair == temp2); TESTB("paired_rl", temp2->pair == temp1); temp1 = temp1->next; temp2 = temp2->prev; temp1 = temp1->next; temp2 = temp2->prev; } } TestSubsection("ConvertToLisp"); { RfReference r((R|1,(R|"abcd",(R|3,(R|4),"efgh"),6),7,"i")); SReference r1 = r->ConvertToLisp(); TESTTR("convert_to_lisp", r1, "(1 (\"abcd\" (3 (4) \"efgh\") 6) 7 \"i\")"); } TestSubsection("Memory leaks"); { #ifdef INTELIB_DEBUG_COUNTERS TEST("no_leaks", SExpression::object_counter, before); #endif } TestScore(); } catch(const IntelibX &ex) { printf("Caught IntelibX: %s\n", ex.Description()); doprint(ex.Parameter().GetPtr()); printf("\n"); } catch(...) { printf("Something strange caught\n"); } poc(); return 0; }