comparison helpers/makeline.c @ 3:8123259c7f14

helpers/makeline imported from Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 15 May 2020 02:02:09 +0000
parents
children
comparison
equal deleted inserted replaced
2:14f8a71286c5 3:8123259c7f14
1 /*
2 * This helper utility for the FreeCalypso Selenite 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 exit(0);
76 }