/* $Id: mail.c,v 1.12 2003/02/22 07:53:10 reinelt Exp $ * * email specific functions * * Copyright 2001 by Axel Ehnert * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * * $Log: mail.c,v $ * Revision 1.12 2003/02/22 07:53:10 reinelt * cfg_get(key,defval) * * Revision 1.11 2001/09/12 05:58:16 reinelt * fixed bug in mail2.c * * Revision 1.10 2001/09/12 05:37:22 reinelt * * fixed a bug in seti.c (file was never closed, lcd4linux run out of fd's * * improved socket debugging * * Revision 1.9 2001/08/05 17:13:29 reinelt * * cleaned up inlude of sys/time.h and time.h * * Revision 1.8 2001/03/15 15:49:23 ltoetsch * fixed compile HD44780.c, cosmetics * * Revision 1.7 2001/03/15 14:25:05 ltoetsch * added unread/total news * * Revision 1.6 2001/03/14 13:19:29 ltoetsch * Added pop3/imap4 mail support * * Revision 1.5 2001/03/13 08:34:15 reinelt * * corrected a off-by-one bug with sensors * * Revision 1.4 2001/03/08 09:02:04 reinelt * * seti client cleanup * * Revision 1.3 2001/02/21 04:48:13 reinelt * * big mailbox patch from Axel Ehnert * thanks to herp for his idea to check mtime of mailbox * * Revision 1.2 2001/02/19 00:15:46 reinelt * * integrated mail and seti client * major rewrite of parser and tokenizer to support double-byte tokens * * Revision 1.1 2001/02/18 22:11:34 reinelt * *** empty log message *** * */ /* * exported functions: * * Mail (int index, int *num) * returns 0 if ok, -1 if error * sets num to number of emails in mailbox #index * */ #define FALSE 0 #define TRUE 1 #include #include #include #include #include #include #include #include #include #include "cfg.h" #include "debug.h" #include "mail.h" int Mail (int index, int *num, int *unseen) { FILE *fstr; char buffer[32]; static int cfgmbx[MAILBOXES+1]={[0 ... MAILBOXES]=TRUE,}; // Mailbox #index configured? static time_t mbxlt[MAILBOXES+1]={[0 ... MAILBOXES]=0,}; // mtime of Mailbox #index static int mbxnum[MAILBOXES+1]={[0 ... MAILBOXES]=0,}; // Last calculated # of mails static time_t now[MAILBOXES+1]={[0 ... MAILBOXES]=0,}; // Last call to procedure at // for Mailbox #index char *fnp1; int v1=0; int last_line_blank1; // Was the last line blank? struct stat fst; int rc; char *txt; char txt1[100]; if (index<0 || index>MAILBOXES) return -1; if (now[index] == 0) { /* first time, to give faster a chance */ now[index] = -1-index; return 0; } if (now[index] < -1) { /* wait different time to avoid long startup */ now[index]++; return 0; } if (now[index] > 0) { /* not first time, delay */ sprintf(txt1, "Delay_e%d", index); if (time(NULL)<=now[index]+atoi(cfg_get(txt1,"5"))) return 0; // no more then 5/Delay_eX seconds after last check? } time(&now[index]); // for Mailbox #index /* Build the filename from the config */ snprintf(buffer, sizeof(buffer), "Mailbox%d", index); fnp1=cfg_get(buffer,NULL); if (fnp1==NULL || *fnp1=='\0') { cfgmbx[index]=FALSE; // There is now entry for Mailbox #index } v1=mbxnum[index]; /* Open the file */ if (cfgmbx[index]==TRUE) { /* Check the last touch of mailbox. Changed? */ rc=stat(fnp1, &fst); if ( rc != 0 ) { /* is it pop3, imap4 or nntp? */ rc = Mail_pop_imap_news(fnp1, num, unseen); if (rc == 0) return 0; else cfgmbx[index] = FALSE; /* don't try again */ error ("Error getting stat of Mailbox%d", index); return (-1); } if ( mbxlt[index] != fst.st_mtime ) { mbxlt[index]=fst.st_mtime; fstr=fopen(fnp1,"r"); if (fstr != NULL) { txt=&txt1[0]; last_line_blank1=TRUE; v1=0; while ( ( fgets ( txt1, 100, fstr ) ) != NULL ) { txt1[strlen(txt1)-1]='\0'; // cut the newline /* Is there a "From ..." line. Count only, if a blank line was directly before this */ if ( strncmp (txt1, "From ", 5 ) == 0 ) { if ( last_line_blank1 == TRUE ) { v1++; last_line_blank1 = FALSE; } } if ( strlen (txt1) == 0 ) { last_line_blank1 = TRUE; } else { last_line_blank1 = FALSE; } } fclose (fstr); } } } /* FIXME look at the Status of Mails */ *unseen = v1 - mbxnum[index]; if (*unseen < 0) *unseen = 0; mbxnum[index]=v1; *num=v1; return (0); } 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
/* $Id: layout.c,v 1.14 2004/06/26 12:04:59 reinelt Exp $
 *
 * new layouter framework
 *
 * Copyright 1999-2003 Michael Reinelt <reinelt@eunet.at>
 * Copyright 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
 *
 * This file is part of LCD4Linux.
 *
 * LCD4Linux is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * LCD4Linux is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *
 * $Log: layout.c,v $
 * Revision 1.14  2004/06/26 12:04:59  reinelt
 *
 * uh-oh... the last CVS log message messed up things a lot...
 *
 * Revision 1.13  2004/06/26 09:27:21  reinelt
 *
 * added '-W' to CFLAGS
 * changed all C++ comments to C ones
 * cleaned up a lot of signed/unsigned mistakes
 *
 * Revision 1.12  2004/06/20 10:09:56  reinelt
 *
 * 'const'ified the whole source
 *
 * Revision 1.11  2004/06/02 09:41:19  reinelt
 *
 * prepared support for startup splash screen
 *
 * Revision 1.10  2004/03/03 03:47:04  reinelt
 * big patch from Martin Hejl:
 * - use qprintf() where appropriate
 * - save CPU cycles on gettimeofday()
 * - add quit() functions to free allocated memory
 * - fixed lots of memory leaks
 *
 * Revision 1.9  2004/02/01 19:37:40  reinelt
 * got rid of every strtok() incarnation.
 *
 * Revision 1.8  2004/02/01 18:08:50  reinelt
 * removed strtok() from layout processing (took me hours to find this bug)
 * further strtok() removind should be done!
 *
 * Revision 1.7  2004/01/30 20:57:56  reinelt
 * HD44780 patch from Martin Hejl
 * dmalloc integrated
 *
 * Revision 1.6  2004/01/14 11:33:00  reinelt
 * new plugin 'uname' which does what it's called
 * text widget nearly finished
 * first results displayed on MatrixOrbital
 *
 * Revision 1.5  2004/01/13 08:18:19  reinelt
 * timer queues added
 * liblcd4linux deactivated turing transformation to new layout
 *
 * Revision 1.4  2004/01/12 03:51:01  reinelt
 * evaluating the 'Variables' section in the config file
 *
 * Revision 1.3  2004/01/11 18:26:02  reinelt
 * further widget and layout processing
 *
 * Revision 1.2  2004/01/11 09:26:15  reinelt
 * layout starts to exist...
 *
 * Revision 1.1  2004/01/10 20:22:33  reinelt
 * added new function 'cfg_list()' (not finished yet)
 * added layout.c (will replace processor.c someday)
 * added widget_text.c (will be the first and most important widget)
 * modified lcd4linux.c so that old-style configs should work, too
 *
 */

