Browse Source

Add some parameters

Olivier Marty 9 years ago
parent
commit
2d0f552e2a
4 changed files with 60 additions and 19 deletions
  1. 1 1
      README.md
  2. 46 10
      main.c
  3. 11 7
      printer.c
  4. 2 1
      printer.h

+ 1 - 1
README.md

@@ -28,7 +28,7 @@ To quit, press CTRL+C in the terminal.
 
 ### Optional arguments
 
-It is possible to skip x seconds, or to change the delay before starting. For details see
+It is possible to skip x seconds, or to change the delay before starting. For other parameters and details see
 ```bash
 ./subtitlesPrinter -h
 ```

+ 46 - 10
main.c

@@ -21,34 +21,69 @@
 #include "printer.h"
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
 
 void displayUsage(char *name)
 {
-  printf("Usage : %s file.srt [-s shift] [-d delay] [-h]\n", name);
-  printf("  -s x : skip the first x seconds\n");
-  printf("  -d x : wait x seconds before starting\n");
-  printf("  -h   : display this help and exit\n");
+  printf("Usage : %s file.srt\n", name);
+  printf("Options :\n");
+  printf("  -s sec\t: skip the first x seconds\n");
+  printf("  -d sec\t: wait x seconds before starting (default : 5)\n");
+  printf("  -w px\t\t: width of the window\n");
+  printf("  -H px\t\t: height of the window\n");
+  printf("  -m px\t\t: margin with the bottom of the screen\n");
+  printf("  -f fontname\t: name of the font to use\n");
+  printf("  -i fontname\t: name of the italic font to use\n");
+  printf("  -b fontname\t: name of the bold font to use\n");
+  printf("  -j fontname\t: name of the bold and italic font to use\n");
+  printf("  -h\t\t: display this help and exit\n");
 }
 
 int main(int argc, char **argv)
 {
-  int i, shift = 0, delay = 5;
+  int i, shift = 0, delay = 5, width = -1, height = 240, margin_bottom = 50;
+  char *font = NULL, *font_i = NULL, *font_b = NULL, *font_bi = NULL;
   FILE *f = NULL;
   
   // parse arguments
   int c;
-  while((c = getopt (argc, argv, "hs:d:")) != -1)
+  while((c = getopt (argc, argv, "s:d:w:H:m:f:i:b:j:h")) != -1)
     switch(c)
     {
-      case 'h':
-        displayUsage(argv[0]);
-        return 0;
       case 's':
         shift = atoi(optarg);
         break;
       case 'd':
         delay = atoi(optarg);
         break;
+      case 'w':
+        width = atoi(optarg);
+        break;
+      case 'H':
+        height = atoi(optarg);
+        break;
+      case 'm':
+        margin_bottom = atoi(optarg);
+        break;
+      case 'f':
+        font = malloc(strlen(optarg)+1);
+        strcpy(font, optarg);
+        break;
+      case 'i':
+        font_i = malloc(strlen(optarg)+1);
+        strcpy(font_i, optarg);
+        break;
+      case 'b':
+        font_b = malloc(strlen(optarg)+1);
+        strcpy(font_b, optarg);
+        break;
+      case 'j':
+        font_bi = malloc(strlen(optarg)+1);
+        strcpy(font_bi, optarg);
+        break;
+      case 'h':
+        displayUsage(argv[0]);
+        return 0;
       //case '?':
       default:
         return 1;
@@ -69,7 +104,8 @@ int main(int argc, char **argv)
   }
   
   // open the window
-  struct printerEnv penv = printerOpenWindow(-1, 240, 0);
+  struct printerEnv penv = printerOpenWindow(width, height, margin_bottom,
+    font, font_i, font_b, font_bi);
   
   // show a counter before start the clock
   for(i = delay; i > 0; i--)

+ 11 - 7
printer.c

@@ -43,8 +43,8 @@ char *strnstr(const char *s, const char *find, size_t slen)
 	return ((char *)s);
 }
 
-
-struct printerEnv printerOpenWindow(int width, int height, int padding_bottom)
+struct printerEnv printerOpenWindow(int width, int height, int margin_bottom,
+  char *font, char *font_i, char *font_b, char *font_bi)
 {
   struct printerEnv env;
 
@@ -86,15 +86,19 @@ struct printerEnv printerOpenWindow(int width, int height, int padding_bottom)
   env.height = height;
   env.w = XCreateWindow(env.d, RootWindow(env.d, env.s),
     (RootAttr.width - env.width)/2,
-    RootAttr.height - env.height - padding_bottom, env.width, env.height, 0,
+    RootAttr.height - env.height - margin_bottom, env.width, env.height, 0,
     vinfo.depth, InputOutput, vinfo.visual,
     CWColormap | CWBorderPixel | CWBackPixel | CWOverrideRedirect, &attr);
   
   // setting fonts
-  char fontname[]    = "*x24*",//"*charter-medium-r-normal*",
-       fontname_i[]  = "*charter-medium-i-normal*",
-       fontname_b[]  = "*charter-bold-r-normal*",
-       fontname_bi[] = "*charter-bold-i-normal*";
+  char *fontname    = "*x24*",//"*charter-medium-r-normal*",
+       *fontname_i  = "*charter-medium-i-normal*",
+       *fontname_b  = "*charter-bold-r-normal*",
+       *fontname_bi = "*charter-bold-i-normal*";
+  fontname    = (font == NULL)    ? fontname    : font;
+  fontname_i  = (font_i == NULL)  ? fontname_i  : font_i;
+  fontname_b  = (font_b == NULL)  ? fontname_b  : font_b;
+  fontname_bi = (font_bi == NULL) ? fontname_bi : font_bi;
   env.fontinfo    = XLoadQueryFont(env.d, fontname);
   env.fontinfo_i  = XLoadQueryFont(env.d, fontname_i);
   env.fontinfo_b  = XLoadQueryFont(env.d, fontname_b);

+ 2 - 1
printer.h

@@ -39,7 +39,8 @@ struct printerEnv
 enum t_type {T_ITALIC = 1, T_BOLD = 2};
 
 // if width < 0 the window will be as larger as possible
-struct printerEnv printerOpenWindow(int width, int height, int padding_bottom);
+struct printerEnv printerOpenWindow(int width, int height, int margin_bottom,
+  char *font, char *font_i, char *font_b, char *font_bi);
 void printerCloseWindow(struct printerEnv env);
 
 void printerShow(struct printerEnv env, char* text, enum t_type font);