mash/xutil.c

Sun, 31 Aug 2014 17:51:04 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 31 Aug 2014 17:51:04 +0200
changeset 272
f436d826de4b
parent 103
99c47a8a61cb
permissions
-rw-r--r--

Added Heater and Cooler delay edit fields. Added more checks on entered data in the units edit screen.

103
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2008-2014
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with EC-65K; see the file COPYING. If not, write to the Free
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 #include "mash.h"
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 #include "xutil.h"
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 char *xmalloc(size_t size)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 char *tmp;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 tmp = malloc(size);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 if (!tmp)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 abort();
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 return tmp;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 char *xstrcpy(char *src)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 char *tmp;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 if (src == NULL)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 return(NULL);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 tmp = xmalloc(strlen(src)+1);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 strcpy(tmp, src);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 return tmp;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 char *xstrcat(char *src, char *add)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 char *tmp;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 size_t size = 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 if ((add == NULL) || (strlen(add) == 0))
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 return src;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 if (src)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 size = strlen(src);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 size += strlen(add);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 tmp = xmalloc(size + 1);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 *tmp = '\0';
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 if (src) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 strcpy(tmp, src);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 free(src);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 strcat(tmp, add);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 return tmp;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73

mercurial