source: app/src/tok.c/tok.c @ 3748bd1

help
Last change on this file since 3748bd1 was 25ae32e, checked in by obrebski <obrebski@…>, 16 years ago

git-svn-id: svn://atos.wmid.amu.edu.pl/utt@4 e293616e-ec6a-49c2-aa92-f4a8b91c5d16

  • Property mode set to 100644
File size: 1.5 KB
Line 
1
2#include <ctype.h>
3#include <stdio.h>
4#include <string.h>
5#include <locale.h>
6
7
8#include <stdlib.h>
9//#include "../lib/iotools.h"
10
11#include "cmdline.h"
12
13
14char buf[257];
15int filepos=0;
16char* tokstart;
17char* tokend;
18char tmp;
19char tag;
20
21
22gengetopt_args_info args;
23
24
25inline
26void printtoken(char tag)
27{
28  tmp=*tokend;
29  *tokend='\0';
30  printf("%04d %02d %c %s\n", filepos, tokend-tokstart, tag, tokstart);
31  *tokend=tmp;
32  filepos+=tokend-tokstart;
33  tokstart=tokend;
34  if(args.interactive_flag) fflush(stdout);
35}
36
37main(int argc, char** argv)
38{
39
40  if (cmdline_parser(argc, argv, &args) != 0)
41    exit(1);
42
43  printf("inter:%d\n",args.interactive_flag);
44
45  //  process_common_options(&args, argv[0]);
46  //  process_tok_options(args);
47
48  setlocale(LC_CTYPE,"");
49  setlocale(LC_COLLATE,"");
50
51  while(fgets(buf,256,stdin))
52  {
53
54    tokstart=tokend=buf;
55    while(*tokend)
56    {
57      char *prev=tokend;
58      ++tokend;
59      if(isalpha(*prev) && !isalpha(*tokend))
60         printtoken('W');
61      else if(isdigit(*prev) && !isdigit(*tokend))
62        printtoken('N');
63      else if(isspace(*prev))
64        {
65          switch(*prev)
66            {
67            case ' ': *prev='_'; break;
68            case '\t':*prev='t'; break;
69            case '\r':*prev='r'; break;
70            case '\f':*prev='f'; break;
71            case '\n':*prev='n';
72            }
73          if(!isspace(*tokend))
74            printtoken('S');
75        }
76      else if(ispunct(*prev))
77         printtoken('P');
78    }
79  }
80
81  cmdline_parser_free(&args);
82}
83
Note: See TracBrowser for help on using the repository browser.