Пример #1
0
void process_input(char *input, struct Graph *g){
    int i = 0;
    char name_a[50];
    char name_b[50];
    char type[5];
    sscanf(input, "%s %s %s", type, name_a, name_b);
    if(!strcmp(type,"new")){
        add_new_node(name_a, g);
    }
    else if(!strcmp(type,"link")){
        add_new_link(name_a, name_b, g);
    }
    else if(!strcmp(type,"out")){
        print_outgoing_nodes(name_a, g);
    }
    else if(!strcmp(type,"in")){
        print_incoming_nodes(name_a, g);
    }
    else if(!strcmp(type,"wn")){
        write_data_prompt(name_a, g);
    }
    else if(!strcmp(type,"rn")){
        read_data(name_a, g);
    }
    else if(!strcmp(type, "all")){
        print_graph(g);
    }
    else if(!strcmp(type,"wl")){
        write_link_data_prompt(name_a, name_b, g);
    }
    else if(!strcmp(type,"rl")){
        read_link_data(name_a, name_b, g);
    }
    else if(!strcmp(type, "path")){
        // printf("Hey");
        test_for_path(name_a, name_b, g);
    }
    else if(!strcmp(type, "save")){
        save_to_disk(g, name_a);
    }
    else if(!strcmp(type, "load")){
        read_from_disk(name_a, g);
    }
    else if(!strcmp(type, "getl")){
        get_links(g);
        // all links (node pairs) with X data
    }
    else if(!strcmp(type, "getn")){
        get_nodes(g);
        // all nodes with X data
    }
    else if(!strcmp(type, "add")){
        add_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "div")){
        divide_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "sub")){
        subtract_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "mult")){
        multiply_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "cmd")){
        run_command(name_a, g);
    }
    else if(!strcmp(type, "id")){
        long long_val;
        long_val = strtol(name_a, NULL, 10);
        int id = (int) long_val;
        struct Node *node; 
        node = get_node_by_id(id, g);
        if(!strcmp(node->name, "NULL")){
            printf("{ \"error\": \"No node with id %d\" }\n", id);
            free(node->name);
            free(node);
        } else {
            printf("{ \"id: %d, \"name\": \"%s\", \"data\": \"%s\" }\n", id, node->name, node->data);
        }
    }
}
Пример #2
0
/*
 *  Save the current state of all the desktop options/icons/windows
 *  etc to memory and, optionally, to a file called EMUDESK.INF
 */
