static void cmd_export_impl (void *data, int argc, char **argv) { int i; GError *err = NULL; gchar *tmp; const gchar *out_suffix; struct ExportFormat *exporter = NULL; GArray *render_color_map = NULL; gchar *original_cwd = g_get_current_dir (); gtk_init_check (&argc, &argv); scm_init_guile (); libgeda_init (); scm_dynwind_begin (0); toplevel = s_toplevel_new (); edascm_dynwind_toplevel (toplevel); /* Now load rc files, if necessary */ if (getenv ("GAF_INHIBIT_RCFILES") == NULL) { g_rc_parse (toplevel, "gaf export", NULL, NULL); } i_vars_libgeda_set (toplevel); /* Ugh */ /* Parse configuration files */ export_config (); /* Parse command-line arguments */ export_command_line (argc, argv); /* If no format was specified, try and guess from output * filename. */ if (settings.format == NULL) { out_suffix = strrchr (settings.outfile, '.'); if (out_suffix != NULL) { out_suffix++; /* Skip '.' */ } else { fprintf (stderr, _("ERROR: Cannot infer output format from filename '%s'.\n"), settings.outfile); exit (1); } } /* Try and find an exporter function */ tmp = g_utf8_strdown ((settings.format == NULL) ? out_suffix : settings.format, -1); for (i = 0; formats[i].name != NULL; i++) { if (strcmp (tmp, formats[i].alias) == 0) { exporter = &formats[i]; break; } } if (exporter == NULL) { if (settings.format == NULL) { fprintf (stderr, _("ERROR: Cannot find supported format for filename '%s'.\n"), settings.outfile); exit (1); } else { fprintf (stderr, _("ERROR: Unsupported output format '%s'.\n"), settings.format); fprintf (stderr, see_help_msg); exit (1); } } g_free (tmp); /* If more than one schematic/symbol file was specified, check that * exporter supports multipage output. */ if ((settings.infilec > 1) && !(exporter->flags & OUTPUT_MULTIPAGE)) { fprintf (stderr, _("ERROR: Selected output format does not support multipage output\n")); exit (1); } /* Load schematic files */ while (optind < argc) { PAGE *page; tmp = argv[optind++]; page = s_page_new (toplevel, tmp); if (!f_open (toplevel, page, tmp, &err)) { fprintf (stderr, _("ERROR: Failed to load '%s': %s\n"), tmp, err->message); exit (1); } if (g_chdir (original_cwd) != 0) { fprintf (stderr, _("ERROR: Failed to change directory to '%s': %s\n"), original_cwd, g_strerror (errno)); exit (1); } } /* Create renderer */ renderer = eda_renderer_new (NULL, NULL); if (settings.font != NULL) { g_object_set (renderer, "font-name", settings.font, NULL); } /* Make sure libgeda knows how to calculate the bounds of text * taking into account font etc. */ o_text_set_rendered_bounds_func (toplevel, export_text_rendered_bounds, renderer); /* Create color map */ render_color_map = g_array_sized_new (FALSE, FALSE, sizeof(GedaColor), MAX_COLORS); render_color_map = g_array_append_vals (render_color_map, print_colors, MAX_COLORS); if (!settings.color) { /* Create a black and white color map. All non-background colors * are black. */ GedaColor white = {~0, ~0, ~0, ~0, TRUE}; GedaColor black = {0, 0, 0, ~0, TRUE}; for (i = 0; i < MAX_COLORS; i++) { GedaColor *c = &g_array_index (render_color_map, GedaColor, i); if (!c->enabled) continue; if (c->a == 0) { c->enabled = FALSE; continue; } if (i == OUTPUT_BACKGROUND_COLOR) { *c = white; } else { *c = black; } } } eda_renderer_set_color_map (renderer, render_color_map); /* Render */ exporter->func (); scm_dynwind_end (); exit (0); }
/* ** COMMAND: configuration* ** ** Usage: %vcs configuration METHOD ... ?OPTIONS? ** ** Where METHOD is one of: export import merge pull push reset. All methods ** accept the -R or --repository option to specific a repository. ** ** %vcs configuration export AREA FILENAME ** ** Write to FILENAME exported configuraton information for AREA. ** AREA can be one of: all email project shun skin ticket user ** ** %vcs configuration import FILENAME ** ** Read a configuration from FILENAME, overwriting the current ** configuration. ** ** %vcs configuration merge FILENAME ** ** Read a configuration from FILENAME and merge its values into ** the current configuration. Existing values take priority over ** values read from FILENAME. ** ** %vcs configuration pull AREA ?URL? ** ** Pull and install the configuration from a different server ** identified by URL. If no URL is specified, then the default ** server is used. Use the --legacy option for the older protocol ** (when talking to servers compiled prior to 2011-04-27.) Use ** the --overwrite flag to completely replace local settings with ** content received from URL. ** ** %vcs configuration push AREA ?URL? ** ** Push the local configuration into the remote server identified ** by URL. Admin privilege is required on the remote server for ** this to work. When the same record exists both locally and on ** the remote end, the one that was most recently changed wins. ** Use the --legacy flag when talking to holder servers. ** ** %vcs configuration reset AREA ** ** Restore the configuration to the default. AREA as above. ** ** %vcs configuration sync AREA ?URL? ** ** Synchronize configuration changes in the local repository with ** the remote repository at URL. ** ** Options: ** -R|--repository FILE Extract info from repository FILE ** ** See also: settings, unset */ void configuration_cmd(void) { int n; const char *zMethod; if( g.argc<3 ) { usage("export|import|merge|pull|reset ..."); } db_find_and_open_repository(0, 0); db_open_config(0); zMethod = g.argv[2]; n = strlen(zMethod); if( strncmp(zMethod, "export", n)==0 ) { int mask; const char *zSince = find_option("since",0,1); sqlite3_int64 iStart; if( g.argc!=5 ) { usage("export AREA FILENAME"); } mask = configure_name_to_mask(g.argv[3], 1); if( zSince ) { iStart = db_multi_exec( "SELECT coalesce(strftime('%%s',%Q),strftime('%%s','now',%Q))+0", zSince, zSince ); } else { iStart = 0; } export_config(mask, g.argv[3], iStart, g.argv[4]); } else if( strncmp(zMethod, "import", n)==0 || strncmp(zMethod, "merge", n)==0 ) { Blob in; int groupMask; if( g.argc!=4 ) usage(mprintf("%s FILENAME",zMethod)); blob_read_from_file(&in, g.argv[3]); db_begin_transaction(); if( zMethod[0]=='i' ) { groupMask = CONFIGSET_ALL | CONFIGSET_OVERWRITE; } else { groupMask = CONFIGSET_ALL; } configure_receive_all(&in, groupMask); db_end_transaction(0); } else if( strncmp(zMethod, "pull", n)==0 || strncmp(zMethod, "push", n)==0 || strncmp(zMethod, "sync", n)==0 ) { int mask; const char *zServer; const char *zPw; int legacyFlag = 0; int overwriteFlag = 0; if( zMethod[0]!='s' ) legacyFlag = find_option("legacy",0,0)!=0; if( strncmp(zMethod,"pull",n)==0 ) { overwriteFlag = find_option("overwrite",0,0)!=0; } url_proxy_options(); if( g.argc!=4 && g.argc!=5 ) { usage("pull AREA ?URL?"); } mask = configure_name_to_mask(g.argv[3], 1); if( g.argc==5 ) { zServer = g.argv[4]; zPw = 0; g.dontKeepUrl = 1; } else { zServer = db_get("last-sync-url", 0); if( zServer==0 ) { vcs_fatal("no server specified"); } zPw = unobscure(db_get("last-sync-pw", 0)); } url_parse(zServer); if( g.urlPasswd==0 && zPw ) g.urlPasswd = mprintf("%s", zPw); user_select(); url_enable_proxy("via proxy: "); if( legacyFlag ) mask |= CONFIGSET_OLDFORMAT; if( overwriteFlag ) mask |= CONFIGSET_OVERWRITE; if( strncmp(zMethod, "push", n)==0 ) { client_sync(0,0,0,0,0,mask); } else if( strncmp(zMethod, "pull", n)==0 ) { client_sync(0,0,0,0,mask,0); } else { client_sync(0,0,0,0,mask,mask); } } else if( strncmp(zMethod, "reset", n)==0 ) { int mask, i; char *zBackup; if( g.argc!=4 ) usage("reset AREA"); mask = configure_name_to_mask(g.argv[3], 1); zBackup = db_text(0, "SELECT strftime('config-backup-%%Y%%m%%d%%H%%M%%f','now')"); db_begin_transaction(); export_config(mask, g.argv[3], 0, zBackup); for(i=0; i<count(aConfig); i++) { const char *zName = aConfig[i].zName; if( (aConfig[i].groupMask & mask)==0 ) continue; if( zName[0]!='@' ) { db_multi_exec("DELETE FROM config WHERE name=%Q", zName); } else if( vcs_strcmp(zName,"@user")==0 ) { db_multi_exec("DELETE FROM user"); db_create_default_users(0, 0); } else if( vcs_strcmp(zName,"@concealed")==0 ) { db_multi_exec("DELETE FROM concealed"); } else if( vcs_strcmp(zName,"@shun")==0 ) { db_multi_exec("DELETE FROM shun"); } else if( vcs_strcmp(zName,"@reportfmt")==0 ) { db_multi_exec("DELETE FROM reportfmt"); } } db_end_transaction(0); vcs_print("Configuration reset to factory defaults.\n"); vcs_print("To recover, use: %s %s import %s\n", vcs_nameofexe(), g.argv[1], zBackup); } else { vcs_fatal("METHOD should be one of:" " export import merge pull push reset"); } }