LPTSTR PlayerFileDialogServiceWin::parseExtensions(const std::string &extensions) const { static WCHAR *defaultExtensions = L"All Files (*.*)\0*.*\0"; if (extensions.length() == 0) { WCHAR *buff = new WCHAR[wcslen(defaultExtensions) + 1]; wcscpy(buff, defaultExtensions); return buff; } // 1. // "Lua Script File|*.lua;JSON File|*.json" // to // "Lua Script File (*.lua)\0*.lua\0JSON File (*.json)\0*.json\0"; // // 2. // "Lua Script File|*.lua;Cocos Studio File|*.csd,*.csb" // to // "Lua Script File (*.lua)\0*.lua\0Cocos Studio File (*.csd;*.csb")\0*.csd;*.csb"\0"; std::u16string u16extensions; std::u16string split1((char16_t*)L";"); std::u16string split2((char16_t*)L"|"); std::u16string split3((char16_t*)L","); std::string extensionsArg(extensions); cocos2d::StringUtils::UTF8ToUTF16(extensions, u16extensions); vector<std::u16string> pairs = splitString(u16extensions, split1); size_t buffsize = extensions.length() * 6; WCHAR *buff = new WCHAR[buffsize]; memset(buff, 0, sizeof(WCHAR) * buffsize); size_t offset = 0; for (auto it = pairs.begin(); it != pairs.end(); ++it) { vector<std::u16string> p = splitString(*it, split2); std::u16string descr, ext; if (p.size() < 2) { descr = ext = *it; } else { descr = p.at(0); ext = p.at(1); } // *.csd,*.csb -> *.csd;*.csb std::replace(ext.begin(), ext.end(), ',', ';'); wcscat(buff + offset, (WCHAR*)descr.c_str()); wcscat(buff + offset, L" ("); wcscat(buff + offset, (WCHAR*)ext.c_str()); wcscat(buff + offset, L")"); offset += descr.length() + ext.length() + 4; wcscat(buff + offset, (WCHAR*)ext.c_str()); offset += ext.length() + 1; } return buff; }
//Reads from the file line by line and calls split1() for each line void getLeader() { FILE * fp; char * line = NULL; size_t len = 0; size_t read; int i, j, k, z, flag; fp = fopen("input.txt", "r"); while (read=getline(&line,&len,fp)!=-1) split1(line); fclose(fp); }
TEST(TestTransaction, shouldAddSplitIntoAccount) { //given AccountPtr account(new Account()); SplitPtr split1(new Split()); SplitPtr split2(new Split()); //when account->addSplit(split1); account->addSplit(split2); //then const Splits& splits = account->getSplits(); ASSERT_EQ(2, splits.size()); ASSERT_EQ(split1, splits[0]); ASSERT_EQ(split2, splits[1]); }
void Shape::drawAvailable(vector<Line> available, vector<Point> demand, ShadowBuffer& sb, Color c) { for (int j=0; j<demand.size()-1; j+=2) { vector<Line> newAvailable; for (int i= 0; i < available.size(); i++ ) { if (available[i].getPoint2().x<=available[i].getPoint1().x) { //sudah tidak ada slot } else if ((available[i].getPoint1().x <= demand[j].x) && (demand[j+1].x <= available[i].getPoint2().x)) { //demand berada di tengah Line split1(available[i].getPoint1(), Point(demand[j].x-1, available[i].getPoint1().y,0)); Line split2(Point(demand[j+1].x+1,available[i].getPoint2().y,0), available[i].getPoint2()); newAvailable.push_back(split1); newAvailable.push_back(split2); Line line(demand[j], demand[j+1]); line.color = c; line.draw(sb, line.getPoint1(), line.getPoint1().getDistance(line.getPoint2()), line.color, Color(line.color.r - 50, line.color.g - 50, line.color.b - 50)); } else if (available[i].getPoint1().x <= demand[j].x) { //demand lebih banyak kebelakang Line split(available[i].getPoint1(), Point(demand[j].x-1, available[i].getPoint1().y,0)); newAvailable.push_back(split); Line line(demand[j], Point(available[i].getPoint2().x,demand[j].y,0)); line.color = c; line.draw(sb, line.getPoint1(), line.getPoint1().getDistance(line.getPoint2()), line.color, Color(line.color.r - 50, line.color.g - 50, line.color.b - 50)); } else if (demand[j+1].x <= available[i].getPoint2().x) { //demand lebih banyak di depan Line split(Point(demand[j+1].x+1,available[i].getPoint2().y,0), available[i].getPoint2()); Line line(Point(available[i].getPoint1().x,demand[j+1].y,0),demand[j+1]); line.color = c; line.draw(sb, line.getPoint1(), line.getPoint1().getDistance(line.getPoint2()), line.color, Color(line.color.r - 50, line.color.g - 50, line.color.b - 50)); newAvailable.push_back(split); } else { newAvailable.push_back(available[i]); } } //available.clear(); available = newAvailable; //update info available //Available.push_back(newAvailable); } }
/* * split3 -- * Split the input into specified number of chunks */ static void split3(void) { struct stat sb; if (fstat(ifd, &sb) == -1) { err(1, "stat"); /* NOTREACHED */ } if (chunks > sb.st_size) { errx(1, "can't split into more than %d files", (int)sb.st_size); /* NOTREACHED */ } bytecnt = sb.st_size / chunks; split1(); }
int main(int argc, char **argv) { intmax_t bytecnti; long scale; int ch; char *ep, *p; setlocale(LC_ALL, ""); while ((ch = getopt(argc, argv, "0123456789a:b:l:n:p:")) != -1) switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* * Undocumented kludge: split was originally designed * to take a number after a dash. */ if (numlines == 0) { p = argv[optind - 1]; if (p[0] == '-' && p[1] == ch && !p[2]) numlines = strtol(++p, &ep, 10); else numlines = strtol(argv[optind] + 1, &ep, 10); if (numlines <= 0 || *ep) errx(EX_USAGE, "%s: illegal line count", optarg); } break; case 'a': /* Suffix length */ if ((sufflen = strtol(optarg, &ep, 10)) <= 0 || *ep) errx(EX_USAGE, "%s: illegal suffix length", optarg); break; case 'b': /* Byte count. */ errno = 0; if ((bytecnti = strtoimax(optarg, &ep, 10)) <= 0 || strchr("kKmMgG", *ep) == NULL || errno != 0) errx(EX_USAGE, "%s: illegal byte count", optarg); if (*ep == 'k' || *ep == 'K') scale = 1024; else if (*ep == 'm' || *ep == 'M') scale = 1024 * 1024; else if (*ep == 'g' || *ep == 'G') scale = 1024 * 1024 * 1024; else scale = 1; if (bytecnti > OFF_MAX / scale) errx(EX_USAGE, "%s: offset too large", optarg); bytecnt = (off_t)(bytecnti * scale); break; case 'l': /* Line count. */ if (numlines != 0) usage(); if ((numlines = strtol(optarg, &ep, 10)) <= 0 || *ep) errx(EX_USAGE, "%s: illegal line count", optarg); break; case 'n': /* Chunks. */ if (!isdigit((unsigned char)optarg[0]) || (chunks = (size_t)strtoul(optarg, &ep, 10)) == 0 || *ep != '\0') { errx(EX_USAGE, "%s: illegal number of chunks", optarg); } break; case 'p': /* pattern matching. */ if (regcomp(&rgx, optarg, REG_EXTENDED|REG_NOSUB) != 0) errx(EX_USAGE, "%s: illegal regexp", optarg); pflag = 1; break; default: usage(); } argv += optind; argc -= optind; if (*argv != NULL) { /* Input file. */ if (strcmp(*argv, "-") == 0) ifd = STDIN_FILENO; else if ((ifd = open(*argv, O_RDONLY, 0)) < 0) err(EX_NOINPUT, "%s", *argv); ++argv; } if (*argv != NULL) /* File name prefix. */ if (strlcpy(fname, *argv++, sizeof(fname)) >= sizeof(fname)) errx(EX_USAGE, "file name prefix is too long"); if (*argv != NULL) usage(); if (strlen(fname) + (unsigned long)sufflen >= sizeof(fname)) errx(EX_USAGE, "suffix is too long"); if (pflag && (numlines != 0 || bytecnt != 0 || chunks != 0)) usage(); if (numlines == 0) numlines = DEFLINE; else if (bytecnt != 0 || chunks != 0) usage(); if (bytecnt && chunks) usage(); if (ifd == -1) /* Stdin by default. */ ifd = 0; if (bytecnt) { split1(); exit (0); } else if (chunks) { split3(); exit (0); } split2(); if (pflag) regfree(&rgx); exit(0); }
/* analyze triangles and split if needed */ static int anaelt(pMesh mesh,pSol met,char typchk) { pTria pt; pPoint ppt,p1,p2; Hash hash; Bezier pb; pGeom go; double s,o[3],no[3],to[3],dd,len; int vx[3],i,j,ip,ip1,ip2,ier,k,ns,nc,nt; char i1,i2; static double uv[3][2] = { {0.5,0.5}, {0.,0.5}, {0.5,0.} }; hashNew(&hash,mesh->np); ns = 0; s = 0.5; for (k=1; k<=mesh->nt; k++) { pt = &mesh->tria[k]; if ( !MS_EOK(pt) || pt->ref < 0 ) continue; if ( MS_SIN(pt->tag[0]) || MS_SIN(pt->tag[1]) || MS_SIN(pt->tag[2]) ) continue; /* check element cut */ pt->flag = 0; if ( typchk == 1 ) { if ( !chkedg(mesh,k) ) continue; } else if ( typchk == 2 ) { for (i=0; i<3; i++) { i1 = inxt[i]; i2 = iprv[i]; len = lenedg(mesh,met,pt->v[i1],pt->v[i2],0); if ( len > LLONG ) MS_SET(pt->flag,i); } if ( !pt->flag ) continue; } ns++; /* geometric support */ ier = bezierCP(mesh,k,&pb); assert(ier); /* scan edges to split */ for (i=0; i<3; i++) { if ( !MS_GET(pt->flag,i) ) continue; i1 = inxt[i]; i2 = iprv[i]; ip1 = pt->v[i1]; ip2 = pt->v[i2]; ip = hashGet(&hash,ip1,ip2); if ( !MS_EDG(pt->tag[i]) && ip > 0 ) continue; /* new point along edge */ ier = bezierInt(&pb,uv[i],o,no,to); if ( !ip ) { ip = newPt(mesh,o,MS_EDG(pt->tag[i]) ? to : no); assert(ip); hashEdge(&hash,ip1,ip2,ip); p1 = &mesh->point[ip1]; p2 = &mesh->point[ip2]; ppt = &mesh->point[ip]; if ( MS_EDG(pt->tag[i]) ) { ++mesh->ng; assert(mesh->ng < mesh->ngmax); ppt->tag = pt->tag[i]; if ( p1->ref == pt->edg[i] || p2->ref == pt->edg[i] ) ppt->ref = pt->edg[i]; ppt->ig = mesh->ng; go = &mesh->geom[mesh->ng]; memcpy(go->n1,no,3*sizeof(double)); dd = go->n1[0]*ppt->n[0] + go->n1[1]*ppt->n[1] + go->n1[2]*ppt->n[2]; ppt->n[0] -= dd*go->n1[0]; ppt->n[1] -= dd*go->n1[1]; ppt->n[2] -= dd*go->n1[2]; dd = ppt->n[0]*ppt->n[0] + ppt->n[1]*ppt->n[1] + ppt->n[2]*ppt->n[2]; if ( dd > EPSD2 ) { dd = 1.0 / sqrt(dd); ppt->n[0] *= dd; ppt->n[1] *= dd; ppt->n[2] *= dd; } } if ( met->m ) { if ( typchk == 1 ) intmet33(mesh,met,ip1,ip2,ip,s); else intmet(mesh,met,k,i,ip,s); } } else if ( pt->tag[i] & MS_GEO ) { ppt = &mesh->point[ip]; go = &mesh->geom[ppt->ig]; memcpy(go->n2,no,3*sizeof(double)); /* a computation of the tangent with respect to these two normals is possible */ ppt->n[0] = go->n1[1]*go->n2[2] - go->n1[2]*go->n2[1]; ppt->n[1] = go->n1[2]*go->n2[0] - go->n1[0]*go->n2[2]; ppt->n[2] = go->n1[0]*go->n2[1] - go->n1[1]*go->n2[0]; dd = ppt->n[0]*ppt->n[0] + ppt->n[1]*ppt->n[1] + ppt->n[2]*ppt->n[2]; if ( dd > EPSD2 ) { dd = 1.0 / sqrt(dd); ppt->n[0] *= dd; ppt->n[1] *= dd; ppt->n[2] *= dd; } } } } if ( !ns ) { free(hash.item); return(ns); } /* step 2. checking if split by adjacent */ for (k=1; k<=mesh->nt; k++) { pt = &mesh->tria[k]; if ( !MS_EOK(pt) || pt->ref < 0 ) continue; else if ( pt->flag == 7 ) continue; /* geometric support */ ier = bezierCP(mesh,k,&pb); assert(ier); nc = 0; for (i=0; i<3; i++) { i1 = inxt[i]; i2 = inxt[i1]; if ( !MS_GET(pt->flag,i) && !MS_SIN(pt->tag[i]) ) { ip = hashGet(&hash,pt->v[i1],pt->v[i2]); if ( ip > 0 ) { MS_SET(pt->flag,i); nc++; if ( pt->tag[i] & MS_GEO ) { /* new point along edge */ ier = bezierInt(&pb,uv[i],o,no,to); assert(ier); ppt = &mesh->point[ip]; go = &mesh->geom[ppt->ig]; memcpy(go->n2,no,3*sizeof(double)); /* a computation of the tangent with respect to these two normals is possible */ ppt->n[0] = go->n1[1]*go->n2[2] - go->n1[2]*go->n2[1]; ppt->n[1] = go->n1[2]*go->n2[0] - go->n1[0]*go->n2[2]; ppt->n[2] = go->n1[0]*go->n2[1] - go->n1[1]*go->n2[0]; dd = ppt->n[0]*ppt->n[0] + ppt->n[1]*ppt->n[1] + ppt->n[2]*ppt->n[2]; if ( dd > EPSD2 ) { dd = 1.0 / sqrt(dd); ppt->n[0] *= dd; ppt->n[1] *= dd; ppt->n[2] *= dd; } } } } } if ( nc > 0 ) ++ns; } if ( info.ddebug && ns ) { fprintf(stdout," %d analyzed %d proposed\n",mesh->nt,ns); fflush(stdout); } /* step 3. splitting */ ns = 0; nt = mesh->nt; for (k=1; k<=nt; k++) { pt = &mesh->tria[k]; if ( !MS_EOK(pt) || pt->ref < 0 ) continue; else if ( pt->flag == 0 ) continue; j = -1; vx[0] = vx[1] = vx[2] = 0; for (i=0; i<3; i++) { i1 = inxt[i]; i2 = inxt[i1]; if ( MS_GET(pt->flag,i) ) { vx[i] = hashGet(&hash,pt->v[i1],pt->v[i2]); assert(vx[i]); j = i; } } if ( pt->flag == 1 || pt->flag == 2 || pt->flag == 4 ) { ier = split1(mesh,met,k,j,vx); assert(ier); ns++; } else if ( pt->flag == 7 ) { ier = split3(mesh,met,k,vx); assert(ier); ns++; } else { ier = split2(mesh,met,k,vx); assert(ier); ns++; } } if ( (info.ddebug || abs(info.imprim) > 5) && ns > 0 ) fprintf(stdout," %7d splitted\n",ns); free(hash.item); return(ns); }
int main(int argc, char *argv[]) { int ch, scale; char *ep, *p; const char *errstr; while ((ch = getopt(argc, argv, "0123456789a:b:l:p:-")) != -1) switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* * Undocumented kludge: split was originally designed * to take a number after a dash. */ if (numlines == 0) { p = argv[optind - 1]; if (p[0] == '-' && p[1] == ch && !p[2]) numlines = strtol(++p, &ep, 10); else numlines = strtol(argv[optind] + 1, &ep, 10); if (numlines <= 0 || *ep) errx(EX_USAGE, "%s: illegal line count", optarg); } break; case '-': /* Undocumented: historic stdin flag. */ if (ifd != -1) usage(); ifd = 0; break; case 'a': /* suffix length. */ sufflen = strtonum(optarg, 1, NAME_MAX, &errstr); if (errstr) errx(EX_USAGE, "%s: %s", optarg, errstr); break; case 'b': /* Byte count. */ if ((bytecnt = strtol(optarg, &ep, 10)) <= 0 || (*ep != '\0' && *ep != 'k' && *ep != 'm')) errx(EX_USAGE, "%s: illegal byte count", optarg); if (*ep == 'k') scale = 1024; else if (*ep == 'm') scale = 1048576; else scale = 1; if (bytecnt > SSIZE_MAX / scale) errx(EX_USAGE, "%s: byte count too large", optarg); bytecnt *= scale; break; case 'p' : /* pattern matching. */ if (regcomp(&rgx, optarg, REG_EXTENDED|REG_NOSUB) != 0) errx(EX_USAGE, "%s: illegal regexp", optarg); pflag = 1; break; case 'l': /* Line count. */ if (numlines != 0) usage(); if ((numlines = strtol(optarg, &ep, 10)) <= 0 || *ep) errx(EX_USAGE, "%s: illegal line count", optarg); break; default: usage(); } argv += optind; argc -= optind; if (*argv != NULL) if (ifd == -1) { /* Input file. */ if ((ifd = open(*argv, O_RDONLY, 0)) < 0) err(EX_NOINPUT, "%s", *argv); ++argv; } if (*argv != NULL) /* File name prefix. */ (void)strlcpy(fname, *argv++, sizeof(fname)); if (*argv != NULL) usage(); if (strlen(fname) + sufflen >= sizeof(fname)) errx(EX_USAGE, "suffix is too long"); if (pflag && (numlines != 0 || bytecnt != 0)) usage(); if (numlines == 0) numlines = DEFLINE; else if (bytecnt != 0) usage(); if (ifd == -1) /* Stdin by default. */ ifd = 0; if (bytecnt) { split1(); exit (0); } split2(); if (pflag) regfree(&rgx); exit(0); }