comparison PubdicPlus/wtopd.c @ 0:bbc77ca4def5

initial import
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 13 Dec 2007 04:30:14 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bbc77ca4def5
1 /* Copyright 1994 Pubdic Project.
2 *
3 * Permission to use, copy, modify, distribute and sell this software
4 * and its documentation for any purpose is hereby granted without
5 * fee, provided that the above copyright notice appear in all copies
6 * and that both that copyright notice and this permission notice
7 * appear in supporting documentation, and that the name of Pubdic
8 * Project not be used in advertising or publicity pertaining to
9 * distribution of the software without specific, written prior
10 * permission. Pubdic Project makes no representations about the
11 * suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * PUBDIC PROJECT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
16 * NO EVENT SHALL PUBDIC PROJECT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19 * OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23 #ifndef lint
24 static char rcsid[] = "$Id: wtopd.c,v 1.2 2001/06/14 18:15:54 ura Exp $";
25 #endif
26
27 #include <stdio.h>
28
29 static char *program;
30
31 #define READBUFSIZE 1024
32
33 char *
34 extstr (p, pp)
35 char *p, **pp;
36 {
37 char *res;
38
39 while (*p == ' ' || *p == '\t')
40 p++;
41 res = p;
42 while (*p && *p != ' ' && *p != '\t' && *p != '\n')
43 p++;
44 *p++ = '\0';
45 if (pp)
46 *pp = p;
47 return res;
48 }
49
50 static void
51 wtop (file)
52 FILE *file;
53 {
54 char readbuf[READBUFSIZE], *p, *yomi, *hinshi, *kouho, *hindo;
55
56 while (p = fgets (readbuf, sizeof (readbuf), file))
57 {
58 yomi = extstr (p, &p);
59 kouho = extstr (p, &p);
60 hinshi = extstr (p, &p);
61 hindo = extstr (p, &p);
62
63 printf ("%s %s %s %s\n", yomi, kouho, hinshi, hindo);
64 }
65 }
66
67 main (argc, argv)
68 int argc;
69 char *argv[];
70 {
71 FILE *ins = stdin;
72
73 for (program = argv[0] + strlen (argv[0]); argv[0] < program; program--)
74 {
75 if (program[0] == '/')
76 {
77 program++;
78 break;
79 }
80 }
81
82 if (argc > 1)
83 {
84 ins = fopen (argv[1], "r");
85 if (!ins)
86 {
87 fprintf (stderr, "%s: can not open file \"%s\".\n", program, argv[1]);
88 }
89 }
90 wtop (ins);
91 fclose (ins);
92 exit (0);
93 }