File: ver_edit.c

package info (click to toggle)
librnd 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,812 kB
  • sloc: ansic: 126,990; sh: 2,602; makefile: 2,145; awk: 7
file content (25 lines) | stat: -rw-r--r-- 572 bytes parent folder | download | duplicates (12)
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
#include <stdio.h>
#include <string.h>

#define replace(pattern, value) \
do { \
	char *next, *s = strstr(line, pattern); \
	if (s != NULL) { \
		next = s + strlen(pattern); \
		strcpy(s, value); \
		s += strlen(value); \
		memmove(s, next, strlen(next)+1); \
	} \
} while(0)

int main(int argc, char *argv[])
{
	char *major = argv[1], *minor = argv[2], *patch = argv[3], line[256];;
	while(fgets(line, sizeof(line), stdin) != NULL) {
		replace("_VER_MAJOR_", major);
		replace("_VER_MINOR_", minor);
		replace("_VER_PATCH_", patch);
		printf("%s", line);
	}
	return 0;
}