From owner-svn-soc-all@FreeBSD.ORG Sun May 25 09:18:50 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6DF7C271 for ; Sun, 25 May 2014 09:18:50 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5A4DF2DDB for ; Sun, 25 May 2014 09:18:50 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4P9IoOY090520 for ; Sun, 25 May 2014 09:18:50 GMT (envelope-from seiya@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s4P9InvH090294 for svn-soc-all@FreeBSD.org; Sun, 25 May 2014 09:18:49 GMT (envelope-from seiya@FreeBSD.org) Date: Sun, 25 May 2014 09:18:49 GMT Message-Id: <201405250918.s4P9InvH090294@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to seiya@FreeBSD.org using -f From: seiya@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r268579 - soc2014/seiya/bootsplash/sys/dev/fb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 May 2014 09:18:50 -0000 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 #include #include +#include +#include + +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); +