Command line interface finished

This commit is contained in:
2018-07-23 21:12:25 +02:00
parent b25f147707
commit bb13993e34
3 changed files with 87 additions and 8 deletions

View File

@@ -17,9 +17,12 @@
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "command-line.h"
#include "gds-parser/gds-parser.h"
#include "mapping-parser.h"
#include "cairo-output/cairo-output.h"
#include "latex-output/latex-output.h"
static void delete_layer_info_with_name(struct layer_info *info)
{
@@ -30,9 +33,11 @@ static void delete_layer_info_with_name(struct layer_info *info)
}
}
void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gboolean pdf, gboolean tex, char *layer_file)
void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gboolean pdf, gboolean tex,
char *layer_file, char *cell_name, double scale, gboolean pdf_layers, gboolean pdf_standalone)
{
GList *libs = NULL;
FILE *tex_file;
int res;
GFile *file;
int i;
@@ -43,10 +48,12 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
int layer;
char *layer_name;
GList *layer_info_list = NULL;
GList *cell_list;
struct layer_info *linfo_temp;
struct gds_cell *toplevel_cell = NULL, *temp_cell;
/* Check if parameters are valid */
if (!gds_name || ! pdf_name || !tex_name || !layer_file) {
if (!gds_name || ! pdf_name || !tex_name || !layer_file || !cell_name) {
printf("Probably missing argument. Check --help option\n");
return;
}
@@ -60,14 +67,17 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
file = g_file_new_for_path(layer_file);
stream = g_file_read(file, NULL, NULL);
if (!stream)
if (!stream) {
printf("Layer mapping not readable!\n");
goto destroy_file;
}
dstream = g_data_input_stream_new(G_INPUT_STREAM(stream));
i = 0;
do {
res = load_csv_line(dstream, &layer_export, &layer_name, &layer, &layer_color);
if (res == 0) {
if (!layer_export)
continue;
linfo_temp = (struct layer_info *)malloc(sizeof(struct layer_info));
if (!linfo_temp) {
printf("Out of memory\n");
@@ -84,6 +94,37 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
}
} while(res >= 0);
/* find_cell in first library. */
if (!libs)
goto ret_clear_list;
for (cell_list = ((struct gds_library *)libs->data)->cells; cell_list != NULL; cell_list = g_list_next(cell_list)) {
temp_cell = (struct gds_cell *)cell_list->data;
if (!strcmp(temp_cell->name, cell_name)) {
toplevel_cell = temp_cell;
break;
}
}
if (!toplevel_cell) {
printf("Couldn't find cell in first library!\n");
goto ret_clear_list;
}
/* Render outputs */
if (pdf == TRUE) {
cairo_render_cell_to_pdf(toplevel_cell, layer_info_list, pdf_name, scale);
}
if (tex == TRUE) {
tex_file = fopen(tex_name, "w");
if (!tex_file)
goto ret_clear_list;
latex_render_cell_to_code(toplevel_cell, layer_info_list, tex_file, scale, pdf_layers, pdf_standalone);
fclose(tex_file);
}
ret_clear_list:
g_list_free_full(layer_info_list, (GDestroyNotify)delete_layer_info_with_name);