File: texi-linearize.c

package info (click to toggle)
fdutils 5.6-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,540 kB
  • sloc: ansic: 6,334; sh: 3,570; makefile: 262; sed: 4
file content (57 lines) | stat: -rw-r--r-- 973 bytes parent folder | download | duplicates (10)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


FILE *my_open(char *directory, char *file)
{
	char path[8192];
	FILE *r;

	strcpy(path, directory);
	strcat(path,"/");
	strcat(path, file);
	
	r= fopen(path, "r");
	if(r == NULL) {
		fprintf(stderr,"Could not open %s\n", path);
		perror("open");
		exit(1);
	}
	return r;
}

int main(int argc, char **argv)
{
  FILE *stack[256];
  int sp;
  char line[4096];
  char *directory;

  sp = 0;

  if(argc < 3) {
	  fprintf(stderr,"Usage: %s directory root texi file\n", argv[0]);
	  exit(1);
  }

  directory = argv[1];

  stack[sp++] = my_open(directory, argv[2]);
  while(sp) {
	  if(fgets(line, 4095, stack[sp-1]) ) {
		  line[strlen(line)-1]='\0';
		  if(!strncmp(line, "@input", 6)) {
			  stack[sp++] = my_open(directory, line+7);
			  continue;
		  }
		  if(!strncmp(line, "@include", 8)) {
			  stack[sp++] = my_open(directory, line+9);
			  continue;
		  }
		  puts(line);
	  } else
		  sp--;
  }
  exit(0);
}