3 * Copyright (C) 1998-2001 A.J. van Os; Released under GPL
6 * Try to force a single startup of !Antiword
19 #if !defined(TaskManager_EnumerateTasks)
20 #define TaskManager_EnumerateTasks 0x042681
21 #endif /* TaskManager_EnumerateTasks */
24 * bIsMatch - decide whether the two strings match
26 * like strcmp, but this one ignores case
29 bIsMatch(const char *szStr1
, const char *szStr2
)
31 const char *pcTmp1
, *pcTmp2
;
33 for (pcTmp1
= szStr1
, pcTmp2
= szStr2
;
36 if (toupper(*pcTmp1
) != toupper(*pcTmp2
)) {
40 return *pcTmp2
== '\0';
41 } /* end of bIsMatch */
44 * tGetTaskHandle - get the task handle of the given task
46 * returns the task handle when found, otherwise 0
49 tGetTaskHandle(const char *szTaskname
, int iOSVersion
)
51 _kernel_swi_regs regs
;
58 if (iOSVersion
< 310) {
60 * SWI TaskManager_EnumerateTasks does not
61 * exist in earlier versions of RISC OS
66 (void)memset((void *)®s
, 0, sizeof(regs
));
70 /* Get info on the next task */
71 regs
.r
[1] = (int)aiBuffer
;
72 regs
.r
[2] = sizeof(aiBuffer
);
73 e
= _kernel_swi(TaskManager_EnumerateTasks
, ®s
, ®s
);
75 werr(1, "TaskManager_EnumerateTasks error %d: %s",
76 e
->errnum
, e
->errmess
);
79 /* Copy the (control character terminated) task name */
80 for (iIndex
= 0, pcTmp
= (const char *)aiBuffer
[1];
81 iIndex
< elementsof(szTmp
);
83 if (iscntrl(*pcTmp
)) {
87 szTmp
[iIndex
] = *pcTmp
;
89 szTmp
[elementsof(szTmp
) - 1] = '\0';
90 if (bIsMatch(szTmp
, szTaskname
)) {
92 return (wimp_t
)aiBuffer
[0];
94 } while (regs
.r
[0] >= 0);
98 } /* end of tGetTaskHandle */
101 main(int argc
, char **argv
)
109 iVersion
= wimpt_init("StartUp");
112 tArgLen
= strlen(argv
[1]);
116 if (tArgLen
>= sizeof(tMsg
.data
.dataload
.name
)) {
117 werr(1, "Input filename too long");
121 tTaskHandle
= tGetTaskHandle("antiword", iVersion
);
123 if (tTaskHandle
== 0) {
124 /* Antiword is not active */
125 strcpy(szCommand
, "chain:<Antiword$Dir>.!Antiword");
127 strcat(szCommand
, " ");
128 strcat(szCommand
, argv
[1]);
131 strcat(szCommand
, " ");
132 strcat(szCommand
, "2><Antiword$Dir>.Debug");
135 /* If we reach here something has gone wrong */
139 /* Antiword is active */
141 /* Send the argument to Antiword */
142 tMsg
.hdr
.size
= ROUND4(sizeof(tMsg
) -
143 sizeof(tMsg
.data
.dataload
.name
) +
145 tMsg
.hdr
.your_ref
= 0;
146 tMsg
.hdr
.action
= wimp_MDATALOAD
;
147 tMsg
.data
.dataload
.w
= -1;
148 tMsg
.data
.dataload
.size
= 0;
149 tMsg
.data
.dataload
.type
= FILETYPE_MSWORD
;
150 strcpy(tMsg
.data
.dataload
.name
, argv
[1]);
151 wimpt_noerr(wimp_sendmessage(wimp_ESEND
,
152 &tMsg
, tTaskHandle
));
155 /* Give an error message and return */
156 werr(1, "Antiword is already running");