socsvn commit: r268579 - soc2014/seiya/bootsplash/sys/dev/fb
seiya at FreeBSD.org
seiya at FreeBSD.org
Sun May 25 09:18:50 UTC 2014
Author: seiya
Date: Sun May 25 09:18:49 2014
New Revision: 268579
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=268579
Log:
implement config parser
Modified:
soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c
Modified: soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c
==============================================================================
--- soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c Sun May 25 08:09:55 2014 (r268578)
+++ soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c Sun May 25 09:18:49 2014 (r268579)
@@ -32,38 +32,149 @@
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/linker.h>
+#include <sys/libkern.h>
+#include <sys/malloc.h>
+
+MALLOC_DEFINE(M_BSPLASH, "bsplash", "Buffers to store configuration");
+
+enum config_keys {
+ CONF_FULLSCREEN_FIRST_IMAGE = 0,
+ CONF_FULLSCREEN_AMINATION_IMAGES = 1,
+ CONF_ANIMATION_FPS = 2,
+ CONF_NUM = 3
+};
+
+#define CONF_VAL_MAX 256
+
+static char *config [CONF_NUM];
static int load_config(void)
{
caddr_t conf;
- char* ptr;
+ char *ptr;
+ char *key;
+ char *val;
+ int line;
conf = preload_search_by_type("bsplash_conf");
- if(conf == NULL)
+ if(conf == NULL) {
+ printf("bsplash: failed to load bootsplash configuration\n");
return -1;
+ }
ptr = preload_fetch_addr(conf);
- printf("bsplash conf: ");
- /* parse config file */
- while(*ptr){
- printf("%c", *ptr);
- ptr++;
+ for(int i=0; i < CONF_NUM; i++) {
+ if((config[i] = malloc(CONF_VAL_MAX, M_BSPLASH, M_NOWAIT)) == NULL) {
+ printf("bsplash: malloc() returned NULL, aborted\n");
+ return -1;
+ }
+ }
+
+ /*
+ * parse config file
+ */
+ for(line = 1; *ptr; line++) {
+ /* skip whitespaces / tabs */
+ while(*ptr && (*ptr == ' ' || *ptr == '\t'))
+ ptr++;
+ if(*ptr == '\0')
+ break;
+
+ if(*ptr != '\n' && *ptr != '#') {
+ /*
+ * parse a line
+ */
+
+ key = ptr;
+ while(*ptr && *ptr != '=')
+ ptr++;
+ /* '=' not found */
+ if(*ptr == '\0')
+ goto parse_error;
+
+ *ptr = '\0'; /* '=' -> '\0' */
+ val = ++ptr;
+
+ /* '\n' -> '\0' */
+ while(*ptr && *ptr != '\n')
+ ptr++;
+ if(*ptr){
+ *ptr = '\0';
+ ptr++;
+ }
+
+ if(*val == '\0' || val[0] != '"' || val[strlen(val)-1] != '"')
+ goto parse_error;
+
+ /* FIXME: ignore if `val' is too long */
+ if(strlen(val) > CONF_VAL_MAX){
+ printf("bsplash: line %d is too long, ignored\n", line);
+ }else{
+
+ /*
+ * save config
+ */
+ if(!strcmp(key, "fullscreen_first_image")) {
+ strcpy(config[CONF_FULLSCREEN_FIRST_IMAGE], val);
+ }else if(!strcmp(key, "fullscreen_animation_images")) {
+ strcpy(config[CONF_FULLSCREEN_AMINATION_IMAGES], val);
+ }else if(!strcmp(key, "animation_fps")) {
+ strcpy(config[CONF_ANIMATION_FPS], val);
+ }else{
+ printf("bsplash: unknown configuration '%s', ignored\n", key);
+ }
+ }
+
+ /* in comment line or blank line */
+ }else{
+ /* skip this line */
+ while(*ptr && *ptr != '\n')
+ ptr++;
+ if(*ptr)
+ ptr++;
+ }
}
- printf("\n");
return 0;
+
+ parse_error:
+ printf("bsplash: configuration parse error at line %d\n", line);
+ return -1;
+}
+
+
+/*
+ * Load configuration and draw image before kernel thread mechanism is activated.
+ */
+static void bsplash_early_init (void){
+
+ for(int i=0; i < CONF_NUM; i++)
+ config[i] = NULL;
+
+ load_config();
}
+
+static void bsplash_uninit (void){
+
+ for(int i=0; i < CONF_NUM; i++) {
+ if(config[i])
+ free(config[i], M_BSPLASH);
+ }
+}
+
+
static int modevent(module_t mod, int type, void *data)
{
printf("bsplash: hello world!\n");
switch ((modeventtype_t)type) {
case MOD_LOAD:
- load_config();
+ bsplash_early_init();
break;
case MOD_UNLOAD:
+ bsplash_uninit();
break;
default:
return EOPNOTSUPP;
@@ -79,3 +190,4 @@
};
DECLARE_MODULE(bsplash, bsplash_mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
+
More information about the svn-soc-all
mailing list