3 * Copyright (C) 1998-2001 A.J. van Os; Released under GPL
6 * Try to force a single startup of !Antiword
12 #include "DeskLib:Error.h"
13 #include "DeskLib:Event.h"
14 #include "DeskLib:SWI.h"
18 #if !defined(TaskManager_EnumerateTasks)
19 #define TaskManager_EnumerateTasks 0x042681
20 #endif /* TaskManager_EnumerateTasks */
23 * bIsMatch - decide whether the two strings match
25 * like strcmp, but this one ignores case
28 bIsMatch(const char *szStr1
, const char *szStr2
)
30 const char *pcTmp1
, *pcTmp2
;
32 for (pcTmp1
= szStr1
, pcTmp2
= szStr2
;
35 if (toupper(*pcTmp1
) != toupper(*pcTmp2
)) {
39 return *pcTmp2
== '\0';
40 } /* end of bIsMatch */
43 * tGetTaskHandle - get the task handle of the given task
45 * returns the task handle when found, otherwise 0
48 tGetTaskHandle(const char *szTaskname
)
57 /* Get info on the next task */
58 Error_CheckFatal(SWI(3, 1, TaskManager_EnumerateTasks
| XOS_Bit
,
59 iReg0
, aiBuffer
, sizeof(aiBuffer
), &iReg0
));
60 /* Copy the (control character terminated) task name */
61 for (iIndex
= 0, pcTmp
= (const char *)aiBuffer
[1];
62 iIndex
< elementsof(szTmp
);
64 if (iscntrl(*pcTmp
)) {
68 szTmp
[iIndex
] = *pcTmp
;
70 szTmp
[elementsof(szTmp
) - 1] = '\0';
71 if (bIsMatch(szTmp
, szTaskname
)) {
73 return (task_handle
)aiBuffer
[0];
79 } /* end of tGetTaskHandle */
82 main(int argc
, char **argv
)
85 task_handle tTaskHandle
;
87 int aiMessages
[] = {0};
90 Event_Initialise3("StartUp", 310, aiMessages
);
93 tArgLen
= strlen(argv
[1]);
97 if (tArgLen
>= sizeof(tMsg
.data
.dataload
.filename
)) {
98 werr(1, "Input filename too long");
102 tTaskHandle
= tGetTaskHandle("antiword");
104 if (tTaskHandle
== 0) {
105 /* Antiword is not active */
106 strcpy(szCommand
, "chain:<Antiword$Dir>.!Antiword");
108 strcat(szCommand
, " ");
109 strcat(szCommand
, argv
[1]);
112 strcat(szCommand
, " ");
113 strcat(szCommand
, "2><Antiword$Dir>.Debug");
116 /* If we reach here something has gone wrong */
120 /* Antiword is active */
123 * Send the argument to Antiword by imitating a
124 * drag-and-drop to Antiword's iconbar icon
126 memset(&tMsg
, 0, sizeof(tMsg
));
127 tMsg
.header
.size
= ROUND4(offsetof(message_block
, data
) +
128 offsetof(message_dataload
, filename
) +
130 tMsg
.header
.yourref
= 0;
131 tMsg
.header
.action
= message_DATALOAD
;
132 tMsg
.data
.dataload
.window
= window_ICONBAR
;
133 tMsg
.data
.dataload
.icon
= -1;
134 tMsg
.data
.dataload
.size
= 0;
135 tMsg
.data
.dataload
.filetype
= FILETYPE_MSWORD
;
136 strcpy(tMsg
.data
.dataload
.filename
, argv
[1]);
137 Error_CheckFatal(Wimp_SendMessage(event_SEND
,
138 &tMsg
, tTaskHandle
, 0));
141 /* Give an error message and return */
142 werr(1, "Antiword is already running");