static int log_results(struct loopback_test *t) { int fd, i, len, ret; struct tm tm; time_t local_time; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; char file_name[MAX_SYSFS_PATH]; char data[CSV_MAX_LINE]; local_time = time(NULL); tm = *localtime(&local_time); /* * file name will test_name_size_iteration_max.csv * every time the same test with the same parameters is run we will then * append to the same CSV with datestamp - representing each test * dataset. */ if (t->file_output && !t->porcelain) { snprintf(file_name, sizeof(file_name), "%s_%d_%d.csv", t->test_name, t->size, t->iteration_max); fd = open(file_name, O_WRONLY | O_CREAT | O_APPEND, mode); if (fd < 0) { fprintf(stderr, "unable to open %s for appendation\n", file_name); abort(); } } for (i = 0; i < t->device_count; i++) { if (!device_enabled(t, i)) continue; len = format_output(t, &t->devices[i].results, t->devices[i].name, data, sizeof(data), &tm); if (t->file_output && !t->porcelain) { ret = write(fd, data, len); if (ret == -1) fprintf(stderr, "unable to write %d bytes to csv.\n", len); } } if (t->aggregate_output) { len = format_output(t, &t->aggregate_results, "aggregate", data, sizeof(data), &tm); if (t->file_output && !t->porcelain) { ret = write(fd, data, len); if (ret == -1) fprintf(stderr, "unable to write %d bytes to csv.\n", len); } } if (t->file_output && !t->porcelain) close(fd); return 0; }
void print_output(t_struct var, unsigned char *ptr) { unsigned char *current; long int i; unsigned int j; current = ptr + var.offset; i = 0; while (i < var.size) { j = -1; print_addr(var); while (++j < 16) { if (i >= var.size) break ; if (current[i] < 16) write(1, "0", 1); format_output(current[i]); write(1, " ", 1); ++i; } var.addr += 16; ft_putchar('\n'); } }
static int print_os (int announce, char* format) { char buffer[bsize]; char user[bsize]; char host[bsize]; char kernel[bsize]; if (xs_parse_os (user, host, kernel) != 0) { hexchat_printf (ph, "%s\tERROR in parse_os()", name); return HEXCHAT_EAT_ALL; } snprintf (buffer, bsize, "%s@%s, %s", user, host, kernel); format_output ("OS", buffer, format); if (announce) { hexchat_commandf (ph, "SAY %s", buffer); } else { hexchat_printf (ph, "%s", buffer); } return HEXCHAT_EAT_ALL; }
static int print_ram (int announce, char* format) { unsigned long long mem_total; unsigned long long mem_free; unsigned long long swap_total; unsigned long long swap_free; char string[bsize]; if (xs_parse_meminfo (&mem_total, &mem_free, 0) == 1) { hexchat_printf (ph, "%s\tERROR in parse_meminfo!", name); return HEXCHAT_EAT_ALL; } if (xs_parse_meminfo (&swap_total, &swap_free, 1) == 1) { hexchat_printf (ph, "%s\tERROR in parse_meminfo!", name); return HEXCHAT_EAT_ALL; } snprintf (string, bsize, "%s - %s", pretty_freespace ("Physical", &mem_free, &mem_total), pretty_freespace ("Swap", &swap_free, &swap_total)); format_output ("RAM", string, format); if (announce) { hexchat_commandf (ph, "SAY %s", string); } else { hexchat_printf (ph, "%s", string); } return HEXCHAT_EAT_ALL; }
char *TKGetNextToken(TokenizerT *tk) { char *delim = tk->delimiter; char *delim_itr = tk->delimiter; char *output = malloc(strlen(tk->inputString) + 1); while(*tk->inputString != '\0') { while(*delim_itr != '\0') { if(*tk->inputString == *delim_itr) { if( strlen(output) == 0) { delim_itr = delim; tk->inputString++; break; } else { tk->inputString++; format_output(&output); return output; } } delim_itr++; } delim_itr = delim; output[strlen(output)] = *tk->inputString; output[strlen(output) + 1] = '\0'; tk->inputString++; } if(strlen(output)==0) { return NULL; } else { format_output(&output); tk->token = realloc(tk->token, strlen(output)+1); copy_string(tk->token, output); //FREE(output); return output; } }
void PRESENT80_enc(dqword *input, const unsigned char* userkey){ format_input(input); for(int i=0; i<31; i++){ addRoundKey(input, &rks[i]); sBoxLayer(input); pLayer(input); } addRoundKey(input, &rks[31]); format_output(input); }
static int print_uptime (int announce, char* format) { char buffer[bsize]; int weeks; int days; int hours; int minutes; int seconds; if (xs_parse_uptime (&weeks, &days, &hours, &minutes, &seconds)) { hexchat_printf (ph, "%s\tERROR in parse_uptime()", name); return HEXCHAT_EAT_ALL; } if (minutes != 0 || hours != 0 || days != 0 || weeks != 0) { if (hours != 0 || days != 0 || weeks != 0) { if (days !=0 || weeks != 0) { if (weeks != 0) { snprintf (buffer, bsize, "%dw %dd %dh %dm %ds", weeks, days, hours, minutes, seconds); } else { snprintf (buffer, bsize, "%dd %dh %dm %ds", days, hours, minutes, seconds); } } else { snprintf (buffer, bsize, "%dh %dm %ds", hours, minutes, seconds); } } else { snprintf (buffer, bsize, "%dm %ds", minutes, seconds); } } format_output ("Uptime", buffer, format); if (announce) { hexchat_commandf (ph, "SAY %s", buffer); } else { hexchat_printf (ph, "%s", buffer); } return HEXCHAT_EAT_ALL; }
static void intercom_tell_player(char *str, int format) { char *name, *msg; player *p; char *oldstack = stack, *stack_ptr, *end_ptr; name = str; if (!str || !*str) { log("error", "Empty message in intercom_tell_player"); return; } msg = strchr(str, ':'); if (msg) *msg++ = '\0'; if (!msg || !*msg) return; p = find_player_global_quiet(name); if (!p) return; /*We have a player, p, so if we need to, format the output */ if (format) msg = format_output(p, msg); /*Put the whole thing on the stack, so we can add a \n on it. This is thanks to Nevyn at Crazylands, cos he threw away process output and now Crazylands cant handle the \n at the end cos of colour code methods. */ stack_ptr = stack; strcpy(stack_ptr, msg); stack = end_string(stack_ptr); end_ptr = stack - 1; if (end_ptr >= stack_ptr && *end_ptr != '\n') { sprintf(end_ptr, "%s\n", COLOUR_TERMINATOR); stack = end_string(end_ptr); } if (p->flags & PROMPT) pager(p, stack_ptr); else tell_player(p, stack_ptr); stack = oldstack; command_type = 0; return; }
static void format_output(unsigned char n) { int remain; int digit; static char *base = "0123456789abcdef"; remain = n % 16; digit = remain + '0'; if (n / 16 != 0) format_output(n / 16); write(1, &base[digit - 48], 1); }
void get_code_player(guess* kode) /**************************************/ /* Function: accepts player guess */ /* */ /* Parameters: */ /* kode: IN OUT guess structure */ /**************************************/ { char c[4][7]; int bad_in, code_valid; int x; code_valid = bad_in = FALSE; kode->blacks = kode->whites = 0; while (!code_valid) { code_valid = TRUE; if (bad_in) format_output("Previous code contains invalid color.\n",1); format_output("Please enter guess",1); printf(" #%d -> ",cur + 1); scanf("%s %s %s %s",c[0],c[1],c[2],c[3]); while (getchar() != '\n'); /* loop to get 4 colors*/ for (x = 0; x < 4; x++) { kode->pegs[x].used = NONE; kode->pegs[x].color = find_digit(c[x]); if (kode->pegs[x].color == BAD_COLOR) { /*invalid code color*/ code_valid = FALSE; bad_in = TRUE; } } } }
void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t) { char *outwalk = buffer; static char *form = NULL; struct tm current_tm; struct disc_time *dt; set_timezone(NULL); /* Use local time. */ localtime_r(&t, ¤t_tm); if ((dt = get_ddate(¤t_tm)) == NULL) return; if (form == NULL) if ((form = malloc(strlen(format) + 1)) == NULL) return; strcpy(form, format); outwalk += format_output(outwalk, form, dt); OUTPUT_FULL_TEXT(buffer); }
static int print_cpu (int announce, char* format) { char model[bsize]; char vendor[bsize]; char cache[bsize]; char buffer[bsize]; unsigned int count; double freq; int giga = 0; if (xs_parse_cpu (model, vendor, &freq, cache, &count) != 0) { hexchat_printf (ph, "%s\tERROR in parse_cpu()", name); return HEXCHAT_EAT_ALL; } if (freq > 1000) { freq /= 1000; giga = 1; } if (giga) { snprintf (buffer, bsize, "%d x %s (%s) @ %.2fGHz w/ %s L2 Cache", count, model, vendor, freq, cache); } else { snprintf (buffer, bsize, "%d x %s (%s) @ %.0fMHz w/ %s L2 Cache", count, model, vendor, freq, cache); } format_output ("CPU", buffer, format); if (announce) { hexchat_commandf (ph, "SAY %s", buffer); } else { hexchat_printf (ph, "%s", buffer); } return HEXCHAT_EAT_ALL; }
static int print_disk (int announce, char* format) { char string[bsize] = {0,}; #if 0 if (*word == '\0') { if (xs_parse_df (NULL, string)) { hexchat_printf (ph, "ERROR in parse_df"); return HEXCHAT_EAT_ALL; } } else { if (xs_parse_df (*word, string)) { hexchat_printf (ph, "ERROR in parse_df"); return HEXCHAT_EAT_ALL; } } #endif if (xs_parse_df (NULL, string)) { hexchat_printf (ph, "%s\tERROR in parse_df", name); return HEXCHAT_EAT_ALL; } format_output ("Disk", string, format); if (announce) { hexchat_commandf (ph, "SAY %s", string); } else { hexchat_printf (ph, "%s", string); } return HEXCHAT_EAT_ALL; }
void score_player() /**************************************/ /* Function: defines score for */ /* current guess */ /**************************************/ { int x, y; /* checks black pegs*/ for (x = 0; x < 4; x++) guesses[cur].pegs[x].used = code.pegs[x].used = NONE; for (x = 0; x < 4; x++) if (guesses[cur].pegs[x].color == code.pegs[x].color) { /* guess color = code color */ code.pegs[x].used = guesses[cur].pegs[x].used = BLACK; guesses[cur].blacks++; PDEBUG(0,guesses[cur].blacks); printf("b"); } if (guesses[cur].blacks != 4) /* if not game_won, checks white pegs*/ { for (x = 0; x < 4; x++) for (y = 0; y < 4; y++) if (guesses[cur].pegs[x].color == code.pegs[y].color && !code.pegs[y].used && !guesses[cur].pegs[x].used) { code.pegs[y].used = guesses[cur].pegs[x].used = WHITE; guesses[cur].whites++; printf("w"); } } else game_won = TRUE; if (guesses[cur].blacks != 0 || guesses[cur].whites != 0) skipline(2); else /*bad guess,no score */ format_output("No score.\n\n",1); }
void help(int* tt) /*******************************/ /* Function: helps player */ /* */ /* Parameters: */ /* tt: IN a guess */ /*******************************/ { int z, w ; skipline(1); z = 0; /* Enter the guess you need the hint for */ while (z < 1 || z > cur) { z = 0; format_output("Enter the guess you need the hint for -> ",1); while((*tt = getchar()) != '\n') z = z * 10 + *tt - '0'; } w = 0; /*choose the peg you need the hint for */ while (w < 1 || w > 4) { w = 0; format_output("Which peg of guess",1); printf(" #%d -> ",z); while((*tt = getchar()) != '\n') w = w * 10 + *tt - '0'; } format_output("In guess",1); printf(" #%d,",z); printf("peg #%d received ",w); if (guesses[z - 1].pegs[w - 1].used == BLACK) format_output("a black peg.\n",0); if (guesses[z - 1].pegs[w - 1].used == WHITE) format_output("a white peg.\n",0); if (guesses[z - 1].pegs[w - 1].used == NONE) format_output("no peg.\n",0); skipline(1); }
static int netdata_cb (char *word[], char *word_eol[], void *userdata) { char netdata[bsize]; char format[bsize]; unsigned long long bytes_recv; unsigned long long bytes_sent; if (*word[2] == '\0') { hexchat_printf (ph, "%s\tYou must specify a network device (e.g. /NETDATA eth0)!", name); return HEXCHAT_EAT_ALL; } if (xs_parse_netdev (word[2], &bytes_recv, &bytes_sent) != 0) { hexchat_printf (ph, "%s\tERROR in parse_netdev", name); return HEXCHAT_EAT_ALL; } bytes_recv /= 1024; bytes_sent /= 1024; snprintf (netdata, bsize, "%s: %.1f MB Recieved, %.1f MB Sent", word[2], (double)bytes_recv/1024.0, (double)bytes_sent/1024.0); hexchat_pluginpref_get_str (ph, "format", format); format_output ("Netdata", netdata, format); if (hexchat_list_int (ph, NULL, "type") >= 2) { hexchat_commandf (ph, "SAY %s", netdata); } else { hexchat_printf (ph, "%s", netdata); } return HEXCHAT_EAT_ALL; }
static int print_ethernet (int announce, char* format) { char ethernet_card[bsize]; if (xs_parse_ether (ethernet_card)) { strncpy (ethernet_card, "None found", bsize); } format_output ("Ethernet", ethernet_card, format); if (announce) { hexchat_commandf (ph, "SAY %s", ethernet_card); } else { hexchat_printf (ph, "%s", ethernet_card); } return HEXCHAT_EAT_ALL; }
/** The Smith Waterman algorithm output function. */ void smith_waterman_output(FILE *fp) { get_trace_cell_value(); Result_t result; smith_waterman_traceback(&result); fprintf(fp, ">>sequence #1: %s(Length: %d), sequence #2: %s(Length: %d)\n", seq1->name, seq1->length, seq2->name, seq2->length); fprintf(fp, " Scoring_Matrix: %s, open gap: %d, extend gap: %d\n", get_scoring_matrix_id(), op, ep); fprintf(fp, ">Result:\n"); fprintf(fp, " Score: %d, Aligned Length: %d\n", result.score, result.length); fprintf( fp, " Identity: %d/%d (%.2lf%%), Similarity: %d/%d (%.2lf%%), Gaps: %d/%d (%.2lf%%)\n", result.identity, result.length, result.identity / (result.length * 0.01), result.similarity, result.length, result.similarity / (result.length * 0.01), result.gaps, result.length, result.gaps / (result.length * 0.01)); format_output(fp, &result); smith_waterman_destroy(); }
static int print_distro (int announce, char* format) { char name[bsize]; if (xs_parse_distro (name) != 0) { hexchat_printf (ph, "%s\tERROR in parse_distro()!", name); return HEXCHAT_EAT_ALL; } format_output("Distro", name, format); if (announce) { hexchat_commandf (ph, "SAY %s", name); } else { hexchat_printf (ph, "%s", name); } return HEXCHAT_EAT_ALL; }
gboolean weather_update_text(void* ptr) { struct weather_monitor* m; if ((m = (struct weather_monitor*)ptr) != NULL) { char* output; CURLcode code = download_data(m->curl, m->request_str->str, m->res); if (code == CURLE_OK && format_output(m->res, m->icon) != -1) { output = m->res->str; } else { output = m->err; } g_mutex_lock(m->mutex); m->bar_text = g_string_assign(m->bar_text, output); g_mutex_unlock(m->mutex); return TRUE; } else { fprintf(stderr, "Weather monitor not received in update.\n"); exit(EXIT_FAILURE); } }
static int print_sound (int announce, char* format) { char sound[bsize]; if (xs_parse_sound (sound) != 0) { hexchat_printf (ph, "%s\tERROR in parse_asound()!", name); return HEXCHAT_EAT_ALL; } format_output ("Sound", sound, format); if (announce) { hexchat_commandf (ph, "SAY %s", sound); } else { hexchat_printf (ph, "%s", sound); } return HEXCHAT_EAT_ALL; }
static int print_vga (int announce, char* format) { char vid_card[bsize]; char agp_bridge[bsize]; char buffer[bsize]; int ret; if ((ret = xs_parse_video (vid_card)) != 0) { hexchat_printf (ph, "%s\tERROR in parse_video! %d", name, ret); return HEXCHAT_EAT_ALL; } if (xs_parse_agpbridge (agp_bridge) != 0) { snprintf (buffer, bsize, "%s", vid_card); } else { snprintf (buffer, bsize, "%s @ %s", vid_card, agp_bridge); } format_output ("VGA", buffer, format); if (announce) { hexchat_commandf (ph, "SAY %s", buffer); } else { hexchat_printf (ph, "%s", buffer); } return HEXCHAT_EAT_ALL; }
void player_plays() /**************************************/ /* Function: player looking for */ /* computer's code */ /**************************************/ { int good_try; char inst, action; int coach, quit; int t; coach = quit = FALSE; format_output("Do you want coaching, y/n [default is n] -> ",1); if ((inst = getchar()) != '\n') while (getchar() != '\n'); if (inst == 'y' || inst == 'Y') coach = TRUE; skipline(1); format_output("Choosing a code for you to guess.\n",1); t = rand() % 3 + 2; sleep(t); make_code(&code); if (JACKPOT == 1) { /* ... mark ... */ /* Mark in order to succeed with the first guess. */ printf(" You must guess: %-8s %-8s %-8s %-8s\n", col[dig[code.pegs[0].color]], col[dig[code.pegs[1].color]], col[dig[code.pegs[2].color]], col[dig[code.pegs[3].color]]); /* ... end mark ... */ } for (cur = 0; cur < MAX_TRY && !game_won;) { if (cur) { good_try = cur + 1; format_output("guess, refresh, print, or quit [default is guess] -> ",1); if ((action = getchar()) != '\n') while (getchar() != '\n'); } else action = 'g'; switch (action) { case 'r': case 'R': /* you want to see your guesses*/ if (cur != 0) { refresh(); break; } case 'q': case 'Q': /* you want to quit*/ end_game(&cur,&quit); break; case 'h': case 'H': /* you need a hint to find the code*/ help(&t); break; case 'p': case 'P': /* you want to have help*/ /*about this menu*/ print_help(); break; default: /* you want to guess*/ play(guesses,&cur,coach); break; } } if (game_won) { if (cur != 1) { format_output(" You broke the code in",0); printf(" %d tries.\n",good_try); skipline(1); format_output(" FREE GAME - PLAY AGAIN\n",0); } else { system("/usr/5bin/banner \" JACKPOT\""); } print_score_player(good_try); } else if (!quit) { skipline(1); format_output("Sorry. You've run out of guesses.\n",1); /* display the correct code*/ format_output(" The correct code was:",1); printf(" %-8s %-8s %-8s %-8s\n", col[dig[code.pegs[0].color]], col[dig[code.pegs[1].color]], col[dig[code.pegs[2].color]], col[dig[code.pegs[3].color]]); } else format_output("Was that too tough for you? I'll be nicer next time.\n",1); }
int main(int argc, char* argv[]) { int n = 20000000; int repeats = 20; if(argc > 1) n = boost::lexical_cast<int>(argv[1]); if(argc > 2) repeats = boost::lexical_cast<int>(argv[2]); typedef std::vector<int> vector; typedef std::list<int> list; typedef std::vector<non_trivial_cctor> vector2; vector v(n); typedef int* copy_mem; typedef non_trivial_cctor* copy_mem2; copy_mem copy_m = new int[n]; //wiki markup header std::cout << "{| \n" "! Library !! From Container !! To !! #Elements !! items/sec \n" "|- \n"; float item_sec; #ifndef CGAL_CFG_NO_CPP0X_COPY_N item_sec = test(v.begin(), n, copy_m, repeats, std_tag()); format_output("stdlib", "vector<int>", "int*", n, item_sec); std::cout << "|- \n"; #endif item_sec = test(v.begin(), n, copy_m, repeats, cgal_tag()); format_output("CGAL", "vector<int>", "int*", n, item_sec); std::cout << "|- \n"; //purge v.clear(); std::fill_n(copy_m, n, 0); list l(n); #ifndef CGAL_CFG_NO_CPP0X_COPY_N item_sec = test(l.begin(), n, copy_m, repeats, std_tag()); format_output("stdlib", "list<int>", "int*", n, item_sec); std::cout << "|- \n"; #endif item_sec = test(l.begin(), n, copy_m, repeats, cgal_tag()); format_output("CGAL", "list<int>", "int*", n, item_sec); std::cout << "|- \n"; delete[] copy_m; vector2 v2(n); copy_mem2 copy_m2 = new non_trivial_cctor[n]; #ifndef CGAL_CFG_NO_CPP0X_COPY_N item_sec = test(v2.begin(), n, copy_m2, repeats, std_tag()); format_output("stdlib", "vector<non_trivial_cctor>", "non_trivial_cctor*", n, item_sec); std::cout << "|- \n"; #endif item_sec = test(v2.begin(), n, copy_m2, repeats, cgal_tag()); format_output("CGAL", "vector<non_trivial_cctor>", "non_trivial_cctor*", n, item_sec); //wiki markup footer std::cout << "|}" << std::endl; return EXIT_SUCCESS; }
/* ---------------------------------------------------------------------- * read one set of motion parameters (extras?) and store in structure * * return 1 : finished * 0 : have data: continue * -1 : error * ---------------------------------------------------------------------- */ int read_socket(optiondata * opt, port_list * plist, motparm * mp) { static char * outstring = NULL; static int oslen = 0; int rv, len; if ( (rv = test_socket(plist->tdata_sd)) < 0 ) return -1; else if ( rv == 1 ) { if ( opt->debug > 0 ) fprintf(stderr,"++ found close request, mpcount = %d\n", mp->nread); return 1; } /* get motion params */ len = mp->nvals * sizeof(float); if ( (rv = recv(plist->tdata_sd, (void *)mp->data, len, 0)) < len ) { fprintf(stderr,"** read only %d of %d bytes on socket\n", rv, len); perror("recv mot parm"); return -1; } if ( opt->show_times && opt->debug > 2 ) show_time("received mp data"); if ( opt->swap ) swap_4(mp->data, mp->nvals); /* get extra floats */ if( mp->nex > 0 ) { len = mp->nex * sizeof(float); if ( (rv = recv(plist->tdata_sd, (void *)mp->extras, len, 0)) < len ) { fprintf(stderr,"** read only %d of %d Ebytes on socket\n", rv, len); perror("recv extra floats"); return -1; } if ( opt->swap ) swap_4(mp->extras, mp->nex); } mp->nread++; if ( opt->show_times ) { char mesg[32]; sprintf(mesg, "received mp data #%03d", mp->nread); show_time(mesg); } if ( opt->debug > 2 || opt->disp_all ) { rv = format_output(opt, mp, &outstring, &oslen); if( rv ) { fprintf(stderr,"** failed to format output string\n"); if( outstring ) { free(outstring); outstring = NULL; } return 1; } /* will probably want to send elsewhere, later */ fputs(outstring,stderr); fflush(stderr); /* may get buffered */ } return 0; }
static int print_summary (int announce, char* format) { char sysinfo[bsize]; char buffer[bsize]; char cpu_model[bsize]; char cpu_cache[bsize]; char cpu_vendor[bsize]; char os_host[bsize]; char os_user[bsize]; char os_kernel[bsize]; unsigned long long mem_total; unsigned long long mem_free; unsigned int count; double cpu_freq; int giga = 0; int weeks; int days; int hours; int minutes; int seconds; sysinfo[0] = '\0'; snprintf (buffer, bsize, "%s", hexchat_get_info (ph, "version")); format_output ("HexChat", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN OS PARSING */ if (xs_parse_os (os_user, os_host, os_kernel) != 0) { hexchat_printf (ph, "%s\tERROR in parse_os()", name); return HEXCHAT_EAT_ALL; } snprintf (buffer, bsize, "%s", os_kernel); format_output ("OS", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN DISTRO PARSING */ if (xs_parse_distro (buffer) != 0) { strncpy (buffer, "Unknown", bsize); } format_output ("Distro", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN CPU PARSING */ if (xs_parse_cpu (cpu_model, cpu_vendor, &cpu_freq, cpu_cache, &count) != 0) { hexchat_printf (ph, "%s\tERROR in parse_cpu()", name); return HEXCHAT_EAT_ALL; } if (cpu_freq > 1000) { cpu_freq /= 1000; giga = 1; } if (giga) { snprintf (buffer, bsize, "%d x %s (%s) @ %.2fGHz", count, cpu_model, cpu_vendor, cpu_freq); } else { snprintf (buffer, bsize, "%d x %s (%s) @ %.0fMHz", count, cpu_model, cpu_vendor, cpu_freq); } format_output ("CPU", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN MEMORY PARSING */ if (xs_parse_meminfo (&mem_total, &mem_free, 0) == 1) { hexchat_printf (ph, "%s\tERROR in parse_meminfo!", name); return HEXCHAT_EAT_ALL; } snprintf (buffer, bsize, "%s", pretty_freespace ("Physical", &mem_free, &mem_total)); format_output ("RAM", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN DISK PARSING */ if (xs_parse_df (NULL, buffer)) { hexchat_printf (ph, "%s\tERROR in parse_df", name); return HEXCHAT_EAT_ALL; } format_output ("Disk", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); /* BEGIN VIDEO PARSING */ if (xs_parse_video (buffer)) { hexchat_printf (ph, "%s\tERROR in parse_video", name); return HEXCHAT_EAT_ALL; } format_output ("VGA", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); /* BEGIN SOUND PARSING */ if (xs_parse_sound (buffer)) { strncpy (buffer, "Not present", bsize); } format_output ("Sound", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); /* BEGIN ETHERNET PARSING */ if (xs_parse_ether (buffer)) { strncpy (buffer, "None found", bsize); } format_output ("Ethernet", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); /* BEGIN UPTIME PARSING */ if (xs_parse_uptime (&weeks, &days, &hours, &minutes, &seconds)) { hexchat_printf (ph, "%s\tERROR in parse_uptime()", name); return HEXCHAT_EAT_ALL; } if (minutes != 0 || hours != 0 || days != 0 || weeks != 0) { if (hours != 0 || days != 0 || weeks != 0) { if (days !=0 || weeks != 0) { if (weeks != 0) { snprintf (buffer, bsize, "%dw %dd %dh %dm %ds", weeks, days, hours, minutes, seconds); } else { snprintf (buffer, bsize, "%dd %dh %dm %ds", days, hours, minutes, seconds); } } else { snprintf (buffer, bsize, "%dh %dm %ds", hours, minutes, seconds); } } else { snprintf (buffer, bsize, "%dm %ds", minutes, seconds); } } format_output ("Uptime", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); if (announce) { hexchat_commandf (ph, "SAY %s", sysinfo); } else { hexchat_printf (ph, "%s", sysinfo); } return HEXCHAT_EAT_ALL; }
static int netstream_cb (char *word[], char *word_eol[], void *userdata) { char netstream[bsize]; char mag_r[5]; char mag_s[5]; char format[bsize]; unsigned long long bytes_recv; unsigned long long bytes_sent; unsigned long long bytes_recv_p; unsigned long long bytes_sent_p; struct timespec ts = {1, 0}; if (*word[2] == '\0') { hexchat_printf (ph, "%s\tYou must specify a network device (e.g. /NETSTREAM eth0)!", name); return HEXCHAT_EAT_ALL; } if (xs_parse_netdev(word[2], &bytes_recv, &bytes_sent) != 0) { hexchat_printf (ph, "%s\tERROR in parse_netdev", name); return HEXCHAT_EAT_ALL; } while (nanosleep (&ts, &ts) < 0); if (xs_parse_netdev(word[2], &bytes_recv_p, &bytes_sent_p) != 0) { hexchat_printf (ph, "%s\tERROR in parse_netdev", name); return HEXCHAT_EAT_ALL; } bytes_recv = (bytes_recv_p - bytes_recv); bytes_sent = (bytes_sent_p - bytes_sent); if (bytes_recv > 1024) { bytes_recv /= 1024; snprintf (mag_r, 5, "KB/s"); } else { snprintf (mag_r, 5, "B/s"); } if (bytes_sent > 1024) { bytes_sent /= 1024; snprintf (mag_s, 5, "KB/s"); } else { snprintf (mag_s, 5, "B/s"); } snprintf (netstream, bsize, "%s: Receiving %llu %s, Sending %llu %s", word[2], bytes_recv, mag_r, bytes_sent, mag_s); hexchat_pluginpref_get_str (ph, "format", format); format_output ("Netstream", netstream, format); if (hexchat_list_int (ph, NULL, "type") >= 2) { hexchat_commandf (ph, "SAY %s", netstream); } else { hexchat_printf (ph, "%s", netstream); } return HEXCHAT_EAT_ALL; }
/* Piccolo main encryption block: it supposes that the scheduled keys are in memory pointed by the second argument */ __attribute__((noinline)) void Piccolo80vperm_core(const u8* message, const u8* subkeys, u8* ciphertext) { /* Note : message is in rdi, subkeys in rsi and ciphertext in rdx */ /* __cdecl calling convention */ asm (".intel_syntax noprefix"); Push_All_Regs(); /* Key Index */ asm("xor "tostr(RoundCounter_)", "tostr(RoundCounter_)""); /* Load constants (SBoxes, multiplications ...) */ asm("movdqa "tostr(PiccoloSBoxL_)", [rip + PiccoloSBoxL]"); asm("movdqa "tostr(PiccoloSBoxH_)", [rip + PiccoloSBoxH]"); asm("movdqa "tostr(TwoMulPiccoloSBoxL_)", [rip + TwoMulPiccoloSBoxL]"); asm("movdqa "tostr(ThreeMulPiccoloSBoxL_)", [rip + ThreeMulPiccoloSBoxL]"); asm("movdqa "tostr(PiccoloThreeShuf_)", [rip + PiccoloThreeShuf]"); asm("movdqa "tostr(PiccoloOneShufa_)", [rip + PiccoloOneShufa]"); asm("movdqa "tostr(PiccoloOneShufb_)", [rip + PiccoloOneShufb]"); /* Load the masks */ asm("movdqa "tostr(PiccoloAndMaskL_)", [rip + PiccoloAndMaskL]"); /* Load Piccolo's Round Permutation PiccoloRP */ asm("movdqa "tostr(PiccoloRP_)", [rip + PiccoloRP]"); /* Scheduled keys from [rsi] and above */ /* Load the messages and format them */ format_input(Plaintext_, Plaintext_+8, State_, Tmp1_, Tmp2_, Tmp3_); /* Pre Whitening AddRoundKey */ asm("pxor "tostr(State_)", ["tostr(Keys_)"+"tostr(RoundCounter_)"]"); asm("add "tostr(RoundCounter_)", 16"); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloROUND(); PiccoloLASTROUND(); /* Post Whitening AddRoundKey */ asm("pxor "tostr(State_)", ["tostr(Keys_)"+"tostr(RoundCounter_)"]"); /* Move back the result in the input message, formatted */ format_output(Ciphertext_, State_, Tmp1_, Tmp2_, Tmp3_); Pop_All_Regs(); asm (".att_syntax noprefix"); return; }
/* Print the date *dt in format *format */ static int format_output(char *outwalk, char *format, struct disc_time *dt) { char *orig_outwalk = outwalk; char *i; char *tibs_end = 0; for (i = format; *i != '\0'; i++) { if (*i != '%') { *(outwalk++) = *i; continue; } switch (*(i+1)) { /* Weekday in long and abbreviation */ case 'A': outwalk += sprintf(outwalk, "%s", day_long[dt->week_day]); break; case 'a': outwalk += sprintf(outwalk, "%s", day_short[dt->week_day]); break; /* Season in long and abbreviation */ case 'B': outwalk += sprintf(outwalk, "%s", season_long[dt->season]); break; case 'b': outwalk += sprintf(outwalk, "%s", season_short[dt->season]); break; /* Day of the season (ordinal and cardinal) */ case 'd': outwalk += sprintf(outwalk, "%d", dt->season_day + 1); break; case 'e': outwalk += sprintf(outwalk, "%d", dt->season_day + 1); if (dt->season_day > 9 && dt->season_day < 13) { outwalk += sprintf(outwalk, "th"); break; } switch (dt->season_day % 10) { case 0: outwalk += sprintf(outwalk, "st"); break; case 1: outwalk += sprintf(outwalk, "nd"); break; case 2: outwalk += sprintf(outwalk, "rd"); break; default: outwalk += sprintf(outwalk, "th"); break; } break; /* YOLD */ case 'Y': outwalk += sprintf(outwalk, "%d", dt->year); break; /* Holidays */ case 'H': if (dt->season_day == 4) { outwalk += sprintf(outwalk, "%s", holidays[dt->season]); } if (dt->season_day == 49) { outwalk += sprintf(outwalk, "%s", holidays[dt->season + 5]); } break; /* Stop parsing the format string, except on Holidays */ case 'N': if (dt->season_day != 4 && dt->season_day != 49) { return (outwalk - orig_outwalk); } break; /* Newline- and Tabbing-characters */ case 'n': outwalk += sprintf(outwalk, "\n"); break; case 't': outwalk += sprintf(outwalk, "\t"); break; /* The St. Tib's Day replacement */ case '{': tibs_end = strstr(i, "%}"); if (tibs_end == NULL) { i++; break; } if (dt->st_tibs_day) { /* We outpt "St. Tib's Day... */ outwalk += sprintf(outwalk, "St. Tib's Day"); } else { /* ...or parse the substring between %{ and %} ... */ *tibs_end = '\0'; outwalk += format_output(outwalk, i + 2, dt); *tibs_end = '%'; } /* ...and continue with the rest */ i = tibs_end; break; case '}': i++; break; default: /* No escape-sequence, so we just skip */ outwalk += sprintf(outwalk, "%%%c", *(i+1)); break; } i++; } return (outwalk - orig_outwalk); }
/* LED main encryption block: it supposes that the scheduled keys are in memory pointed by the second argument */ __attribute__((noinline)) void LED128vperm_core(const u8* message, const u8* subkeys, u8* ciphertext) { /* Note : message is in rdi, subkeys in rsi and ciphertext in rdx */ /* __cdecl calling convention */ asm (".intel_syntax noprefix"); \ Push_All_Regs(); /* Key Index */ asm("xor "tostr(RoundCounter_)", "tostr(RoundCounter_)""); asm("lea "tostr(RCBase_)", [rip + RC128_LED]"); /* Load constants (TBoxes) */ asm("movdqa "tostr(T1a_LED_)", [rip + T1a_LED]"); asm("movdqa "tostr(T1b_LED_)", [rip + T1b_LED]"); asm("movdqa "tostr(T2a_LED_)", [rip + T2a_LED]"); asm("movdqa "tostr(T2b_LED_)", [rip + T2b_LED]"); asm("movdqa "tostr(T3a_LED_)", [rip + T3a_LED]"); asm("movdqa "tostr(T3b_LED_)", [rip + T3b_LED]"); asm("movdqa "tostr(T4a_LED_)", [rip + T4a_LED]"); asm("movdqa "tostr(T4b_LED_)", [rip + T4b_LED]"); /* Load the the And mask */ asm("movdqa "tostr(AndMask_LED_)", [rip + AndMask_LED]"); asm("movdqa "tostr(OrMask_LED_)", [rip + OrMask_LED]"); /* Load the message */ asm("movdqa "tostr(State_)", ["tostr(Plaintext_)"]"); /* Transform the message from line wise to column wise */ format_input(State_); /* Transform the keys from line wise to column wise */ asm("movdqa "tostr(Tmp4_)", ["tostr(Keys_)"]"); format_input(Tmp4_); asm("movdqa ["tostr(Keys_)"], "tostr(Tmp4_)""); asm("movdqa "tostr(Tmp4_)", ["tostr(Keys_)"+16]"); format_input(Tmp4_); asm("movdqa ["tostr(Keys_)"+16], "tostr(Tmp4_)""); /* Interleave the half keys */ asm("mov rax, ["tostr(Keys_)"+8]"); asm("mov rbx, ["tostr(Keys_)"+16]"); asm("mov ["tostr(Keys_)"+16], rax"); asm("mov ["tostr(Keys_)"+8], rbx"); asm("pxor "tostr(State_)", ["tostr(Keys_)"]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"+16]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"+16]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"+16]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"+16]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"+16]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"]"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"]+16"); LEDROUND(); LEDROUND(); LEDROUND(); LEDROUND(); asm("pxor "tostr(State_)", ["tostr(Keys_)"]"); /* Transform the message back from column wise to line wise */ format_output(State_); /* Move back the result in the input message */ asm("movdqa ["tostr(Ciphertext_)"], "tostr(State_)""); Pop_All_Regs(); asm (".att_syntax noprefix"); return; }