コード例 #1
0
int main() {
  init_state_descriptors();
  set_descriptors(triples);  
  print_descriptors();

  build_tables();
  print_tables();
  check_tables();
  return 0;
}
コード例 #2
0
ファイル: gen_enc_table.c プロジェクト: zruibin/aes_128
int main () {

    int i;
    for ( i = 0; i < 256; ++i ) {

        SBOX2[i] = SBOX[i] << 1;

        if ( SBOX[i] >= 128 ) {
            SBOX2[i] ^= CONX;
        }

        SBOX3[i] = SBOX2[i] ^ SBOX[i];

    }

    generate_tables();
    print_tables();

    return 0;
}
コード例 #3
0
ファイル: cmd.c プロジェクト: colomonkey/opticon
/** The get-recrod command */
int cmd_get_record (int argc, const char *argv[]) {
    if (OPTIONS.tenant[0] == 0) {
        fprintf (stderr, "%% No tenantid provided\n");
        return 1;
    }
    if (OPTIONS.host[0] == 0) {
        fprintf (stderr, "%% No hostid provided\n");
        return 1;
    }

    var *apires = api_get ("/%s/host/%s", OPTIONS.tenant, OPTIONS.host);
    
    if (OPTIONS.json) {
        var_dump (apires, stdout);
        var_free (apires);
        return 0;
    }
    
    #define Arr(x) var_get_array_forkey(apires,x)
    #define Vint(x) var_get_int_forkey(apires,x)
    #define Vstr(x) var_get_str_forkey(apires,x)
    #define Vfrac(x) var_get_double_forkey(apires,x)
    #define VDint(x,y) var_get_int_forkey(var_get_dict_forkey(apires,x),y)
    #define VDstr(x,y) var_get_str_forkey(var_get_dict_forkey(apires,x),y)
    #define VDfrac(x,y) var_get_double_forkey(var_get_dict_forkey(apires,x),y)
    #define VAfrac(x,y) var_get_double_atindex(var_get_array_forkey(apires,x),y)
    #define Vdone(x) var_delete_key(apires,x)
    /* -------------------------------------------------------------*/
    print_hdr ("HOST");
    print_value ("UUID", "%s", OPTIONS.host);
    print_value ("Hostname", "%s", Vstr("hostname"));
    print_value ("Address", "%s", VDstr("agent","ip"));
    print_value ("Status", "\033[1m%s\033[0m", Vstr("status"));
    
    print_array ("Problems", Arr("problems"));
    
    Vdone("hostname");
    Vdone("agent");
    Vdone("status");
    Vdone("problems");
    
    char uptimestr[128];
    uint64_t uptime = Vint("uptime"); Vdone("uptime");
    uint64_t u_days = uptime / 86400ULL;
    uint64_t u_hours = (uptime - (86400 * u_days)) / 3600ULL;
    uint64_t u_mins = (uptime - (86400 * u_days) - (3600 * u_hours)) / 60ULL;
    uint64_t u_sec = uptime % 60;
    
    if (u_days) {
        sprintf (uptimestr, "%llu day%s, %llu:%02llu:%02llu", u_days,
                 (u_days==1)?"":"s", u_hours, u_mins, u_sec);
    }
    else if (u_hours) {
        sprintf (uptimestr, "%llu:%02llu:%02llu", u_hours, u_mins, u_sec);
    }
    else {
        sprintf (uptimestr, "%llu minute%s, %llu second%s",
                 u_mins, (u_mins==1)?"":"s", u_sec, (u_sec==1)?"":"s");
    }
    
    print_value ("Uptime","%s",uptimestr);
    print_value ("OS/Hardware","%s %s (%s)", VDstr("os","kernel"),
                 VDstr("os","version"), VDstr("os","arch"));
    const char *dist = VDstr("os","distro");
    if (dist) print_value ("Distribution", "%s", dist);
    Vdone("os");
    
    /* -------------------------------------------------------------*/
    print_hdr ("RESOURCES");
    print_value ("Processes","\033[1m%llu\033[0m "
                             "(\033[1m%llu\033[0m running, "
                             "\033[1m%llu\033[0m stuck)",
                             VDint("proc","total"),
                             VDint("proc","run"),
                             VDint("proc","stuck"));
    Vdone("proc");
 
     print_value ("Load Average", "\033[1m%6.2f\033[0m / "
                                  "\033[1m%6.2f\033[0m / "
                                  "\033[1m%6.2f\033[0m",
                 VAfrac ("loadavg",0), VAfrac ("loadavg", 1),
                 VAfrac ("loadavg",2));
    Vdone ("loadavg");

    char cpubuf[128];
    sprintf (cpubuf, "\033[1m%6.2f \033[0m%%", Vfrac("pcpu"));
    
    char meter[32];
    strcpy (meter, "-[                      ]+");
    
    double iowait = VDfrac("io","pwait");
    double pcpu = Vfrac("pcpu"); Vdone("pcpu");
    double level = 4.5;
    
    int pos = 2;
    while (level < 100.0 && pos < 22) {
        if (level < pcpu) meter[pos++] = '#';
        else meter[pos++] = ' ';
        level += 4.5;
    }
    
    
    print_value ("CPU", "%-40s %s", cpubuf, meter);
    if (iowait>0.001) print_value ("CPU iowait", 
                                   "\033[1m%6.2f %%\033[0m", iowait);
    print_value ("Available RAM", "\033[1m%.2f\033[0m MB",
                 ((double)VDint("mem","total"))/1024.0);
    print_value ("Free RAM", "\033[1m%.2f\033[0m MB",
                 ((double)VDint("mem","free"))/1024.0);
    
    print_value ("Network in/out", "\033[1m%i\033[0m Kb/s "
                                   "(\033[1m%i\033[0m pps) / "
                                   "\033[1m%i\033[0m Kb/s "
                                   "(\033[1m%i\033[0m pps)",
                                   VDint("net","in_kbs"),
                                   VDint("net","in_pps"),
                                   VDint("net","out_kbs"),
                                   VDint("net","out_pps"));
    
    print_value ("Disk i/o", "\033[1m%i\033[0m rdops / "
                             "\033[1m%i\033[0m wrops",
                 VDint("io","rdops"), VDint("io","wrops"));
    
    Vdone("mem");
    Vdone("net");
    Vdone("io");
    Vdone("badness");

    print_values (apires, NULL);
    
    /* -------------------------------------------------------------*/
    print_hdr ("PROCESS LIST");
    
    const char *top_hdr[] = {"USER","PID","CPU","MEM","NAME",NULL};
    const char *top_fld[] = {"user","pid","pcpu","pmem","name",NULL};
    columnalign top_align[] = {CA_L, CA_R, CA_R, CA_R, CA_L, CA_NULL};
    vartype top_tp[] =
        {VAR_STR,VAR_INT,VAR_DOUBLE,VAR_DOUBLE,VAR_STR,VAR_NULL};
    int top_wid[] = {15, 7, 9, 9, 0, 0};
    int top_div[] = {0, 0, 0, 0, 0, 0};
    const char *top_suf[] = {"",""," %", " %", "", NULL};
    
    var *v_top = var_get_array_forkey (apires, "top");
    print_table (v_top, top_hdr, top_fld, 
                 top_align, top_tp, top_wid, top_suf, top_div);
    
    Vdone("top");
    /* -------------------------------------------------------------*/
    print_hdr ("STORAGE");
    
    const char *df_hdr[] = {"DEVICE","SIZE","FS","USED","MOUNTPOINT",NULL};
    const char *df_fld[] = {"device","size","fs","pused","mount",NULL};
    columnalign df_aln[] = {CA_L,CA_R,CA_L,CA_R,CA_L,CA_NULL};
    vartype df_tp[] = {VAR_STR,VAR_INT,VAR_STR,VAR_DOUBLE,VAR_STR,VAR_NULL};
    int df_wid[] = {12, 14, 6, 8, 0};
    int df_div[] = {0, (1024), 0, 0, 0, 0};
    const char *df_suf[] = {""," GB", "", " %", "", ""};
    
    var *v_df = var_get_array_forkey (apires, "df");
    
    /*print_generic_table (v_df);*/
    
    print_table (v_df, df_hdr, df_fld,
                 df_aln, df_tp, df_wid, df_suf, df_div);
    
    Vdone("df");
    
    /** Print any remaining table data */
    print_tables (apires);
        
    printf ("---------------------------------------------"
            "-----------------------------------\n");

    var_free (apires);
    print_done();
    return 0;    
}