/* * The main function parse the config file. * * @param context The main context pointer * @param simple_parse Simple parse flag */ void process_config_file(build_image_context *context, u_int8_t simple_parse) { char buffer[MAX_BUFFER]; int space = 0; char current; u_int8_t c_eol_comment_start = 0; /* True after first slash */ u_int8_t comment = 0; u_int8_t string = 0; u_int8_t equal_encounter = 0; assert(context != NULL); assert(context->config_file != NULL); while ((current = fgetc(context->config_file)) != EOF) { if (space >= (MAX_BUFFER-1)) { /* if we exceeded the max buffer size, it is likely due to a missing semi-colon at the end of a line */ printf("Config file parsing error!"); exit(1); } /* Handle failure to complete "//" comment token. Insert the '/' into the busffer and proceed with processing the current character. */ if (c_eol_comment_start && current != '/') { c_eol_comment_start = 0; buffer[space++] = '/'; } switch (current) { case '\"': /* " indicates start or end of a string */ if (!comment) { string ^= 1; buffer[space++] = current; } break; case ';': if (!string && !comment) { buffer[space++] = '\0'; if (process_statement(context, buffer, simple_parse)) goto error; space = 0; equal_encounter = 0; } else if (string) buffer[space++] = current; break; case '/': if (!string && !comment) { if (c_eol_comment_start) { /* EOL comment started. */ comment = 1; c_eol_comment_start = 0; } else { /* Potential start of eol comment. */ c_eol_comment_start = 1; } } else if (!comment) buffer[space++] = current; break; /* ignore whitespace. uses fallthrough */ case '\n': case '\r': /* carriage returns end comments */ string = 0; comment = 0; c_eol_comment_start = 0; case ' ': case '\t': if (string) buffer[space++] = current; break; case '#': if (!string) comment = 1; else buffer[space++] = current; break; default: if (!comment) { buffer[space++] = current; if (current == '=') { if (!equal_encounter) equal_encounter = 1; else goto error; } } break; } } return; error: printf("Error parsing: %s\n", buffer); exit(1); }
int main( int argc, char *argv[] ) /********************************/ { char fname[ PATH_MAX ]; FILE *fi; FILE *fo; char *p; int i; char *line; char *buff1; char *buff2; char *separators = " \t"; i = process_cmdl( argc, argv ); if( i == 0 ) { disp_usage(); return( -1 ); } strcpy( fname, argv[ i ] ); if( strrchr( fname, '.' ) == NULL ) strcat( fname, ".dlg" ); fi = fopen( fname, "r" ); if( fi == NULL ) { printf( "Could not open input file: %s\n", fname ); return( -1 ); } if( i + 1 < argc ) { strcpy( fname, argv[ i + 1 ] ); if( strrchr( fname, '.' ) == NULL ) { strcat( fname, ".dlg" ); } } else { strcpy( fname, "os2dlg.dlg" ); } fo = fopen( fname, "w" ); if( fo == NULL ) { printf( "Could not open input file: %s\n", fname ); return( -1 ); } alloc_statement( &dlg_hdr ); alloc_statement( &dlg_item ); line = malloc( MAX_LINE_LEN ); buff1 = malloc( MAX_LINE_LEN ); buff2 = malloc( MAX_LINE_LEN ); my_fgets( line, MAX_LINE_LEN, fi ); while( !feof( fi ) ) { while( !feof( fi ) ) { if( strstr( line, "DLGINCLUDE" ) != NULL ) { /********************** * source file format: * * DLGINCLUDE * BEGIN * filename * END * * converted to: * * DLGINCLUDE 1 filename */ p = malloc( MAX_LINE_LEN ); strcpy( p, line ); fprintf( fo, "%s 1 ", strtok( p, separators ) ); my_fgets( line, MAX_LINE_LEN, fi ); my_fgets( line, MAX_LINE_LEN, fi ); strcpy( p, line ); fprintf( fo, "%s\n", strtok( p, separators ) ); free( p ); my_fgets( line, MAX_LINE_LEN, fi ); my_fgets( line, MAX_LINE_LEN, fi ); } else if( strstr( line, "DIALOG" ) != NULL ) { p = malloc( MAX_LINE_LEN ); strcpy( p, line ); process_dialog_declaration( fi, fo, p ); strcpy( line, p ); free( p ); } else if( strstr( line, "BEGIN" ) != NULL ) { my_fgets( line, MAX_LINE_LEN, fi ); break; } else { #if !defined( OLD_FORMAT ) if( *line != '\0' ) #endif fprintf( fo, "%s\n", line ); my_fgets( line, MAX_LINE_LEN, fi ); } } p = ""; while( !feof( fi ) && strcmp( p, "END" ) ) { while( my_fgets( buff1, MAX_LINE_LEN, fi ) != NULL ) { if( check_statement( buff1 ) ) break; strncat( line, skip_separator( buff1 ), MAX_LINE_LEN ); } process_statement( line, fo ); strcpy( line, buff1 ); strcpy( buff2, buff1 ); p = strtok( buff2, separators ); } if( !feof( fi ) ) { fprintf( fo, "%sEND\n", STR_SPC ); } } free( buff2 ); free( buff1 ); free( line ); free_statement( &dlg_item ); free_statement( &dlg_hdr ); if( fi != NULL ) fclose( fi ); if( fo != NULL ) { #if defined( OLD_FORMAT ) fprintf( fo, "\n" ); #endif fclose( fo ); } if( !opt.quiet ) fprintf( stdout, "\nParsed %d dialogs.\n", dialogs_cnt ); if( opt.flist_data ) { for( i = 0; i < opt.flist_cnt; i++ ) free( opt.flist_data[ i ] ); free( opt.flist_data ); } return( 0 ); }
int main (int argc, char *argv[]) { int opt_err; MY_INIT (argv[0]); load_defaults ("my", client_groups, &argc, &argv); if ((opt_err = handle_options (&argc, &argv, my_opts, get_one_option))) exit (opt_err); /* solicit password if necessary */ if (ask_password) opt_password = get_tty_password (NULL); /* get database name if present on command line */ if (argc > 0) { opt_db_name = argv[0]; --argc; ++argv; } /* initialize client library */ if (mysql_library_init (0, NULL, NULL)) { print_error (NULL, "mysql_library_init() failed"); exit (1); } /* initialize connection handler */ conn = mysql_init (NULL); if (conn == NULL) { print_error (NULL, "mysql_init() failed (probably out of memory)"); exit (1); } if (opt_protocol) mysql_options (conn, MYSQL_OPT_PROTOCOL, (char*)&opt_protocol); #ifdef HAVE_SMEM if (opt_shared_memory_base_name) mysql_options (conn, MYSQL_SHARED_MEMORY_BASE_NAME, opt_shared_memory_base_name); #endif /* connect to server */ if (mysql_real_connect (conn, opt_host_name, opt_user_name, opt_password, opt_db_name, opt_port_num, opt_socket_name, opt_flags) == NULL) { print_error (conn, "mysql_real_connect() failed"); mysql_close (conn); exit (1); } while (1) { char buf[10000]; fprintf (stderr, "query> "); /* print prompt */ if (fgets (buf, sizeof (buf), stdin) == NULL) /* read statement */ break; if (strcmp (buf, "quit\n") == 0 || strcmp (buf, "\\q\n") == 0) break; process_statement (conn, buf); /* execute it */ } /* disconnect from server, terminate client library */ mysql_close (conn); mysql_library_end (); exit (0); }
int main (int argc, char *argv[]) { int opt_err; MY_INIT (argv[0]); load_defaults ("my", client_groups, &argc, &argv); if ((opt_err = handle_options (&argc, &argv, my_opts, get_one_option))) exit (opt_err); /* solicit password if necessary */ if (ask_password) opt_password = get_tty_password (NULL); /* get database name if present on command line */ if (argc > 0) { opt_db_name = argv[0]; --argc; ++argv; } /* initialize client library */ if (mysql_library_init (0, NULL, NULL)) { print_error (NULL, "mysql_library_init() failed"); exit (1); } /* #@ _SET_UP_SSL_ */ /* initialize connection handler */ conn = mysql_init (NULL); if (conn == NULL) { print_error (NULL, "mysql_init() failed (probably out of memory)"); exit (1); } #ifdef HAVE_OPENSSL /* pass SSL information to client library */ if (opt_use_ssl) mysql_ssl_set (conn, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, opt_ssl_cipher); mysql_options (conn,MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (char*)&opt_ssl_verify_server_cert); #endif /* connect to server */ if (mysql_real_connect (conn, opt_host_name, opt_user_name, opt_password, opt_db_name, opt_port_num, opt_socket_name, opt_flags) == NULL) { print_error (conn, "mysql_real_connect() failed"); mysql_close (conn); exit (1); } /* #@ _SET_UP_SSL_ */ printf ("Testing connection...\n"); process_statement (conn, "SHOW STATUS LIKE 'Ssl_cipher'"); printf ("If Ssl_cipher is non-blank, the connection is secure.\n"); while (1) { char buf[10000]; fprintf (stderr, "query> "); /* print prompt */ if (fgets (buf, sizeof (buf), stdin) == NULL) /* read statement */ break; if (strcmp (buf, "quit\n") == 0 || strcmp (buf, "\\q\n") == 0) break; process_statement (conn, buf); /* execute it */ } /* disconnect from server, terminate client library */ mysql_close (conn); mysql_library_end (); exit (0); }