Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: lsplitter.c | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | #include <stdio.h> | |
24 | #include <stdlib.h> | |
25 | #include <unistd.h> | |
26 | ||
27 | /* really dumb line splitting program */ | |
28 | ||
29 | int | |
30 | main(int argc, char ** argv) | |
31 | { | |
32 | FILE * infp, *outfp; | |
33 | char * matchp; | |
34 | int idx, ch; | |
35 | ||
36 | if (argc != 2) { | |
37 | fprintf(stderr,"usage: %s <splitstring>\n", argv[0]); | |
38 | exit(1); | |
39 | } | |
40 | ||
41 | matchp = argv[1]; | |
42 | ||
43 | infp = stdin; | |
44 | outfp = stdout; | |
45 | ||
46 | idx = 0; | |
47 | ||
48 | while ( (ch=fgetc(infp))!=EOF) { | |
49 | if (matchp[idx] == ch) { | |
50 | idx ++; | |
51 | if (matchp[idx]=='\0') { | |
52 | fputc('\n', outfp); | |
53 | idx = 0; | |
54 | } | |
55 | } else { | |
56 | int q; | |
57 | for (q=0; q<idx; q++) | |
58 | fputc(matchp[q], outfp); | |
59 | fputc(ch, outfp); | |
60 | idx = 0; | |
61 | } | |
62 | } | |
63 | ||
64 | fclose(outfp); | |
65 | fclose(infp); | |
66 | return (0); | |
67 | } |