about summary refs log tree commit diff
path: root/sourcecodes/k-best/src/parents2arcs.c
blob: 81e8b3b10c5320ae559a5778b95eceaf29afb318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "cfg.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define BUFSIZE (1024)

void parents2arcs(char* parfile, char* arcfile)
{
  char buffer[BUFSIZE];
  int v;
  FILE* parf = strcmp(parfile,"-") ? fopen(parfile, "r") : stdin;
  FILE* arcf = strcmp(arcfile,"-") ? fopen(arcfile, "w") : stdout;
  for(v=0; NULL != fgets(buffer, BUFSIZE, parf); ++v){
    /* could check that the last character in buffer is newline */
    char* token;
    for(token=strtok(buffer, " \t\r\n"); token; token=strtok(NULL, " \t\r\n")){
      fprintf(arcf, "%d %d\n", atoi(token), v);
    }
  }
  fclose(arcf);
  fclose(parf);
}

int main(int argc, char* argv[])
{

  if (argc!=3) {
    fprintf(stderr, "Usage: parents2arcs parentfile arcfile\n");
    return 1;
  }

  parents2arcs(argv[1], argv[2]);

  return 0;
}