home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / pst / part03 < prev    next >
Encoding:
Text File  |  1993-11-26  |  54.8 KB  |  2,188 lines

  1. Newsgroups: comp.sources.misc
  2. From: Panos Tsirigotis (panos@cs.colorado.edu)
  3. Subject: v40i174:  pst - extract text from a postscript file, Part03/06
  4. Message-ID: <1993Nov26.170731.6476@sparky.sterling.com>
  5. X-Md4-Signature: b266621814b57b5f588228e906dae7b7
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Fri, 26 Nov 1993 17:07:31 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: Panos Tsirigotis (panos@cs.colorado.edu)
  12. Posting-number: Volume 40, Issue 174
  13. Archive-name: pst/part03
  14. Environment: BSD, SUNOS, ULTRIX, SYSVR4, SYSVR3, POSIX
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  libs/src/sio/README libs/src/sio/Sprint.3
  21. #   libs/src/sio/impl.h libs/src/sio/sioconf.h
  22. #   libs/src/sio/suite/copytest.c libs/src/sio/suite/tester
  23. #   libs/src/str/Makefile libs/src/str/strparse.c libs/src/str/strs.3
  24. #   pst/dvi.c
  25. # Wrapped by kent@sparky on Fri Nov 26 11:02:46 1993
  26. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  27. echo If this archive is complete, you will see the following message:
  28. echo '          "shar: End of archive 3 (of 6)."'
  29. if test -f 'libs/src/sio/README' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'libs/src/sio/README'\"
  31. else
  32.   echo shar: Extracting \"'libs/src/sio/README'\" \(4699 characters\)
  33.   sed "s/^X//" >'libs/src/sio/README' <<'END_OF_FILE'
  34. X======================================================================
  35. XNOTE: I use vi with a tabstop value of 3. Using the same tabstop
  36. X        value will make the text/code look properly indented.
  37. X======================================================================
  38. X
  39. X
  40. X1. What is SIO ?
  41. X
  42. XSIO is a library that provides _stream_ I/O which is what most Unix
  43. Xprograms do. As such it is a competitor to stdio.
  44. X
  45. X
  46. X2. Why would you care to use it ?
  47. X
  48. Xa. SIO is a little faster than stdio
  49. Xb. SIO provides an easier-to-use interface (IMHO)
  50. Xc. SIO is capable of using memory mapping for reading files if the operating
  51. X    system supports it.
  52. Xd. If you have a program that uses read(2)/write(2) it is trivial
  53. X   to convert it to use SIO (just replace read with Sread and 
  54. X   write with Swrite)
  55. Xe. You get source
  56. X
  57. X
  58. X
  59. X3. Setting up the Stream I/O (SIO) library
  60. X
  61. XThere are 3 steps to the process:
  62. X    1) compiling SIO for your system
  63. X    2) testing SIO
  64. X    3) installing the library and manpages
  65. X
  66. X
  67. X3.1. How to compile the Stream I/O (SIO) library
  68. X
  69. XAll the system-dependent stuff of SIO is placed in the sioconf.h file.
  70. XIf your system is not among those listed below, you will need to read
  71. Xthat file to see what flags you need to set to properly compile SIO.
  72. X
  73. X    SunOS 4.x:
  74. X        make "DEFS=-DHAS_MMAP -DHAS_ONEXIT -DHAS_MEMOPS -DHAS_ISATTY"
  75. X
  76. X    SunOS 5.x (aka Solaris 2.y):
  77. X        make "DEFS=-DHAS_MMAP -DHAS_ATEXIT -DHAS_MEMOPS -DHAS_ISATTY"
  78. X    (I don't have access to a system running Solaris 2.y so I have not
  79. X    tested this)
  80. X
  81. X    Ultrix 4.x:
  82. X        make "DEFS=-DHAS_MEMOPS -DHAS_ATEXIT -DHAS_ISATTY"
  83. X
  84. XIf your system is one of the above, then you can skip to the next subsection.
  85. XHowever, I should mention that the library compiles by default with
  86. Xdebugging enabled (i.e. uses the -g flag of cc). You can override this
  87. Xby appending to the above invocations of 'make' the argument "DEBUG=-O"
  88. X
  89. XIf your system is not among the above, then you will need to modify the
  90. Xsioconf.h file. You do this by uncommenting the inclusion of
  91. Xcustomconf.h. Then, you can override all constants/macros defined in
  92. Xsioconf.h by defining them first in customconf.h.  Please read
  93. Xsioconf.h for more information on what constants/macros can be
  94. Xdefined.
  95. X
  96. XThe Makefile has a header that explains what the Makefile can do.
  97. XThe only flag that you may want to define is -DDEBUG which enables 
  98. Xassertions in the SIO code (if an assertion fails, the program is 
  99. Xterminated with an error message that lists the SIO file and line 
  100. Xnumber where the error occured).
  101. X
  102. X
  103. X3.2. Testing SIO
  104. X
  105. XAfter you have successfully compiled SIO, you can use the programs in
  106. Xthe "suite" directory to test the SIO functions. It may make you feel
  107. Xbetter if you test the library before installing it.
  108. XThe script testlib does everything; just type:
  109. X
  110. X    testlib all
  111. X
  112. XThe script sprint_test (invoked by testlib) tests Sprint by using a variety 
  113. Xof formats and comparing its output with that of an ANSI-compatible printf.
  114. XAt least on Ultrix 4.1 and 4.2 this test fails because printf is not 
  115. XANSI-compatible.
  116. XIn such a case, you can test the rest of the SIO functions by typing:
  117. X
  118. X    testlib all Sprint
  119. X
  120. X(anything after the 'all' argument is interpreted as a function that
  121. Xshould not be tested).
  122. X
  123. XThe README file in the "suite" directory describes how to do a
  124. Xfew more tests that cannot be done automatically.
  125. X
  126. X
  127. X3.3. Installing the library and manpages
  128. X
  129. XThe default 'make' target will create libsio.a in the current directory.
  130. XThe Makefile includes an "install" target. Doing a 'make install' will 
  131. Xcause the following:
  132. X
  133. Xa) libsio.a will be installed in LIBDIR
  134. Xb) the necessary SIO header files will be installed in INCLUDEDIR
  135. Xc) the SIO man pages will be installed in MANDIR
  136. X
  137. XLIBDIR, INCLUDEDIR, and MANDIR are Makefile variables that you can edit in
  138. Xthe Makefile or override when you invoke 'make'.
  139. XHere is a sample command to install SIO:
  140. X
  141. X    make install LIBDIR=/usr/local/lib INCLUDEDIR=/usr/local/include MANDIR=/usr/local/man/man3
  142. X
  143. X
  144. X4. Epilogue
  145. X
  146. XFeel free to modify SIO to suit your needs. Please let me know if you
  147. Xfind any bugs (my email address is panos@cs.colorado.edu).
  148. X
  149. XIf you want to distribute your modifications, please read the COPYRIGHT
  150. Xfile.  It basically says that you are free to redistribute as long as
  151. Xyou retain the original copyright notice and you make sure that your
  152. Xmodifications are identifiable. In order to achieve this I have
  153. Xreserved the first 3 components of the version number (for example,
  154. X1.4.2) and you can identify your mods by appending another component to
  155. Xthat version number (for example, 1.4.2.A2). Also, if you distribute a
  156. Xmodified version of the library, you take full responsibility for any
  157. Xbugs in the code (not just your code; the whole thing).
  158. X
  159. X
  160. X    ** Panos Tsirigotis **
  161. X
  162. END_OF_FILE
  163.   if test 4699 -ne `wc -c <'libs/src/sio/README'`; then
  164.     echo shar: \"'libs/src/sio/README'\" unpacked with wrong size!
  165.   fi
  166.   # end of 'libs/src/sio/README'
  167. fi
  168. if test -f 'libs/src/sio/Sprint.3' -a "${1}" != "-c" ; then 
  169.   echo shar: Will not clobber existing file \"'libs/src/sio/Sprint.3'\"
  170. else
  171.   echo shar: Extracting \"'libs/src/sio/Sprint.3'\" \(5277 characters\)
  172.   sed "s/^X//" >'libs/src/sio/Sprint.3' <<'END_OF_FILE'
  173. X.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  174. X.\"All rights reserved.  The file named COPYRIGHT specifies the terms 
  175. X.\"and conditions for redistribution.
  176. X.\"
  177. X.\" $Id: Sprint.3,v 8.1 1993/03/13 01:15:34 panos Exp $
  178. X.TH Sprint 3X "29 May 1992"
  179. X.SH NAME
  180. XSprint -- formatted stream output
  181. X.SH SYNOPSIS
  182. X.LP
  183. X.nf
  184. X.ft B
  185. Xint Sprint( fd, format [ , ... ] )
  186. Xint fd ;
  187. Xchar *format ;
  188. X.SH DESCRIPTION
  189. X\fBSprint()\fR provides formatted output conversion. The formatting is
  190. Xcontrolled by the \fIformat\fR argument. All characters in
  191. X\fIformat\fR that do not specify a conversion are printed. A conversion
  192. Xis specified by a '%' followed by a string that ends with a
  193. Xconversion type character. The string may contain flags, a field width,
  194. Xa precision, and a modifier.
  195. X.LP
  196. XPossible flags (more that one can be specified and they can be in any order)
  197. Xinclude:
  198. X.TP 10
  199. X.B \'-'
  200. Xspecifies left adjustment of the converted argument. The default
  201. Xis right adjustment. This flag is meaningful only if a field width
  202. Xis specified.
  203. X.TP
  204. X.B \'+'
  205. Xspecifies that a number will always have a sign as a prefix (this
  206. Xforces a '+' sign to appear if the number is positive).
  207. X.TP
  208. X.B \' '
  209. Xprefixes a \fIspace\fR to the number if the number has not a sign
  210. X(therefore the '+' flag overrides this flag).
  211. X.TP
  212. X.B \'#'
  213. XThe meaning of '#' depends on the conversion type character: for \fBo\fR 
  214. Xconversions the first digit will be 0; for \fBx\fR or \fBX\fR conversions
  215. X\fB0x\fR or \fB0X\fR respectively will be prefixed to the number (if it
  216. Xis not zero); for \fBe\fR, \fBE\fR, \fBf\fR, \fBg\fR, and \fBG\fR conversions
  217. Xthe number will always have a decimal point.
  218. X.TP
  219. X.B \'0'
  220. Xspecifies padding with zeros instead of spaces.
  221. X.LP
  222. XThe field width is specified by a number. This number indicates the
  223. X\fIminimum\fR width for the field. A '*' may be used instead of the number.
  224. XIn that case the width is the value of the next argument which should
  225. Xbe an \fBint\fR. 
  226. XA negative width value specifies left adjustment with a width equal
  227. Xto the absolute width value.
  228. X.LP
  229. XA precision is specified by a '.' followed by a number. The meaning of
  230. Xthe precision depends on the type conversion character. For a string
  231. Xconversion, precision determines how many characters are printed from
  232. Xthe string. For integer conversions, precision determines the 
  233. Xnumber of digits used to print the number (zero padding is done if
  234. Xthe precision exceeds the length of the number). For floating point
  235. Xconversions, precision determines the number of digits after the
  236. Xdecimal point (\fBe\fR, \fBE\fR, \fBf\fR) or the number of
  237. Xsignificant digits (\fBg\fR, \fBG\fR).
  238. XA '*' may be used instead of a number to specify the precision. In that
  239. Xcase the precision is the value of the next argument which should
  240. Xbe an \fBint\fR.
  241. XThe behavior of \fBSprint()\fR is undefined if the precision is negative.
  242. X.LP
  243. XThe length modifier is \fBl\fR and indicates that the argument is
  244. Xa \fBlong\fR integer.
  245. X.LP
  246. XThe type conversion characters are:
  247. X\fBd, i, o, x, X, u, c, s, f, e, E, g, G, p, n, %\fR.
  248. XFor floating point conversions the argument should be of type \fIdouble\fR.
  249. X.TP 10
  250. X.B d,i
  251. Xspecify signed decimal conversion.
  252. X.TP
  253. X.B u
  254. Xspecifies unsigned decimal conversion.
  255. X.TP
  256. X.B o
  257. Xspecifies octal conversion.
  258. X.TP
  259. X.B x,X
  260. Xspecify hexadecimal conversion. For 
  261. X.B x
  262. Xthe hex digits used are 0123456789abcdef. For
  263. X.B X
  264. Xthe hex digits used are 0123456789ABCDEF.
  265. XThere is no leading
  266. X.B 0x
  267. Xor
  268. X.B 0X
  269. X(use the '#' flag for that).
  270. X.TP
  271. X.B c
  272. Xspecifies character conversion; the argument should be of type
  273. X\fIchar\fR.
  274. X.TP
  275. X.B s
  276. Xspecifies string conversion; the argument should be of type
  277. X\fIchar *\fR.
  278. X.TP
  279. X.B f
  280. Xspecifies conversion to the form [-]ddd.dddd. The number
  281. Xof digits after the decimal point depends on precision; the default is 6.
  282. XIf the precision is 0, the decimal point is not printed (this can
  283. Xbe overriden with the '#' flag).
  284. X.B e,E
  285. Xspecify conversion to the form [-]ddd.dddd[eE][+-]ddd.
  286. XThe number of digits after the decimal point depends on precision;
  287. Xthe default is 6. If the precision is 0, the decimal point is not printed
  288. X(this can be overriden with the '#' flag).
  289. XThe exponent is at least 2 digit wide.
  290. X.TP
  291. X.B g,G
  292. Xspecify a conversion using the
  293. X.B e,E
  294. Xformat respectively if the
  295. Xexponent is less than -4 or greater than or equal to the precision;
  296. Xotherwise the 
  297. X.B f
  298. Xformat is used.
  299. X.TP
  300. X.B p
  301. Xis used to print pointers (type \fIvoid *\fR,
  302. Xor \fIchar *\fR if the compiler does not support the former).
  303. X.TP
  304. X.B n
  305. Xexpects a \fIint *\fR argument and puts in that integer 
  306. Xthe number of characters already printed by this call.
  307. X.TP
  308. X.B %
  309. Xis used to print a \fI%\fR.
  310. X.LP
  311. XIf an unknown conversion character is specified, the percent sign
  312. Xfollowed by that character will be printed.
  313. X.SH RETURN VALUE
  314. X.LP
  315. XIf no error occured, \fBSprint()\fR returns the number of characters
  316. Xprinted. In case of error, it returns \fBSIO_ERR\fR.
  317. X.SH BUGS
  318. X.LP
  319. XThis is a list of differences between \fBSprint()\fR and the ANSI C Standard
  320. X\fBprintf()\fR:
  321. X.LP
  322. X\fBSprint()\fR does not support non-removal of trailing zeroes for
  323. X\fBg\fR and \fBG\fR conversions when the '#' flag is used.
  324. X.LP
  325. X\fBSprint()\fR does not support the h and L modifiers.
  326. X.LP
  327. XThe current implementation assumes that \fIsizeof(int)==sizeof(long)\fR.
  328. X.LP
  329. X\fBSprint()\fR supports "%p" only if \fIsizeof(pointer)<=sizeof(int)\fR.
  330. END_OF_FILE
  331.   if test 5277 -ne `wc -c <'libs/src/sio/Sprint.3'`; then
  332.     echo shar: \"'libs/src/sio/Sprint.3'\" unpacked with wrong size!
  333.   fi
  334.   # end of 'libs/src/sio/Sprint.3'
  335. fi
  336. if test -f 'libs/src/sio/impl.h' -a "${1}" != "-c" ; then 
  337.   echo shar: Will not clobber existing file \"'libs/src/sio/impl.h'\"
  338. else
  339.   echo shar: Extracting \"'libs/src/sio/impl.h'\" \(5528 characters\)
  340.   sed "s/^X//" >'libs/src/sio/impl.h' <<'END_OF_FILE'
  341. X/*
  342. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  343. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  344. X * and conditions for redistribution.
  345. X */
  346. X
  347. X/*
  348. X * $Id: impl.h,v 8.1 1993/03/13 01:15:06 panos Exp $
  349. X */
  350. X
  351. X#ifndef SIO_BUFFER_SIZE
  352. X
  353. X#include "sioconf.h"
  354. X
  355. X#ifdef HAS_MMAP
  356. X#include <sys/types.h>
  357. X
  358. X
  359. X/*
  360. X * A struct map_unit describes a memory mapped area of a file.
  361. X *
  362. X * addr is the address where the file is mapped. If addr is NULL
  363. X * the other fields are meaningless.
  364. X * valid_bytes indicates how many bytes are _valid_ in that unit
  365. X * mapped_bytes of a unit is how many bytes are mapped in that
  366. X * unit ( valid <= mapped ).
  367. X * Normally mapped_bytes will be equal to valid_bytes until
  368. X * we reach the end of the file. Then if the file size is not a multiple
  369. X * of the unit size, only the rest of the file will be mapped at the
  370. X * unit, leaving part of what was mapped at the unit before still
  371. X * visible (this happens because I chose not to unmap a unit before
  372. X * remapping it). In that case valid_bytes shows the size of the "new"
  373. X * mapping and mapped_bytes shows how many bytes are really mapped.
  374. X * mapped_bytes is used in Sdone() to unmap the units.
  375. X */
  376. Xstruct map_unit
  377. X{
  378. X    caddr_t addr ;
  379. X    size_t valid_bytes ;
  380. X    size_t mapped_bytes ;
  381. X} ;
  382. X
  383. X
  384. X/*
  385. X * Meaning of fields used when memory mapping:
  386. X *
  387. X *    file_offset:      it is the offset in the file where the next
  388. X *                      mapping should be done
  389. X *
  390. X *    file_size:        size of the file (obtained from stat(2))
  391. X */
  392. Xstruct mmap_descriptor
  393. X{
  394. X   off_t file_offset ;
  395. X   off_t file_size ;
  396. X    struct map_unit first_unit ;
  397. X    struct map_unit second_unit ;
  398. X} ;
  399. X
  400. Xtypedef struct mmap_descriptor mapd_s ;
  401. X
  402. X#endif /* HAS_MMAP */
  403. X
  404. Xtypedef enum { FAILURE, SUCCESS } status_e ;
  405. X
  406. X/*
  407. X * Descriptor management: convert a descriptor pointer to an input or
  408. X * output descriptor pointer
  409. X */
  410. X#define IDP( dp )                        (&(dp)->descriptor.input_descriptor)
  411. X#define ODP( dp )                        (&(dp)->descriptor.output_descriptor)
  412. X
  413. X#define DESCRIPTOR_INITIALIZED( dp )    ((dp)->initialized)
  414. X
  415. X/*
  416. X * Internal constants
  417. X */
  418. X#define SIO_BUFFER_SIZE           8192
  419. X#define SIO_NO_TIED_FD                (-1)
  420. X
  421. Xtypedef enum { NO = 0, YES = 1 } boolean_e ;
  422. X
  423. X#ifndef FALSE
  424. X#define FALSE            0
  425. X#define TRUE            1
  426. X#endif
  427. X
  428. X#ifndef NULL
  429. X#define NULL            0
  430. X#endif
  431. X
  432. X#ifdef MIN
  433. X#undef MIN
  434. X#endif
  435. X#define MIN( a, b )                    ( (a) < (b) ? (a) : (b) )
  436. X
  437. X#define NUL                                '\0'
  438. X
  439. X#define PRIVATE                        static
  440. X
  441. X#ifdef DEBUG
  442. X
  443. Xstatic char *itoa( num )
  444. X    unsigned num ;
  445. X{
  446. X#define NUMBUF_SIZE        15
  447. X    static char numbuf[ NUMBUF_SIZE ] ;
  448. X    register char *p = &numbuf[ NUMBUF_SIZE ] ;
  449. X
  450. X    *--p = '\0' ;
  451. X    do
  452. X    {
  453. X        *--p = num % 10 + '0' ;
  454. X        num /= 10 ;
  455. X    }
  456. X    while ( num ) ;
  457. X    return( p ) ;
  458. X}
  459. X
  460. X#    define ASSERT( expr )                                                        \
  461. X        if ( ! (expr) )                                                            \
  462. X        {                                                                                \
  463. X            char *s1 = "SIO assertion << expr >> failed: File: " ;    \
  464. X            char *s2 = __FILE__ ;                                                \
  465. X            char *s3 = ", line: " ;                                                \
  466. X            char *s4 = itoa( __LINE__ ) ;                                        \
  467. X            char *s5 = "\n" ;                                                        \
  468. X            (void) write( 2, s1, strlen( s1 ) ) ;                            \
  469. X            (void) write( 2, s2, strlen( s2 ) ) ;                            \
  470. X            (void) write( 2, s3, strlen( s3 ) ) ;                            \
  471. X            (void) write( 2, s4, strlen( s4 ) ) ;                            \
  472. X            (void) write( 2, s5, strlen( s5 ) ) ;                            \
  473. X            exit ( 1 ) ;                                                            \
  474. X        }
  475. X#else
  476. X#    define ASSERT( expr )
  477. X#endif
  478. X
  479. X
  480. X#include <errno.h>
  481. Xextern int errno ;
  482. X
  483. X/*
  484. X * IO_SETUP initializes a descriptor if it is not already initialized.
  485. X * It checks if the stream is of the right type (input or output).
  486. X * CONTROL_SETUP checks if the descriptor is initialized and if the
  487. X * stream is of the right type (input or output). 
  488. X *
  489. X *     fd: file descriptor
  490. X *     dp: descriptor pointer
  491. X *     op: operation
  492. X *     ev: error value (if __sio_init fails; __sio_init should set errno) 
  493. X *
  494. X * IO_SETUP will call __sio_init if the descriptor is not initialized.
  495. X * Possible errors:
  496. X *        1. Using CONTROL_SETUP on an uninitialized descriptor.
  497. X *        2. The operation is not appropriate for the descriptor (e.g.
  498. X *            a read operation on an descriptor used for writing). 
  499. X * Both errors set errno to EBADF.
  500. X */
  501. X#define CONTROL_SETUP( dp, type, ev )                                                        \
  502. X            {                                                                                            \
  503. X                if ( ! DESCRIPTOR_INITIALIZED( dp ) || dp->stream_type != type )    \
  504. X                {                                                                                        \
  505. X                    errno = EBADF ;                                                                \
  506. X                    return( ev ) ;                                                                    \
  507. X                }                                                                                        \
  508. X            }
  509. X
  510. X
  511. X#define IO_SETUP( fd, dp, type, ev )                                                        \
  512. X            {                                                                                            \
  513. X                if ( DESCRIPTOR_INITIALIZED( dp ) )                                         \
  514. X                {                                                                                        \
  515. X                    if ( dp->stream_type != type )                                            \
  516. X                    {                                                                                    \
  517. X                        errno = EBADF ;                                                            \
  518. X                        return( ev ) ;                                                                \
  519. X                    }                                                                                    \
  520. X                }                                                                                        \
  521. X                else if ( __sio_init( dp, fd, type ) == SIO_ERR )                        \
  522. X                    return( ev ) ;                                                                    \
  523. X            }
  524. X
  525. X
  526. X/*
  527. X * Internal functions that are visible
  528. X */
  529. Xint __sio_readf(), __sio_writef(), __sio_pwritef() ;
  530. Xint __sio_extend_buffer(), __sio_init(), __sio_converter(), __sio_more() ;
  531. Xstatus_e __sio_switch() ;
  532. X
  533. X
  534. X#ifdef HAS_MEMOPS
  535. X#include <memory.h>
  536. X#define sio_memcopy( from, to, nbytes )       (void) memcpy( to, from, nbytes )
  537. X#define sio_memscan( from, nbytes, ch )      memchr( from, ch, nbytes )
  538. X#endif
  539. X
  540. X#ifdef HAS_BCOPY
  541. X#define sio_memcopy( from, to, nbytes )      (void) bcopy( from, to, nbytes )
  542. X#endif
  543. X
  544. X#ifndef sio_memcopy
  545. X#define sio_memcopy        __sio_memcopy
  546. X#define NEED_MEMCOPY
  547. Xvoid __sio_memcopy() ;
  548. X#endif
  549. X
  550. X#ifndef sio_memscan
  551. Xchar *sio_memscan() ;
  552. X#endif
  553. X
  554. X#endif /* SIO_BUFFER_SIZE */
  555. X
  556. END_OF_FILE
  557.   if test 5528 -ne `wc -c <'libs/src/sio/impl.h'`; then
  558.     echo shar: \"'libs/src/sio/impl.h'\" unpacked with wrong size!
  559.   fi
  560.   # end of 'libs/src/sio/impl.h'
  561. fi
  562. if test -f 'libs/src/sio/sioconf.h' -a "${1}" != "-c" ; then 
  563.   echo shar: Will not clobber existing file \"'libs/src/sio/sioconf.h'\"
  564. else
  565.   echo shar: Extracting \"'libs/src/sio/sioconf.h'\" \(5101 characters\)
  566.   sed "s/^X//" >'libs/src/sio/sioconf.h' <<'END_OF_FILE'
  567. X/*
  568. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  569. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  570. X * and conditions for redistribution.
  571. X */
  572. X
  573. X
  574. X/*
  575. X * $Id: sioconf.h,v 8.5 1993/03/17 02:54:47 panos Exp $
  576. X */
  577. X
  578. X/*
  579. X * This file has 2 sections:
  580. X *        1. a OS-specific section
  581. X *        2. a CPU/compiler-specific section
  582. X *
  583. X * You can override/redefing any of the constants/macros in this file.
  584. X * by uncommenting the inclusion of customconf.h and placing your own
  585. X * definitions in that file.
  586. X */
  587. X
  588. X/* #include "customconf.h" */
  589. X
  590. X
  591. X
  592. X/*
  593. X * OS-specific section.
  594. X *
  595. X * Features here use the flag HAS_<feature>.
  596. X * List of flags (check the following for macros that can be overriden):
  597. X *
  598. X *            HAS_MMAP (overridable macros)
  599. X *
  600. X *            HAS_ATEXIT
  601. X *            HAS_ONEXIT
  602. X *            HAS_OTHER_FINALIZER    (must define macros)
  603. X *
  604. X *            HAS_MEMOPS
  605. X *            HAS_BCOPY             (HAS_MEMOPS will be preferred if both are defined)
  606. X *
  607. X *    At least one of the following flags must be defined. The 2nd and 3rd
  608. X * flags are incompatible.
  609. X *            HAS_ISATTY
  610. X *            HAS_SYSVTTY
  611. X *            HAS_BSDTTY
  612. X */
  613. X
  614. X/*
  615. X * Memory mapping.
  616. X *        The library requires 3 macros: SIO_MMAP, SIO_MUNMAP, SIO_MNEED.
  617. X *        You can selectively override any of them.
  618. X *        Notice that the SIO_MNEED macro is not required. If your system
  619. X *        does not have madvise, you can define the macro as:
  620. X *            #define SIO_MNEED( addr, len )
  621. X */
  622. X#ifdef HAS_MMAP
  623. X
  624. X#if !defined( SIO_MMAP ) || !defined( SIO_MUNMAP ) || !defined( SIO_MNEED )
  625. X#include <sys/types.h>
  626. X#include <sys/mman.h>
  627. X#endif
  628. X
  629. X#ifndef SIO_MMAP
  630. X#define SIO_MMAP( addr, len, fd, off )                                  \
  631. X         mmap( addr, len, PROT_READ,                                    \
  632. X            ( addr == 0 ) ? MAP_PRIVATE : MAP_PRIVATE + MAP_FIXED,      \
  633. X               fd, off )
  634. X#endif
  635. X
  636. X#ifndef SIO_MUNMAP
  637. X#define SIO_MUNMAP( addr, len )  munmap( addr, len )
  638. X#endif
  639. X
  640. X#ifndef SIO_MNEED
  641. X#define SIO_MNEED( addr, len )      (void) madvise( addr, len, MADV_WILLNEED )
  642. X#endif
  643. X
  644. X#endif    /* HAS_MMAP */
  645. X
  646. X/*
  647. X * N_SIO_DESCRIPTORS is the maximum number of file descriptors
  648. X * supported by the OS
  649. X */
  650. X#ifndef N_SIO_DESCRIPTORS
  651. X#include <sys/param.h>
  652. X#define N_SIO_DESCRIPTORS        NOFILE
  653. X#endif
  654. X
  655. X
  656. X
  657. X/*
  658. X * Finalization function. 
  659. X *
  660. X * The purpose of this function is to do work after your program has
  661. X * called exit(3). In the case of SIO, this means flushing the SIO
  662. X * output buffers.
  663. X *
  664. X * If your system does not support atexit or onexit but has some other
  665. X * way of installing a finalization function, you define the flag 
  666. X * HAS_FINALIZER. Then you must define the macros 
  667. X *            SIO_FINALIZE and SIO_DEFINE_FIN
  668. X *
  669. X * SIO_FINALIZE attempts to install a finalization function and returns TRUE 
  670. X * if successful, FALSE if unsuccessful.
  671. X * SIO_DEFINE_FIN defines the finalization function (the reason for this macro
  672. X * s that different systems pass different number/type of arguments to the
  673. X * finalization function; the SIO finalization function does not use any
  674. X * arguments).
  675. X */
  676. X#if defined(HAS_ONEXIT) || defined(HAS_ATEXIT) || defined(HAS_FINALIZER)
  677. X
  678. X#define HAS_FINALIZATION_FUNCTION
  679. X
  680. X#if defined( HAS_ONEXIT ) && defined( HAS_ATEXIT )
  681. X#undef HAS_ONEXIT
  682. X#endif
  683. X
  684. X#ifdef HAS_ONEXIT
  685. X#define SIO_FINALIZE( func )        ( on_exit( func, (caddr_t) 0 ) == 0 )
  686. X#define SIO_DEFINE_FIN( func )      static void func ( exit_status, arg )  \
  687. X                                          int exit_status ;                \
  688. X                                          caddr_t arg ;
  689. X#endif    /* HAS_ONEXIT */
  690. X
  691. X#ifdef HAS_ATEXIT
  692. X#define SIO_FINALIZE( func )        ( atexit( func ) == 0 )
  693. X#define SIO_DEFINE_FIN( func )      static void func ()
  694. X#endif    /* HAS_ATEXIT */
  695. X
  696. X#endif    /* HAS_ONEXIT || HAS_ATEXIT || HAS_FINALIZER */
  697. X
  698. X
  699. X/*
  700. X * HAS_MEMOPS should be defined if your OS supports the mem* functions
  701. X * (memcpy etc). If not, then you can define HAS_BCOPY if your OS supports 
  702. X * bcopy.
  703. X */
  704. X#if defined( HAS_MEMOPS ) && defined( HAS_BCOPY )
  705. X#undef HAS_BCOPY
  706. X#endif
  707. X
  708. X
  709. X/*
  710. X * Support for the isatty(3) function. This function identifies if a 
  711. X * desciptor refers to a terminal.
  712. X *
  713. X * Case 1: isatty(3) is in the C library
  714. X *        --> define HAS_ISATTY
  715. X *    Case 2: no isatty(3), BSD 4.3 tty handling
  716. X *        --> define HAS_BSDTTY
  717. X * Case 3: no isatty(3), System V tty handling
  718. X *        --> define HAS_SYSVTTY
  719. X *
  720. X * The following code checks:
  721. X *        1) that at least one of the flags is defined
  722. X *        2) only one of the BSD, SYS V flags is defined
  723. X */
  724. X#if !defined(HAS_ISATTY) && !defined(HAS_BSDTTY) && !defined(HAS_SYSVTTY)
  725. XERROR function_isatty_not_available ;
  726. X#endif
  727. X
  728. X#ifdef HAS_ISATTY
  729. X#undef HAS_BSDTTY
  730. X#undef HAS_SYSVTTY
  731. X#endif
  732. X
  733. X#if defined(HAS_BSDTTY) && defined(HAS_SYSVTTY)
  734. XERROR HAS_BSDTTY_and_HAS_SYSVTTY_both_defined ;
  735. X#endif
  736. X
  737. X
  738. X
  739. X/*
  740. X * CPU/compiler-specific section.
  741. X *
  742. X * The following constant affects the behavior of Sprint.
  743. X *
  744. X * Sprint performs integer->string conversions by first converting
  745. X * the integer to the widest int type supported by the CPU/compiler.
  746. X * By default, this is the "long int" type. If your machine has
  747. X * a wider type, you can specify it by defining the WIDE_INT constant.
  748. X * For example:
  749. X *        #define WIDE_INT                    long long
  750. X */
  751. X
  752. END_OF_FILE
  753.   if test 5101 -ne `wc -c <'libs/src/sio/sioconf.h'`; then
  754.     echo shar: \"'libs/src/sio/sioconf.h'\" unpacked with wrong size!
  755.   fi
  756.   # end of 'libs/src/sio/sioconf.h'
  757. fi
  758. if test -f 'libs/src/sio/suite/copytest.c' -a "${1}" != "-c" ; then 
  759.   echo shar: Will not clobber existing file \"'libs/src/sio/suite/copytest.c'\"
  760. else
  761.   echo shar: Extracting \"'libs/src/sio/suite/copytest.c'\" \(4308 characters\)
  762.   sed "s/^X//" >'libs/src/sio/suite/copytest.c' <<'END_OF_FILE'
  763. X/*
  764. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  765. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  766. X * and conditions for redistribution.
  767. X */
  768. X
  769. Xstatic char RCSid[] = "$Id: copytest.c,v 8.2 1993/09/08 05:59:46 panos Exp $" ;
  770. X
  771. X#include "sio.h"
  772. X#include <stdio.h>
  773. X#include <syscall.h>
  774. X
  775. X#ifndef RANDOM
  776. X#define RANDOM        random
  777. X#endif
  778. X
  779. X
  780. X/*************************************************************/
  781. X
  782. X#ifdef TEST_Sread
  783. X
  784. X#define BUFFER_SIZE  4096
  785. X
  786. Xmain()
  787. X{
  788. X    char buf[ BUFFER_SIZE ] ;
  789. X    int cc ;
  790. X    int nbytes ;
  791. X
  792. X    for ( ;; )
  793. X    {
  794. X        nbytes = RANDOM() & ( BUFFER_SIZE - 1 ) ;
  795. X        if ( nbytes == 0 )
  796. X            nbytes = 1 ;
  797. X        cc = Sread( 0, buf, nbytes ) ;
  798. X        if ( cc == 0 )
  799. X            break ;
  800. X        if ( cc == SIO_ERR )
  801. X            exit( 1 ) ;
  802. X        write( 1, buf, cc ) ;
  803. X    }
  804. X    exit( 0 ) ;
  805. X}
  806. X#endif /* TEST_Sread */
  807. X
  808. X/*************************************************************/
  809. X
  810. X#ifdef TEST_Swrite
  811. X
  812. X#define BUFFER_SIZE  4096
  813. X
  814. Xmain()
  815. X{
  816. X    char buf[ BUFFER_SIZE ] ;
  817. X    int cc ;
  818. X    int nbytes ;
  819. X
  820. X    for ( ;; )
  821. X    {
  822. X        nbytes = RANDOM() & ( BUFFER_SIZE - 1 ) ;
  823. X        if ( nbytes == 0 )
  824. X            nbytes = 1 ;
  825. X        cc = read( 0, buf, nbytes ) ;
  826. X        if ( cc == 0 )
  827. X            break ;
  828. X        if ( Swrite( 1, buf, cc ) != cc )
  829. X            exit( 1 ) ;
  830. X    }
  831. X    exit( 0 ) ;
  832. X}
  833. X#endif /* TEST_Swrite */
  834. X
  835. X/*************************************************************/
  836. X
  837. X#ifdef TEST_Srdline
  838. X
  839. Xmain()
  840. X{
  841. X    char *s ;
  842. X    int count=0 ;
  843. X
  844. X    while ( s = Srdline( 0 ) )
  845. X    {
  846. X        puts( s ) ;
  847. X        count++ ;
  848. X    }
  849. X    Sdone( 0 ) ;
  850. X    exit( 0 ) ;
  851. X}
  852. X
  853. X#endif  /* TEST_Srdline */
  854. X
  855. X/*************************************************************/
  856. X
  857. X#ifdef TEST_Sputchar
  858. X
  859. Xmain()
  860. X{
  861. X    int c ;
  862. X
  863. X    while ( ( c = getchar() ) != EOF )
  864. X        if ( Sputchar( 1, c ) != c )
  865. X            exit( 1 ) ;
  866. X    exit( 0 ) ;
  867. X}
  868. X
  869. X#endif /* TEST_Sputchar */
  870. X
  871. X/*************************************************************/
  872. X
  873. X#ifdef TEST_Sgetchar
  874. X
  875. Xmain()
  876. X{
  877. X    int c ;
  878. X
  879. X    while ( ( c = Sgetchar( 0 ) ) != SIO_EOF )
  880. X        putchar( c ) ;
  881. X    exit( 0 ) ;
  882. X}
  883. X
  884. X#endif    /* TEST_Sgetchar */
  885. X
  886. X/*************************************************************/
  887. X
  888. X#ifdef TEST_Sputc
  889. X
  890. Xmain()
  891. X{
  892. X   int c ;
  893. X   while ( ( c = getchar() ) != EOF )
  894. X      if ( Sputc( 1, c ) != c )
  895. X         exit( 1 ) ;
  896. X   exit( 0 ) ;
  897. X}
  898. X
  899. X#endif /* TEST_Sputc */
  900. X
  901. X/*************************************************************/
  902. X
  903. X#ifdef TEST_Sgetc
  904. X
  905. Xmain()
  906. X{
  907. X   int c ;
  908. X
  909. X   while ( ( c = Sgetc( 0 ) ) != SIO_EOF )
  910. X      putchar( c ) ;
  911. X   exit( 0 ) ;
  912. X}
  913. X
  914. X#endif /* TEST_Sgetc */
  915. X
  916. X/*************************************************************/
  917. X
  918. X#ifdef TEST_Sfetch
  919. X
  920. Xmain()
  921. X{
  922. X    char *s ;
  923. X    int len ;
  924. X
  925. X    while ( s = Sfetch( 0, &len ) )
  926. X        fwrite( s, 1, len, stdout ) ;
  927. X    exit( 0 ) ;
  928. X}
  929. X
  930. X#endif /* TEST_Sfetch */
  931. X
  932. X/*************************************************************/
  933. X
  934. X#ifdef TEST_Sflush
  935. X
  936. X#define MAX_COUNT        100
  937. X
  938. Xmain()
  939. X{
  940. X    int c ;
  941. X    int errval ;
  942. X    int count = 0 ;
  943. X    int max_count = RANDOM() % MAX_COUNT + 1 ;
  944. X
  945. X    while ( ( c = getchar() ) != EOF )
  946. X        if ( Sputchar( 1, c ) != c )
  947. X            exit( errval ) ;
  948. X        else
  949. X        {
  950. X            count++ ;
  951. X            if ( count >= max_count )
  952. X            {
  953. X                errval = Sflush( 1 ) ;
  954. X                if ( errval != 0 )
  955. X                    exit( 1 ) ;
  956. X                max_count = RANDOM() % MAX_COUNT + 1 ;
  957. X                count = 0 ;
  958. X            }
  959. X        }
  960. X    exit( 0 ) ;
  961. X}
  962. X
  963. X#endif /* TEST_Sflush */
  964. X
  965. X/*************************************************************/
  966. X
  967. X#ifdef TEST_Sundo
  968. X
  969. Xmain()
  970. X{
  971. X    int c ;
  972. X    char *s ;
  973. X    int errval ;
  974. X
  975. X    for ( ;; )
  976. X    {
  977. X        if ( RANDOM() % 1 )
  978. X        {
  979. X            s = Srdline( 0 ) ;
  980. X            if ( s == NULL )
  981. X                break ;
  982. X            if ( RANDOM() % 16 < 5 )
  983. X            {
  984. X                errval = Sundo( 0, SIO_UNDO_LINE ) ;
  985. X                if ( errval == SIO_ERR )
  986. X                    exit( 1 ) ;
  987. X            }
  988. X            else
  989. X                puts( s ) ;
  990. X        }
  991. X        else
  992. X        {
  993. X            c = Sgetchar( 0 ) ;
  994. X            if ( c == SIO_EOF )
  995. X                break ;
  996. X            if ( RANDOM() % 16 < 5 )
  997. X            {
  998. X                errval = Sundo( 0, SIO_UNDO_CHAR ) ;
  999. X                if ( errval == SIO_ERR )
  1000. X                    exit( 2 ) ;
  1001. X            }
  1002. X            else
  1003. X                putchar( c ) ;
  1004. X        }
  1005. X    }
  1006. X    exit( 0 ) ;
  1007. X}
  1008. X
  1009. X#endif /* TEST_Sundo */
  1010. X
  1011. X
  1012. X#if defined( TEST_switch ) || defined( TEST_switch2 )
  1013. X
  1014. Xmain()
  1015. X{
  1016. X    int c ;
  1017. X    char *s ;
  1018. X    int lines = 4000 ;
  1019. X
  1020. X    for ( ;; )
  1021. X    {
  1022. X        c = Sgetchar( 0 ) ;
  1023. X        if ( c == SIO_EOF )
  1024. X            exit( 0 ) ;
  1025. X        if ( c == SIO_ERR )
  1026. X            exit( 1 ) ;
  1027. X        putchar( c ) ;
  1028. X        if ( c == '\n' )
  1029. X        {
  1030. X            lines-- ;
  1031. X            if ( lines == 0 )
  1032. X                break ;
  1033. X        }
  1034. X    }
  1035. X    while ( s = Srdline( 0 ) )
  1036. X        puts( s ) ;
  1037. X    exit( 0 ) ;
  1038. X}
  1039. X
  1040. X#ifdef TEST_switch2
  1041. X
  1042. Xchar *mmap( addr, len, prot, type, fd, off )
  1043. X    char *addr ;
  1044. X    int len, prot, type, fd, off ;
  1045. X{
  1046. X    return( (char *)-1 ) ;
  1047. X}
  1048. X
  1049. X#endif    /* TEST_switch2 */
  1050. X
  1051. X#endif     /* TEST_switch */
  1052. X
  1053. X
  1054. X
  1055. END_OF_FILE
  1056.   if test 4308 -ne `wc -c <'libs/src/sio/suite/copytest.c'`; then
  1057.     echo shar: \"'libs/src/sio/suite/copytest.c'\" unpacked with wrong size!
  1058.   fi
  1059.   # end of 'libs/src/sio/suite/copytest.c'
  1060. fi
  1061. if test -f 'libs/src/sio/suite/tester' -a "${1}" != "-c" ; then 
  1062.   echo shar: Will not clobber existing file \"'libs/src/sio/suite/tester'\"
  1063. else
  1064.   echo shar: Extracting \"'libs/src/sio/suite/tester'\" \(3962 characters\)
  1065.   sed "s/^X//" >'libs/src/sio/suite/tester' <<'END_OF_FILE'
  1066. X#!/bin/sh
  1067. X
  1068. X# (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  1069. X# All rights reserved.  The file named COPYRIGHT specifies the terms 
  1070. X# and conditions for redistribution.
  1071. X
  1072. X
  1073. X#
  1074. X# $Id: tester,v 8.3 1993/09/08 05:59:30 panos Exp $
  1075. X#
  1076. X
  1077. X#
  1078. X# Usage:
  1079. X#            tester [all] [function-name function-name ...]
  1080. X#
  1081. X# function-name is the name of a sio function (or macro)
  1082. X#
  1083. X# If "all" is used, functions after it will *not* be tested.
  1084. X#
  1085. X
  1086. Xscript_name=`basename $0`
  1087. X
  1088. Xcopy_file=/usr/dict/words
  1089. Xtemp_file=/tmp/w
  1090. Xmake_log=MAKE.LOG
  1091. X
  1092. Xif test ! -f $copy_file ; then
  1093. X    echo "The file '$copy_file' is not available."
  1094. X    echo "Please edit the '$script_name' script and change set the"
  1095. X    echo "variable 'copy_file' to the name of a publicly readable file"
  1096. X    echo "with at least a few tens of thousands of lines."
  1097. X    exit 1
  1098. Xfi
  1099. X
  1100. Xtrap_function()
  1101. X{
  1102. X    rm -f $temp_file $make_log
  1103. X    echo
  1104. X    exit 1
  1105. X}
  1106. X
  1107. X
  1108. Xmake_program()
  1109. X{
  1110. X    target=$1
  1111. X    cflags="$2"
  1112. X    if test -f $1 -a ! -x $1 ; then rm -f $1 ; fi
  1113. X    if test "$cflags"
  1114. X    then
  1115. X        make -s "$cflags" $target >$make_log 2>&1
  1116. X    else
  1117. X        make -s $target >$make_log 2>&1
  1118. X    fi
  1119. X    exit_code=$?
  1120. X    if test $exit_code -eq 0 -a -x $1
  1121. X    then
  1122. X        rm -f $make_log
  1123. X    else
  1124. X        echo "FAILED"
  1125. X        echo "   The make failed. Check the make log file << $make_log >>"
  1126. X        exit
  1127. X    fi
  1128. X}
  1129. X
  1130. X
  1131. X
  1132. X#
  1133. X# test_function expects a single argument, the name of the function
  1134. X# it will test.
  1135. X# It creates a program that has the name of the function by invoking
  1136. X# make with the symbol -DTEST_<function_name>
  1137. X#
  1138. Xtest_function()
  1139. X{
  1140. X    expression="echo $"$1
  1141. X    var=`eval $expression`
  1142. X    if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  1143. X
  1144. X    echo -n "TESTING $1 "
  1145. X    make_program $1 "DEFS=-DTEST_$1"
  1146. X
  1147. X    ./$1 < $copy_file >$temp_file
  1148. X    exit_code=$?
  1149. X    if test $exit_code -ne 0
  1150. X    then
  1151. X        echo "FAILED"
  1152. X        echo "   Test program exited with exit code $exit_code"
  1153. X        echo "   Temporary file << $temp_file >> not deleted"
  1154. X        exit
  1155. X    fi
  1156. X    cmp -s $copy_file $temp_file
  1157. X    if test $? -ne 0
  1158. X    then
  1159. X        echo "FAILED"
  1160. X        echo "   The files << $copy_file >> and << $temp_file >> are not the same"
  1161. X        exit
  1162. X    else
  1163. X        echo PASSED
  1164. X    fi
  1165. X    rm -f $temp_file
  1166. X}
  1167. X
  1168. X
  1169. Xtest_sprint()
  1170. X{
  1171. X    var=$Sprint
  1172. X    program=Sprint
  1173. X    if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  1174. X
  1175. X    echo TESTING Sprint
  1176. X    make_program $program ""
  1177. X    $TESTSHELL sprint_test
  1178. X}
  1179. X
  1180. X
  1181. Xtest_smorefds()
  1182. X{
  1183. X    var=$Smorefds
  1184. X    program=fdtest
  1185. X    if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
  1186. X
  1187. X    echo -n "TESTING Smorefds "
  1188. X    make_program $program "DEFS="
  1189. X    v=`fdtest 2>&1`
  1190. X    if test $? -eq 0 ; then
  1191. X        echo PASSED
  1192. X    else
  1193. X        echo "FAILED: $v"
  1194. X    fi
  1195. X}
  1196. X
  1197. X
  1198. Xtrap trap_function 1 2 3 15
  1199. X
  1200. X#
  1201. X# There is a variable for every function to be tested. That variable
  1202. X# can have the values "yes", "no" or "".
  1203. X# When a function is specified, it takes the value of $run. Initially $run 
  1204. X# is "yes", so a specified function has its variable set to "yes". 
  1205. X# If "all" is specified, $run becomes "no", so subsequently specified
  1206. X# functions, have their variables set to "no".
  1207. X#
  1208. X# We test a function iff:
  1209. X#        its variable is "yes" OR its variable is "" and $all is "yes"
  1210. X# We don't test a function iff:
  1211. X#        its variable is "no" OR its variable is "" and $all is "no"
  1212. X#        
  1213. X# Therefore, all functions specified after "all" will NOT be tested.
  1214. X#
  1215. Xrun=yes
  1216. Xall=no
  1217. X
  1218. Xwhile test $# -gt 0
  1219. Xdo
  1220. X    case $1 in
  1221. X        Sputchar)    Sputchar=$run ;;
  1222. X        Sgetchar)    Sgetchar=$run ;;
  1223. X        Srdline)        Srdline=$run ;;
  1224. X        Sfetch)        Sfetch=$run ;;
  1225. X        Sread)        Sread=$run ;;
  1226. X        Swrite)        Swrite=$run ;;
  1227. X        Sgetc)        Sgetc=$run ;;
  1228. X        Sputc)        Sputc=$run ;;
  1229. X        Sflush)        Sflush=$run ;;
  1230. X        Sundo)        Sundo=$run ;;
  1231. X        Sprint)        Sprint=$run ;;
  1232. X        switch)        switch=$run ;;
  1233. X        switch2)        switch2=$run ;;
  1234. X        Smorefds)    Smorefds=$run ;;
  1235. X        all)            all=yes ; run="no" ;;
  1236. X        *) echo Bad argument: $1
  1237. X    esac
  1238. X    shift
  1239. Xdone
  1240. X
  1241. Xtest_function Sgetchar
  1242. Xtest_function Sputchar
  1243. Xtest_function Sread
  1244. Xtest_function Swrite
  1245. Xtest_function Srdline
  1246. Xtest_function Sfetch
  1247. Xtest_function Sgetc
  1248. Xtest_function Sputc
  1249. Xtest_function Sflush
  1250. Xtest_function Sundo
  1251. Xtest_function switch
  1252. Xtest_function switch2
  1253. Xtest_smorefds
  1254. Xtest_sprint
  1255. X
  1256. END_OF_FILE
  1257.   if test 3962 -ne `wc -c <'libs/src/sio/suite/tester'`; then
  1258.     echo shar: \"'libs/src/sio/suite/tester'\" unpacked with wrong size!
  1259.   fi
  1260.   # end of 'libs/src/sio/suite/tester'
  1261. fi
  1262. if test -f 'libs/src/str/Makefile' -a "${1}" != "-c" ; then 
  1263.   echo shar: Will not clobber existing file \"'libs/src/str/Makefile'\"
  1264. else
  1265.   echo shar: Extracting \"'libs/src/str/Makefile'\" \(4534 characters\)
  1266.   sed "s/^X//" >'libs/src/str/Makefile' <<'END_OF_FILE'
  1267. X# (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  1268. X# All rights reserved.  The file named COPYRIGHT specifies the terms 
  1269. X# and conditions for redistribution.
  1270. X
  1271. X#
  1272. X# $Id: Makefile,v 3.3 1993/11/12 20:15:25 panos Exp $
  1273. X#
  1274. X# Based on Library makefile template: *Revision: 1.15 *
  1275. X#
  1276. X
  1277. X# 
  1278. X# Available entries:
  1279. X#         lib             --> creates the library
  1280. X#        install        --> installs the library (archive, man page(s), header(s))
  1281. X#        uninstall    --> uninstall the library
  1282. X#        clean            --> removes all .o and .a files
  1283. X#        spotless        --> clean + uninstall
  1284. X#         lint            --> lints a file (usage: make lint MODULE=foo.c)
  1285. X#        tags            --> creates a tags file (from the SOURCES and HEADERS)
  1286. X#        checkout     --> checkout all files
  1287. X#        dist            --> distribution support
  1288. X#
  1289. X
  1290. XNAME                = str
  1291. XVERSION            = 1.4.2
  1292. X
  1293. XHEADERS            = str.h strparse.h \
  1294. X                        ss_impl.h ss_rk.h ss_kmp.h ss_sbm.h ss_bmh.h ss_so.h
  1295. XSOURCES            = strutil.c strprint.c strparse.c strs.c \
  1296. X                        ss_rk.c ss_kmp.c ss_bf.c ss_sbm.c ss_bmh.c ss_so.c
  1297. XOBJECTS            = strutil.o strprint.o strparse.o strs.o \
  1298. X                        ss_rk.o ss_kmp.o ss_bf.o ss_sbm.o ss_bmh.o ss_so.o
  1299. X
  1300. XMANFILES            = strparse.3 strprint.3 strutil.3 strs.3
  1301. XINCLUDEFILES    = str.h
  1302. X
  1303. X# The following variables are used by the 'install' entry and
  1304. X# should be customized:
  1305. X#     LIBDIR:     where the library will be placed
  1306. X#     INCUDEDIR:  where the include files will be placed
  1307. X#     MANDIR:     where the man pages will be placed
  1308. X#
  1309. XLIBDIR            = $(HOME)/.links/libraries/$(ARCH)
  1310. XMANDIR            = $(HOME)/.links/manpages/man3
  1311. XINCLUDEDIR        = $(HOME)/.links/includes
  1312. X
  1313. X#
  1314. X# Available flags
  1315. X#    NBIC                : number of bits in a character variable (defaults to 8)
  1316. X#    WIDE_INT            : widest integer supported by the CPU/compiler
  1317. X#                          (defaults to 'long')
  1318. X#    WIDE_INT_SIZE  : size of the WIDE_INT type in bits (defaults to 32);
  1319. X#                          effective (and required) only when WIDE_INT is defined
  1320. X#    NO_SIO            : if the SIO library is not available (results in turning
  1321. X#                          all the string printing functions to no-ops)
  1322. X#
  1323. XDEFS                =         # for example, -DNO_SIO
  1324. XDEBUG                = -g                # -g or -O
  1325. XVERSION_DEF        = -DVERSION=\"STR\ Version\ $(VERSION)\"
  1326. X
  1327. XCPP_DEFS            = $(VERSION_DEF) $(DEFS)
  1328. X
  1329. X#
  1330. X# The following variables shouldn't need to be changed
  1331. X#
  1332. XLINT_FLAGS        = -hbux
  1333. XCPP_FLAGS        = $(CPP_DEFS) -I$(INCLUDEDIR)
  1334. XCC_FLAGS            = $(DEBUG)
  1335. XCFLAGS            = $(CPP_FLAGS) $(CC_FLAGS)
  1336. X
  1337. XINSTALL            = install -c
  1338. XFMODE                = -m 640            # used by install
  1339. XRANLIB            = ranlib
  1340. X
  1341. XPAGER                = less
  1342. X
  1343. X
  1344. XLIBNAME            = lib$(NAME).a
  1345. X
  1346. Xlib: $(LIBNAME)
  1347. X
  1348. Xlibopt: clean
  1349. X    make DEBUG=-O "DEFS=$(DEFS)" lib
  1350. X    $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR)-O
  1351. X
  1352. X$(LIBNAME): $(OBJECTS)
  1353. X    ar r $@ $?
  1354. X    $(RANLIB) $@
  1355. X
  1356. XLINT_IGNORE=possible pointer alignment|RCSid unused
  1357. X
  1358. Xlint:
  1359. X    lint $(CPP_FLAGS) $(LINT_FLAGS) $(MODULE) 2>&1 | egrep -v '$(LINT_IGNORE)' | $(PAGER)
  1360. X
  1361. Xinstall: $(LIBNAME)
  1362. X    @if test "$(LIBDIR)" -a "$(INCLUDEDIR)" -a "$(MANDIR)" ;\
  1363. X    then \
  1364. X        $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR) ;\
  1365. X        echo "Installed $(LIBNAME) to $(LIBDIR)" ;\
  1366. X        for i in $(INCLUDEFILES); do $(INSTALL) $(FMODE) $$i $(INCLUDEDIR) ; done ;\
  1367. X        echo Installed $(INCLUDEFILES) to $(INCLUDEDIR) ;\
  1368. X        for i in $(MANFILES) ; do $(INSTALL) $(FMODE) $$i $(MANDIR) ; done ;\
  1369. X        echo Installed $(MANFILES) to $(MANDIR) ;\
  1370. X    else \
  1371. X        echo "You forgot to set one of the following variables: LIBDIR,INCLUDEDIR,MANDIR" ;\
  1372. X    fi
  1373. X
  1374. Xuninstall:
  1375. X    a=`pwd` ; cd $(INCLUDEDIR) ;\
  1376. X    if test $$a != `pwd` ; then rm -f $(INCLUDEFILES) ; fi
  1377. X    a=`pwd` ; cd $(LIBDIR) ;\
  1378. X    if test $$a != `pwd` ; then rm -f $(LIBNAME) ; fi
  1379. X    a=`pwd` ; cd $(MANDIR) ;\
  1380. X    if test $$a != `pwd` ; then rm -f $(MANFILES) ; fi
  1381. X
  1382. Xclean:
  1383. X    rm -f $(OBJECTS) $(LIBNAME) core
  1384. X
  1385. Xspotless: clean uninstall
  1386. X
  1387. Xtags: $(SOURCES) $(HEADERS)
  1388. X    ctags -w $(SOURCES) $(HEADERS)
  1389. X
  1390. Xcheckout:
  1391. X    co $(SOURCES) $(HEADERS) $(MANFILES)
  1392. X
  1393. X#
  1394. X# Distribution section
  1395. X# This section contains the 2 targets for distribution support: dist, dirs
  1396. X# "dist" checks out all files to be distributed
  1397. X# "dirs" prints a list of directories to be included in the distribution.
  1398. X# These directories should have a Makefile with a "dist" target
  1399. X#
  1400. XDISTRIBUTION_FILES    = $(SOURCES) $(HEADERS) $(MANFILES) COPYRIGHT README
  1401. XDIRS                        =
  1402. X
  1403. Xdist:
  1404. X    -co -q $(DISTRIBUTION_FILES)
  1405. X
  1406. Xdirs:
  1407. X    @echo $(DIRS)
  1408. X
  1409. X#
  1410. X# PUT HERE THE RULES TO MAKE THE OBJECT FILES
  1411. X#
  1412. Xstrparse.o:        strparse.h str.h
  1413. Xstrprint.o:        str.h
  1414. Xstrutil.o:        str.h
  1415. Xstrs.o:            ss_impl.h str.h
  1416. Xss_bf.o:            ss_impl.h
  1417. Xss_rk.o:            ss_impl.h ss_rk.h
  1418. Xss_kmp.o:        ss_impl.h ss_kmp.h
  1419. Xss_sbm.o:        ss_impl.h ss_sbm.h
  1420. Xss_bmh.o:        ss_impl.h ss_bmh.h
  1421. Xss_so.o:            ss_impl.h ss_so.h
  1422. X
  1423. X
  1424. X#
  1425. X# Test program
  1426. X#
  1427. Xtt: tt.c $(LIBNAME)
  1428. X    $(CC) -I$(INCDIR) -g -o $@ tt.c $(LIBNAME) -L$(LIBDIR) -lsio -lmisc
  1429. X
  1430. END_OF_FILE
  1431.   if test 4534 -ne `wc -c <'libs/src/str/Makefile'`; then
  1432.     echo shar: \"'libs/src/str/Makefile'\" unpacked with wrong size!
  1433.   fi
  1434.   # end of 'libs/src/str/Makefile'
  1435. fi
  1436. if test -f 'libs/src/str/strparse.c' -a "${1}" != "-c" ; then 
  1437.   echo shar: Will not clobber existing file \"'libs/src/str/strparse.c'\"
  1438. else
  1439.   echo shar: Extracting \"'libs/src/str/strparse.c'\" \(4683 characters\)
  1440.   sed "s/^X//" >'libs/src/str/strparse.c' <<'END_OF_FILE'
  1441. X/*
  1442. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  1443. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  1444. X * and conditions for redistribution.
  1445. X */
  1446. X
  1447. Xstatic char RCSid[] = "$Id: strparse.c,v 3.1 1993/06/13 02:48:19 panos Exp $" ;
  1448. Xstatic char version[] = VERSION ;
  1449. X
  1450. X#include "str.h"
  1451. X#include "strparse.h"
  1452. X
  1453. Xchar *strcpy() ;
  1454. Xchar *strncpy() ;
  1455. Xchar *strpbrk() ;
  1456. X
  1457. Xchar *malloc() ;
  1458. X
  1459. Xint str_errno ;
  1460. X
  1461. X
  1462. XPRIVATE char *new_string( s )
  1463. X    register char *s ;
  1464. X{
  1465. X    register char *p = malloc( (unsigned)strlen( s ) + 1 ) ;
  1466. X
  1467. X    return( p ? strcpy( p, s ) : p ) ;
  1468. X}
  1469. X
  1470. X
  1471. Xstr_h str_parse( str, separ, flags, errnop )
  1472. X    register char    *str ;
  1473. X    char                *separ ;
  1474. X    int                flags ;
  1475. X    int                *errnop ;
  1476. X{
  1477. X    register struct str_handle *hp ;
  1478. X    int *errp = ( errnop == NULL ) ? &str_errno : errnop ;
  1479. X
  1480. X    if ( separ == NULL )
  1481. X        HANDLE_ERROR( flags, NULL, errp, STR_ENULLSEPAR,
  1482. X                                "STR str_parse: NULL separator\n" ) ;
  1483. X
  1484. X    hp = (struct str_handle *) malloc( sizeof( struct str_handle ) ) ;
  1485. X    if ( hp == NULL )
  1486. X        HANDLE_ERROR( flags, NULL, errp, STR_ENOMEM,
  1487. X                                "STR str_parse: malloc failed\n" ) ;
  1488. X
  1489. X    hp->string = str ;
  1490. X    hp->pos = str ;
  1491. X    hp->separator = new_string( separ ) ;
  1492. X    if ( hp->separator == NULL )
  1493. X        if ( flags & STR_RETURN_ERROR )
  1494. X        {
  1495. X            free( (char *) hp ) ;
  1496. X            *errp = STR_ENOMEM ;
  1497. X            return( NULL ) ;
  1498. X        }
  1499. X        else
  1500. X            TERMINATE( "STR str_parse: malloc failed\n" ) ;
  1501. X    
  1502. X    hp->flags = flags ;
  1503. X    hp->errnop = errp ;
  1504. X    hp->no_more = ( str == NULL ) ;
  1505. X    return( (str_h) hp ) ;
  1506. X}
  1507. X
  1508. X
  1509. Xvoid str_endparse( handle )
  1510. X    str_h handle ;
  1511. X{
  1512. X    register struct str_handle *hp = (struct str_handle *) handle ;
  1513. X
  1514. X    free( hp->separator ) ;
  1515. X    free( (char *) handle ) ;
  1516. X}
  1517. X
  1518. X
  1519. X/*
  1520. X * Change the string
  1521. X */
  1522. Xint str_setstr( handle, newstr )
  1523. X    str_h handle ;
  1524. X    char *newstr ;
  1525. X{
  1526. X    register struct str_handle *hp = (struct str_handle *) handle ;
  1527. X    
  1528. X    if ( newstr == NULL )
  1529. X        HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENULLSTRING,
  1530. X                                "STR str_setstr: NULL string\n" ) ;
  1531. X    
  1532. X    hp->string = newstr ;
  1533. X    hp->pos = newstr ;
  1534. X    hp->no_more = FALSE ;
  1535. X    return( STR_OK ) ;
  1536. X}
  1537. X
  1538. X
  1539. X
  1540. X/*
  1541. X * Change the separator
  1542. X */
  1543. Xint str_separator( handle, separator )
  1544. X    str_h handle ;
  1545. X    char *separator ;
  1546. X{
  1547. X    register struct str_handle *hp = (struct str_handle *) handle ;
  1548. X    char *new_separator ;
  1549. X
  1550. X    if ( separator == NULL )
  1551. X        HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENULLSEPAR,
  1552. X                                "STR str_separator: NULL separator\n" ) ;
  1553. X    new_separator = new_string( separator ) ;
  1554. X    if ( new_separator == NULL )
  1555. X        HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENOMEM,
  1556. X            "STR str_separator: malloc failed\n" ) ;
  1557. X
  1558. X    free( hp->separator ) ;
  1559. X    hp->separator = new_separator ;
  1560. X    return( STR_OK ) ;
  1561. X}
  1562. X
  1563. X
  1564. Xchar *str_nextpos( handle )
  1565. X    str_h handle ;
  1566. X{
  1567. X    struct str_handle *hp = (struct str_handle *) handle ;
  1568. X
  1569. X    if ( hp->no_more || *hp->pos == '\0' )
  1570. X        return( NULL ) ;
  1571. X    else
  1572. X        return( hp->pos ) ;
  1573. X}
  1574. X
  1575. X
  1576. Xchar *str_component( handle )
  1577. X    str_h handle ;
  1578. X{
  1579. X    register char                        *start ;
  1580. X    register char                        *last ;
  1581. X    register int                        sep_count ;
  1582. X    char                                    *retval ;
  1583. X    int                                    last_char ;
  1584. X    register struct str_handle        *hp            = (struct str_handle *) handle ;
  1585. X    register int                        first_call    = ( hp->pos == hp->string ) ;
  1586. X
  1587. X    if ( hp->no_more )
  1588. X        return( NULL ) ;
  1589. X
  1590. X    /*
  1591. X     * Get number of separator characters.
  1592. X     * Find beginning of component.
  1593. X     */
  1594. X    sep_count = strspn( hp->pos, hp->separator ) ;
  1595. X
  1596. X    /*
  1597. X     * If this is the first call, and there are separator characters
  1598. X     * at the beginning of the string and the STR_NULL_START flag is set
  1599. X     * we return a 0-length string.
  1600. X     */
  1601. X    if ( first_call && sep_count > 0 && ( hp->flags & STR_NULL_START ) )
  1602. X    {
  1603. X        start = hp->pos ;
  1604. X        last = hp->pos ;
  1605. X    }
  1606. X    else
  1607. X    {
  1608. X        start = hp->pos + sep_count ;
  1609. X
  1610. X        if ( *start == '\0' )
  1611. X        {
  1612. X            last = start ;
  1613. X            hp->no_more = TRUE ;
  1614. X            if ( ! ( hp->flags & STR_NULL_END ) )
  1615. X                return( NULL ) ;
  1616. X        }
  1617. X        else
  1618. X        {
  1619. X            last = strpbrk( start, hp->separator ) ;
  1620. X            if ( last == NULL )
  1621. X                last = start + strlen( start ) ;
  1622. X        }
  1623. X    }
  1624. X
  1625. X    /*
  1626. X     * At this point, the following variables must be set:
  1627. X     *        start:    beginning of component
  1628. X     *        last:       end of component + 1
  1629. X     *
  1630. X     * If STR_MALLOC is set, allocate space for the new string.
  1631. X     *
  1632. X     * NOTE: If STR_MALLOC is not set, the processed string is trashed.
  1633. X     */
  1634. X    last_char = *last ;
  1635. X    if ( hp->flags & STR_MALLOC )
  1636. X    {
  1637. X        int len = last - start ;
  1638. X
  1639. X        retval = malloc( (unsigned)len + 1 ) ;
  1640. X        if ( retval == NULL )
  1641. X            HANDLE_ERROR( hp->flags, NULL, hp->errnop, STR_ENOMEM,
  1642. X                                            "STR str_component: malloc failed\n" ) ;
  1643. X        strncpy( retval, start, len )[ len ] = '\0' ;
  1644. X    }
  1645. X    else
  1646. X    {
  1647. X        retval = start ;
  1648. X        *last = '\0' ;
  1649. X    }
  1650. X
  1651. X    /*
  1652. X     * Check if last_char is NUL to avoid setting hp->pos past the
  1653. X     * end of the string
  1654. X     */
  1655. X    hp->pos = ( last_char == '\0' ) ? last : last+1 ;
  1656. X    return( retval ) ;
  1657. X}
  1658. X
  1659. X
  1660. END_OF_FILE
  1661.   if test 4683 -ne `wc -c <'libs/src/str/strparse.c'`; then
  1662.     echo shar: \"'libs/src/str/strparse.c'\" unpacked with wrong size!
  1663.   fi
  1664.   # end of 'libs/src/str/strparse.c'
  1665. fi
  1666. if test -f 'libs/src/str/strs.3' -a "${1}" != "-c" ; then 
  1667.   echo shar: Will not clobber existing file \"'libs/src/str/strs.3'\"
  1668. else
  1669.   echo shar: Extracting \"'libs/src/str/strs.3'\" \(4394 characters\)
  1670.   sed "s/^X//" >'libs/src/str/strs.3' <<'END_OF_FILE'
  1671. X.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  1672. X.\"All rights reserved.  The file named COPYRIGHT specifies the terms 
  1673. X.\"and conditions for redistribution.
  1674. X.\"
  1675. X.\" $Id: strs.3,v 3.1 1993/06/13 02:49:50 panos Exp $
  1676. X.TH STRS 3X "12 June 1993"
  1677. X.SH NAME
  1678. Xstrs_setup, strs_match, strs_done, strs_search - string matching functions
  1679. X.SH SYNOPSIS
  1680. X.LP
  1681. X.nf
  1682. X.ft B
  1683. X#include "str.h"
  1684. X.LP
  1685. X.ft B
  1686. Xstrs_h strs_setup( flags, pattern [, patlen] )
  1687. Xint flags ;
  1688. Xchar *pattern ;
  1689. X.LP
  1690. X.ft B
  1691. Xchar *strs_match( handle, str, len )
  1692. Xstrs_h handle ;
  1693. Xchar *str ;
  1694. Xint len ;
  1695. X.LP
  1696. X.ft B
  1697. Xvoid strs_done( handle )
  1698. Xstrs_h handle ;
  1699. X.LP
  1700. X.ft B
  1701. Xchar *strs_search( flags, str, len, pattern [, patlen] )
  1702. Xint flags ;
  1703. Xchar *str ;
  1704. Xint len ;
  1705. Xchar *pattern ;
  1706. X.SH DESCRIPTION
  1707. X.LP
  1708. XThese functions perform string matching. They have been designed with
  1709. Xthe assumption that one needs to find a certain pattern in a set of
  1710. Xstrings. It is also possible to use them to find if a pattern occurs
  1711. Xin a specific string.
  1712. X.LP
  1713. X.B strs_setup()
  1714. Xis used to specify the pattern to look for. It returns a
  1715. X.I handle
  1716. Xwhich is used in subsequent string matching operations against
  1717. Xthe specified
  1718. X.I pattern.
  1719. XThe
  1720. X.I flags
  1721. Xargument has two parts: a search method and generic flags.
  1722. XThe available search methods include the following algorithms:
  1723. X.RS
  1724. X.TP 15
  1725. X.SB STRS_BF
  1726. Xbrute force algorithm (also called naive in the literature). 
  1727. X.TP
  1728. X.SB STRS_RK
  1729. XRabin-Karp algorithm (probabilistic).
  1730. X.TP
  1731. X.SB STRS_KMP
  1732. XKnuth-Morris-Pratt algorithm.
  1733. X.TP
  1734. X.SB STRS_SBM
  1735. XSimple Boyer-Moore (uses only the last occurrence heuristic).
  1736. X.TP
  1737. X.SB STRS_BMH
  1738. XThis is the Boyer-Moore algorithm using the last occurrence heuristic
  1739. Xas modified by Horspool (this is faster than the simple Boyer-Moore).
  1740. X.TP
  1741. X.SB STRS_SO
  1742. XShift-Or algorithm (this algorithm works only for patterns whose length
  1743. Xdoes not exceed the number of bits in a word).
  1744. X.RE
  1745. X.LP
  1746. XThe default algorithm is the brute force method.
  1747. XIn practice, the fastest algorithm is the
  1748. XBoyer-Moore-Horspool one.
  1749. X.LP
  1750. XThe flags that can be specified include:
  1751. X.RS
  1752. X.TP 15
  1753. X.SB STRS_NOMALLOC
  1754. Xdo not allocate space for the pattern. This can be specified if
  1755. Xthe pattern space will be available during the matching phase
  1756. X(i.e. do not use this flag if the pattern space was malloc'ed and
  1757. Xyou free it before doing any matching).
  1758. X.TP
  1759. X.SB STRS_IGNCASE
  1760. Xperform case-insensitive string matching
  1761. X(the default is case-sensitive matching).
  1762. X.TP
  1763. X.SB STRS_NOSWITCH
  1764. Xdisallows switching to another search method; a switch to the brute
  1765. Xforce algorithm happens if the length of the pattern is less than 4
  1766. Xor if the initialization of the specified search algorithm fails (for
  1767. Xexample, when using the shift-or algorithm with a very long pattern).
  1768. XWhen this flag is used, no switch happens.
  1769. X.TP
  1770. X.SB STRS_PATLEN
  1771. Xis used to explicitly specify the length of the pattern
  1772. X(with the
  1773. X.I patlen
  1774. Xargument); normally the pattern is assumed to be NUL-terminated.
  1775. X.RE
  1776. X.LP
  1777. X.B strs_match()
  1778. Xtries to match the string specified by
  1779. X.I str
  1780. Xagainst the pattern identified by
  1781. X.I handle.
  1782. XSince the length of the string is given by the
  1783. X.I len
  1784. Xargument the string does not need to be NUL-terminated.
  1785. X.B strs_done()
  1786. Xshould be invoked after all matching against the pattern identified by
  1787. X.I handle
  1788. Xis done.
  1789. X.LP
  1790. X.B strs_search()
  1791. Xis equivalent to:
  1792. X.LP
  1793. X.PD .1v
  1794. X.nf
  1795. X.RS
  1796. Xh = strs_setup( flags, pattern ) ;
  1797. Xp = strs_match( h, str, len ) ;
  1798. Xstrs_done( h ) ;
  1799. Xreturn( p ) ;
  1800. X.RE
  1801. X.PD
  1802. X.SH "RETURN VALUES"
  1803. X.LP
  1804. X.B strs_setup()
  1805. Xreturns a search handle on success or
  1806. X.SM NULL
  1807. Xon failure.
  1808. X.LP
  1809. X.B strs_match()
  1810. Xand
  1811. X.B strs_search()
  1812. Xreturn a pointer to the first occurrence of the pattern in the string or
  1813. X.SM NULL
  1814. Xif the pattern does not occur in the string.
  1815. X.SH "SEE ALSO"
  1816. XDonald E. Knuth, James H. Morris, Vaughan R. Pratt.
  1817. XFast pattern matching in strings.
  1818. XSIAM Journal on Computing, 6(2):323-350, 1977.
  1819. X.LP
  1820. XRichard M. Karp, Michael O. Rabin.
  1821. XEfficient randomized pattern-matching algorithms.
  1822. XTechnical Report TR-31-81,
  1823. XAiken Computation Laboratory, Harvard University, 1981.
  1824. X.LP
  1825. XRobert S. Boyer, J. Strother Moore.
  1826. XA fast string-searching algorithm.
  1827. XCommunications of the ACM, 20(10):762-772, 1977.
  1828. X.LP
  1829. XN. Horspool.
  1830. XPractical fast searching in strings.
  1831. XSoftware - Practice and Experience, 10:501-506, 1980.
  1832. X.LP
  1833. XR. Baeza-Yates, G.H. Gonnet.
  1834. XA new approach to text searching.
  1835. XProceedings of 12th SIGIR, June 1989.
  1836. X.LP
  1837. XThomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest.
  1838. XIntroduction to Algorithms.
  1839. XMcGraw-Hill 1990.
  1840. END_OF_FILE
  1841.   if test 4394 -ne `wc -c <'libs/src/str/strs.3'`; then
  1842.     echo shar: \"'libs/src/str/strs.3'\" unpacked with wrong size!
  1843.   fi
  1844.   # end of 'libs/src/str/strs.3'
  1845. fi
  1846. if test -f 'pst/dvi.c' -a "${1}" != "-c" ; then 
  1847.   echo shar: Will not clobber existing file \"'pst/dvi.c'\"
  1848. else
  1849.   echo shar: Extracting \"'pst/dvi.c'\" \(5447 characters\)
  1850.   sed "s/^X//" >'pst/dvi.c' <<'END_OF_FILE'
  1851. X/*
  1852. X * (c) Copyright 1993 by Panagiotis Tsirigotis
  1853. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  1854. X * and conditions for redistribution.
  1855. X */
  1856. X
  1857. Xstatic char RCSid[] = "$Id: dvi.c,v 1.3 1993/02/10 21:16:36 panos Exp $" ;
  1858. X
  1859. X#include <ctype.h>
  1860. X
  1861. X#include "sio.h"
  1862. X
  1863. X#include "defs.h"
  1864. X
  1865. X
  1866. Xint get_file_char( fdp )
  1867. X    int *fdp ;
  1868. X{
  1869. X    return( next_char( *fdp ) ) ;
  1870. X}
  1871. X
  1872. X
  1873. X/*
  1874. X * This function is called for lines starting with '%'
  1875. X */
  1876. XPRIVATE int check_for_new_page( fd )
  1877. X    int fd ;
  1878. X{
  1879. X    char *line ;
  1880. X    char *page_id = "Page:" ;
  1881. X    int id_len = strlen( page_id ) ;
  1882. X    int new_page = FALSE ;
  1883. X    void start_paragraph() ;
  1884. X
  1885. X    while ( line = Srdline( fd ) )
  1886. X    {
  1887. X        if ( line[0] != '%' )
  1888. X        {
  1889. X            Sundo( fd, SIO_UNDO_LINE ) ;
  1890. X            break ;
  1891. X        }
  1892. X        line_count++ ;
  1893. X        if ( line[1] != '%' )
  1894. X            continue ;
  1895. X        if ( strncmp( &line[2], page_id, id_len ) == 0 )
  1896. X        {
  1897. X            if ( ! new_page )
  1898. X                start_paragraph() ;
  1899. X            new_page = TRUE ;
  1900. X        }
  1901. X    }
  1902. X    return( new_page ) ;
  1903. X}
  1904. X
  1905. X
  1906. Xvoid dvi_process( fd )
  1907. X    int fd ;
  1908. X{
  1909. X    int c ;
  1910. X    int num ;
  1911. X    int output_string = FALSE ;
  1912. X    int last_cmd = SPACE ;
  1913. X    token_e last_token = TOK_OTHER ;
  1914. X    void process_string() ;
  1915. X    void skip_until() ;
  1916. X    void skip_bracket() ;
  1917. X    void decode_string() ;
  1918. X
  1919. X    for ( ;; )
  1920. X    {
  1921. X        NEXT_CHAR( fd, c ) ;
  1922. X        if ( c == SIO_EOF )
  1923. X            break ;
  1924. X        
  1925. X        if ( c == '%' )
  1926. X        {
  1927. X            skip_until( fd, NEWLINE ) ;
  1928. X            last_token = TOK_OTHER ;
  1929. X            continue ;
  1930. X        }
  1931. X
  1932. X        if ( c == SPACE )
  1933. X            continue ;
  1934. X
  1935. X        if ( c == NEWLINE )
  1936. X        {
  1937. X            /*
  1938. X             * Peek at the next character to check if it is a line beginning 
  1939. X             * with '%%'
  1940. X             */
  1941. X            NEXT_CHAR( fd, c ) ;
  1942. X            if ( c == SIO_EOF )
  1943. X                break ;
  1944. X            PUTBACK( fd, c ) ;
  1945. X
  1946. X            if ( c != '%' )
  1947. X                continue ;
  1948. X
  1949. X            if ( check_for_new_page( fd ) )
  1950. X                output_string = FALSE ;
  1951. X            last_token = TOK_OTHER ;
  1952. X            continue ;
  1953. X        }
  1954. X        
  1955. X        if ( c == SLASH )
  1956. X        {
  1957. X            for ( ;; )
  1958. X            {
  1959. X                NEXT_CHAR( fd, c ) ;
  1960. X                if ( c == SIO_EOF )
  1961. X                    error( "Reached EOF reading literal\n" ) ;
  1962. X                if ( ! isalnum( c ) )
  1963. X                {
  1964. X                    PUTBACK( fd, c ) ;
  1965. X                    break ;
  1966. X                }
  1967. X            }
  1968. X            last_token = TOK_OTHER ;
  1969. X            continue ;
  1970. X        }
  1971. X
  1972. X        /*
  1973. X         * This piece of code has been commented out because I have found
  1974. X         * valid Postscript files that contain an unbalanced number of '['.
  1975. X         * Specifically, this is what was found:
  1976. X         *
  1977. X         *        81[31 52[28 3[31 19 22 25 31 1[28 31 47 16 2[16 31 28 19 25
  1978. X         *
  1979. X         * The reason may be that the '[' between numbers has a different
  1980. X         * meaning but I could not find such a reference in the
  1981. X         * Postscript Language Reference Manual
  1982. X         *
  1983. X        if ( c == OPEN_BRACKET )
  1984. X        {
  1985. X            skip_bracket( fd, OPEN_BRACKET, CLOSED_BRACKET ) ;
  1986. X            last_token = TOK_OTHER ;
  1987. X            continue ;
  1988. X        }
  1989. X         *
  1990. X         */
  1991. X
  1992. X        if ( c == OPEN_CURLY_BRACKET )
  1993. X        {
  1994. X            skip_bracket( fd, OPEN_CURLY_BRACKET, CLOSED_CURLY_BRACKET ) ;
  1995. X            last_token = TOK_OTHER ;
  1996. X            continue ;
  1997. X        }
  1998. X
  1999. X        if ( c == LESS_THAN )
  2000. X        {
  2001. X            skip_until( fd, GREATER_THAN ) ;
  2002. X            last_token = TOK_OTHER ;
  2003. X            continue ;
  2004. X        }
  2005. X
  2006. X        if ( c == OPEN_PAREN )
  2007. X        {
  2008. X            decode_string( get_file_char, (void *)&fd ) ;
  2009. X            output_string = TRUE ;
  2010. X            last_token = TOK_STRING ;
  2011. X            continue ;
  2012. X        }
  2013. X
  2014. X        if ( c == MINUS )
  2015. X        {
  2016. X            /*
  2017. X             * Check for a negative number
  2018. X             */
  2019. X            NEXT_CHAR( fd, c ) ;
  2020. X            if ( ! isdigit( c ) )
  2021. X            {
  2022. X                PUTBACK( fd, c ) ;
  2023. X                continue ;
  2024. X            }
  2025. X            num = -get_num( fd, c ) ;
  2026. X            last_token = TOK_NUMBER ;
  2027. X            continue ;
  2028. X        }
  2029. X
  2030. X        if ( isdigit( c ) )
  2031. X        {
  2032. X            num = get_num( fd, c ) ;
  2033. X
  2034. X            /*
  2035. X             * Check if we got 2 number tokens in a row
  2036. X             */
  2037. X            if ( last_token == TOK_NUMBER )
  2038. X            {
  2039. X                /*
  2040. X                 * We got an (x,y) pair denoting the beginning of a line.
  2041. X                 * Do a line-feed if the last output was a string
  2042. X                 */
  2043. X                if ( output_string )
  2044. X                {
  2045. X                    printout( NEWLINE ) ;
  2046. X                    output_string = FALSE ;
  2047. X                }
  2048. X            }
  2049. X            last_token = TOK_NUMBER ;
  2050. X            continue ;
  2051. X        }
  2052. X
  2053. X        if ( isalpha( c ) )
  2054. X        {
  2055. X            char letter_buf[ 16 ] ;
  2056. X            int li = 0 ;            /* letter buf index */
  2057. X            int n_letters = 0 ;
  2058. X
  2059. X            letter_buf[ li++ ] = c ;
  2060. X            n_letters++ ;
  2061. X
  2062. X            for ( ;; )
  2063. X            {
  2064. X                NEXT_CHAR( fd, c ) ;
  2065. X                if ( c == SIO_EOF )
  2066. X                    break ;
  2067. X                if ( ! isalnum( c ) )
  2068. X                {
  2069. X                    PUTBACK( fd, c ) ;
  2070. X                    break ;
  2071. X                }
  2072. X                letter_buf[ li++ ] = c ;
  2073. X                li %= sizeof( letter_buf ) ;
  2074. X                n_letters++ ;
  2075. X            }
  2076. X
  2077. X            if ( n_letters > 2 )            /* ignore */
  2078. X            {
  2079. X                last_token = TOK_OTHER ;
  2080. X                continue ;
  2081. X            }
  2082. X
  2083. X            /*
  2084. X             * We have a command: identify it
  2085. X             */
  2086. X            switch ( letter_buf[ 0 ] )
  2087. X            {
  2088. X                case 'l':
  2089. X                case 'm':
  2090. X                case 'n':
  2091. X                case 'o':
  2092. X                case 'p':
  2093. X                case 'q':
  2094. X                case 'r':
  2095. X                case 's':
  2096. X                case 't':
  2097. X                    break ;            /* command requires no action */
  2098. X                
  2099. X                default:
  2100. X                    if ( output_string )
  2101. X                    {
  2102. X                        int print_space = FALSE ;
  2103. X
  2104. X                        switch ( last_token )
  2105. X                        {
  2106. X                            case TOK_NUMBER:
  2107. X                                if ( num >= 0 )
  2108. X                                    print_space = TRUE ;
  2109. X                                break ;
  2110. X
  2111. X                            case TOK_CMD:
  2112. X                                if ( last_cmd != 'p' )
  2113. X                                    print_space = TRUE ;
  2114. X                                break ;
  2115. X
  2116. X                            default:
  2117. X                                print_space = TRUE ;
  2118. X                        }
  2119. X
  2120. X                        if ( print_space )
  2121. X                        {
  2122. X                            printout( SPACE ) ;
  2123. X                            output_string = FALSE ;
  2124. X                        }
  2125. X                    }
  2126. X            }
  2127. X            last_cmd = letter_buf[ 0 ] ;
  2128. X            last_token = TOK_CMD ;
  2129. X        }
  2130. X    }
  2131. X}
  2132. X
  2133. X
  2134. XPRIVATE int get_num( fd, c )
  2135. X    int fd ;
  2136. X    int c ;
  2137. X{
  2138. X    int num = NUM( c ) ;
  2139. X
  2140. X    for ( ;; )
  2141. X    {
  2142. X        NEXT_CHAR( fd, c ) ;
  2143. X        if ( c == SIO_EOF )
  2144. X            error( "Unexpected end of file while reading number\n" ) ;
  2145. X
  2146. X        if ( isdigit( c ) )
  2147. X        {
  2148. X            num *= 10 ;
  2149. X            num += NUM( c ) ;
  2150. X        }
  2151. X        else if ( isalpha( c ) )
  2152. X            error( "Unexpected character terminating number: '%c'\n", c ) ;
  2153. X        else if ( c == SPACE || c == NEWLINE )
  2154. X            break ;
  2155. X        else
  2156. X        {
  2157. X            PUTBACK( fd, c ) ;
  2158. X            break ;
  2159. X        }
  2160. X    }
  2161. X    return( num ) ;
  2162. X}
  2163. X
  2164. END_OF_FILE
  2165.   if test 5447 -ne `wc -c <'pst/dvi.c'`; then
  2166.     echo shar: \"'pst/dvi.c'\" unpacked with wrong size!
  2167.   fi
  2168.   # end of 'pst/dvi.c'
  2169. fi
  2170. echo shar: End of archive 3 \(of 6\).
  2171. cp /dev/null ark3isdone
  2172. MISSING=""
  2173. for I in 1 2 3 4 5 6 ; do
  2174.     if test ! -f ark${I}isdone ; then
  2175.     MISSING="${MISSING} ${I}"
  2176.     fi
  2177. done
  2178. if test "${MISSING}" = "" ; then
  2179.     echo You have unpacked all 6 archives.
  2180.     rm -f ark[1-9]isdone
  2181. else
  2182.     echo You still must unpack the following archives:
  2183.     echo "        " ${MISSING}
  2184. fi
  2185. exit 0
  2186. exit 0 # Just in case...
  2187.