void weechat_end (void (*gui_end_cb)(int clean_exit)) { gui_layout_store_on_exit (); /* store layout */ plugin_end (); /* end plugin interface(s) */ if (CONFIG_BOOLEAN(config_look_save_config_on_exit)) (void) config_weechat_write (); /* save WeeChat config file */ (void) secure_write (); /* save secured data */ if (gui_end_cb) (*gui_end_cb) (1); /* shut down WeeChat GUI */ proxy_free_all (); /* free all proxies */ config_weechat_free (); /* free WeeChat options */ secure_free (); /* free secured data options */ config_file_free_all (); /* free all configuration files */ gui_key_end (); /* remove all keys */ unhook_all (); /* remove all hooks */ hdata_end (); /* end hdata */ secure_end (); /* end secured data */ string_end (); /* end string */ weechat_shutdown (-1, 0); /* end other things */ }
int main(int argc, char* argv[]) { string_t* pstr_hello = create_string(); string_t* pstr_s = create_string(); string_iterator_t it_pos; if(pstr_hello == NULL || pstr_s == NULL) { return -1; } string_init_cstr(pstr_hello, "Hello, how are you?"); string_init_copy_range(pstr_s, string_begin(pstr_hello), string_end(pstr_hello)); for(it_pos = string_begin(pstr_s); !iterator_equal(it_pos, string_end(pstr_s)); it_pos = iterator_next(it_pos)) { printf("%c", *(char*)iterator_get_pointer(it_pos)); } printf("\n"); algo_reverse(string_begin(pstr_s), string_end(pstr_s)); printf("reverse: %s\n", string_c_str(pstr_s)); algo_sort(string_begin(pstr_s), string_end(pstr_s)); printf("ordered: %s\n", string_c_str(pstr_s)); string_erase_range(pstr_s, algo_unique(string_begin(pstr_s), string_end(pstr_s)), string_end(pstr_s)); printf("uniqued: %s\n", string_c_str(pstr_s)); string_destroy(pstr_hello); string_destroy(pstr_s); return 0; }
/** * Erase an element in a basic string from a specificed position. */ string_iterator_t string_erase(string_t* pstr_string, string_iterator_t it_pos) { assert(!iterator_equal(it_pos, string_end(pstr_string))); return basic_string_erase(pstr_string, it_pos); }
int main (int argc, char *argv[]) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); setlocale (LC_ALL, ""); /* initialize gettext */ #ifdef ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif #ifdef HAVE_LANGINFO_CODESET weechat_local_charset = strdup (nl_langinfo (CODESET)); #else weechat_local_charset = strdup (""); #endif utf8_init (); util_catch_signal (SIGINT, SIG_IGN); /* ignore SIGINT signal */ util_catch_signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal */ util_catch_signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump for SIGSEGV signal */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_main_pre_init (&argc, &argv); /* pre-initialize interface */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ weechat_shutdown (EXIT_FAILURE, 0); weechat_parse_args (argc, argv); /* parse command line args */ weechat_create_home_dir (); /* create WeeChat home directory */ log_init (); /* init log file */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ gui_main_init (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_welcome_message (); /* display WeeChat welcome message */ gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_auto_load_plugins, /* init plugin interface(s) */ argc, argv); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ gui_main_loop (); /* WeeChat main loop */ gui_layout_store_on_exit (); /* store layout */ plugin_end (); /* end plugin interface(s) */ if (CONFIG_BOOLEAN(config_look_save_config_on_exit)) (void) config_weechat_write (); /* save WeeChat config file */ (void) secure_write (); /* save secured data */ gui_main_end (1); /* shut down WeeChat GUI */ proxy_free_all (); /* free all proxies */ config_weechat_free (); /* free WeeChat options */ secure_free (); /* free secured data options */ config_file_free_all (); /* free all configuration files */ gui_key_end (); /* remove all keys */ unhook_all (); /* remove all hooks */ hdata_end (); /* end hdata */ secure_end (); /* end secured data */ string_end (); /* end string */ weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */ return EXIT_SUCCESS; /* make C compiler happy */ }
static void phase3_get (token_ty *tp) { int c; int c2; int c_start; if (phase3_pushback_length) { *tp = phase3_pushback[--phase3_pushback_length]; return; } tp->string = NULL; for (;;) { tp->line_number = line_number; c = phase2_getc (); switch (c) { case EOF: tp->type = token_type_eof; return; case '\n': if (last_non_comment_line > last_comment_line) savable_comment_reset (); /* Intentionally not breaking. */ case ' ': case '\t': case '\f': continue; case '+': case '-': case '*': case '/': case '^': case '%': case '#': tp->type = token_type_operator1; return; case '<': case '>': case '=': c2 = phase1_getc (); if (c2 != '=') phase1_ungetc (c2); tp->type = token_type_operator2; return; case '~': c2 = phase1_getc (); if (c2 == '=') { tp->type = token_type_operator2; return; } else phase1_ungetc (c2); continue; case '(': tp->type = token_type_lparen; return; case ')': tp->type = token_type_rparen; return; case ',': tp->type = token_type_comma; return; case ';': tp->type = token_type_other; return; /* There are three operators beginning with a dot. '.', '..' and '...'. The most useful for us is the string concatenation operator ('..'). */ case '.': c = phase1_getc (); if (c == '.') { c = phase1_getc (); if (c == '.') { tp->type = token_type_other; return; } else { phase1_ungetc (c); tp->type = token_type_doubledot; return; } } else if (c >= '0' && c <= '9') { /* It's a number. We aren't interested in the actual numeric value, so ignore the dot and let next iteration eat the number. */ phase1_ungetc (c); continue; } else { phase1_ungetc (c); tp->type = token_type_dot; return; } case '"': case '\'': c_start = c; string_start (); for (;;) { /* We need unprocessed characters from phase 1. */ c = phase1_getc (); /* We got '\', this is probably an escape sequence. */ if (c == '\\') { c = phase1_getc (); switch (c) { case 'a': string_add ('\a'); break; case 'b': string_add ('\b'); break; case 'f': string_add ('\f'); break; case 'n': string_add ('\n'); break; case 'r': string_add ('\r'); break; case 't': string_add ('\t'); break; case 'v': string_add ('\v'); break; case 'x': { int num = 0; int i = 0; for (i = 0; i < 2; i++) { c = phase1_getc (); if (c >= '0' && c <= '9') num += c - '0'; else if (c >= 'a' && c <= 'f') num += c - 'a' + 10; else if (c >= 'A' && c <= 'F') num += c - 'A' + 10; else { phase1_ungetc (c); break; } if (i == 0) num *= 16; } if (i == 2) string_add (num); } break; case 'z': /* Ignore the following whitespace. */ do { c = phase1_getc (); } while (c == ' ' || c == '\n' || c == '\t' || c == '\r' || c == '\f' || c == '\v'); phase1_ungetc (c); break; default: /* Check if it's a '\ddd' sequence. */ if (c >= '0' && c <= '9') { int num = 0; int i = 0; while (c >= '0' && c <= '9' && i < 3) { num *= 10; num += (c - '0'); c = phase1_getc (); i++; } /* The last read character is either a non-number or another number after our '\ddd' sequence. We need to ungetc it. */ phase1_ungetc (c); /* The sequence number is too big, this causes a lexical error. Ignore it. */ if (num < 256) string_add (num); } else string_add (c); } } else if (c == c_start || c == EOF || c == '\n') { /* End of string. */ string_end (); tp->string = xstrdup (string_buf); tp->comment = add_reference (savable_comment); tp->type = token_type_string; return; } else string_add (c); } break; case '[': c = phase1_getc (); /* Count the number of equal signs. */ int esigns = 0; while (c == '=') { esigns++; c = phase1_getc (); } if (c != '[') { /* We did not find what we were looking for, ungetc it. */ phase1_ungetc (c); if (esigns == 0) { /* Our current character isn't '[' and we got 0 equal signs, so the first '[' must have been a left bracket. */ tp->type = token_type_lbracket; return; } else /* Lexical error, ignore it. */ continue; } string_start (); for (;;) { c = phase1_getc (); if (c == ']') { c = phase1_getc (); /* Count the number of equal signs. */ int esigns2 = 0; while (c == '=') { esigns2++; c = phase1_getc (); } if (c == ']' && esigns == esigns2) { /* We got ']==...==]', where the number of equal signs matches the number of equal signs in the opening bracket. */ string_end (); tp->string = xstrdup (string_buf); tp->comment = add_reference (savable_comment); tp->type = token_type_string; return; } else { /* Otherwise we got either ']==' garbage or ']==...==]' with a different number of equal signs. Add ']' and equal signs to the string, and ungetc the current character, because the second ']' might be a part of another closing long bracket, e.g. '==]===]'. */ phase1_ungetc (c); string_add (']'); while (esigns2--) string_add ('='); } } else { if (c == EOF) { string_end (); tp->string = xstrdup (string_buf); tp->comment = add_reference (savable_comment); tp->type = token_type_string; return; } else string_add (c); } } break; case ']': tp->type = token_type_rbracket; return; default: if (c >= '0' && c <= '9') { while (c >= '0' && c <= '9') c = phase1_getc (); if (c == '.') { c = phase1_getc (); while (c >= '0' && c <= '9') c = phase1_getc (); } if (c == 'e' || c == 'E') { if (c == '+' || c == '-') c = phase1_getc (); while (c >= '0' && c <= '9') c = phase1_getc (); } phase1_ungetc (c); tp->type = token_type_number; return; } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_') { string_start (); while ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9')) { string_add (c); c = phase1_getc (); } string_end (); phase1_ungetc (c); if (strcmp (string_buf, "not") == 0) tp->type = token_type_operator1; else if (strcmp (string_buf, "and") == 0) tp->type = token_type_operator2; else if (strcmp (string_buf, "or") == 0) tp->type = token_type_operator2; else { tp->string = xstrdup (string_buf); tp->type = token_type_symbol; } return; } else tp->type = token_type_other; } } }