main.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Copyright (C) 2014 Olivier Marty <olivier.marty.m@gmail.com>
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. */
  15. #include "parser.h"
  16. #include "time.h"
  17. #include "printer.h"
  18. #include <stdlib.h>
  19. int main(int argc, char **argv)
  20. {
  21. int i;
  22. FILE *f= NULL;
  23. if(argc < 2)
  24. {
  25. fprintf(stderr, "Usage : subtitles file.srt [shift in seconds [waiting time in seconds]]\n");
  26. return 1;
  27. }
  28. f = fopen(argv[1], "r");
  29. if(f == NULL)
  30. {
  31. perror("fopen()");
  32. exit(1);
  33. }
  34. // open the window
  35. struct printerEnv penv = printerOpenWindow(-1, 240, 50);
  36. // show a counter before start the clock
  37. for(i = (argc > 3) ? atoi(argv[3]) : 5; i > 0; i--)
  38. {
  39. char t[16];
  40. sprintf(t, "%d...\n", i);
  41. printf("%s", t);
  42. printerShow(penv, t);
  43. sleep(1);
  44. }
  45. printf("0 !\n");
  46. printerClean(penv);
  47. timeInitialize((argc > 2) ? atoi(argv[2]) : 0);
  48. struct SubtitleLine sline;
  49. int id = 0;
  50. while(!feof(f))
  51. {
  52. id = next(f, id+1, &sline);
  53. timeSleepUntil(sline.begin);
  54. // show
  55. printf("%s\n", sline.text);
  56. printerShow(penv, sline.text);
  57. // hide
  58. timeSleepUntil(sline.end);
  59. // TODO manage when the next subtitle appear before
  60. printf("\n");
  61. printerClean(penv);
  62. }
  63. printerCloseWindow(penv);
  64. fclose(f);
  65. }