static void RemoveBDFWindows(BDFFont *bdf) { int i; for ( i=0; i<bdf->glyphcnt; ++i ) if ( bdf->glyphs[i]!=NULL ) { BCDestroyAll(bdf->glyphs[i]); } if ( !no_windowing_ui ) { ff_progress_allow_events(); /* Just in case... */ ff_progress_allow_events(); } /* We can't free the bdf until all the windows have executed their destroy*/ /* routines (which they will when they get the destroy window event) */ /* because those routines depend on the bdf existing ... */ }
int main( int argc, char **argv ) { extern const char *source_modtime_str, *source_version_str; const char *load_prefs = getenv("FONTFORGE_LOADPREFS"); int i; extern int splash; int recover=1; GtkWidget *notices, *ffsplash; gchar *home_dir, *rc_path; struct argcontext args; #ifdef FONTFORGE_CONFIG_TYPE3 fprintf( stderr, "Copyright (c) 2000-2012 by George Williams.\n Executable based on sources from %s-ML.\n", source_modtime_str ); #else fprintf( stderr, "Copyright (c) 2000-2012 by George Williams.\n Executable based on sources from %s.\n", source_modtime_str ); #endif fprintf( stderr, " Library based on sources from %s.\n", library_version_configuration.library_source_modtime_string ); gtk_set_locale (); home_dir = (gchar*) g_get_home_dir(); rc_path = g_strdup_printf("%s/.fontforgerc", home_dir); gtk_rc_add_default_file(rc_path); g_free(rc_path); gtk_init (&argc, &argv); #if defined(SHAREDIR) add_pixmap_directory( SHAREDIR "/pixmaps"); #elif defined(PREFIX) add_pixmap_directory( PREFIX "/share/fontforge/pixmaps" ); #else add_pixmap_directory( "./pixmaps" ); #endif bind_textdomain_codeset("FontForge","UTF-8"); bindtextdomain("FontForge", getLocaleDir()); textdomain("FontForge"); #if defined(__Mac) /* Start X if they haven't already done so. Well... try anyway */ /* Must be before we change DYLD_LIBRARY_PATH or X won't start */ if ( uses_local_x(argc,argv) && getenv("DISPLAY")==NULL ) { system( "open /Applications/Utilities/X11.app/" ); setenv("DISPLAY",":0.0",0); } #endif FF_SetUiInterface(>k_ui_interface); FF_SetPrefsInterface(>k_prefs_interface); /*FF_SetSCInterface(>k_sc_interface);*/ /*FF_SetCVInterface(>k_cv_interface);*/ /*FF_SetBCInterface(>k_bc_interface);*/ FF_SetFVInterface(>k_fv_interface); /*FF_SetFIInterface(>k_fi_interface);*/ /*FF_SetMVInterface(>k_mv_interface);*/ /*FF_SetClipInterface(>k_clip_interface);*/ #ifndef _NO_PYTHON PythonUI_Init(); #endif InitSimpleStuff(); if ( load_prefs!=NULL && strcasecmp(load_prefs,"Always")==0 ) LoadPrefs(); if ( default_encoding==NULL ) default_encoding=FindOrMakeEncoding("ISO8859-1"); if ( default_encoding==NULL ) default_encoding=&custom; /* In case iconv is broken */ CheckIsScript(argc,argv); /* Will run the script and exit if it is a script */ /* If there is no UI, there is always a script */ /* and we will never return from the above */ if ( load_prefs==NULL || (strcasecmp(load_prefs,"Always")!=0 && /* Already loaded */ strcasecmp(load_prefs,"Never")!=0 )) LoadPrefs(); for ( i=1; i<argc; ++i ) { char *pt = argv[i]; if ( pt[0]=='-' && pt[1]=='-' ) ++pt; if ( strcmp(pt,"-nosplash")==0 ) splash = 0; else if ( strcmp(pt,"-recover")==0 && i<argc-1 ) { ++i; if ( strcmp(argv[i],"none")==0 ) recover=0; else if ( strcmp(argv[i],"clean")==0 ) recover= -1; else if ( strcmp(argv[i],"auto")==0 ) recover= 1; else if ( strcmp(argv[i],"inquire")==0 ) recover= 2; else { fprintf( stderr, "Invalid argument to -recover, must be none, auto, inquire or clean\n" ); dousage(); } } else if ( strcmp(pt,"-recover=none")==0 ) { recover = 0; } else if ( strcmp(pt,"-recover=clean")==0 ) { recover = -1; } else if ( strcmp(pt,"-recover=auto")==0 ) { recover = 1; } else if ( strcmp(pt,"-recover=inquire")==0 ) { recover = 2; } else if ( strcmp(pt,"-help")==0 ) dohelp(); else if ( strcmp(pt,"-usage")==0 ) dousage(); else if ( strcmp(pt,"-version")==0 ) doversion(source_version_str); else if ( strcmp(pt,"-library-status")==0 ) dolibrary(); } InitCursors(); #ifndef _NO_PYTHON PyFF_ProcessInitFiles(); #endif if ( splash ) { splashw = create_FontForgeSplash (); splash_window_tooltip_fun( splashw ); notices = lookup_widget(splashw,"Notices"); if ( notices!=NULL ) gtk_widget_hide(notices); ffsplash = lookup_widget(splashw,"ffsplash2"); if ( ffsplash!=NULL ) gtk_widget_hide(ffsplash); ffsplash = lookup_widget(splashw,"ffsplash3"); if ( ffsplash!=NULL ) gtk_widget_hide(ffsplash); gtk_window_set_position(GTK_WINDOW(splashw),GTK_WIN_POS_CENTER_ALWAYS); gtk_widget_show (splashw); ff_progress_allow_events(); gtk_timeout_add(1000,Splash_Changes,splashw); } gtk_timeout_add(30*1000,__DoAutoSaves,NULL); /* Check for autosave every 30 seconds */ args.argc = argc; args.argv = argv; args.recover = recover; gtk_timeout_add(100,ParseArgs,&args); /* Parse arguments within the main loop */ gtk_main (); return( 0 ); }
static FILE *HttpURLToTempFile(const char *url, void *_lock) { pthread_mutex_t *lock = _lock; struct sockaddr_in addr; char *pt, *host, *filename, *username, *password; int port; FILE *ret; char buffer[300]; int first, code; int soc; int datalen, len; char *databuf; snprintf(buffer,sizeof(buffer),_("Downloading from %s"), url); if ( strncasecmp(url,"http://",7)!=0 ) { if ( lock!=NULL ) pthread_mutex_lock(lock); ff_post_error(_("Could not parse URL"),_("Got something else when expecting an http URL")); if ( lock!=NULL ) pthread_mutex_unlock(lock); return( NULL ); } if ( lock!=NULL ) pthread_mutex_lock(lock); filename = decomposeURL(url, &host, &port, &username, &password); /* I don't support username/passwords for http */ free( username ); free( password ); if ( lock!=NULL ) pthread_mutex_unlock(lock); if ( lock==NULL ) { ff_progress_start_indicator(0,_("Font Download..."),buffer, _("Resolving host"),1,1); ff_progress_enable_stop(false); ff_progress_allow_events(); ff_progress_allow_events(); } /* This routine contains it's own lock */ if ( !findHTTPhost(&addr, host, port)) { if ( lock==NULL ) ff_progress_end_indicator(); else pthread_mutex_lock(lock); ff_post_error(_("Could not find host"),_("Could not find \"%s\"\nAre you connected to the internet?"), host ); free( host ); free( filename ); if ( lock!=NULL ) pthread_mutex_unlock(lock); return( false ); } soc = makeConnection(&addr); if ( soc==-1 ) { if ( lock==NULL ) ff_progress_end_indicator(); else pthread_mutex_lock(lock); ff_post_error(_("Could not connect to host"),_("Could not connect to \"%s\"."), host ); free( host ); free( filename ); if ( lock!=NULL ) pthread_mutex_unlock(lock); return( false ); } if ( lock!=NULL ) pthread_mutex_lock(lock); datalen = 8*8*1024; databuf = malloc(datalen+1); if ( lock!=NULL ) pthread_mutex_unlock(lock); else ChangeLine2_8(_("Requesting font...")); sprintf( databuf,"GET %s HTTP/1.1\r\n" "Host: %s\r\n" "User-Agent: FontForge\r\n" "Connection: close\r\n\r\n", filename, host ); if ( write(soc,databuf,strlen(databuf))==-1 ) { if ( lock==NULL ) ff_progress_end_indicator(); if ( lock!=NULL ) pthread_mutex_lock(lock); ff_post_error(_("Could not send request"),_("Could not send request to \"%s\"."), host ); close( soc ); free( databuf ); free( host ); free( filename ); free( host ); free( filename ); if ( lock!=NULL ) pthread_mutex_unlock(lock); return( NULL ); } if ( lock==NULL ) ChangeLine2_8(_("Downloading font...")); if ( lock!=NULL ) pthread_mutex_lock(lock); ret = tmpfile(); if ( lock!=NULL ) pthread_mutex_unlock(lock); first = 1; code = 404; while ((len = read(soc,databuf,datalen))>0 ) { if ( first ) { databuf[len] = '\0'; sscanf(databuf,"HTTP/%*f %d", &code ); first = 0; /* check for redirects */ if ( code>=300 && code<399 && (pt=strstr(databuf,"Location: "))!=NULL ) { char *newurl = pt + strlen("Location: "); pt = strchr(newurl,'\r'); if ( *pt ) *pt = '\0'; close( soc ); if ( lock!=NULL ) pthread_mutex_lock(lock); fclose(ret); free(host); free( filename ); free(databuf); if ( lock!=NULL ) pthread_mutex_unlock(lock); ret = URLToTempFile(newurl,lock); return( ret ); } pt = strstr(databuf,"Content-Length: "); if ( lock==NULL && pt!=NULL ) { pt += strlen( "Content-Length: "); ff_progress_change_total(strtol(pt,NULL,10)); } pt = strstr(databuf,"\r\n\r\n"); if ( pt!=NULL ) { pt += strlen("\r\n\r\n"); fwrite(pt,1,len-(pt-databuf),ret); if ( lock==NULL ) ff_progress_increment(len-(pt-databuf)); } } else { fwrite(databuf,1,len,ret); if ( lock==NULL ) ff_progress_increment(len); } } if ( lock==NULL ) ff_progress_end_indicator(); close( soc ); free( databuf ); if ( lock!=NULL ) pthread_mutex_lock(lock); free( host ); free( filename ); if ( len==-1 ) { ff_post_error(_("Could not download data"),_("Could not download data.") ); fclose(ret); ret = NULL; } else if ( code<200 || code>299 ) { ff_post_error(_("Could not download data"),_("HTTP return code: %d."), code ); fclose(ret); ret = NULL; } else rewind(ret); if ( lock!=NULL ) pthread_mutex_unlock(lock); return( ret ); }
static int FtpURLAndTempFile(const char *url,FILE **to,FILE *from) { struct sockaddr_in addr, data_addr; char *host, *filename, *username, *password; int port; FILE *ret; char buffer[300]; int soc, data; int datalen, len; char *databuf, *cmd; if ( from==NULL ) { snprintf(buffer,sizeof(buffer),_("Downloading from %s"), url); *to = NULL; } else snprintf(buffer,sizeof(buffer),_("Uploading to %s"), url); if ( strncasecmp(url,"ftp://",6)!=0 ) { ff_post_error(_("Could not parse URL"),_("Got something else when expecting an ftp URL")); return( false ); } filename = decomposeURL(url, &host, &port, &username, &password); ff_progress_start_indicator(0,_("Font Download..."),buffer, _("Resolving host"),1,1); ff_progress_enable_stop(false); ff_progress_allow_events(); ff_progress_allow_events(); if ( !findFTPhost(&addr, host, port)) { ff_progress_end_indicator(); ff_post_error(_("Could not find host"),_("Could not find \"%s\"\nAre you connected to the internet?"), host ); free( host ); free( filename ); return( false ); } soc = makeConnection(&addr); if ( soc==-1 ) { ff_progress_end_indicator(); ff_post_error(_("Could not connect to host"),_("Could not connect to \"%s\"."), host ); free( host ); free( filename ); return( false ); } datalen = 8*8*1024; databuf = malloc(datalen+1); cmd = databuf; ChangeLine2_8(_("Logging in...")); if ( getresponse(soc,databuf,datalen) == -1 ) { /* ftp servers say "Hi" when then connect */ ff_progress_end_indicator(); ff_post_error(_("Could not connect to host"),_("Could not connect to \"%s\"."), host ); free( host ); free( filename ); free(username); free(password); close( soc ); return( false ); } free( host ); if ( username==NULL ) { username=copy("anonymous"); if ( password==NULL ) password=copy("FontForge"); } else if ( password==NULL ) password = copy(""); sprintf(cmd,"USER %s\r\n", username); if ( ftpsendr(soc,cmd,databuf,datalen)== -1 ) { ff_progress_end_indicator(); close( soc ); free(filename); free(databuf); free(username); free(password); return( false ); } sprintf(cmd,"PASS %s\r\n", password); free(username); free(password); if ( ftpsendr(soc,cmd,databuf,datalen)<=0 ) { ff_progress_end_indicator(); LogError(_("Bad Username/Password\n")); close( soc ); free(filename); free(databuf); return( false ); } if ( ftpsendr(soc,"TYPE I\r\n",databuf,datalen)==-1 ) { /* Binary */ ff_progress_end_indicator(); close( soc ); free(filename); free(databuf); return( false ); } if ( from==NULL ) ChangeLine2_8(_("Requesting font...")); else ChangeLine2_8(_("Transmitting font...")); if ( ftpsendpassive(soc,&data_addr,databuf,datalen)<= 0 ) { ff_progress_end_indicator(); close( soc ); free(filename); free(databuf); return( false ); } if (( data = socket(PF_INET,SOCK_STREAM,0))==-1 || connect(data,(struct sockaddr *) &data_addr,sizeof(data_addr))== -1 ) { ff_progress_end_indicator(); if ( data!=-1 ) close(data); close( soc ); free(filename); free(databuf); LogError(_("FTP passive Data Connect failed\n")); return( 0 ); } if ( from==NULL ) { sprintf(cmd,"RETR %s\r\n", filename); if ( ftpsendr(soc,cmd, databuf, datalen)<=0 ) { ff_progress_end_indicator(); ff_post_error(_("Could not download data"),_("Could not find file.") ); close(data); close( soc ); free(filename); free(databuf); return( false ); } ChangeLine2_8(_("Downloading font...")); ret = tmpfile(); while ((len = read(data,databuf,datalen))>0 ) { fwrite(databuf,1,len,ret); } *to = ret; rewind(ret); } else { sprintf(cmd,"STOR %s\r\n", filename); if ( ftpsendr(soc,cmd, databuf, datalen)<=0 ) { ff_progress_end_indicator(); ff_post_error(_("Could not download data"),_("Could not find file.") ); close(data); close( soc ); free(filename); free(databuf); return( false ); } ChangeLine2_8(_("Uploading font...")); rewind(from); while ((len = fread(databuf,1,datalen,from))>0 ) { if ( (len = write(data,databuf,len))<0 ) break; } ret = NULL; } ff_progress_end_indicator(); close( soc ); close( data ); free( databuf ); free( filename ); if ( len==-1 ) { ff_post_error(_("Could not transmit data"),_("Could not transmit data.") ); if ( ret!=NULL ) fclose(ret); return( false ); } return( true ); }
static void ChangeLine2_8(char *str) { ff_progress_change_line2(str); ff_progress_allow_events(); }