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

  1. Newsgroups: comp.sources.unix
  2. From: panos@anchor.cs.colorado.edu (Panos Tsirigotis)
  3. Subject: v27i120: clc - C Libraries Collection, Part14/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 120
  10. Archive-Name: clc/part14
  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 14 (of 20)."
  19. # Contents:  INSTALL libs/src/sio/suite/print.c libs/src/timer/sysdep.c
  20. # Wrapped by panos@eclipse on Sun Nov 28 14:48:17 1993
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'INSTALL' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'INSTALL'\"
  24. else
  25. echo shar: Extracting \"'INSTALL'\" \(7979 characters\)
  26. sed "s/^X//" >'INSTALL' <<'END_OF_FILE'
  27. X---------------------------------------------------------------------------
  28. XNOTE: You may want to set your tabstop to 3; this will make everything
  29. X      look properly indented.
  30. X---------------------------------------------------------------------------
  31. X
  32. X
  33. X1. Distribution
  34. X
  35. XThis library package is distributed in shar archive kit form. After all
  36. Xthe archives are unpacked, you should end up with the following
  37. Xdirectory structure:
  38. X
  39. X    README                :    You should read this file first
  40. X    INSTALL                :    This is this file
  41. X    Makefile                :    Top-level makefile
  42. X    libconf                :    Shell script for configuration support
  43. X    fixman                :    Shell script for fixing man pages
  44. X    sysinc                :    Shell script to create protected header files (you
  45. X                                may not need this)
  46. X    ./libs                
  47. X    ./libs/include
  48. X    ./libs/man
  49. X    ./libs/lib
  50. X    ./libs/src/{sio,str,pset,misc,xlog,timer,pq,fsma,dict}
  51. X
  52. X
  53. X
  54. X2. Requirements
  55. X
  56. XThe TIMER library requires a system that supports the setitimer(2)
  57. Xsystem call, and either the sigvec(2) or sigaction(2) system calls. If
  58. Xthese are not available on your system, this library will be useless.
  59. XThe rest of the libraries should work on any UNIX system.
  60. X
  61. X
  62. X3. Compiling
  63. X
  64. XYou can compile the libraries using the top level Makefile, or
  65. Xyou may go to each library directory and use the Makefile there.
  66. XIn the following I will assume the former approach.
  67. X
  68. X
  69. X3.1. Library dependencies
  70. X
  71. XSome of the libraries depend on others (i.e. they expect the header
  72. Xfiles exported by those libraries), so there are restrictions on
  73. Xthe order of compilation. The dependency list is as follows:
  74. X
  75. XSTR             depends on         SIO
  76. XTIMER            depends on        PQ
  77. XDICT            depends on        FSMA
  78. XXLOG            depends on        SIO
  79. X
  80. XThe only dependency you can work around is that of STR on SIO (in case
  81. Xyou want to use STR but not SIO). Check the README in libs/src/str
  82. Xfor more information. In the following, I will assume that SIO will
  83. Xalso be used.
  84. X
  85. XThe top level Makefile handles the compilation order correctly.
  86. X
  87. X
  88. X
  89. X3.2. Compiling using the top level Makefile
  90. X
  91. XThe majority of the libraries should compile without any problem.  The
  92. Xonly possible exceptions are SIO, XLOG and TIMER because they depend on
  93. Xfacilities provided by the operating system. You can customize these
  94. Xlibraries for your system using appropriate preprocessor flags.  These
  95. Xflags are documented in the makefiles of the particular libraries, as
  96. Xwell as on the top level Makefile.
  97. X
  98. XIf your system is running SunOS 4.x, Solaris 2.x, Ultrix 4.x, or if it
  99. Xis POSIX-compatible, you can find the appropriate flag settings in the
  100. Xtop level Makefile.  If your system is not among those, you have two
  101. Xoptions: you can either check the top level Makefile for the particular
  102. Xflags that may need to be set, or you can use the libconf script whose
  103. Xpurpose is to determine the appropriate flags for your system.
  104. X
  105. Xlibconf relies on being able to interpret correctly the output of the
  106. X'nm' command. The distributed version of the script relies on BSD
  107. X4.3-style output. In this output, each symbol in an object file is
  108. Xpreceded by the letter 'T' if it is a function, or by the letter 'D' if
  109. Xit is a variable. The libconf script variables "nm_defined_func" and
  110. X"nm_defined_var" are set to these letters.  If the output of 'nm' on
  111. Xyour system uses different conventions for determining what is a
  112. Xfunction and what is a variable, you should change the values of those
  113. Xtwo variables accordingly. Note that these values can be arbitrary
  114. Xregular expressions (which are parsed by egrep), not just single
  115. Xletters.
  116. X
  117. XFinally, the library man pages make use of the ".SB" request, which
  118. Xreduces the size of the following text by one point and makes it
  119. Xboldface. This is available on SunOS 4.x, but may not be available on
  120. Xyour system. If that is the case, you can use the fixman script to
  121. Xconvert all occurrences of ".SB" to ".B". The script is invoked with
  122. X    fixman manpage manpage ...
  123. XIf the script modifies a manpage, it will also save the original in a
  124. Xfile named after the manpage, with the string ".orig" appended to its
  125. Xname.  For example, if sio.3 is modified, then sio.3.orig will be the
  126. Xoriginal man page.
  127. X
  128. X
  129. X
  130. X3.3. Library creation and installation
  131. X
  132. XSince some libraries depend on others, the top level Makefile does not
  133. Xsimply compile each library, but also installs it. The installation
  134. Xprocess is controlled by the Makefile variables LIBDIR (the .a files
  135. Xwill go here), INCLUDEDIR (the include files will go here), and MANDIR
  136. X(the man pages will go here).
  137. X
  138. XBy default, the top level Makefile assumes that the 'ranlib' command
  139. Xneeds to be applied to each library archive. This is true for
  140. XBSD-derived systems, but is may be unnecessary for other systems (for
  141. Xexample, System V-derived systems). If this is the case for your
  142. Xsystem, you should set the RANLIB variable in the top level Makefile to
  143. X'true'.
  144. X
  145. XThe other possible installation complication is the 'install' command.
  146. XThe top level Makefile assumes a BSD 4.3-compatible install command
  147. Xthat accepts the "-c" option. If your system does not have such a
  148. Xcommand, use the following settings:
  149. X    INSTALL    = cp
  150. X    FMODE        =
  151. XIf your system has such a command but not at a standard place, set the
  152. XINSTALL variable to the pathname of the command (for example, for
  153. XSVR4-compatible systems, set INSTALL to "/usr/ucb/install -c".
  154. X
  155. XYou can undo an installation by typing "make uninstall". However, the
  156. Xvalues of the variables LIBDIR, INCLUDEDIR, and MANDIR should not have
  157. Xchanged since the last "make install".
  158. X
  159. X
  160. X
  161. X4. Compilation problems
  162. X
  163. X4.1. Unprotected system include files
  164. X
  165. XTypically, system include files start with the protective sequence
  166. X
  167. X#ifndef __special_flag
  168. X#define __special_flag
  169. X....
  170. X#endif
  171. X
  172. XThis allows the file to be included multiple times without a
  173. Xcompilation error. Some of the libraries rely on this property, so on
  174. Xsystems that don't have such include files, those libraries will fail
  175. Xto compile.
  176. X
  177. XTo circumvent this problem, I have provided the 'sysinc' script, which
  178. Xcan be used as follows:
  179. X
  180. X   sysinc -d <clone_dir> header_files_and_C_files_of_all_libraries
  181. X
  182. XThe script will find all the system include files used by the specified
  183. Xheader and C-source files, and then it will create a "clone" directory
  184. Xstructure of include files with the same name as the system include
  185. Xfiles, under "clone_dir". These clone files will have the protective
  186. Xsequence, and will include the corresponding system include files.
  187. X
  188. XYou can then set the SYSINC variable of the top level Makefile as follows:
  189. X    SYSINC = -I<clone_dir>
  190. XNote that "clone_dir" should be an absolute pathname.
  191. X
  192. X4.2. C compiler does not support 'void *' pointers
  193. X
  194. X   libs/src/pset/pset.h:   change the typedef of __pset_pointer from 'void *'
  195. X                           to 'char *'
  196. X   libs/src/xlog/xlog.h:   change the typedef of xlog_h from 'void *'
  197. X                           to 'char *'
  198. X   libs/src/xlog/impl.h:   in 'struct xlog' change the type of the
  199. X                           xl_callback_arg and xl_data fields from 'void *'
  200. X                           to 'char *'
  201. X   libs/src/pq/pq.h:       change the typedefs of pq_h and pq_obj from
  202. X                           'void *' to 'char *'
  203. X   libs/src/timer/timer.h: in 'struct timer_action' change the type of the
  204. X                           ta_arg field from 'void *' to 'char *';
  205. X                           also change the typedef of timer_h from 'void *'
  206. X                           to 'char *'
  207. X   libs/src/timer/timer.c: in the line:
  208. X                              void  *arg        = tp->t_action.ta_arg ;
  209. X                           change the type of 'arg' from 'void *' to 'char *'
  210. X
  211. XYou may wonder why there is no '#ifdef' for this problem. The reason is
  212. Xthat decent C compilers have supported 'void *' pointers since a long time,
  213. Xand there is now a free C compiler, gcc, that also supports such pointers.
  214. XTherefore, I don't want to overburden the code with more '#ifdefs' just
  215. Xfor the sake of outdated C compilers.
  216. X
  217. X
  218. X5. Epilogue
  219. X
  220. XPlease send all comments/suggestions/bug-reports to panos@cs.colorado.edu
  221. X
  222. X    -- Panos Tsirigotis, Nov. 26, 1993 --
  223. X
  224. END_OF_FILE
  225. if test 7979 -ne `wc -c <'INSTALL'`; then
  226.     echo shar: \"'INSTALL'\" unpacked with wrong size!
  227. fi
  228. # end of 'INSTALL'
  229. fi
  230. if test -f 'libs/src/sio/suite/print.c' -a "${1}" != "-c" ; then 
  231.   echo shar: Will not clobber existing file \"'libs/src/sio/suite/print.c'\"
  232. else
  233. echo shar: Extracting \"'libs/src/sio/suite/print.c'\" \(8243 characters\)
  234. sed "s/^X//" >'libs/src/sio/suite/print.c' <<'END_OF_FILE'
  235. X/*
  236. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  237. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  238. X * and conditions for redistribution.
  239. X */
  240. X
  241. Xstatic char RCSid[] = "$Id: print.c,v 8.1 1993/03/13 01:21:48 panos Exp $" ;
  242. X
  243. X#include <stdio.h>
  244. X#include <math.h>
  245. X#include <values.h>
  246. X#include <string.h>
  247. X
  248. X#include "sio.h"
  249. X
  250. X#define FLUSH()            fflush( stdout ) ; Sflush( 1 )
  251. X#define COMPARE( printf_count, sprint_count )                                        \
  252. X                            if ( printf_count != sprint_count )                            \
  253. X                                printf( "printf_count = %d, sprint_count = %d\n",    \
  254. X                                            printf_count, sprint_count )
  255. X
  256. Xenum bool { NO = 0, YES = 1 } ;
  257. X
  258. Xenum test_flag
  259. X{
  260. X    DECIMAL, HEX, CAP_HEX, OCTAL, UNSIGNED,
  261. X    F_FLOAT, G_FLOAT, E_FLOAT, CAP_E_FLOAT, CAP_G_FLOAT,
  262. X    CHAR, STRING,
  263. X    POINTER,
  264. X    BOUND,
  265. X    N_FLAGS
  266. X} ;
  267. X
  268. Xtypedef enum test_flag FLAG ;
  269. X
  270. X#define CHECK( f )                if ( ! flags[ f ] ) return
  271. X
  272. X/*
  273. X * Flags
  274. X */
  275. Xenum bool flags[ N_FLAGS ] ;
  276. X
  277. Xchar *precision ;
  278. Xchar *width ;
  279. Xchar *print_flags ;
  280. X
  281. Xint i_begin = 123456 ;
  282. Xint i_end = 123470 ;
  283. Xint i_step = 1 ;
  284. X
  285. Xdouble f_begin = 1.234567654312 ;
  286. Xdouble f_end = 2.0 ;
  287. Xdouble f_step = 0.011 ;
  288. X
  289. X#define LEN( s )                    ( s ? strlen( s ) : 0 )
  290. X
  291. Xchar *format( f )
  292. X    char *f ;
  293. X{
  294. X    char *malloc() ;
  295. X    static char *newfmt ;
  296. X
  297. X    if ( newfmt )
  298. X        free( newfmt ) ;
  299. X
  300. X    newfmt = malloc( strlen( f )
  301. X                + LEN( precision ) + LEN( width ) + LEN( print_flags ) + 2 ) ;
  302. X    (void) strcpy( newfmt, "%" ) ;
  303. X    if ( print_flags )
  304. X        (void) strcat( newfmt, print_flags ) ;
  305. X    if ( width )
  306. X        (void) strcat( newfmt, width ) ;
  307. X    if ( precision )
  308. X        (void) strcat( strcat( newfmt, "." ), precision ) ;
  309. X    (void) strcat( newfmt, &f[1] ) ;
  310. X    return( newfmt ) ;
  311. X}
  312. X
  313. X#define decimal_test()            integer_test( "%d %d\n", DECIMAL )
  314. X#define hex_test()                integer_test( "%x %x\n", HEX )
  315. X#define cap_hex_test()            integer_test( "%X %X\n", CAP_HEX )
  316. X#define octal_test()                integer_test( "%o %o\n", OCTAL )
  317. X#define unsigned_test()            integer_test( "%u %u\n", UNSIGNED )
  318. X
  319. Xvoid integer_test( fmt, flag )
  320. X    char *fmt ;
  321. X    FLAG flag ;
  322. X{
  323. X    int i ;
  324. X    int ccs, ccp ;
  325. X
  326. X    CHECK( flag ) ;
  327. X    fmt = format( fmt ) ;
  328. X
  329. X    for ( i = i_begin ; i < i_end ; i += i_step )
  330. X    {
  331. X        ccp = printf( fmt, -i, i ) ;
  332. X        ccs = Sprint( 2, fmt, -i, i ) ;
  333. X        FLUSH() ;
  334. X        COMPARE( ccp, ccs ) ;
  335. X    }
  336. X}
  337. X
  338. X
  339. X#define f_float_test()            fp_test( "%f\n", F_FLOAT )
  340. X#define g_float_test()            fp_test( "%g\n", G_FLOAT )
  341. X#define e_float_test()            fp_test( "%e\n", E_FLOAT )
  342. X#define cap_e_float_test()        fp_test( "%E\n", CAP_E_FLOAT )            
  343. X#define cap_g_float_test()        fp_test( "%G\n", CAP_G_FLOAT )
  344. X
  345. Xvoid fp_test( fmt, flag )
  346. X    char *fmt ;
  347. X    FLAG flag ;
  348. X{
  349. X    double d ;
  350. X    double step ;
  351. X    int ccs, ccp ;
  352. X
  353. X    CHECK( flag ) ;
  354. X    fmt = format( fmt ) ;
  355. X    
  356. X    for ( d = f_begin, step = f_step ; d < f_end ; d += step, step += step )
  357. X    {
  358. X
  359. X        ccp = printf( fmt, d ) ;
  360. X        ccs = Sprint( 2, fmt, d ) ;
  361. X        FLUSH() ;
  362. X        COMPARE( ccp, ccs ) ;
  363. X    }
  364. X}
  365. X
  366. X
  367. Xvoid char_test()
  368. X{
  369. X    char *s = "foobar" ;
  370. X    int len = strlen( s ) ;
  371. X    int i ;
  372. X    char *fmt = "%c\n" ;
  373. X    int ccs, ccp ;
  374. X
  375. X    CHECK( CHAR ) ;
  376. X    fmt = format( fmt ) ;
  377. X
  378. X    for ( i = 0 ; i < len ; i++ )
  379. X    {
  380. X        ccp = printf( fmt, s[ i ] ) ;
  381. X        ccs = Sprint( 2, fmt, s[ i ] ) ;
  382. X        FLUSH() ;
  383. X        COMPARE( ccp, ccs ) ;
  384. X    }
  385. X}
  386. X
  387. X
  388. Xvoid string_test()
  389. X{
  390. X    static char *list[] = 
  391. X    {
  392. X        "foobar",
  393. X        "hello",
  394. X        "world",
  395. X        "this is a very long string, a really long string, really, true, honest",
  396. X        "i am getting tired of this",
  397. X        "SO THIS IS THE END",
  398. X        0
  399. X    } ;
  400. X    char *fmt = "%s\n" ;
  401. X    char **p ;
  402. X    int ccp, ccs ;
  403. X
  404. X    CHECK( STRING ) ;
  405. X    fmt = format( fmt ) ;
  406. X
  407. X    for ( p = &list[ 0 ] ; *p ; p++ )
  408. X    {
  409. X        ccp = printf( fmt, *p ) ;
  410. X        ccs = Sprint( 2, fmt, *p ) ;
  411. X        FLUSH() ;
  412. X        COMPARE( ccp, ccs ) ;
  413. X    }
  414. X}
  415. X
  416. X
  417. Xvoid pointer_test()
  418. X{
  419. X    struct foo
  420. X    {
  421. X        char bar1 ;
  422. X        short bar2 ;
  423. X        int bar3 ;
  424. X        long bar4 ;
  425. X        char *bar5 ;
  426. X    } foo, *end = &foo, *p ;
  427. X    char *fmt = "%p\n" ;
  428. X    int ccp, ccs ;
  429. X
  430. X    CHECK( POINTER ) ;
  431. X    fmt = format( fmt ) ;
  432. X
  433. X    end += 10 ;
  434. X    for ( p = &foo ; p < end ; p++ )
  435. X    {
  436. X        ccp = printf( fmt, p ) ;
  437. X        ccs = Sprint( 2, fmt, p ) ;
  438. X        FLUSH() ;
  439. X    }
  440. X}
  441. X
  442. X
  443. X/* 
  444. X * bound_test is only available on SunOS 4.x
  445. X */
  446. X#if defined( sun )
  447. X
  448. Xvoid bound_test()
  449. X{
  450. X    char *fmt ;
  451. X    double bound_values[ 10 ] ;
  452. X    static char *bound_names[] =
  453. X    {
  454. X        "min_subnormal",
  455. X        "max_subnormal",
  456. X        "min_normal",
  457. X        "max_normal",
  458. X        "infinity",
  459. X        "quiet_nan",
  460. X        "signaling_nan"
  461. X    } ;
  462. X    int n_values ;
  463. X    int i ;
  464. X    int ccp, ccs ;
  465. X
  466. X    bound_values[ 0 ] = min_subnormal() ;
  467. X    bound_values[ 1 ] = max_subnormal() ;
  468. X    bound_values[ 2 ] = min_normal() ;
  469. X    bound_values[ 3 ] = max_normal() ;
  470. X    bound_values[ 4 ] = infinity() ;
  471. X    bound_values[ 5 ] = quiet_nan( 7L ) ;
  472. X    bound_values[ 6 ] = signaling_nan( 7L ) ;
  473. X    n_values = 7 ;
  474. X
  475. X    CHECK( BOUND ) ;
  476. X
  477. X    for ( i = 0 ; i < n_values ; i++ )
  478. X    {
  479. X        double d = bound_values[ i ] ;
  480. X        char *name = bound_names[ i ] ;
  481. X
  482. X        fmt = format( "%f (%s)\n" ) ;
  483. X        ccp = printf( fmt, d, name ) ;
  484. X        ccs = Sprint( 2, fmt, d, name ) ;
  485. X        FLUSH() ;
  486. X        COMPARE( ccp, ccs ) ;
  487. X
  488. X        fmt = format( "%e (%s)\n" ) ;
  489. X        ccp = printf( fmt, d, name ) ;
  490. X        ccs = Sprint( 2, fmt, d, name ) ;
  491. X        FLUSH() ;
  492. X        COMPARE( ccp, ccs ) ;
  493. X
  494. X        fmt = format( "%g (%s)\n" ) ;
  495. X        ccp = printf( fmt, d, name ) ;
  496. X        ccs = Sprint( 2, fmt, d, name ) ;
  497. X        FLUSH() ;
  498. X        COMPARE( ccp, ccs ) ;
  499. X    }
  500. X
  501. X    fmt = format( "%d (MININT)\n" ) ;
  502. X    ccp = printf( fmt, -MAXINT-1 ) ;
  503. X    ccs = Sprint( 2, fmt, -MAXINT-1 ) ;
  504. X    COMPARE( ccp, ccs ) ;
  505. X}
  506. X#else
  507. Xvoid bound_test()
  508. X{
  509. X}
  510. X#endif
  511. X
  512. X
  513. Xint get_options( argc, argv )
  514. X    int argc ;
  515. X    char *argv[] ;
  516. X{
  517. X    int arg_index = 1 ;
  518. X    char *p ;
  519. X    double atof() ;
  520. X
  521. X    for ( arg_index = 1 ;
  522. X            arg_index < argc && argv[ arg_index ][ 0 ] == '-' ; arg_index++ )
  523. X    {
  524. X        switch ( argv[ arg_index ][ 1 ] )
  525. X        {
  526. X            case 'd':
  527. X                flags[ DECIMAL ] = YES ;
  528. X                break ;
  529. X            
  530. X            case 'x':
  531. X                flags[ HEX ] = YES ;
  532. X                break ;
  533. X            
  534. X            case 'X':
  535. X                flags[ CAP_HEX ] = YES ;
  536. X                break ;
  537. X            
  538. X            case 'o':
  539. X                flags[ OCTAL ] = YES ;
  540. X                break ;
  541. X            
  542. X            case 'u':
  543. X                flags[ UNSIGNED ] = YES ;
  544. X                break ;
  545. X
  546. X            case 'f':
  547. X                flags[ F_FLOAT ] = YES ;
  548. X                break ;
  549. X            
  550. X            case 'g':
  551. X                flags[ G_FLOAT ] = YES ;
  552. X                break ;
  553. X            
  554. X            case 'e':
  555. X                flags[ E_FLOAT ] = YES ;
  556. X                break ;
  557. X            
  558. X            case 'E':
  559. X                flags[ CAP_E_FLOAT ] = YES ;
  560. X                break ;
  561. X            
  562. X            case 'G':
  563. X                flags[ CAP_G_FLOAT ] = YES ;
  564. X                break ;
  565. X
  566. X            case 'c':
  567. X                flags[ CHAR ] = YES ;
  568. X                break ;
  569. X            
  570. X            case 's':
  571. X                flags[ STRING ] = YES ;
  572. X                break ;
  573. X            
  574. X            case 'p':
  575. X                flags[ POINTER ] = YES ;
  576. X                break ;
  577. X            
  578. X            case 'b':        /* this is for checking bounds in fp formats */
  579. X                flags[ BOUND ] = YES ;
  580. X                break ;
  581. X                
  582. X            case 'P':    /* precision, must be followed by a number, e.g. -P10 */
  583. X                precision = &argv[ arg_index ][ 2 ] ;
  584. X                break ;
  585. X            
  586. X            case 'W':    /* width, must be followed by a number, e.g. -w10 */
  587. X                width = &argv[ arg_index ][ 2 ] ;
  588. X                break ;
  589. X            
  590. X            case 'F':    /* flags, whatever is after the F */
  591. X                print_flags = &argv[ arg_index ][ 2 ] ;
  592. X                break ;
  593. X            
  594. X            /*
  595. X             * Options recognized in this case:    -Vf, -Vi
  596. X             * Usage: -V[if] start end step
  597. X             */
  598. X            case 'V':
  599. X                /*
  600. X                 * Check if we have enough extra arguments
  601. X                 */
  602. X                if ( argc - ( arg_index + 1 ) < 3 )
  603. X                {
  604. X                    fprintf( stderr, "Insufficient # of args after V option\n" ) ;
  605. X                    exit( 1 ) ;
  606. X                }
  607. X                switch ( argv[ arg_index ][ 2 ] )
  608. X                {
  609. X                    case 'f':
  610. X                        f_begin = atof( argv[ arg_index+1 ] ) ;
  611. X                        f_end   = atof( argv[ arg_index+2 ] ) ;
  612. X                        f_step  = atof( argv[ arg_index+3 ] ) ;
  613. X                        break ;
  614. X                    
  615. X                    case 'i':
  616. X                        i_begin = atoi( argv[ arg_index+1 ] ) ;
  617. X                        i_end   = atoi( argv[ arg_index+2 ] ) ;
  618. X                        i_step  = atoi( argv[ arg_index+3 ] ) ;
  619. X                        break ;
  620. X                }
  621. X                arg_index += 3 ;
  622. X                break ;
  623. X
  624. X            case 'S':
  625. X                f_step = atof( &argv[ arg_index ][ 2 ] ) ;
  626. X                break ;
  627. X        }
  628. X    }
  629. X    return( arg_index ) ;
  630. X}
  631. X
  632. X
  633. X#define EQ( s1, s2 )                ( strcmp( s1, s2 ) == 0 )
  634. X
  635. X
  636. Xint main( argc, argv )
  637. X    int argc ;
  638. X    char *argv[] ;
  639. X{
  640. X
  641. X    if ( Sbuftype( 2, SIO_LINEBUF ) == SIO_ERR )
  642. X    {
  643. X        char *msg = "Sbuftype failed\n" ;
  644. X
  645. X        write( 2, msg, strlen( msg ) ) ;
  646. X        exit( 1 ) ;
  647. X    }
  648. X
  649. X    if ( argc == 1 || argc == 2 && EQ( argv[ 1 ], "ALL" ) )
  650. X    {
  651. X        /* perform all tests */
  652. X        int i ;
  653. X
  654. X        for ( i = 0 ; i < N_FLAGS ; i++ )
  655. X            flags[ i ] = YES ;
  656. X    }
  657. X    else
  658. X        (void) get_options( argc, argv ) ;
  659. X
  660. X    decimal_test() ;
  661. X    hex_test() ;
  662. X    cap_hex_test() ;
  663. X    octal_test() ;
  664. X    unsigned_test() ;
  665. X
  666. X    f_float_test() ;
  667. X    g_float_test() ;
  668. X    e_float_test() ;
  669. X    cap_g_float_test() ;
  670. X    cap_e_float_test() ;
  671. X
  672. X    string_test() ;
  673. X    char_test() ;
  674. X    pointer_test() ;
  675. X    bound_test() ;
  676. X    exit( 0 ) ;
  677. X}
  678. END_OF_FILE
  679. if test 8243 -ne `wc -c <'libs/src/sio/suite/print.c'`; then
  680.     echo shar: \"'libs/src/sio/suite/print.c'\" unpacked with wrong size!
  681. fi
  682. # end of 'libs/src/sio/suite/print.c'
  683. fi
  684. if test -f 'libs/src/timer/sysdep.c' -a "${1}" != "-c" ; then 
  685.   echo shar: Will not clobber existing file \"'libs/src/timer/sysdep.c'\"
  686. else
  687. echo shar: Extracting \"'libs/src/timer/sysdep.c'\" \(7951 characters\)
  688. sed "s/^X//" >'libs/src/timer/sysdep.c' <<'END_OF_FILE'
  689. X/*
  690. X * (c) Copyright 1993 by Panagiotis Tsirigotis
  691. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  692. X * and conditions for redistribution.
  693. X */
  694. X
  695. X#include <signal.h>
  696. X#include <sys/time.h>
  697. X#include <sys/resource.h>
  698. X
  699. X#include "defs.h"
  700. X#include "impl.h"
  701. X#include "ostimer.h"
  702. X#include "timemacros.h"
  703. X
  704. X
  705. XPRIVATE void sigalrm_handler() ;
  706. XPRIVATE void sigvtalrm_handler() ;
  707. XPRIVATE void sigprof_handler() ;
  708. X
  709. XPRIVATE void get_real_time() ;
  710. XPRIVATE void get_virtual_time() ;
  711. XPRIVATE void get_prof_time() ;
  712. X
  713. X#define SIGNOSIG                            0
  714. X
  715. X/*
  716. X * The reason for having the AVAILABLE/UNAVAILABLE fields instead of
  717. X * simply not having entries if a specified timer type is not supported,
  718. X * is that we use the timer type as an index into the os_timers[] array.
  719. X */
  720. Xstatic struct os_timer os_timers[] =
  721. X   {
  722. X        {
  723. X#if defined( ITIMER_REAL ) && ! defined( NO_ITIMER_REAL )
  724. X            AVAILABLE,     ITIMER_REAL,        SIGALRM,
  725. X#else
  726. X            UNAVAILABLE,    0,                        SIGNOSIG,
  727. X#endif
  728. X            TIMER_REAL,        sigalrm_handler,     get_real_time     },
  729. X
  730. X        {
  731. X#if defined( ITIMER_VIRTUAL ) && ! defined( NO_ITIMER_VIRTUAL )
  732. X            AVAILABLE,    ITIMER_VIRTUAL,    SIGVTALRM,
  733. X#else
  734. X            UNAVAILABLE,    0,                        SIGNOSIG,
  735. X#endif
  736. X          TIMER_VIRTUAL,    sigvtalrm_handler,   get_virtual_time  },
  737. X
  738. X        {
  739. X#if defined( ITIMER_PROF ) && ! defined( NO_ITIMER_PROF )
  740. X            AVAILABLE,    ITIMER_PROF,        SIGPROF,
  741. X#else
  742. X            UNAVAILABLE,    0,                    SIGNOSIG,
  743. X#endif
  744. X            TIMER_PROF,       sigprof_handler,     get_prof_time      },
  745. X
  746. X        {    UNAVAILABLE,    0,                        SIGNOSIG,
  747. X          TIMER_REAL,        NULL,                NULL,             }
  748. X   } ;
  749. X
  750. X
  751. X/*
  752. X * The timer_block_mask blocks all timer signals when a timer signal
  753. X * happens (using the sa_mask field of struct sigaction). This is necessary
  754. X * when the user function associated with the timer does not return.
  755. X * Consider the following scenario:
  756. X *    The user creates 2 timers, one TIMER_REAL (signal: SIGALRM), one
  757. X *    TIMER_VIRTUAL (signal: SIGVTALRM).
  758. X *    SIGALRM occurs first but before it is handled, SIGVTALRM happens.
  759. X *    At this point both SIGARLM and SIGVTALRM are blocked.
  760. X *    SIGVTALRM gets unblocked and the function for the TIMER_VIRTUAL is
  761. X *    invoked and never returns. The function for the TIMER_REAL is never
  762. X *    invoked (and any TIMER_REAL timers never expire).
  763. X */
  764. X#ifndef NO_POSIX_SIGS
  765. Xstatic sigset_t timer_block_mask ;
  766. X#else
  767. Xstatic int timer_block_mask ;
  768. X#endif
  769. X
  770. Xstatic int timer_block_mask_set ;         /* flag */
  771. X
  772. X
  773. X/*
  774. X * Initialize the timer_block_mask.
  775. X * As a side-effect it also initializes the block_mask of each ostimer.
  776. X */
  777. XPRIVATE void set_timer_block_mask()
  778. X{
  779. X   ostimer_s *otp ;
  780. X
  781. X#ifndef NO_POSIX_SIGS
  782. X   (void) sigemptyset( &timer_block_mask ) ;
  783. X#else
  784. X    /* timer_block_mask is a global variable so it is initialized to 0 */
  785. X#endif
  786. X
  787. X   for ( otp = &os_timers[ 0 ] ; otp->ost_handler ; otp++ )
  788. X   {
  789. X#ifndef NO_POSIX_SIGS
  790. X      (void) sigemptyset( &otp->ost_block_mask ) ;
  791. X      (void) sigaddset( &otp->ost_block_mask, otp->ost_signal ) ;
  792. X      (void) sigaddset( &timer_block_mask, otp->ost_signal ) ;
  793. X#else
  794. X      otp->ost_block_mask = sigmask( otp->ost_signal ) ;
  795. X      timer_block_mask |= otp->ost_block_mask ;
  796. X#endif
  797. X   }
  798. X
  799. X   timer_block_mask_set = TRUE ;
  800. X}
  801. X
  802. X
  803. XPRIVATE ostimer_s *ostimer_find( type )
  804. X    enum timer_types    type ;
  805. X{
  806. X    register ostimer_s *otp ;
  807. X
  808. X    for ( otp = os_timers ; otp->ost_handler ; otp++ )
  809. X        if ( otp->ost_timertype == type )
  810. X            return( otp->ost_availability == AVAILABLE ? otp : OSTIMER_NULL ) ;
  811. X    return( OSTIMER_NULL ) ;
  812. X}
  813. X
  814. X
  815. XPRIVATE int time_compare( p1, p2 )
  816. X   pq_obj p1, p2 ;
  817. X{
  818. X   return( TV_LT( TP( p1 )->t_expiration, TP( p2 )->t_expiration ) ) ;
  819. X}
  820. X
  821. X
  822. X/*
  823. X * Initialize an OS timer. The initialization steps are:
  824. X *
  825. X *    create priority queue
  826. X *    install signal handler
  827. X *
  828. X * We also initialize the timer_block_mask if it has not been initialized yet.
  829. X */
  830. Xostimer_s *__ostimer_init( tp, type )
  831. X    timer_s                *tp ;
  832. X    enum timer_types    type ;
  833. X{
  834. X#ifndef NO_POSIX_SIGS
  835. X   struct sigaction  sa ;
  836. X#else
  837. X   struct sigvec     sv ;
  838. X#endif
  839. X   ostimer_s           *otp ;
  840. X   struct timer_q    *tqp ;
  841. X
  842. X    /*
  843. X     * Find the corresponding ostimer
  844. X     */
  845. X    if ( ( otp = ostimer_find( type ) ) == OSTIMER_NULL )
  846. X        HANDLE_ERROR( tp->t_flags, OSTIMER_NULL,
  847. X            tp->t_errnop, TIMER_ENOTAVAILABLE,
  848. X                "TIMER __ostimer_init: requested timer type not available\n" ) ;
  849. X
  850. X    /*
  851. X     * We use the value of ost_timerq to determine if the os_timer
  852. X     * has been initialized.
  853. X     */
  854. X   tqp = &otp->ost_timerq ;
  855. X    if ( tqp->tq_handle )
  856. X        return( otp ) ;
  857. X    
  858. X   tqp->tq_handle = pq_create( time_compare,
  859. X                tp->t_flags & TIMER_RETURN_ERROR ? PQ_RETURN_ERROR : PQ_NOFLAGS,
  860. X                                        &tqp->tq_errno ) ;
  861. X   if ( tqp->tq_handle == NULL )
  862. X   {
  863. X      *tp->t_errnop = TIMER_ENOMEM ;
  864. X      return( OSTIMER_NULL ) ;
  865. X   }
  866. X
  867. X   if ( ! timer_block_mask_set )
  868. X      set_timer_block_mask() ;
  869. X
  870. X#ifndef NO_POSIX_SIGS
  871. X   sa.sa_handler = otp->ost_handler ;
  872. X   sa.sa_mask = timer_block_mask ;
  873. X   sa.sa_flags = 0 ;
  874. X   if ( sigaction( otp->ost_signal, &sa, SIGACTION_NULL ) == -1 )
  875. X#else
  876. X   sv.sv_handler = otp->ost_handler ;
  877. X   sv.sv_mask = timer_block_mask ;
  878. X   sv.sv_flags = 0 ;
  879. X   if ( sigvec( otp->ost_signal, &sv, SIGVEC_NULL ) == -1 )
  880. X#endif
  881. X      HANDLE_ERROR( tp->t_flags, OSTIMER_NULL, tp->t_errnop, TIMER_ESIGPROBLEM,
  882. X         "TIMER __ostimer_init: signal handler installation failed\n" ) ;
  883. X   return( otp ) ;
  884. X}
  885. X
  886. X
  887. X/*
  888. X * timer_* functions that need access to private data of ostimer
  889. X */
  890. Xvoid timer_block_type( type )
  891. X   enum timer_types    type ;
  892. X{
  893. X   ostimer_s            *otp = ostimer_find( type ) ;
  894. X
  895. X    if ( otp == OSTIMER_NULL )
  896. X        return ;
  897. X
  898. X#ifndef NO_POSIX_SIGS
  899. X   (void) sigprocmask( SIG_BLOCK, &otp->ost_block_mask, SIGSET_NULL ) ;
  900. X#else
  901. X   (void) sigblock( otp->ost_block_mask ) ;
  902. X#endif
  903. X}
  904. X
  905. X
  906. Xvoid timer_unblock_type( type )
  907. X   enum timer_types    type ;
  908. X{
  909. X   ostimer_s            *otp = ostimer_find( type ) ;
  910. X
  911. X    if ( otp == OSTIMER_NULL )
  912. X        return ;
  913. X
  914. X#ifndef NO_POSIX_SIGS
  915. X   (void) sigprocmask( SIG_UNBLOCK, &otp->ost_block_mask, SIGSET_NULL ) ;
  916. X#else
  917. X    {
  918. X        int old_mask = sigblock( ~0 ) ;
  919. X
  920. X        (void) sigsetmask( old_mask & ~otp->ost_block_mask ) ;
  921. X    }
  922. X#endif
  923. X}
  924. X
  925. X
  926. Xvoid __ostimer_blockall()
  927. X{
  928. X#ifndef NO_POSIX_SIGS
  929. X   (void) sigprocmask( SIG_BLOCK, &timer_block_mask, SIGSET_NULL ) ;
  930. X#else
  931. X   (void) sigblock( timer_block_mask ) ;
  932. X#endif
  933. X}
  934. X
  935. X
  936. Xvoid __ostimer_unblockall()
  937. X{
  938. X#ifndef NO_POSIX_SIGS
  939. X   (void) sigprocmask( SIG_UNBLOCK, &timer_block_mask, SIGSET_NULL ) ;
  940. X#else
  941. X   int old_mask = sigblock( ~0 ) ;
  942. X
  943. X   (void) sigsetmask( old_mask & ~timer_block_mask ) ;
  944. X#endif
  945. X}
  946. X
  947. X
  948. Xvoid __ostimer_unblockall_except( otp )
  949. X   ostimer_s *otp ;
  950. X{
  951. X#ifndef NO_POSIX_SIGS
  952. X   sigset_t new_mask = timer_block_mask ;
  953. X
  954. X   (void) sigdelset( &new_mask, otp->ost_signal ) ;
  955. X   (void) sigprocmask( SIG_UNBLOCK, &new_mask, SIGSET_NULL ) ;
  956. X#else
  957. X   int old_mask = sigblock( ~0 ) ;
  958. X
  959. X   (void) sigsetmask( ( old_mask & ~timer_block_mask )
  960. X                                          | otp->ost_block_mask ) ;
  961. X#endif
  962. X}
  963. X
  964. X
  965. XPRIVATE void sigalrm_handler()
  966. X{
  967. X#ifdef DEBUG_MSGS
  968. X   printf( "\tSIGALRM happened\n" ) ;
  969. X#endif
  970. X   __ostimer_interrupt( &os_timers[ (int)TIMER_REAL ] ) ;
  971. X}
  972. X
  973. X
  974. XPRIVATE void sigvtalrm_handler()
  975. X{
  976. X#ifdef DEBUG_MSGS
  977. X   printf( "\tSIGVTALRM happened\n" ) ;
  978. X#endif
  979. X   __ostimer_interrupt( &os_timers[ (int)TIMER_VIRTUAL ] ) ;
  980. X}
  981. X
  982. X
  983. XPRIVATE void sigprof_handler()
  984. X{
  985. X#ifdef DEBUG_MSGS
  986. X   printf( "\tSIGPROF happened\n" ) ;
  987. X#endif
  988. X   __ostimer_interrupt( &os_timers[ (int)TIMER_PROF ] ) ;
  989. X}
  990. X
  991. X
  992. XPRIVATE void get_real_time( tvp )
  993. X   struct timeval *tvp ;
  994. X{
  995. X#if defined( ITIMER_REAL ) && ! defined( NO_ITIMER_REAL )
  996. X   (void) gettimeofday( tvp, TIMEZONE_NULL ) ;
  997. X#endif
  998. X}
  999. X
  1000. X
  1001. XPRIVATE void get_virtual_time( tvp )
  1002. X   struct timeval *tvp ;
  1003. X{
  1004. X#if defined( ITIMER_VIRTUAL ) && ! defined( NO_ITIMER_VIRTUAL )
  1005. X   struct rusage ru ;
  1006. X
  1007. X   (void) getrusage( RUSAGE_SELF, &ru ) ;
  1008. X   *tvp = ru.ru_utime ;
  1009. X#endif
  1010. X}
  1011. X
  1012. X
  1013. XPRIVATE void get_prof_time( tvp )
  1014. X   struct timeval *tvp ;
  1015. X{
  1016. X#if defined( ITIMER_PROF ) && ! defined( NO_ITIMER_PROF )
  1017. X   struct rusage ru ;
  1018. X
  1019. X   (void) getrusage( RUSAGE_SELF, &ru ) ;
  1020. X   TV_ADD( *tvp, ru.ru_utime, ru.ru_stime ) ;
  1021. X#endif
  1022. X}
  1023. X
  1024. X
  1025. END_OF_FILE
  1026. if test 7951 -ne `wc -c <'libs/src/timer/sysdep.c'`; then
  1027.     echo shar: \"'libs/src/timer/sysdep.c'\" unpacked with wrong size!
  1028. fi
  1029. # end of 'libs/src/timer/sysdep.c'
  1030. fi
  1031. echo shar: End of archive 14 \(of 20\).
  1032. cp /dev/null ark14isdone
  1033. MISSING=""
  1034. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ; do
  1035.     if test ! -f ark${I}isdone ; then
  1036.     MISSING="${MISSING} ${I}"
  1037.     fi
  1038. done
  1039. if test "${MISSING}" = "" ; then
  1040.     echo You have unpacked all 20 archives.
  1041.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1042. else
  1043.     echo You still need to unpack the following archives:
  1044.     echo "        " ${MISSING}
  1045. fi
  1046. ##  End of shell archive.
  1047. exit 0
  1048.