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

  1. Newsgroups: comp.sources.misc
  2. From: Panos Tsirigotis (panos@cs.colorado.edu)
  3. Subject: v40i175:  pst - extract text from a postscript file, Part04/06
  4. Message-ID: <1993Nov26.170800.6562@sparky.sterling.com>
  5. X-Md4-Signature: a2cc541f2540d73eab28031403d31f5d
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Fri, 26 Nov 1993 17:08:00 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: Panos Tsirigotis (panos@cs.colorado.edu)
  12. Posting-number: Volume 40, Issue 175
  13. Archive-name: pst/part04
  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/Makefile libs/src/sio/events.h
  21. #   libs/src/str/README libs/src/str/ss_impl.h libs/src/str/ss_kmp.c
  22. #   libs/src/str/ss_so.c libs/src/str/str.h libs/src/str/strparse.3
  23. #   libs/src/str/strprint.3 libs/src/str/strprint.c
  24. #   libs/src/str/strutil.c pst/COPYRIGHT pst/Makefile pst/main.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 4 (of 6)."'
  29. if test -f 'libs/src/sio/Makefile' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'libs/src/sio/Makefile'\"
  31. else
  32.   echo shar: Extracting \"'libs/src/sio/Makefile'\" \(4242 characters\)
  33.   sed "s/^X//" >'libs/src/sio/Makefile' <<'END_OF_FILE'
  34. X# (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  35. X# All rights reserved.  The file named COPYRIGHT specifies the terms 
  36. X# and conditions for redistribution.
  37. X
  38. X#
  39. X# $Id: Makefile,v 8.7 1993/09/08 05:57:40 panos Exp $
  40. X#
  41. X# Based on Library makefile template: *Revision: 1.15 *
  42. X#
  43. X
  44. X# 
  45. X# Available entries:
  46. X#         lib             --> creates the library
  47. X#        install        --> installs the library (archive, man page(s), header(s))
  48. X#        uninstall    --> uninstall the library
  49. X#        clean            --> removes all .o and .a files
  50. X#        spotless        --> clean + uninstall
  51. X#         lint            --> lints a file (usage: make lint MODULE=foo.c)
  52. X#        tags            --> creates a tags file (from the SOURCES and HEADERS)
  53. X#        checkout     --> checkout all files
  54. X#        dist            --> distribution support
  55. X#
  56. X
  57. XNAME                = sio
  58. XVERSION            = 1.6.3
  59. X
  60. XHEADERS            = sio.h impl.h events.h sioconf.h
  61. XSOURCES            = sprint.c sio.c siosup.c
  62. XOBJECTS            = sprint.o sio.o siosup.o
  63. X
  64. XMANFILES            = sio.3 Sprint.3
  65. XINCLUDEFILES    = sio.h
  66. X
  67. X# The following variables are used by the 'install' entry and
  68. X# should be customized:
  69. X#     LIBDIR:     where the library will be placed
  70. X#     INCUDEDIR:  where the include files will be placed
  71. X#     MANDIR:     where the man pages will be placed
  72. X#
  73. XLIBDIR            = $(HOME)/.links/libraries/$(ARCH)
  74. XINCLUDEDIR        = $(HOME)/.links/includes
  75. XMANDIR            = $(HOME)/.links/manpages/man3
  76. X
  77. X#
  78. X# Available flags:
  79. X#  -DDEBUG           :  enables assertions in the code. A failed assertion
  80. X#                       terminates the program
  81. X#  -DEVENTS          :  enables code that records events (currently limited
  82. X#                       to which functions have been called on a given fd)
  83. X#                       and code that accesses the event buffers.
  84. X#  -DLITTLE_ENDIAN   :  says that the machine is a little endian. This is
  85. X#                       needed if you enable EVENTS and your machine is a
  86. X#                       little endian (big endian is the default).
  87. X#
  88. X
  89. X#
  90. X# DEFS should be set from the command line; the current group of defs
  91. X# is for SunOS 4.x
  92. X#
  93. XDEFS                = -DHAS_MMAP -DHAS_ONEXIT -DHAS_MEMOPS -DHAS_ISATTY
  94. X
  95. XDEBUG                = -g            # -g or -O
  96. XVERSION_DEF        = -DVERSION=\"SIO\ Version\ $(VERSION)\"
  97. X
  98. XCPP_DEFS            = $(VERSION_DEF) $(DEFS)
  99. X
  100. X#
  101. X# The following variables shouldn't need to be changed
  102. X#
  103. XLINT_FLAGS        = -hbux
  104. XCPP_FLAGS        = $(CPP_DEFS)
  105. XCC_FLAGS            = $(DEBUG)
  106. XCFLAGS            = $(CPP_FLAGS) $(CC_FLAGS)
  107. X
  108. XINSTALL            = install -c
  109. XFMODE                = -m 640            # used by install
  110. XRANLIB            = ranlib
  111. X
  112. XPAGER                = less
  113. X
  114. X
  115. XLIBNAME            = lib$(NAME).a
  116. X
  117. Xlib: $(LIBNAME)
  118. X
  119. Xlibopt: clean
  120. X    make DEBUG=-O "DEFS=$(DEFS)" lib
  121. X    $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR)/optimized
  122. X
  123. X$(LIBNAME): $(OBJECTS)
  124. X    ar r $@ $?
  125. X    $(RANLIB) $@
  126. X
  127. Xlint:
  128. X    lint $(CPP_FLAGS) $(LINT_FLAGS) $(MODULE) 2>&1 | $(PAGER)
  129. X
  130. Xinstall: $(LIBNAME)
  131. X    @if test "$(LIBDIR)" -a "$(INCLUDEDIR)" -a "$(MANDIR)" ;\
  132. X    then \
  133. X        $(INSTALL) $(FMODE) $(LIBNAME) $(LIBDIR) ;\
  134. X        echo "Installed $(LIBNAME) to $(LIBDIR)" ;\
  135. X        for i in $(INCLUDEFILES); do $(INSTALL) $(FMODE) $$i $(INCLUDEDIR) ; done ;\
  136. X        echo Installed $(INCLUDEFILES) to $(INCLUDEDIR) ;\
  137. X        for i in $(MANFILES) ; do $(INSTALL) $(FMODE) $$i $(MANDIR) ; done ;\
  138. X        echo Installed $(MANFILES) to $(MANDIR) ;\
  139. X    else \
  140. X        echo "You forgot to set one of the following variables: LIBDIR,INCLUDEDIR,MANDIR" ;\
  141. X    fi
  142. X
  143. Xuninstall:
  144. X    a=`pwd` ; cd $(INCLUDEDIR) ;\
  145. X    if test $$a != `pwd` ; then rm -f $(INCLUDEFILES) ; fi
  146. X    a=`pwd` ; cd $(LIBDIR) ;\
  147. X    if test $$a != `pwd` ; then rm -f $(LIBNAME) ; fi
  148. X    a=`pwd` ; cd $(MANDIR) ;\
  149. X    if test $$a != `pwd` ; then rm -f $(MANFILES) ; fi
  150. X
  151. Xclean:
  152. X    rm -f $(OBJECTS) $(LIBNAME) core
  153. X
  154. Xspotless: clean uninstall
  155. X
  156. Xtags: $(SOURCES) $(HEADERS)
  157. X    ctags -w $(SOURCES) $(HEADERS)
  158. X
  159. Xcheckout:
  160. X    co $(SOURCES) $(HEADERS) $(MANFILES)
  161. X
  162. X#
  163. X# Distribution section
  164. X# This section contains the 2 targets for distribution support: dist, dirs
  165. X# "dist" checks out all files to be distributed
  166. X# "dirs" prints a list of directories to be included in the distribution.
  167. X# These directories should have a Makefile with a "dist" target
  168. X#
  169. XDISTRIBUTION_FILES    = $(HEADERS) $(SOURCES) $(MANFILES) README COPYRIGHT
  170. XDIRS                        = suite
  171. X
  172. Xdist:
  173. X    -co -q $(DISTRIBUTION_FILES)
  174. X
  175. Xdirs:
  176. X    @echo $(DIRS)
  177. X
  178. X#
  179. X# PUT HERE THE RULES TO MAKE THE OBJECT FILES
  180. X#
  181. Xsprint.o:   sio.h impl.h sioconf.h
  182. Xsio.o:      sio.h impl.h sioconf.h events.h
  183. Xsiosup.o:   sio.h impl.h sioconf.h events.h
  184. X
  185. END_OF_FILE
  186.   if test 4242 -ne `wc -c <'libs/src/sio/Makefile'`; then
  187.     echo shar: \"'libs/src/sio/Makefile'\" unpacked with wrong size!
  188.   fi
  189.   # end of 'libs/src/sio/Makefile'
  190. fi
  191. if test -f 'libs/src/sio/events.h' -a "${1}" != "-c" ; then 
  192.   echo shar: Will not clobber existing file \"'libs/src/sio/events.h'\"
  193. else
  194.   echo shar: Extracting \"'libs/src/sio/events.h'\" \(3168 characters\)
  195.   sed "s/^X//" >'libs/src/sio/events.h' <<'END_OF_FILE'
  196. X/*
  197. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  198. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  199. X * and conditions for redistribution.
  200. X */
  201. X
  202. X
  203. X/*
  204. X * $Id: events.h,v 8.1 1993/03/13 01:13:58 panos Exp $
  205. X */
  206. X
  207. X/*
  208. X * Event codes
  209. X * 
  210. X * We use a 2 letter code so that events that accumulate in a buffer
  211. X * can be displayed as a string
  212. X * We follow the convention that the first event letter is a capitalized
  213. X * and the second letter is in lower case. This allows one to easily
  214. X * recognize events in an event string.
  215. X */
  216. X
  217. X/*
  218. X * The ENCODE macro takes 2 characters and creates a short integer
  219. X * The size of the short integer is assumed to be 16-bits.
  220. X * The macro makes sure that regardless of the endianess of the machine,
  221. X * the low order byte contains the 1st character and the high order byte
  222. X * contains the 2nd character.
  223. X */
  224. X#ifdef LITTLE_ENDIAN
  225. X#define ENCODE( c1, c2 )                    ( (c1) + ( (c2) << 8 ) )
  226. X#else        /* BIG_ENDIAN */
  227. X#define ENCODE( c1, c2 )                    ( (c2) + ( (c1) << 8 ) )
  228. X#endif
  229. X
  230. X/*
  231. X * Event codes for SIO interface functions
  232. X * We use the first 2 lettes after the initial 'S'
  233. X */
  234. X#define EV_SGETC                        ENCODE( 'G', 'e' )
  235. X#define EV_SPUTC                        ENCODE( 'P', 'u' )
  236. X#define EV_SREAD                        ENCODE( 'R', 'e' )
  237. X#define EV_SWRITE                        ENCODE( 'W', 'r' ) 
  238. X#define EV_SRDLINE                    ENCODE( 'R', 'd' )
  239. X#define EV_SFETCH                        ENCODE( 'F', 'e' )
  240. X#define EV_SUNDO                        ENCODE( 'U', 'n' )
  241. X#define EV_SDONE                        ENCODE( 'D', 'o' )
  242. X#define EV_SFLUSH                        ENCODE( 'F', 'l' )
  243. X#define EV_SCLOSE                        ENCODE( 'C', 'l' )
  244. X#define EV_STIE                        ENCODE( 'T', 'i' )
  245. X#define EV_SUNTIE                        ENCODE( 'U', 't' )
  246. X#define EV_SBUFTYPE                    ENCODE( 'B', 'u' )
  247. X
  248. X/*
  249. X * Event codes for internal functions
  250. X * For the __sio_<name> functions we use 'S' and the first letter of <name>
  251. X * For the rest we use the first letter from the first two components of
  252. X * their name, for example for try_memory_mapping we use Tm.
  253. X */
  254. X#define EV_SIO_INIT                    ENCODE( 'S', 'i' )
  255. X#define EV_SIO_SWITCH                ENCODE( 'S', 's' )
  256. X#define EV_SIO_READF                    ENCODE( 'S', 'r' )
  257. X#define EV_SIO_WRITEF                ENCODE( 'S', 'w' )
  258. X#define EV_SIO_EXTEND_BUFFER        ENCODE( 'S', 'e' )
  259. X#define EV_SIO_MORE                    ENCODE( 'S', 'm' )
  260. X#define EV_TRY_MEMORY_MAPPING        ENCODE( 'T', 'm' )
  261. X#define EV_INITIAL_MAP                ENCODE( 'I', 'm' )
  262. X#define EV_MAP_UNIT                    ENCODE( 'M', 'u' )
  263. X#define EV_INIT_INPUT_STREAM        ENCODE( 'I', 'i' )
  264. X#define EV_INIT_OUTPUT_STREAM        ENCODE( 'I', 'o' )
  265. X
  266. X/*
  267. X * The # of entries must be a power of 2
  268. X */
  269. X#define EVENT_ENTRIES        512
  270. X
  271. Xstruct events
  272. X{
  273. X    short next ;
  274. X    short start ;
  275. X    short *codes ;            /* malloc'ed memory */
  276. X} ;
  277. X
  278. Xtypedef struct events events_s ;
  279. X
  280. Xextern events_s *__sio_events ;
  281. X
  282. X
  283. X#define ADD( index, x )                (index) += x ;                                \
  284. X                                            (index) &= ( EVENT_ENTRIES - 1 )
  285. X
  286. X#define EVENT( fd, code )                                                            \
  287. X                    {                                                                        \
  288. X                        events_s *evp = &__sio_events[ fd ] ;                    \
  289. X                                                                                            \
  290. X                        if ( evp->codes != NULL )                                    \
  291. X                        {                                                                    \
  292. X                            evp->codes[ evp->next ] = code ;                        \
  293. X                            ADD( evp->next, 1 ) ;                                    \
  294. X                            if ( evp->next == evp->start )                        \
  295. X                            { ADD( evp->start, 1 ) ; }                                \
  296. X                        }                                                                    \
  297. X                    }
  298. X
  299. END_OF_FILE
  300.   if test 3168 -ne `wc -c <'libs/src/sio/events.h'`; then
  301.     echo shar: \"'libs/src/sio/events.h'\" unpacked with wrong size!
  302.   fi
  303.   # end of 'libs/src/sio/events.h'
  304. fi
  305. if test -f 'libs/src/str/README' -a "${1}" != "-c" ; then 
  306.   echo shar: Will not clobber existing file \"'libs/src/str/README'\"
  307. else
  308.   echo shar: Extracting \"'libs/src/str/README'\" \(3369 characters\)
  309.   sed "s/^X//" >'libs/src/str/README' <<'END_OF_FILE'
  310. X======================================================================
  311. XNOTE: I use vi with a tabstop value of 3. Using the same tabstop
  312. X        value will make the text/code look properly indented.
  313. X======================================================================
  314. X
  315. X
  316. X1. What is this library about ?
  317. X
  318. XThe STR library consists of string handling functions. These
  319. Xfunctions can be separated into 4 groups:
  320. X
  321. XA. String matching functions. A variety of algorithms are available
  322. X    for string matching:
  323. X            brute force
  324. X            Rabin-Karp
  325. X            Knuth-Morris-Pratt
  326. X            Boyer-Moore
  327. X            Shift-or
  328. X
  329. XB. String printing functions (similar to sprintf). These functions offer
  330. X    2 significant advantages over sprintf:
  331. X        1) they include functions that will *not* overrun the string buffer 
  332. X            provided
  333. X        2) they include functions returning "char *" as well as functions
  334. X            returning "int" so that one can pick the most appropriate one.
  335. X
  336. XC. String parsing functions. These functions offer an easy way of breaking
  337. X    a string into substrings.
  338. X
  339. XD. String utility functions. This group includes functions that will
  340. X    convert a string to upper/lower case etc.
  341. X
  342. X
  343. X2. Setting up the STR library
  344. X
  345. XAll you need to do is type 'make'. This will create the library in the
  346. Xcurrent directory.  The string printing functions use (and therefore
  347. Xrequire) the underlying format conversion facility of my SIO (Stream
  348. XI/O) library. If you got this library as part of a program distribution,
  349. Xthen the SIO library should also be part of that distribution if the
  350. Xprogram requires it.  If the SIO library is not present, then you
  351. Xhave the following options:
  352. Xa) If you don't want to bother with it, you can define the
  353. X    flag NO_SIO in the Makefile (check the Makefile comments on how to do
  354. X    this) which will turn all string printing functions to no-ops.
  355. Xb) You can get the SIO library via anonymous FTP from any site that
  356. X    archives comp.sources.unix; SIO is part of the xinetd distribution
  357. X    which appeared in Volume 26 of comp.sources.unix
  358. Xc) You can send email to me (panos@cs.colorado.edu) and I will mail it to you
  359. X
  360. XNote that if you do find SIO via some other way, or if you already have
  361. Xit, make sure that the version you use is 1.6.2 or later; versions
  362. Xprior to 1.6.2 will result in identical behavior between the
  363. Xstrx_*print* and the str_*print* functions.
  364. X
  365. XTo install the library and the associated man pages and include files
  366. Xtype 'make install'. This will install the library in LIBDIR, the man
  367. Xpages in MANDIR and the include files in INCLUDEDIR.  LIBDIR,
  368. XINCLUDEDIR, and MANDIR are Makefile variables that you can edit in the
  369. XMakefile or override when you invoke 'make'.
  370. X
  371. X
  372. X
  373. X3. Epilogue
  374. X
  375. XPlease send bug-reports/comments to panos@cs.colorado.edu
  376. X
  377. XFeel free to modify the library to suit your needs.  If you want to
  378. Xdistribute modifications to this library, please read the COPYRIGHT
  379. Xfile.  It basically says that you are free to redistribute as long as
  380. Xyou retain the original copyright notice and you make sure that your
  381. Xmodifications are identifiable. In order to achieve this I have
  382. Xreserved the first 3 components of the version number (for example,
  383. X1.4.2) and you can identify your mods by appending another component to
  384. Xthat version number (for example, 1.4.2.A2). Also, if you distribute a
  385. Xmodified version of the library, you take full responsibility for any
  386. Xbugs in the code (not just your code; the whole thing).
  387. X
  388. END_OF_FILE
  389.   if test 3369 -ne `wc -c <'libs/src/str/README'`; then
  390.     echo shar: \"'libs/src/str/README'\" unpacked with wrong size!
  391.   fi
  392.   # end of 'libs/src/str/README'
  393. fi
  394. if test -f 'libs/src/str/ss_impl.h' -a "${1}" != "-c" ; then 
  395.   echo shar: Will not clobber existing file \"'libs/src/str/ss_impl.h'\"
  396. else
  397.   echo shar: Extracting \"'libs/src/str/ss_impl.h'\" \(2969 characters\)
  398.   sed "s/^X//" >'libs/src/str/ss_impl.h' <<'END_OF_FILE'
  399. X/*
  400. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  401. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  402. X * and conditions for redistribution.
  403. X */
  404. X
  405. X#ifndef SS_IMPL_H
  406. X#define SS_IMPL_H
  407. X
  408. X/*
  409. X * $Id: ss_impl.h,v 3.2 1993/06/16 00:06:34 panos Exp $
  410. X */
  411. X
  412. X/*
  413. X * NBIC is the Number-of-Bits-In-a-Char
  414. X */
  415. X#ifndef NBIC
  416. X#define NBIC                                8
  417. X#endif
  418. X
  419. X#define ALPHABET_SIZE                    ( 1 << NBIC )
  420. X
  421. X#ifndef WIDE_INT
  422. X#define WIDE_INT                 long
  423. X#define WIDE_INT_SIZE            32       /* bits */
  424. X#endif
  425. X
  426. Xtypedef WIDE_INT wide_int ;
  427. Xtypedef unsigned WIDE_INT u_wide_int ;
  428. X
  429. X
  430. X#include "ss_rk.h"
  431. X#include "ss_kmp.h"
  432. X#include "ss_sbm.h"
  433. X#include "ss_bmh.h"
  434. X#include "ss_so.h"
  435. X
  436. X#include "str.h"
  437. X
  438. Xstruct ss_ops
  439. X{
  440. X    int    (*so_setup)() ;
  441. X    char    *(*so_match)() ;
  442. X    void    (*so_done)() ;
  443. X} ;
  444. X
  445. X
  446. Xstruct ss_header
  447. X{
  448. X    char                 *ss_pattern ;
  449. X    int                ss_patlen ;
  450. X    int                ss_flags ;
  451. X    char                *ss_map ;                /* either identity or upper->lower */
  452. X    struct ss_ops    *ss_ops ;
  453. X    union ss_headers
  454. X    {
  455. X        struct rk_header    rkh ;
  456. X        struct kmp_header kmph ;
  457. X        struct sbm_header sbmh ;
  458. X        struct bmh_header bmhh ;
  459. X        struct so_header    soh ;
  460. X    } ss_h ;
  461. X} ;
  462. X
  463. Xtypedef struct ss_header header_s ;
  464. X
  465. X#define HP( p )                            ((header_s *)(p))
  466. X
  467. X/*
  468. X * Structure field access
  469. X */
  470. X#define SS_PATTERN( hp )                (hp)->ss_pattern
  471. X#define SS_PATLEN( hp )                    (hp)->ss_patlen
  472. X#define SS_FLAGS( hp )                    (hp)->ss_flags
  473. X#define SS_OPS( hp )                        (hp)->ss_ops
  474. X#define SS_SETMAP( hp, map )            (hp)->ss_map = map
  475. X#define SS_MAP( hp, c )                    (hp)->ss_map[ (unsigned char) (c) ]
  476. X
  477. X/*
  478. X * Predicates
  479. X */
  480. X#define SS_MALLOC( hp )                ( ! ( SS_FLAGS( hp ) & STRS_NOMALLOC ) )
  481. X#define SS_IGNCASE( hp )            ( SS_FLAGS( hp ) & STRS_IGNCASE )
  482. X#define SS_SWITCH( hp )                ( ! ( SS_FLAGS( hp ) & STRS_NOSWITCH ) )
  483. X#define SS_SETMALLOC( hp )            SS_FLAGS( hp ) &= ~ STRS_NOMALLOC
  484. X
  485. X/*
  486. X * Indirect op invocation
  487. X */
  488. X#define SS_SETUP( hp )                    (*SS_OPS( hp )->so_setup)( hp )
  489. X#define SS_MATCH( hp, str, len )        (*SS_OPS( hp )->so_match)( hp, str, len )
  490. X#define SS_DONE( hp )                    (*SS_OPS( hp )->so_done)( hp )
  491. X
  492. X/*
  493. X * Header extraction
  494. X */
  495. X#define RK_HEADER( hp )                    (&(hp)->ss_h.rkh)
  496. X#define KMP_HEADER( hp )                (&(hp)->ss_h.kmph)
  497. X#define SBM_HEADER( hp )                (&(hp)->ss_h.sbmh)
  498. X#define BMH_HEADER( hp )                (&(hp)->ss_h.bmhh)
  499. X#define SO_HEADER( hp )                    (&(hp)->ss_h.soh)
  500. X
  501. X/*
  502. X * Macros to extract method and flags from the 'flags' argument
  503. X */
  504. X#define METHOD_BITS                        5        /* flag bits devoted to methods */
  505. X#define METHOD_MASK                        ( ( 1 << METHOD_BITS ) - 1 )
  506. X#define SS_GETMETHOD( x )                ( (x) & METHOD_MASK )
  507. X#define SS_GETFLAGS( x )                ( (x) & ~METHOD_MASK )
  508. X
  509. X
  510. Xstruct ss_select
  511. X{
  512. X    int                sel_method ;
  513. X    struct ss_ops    *sel_ops ;
  514. X} ;
  515. X
  516. X
  517. X#ifndef NULL
  518. X#define NULL                                0
  519. X#endif
  520. X
  521. X#ifndef FALSE
  522. X#define FALSE                                0
  523. X#define TRUE                                1
  524. X#endif
  525. X
  526. X#define CHAR_NULL                            ((char *)0)
  527. X#define NULL_HANDLE                        ((strs_h)0)
  528. X
  529. X#define PRIVATE                            static
  530. X
  531. X
  532. X/*
  533. X * Return values
  534. X */
  535. X#define SS_OK                                0
  536. X#define SS_ERR                                (-1)
  537. X
  538. X#endif    /* SS_IMPL_H */
  539. X
  540. END_OF_FILE
  541.   if test 2969 -ne `wc -c <'libs/src/str/ss_impl.h'`; then
  542.     echo shar: \"'libs/src/str/ss_impl.h'\" unpacked with wrong size!
  543.   fi
  544.   # end of 'libs/src/str/ss_impl.h'
  545. fi
  546. if test -f 'libs/src/str/ss_kmp.c' -a "${1}" != "-c" ; then 
  547.   echo shar: Will not clobber existing file \"'libs/src/str/ss_kmp.c'\"
  548. else
  549.   echo shar: Extracting \"'libs/src/str/ss_kmp.c'\" \(2827 characters\)
  550.   sed "s/^X//" >'libs/src/str/ss_kmp.c' <<'END_OF_FILE'
  551. X/*
  552. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  553. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  554. X * and conditions for redistribution.
  555. X */
  556. X
  557. Xstatic char RCSid[] = "$Id: ss_kmp.c,v 3.1 1993/06/13 02:44:39 panos Exp $" ;
  558. X
  559. Xchar *malloc() ;
  560. X
  561. X#include "ss_impl.h"
  562. X
  563. XPRIVATE int kmp_setup() ;
  564. XPRIVATE char *kmp_match() ;
  565. XPRIVATE void kmp_done() ;
  566. X
  567. Xstruct ss_ops __strs_kmpops = { kmp_setup, kmp_match, kmp_done } ;
  568. X
  569. X
  570. XPRIVATE void compute_next( hp )
  571. X    header_s *hp ;
  572. X{
  573. X    char            *pattern = SS_PATTERN( hp ) ;
  574. X    int            patlen    = SS_PATLEN( hp ) ;
  575. X    next_int        *next        = KMP_HEADER( hp )->next ;
  576. X    int            q ;
  577. X    next_int     k ;
  578. X
  579. X    k = next[ 0 ] = -1 ;
  580. X
  581. X    for ( q = 0 ; q < patlen-1 ; )
  582. X    {
  583. X        /*
  584. X         * The invariant of the following loop is:
  585. X         * if k>=0, then
  586. X         *        pattern[ 0..k-1 ] SUFFIX pattern[ 0..q-1 ]  ( <==> next[ q ] = k )
  587. X         * This condition is true on entry to the loop.
  588. X         */
  589. X        while ( k >= 0 && pattern[ k ] != pattern[ q ] )
  590. X            k = next[ k ] ;
  591. X
  592. X        /*
  593. X         * Case 1: k == -1
  594. X         *        Setting next[ q+1 ] = 0 is ok since it implies that the next
  595. X         *        position in the pattern to check is position 0 (i.e. start
  596. X         *        from the beginning).
  597. X         *    Case 2: k >= 0.
  598. X         *        Since we exited the loop, pattern[ k ] == pattern[ q ].
  599. X         *        Therefore,
  600. X         *            pattern[ 0..k ] SUFFIX pattern[ 0..q ] ==> next[ q+1 ] = k+1
  601. X         */
  602. X        k++, q++ ;
  603. X#ifdef PATH_COMPRESSION
  604. X        if ( pattern[ k ] == pattern[ q ] )
  605. X            next[ q ] = next[ k ] ;
  606. X#endif
  607. X        next[ q ] = k ;
  608. X    }
  609. X}
  610. X
  611. X
  612. XPRIVATE int kmp_setup( hp )
  613. X    register header_s *hp ;
  614. X{
  615. X    register next_int *next ;
  616. X
  617. X    next = (next_int *) malloc( (unsigned)SS_PATLEN( hp )*sizeof( next_int ) ) ;
  618. X    if ( next == (next_int *)0 )
  619. X        return( SS_ERR ) ;
  620. X    
  621. X    KMP_HEADER( hp )->next = next ;
  622. X
  623. X    compute_next( hp ) ;
  624. X
  625. X    return( SS_OK ) ;
  626. X}
  627. X
  628. X
  629. XPRIVATE char *kmp_match( hp, str, len )
  630. X    header_s        *hp ;
  631. X    char            *str ;
  632. X    int            len ;
  633. X{
  634. X    register int            i ;
  635. X    register next_int     q ;
  636. X    next_int                    *next        = KMP_HEADER( hp )->next ;
  637. X    char                        *pattern = SS_PATTERN( hp ) ;
  638. X    register int            patlen    = SS_PATLEN( hp ) ;
  639. X
  640. X    /*
  641. X     * As a special case, we consider pattern[ -1..0 ] to be the empty string.
  642. X     */
  643. X    for ( q = 0, i = 0 ; i < len ; i++ )
  644. X    {
  645. X        register char current_char = SS_MAP( hp, str[ i ] ) ;
  646. X
  647. Xagain:
  648. X        /*
  649. X         * At this point:
  650. X         *        pattern[ 0..q-1 ] is a suffix of str[ 0..i-1 ]
  651. X         */
  652. X        if ( pattern[ q ] == current_char )
  653. X        {
  654. X            q++ ;
  655. X            if ( q == patlen )
  656. X                return( &str[ i - patlen + 1 ] ) ;
  657. X        }
  658. X        else
  659. X        {
  660. X            /*
  661. X             * Let q' = next[ q ]. If q' >= 0, then
  662. X             *        pattern[ 0..q'-1 ] SUFFIX pattern[ 0..q-1 ]
  663. X             *    which implies that
  664. X             *        pattern[ 0..q'-1 ] SUFFIX str[ 0..i-1 ]
  665. X             * Therefore, it is ok to set q = q'.
  666. X             */
  667. X            q = next[ q ] ;
  668. X            if ( q >= 0 )
  669. X                goto again ;
  670. X            q++ ;
  671. X        }
  672. X    }
  673. X
  674. X    return( CHAR_NULL ) ;
  675. X}
  676. X
  677. X
  678. XPRIVATE void kmp_done( hp )
  679. X    header_s *hp ;
  680. X{
  681. X    (void) free( (char *)KMP_HEADER( hp )->next ) ;
  682. X}
  683. X
  684. END_OF_FILE
  685.   if test 2827 -ne `wc -c <'libs/src/str/ss_kmp.c'`; then
  686.     echo shar: \"'libs/src/str/ss_kmp.c'\" unpacked with wrong size!
  687.   fi
  688.   # end of 'libs/src/str/ss_kmp.c'
  689. fi
  690. if test -f 'libs/src/str/ss_so.c' -a "${1}" != "-c" ; then 
  691.   echo shar: Will not clobber existing file \"'libs/src/str/ss_so.c'\"
  692. else
  693.   echo shar: Extracting \"'libs/src/str/ss_so.c'\" \(2898 characters\)
  694.   sed "s/^X//" >'libs/src/str/ss_so.c' <<'END_OF_FILE'
  695. X/*
  696. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  697. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  698. X * and conditions for redistribution.
  699. X */
  700. X
  701. Xstatic char RCSid[] = "$Id: ss_so.c,v 3.1 1993/06/13 02:46:12 panos Exp $" ;
  702. X
  703. Xchar *malloc() ;
  704. X
  705. X#include "ss_impl.h"
  706. X
  707. XPRIVATE int so_setup() ;
  708. XPRIVATE char *so_match() ;
  709. XPRIVATE void so_done() ;
  710. X
  711. Xstruct ss_ops __strs_soops = { so_setup, so_match, so_done } ;
  712. X
  713. X/*
  714. X * There is a single twist in this implementation of the shift-or algorithm:
  715. X * To make the check for complete match faster, we are using the sign-bit
  716. X * of the word. This means that everything is shifted to the left by
  717. X *             (word_size - pattern_length)
  718. X */
  719. X
  720. XPRIVATE int so_setup( hp )
  721. X    header_s *hp ;
  722. X{
  723. X    register wide_int        *maskbuf ;
  724. X    register wide_int        mask ;
  725. X    register wide_int        offset_mask ;
  726. X    register int            i ;
  727. X    int                        offset ;
  728. X    register int            patlen    = SS_PATLEN( hp ) ;
  729. X    register char            *pattern = SS_PATTERN( hp ) ;
  730. X
  731. X    if ( patlen > WIDE_INT_SIZE )
  732. X        return( SS_ERR ) ;
  733. X    
  734. X    maskbuf = (wide_int *) malloc( ALPHABET_SIZE * sizeof( wide_int ) ) ;
  735. X    if ( maskbuf == (wide_int *)NULL )
  736. X        return( SS_ERR ) ;
  737. X    
  738. X    offset = WIDE_INT_SIZE - patlen ;
  739. X    offset_mask = ( (~0) << offset ) ;
  740. X    
  741. X    /*
  742. X     * The bits of each word that won't be used must be set to 0
  743. X     */
  744. X    for ( i = 0 ; i < ALPHABET_SIZE ; i++ )
  745. X        maskbuf[ i ] = offset_mask ;
  746. X
  747. X    for ( i = 0, mask = 1 << offset ; i < patlen ; i++, mask <<= 1 )
  748. X        maskbuf[ (unsigned char) pattern[ i ] ] &= ~mask ;
  749. X
  750. X    SO_HEADER( hp )->mask = maskbuf ;
  751. X    SO_HEADER( hp )->offset_mask = offset_mask ;
  752. X    return( SS_OK ) ;
  753. X}
  754. X
  755. X
  756. XPRIVATE char *so_match( hp, str, len )
  757. X    register header_s        *hp ;
  758. X    char                        *str ;
  759. X    int                        len ;
  760. X{
  761. X    register char            *p ;
  762. X    register char            pfc                = SS_PATTERN( hp )[ 0 ] ;
  763. X    register wide_int        *mask                = SO_HEADER( hp )->mask ;
  764. X    register char            *endmatch        = &str[ len - SS_PATLEN( hp ) + 1 ] ;
  765. X    char                        *endstr            = &str[ len ] ;
  766. X    wide_int                    no_match_state = ~0 & SO_HEADER( hp )->offset_mask ;
  767. X
  768. X    /*
  769. X     * The shift-or algorithm can be described by the following for-loop:
  770. X     *
  771. X     *    for ( p = str ; p < endstr ; p++ )
  772. X     *    {
  773. X     *        state = ( state << 1 ) | mask[ (unsigned char) SS_MAP( hp, *p ) ] ;
  774. X     *        if ( state >= 0 )
  775. X     *            return( &p[ -SS_PATLEN( hp ) + 1 ] ) ;
  776. X     *    }
  777. X     *
  778. X     * For efficiency reasons, the algorithm is used only after the first 
  779. X     * character of the pattern is matched against a character of the string.
  780. X     */
  781. X
  782. X    for ( p = str ; p < endmatch ; p++ )
  783. X    {
  784. X        register wide_int state ;
  785. X
  786. X        if ( SS_MAP( hp, *p ) != pfc )
  787. X            continue ;
  788. X
  789. X        for ( state = no_match_state ; p < endstr ; p++ )
  790. X        {
  791. X            state = ( state << 1 ) | mask[ (unsigned char) SS_MAP( hp, *p ) ] ;
  792. X            if ( state >= 0 )
  793. X                return( &p[ -SS_PATLEN( hp ) + 1 ] ) ;
  794. X            if ( state == no_match_state )
  795. X                break ;
  796. X        }
  797. X    }
  798. X    return( CHAR_NULL ) ;
  799. X}
  800. X
  801. X
  802. XPRIVATE void so_done( hp )
  803. X    header_s *hp ;
  804. X{
  805. X    (void) free( (char *) SO_HEADER( hp )->mask ) ;
  806. X}
  807. X
  808. END_OF_FILE
  809.   if test 2898 -ne `wc -c <'libs/src/str/ss_so.c'`; then
  810.     echo shar: \"'libs/src/str/ss_so.c'\" unpacked with wrong size!
  811.   fi
  812.   # end of 'libs/src/str/ss_so.c'
  813. fi
  814. if test -f 'libs/src/str/str.h' -a "${1}" != "-c" ; then 
  815.   echo shar: Will not clobber existing file \"'libs/src/str/str.h'\"
  816. else
  817.   echo shar: Extracting \"'libs/src/str/str.h'\" \(3551 characters\)
  818.   sed "s/^X//" >'libs/src/str/str.h' <<'END_OF_FILE'
  819. X/*
  820. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  821. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  822. X * and conditions for redistribution.
  823. X */
  824. X
  825. X
  826. X#ifndef __STR_H
  827. X#define __STR_H
  828. X
  829. X/*
  830. X * $Id: str.h,v 3.1 1993/06/13 02:47:14 panos Exp $
  831. X */
  832. X
  833. X#include <varargs.h>
  834. X
  835. X
  836. X#ifdef __ARGS
  837. X#undef __ARGS
  838. X#endif
  839. X
  840. X#ifdef PROTOTYPES
  841. X#   define __ARGS( s )               s
  842. X#else
  843. X#   define __ARGS( s )               ()
  844. X#endif
  845. X
  846. X
  847. X/*
  848. X * strprint(3) functions
  849. X */
  850. Xchar *str_sprint __ARGS( ( char *buf, char *fmt, ... ) ) ;
  851. Xint str_nprint __ARGS( ( char *buf, char *fmt, ... ) ) ;
  852. Xvoid str_print __ARGS( ( int *count, char *buf, char *fmt, ... ) ) ;
  853. X
  854. Xchar *str_sprintv __ARGS( ( char *buf, char *fmt, va_list ) ) ;
  855. Xint str_nprintv __ARGS( ( char *buf, char *fmt, va_list ) ) ;
  856. Xvoid str_printv __ARGS( ( int *count, char *buf, char *fmt, va_list ) ) ;
  857. X
  858. Xchar *strx_sprint __ARGS( ( char *buf, int len, char *fmt, ... ) ) ;
  859. Xint strx_nprint __ARGS( ( char *buf, int len, char *fmt, ... ) ) ;
  860. Xvoid strx_print __ARGS( ( int *count, char *buf, int len, char *fmt, ... ) ) ;
  861. X
  862. Xchar *strx_sprintv __ARGS( ( char *buf, int len, char *fmt, va_list ) ) ;
  863. Xint strx_nprintv __ARGS( ( char *buf, int len, char *fmt, va_list ) ) ;
  864. Xvoid strx_printv __ARGS(( int *cnt, char *buf, int len, char *fmt, va_list )) ;
  865. X
  866. X
  867. X/*
  868. X * strparse(3) functions
  869. X */
  870. X
  871. X/*
  872. X * Return values
  873. X */
  874. X#define STR_OK                        0
  875. X#define STR_ERR                    (-1)
  876. X
  877. X
  878. X/* 
  879. X * Flags for the string parsing functions
  880. X */
  881. X#define STR_NOFLAGS                0x0
  882. X#define STR_RETURN_ERROR        0x1
  883. X#define STR_NULL_START            0x2
  884. X#define STR_NULL_END                0x4
  885. X#define STR_MALLOC                0x8
  886. X
  887. Xextern int str_errno ;
  888. X
  889. X/*
  890. X * Error values
  891. X */
  892. X#define STR_ENULLSEPAR            1
  893. X#define STR_ENULLSTRING            2
  894. X#define STR_ENOMEM                3
  895. X
  896. Xtypedef void *str_h ;
  897. X
  898. Xstr_h str_parse __ARGS( ( char *str, char *separ, int flags, int *errnop ) ) ;
  899. Xvoid str_endparse __ARGS( ( str_h handle ) ) ;
  900. Xchar *str_component __ARGS( ( str_h handle ) ) ;
  901. Xint str_setstr __ARGS( ( str_h handle, char *newstr ) ) ;
  902. Xint str_separator __ARGS( ( str_h handle, char *separ ) ) ;
  903. Xchar *str_nextpos __ARGS( ( str_h handle ) ) ;
  904. X
  905. X/*
  906. X * For backwards compatibility
  907. X */
  908. X#define str_process( s, sep, flags )    str_parse( s, sep, flags, (int *)0 )
  909. X#define str_endprocess( handle )            str_endparse( handle )
  910. X
  911. X
  912. X/*
  913. X * strutil(3) functions
  914. X */
  915. Xchar *str_find __ARGS( ( char *s1, char *s2 ) ) ;
  916. Xchar *str_casefind __ARGS( ( char *s1, char *s2 ) ) ;
  917. Xvoid str_fill __ARGS( ( char *s, char c ) ) ;
  918. Xchar *str_lower __ARGS( ( char *s ) ) ;
  919. Xchar *str_upper __ARGS( ( char *s ) ) ;
  920. X
  921. X
  922. X/*
  923. X * strsearch(3) functions
  924. X */
  925. X
  926. X/*
  927. X * Methods
  928. X */
  929. X#define STRS_BF                                0            /* brute force                */
  930. X#define STRS_RK                                1            /* Rabin-Karp                */
  931. X#define STRS_KMP                                2            /* Knuth-Morris-Pratt    */
  932. X#define STRS_SBM                                3            /* Simple Boyer-Moore    */
  933. X#define STRS_BMH                                4            /* Boyer-Moore-Horspool */
  934. X#define STRS_SO                                5            /* Shift-Or                    */
  935. X
  936. X#define __STRS_METHOD_BITS                    5
  937. X#define STRS_METHODS_MAX                    ( 1 << __STRS_METHOD_BITS )
  938. X
  939. X/*
  940. X * Flags
  941. X */
  942. X#define __STRS_MAKEFLAG( v )                ( (v) << __STRS_METHOD_BITS )
  943. X#define STRS_IGNCASE                            __STRS_MAKEFLAG( 0x1 )
  944. X#define STRS_NOMALLOC                        __STRS_MAKEFLAG( 0x2 )
  945. X#define STRS_NOSWITCH                        __STRS_MAKEFLAG( 0x4 )
  946. X#define STRS_PATLEN                            __STRS_MAKEFLAG( 0x8 )
  947. X
  948. X
  949. Xtypedef void *strs_h ;
  950. X
  951. Xchar *strs_search __ARGS( ( int flags, char *str, int len, char *pat, ... ) ) ;
  952. Xstrs_h strs_setup __ARGS( ( int flags, char *pattern, ... ) ) ;
  953. Xchar *strs_match    __ARGS( ( strs_h handle, char *str, int len ) ) ;
  954. Xvoid strs_done        __ARGS( ( strs_h handle ) ) ;
  955. X
  956. X#endif     /* __STR_H */
  957. X
  958. END_OF_FILE
  959.   if test 3551 -ne `wc -c <'libs/src/str/str.h'`; then
  960.     echo shar: \"'libs/src/str/str.h'\" unpacked with wrong size!
  961.   fi
  962.   # end of 'libs/src/str/str.h'
  963. fi
  964. if test -f 'libs/src/str/strparse.3' -a "${1}" != "-c" ; then 
  965.   echo shar: Will not clobber existing file \"'libs/src/str/strparse.3'\"
  966. else
  967.   echo shar: Extracting \"'libs/src/str/strparse.3'\" \(4130 characters\)
  968.   sed "s/^X//" >'libs/src/str/strparse.3' <<'END_OF_FILE'
  969. X.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  970. X.\"All rights reserved.  The file named COPYRIGHT specifies the terms 
  971. X.\"and conditions for redistribution.
  972. X.\"
  973. X.\" $Id: strparse.3,v 3.1 1993/06/13 02:48:02 panos Exp $
  974. X.TH STRPARSE 3X "30 September 1992"
  975. X.SH NAME
  976. Xstr_parse, str_endparse, str_component, str_separator, str_nextpos
  977. X.SH SYNOPSIS
  978. X.LP
  979. X.nf
  980. X.ft B
  981. X#include "str.h"
  982. X.LP
  983. X.ft B
  984. Xstr_h str_parse( str, separ, flags, errnop )
  985. Xchar *str ;
  986. Xchar *separ ;
  987. Xint flags ;
  988. Xint *errnop ;
  989. X.LP
  990. X.ft B
  991. Xvoid str_endparse( handle )
  992. Xstr_h handle ;
  993. X.LP
  994. X.ft B
  995. Xchar *str_component( handle )
  996. Xstr_h handle ;
  997. X.LP
  998. X.ft B
  999. Xint str_setstr( handle, newstr )
  1000. Xstr_h handle ;
  1001. Xchar *newstr ;
  1002. X.LP
  1003. X.ft B
  1004. Xint str_separator( handle, separ )
  1005. Xstr_h handle ;
  1006. Xchar *separ ;
  1007. X.LP
  1008. X.ft B
  1009. Xchar *str_nextpos( handle )
  1010. Xstr_h handle ;
  1011. X.LP
  1012. Xextern int str_errno ;
  1013. X.SH DESCRIPTION
  1014. X.LP
  1015. XThese functions are useful for parsing strings.  In this context
  1016. Xparsing means breaking the string into substrings. The substrings are
  1017. Xseparated by a list of possible separator characters.
  1018. X.LP
  1019. X.B str_component()
  1020. Xreturns successive substrings of the string.
  1021. X.B str_parse()
  1022. Xcreates and initializes a string parser with the string
  1023. Xthat will be processed, \fIstr\fR, the list of possible separator
  1024. Xcharacters, \fIsepar\fR, and flags that control how the parser
  1025. Xworks. The \fIflags\fR argument is formed by ORing one or more of
  1026. Xthe following constants:
  1027. X.TP 20
  1028. X.SB STR_RETURN_ERROR
  1029. XIf something goes wrong return a value that indicates that an error occured
  1030. X(e.g. out of memory). The default is for the program to be terminated
  1031. Xwith an appropriate error message.
  1032. X.TP
  1033. X.SB STR_NULL_START
  1034. XIf \fIstr\fR starts with a separator then a zero-length string will be returned
  1035. Xthe first time \fBstr_component()\fR is called.
  1036. X.TP
  1037. X.SB STR_NULL_END
  1038. XIf \fIstr\fR ends with a separator then a zero-length string will be returned
  1039. Xby \fBstr_component()\fR when the substrings of \fIstr\fR are exhausted.
  1040. X.TP
  1041. X.SB STR_MALLOC
  1042. XThe strings returned by \fBstr_component()\fR will be in malloc'ed memory.
  1043. XBy default the substrings are part of \fIstr\fR.
  1044. XIf this option is not used \fIstr\fR will be modified
  1045. Xby \fBstr_component()\fR.
  1046. X.LP
  1047. XFinally, \fBSTR_NOFLAGS\fR may be used to specify no flags.
  1048. XThe \fIerrnop\fR argument points to an integer where the string processing
  1049. Xfunctions will deposit an error code if an error occurs.
  1050. XIf \fIerrnop\fR
  1051. Xis
  1052. X.SM NULL
  1053. Xthe error codes will be placed in \fIstr_errno\fR.
  1054. XThis is useful only if \fBSTR_RETURN_ERROR\fR is used in \fIflags\fR.
  1055. XIt is possible that \fIstr\fP is 
  1056. X.SM NULL.
  1057. XIn this case, a subsequent
  1058. X.B str_setstr()
  1059. Xshould be used to specify the string to be processed.
  1060. X.LP
  1061. X.B str_component()
  1062. Xreturns successive substrings from the string associated with the
  1063. Xparser specified by \fIhandle\fR.
  1064. X.LP
  1065. X.B str_endparse()
  1066. Xdestroys the parser specified by \fIhandle\fR.
  1067. X.LP
  1068. X.B str_setstr()
  1069. Xchanges the processed string to \fInewstr\fP.
  1070. X.LP
  1071. X.B str_separator()
  1072. Xreplaces the list of separator characters with \fIsepar\fR.
  1073. XProcessing continues from the current position.
  1074. X.LP
  1075. X.B str_nextpos()
  1076. Xreturns a pointer to the rest of the string. The previous character
  1077. Xis a separator character (if \fBSTR_MALLOC\fR is not set, then the
  1078. Xprevious character is
  1079. X.SM NUL
  1080. X).
  1081. X.SH "RETURN VALUES"
  1082. X.LP
  1083. X.B str_parse()
  1084. Xreturns a parser handle or
  1085. X.SM NULL
  1086. Xif something goes wrong and \fIflags\fR & \fBSTR_RETURN_ERROR\fR is true.
  1087. XPossible \fIstr_errno\fR values:
  1088. X.RS
  1089. X.TP 20
  1090. X.SB STR_ENULLSEPAR
  1091. X\fIsepar\fR is
  1092. X.SM NULL
  1093. X.TP
  1094. X.SB STR_ENOMEM
  1095. Xthe program ran out of memory
  1096. X.RE
  1097. X.LP
  1098. X.B str_component()
  1099. Xreturns a pointer to the next substring or
  1100. X.SM NULL
  1101. Xif something goes wrong and \fIflags\fR & \fBSTR_RETURN_ERROR\fR is true.
  1102. X.LP
  1103. X.B str_setstr()
  1104. Xreturns 
  1105. X.SB STR_OK
  1106. Xon success or
  1107. X.SB STR_ERR
  1108. Xon failure.
  1109. X.LP
  1110. X.B str_separator()
  1111. Xreturns 
  1112. X.SB STR_OK
  1113. Xon success or
  1114. X.SB STR_ERR
  1115. Xon failure.
  1116. X.LP
  1117. X.B str_nextpos()
  1118. Xreturns a pointer or
  1119. X.SM NULL
  1120. Xif the end of string has been reached.
  1121. X.SH BUGS
  1122. X.B str_component()
  1123. Xmodifies the string unless \fBSTR_MALLOC\fR is
  1124. Xset in the parser.
  1125. X.LP
  1126. XThere should be only one parser active on a specific string. If there
  1127. Xis more than
  1128. Xone, they all must use the \fBSTR_MALLOC\fR option.
  1129. X
  1130. END_OF_FILE
  1131.   if test 4130 -ne `wc -c <'libs/src/str/strparse.3'`; then
  1132.     echo shar: \"'libs/src/str/strparse.3'\" unpacked with wrong size!
  1133.   fi
  1134.   # end of 'libs/src/str/strparse.3'
  1135. fi
  1136. if test -f 'libs/src/str/strprint.3' -a "${1}" != "-c" ; then 
  1137.   echo shar: Will not clobber existing file \"'libs/src/str/strprint.3'\"
  1138. else
  1139.   echo shar: Extracting \"'libs/src/str/strprint.3'\" \(3148 characters\)
  1140.   sed "s/^X//" >'libs/src/str/strprint.3' <<'END_OF_FILE'
  1141. X.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  1142. X.\"All rights reserved.  The file named COPYRIGHT specifies the terms 
  1143. X.\"and conditions for redistribution.
  1144. X.\"
  1145. X.\" $Id: strprint.3,v 3.1 1993/06/13 02:48:55 panos Exp $
  1146. X.TH STRPRINT 3X "30 September 1992"
  1147. X.SH NAME
  1148. Xstr_sprint, tr_sprintv, str_nprint, str_nprintv, str_print, str_printv, strx_sprint, strx_sprintv, strx_nprint, strx_nprintv, strx_print, strx_printv -- formatted conversion to string
  1149. X.SH SYNOPSIS
  1150. X.LP
  1151. X.nf
  1152. X.ft B
  1153. X#include "str.h"
  1154. X.LP
  1155. X.ft B
  1156. Xchar *str_sprint( buf, format, ... )
  1157. Xchar *buf ;
  1158. Xchar *format ;
  1159. X.LP
  1160. X.ft B
  1161. Xchar *str_sprintv( buf, format, ap )
  1162. Xchar *buf ;
  1163. Xchar *format ;
  1164. Xva_list ap ;
  1165. X.LP
  1166. X.ft B
  1167. Xint str_nprint( buf, format, ... )
  1168. Xchar *buf ;
  1169. Xchar *format ;
  1170. X.LP
  1171. X.ft B
  1172. Xint str_nprintv( buf, format, ap )
  1173. Xchar *buf ;
  1174. Xchar *format ;
  1175. Xva_list ap ;
  1176. X.LP
  1177. X.ft B
  1178. Xvoid str_print( countp, buf, format, ... )
  1179. Xint *countp ;
  1180. Xchar *buf ;
  1181. Xchar *format ;
  1182. X.LP
  1183. X.ft B
  1184. Xvoid str_printv( countp, buf, format, ap )
  1185. Xint *countp ;
  1186. Xchar *buf ;
  1187. Xchar *format ;
  1188. Xva_list ap ;
  1189. X.LP
  1190. X.ft B
  1191. Xchar *strx_sprint( buf, len, format, ... )
  1192. Xchar *buf ;
  1193. Xint len ;
  1194. Xchar *format ;
  1195. X.LP
  1196. X.ft B
  1197. Xchar *strx_sprintv( buf, len, format, ap )
  1198. Xchar *buf ;
  1199. Xint len ;
  1200. Xchar *format ;
  1201. Xva_list ap ;
  1202. X.LP
  1203. X.ft B
  1204. Xint strx_nprint( buf, len, format, ... )
  1205. Xchar *buf ;
  1206. Xint len ;
  1207. Xchar *format ;
  1208. X.LP
  1209. X.ft B
  1210. Xint strx_nprintv( buf, len, format, ap )
  1211. Xchar *buf ;
  1212. Xint len ;
  1213. Xchar *format ;
  1214. Xva_list ap ;
  1215. X.LP
  1216. X.ft B
  1217. Xvoid strx_print( countp, buf, len, format, ... )
  1218. Xint *countp ;
  1219. Xchar *buf ;
  1220. Xint len ;
  1221. Xchar *format ;
  1222. X.LP
  1223. X.ft B
  1224. Xvoid strx_printv( countp, buf, len, format, ap )
  1225. Xint *countp ;
  1226. Xchar *buf ;
  1227. Xint len ;
  1228. Xchar *format ;
  1229. Xva_list ap ;
  1230. X.SH DESCRIPTION
  1231. X.LP
  1232. XAll functions are similar in functionality to \fIsprintf()\fR.
  1233. XTheir only difference is in their return values. For information about their
  1234. Xconversion capabilities, check \fISprint(3)\fR.
  1235. X.LP
  1236. XThe difference between the \fIstr_*\fR and the \fIstrx_*\fR functions
  1237. Xis that the latter take an extra argument, the size of the buffer, so
  1238. Xthat they will never write beyond the end of the buffer. Writing
  1239. Xbeyond the end of the buffer is possible with the \fIstr_*\fR functions.
  1240. XInvoking any of the \fIstrx_*\fR functions with the
  1241. X.I len
  1242. Xargument set to 0
  1243. Xis the same as calling the equivalent \fIstr_*\fR function.
  1244. X.LP
  1245. XAll functions will append a
  1246. X.SM NUL
  1247. Xat the end of
  1248. X.I buf
  1249. X(the \fIstrx_*\fR functions will not do this if it would cause 
  1250. Xa buffer overrun).
  1251. X.LP
  1252. X.B str_print(),
  1253. X.B str_printv(),
  1254. X.B strx_print(),
  1255. Xand
  1256. X.B strx_printv()
  1257. Xwill put in
  1258. X.I "*countp"
  1259. Xthe number of characters placed in 
  1260. X.I buf
  1261. Xexcluding the ending
  1262. X.SM NUL
  1263. X(this happens only if
  1264. X.I "*countp"
  1265. Xis not
  1266. X.SM NULL
  1267. X).
  1268. X.LP
  1269. XThe functions that have a name ending in 'v' are similar to those without
  1270. Xthe 'v' at the end of their name
  1271. Xexcept that instead of accepting a variable number of arguments, they
  1272. Xexpect a \fIvarargs(3)\fR argument list.
  1273. X.SH "RETURN VALUES"
  1274. X.LP
  1275. X.B str_sprint(),
  1276. X.B str_sprintv(),
  1277. X.B strx_sprint(),
  1278. Xand
  1279. X.B strx_sprintv()
  1280. Xreturn
  1281. X.I buf.
  1282. X.LP
  1283. X.B str_nprint(),
  1284. X.B str_nprintv(),
  1285. X.B strx_nprint(),
  1286. Xand
  1287. X.B strx_nprintv()
  1288. Xreturn the number of characters placed in 
  1289. X.I buf
  1290. Xexcluding the ending
  1291. X.SM NUL.
  1292. X.SH "SEE ALSO"
  1293. XSprint(3)
  1294. END_OF_FILE
  1295.   if test 3148 -ne `wc -c <'libs/src/str/strprint.3'`; then
  1296.     echo shar: \"'libs/src/str/strprint.3'\" unpacked with wrong size!
  1297.   fi
  1298.   # end of 'libs/src/str/strprint.3'
  1299. fi
  1300. if test -f 'libs/src/str/strprint.c' -a "${1}" != "-c" ; then 
  1301.   echo shar: Will not clobber existing file \"'libs/src/str/strprint.c'\"
  1302. else
  1303.   echo shar: Extracting \"'libs/src/str/strprint.c'\" \(3569 characters\)
  1304.   sed "s/^X//" >'libs/src/str/strprint.c' <<'END_OF_FILE'
  1305. X/*
  1306. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  1307. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  1308. X * and conditions for redistribution.
  1309. X */
  1310. X
  1311. Xstatic char RCSid[] = "$Id: strprint.c,v 3.1 1993/06/13 02:50:11 panos Exp $" ;
  1312. X
  1313. X#ifndef NO_SIO
  1314. X#include "sio.h"
  1315. X#endif
  1316. X
  1317. X#include "str.h"
  1318. X
  1319. X#define INT_NULL                        ((int *)0)
  1320. X
  1321. X/*
  1322. X * The strx_* functions will never overwrite the buffer
  1323. X * The str_* functions may overwrite the buffer
  1324. X */
  1325. X
  1326. X/*
  1327. X * Group 1: the strx_* functions
  1328. X */
  1329. X
  1330. X/*
  1331. X * This is the general purpose conversion function. It is invoked
  1332. X * by all the other str[x]_* functions
  1333. X */
  1334. Xvoid strx_printv( ccp, buf, len, format, ap )
  1335. X    int *ccp ;
  1336. X    char *buf ;
  1337. X    int len ;
  1338. X    char *format ;
  1339. X    va_list ap ;
  1340. X{
  1341. X#ifndef NO_SIO
  1342. X    __sio_od_t od ;
  1343. X    int cc ;
  1344. X
  1345. X   /*
  1346. X    * First initialize the descriptor
  1347. X     * Notice that if no length is given, we initialize buf_end to the
  1348. X     * highest possible address.
  1349. X    */
  1350. X   od.buf = buf ;                                        /* NOT NEEDED        */
  1351. X   od.buf_end = len ? &buf[ len ] : (char *) ~0 ;    /* NEEDED                */
  1352. X   od.buffer_size = 0 ;                                  /* NOT NEEDED        */
  1353. X   od.start = buf ;                                      /* NOT NEEDED        */
  1354. X   od.nextb = buf ;                                      /* NEEDED            */
  1355. X   od.buftype = 0 ;                                      /* NOT NEEDED        */
  1356. X
  1357. X   /*
  1358. X    * Do the conversion
  1359. X    */
  1360. X   cc = __sio_converter( &od, -1, format, ap ) ;
  1361. X    if ( len == 0 || od.nextb < od.buf_end )
  1362. X        *(od.nextb) = '\0' ;
  1363. X   if ( ccp )
  1364. X      *ccp = cc ;
  1365. X#endif    /* ! NO_SIO */
  1366. X}
  1367. X
  1368. X
  1369. Xvoid strx_print( ccp, buf, len, format, va_alist )
  1370. X    int *ccp ;
  1371. X    char *buf ;
  1372. X    int len ;
  1373. X    char *format ;
  1374. X    va_dcl
  1375. X{
  1376. X    va_list ap ;
  1377. X
  1378. X    va_start( ap ) ;
  1379. X    strx_printv( ccp, buf, len, format, ap ) ;
  1380. X    va_end( ap ) ;
  1381. X}
  1382. X
  1383. X
  1384. Xchar *strx_sprint( buf, len, format, va_alist )
  1385. X    char *buf ;
  1386. X    int len ;
  1387. X    char *format ;
  1388. X    va_dcl
  1389. X{
  1390. X    va_list ap ;
  1391. X
  1392. X    va_start( ap ) ;
  1393. X    strx_printv( INT_NULL, buf, len, format, ap ) ;
  1394. X    va_end( ap ) ;
  1395. X    return( buf ) ;
  1396. X}
  1397. X
  1398. X
  1399. Xchar *strx_sprintv( buf, len, format, ap )
  1400. X    char *buf ;
  1401. X    int len ;
  1402. X    char *format ;
  1403. X    va_list ap ;
  1404. X{
  1405. X    strx_printv( INT_NULL, buf, len, format, ap ) ;
  1406. X    return( buf ) ;
  1407. X}
  1408. X
  1409. X
  1410. Xint strx_nprint( buf, len, format, va_alist )
  1411. X    char *buf ;
  1412. X    int len ;
  1413. X    char *format ;
  1414. X    va_dcl
  1415. X{
  1416. X    int cc ;
  1417. X    va_list ap ;
  1418. X
  1419. X    va_start( ap ) ;
  1420. X    strx_printv( &cc, buf, len, format, ap ) ;
  1421. X    va_end( ap ) ;
  1422. X    return( cc ) ;
  1423. X}
  1424. X
  1425. X
  1426. Xint strx_nprintv( buf, len, format, ap )
  1427. X    char *buf ;
  1428. X    int len ;
  1429. X    char *format ;
  1430. X    va_list ap ;
  1431. X{
  1432. X    int cc ;
  1433. X
  1434. X    strx_printv( &cc, buf, len, format, ap ) ;
  1435. X    return( cc ) ;
  1436. X}
  1437. X
  1438. X
  1439. X
  1440. X/*
  1441. X * Group 2: the str_* functions
  1442. X */
  1443. X
  1444. Xvoid str_print( ccp, buf, format, va_alist )
  1445. X    int *ccp ;
  1446. X    char *buf ;
  1447. X    char *format ;
  1448. X    va_dcl
  1449. X{
  1450. X    va_list ap ;
  1451. X
  1452. X    va_start( ap ) ;
  1453. X    strx_printv( ccp, buf, 0, format, ap ) ;
  1454. X    va_end( ap ) ;
  1455. X}
  1456. X
  1457. X
  1458. Xvoid str_printv( ccp, buf, format, ap )
  1459. X    int *ccp ;
  1460. X    char *buf ;
  1461. X    char *format ;
  1462. X    va_list ap ;
  1463. X{
  1464. X    strx_printv( ccp, buf, 0, format, ap ) ;
  1465. X}
  1466. X
  1467. X
  1468. Xchar *str_sprint( buf, format, va_alist )
  1469. X    char *buf ;
  1470. X    char *format ;
  1471. X    va_dcl
  1472. X{
  1473. X    va_list ap ;
  1474. X
  1475. X    va_start( ap ) ;
  1476. X    strx_printv( INT_NULL, buf, 0, format, ap ) ;
  1477. X    va_end( ap ) ;
  1478. X    return( buf ) ;
  1479. X}
  1480. X
  1481. X
  1482. Xchar *str_sprintv( buf, format, ap )
  1483. X    char *buf ;
  1484. X    char *format ;
  1485. X    va_list ap ;
  1486. X{
  1487. X    strx_printv( INT_NULL, buf, 0, format, ap ) ;
  1488. X    return( buf ) ;
  1489. X}
  1490. X
  1491. X
  1492. Xint str_nprint( buf, format, va_alist )
  1493. X    char *buf ;
  1494. X    char *format ;
  1495. X    va_dcl
  1496. X{
  1497. X    int cc ;
  1498. X    va_list ap ;
  1499. X
  1500. X    va_start( ap ) ;
  1501. X    strx_printv( &cc, buf, 0, format, ap ) ;
  1502. X    va_end( ap ) ;
  1503. X    return( cc ) ;
  1504. X}
  1505. X
  1506. X
  1507. X
  1508. Xint str_nprintv( buf, format, ap )
  1509. X    char *buf ;
  1510. X    char *format ;
  1511. X    va_list ap ;
  1512. X{
  1513. X    int cc ;
  1514. X
  1515. X    strx_printv( &cc, buf, 0, format, ap ) ;
  1516. X    return( cc ) ;
  1517. X}
  1518. X
  1519. X
  1520. END_OF_FILE
  1521.   if test 3569 -ne `wc -c <'libs/src/str/strprint.c'`; then
  1522.     echo shar: \"'libs/src/str/strprint.c'\" unpacked with wrong size!
  1523.   fi
  1524.   # end of 'libs/src/str/strprint.c'
  1525. fi
  1526. if test -f 'libs/src/str/strutil.c' -a "${1}" != "-c" ; then 
  1527.   echo shar: Will not clobber existing file \"'libs/src/str/strutil.c'\"
  1528. else
  1529.   echo shar: Extracting \"'libs/src/str/strutil.c'\" \(3554 characters\)
  1530.   sed "s/^X//" >'libs/src/str/strutil.c' <<'END_OF_FILE'
  1531. X/*
  1532. X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  1533. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  1534. X * and conditions for redistribution.
  1535. X */
  1536. X
  1537. Xstatic char RCSid[] = "$Id: strutil.c,v 3.1 1993/06/13 02:50:22 panos Exp $" ;
  1538. X
  1539. X
  1540. X#include <ctype.h>
  1541. X
  1542. X#define NULL                0
  1543. X
  1544. X
  1545. X#ifndef TRIVIAL_STR_FIND
  1546. X
  1547. X/*
  1548. X * look for an instance of s2 in s1
  1549. X * Returns a pointer to the beginning of s2 in s1
  1550. X */
  1551. Xchar *str_find( str, sstr )
  1552. X    register char *str ;
  1553. X    register char *sstr ;
  1554. X{
  1555. X   register int ssfc = *sstr++ ;    /* sub-string first char */
  1556. X
  1557. X    if ( ssfc == 0 )            /* empty string is always a match */
  1558. X        return( str ) ;
  1559. X
  1560. X    while ( *str )
  1561. X    {
  1562. X        char *current = str ;
  1563. X        register int strc = *str++ ;
  1564. X        register char *sp ;                    /* string pointer */
  1565. X        register char *ssp ;                   /* sub-string pointer */
  1566. X
  1567. X        if ( strc != ssfc )
  1568. X            continue ;
  1569. X        
  1570. X        /*
  1571. X         * We don't need to make the end of str a special case since
  1572. X         * the comparison of *sp against *ssp is guaranteed to fail
  1573. X         */
  1574. X        for ( sp = str, ssp = sstr ;; sp++, ssp++ )
  1575. X        {
  1576. X            if ( *ssp == 0 )
  1577. X                return( current ) ;
  1578. X            if ( *sp != *ssp )
  1579. X                break ;
  1580. X        }
  1581. X    }
  1582. X
  1583. X    return( 0 ) ;
  1584. X}
  1585. X
  1586. X
  1587. X#define LOWER_CASE( c )                    ( (c) + 'a' - 'A' )
  1588. X
  1589. X/*
  1590. X * str_casefind is similar to str_find except that it ignores the
  1591. X * case of the alphabetic characters
  1592. X */
  1593. Xchar *str_casefind( str, sstr )
  1594. X    register char *str ;
  1595. X    char *sstr ;
  1596. X{
  1597. X    register int ssfc = *sstr++ ;        /* sub-string first char */
  1598. X
  1599. X    if ( ssfc == 0 )
  1600. X        return( str ) ;
  1601. X
  1602. X    if ( isalpha( ssfc ) && isupper( ssfc ) )
  1603. X        ssfc = LOWER_CASE( ssfc ) ;
  1604. X
  1605. X    while ( *str )
  1606. X    {
  1607. X        char *current = str ;
  1608. X        register int strc = *str++ ;
  1609. X        char *sp ;                            /* string pointer */
  1610. X        char *ssp ;                            /* sub-string pointer */
  1611. X
  1612. X        if ( isalpha( strc ) && isupper( strc ) )
  1613. X            strc = LOWER_CASE( strc ) ;
  1614. X        if ( strc != ssfc )
  1615. X            continue ;
  1616. X        
  1617. X        for ( sp = str, ssp = sstr ;; sp++, ssp++ )
  1618. X        {
  1619. X            register int sc = *sp ;                /* string char */
  1620. X            register int ssc = *ssp ;            /* substring char */
  1621. X
  1622. X            /*
  1623. X             * End-of-substring means we got a match
  1624. X             */
  1625. X            if ( ssc == 0 )
  1626. X                return( current ) ;
  1627. X
  1628. X            /*
  1629. X             * Convert to lower case if alphanumeric
  1630. X             */
  1631. X            if ( isalpha( sc ) && isupper( sc ) )
  1632. X                sc = LOWER_CASE( sc ) ;
  1633. X            if ( isalpha( ssc ) && isupper( ssc ) )
  1634. X                ssc = LOWER_CASE( ssc ) ;
  1635. X            if ( sc != ssc )
  1636. X                break ;
  1637. X        }
  1638. X    }
  1639. X
  1640. X    return( 0 ) ;
  1641. X}
  1642. X
  1643. X
  1644. X#else        /* defined( TRIVIAL_STR_FIND ) */
  1645. X
  1646. X/*
  1647. X * look for an instance of s2 in s1
  1648. X * Returns a pointer to the beginning of s2 in s1
  1649. X */
  1650. Xchar *str_find( s1, s2 )
  1651. X    char *s1 ;
  1652. X    char *s2 ;
  1653. X{
  1654. X   int i ;
  1655. X   int l1 = strlen( s1 ) ;
  1656. X   int l2 = strlen( s2 ) ;
  1657. X
  1658. X   for ( i = 0 ; i < l1 - l2 + 1 ; i++ )
  1659. X      if ( strncmp( &s1[ i ], s2, l2 ) == 0 )
  1660. X         return( &s1[ i ] ) ;
  1661. X   return( NULL ) ;
  1662. X}
  1663. X
  1664. X
  1665. Xchar *str_casefind( s1, s2 )
  1666. X    char *s1 ;
  1667. X    char *s2 ;
  1668. X{
  1669. X   int i ;
  1670. X   int l1 = strlen( s1 ) ;
  1671. X   int l2 = strlen( s2 ) ;
  1672. X
  1673. X   for ( i = 0 ; i < l1 - l2 + 1 ; i++ )
  1674. X      if ( strncasecmp( &s1[ i ], s2, l2 ) == 0 )
  1675. X         return( &s1[ i ] ) ;
  1676. X   return( NULL ) ;
  1677. X}
  1678. X
  1679. X#endif     /* TRIVIAL_STR_FIND */
  1680. X
  1681. X
  1682. X/*
  1683. X * Fill string s with character c
  1684. X */
  1685. Xvoid str_fill( s, c )
  1686. X    register char *s ;
  1687. X    register char c ;
  1688. X{
  1689. X    while ( *s ) *s++ = c ;
  1690. X}
  1691. X
  1692. X
  1693. Xchar *str_lower( s )
  1694. X    char *s ;
  1695. X{
  1696. X    register char *p ;
  1697. X    register int offset = 'a' - 'A' ;
  1698. X
  1699. X    for ( p = s ; *p ; p++ )
  1700. X        if ( isascii( *p ) && isupper( *p ) )
  1701. X            *p += offset ;
  1702. X    return( s ) ;
  1703. X}
  1704. X
  1705. X
  1706. Xchar *str_upper( s )
  1707. X    char *s ;
  1708. X{
  1709. X    register char *p ;
  1710. X    register int offset = 'a' - 'A' ;
  1711. X
  1712. X    for ( p = s ; *p ; p++ )
  1713. X        if ( isascii( *p ) && islower( *p ) )
  1714. X            *p -= offset ;
  1715. X    return( s ) ;
  1716. X}
  1717. X
  1718. X
  1719. END_OF_FILE
  1720.   if test 3554 -ne `wc -c <'libs/src/str/strutil.c'`; then
  1721.     echo shar: \"'libs/src/str/strutil.c'\" unpacked with wrong size!
  1722.   fi
  1723.   # end of 'libs/src/str/strutil.c'
  1724. fi
  1725. if test -f 'pst/COPYRIGHT' -a "${1}" != "-c" ; then 
  1726.   echo shar: Will not clobber existing file \"'pst/COPYRIGHT'\"
  1727. else
  1728.   echo shar: Extracting \"'pst/COPYRIGHT'\" \(1323 characters\)
  1729.   sed "s/^X//" >'pst/COPYRIGHT' <<'END_OF_FILE'
  1730. XThis software is
  1731. X
  1732. X(c) Copyright 1993 by Panagiotis Tsirigotis
  1733. X
  1734. XThe author (Panagiotis Tsirigotis) grants permission to use, copy,
  1735. Xand distribute this software and its documentation for any purpose 
  1736. Xand without fee, provided that the above copyright notice extant in
  1737. Xfiles in this distribution is not removed from files included in any
  1738. Xredistribution and that this file is also included in any redistribution.
  1739. X
  1740. XModifications to this software may be distributed, either by distributing
  1741. Xthe modified software or by distributing patches to the original software,
  1742. Xunder the following additional terms:
  1743. X
  1744. X1. The version number will be modified as follows:
  1745. X      a. The first 3 components of the version number
  1746. X         (i.e <number>.<number>.<number>) will remain unchanged.
  1747. X      b. A new component will be appended to the version number to indicate
  1748. X         the modification level. The form of this component is up to the 
  1749. X         author of the modifications.
  1750. X
  1751. X2. The author of the modifications will include his/her name by appending it 
  1752. X   along with the new version number to this file and will be responsible for 
  1753. X   any wrong behavior of the modified software.
  1754. X
  1755. XThe author makes no representations about the suitability of this 
  1756. Xsoftware for any purpose.  It is provided "as is" without any express 
  1757. Xor implied warranty.
  1758. X
  1759. END_OF_FILE
  1760.   if test 1323 -ne `wc -c <'pst/COPYRIGHT'`; then
  1761.     echo shar: \"'pst/COPYRIGHT'\" unpacked with wrong size!
  1762.   fi
  1763.   # end of 'pst/COPYRIGHT'
  1764. fi
  1765. if test -f 'pst/Makefile' -a "${1}" != "-c" ; then 
  1766.   echo shar: Will not clobber existing file \"'pst/Makefile'\"
  1767. else
  1768.   echo shar: Extracting \"'pst/Makefile'\" \(3407 characters\)
  1769.   sed "s/^X//" >'pst/Makefile' <<'END_OF_FILE'
  1770. X# (c) Copyright 1993 by Panagiotis Tsirigotis
  1771. X# All rights reserved.  The file named COPYRIGHT specifies the terms 
  1772. X# and conditions for redistribution.
  1773. X
  1774. X#
  1775. X# $Id: Makefile,v 1.13 1993/11/14 05:24:54 panos Exp $
  1776. X#
  1777. X
  1778. X#
  1779. X# Based on Program makefile template: *Revision: 1.19 *
  1780. X#
  1781. X
  1782. X#
  1783. X# Available entries:
  1784. X#        $(NAME)        --> create the program (this is the default target)
  1785. X#        install        --> install the program
  1786. X#        install.man --> install man page
  1787. X#        uninstall    --> uninstall the program (and man page)
  1788. X#        clean            --> cleanup
  1789. X#        spotless        --> clean + uninstall
  1790. X#         lint            --> lints a specific file (usage: make lint MODULE=foo.c)
  1791. X#        lintall        --> lint all files
  1792. X#        tags            --> creates a tags file
  1793. X#        checkout     --> checkout all files
  1794. X#
  1795. X
  1796. XNAME                    = pst
  1797. XVERSION                = 1.0.0
  1798. X
  1799. XDEFS                    =
  1800. XDEBUG                    = -g
  1801. XLDFLAGS                = -L$(LIBDIR)
  1802. XLIBS                    = -lsio -lstr
  1803. X
  1804. XOPT                    = options.opt
  1805. XOPT_HEADER            = options.h
  1806. XOPT_SOURCE            = options.c
  1807. XOPT_OBJECT            = options.o
  1808. X
  1809. XSRCS                    = dvi.c main.c common.c dit.c wp.c
  1810. XHDRS                    = defs.h
  1811. XOBJS                    = dvi.o main.o common.o dit.o wp.o
  1812. X
  1813. XSOURCES                = $(SRCS) $(OPT_SOURCE)
  1814. XHEADERS                = $(HDRS) $(OPT_HEADER)
  1815. XOBJECTS                = $(OBJS) $(OPT_OBJECT)
  1816. X
  1817. X
  1818. XINCLUDEDIR            = -I$(INCDIR)
  1819. XMANPATHDIR            = $(HOME)/.links/manpages
  1820. XINSTALLDIR            = $(BINDIR)
  1821. X
  1822. X
  1823. X#
  1824. X# You may modify the following variables but you probably don't need to.
  1825. X#
  1826. X
  1827. XPROGRAM                = $(NAME)
  1828. XMANSECTION            = 1
  1829. XMANSUBSECTION        =                        # like V,X,l
  1830. XMANFILE                = $(PROGRAM).man
  1831. XMANPAGE                = $(PROGRAM).$(MANSECTION)$(MANSUBSECTION)
  1832. XMANDIR                = $(MANPATHDIR)/man$(MANSECTION)
  1833. X
  1834. XCC                        = cc            # used for compiler-specific options
  1835. XCC_FLAGS                = $(DEBUG)    # used for generic options
  1836. X
  1837. XXMODE                    = -m 700                # mode for executables
  1838. XFMODE                    = -m 640                # mode for anything but executables
  1839. XINSTALL                = install -c
  1840. X
  1841. XLINT_FLAGS            = -hbux
  1842. XPAGER                    = less
  1843. X
  1844. XCPP_DEFS                = $(VERSION_DEF) $(DEFS)
  1845. X
  1846. X#
  1847. X# The following variables do not need to be changed
  1848. X#
  1849. X
  1850. XVERSION_DEF            = -DVERSION=\"$(PROGRAM)\ Version\ $(VERSION)\"
  1851. XCPP_FLAGS            = $(CPP_DEFS) $(INCLUDEDIR)
  1852. XCFLAGS                = $(CPP_FLAGS) $(CC_FLAGS)
  1853. X
  1854. X$(PROGRAM): $(OBJECTS)
  1855. X    $(CC) $(DEBUG) -o $@ $(OBJECTS) $(LDFLAGS) $(LIBS) || rm -f $(PROGRAM)
  1856. X
  1857. Xtags: $(HEADERS) $(SOURCES)
  1858. X    ctags -w $(HEADERS) $(SOURCES)
  1859. X
  1860. Xcheckout:
  1861. X
  1862. Xlint:
  1863. X    lint $(LINT_FLAGS) $(CPP_FLAGS) $(MODULE) 2>&1 | $(PAGER)
  1864. X
  1865. Xlintall:
  1866. X    lint $(LINT_FLAGS) $(CPP_FLAGS) $(SOURCES) 2>&1 | $(PAGER)
  1867. X
  1868. Xclean:
  1869. X    rm -f $(OBJECTS) $(PROGRAM) core
  1870. X
  1871. Xxclean: clean
  1872. X    rm -f $(OPT_HEADER) $(OPT_SOURCE)
  1873. X
  1874. Xinstall: $(PROGRAM)
  1875. X    $(INSTALL) $(XMODE) $(PROGRAM) $(INSTALLDIR)
  1876. X
  1877. Xinstall.man:
  1878. X    if test "$(MANFILE)" -a "$(MANDIR)" ; then $(INSTALL) $(FMODE) $(MANFILE) $(MANDIR)/$(MANPAGE) ; fi
  1879. X
  1880. Xuninstall:
  1881. X    a=`pwd` ; cd $(INSTALLDIR) ;\
  1882. X    if test $$a != `pwd` ; then rm -f $(PROGRAM) ; fi
  1883. X    a=`pwd` ; cd $(MANDIR) ;\
  1884. X    if test $$a != `pwd` ; then rm -f $(MANPAGE) ; fi
  1885. X
  1886. X#
  1887. X# Distribution section
  1888. X# This section contains the 2 targets for distribution support: dist, dirs
  1889. X# "dist" checks out all files to be distributed
  1890. X# "dirs" prints a list of directories to be included in the distribution.
  1891. X# These directories should have a Makefile with a "dist" target
  1892. X#
  1893. XDISTRIBUTION_FILES    = $(SRCS) $(HDRS) $(MANFILE) COPYRIGHT CHANGELOG
  1894. XDIRS                        =
  1895. X
  1896. Xdist1:
  1897. X
  1898. Xdist: dist1 $(OPT_SOURCE)
  1899. X    -co -q $(DISTRIBUTION_FILES)
  1900. X
  1901. Xdirs:
  1902. X    @echo $(DIRS)
  1903. X
  1904. X#
  1905. X# This part of the file shows how to make $(OBJECTS) 
  1906. X#
  1907. X
  1908. X$(OPT_OBJECT): $(OPT_HEADER)
  1909. Xmain.o:            $(OPT_HEADER) defs.h
  1910. Xdvi.o:            defs.h
  1911. Xcommon.o:        defs.h
  1912. Xdit.o:            defs.h
  1913. Xwp.o:                defs.h
  1914. END_OF_FILE
  1915.   if test 3407 -ne `wc -c <'pst/Makefile'`; then
  1916.     echo shar: \"'pst/Makefile'\" unpacked with wrong size!
  1917.   fi
  1918.   # end of 'pst/Makefile'
  1919. fi
  1920. if test -f 'pst/main.c' -a "${1}" != "-c" ; then 
  1921.   echo shar: Will not clobber existing file \"'pst/main.c'\"
  1922. else
  1923.   echo shar: Extracting \"'pst/main.c'\" \(3955 characters\)
  1924.   sed "s/^X//" >'pst/main.c' <<'END_OF_FILE'
  1925. X/*
  1926. X * (c) Copyright 1993 by Panagiotis Tsirigotis
  1927. X * All rights reserved.  The file named COPYRIGHT specifies the terms 
  1928. X * and conditions for redistribution.
  1929. X */
  1930. X
  1931. Xstatic char RCSid[] = "$Id: main.c,v 1.5 1993/11/14 05:24:19 panos Exp $" ;
  1932. Xstatic char version[] = VERSION ;
  1933. X
  1934. X#include <fcntl.h>
  1935. X
  1936. Xvoid exit() ;
  1937. X
  1938. X#include "sio.h"
  1939. X#include "str.h"
  1940. X
  1941. X#include "options.h"
  1942. X
  1943. X#include "defs.h"
  1944. X
  1945. Xint line_count = 1 ;
  1946. X
  1947. Xtypedef void (*ps_process)() ;
  1948. X
  1949. X/*
  1950. X * Available processes
  1951. X */
  1952. Xvoid dvi_process() ;
  1953. Xvoid psdit_process() ;
  1954. Xvoid troff_process() ;
  1955. Xvoid ditroff_process() ;
  1956. Xvoid wordperfect_process() ;
  1957. X
  1958. X
  1959. X
  1960. Xstruct process_string
  1961. X{
  1962. X    char            *ps_string ;
  1963. X    char            *ps_name ;
  1964. X    ps_process    ps_func ;
  1965. X    strs_h        ps_sh ;
  1966. X} ;
  1967. X
  1968. Xstatic struct process_string procstr[] =
  1969. X    {
  1970. X        {    ".dvi",        "dvi file",                        dvi_process                },
  1971. X        {    "/wpdict",    "wordperfect document",        wordperfect_process    },
  1972. X        {    "idraw",        "idraw",                            troff_process            },
  1973. X        {    "psdit",        "ditroff through psdit",    psdit_process            },
  1974. X        {    "tpscript",    "Kolstad's hack",                ditroff_process        },
  1975. X        {    "ditroff",    "ditroff file",                ditroff_process        },
  1976. X        {    "troff",        "troff file",                    troff_process            },
  1977. X        {    NULL }
  1978. X    } ;
  1979. X
  1980. X
  1981. Xstruct process_name
  1982. X    {
  1983. X        char            *pn_name ;
  1984. X        ps_process    pn_func ;
  1985. X    } ;
  1986. X
  1987. X
  1988. Xstatic struct process_name procnames[] =
  1989. X    {
  1990. X        {    "dvi",        dvi_process                },
  1991. X        {    "psdit",        psdit_process            },
  1992. X        {    "dit",        ditroff_process        },
  1993. X        {    "troff",        troff_process            },
  1994. X        {    "wp",            wordperfect_process    },
  1995. X        { NULL }
  1996. X    } ;
  1997. X
  1998. X
  1999. Xint main( argc, argv )
  2000. X    int argc ;
  2001. X    char *argv[] ;
  2002. X{
  2003. X    int            first_arg = opt_recognize( argc, argv ) ;
  2004. X    int            in_fd ;
  2005. X    ps_process    process ;
  2006. X    ps_process    find_process() ;
  2007. X    void            printout_flush() ;
  2008. X
  2009. X    if ( argc - first_arg > 1 )        /* at most 1 arg */
  2010. X        usage() ;
  2011. X
  2012. X    if ( first_arg == argc )
  2013. X        in_fd = 0 ;
  2014. X    else
  2015. X    {
  2016. X        extern int errno ;
  2017. X        char *file = argv[ first_arg ] ;
  2018. X
  2019. X        in_fd = open( file, O_RDONLY ) ;
  2020. X        if ( in_fd == -1 )
  2021. X            error( "Failed to open file %s (errno = %d)\n", file, errno ) ;
  2022. X    }
  2023. X    
  2024. X    if ( l_option )
  2025. X    {
  2026. X        struct process_name *pnp ;
  2027. X
  2028. X        Sprint( 1, "Recognized algorithm names:\n" );
  2029. X        for ( pnp = procnames ; pnp->pn_name ; pnp++ )
  2030. X            Sprint( 1, "\t%s\n", pnp->pn_name ) ;
  2031. X        exit( 0 ) ;
  2032. X    }
  2033. X
  2034. X    if ( d_option )
  2035. X        Sbuftype( 1, SIO_NOBUF ) ;
  2036. X
  2037. X    if ( a_option )
  2038. X    {
  2039. X        struct process_name *pnp ;
  2040. X
  2041. X        for ( pnp = procnames ;; pnp++ )
  2042. X        {
  2043. X            if ( pnp->pn_name == NULL )
  2044. X                error( "Unknown algorithm: %s\n", a_option_arg ) ;
  2045. X            if ( strcmp( pnp->pn_name, a_option_arg ) == 0 )
  2046. X            {
  2047. X                process = pnp->pn_func ;
  2048. X                break ;
  2049. X            }
  2050. X        }
  2051. X    }
  2052. X    else
  2053. X        process = find_process( in_fd ) ;
  2054. X
  2055. X    if ( ! n_option )
  2056. X    {
  2057. X        (*process)( in_fd ) ;
  2058. X        printout_flush() ;
  2059. X    }
  2060. X
  2061. X    exit( 0 ) ;
  2062. X    /* NOTREACHED */
  2063. X}
  2064. X
  2065. X/*
  2066. X * Determine what process to use to parse this file.
  2067. X */
  2068. XPRIVATE ps_process find_process( fd )
  2069. X    int fd ;
  2070. X{
  2071. X    char                            *line ;
  2072. X    struct process_string    *psp ;
  2073. X    struct process_string    *found = NULL ;
  2074. X
  2075. X    /*
  2076. X     * Create string matchers
  2077. X     */
  2078. X    for ( psp = procstr ; psp->ps_string ; psp++ )
  2079. X    {
  2080. X        psp->ps_sh = strs_setup( STRS_BF + STRS_NOMALLOC, psp->ps_string ) ;
  2081. X        if ( psp->ps_sh == NULL )
  2082. X            error( "out of memory\n" ) ;
  2083. X    }
  2084. X
  2085. X    /*
  2086. X     * Try to determine how the file was derived.
  2087. X     * Method:
  2088. X     *        Read lines looking for one of the identifier strings
  2089. X     *        If an identifier string is found, continue reading lines
  2090. X     *     until a non-comment line is found.
  2091. X     */
  2092. X    while ( line = Srdline( fd ) )
  2093. X    {
  2094. X        line_count++ ;
  2095. X        if ( line[ 0 ] != '%' && found )
  2096. X            break ;
  2097. X        
  2098. X        /*
  2099. X         * Check what process (if any) is identified by this line
  2100. X         */
  2101. X        for ( psp = procstr ; psp->ps_string ; psp++ )
  2102. X            if ( strs_match( psp->ps_sh, line, SIOLINELEN( fd ) ) )
  2103. X            {
  2104. X                /*
  2105. X                 * psdit process takes precedence over ditroff_process
  2106. X                 */
  2107. X                if ( ! found || found->ps_func == ditroff_process && 
  2108. X                                                        psp->ps_func == psdit_process )
  2109. X                    found = psp ;
  2110. X            }
  2111. X    }
  2112. X    if ( ! found )
  2113. X        error( "Failed to identify how this file was derived\n" ) ;
  2114. X    if ( v_option )
  2115. X        Sprint( 2, "Postscript file derived from %s\n", found->ps_name ) ;
  2116. X    return( found->ps_func ) ;
  2117. X}
  2118. X
  2119. END_OF_FILE
  2120.   if test 3955 -ne `wc -c <'pst/main.c'`; then
  2121.     echo shar: \"'pst/main.c'\" unpacked with wrong size!
  2122.   fi
  2123.   # end of 'pst/main.c'
  2124. fi
  2125. echo shar: End of archive 4 \(of 6\).
  2126. cp /dev/null ark4isdone
  2127. MISSING=""
  2128. for I in 1 2 3 4 5 6 ; do
  2129.     if test ! -f ark${I}isdone ; then
  2130.     MISSING="${MISSING} ${I}"
  2131.     fi
  2132. done
  2133. if test "${MISSING}" = "" ; then
  2134.     echo You have unpacked all 6 archives.
  2135.     rm -f ark[1-9]isdone
  2136. else
  2137.     echo You still must unpack the following archives:
  2138.     echo "        " ${MISSING}
  2139. fi
  2140. exit 0
  2141. exit 0 # Just in case...
  2142.