void egxp_node_add_in_order (Ecore_DList * l, Egxp_Node * n) { #ifdef EGXP_DEBUG printf("TRACE: egxp_node_add_in_order\n"); #endif assert (l && n); Egxp_Node * pn = NULL; /* before doing anything, check if there is condition, if not we add it to the end if the list */ if (n->conditions == NULL || ecore_list_nodes (l) == 0) { ecore_dlist_append (l, n); return; } /* go to the first node */ ecore_dlist_goto_first(l); while((pn = EGXP_NODE(ecore_dlist_next(l))) != NULL) { if (pn->conditions == NULL || ecore_dlist_nodes (n->conditions) > ecore_dlist_nodes(pn->conditions)) { ecore_dlist_previous(l); ecore_dlist_insert (l, n); return; } } ecore_dlist_append (l, n); }
static const char * help_reader_window_history_next(Help_Reader_Window * win) { ecore_dlist_next(win->history); help_reader_window_buttons_update(win); return ecore_dlist_current(win->history); }
void evfs_token_list_free(Ecore_DList * tokens) { evfs_uri_token *token; ecore_dlist_first_goto(tokens); while ((token = ecore_dlist_next(tokens))) { free(token->token_s); free(token); } ecore_dlist_destroy(tokens); }
evfs_uri_token * evfs_token_expect(Ecore_DList * tokens, evfs_uri_token_type type, char *tok) { evfs_uri_token *token; token = ecore_dlist_next(tokens); /*if (token) { * printf("Token string:\n"); * printf("'%s'\n", token->token_s); * } */ if (token && token->type == type && (tok == NULL || !strcmp(token->token_s, tok))) { //printf("Got expected token type, '%s'\n", token->token_s); return token; } else { ecore_dlist_previous(tokens); //printf("Didn't get expected token type, '%s'\n", token->token_s); return NULL; } }
/*We should rewrite this,use a proper parser*/ EvfsFilereference * evfs_parse_uri_single(char *uri) { evfs_uri_token *token; EvfsFilereference *ref = NULL, *new_ref = NULL, *root_ref = NULL, *bottom_ref = NULL; Ecore_DList *tokens; /*for (i=0;i<strlen(uri);i++) { * printf("URI Input: '%s'\n", uri); * } */ tokens = evfs_tokenize_uri(uri); ecore_dlist_first_goto(tokens); while ((token = ecore_dlist_next(tokens))) { //printf("Token str: '%s'\n", token->token_s); } ecore_dlist_first_goto(tokens); start_uri_section: new_ref = NEW(EvfsFilereference); if (!ref) { new_ref->parent = NULL; } else { new_ref->parent = ref; } token = evfs_token_expect(tokens, EVFS_URI_TOKEN_KEYWORD, NULL); if (token) { /*Should be a plugin, assume it is (bad) */ /*Patch for posix->file*/ if (!strcmp(token->token_s, "posix")) { new_ref->plugin_uri = strdup("file"); } else { new_ref->plugin_uri = strdup(token->token_s); } } else { printf("Couldn't get a plugin uri, token was (instead): '%s'\n", token->token_s); return NULL; } token = evfs_token_expect(tokens, EVFS_URI_TOKEN_OPERATOR, "://"); /* '://' */ /*Auth included? */ token = evfs_token_expect(tokens, EVFS_URI_TOKEN_OPERATOR, "/"); if (!token) { /*Looks like we have an auth structure... */ token = evfs_token_expect(tokens, EVFS_URI_TOKEN_STRING, NULL); if (token) { //printf("Username is '%s'\n", token->token_s); new_ref->username = strdup(token->token_s); } if (!(token = evfs_token_expect(tokens, EVFS_URI_TOKEN_OPERATOR, ":"))) return NULL; /* ':' */ token = evfs_token_expect(tokens, EVFS_URI_TOKEN_STRING, NULL); if (token) { //printf("Password is '%s'\n", token->token_s); new_ref->password = strdup(token->token_s); } if (!(token = evfs_token_expect(tokens, EVFS_URI_TOKEN_OPERATOR, "@"))) return NULL; /* '@' */ if (!(token = evfs_token_expect(tokens, EVFS_URI_TOKEN_OPERATOR, "/"))) return NULL; /* '/' */ } if (token) { new_ref->path = malloc(strlen(token->token_s) + 1); strcpy(new_ref->path, token->token_s); } else { new_ref->path = calloc(1, 1); } /*Blindly get the rest of the tokens and append */ while ((token = ecore_dlist_next(tokens))) { if (!strcmp(token->token_s, "#")) break; new_ref->path = realloc(new_ref->path, strlen(new_ref->path) + strlen(token->token_s) + 1); new_ref->path = strcat(new_ref->path, token->token_s); } if (token && !strcmp(token->token_s, "#")) { ref = new_ref; if (!root_ref) root_ref = new_ref; goto start_uri_section; } if (!root_ref) root_ref = new_ref; bottom_ref = new_ref; evfs_token_list_free(tokens); return bottom_ref; }
Ecore_DList * evfs_tokenize_uri(char *uri) { Ecore_DList *tokens = ecore_dlist_new(); Ecore_DList *reserved = ecore_dlist_new(); Ecore_DList *plugin = ecore_dlist_new(); char *dup_uri = malloc(strlen(uri) + 2); /*dup_uri = realloc(dup_uri, strlen(uri)+2); * strcat(dup_uri," "); */ char *l_uri = dup_uri; int solid_alpha = 0; int new_alpha = 0; evfs_uri_token *token; char *cmp; char tmp_tok[255]; /*This need to be longer? */ int i = 0; int j = 1; int len = 0; char tagged = 0; snprintf(dup_uri, strlen(uri) + 1, "%s ", uri); ecore_dlist_append(plugin, "smb"); /*Shift these to register when a plugin registers */ ecore_dlist_append(plugin, "file"); ecore_dlist_append(plugin, "tar"); ecore_dlist_append(plugin, "bzip2"); ecore_dlist_append(plugin, "ftp"); ecore_dlist_append(plugin, "gzip"); ecore_dlist_append(plugin, "sftp"); ecore_dlist_append(plugin, "posix"); ecore_dlist_append(plugin, "vfolder"); ecore_dlist_append(plugin, "trash"); ecore_dlist_append(reserved, "://"); ecore_dlist_append(reserved, "@"); ecore_dlist_append(reserved, "/"); ecore_dlist_append(reserved, ":"); ecore_dlist_append(reserved, "#"); ecore_dlist_append(reserved, ";"); //printf ("Lexing '%s'\n", dup_uri); //printf("Strlen(uri): %d\n", strlen(uri)); while (j <= strlen(dup_uri)) { new_alpha = (isalnum(l_uri[i]) || l_uri[i] == '.'); len = 0; tagged = 0; strncpy(tmp_tok, l_uri, 3); tmp_tok[3] = '\0'; //printf("Current token is: '%s'\n", tmp_tok); /*Check if it's an operator */ ecore_dlist_first_goto(reserved); while ((cmp = ecore_dlist_next(reserved))) { if (!strncmp(tmp_tok, cmp, strlen(cmp))) { //printf("Found token (operator) %s, added %d to l_uri\n", cmp, strlen(cmp)); l_uri += strlen(cmp); len = strlen(cmp); tagged = 1; //printf("L_URI becomes '%s'\n", l_uri); token = NEW(evfs_uri_token); token->token_s = strdup(cmp); token->type = EVFS_URI_TOKEN_OPERATOR; ecore_dlist_append(tokens, token); bzero(tmp_tok, 255); goto cont_loop; } } /*Check if it's a keyword */ strncpy(tmp_tok, l_uri, i); tmp_tok[i] = '\0'; //printf("Current token (keyword match) is: '%s'\n", tmp_tok); ecore_dlist_first_goto(plugin); while ((cmp = ecore_dlist_next(plugin))) { if (!strncmp(tmp_tok, cmp, strlen(cmp))) { //printf("Found token (keyword) %s, added %d to l_uri\n", cmp, strlen(cmp)); l_uri += strlen(cmp); tagged = 2; token = NEW(evfs_uri_token); token->token_s = strdup(cmp); token->type = EVFS_URI_TOKEN_KEYWORD; ecore_dlist_append(tokens, token); bzero(tmp_tok, 255); goto cont_loop; /*Eww goto - but we're in two while loops */ } } if (solid_alpha && !new_alpha) { strncpy(tmp_tok, l_uri, i); /*There is a lexer position bug for now- this will fix it FIXME */ if (tmp_tok[0] == '\0') goto lexer_done; tmp_tok[i] = '\0'; token = NEW(evfs_uri_token); token->token_s = strdup(tmp_tok); token->type = EVFS_URI_TOKEN_STRING; ecore_dlist_append(tokens, token); bzero(tmp_tok, 255); l_uri += i; tagged = 3; } solid_alpha = new_alpha; cont_loop: if (tagged > 0) { if (tagged == 1 || tagged == 2) j += strlen(cmp); else j += i; i = 0; } i++; //printf("i:J (%d:%d) - %d\n", i,j,strlen(dup_uri)); } lexer_done: /*This is really evil - we assume the last token is a string */ /*There is something wrong with the offsets above if this is * the case*/ if (strlen(tmp_tok) > 0) { printf("libevfs.c evil - FIXME\n"); token = NEW(evfs_uri_token); token->token_s = strdup(tmp_tok); token->type = EVFS_URI_TOKEN_STRING; ecore_dlist_append(tokens, token); } ecore_dlist_destroy(plugin); ecore_dlist_destroy(reserved); free(dup_uri); return tokens; }