main.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <draw.h>
  13. #include <html.h>
  14. #include "dat.h"
  15. char *url = "";
  16. int aflag;
  17. int width = 70;
  18. int defcharset;
  19. void
  20. usage(void)
  21. {
  22. fprint(2, "usage: htmlfmt [-c charset] [-u URL] [-a] [-l length] [file ...]\n");
  23. exits("usage");
  24. }
  25. void
  26. main(int argc, char *argv[])
  27. {
  28. int i, fd;
  29. char *p, *err, *file;
  30. char errbuf[ERRMAX];
  31. ARGBEGIN{
  32. case 'a':
  33. aflag++;
  34. break;
  35. case 'c':
  36. p = smprint("<meta charset=\"%s\">", EARGF(usage()));
  37. defcharset = charset(p);
  38. free(p);
  39. break;
  40. case 'l': case 'w':
  41. err = EARGF(usage());
  42. width = atoi(err);
  43. if(width <= 0)
  44. usage();
  45. break;
  46. case 'u':
  47. url = EARGF(usage());
  48. aflag++;
  49. break;
  50. default:
  51. usage();
  52. }ARGEND
  53. err = nil;
  54. file = "<stdin>";
  55. if(argc == 0)
  56. err = loadhtml(0);
  57. else
  58. for(i=0; err==nil && i<argc; i++){
  59. file = argv[i];
  60. fd = open(file, OREAD);
  61. if(fd < 0){
  62. errstr(errbuf, sizeof errbuf);
  63. err = errbuf;
  64. break;
  65. }
  66. err = loadhtml(fd);
  67. close(fd);
  68. if(err)
  69. break;
  70. }
  71. if(err)
  72. fprint(2, "htmlfmt: processing %s: %s\n", file, err);
  73. exits(err);
  74. }