📄 rply.c
字号:
if (!ply_read_word(ply)) return 0; property->value_type = ply_find_string(BWORD(ply), ply_type_list); if (property->value_type == (e_ply_type) (-1)) return 0; } /* get property name */ if (!ply_read_word(ply)) return 0; strcpy(property->name, BWORD(ply)); if (!ply_read_word(ply)) return 0; return 1;}static int ply_read_header_element(p_ply ply) { p_ply_element element = NULL; long dummy; assert(ply && ply->fp && ply->io_mode == PLY_READ); if (strcmp(BWORD(ply), "element")) return 0; /* allocate room for new element */ element = ply_grow_element(ply); if (!element) return 0; /* get element name */ if (!ply_read_word(ply)) return 0; strcpy(element->name, BWORD(ply)); /* get number of elements of this type */ if (!ply_read_word(ply)) return 0; if (sscanf(BWORD(ply), "%ld", &dummy) != 1) { ply_error(ply, "Expected number got '%s'", BWORD(ply)); return 0; } element->ninstances = dummy; /* get all properties for this element */ if (!ply_read_word(ply)) return 0; while (ply_read_header_property(ply) || ply_read_header_comment(ply) || ply_read_header_obj_info(ply)) /* do nothing */; return 1;}static void ply_error_cb(const char *message) { fprintf(stderr, "RPly: %s\n", message);}static void ply_error(p_ply ply, const char *fmt, ...) { char buffer[1024]; va_list ap; va_start(ap, fmt); vsprintf(buffer, fmt, ap); va_end(ap); ply->error_cb(buffer);}static e_ply_storage_mode ply_arch_endian(void) { unsigned long i = 1; unsigned char *s = (unsigned char *) &i; if (*s == 1) return PLY_LITTLE_ENDIAN; else return PLY_BIG_ENDIAN;}static int ply_type_check(void) { assert(sizeof(char) == 1); assert(sizeof(unsigned char) == 1); assert(sizeof(short) == 2); assert(sizeof(unsigned short) == 2); assert(sizeof(long) == 4); assert(sizeof(unsigned long) == 4); assert(sizeof(float) == 4); assert(sizeof(double) == 8); if (sizeof(char) != 1) return 0; if (sizeof(unsigned char) != 1) return 0; if (sizeof(short) != 2) return 0; if (sizeof(unsigned short) != 2) return 0; if (sizeof(long) != 4) return 0; if (sizeof(unsigned long) != 4) return 0; if (sizeof(float) != 4) return 0; if (sizeof(double) != 8) return 0; return 1;}/* ---------------------------------------------------------------------- * Output handlers * ---------------------------------------------------------------------- */static int oascii_int8(p_ply ply, double value) { if (value > CHAR_MAX || value < CHAR_MIN) return 0; return fprintf(ply->fp, "%d ", (char) value) > 0;}static int oascii_uint8(p_ply ply, double value) { if (value > UCHAR_MAX || value < 0) return 0; return fprintf(ply->fp, "%d ", (unsigned char) value) > 0;}static int oascii_int16(p_ply ply, double value) { if (value > SHRT_MAX || value < SHRT_MIN) return 0; return fprintf(ply->fp, "%d ", (short) value) > 0;}static int oascii_uint16(p_ply ply, double value) { if (value > USHRT_MAX || value < 0) return 0; return fprintf(ply->fp, "%d ", (unsigned short) value) > 0;}static int oascii_int32(p_ply ply, double value) { if (value > LONG_MAX || value < LONG_MIN) return 0; return fprintf(ply->fp, "%d ", (int) value) > 0;}static int oascii_uint32(p_ply ply, double value) { if (value > ULONG_MAX || value < 0) return 0; return fprintf(ply->fp, "%d ", (unsigned int) value) > 0;}static int oascii_float32(p_ply ply, double value) { if (value < -FLT_MAX || value > FLT_MAX) return 0; return fprintf(ply->fp, "%g ", (float) value) > 0;}static int oascii_float64(p_ply ply, double value) { if (value < -DBL_MAX || value > DBL_MAX) return 0; return fprintf(ply->fp, "%g ", value) > 0;}static int obinary_int8(p_ply ply, double value) { char int8 = (char) value; if (value > CHAR_MAX || value < CHAR_MIN) return 0; return ply->odriver->ochunk(ply, &int8, sizeof(int8));}static int obinary_uint8(p_ply ply, double value) { unsigned char uint8 = (unsigned char) value; if (value > UCHAR_MAX || value < 0) return 0; return ply->odriver->ochunk(ply, &uint8, sizeof(uint8)); }static int obinary_int16(p_ply ply, double value) { short int16 = (short) value; if (value > SHRT_MAX || value < SHRT_MIN) return 0; return ply->odriver->ochunk(ply, &int16, sizeof(int16));}static int obinary_uint16(p_ply ply, double value) { unsigned short uint16 = (unsigned short) value; if (value > USHRT_MAX || value < 0) return 0; return ply->odriver->ochunk(ply, &uint16, sizeof(uint16)); }static int obinary_int32(p_ply ply, double value) { long int32 = (long) value; if (value > LONG_MAX || value < LONG_MIN) return 0; return ply->odriver->ochunk(ply, &int32, sizeof(int32));}static int obinary_uint32(p_ply ply, double value) { unsigned long uint32 = (unsigned long) value; if (value > ULONG_MAX || value < 0) return 0; return ply->odriver->ochunk(ply, &uint32, sizeof(uint32));}static int obinary_float32(p_ply ply, double value) { float float32 = (float) value; if (value > FLT_MAX || value < -FLT_MAX) return 0; return ply->odriver->ochunk(ply, &float32, sizeof(float32));}static int obinary_float64(p_ply ply, double value) { return ply->odriver->ochunk(ply, &value, sizeof(value)); }/* ---------------------------------------------------------------------- * Input handlers * ---------------------------------------------------------------------- */static int iascii_int8(p_ply ply, double *value) { char *end; if (!ply_read_word(ply)) return 0; *value = strtol(BWORD(ply), &end, 10); if (*end || *value > CHAR_MAX || *value < CHAR_MIN) return 0; return 1;}static int iascii_uint8(p_ply ply, double *value) { char *end; if (!ply_read_word(ply)) return 0; *value = strtol(BWORD(ply), &end, 10); if (*end || *value > UCHAR_MAX || *value < 0) return 0; return 1;}static int iascii_int16(p_ply ply, double *value) { char *end; if (!ply_read_word(ply)) return 0; *value = strtol(BWORD(ply), &end, 10); if (*end || *value > SHRT_MAX || *value < SHRT_MIN) return 0; return 1;}static int iascii_uint16(p_ply ply, double *value) { char *end; if (!ply_read_word(ply)) return 0; *value = strtol(BWORD(ply), &end, 10); if (*end || *value > USHRT_MAX || *value < 0) return 0; return 1;}static int iascii_int32(p_ply ply, double *value) { char *end; if (!ply_read_word(ply)) return 0; *value = strtol(BWORD(ply), &end, 10); if (*end || *value > LONG_MAX || *value < LONG_MIN) return 0; return 1;}static int iascii_uint32(p_ply ply, double *value) { char *end; if (!ply_read_word(ply)) return 0; *value = strtol(BWORD(ply), &end, 10); if (*end || *value < 0) return 0; return 1;}static int iascii_float32(p_ply ply, double *value) { char *end; if (!ply_read_word(ply)) return 0; *value = strtod(BWORD(ply), &end); if (*end || *value < -FLT_MAX || *value > FLT_MAX) return 0; return 1;}static int iascii_float64(p_ply ply, double *value) { char *end; if (!ply_read_word(ply)) return 0; *value = strtod(BWORD(ply), &end); if (*end || *value < -DBL_MAX || *value > DBL_MAX) return 0; return 1;}static int ibinary_int8(p_ply ply, double *value) { char int8; if (!ply->idriver->ichunk(ply, &int8, 1)) return 0; *value = int8; return 1;}static int ibinary_uint8(p_ply ply, double *value) { unsigned char uint8; if (!ply->idriver->ichunk(ply, &uint8, 1)) return 0; *value = uint8; return 1;}static int ibinary_int16(p_ply ply, double *value) { short int16; if (!ply->idriver->ichunk(ply, &int16, sizeof(int16))) return 0; *value = int16; return 1;}static int ibinary_uint16(p_ply ply, double *value) { unsigned short uint16; if (!ply->idriver->ichunk(ply, &uint16, sizeof(uint16))) return 0; *value = uint16; return 1;}static int ibinary_int32(p_ply ply, double *value) { long int32; if (!ply->idriver->ichunk(ply, &int32, sizeof(int32))) return 0; *value = int32; return 1;}static int ibinary_uint32(p_ply ply, double *value) { unsigned long uint32; if (!ply->idriver->ichunk(ply, &uint32, sizeof(uint32))) return 0; *value = uint32; return 1;}static int ibinary_float32(p_ply ply, double *value) { float float32; if (!ply->idriver->ichunk(ply, &float32, sizeof(float32))) return 0; *value = float32; ply_reverse(&float32, sizeof(float32)); return 1;}static int ibinary_float64(p_ply ply, double *value) { return ply->idriver->ichunk(ply, value, sizeof(double));}/* ---------------------------------------------------------------------- * Constants * ---------------------------------------------------------------------- */static t_ply_idriver ply_idriver_ascii = { { iascii_int8, iascii_uint8, iascii_int16, iascii_uint16, iascii_int32, iascii_uint32, iascii_float32, iascii_float64, iascii_int8, iascii_uint8, iascii_int16, iascii_uint16, iascii_int32, iascii_uint32, iascii_float32, iascii_float64 }, /* order matches e_ply_type enum */ NULL, "ascii input"};static t_ply_idriver ply_idriver_binary = { { ibinary_int8, ibinary_uint8, ibinary_int16, ibinary_uint16, ibinary_int32, ibinary_uint32, ibinary_float32, ibinary_float64, ibinary_int8, ibinary_uint8, ibinary_int16, ibinary_uint16, ibinary_int32, ibinary_uint32, ibinary_float32, ibinary_float64 }, /* order matches e_ply_type enum */ ply_read_chunk, "binary input"};static t_ply_idriver ply_idriver_binary_reverse = { { ibinary_int8, ibinary_uint8, ibinary_int16, ibinary_uint16, ibinary_int32, ibinary_uint32, ibinary_float32, ibinary_float64, ibinary_int8, ibinary_uint8, ibinary_int16, ibinary_uint16, ibinary_int32, ibinary_uint32, ibinary_float32, ibinary_float64 }, /* order matches e_ply_type enum */ ply_read_chunk_reverse, "reverse binary input"};static t_ply_odriver ply_odriver_ascii = { { oascii_int8, oascii_uint8, oascii_int16, oascii_uint16, oascii_int32, oascii_uint32, oascii_float32, oascii_float64, oascii_int8, oascii_uint8, oascii_int16, oascii_uint16, oascii_int32, oascii_uint32, oascii_float32, oascii_float64 }, /* order matches e_ply_type enum */ NULL, "ascii output"};static t_ply_odriver ply_odriver_binary = { { obinary_int8, obinary_uint8, obinary_int16, obinary_uint16, obinary_int32, obinary_uint32, obinary_float32, obinary_float64, obinary_int8, obinary_uint8, obinary_int16, obinary_uint16, obinary_int32, obinary_uint32, obinary_float32, obinary_float64 }, /* order matches e_ply_type enum */ ply_write_chunk, "binary output"};static t_ply_odriver ply_odriver_binary_reverse = { { obinary_int8, obinary_uint8, obinary_int16, obinary_uint16, obinary_int32, obinary_uint32, obinary_float32, obinary_float64, obinary_int8, obinary_uint8, obinary_int16, obinary_uint16, obinary_int32, obinary_uint32, obinary_float32, obinary_float64 }, /* order matches e_ply_type enum */ ply_write_chunk_reverse, "reverse binary output"};/* ---------------------------------------------------------------------- * Copyright (C) 2003 Diego Nehab. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ---------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -