// Function to fill the table void fillThread(int c) { // Transform the lock CondId cond = (int)c; tab[0] = 0; tab[1] = 1; int i; int j; for (i = 2; i < NUM; i++) { tab[i] = 0; for (j = (i-1); j > 0; j--) { tab[i] += tab[j]; } } n_printf("Table just filled\n"); // Signal the cond if (CondSignal(cond) < 0) n_printf("Error signal condition"); Exit(0); }
static void dumpBytes(u_char * memptr, int count) { int i, linecounter; linecounter = 0; if (count > 64) { /* dumping whole packet takes too long */ count = 64; } for (i = 0; i < count; i++) { if (linecounter == 0) { n_printf("%p: ", memptr); } n_printf("%02x ", *memptr++); if (linecounter == 7) { n_printf("-"); } linecounter++; if (linecounter == 16) { n_printf("\n"); linecounter = 0; } } n_printf("\n"); }
/** * Main function */ int main() { // We create a condition CondId cond = CondCreate("TableCondition"); // We create a thread to fill it and one to read it ThreadId thread_fill = newThread("FillThread", (int)fillThread, (int)cond); ThreadId thread_read = newThread("ReadThread", (int)readThread, (int)cond); // Wait the two threads before returning if (Join(thread_fill) < 0) n_printf("Error joining first thread"); n_printf("Thread fill just finished"); if (Join(thread_read) < 0) n_printf("Error joining second thread"); n_printf("Thread read just finished"); // Delete the condition if (CondDestroy(cond) < 0) n_printf("Error destroy lock"); // Exit the program return 0; }
static u_char IPXListenForPacket(far_t ECBPtr) { ipx_socket_t *mysock; printECB(ECBp); /* see if the socket is open for this ECB */ mysock = ipx_find_socket(ECBp->ECBSocket); if (mysock == NULL) { n_printf("IPX: listen on unopened socket\n"); ECBp->InUseFlag = IU_ECB_FREE; ECBp->CompletionCode = CC_SOCKET_NOT_OPEN; return (RCODE_SOCKET_NOT_OPEN); } ECBp->InUseFlag = IU_ECB_LISTENING; ECBp->CompletionCode = CC_SUCCESS; /* now put this ECB on the listen list for this socket */ ECBp->Link = mysock->listenList; mysock->listenList = ECBPtr; mysock->listenCount++; n_printf("IPX: successfully posted listen packet on socket %x\n", ntohs(mysock->socket)); return (RCODE_SUCCESS); }
static u_char IPXScheduleEvent(far_t ECBPtr, u_char inUseCode, u_short delayTime) { ipx_socket_t *mysock; printECB(ECBp); /* see if the socket is open for this ECB */ mysock = ipx_find_socket(ECBp->ECBSocket); if (mysock == NULL) { n_printf("IPX: AES event on unopened socket\n"); ECBp->InUseFlag = IU_ECB_FREE; ECBp->CompletionCode = CC_SOCKET_NOT_OPEN; return (RCODE_SOCKET_NOT_OPEN); } ECBp->InUseFlag = inUseCode; ECBp->CompletionCode = CC_SUCCESS; /* now put this ECB on the AES list for this socket */ ECBp->Link = mysock->AESList; AESECBp->TimeLeft = delayTime; mysock->AESList = ECBPtr; mysock->AESCount++; n_printf("IPX: successfully posted AES event on socket %x\n", ntohs(mysock->socket)); n_printf("IPX: AES delay time %d\n", AESECBp->TimeLeft); return (RCODE_SUCCESS); }
void load_array(char* fn, int* size, int* p) { FILE* fp = fopen(fn, "r"); if (fp != NULL) { int max_size = _MAX_ARRAY_SIZE; int sz = *size; if (sz <= max_size) { for (int i = 0; i < sz; i++) { fscanf(fp, "%d", &p[i]); } n_printf("Array loaded!"); fclose(fp); } else { n_printf("Size cannot be more than 100."); } } else { n_printf("File not found!"); *size = 0; } }
void test1() { n_printf("\n Inside the first test now waiting for test2 to give latest value of y \n"); CondWait(cond); /*Waiting for the signal*/ y=y+20; n_printf("\n Test 1 is not waiting now and value of y is %d",y); }
static u_char IPXSendPacket(far_t ECBPtr) { IPXPacket_t *IPXHeader; u_char data[MAX_PACKET_DATA]; struct sockaddr_ipx ipxs; int dataLen; ipx_socket_t *mysock; printECB(ECBp); dataLen = GatherFragmentData(data, ECBp); if (dataLen == -1) { ECBp->InUseFlag = IU_ECB_FREE; ECBp->CompletionCode = CC_FRAGMENT_ERROR; return RCODE_ECB_NOT_IN_USE; /* FIXME - what is to return here?? */; } IPXHeader = (IPXPacket_t *)FARt_PTR(ECBp->FragTable[0].Address); /* for a complete emulation, we need to fill in fields in the */ /* send packet header */ /* first field is an IPX convention, not really a checksum */ IPXHeader->Checksum = 0xffff; IPXHeader->Length = htons(dataLen + 30); /* in network order */ memcpy(&IPXHeader->Source, MyAddress, 10); memcpy(&IPXHeader->Source.Socket, &ECBp->ECBSocket, 2); printIPXHeader(IPXHeader); ipxs.sipx_family = AF_IPX; /* get destination address from IPX packet header */ memcpy(&ipxs.sipx_network, IPXHeader->Destination.Network, 4); /* if destination address is 0, then send to my net */ if (ipxs.sipx_network == 0) { memcpy(&ipxs.sipx_network, MyAddress, 4); /* ipxs.sipx_network = htonl(MyNetwork); */ } memcpy(&ipxs.sipx_node, IPXHeader->Destination.Node, 6); memcpy(&ipxs.sipx_port, IPXHeader->Destination.Socket, 2); ipxs.sipx_type = 1; /* ipxs.sipx_port=htons(0x452); */ mysock = ipx_find_socket(ECBp->ECBSocket); if (mysock == NULL) { /* DANG_FIXTHIS - should do a bind, send, close here */ /* DOS IPX allows sending on unopened sockets */ n_printf("IPX: send to unopened socket %04x\n", ntohs(ECBp->ECBSocket)); return RCODE_SOCKET_NOT_OPEN; } if (sendto(mysock->fd, (void *) &data, dataLen, 0, &ipxs, sizeof(ipxs)) == -1) { n_printf("IPX: error sending packet: %s\n", strerror(errno)); ECBp->InUseFlag = IU_ECB_FREE; ECBp->CompletionCode = CC_HARDWARE_ERROR; return RCODE_CANNOT_FIND_ROUTE; /* FIXME - what is to return here?? */ } else { ECBp->InUseFlag = IU_ECB_FREE; ECBp->CompletionCode = CC_SUCCESS; n_printf("IPX: successfully sent packet\n"); } return RCODE_SUCCESS; }
static int GetMyAddress( void ) { int sock; struct sockaddr_ipx ipxs; struct sockaddr_ipx ipxs2; socklen_t len; int i; sock=socket(AF_IPX,SOCK_DGRAM,PF_IPX); if(sock==-1) { n_printf("IPX: could not open socket in GetMyAddress: %s\n", strerror(errno)); return(-1); } #define DYNAMIC_PORT 1 #if DYNAMIC_PORT #define DEF_PORT 0 #else #define DEF_PORT 0x5000 #endif ipxs.sipx_family=AF_IPX; ipxs.sipx_network=htonl(config.ipx_net); ipxs.sipx_port=htons(DEF_PORT); /* bind this socket to network */ if(bind(sock,&ipxs,sizeof(ipxs))==-1) { n_printf("IPX: could not bind to network %#lx in GetMyAddress: %s\n", config.ipx_net, strerror(errno)); close( sock ); return(-1); } len = sizeof(ipxs2); if (getsockname(sock,&ipxs2,&len) < 0) { n_printf("IPX: could not get socket name in GetMyAddress: %s\n", strerror(errno)); close( sock ); return(-1); } memcpy(MyAddress, &ipxs2.sipx_network, 4); for (i = 0; i < 6; i++) { MyAddress[4+i] = ipxs2.sipx_node[i]; } n_printf("IPX: using network address %02X%02X%02X%02X\n", MyAddress[0], MyAddress[1], MyAddress[2], MyAddress[3] ); n_printf("IPX: using node address of %02X%02X%02X%02X%02X%02X\n", MyAddress[4], MyAddress[5], MyAddress[6], MyAddress[7], MyAddress[8], MyAddress[9] ); #if DYNAMIC_PORT close( sock ); #endif return(0); }
// Function to read the table void readThread(int c) { // Transform the lock CondId cond = (int)c; // Wait our condition if (CondWait(cond) < 0) n_printf("Error condition wait"); int i; for (i = 0; i < NUM; i++) { n_printf("Tab[%d] = %d\n", i, tab[i]); } Exit(0); }
// "Travel" command handler bool CPropTransitionZone::OnTravel(const Events::CEventBase& Event) { Data::PParams P = ((const Events::CEvent&)Event).Params; Game::CEntity* pActorEnt = EntityMgr->GetEntityByID(P->Get<CStrID>(CStrID("Actor"))); n_assert(pActorEnt); const nString& LevelID = GetEntity()->Get<nString>(Attr::TargetLevelID); const nString& DestPt = GetEntity()->Get<nString>(Attr::DestPoint); //???set pause? if (DestPt.IsValid()) { matrix44 Tfm; if (EntityFct->GetEntityAttribute<matrix44>(DestPt, Attr::Transform, Tfm)) pActorEnt->Set<matrix44>(Attr::Transform, Rotate180 * Tfm); //???or fire SetTransform? else n_printf("Travel, Warning: destination point '%s' not found\n", DestPt.Get()); } pActorEnt->Set<nString>(Attr::LevelID, LevelID); LoaderSrv->CommitChangesToDB(); P = n_new(Data::CParams(1)); P->Set(CStrID("LevelID"), LevelID); EventMgr->FireEvent(CStrID("RequestLevel"), P); OK; }
int IPXCheckForAESReady(int ilevel) { ipx_socket_t *s; far_t ECBPtr; u_short rcode; s = ipx_socket_list; while (s) { if (s->AESCount) { ECBPtr = s->AESList; while (FARt_PTR(ECBPtr)) { if (AESECBp->TimeLeft == 0) { /* DANG_FIXTHIS - this architecture currently only supports firing of one AES event per call */ n_printf("IPX: AES event ready on ECB at %p\n", ECBp); printECB(ECBp); aesECB = ECBPtr; /* now remove the ECB from the AES list */ rcode = IPXCancelEvent(ECBPtr); if (rcode == RCODE_SUCCESS) { ECBp->CompletionCode = CC_SUCCESS; } return 1; /* run IRQ */ } ECBPtr = ECBp->Link; } } s = s->next; } return 0; }
void AESTimerTick(void) { ipx_socket_t *mysock; AESECB_t *ECB; /* run through the socket list, and process any pending AES events */ mysock = ipx_socket_list; while (mysock) { /* see if this socket has any AES events pending */ ECB = FARt_PTR(mysock->AESList); while (ECB) { if (ECB->TimeLeft > 0) { ECB->TimeLeft--; n_printf("IPX: AES timer decremented to %d on ECB at %p\n", ECB->TimeLeft, ECB); if (ECB->TimeLeft == 0) { /* now setup to call the ESR for this event */ pic_request(PIC_IPX_AES); return; } } ECB = FARt_PTR(ECB->Link); } mysock = mysock->next; } }
static int IPXReceivePacket(ipx_socket_t * s) { struct sockaddr_ipx ipxs; unsigned char buffer[MAX_PACKET_DATA]; far_t ECBPtr; int size; socklen_t sz; sz = sizeof(ipxs); size = recvfrom(s->fd, buffer, sizeof(buffer), 0, &ipxs, &sz); n_printf("IPX: received %d bytes of data\n", size); if (size > 0 && s->listenCount) { ECBPtr = s->listenList; printECB(ECBp); sz = ScatterFragmentData(size, buffer, ECBp, &ipxs); IPXCancelEvent(ECBPtr); /* if there was packet left over, then report a fragment error */ if (sz) { error("IPX: fragmentation error, %i left\n", sz); ECBp->CompletionCode = CC_FRAGMENT_ERROR; /* DANG_FIXTHIS - should remove this override, linux IPX stack returns bad sizes, but we ignore this here */ ECBp->CompletionCode = CC_SUCCESS; } else { ECBp->CompletionCode = CC_SUCCESS; } return 1; } return 0; }
void test2() { CondSignal(cond); /*Signalling the waiting thread */ y+=10; n_printf("\n value of x inside Test2 is %d", y); Join(tid1); }
int main() { n_printf("** ** ** Bonjour le monde ** ** **\n"); return 0; }
static int GatherFragmentData(u_char *buffer, ECB_t * ECB) { int i; int nextFragLen, totalDataCount; u_char *bufptr, *memptr; totalDataCount = 0; bufptr = buffer; for (i = 0; i < ECB->FragmentCount; i++) { nextFragLen = ECB->FragTable[i].Length; memptr = FARt_PTR(ECB->FragTable[i].Address); if (i == 0) { /* subtract off IPX header size from first fragment */ nextFragLen -= 30; memptr += 30; } if (nextFragLen) { /* DANG_FIXTHIS - dumb use of hardcoded 1500 here */ if (totalDataCount + nextFragLen > 1500) { return (-1); } memcpy(bufptr, memptr, nextFragLen); bufptr += nextFragLen; totalDataCount += nextFragLen; } } n_printf("IPX: gathered %d fragments for %d bytes of data\n", ECB->FragmentCount, totalDataCount); if (debug_level('n')) { dumpBytes(buffer, totalDataCount); } return (totalDataCount); }
int main() { n_printf("Beginning of the test of mapped file managment\n"); return 0; }
void ThreadTest() { int tid; tid = threadCreate("smr", SimpleThread); /* Creating a thread */ n_printf("Entering SimpleTest"); SimpleThread(2); /* Calling the function with argument to distinguish between the threads */ }
PParams CDataServer::ReloadHRD(const nString& FileName, bool Cache) { char* Buffer; int BytesRead = LoadFileToBuffer(FileName, Buffer); PParams Params; if (!pHRDParser.isvalid()) pHRDParser = n_new(CHRDParser); if (pHRDParser->ParseBuffer(Buffer, BytesRead, Params)) { n_printf("FileIO: HRD \"%s\" successfully loaded from HDD\n", FileName.Get()); if (Cache) HRDCache.Add(FileName.Get(), Params); //!!!???mangle/unmangle path to avoid duplicates? } else n_printf("FileIO: HRD parsing of \"%s\" failed\n", FileName.Get()); n_delete_array(Buffer); return Params; }
static void ipx_esr_call_setregs(far_t ECBPtr, u_char AXVal) { n_printf("IPX: Calling ESR at %04x:%04x of ECB at %04x:%04x\n", ECBp->ESRAddress.segment, ECBp->ESRAddress.offset, ECBPtr.segment, ECBPtr.offset); REG(es) = ECBPtr.segment; LWORD(esi) = ECBPtr.offset; LO(ax) = AXVal; }
void SimpleThread(int arg) { int num; for (num = 0; num < 5; num++) { n_printf("*** thread %d looped %d times\n", arg, num); Yield(); } }
/************************* * Check for IPX - int 2f, AH=7A * returns AL=FF * ES:DI points to helper routine which gets to FarCallHandler *************************/ int IPXInt2FHandler(void) { LO(ax) = 0xff; REG(es) = IPX_SEG; LWORD(edi) = IPX_OFF; n_printf("IPX: request for IPX far call handler address %x:%x\n", IPX_SEG, IPX_OFF); return 1; }
static void ipx_esr_call(far_t ECBPtr, u_char AXVal) { struct vm86_regs saved_regs; saved_regs = REGS; ipx_esr_call_setregs(ECBPtr, AXVal); do_call_back(ECBp->ESRAddress.segment, ECBp->ESRAddress.offset); REGS = saved_regs; n_printf("IPX: ESR callback ended\n"); }
int ipx_receive(int ilevel) { /* DOS program has given us a time slice */ /* let's use this as an opportunity to poll outstanding listens */ fd_set fds; int selrtn; ipx_socket_t *s; far_t ECBPtr; struct timeval timeout; FD_ZERO(&fds); ipx_fdset(&fds); timeout.tv_sec = 0; timeout.tv_usec = 0; n_printf("IPX: select\n"); switch ((selrtn = select(255, &fds, NULL, NULL, &timeout))) { case 0: /* none ready */ /* n_printf("IPX: no receives ready\n"); */ break; case -1: /* error (not EINTR) */ error("bad ipc_select: %s\n", strerror(errno)); break; default: /* has at least 1 descriptor ready */ n_printf("IPX: receive ready (%i), checking fd\n", selrtn); if ((s = check_ipx_ready(&fds))) { ECBPtr = s->listenList; if (IPXReceivePacket(s)) { if (FARt_PTR(ECBp->ESRAddress)) { recvECB = ECBPtr; return 1; /* run IRQ */ } } } break; } return 0; }
int main() { int i, j, key; Write("Start sort\n",11,ConsoleOutput); /* first initialize the array, in reverse sorted order */ for (i = 0; i < NUM; i++) A[i] = NUM - i; for (i = 0; i < NUM; i++) { n_printf("%d ",A[i]); } n_printf("\n"); /* Write("\n\n",2,ConsoleOutput);*/ /* then sort! */ for (j=1;j<NUM;j++) { key = A[j]; i = j - 1; while (i>= 0 && A[i] > key) { A[i+1] = A[i]; i--; } A[i+1] = key; } for (i = 0; i < NUM; i++) { n_printf("%d ",A[i]); } n_printf("\n"); Write("End sort\n",9,ConsoleOutput); Exit(A[0]); /* and then we're done -- should be 0! */ return 0; }
PXMLDocument CDataServer::LoadXML(const nString& FileName) //, bool Cache) { char* Buffer; int BytesRead = DataSrv->LoadFileToBuffer(FileName, Buffer); PXMLDocument XML = n_new(CXMLDocument); if (XML->Parse(Buffer, BytesRead) == tinyxml2::XML_SUCCESS) { n_printf("FileIO: XML \"%s\" successfully loaded from HDD\n", FileName.Get()); //if (Cache) XMLCache.Add(FileName.Get(), XML); //!!!???mangle/unmangle path to avoid duplicates? } else { n_printf("FileIO: XML parsing of \"%s\" failed: %s. %s.\n", FileName.Get(), XML->GetErrorStr1(), XML->GetErrorStr2()); XML = NULL; } n_delete_array(Buffer); return XML; }
PParams CDataServer::ReloadPRM(const nString& FileName, bool Cache) { CFileStream File; if (!File.Open(FileName, SAM_READ)) return NULL; CBinaryReader Reader(File); PParams Params; Params.Create(); if (Reader.ReadParams(*Params)) { if (Cache) HRDCache.Add(FileName.Get(), Params); //!!!???mangle path to avoid duplicates? n_printf("FileIO: PRM \"%s\" successfully loaded from HDD\n", FileName.Get()); } else { Params = NULL; n_printf("FileIO: PRM loading from \"%s\" failed\n", FileName.Get()); } return Params; }
static u_char IPXCloseSocket(u_short port) { ipx_socket_t *mysock; far_t ECBPtr; /* see if this socket is actually open */ n_printf("IPX: close socket %x\n", port); mysock = ipx_find_socket(port); if (mysock == NULL) { n_printf("IPX: close of unopened socket\n"); return (RCODE_SOCKET_NOT_OPEN); } /* cancel all pending events on this socket */ n_printf("IPX: canceling all listen events on socket %x\n", port); ECBPtr = mysock->listenList; while (FARt_PTR(ECBPtr)) { if (IPXCancelEvent(ECBPtr) != RCODE_SUCCESS) return RCODE_CANNOT_CANCEL_EVENT; ECBPtr = mysock->listenList; } n_printf("IPX: canceling all AES events on socket %x\n", port); ECBPtr = mysock->AESList; while (FARt_PTR(ECBPtr)) { if (IPXCancelEvent(ECBPtr) != RCODE_SUCCESS) return RCODE_CANNOT_CANCEL_EVENT; ECBPtr = mysock->AESList; } /* now close the file descriptor for the socket, and free it */ n_printf("IPX: closing file descriptor on socket %x\n", port); remove_from_io_select(mysock->fd); close(mysock->fd); ipx_remove_socket(mysock); n_printf("IPX: successfully closed socket %x\n", port); return (RCODE_SUCCESS); }
void CNebula2Logger::logEvent(const CEGUI::String& message, CEGUI::LoggingLevel level) { if (Enable && level <= getLoggingLevel()) switch (level) { case CEGUI::Errors: //nKernelServer::Instance()->Error("%s\n", message.c_str()); ///!!! TODO //break; case CEGUI::Standard: case CEGUI::Informative: case CEGUI::Insane: n_printf("%s\n", message.c_str()); break; default: n_error("Unknown CEGUI logging level\n"); } }