unfwcf.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* $MirOS: contrib/hosted/fwcf/unfwcf/unfwcf.c,v 1.8 2006/09/24 20:35:01 tg Exp $ */
  2. /*-
  3. * Copyright (c) 2006
  4. * Thorsten Glaser <tg@mirbsd.de>
  5. *
  6. * Licensee is hereby permitted to deal in this work without restric-
  7. * tion, including unlimited rights to use, publicly perform, modify,
  8. * merge, distribute, sell, give away or sublicence, provided all co-
  9. * pyright notices above, these terms and the disclaimer are retained
  10. * in all redistributions or reproduced in accompanying documentation
  11. * or other materials provided with binary redistributions.
  12. *
  13. * Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
  14. * express, or implied, to the maximum extent permitted by applicable
  15. * law, without malicious intent or gross negligence; in no event may
  16. * licensor, an author or contributor be held liable for any indirect
  17. * or other damage, or direct damage except proven a consequence of a
  18. * direct error of said person and intended use of this work, loss or
  19. * other issues arising in any way out of its use, even if advised of
  20. * the possibility of such damage or existence of a defect.
  21. */
  22. #include <sys/param.h>
  23. #include <err.h>
  24. #include <fcntl.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include "defs.h"
  29. #include "compress.h"
  30. #include "pack.h"
  31. __RCSID("$MirOS: contrib/hosted/fwcf/unfwcf/unfwcf.c,v 1.8 2006/09/24 20:35:01 tg Exp $");
  32. static int unfwcf(int, const char *);
  33. static __dead void usage(void);
  34. static int do_dump = 0;
  35. int
  36. main(int argc, char *argv[])
  37. {
  38. int c;
  39. int fd = STDIN_FILENO;
  40. const char *file_root = NULL, *infile = NULL;
  41. while ((c = getopt(argc, argv, "di:l")) != -1)
  42. switch (c) {
  43. case 'd':
  44. do_dump = 1;
  45. break;
  46. case 'i':
  47. infile = optarg;
  48. break;
  49. case 'l':
  50. return (list_compressors());
  51. default:
  52. usage();
  53. }
  54. argc -= optind;
  55. argv += optind;
  56. if (argc != (1 - do_dump))
  57. usage();
  58. file_root = *argv;
  59. if (infile != NULL)
  60. if ((fd = open(infile, O_RDONLY, 0)) < 0)
  61. err(1, "open %s", infile);
  62. return (unfwcf(fd, file_root));
  63. }
  64. static __dead void
  65. usage(void)
  66. {
  67. extern const char *__progname;
  68. fprintf(stderr, "Usage:\t%s [-i <infile>] <directory>"
  69. "\n\t%s -d [-i <infile>]"
  70. "\n\t%s -l\n", __progname, __progname, __progname);
  71. exit(1);
  72. }
  73. static int
  74. unfwcf(int fd, const char *dir)
  75. {
  76. char *udata;
  77. if ((udata = fwcf_unpack(fd, NULL))) {
  78. if (do_dump)
  79. ft_dump(udata);
  80. else
  81. ft_creatm(udata, dir);
  82. }
  83. return (udata != NULL ? 0 : 1);
  84. }