1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 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
|
/*
* telak - A program that display pictures in root window
* (c) 2005 - Julien Danjou <julien@danjou.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <time.h>
#include <sys/time.h>
#include "telak.h"
#include "image.h"
#define BUF_SIZE 4096
extern struct config conf;
struct deskitem *
init_deskitem(struct deskitem * img)
{
img->url = NULL;
img->x = 0;
img->y = 0;
img->w = 0;
img->h = 0;
img->loaded = 0;
img->refresh = 0;
img->reverse = 0;
return img;
}
void
parse()
{
FILE *rcfile;
char buf[BUF_SIZE];
struct deskitem img;
int new = 0;
init_deskitem(&img);
/* Now parse rcfile */
rcfile = fopen(conf.file, "r");
if(!rcfile)
{
perror("Error opening configuration file");
exit(EXIT_FAILURE);
}
while(fgets(buf, BUF_SIZE, rcfile))
{
/* Skip comments */
if(buf[0] == '#')
continue;
/* New entry */
if(buf[0] == '[')
{
printf("Parsing %s", buf);
/* Load img in list */
if(new && img.url)
load(&img);
else if(new && !img.url)
{
fprintf(stderr, "Error: at least one of your pictures does not have an URL.\n");
exit(EXIT_FAILURE);
}
else
new = 1;
/* Reinit img */
init_deskitem(&img);
}
if(!strncmp(buf, "url", 3) && new)
{
img.url = (char *) malloc(sizeof(char) * strlen(buf));
sscanf(buf, "%*s = %s", img.url);
continue;
}
if(!strncmp(buf, "height", 6) && new)
{
sscanf(buf, "%*s = %d", &img.h);
continue;
}
if(!strncmp(buf, "width", 5) && new)
{
sscanf(buf, "%*s = %d", &img.w);
continue;
}
if(!strncmp(buf, "x", 1) && new)
{
sscanf(buf, "%*s = %d", &img.x);
continue;
}
if(!strncmp(buf, "y", 1) && new)
{
sscanf(buf, "%*s = %d", &img.y);
continue;
}
if(!strncmp(buf, "refresh", 7) && new)
{
sscanf(buf, "%*s = %d", &img.refresh);
continue;
}
if(!strncmp(buf, "reverse", 7) && new)
{
sscanf(buf, "%*s = %d", &img.reverse);
continue;
}
}
fclose(rcfile);
/* Load last img in list */
if(new && img.url)
load(&img);
else if(new && !img.url)
{
fprintf(stderr, "Error: at least one of your pictures does not have an URL.\n");
exit(EXIT_FAILURE);
}
if(!new)
{
fprintf(stderr, "Fatal error: config file is not valid.\n");
exit(EXIT_FAILURE);
}
}
|