home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume27 / clc / part08 < prev    next >
Encoding:
Text File  |  1993-11-28  |  32.7 KB  |  1,291 lines

  1. Newsgroups: comp.sources.unix
  2. From: panos@anchor.cs.colorado.edu (Panos Tsirigotis)
  3. Subject: v27i114: clc - C Libraries Collection, Part08/20
  4. References: <1.754527080.23891@gw.home.vix.com>
  5. Sender: unix-sources-moderator@gw.home.vix.com
  6. Approved: vixie@gw.home.vix.com
  7.  
  8. Submitted-By: panos@anchor.cs.colorado.edu (Panos Tsirigotis)
  9. Posting-Number: Volume 27, Issue 114
  10. Archive-Name: clc/part08
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 8 (of 20)."
  19. # Contents:  libs/src/misc/ftwx.c libs/src/sio/suite/tester
  20. #   libs/src/str/strparse.3 libs/src/timer/Makefile
  21. #   libs/src/timer/timemacros.h libs/src/xlog/Makefile
  22. #   libs/src/xlog/slog.c
  23. # Wrapped by panos@eclipse on Sun Nov 28 14:48:16 1993
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'libs/src/misc/ftwx.c' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'libs/src/misc/ftwx.c'\"
  27. else
  28. echo shar: Extracting \"'libs/src/misc/ftwx.c'\" \(3822 characters\)
  29. sed "s/^X//" >'libs/src/misc/ftwx.c' <<'END_OF_FILE'
  30. X/*
  31. X * (c) Copyright 1992 by Panagiotis Tsirigotis
  32. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  33. X * and conditions for redistribution.
  34. X */
  35. X
  36. Xstatic char RCSid[] = "$Id: ftwx.c,v 2.1 1992/10/01 00:41:02 panos Exp $" ;
  37. X
  38. X#include <sys/types.h>
  39. X#include <sys/stat.h>
  40. X#include <sys/file.h>
  41. X#ifndef OLD_DIR
  42. X#include <dirent.h>
  43. X#else
  44. X#include <sys/dir.h>
  45. X#define dirent direct
  46. X#endif
  47. X
  48. Xextern int errno ;
  49. X
  50. X#include "misc.h"
  51. X#include "ftwx.h"
  52. X
  53. X#define PRIVATE            static
  54. X
  55. X#define NUL                    '\0'
  56. X
  57. X
  58. Xtypedef enum { NO, YES } boolean_e ;
  59. X
  60. Xstatic struct
  61. X{
  62. X    int (*stat_func)() ;
  63. X    int (*user_func)() ;
  64. X} ftwx_data ;
  65. X
  66. X/*
  67. X * ftwx is an extension to ftw, that optionally follows symlinks (the
  68. X * default is NOT to follow them).
  69. X *
  70. X * Possible flag values:
  71. X *        FTWX_FOLLOW:         follow symlinks
  72. X *
  73. X * Possible depth values:
  74. X *        0            : means only the specified path
  75. X *        positive : means go as deep as specified
  76. X *        FTWX_ALL : no depth limitation
  77. X *
  78. X * User function return value:
  79. X *        negative : means an error occured and the traversal should stop
  80. X *        0            : OK
  81. X *        positive : means that if the current object is a directory it
  82. X *                      should not be traversed.
  83. X *
  84. X * Return value:
  85. X *        -1         : if an error occurs
  86. X *  frv            : frv is the function return value if it is negative (it
  87. X *                      should not be -1).
  88. X *        0            : if successful
  89. X */
  90. Xint ftwx( path, func, depth, flags )
  91. X    char *path ;
  92. X    int (*func)() ;
  93. X    int depth ;
  94. X    int flags ;
  95. X{
  96. X    int stat(), lstat() ;
  97. X
  98. X    /*
  99. X     * Initialize the data structure
  100. X     */
  101. X    ftwx_data.stat_func = ( flags & FTWX_FOLLOW ) ? stat : lstat ;
  102. X    ftwx_data.user_func = func ;
  103. X
  104. X    return( ftwx_traverse( path, depth ) ) ;
  105. X}
  106. X
  107. X
  108. X
  109. X
  110. X/*
  111. X * ftwx_traverse works in two phases:
  112. X *
  113. X * Phase 1: process the current path
  114. X *
  115. X * Phase 2: if the current path is a directory, it invokes ftwx_traverse
  116. X *                for each directory entry
  117. X */
  118. XPRIVATE int ftwx_traverse( path, depth )
  119. X    char *path ;
  120. X    int depth ;
  121. X{
  122. X    DIR *dirp ;
  123. X    struct stat st ;
  124. X    int ftw_flag = 0 ;
  125. X    boolean_e traverse = YES ;
  126. X    int retval ;
  127. X    int save_errno ;
  128. X
  129. X    if ( (*ftwx_data.stat_func)( path, &st ) == -1 )
  130. X        ftw_flag = FTW_NS ;
  131. X    else
  132. X    {
  133. X        /*
  134. X         * If it is a directory and determine if it is readable
  135. X         * (if it is not readable, we don't traverse it
  136. X         */
  137. X        if ( S_ISDIR( st.st_mode ) )
  138. X            if ( access( path, R_OK ) == 0 )
  139. X                ftw_flag = FTW_D ;
  140. X            else
  141. X                ftw_flag = FTW_DNR ;
  142. X        else
  143. X            ftw_flag = FTW_F ;
  144. X    }
  145. X    retval = (*ftwx_data.user_func)( path, &st, ftw_flag ) ;
  146. X    if ( retval < 0 )
  147. X        return( retval ) ;
  148. X    else if ( retval > 0 && ftw_flag == FTW_D )
  149. X        traverse = NO ;
  150. X
  151. X    /*
  152. X     * Stop traversal if:
  153. X     *        a. depth reached 0
  154. X     *        b. the current path is not a readable directory
  155. X     *        c. the user doesn't want us to traverse this directory tree
  156. X     */
  157. X    if ( depth == 0 || ftw_flag != FTW_D || traverse == NO )
  158. X        return( 0 ) ;
  159. X
  160. X    if ( depth != FTWX_ALL )
  161. X        depth-- ;
  162. X
  163. X    if ( ( dirp = opendir( path ) ) == NULL )
  164. X        return( -1 ) ;
  165. X
  166. X    for ( ;; )
  167. X    {
  168. X        struct dirent *dp ;
  169. X        char *filename ;
  170. X
  171. X        errno = 0 ;            /* to detect readdir errors */
  172. X        dp = readdir( dirp ) ;
  173. X        if ( dp == NULL )
  174. X        {
  175. X            retval = ( errno == 0 ) ? 0 : -1 ;
  176. X            break ;
  177. X        }
  178. X
  179. X        /*
  180. X         * The special names: "." and ".." are skipped
  181. X         */
  182. X        if ( dp->d_name[ 0 ] == '.' )
  183. X            if ( dp->d_name[ 1 ] == NUL ||
  184. X                        dp->d_name[ 1 ] == '.' && dp->d_name[ 2 ] == NUL )
  185. X                continue ;
  186. X
  187. X        filename = make_pathname( 2, path, dp->d_name ) ;
  188. X        if ( filename == NULL )
  189. X        {
  190. X            retval = -1 ;
  191. X            break ;
  192. X        }
  193. X        
  194. X        retval = ftwx_traverse( filename, depth ) ;
  195. X        free( filename ) ;
  196. X
  197. X        /*
  198. X         * Check for a negative value instead of -1 because the
  199. X         * user function may use any negative value
  200. X         */
  201. X        if ( retval < 0 )
  202. X            break ;
  203. X    }
  204. X    /*
  205. X     * Make sure we don't trash errno; we should only do this if
  206. X     * retval is negative, but we are lazy...
  207. X     */
  208. X    save_errno = errno ;
  209. X    (void) closedir( dirp ) ;
  210. X    errno = save_errno ;
  211. X    return( retval ) ;
  212. X}
  213. X
  214. END_OF_FILE
  215. if test 3822 -ne `wc -c <'libs/src/misc/ftwx.c'`; then
  216.     echo shar: \"'libs/src/misc/ftwx.c'\" unpacked with wrong size!
  217. fi
  218. # end of 'libs/src/misc/ftwx.c'
  219. fi
  220. if test -f 'libs/src/sio/suite/tester' -a "${1}" != "-c" ; then 
  221.   echo shar: Will not clobber existing file \"'libs/src/sio/suite/tester'\"
  222. else
  223. echo shar: Extracting \"'libs/src/sio/suite/tester'\" \(3962 characters\)
  224. sed "s/^X//" >'libs/src/sio/suite/tester' <<'END_OF_FILE'
  225. X#!/bin/sh
  226. X
  227. X# (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  228. X# All rights reserved.  The file named COPYRIGHT specifies the terms 
  229. X# and conditions for redistribution.
  230. X
  231. X
  232. X#
  233. X# $Id: tester,v 8.3 1993/09/08 05:59:30 panos Exp $
  234. X#
  235. X
  236. X#
  237. X# Usage:
  238. X#            tester [all] [function-name function-name ...]
  239. X#
  240. X# function-name is the name of a sio function (or macro)
  241. X#
  242. X# If "all" is used, functions after it will *not* be tested.
  243. X#
  244. X
  245. Xscript_name=`basename $0`
  246. X
  247. Xcopy_file=/usr/dict/words
  248. Xtemp_file=/tmp/w
  249. Xmake_log=MAKE.LOG
  250. X
  251. Xif test ! -f $copy_file ; then
  252. X    echo "The file '$copy_file' is not available."
  253. X    echo "Please edit the '$script_name' script and change set the"
  254. X    echo "variable 'copy_file' to the name of a publicly readable file"
  255. X    echo "with at least a few tens of thousands of lines."
  256. X    exit 1
  257. Xfi
  258. X
  259. Xtrap_function()
  260. X{
  261. X    rm -f $temp_file $make_log
  262. X    echo
  263. X    exit 1
  264. X}
  265. X
  266. X
  267. Xmake_program()
  268. X{
  269. X    target=$1
  270. X    cflags="$2"
  271. X    if test -f $1 -a ! -x $1 ; then rm -f $1 ; fi
  272. X    if test "$cflags"
  273. X    then
  274. X        make -s "$cflags" $target >$make_log 2>&1
  275. X    else
  276. X        make -s $target >$make_log 2>&1
  277. X    fi
  278. X    exit_code=$?
  279. X    if test $exit_code -eq 0 -a -x $1
  280. X    then
  281. X        rm -f $make_log
  282. X    else
  283. X        echo "FAILED"
  284. X        echo "   The make failed. Check the make log file << $make_log >>"
  285. X        exit
  286. X    fi
  287. X}
  288. X
  289. X
  290. X
  291. X#
  292. X# test_function expects a single argument, the name of the function
  293. X# it will test.
  294. X# It creates a program that has the name of the function by invoking
  295. X# make with the symbol -DTEST_<function_name>
  296. X#
  297. Xtest_function()
  298. X{
  299. X    expression="echo $"$1
  300. X    var=`eval $expression`
  301. X    if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  302. X
  303. X    echo -n "TESTING $1 "
  304. X    make_program $1 "DEFS=-DTEST_$1"
  305. X
  306. X    ./$1 < $copy_file >$temp_file
  307. X    exit_code=$?
  308. X    if test $exit_code -ne 0
  309. X    then
  310. X        echo "FAILED"
  311. X        echo "   Test program exited with exit code $exit_code"
  312. X        echo "   Temporary file << $temp_file >> not deleted"
  313. X        exit
  314. X    fi
  315. X    cmp -s $copy_file $temp_file
  316. X    if test $? -ne 0
  317. X    then
  318. X        echo "FAILED"
  319. X        echo "   The files << $copy_file >> and << $temp_file >> are not the same"
  320. X        exit
  321. X    else
  322. X        echo PASSED
  323. X    fi
  324. X    rm -f $temp_file
  325. X}
  326. X
  327. X
  328. Xtest_sprint()
  329. X{
  330. X    var=$Sprint
  331. X    program=Sprint
  332. X    if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  333. X
  334. X    echo TESTING Sprint
  335. X    make_program $program ""
  336. X    $TESTSHELL sprint_test
  337. X}
  338. X
  339. X
  340. Xtest_smorefds()
  341. X{
  342. X    var=$Smorefds
  343. X    program=fdtest
  344. X    if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  345. X
  346. X    echo -n "TESTING Smorefds "
  347. X    make_program $program "DEFS="
  348. X    v=`fdtest 2>&1`
  349. X    if test $? -eq 0 ; then
  350. X        echo PASSED
  351. X    else
  352. X        echo "FAILED: $v"
  353. X    fi
  354. X}
  355. X
  356. X
  357. Xtrap trap_function 1 2 3 15
  358. X
  359. X#
  360. X# There is a variable for every function to be tested. That variable
  361. X# can have the values "yes", "no" or "".
  362. X# When a function is specified, it takes the value of $run. Initially $run 
  363. X# is "yes", so a specified function has its variable set to "yes". 
  364. X# If "all" is specified, $run becomes "no", so subsequently specified
  365. X# functions, have their variables set to "no".
  366. X#
  367. X# We test a function iff:
  368. X#        its variable is "yes" OR its variable is "" and $all is "yes"
  369. X# We don't test a function iff:
  370. X#        its variable is "no" OR its variable is "" and $all is "no"
  371. X#        
  372. X# Therefore, all functions specified after "all" will NOT be tested.
  373. X#
  374. Xrun=yes
  375. Xall=no
  376. X
  377. Xwhile test $# -gt 0
  378. Xdo
  379. X    case $1 in
  380. X        Sputchar)    Sputchar=$run ;;
  381. X        Sgetchar)    Sgetchar=$run ;;
  382. X        Srdline)        Srdline=$run ;;
  383. X        Sfetch)        Sfetch=$run ;;
  384. X        Sread)        Sread=$run ;;
  385. X        Swrite)        Swrite=$run ;;
  386. X        Sgetc)        Sgetc=$run ;;
  387. X        Sputc)        Sputc=$run ;;
  388. X        Sflush)        Sflush=$run ;;
  389. X        Sundo)        Sundo=$run ;;
  390. X        Sprint)        Sprint=$run ;;
  391. X        switch)        switch=$run ;;
  392. X        switch2)        switch2=$run ;;
  393. X        Smorefds)    Smorefds=$run ;;
  394. X        all)            all=yes ; run="no" ;;
  395. X        *) echo Bad argument: $1
  396. X    esac
  397. X    shift
  398. Xdone
  399. X
  400. Xtest_function Sgetchar
  401. Xtest_function Sputchar
  402. Xtest_function Sread
  403. Xtest_function Swrite
  404. Xtest_function Srdline
  405. Xtest_function Sfetch
  406. Xtest_function Sgetc
  407. Xtest_function Sputc
  408. Xtest_function Sflush
  409. Xtest_function Sundo
  410. Xtest_function switch
  411. Xtest_function switch2
  412. Xtest_smorefds
  413. Xtest_sprint
  414. X
  415. END_OF_FILE
  416. if test 3962 -ne `wc -c <'libs/src/sio/suite/tester'`; then
  417.     echo shar: \"'libs/src/sio/suite/tester'\" unpacked with wrong size!
  418. fi
  419. # end of 'libs/src/sio/suite/tester'
  420. fi
  421. if test -f 'libs/src/str/strparse.3' -a "${1}" != "-c" ; then 
  422.   echo shar: Will not clobber existing file \"'libs/src/str/strparse.3'\"
  423. else
  424. echo shar: Extracting \"'libs/src/str/strparse.3'\" \(4130 characters\)
  425. sed "s/^X//" >'libs/src/str/strparse.3' <<'END_OF_FILE'
  426. X.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  427. X.\"All rights reserved.  The file named COPYRIGHT specifies the terms 
  428. X.\"and conditions for redistribution.
  429. X.\"
  430. X.\" $Id: strparse.3,v 3.1 1993/06/13 02:48:02 panos Exp $
  431. X.TH STRPARSE 3X "30 September 1992"
  432. X.SH NAME
  433. Xstr_parse, str_endparse, str_component, str_separator, str_nextpos
  434. X.SH SYNOPSIS
  435. X.LP
  436. X.nf
  437. X.ft B
  438. X#include "str.h"
  439. X.LP
  440. X.ft B
  441. Xstr_h str_parse( str, separ, flags, errnop )
  442. Xchar *str ;
  443. Xchar *separ ;
  444. Xint flags ;
  445. Xint *errnop ;
  446. X.LP
  447. X.ft B
  448. Xvoid str_endparse( handle )
  449. Xstr_h handle ;
  450. X.LP
  451. X.ft B
  452. Xchar *str_component( handle )
  453. Xstr_h handle ;
  454. X.LP
  455. X.ft B
  456. Xint str_setstr( handle, newstr )
  457. Xstr_h handle ;
  458. Xchar *newstr ;
  459. X.LP
  460. X.ft B
  461. Xint str_separator( handle, separ )
  462. Xstr_h handle ;
  463. Xchar *separ ;
  464. X.LP
  465. X.ft B
  466. Xchar *str_nextpos( handle )
  467. Xstr_h handle ;
  468. X.LP
  469. Xextern int str_errno ;
  470. X.SH DESCRIPTION
  471. X.LP
  472. XThese functions are useful for parsing strings.  In this context
  473. Xparsing means breaking the string into substrings. The substrings are
  474. Xseparated by a list of possible separator characters.
  475. X.LP
  476. X.B str_component()
  477. Xreturns successive substrings of the string.
  478. X.B str_parse()
  479. Xcreates and initializes a string parser with the string
  480. Xthat will be processed, \fIstr\fR, the list of possible separator
  481. Xcharacters, \fIsepar\fR, and flags that control how the parser
  482. Xworks. The \fIflags\fR argument is formed by ORing one or more of
  483. Xthe following constants:
  484. X.TP 20
  485. X.SB STR_RETURN_ERROR
  486. XIf something goes wrong return a value that indicates that an error occured
  487. X(e.g. out of memory). The default is for the program to be terminated
  488. Xwith an appropriate error message.
  489. X.TP
  490. X.SB STR_NULL_START
  491. XIf \fIstr\fR starts with a separator then a zero-length string will be returned
  492. Xthe first time \fBstr_component()\fR is called.
  493. X.TP
  494. X.SB STR_NULL_END
  495. XIf \fIstr\fR ends with a separator then a zero-length string will be returned
  496. Xby \fBstr_component()\fR when the substrings of \fIstr\fR are exhausted.
  497. X.TP
  498. X.SB STR_MALLOC
  499. XThe strings returned by \fBstr_component()\fR will be in malloc'ed memory.
  500. XBy default the substrings are part of \fIstr\fR.
  501. XIf this option is not used \fIstr\fR will be modified
  502. Xby \fBstr_component()\fR.
  503. X.LP
  504. XFinally, \fBSTR_NOFLAGS\fR may be used to specify no flags.
  505. XThe \fIerrnop\fR argument points to an integer where the string processing
  506. Xfunctions will deposit an error code if an error occurs.
  507. XIf \fIerrnop\fR
  508. Xis
  509. X.SM NULL
  510. Xthe error codes will be placed in \fIstr_errno\fR.
  511. XThis is useful only if \fBSTR_RETURN_ERROR\fR is used in \fIflags\fR.
  512. XIt is possible that \fIstr\fP is 
  513. X.SM NULL.
  514. XIn this case, a subsequent
  515. X.B str_setstr()
  516. Xshould be used to specify the string to be processed.
  517. X.LP
  518. X.B str_component()
  519. Xreturns successive substrings from the string associated with the
  520. Xparser specified by \fIhandle\fR.
  521. X.LP
  522. X.B str_endparse()
  523. Xdestroys the parser specified by \fIhandle\fR.
  524. X.LP
  525. X.B str_setstr()
  526. Xchanges the processed string to \fInewstr\fP.
  527. X.LP
  528. X.B str_separator()
  529. Xreplaces the list of separator characters with \fIsepar\fR.
  530. XProcessing continues from the current position.
  531. X.LP
  532. X.B str_nextpos()
  533. Xreturns a pointer to the rest of the string. The previous character
  534. Xis a separator character (if \fBSTR_MALLOC\fR is not set, then the
  535. Xprevious character is
  536. X.SM NUL
  537. X).
  538. X.SH "RETURN VALUES"
  539. X.LP
  540. X.B str_parse()
  541. Xreturns a parser handle or
  542. X.SM NULL
  543. Xif something goes wrong and \fIflags\fR & \fBSTR_RETURN_ERROR\fR is true.
  544. XPossible \fIstr_errno\fR values:
  545. X.RS
  546. X.TP 20
  547. X.SB STR_ENULLSEPAR
  548. X\fIsepar\fR is
  549. X.SM NULL
  550. X.TP
  551. X.SB STR_ENOMEM
  552. Xthe program ran out of memory
  553. X.RE
  554. X.LP
  555. X.B str_component()
  556. Xreturns a pointer to the next substring or
  557. X.SM NULL
  558. Xif something goes wrong and \fIflags\fR & \fBSTR_RETURN_ERROR\fR is true.
  559. X.LP
  560. X.B str_setstr()
  561. Xreturns 
  562. X.SB STR_OK
  563. Xon success or
  564. X.SB STR_ERR
  565. Xon failure.
  566. X.LP
  567. X.B str_separator()
  568. Xreturns 
  569. X.SB STR_OK
  570. Xon success or
  571. X.SB STR_ERR
  572. Xon failure.
  573. X.LP
  574. X.B str_nextpos()
  575. Xreturns a pointer or
  576. X.SM NULL
  577. Xif the end of string has been reached.
  578. X.SH BUGS
  579. X.B str_component()
  580. Xmodifies the string unless \fBSTR_MALLOC\fR is
  581. Xset in the parser.
  582. X.LP
  583. XThere should be only one parser active on a specific string. If there
  584. Xis more than
  585. Xone, they all must use the \fBSTR_MALLOC\fR option.
  586. X
  587. END_OF_FILE
  588. if test 4130 -ne `wc -c <'libs/src/str/strparse.3'`; then
  589.     echo shar: \"'libs/src/str/strparse.3'\" unpacked with wrong size!
  590. fi
  591. # end of 'libs/src/str/strparse.3'
  592. fi
  593. if test -f 'libs/src/timer/Makefile' -a "${1}" != "-c" ; then 
  594.   echo shar: Will not clobber existing file \"'libs/src/timer/Makefile'\"
  595. else
  596. echo shar: Extracting \"'libs/src/timer/Makefile'\" \(4062 characters\)
  597. sed "s/^X//" >'libs/src/timer/Makefile' <<'END_OF_FILE'
  598. X# (c) Copyright 1993 by Panagiotis Tsirigotis
  599. X# All rights reserved.  The file named COPYRIGHT specifies the terms 
  600. X# and conditions for redistribution.
  601. X
  602. X#
  603. X# $Id: Makefile,v 5.1 93/11/26 12:38:00 panos Exp $
  604. X#
  605. X# Based on Library makefile template: *Revision: 1.15 *
  606. X#
  607. X
  608. X# 
  609. X# Available entries:
  610. X#         lib             --> creates the library
  611. X#        install        --> installs the library (archive, man page(s), header(s))
  612. X#        uninstall    --> uninstall the library
  613. X#        clean            --> removes all .o and .a files
  614. X#        spotless        --> clean + uninstall
  615. X#         lint            --> lints a file (usage: make lint MODULE=foo.c)
  616. X#        tags            --> creates a tags file (from the SOURCES and HEADERS)
  617. X#        checkout     --> checkout all files
  618. X#        dist            --> distribution support
  619. X#
  620. X
  621. XNAME                = timer
  622. XVERSION            = 1.3.0
  623. X
  624. XHEADERS            = timer.h impl.h ostimer.h timemacros.h defs.h
  625. XSOURCES            = timer.c ostimer.c sysdep.c
  626. XOBJECTS            = timer.o ostimer.o sysdep.o
  627. X
  628. XMANFILES            = timer.3 timemacros.3
  629. XINCLUDEFILES    = timer.h timemacros.h
  630. X
  631. X# The following variables are used by the 'install' entry and
  632. X# should be customized:
  633. X#     LIBDIR:     where the library will be placed
  634. X#     INCUDEDIR:  where the include files will be placed
  635. X#     MANDIR:     where the man pages will be placed
  636. X#
  637. XLIBDIR            = $(HOME)/.links/libraries/$(ARCH)
  638. XMANDIR            = $(HOME)/.links/manpages/man3
  639. XINCLUDEDIR        = $(HOME)/.links/includes
  640. X
  641. X#
  642. X# Available flags:
  643. X#
  644. X#    DEBUG                        :    enable some debugging code; terminate in case
  645. X#                                    of error
  646. X#    DEBUG_REPORT_ERRORS    :    print debugging messages
  647. X#    NO_POSIX_SIGS            :    sigaction is not available (but sigvec is)
  648. X#    NO_ITIMER_REAL         :    don't use ITIMER_REAL timers
  649. X#    NO_ITIMER_VIRTUAL        :    don't use ITIMER_VIRTUAL timers
  650. X#    NO_ITIMER_PROF         :    don't use ITIMER_PROF timers
  651. X#
  652. XDEFS                = -DDEBUG -DNO_POSIX_SIGS
  653. XDEBUG                = -g            # -g or -O
  654. XVERSION_DEF        = -DVERSION=\"TIMER\ Version\ $(VERSION)\"
  655. X
  656. XCPP_DEFS            = $(VERSION_DEF) $(DEFS)
  657. X
  658. X#
  659. X# The following variables shouldn't need to be changed
  660. X#
  661. XLINT_FLAGS        = -hbux
  662. XCPP_FLAGS        = $(CPP_DEFS) -I$(INCLUDEDIR)
  663. XCC_FLAGS            = $(DEBUG)
  664. XCFLAGS            = $(CPP_FLAGS) $(CC_FLAGS)
  665. X
  666. XINSTALL            = install -c
  667. XFMODE                = -m 640            # used by install
  668. XRANLIB            = ranlib
  669. X
  670. XPAGER                = less
  671. X
  672. X
  673. XLIBNAME            = lib$(NAME).a
  674. X
  675. Xlib: $(LIBNAME)
  676. X
  677. Xlibopt: clean
  678. X    make DEBUG=-O lib
  679. X    $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR)/optimized
  680. X
  681. X$(LIBNAME): $(OBJECTS)
  682. X    ar r $@ $?
  683. X    $(RANLIB) $@
  684. X
  685. Xlint:
  686. X    lint $(CPP_FLAGS) $(LINT_FLAGS) $(MODULE) 2>&1 | $(PAGER)
  687. X
  688. Xinstall: $(LIBNAME)
  689. X    @if test "$(LIBDIR)" -a "$(INCLUDEDIR)" -a "$(MANDIR)" ;\
  690. X    then \
  691. X        $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR) ;\
  692. X        echo "Installed $(LIBNAME) to $(LIBDIR)" ;\
  693. X        for i in $(INCLUDEFILES); do $(INSTALL) $(FMODE) $$i $(INCLUDEDIR) ; done ;\
  694. X        echo Installed $(INCLUDEFILES) to $(INCLUDEDIR) ;\
  695. X        for i in $(MANFILES) ; do $(INSTALL) $(FMODE) $$i $(MANDIR) ; done ;\
  696. X        echo Installed $(MANFILES) to $(MANDIR) ;\
  697. X    else \
  698. X        echo "You forgot to set one of the following variables: LIBDIR,INCLUDEDIR,MANDIR" ;\
  699. X    fi
  700. X
  701. Xuninstall:
  702. X    a=`pwd` ; cd $(INCLUDEDIR) ;\
  703. X    if test $$a != `pwd` ; then rm -f $(INCLUDEFILES) ; fi
  704. X    a=`pwd` ; cd $(LIBDIR) ;\
  705. X    if test $$a != `pwd` ; then rm -f $(LIBNAME) ; fi
  706. X    a=`pwd` ; cd $(MANDIR) ;\
  707. X    if test $$a != `pwd` ; then rm -f $(MANFILES) ; fi
  708. X
  709. Xclean:
  710. X    rm -f $(OBJECTS) $(LIBNAME) core
  711. X
  712. Xspotless: clean uninstall
  713. X
  714. Xtags: $(SOURCES) $(HEADERS)
  715. X    ctags -w $(SOURCES) $(HEADERS)
  716. X
  717. Xcheckout:
  718. X    co $(SOURCES) $(HEADERS) $(MANFILES)
  719. X
  720. X#
  721. X# Distribution section
  722. X# This section contains the 2 targets for distribution support: dist, dirs
  723. X# "dist" checks out all files to be distributed
  724. X# "dirs" prints a list of directories to be included in the distribution.
  725. X# These directories should have a Makefile with a "dist" target
  726. X#
  727. XDISTRIBUTION_FILES    = $(SOURCES) $(HEADERS) $(MANFILES) COPYRIGHT STATES
  728. XDIRS                        =
  729. X
  730. Xdist:
  731. X    -co -q $(DISTRIBUTION_FILES)
  732. X
  733. Xdirs:
  734. X    @echo $(DIRS)
  735. X
  736. X#
  737. X# PUT HERE THE RULES TO MAKE THE OBJECT FILES
  738. X#
  739. Xtimer.o:        timemacros.h impl.h timer.h defs.h
  740. Xostimer.o:    ostimer.h timemacros.h impl.h timer.h defs.h
  741. Xsysdep.o:    ostimer.h timemacros.h impl.h timer.h defs.h
  742. X
  743. Xttest: ttest.c $(LIBNAME)
  744. X    cc $(DEBUG) -o $@ ttest.c $(LIBNAME) -L$(LIBDIR) -lpq
  745. X
  746. END_OF_FILE
  747. if test 4062 -ne `wc -c <'libs/src/timer/Makefile'`; then
  748.     echo shar: \"'libs/src/timer/Makefile'\" unpacked with wrong size!
  749. fi
  750. # end of 'libs/src/timer/Makefile'
  751. fi
  752. if test -f 'libs/src/timer/timemacros.h' -a "${1}" != "-c" ; then 
  753.   echo shar: Will not clobber existing file \"'libs/src/timer/timemacros.h'\"
  754. else
  755. echo shar: Extracting \"'libs/src/timer/timemacros.h'\" \(3697 characters\)
  756. sed "s/^X//" >'libs/src/timer/timemacros.h' <<'END_OF_FILE'
  757. X/*
  758. X * (c) Copyright 1993 by Panagiotis Tsirigotis
  759. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  760. X * and conditions for redistribution.
  761. X */
  762. X
  763. X#ifndef __TIMEMACROS_H
  764. X#define __TIMEMACROS_H
  765. X
  766. X/*
  767. X * $Id: timemacros.h,v 5.1 93/11/26 12:10:31 panos Exp $
  768. X */
  769. X
  770. X#include <sys/types.h>
  771. X#include <sys/time.h>
  772. X
  773. X/*
  774. X * Define a few relevant NULL values
  775. X */
  776. X#ifndef TIMEZONE_NULL
  777. X#define TIMEZONE_NULL        ((struct timezone *)0)
  778. X#endif
  779. X#ifndef TIMEVAL_NULL
  780. X#define TIMEVAL_NULL            ((struct timeval *)0)
  781. X#endif
  782. X#ifndef ITIMERVAL_NULL
  783. X#define ITIMERVAL_NULL        ((struct itimerval *)0)
  784. X#endif
  785. X
  786. X/*
  787. X * The TV_* macros work with timeval structures.
  788. X * The TVP_* macros work with pointers to timeval structures.
  789. X *
  790. X * We support the following operations:
  791. X *
  792. X *            EQ( tv1, tv2 )            : tv1 == tv2
  793. X *            NE( tv1, tv2 )            : tv1 != tv2
  794. X *            LT( tv1, tv2 )            : tv1 <  tv2
  795. X *            LE( tv1, tv2 )            : tv1 <= tv2
  796. X *            GT( tv1, tv2 )            : tv1 >  tv2
  797. X *            GE( tv1, tv2 )            : tv1 >= tv2
  798. X *            ISZERO( tv )            : tv == 0
  799. X *            ZERO( tv )                : tv = 0
  800. X *            ADD( res, tv1, tv2 ) : res = tv1 + tv2
  801. X *            SUB( res, tv1, tv2 ) : res = tv1 = tv2
  802. X *
  803. X * We make sure the result is normalized after addition and subtraction.
  804. X */
  805. X
  806. X#define __ONE_MILLION                    1000000
  807. X
  808. X#define TV_ADD( tv_res, tv1, tv2 )                                    \
  809. X    {                                                                            \
  810. X        (tv_res).tv_sec = (tv1).tv_sec + (tv2).tv_sec ;            \
  811. X        (tv_res).tv_usec = (tv1).tv_usec + (tv2).tv_usec ;        \
  812. X        if ( (tv_res).tv_usec >= __ONE_MILLION )                    \
  813. X        {                                                                        \
  814. X            (tv_res).tv_sec++ ;                                            \
  815. X            (tv_res).tv_usec -= __ONE_MILLION ;                        \
  816. X        }                                                                        \
  817. X    }
  818. X
  819. X/*
  820. X * We handle the possibility of underflow in advance in case
  821. X * tv_usec is an unsigned integer.
  822. X */
  823. X#define TV_SUB( tv_res, tv1, tv2 )                                    \
  824. X    {                                                                            \
  825. X        if ( (tv1).tv_usec < (tv2).tv_usec )                        \
  826. X        {                                                                        \
  827. X            (tv1).tv_usec += __ONE_MILLION ;                            \
  828. X            (tv1).tv_sec-- ;                                                \
  829. X        }                                                                        \
  830. X        (tv_res).tv_sec = (tv1).tv_sec - (tv2).tv_sec ;            \
  831. X        (tv_res).tv_usec = (tv1).tv_usec - (tv2).tv_usec ;        \
  832. X    }
  833. X
  834. X#define TV_LT( tv1, tv2 )                                                                    \
  835. X        ( (tv1).tv_sec < (tv2).tv_sec ||                                                    \
  836. X          (tv1).tv_sec == (tv2).tv_sec && (tv1).tv_usec < (tv2).tv_usec )
  837. X
  838. X#define TV_LE( tv1, tv2 )                                                                    \
  839. X        ( (tv1).tv_sec < (tv2).tv_sec ||                                                    \
  840. X          (tv1).tv_sec == (tv2).tv_sec && (tv1).tv_usec <= (tv2).tv_usec )
  841. X
  842. X#define TV_GT( tv1, tv2 )                                                                    \
  843. X        ( (tv1).tv_sec > (tv2).tv_sec ||                                                    \
  844. X          (tv1).tv_sec == (tv2).tv_sec && (tv1).tv_usec > (tv2).tv_usec )
  845. X
  846. X#define TV_GE( tv1, tv2 )                                                                    \
  847. X        ( (tv1).tv_sec > (tv2).tv_sec ||                                                    \
  848. X          (tv1).tv_sec == (tv2).tv_sec && (tv1).tv_usec >= (tv2).tv_usec )
  849. X
  850. X#define TV_EQ( tv1, tv2 )                                                                    \
  851. X        ( (tv1).tv_sec == (tv2).tv_sec && (tv1).tv_usec == (tv2).tv_usec )
  852. X
  853. X#define TV_NE( tv1, tv2 )                                                                    \
  854. X        ( (tv1).tv_sec != (tv2).tv_sec || (tv1).tv_usec != (tv2).tv_usec )
  855. X
  856. X#define TV_ISZERO( tv )            ( (tv).tv_sec == 0 && (tv).tv_usec == 0 )
  857. X
  858. X#define TV_ZERO( tv )            (tv).tv_sec = (tv).tv_usec = 0
  859. X
  860. X
  861. X/*
  862. X * Pointer macros
  863. X */
  864. X
  865. X#define TVP_ADD( tvp_res, tvp1, tvp2 )    TV_ADD( *(tvp_res), *(tvp1), *(tvp2) )
  866. X#define TVP_SUB( tvp_res, tvp1, tvp2 )    TV_SUB( *(tvp_res), *(tvp1), *(tvp2) )
  867. X#define TVP_LT( tvp1, tvp2 )                TV_LT( *(tvp1), *(tvp2) )
  868. X#define TVP_LE( tvp1, tpv2 )                TV_LE( *(tvp1), *(tvp2) )
  869. X#define TVP_GT( tvp1, tvp2 )                TV_GT( *(tvp1), *(tvp2) )
  870. X#define TVP_GE( tvp1, tvp2 )                TV_GE( *(tvp1), *(tvp2) )
  871. X#define TVP_EQ( tvp1, tvp2 )                TV_EQ( *(tvp1), *(tvp2) )
  872. X#define TVP_NE( tvp1, tvp2 )                TV_NE( *(tvp1), *(tvp2) )
  873. X#define TVP_ISZERO( tvp )                    TV_ISZERO( *(tvp) )
  874. X#define TVP_ZERO( tvp )                        TV_ZERO( *(tvp) )
  875. X
  876. X#endif    /* __TIMEMACROS_H */
  877. END_OF_FILE
  878. if test 3697 -ne `wc -c <'libs/src/timer/timemacros.h'`; then
  879.     echo shar: \"'libs/src/timer/timemacros.h'\" unpacked with wrong size!
  880. fi
  881. # end of 'libs/src/timer/timemacros.h'
  882. fi
  883. if test -f 'libs/src/xlog/Makefile' -a "${1}" != "-c" ; then 
  884.   echo shar: Will not clobber existing file \"'libs/src/xlog/Makefile'\"
  885. else
  886. echo shar: Extracting \"'libs/src/xlog/Makefile'\" \(3745 characters\)
  887. sed "s/^X//" >'libs/src/xlog/Makefile' <<'END_OF_FILE'
  888. X# (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  889. X# All rights reserved.  The file named COPYRIGHT specifies the terms 
  890. X# and conditions for redistribution.
  891. X
  892. X#
  893. X# $Id: Makefile,v 2.4 1993/10/28 01:39:07 panos Exp $
  894. X#
  895. X# Based on Library makefile template: *Revision: 1.15 *
  896. X#
  897. X
  898. X# 
  899. X# Available entries:
  900. X#         lib             --> creates the library
  901. X#        install        --> installs the library (archive, man page(s), header(s))
  902. X#        uninstall    --> uninstall the library
  903. X#        clean            --> removes all .o and .a files
  904. X#        spotless        --> clean + uninstall
  905. X#         lint            --> lints a file (usage: make lint MODULE=foo.c)
  906. X#        tags            --> creates a tags file (from the SOURCES and HEADERS)
  907. X#        checkout     --> checkout all files
  908. X#        dist            --> distribution support
  909. X#
  910. X
  911. XNAME                = xlog
  912. XVERSION            = 1.1.3
  913. X
  914. XHEADERS            = xlog.h impl.h slog.h filelog.h
  915. XSOURCES            = xlog.c filelog.c slog.c util.c
  916. XOBJECTS            = xlog.o filelog.o slog.o util.o
  917. X
  918. XMANFILES            = xlog.3
  919. XINCLUDEFILES    = xlog.h
  920. X
  921. X# The following variables are used by the 'install' entry and
  922. X# should be customized:
  923. X#     LIBDIR:     where the library will be placed
  924. X#     INCUDEDIR:  where the include files will be placed
  925. X#     MANDIR:     where the man pages will be placed
  926. X#
  927. XLIBDIR            = $(HOME)/.links/libraries/$(ARCH)
  928. XMANDIR            = $(HOME)/.links/manpages/man3
  929. XINCLUDEDIR        = $(HOME)/.links/includes
  930. X
  931. X#
  932. X# Flags:
  933. X#     -DNO_SYSLOG            : do not use syslog
  934. X#        -DSYSLOG_IN_SYS    : syslog.h is in /usr/include/sys
  935. X#
  936. XDEFS                =
  937. X
  938. XDEBUG                = -g            # -g or -O
  939. XVERSION_DEF        = -DVERSION=\"XLOG\ Version\ $(VERSION)\"
  940. X
  941. XCPP_DEFS            = $(VERSION_DEF) $(DEFS)
  942. X
  943. X#
  944. X# The following variables shouldn't need to be changed
  945. X#
  946. XLINT_FLAGS        = -hbux
  947. XCPP_FLAGS        = $(CPP_DEFS) -I$(INCLUDEDIR)
  948. XCC_FLAGS            = $(DEBUG)
  949. XCFLAGS            = $(CPP_FLAGS) $(CC_FLAGS)
  950. X
  951. XINSTALL            = install -c
  952. XFMODE                = -m 640            # used by install
  953. XRANLIB            = ranlib
  954. X
  955. XPAGER                = less
  956. X
  957. X
  958. XLIBNAME            = lib$(NAME).a
  959. X
  960. Xlib: $(LIBNAME)
  961. X
  962. Xlibopt: clean
  963. X    make DEBUG=-O "DEFS=$(DEFS)" lib
  964. X    $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR)/optimized
  965. X
  966. X$(LIBNAME): $(OBJECTS)
  967. X    ar r $@ $?
  968. X    $(RANLIB) $@
  969. X
  970. Xlint:
  971. X    lint $(CPP_FLAGS) $(LINT_FLAGS) $(MODULE) 2>&1 | grep -v 'possible pointer alignment' | $(PAGER)
  972. X
  973. Xinstall: $(LIBNAME)
  974. X    @if test "$(LIBDIR)" -a "$(INCLUDEDIR)" -a "$(MANDIR)" ;\
  975. X    then \
  976. X        $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR) ;\
  977. X        echo "Installed $(LIBNAME) to $(LIBDIR)" ;\
  978. X        for i in $(INCLUDEFILES); do $(INSTALL) $(FMODE) $$i $(INCLUDEDIR) ; done ;\
  979. X        echo Installed $(INCLUDEFILES) to $(INCLUDEDIR) ;\
  980. X        for i in $(MANFILES) ; do $(INSTALL) $(FMODE) $$i $(MANDIR) ; done ;\
  981. X        echo Installed $(MANFILES) to $(MANDIR) ;\
  982. X    else \
  983. X        echo "You forgot to set one of the following variables: LIBDIR,INCLUDEDIR,MANDIR" ;\
  984. X    fi
  985. X
  986. Xuninstall:
  987. X    a=`pwd` ; cd $(INCLUDEDIR) ;\
  988. X    if test $$a != `pwd` ; then rm -f $(INCLUDEFILES) ; fi
  989. X    a=`pwd` ; cd $(LIBDIR) ;\
  990. X    if test $$a != `pwd` ; then rm -f $(LIBNAME) ; fi
  991. X    a=`pwd` ; cd $(MANDIR) ;\
  992. X    if test $$a != `pwd` ; then rm -f $(MANFILES) ; fi
  993. X
  994. Xclean:
  995. X    rm -f $(OBJECTS) $(LIBNAME) core
  996. X
  997. Xspotless: clean uninstall
  998. X
  999. Xtags: $(SOURCES) $(HEADERS)
  1000. X    ctags -w $(SOURCES) $(HEADERS)
  1001. X
  1002. Xcheckout:
  1003. X    co $(SOURCES) $(HEADERS) $(MANFILES)
  1004. X
  1005. X#
  1006. X# Distribution section
  1007. X# This section contains the 2 targets for distribution support: dist, dirs
  1008. X# "dist" checks out all files to be distributed
  1009. X# "dirs" prints a list of directories to be included in the distribution.
  1010. X# These directories should have a Makefile with a "dist" target
  1011. X#
  1012. XDISTRIBUTION_FILES    = $(SOURCES) $(HEADERS) $(MANFILES) COPYRIGHT
  1013. XDIRS                        =
  1014. X
  1015. Xdist:
  1016. X    -co -q $(DISTRIBUTION_FILES)
  1017. X
  1018. Xdirs:
  1019. X    @echo $(DIRS)
  1020. X
  1021. X#
  1022. X# PUT HERE THE RULES TO MAKE THE OBJECT FILES
  1023. X#
  1024. Xxlog.o:            xlog.h impl.h
  1025. Xfilelog.o:        xlog.h impl.h filelog.h
  1026. Xslog.o:            xlog.h impl.h slog.h
  1027. X
  1028. X#
  1029. X# Test program
  1030. X#
  1031. Xxlt: xlt.c $(LIBNAME)
  1032. X    $(CC) -g -o $@ xlt.c $(LIBNAME) -L$(LIBDIR) -lstr -lsio
  1033. X
  1034. X
  1035. END_OF_FILE
  1036. if test 3745 -ne `wc -c <'libs/src/xlog/Makefile'`; then
  1037.     echo shar: \"'libs/src/xlog/Makefile'\" unpacked with wrong size!
  1038. fi
  1039. # end of 'libs/src/xlog/Makefile'
  1040. fi
  1041. if test -f 'libs/src/xlog/slog.c' -a "${1}" != "-c" ; then 
  1042.   echo shar: Will not clobber existing file \"'libs/src/xlog/slog.c'\"
  1043. else
  1044. echo shar: Extracting \"'libs/src/xlog/slog.c'\" \(4152 characters\)
  1045. sed "s/^X//" >'libs/src/xlog/slog.c' <<'END_OF_FILE'
  1046. X/*
  1047. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  1048. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  1049. X * and conditions for redistribution.
  1050. X */
  1051. X
  1052. Xstatic char RCSid[] = "$Id: slog.c,v 2.3 1993/10/28 01:37:48 panos Exp $" ;
  1053. X
  1054. X#include <varargs.h>
  1055. X
  1056. X#ifndef NO_SYSLOG
  1057. X#    ifndef SYSLOG_IN_SYS
  1058. X#        include <syslog.h>
  1059. X#    else
  1060. X#        include <sys/syslog.h>
  1061. X#    endif
  1062. X#endif
  1063. X
  1064. X#include "xlog.h"
  1065. X#include "impl.h"
  1066. X#include "slog.h"
  1067. X
  1068. X#define MSGBUFSIZE            2048
  1069. X
  1070. X
  1071. XPRIVATE int syslog_init() ;
  1072. XPRIVATE void syslog_fini() ;
  1073. XPRIVATE int syslog_control() ;
  1074. XPRIVATE int syslog_write() ;
  1075. XPRIVATE int syslog_parms() ;
  1076. X
  1077. Xstatic struct syslog_parms parms =
  1078. X   {
  1079. X      0,
  1080. X#ifndef NO_SYSLOG
  1081. X
  1082. X#ifdef LOG_PID
  1083. X        LOG_PID +
  1084. X#endif
  1085. X#ifdef LOG_NOWAIT
  1086. X        LOG_NOWAIT +
  1087. X#endif
  1088. X        0,
  1089. X      LOG_USER,
  1090. X
  1091. X#else        /* NO_SYSLOG */
  1092. X
  1093. X        0,
  1094. X        0,
  1095. X
  1096. X#endif    /* ! NO_SYSLOG */
  1097. X      "XLOG"
  1098. X   } ;
  1099. X
  1100. X
  1101. Xstruct xlog_ops __xlog_syslog_ops =
  1102. X    {
  1103. X        syslog_init,
  1104. X        syslog_fini,
  1105. X        syslog_write,
  1106. X        syslog_control,
  1107. X        syslog_parms
  1108. X    } ;
  1109. X
  1110. X#ifdef NO_SYSLOG
  1111. X
  1112. X/*
  1113. X * Notice that the following functions will never be invoked since
  1114. X * the xlog_* functions will not call them. However, we need to define
  1115. X * them so that we don't have any unresolved references; and we define 
  1116. X * them without any arguments.
  1117. X */
  1118. XPRIVATE void syslog()
  1119. X{
  1120. X}
  1121. X
  1122. XPRIVATE void openlog()
  1123. X{
  1124. X}
  1125. X
  1126. XPRIVATE void closelog()
  1127. X{
  1128. X}
  1129. X
  1130. X#else
  1131. X
  1132. Xvoid closelog() ;
  1133. X
  1134. X#endif    /* NO_SYSLOG */
  1135. X
  1136. X
  1137. X/*
  1138. X * Expected arguments:
  1139. X *        facility, level
  1140. X */
  1141. XPRIVATE int syslog_init( xp, ap )
  1142. X    xlog_s    *xp ;
  1143. X    va_list    ap ;
  1144. X{
  1145. X    register struct syslog_parms    *slp = &parms ;
  1146. X    struct syslog                        *sp ;
  1147. X
  1148. X    sp = NEW( struct syslog ) ;
  1149. X    if ( sp == NULL )
  1150. X        return( XLOG_ENOMEM ) ;
  1151. X    
  1152. X    sp->sl_facility = va_arg( ap, int ) ;
  1153. X    sp->sl_default_level = va_arg( ap, int ) ;
  1154. X    if ( slp->slp_n_xlogs++ == 0 )
  1155. X        openlog( slp->slp_ident, slp->slp_logopts, slp->slp_facility ) ;
  1156. X    xp->xl_data = sp ;
  1157. X    return( XLOG_ENOERROR ) ;
  1158. X}
  1159. X
  1160. X
  1161. XPRIVATE void syslog_fini( xp )
  1162. X    xlog_s *xp ;
  1163. X{
  1164. X    if ( --parms.slp_n_xlogs == 0 )
  1165. X        closelog() ;
  1166. X    FREE( SYSLOG( xp ) ) ;
  1167. X    xp->xl_data = NULL ;
  1168. X}
  1169. X
  1170. X
  1171. XPRIVATE int syslog_control( xp, cmd, ap )
  1172. X    xlog_s        *xp ;
  1173. X    xlog_cmd_e    cmd ;
  1174. X    va_list        ap ;
  1175. X{
  1176. X    switch ( cmd )
  1177. X    {
  1178. X        case XLOG_LEVEL:
  1179. X            SYSLOG( xp )->sl_default_level = va_arg( ap, int ) ;
  1180. X            break ;
  1181. X
  1182. X        case XLOG_FACILITY:
  1183. X            SYSLOG( xp )->sl_facility = va_arg( ap, int ) ;
  1184. X            break ;
  1185. X        
  1186. X        case XLOG_PREEXEC:
  1187. X            closelog() ;
  1188. X            break ;
  1189. X
  1190. X        case XLOG_POSTEXEC:
  1191. X            if ( parms.slp_n_xlogs )
  1192. X                openlog( parms.slp_ident, parms.slp_logopts, parms.slp_facility ) ;
  1193. X            break ;
  1194. X        
  1195. X        case XLOG_GETFD:
  1196. X            return( XLOG_EBADOP ) ;
  1197. X    }
  1198. X    return( XLOG_ENOERROR ) ;
  1199. X}
  1200. X
  1201. X
  1202. XPRIVATE int syslog_write( xp, buf, len, flags, ap )
  1203. X    xlog_s    *xp ;
  1204. X    char        buf[] ;
  1205. X    int        len ;
  1206. X    int        flags ;
  1207. X    va_list    ap ;
  1208. X{
  1209. X    int    level ;
  1210. X    int    syslog_arg ;
  1211. X    char    prefix[ MSGBUFSIZE ] ;
  1212. X    int    prefix_size = sizeof( prefix ) ;
  1213. X    int    prefix_len = 0 ;
  1214. X    int    cc ;
  1215. X    char    *percent_m_pos ;
  1216. X    int    action_flags = ( flags | xp->xl_flags ) ;
  1217. X
  1218. X    if ( flags & XLOG_SET_LEVEL )
  1219. X        level = va_arg( ap, int ) ;
  1220. X    else
  1221. X        level = SYSLOG( xp )->sl_default_level ;
  1222. X    syslog_arg = SYSLOG( xp )->sl_facility + level ;
  1223. X
  1224. X    if ( action_flags & XLOG_PRINT_ID )
  1225. X    {
  1226. X        cc = strx_nprint( &prefix[ prefix_len ], prefix_size, "%s: ",
  1227. X                            xp->xl_id ) ;
  1228. X        prefix_len += cc ;
  1229. X        prefix_size -= cc ;
  1230. X    }
  1231. X
  1232. X    if ( ( action_flags & XLOG_NO_ERRNO ) ||
  1233. X                        ( percent_m_pos = __xlog_add_errno( buf, len ) ) == NULL )
  1234. X        syslog( syslog_arg, "%.*s%.*s", prefix_len, prefix, len, buf ) ;
  1235. X    else
  1236. X    {
  1237. X        int cc_before_errno = percent_m_pos - buf ;
  1238. X        int cc_after_errno = len - cc_before_errno - 2 ;
  1239. X        char *ep ;
  1240. X        char errno_buf[ 100 ] ;
  1241. X        unsigned size = sizeof( errno_buf ) ;
  1242. X        
  1243. X        ep = __xlog_explain_errno( errno_buf, &size ) ;
  1244. X        syslog( syslog_arg, "%.*s%.*s%.*s%.*s",
  1245. X                prefix_len, prefix,
  1246. X                    cc_before_errno, buf,
  1247. X                        (int)size, ep,
  1248. X                            cc_after_errno, &percent_m_pos[ 2 ] ) ;
  1249. X    }
  1250. X    return( XLOG_ENOERROR ) ;
  1251. X}
  1252. X
  1253. X
  1254. XPRIVATE int syslog_parms( ap )
  1255. X    va_list ap ;
  1256. X{
  1257. X    char *__xlog_new_string() ;
  1258. X    char *id = __xlog_new_string( va_arg( ap, char * ) ) ;
  1259. X
  1260. X    if ( id == NULL )
  1261. X        return( XLOG_ENOMEM ) ;
  1262. X    parms.slp_ident = id ;
  1263. X    parms.slp_logopts = va_arg( ap, int ) ;
  1264. X    parms.slp_facility = va_arg( ap, int ) ;
  1265. X    return( XLOG_ENOERROR ) ;
  1266. X}
  1267. X
  1268. END_OF_FILE
  1269. if test 4152 -ne `wc -c <'libs/src/xlog/slog.c'`; then
  1270.     echo shar: \"'libs/src/xlog/slog.c'\" unpacked with wrong size!
  1271. fi
  1272. # end of 'libs/src/xlog/slog.c'
  1273. fi
  1274. echo shar: End of archive 8 \(of 20\).
  1275. cp /dev/null ark8isdone
  1276. MISSING=""
  1277. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ; do
  1278.     if test ! -f ark${I}isdone ; then
  1279.     MISSING="${MISSING} ${I}"
  1280.     fi
  1281. done
  1282. if test "${MISSING}" = "" ; then
  1283.     echo You have unpacked all 20 archives.
  1284.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1285. else
  1286.     echo You still need to unpack the following archives:
  1287.     echo "        " ${MISSING}
  1288. fi
  1289. ##  End of shell archive.
  1290. exit 0
  1291.