Exemple #1
0
int printElement(Tny *tny, int level)
{
	if (tny->type == TNY_NULL) {
		printf("NULL\n");
	} else if (tny->type == TNY_OBJ) {
		printf("\n");
		printObj(tny->value.tny, level + 1);
	} else if (tny->type == TNY_BIN) {
		printf("%s\n", (char*)tny->value.ptr);
	} else if (tny->type == TNY_INT32) {
		printf("%"PRIu32"\n", (uint32_t)tny->value.num);
	} else if (tny->type == TNY_INT64) {
		printf("%"PRIu64"\n", tny->value.num);
	} else if (tny->type == TNY_CHAR) {
		printf("%c\n", tny->value.chr);
	} else if (tny->type == TNY_DOUBLE) {
		printf("%g\n", tny->value.flt);
	} else {
		return 1;
	}

	return 0;
}
Exemple #2
0
int main(int argc, char *argv[])
{
	struct sockaddr_in serverAddr;
	struct sockaddr_in clientAddr;
	int clntSock = -1;
	ssize_t size = -1;
	int read = 0;
	obj o;
	
	if (argc != 2)
	{
		fprintf(stderr, "Usage %s <Server Port>\n", argv[0]);
		exit(1);
	}
	
	(void) signal(SIGCHLD, childDieHandler);
	
	int sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
	bzero(&serverAddr,sizeof(serverAddr));
	
	serverAddr.sin_family=AF_INET;
	serverAddr.sin_addr.s_addr=htonl(INADDR_ANY); //hton(l&s): coherence du format avec internet (Big Endian)
	serverAddr.sin_port=htons(atoi(argv[1]));// s=short et l=long
	
	if(bind(sd,(struct sockaddr *) &serverAddr, sizeof(serverAddr))< 0)
	{
		perror("error bind");
		exit(1);
	}
	
	if (listen(sd,SOMAXCONN)<0)
	{
		perror("error listen");
		exit(1);
	}
	
	while (1)
	{
		printf("Wait client connection...\n");
		int cltSize = sizeof clientAddr;
		if ((clntSock = accept(sd, (struct sockaddr *) &clientAddr, &cltSize)) < 0)
		{
			perror("error accept");
			exit(1);
		}
		
		printf("Accept client %s\n", inet_ntoa(clientAddr.sin_addr));
		pid_t pid=fork();
		
		
		if (pid < 0)
		{
			perror("error fork\n");
		}
		
		if (pid ==0) // child
		{
			printf("Client %s run on process %d\n", inet_ntoa(clientAddr.sin_addr), getpid());
			while (1)
			{
                if (recvObj(clntSock, &o) < 0) {
					perror("recvObj");
					exit(1);
				}
                
                printf("recv from client %s (pid=%d): ", inet_ntoa(clientAddr.sin_addr), getpid());
                printObj(&o);
                putchar('\n');
                
                //printf("o.iqt = %d\n", o.iqt);
                
				sleep(1);
				
                if (o.iqt < 0) break;
                else {
							
					// change object
					strcpy(o.chaine12, "yooo");
					strcpy(o.chaine, "je suis le serveur");
					
					// send it
					int s = sizeof(o);
					send(clntSock,&s,sizeof(s),0);
					send(clntSock,&o,sizeof(o),0);
				}
			}
			
			
			printf("End client %s (pid=%d)\n", inet_ntoa(clientAddr.sin_addr), getpid());
			close(clntSock);
			exit(0);
		}
		else
		{
			// father, do nothing
		}
	}
	
	return 0;
}
Exemple #3
0
void
printStackChunk( StgPtr sp, StgPtr spBottom )
{
    StgWord bitmap;
    const StgInfoTable *info;

    ASSERT(sp <= spBottom);
    for (; sp < spBottom; sp += stack_frame_sizeW((StgClosure *)sp)) {

	info = get_itbl((StgClosure *)sp);

	switch (info->type) {
	    
	case UPDATE_FRAME:
	case CATCH_FRAME:
        case UNDERFLOW_FRAME:
        case STOP_FRAME:
            printObj((StgClosure*)sp);
	    continue;

	case RET_DYN:
	{ 
	    StgRetDyn* r;
	    StgPtr p;
	    StgWord dyn;
	    nat size;

	    r = (StgRetDyn *)sp;
	    dyn = r->liveness;
	    debugBelch("RET_DYN (%p)\n", r);

	    p = (P_)(r->payload);
	    printSmallBitmap(spBottom, sp,
			     RET_DYN_LIVENESS(r->liveness), 
			     RET_DYN_BITMAP_SIZE);
	    p += RET_DYN_BITMAP_SIZE + RET_DYN_NONPTR_REGS_SIZE;

	    for (size = RET_DYN_NONPTRS(dyn); size > 0; size--) {
		debugBelch("   stk[%ld] (%p) = ", (long)(spBottom-p), p);
		debugBelch("Word# %ld\n", (long)*p);
		p++;
	    }
	
	    for (size = RET_DYN_PTRS(dyn); size > 0; size--) {
		debugBelch("   stk[%ld] (%p) = ", (long)(spBottom-p), p);
		printPtr(p);
		p++;
	    }
	    continue;
	}

	case RET_SMALL:
	    debugBelch("RET_SMALL (%p)\n", info);
	    bitmap = info->layout.bitmap;
	    printSmallBitmap(spBottom, sp+1, 
			     BITMAP_BITS(bitmap), BITMAP_SIZE(bitmap));
	    continue;

	case RET_BCO: {
	    StgBCO *bco;
	    
	    bco = ((StgBCO *)sp[1]);

	    debugBelch("RET_BCO (%p)\n", sp);
	    printLargeBitmap(spBottom, sp+2,
			     BCO_BITMAP(bco), BCO_BITMAP_SIZE(bco));
	    continue;
	}

	case RET_BIG:
	    barf("todo");

	case RET_FUN:
	{
	    StgFunInfoTable *fun_info;
	    StgRetFun *ret_fun;

	    ret_fun = (StgRetFun *)sp;
	    fun_info = get_fun_itbl(ret_fun->fun);
	    debugBelch("RET_FUN (%p) (type=%d)\n", ret_fun->fun, (int)fun_info->f.fun_type);
	    switch (fun_info->f.fun_type) {
	    case ARG_GEN:
		printSmallBitmap(spBottom, sp+2,
				 BITMAP_BITS(fun_info->f.b.bitmap),
				 BITMAP_SIZE(fun_info->f.b.bitmap));
		break;
	    case ARG_GEN_BIG:
		printLargeBitmap(spBottom, sp+2,
				 GET_FUN_LARGE_BITMAP(fun_info),
				 GET_FUN_LARGE_BITMAP(fun_info)->size);
		break;
	    default:
		printSmallBitmap(spBottom, sp+2,
				 BITMAP_BITS(stg_arg_bitmaps[fun_info->f.fun_type]),
				 BITMAP_SIZE(stg_arg_bitmaps[fun_info->f.fun_type]));
		break;
	    }
	    continue;
	}
	   
	default:
	    debugBelch("unknown object %d\n", (int)info->type);
	    barf("printStackChunk");
	}
    }
}
Exemple #4
0
static void nodeObs(vector<BitObj*> &extents, ofstream &obs, int num_obs) {
    cout << "Writing node objects to obs.txt...\n";
    for (int i = 0; i < extents.size(); ++i) {
        printObj(extents[i]->A, obs, num_obs);
    }
}
Exemple #5
0
int main(int argc, const char * argv[]) {
    ifstream fstream("input.txt");
    ofstream edges("edges.txt");
    ofstream coords("coords.txt");
    ofstream obs("obs.txt");
    ofstream json("fca.json");
    vector<string> input;
    string line;
    if (fstream.is_open()) {
        while (getline(fstream, line)) {
            input.push_back(line);
        }
        fstream.close();
        int num_obs = (int)input.size();
        unordered_set<bitset<MAX> > concepts;
        vector<BitObj*> extents;
        findConc(input, concepts, extents);
        vector<bitset<MAX> > relation(concepts.size());
        nodeJSON(extents, json);
        findEdges(extents, relation, edges);
        linkJSON(json);
        findCoords(extents, coords);
        nodeObs(extents, obs, num_obs);
        
        //Set operations
        ifstream com("com.txt");
        cout << "Computing operations...\n";
        string line;
        while (getline(com, line)) {
            cout << '\n';
            bitset<MAX> A = convInput(line.substr(2), num_obs);
            cout << "Input A: ";
            printObj(A, cout, num_obs);
            switch (line[0]) {
                case 'c':
                    cout << "Closure of A: ";
                    printObj(closure(extents, A).second, cout, num_obs);
                    break;
                case 'b':
                    cout << "Boundary of A: ";
                    printObj(boundary(extents, A, num_obs).second, cout, num_obs);
                    break;
                case 'i':
                    cout << "Interior of A: ";
                    printObj(interior(extents, A, num_obs), cout, num_obs);
                    break;
                case 'd':
                    cout << "Derived set of A: ";
                    printObj(derived(extents, A, num_obs), cout, num_obs);
                    break;
                case 's':
                    cout << "Isolated point of A: ";
                    printObj(isolated(extents, A, num_obs), cout, num_obs);
                    break;
            }
        }
        for (BitObj *b : extents)
            delete b;
    }
    else
        cerr << "Unable to open file" << endl;
    return 0;
}
Exemple #6
0
Capability *
interpretBCO (Capability* cap)
{
    // Use of register here is primarily to make it clear to compilers
    // that these entities are non-aliasable.
    register StgPtr       Sp;    // local state -- stack pointer
    register StgPtr       SpLim; // local state -- stack lim pointer
    register StgClosure   *tagged_obj = 0, *obj;
    nat n, m;

    LOAD_STACK_POINTERS;

    cap->r.rHpLim = (P_)1; // HpLim is the context-switch flag; when it
                           // goes to zero we must return to the scheduler.

    // ------------------------------------------------------------------------
    // Case 1:
    // 
    //       We have a closure to evaluate.  Stack looks like:
    //       
    //      	|   XXXX_info   |
    //      	+---------------+
    //       Sp |      -------------------> closure
    //      	+---------------+
    //       
    if (Sp[0] == (W_)&stg_enter_info) {
       Sp++;
       goto eval;
    }

    // ------------------------------------------------------------------------
    // Case 2:
    // 
    //       We have a BCO application to perform.  Stack looks like:
    //
    //      	|     ....      |
    //      	+---------------+
    //      	|     arg1      |
    //      	+---------------+
    //      	|     BCO       |
    //      	+---------------+
    //       Sp |   RET_BCO     |
    //      	+---------------+
    //       
    else if (Sp[0] == (W_)&stg_apply_interp_info) {
	obj = UNTAG_CLOSURE((StgClosure *)Sp[1]);
	Sp += 2;
	goto run_BCO_fun;
    }

    // ------------------------------------------------------------------------
    // Case 3:
    //
    //       We have an unboxed value to return.  See comment before
    //       do_return_unboxed, below.
    //
    else {
	goto do_return_unboxed;
    }

    // Evaluate the object on top of the stack.
eval:
    tagged_obj = (StgClosure*)Sp[0]; Sp++;

eval_obj:
    obj = UNTAG_CLOSURE(tagged_obj);
    INTERP_TICK(it_total_evals);

    IF_DEBUG(interpreter,
             debugBelch(
             "\n---------------------------------------------------------------\n");
             debugBelch("Evaluating: "); printObj(obj);
             debugBelch("Sp = %p\n", Sp);
             debugBelch("\n" );

             printStackChunk(Sp,cap->r.rCurrentTSO->stackobj->stack+cap->r.rCurrentTSO->stackobj->stack_size);
             debugBelch("\n\n");
            );
// Prints the message passed in by eventStr and then
// proceeds to call printObj to print the information about
// the object that's triggered the notification.
//
void
printDbEvent(const AcDbObject* pObj, const char* pEvent)
{
    acutPrintf("  Event: AcDbDatabaseReactor::%s ", pEvent);
    printObj(pObj);
}
Exemple #8
0
void
printStackChunk( StgPtr sp, StgPtr spBottom )
{
    StgWord bitmap;
    const StgInfoTable *info;

    ASSERT(sp <= spBottom);
    for (; sp < spBottom; sp += stack_frame_sizeW((StgClosure *)sp)) {

        info = get_itbl((StgClosure *)sp);

        switch (info->type) {

        case UPDATE_FRAME:
        case CATCH_FRAME:
        case UNDERFLOW_FRAME:
        case STOP_FRAME:
            printObj((StgClosure*)sp);
            continue;

        case RET_SMALL:
            debugBelch("RET_SMALL (%p)\n", info);
            bitmap = info->layout.bitmap;
            printSmallBitmap(spBottom, sp+1,
                             BITMAP_BITS(bitmap), BITMAP_SIZE(bitmap));
            continue;

        case RET_BCO: {
            StgBCO *bco;

            bco = ((StgBCO *)sp[1]);

            debugBelch("RET_BCO (%p)\n", sp);
            printLargeBitmap(spBottom, sp+2,
                             BCO_BITMAP(bco), BCO_BITMAP_SIZE(bco));
            continue;
        }

        case RET_BIG:
            barf("todo");

        case RET_FUN:
        {
            StgFunInfoTable *fun_info;
            StgRetFun *ret_fun;

            ret_fun = (StgRetFun *)sp;
            fun_info = get_fun_itbl(ret_fun->fun);
            debugBelch("RET_FUN (%p) (type=%d)\n", ret_fun->fun, (int)fun_info->f.fun_type);
            switch (fun_info->f.fun_type) {
            case ARG_GEN:
                printSmallBitmap(spBottom, sp+2,
                                 BITMAP_BITS(fun_info->f.b.bitmap),
                                 BITMAP_SIZE(fun_info->f.b.bitmap));
                break;
            case ARG_GEN_BIG:
                printLargeBitmap(spBottom, sp+2,
                                 GET_FUN_LARGE_BITMAP(fun_info),
                                 GET_FUN_LARGE_BITMAP(fun_info)->size);
                break;
            default:
                printSmallBitmap(spBottom, sp+2,
                                 BITMAP_BITS(stg_arg_bitmaps[fun_info->f.fun_type]),
                                 BITMAP_SIZE(stg_arg_bitmaps[fun_info->f.fun_type]));
                break;
            }
            continue;
        }

        default:
            debugBelch("unknown object %d\n", (int)info->type);
            barf("printStackChunk");
        }
    }
}
Exemple #9
0
Fichier : vm.cpp Projet : pangc/pvm
void VMachine::showObj(){
    for(int index = 0;index<MAX_OBJ;index++)
    if(ObjTable[index].t==NUMBER||ObjTable[index].t==BOOLEAN)
        printObj(ObjTable[index]);
}
Exemple #10
0
// port internet =10 000 + 45 = 10045 (incrementer entre deux tests (+100))
int main(int argc, char *argv[])
{
    struct sockaddr_in serverAddr;
    struct sockaddr_in clientAddr;
    int clntSock = -1;
    
    if (argc != 2)
    {
        fprintf(stderr, "Usage %s <Server Port>\n", argv[0]);
        exit(1);
    }
    
    int sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    bzero(&serverAddr,sizeof(serverAddr));
    
    serverAddr.sin_family=AF_INET;
    serverAddr.sin_addr.s_addr=htonl(INADDR_ANY); //hton(l&s): coherence du format avec internet (Big Endian)
    serverAddr.sin_port=htons(atoi(argv[1]));// s=short et l=long
    
    if(bind(sd,(struct sockaddr *) &serverAddr, sizeof(serverAddr))< 0)
    {
        perror("error bind");
        exit(1);
    }
    
    if (listen(sd,SOMAXCONN)<0)
    {
        perror("error listen");
        exit(1);
    }
    
    while (1)
    {
        printf("Wait client connection...\n");
        int cltSize = sizeof clientAddr;
        if ((clntSock = accept(sd, (struct sockaddr *) &clientAddr, &cltSize)) < 0)
        {
            perror("error accept");
            exit(1);
        }
        
        printf("client %s\n",inet_ntoa(clientAddr.sin_addr));
        pid_t pid=fork();
        
        
        if (pid < 0)
        {
            perror("error fork\n");
        }
        
        if (pid ==0)
        {
            obj o;
            int size;
            printf("Fils\n");
            
            while (1)
            {
                if ((size=recv(clntSock, &o, sizeof(o), 0)) < 0)
                {
                    perror("error rcv");
                    exit(1);            
                
                }
                if (size!=sizeof(o))
                {
                    perror("size");
                    exit(1);
                }
                
                printObj(&o);
                putchar('\n');
                if (o.iqt < 0) break;
            }
            
            exit(0);
            
        }
        else
        {   //cas du pere
            printf("Pere\n");
            int status=-1;
            waitpid(pid, &status, WUNTRACED);
            printf("pid : %d\n", status);
            
            if (status == 0)
            {
                close(clntSock);
                break;
                
            }
        }
    }
    
    printf("Arret serveur\n");
    
    
    return 0;
}
int main (int argc, const char* argv[]) {
	if (argc <= 1) {
		fprintf(stderr, "Usage: visualize-archived-object <archived-file>\n\n");
		return 0;
	}
	
	CFStringRef fileNameAsCFString = CFStringCreateWithCString(NULL, argv[1], 0);
	CFURLRef fileURL = CFURLCreateWithFileSystemPath(NULL, fileNameAsCFString, kCFURLPOSIXPathStyle, false);
	CFRelease(fileNameAsCFString);
	
	CFReadStreamRef readStream = CFReadStreamCreateWithFile(NULL, fileURL);
	CFRelease(fileURL);
	if (!readStream) {
		fprintf(stderr, "Error: Cannot open file for reading.\n\n");
		return 1;
	}
	if (!CFReadStreamOpen(readStream)) {
		fprintf(stderr, "Error: Cannot open file for reading.\n\n");
		CFRelease(readStream);
		return 2;
	}
	
	CFStringRef errStr = NULL;
	CFPropertyListRef val = CFPropertyListCreateFromStream(NULL, readStream, 0, kCFPropertyListImmutable, NULL, &errStr);
	CFReadStreamClose(readStream);
	CFRelease(readStream);
	if (errStr != NULL) {
		CFIndex strlength = CFStringGetLength(errStr)*3+1;
		char* res_cstring = malloc(strlength);
		CFStringGetCString(errStr, res_cstring, strlength, 0);
		fprintf(stderr, "Error: Cannot parse file as serialized property list.\n%s\n\n", res_cstring);
		CFRelease(errStr);
		free(res_cstring);
		if (val != NULL)
			CFRelease(val);
		return 3;
	}
	
	if (CFGetTypeID(val) != CFDictionaryGetTypeID()) {
		fprintf(stderr, "Error: Not a dictionary.");
		CFRelease(val);
		return 4;
	}
	
	CFStringRef archiver = CFDictionaryGetValue(val, CFSTR("$archiver"));
	if (archiver == NULL || !CFEqual(archiver, CFSTR("NSKeyedArchiver"))) {
		fprintf(stderr, "Error: Not encoded using an NSKeyedArchiver.");
		CFRelease(val);
		return 5;
	}
	
	CFArrayRef objs = CFDictionaryGetValue(val, CFSTR("$objects"));
	if (objs == NULL || CFGetTypeID(objs) != CFArrayGetTypeID()) {
		fprintf(stderr, "Error: $objects is not an array.");
		CFRelease(val);
		return 6;
	}
	CFIndex objsCount = CFArrayGetCount(objs);
	
	CFDictionaryRef topObj = CFDictionaryGetValue(val, CFSTR("$top"));
	if (topObj == NULL || CFGetTypeID(topObj) != CFDictionaryGetTypeID()) {
		CFShow(topObj);
		fprintf(stderr, "Error: $top is not a dictionary.");
		CFRelease(val);
		return 7;
	}
	
	int* refCount = calloc(objsCount, sizeof(int));
	CFArrayApplyFunction(objs, CFRangeMake(0, objsCount), (CFArrayApplierFunction)&refCounter, refCount);
	
	struct printContext c;
	c.tabs = 0;
	c.refCount = refCount;
	c.objs = objs;
	
	printf("%s", "top = ");
	printObj(topObj, &c);
	printf(";\n\n");
	
	for (CFIndex i = 0; i < objsCount; ++ i)
		if (refCount[i] > 1) {
			CFPropertyListRef refObj = CFArrayGetValueAtIndex(objs, i);
			if (isComplexObj(refObj)) {
				printf("/*CF$UID; referenced %u times*/ %ld = ", refCount[i], i);
				printObj(refObj, &c);
				printf(";\n\n");
			}
		}
	
	free(refCount);
	CFRelease(val);
	
	return 0;
}
static void printObjAsArrayEntry(CFPropertyListRef value, struct printContext* c) {
	for (unsigned i = 0; i < c->tabs; ++ i)
		printf("\t");
	printObj(value, c);
	printf(",\n");
}