1 Star 0 Fork 1

chuck/ply

forked from FightingforYoung/ply 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
headply.c 3.42 KB
一键复制 编辑 原始数据 按行查看 历史
peteflorence 提交于 2017-05-24 02:43 +08:00 . first commit
/*
Print out the header of a PLY file.
Greg Turk
-----------------------------------------------------------------------
Copyright (c) 1998 Georgia Institute of Technology. All rights reserved.
Permission to use, copy, modify and distribute this software and its
documentation for any purpose is hereby granted without fee, provided
that the above copyright notice and this permission notice appear in
all copies of this software and that you do not sell the software.
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdio.h>
#include <math.h>
#include <strings.h>
void read_header(FILE *fp);
/******************************************************************************
Main program.
******************************************************************************/
main(int argc, char *argv[])
{
int i,j;
char *s;
char *progname;
char filename[80];
FILE *fp;
progname = argv[0];
while (--argc > 0 && (*++argv)[0]=='-') {
for (s = argv[0]+1; *s; s++)
switch (*s) {
/*
case 'f':
fract = atof (*++argv);
argc -= 1;
break;
*/
default:
usage (progname);
exit (-1);
break;
}
}
/* read from named file or from stdin */
if (argc >= 1) {
strcpy (filename, *argv);
if (strlen (filename) < 4 ||
strcmp (filename + strlen (filename) - 4, ".ply") != 0)
strcat (filename, ".ply");
fp = fopen (filename, "r");
if (fp == NULL) {
fprintf (stderr, "Cannot open file '%s'\n", filename);
exit (-1);
}
read_header (fp);
}
else
read_header (stdin);
}
/******************************************************************************
Print out usage information.
******************************************************************************/
usage(char *progname)
{
fprintf (stderr, "usage: %s <in.ply\n", progname);
fprintf (stderr, " or\n");
fprintf (stderr, "usage: %s in.[ply]\n", progname);
}
/******************************************************************************
Get a line from a text file.
Entry:
fp - file to read from
Exit:
returns string of characters from the file
******************************************************************************/
char *get_line(FILE *fp)
{
static char str[200];
char *ptr;
fgets (str, 200, fp);
str[200] = '\0';
/* replace new-line with null character */
for (ptr = str; *ptr != '\0'; ptr++)
if (*ptr == '\n') {
*ptr = '\0';
break;
}
return (str);
}
/******************************************************************************
Read the header from a PLY file and print it out.
Entry:
fp - file pointer of the file to read from
******************************************************************************/
void read_header(FILE *fp)
{
char *str;
int count = 0;
str = get_line (fp);
/* make sure this is a PLY file */
if (strcmp(str, "ply") != 0) {
fprintf (stderr, "This is not a PLY file.\n");
exit (-1);
}
printf ("%s\n", str);
while (1) {
str = get_line (fp);
printf ("%s\n", str);
count++;
if (count > 100) {
fprintf (stderr, "Header seems to be too long, so we're quitting.\n");
break;
}
if (strcmp(str, "end_header") == 0)
break;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chuck_chen/ply.git
git@gitee.com:chuck_chen/ply.git
chuck_chen
ply
ply
master

搜索帮助