Changeset 1110


Ignore:
Timestamp:
02/12/10 14:18:16 (7 months ago)
Author:
mjona
Message:

Improved config behavior.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugin_fifo.c

    r1108 r1110  
    22 * $URL$ 
    33 * 
    4  * plugin template 
     4 * Fifo plugin 
    55 * 
    66 * Copyright (C) 2008 Michael Vogt <michu@neophob.com> 
     
    2626 */ 
    2727 
    28 /* define the include files you need */ 
     28/* 
     29 * Configuration parameters: 
     30 * 
     31 * - FifoPath 'string'  : use <string> as the fifo complete file path 
     32 *        If absent use  /tmp/lcd4linux.fifo) 
     33 * 
     34 * - FifoBufSize num  : if the plugin is unable to determine the display size then 
     35 *        set the size of the internal buffer to <num> characters 
     36 *        otherwise use the display size (number of columns). 
     37 *        If no display size is available and no FifoBufSize parameter 
     38  *       is specified then arbitrarily set the internal buffer size 
     39 *        to 80 characters. 
     40 */ 
     41 
    2942#include "config.h" 
    3043 
     
    3851#include <signal.h> 
    3952 
    40 /* these should always be included */ 
    4153#include "debug.h" 
    4254#include "plugin.h" 
     
    7991  path = cfg_get(fifosect, "FifoPath", string(FIFO_DEFAULT_PATH)); 
    8092  pathlen = strlen(path); 
     93  if (pathlen == 0) { 
     94    info("[FIFO] Invalid '%s.FifoPath' entry from '%s'. " 
     95      "Assuming "string(FIFO_DEFAULT_PATH), fifosect, cfg_source()); 
     96    free(path); 
     97    path = strdup(string(FIFO_DEFAULT_PATH)); 
     98    pathlen = strlen(path); 
     99  } 
    81100  if (pathlen > FIFO_MAXPATH) { 
    82101    error("[FIFO] Error: Too long '%s.FifoPath' entry from '%s'. " 
     
    89108  disp = cfg_get(NULL, "Display", NULL); 
    90109  if (disp == NULL) { 
    91     error("[FIFO] Error: Could not get the Display name from '%s'.", cfg_source()); 
     110    error("[FIFO] Error: Could not get the Display name from '%s'", cfg_source()); 
    92111    free(path); 
    93112    return (-1); 
     
    106125  disp = cfg_get(sect, "Size", NULL); 
    107126  if (disp != NULL) { 
    108     info("[FIFO] Getting the buffer size from '%s.Size'.", sect); 
    109     sscanf(disp, "%dx%*d", &p->msglen); 
     127    info("[FIFO] Getting the buffer size from '%s.Size'", sect); 
     128    if (sscanf(disp, "%dx%*d", &p->msglen) != 1) { 
     129      info("[FIFO] Could not determine the display size. " 
     130        "Assuming "string(FIFO_DEFAULT_BUFSIZE)); 
     131      p->msglen = FIFO_DEFAULT_BUFSIZE; 
     132    } 
     133    free(disp); 
    110134  } else { 
    111135    info("[FIFO] Could not find a '%s.Size' entry.", sect); 
    112136    if (cfg_number(fifosect, "FifoBufSize", FIFO_DEFAULT_BUFSIZE, 0, -1, &p->msglen) > 0) { 
    113       info("[FIFO] Getting the buffer size from '%s.FifoBufSize'.", fifosect); 
     137      info("[FIFO] Getting the buffer size from '%s.FifoBufSize'", fifosect); 
    114138    } else { 
    115139      info("[FIFO] Could not find a valid '%s.FifoBufSize' entry. " 
    116         "Assuming "string(FIFO_DEFAULT_BUFSIZE)".", fifosect); 
     140        "Assuming "string(FIFO_DEFAULT_BUFSIZE), fifosect); 
    117141      p->msglen = FIFO_DEFAULT_BUFSIZE; 
    118142    } 
     
    120144  info("[FIFO] Read buffer size is '%d'", p->msglen); 
    121145  free(sect); 
    122   free(disp); 
    123146 
    124147  if ((p->msg = malloc(2+pathlen+p->msglen)) == NULL) { 
Note: See TracChangeset for help on using the changeset viewer.