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); }
int open_asf_data(const char *filename, const char *band, int multilook, meta_parameters *meta, ClientInterface *client) { ReadAsfClientInfo *info = MALLOC(sizeof(ReadAsfClientInfo)); info->is_rgb = FALSE; info->band_gs = info->band_r = info->band_g = info->band_b = 0; info->ml = multilook; // special hack for Avnir data! if (!band && strcmp_case(meta->general->sensor_name, "AVNIR") == 0 && meta->general->band_count >= 3) { // no band was specifed -- show true color (3,2,1) asfPrintStatus("Avnir data: defaulting to TRUE color -- " "Red=3, Green=2, Blue=1\n"); band = "03,02,01"; } if (band) { char *r, *b, *g; if (split3(band, &r, &g, &b, ',')) { // Looks like we were given 3 bands -- so, we are doing rgb info->band_r = get_band_number(meta->general->bands, meta->general->band_count, r); if (info->band_r < 0) asfPrintWarning("Red band '%s' not found.\n", r); else asfPrintStatus("Red band is band #%d: %s\n", info->band_r+1, r); info->band_g = get_band_number(meta->general->bands, meta->general->band_count, g); if (info->band_g < 0) asfPrintWarning("Green band '%s' not found.\n", g); else asfPrintStatus("Green band is band #%d: %s\n", info->band_g+1, g); info->band_b = get_band_number(meta->general->bands, meta->general->band_count, b); if (info->band_b < 0) asfPrintWarning("Blue band '%s' not found.\n", b); else asfPrintStatus("Blue band is band #%d: %s\n", info->band_b+1, b); if (info->band_r < 0 && info->band_g < 0 && info->band_b < 0) { // none of the bands were found return FALSE; } info->is_rgb = TRUE; FREE(r); FREE(g); FREE(b); set_bands_rgb(info->band_r, info->band_g, info->band_b); } else { // Single band name given info->band_gs = get_band_number(meta->general->bands, meta->general->band_count, (char*)band); if (info->band_gs < 0) { asfPrintWarning("Band '%s' not found.\n", band); return FALSE; } else { asfPrintStatus("Reading band #%d: %s\n", info->band_gs+1, band); } set_bands_greyscale(info->band_gs); } } info->fp = fopen(filename, "rb"); if (!info->fp) { asfPrintWarning("Failed to open ASF Internal file %s: %s\n", filename, strerror(errno)); return FALSE; } client->read_client_info = info; client->read_fn = read_asf_client; client->thumb_fn = get_asf_thumbnail_data; client->free_fn = free_asf_client_info; if (meta->general->data_type == ASF_BYTE) client->data_type = info->is_rgb ? RGB_BYTE : GREYSCALE_BYTE; else client->data_type = info->is_rgb ? RGB_FLOAT : GREYSCALE_FLOAT; return TRUE; }
int open_asf_data(const char *filename, const char *band, int multilook, meta_parameters *meta, ClientInterface *client) { ReadAsfClientInfo *info = MALLOC(sizeof(ReadAsfClientInfo)); info->is_rgb = FALSE; info->band_gs = info->band_r = info->band_g = info->band_b = 0; info->ml = multilook; // special hack for Avnir data! if (!band && strcmp_case(meta->general->sensor_name, "AVNIR") == 0 && meta->general->band_count >= 3) { // no band was specifed -- show true color (3,2,1) asfPrintStatus("Avnir data: defaulting to TRUE color -- " "Red=3, Green=2, Blue=1\n"); band = "03,02,01"; } if (band) { char *r, *b, *g; if (split3(band, &r, &g, &b, ',')) { // Looks like we were given 3 bands -- so, we are doing rgb info->band_r = get_band_number(meta->general->bands, meta->general->band_count, r); if (info->band_r < 0) asfPrintWarning("Red band '%s' not found.\n", r); else asfPrintStatus("Red band is band #%d: %s\n", info->band_r+1, r); info->band_g = get_band_number(meta->general->bands, meta->general->band_count, g); if (info->band_g < 0) asfPrintWarning("Green band '%s' not found.\n", g); else asfPrintStatus("Green band is band #%d: %s\n", info->band_g+1, g); info->band_b = get_band_number(meta->general->bands, meta->general->band_count, b); if (info->band_b < 0) asfPrintWarning("Blue band '%s' not found.\n", b); else asfPrintStatus("Blue band is band #%d: %s\n", info->band_b+1, b); if (info->band_r < 0 && info->band_g < 0 && info->band_b < 0) { // none of the bands were found return FALSE; } info->is_rgb = TRUE; FREE(r); FREE(g); FREE(b); set_bands_rgb(info->band_r, info->band_g, info->band_b); } else { // Single band name given info->band_gs = get_band_number(meta->general->bands, meta->general->band_count, (char*)band); if (info->band_gs < 0) { asfPrintWarning("Band '%s' not found.\n", band); return FALSE; } else { asfPrintStatus("Reading band #%d: %s\n", info->band_gs+1, band); } set_bands_greyscale(info->band_gs); } } info->fp = fopen(filename, "rb"); if (!info->fp) { asfPrintWarning("Failed to open ASF Internal file %s: %s\n", filename, strerror(errno)); return FALSE; } client->read_client_info = info; client->read_fn = read_asf_client; client->thumb_fn = get_asf_thumbnail_data; client->free_fn = free_asf_client_info; if (meta->general->data_type == ASF_BYTE) client->data_type = info->is_rgb ? RGB_BYTE : GREYSCALE_BYTE; else client->data_type = info->is_rgb ? RGB_FLOAT : GREYSCALE_FLOAT; // special sanity checks for ASF data if (meta->general->line_count == 0 || meta->general->sample_count == 0) { asfPrintStatus("Line count: %d\n", meta->general->line_count); asfPrintStatus("Sample count: %d\n", meta->general->sample_count); asfPrintWarning("Line count or sample count is 0.\n"); return FALSE; } long long sz = fileSize(filename); int mult = (info->is_rgb ? 3 : 1) * (meta->general->data_type == ASF_BYTE ? 1 : 4); long long expected_sz = meta->general->line_count * meta->general->sample_count * mult; if (sz < expected_sz) { asfPrintWarning("File is too short! Truncating lines...\n"); int orig = meta->general->line_count; asfPrintStatus("Original line count: %d\n", orig); meta->general->line_count = sz / mult / meta->general->sample_count; asfPrintStatus("Truncated line count (calculated from file size): %d\n", meta->general->line_count); asfPrintWarning("Truncated %d lines!\n", orig - meta->general->line_count); } return TRUE; }
/* 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); }
void BuildingType::loadRules(INIFile* rules) { INISection* rulesSection = rules->getSection(ID); if (!rulesSection) return; TechnoType::loadRules(rules); rulesSection->readStringValue("ToTile", ToTile, ToTile); rulesSection->readBoolValue("HasSpotlight", HasSpotlight, HasSpotlight); rulesSection->readStringValue("HalfDamageSmokeLocation1", HalfDamageSmokeLocation1_str, HalfDamageSmokeLocation1_str); LineSplitter split(HalfDamageSmokeLocation1_str); HalfDamageSmokeLocation1.x = split.pop_int(); HalfDamageSmokeLocation1.y = split.pop_int(); HalfDamageSmokeLocation1.z = split.pop_int(); rulesSection->readStringValue("HalfDamageSmokeLocation2", HalfDamageSmokeLocation2_str, HalfDamageSmokeLocation2_str); LineSplitter split2(HalfDamageSmokeLocation2_str); HalfDamageSmokeLocation2.x = split2.pop_int(); HalfDamageSmokeLocation2.y = split2.pop_int(); HalfDamageSmokeLocation2.z = split2.pop_int(); rulesSection->readBoolValue("WaterBound", WaterBound, WaterBound); rulesSection->readBoolValue("Powered", Powered, Powered); rulesSection->readIntValue("RefinerySmokeFrames", RefinerySmokeFrames, RefinerySmokeFrames); rulesSection->readBoolValue("Wall", Wall, Wall); VehicleType::Array.findOrAllocate(FreeUnit); rulesSection->readBoolValue("IsPlug", IsPlug); InfantryType::Array.findOrAllocate(SecretInfantry); VehicleType::Array.findOrAllocate(SecretUnit); BuildingType::Array.findOrAllocate(SecretBuilding); rulesSection->readBoolValue("Gate", Gate); rulesSection->readBoolValue("LaserFencePost", LaserFencePost); rulesSection->readBoolValue("LaserFence", LaserFence); rulesSection->readBoolValue("FirestormWall", FirestormWall); rulesSection->readStringValue("PowersUpBuilding", PowersUpBuilding); rulesSection->readIntValue("PowersUpToLevel", PowersUpToLevel); rulesSection->readIntValue("Power", Power); rulesSection->readIntValue("ExtraPower", ExtraPower); rulesSection->readStringValue("TurretAnim", TurretAnim); rulesSection->readStringValue("TurretAnimDamaged", TurretAnimDamaged); rulesSection->readStringValue("TurretAnimGarrisoned", TurretAnimGarrisoned); rulesSection->readIntValue("TurretAnimX", TurretAnimX); rulesSection->readIntValue("TurretAnimY", TurretAnimY); rulesSection->readIntValue("TurretAnimZAdjust", TurretAnimZAdjust); rulesSection->readIntValue("TurretAnimYSort", TurretAnimYSort); rulesSection->readBoolValue("TurretAnimPowered", TurretAnimPowered); rulesSection->readBoolValue("TurretAnimPoweredLight", TurretAnimPoweredLight); rulesSection->readBoolValue("TurretAnimPoweredEffect", TurretAnimPoweredEffect); rulesSection->readBoolValue("TurretAnimPoweredSpecial", TurretAnimPoweredSpecial); rulesSection->readBoolValue("TurretAnimIsVoxel", TurretAnimIsVoxel); rulesSection->readStringValue("VoxelBarrelFile", VoxelBarrelFile); rulesSection->readStringValue("VoxelBarrelOffsetToRotatePivotPoint", VoxelBarrelOffsetToRotatePivotPoint_str); LineSplitter split3(VoxelBarrelOffsetToRotatePivotPoint_str); VoxelBarrelOffsetToRotatePivotPoint.x = split3.pop_int(); VoxelBarrelOffsetToRotatePivotPoint.y = split3.pop_int(); VoxelBarrelOffsetToRotatePivotPoint.z = split3.pop_int(); rulesSection->readStringValue("VoxelBarrelOffsetToBuildingPivotPoint", VoxelBarrelOffsetToBuildingPivotPoint_str); LineSplitter split4(VoxelBarrelOffsetToBuildingPivotPoint_str); VoxelBarrelOffsetToBuildingPivotPoint.x = split4.pop_int(); VoxelBarrelOffsetToBuildingPivotPoint.y = split4.pop_int(); VoxelBarrelOffsetToBuildingPivotPoint.z = split4.pop_int(); rulesSection->readStringValue("VoxelBarrelOffsetToPitchPivotPoint", VoxelBarrelOffsetToPitchPivotPoint_str); LineSplitter split5(VoxelBarrelOffsetToPitchPivotPoint_str); VoxelBarrelOffsetToPitchPivotPoint.x = split5.pop_int(); VoxelBarrelOffsetToPitchPivotPoint.y = split5.pop_int(); VoxelBarrelOffsetToPitchPivotPoint.z = split5.pop_int(); rulesSection->readStringValue("VoxelBarrelOffsetToBarrelEnd", VoxelBarrelOffsetToBarrelEnd_str); LineSplitter split6(VoxelBarrelOffsetToBarrelEnd_str); VoxelBarrelOffsetToBarrelEnd.x = split6.pop_int(); VoxelBarrelOffsetToBarrelEnd.y = split6.pop_int(); VoxelBarrelOffsetToBarrelEnd.z = split6.pop_int(); rulesSection->readIntValue("Upgrades", Upgrades, Upgrades); }