int main(int argc, char *argv[]) { char ch; int ret = EXIT_FAILURE; struct sc_config config; config.in_place = 0; config.file[FILE_DIC] = DEFAULT_DICTIONARY; while ((ch = getopt(argc, argv, "d:hi:o:pv")) != -1) { switch (ch) { case 'd': config.file[FILE_DIC] = optarg; break; case 'h': print_content(SC_FILE_HELP); return EXIT_SUCCESS; case 'i': config.file[FILE_DOC] = optarg; break; case 'o': if (config.in_place) { log_fatal("output file cannot be specified " "if in-place edit is asked for"); return EXIT_FAILURE; } config.file[FILE_OUT] = optarg; break; case 'p': if (config.file[FILE_OUT]) { log_fatal("document cannot be edited in place " "if output file is specified"); return EXIT_FAILURE; } config.in_place = 1; break; case 'v': print_content(SC_FILE_VERSION); return EXIT_SUCCESS; default: print_content(SC_FILE_HELP); return EXIT_FAILURE; } } if (check_config(&config, argc, argv)) { print_content(SC_FILE_HELP); goto ERROR; } if (spell_check(&config)) goto ERROR; print_content(SC_FILE_BANNER); ret = EXIT_SUCCESS; ERROR: if (config.file[FILE_OUT]) free(config.file[FILE_OUT]); return ret; }
void print_content(struct text_view_info *viewinfo, const char* content, int state){ GtkTextIter end; int i=0; if (strlen(content) == 0) return; while (1){ if (content[i] == '\0') { gtk_text_buffer_get_end_iter(viewinfo->view1_buffer,&end); gtk_text_buffer_insert(viewinfo->view1_buffer,&end,content,-1); break; } else if (content[i] == '/') { //打印处'/'前面的部分 if (i > 0){ char precontent[i+1]; int j=0; for (j=0;j<i;j++) precontent[j]=content[j]; precontent[j]='\0'; gtk_text_buffer_get_end_iter(viewinfo->view1_buffer,&end); gtk_text_buffer_insert(viewinfo->view1_buffer,&end,precontent,-1); } //如果是表情,插入缓冲区,否则将这段字符插入 if (content[i+1] != '\0' && content[i+2] != '\0'){ char tmp[4]; tmp[0]='/'; tmp[1]=content[i+1]; tmp[2]=content[i+2]; tmp[3]='\0'; print_sticker(viewinfo,tmp); //打印后面部分 print_content(viewinfo,&content[i+3],0); break; } else { gtk_text_buffer_get_end_iter(viewinfo->view1_buffer,&end); gtk_text_buffer_insert(viewinfo->view1_buffer,&end,"/",-1); print_content(viewinfo,&content[i+1],0); break; } } i++; } if (state == 1) { gtk_text_buffer_get_end_iter(viewinfo->view1_buffer,&end); gtk_text_buffer_insert(viewinfo->view1_buffer,&end,"\n",-1); } }
void print_files(char **paths, int flags) { t_stat attrib; t_file *file; t_padding paddings; t_btree *list; init_paddings(&paddings); list = NULL; while (*paths != NULL) { if (lstat(*paths, &attrib) != -1) { if (!S_ISDIR(attrib.st_mode) || flags & DIR_FILE) { file = get_file_infos(*paths, &paddings, flags); btree_add(&list, file, flags & TIME ? &timecmp : &namecmp); flags |= THERE_FILE; } else flags |= THERE_DIR; } paths++; } print_content(list, flags, paddings); if (flags & THERE_DIR && flags & THERE_FILE) ft_putchar('\n'); }
void print_msg(struct text_view_info *viewinfo, const char* info, const char* content){ GtkTextIter end; gtk_text_buffer_get_end_iter(viewinfo->view1_buffer,&end); gtk_text_buffer_insert_with_tags_by_name(viewinfo->view1_buffer,&end,info,-1,"blue_foreground",NULL); //gtk_text_buffer_insert(buffer,&end,content,-1); print_content(viewinfo,content,1); scroll_to_the_end(viewinfo); }
/** * Prints the content of every given file as a parameter. * @param argc Number of arguments recieved * @param argv Array of arguments recieved */ void main(int argc, char *argv[]) { if(argc < 2) Usage(); signal(SIGALRM, kill_all); alarm(10); int i; for(i = 1; i < argc; ++i) print_content(argv[i]); }
void DAG_graph::build(){ std::vector<Quaternion *>::iterator iter = codes.begin(); /* Skip block which contains items below. */ while(iter!= codes.end()){ Quaternion::op opcode = (*iter)->opcode; if( opcode==Quaternion::ARR_LOAD|| opcode==Quaternion::PUSH|| opcode==Quaternion::PUSH_VAR|| opcode == Quaternion::CALL || opcode==Quaternion::READ|| opcode==Quaternion::WRITE) return ; iter++; } /* Set head and tail code. */ iter = codes.begin(); while(iter != codes.end()){ if(iter == codes.begin()&& ((*iter)->opcode == Quaternion::PROC|| (*iter)->opcode== Quaternion::LABEL)){ head = *iter; }else if(iter+1 == codes.end()&& ((*iter)->opcode == Quaternion::END|| ((*iter)->opcode >= Quaternion::JE && (*iter)->opcode <=Quaternion::JMP))){ tail = *iter; }else{ add_node(*iter); } iter++; } // Now i did this when set node map. // /* Add items to node and set value to each nodes. */ // std::map<Symbol_item * ,DAG_node *>::iterator m_iter = node_map.begin(); // while(m_iter!= node_map.end()){ // Symbol_item * item= m_iter->first; // DAG_node * node = m_iter->second; // node->items.push_back(item); // /* Maybe useless. */ // if (node->item == NULL) node->item = item; // m_iter++; // } print_content(std::cout); regenerate(); }
/** * Main function of testing environment */ int main(void) { KCLinkedList list; int retval, i, buffer3; char *buffer1, buffer2[BUFFER_LENGTH]; buffer1 = BUFFER_1; memcpy(buffer2, BUFFER_2, strlen(BUFFER_2)); buffer2[strlen(BUFFER_2)] = '\0'; buffer3 = BUFFER_3; list = kc_linked_list_new(); for (i = 0; i < 3; i++) { kc_linked_list_add(list, buffer1); kc_linked_list_add(list, buffer2); kc_linked_list_add(list, &buffer3); } print_content(list, TRUE); buffer1 = BUFFER_2; memcpy(buffer2, BUFFER_1, strlen(BUFFER_1)); buffer2[strlen(BUFFER_1)] = '\0'; buffer3 = 5678; print_content(list, TRUE); retval = 0; while (retval >= 0) { retval = kc_linked_list_remove(list, &buffer3); if (retval >= 0) { printf("Removed \"%d\" on position %d\n", buffer3, retval); } } print_content(list, FALSE); kc_linked_list_free(list); return (EXIT_SUCCESS); }
static void curses_draw(void) { if (NULL == get_current_node()) { first_node(); first_intf(); } row = 0; move(0,0); getmaxyx(stdscr, rows, cols); if (cols < 80) { clear(); putl("Screen must be at least 80 columns wide"); refresh(); return; } if (c_use_colors) attrset(COLOR_PAIR(LAYOUT_STATUSBAR) | layout[LAYOUT_STATUSBAR].attr); else attrset(A_REVERSE); if (get_current_node() && get_current_intf()) { putl(" interface: %s at %s", get_current_intf()->i_name, get_current_node()->n_name); } move(row, COLS - strlen(PACKAGE_STRING) - 1); putl("%s", PACKAGE_STRING); move(row, 0); if (c_use_colors) attrset(COLOR_PAIR(LAYOUT_DEFAULT) | layout[LAYOUT_DEFAULT].attr); else attroff(A_REVERSE); print_content(); if (quit_mode) print_quit(); else if (print_help) draw_help(); for (; row < rows-2;) { move(++row, 0); putl(""); } row = rows-1; move(row, 0); if (c_use_colors) attrset(COLOR_PAIR(LAYOUT_STATUSBAR) | layout[LAYOUT_STATUSBAR].attr); else attrset(A_REVERSE); putl(" ^ prev interface, v next interface, <- prev node, -> next node, ? help"); attrset(0); refresh(); }
int main() { print_header(); print_content(); }
/*-------------------------------------------------------------------*/ int main(int argc, char **argv) { unsigned int pkt_counter = 1; /* packet counter */ /* unsigned long byte_counter=0; */ /* total bytes seen in entire trace */ /* unsigned long cur_counter=0; */ /* counter for current 1-second interval */ /* unsigned long current_ts=0; */ /* current timestamp */ struct tcphdr *mytcp; struct udphdr *myudp; int fnum; /* temporary packet buffers */ struct pcap_pkthdr header; /* The header that pcap gives us */ const u_char *packet; /* The actual packet */ /* check command line arguments */ if (argc < 2) { fprintf(stderr, "Usage: %s [input pcaps]\n", argv[0]); exit(EXIT_FAILURE); } /* -------- Begin Main Packet Processing Loop ------------------- */ /* loop through each pcap file in command line args */ for (fnum = 1; fnum < argc; fnum++) { /* ------------------ */ /* open the pcap file */ pcap_t *handle; char errbuf[PCAP_ERRBUF_SIZE]; /* not sure what to do with this, oh well */ handle = pcap_open_offline(argv[fnum], errbuf); /* call pcap library function */ if (handle == NULL) { fprintf(stderr, "Couldn't open pcap file %s: %s\n", argv[fnum], errbuf); return (2); } /* ----------------- */ /* begin processing the packets in this particular file, one at a time */ while ((packet = pcap_next(handle, &header)) != NULL) { /* header contains information about the packet (e.g. timestamp) */ u_char *pkt_ptr = (u_char *) packet; /* cast a pointer to the packet data */ /* parse the first (ethernet) header, grabbing the type field */ int ether_type = ((int)(pkt_ptr[12]) << 8) | (int)pkt_ptr[13]; int ether_offset = 0; if (ether_type == ETHER_TYPE_IP) /* most common */ ether_offset = 14; else if (ether_type == ETHER_TYPE_8021Q) /* dot1q tag ? */ ether_offset = 18; else fprintf(stderr, "Unknown ethernet type, %04X, skipping...\n", ether_type); /* parse the IP header */ pkt_ptr += ether_offset; /* skip past the Ethernet II header */ struct ip *ip_hdr = (struct ip *)pkt_ptr; /* point to an IP header structure */ int packet_length = ntohs(ip_hdr->ip_len); if (ip_hdr->ip_p == IPPROTO_UDP) { myudp = (struct udphdr *)(pkt_ptr + sizeof(struct ip)); int size_payload = packet_length - (sizeof(struct iphdr) + sizeof(struct udphdr)); printf("%04d UDP %s -> ", pkt_counter, inet_ntoa(ip_hdr->ip_src)); printf("%s port %d -> %d", inet_ntoa(ip_hdr->ip_dst), ntohs(myudp->uh_sport), ntohs(myudp->uh_dport)); printf(" packet_length %d\n", size_payload); print_content((unsigned char *)pkt_ptr + sizeof(struct iphdr) + sizeof(struct udphdr), size_payload); printf("\n"); } if (ip_hdr->ip_p == IPPROTO_TCP) { mytcp = (struct tcphdr *)(pkt_ptr + sizeof(struct ip)); int tcp_offset = mytcp->th_off * 4; int size_payload = packet_length - (sizeof(struct iphdr) + tcp_offset); if (size_payload > 0) { printf("%04d TCP %s -> ", pkt_counter, inet_ntoa(ip_hdr->ip_src)); printf("%s port %d -> %d", inet_ntoa(ip_hdr->ip_dst), ntohs(mytcp->th_sport), ntohs(mytcp->th_dport)); unsigned char *dump = (unsigned char *)pkt_ptr + sizeof(struct iphdr) + tcp_offset; printf(" packet_length %d\n", size_payload); print_content(dump, size_payload); printf("\n"); } } /* check to see if the next second has started, for statistics purposes */ #if 0 if (current_ts == 0) { /* this takes care of the very first packet seen */ current_ts = header.ts.tv_sec; } else if (header.ts.tv_sec > current_ts) { printf("%ld KBps\n", cur_counter / 1000); cur_counter = 0; /* reset counters */ current_ts = header.ts.tv_sec; /* update time interval */ } cur_counter += packet_length; byte_counter += packet_length; /* byte counter update */ #endif pkt_counter++; /* increment number of packets seen */ } pcap_close(handle); /* close the pcap file */ } return 0; }
static void curses_draw(void) { if (NULL == get_current_node()) { first_node(); first_item(); } row = 0; move(0,0); getmaxyx(stdscr, rows, cols); if (cols < 80) { clear(); putl("Screen must be at least 80 columns wide"); refresh(); return; } if (c_use_colors) attrset(COLOR_PAIR(LAYOUT_STATUSBAR) | layout[LAYOUT_STATUSBAR].attr); else attrset(A_REVERSE); if (get_current_node() && get_current_item()) { putl(" %s on %s", get_current_item()->i_name, get_current_node()->n_name); } move(row, COLS - strlen(PACKAGE_STRING) - 1); putl("%s", PACKAGE_STRING); move(row, 0); if (c_use_colors) attrset(COLOR_PAIR(LAYOUT_DEFAULT) | layout[LAYOUT_DEFAULT].attr); else attroff(A_REVERSE); print_content(); if (quit_mode) print_quit(); else if (print_help) { if (help_page == 0) draw_help(); else draw_help_2(); } for (; row < rows-2;) { move(++row, 0); putl(""); } row = rows-1; move(row, 0); if (c_use_colors) attrset(COLOR_PAIR(LAYOUT_STATUSBAR) | layout[LAYOUT_STATUSBAR].attr); else attrset(A_REVERSE); if (1) { char s[27]; time_t t = time(0); double d; int h, m; asctime_r(localtime(&t), s); s[strlen(s) - 1] = '\0'; d = difftime(time(0), start_time); if (d / 3600) { h = (int) d / 3600; m = (int) d % 3600; m /= 60; } else { h = 0; m = (int) d / 60; } putl(" %s (%dh/%dm)", s, h, m); move(row, COLS - strlen("Press ? for help") - 1); putl("%s", "Press ? for help"); move(row, 0); } attrset(0); refresh(); }