library.ltx

来自「UUDeview是一个编码解码器」· LTX 代码 · 共 1,403 行 · 第 1/5 页

LTX
1,403
字号
are used throughout the library. For a full listing of the availablereplacement functions, see section \ref{chap-rf}.However, there are two functions, \texttt{strerror} and\texttt{tempnam}, that aren't fully implemented. The replacement\texttt{strerror} does not have a table of error messages and onlyproduces the error number as string, and the ``fake''\texttt{tempnam} does not necessarily use a proper temp directory.Because some functionality is missing, the replacement functions should\emph{only} be used if the original is not available.\begin{description}\item[\texttt{strerror}]If your system does not provide a \texttt{strerror} function of itsown, define to \texttt{\_FP\_strerror}. This causes the replacementfunction to be used throughout the library.\item[\texttt{tempnam}]If your system does not provide a \texttt{tempnam} function of itsown, define to \texttt{\_FP\_tempnam}. This causes the replacementfunction to be used throughout the library. Must not be defined if thefunction is in fact available.\end{description}\subsection{Creating the \texttt{Makefile} by hand}The \texttt{Makefile} is automatically generated by the configurationscript from the template in \texttt{Makefile.in}. This sectionexplains how the template must be edited into a proper Makefile.Just copy \texttt{Makefile.in} to \texttt{Makefile} and edit theplace-holders for the following values.\begin{description}\item[\texttt{CC}]Your system's ``C'' compiler.\item[\texttt{CFLAGS}]The compilation flags to be passed to the compiler. This must include``-I.'' so that the include files from the local directory are found,and ``\mbox{-DHAVE\_CONFIG\_H}'' to declare that a configuration fileis present.\item[\texttt{RANLIB}]Set to ``ranlib'' if such a program is available on your system, or to``:'' (colon) otherwise.\item[\texttt{VERSION}]A string holding the release number of the library, currently``\uuversion{}''\item[\texttt{PATCH}]A string holding the patchlevel, currently ``\uupatch{}''.\end{description}Some systems do not know Makefiles but offer the concept of a``project''.\footnote{Actually, most project-oriented systems compilethe project definitions into a Makefile for use by the back-ends.} Inthis case, create a new project targeting a library and add allsource codes to the project. Then, make sure that the include pathincludes the current directory. Add options to the compiler commandso that the symbol ``HAVE\_CONFIG\_H'' gets defined.Additionally, the symbol ``VERSION'' must be defined as astring holding the release number, currently ``\uuversion{}'' and``PATCH'' must be defined as a string holding the patch level,currently ``\uupatch{}''.On 16-bit systems, the package should be compiled using the ``Large''memory model, so that more than just 64k data space is available.\subsection{Compiling your Projects}Compiling the parts of your project that use the functions from thedecoding library is pretty straightforward:\begin{itemize}\item All modules that call library functions must include the\texttt{<uudeview.h>} header file.\item Optionally, if you want to use the replacement functions to makeyour own application more portable, they may also include\texttt{<fptools.h>}.\item If your compiler understands about function prototypes, definethe symbol \texttt{PROTOTYPES}. This causes the library functions tobe declared with a full parameter list.\item Modify the include file search path so that the compiler findsthe include files (usually with the ``-I'' option).\item Link with the \texttt{libuu.a} library, usually using the``-luu'' option.\item Make sure the library is found (usually with the ``-L'' option).\end{itemize}\section{Callback Functions}\subsection{Intro}At some points, the decoding library offers to call your customprocedures to do jobs you want to take care of yourself. Some examplesare the ``Message Callback'' to print a message or the ``BusyCallback'', which is frequently called during lengthy processingof data to indicate the progress. You can hook up your functions bycalling some library function with a pointer to your function as aparameter.In some cases, you will want that one of your functions receivescertain data as a parameter. One reason to achieve this would bethrough global data; another possibility is provided through thepassing of an opaque data pointer.All callback functions are declared to take an additional parameter oftype \texttt{void*}. When hooking up one of your callbacks, you canspecify a value that will passed whenever your function iscalled. Since this pointer is never touched by the library, it can beany kind of data, usually some composed structure. Some applicationfor the Message Callback might be a \texttt{FILE*} pointer to log themessages to.For portability reasons, you should declare your callbacks with thefirst parameter actually being a \texttt{void*} pointer and only castthis pointer to its real type within the function body. This preventscompiler warnings about the callback setup.\subsection{Message Callback}\label{Section-Msg-Callback}For portability reasons, the library does not assume the availabilityof a terminal, so it does not initially know where to print messagesto. The library generates some messages about its progress as wellas more serious warnings and errors. An application should provide amessage callback that displays them. The function might also choose toignore informative messages and only display the fatal ones.A Message Callback takes three parameters. The first one is the opaquedata pointer of type \texttt{void*}. The second one is a text messageof more or less arbitrary length without line breaks. The lastparameter is an indicator of the seriousness of this message. A stringrepresentation of the warning level is also prefixed to the message.\begin{description}\item[\texttt{UUMSG\_MESSAGE}]This is just a plain informative message, nothing important. Theapplication can choose to simply ignore the message. If a log fileis available, it should be logged, but the message should never resultin a modal dialogue.\item[\texttt{UUMSG\_NOTE}] ``Note:''Still an informative message, meaning that the library made a decisionon its own that might interest the user. One example for a note isthat the setuid bit has been stripped from a file mode for securityreasons. Notes are nothing serious and may still be ignored.\item[\texttt{UUMSG\_WARNING}] ``Warning:''A warning indicates that a non-serious problem occurred which did notstop the library from proceeding with the current action. One exampleis a temporary file that could not be removed. Warnings should bedisplayed, but an application may decide to continue even without userintervention.\item[\texttt{UUMSG\_ERROR}] ``ERROR:''A problem occurred that caused termination of the current request, forexample if the library tried to access a non-existing file. After anerror has occurred, the application should closely examine theresulting return code of the operation. Error messages are usuallyprinted in modal dialogues; another option is to save the errormessage string somewhere and later print the error message after theapplication has examined the operation's return value.\item[\texttt{UUMSG\_FATAL}] ``Fatal Error:''This would indicate that a serious problem has occurred that preventsthe library from processing any more requests. Currently unused.\item[\texttt{UUMSG\_PANIC}] ``Panic:''Such a message would indicate a panic condition, meaning theapplication should terminate without further clean-up handling.Unused so far.\footnote{It is not intended that this and the previouserror levels will ever be used. Currently, there's no need to includehandling for them.}\end{description}\subsection{Busy Callback}\label{Section-Busy-Callback}Some library functions, like scanning of an input file or decoding anoutput file, can take quite some time. An application will usuallywant to inform the user of the progress. A custom ``Busy Callback''can be provided to take care of this job. This function will then becalled frequently while a large action is being executed within thelibrary. It is not called when the application itself has control.Apart from the usual opaque data pointer, the Busy Callback receives astructure of type \texttt{uuprogress} with the following members:\begin{description}\item[\texttt{action}]What the library is currently doing. One of the following integerconstants:\begin{description}\item[\texttt{UUACT\_IDLE}]The library is idle. This value shouldn't be seen in the BusyCallback, because the Busy Callback is never called in an idle state.\item[\texttt{UUACT\_SCANNING}] Scanning an input file.\item[\texttt{UUACT\_DECODING}] Decoding a file.\item[\texttt{UUACT\_COPYING}]  Copying a file.\item[\texttt{UUACT\_ENCODING}] Encoding a file.\end{description}\item[\texttt{curfile}]The name of the file we're working on. May include the fullpath. Guaranteed to be 256 characters or shorter.\item[\texttt{partno}]When decoding a file, this is the current part number we're workingon. May be zero.\item[\texttt{numparts}]The maximum part number of this file. Guaranteed to be positive(non-zero).\item[\texttt{percent}]The percentage of the current \emph{part} already processed. The totalpercentage can be calculated as $(100*partno-percent)/numparts$.\item[\texttt{fsize}]The size of the current file. The percent information is only valid ifthis field is \emph{positive}. Whenever the size of a file cannot beproperly determined, this field is set to -1; in this case, thepercent field may hold garbage.\end{description}In some cases, it is possible that the percent counter jumpsbackwards. This happens seldom enough not to worry about it, but thecallback should take care not to crash in this case.\footnote{Thishappens if, in a MIME multipart posting, the final boundary cannot befound. After searching the boundary until the end-of-file, the scannerresets itself to the location of the previous boundary.}The Busy Callback is declared to return an integer value. If a\emph{non-zero} value is returned, the current operation fromwhich the callback was called is canceled, which then aborts witha return value of \texttt{UURET\ush{}CANCEL} (see later).\subsection{File Callback}\label{Section-File-Callback}Input files are usually needed twice, first for scanning and then fordecoding. If the input files are downloaded from a remote server,perhaps by \emph{NNTP}, they would have to be stored on the local diskand await further handling. However, the user may choose not to decodesome files after all.If disk space is important, it is possible to install a ``FileCallback''. When scanning a file, it is assigned an ``Id''. Afterscanning has completed, the application can delete the input file. Ifit should be required later on for decoding, the File Callback iscalled to map the Id back to a filename, possibly retrievinganother copy and disposing of it afterwards.The File Callback receives four parameters. The first is the opaquedata pointer, the second is the Id that was assigned to the file whilescanning. The fourth parameter is an integer. If it is non-zero, thenthe function is supposed to retrieve the file in question, store it onlocal disk, and write the resulting filename into the area to whichthe third parameter (a \texttt{char*} pointer) points. A fourthparameter of zero indicates that the decoder is done handling thefile, so that the function can decide whether or not to remove thefile.The function must return \texttt{UURET\_OK} upon success, or any otherappropriate error code upon failure.Since it can usually be assumed that disk space is plentily available,and storing a file is ``cheaper'' than retrieving it twice, thismechanism has not been used so far.\subsection{Filename Filter}\label{Section-FName-Filter}For portability reasons, the library does not make any assumptions ofthe legality of certain filenames. It will pick up a ``garbage'' filename from the encoded file and happily use it if not toldotherwise. For example, on DOS systems many filenames must betruncated in order to be valid.If a ``Filename Filter'' is installed, the library will pass eachpotential filename to the filter and then use the filename that thefilter function returns. The filter also has to remove all directoryinformation from the filename -- the library itself does not knowabout directories at all.The filter function receives the potential filename as string and mustreturn a pointer to a string with the corrected filename. It mayeither return a pointer to some position in the original string or apointer to some static area, but it should not modify the sourcestring.Two examples of filename filters can be found among the UUDeviewdistribution as \texttt{uufnflt.c}. The DOS filter function disposesdirectory information, uses only the first 8 characters of the basefilename and the first three characters after the last '.'~(since afilename might have two extensions). Also, space characters arereplaced by underscores. The Unix filter just returns a pointer to the

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?