예제 #1
0
파일: main.c 프로젝트: oleiade/Ash
static void	initsh(t_lexlist **list,
                   t_list **histo,
                   t_sllist **myenv)
{
    *list = NULL;
    *histo = get_hist_from_file(HISTORY_FILE, myenv);
    if (!*histo)
        *histo = init_history();
    update_alias(1, NULL);
    load_conf(myenv);
    auto_comp(NULL, NULL, 0, *myenv);
    update_history(*histo);
}
예제 #2
0
char *localcommand(char *line)
{
    char *retstr;
    if ( strcmp(line,"list") == 0 )
    {
        if ( (retstr= relays_jsonstr(0,0)) != 0 )
        {
            printf("%s\n",retstr);
            free(retstr);
        }
        return(0);
    }
    else if ( strncmp(line,"alias",5) == 0 )
    {
        update_alias(line+6);
        return(0);
    }
    else if ( strcmp(line,"help") == 0 )
    {
        printf("local commands:\nhelp, list, alias <name> <any string> then #name is expanded to <any string>\n");
        printf("alias expansions are iterated, so be careful with recursive macros!\n\n");
        
        printf("<plugin name> <method> {json args} -> invokes plugin with method and args, \"myipaddr\" and \"NXT\" are default attached\n\n");
        printf("network commands: default timeout is used if not specified\n");
        printf("relay <plugin name> <method> {json args} -> will send to random relay\n");
        printf("peers <plugin name> <method> {json args} -> will send all peers\n");
        printf("!<plugin name> <method> {json args} -> sends to random relay which will send to all its peers and combine results.\n\n");
        
        printf("publish shortcut: pub <any string> -> invokes the subscriptions plugin with publish method and all subscribers will be sent <any string>\n\n");
        
        printf("direct to specific relay needs to have a direct connection established first:\nrelay direct or peers direct <ipaddr>\n");
        printf("in case you cant directly reach a specific relay with \"peers direct <ipaddr>\" you can add \"!\" and let a relay broadcast\n");
        printf("without an <ipaddr> it will connect to a random relay. Once directly connected, commands are sent by:\n");
        printf("<ipaddress> {\"plugin\":\"<name>\",\"method\":\"<methodname>\",...}\n");
        printf("responses to direct requests are sent through as a subscription feed\n\n");
        
        printf("\"relay join\" adds your node to the list of relay nodes, your node will need to stay in sync with the other relays\n");
        //printf("\"relay mailbox <64bit number> <name>\" creates synchronized storage in all relays\n");
        return(0);
    }
    return(line);
}
예제 #3
0
파일: alias.c 프로젝트: lljllj122/MyShell
void exe_alias(char **args, int argc, struct alias_List * list)
{	
	char buf[256+1];
	

	if(argc==1){
		//show the alias list.
		// printf("%s\n", "show alias");
		show_alias(list);
		return;
	}

	else if(argc==2){
		if(strcmp(args[1],"-a")==0){
			// add here if have time!
			// remove all the node in alias list
			alias_List_remove_all(list);
			return;
		

		}else{
			// printf("%s\n", "add or check alias");
			if(strlen(args[1])>256){
				fprintf(stderr, "%s\n", "alias: too long");
				return;
			}
			strncpy(buf,args[1],strlen(args[1])+1);
			buf[strlen(args[1])]='\0';

			char *left;
			char *right;
			parseAlias(buf,&left,&right);


			if(!right){
				//add new
				show_alias_one(list,left);


			}else{
				// printf("%s\n", "add");
				//add the alias to the list
				if(check_alias(list,left)){
					update_alias(list,left,right);
				}else{
					char *left_value = calloc(strlen(left)+1,sizeof(char));
					strncpy(left_value,left,strlen(left)+1);
					char *right_value = calloc(strlen(right)+1,sizeof(char));
					strncpy(right_value,right,strlen(right)+1);
					alias_List_push(list,left_value,right_value);

				}
				
			}

		}
		
	}
	

	else {
		fprintf(stderr, "%s\n", "format error");
	}

}