/* Perform end of run tasks and prepare to exit gracefully */ void cleanup() { /* This may have already been called, but might not have depending on how we got here */ if (pcap_hnd) pcap_breakloop(pcap_hnd); fflush(NULL); free_format(); free_methods(); if (buf) free(buf); /* Note that this won't get removed if we've switched to a user that doesn't have permission to delete the file */ if (daemon_mode) remove(PID_FILE); if (pcap_hnd) pcap_close(pcap_hnd); return; }
static GList * unregister_format (GList *formats, GdkAtom atom) { GList *list; for (list = formats; list; list = g_list_next (list)) { GtkRichTextFormat *format = list->data; if (format->atom == atom) { free_format (format); return g_list_delete_link (formats, list); } } return formats; }
/* * The final format - create the format-list * (that list it will be used later by fmt_printN and fmt_printS) * * '_' the next character is not belongs to format (simple string) */ void build_format(const char *fmt_cnst) { char *fmt; char *p; int nc; #if defined(OS_LIMITED) char buf[128], *b; #else char buf[1024], *b; #endif free_format(); // backup of format fmt = tmp_alloc(strlen(fmt_cnst) + 1); strcpy(fmt, fmt_cnst); p = fmt; b = buf; nc = 0; while (*p) { switch (*p) { case '_': // store prev. buf *b = '\0'; if (strlen(buf)) { fmt_addfmt(buf, 0); } // store the new buf[0] = *(p + 1); buf[1] = '\0'; fmt_addfmt(buf, 0); b = buf; p++; break; case '-': case '+': case '^': case '0': case '#': // store prev. buf *b = '\0'; if (strlen(buf)) { fmt_addfmt(buf, 0); } // get num-fmt p = fmt_getnumfmt(buf, p); fmt_addfmt(buf, 1); b = buf; nc = 1; break; case '&': case '!': case '\\': // store prev. buf *b = '\0'; if (strlen(buf)) { fmt_addfmt(buf, 0); } // get str-fmt p = fmt_getstrfmt(buf, p); fmt_addfmt(buf, 2); b = buf; nc = 1; break; default: *b++ = *p; } if (*p) { if (nc) { // do not advance nc = 0; } else { p++; } } } // store prev. buf *b = '\0'; if (strlen(buf)) { fmt_addfmt(buf, 0); } // cleanup tmp_free(fmt); }