File: key_settings.c

package info (click to toggle)
keytouch 2.2.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,212 kB
  • ctags: 1,399
  • sloc: ansic: 9,195; sh: 3,630; makefile: 399
file content (119 lines) | stat: -rw-r--r-- 3,546 bytes parent folder | download | duplicates (3)
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
/*---------------------------------------------------------------------------------
Name               : key_settings.c
Author             : Marvin Raaijmakers
Description        : Performs action for the KTKeySettingsList
Date of last change: 20-Aug-2005

    Copyright (C) 2005 Marvin Raaijmakers

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

    You can contact me at: marvinr(at)users(dot)sf(dot)net
    (replace (at) by @ and (dot) by .)
-----------------------------------------------------------------------------------*/
#include <string.h>

#include <mxml.h>
#include <keytouchd.h>

KTKeySettings
*find_key_settings (	char			*key_name,
			KTKeySettingsList	*key_list  )
/*
Input:
	key_name	- The name of the key to get the key settings from.
	key_list	- The list to search in for the key setting.
Output:
	-
Returns:
	A pointer to the key settings of the key that has the name key_name. If no
	such key settings exist, NULL is returned.
Description:
	This function searches in key_list the key settings of the key that has
	the name key_name.
*/
{
	KTKeySettings *key_settings;
	
	for (key_settings = key_list->head;
	      key_settings != NULL &&
	      strcmp(key_settings->key_name, key_name) != EQUAL;
	     key_settings = key_settings->next)
		; /* NULL Statement */
	return (key_settings);
}

KTKeySettings
*key_settings_of_keycode (	unsigned int		keycode,
				KTKeySettingsList	*key_list  )
/*
Input:
	keycode		- The keycode of the key to get the key settings from.
	key_list	- The list to search in for the key setting.
Output:
	-
Returns:
	A pointer to the key settings of the key that has keycode 'keycode'. If no
	such key settings exist, NULL is returned.
Description:
	This function searches in key_list the key settings of the key that has
	keycode 'keycode'.
*/
{
	KTKeySettings *key_settings;
	
	for (key_settings = key_list->head;
	     key_settings != NULL && key_settings->keycode != keycode;
	     key_settings = key_settings->next)
		; /* NULL Statement */
	return (key_settings);
}

void
clear_key_settings_list (KTKeySettingsList *key_list)
/*
Input:
	key_list	- The key settings list to clear
Output:
	key_list	- The cleared key settings list
Returns:
	-
Description:
	This function clears key_list.
*/
{
	KTKeySettings	*key_settings,
			*next;
	
	for (key_settings = key_list->head;
	     key_settings != NULL;
	     key_settings = next)
	{
		next = key_settings->next;
		/* Because key_settings->key_name was read with XmlGetElementString()
		 * we should free it with XmlFree()
		 */
		XmlFree (key_settings->key_name);
		if (key_settings->action.type == KTActionTypeProgram)
		{
			/* Because key_settings->action.program.command was read with
			 * XmlGetElementString() we should free it with XmlFree()
			 */
			XmlFree (key_settings->action.program.command);
		}
		free (key_settings);
	}
	key_list->head = key_list->tail = NULL;
}