mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	rc.xml: move nodename() to nodename.c
This commit is contained in:
		
							parent
							
								
									a97428020e
								
							
						
					
					
						commit
						9eac349046
					
				
					 4 changed files with 58 additions and 34 deletions
				
			
		
							
								
								
									
										19
									
								
								include/common/nodename.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								include/common/nodename.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,19 @@
 | 
				
			||||||
 | 
					#ifndef __LABWC_NODENAME_H
 | 
				
			||||||
 | 
					#define __LABWC_NODENAME_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <libxml/parser.h>
 | 
				
			||||||
 | 
					#include <libxml/tree.h>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * nodename - give xml node an ascii name
 | 
				
			||||||
 | 
					 * @node: xml-node
 | 
				
			||||||
 | 
					 * @buf: buffer to receive the name
 | 
				
			||||||
 | 
					 * @len: size of buffer
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For example, the xml structure <a><b><c></c></b></a> would return the
 | 
				
			||||||
 | 
					 * name c.b.a
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					char *nodename(xmlNode *node, char *buf, int len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* __LABWC_NODENAME_H */
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ labwc_sources += files(
 | 
				
			||||||
  'font.c',
 | 
					  'font.c',
 | 
				
			||||||
  'grab-file.c',
 | 
					  'grab-file.c',
 | 
				
			||||||
  'log.c',
 | 
					  'log.c',
 | 
				
			||||||
 | 
					  'nodename.c',
 | 
				
			||||||
  'spawn.c',
 | 
					  'spawn.c',
 | 
				
			||||||
  'string-helpers.c',
 | 
					  'string-helpers.c',
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										37
									
								
								src/common/nodename.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/common/nodename.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,37 @@
 | 
				
			||||||
 | 
					#include <ctype.h>
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include "common/nodename.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *
 | 
				
			||||||
 | 
					nodename(xmlNode *node, char *buf, int len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!node || !node->name) {
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Ignore superflous 'text.' in node name */
 | 
				
			||||||
 | 
						if (node->parent && !strcmp((char *)node->name, "text")) {
 | 
				
			||||||
 | 
							node = node->parent;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						char *p = buf;
 | 
				
			||||||
 | 
						p[--len] = 0;
 | 
				
			||||||
 | 
						for (;;) {
 | 
				
			||||||
 | 
							const char *name = (char *)node->name;
 | 
				
			||||||
 | 
							char c;
 | 
				
			||||||
 | 
							while ((c = *name++) != 0) {
 | 
				
			||||||
 | 
								*p++ = tolower(c);
 | 
				
			||||||
 | 
								if (!--len)
 | 
				
			||||||
 | 
									return buf;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							*p = 0;
 | 
				
			||||||
 | 
							node = node->parent;
 | 
				
			||||||
 | 
							if (!node || !node->name) {
 | 
				
			||||||
 | 
								return buf;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							*p++ = '.';
 | 
				
			||||||
 | 
							if (!--len) {
 | 
				
			||||||
 | 
								return buf;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -14,6 +14,7 @@
 | 
				
			||||||
#include "common/dir.h"
 | 
					#include "common/dir.h"
 | 
				
			||||||
#include "common/font.h"
 | 
					#include "common/font.h"
 | 
				
			||||||
#include "common/log.h"
 | 
					#include "common/log.h"
 | 
				
			||||||
 | 
					#include "common/nodename.h"
 | 
				
			||||||
#include "common/string-helpers.h"
 | 
					#include "common/string-helpers.h"
 | 
				
			||||||
#include "config/keybind.h"
 | 
					#include "config/keybind.h"
 | 
				
			||||||
#include "config/rcxml.h"
 | 
					#include "config/rcxml.h"
 | 
				
			||||||
| 
						 | 
					@ -146,40 +147,6 @@ entry(xmlNode *node, char *nodename, char *content)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static char *
 | 
					 | 
				
			||||||
nodename(xmlNode *node, char *buf, int len)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	if (!node || !node->name) {
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Ignore superflous 'text.' in node name */
 | 
					 | 
				
			||||||
	if (node->parent && !strcmp((char *)node->name, "text")) {
 | 
					 | 
				
			||||||
		node = node->parent;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	char *p = buf;
 | 
					 | 
				
			||||||
	p[--len] = 0;
 | 
					 | 
				
			||||||
	for (;;) {
 | 
					 | 
				
			||||||
		const char *name = (char *)node->name;
 | 
					 | 
				
			||||||
		char c;
 | 
					 | 
				
			||||||
		while ((c = *name++) != 0) {
 | 
					 | 
				
			||||||
			*p++ = tolower(c);
 | 
					 | 
				
			||||||
			if (!--len)
 | 
					 | 
				
			||||||
				return buf;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		*p = 0;
 | 
					 | 
				
			||||||
		node = node->parent;
 | 
					 | 
				
			||||||
		if (!node || !node->name) {
 | 
					 | 
				
			||||||
			return buf;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		*p++ = '.';
 | 
					 | 
				
			||||||
		if (!--len) {
 | 
					 | 
				
			||||||
			return buf;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
process_node(xmlNode *node)
 | 
					process_node(xmlNode *node)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue