|
1 | 1 | # cpp-merge |
2 | | -Tool to produce single source file from multiple C/C++ files. Is was developed mainly to use in programming contests |
3 | | -in which solution must be submitted as single source file. |
| 2 | + |
| 3 | +Tool to produce a single source file from multiple C/C++ files. It was developed mainly to be used in programming |
| 4 | +contests that require submitting a solution as a single source file. |
4 | 5 |
|
5 | 6 | ## Install |
| 7 | + |
6 | 8 | #### Prerequisites |
| 9 | + |
7 | 10 | * node |
8 | 11 | * npm |
9 | 12 | * yarn (optional) |
10 | 13 |
|
11 | 14 | #### Installation from npm |
| 15 | + |
12 | 16 | ``` |
13 | 17 | npm install -g cpp-merge |
14 | 18 | ``` |
15 | 19 |
|
16 | 20 | #### Installation from source |
| 21 | + |
17 | 22 | ##### Clone git repository |
| 23 | + |
18 | 24 | ``` |
19 | 25 | git clone git@github.com:RandomVoid/cpp-merge.git |
20 | 26 | ``` |
21 | 27 |
|
22 | 28 | ##### Build and link package |
| 29 | + |
23 | 30 | Using npm: |
| 31 | + |
24 | 32 | ``` |
25 | 33 | npm install |
26 | 34 | npm run build |
27 | 35 | npm link |
28 | 36 | ``` |
29 | 37 |
|
30 | 38 | Or using yarn: |
| 39 | + |
31 | 40 | ``` |
32 | 41 | yarn |
33 | 42 | yarn build |
34 | 43 | yarn link |
35 | 44 | ``` |
36 | 45 |
|
37 | 46 | ## Usage |
38 | | -This tool will produce single source file from multiple C/C++ files. By default produced content is displayed on |
39 | | -the standard output. To save it into a file use option `-o` or `--output`. |
40 | 47 |
|
41 | | -File passed as an argument will be processed similarly to what preprocessor would do. It means all included local |
42 | | -files (ex. `#include "header.hpp"`) will processed and added to output in place of the include directive. |
43 | | -Program will search for include files first in directory where currently processed file is located and then in |
| 48 | +This tool will produce a single source file from multiple C/C++ files. By default produced content is displayed on the |
| 49 | +standard output. To save it into a file use option `-o` or `--output`. |
| 50 | + |
| 51 | +File passed as an argument will be processed similarly to what the preprocessor would do. It means all included local |
| 52 | +files (ex. `#include "header.hpp"`) will be processed and added to output in place of the include directive. Program |
| 53 | +will search for include files first in the directory where the currently processed file is located and then in |
44 | 54 | additional include directory, if it was specified in program arguments (option `-i` or `--include`). |
45 | 55 |
|
46 | 56 | Files containing `#pragma once` will be processed only once, so use this directive to avoid duplication of content of |
47 | 57 | files in the output and to reduce its size. |
48 | 58 |
|
49 | | -After processing all included files, program will try to find related source file for each of included local header |
50 | | -files. If file with same base name and extension .c or .cpp exists, it will be appended to the output. Program will |
51 | | -search first in the same directory where main source file is located and then in additional source directory, if it was |
52 | | -specified in program arguments (option `-s` or `--source`). If the header was included using relative path ex. |
53 | | -`#include "one/two/three.hpp"` the program will search for `three.c` or `three.cpp` in `one/two/` or |
54 | | -`${sourceDirectory}/one/two/`. First found file will be appended to the output. |
| 59 | +After processing all included files, the program will try to find related source files for each of included local header |
| 60 | +files. If a file with the same base name and extension .c or .cpp exists, it will be appended to the output. Program |
| 61 | +will search first in the same directory where the main source file is located and then in an additional source |
| 62 | +directory, if it was specified in program arguments (option `-s` or `--source`). If the header was included using |
| 63 | +relative path ex. `#include "one/two/three.hpp"` the program will search for `three.c` or `three.cpp` in `one/two/` |
| 64 | +or `${sourceDirectory}/one/two/`. First found file will be appended to the output. |
55 | 65 |
|
56 | | -Program will detect duplication of system header includes, so output will contain only unique set of them, ordered |
57 | | -alphabetically. Any of processed header and source files will not be changed. |
| 66 | +Program will detect duplication of system header includes, so output will contain only a unique set of them, ordered |
| 67 | +alphabetically. Any of the processed header and source files will not be changed. |
| 68 | + |
| 69 | +Display the build-in help: |
58 | 70 |
|
59 | | -Display build-in help: |
60 | 71 | ``` |
61 | 72 | cpp-merge --help |
62 | 73 | ``` |
63 | 74 |
|
64 | 75 | #### Usage examples |
65 | | -Process `main.cpp` and display produced content on standard output: |
| 76 | + |
| 77 | +Process `main.cpp` and display produced content on the standard output: |
| 78 | + |
66 | 79 | ``` |
67 | 80 | cpp-merge main.cpp |
68 | 81 | ``` |
69 | 82 |
|
70 | 83 | Process `main.cpp` and save output to file `output.cpp`: |
| 84 | + |
71 | 85 | ``` |
72 | 86 | cpp-merge --output output.cpp main.cpp |
73 | 87 | ``` |
74 | 88 |
|
75 | 89 | Specify additional include and source directory: |
| 90 | + |
76 | 91 | ``` |
77 | 92 | cpp-merge --include ../include --source ../src main.cpp |
78 | | -``` |
| 93 | +``` |
0 commit comments