コード例 #1
0
ファイル: bdyconv.c プロジェクト: daemqn/Atari_ST_Sources
int main (int argc, char **argv) {
	long fh;
	long i;
	struct objhead_struct *dst_adr=(struct objhead_struct *)&dst_buffer;
	
	if (argc<3) {
		printf("Usage: bdyconv.ttp <source.bdy> <dest.e3d>\n");
		Cconin();
		return 0;
	}
	printf("loading %s...\n",*(argv+1));
	
	fh=Fopen(*(argv+1),FO_READ);
	if (fh<0) return 0;
	
	Fread(fh,153600,&bdy_buffer);
	Fclose(fh);

	print_header_info((struct bdy_header *)&bdy_buffer);
	parse_bdy_data(&bdy_buffer,dst_adr);

	printf("saving %s...",*(argv+2));
	
	fh=Fcreate(*(argv+2),0);
	if (fh<0) return 0;
	Fwrite(fh,4,&dst_adr->num_of_points);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->x_buf);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->y_buf);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->z_buf);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->nx_buf);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->ny_buf);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->nz_buf);
	Fwrite(fh,4,&dst_adr->num_of_polys);
	Fwrite(fh,sizeof(struct bdy_poly)*dst_adr->num_of_polys,dst_adr->polygons);
	Fclose(fh);
	printf("done.\n");

	return 0;
}
コード例 #2
0
ファイル: rogg_eosfix.c プロジェクト: manxorist/rogg
int main(int argc, char *argv[])
{
  int f, i;
  unsigned char *p, *q, *o, *e;
  struct stat s;
  rogg_page_header header;
  streamref *refs;

  for (i = 1; i < argc; i++) {
    f = open(argv[i], O_RDWR);
    if (f < 0) {
	fprintf(stderr, "couldn't open '%s'\n", argv[i]);
	continue;
    }
    if (fstat(f, &s) < 0) {
	fprintf(stderr, "couldn't stat '%s'\n", argv[i]);
	close(f);
	continue;
    }
    p = mmap(0, s.st_size, PROT_READ|PROT_WRITE,
	MAP_SHARED, f, 0);
    if (p == MAP_FAILED) {
	fprintf(stderr, "couldn't mmap '%s'\n", argv[i]);
	close(f);
	continue;
    }
    fprintf(stdout, "Checking Ogg file '%s'\n", argv[i]);
    e = p + s.st_size; /* pointer to the end of the file */
    q = rogg_scan(p, s.st_size); /* scan for an Ogg page */
    refs = NULL;
    if (q == NULL) {
	fprintf(stdout, "couldn't find ogg data!\n");
    } else {
      if (q > p) {
	fprintf(stdout, "Skipped %d garbage bytes at the start\n", (int)(q-p));
      } 
      while (q < e) {
	o = rogg_scan(q, e-q); /* find the next Ogg page */
	if (o > q) {
	  fprintf(stdout, "Hole in data! skipped %d bytes\n", (int)(o-q));
	   q = o;
	} else if (o == NULL) {
	  fprintf(stdout, "Skipped %d garbage bytes as the end\n", (int)(e-q));
	  break;
	}
	rogg_page_parse(q, &header);
#ifdef VERBOSE
	print_header_info(stdout, &header);
#endif
#ifdef STRIP_EOS
	if (header.eos) {
	  /* unset any eos flags */
	  q[ROGG_OFFSET_FLAGS] &= ~0x04;
	  rogg_page_update_crc(q);
	  fprintf(stderr, "Removed eos flag on stream %08x\n",
		header.serialno);
        }
#endif
	refs = streamref_update(refs, &header);
	q += header.length;
      }
    }
#ifndef STRIP_EOS
    streamref_seteos(refs);
#endif
    streamref_free(refs);
    munmap(p, s.st_size);
    close(f);
  }
  return 0;
}
コード例 #3
0
int main(int argc, char *argv[])
{
	int dicsize;
	unsigned int udicsize;
	char *uncompressed;
	Dawg_edge rootnode = { 0, 0, 0, 0, 0 };
	Dawg_edge specialnode = { 0, 0, 0, 0, 0 };

	char *outfilename;
	char outfilenamedefault[] = "dic.dawg";
	clock_t starttime, endtime;

	if (argc < 2) {
		fprintf(stderr, "usage: %s uncompressed_dic [compressed_dic]\n",
			argv[0]);
		exit(1);
	}

	dicsize = file_length(argv[1]);
	if (dicsize < 0) {
		fprintf(stderr, "Cannot stat uncompressed dictionary %s\n",
			argv[1]);
		exit(1);
	}

	udicsize = (unsigned int)dicsize;

	outfilename = (argc == 3) ? argv[2] : outfilenamedefault;

	if ((global_outfile = fopen(outfilename, "wb")) == NULL) {
		fprintf(stderr, "Cannot open output file %s\n", outfilename);
		exit(1);
	}

	if ((uncompressed = load_uncompressed(argv[1], &udicsize)) == NULL) {
		fprintf(stderr,
			"Cannot load uncompressed dictionary into memory\n");
		exit(1);
	}

	global_input = uncompressed;
	global_endofinput = global_input + dicsize;

#define SCALE 0.6
	global_hashtable = hash_init(dicsize * SCALE);
#undef SCALE

	skip_init_header(global_outfile, &global_header);

	specialnode.last = 1;
	write_node(&specialnode, sizeof(specialnode), 1, global_outfile);
	/*
	 * Call makenode with null (relative to stringbuf) prefix;
	 * Initialize string to null; Put index of start node on output
	 */
	starttime = clock();
	rootnode.ptr = makenode(global_endstring = global_stringbuf);
	endtime = clock();
	write_node(&rootnode, sizeof(rootnode), 1, global_outfile);

	fix_header(global_outfile, &global_header);

	print_header_info(&global_header);
	hash_destroy(global_hashtable);
	free(uncompressed);
	fclose(global_outfile);

	printf(" Elapsed time is                 : %f s\n",
	       1.0 * (endtime - starttime) / CLOCKS_PER_SEC);
	printf(" Maximum recursion level reached : %d\n", max_rec);
	return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: MrBan/ubnt-image
int main (int argc, char **argv)
{
	int o;
	FILE *f = NULL;
	char *filename = NULL;
	const char *location = NULL;
	int extract = 0;
	char magic[MAGIC_LEN];

	while ((o = getopt(argc, argv, "hixC:")) != -1)
	{
		switch (o) {
		case 'i':
			extract = 0;
			break;
		case 'x':
			extract = 1;
			break;
		case 'C':
			location = optarg;
			break;
		case 'h':
			usage(argv[0]);
			return EXIT_SUCCESS;
		default:
			printf("ERROR: unkown argument '%c'\n\n", o);
			usage(argv[0]);
			return EXIT_FAILURE;
		}
	}

	if (optind >= argc) {
		printf("ERROR: no image-file\n\n");
		usage(argv[0]);
		return EXIT_FAILURE;
	}

	filename = strdup(argv[optind]);
	if (filename == NULL) {
		printf("ERROR: %s\n", strerror(errno));
		return EXIT_FAILURE;
	}

	if ((f = fopen(filename, "r")) == NULL) {
		printf("ERROR: Cannot open image file %s\n", filename);
		return EXIT_FAILURE;
	}

	if (location) {
		DIR *d = NULL;

		if (strlen(location) > (FILE_PATH_MAXLEN - FILE_SECTION_MAXLEN)) {
			printf("ERROR: location path too long\n");
			goto fail;
		}

		d = opendir(location);
		if (!d) {
			printf("ERROR: location dir: %s\n", strerror(errno));
			goto fail;
		}
		closedir(d);
	}

	printf("\nImage file: %s\n\n", filename);

	if (fread(magic, MAGIC_LEN, 1, f) != 1) {
		printf("ERROR: %s\n", strerror(errno));
		goto fail;
	}

	if (memcmp(magic, MAGIC_HEADER, 4) == 0) {
		struct header h;

		if (fread(&h, sizeof(struct header), 1, f) != 1) {
			printf("ERROR: %s\n", strerror(errno));
			goto fail;
		}

		if (!extract) {
			print_header_info(&h);
			printf("\n");
		}

	} else {
		goto fail;
	}

	while (!feof(f)) {

		if (fread(magic, MAGIC_LEN, 1, f) != 1) {
			printf("ERROR: %s\n", strerror(errno));
			goto fail;
		}

		if (memcmp(magic, MAGIC_END, 4) == 0) {

			struct signature s;

			if (fread(&s, sizeof(struct signature), 1, f) != 1) {
				printf("ERROR: %s\n", strerror(errno));
				goto fail;
			}

			if (!extract) {
				printf("Sign CRC: 0x%.8x\n", ntohl(s.crc));
				printf("\n");
			}

			break;
		} else { /* Assume a section */
			struct section s;

			if (fread(&s, sizeof(struct section), 1, f) < 1) {
				printf("ERROR: %s\n", strerror(errno));
				goto fail;
			}

			if (!extract) {
				struct section_crc scrc;

				print_section_info(&s);

				fseek(f, ntohl(s.data_size), SEEK_CUR);

				if (fread(&scrc, sizeof(struct section_crc), 1, f) != 1) {
					printf("ERROR: %s\n", strerror(errno));
					goto fail;
				}

				printf("Section CRC: 0x%.8x\n", ntohl(scrc.crc));
				printf("\n");
			} else {
				char *data = (char *)malloc(ntohl(s.data_size));
				if (data == NULL) {
					printf("ERROR: %s\n", strerror(errno));
					goto fail;
				}

				if (fread(data, ntohl(s.data_size), 1, f) != 1) {
					printf("ERROR: %s\n", strerror(errno));
					goto fail;
				}

				if (write_section(&s, (const char *)data, location) == -1) {
					goto fail;
				}

				free(data);

				fseek(f, sizeof(struct section_crc), SEEK_CUR);
			}

		}
	}

	fclose(f);
	free(filename);

	return EXIT_SUCCESS;

fail:
	fclose(f);
	free(filename);
	return EXIT_FAILURE;
}