void app_save(WORD todisk)
{
    WORD i;
    WORD env1, env2, mode, env5;
    BYTE type;
    BYTE *pcurr, *ptmp;
    ANODE *pa;
    WSAVE *pws;

    memset(gl_afile, 0, SIZE_AFILE);
    pcurr = gl_afile;

    /* save revision level */
    pcurr += sprintf(pcurr,"#R %02X\r\n",INF_REV_LEVEL);

    /* save autorun (if any) */
    for (pa = G.g_ahead; pa; pa = pa->a_next)
        if (pa->a_flags & AF_AUTORUN)
            pcurr += sprintf(pcurr,"#Z %02X %s@\r\n",pa->a_flags&AF_ISCRYS,pa->a_pappl);

    /* save environment */
    env1 = (G.g_cnxsave.cs_view) ? INF_E1_VIEWTEXT : 0x00;
    env1 |= ((G.g_cnxsave.cs_sort) << 5) & INF_E1_SORTMASK;
    env1 |= (G.g_cnxsave.cs_confdel) ? INF_E1_CONFDEL : 0x00;
    env1 |= (G.g_cnxsave.cs_confcpy) ? INF_E1_CONFCPY : 0x00;
    env1 |= G.g_cnxsave.cs_dblclick & INF_E1_DCMASK;
    env2 = (G.g_cnxsave.cs_confovwr) ? 0x00 : INF_E2_ALLOWOVW;
    env2 |= (G.g_cnxsave.cs_mnuclick) ? INF_E2_MNUCLICK : 0x00;
    switch(G.g_cnxsave.cs_datefmt)
    {
    case DATEFORM_IDT:
        env2 |= INF_E2_IDTDATE;
        break;
    case DATEFORM_DMY:
        env2 |= INF_E2_DAYMONTH;
        break;
    }
    switch(G.g_cnxsave.cs_timefmt)
    {
    case TIMEFORM_IDT:
        env2 |= INF_E2_IDTTIME;
        break;
    case TIMEFORM_24H:
        env2 |= INF_E2_24HCLOCK;
        break;
    }
    env2 |= sound(FALSE, 0xFFFF, 0)  ? 0x00 : INF_E2_SOUND;
#if CONF_WITH_VIDEL
    mode = get_videl_mode();
    if (!mode)                      /* i.e. not videl */
#endif
        mode = 0xff00 | Getrez();
    env5 = (G.g_cnxsave.cs_sort == CS_NOSORT) ? INF_E5_NOSORT : 0;
    pcurr += sprintf(pcurr,"#E %02X %02X %02X %02X %02X\r\n",
                    env1,env2,(mode>>8)&0x00ff,mode&0x00ff,env5);

    /* save windows */
    for (i = 0; i < NUM_WNODES; i++)
    {
        pws = &G.g_cnxsave.cs_wnode[i];
        ptmp = pws->pth_save;
        pcurr += sprintf(pcurr,"#W %02X %02X %02X %02X %02X %02X %02X",
                        0,pws->vsl_save,pws->x_save/gl_wchar,
                        pws->y_save/gl_hchar,pws->w_save/gl_wchar,
                        pws->h_save/gl_hchar,pws->obid_save);
        pcurr += sprintf(pcurr," %s@\r\n",(*ptmp!='@')?ptmp:"");
    }

    /*
     * reverse the ANODE list before we write it.  this ensures
     * that the generic ANODEs are written ahead of the ones
     * created for installed applications.  when we read it back
     * in, using app_alloc(TRUE) to allocate the ANODEs, the
     * generic ANODEs will once again be at the end of the list.
     */
    app_revit();

    /* save ANODE list */
    for (pa = G.g_ahead; pa; pa = pa->a_next)
    {
        switch(pa->a_type)
        {
        case AT_ISDISK:
            type = 'M';
            break;
        case AT_ISFILE:
            if (pa->a_flags & AF_WINDOW)
            {
                type = (pa->a_flags & AF_ISEXEC) ? 'I' : 'N';
                break;
            }
            if (pa->a_flags & AF_ISCRYS)
                type = (pa->a_flags & AF_ISPARM) ? 'Y' : 'G';
            else
                type = (pa->a_flags & AF_ISPARM) ? 'P' : 'F';
            break;
        case AT_ISFOLD:
            type = 'D';
            break;
        case AT_ISTRSH:     /* Trash */
            type = 'T';
            break;
        default:
            type = ' ';
        }
        pcurr += sprintf(pcurr,"#%c",type);
        if (pa->a_flags & AF_ISDESK)
            pcurr += sprintf(pcurr," %02X %02X",(pa->a_xspot/G.g_icw)&0x00ff,
                            (max(0,(pa->a_yspot-G.g_ydesk))/G.g_ich)&0x00ff);
        pcurr += sprintf(pcurr," %02X %02X",pa->a_aicon&0x00ff,pa->a_dicon&0x00ff);
        if (pa->a_flags & AF_ISDESK)
            pcurr += sprintf(pcurr," %c",pa->a_letter?pa->a_letter:' ');
        pcurr += sprintf(pcurr," %s@ %s@",pa->a_pappl,pa->a_pdata);
        if (pa->a_type == AT_ISFILE)
        {
            type = 0;
            if (pa->a_flags & AF_APPDIR)
                type |= INF_AT_APPDIR;
            if (pa->a_flags & AF_ISFULL)
                type |= INF_AT_ISFULL;
            pcurr += sprintf(pcurr," %X%02X %s@",type,pa->a_funkey,pa->a_pargs);
        }
        *pcurr++ = '\r';
        *pcurr++ = '\n';
    }
    *pcurr++ = 0x0;

    /* reverse list back */
    app_revit();

    /* calculate size */
    G.g_afsize = pcurr - gl_afile;

    /* save in memory */
    shel_put(gl_afile, G.g_afsize);

    /* save to disk */
    if (todisk)
        save_to_disk();
}