Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/startup_8c_source.html
--- a/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/startup_8c_source.html Fri Jun 11 15:24:34 2010 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,161 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
-<title>TB9.2 Example Applications: examples/PIPS/antiword/src/startup.c Source File</title>
-<link href="tabs.css" rel="stylesheet" type="text/css"/>
-<link href="doxygen.css" rel="stylesheet" type="text/css"/>
-</head>
-<body>
-<!-- Generated by Doxygen 1.6.2 -->
-<h1>examples/PIPS/antiword/src/startup.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
-<a name="l00002"></a>00002 <span class="comment"> * startup.c</span>
-<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 1998-2001 A.J. van Os; Released under GPL</span>
-<a name="l00004"></a>00004 <span class="comment"> *</span>
-<a name="l00005"></a>00005 <span class="comment"> * Description:</span>
-<a name="l00006"></a>00006 <span class="comment"> * Try to force a single startup of !Antiword</span>
-<a name="l00007"></a>00007 <span class="comment"> */</span>
-<a name="l00008"></a>00008
-<a name="l00009"></a>00009 <span class="preprocessor">#include <stdlib.h></span>
-<a name="l00010"></a>00010 <span class="preprocessor">#include <string.h></span>
-<a name="l00011"></a>00011 <span class="preprocessor">#include <ctype.h></span>
-<a name="l00012"></a>00012 <span class="preprocessor">#include "DeskLib:Error.h"</span>
-<a name="l00013"></a>00013 <span class="preprocessor">#include "DeskLib:Event.h"</span>
-<a name="l00014"></a>00014 <span class="preprocessor">#include "DeskLib:SWI.h"</span>
-<a name="l00015"></a>00015 <span class="preprocessor">#include "antiword.h"</span>
-<a name="l00016"></a>00016
-<a name="l00017"></a>00017
-<a name="l00018"></a>00018 <span class="preprocessor">#if !defined(TaskManager_EnumerateTasks)</span>
-<a name="l00019"></a>00019 <span class="preprocessor"></span><span class="preprocessor">#define TaskManager_EnumerateTasks 0x042681</span>
-<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* TaskManager_EnumerateTasks */</span>
-<a name="l00021"></a>00021
-<a name="l00022"></a>00022 <span class="comment">/*</span>
-<a name="l00023"></a>00023 <span class="comment"> * bIsMatch - decide whether the two strings match</span>
-<a name="l00024"></a>00024 <span class="comment"> *</span>
-<a name="l00025"></a>00025 <span class="comment"> * like strcmp, but this one ignores case</span>
-<a name="l00026"></a>00026 <span class="comment"> */</span>
-<a name="l00027"></a>00027 <span class="keyword">static</span> BOOL
-<a name="l00028"></a>00028 bIsMatch(<span class="keyword">const</span> <span class="keywordtype">char</span> *szStr1, <span class="keyword">const</span> <span class="keywordtype">char</span> *szStr2)
-<a name="l00029"></a>00029 {
-<a name="l00030"></a>00030 <span class="keyword">const</span> <span class="keywordtype">char</span> *pcTmp1, *pcTmp2;
-<a name="l00031"></a>00031
-<a name="l00032"></a>00032 <span class="keywordflow">for</span> (pcTmp1 = szStr1, pcTmp2 = szStr2;
-<a name="l00033"></a>00033 *pcTmp1 != <span class="charliteral">'\0'</span>;
-<a name="l00034"></a>00034 pcTmp1++, pcTmp2++) {
-<a name="l00035"></a>00035 <span class="keywordflow">if</span> (toupper(*pcTmp1) != toupper(*pcTmp2)) {
-<a name="l00036"></a>00036 <span class="keywordflow">return</span> FALSE;
-<a name="l00037"></a>00037 }
-<a name="l00038"></a>00038 }
-<a name="l00039"></a>00039 <span class="keywordflow">return</span> *pcTmp2 == <span class="charliteral">'\0'</span>;
-<a name="l00040"></a>00040 } <span class="comment">/* end of bIsMatch */</span>
-<a name="l00041"></a>00041
-<a name="l00042"></a>00042 <span class="comment">/*</span>
-<a name="l00043"></a>00043 <span class="comment"> * tGetTaskHandle - get the task handle of the given task</span>
-<a name="l00044"></a>00044 <span class="comment"> *</span>
-<a name="l00045"></a>00045 <span class="comment"> * returns the task handle when found, otherwise 0</span>
-<a name="l00046"></a>00046 <span class="comment"> */</span>
-<a name="l00047"></a>00047 <span class="keyword">static</span> task_handle
-<a name="l00048"></a>00048 tGetTaskHandle(<span class="keyword">const</span> <span class="keywordtype">char</span> *szTaskname)
-<a name="l00049"></a>00049 {
-<a name="l00050"></a>00050 <span class="keyword">const</span> <span class="keywordtype">char</span> *pcTmp;
-<a name="l00051"></a>00051 <span class="keywordtype">int</span> iReg0, iIndex;
-<a name="l00052"></a>00052 <span class="keywordtype">int</span> aiBuffer[4];
-<a name="l00053"></a>00053 <span class="keywordtype">char</span> szTmp[21];
-<a name="l00054"></a>00054
-<a name="l00055"></a>00055 iReg0 = 0;
-<a name="l00056"></a>00056 <span class="keywordflow">do</span> {
-<a name="l00057"></a>00057 <span class="comment">/* Get info on the next task */</span>
-<a name="l00058"></a>00058 Error_CheckFatal(SWI(3, 1, TaskManager_EnumerateTasks | XOS_Bit,
-<a name="l00059"></a>00059 iReg0, aiBuffer, <span class="keyword">sizeof</span>(aiBuffer), &iReg0));
-<a name="l00060"></a>00060 <span class="comment">/* Copy the (control character terminated) task name */</span>
-<a name="l00061"></a>00061 <span class="keywordflow">for</span> (iIndex = 0, pcTmp = (<span class="keyword">const</span> <span class="keywordtype">char</span> *)aiBuffer[1];
-<a name="l00062"></a>00062 iIndex < elementsof(szTmp);
-<a name="l00063"></a>00063 iIndex++, pcTmp++) {
-<a name="l00064"></a>00064 <span class="keywordflow">if</span> (iscntrl(*pcTmp)) {
-<a name="l00065"></a>00065 szTmp[iIndex] = <span class="charliteral">'\0'</span>;
-<a name="l00066"></a>00066 <span class="keywordflow">break</span>;
-<a name="l00067"></a>00067 }
-<a name="l00068"></a>00068 szTmp[iIndex] = *pcTmp;
-<a name="l00069"></a>00069 }
-<a name="l00070"></a>00070 szTmp[elementsof(szTmp) - 1] = <span class="charliteral">'\0'</span>;
-<a name="l00071"></a>00071 <span class="keywordflow">if</span> (bIsMatch(szTmp, szTaskname)) {
-<a name="l00072"></a>00072 <span class="comment">/* Task found */</span>
-<a name="l00073"></a>00073 <span class="keywordflow">return</span> (task_handle)aiBuffer[0];
-<a name="l00074"></a>00074 }
-<a name="l00075"></a>00075 } <span class="keywordflow">while</span> (iReg0 >= 0);
-<a name="l00076"></a>00076
-<a name="l00077"></a>00077 <span class="comment">/* Task not found */</span>
-<a name="l00078"></a>00078 <span class="keywordflow">return</span> 0;
-<a name="l00079"></a>00079 } <span class="comment">/* end of tGetTaskHandle */</span>
-<a name="l00080"></a>00080
-<a name="l00081"></a>00081 <span class="keywordtype">int</span>
-<a name="l00082"></a>00082 <a class="code" href="redirectprintf_8c.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
-<a name="l00083"></a>00083 {
-<a name="l00084"></a>00084 message_block tMsg;
-<a name="l00085"></a>00085 task_handle tTaskHandle;
-<a name="l00086"></a>00086 <span class="keywordtype">size_t</span> tArgLen;
-<a name="l00087"></a>00087 <span class="keywordtype">int</span> aiMessages[] = {0};
-<a name="l00088"></a>00088 <span class="keywordtype">char</span> szCommand[512];
-<a name="l00089"></a>00089
-<a name="l00090"></a>00090 Event_Initialise3(<span class="stringliteral">"StartUp"</span>, 310, aiMessages);
-<a name="l00091"></a>00091
-<a name="l00092"></a>00092 <span class="keywordflow">if</span> (argc > 1) {
-<a name="l00093"></a>00093 tArgLen = strlen(argv[1]);
-<a name="l00094"></a>00094 } <span class="keywordflow">else</span> {
-<a name="l00095"></a>00095 tArgLen = 0;
-<a name="l00096"></a>00096 }
-<a name="l00097"></a>00097 <span class="keywordflow">if</span> (tArgLen >= <span class="keyword">sizeof</span>(tMsg.data.dataload.filename)) {
-<a name="l00098"></a>00098 werr(1, <span class="stringliteral">"Input filename too long"</span>);
-<a name="l00099"></a>00099 <span class="keywordflow">return</span> EXIT_FAILURE;
-<a name="l00100"></a>00100 }
-<a name="l00101"></a>00101
-<a name="l00102"></a>00102 tTaskHandle = tGetTaskHandle(<span class="stringliteral">"antiword"</span>);
-<a name="l00103"></a>00103
-<a name="l00104"></a>00104 <span class="keywordflow">if</span> (tTaskHandle == 0) {
-<a name="l00105"></a>00105 <span class="comment">/* Antiword is not active */</span>
-<a name="l00106"></a>00106 strcpy(szCommand, <span class="stringliteral">"chain:<Antiword$Dir>.!Antiword"</span>);
-<a name="l00107"></a>00107 <span class="keywordflow">if</span> (argc > 1) {
-<a name="l00108"></a>00108 strcat(szCommand, <span class="stringliteral">" "</span>);
-<a name="l00109"></a>00109 strcat(szCommand, argv[1]);
-<a name="l00110"></a>00110 }
-<a name="l00111"></a>00111 <span class="preprocessor">#if defined(DEBUG)</span>
-<a name="l00112"></a>00112 <span class="preprocessor"></span> strcat(szCommand, <span class="stringliteral">" "</span>);
-<a name="l00113"></a>00113 strcat(szCommand, <span class="stringliteral">"2><Antiword$Dir>.Debug"</span>);
-<a name="l00114"></a>00114 <span class="preprocessor">#endif </span><span class="comment">/* DEBUG */</span>
-<a name="l00115"></a>00115 system(szCommand);
-<a name="l00116"></a>00116 <span class="comment">/* If we reach here something has gone wrong */</span>
-<a name="l00117"></a>00117 <span class="keywordflow">return</span> EXIT_FAILURE;
-<a name="l00118"></a>00118 }
-<a name="l00119"></a>00119
-<a name="l00120"></a>00120 <span class="comment">/* Antiword is active */</span>
-<a name="l00121"></a>00121 <span class="keywordflow">if</span> (argc > 1) {
-<a name="l00122"></a>00122 <span class="comment">/*</span>
-<a name="l00123"></a>00123 <span class="comment"> * Send the argument to Antiword by imitating a</span>
-<a name="l00124"></a>00124 <span class="comment"> * drag-and-drop to Antiword's iconbar icon</span>
-<a name="l00125"></a>00125 <span class="comment"> */</span>
-<a name="l00126"></a>00126 memset(&tMsg, 0, <span class="keyword">sizeof</span>(tMsg));
-<a name="l00127"></a>00127 tMsg.header.size = ROUND4(offsetof(message_block, data) +
-<a name="l00128"></a>00128 offsetof(message_dataload, filename) +
-<a name="l00129"></a>00129 1 + tArgLen);
-<a name="l00130"></a>00130 tMsg.header.yourref = 0;
-<a name="l00131"></a>00131 tMsg.header.action = message_DATALOAD;
-<a name="l00132"></a>00132 tMsg.data.dataload.window = window_ICONBAR;
-<a name="l00133"></a>00133 tMsg.data.dataload.icon = -1;
-<a name="l00134"></a>00134 tMsg.data.dataload.size = 0;
-<a name="l00135"></a>00135 tMsg.data.dataload.filetype = FILETYPE_MSWORD;
-<a name="l00136"></a>00136 strcpy(tMsg.data.dataload.filename, argv[1]);
-<a name="l00137"></a>00137 Error_CheckFatal(Wimp_SendMessage(event_SEND,
-<a name="l00138"></a>00138 &tMsg, tTaskHandle, 0));
-<a name="l00139"></a>00139 <span class="keywordflow">return</span> EXIT_SUCCESS;
-<a name="l00140"></a>00140 } <span class="keywordflow">else</span> {
-<a name="l00141"></a>00141 <span class="comment">/* Give an error message and return */</span>
-<a name="l00142"></a>00142 werr(1, <span class="stringliteral">"Antiword is already running"</span>);
-<a name="l00143"></a>00143 <span class="keywordflow">return</span> EXIT_FAILURE;
-<a name="l00144"></a>00144 }
-<a name="l00145"></a>00145 } <span class="comment">/* end of main */</span>
-</pre></div></div>
-<hr size="1"/><address style="text-align: right;"><small>Generated by
-<a href="http://www.doxygen.org/index.html">
-<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
-</body>
-</html>