aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--VERSION2
-rw-r--r--fb-gui.c50
-rw-r--r--fb-gui.h1
-rw-r--r--fbi.c255
-rw-r--r--fbi.man29
-rw-r--r--fbiconfig.c152
-rw-r--r--fbiconfig.h63
-rw-r--r--parseconfig.c96
-rw-r--r--parseconfig.h4
9 files changed, 417 insertions, 235 deletions
diff --git a/VERSION b/VERSION
index cd5ac03..2888737 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.0
+2.00
diff --git a/fb-gui.c b/fb-gui.c
index eb04e46..f0d78f3 100644
--- a/fb-gui.c
+++ b/fb-gui.c
@@ -182,6 +182,14 @@ void shadow_clear(void)
shadow_clear_lines(0, sheight-1);
}
+void shadow_set_dirty(void)
+{
+ int i;
+
+ for (i = 0; i < sheight; i++)
+ sdirty[i]++;
+}
+
void shadow_set_palette(int fd)
{
if (fb_fix.visual != FB_VISUAL_DIRECTCOLOR && fb_var.bits_per_pixel != 8)
@@ -433,13 +441,15 @@ int shadow_draw_string(FT_Face face, int x, int y, wchar_t *str, int align)
FT_Glyph image;
FT_BitmapGlyph bit;
size_t len;
- int i,ng,pos,kerning;
+ int i,ng,pos;
+ int kerning,scalable;
len = wcslen(str);
glyphs = malloc(sizeof(*glyphs) * len);
memset(glyphs,0,sizeof(*glyphs) * len);
- kerning = FT_HAS_KERNING(face);
+ kerning = FT_HAS_KERNING(face);
+ scalable = FT_IS_SCALABLE(face);
pgi = 0;
for (ng = 0, pos = 0, i = 0; str[i] != 0; i++) {
@@ -458,30 +468,32 @@ int shadow_draw_string(FT_Face face, int x, int y, wchar_t *str, int align)
ng++;
}
+ switch(align) {
+ case -1: /* left */
+ break;
+ case 0: /* center */
+ x -= pos >> 7;
+ break;
+ case 1: /* right */
+ x -= pos >> 6;
+ break;
+ }
+ pen.x = 0;
+ pen.y = 0;
for (i = 0; i < ng; i++) {
- pen.x = (x << 6) + glyphs[i].pos;
- pen.y = (sheight - y) << 6;
- switch(align) {
- case -1: /* left */
- break;
- case 0: /* center */
- pen.x -= pos/2;
- break;
- case 1: /* right */
- pen.x -= pos;
- break;
- }
image = glyphs[i].glyph;
if (0 != FT_Glyph_To_Bitmap(&image,FT_RENDER_MODE_NORMAL,&pen,0))
continue;
bit = (FT_BitmapGlyph)image;
- shadow_draw_glyph(&bit->bitmap, bit->left, sheight - bit->top);
- FT_Done_Glyph(image);
+ shadow_draw_glyph(&bit->bitmap,
+ x + bit->left + (glyphs[i].pos >> 6),
+ y - bit->top);
+ if (image != glyphs[i].glyph)
+ FT_Done_Glyph(image);
}
- for (i = 0; i < ng; i++) {
+ for (i = 0; i < ng; i++)
FT_Done_Glyph(glyphs[i].glyph);
- }
free(glyphs);
return pos >> 6;
@@ -529,7 +541,7 @@ void shadow_draw_text_box(FT_Face face, int x, int y, int percent, wchar_t *line
max = len;
}
- FT_Load_Glyph(face, FT_Get_Char_Index(face, 'm'), FT_LOAD_DEFAULT);
+ FT_Load_Glyph(face, FT_Get_Char_Index(face, 'x'), FT_LOAD_DEFAULT);
x1 = x;
x2 = x + max * (face->glyph->advance.x >> 6);
y1 = y;
diff --git a/fb-gui.h b/fb-gui.h
index 4085346..351f866 100644
--- a/fb-gui.h
+++ b/fb-gui.h
@@ -7,6 +7,7 @@ extern int visible;
void shadow_render(void);
void shadow_clear_lines(int first, int last);
void shadow_clear(void);
+void shadow_set_dirty(void);
void shadow_set_palette(int fd);
void shadow_init(void);
void shadow_fini(void);
diff --git a/fbi.c b/fbi.c
index 77d86bb..db4057a 100644
--- a/fbi.c
+++ b/fbi.c
@@ -1,7 +1,7 @@
/*
* image viewer, for framebuffer devices
*
- * (c) 1998-2002 Gerd Knorr <kraxel@bytesex.org>
+ * (c) 1998-2004 Gerd Knorr <kraxel@bytesex.org>
*
*/
@@ -41,7 +41,6 @@
#include "filter.h"
#include "desktop.h"
#include "list.h"
-#include "parseconfig.h"
#include "fbiconfig.h"
#include "jpeg/transupp.h" /* Support routines for jpegtran */
@@ -112,39 +111,10 @@ struct fb_cmap cmap = { 0, 256, red, green, blue };
static float fbgamma = 1;
/* Command line options. */
-
-int autodown = 0;
-int autoup = 0;
-int comments = 0;
-int transparency = 30;
-
-struct option fbi_options[] = {
- {"version", no_argument, NULL, 'V'}, /* version */
- {"help", no_argument, NULL, 'h'}, /* help */
- {"device", required_argument, NULL, 'd'}, /* device */
- {"mode", required_argument, NULL, 'm'}, /* video mode */
- {"gamma", required_argument, NULL, 'g'}, /* set gamma */
- {"quiet", no_argument, NULL, 'q'}, /* quiet */
- {"verbose", no_argument, NULL, 'v'}, /* verbose */
- {"scroll", required_argument, NULL, 's'}, /* set scrool */
- {"timeout", required_argument, NULL, 't'}, /* timeout value */
- {"once", no_argument, NULL, '1'}, /* loop only once */
- {"resolution", required_argument, NULL, 'r'}, /* select resolution */
- {"random", no_argument, NULL, 'u'}, /* randomize images */
- {"font", required_argument, NULL, 'f'}, /* font */
- {"autozoom", no_argument, NULL, 'a'},
- {"edit", no_argument, NULL, 'e'}, /* enable editing */
- {"list", required_argument, NULL, 'l'},
- {"vt", required_argument, NULL, 'T'},
- {"backup", no_argument, NULL, 'b'},
- {"preserve", no_argument, NULL, 'p'},
-
- /* long-only options */
- {"autoup", no_argument, &autoup, 1 },
- {"autodown", no_argument, &autodown, 1 },
- {"comments", no_argument, &comments, 1 },
- {0,0,0,0}
-};
+int autodown;
+int autoup;
+int comments;
+int transparency = 40;
/* font handling */
static char *fontname = NULL;
@@ -155,8 +125,10 @@ static FT_Face face;
static void
version(void)
{
- fprintf(stderr, "fbi version " VERSION
- " (c) 1999-2003 Gerd Knorr; compiled on %s.\n", __DATE__ );
+ fprintf(stderr,
+ "fbi version " VERSION ", compiled on %s\n"
+ "(c) 1999-2004 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]\n",
+ __DATE__ );
}
static void
@@ -172,40 +144,21 @@ usage(char *name)
"Supported formats: PhotoCD, jpeg, ppm, gif, tiff, xwd, bmp, png.\n"
"It tries to use ImageMagick's convert for unknown file formats.\n"
"\n"
- " Usage: %s [ options ] file1 file2 ... fileN\n"
- "\n"
- " --help [-h] Print this text\n"
- " --version [-V] Show the fbi version number\n"
- " --device [-d] dev Framebuffer device [%s]\n"
- " --mode [-m] mode Video mode (must be listed in /etc/fb.modes)\n"
- " - Default is current mode.\n"
- " --gamma [-g] f Set gamma\n"
- " --scroll [-s] n Set scroll steps in pixels (default: 50)\n"
- " --quiet [-q] don't print anything at all\n"
- " --verbose [-v] show print filenames all the time\n"
- " --timeout [-t] n Load next image after N sec without any keypress\n"
- " --once [-1] Don't loop (for use with -t).\n"
- " --resolution [-r] n Select resolution [1..5] (PhotoCD)\n"
- " --random [-u] Show file1 .. fileN in a random order\n"
- " --font [-f] fn Use font fn (either console psf file or\n"
- " X11 font spec if a font server is available\n"
- " --autozoom [-a] Automagically pick useful zoom factor.\n"
- " --autoup Like the above, but upscale only.\n"
- " --autodown Like the above, but downscale only.\n"
- " --edit [-e] enable editing commands (see man page).\n"
- " --backup [-b] create backup files when editing.\n"
- " --preserve [-p] preserve timestamps when editing.\n"
- " --list [-l] file read list of images from file\n"
- " --comments display image comments\n"
- " --vt [-T] vt start on console #vt\n"
+ "usage: %s [ options ] file1 file2 ... fileN\n"
+ "\n",
+ name);
+
+ cfg_help_cmdline(fbi_cmd,4,20,0);
+ cfg_help_cmdline(fbi_cfg,4,20,40);
+
+ fprintf(stderr,
"\n"
"Large images can be scrolled using the cursor keys. Zoom in/out\n"
"works with '+' and '-'. Use ESC or 'q' to quit. Space and PgDn\n"
"show the next, PgUp shows the previous image. Jumping to a image\n"
"works with <number>g. Return acts like Space but additionally\n"
"prints the filename of the currently displayed image to stdout.\n"
- "\n",
- name, fbdev ? fbdev : "/dev/fb0");
+ "\n");
}
/* ---------------------------------------------------------------------- */
@@ -585,7 +538,7 @@ static void debug_key(char *key)
}
static void
-console_switch(int is_busy)
+console_switch(void)
{
switch (fb_switch_state) {
case FB_REL_REQ:
@@ -597,11 +550,10 @@ console_switch(int is_busy)
fb_switch_acquire();
case FB_ACTIVE:
visible = 1;
- redraw = 1;
ioctl(fd,FBIOPAN_DISPLAY,&fb_var);
- shadow_clear();
- if (is_busy)
- status_update(NULL, "busy, please wait ...", NULL);
+ shadow_set_palette(fd);
+ shadow_set_dirty();
+ shadow_render();
break;
default:
break;
@@ -673,7 +625,7 @@ read_image(char *filename)
img->data = malloc(img->i.width * img->i.height * 3);
for (y = 0; y < img->i.height; y++) {
if (switch_last != fb_switch_state)
- console_switch(1);
+ console_switch();
loader->read(img->data + img->i.width * 3 * y, y, data);
}
loader->done(data);
@@ -706,7 +658,7 @@ scale_image(struct ida_image *src, float scale)
dest->data = malloc(dest->i.width * dest->i.height * 3);
for (y = 0; y < dest->i.height; y++) {
if (switch_last != fb_switch_state)
- console_switch(1);
+ console_switch();
desc_resize.work(src,&rect,
dest->data + 3 * dest->i.width * y,
y, data);
@@ -781,7 +733,7 @@ svga_show(struct ida_image *img, int timeout, char *desc, char *info, int *nr)
shadow_render();
}
if (switch_last != fb_switch_state) {
- console_switch(0);
+ console_switch();
continue;
}
FD_ZERO(&set);
@@ -796,9 +748,9 @@ svga_show(struct ida_image *img, int timeout, char *desc, char *info, int *nr)
limit.tv_sec = timeout;
limit.tv_usec = 0;
rc = select(fdmax, &set, NULL, NULL,
- (-1 != timeout && !paused) ? &limit : NULL);
+ (0 != timeout && !paused) ? &limit : NULL);
if (switch_last != fb_switch_state) {
- console_switch(0);
+ console_switch();
continue;
}
if (0 == rc)
@@ -878,7 +830,7 @@ svga_show(struct ida_image *img, int timeout, char *desc, char *info, int *nr)
} else if (0 == strcmp(key, "p") ||
0 == strcmp(key, "P")) {
- if (-1 != timeout) {
+ if (0 != timeout) {
paused = !paused;
status_update(img, paused ? "pause on " : "pause off", NULL);
}
@@ -1028,16 +980,12 @@ static char edit_line(struct ida_image *img, char *line, int max)
fd_set set;
do {
-#if 0
- fb_edit_line(line,pos);
-#else
status_edit(img,line,pos);
-#endif
-
+
FD_SET(0, &set);
rc = select(1, &set, NULL, NULL, NULL);
if (switch_last != fb_switch_state) {
- console_switch(0);
+ console_switch();
continue;
}
rc = read(0, key, sizeof(key)-1);
@@ -1137,10 +1085,7 @@ static void cleanup_and_exit(int code)
int
main(int argc, char *argv[])
{
- int timeout = -1;
- int randomize = -1;
- int opt_index = 0;
- int vt = 0;
+ int timeout = 0;
int backup = 0;
int preserve = 0;
@@ -1150,109 +1095,65 @@ main(int argc, char *argv[])
float scale = 1;
float newscale = 1;
- int c, editable = 0, once = 0;
+ int editable = 0, once = 0;
int need_read;
int i, arg, key;
- char *line, *info, *desc;
+ char *info, *desc, *filelist;
char linebuffer[128];
-#if 0 /* debug aid */
+#if 0
+ /* debug aid, to attach gdb ... */
fprintf(stderr,"pid %d\n",getpid());
- sleep(30);
+ sleep(10);
#endif
- if (NULL != (line = getenv("FRAMEBUFFER")))
- fbdev = line;
- if (NULL != (line = getenv("FBGAMMA")))
- fbgamma = atof(line);
- if (NULL != (line = getenv("FBFONT")))
- fontname = line;
-
+ setlocale(LC_ALL,"");
#ifdef HAVE_LIBLIRC
lirc = lirc_fbi_init();
#endif
fbi_read_config();
+ cfg_parse_cmdline(&argc,argv,fbi_cmd);
+ cfg_parse_cmdline(&argc,argv,fbi_cfg);
- setlocale(LC_ALL,"");
- for (;;) {
- c = getopt_long(argc, argv, "u1evahPqVbpr:t:m:d:g:s:f:l:T:",
- fbi_options, &opt_index);
- if (c == -1)
- break;
- switch (c) {
- case 0:
- /* long option, nothing to do */
- break;
- case '1':
- once = 1;
- break;
- case 'a':
- autoup = 1;
- autodown = 1;
- break;
- case 'q':
- statusline = 0;
- break;
- case 'v':
- statusline = 1;
- break;
- case 'P':
- textreading = 1;
- break;
- case 'g':
- fbgamma = atof(optarg);
- break;
- case 'r':
- pcd_res = atoi(optarg);
- break;
- case 's':
- steps = atoi(optarg);
- break;
- case 't':
- timeout = atoi(optarg);
- break;
- case 'u':
- randomize = 1;
- break;
- case 'd':
- fbdev = optarg;
- break;
- case 'm':
- fbmode = optarg;
- break;
- case 'f':
- fontname = optarg;
- break;
- case 'e':
- editable = 1;
- break;
- case 'b':
- backup = 1;
- break;
- case 'p':
- preserve = 1;
- break;
- case 'l':
- flist_add_list(optarg);
- break;
- case 'T':
- vt = atoi(optarg);
- break;
- case 'V':
- version();
- exit(0);
- break;
- default:
- case 'h':
- usage(argv[0]);
- exit(1);
- }
+ if (GET_AUTO_ZOOM()) {
+ cfg_set_bool(O_AUTO_UP, 1);
+ cfg_set_bool(O_AUTO_DOWN, 1);
}
- for (i = optind; i < argc; i++) {
- flist_add(argv[i]);
+ if (GET_HELP()) {
+ usage(argv[0]);
+ exit(0);
+ }
+ if (GET_VERSION()) {
+ version();
+ exit(0);
}
+ if (GET_WRITECONF())
+ fbi_write_config();
+
+ once = GET_ONCE();
+ autoup = GET_AUTO_UP();
+ autodown = GET_AUTO_DOWN();
+ statusline = GET_VERBOSE();
+ textreading = GET_TEXT_MODE();
+ editable = GET_EDIT();
+ backup = GET_BACKUP();
+ preserve = GET_PRESERVE();
+
+ steps = GET_SCROLL();
+ timeout = GET_TIMEOUT();
+ pcd_res = GET_PCD_RES();
+
+ fbgamma = GET_GAMMA();
+
+ fontname = cfg_get_str(O_FONT);
+ filelist = cfg_get_str(O_FILE_LIST);
+
+ if (filelist)
+ flist_add_list(filelist);
+ for (i = optind; i < argc; i++)
+ flist_add(argv[i]);
flist_renumber();
if (0 == fcount) {
@@ -1260,14 +1161,16 @@ main(int argc, char *argv[])
exit(1);
}
- if (randomize != -1)
+ if (GET_RANDOM())
flist_randomize();
fcurrent = flist_first();
need_read = 1;
font_init();
- face = font_open("monospace:size=16");
- fd = fb_init(fbdev, fbmode, vt);
+ face = font_open(fontname ? fontname : "monospace:size=16");
+ fd = fb_init(cfg_get_str(O_DEVICE),
+ cfg_get_str(O_VIDEO_MODE),
+ GET_VT());
fb_catch_exit_signals();
fb_switch_init();
shadow_init();
diff --git a/fbi.man b/fbi.man
index 35b8a7e..99dd0b1 100644
--- a/fbi.man
+++ b/fbi.man
@@ -1,4 +1,4 @@
-.TH fbi 1 "(c) 1999-2002 Gerd Knorr"
+.TH fbi 1 "(c) 1999-2004 Gerd Knorr"
.SH NAME
fbi - linux \fBf\fPrame\fBb\fPuffer \fBi\fPmageviewer
.SH SYNOPSIS
@@ -22,11 +22,8 @@ mapped to.
name of the video mode to use video mode (must be listed in
/etc/fb.modes). Default is not to change the video mode.
.TP
-.B -q
-be quiet: don't print anything.
-.TP
.B -v
-be verbose: allways print filenames.
+be verbose: enable status line on the bottom of the screen.
.TP
.B -P
Enable textreading mode. This has the effect that fbi will display
@@ -52,12 +49,11 @@ select resolution. PhotoCD only, n = 1..5.
set scroll steps in pixels (default is 50).
.TP
.B -f font
-Set font. This can be either a pcf console font file or a X11 font
-spec. Using X11 fonts requires a font server (The one specified in
-the environment variable FONTSERVER or on localhost). The FBFONT
-environment variable is used as default. If unset, fbi will
-fallback to 10x20 (X11) / lat1u-16.psf (console).
-.TP
+Set font. This can be anything fontconfig accepts. Try fc-list for a
+list of known fonts on your system. The fontconfig config file is
+evaluated as well, so any generic stuff defined there (such as mono,
+sans) will work as well. It is recommended to use monospaced fonts,
+the textboxes (help text, exif info) look better then.
.B -a
Enable autozoom. fbi will automagically pick a reasonable zoom factor
when loading a new image.
@@ -95,6 +91,9 @@ PgDn, Space next image
Return next image, write the filename of the current
image to stdout.
P pause the slideshow (if started with -t, toggle)
+V enable/disable status line
+H display textbox with brief help
+I display textbox with some EXIF info
<number>g jump to image #<number>
.fi
.P
@@ -115,10 +114,8 @@ to type Shift+D. This is done to avoid deleting images by mistake
because there are no safety bells: If you ask fbi to delete the image,
it will be deleted without questions asked.
.P
-The rotate function actually works for JPEG images only because it
-calls the jpegtran command to perform a lossless rotation if the image.
-It is especially useful if you review the images of your digital
-camera.
+The rotate function actually works for JPEG images only. It does
+a lossless transformation of the image.
.SH COMMON PROBLEMS
.B fbi
needs rw access to the framebuffer devices (/dev/fbN), i.e you (our
@@ -139,7 +136,7 @@ logins, but any kind of a pseudo tty (xterm, ssh, screen, ...) will
.B not
work.
.SH SEE ALSO
-fbset(1), convert(1), jpegtran(1)
+fbset(1), convert(1)
.SH AUTHOR
Gerd Knorr <kraxel@bytesex.org>
.SH COPYRIGHT
diff --git a/fbiconfig.c b/fbiconfig.c
index 0d86860..249a5ab 100644
--- a/fbiconfig.c
+++ b/fbiconfig.c
@@ -4,9 +4,159 @@
#include <string.h>
#include <sys/stat.h>
-#include "parseconfig.h"
#include "fbiconfig.h"
+/* ------------------------------------------------------------------------ */
+
+struct cfg_cmdline fbi_cmd[] = {
+ {
+ .letter = 'h',
+ .cmdline = "help",
+ .option = { O_HELP },
+ .value = "1",
+ .desc = "print this help text",
+ },{
+ .letter = 'V',
+ .cmdline = "version",
+ .option = { O_VERSION },
+ .value = "1",
+ .desc = "print fbi version number",
+ },{
+ .cmdline = "store",
+ .option = { O_WRITECONF },
+ .value = "1",
+ .desc = "write cmd line args to config file",
+ },{
+ .letter = 'l',
+ .cmdline = "list",
+ .option = { O_FILE_LIST },
+ .needsarg = 1,
+ .desc = "read image filelist from file <arg>",
+ },{
+ .letter = 'P',
+ .cmdline = "text",
+ .option = { O_TEXT_MODE },
+ .needsarg = 1,
+ .desc = "switch into text reading mode",
+ },{
+ .letter = 'a',
+ .cmdline = "autozoom",
+ .option = { O_AUTO_ZOOM },
+ .value = "1",
+ .desc = "automagically pick useful zoom factor",
+ },{
+ /* end of list */
+ }
+};
+
+struct cfg_cmdline fbi_cfg[] = {
+ {
+ .cmdline = "autoup",
+ .option = { O_AUTO_UP },
+ .yesno = 1,
+ .desc = " like the above, but upscale only",
+ },{
+ .cmdline = "autodown",
+ .option = { O_AUTO_DOWN },
+ .yesno = 1,
+ .desc = " like the above, but downscale only",
+
+ },{
+ .letter = 'v',
+ .cmdline = "verbose",
+ .option = { O_VERBOSE },
+ .yesno = 1,
+ .desc = "show filenames all the time",
+ },{
+ .letter = 'u',
+ .cmdline = "random",
+ .option = { O_RANDOM },
+ .yesno = 1,
+ .desc = "show files in a random order",
+ },{
+ .letter = '1',
+ .cmdline = "once",
+ .option = { O_ONCE },
+ .yesno = 1,
+ .desc = "don't loop (for use with -t)",
+ },{
+ .cmdline = "comments",
+ .option = { O_COMMENTS },
+ .yesno = 1,
+ .desc = "display image comments",
+ },{
+ .letter = 'e',
+ .cmdline = "edit",
+ .option = { O_EDIT },
+ .yesno = 1,
+ .desc = "enable editing commands (see man page)",
+ },{
+ .cmdline = "backup",
+ .option = { O_BACKUP },
+ .yesno = 1,
+ .desc = " create backup files when editing",
+ },{
+ .cmdline = "preserve",
+ .option = { O_PRESERVE },
+ .yesno = 1,
+ .desc = " preserve timestamps when editing",
+
+ },{
+ .letter = 'T',
+ .cmdline = "vt",
+ .option = { O_VT },
+ .needsarg = 1,
+ .desc = "start on virtual console <arg>",
+ },{
+ .letter = 's',
+ .cmdline = "scroll",
+ .option = { O_SCROLL },
+ .needsarg = 1,
+ .desc = "scroll image by <arg> pixels",
+ },{
+ .letter = 't',
+ .cmdline = "timeout",
+ .option = { O_TIMEOUT },
+ .needsarg = 1,
+ .desc = "load next image after <arg> sec without user input",
+ },{
+ .letter = 'r',
+ .cmdline = "resolution",
+ .option = { O_PCD_RES },
+ .needsarg = 1,
+ .desc = "pick PhotoCD resolution (1..5)",
+ },{
+ .letter = 'g',
+ .cmdline = "gamma",
+ .option = { O_GAMMA },
+ .needsarg = 1,
+ .desc = "set display gamma (doesn't work on all hardware)",
+ },{
+ .letter = 'f',
+ .cmdline = "font",
+ .option = { O_FONT },
+ .needsarg = 1,
+ .desc = "use font <arg> (anything fontconfig accepts)",
+ },{
+ .letter = 'd',
+ .cmdline = "device",
+ .option = { O_DEVICE },
+ .needsarg = 1,
+ .desc = "use framebuffer device <arg>",
+ },{
+ .letter = 'm',
+ .cmdline = "mode",
+ .option = { O_VIDEO_MODE },
+ .needsarg = 1,
+ .desc = "use video mode <arg> (from /etc/fb.modes)",
+
+ },{
+ /* end of list */
+ }
+};
+
+/* ------------------------------------------------------------------------ */
+
static char *fbi_config = NULL;
static void init_config(void)
diff --git a/fbiconfig.h b/fbiconfig.h
index ff99e7e..7dcde2c 100644
--- a/fbiconfig.h
+++ b/fbiconfig.h
@@ -1,2 +1,65 @@
+#include "parseconfig.h"
+
+#define O_CMDLINE "cmdline", "options"
+#define O_OPTIONS "config", "options"
+
+#define O_HELP O_CMDLINE, "help"
+#define O_VERSION O_CMDLINE, "version"
+#define O_WRITECONF O_CMDLINE, "writeconf"
+#define O_FILE_LIST O_CMDLINE, "file-list"
+#define O_TEXT_MODE O_CMDLINE, "text-mode"
+#define O_AUTO_ZOOM O_CMDLINE, "auto-zoom"
+
+#define O_AUTO_UP O_OPTIONS, "auto-up"
+#define O_AUTO_DOWN O_OPTIONS, "auto-down"
+#define O_QUIET O_OPTIONS, "quiet"
+#define O_VERBOSE O_OPTIONS, "verbose"
+#define O_RANDOM O_OPTIONS, "random"
+#define O_ONCE O_OPTIONS, "once"
+#define O_COMMENTS O_OPTIONS, "comments"
+#define O_EDIT O_OPTIONS, "edit"
+#define O_BACKUP O_OPTIONS, "backup"
+#define O_PRESERVE O_OPTIONS, "preserve"
+
+#define O_VT O_OPTIONS, "vt"
+#define O_SCROLL O_OPTIONS, "scroll"
+#define O_TIMEOUT O_OPTIONS, "timeout"
+#define O_PCD_RES O_OPTIONS, "photocd-res"
+
+#define O_GAMMA O_OPTIONS, "gamma"
+
+#define O_DEVICE O_OPTIONS, "device"
+#define O_FONT O_OPTIONS, "font"
+#define O_VIDEO_MODE O_OPTIONS, "video-mode"
+
+#define GET_HELP() cfg_get_bool(O_HELP, 0)
+#define GET_VERSION() cfg_get_bool(O_VERSION, 0)
+#define GET_WRITECONF() cfg_get_bool(O_WRITECONF, 0)
+#define GET_TEXT_MODE() cfg_get_bool(O_TEXT_MODE, 0)
+#define GET_AUTO_ZOOM() cfg_get_bool(O_AUTO_ZOOM, 0)
+
+#define GET_AUTO_UP() cfg_get_bool(O_AUTO_UP, 0)
+#define GET_AUTO_DOWN() cfg_get_bool(O_AUTO_DOWN, 0)
+#define GET_QUIET() cfg_get_bool(O_QUIET, 0)
+#define GET_VERBOSE() cfg_get_bool(O_VERBOSE, 1)
+#define GET_RANDOM() cfg_get_bool(O_RANDOM, 0)
+#define GET_ONCE() cfg_get_bool(O_ONCE, 0)
+#define GET_COMMENTS() cfg_get_bool(O_COMMENTS, 0)
+#define GET_EDIT() cfg_get_bool(O_EDIT, 0)
+#define GET_BACKUP() cfg_get_bool(O_BACKUP, 0)
+#define GET_PRESERVE() cfg_get_bool(O_PRESERVE, 0)
+
+#define GET_VT() cfg_get_int(O_VT, 0)
+#define GET_SCROLL() cfg_get_int(O_SCROLL, 50)
+#define GET_TIMEOUT() cfg_get_int(O_TIMEOUT, 0)
+#define GET_PCD_RES() cfg_get_int(O_PCD_RES, 3)
+
+#define GET_GAMMA() cfg_get_float(O_GAMMA, 1)
+
+/* -------------------------------------------------------------------------- */
+
+extern struct cfg_cmdline fbi_cmd[];
+extern struct cfg_cmdline fbi_cfg[];
void fbi_read_config(void);
void fbi_write_config(void);
+
diff --git a/parseconfig.c b/parseconfig.c
index 8c20169..e7a0e0a 100644
--- a/parseconfig.c
+++ b/parseconfig.c
@@ -333,18 +333,64 @@ void
cfg_parse_cmdline(int *argc, char **argv, struct cfg_cmdline *opt)
{
int i,j,o,shift,len;
+ char sopt,*lopt;
for (i = 1; i < *argc;) {
if (argv[i][0] != '-') {
i++;
continue;
}
+ if (argv[i][1] == 0) {
+ i++;
+ continue;
+ }
+
+ sopt = 0;
+ lopt = NULL;
+ if (argv[i][1] != '-' &&
+ argv[i][2] == 0) {
+ /* short option: -f */
+ sopt = argv[i][1];
+ }
+ if (argv[i][1] != '-') {
+ /* long option: -foo */
+ lopt = argv[i]+1;
+ } else {
+ /* also accept gnu-style: --foo */
+ lopt = argv[i]+2;
+ }
for (shift = 0, o = 0;
0 == shift && opt[o].cmdline != NULL;
o++) {
len = strlen(opt[o].cmdline);
- if (opt[o].yesno && 0 == strcmp(argv[i]+1,opt[o].cmdline)) {
+
+ if (opt[o].yesno && sopt && sopt == opt[o].letter) {
+ /* yesno: -f */
+ cfg_set_bool(opt[o].option.domain,
+ opt[o].option.section,
+ opt[o].option.entry,
+ 1);
+ shift = 1;
+
+ } else if (opt[o].needsarg && sopt && sopt == opt[o].letter) {
+ /* arg: -f bar */
+ cfg_set_str(opt[o].option.domain,
+ opt[o].option.section,
+ opt[o].option.entry,
+ argv[i+1]);
+ shift = 2;
+
+ } else if (opt[o].value && sopt && sopt == opt[o].letter) {
+ /* -f sets fixed value */
+ cfg_set_str(opt[o].option.domain,
+ opt[o].option.section,
+ opt[o].option.entry,
+ opt[o].value);
+ shift = 1;
+
+ } else if (opt[o].yesno && lopt &&
+ 0 == strcmp(lopt,opt[o].cmdline)) {
/* yesno: -foo */
cfg_set_bool(opt[o].option.domain,
opt[o].option.section,
@@ -352,9 +398,9 @@ cfg_parse_cmdline(int *argc, char **argv, struct cfg_cmdline *opt)
1);
shift = 1;
- } else if (opt[o].yesno &&
- 0 == strncmp(argv[i]+1,"no",2) &&
- 0 == strcmp(argv[i]+3,opt[o].cmdline)) {
+ } else if (opt[o].yesno && lopt &&
+ 0 == strncmp(lopt,"no",2) &&
+ 0 == strcmp(lopt+2,opt[o].cmdline)) {
/* yesno: -nofoo */
cfg_set_bool(opt[o].option.domain,
opt[o].option.section,
@@ -362,8 +408,8 @@ cfg_parse_cmdline(int *argc, char **argv, struct cfg_cmdline *opt)
0);
shift = 1;
- } else if (opt[o].needsarg &&
- 0 == strcmp(argv[i]+1,opt[o].cmdline) &&
+ } else if (opt[o].needsarg && lopt &&
+ 0 == strcmp(lopt,opt[o].cmdline) &&
i+1 < *argc) {
/* arg: -foo bar */
cfg_set_str(opt[o].option.domain,
@@ -372,9 +418,9 @@ cfg_parse_cmdline(int *argc, char **argv, struct cfg_cmdline *opt)
argv[i+1]);
shift = 2;
- } else if (opt[o].needsarg &&
- 0 == strncmp(argv[i]+1,opt[o].cmdline,len) &&
- 0 == strncmp(argv[i]+1+len,"=",1)) {
+ } else if (opt[o].needsarg && lopt &&
+ 0 == strncmp(lopt,opt[o].cmdline,len) &&
+ 0 == strncmp(lopt+len,"=",1)) {
/* arg: -foo=bar */
cfg_set_str(opt[o].option.domain,
opt[o].option.section,
@@ -382,8 +428,8 @@ cfg_parse_cmdline(int *argc, char **argv, struct cfg_cmdline *opt)
argv[i]+2+len);
shift = 1;
- } else if (opt[o].value &&
- 0 == strcmp(argv[i]+1,opt[o].cmdline)) {
+ } else if (opt[o].value && lopt &&
+ 0 == strcmp(lopt,opt[o].cmdline)) {
/* -foo sets some fixed value */
cfg_set_str(opt[o].option.domain,
opt[o].option.section,
@@ -411,6 +457,12 @@ cfg_help_cmdline(struct cfg_cmdline *opt, int w1, int w2, int w3)
for (o = 0; opt[o].cmdline != NULL; o++) {
fprintf(stderr,"%*s",w1,"");
+ if (opt[o].letter) {
+ fprintf(stderr,"-%c ",opt[o].letter);
+ } else {
+ fprintf(stderr," ");
+ }
+
if (opt[o].yesno) {
len = fprintf(stderr,"-(no)%s ",opt[o].cmdline);
} else if (opt[o].needsarg) {
@@ -422,14 +474,16 @@ cfg_help_cmdline(struct cfg_cmdline *opt, int w1, int w2, int w3)
fprintf(stderr,"%*s",w2-len,"");
len = fprintf(stderr,"%s ",opt[o].desc);
- if (len < w3)
- fprintf(stderr,"%*s",w3-len,"");
-
- val = cfg_get_str(opt[o].option.domain,
- opt[o].option.section,
- opt[o].option.entry);
- if (val)
- fprintf(stderr,"[%s]",val);
+
+ if (w3) {
+ if (len < w3)
+ fprintf(stderr,"%*s",w3-len,"");
+ val = cfg_get_str(opt[o].option.domain,
+ opt[o].option.section,
+ opt[o].option.entry);
+ if (val)
+ fprintf(stderr,"[%s]",val);
+ }
fprintf(stderr,"\n");
}
}
@@ -780,13 +834,13 @@ cfg_get_signed_int(char *dname, char *sname, char *ename, unsigned int def)
}
float
-cfg_get_float(char *dname, char *sname, char *ename)
+cfg_get_float(char *dname, char *sname, char *ename, float def)
{
char *val;
val = cfg_get_str(dname,sname,ename);
if (NULL == val)
- return -1;
+ return def;
return atof(val);
}
diff --git a/parseconfig.h b/parseconfig.h
index 90abbfe..2908d9a 100644
--- a/parseconfig.h
+++ b/parseconfig.h
@@ -9,6 +9,7 @@ struct cfg_option {
char *entry;
};
struct cfg_cmdline {
+ char letter;
char *cmdline;
struct cfg_option option;
char *value;
@@ -56,7 +57,8 @@ int cfg_get_int(char *dname, char *sname, char *ename,
int def);
int cfg_get_signed_int(char *dname, char *sname, char *ename,
unsigned int def);
-float cfg_get_float(char *dname, char *sname, char *ename);
+float cfg_get_float(char *dname, char *sname, char *ename,
+ float def);
int cfg_get_bool(char *dname, char *sname, char *ename,
int def);