Res SplayTreeDescribe(SplayTree splay, mps_lib_FILE *stream, Count depth, TreeDescribeFunction nodeDescribe) { Res res; if (!TESTT(SplayTree, splay)) return ResFAIL; if (stream == NULL) return ResFAIL; if (nodeDescribe == NULL) return ResFAIL; res = WriteF(stream, depth, "Splay $P {\n", (WriteFP)splay, " compare $F\n", (WriteFF)splay->compare, " nodeKey $F\n", (WriteFF)splay->nodeKey, " updateNode $F\n", (WriteFF)splay->updateNode, NULL); if (res != ResOK) return res; if (SplayTreeRoot(splay) != TreeEMPTY) { res = WriteF(stream, depth, " tree ", NULL); if (res != ResOK) return res; res = SplayNodeDescribe(SplayTreeRoot(splay), stream, nodeDescribe); if (res != ResOK) return res; } res = WriteF(stream, depth, "\n} Splay $P\n", (WriteFP)splay, NULL); return res; }
void EventDump(mps_lib_FILE *stream) { Event event; EventKind kind; AVER(stream != NULL); /* This can happen if there's a backtrace very early in the life of the MPS, and will cause an access violation if we continue. */ if (!eventInited) { (void)WriteF(stream, 0, "No events\n", NULL); return; } for (kind = 0; kind < EventKindLIMIT; ++kind) { for (event = (Event)EventLast[kind]; (char *)event < EventBuffer[kind] + EventBufferSIZE; event = (Event)((char *)event + event->any.size)) { /* Try to keep going even if there's an error, because this is used as a backtrace and we'll take what we can get. */ (void)EventWrite(event, stream); (void)WriteF(stream, 0, "\n", NULL); } } }
Res MeterWrite(Meter meter, mps_lib_FILE *stream) { Res res = ResOK; res = WriteF(stream, "meter $S {", meter->name, "count: $U", meter->count, NULL); if (res != ResOK) return res; if (meter->count > 0) { double mean = meter->total / (double)meter->count; res = WriteF(stream, ", total: $D", meter->total, ", max: $U", meter->max, ", min: $U", meter->min, ", mean: $D", mean, ", mean^2: $D", meter->meanSquared, NULL); if (res != ResOK) return res; } res = WriteF(stream, "}\n", NULL); return res; }
Res MeterWrite(Meter meter, mps_lib_FILE *stream, Count depth) { Res res = ResOK; res = WriteF(stream, depth, "meter \"$S\" {", (WriteFS)meter->name, "count: $U", (WriteFU)meter->count, NULL); if (res != ResOK) return res; if (meter->count > 0) { double mean = meter->total / (double)meter->count; res = WriteF(stream, 0, ", total $D", (WriteFD)meter->total, ", max $U", (WriteFU)meter->max, ", min $U", (WriteFU)meter->min, ", mean $D", (WriteFD)mean, ", meanSquared $D", (WriteFD)meter->meanSquared, NULL); if (res != ResOK) return res; } res = WriteF(stream, 0, "}\n", NULL); return res; }
/*** * get Public and Private keys and save them in .txt */ void getPublicPrivatekey(mpz_t p, mpz_t q,mpz_t n ,mpz_t phi , mpz_t e, mpz_t d) { mpz_init(p); mpz_init(q); mpz_init(n); mpz_init(phi); mpz_init(d); int seed=rand(); getNumberPremier(p,seed+1); getNumberPremier(q,seed+2); int e_int=65537; mpz_set_ui(e,e_int); mpz_mul(n,p,q); //n=p*q mpz_sub_ui(p, p, 1); //p=p-1 mpz_sub_ui(q, q, 1); //q=q-1 mpz_mul(phi, p, q); //phi=(p-1)*(q-1) mpz_invert(d, e, phi); //calcul d char *str_d=malloc(KEY_LENGTH/4*sizeof(char)); char *str_n=malloc(KEY_LENGTH/2*sizeof(char)); mpz_get_str (str_n, 16, n); mpz_get_str (str_d, 16, d); WriteF(str_n,"publicKey_Modulo"); WriteF(str_d,"privateKey_d"); free(str_n); free(str_d); printf("\nClé ==>==>==>==>==> Gagné\n"); }
Res EventDescribe(Event event, mps_lib_FILE *stream, Count depth) { Res res; /* TODO: Some sort of EventCheck would be good */ if (event == NULL) return ResFAIL; if (stream == NULL) return ResFAIL; res = WriteF(stream, depth, "Event $P {\n", (WriteFP)event, " code $U\n", (WriteFU)event->any.code, " clock ", NULL); if (res != ResOK) return res; res = EVENT_CLOCK_WRITE(stream, depth, event->any.clock); if (res != ResOK) return res; res = WriteF(stream, depth, "\n size $U\n", (WriteFU)event->any.size, NULL); if (res != ResOK) return res; switch (event->any.code) { #define EVENT_DESC_PARAM(name, index, sort, ident) \ "\n $S", (WriteFS)#ident, \ EVENT_WRITE_PARAM_##sort(name, index, sort, ident) #define EVENT_DESC(X, name, _code, always, kind) \ case _code: \ res = WriteF(stream, depth, \ " event \"$S\"", (WriteFS)#name, \ EVENT_##name##_PARAMS(EVENT_DESC_PARAM, name) \ NULL); \ if (res != ResOK) \ return res; \ break; EVENT_LIST(EVENT_DESC, X) default: res = WriteF(stream, depth, " event type unknown", NULL); if (res != ResOK) return res; /* TODO: Hexdump unknown event contents. */ break; } res = WriteF(stream, depth, "\n} Event $P\n", (WriteFP)event, NULL); return res; }
static Res MFSDescribe(Inst inst, mps_lib_FILE *stream, Count depth) { Pool pool = CouldBeA(AbstractPool, inst); MFS mfs = CouldBeA(MFSPool, pool); Res res; if (!TESTC(MFSPool, mfs)) return ResPARAM; if (stream == NULL) return ResPARAM; res = NextMethod(Inst, MFSPool, describe)(inst, stream, depth); if (res != ResOK) return res; return WriteF(stream, depth + 2, "unroundedUnitSize $W\n", (WriteFW)mfs->unroundedUnitSize, "extendBy $W\n", (WriteFW)mfs->extendBy, "extendSelf $S\n", WriteFYesNo(mfs->extendSelf), "unitSize $W\n", (WriteFW)mfs->unitSize, "freeList $P\n", (WriteFP)mfs->freeList, "total $W\n", (WriteFW)mfs->total, "free $W\n", (WriteFW)mfs->free, "tractList $P\n", (WriteFP)mfs->tractList, NULL); }
/* VMArenaDescribe -- describe the VMArena */ static Res VMArenaDescribe(Arena arena, mps_lib_FILE *stream) { Res res; VMArena vmArena; if (!TESTT(Arena, arena)) return ResFAIL; if (stream == NULL) return ResFAIL; vmArena = Arena2VMArena(arena); if (!TESTT(VMArena, vmArena)) return ResFAIL; /* Describe the superclass fields first via next-method call */ /* ...but the next method is ArenaTrivDescribe, so don't call it; * see impl.c.arena#describe.triv.dont-upcall. * super = ARENA_SUPERCLASS(VMArenaClass); res = super->describe(arena, stream); if (res != ResOK) return res; * */ res = WriteF(stream, " spareSize: $U\n", (WriteFU)vmArena->spareSize, NULL); if(res != ResOK) return res; /* (incomplete: some fields are not Described) */ return ResOK; }
static Res EPVMSegDescribe(Seg seg, mps_lib_FILE *stream) { Res res; EPVMSeg epvmSeg; SegClass super; /* .describe.check: Debugging tools don't AVER things. */ if (!CHECKT(Seg, seg)) return ResFAIL; if (stream == NULL) return ResFAIL; epvmSeg = Seg2EPVMSeg(seg); if (!CHECKT(EPVMSeg, epvmSeg)) return ResFAIL; /* Describe the superclass fields first via next-method call */ super = SEG_SUPERCLASS(EPVMSegClass); res = super->describe(seg, stream); if (res != ResOK) return res; res = WriteF(stream, " save $P\n", (WriteFP)epvmSeg->save, NULL); return res; }
Res EventWrite(Event event, mps_lib_FILE *stream) { Res res; if (event == NULL) return ResFAIL; if (stream == NULL) return ResFAIL; res = EVENT_CLOCK_WRITE(stream, event->any.clock); if (res != ResOK) return res; switch (event->any.code) { #define EVENT_WRITE_PARAM(name, index, sort, ident) \ EVENT_WRITE_PARAM_##sort(name, index, sort, ident) #define EVENT_WRITE(X, name, code, always, kind) \ case code: \ res = WriteF(stream, " $S", #name, \ EVENT_##name##_PARAMS(EVENT_WRITE_PARAM, name) \ NULL); \ if (res != ResOK) return res; \ break; EVENT_LIST(EVENT_WRITE, X) default: res = WriteF(stream, " <unknown code $U>", event->any.code, NULL); if (res != ResOK) return res; /* TODO: Hexdump unknown event contents. */ break; } return ResOK; }
static Res SplayNodeDescribe(Tree node, mps_lib_FILE *stream, TreeDescribeFunction nodeDescribe) { Res res; if (!TreeCheck(node)) return ResFAIL; if (stream == NULL) return ResFAIL; if (nodeDescribe == NULL) return ResFAIL; res = WriteF(stream, 0, "( ", NULL); if (res != ResOK) return res; if (TreeHasLeft(node)) { res = SplayNodeDescribe(TreeLeft(node), stream, nodeDescribe); if (res != ResOK) return res; res = WriteF(stream, 0, " / ", NULL); if (res != ResOK) return res; } res = (*nodeDescribe)(node, stream); if (res != ResOK) return res; if (TreeHasRight(node)) { res = WriteF(stream, 0, " \\ ", NULL); if (res != ResOK) return res; res = SplayNodeDescribe(TreeRight(node), stream, nodeDescribe); if (res != ResOK) return res; } res = WriteF(stream, 0, " )", NULL); if (res != ResOK) return res; return ResOK; }
static Res ArenaTrivDescribe(Arena arena, mps_lib_FILE *stream) { if (!CHECKT(Arena, arena)) return ResFAIL; if (stream == NULL) return ResFAIL; return WriteF(stream, " No class-specific description available.\n", NULL); }
// ------------------------------------------------------------------------------------------------ void Buffer::AppendF(const char * fmt, ...) { // Initialize the variable argument list va_list args; va_start(args, fmt); // Forward this to the regular write function m_Cur += WriteF(m_Cur, fmt, args); // Finalize the variable argument list va_end(args); }
static void test_splitted_file() { File_t of; InitializeFile(&of); GenDestFileName(&of,"pool/","split-file",".xxx",false); CreateFile( &of, 0, IOM_NO_STREAM,true); printf("*** created -> press ENTER: "); fflush(stdout); getchar(); SetupSplitFile(&of,OFT_PLAIN,0x80); static char abc[] = "abcdefghijklmnopqrstuvwxyz\n"; static char ABC[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; int i; for ( i = 0; i < 10; i++ ) WriteF(&of,abc,strlen(abc)); printf("*** written -> press ENTER: "); fflush(stdout); getchar(); TRACELINE; CloseFile(&of,0); printf("*** closed -> press ENTER: "); fflush(stdout); getchar(); File_t f; InitializeFile(&f); OpenFileModify(&f,"pool/split-file.xxx",IOM_NO_STREAM); SetupSplitFile(&f,OFT_PLAIN,0x100); SeekF(&f,0xc0); for ( i = 0; i < 20; i++ ) WriteF(&f,ABC,strlen(ABC)); char buf[200]; ReadAtF(&f,0,buf,sizeof(buf)); printf("%.*s|\n",(int)sizeof(buf),buf); CloseFile(&f,false); }
// ------------------------------------------------------------------------------------------------ Buffer::SzType Buffer::WriteF(SzType pos, const char * fmt, ...) { // Initialize the variable argument list va_list args; va_start(args, fmt); // Call the function that takes the variable argument list const SzType ret = WriteF(pos, fmt, args); // Finalize the variable argument list va_end(args); // Return the result return ret; }
enumError TermWriteWDF ( SuperFile_t * sf ) { ASSERT(sf); ASSERT(sf->wc); TRACE("#W# TermWriteWDF(%p)\n",sf); WDF_Chunk_t * wc = sf->wc + sf->wc_used - 1; const u64 last_pos = wc->file_pos + wc->data_size; if ( sf->file_size < last_pos ) { // correction for double layer discs [[2do]] sf->file_size = last_pos; } else if ( sf->file_size > last_pos ) { wc = NeedChunkWDF(sf,sf->wc_used); wc->file_pos = sf->file_size; wc->data_off = sf->f.max_off; } int i = 0; for ( wc = sf->wc; i < sf->wc_used; i++, wc++ ) ConvertToNetworkWC(wc,wc); #if WDF2_ENABLED const uint head_size = sf->wh.wdf_head_size; #else const uint head_size = WDF_VERSION1_SIZE; #endif sf->wh.chunk_n = sf->wc_used; sf->wh.chunk_off = sf->f.max_off; sf->wh.file_size = sf->file_size; sf->wh.data_size = sf->wh.chunk_off - head_size; WDF_Head_t wh; ConvertToNetworkWH(&wh,&sf->wh); // write the magic behind the data (use header) int stat = WriteAtF( &sf->f, sf->wh.chunk_off, &wh.magic, sizeof(wh.magic) ); // write the chunk table if (!stat) stat = WriteF( &sf->f, sf->wc, sf->wh.chunk_n * sizeof(*sf->wc) ); // write the header if (!stat) stat = WriteAtF( &sf->f, 0, &wh, head_size ); TRACE("#W# TermWriteWDF() returns %d\n",stat); return stat; }
Res InstDescribe(Inst inst, mps_lib_FILE *stream, Count depth) { InstClass klass; if (!TESTC(Inst, inst)) return ResPARAM; if (stream == NULL) return ResPARAM; klass = ClassOfPoly(Inst, inst); return WriteF(stream, depth, "$S $P\n", (WriteFS)ClassName(klass), inst, NULL); }
Res ThreadDescribe(Thread thread, mps_lib_FILE *stream) { Res res; res = WriteF(stream, "Thread $P ($U) {\n", (WriteFP)thread, (WriteFU)thread->serial, " arena $P ($U)\n", (WriteFP)thread->arena, (WriteFU)thread->arena->serial, "} Thread $P ($U)\n", (WriteFP)thread, (WriteFU)thread->serial, NULL); if(res != ResOK) return res; return ResOK; }
Res ChunkNodeDescribe(Tree node, mps_lib_FILE *stream) { Chunk chunk; if (!TreeCheck(node)) return ResFAIL; if (stream == NULL) return ResFAIL; chunk = ChunkOfTree(node); if (!TESTT(Chunk, chunk)) return ResFAIL; return WriteF(stream, 0, "[$P,$P)", (WriteFP)chunk->base, (WriteFP)chunk->limit, NULL); }
static Res SplayNodeDescribe(SplayNode node, mps_lib_FILE *stream, SplayNodeDescribeMethod nodeDescribe) { Res res; #if defined(AVER_AND_CHECK) if (!SplayNodeCheck(node)) return ResFAIL; /* stream and nodeDescribe checked by SplayTreeDescribe */ #endif res = WriteF(stream, "( ", NULL); if (res != ResOK) return res; if (SplayNodeLeftChild(node) != NULL) { res = SplayNodeDescribe(SplayNodeLeftChild(node), stream, nodeDescribe); if (res != ResOK) return res; res = WriteF(stream, " / ", NULL); if (res != ResOK) return res; } res = (*nodeDescribe)(node, stream); if (res != ResOK) return res; if (SplayNodeRightChild(node) != NULL) { res = WriteF(stream, " \\ ", NULL); if (res != ResOK) return res; res = SplayNodeDescribe(SplayNodeRightChild(node), stream, nodeDescribe); if (res != ResOK) return res; } res = WriteF(stream, " )", NULL); if (res != ResOK) return res; return ResOK; }
Res SplayTreeDescribe(SplayTree tree, mps_lib_FILE *stream, SplayNodeDescribeMethod nodeDescribe) { Res res; #if defined(AVER_AND_CHECK) if (!SplayTreeCheck(tree)) return ResFAIL; if (stream == NULL) return ResFAIL; if (!FUNCHECK(nodeDescribe)) return ResFAIL; #endif res = WriteF(stream, "Splay $P {\n", (WriteFP)tree, " compare $F\n", (WriteFF)tree->compare, NULL); if (res != ResOK) return res; if (SplayTreeRoot(tree) != NULL) { res = SplayNodeDescribe(SplayTreeRoot(tree), stream, nodeDescribe); if (res != ResOK) return res; } res = WriteF(stream, "\n}\n", NULL); return res; }
/*** * give a message */ int entreMsg() { printf("\ndonnez votre message : "); char Msg[100]; int taille=0; setbuf(stdin,NULL); char ch; while((ch=getchar())!='\n') { Msg[taille]=ch; ++taille; } Msg[taille]='\0'; WriteF(Msg,"Msg"); return taille; }
void EventDump(mps_lib_FILE *stream) { Event event; EventKind kind; AVER(stream != NULL); for (kind = 0; kind < EventKindLIMIT; ++kind) { for (event = (Event)EventLast[kind]; event < (Event)(EventBuffer[kind] + EventBufferSIZE); event = (Event)((char *)event + event->any.size)) { /* Try to keep going even if there's an error, because this is used as a backtrace and we'll take what we can get. */ (void)EventWrite(event, stream); (void)WriteF(stream, "\n", NULL); } } }
Res RangeDescribe(Range range, mps_lib_FILE *stream, Count depth) { Res res; AVERT(Range, range); AVER(stream != NULL); res = WriteF(stream, depth, "Range $P {\n", (WriteFP)range, " base: $P\n", (WriteFP)RangeBase(range), " limit: $P\n", (WriteFP)RangeLimit(range), " size: $U\n", (WriteFU)RangeSize(range), "} Range $P\n", (WriteFP)range, NULL); if (res != ResOK) { return res; } return ResOK; }
static Res ArenaTrivDescribe(Arena arena, mps_lib_FILE *stream) { if (!TESTT(Arena, arena)) return ResFAIL; if (stream == NULL) return ResFAIL; /* .describe.triv.never-called-from-subclass-method: * This Triv method seems to assume that it will never get called * from a subclass-method invoking ARENA_SUPERCLASS()->describe. * It assumes that it only gets called if the describe method has * not been subclassed. (That's the only reason for printing the * "No class-specific description available" message). * This is bogus, but that's the status quo. RHSK 2007-04-27. */ /* .describe.triv.dont-upcall: Therefore (for now) the last * subclass describe method should avoid invoking * ARENA_SUPERCLASS()->describe. RHSK 2007-04-27. */ return WriteF(stream, " No class-specific description available.\n", NULL); }
static Res segBufDescribe(Inst inst, mps_lib_FILE *stream, Count depth) { Buffer buffer = CouldBeA(Buffer, inst); SegBuf segbuf = CouldBeA(SegBuf, buffer); Res res; if (!TESTC(SegBuf, segbuf)) return ResPARAM; if (stream == NULL) return ResPARAM; res = NextMethod(Inst, SegBuf, describe)(inst, stream, depth); if (res != ResOK) return res; return WriteF(stream, depth + 2, "Seg $P\n", (WriteFP)segbuf->seg, "rankSet $U\n", (WriteFU)segbuf->rankSet, NULL); }
Res ShieldDescribe(Shield shield, mps_lib_FILE *stream, Count depth) { Res res; res = WriteF(stream, depth, "Shield $P {\n", (WriteFP)shield, " ", shield->inside ? "inside" : "outside", " shield\n", " suspended $S\n", WriteFYesNo(shield->suspended), " depth $U\n", (WriteFU)shield->depth, " next $U\n", (WriteFU)shield->next, " length $U\n", (WriteFU)shield->length, " unsynced $U\n", (WriteFU)shield->unsynced, " holds $U\n", (WriteFU)shield->holds, "} Shield $P\n", (WriteFP)shield, NULL); if (res != ResOK) return res; return ResOK; }
static Res MFSDescribe(Pool pool, mps_lib_FILE *stream) { MFS mfs; Res res; AVERT(Pool, pool); mfs = PoolPoolMFS(pool); AVERT(MFS, mfs); AVER(stream != NULL); res = WriteF(stream, " unrounded unit size $W\n", (WriteFW)mfs->unroundedUnitSize, " unit size $W\n", (WriteFW)mfs->unitSize, " extent size $W\n", (WriteFW)mfs->extendBy, " free list begins at $P\n", (WriteFP)mfs->freeList, " tract list begin at $P\n", (WriteFP)mfs->tractList, NULL); if(res != ResOK) return res; return ResOK; }
static Res BufferAbsDescribe(Inst inst, mps_lib_FILE *stream, Count depth) { Buffer buffer = CouldBeA(Buffer, inst); Res res; if (!TESTC(Buffer, buffer)) return ResPARAM; if (stream == NULL) return ResPARAM; res = NextMethod(Inst, Buffer, describe)(inst, stream, depth); if (res != ResOK) return res; return WriteF(stream, depth + 2, "serial $U\n", (WriteFU)buffer->serial, "Arena $P\n", (WriteFP)buffer->arena, "Pool $P\n", (WriteFP)buffer->pool, buffer->isMutator ? "Mutator" : "Internal", " Buffer\n", "mode $C$C$C$C (TRANSITION, LOGGED, FLIPPED, ATTACHED)\n", (WriteFC)((buffer->mode & BufferModeTRANSITION) ? 't' : '_'), (WriteFC)((buffer->mode & BufferModeLOGGED) ? 'l' : '_'), (WriteFC)((buffer->mode & BufferModeFLIPPED) ? 'f' : '_'), (WriteFC)((buffer->mode & BufferModeATTACHED) ? 'a' : '_'), "fillSize $U\n", (WriteFU)buffer->fillSize, "emptySize $U\n", (WriteFU)buffer->emptySize, "alignment $W\n", (WriteFW)buffer->alignment, "base $A\n", (WriteFA)buffer->base, "initAtFlip $A\n", (WriteFA)buffer->initAtFlip, "init $A\n", (WriteFA)buffer->ap_s.init, "alloc $A\n", (WriteFA)buffer->ap_s.alloc, "limit $A\n", (WriteFA)buffer->ap_s.limit, "poolLimit $A\n", (WriteFA)buffer->poolLimit, "alignment $W\n", (WriteFW)buffer->alignment, "rampCount $U\n", (WriteFU)buffer->rampCount, NULL); }