/* 
 * exported functions:
 *
 * layout_init (char *section)
 *    initializes the layouter
 *
 */

#include "config.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include "debug.h"
#include "cfg.h"
#include "widget.h"
#include "layout.h"

#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif


int layout_addItem (const char *name, const int row, const int col)
{
  /* allocate widget */
  widget_add (name, row-1, col-1);
  return 0;
}


int layout_init (const char *layout)
{
  char *section;
  char *list, *l;
  char *widget;
  int row, col;
  
  info ("initializing layout '%s'", layout);
  
  /* prepare config section */
  /* strlen("Layout:")=7 */
  section=malloc(strlen(layout)+8);
  strcpy(section, "Layout:");
  strcat(section, layout);
  
  /* get a list of all keys in this section */
  list=cfg_list(section);

  /* map to lower char for scanf() */
  for (l=list; *l!='\0'; l++) *l=tolower(*l);

  l=list;
  while (l!=NULL) {
    char *p;
    int i, n;
    /* list is delimited by | */
    while (*l=='|') l++;
    if ((p=strchr(l, '|'))!=NULL) *p='\0';
    i=sscanf (l, "row%d.col%d%n", &row, &col, &n);
    if (i==2 && l[n]=='\0') {
      widget=cfg_get(section, l, NULL);
      if (widget!=NULL && *widget!='\0') {
        layout_addItem (widget, row, col);
      }
      free(widget);
    }
    /* next field */
    l=p?p+1:NULL;
  }
  free (list);
  free(section);
  return 0;
}