DIPrinter &DIPrinter::operator<<(const DILineInfo &Info) { printName(Info, false); return *this; }
void *accepted(void *csd){ PEER *p = (PEER *) csd; DATA *data = malloc(sizeof(DATA)); DATA *reply = malloc(sizeof(DATA)); int client_sd = p->client_sd; int len, status; int id = p->id; while(1){ printf("B4 recv data\n"); data = recv_data(client_sd,(unsigned int *)&len,&status); printf("AFTER recv data\n"); switch(status){ case -1: case -2: printf("Status = error(%d)\n", status); close(client_sd); offline(id); printf("[Disconnected] Client %s:%d\n", getClientAddr(&p->client_addr), ntohs(p->client_addr.sin_port)); return 0; default: break; } printf("DATA command: %d\n", data->command); switch(data->command){ case LOGIN: printf("Client %s:%d: [LOGIN] Username="******"\n"); data->arg->ip = ntohl(p->client_addr.sin_addr.s_addr); status = online(data->arg, id); if(status >= 0 && status < 10){ reply = newHeader(); reply->command = LOGIN_OK; reply->length = 1; if(!send_data(client_sd,reply,(unsigned int*)&len)) return 0; }else{ printf("[ERROR] Client %s:%d ", getClientAddr(&p->client_addr), ntohs(p->client_addr.sin_port)); reply = newHeader(); reply->command = ERROR; switch(status){ case -1: printf("maximum connection exceed!"); reply->error = TOO_MUCH_CONN; break; case -2: printf("duplication of name!"); reply->error = SAME_NAME; break; case -3: printf("duplication of port and IP address!"); reply->error = SAME_CONN; } printf("\n"); reply->length = 7; if(!send_data(client_sd,reply,(unsigned int*)&len)) return 0; close(client_sd); printf("[Disconnected] Client %s:%d\n", getClientAddr(&p->client_addr), ntohs(p->client_addr.sin_port)); return 0; } break; case GET_LIST: printf("Client %s:%d: GET_LIST\n", getClientAddr(&p->client_addr), ntohs(p->client_addr.sin_port)); reply = newHeader(); reply->command = GET_LIST_OK; getOnlineList(reply); reply->length += 7; if(!send_data(client_sd,reply,(unsigned int*)&len)) return 0; break; default: printf("Client %s:%d: Unknown command\n", getClientAddr(&p->client_addr), ntohs(p->client_addr.sin_port)); break; } } if(client_sd) close(client_sd); offline(id); printOnlineList(); printf("[Disconnected] Client %s:%d\n", getClientAddr(&p->client_addr), p->client_addr.sin_port); }
/* Berechnet naiv die unterschiedlichen Zeilen von zwei Dateien und gibt diese aus. */ int main() { FILE *fp1, *fp2,*lastfp; char fname1[32], fname2[32], output[64]; unsigned int wrong = 0; unsigned int line = 0; char *getF1, *getF2, *getLastFile; int size = 8; char buffer1[size], buffer2[size]; //! initialized with size variable /*Lese Dateiname ein.*/ printf("Enter name of first file :"); scanf("%s",fname1); //! replaced insecure gets with scanf printf("Enter name of second file:"); scanf("%s",fname2); //! replaced insecure gets with scanf printf("\n\n"); fp1 = openfile(fname1); fp2 = openfile(fname2); if (fp1 == NULL) { return EXIT_FAILURE; } else if (fp2 == NULL) { return EXIT_FAILURE; } /* Wir lesen die Dateien aus und vergleichen die Strings. Wir zaehlen die Anzahl der ungleichen Zeilen. */ getF1 = fgets(buffer1,size,fp1); getF2 = fgets(buffer2,size,fp2); getLastFile = NULL; while((getF1 != NULL) && (getF2!= NULL)) { //! if we want to avoid to not match a last line that matches it's not last line counterpart, we need to remove the '\n' before comparing. char buffer1_c[size], buffer2_c[size]; //! strcpy(buffer1_c,buffer1); //! strcpy(buffer2_c,buffer2); //! strtok(buffer1_c,"\n"); //! strtok(buffer2_c,"\n"); //! if(strcmp(buffer1_c,buffer2_c) != 0) //! { wrong++; printf("Ungleiche Zeile.\n"); /* Gebe die Zeile aus der ersten Datei aus. */ printName(output,fname1); printf("%s",buffer1); if(!strchr(buffer1,'\n')) { memset(buffer1,0,size); //! empty buffer before refilling getF1 = printLine(fp1,buffer1,size); if(feof(fp1)) printf("\n"); //! add linebreak at end of file } else { memset(buffer1,0,size); //! empty buffer before refilling getF1 = fgets(buffer1,size,fp1) ; } /* Gebe die Zeile aus der zweiten Datei aus. */ printName(output,fname2); printf("%s",buffer2); //! resolved uncontrolled format /* Überprüfe, ob die letzte Zeile ausgegeben werden muss. */ if(!strchr(buffer2,'\n')) { memset(buffer2,0,size); //! empty buffer before refilling getF2 = printLine(fp2,buffer2,size); if(feof(fp2)) printf("\n"); //! add linebreak at end of file } else { memset(buffer2,0,size); //! empty buffer before refilling getF2 = fgets(buffer2,size,fp2) ; } } else { memset(buffer1,0,size); //! empty buffer before refilling memset(buffer2,0,size); //! empty buffer before refilling getF1 = fgets(buffer1,size,fp1) ; getF2 = fgets(buffer2,size,fp2) ; } line++; printf("\t\t\tline = %3d | wrong = %3d \n",line,wrong); } /* Falls eine Datei früher komplett gelesen wurde. Wir geben den Dateinamen und den Rest aus dem Buffer aus. */ if(!(getF1 == NULL)) { getLastFile = getF1; lastfp = fp1; printf("Verbleibende Zeilen.\n"); printName(output,fname1); // printf(buffer1); //! } else if(!(getF2 == NULL)) { getLastFile = getF2; lastfp = fp2; printf("Verbleibende Zeilen.\n"); printName(output,fname2); strcpy(buffer1,buffer2); //! // printf(buffer2); //! } /* Wir lesen die restliche Datei aus. */ if(getLastFile != NULL) { // getLastFile = fgets(buffer1,size,lastfp); //! while(getLastFile !=NULL) { wrong++; printf("%s",buffer1); //! resolved uncontrolled format if(!strchr(buffer1,'\n')) //! distinguish between complete lines and incomplete lines { memset(buffer1,0,size); //! empty buffer before refilling getLastFile = printLine(lastfp,buffer1,size); if(feof(fp2)) printf("\n"); //! add linebreak at end of file } else { memset(buffer1,0,size); //! empty buffer before refilling getLastFile = fgets(buffer1,size,lastfp); } line++; printf("\t\t\tline = %3d | wrong = %3d \n",line,wrong); } } /* Sind die Datein verschieden? */ if(wrong > 0) { printf("\n\nDateien sind ungleich. Anzahl ungleicher Zeilen: %d\n",wrong); } else { printf("\n\nDateien sind gleich.\n"); } fclose(fp1); fclose(fp2); return (0); }
string Zoo::getThem(){ printName(); return getColor(); }
void printValue(llvm::raw_ostream &out, EValuePtr ev) { switch (ev->type->typeKind) { case BOOL_TYPE : { bool v = ev->as<bool>(); out << (v ? "true" : "false"); break; } case INTEGER_TYPE : { IntegerType *t = (IntegerType *)ev->type.ptr(); if (t->isSigned) { switch (t->bits) { case 8 : out << int(ev->as<signed char>()); break; case 16 : out << ev->as<short>(); break; case 32 : out << ev->as<int>(); break; case 64 : out << ev->as<long long>(); break; default : assert(false); } } else { switch (t->bits) { case 8 : out << int(ev->as<unsigned char>()); break; case 16 : out << ev->as<unsigned short>(); break; case 32 : out << ev->as<unsigned int>(); break; case 64 : out << ev->as<unsigned long long>(); break; default : assert(false); } } break; } case FLOAT_TYPE : { FloatType *t = (FloatType *)ev->type.ptr(); switch (t->bits) { case 32 : writeFloat(out, ev->as<float>()); break; case 64 : writeFloat(out, ev->as<double>()); break; case 80 : writeFloat(out, ev->as<long double>()); break; default : assert(false); } break; } case COMPLEX_TYPE : { ComplexType *t = (ComplexType *)ev->type.ptr(); switch (t->bits) { case 32 : writeFloat(out, ev->as<clay_cfloat>()); break; case 64 : writeFloat(out, ev->as<clay_cdouble>()); break; case 80 : writeFloat(out, ev->as<clay_cldouble>()); break; default : assert(false); } break; } case ENUM_TYPE : { EnumType *t = (EnumType *)ev->type.ptr(); llvm::ArrayRef<EnumMemberPtr> members = t->enumeration->members; int member = ev->as<int>(); if (member >= 0 && size_t(member) < members.size()) { out << members[(size_t)member]->name->str; } else { printName(out, t); out << '(' << member << ')'; } break; } default : break; } }
nmethod* SICompiler::compile() { EventMarker em("SIC-compiling %#lx %#lx", L->selector(), NULL); ShowCompileInMonitor sc(L->selector(), "SIC", recompilee != NULL); // cannot recompile uncommon branches in DI nmethods & top nmethod yet FlagSetting fs2(SICDeferUncommonBranches, SICDeferUncommonBranches && diLink == NULL && L->adeps->length() == 0 && L->selector() != VMString[DO_IT]); // don't use uncommon traps when recompiling because of trap useUncommonTraps = SICDeferUncommonBranches && !currentProcess->isUncommon(); // don't inline into doIt FlagSetting fs3(Inline, Inline && L->selector() != VMString[DO_IT]); # if TARGET_ARCH != I386_ARCH // no FastMapTest possible on I386 // don't use fast map loads if this nmethod trapped a lot FlagSetting fs4(FastMapTest, FastMapTest && (recompilee == NULL || recompilee->flags.trapCount < MapLoadTrapLimit)); # endif FlagSetting fs5(PrintCompilation, PrintCompilation || PrintSICCompilation); timer t; FlagSetting fs6(verifyOften, SICDebug || CheckAssertions); if(PrintCompilation || PrintLongCompilation || PrintCompilationStatistics || VMSICLongProfiling) { t.start(); } if (PrintCompilation || PrintSICCode) { lprintf("*SIC-%s%scompiling %s%s: (SICCompilationCount=%d)", currentProcess->isUncommon() ? "uncommon-" : "", recompilee ? "re" : "", sprintName( (methodMap*) method()->map(), L->selector()), sprintValueMethod( L->receiver ), (void*)SICCompilationCount); } topScope->genCode(); buildBBs(); if (verifyOften) bbIterator->verify(false); bbIterator->eliminateUnreachableNodes(); // needed for removeUptoMerge to work // compute exposed blocks and up-level accessed vars bbIterator->computeExposedBlocks(); bbIterator->computeUplevelAccesses(); // make defs & uses and insert flush nodes for uplevel-accessed vars bbIterator->makeUses(); // added verify here cause want to catch unreachable merge preds // before elimination -- dmu if (verifyOften) bbIterator->verify(); if (SICLocalCopyPropagate) { bbIterator->localCopyPropagate(); if (verifyOften) bbIterator->verify(); } if (SICGlobalCopyPropagate) { bbIterator->globalCopyPropagate(); if (verifyOften) bbIterator->verify(); } if (SICEliminateUnneededNodes) { bbIterator->eliminateUnneededResults(); if (verifyOften) bbIterator->verify(); } // do after CP to explot common type test source regs if (SICOptimizeTypeTests) { bbIterator->computeDominators(); bbIterator->optimizeTypeTests(); if (verifyOften) bbIterator->verify(); } // allocate the temp (i.e. volatile) registers bbIterator->allocateTempRegisters(); // allocate the callee-saved (i.e. non-volatile) registers SICAllocator* a = theAllocator; a->allocate(bbIterator->globals, topScope->incoming); stackLocCount = a->stackTemps; // make sure frame size is aligned properly int32 frame_size_so_far = frameSize(); stackLocCount += roundTo(frame_size_so_far, frame_word_alignment) - frame_size_so_far; // compute the register masks for inline caches bbIterator->computeMasks(stackLocCount, nonRegisterArgCount()); topScope->computeMasks(regStringToMask(topScope->incoming), stackLocCount, nonRegisterArgCount()); if (PrintSICCode) { print_code(false); lprintf("\n\n"); } topScope->describe(); // must come before gen to set scopeInfo genHelper = new SICGenHelper; bbIterator->gen(); assert(theAssembler->verifyLabels(), "undefined labels"); rec->generate(); topScope->fixupBlocks(); // must be after rec->gen to know offsets if (vscopes) computeMarkers(); // ditto nmethod* nm = new_nmethod(this, false); if (theAssembler->lastBackpatch >= theAssembler->instsEnd) fatal("dangling branch"); em.event.args[1] = nm; fint ms = IntervalTimer::dont_use_any_timer ? 0 : t.millisecs(); if (PrintCompilation || PrintLongCompilation) { if (!PrintCompilation && PrintLongCompilation && ms >= MaxCompilePause) { lprintf("*SIC-%s%scompiling ", currentProcess->isUncommon() ? "uncommon-" : "", recompilee ? "re" : ""); methodMap* mm = method() ? (methodMap*) method()->map() : NULL; printName(mm, L->selector()); lprintf(": %#lx (%ld ms; level %ld)\n", nm, (void*)ms, (void*)nm->level()); } else if (PrintCompilation) { lprintf(": %#lx (%ld ms; level %ld v%d)\n", (void*)nm, (void*)ms, (void*)nm->level(), (void*)nm->version()); } } if (SICDebug && estimatedSize() > inlineLimit[NmInstrLimit]) { float rat = (float)estimatedSize() / (float)nm->instsLen(); lprintf("*est. size = %ld, true size = %ld, ratio = %4.2f\n", (void*)estimatedSize(), (void*)nm->instsLen(), *(void**)&rat); } if (PrintCompilationStatistics) { static fint counter = 0; lprintf("\n*SIC-time= |%ld| ms; to/co/sc/lo/de= |%ld|%ld|%ld|%ld|%ld| %ld|%ld|%ld| %ld |", (void*)ms, (void*) (nm->instsLen() + nm->scopes->length() + nm->locsLen() + nm->depsLen), (void*)nm->instsLen(), (void*)nm->scopes->length(), (void*)nm->locsLen(), (void*)nm->depsLen, (void*)BasicNode::currentID, (void*)bbIterator->bbCount, (void*)ncodes, (void*)counter++); } # if GENERATE_DEBUGGING_AIDS if (CheckAssertions) { // nm->verify(); } # endif return nm; }
int main( int argc, char *argv[] ) { int c; /* Command line character */ char * path; /* Path being processed */ me = argv[0]; add_ignore( "." ); add_ignore( ".." ); while( (c = getopt( argc, argv, "aDc:dhFfgl:i:n:o:psuW:w" )) != EOF ) { switch( c ) { default: fprintf( stderr, "%s: no -%c yet!\n", me, c ); /*FALLTHRU*/ case '?': ++nonfatal; break; case 'D': ++debug; break; case 'a': ++a_sw; break; case 'c': whatColumn = atoi( optarg ); break; case 'd': ++d_sw; break; case 'F': ++F_sw; break; case 'f': ++f_sw; break; case 'g': combo_sw |= Iwanna_group; break; case 'h': combo_sw |= Iwanna_size; break; case 'i': add_ignore( optarg ); break; case 'l': depth = atoi( optarg ); break; case 'p': combo_sw |= Iwanna_perms; break; case 'o': ofile = optarg; break; case 's': ++s_sw; break; case 'u': combo_sw |= Iwanna_user; break; case 'W': leadin = optarg; Nleadin = strlen( leadin ); break; case 'w': ++w_sw; break; } } if( nonfatal ) { fprintf( stderr, "%s: illegal switch(es)\n", me ); fprintf( stderr, "usage: %s " "[-D] " "[-a] " "[-d] " "[-c] " "[-d depth] " "[-f] " "[-l limit] " "[-i subdir] " "[-s] " "[-o ofile] " "[-p] " "[-W prefix] " "[-w] " "[dir...]" "\n", me ); exit( 1 ); } if( ofile ) { (void) unlink( ofile ); if( freopen( ofile, "w", stdout ) != stdout ) { fprintf(stderr, "%s: cannot create '%s'\n", me, ofile); exit( 1 ); } } /* Take path list from command if anything left on it */ if( optind < argc ) { struct stat st; int others = 0; while( optind < argc ) { if( others++ ) { putchar( '\n' ); } path = argv[ optind++ ]; if( stat( path, &st ) ) { fprintf( stderr, "%s: " "cannot stat '%s'; " "errno=%d (%s)" ".\n", me, path, errno, strerror( errno ) ); ++nonfatal; continue; } printName( path, &st, 0, 1 ); processDirectory( path, 1 ); } } else { /* Default to current directory */ char here[ PATH_MAX + 1 ]; struct stat st; if( !getcwd( here, sizeof( here ) ) ) { fprintf( stderr, "%s: getcwd() failed; errno=%d (%s).\n", me, errno, strerror( errno ) ); exit( 1 ); } if( stat( here, &st ) ) { fprintf( stderr, "%s: " "cannot stat '%s'; " "errno=%d (%s)" ".\n", me, here, errno, strerror( errno ) ); } else { printName( here, &st, 0, 1 ); processCurrentDirectory( here ); } } return( nonfatal ? 1 : 0 ); }
void CJsonFormatter::nullValue(const std::string & name) { printName(name); buf << "null"; }
void CJsonFormatter::intValue(const std::string & name, ssize_t value) { printName(name); printValue(value); }
void main(void) { char nameList[8] = {0}; int testData[8][2] = {{0,1},{2,3},{4,5},{6,7},{7,6},{5,4},{3,2},{1,0}}; // int testData[8][2] = {{0,1},{1,2},{2,3},{3,4},{3,5},{3,2},{3,1},{3,0}}; // int testData[10][2] = {{TOM,JERRY},{MARK,AVIL},{BILL,CATE},{DAVID,EVAN},{MARK,BILL},{AVIL,CATE},{BILL,DAVID},{CATE,EVAN},{MARK,CATE},{AVIL,BILL}}; // int testData[2][2] = {{TOM,JERRY},{TOM,AVIL}}; int i, j; for(i = 0; i < 8; i++) { nameList[i] = 1 << i; } for(i = 0; i < 8; i++) { switch(testData[i][0]) { case TOM: nameList[TOM] |= 1 << testData[i][1]; break; case JERRY: nameList[JERRY] |= 1 << testData[i][1]; break; case MARK: nameList[MARK] |= 1 << testData[i][1]; break; case AVIL: nameList[AVIL] |= 1 << testData[i][1]; break; case BILL: nameList[BILL] |= 1 << testData[i][1]; break; case CATE: nameList[CATE] |= 1 << testData[i][1]; break; case DAVID: nameList[DAVID] |= 1 << testData[i][1]; break; case EVAN: nameList[EVAN] |= 1 << testData[i][1]; break; default: _Exit(-1); } switch(testData[i][1]) { case TOM: nameList[TOM] |= 1 << testData[i][0]; break; case JERRY: nameList[JERRY] |= 1 << testData[i][0]; break; case MARK: nameList[MARK] |= 1 << testData[i][0]; break; case AVIL: nameList[AVIL] |= 1 << testData[i][0]; break; case BILL: nameList[BILL] |= 1 << testData[i][0]; break; case CATE: nameList[CATE] |= 1 << testData[i][0]; break; case DAVID: nameList[DAVID] |= 1 << testData[i][0]; break; case EVAN: nameList[EVAN] |= 1 << testData[i][0]; break; default: _Exit(-1); } } for(i = 0; i < 8; i++) { for(j = i + 1; j < 8; j++) { if((nameList[i] & nameList[j]) != 0) { nameList[i] |= nameList[j]; nameList[j] = nameList[i]; continue; } } } for(i = 0; i < 8; i++) { for(j = 0; j < 8; j++) { if(j == i) { continue; } else { printf("Are "); printName(i); printf(" & "); printName(j); printf(" friends? "); ((nameList[i] & 1 << j) == 0) ? printf("No\n") : printf("Yes\n"); } } } }
/* decode and parse tbsResponseData, sitting in SecAsn1OCSPBasicResponse as an * ASN_ANY */ static int parseResponseData( SecAsn1CoderRef coder, int indent, const CSSM_DATA &tbsResponseData) { SecAsn1OCSPResponseData respData; SecAsn1OCSPResponderID responderID; uint8 tag; const SecAsn1Template *templ; unsigned numExts; memset(&respData, 0, sizeof(respData)); OSStatus ortn = SecAsn1DecodeData(coder, &tbsResponseData, kSecAsn1OCSPResponseDataTemplate, &respData); if(ortn) { printf("***Error decoding ResponseData\n"); return 1; } if(respData.version && respData.version->Data) { doIndent(indent); printf("version: %u\n", respData.version->Data[0]); } doIndent(indent); printf("ResponderID:\n"); indent += 2; memset(&responderID, 0, sizeof(responderID)); if(respData.responderID.Data == NULL) { doIndent(indent); printf("***Malformed(empty)***\n"); return 1; } /* lame-o choice processing */ tag = respData.responderID.Data[0] & SEC_ASN1_TAGNUM_MASK; switch(tag) { case RIT_Name: templ = kSecAsn1OCSPResponderIDAsNameTemplate; break; case RIT_Key: templ = kSecAsn1OCSPResponderIDAsKeyTemplate; break; default: doIndent(indent); printf("**Unknown tag for ResponderID (%u)\n", tag); return 1; } ortn = SecAsn1DecodeData(coder, &respData.responderID, templ, &responderID); if(ortn) { doIndent(indent); printf("***Error decoding ResponderID\n"); return 1; } doIndent(indent); switch(tag) { case RIT_Name: printf("byName:\n"); printName((NSS_Name &)responderID.byName, indent + 2); break; case RIT_Key: printf("byKey : "); printDataAsHex(&responderID.byKey); break; } indent -= 2; // end of ResponderID doIndent(indent); printf("producedAt: "); printString(&respData.producedAt); unsigned numResps = ocspdArraySize((const void **)respData.responses); doIndent(indent); printf("Num responses: %u\n", numResps); for(unsigned dex=0; dex<numResps; dex++) { SecAsn1OCSPSingleResponse *resp = respData.responses[dex]; doIndent(indent); printf("Response %u:\n", dex); indent += 2; doIndent(indent); printf("CertID:\n"); dumpCertID(&resp->certID, indent + 2); doIndent(indent); printf("certStatus: "); /* lame-o choice processing */ tag = resp->certStatus.Data[0] & SEC_ASN1_TAGNUM_MASK; switch(tag) { case CS_Good: printf("Good\n"); break; case CS_Unknown: printf("Unknown\n"); break; default: printf("**MALFORMED cert status tag (%u)\n", tag); break; case CS_Revoked: { printf("Revoked\n"); doIndent(indent); SecAsn1OCSPCertStatus certStatus; memset(&certStatus, 0, sizeof(certStatus)); ortn = SecAsn1DecodeData(coder, &resp->certStatus, kSecAsn1OCSPCertStatusRevokedTemplate, &certStatus); if(ortn) { doIndent(indent); printf("***error parsing RevokedInfo\n"); break; } if(certStatus.revokedInfo == NULL) { doIndent(indent); printf("***GAK! Malformed (empty) revokedInfo\n");break; } printf("RevokedIndfo:\n"); indent += 2; doIndent(indent); printf("revocationTime: "); printString(&certStatus.revokedInfo->revocationTime); if(certStatus.revokedInfo->revocationReason) { doIndent(indent); printf("reason: %u\n", certStatus.revokedInfo->revocationReason->Data[0]); } indent -= 2; // end of RevokedInfo break; } } /* switch cert status tag */ doIndent(indent); printf("thisUpdate: "); printString(&resp->thisUpdate); if(resp->nextUpdate) { doIndent(indent); printf("nextUpdate: "); printString(resp->nextUpdate); } numExts = ocspdArraySize((const void **)resp->singleExtensions); for(unsigned extDex=0; extDex<numExts; extDex++) { doIndent(indent); printf("singleExtensions[%u]\n", extDex); printOcspExt(coder, resp->singleExtensions[extDex], indent + 2); } indent -= 2; // end of resp[dex] } numExts = ocspdArraySize((const void **)respData.responseExtensions); for(unsigned extDex=0; extDex<numExts; extDex++) { doIndent(indent); printf("responseExtensions[%u]\n", extDex); printOcspExt(coder, respData.responseExtensions[extDex], indent + 2); } return 0; }
static void storeInfoAboutEntry(int fd, struct pcdir *dp, struct pcdir *ldp, int depth, int32_t longEntryStartCluster, char *fullPath, int *fullLen) { struct nameinfo *pathCopy; int32_t start; int haveBad; int hidden = (dp->pcd_attr & PCA_HIDDEN || dp->pcd_attr & PCA_SYSTEM); int dir = (dp->pcd_attr & PCA_DIR); int i; if (hidden) HiddenFileCount++; else if (dir) DirCount++; else FileCount++; appendToPath(dp, fullPath, fullLen); /* * Make a copy of the name at this point. We may want it to * note the original source of an orphaned cluster. */ if ((pathCopy = (struct nameinfo *)malloc(sizeof (struct nameinfo))) != NULL) { if ((pathCopy->fullName = (char *)malloc(*fullLen + 1)) != NULL) { pathCopy->references = 0; (void) strncpy(pathCopy->fullName, fullPath, *fullLen); pathCopy->fullName[*fullLen] = '\0'; } else { free(pathCopy); pathCopy = NULL; } } if (Verbose) { for (i = 0; i < depth; i++) (void) fprintf(stderr, " "); if (hidden) (void) fprintf(stderr, "["); else if (dir) (void) fprintf(stderr, "|_"); else (void) fprintf(stderr, gettext("(%06d) "), FileCount); printName(stderr, dp); if (hidden) (void) fprintf(stderr, "]"); (void) fprintf(stderr, gettext(", %u bytes, start cluster %d"), extractSize(dp), extractStartCluster(dp)); (void) fprintf(stderr, "\n"); } start = extractStartCluster(dp); haveBad = noteUsage(fd, start, dp, ldp, longEntryStartCluster, hidden, dir, pathCopy); if (haveBad > 0) { if (dir && pathCopy->fullName != NULL) { (void) fprintf(stderr, gettext("Adjusting for bad allocation units in " "the meta-data of:\n ")); (void) fprintf(stderr, pathCopy->fullName); (void) fprintf(stderr, "\n"); } truncChainWithBadCluster(fd, dp, start); } if ((pathCopy != NULL) && (pathCopy->references == 0)) { free(pathCopy->fullName); free(pathCopy); } }
//------------------------------------------------------------------- int main(int argc, char *argv[]) { xmlDocPtr doc; xmlNodePtr cur; //Checks for the .xml file name if (argc==1) { fprintf(stderr, "No file name passed."); return -1; } //Opens the .xml file given as an argument doc = xmlParseFile(argv[1]); //Catches an error in parsing the file if (doc == NULL ) { fprintf(stderr,"Document not parsed successfully. \n"); return -1; } cur = xmlDocGetRootElement(doc); //Catches the error of passing a blank document if (cur == NULL) { fprintf(stderr,"Empty document.\n"); xmlFreeDoc(doc); return -1; } //Catches the error of passing a document with a different root tag if (!tagNameIs("help",cur)) { fprintf(stderr,"Document id of the wrong type, " "the root node is not help.\n"); xmlFreeDoc(doc); return -1; } if (argc==2) printf("No output specified.\nOutput will be sent to output.html.\n"); FILE *outFile; outFile=fopen(argc>2?argv[2]:"output.html", "w"); cur=cur->xmlChildrenNode; fprintf(outFile, "<html>\n<body>\n<basefont face=\"sans-serif\"></basefont>\n"); int exampleNum=1; //Outputs the file while (cur != NULL) { //Outputs the arugments of the file if (tagNameIs("arguments",cur)||tagNameIs("outputs",cur)) { xmlNodePtr argumentType; argumentType=(tagNameIs("arguments",cur))?cur->xmlChildrenNode:cur; while (argumentType!=NULL) { if (!tagNameIs("text",argumentType)) { printName(argumentType,outFile); if (tagNameIs("arguments",cur)) fprintf(outFile," ARGUMENTS"); fprintf(outFile,"</h1>"); xmlNodePtr argumentElement; argumentElement=argumentType->xmlChildrenNode; int first=1, justIntro=0, justArg=0; // fprintf (outFile,"\n<table border=\"3\">\n"); while (1) { if (!tagNameIs("text",argumentElement)) { if ((first||justIntro)&&!tagNameIs("intro",argumentElement)) fprintf (outFile, "\n<table border=\"3\">\n<tr><th>%s</th><th>" "Explanation</th></tr>\n", (tagNameIs("arguments",cur))?"Argument":"Output"); if (justArg) { if (tagNameIs("argument",argumentElement)|| tagNameIs("output",argumentElement)) fprintf(outFile, "<td> </td>\n"); justArg=0; } else if (tagNameIs("explanation",argumentElement)) fprintf(outFile, "</tr>\n<tr>\n<td> </td>\n"); if (tagNameIs("argument",argumentElement)|| tagNameIs("output",argumentElement)) justArg=1; if (tagNameIs("intro",argumentElement)) { char *c, *intro; c= (char *)xmlNodeListGetString (doc, argumentElement->xmlChildrenNode, 1); if (first) { intro= malloc(strlen("\n<h3>")+strlen(c)+1); strcpy(intro,"\n<h3>"); first=0; } else { intro= malloc(strlen("</tr>\n</table>\n<h3>")+strlen(c)+1); strcpy(intro,"</tr>\n</table>\n<h3>"); } intro=strcat(intro,c); free(c); while (tagNameIs("intro",argumentElement->next)|| tagNameIs("text",argumentElement->next)) { if (!tagNameIs("text",argumentElement->next)) { char *content; content= (char *)xmlNodeListGetString (doc, argumentElement->next->xmlChildrenNode, 1); char *secondHalf= malloc(strlen("<br />") +strlen(content)+ 1); strcpy(secondHalf,"<br />"); secondHalf=strcat(secondHalf,content); char *temp= malloc(strlen(intro)+strlen(secondHalf)+1); strcpy(temp,intro); temp=strcat(temp,secondHalf); free(intro); intro=temp; } argumentElement=argumentElement->next; } char *temp= malloc(strlen(intro)+strlen("</h3>\n"+1)); strcpy(temp,intro); temp=strcat(temp,"</h3>"); free(intro); intro=temp; fprintf(outFile,"%s\n",intro); free(intro); justIntro=1; } else { if (first) first=0; else if ((tagNameIs("argument",argumentElement)|| tagNameIs("output",argumentElement))&&!justIntro) fprintf(outFile, "</tr>\n"); justIntro=0; printTableContents(doc,argumentElement,outFile); } } argumentElement= argumentElement->next; if (argumentElement==NULL) { if (!justIntro) fprintf (outFile,"</tr>\n</table>\n"); break; } } } if (!tagNameIs("arguments",cur)) break; argumentType=argumentType->next; } } //Outputs all the other tags else if (!tagNameIs("text",cur)) { printName(cur,outFile); if (tagNameIs("EXAMPLE",cur)) fprintf(outFile," %d",exampleNum++); fprintf(outFile,"</h1>"); printContents(doc,cur,outFile); } cur=cur->next; } fprintf(outFile,"</html>\n</body>\n"); return EXIT_SUCCESS; }
/* Berechnet naiv die unterschiedlichen Zeilen von zwei Dateien und gibt diese aus. */ int main() { FILE *fp1, *fp2,*lastfp; char fname1[32], fname2[32], output[64]; int8_t wrong = 0; char *getF1, *getF2, *getLastFile; char buffer1[8], buffer2[8]; int size = 8; /*Lese Dateiname ein.*/ printf("Enter name of first file :"); gets(fname1); printf("Enter name of second file:"); gets(fname2); fp1 = openfile(fname1); fp2 = openfile(fname2); if (fp1 == NULL) { return EXIT_FAILURE; } else if (fp2 == NULL) { return EXIT_FAILURE; } /* Wir lesen die Dateien aus und vergleichen die Strings. Wir zaehlen die Anzahl der ungleichen Zeilen. */ getF1 = fgets(buffer1,size,fp1) ; getF2 = fgets(buffer2,size,fp2) ; getLastFile = NULL; while((getF1 != NULL) && (getF2!= NULL)) { if(strcmp(buffer1,buffer2) != 0) { /* Gebe die Zeile aus der zweiten Datei aus. */ wrong++; printf("Ungleiche Zeile:\n"); printName(output,fname1); printf(buffer1); if(!strchr(buffer1,'\n')) { getF1 = printLine(fp1,buffer1,size); } else { getF1 = fgets(buffer1,size,fp1) ; } /* Gebe die Zeile aus der zweiten Datei aus. */ printName(output,fname2); printf(buffer2); /* Überprüfe, ob die letzte Zeile ausgegeben werden muss. */ if(!strchr(buffer2,'\n')) { getF2 = printLine(fp2,buffer2,size); } else { getF2 = fgets(buffer2,size,fp2) ; } } else { getF1 = fgets(buffer1,size,fp1) ; getF2 = fgets(buffer2,size,fp2) ; } } /* Falls eine Datei früher komplett gelesen wurde. Wir geben den Dateinamen und den Rest aus dem Buffer aus. */ if(!(getF1 == NULL)) { getLastFile = getF1; lastfp = fp1; printName(output,fname1); printf(buffer1); } else if(!(getF2 == NULL)) { getLastFile = getF2; lastfp = fp2; printName(output,fname2); printf(buffer2); } /* Wir lesen die restliche Datei aus. */ if(getLastFile != NULL) { getLastFile= fgets(buffer1,size,lastfp) ; while(getLastFile !=NULL) { wrong++; printf(buffer1); getLastFile = printLine(lastfp,buffer1,size); } } /* Sind die Datein verschieden? */ if(wrong > 0) { printf("\nDateien sind ungleich. Anzahl ungleicher Zeilen: %d\n",wrong); } else { printf("\nDateien sind gleich.\n"); } fclose(fp1); fclose(fp2); return (0); }
void Buttongrid::drawGrid(){ int xPos,yPos,width,height; int btnWidth,btnHeight; xPos = x; yPos = y; width = w; height = h; btnWidth = w / columns; btnHeight = h / rows; //--nums background rectangle Tft.fillRectangle(xPos,yPos,width,height,bgColor); //-- outer border for(byte i=borderWidth; i!=0;i--){ Tft.drawRectangle(xPos++,yPos++,width--,height--,borderColor); width--; height--; } //-- horizontal lines for(byte j=1;j<rows;j++) { // draw # horizontal lines depending on borderWidth for(byte i=0; i<borderWidth;i++){ Tft.drawHorizontalLine(x,y+btnHeight*j+i-vGap,width+borderWidth,borderColor); } //Only draw gaps in between edges if(vGap>0){ //Tft.fillRectangle(xPos,y-vGap+btnHeight*j+1,width,btnHeight-1,BLACK); for(byte i=0; i<borderWidth;i++){ Tft.drawHorizontalLine(x,y+btnHeight*j+i+borderWidth+vGap,width+borderWidth,borderColor); } } } //-- vertical lines for(byte j=1;j<columns;j++) { // draw # of vertical lines depending on borderWidth for(byte i=0; i<borderWidth;i++){ Tft.drawVerticalLine(x+btnWidth*j+i-hGap,y+borderWidth,height+borderWidth,borderColor); } //Only draw gaps in between edges if(hGap>0){ //Tft.fillRectangle(xPos,y-vGap+btnHeight*j+1,width,btnHeight-1,BLACK); for(byte i=0; i<borderWidth;i++){ Tft.drawVerticalLine(x+btnWidth*j+i+borderWidth+hGap,y+borderWidth,height+borderWidth,borderColor); } } } //-- draw contents byte colIndex=0; byte rowIndex=0; for(byte r=1; r<=rows; r++) { for(byte c=1; c<=columns; c++) { //byte num = getNumber(r,c); //c+(r-1)*columns; //Serial.print(" r: "); //Serial.print(r); //Serial.print(" c: "); //Serial.print(c); //Serial.print(" num: "); //Serial.print(num); //Serial.print(" label: "); //Serial.print(labels[r-1][c-1]); //Serial.print(","); //setLabel(getNumber(r,c),labels[r-1][c-1]); printName(getNumber(r,c)); } //Serial.println(); } //-- Gaps fill if(hGap > 0){ for(byte j=1;j<columns;j++){ Tft.fillRectangle(x+j*btnWidth+borderWidth-hGap,y,hGap*2,h,myCanvas->bgColor); } } if(vGap > 0){ for(byte j=1;j<rows;j++){ Tft.fillRectangle(x,y+j*btnHeight+borderWidth-vGap,w,vGap*2,myCanvas->bgColor); } } }
void CJsonFormatter::floatValue(const std::string & name, long double value) { printName(name); printValue(value); }
void nmethod::flush() { BlockProfilerTicks bpt(exclude_nmethod_flush); CSect cs(profilerSemaphore); // for profiler # if GENERATE_DEBUGGING_AIDS if (CheckAssertions) { // for debugging if (nmethodFlushCount && --nmethodFlushCount == 0) warning("nmethodFlushCount"); if (this == (nmethod*)catchThisOne) warning("caught nmethod"); } # endif // EventMarker em("flushing nmethod %#lx %s", this, ""); if (PrintMethodFlushing) { ResourceMark m; char *compilerName = VMString[compiler()]->copy_null_terminated(); lprintf("*flushing %s%s%s-nmethod 0x%lx %d\t(", isZombie() ? "zombie " : "", isAccess() ? "access " : "", compilerName, (void*)(long unsigned)this, (void*)useCount[id]); printName(0, key.selector); lprintf(")"); } // always check the following - tests are really cheap if (flags.flushed) fatal1("nmethod %#lx already flushed", this); if (zone::frame_chain_nesting == 0) fatal("frames must be chained when flushing"); if (frame_chain != NoFrameChain) { // Can't remove an nmethod from deps chains now, because later // programming changes may need to invalidate it. // That is, don't unlink() now. // See comment for makeZombie routine. The comment above is the // "original comment" referred to there. // -- dmu 1/12/03 if (this == recompilee) { // nmethod is being recompiled; cannot really flush yet // em.event.args[1] = "(being recompiled)"; if (PrintMethodFlushing) { lprintf(" (being recompiled)\n"); } } else { // nmethod is currently being executed; cannot flush yet // em.event.args[1] = "(currently active)"; if (PrintMethodFlushing) { lprintf(" (currently active)\n"); } } makeZombie(false); } else { unlink(); // nmethod is not being executed; completely throw away // em.event.args[1] = "(not currently active)"; if (PrintMethodFlushing) { lprintf("\n"); } flatProfiler->flush((char*)this, instsEnd()); zoneLink.remove(); rememberLink.remove(); for (addrDesc* p = locs(), *pend = locsEnd(); p < pend; p++) { if (p->isSendDesc()) { p->asSendDesc(this)->unlink(); } else if (p->isDIDesc()) { p->asDIDesc(this)->dependency()->flush(); } } flags.flushed = 1; // to detect flushing errors # if GENERATE_DEBUGGING_AIDS if (CheckAssertions) { set_oops((oop*)insts(), instsLen()/oopSize, 0); // for quicker detection } # endif Memory->code->free_nmethod(this); } MachineCache::flush_instruction_cache_for_debugging(); }
void CJsonFormatter::floatValue(const std::string & name, ssize_t value, int digits) { printName(name); printValue(value, digits); }
static int processCurrentDirectory( char *path ) { struct direct *d; int lastentry; ++currentDepth; do { int Nnames; struct direct **namelist; struct stat *stp; /* Get basenames from this directory, if we can */ Nnames = scandir( ".", &namelist, permit, (f_sw ? Falphasort : alphasort) ); if( Nnames <= 0 ) { #if 0 fprintf( stderr, "%s: cannot scan '%s'.\n", me, path ); #endif /* NOPE */ ++nonfatal; break; } stp = xmalloc( Nnames * sizeof( *stp ) ); do { int subdirs; int i; /* Stat the directory and count subdirectories */ for( subdirs = i = 0; i < Nnames; ++i ) { d = namelist[ i ]; if( lstat( d->d_name, stp + i ) < 0 ) { fprintf( stderr, "%s: cannot stat '%s'\n", me, d->d_name ); ++nonfatal; stp[i].st_mode = 0; } if( S_ISDIR( stp[i].st_mode ) ) { ++subdirs; } } /* Say current directory and opt trailer line */ if( d_sw ) { if( subdirs && !s_sw ) { printf( "%s|\n", prefix ); } } else if( Nnames && !s_sw ) { printf( "%s|\n", prefix ); } /* Process each name in the directory in order */ for( i = 0; i < Nnames; ++i ) { struct stat * const st = stp + i; mode_t const mode = st->st_mode; int const isDir = S_ISDIR( mode ); d = namelist[i]; /* Show only directories if -d switch */ lastentry = ( (i+1) == Nnames ) ? 1 : 0; if( isDir ) { if( d_sw ) { lastentry = ((--subdirs) <= 0) ? 1 : 0; } printName( d->d_name, st, lastentry, 0 ); if( currentDepth < depth ) { /* Push new directory state */ if( lastentry ) { strcpy( prefix + Nprefix, " " ); } else { strcpy( prefix + Nprefix, "| " ); } Nprefix += 4; processDirectory( d->d_name, lastentry ); Nprefix -= 4; } prefix[ Nprefix ] = '\0'; if( !lastentry && !s_sw ) { printf( "%s|\n", prefix ); } } else if( !d_sw ) { processFile( d->d_name, st, lastentry ); if( !lastentry && !s_sw ) { printf( "%s|\n", prefix ); } } } } while( 0 ); free( stp ); /* Don't need namelist any longer */ free( namelist ); } while( 0 ); --currentDepth; return( 0 ); }
void CJsonFormatter::boolValue(const std::string & name, bool value) { printName(name); printValue(value); }
void typePrint(ostream &out, TypePtr t) { switch (t->typeKind) { case BOOL_TYPE : out << "Bool"; break; case INTEGER_TYPE : { IntegerType *x = (IntegerType *)t.ptr(); if (!x->isSigned) out << "U"; out << "Int" << x->bits; break; } case FLOAT_TYPE : { FloatType *x = (FloatType *)t.ptr(); out << "Float" << x->bits; break; } case POINTER_TYPE : { PointerType *x = (PointerType *)t.ptr(); out << "Pointer[" << x->pointeeType << "]"; break; } case CODE_POINTER_TYPE : { CodePointerType *x = (CodePointerType *)t.ptr(); out << "CodePointer["; if (x->argTypes.size() == 1) { out << x->argTypes[0]; } else { out << "("; for (unsigned i = 0; i < x->argTypes.size(); ++i) { if (i != 0) out << ", "; out << x->argTypes[i]; } out << ")"; } out << ", "; if (x->returnTypes.size() == 1) { if (x->returnIsRef[0]) out << "ByRef[" << x->returnTypes[0] << "]"; else out << x->returnTypes[0]; } else { out << "("; for (unsigned i = 0; i < x->returnTypes.size(); ++i) { if (i != 0) out << ", "; if (x->returnIsRef[i]) out << "ByRef[" << x->returnTypes[i] << "]"; else out << x->returnTypes[i]; } out << ")"; } out << "]"; break; } case CCODE_POINTER_TYPE : { CCodePointerType *x = (CCodePointerType *)t.ptr(); switch (x->callingConv) { case CC_DEFAULT : if (x->hasVarArgs) out << "VarArgsCCodePointer"; else out << "CCodePointer"; break; case CC_STDCALL : out << "StdCallCodePointer"; break; case CC_FASTCALL : out << "FastCallCodePointer"; break; default : assert(false); } out << "["; if (x->argTypes.size() == 1) { out << x->argTypes[0]; } else { out << "("; for (unsigned i = 0; i < x->argTypes.size(); ++i) { if (i != 0) out << ", "; out << x->argTypes[i]; } out << ")"; } out << ", "; if (x->returnType.ptr()) out << x->returnType; else out << "()"; out << "]"; break; } case ARRAY_TYPE : { ArrayType *x = (ArrayType *)t.ptr(); out << "Array[" << x->elementType << ", " << x->size << "]"; break; } case VEC_TYPE : { VecType *x = (VecType *)t.ptr(); out << "Vec[" << x->elementType << ", " << x->size << "]"; break; } case TUPLE_TYPE : { TupleType *x = (TupleType *)t.ptr(); out << "Tuple" << x->elementTypes; break; } case UNION_TYPE : { UnionType *x = (UnionType *)t.ptr(); out << "Union" << x->memberTypes; break; } case RECORD_TYPE : { RecordType *x = (RecordType *)t.ptr(); out << x->record->name->str; if (!x->params.empty()) { out << "["; printNameList(out, x->params); out << "]"; } break; } case VARIANT_TYPE : { VariantType *x = (VariantType *)t.ptr(); out << x->variant->name->str; if (!x->params.empty()) { out << "["; printNameList(out, x->params); out << "]"; } break; } case STATIC_TYPE : { StaticType *x = (StaticType *)t.ptr(); out << "Static["; printName(out, x->obj); out << "]"; break; } case ENUM_TYPE : { EnumType *x = (EnumType *)t.ptr(); out << x->enumeration->name->str; break; } default : assert(false); } }
void CJsonFormatter::rawValue(const std::string & name, const std::string & json) { printName(name); buf << json; }
static void doFile (const char * moduleName) { assert(moduleName); printBeginGuard(moduleName, cout); printCopyright(cout); cout << endl; cout << "#include \"AAFTypes.h\"" << endl; cout << endl; cout << "// AAF stored object UIDs." << endl << "//" << endl << endl; cout << "#if !defined(INIT_AUID)" << endl; cout << "#define "; cout << "DEFINE_AUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\" << endl; cout << " extern \"C\" const aafUID_t name" << endl; cout << "#else" << endl; cout << "#define "; cout << "DEFINE_AUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\" << endl; cout << " extern \"C\" const aafUID_t name = \\" << endl; cout << " { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }" << endl; cout << "#endif" << endl; cout << endl; cout << "// The AAF reference implementation uses shorter names than" << endl << "// SMPTE. The names are shortened by the following aliases." << endl << "//" << endl; size_t maxNameLength = 0; size_t i = 0; for (i = 0; i < sizeof(aliases)/sizeof(aliases[0]); i++){ size_t length = strlen(aliases[i].alias); if (length > maxNameLength) { maxNameLength = length; } } size_t width = maxNameLength; for (i = 0; i < sizeof(aliases)/sizeof(aliases[0]); i++){ cout << "#define " << prefix; printName(aliases[i].alias, width, cout); cout << " " << prefix; printName(aliases[i].name, 0, cout); cout << endl; } cout << endl; for (i = 0; i < sizeof(classes)/sizeof(classes[0]); i++){ printMacroInvocation(prefix, "DEFINE_AUID", classes[i].name, classes[i].identifier, cout); cout << endl; } printEndGuard(moduleName, cout); }
void CJsonFormatter::beginArray(const std::string & name) { printName(name); buf << '['; states.push_back(LIST_FIRST); }
void typePrint(llvm::raw_ostream &out, TypePtr t) { switch (t->typeKind) { case BOOL_TYPE : out << "Bool"; break; case INTEGER_TYPE : { IntegerType *x = (IntegerType *)t.ptr(); if (!x->isSigned) out << "U"; out << "Int" << x->bits; break; } case FLOAT_TYPE : { FloatType *x = (FloatType *)t.ptr(); if(x->isImaginary) { out << "Imag" << x->bits; } else { out << "Float" << x->bits; } break; } case COMPLEX_TYPE : { ComplexType *x = (ComplexType *)t.ptr(); out << "Complex" << x->bits; break; } case POINTER_TYPE : { PointerType *x = (PointerType *)t.ptr(); out << "Pointer[" << x->pointeeType << "]"; break; } case CODE_POINTER_TYPE : { CodePointerType *x = (CodePointerType *)t.ptr(); out << "CodePointer[["; for (size_t i = 0; i < x->argTypes.size(); ++i) { if (i != 0) out << ", "; out << x->argTypes[i]; } out << "], ["; for (size_t i = 0; i < x->returnTypes.size(); ++i) { if (i != 0) out << ", "; if (x->returnIsRef[i]) out << "ByRef[" << x->returnTypes[i] << "]"; else out << x->returnTypes[i]; } out << "]]"; break; } case CCODE_POINTER_TYPE : { CCodePointerType *x = (CCodePointerType *)t.ptr(); out << "ExternalCodePointer["; #define CALLING_CONV_PRINT(e, str) case e: out << str << ", "; break; switch (x->callingConv) { CALLING_CONV_MAP(CALLING_CONV_PRINT) default: assert(false); } #undef CALLING_CONV_PRINT if (x->hasVarArgs) out << "true, "; else out << "false, "; out << "["; for (size_t i = 0; i < x->argTypes.size(); ++i) { if (i != 0) out << ", "; out << x->argTypes[i]; } out << "], ["; if (x->returnType.ptr()) out << x->returnType; out << "]]"; break; } case ARRAY_TYPE : { ArrayType *x = (ArrayType *)t.ptr(); out << "Array[" << x->elementType << ", " << x->size << "]"; break; } case VEC_TYPE : { VecType *x = (VecType *)t.ptr(); out << "Vec[" << x->elementType << ", " << x->size << "]"; break; } case TUPLE_TYPE : { TupleType *x = (TupleType *)t.ptr(); out << "Tuple" << x->elementTypes; break; } case UNION_TYPE : { UnionType *x = (UnionType *)t.ptr(); out << "Union" << x->memberTypes; break; } case RECORD_TYPE : { RecordType *x = (RecordType *)t.ptr(); out << x->record->name->str; if (!x->params.empty()) { out << "["; printNameList(out, x->params); out << "]"; } break; } case VARIANT_TYPE : { VariantType *x = (VariantType *)t.ptr(); out << x->variant->name->str; if (!x->params.empty()) { out << "["; printNameList(out, x->params); out << "]"; } break; } case STATIC_TYPE : { StaticType *x = (StaticType *)t.ptr(); out << "Static["; printName(out, x->obj); out << "]"; break; } case ENUM_TYPE : { EnumType *x = (EnumType *)t.ptr(); out << x->enumeration->name->str; break; } case NEW_TYPE : { NewType *x = (NewType *)t.ptr(); out << x->newtype->name->str; break; } default : assert(false); } }
//Return bool to end game bool takeTurn(int playerNo, int*playerPoints) { int x; int y; int turn; int a; bool stop; if (playerNo == 1) { printName(1); x = roll(); y = roll(); if (x > 1 && y > 1) { turn = x+y; *playerPoints += turn; printroll(x,y,turn); } else if (x == 1 && y == 1) { turn = 0; *playerPoints = 0; printroll(x,y,turn); } else { turn = 0; printroll(x,y,turn); } } if (playerNo == 2) { printName(2); for(a=0; a<2; a++) x = roll(); y = roll(); if (x > 1 && y > 1) { turn = x+y; *playerPoints += turn; printroll(x,y,turn); } else if (x == 1 && y == 1) { turn = 0; *playerPoints = 0; printroll(x,y,turn); } else { turn = 0; printroll(x,y,turn); } } if (playerNo == 3) { printName(3); do { x = roll(); y = roll(); if (x > 1 && y > 1) { turn = x+y; *playerPoints += turn; printroll(x,y,turn); stop = false; } else if (x == 1 && y == 1) { turn = 0; *playerPoints = 0; printroll(x,y,turn); stop = true; } else { turn = 0; printroll(x,y,turn); stop = true; } } while(*playerPoints < 50 && !stop); } printturn(turn,*playerPoints); if (*playerPoints < 50) return false; else { announceWinner(playerNo, *playerPoints); return true; } }