aboutsummaryrefslogtreecommitdiff
path: root/backends/PalmOS/Src/args.cpp
blob: d05f509daeeaa10dc469bc765bb79a37c86397c3 (plain)
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
#include <PalmOS.h>
#include "args.h"

Char **ArgsInit() {
	MemHandle argvH = MemHandleNew(MAX_ARG * sizeof(Char *));
	Char **argvP = (Char **)MemHandleLock(argvH);

	for(UInt8 count = 0; count < MAX_ARG; count++)
		argvP[count] = NULL;

	return argvP;
}

void ArgsAdd(Char **argvP, const Char *argP, const Char *parmP, UInt8 *countArgP) {
	if (argP) {
		MemHandle newArg;
		UInt16 len2 = 0;
		UInt16 len1 = StrLen(argP);

		if (len1 > 0) {
			if (parmP)
				len2 = StrLen(parmP);

			(*countArgP)++;
			newArg = MemHandleNew(len1 + len2 + 1); // +1 = NULL CHAR
			*argvP = (Char *)MemHandleLock(newArg);
			StrCopy(*argvP, argP);

			if (parmP)
				StrCat(*argvP, parmP);
		}
	}
}

void ArgsFree(Char **argvP) {
	if (!argvP)
		return;

	MemHandle oldH;

	for(UInt8 count = 0; count < MAX_ARG; count++)
		if (argvP[count]) {
			oldH = MemPtrRecoverHandle(argvP[count]);
			MemHandleUnlock(oldH);
			MemHandleFree(oldH);
		}

	oldH = MemPtrRecoverHandle(argvP);
	MemHandleUnlock(oldH);
	MemHandleFree(oldH);
}

void ArgsSetOwner(Char **argvP, UInt16 owner) {
	if (!argvP)
		return;

	MemHandle oldH;

	for(UInt8 count = 0; count < MAX_ARG; count++)
		if (argvP[count]) {
			oldH = MemPtrRecoverHandle(argvP[count]);
			MemHandleSetOwner(oldH, owner);
//			MemPtrSetOwner(argvP[count], 0);
		}

	oldH = MemPtrRecoverHandle(argvP);
	MemHandleSetOwner(oldH, owner);
//	MemPtrSetOwner(argvP, 0);
}