patch: make *outfile extern
[platform/upstream/cdrkit.git] / librols / breakline.c
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
4  * The behaviour and appearence of the program code below can differ to a major
5  * extent from the version distributed by the original author(s).
6  *
7  * For details, see Changelog file distributed with the cdrkit package. If you
8  * received this file from another source then ask the distributing person for
9  * a log of modifications.
10  *
11  */
12
13 /* @(#)breakline.c      1.10 04/09/25 Copyright 1985, 1995-2003 J. Schilling */
14 /*
15  *      break a line pointed to by *buf into fields
16  *      returns the number of tokens, the line was broken into (>= 1)
17  *
18  *      delim is the delimiter to break at
19  *      array[0 .. found-1] point to strings from broken line
20  *      array[found ... len] point to '\0'
21  *      len is the size of the array
22  *
23  *      Copyright (c) 1985, 1995-2003 J. Schilling
24  */
25 /*
26  * This program is free software; you can redistribute it and/or modify
27  * it under the terms of the GNU General Public License version 2
28  * as published by the Free Software Foundation.
29  *
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details.
34  *
35  * You should have received a copy of the GNU General Public License along with
36  * this program; see the file COPYING.  If not, write to the Free Software
37  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38  */
39
40 #include <mconfig.h>
41 #include <standard.h>
42 #include <schily.h>
43
44 #ifdef  PROTOTYPES
45 EXPORT int
46 breakline(char *buf,
47                 register char delim,
48                 register char *array[],
49                 register int len)
50 #else
51 EXPORT int
52 breakline(buf, delim, array, len)
53                 char    *buf;
54         register char   delim;
55         register char   *array[];
56         register int    len;
57 #endif
58 {
59         register char   *bp = buf;
60         register char   *dp;
61         register int    i;
62         register int    found;
63
64         for (i = 0, found = 1; i < len; i++) {
65                 for (dp = bp; *dp != '\0' && *dp != delim; dp++)
66                         /* LINTED */
67                         ;
68
69                 array[i] = bp;
70                 if (*dp == delim) {
71                         *dp++ = '\0';
72                         found++;
73                 }
74                 bp = dp;
75         }
76         return (found);
77 }