?? ch05l03.txt
字號:
Listing 5.3 TGI program with only one instance./* Task Gateway Interface -- A. Montefusco * TGI program with only one instance. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#include <time.h>#include <dos.h>#include "tgi.h"/* htPrintf printf-like function emits HTML output stream from TGI callback */int htPrintf (HREQUEST hReq, const char *fmt, ...){ char szBuf[1024]; va_list argptr; int cnt; va_start(argptr, fmt); cnt = vsprintf(szBuf, fmt, argptr); va_end(argptr); TgiPutHtml (hReq, szBuf, (long)cnt); return(cnt);}/* HTML 2.0 compatible header... */static char szHtmlHeader [] = "Content-type: text/html\r\n\r\n" "<html>" "<head><title>Returned from TGI executable !!! </title></head>" "<body>" "<h1>TGI TEST</h1>" "<p>Returned from Task Gateway Interface executable." ;/* ... and trailer */static char szHtmlTrailer [] = "</body></html>" ;/* TGI callback function. hReq parameter must be used in all following calls * to TGI API: pCbData points to optional extension's data. This callback * sends to client a simple screen containing the request's data */long CbExample1 (HREQUEST hReq, void *pCbData){ printf ("Callback: recalled with: %p *p\n", (void *)hReq, pCbData); TgiPutHtml (hReq, szHtmlHeader, strlen(szHtmlHeader)); { char *pszPi; char *pszQi; char *pszFd; htPrintf (hReq, "<p><p><pre>"); TgiGetPathInfo ( hReq, &pszPi ); TgiGetQueryInfo ( hReq, &pszQi ); TgiGetFormData ( hReq, &pszFd ); htPrintf (hReq, "PathInfo : %s<p>", pszPi); htPrintf (hReq, "QueryInfo : %s<p>", pszQi); htPrintf (hReq, "FormData : %s<p>", pszFd); htPrintf (hReq, "<p></pre>"); } /* Remove remark tokens from the following to simulate a lengthy * operation */ /* sleep (10); */ { time_t timeNow = time(0); // request start timestamp time_t timeStart = *((time_t *)pCbData); // program start timestamp htPrintf (hReq, "<p>Run @ %s<p>", asctime (localtime(&timeNow))); htPrintf (hReq, "<p>Tgi module start @ %s<p>", asctime (localtime(&timeStart))); } TgiPutHtml (hReq, szHtmlTrailer, strlen(szHtmlTrailer)); return TGI_OK;}int main (void){ long rc; HTGI hTgi; // handle of the TGI extension char *pszModName = "example_1"; // TGI extension name time_t timeStart; // program start timestamp timeStart = time(0); rc = TgiRegisterModule ( pszModName, CbExample1, &hTgi, 0 ); TGI_FATAL(rc); rc = TgiProcessModule ( hTgi, &timeStart ); TGI_FATAL(rc); rc = TgiDeregisterModule ( hTgi ); TGI_FATAL(rc); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -