int insert_link_above(Stack_t *stack, Stack_ele_t *ele) { int move_ends; move_ends = check_ends(stack); if (stack->curr) { stack->n++; ele->down = stack->curr; ele->up = stack->curr->up; if (stack->curr->up) stack->curr->up->down = ele; stack->curr->up = ele; if ((move_ends == MOVE_TOP) || (move_ends == MOVE_BOTH)) stack->top = ele; if ((move_ends == MOVE_BOTTOM) || (move_ends == MOVE_BOTH)) stack->bottom = stack->curr; stack->curr = ele; return(1); } else if (stack->top) { return(0); // Can't determine position since curr=NULL } else { push_link(stack, ele); return(1); } }
Stack_ele_t *stack_unlink_current(Stack_t *stack, int mv_up) { Stack_ele_t *ele, *up, *down; int move_ends; move_ends = check_ends(stack); ele = stack->curr; if (ele) { stack->n--; up = ele->up; down = ele->down; if (up) up->down = down; if (down) down->up = up; if (mv_up) { stack->curr = up; } else { stack->curr = down; } if ((move_ends == MOVE_TOP) || (move_ends == MOVE_BOTH)) stack->top = down; if ((move_ends == MOVE_BOTTOM) || (move_ends == MOVE_BOTH)) stack->bottom = up; return(ele); } else { return(NULL); } }
int insert_link_below(Stack_t *stack, Stack_ele_t *ele) { int move_ends; move_ends = check_ends(stack); if (stack->curr) { stack->n++; ele->down = stack->curr->down; ele->up = stack->curr; if (stack->curr->down) stack->curr->down->up = ele; stack->curr->down = ele; if ((move_ends == MOVE_TOP) || (move_ends == MOVE_BOTH)) stack->top = stack->curr; if ((move_ends == MOVE_BOTTOM) || (move_ends == MOVE_BOTH)) stack->bottom = ele; stack->curr = ele; return(1); } else if (stack->top) { printf("insert_link_below: Can't determine position!!!!!!!! move_ends = %d\n",move_ends); return(0); // Can't determine position since curr=NULL } else { push_link(stack, ele); return(1); } }
/* to compare two strings given by a fortran routine, considering the space character as the end of the string*/ static int f_strcmp(unsigned char *s1, unsigned char *s2, int s1length, int s2length) { int i = 0; int length; if(s1length <= s2length) length = s1length; else length = s2length; while( i < length && *s1 != ' ' && *s2 != ' ' && *s1 == *s2 && *s1 != '\0' && *s2 != '\0') { s1++; s2++; i++; } if(*s1 == ' ') { fprintf(stderr, "mgilib2::f_strcmp(), before return if(*s1 == ' '), s1 => %s\n ", s1); return check_ends(s1, s2, s1length, s2length, i); } else if(*s2 == ' ') { fprintf(stderr, "mgilib2::f_strcmp(), before return if(*s2 == ' '), s2 => %s\n ", s2); return 2 + check_ends(s2, s1, s2length, s1length, i); } fprintf(stderr, "before return (*(s1) - *(s2)); s1length => %d\n ", s1length); fprintf(stderr, "before return (*(s1) - *(s2)); s2length => %d\n ", s2length); fprintf(stderr, "before return (*(s1) - *(s2)); i => %d\n ", i); fprintf(stderr, "before return (*(s1) - *(s2)); s1 => %s\n ", s1); fprintf(stderr, "before return (*(s1) - *(s2)); s2 => %s\n ", s2); return (*s1 - *s2); }