comparison helpers/makeline.c @ 9:05945a9b9dda

makeline helper written
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2016 20:53:13 +0000
parents
children 352f80da6813
comparison
equal deleted inserted replaced
8:82ae0ab1ff42 9:05945a9b9dda
1 /*
2 * This helper utility for the FreeCalypso Magnetite build system
3 * emits potentially long generated Makefile lines, breaking them into
4 * multiple lines with backslashes.
5 */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <strings.h>
11
12 int is_cmd, equ_or_colon, extra_indent;
13 int linelen;
14
15 main(argc, argv)
16 char **argv;
17 {
18 char **ap;
19
20 if (argc < 4) {
21 fprintf(stderr, "error: too few arguments\n", argv[0]);
22 exit(1);
23 }
24 if (!strcmp(argv[1], "def")) {
25 is_cmd = 0;
26 equ_or_colon = '=';
27 extra_indent = 0;
28 } else if (!strcmp(argv[1], "dep")) {
29 is_cmd = 0;
30 equ_or_colon = ':';
31 extra_indent = 1;
32 } else if (!strcmp(argv[1], "cmd")) {
33 is_cmd = 1;
34 extra_indent = 1;
35 } else {
36 fprintf(stderr, "error: line type \"%s\" not known\n", argv[1]);
37 exit(1);
38 }
39 if (is_cmd) {
40 putchar('\t');
41 linelen = 8;
42 } else
43 linelen = 0;
44 fputs(argv[2], stdout);
45 linelen += strlen(argv[2]);
46 if (is_cmd) {
47 putchar(' ');
48 linelen++;
49 } else {
50 putchar(equ_or_colon);
51 linelen++;
52 putchar('\t');
53 do
54 linelen++;
55 while (linelen & 7);
56 }
57 fputs(argv[3], stdout);
58 linelen += strlen(argv[3]);
59 for (ap = argv + 4; *ap; ap++) {
60 if (linelen + 1 + strlen(*ap) <= 78) {
61 putchar(' ');
62 linelen++;
63 } else {
64 fputs(" \\\n\t", stdout);
65 linelen = 8;
66 if (extra_indent) {
67 fputs(" ", stdout);
68 linelen += 4;
69 }
70 }
71 fputs(*ap, stdout);
72 linelen += strlen(*ap);
73 }
74 putchar('\n');
75 }