themerc.c: consistent indentation
This commit is contained in:
parent
373a362b01
commit
8bc640ded8
144
src/themerc.c
144
src/themerc.c
@ -18,88 +18,92 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
/* read contents of fname into gchar * */
|
/* read contents of fname into gchar * */
|
||||||
gchar **trc_open(gchar *fname) {
|
gchar **trc_open(gchar *fname)
|
||||||
gint fd;
|
{
|
||||||
struct stat fds;
|
gint fd;
|
||||||
ssize_t rb;
|
struct stat fds;
|
||||||
gchar *rc,**rcs;
|
ssize_t rb;
|
||||||
|
gchar *rc, **rcs;
|
||||||
|
|
||||||
if((fd=open(fname, O_RDONLY))==-1) {
|
if ((fd=open(fname, O_RDONLY)) == -1) {
|
||||||
fprintf(stderr, "%s: open() %s failed: %s\n", __FUNCTION__, fname, strerror(errno));
|
fprintf(stderr, "%s: open() %s failed: %s\n", __FUNCTION__, fname, strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if((fstat(fd, &fds))==-1) {
|
if ((fstat(fd, &fds)) == -1) {
|
||||||
close(fd);
|
close(fd);
|
||||||
fprintf(stderr, "%s: fstat() failed: %s\n", __FUNCTION__, strerror(errno));
|
fprintf(stderr, "%s: fstat() failed: %s\n", __FUNCTION__, strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(!(fds.st_size)) {
|
if (!(fds.st_size)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
fprintf(stderr, "%s: zero length file.\n", __FUNCTION__);
|
fprintf(stderr, "%s: zero length file.\n", __FUNCTION__);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(!(rc=malloc(fds.st_size+1))) {
|
if (!(rc=malloc(fds.st_size+1))) {
|
||||||
close(fd);
|
close(fd);
|
||||||
fprintf(stderr, "%s: malloc() failed: cannot alloc %d bytes\n", __FUNCTION__, (int)fds.st_size);
|
fprintf(stderr, "%s: malloc() failed: cannot alloc %d bytes\n", __FUNCTION__, (int)fds.st_size);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if((rb=read(fd, rc, fds.st_size))!=fds.st_size) {
|
if ((rb=read(fd, rc, fds.st_size)) != fds.st_size) {
|
||||||
free(rc);
|
free(rc);
|
||||||
close(fd);
|
close(fd);
|
||||||
if(rb==-1) {
|
if (rb == -1) {
|
||||||
fprintf(stderr, "%s: read() failed: %s\n", __FUNCTION__, strerror(errno));
|
fprintf(stderr, "%s: read() failed: %s\n", __FUNCTION__, strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: read() reads less bytes than expected =/\n", __FUNCTION__);
|
fprintf(stderr, "%s: read() reads less bytes than expected =/\n", __FUNCTION__);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
rc[fds.st_size]=0;
|
rc[fds.st_size]=0;
|
||||||
close(fd);
|
close(fd);
|
||||||
rcs=g_strsplit(rc, "\n", 0);
|
rcs=g_strsplit(rc, "\n", 0);
|
||||||
free(rc);
|
free(rc);
|
||||||
return rcs;
|
return rcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free rc... */
|
/* free rc... */
|
||||||
void trc_close(gchar **rcs) {
|
void trc_close(gchar **rcs) {
|
||||||
if(rcs) {
|
if (rcs) {
|
||||||
g_strfreev(rcs);
|
g_strfreev(rcs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return string value for given parameter. if not found retun NULL */
|
/* return string value for given parameter. if not found retun NULL */
|
||||||
gchar *trc_get_str(gchar **rcs, gchar *param) {
|
gchar *trc_get_str(gchar **rcs, gchar *param)
|
||||||
gint i;
|
{
|
||||||
gchar **strval,*val;
|
gint i;
|
||||||
|
gchar **strval,*val;
|
||||||
|
|
||||||
if(!rcs) {
|
if (!rcs) {
|
||||||
fprintf(stderr, "%s called with uninitialised rcs. strange. \n", __FUNCTION__);
|
fprintf(stderr, "%s called with uninitialised rcs. strange. \n", __FUNCTION__);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(!param) {
|
if (!param) {
|
||||||
fprintf(stderr, "%s called with NULL param. strange. \n", __FUNCTION__);
|
fprintf(stderr, "%s called with NULL param. strange. \n", __FUNCTION__);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for(i=0;rcs[i];i++) {
|
for (i=0;rcs[i];i++) {
|
||||||
if(rcs[i][0] && rcs[i][0]!='#' && (strval=g_strsplit(rcs[i],"=",2)) && strval[0] && strval[1]) {
|
if (rcs[i][0] && rcs[i][0]!='#' && (strval=g_strsplit(rcs[i],"=",2)) && strval[0] && strval[1]) {
|
||||||
if(!(strcmp(g_strstrip(strval[0]),param))) {
|
if (!(strcmp(g_strstrip(strval[0]),param))) {
|
||||||
val=g_strdup(g_strstrip(strval[1]));
|
val=g_strdup(g_strstrip(strval[1]));
|
||||||
g_strfreev(strval);
|
g_strfreev(strval);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
g_strfreev(strval);
|
g_strfreev(strval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return unsigned integer value for given parameter. if not found retun -1 */
|
/* return unsigned integer value for given parameter. if not found retun -1 */
|
||||||
gint trc_get_uint(gchar **rcs, gchar *param) {
|
gint trc_get_uint(gchar **rcs, gchar *param) {
|
||||||
gchar *val;
|
gchar *val;
|
||||||
gint ret;
|
gint ret;
|
||||||
|
|
||||||
if(!(val=trc_get_str(rcs, param))) return -1;
|
if (!(val=trc_get_str(rcs, param))) {
|
||||||
ret=atoi(val);
|
return -1;
|
||||||
g_free(val);
|
}
|
||||||
return ret;
|
ret = atoi(val);
|
||||||
|
g_free (val);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user