void rra(t_stack *stack, int x) { t_ilist *tmp; if (stack->number_in_a == 2) quick_swap(stack); else { tmp = stack->a_begin; stack->a_begin = stack->a_begin->next; stack->a_begin->prev = NULL; i_list_push(&stack->a_begin, tmp); stack->a_end = tmp; } ++stack->n_moves; if (x && !stack->no_command) s_list_push(&stack->moves, s_list_new(ft_strdup("rra"))); if (stack->status && x) { print_stack(&stack->a_begin, stack->number_in_a, 'a', stack->color); print_stack(&stack->b_begin, stack->number_in_b, 'b', stack->color); if (!stack->no_command) print_command(stack); write(1, "\n", 1); } }
/* * Create a new string list. */ S_API s_str_list *s_str_list_new(s_erc *error) { s_str_list *self; S_CLR_ERR(error); self = s_list_new(&s_str_list_compare_fp, &s_str_list_free_fp, error); if (S_CHK_ERR(error, S_CONTERR, "s_str_list_new", "Call to \"s_list_new\" failed")) return NULL; return self; }
void sa(t_stack *stack, int x) { int tmp; tmp = stack->a_end->data; stack->a_end->data = stack->a_end->prev->data; stack->a_end->prev->data = tmp; ++stack->n_moves; if (x && !stack->no_command) s_list_push(&stack->moves, s_list_new(ft_strdup("sa"))); if (stack->status && x) { print_stack(&stack->a_begin, stack->number_in_a, 'a', stack->color); print_stack(&stack->b_begin, stack->number_in_b, 'b', stack->color); if (!stack->no_command) print_command(stack); write(1, "\n", 1); } }
void pb(t_stack *stack) { if (!stack->number_in_a) return ; ++stack->number_in_b; --stack->number_in_a; if (stack->number_in_a == 1) get_a_semi_empty(stack); else if (stack->number_in_a == 0) get_a_empty(stack); else push_to_a(stack); ++stack->n_moves; if (!stack->no_command) s_list_push(&stack->moves, s_list_new(ft_strdup("pb"))); if (stack->status) { print_stack(&stack->a_begin, stack->number_in_a, 'a', stack->color); print_stack(&stack->b_begin, stack->number_in_b, 'b', stack->color); if (!stack->no_command) print_command(stack); write(1, "\n", 1); } }
int main (int argc, char **argv) { char *temp; int i; char *global_config_file = NULL; char tmp[128]; FILE *fp = NULL; /* Save our program name - for error messages */ temp = strrchr (argv[0], '/'); MyName = temp ? temp + 1 : argv[0]; for (i = 1; i < argc && *argv[i] == '-'; i++) { if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help")) usage (); else if (!strcmp (argv[i], "-v") || !strcmp (argv[i], "--version")) version (); else if (!strcmp (argv[i], "-w") || !strcmp (argv[i], "--window")) i++; else if (!strcmp (argv[i], "-c") || !strcmp (argv[i], "--context")) i++; else if (!strcmp (argv[i], "-f") && i + 1 < argc) global_config_file = argv[++i]; } /* Dead pipe == dead AfterStep */ signal (SIGPIPE, DeadPipe); signal (SIGSEGV, DeadPipe); signal (SIGINT, DeadPipe); if ((dpy = XOpenDisplay ("")) == NULL) { fprintf (stderr, "%s: couldn't open display %s\n", MyName, XDisplayName ("")); exit (1); } set_current_X_display (dpy); screen = DefaultScreen (dpy); /* connect to AfterStep */ temp = module_get_socket_property (RootWindow (dpy, screen)); fd[0] = fd[1] = module_connect (temp); XFree (temp); if (fd[0] < 0) { fprintf (stderr, "%s: unable to establish connection to AfterStep\n", MyName); exit (1); } temp = safemalloc (9 + strlen (MyName) + 1); sprintf (temp, "SET_NAME %s", MyName); SendInfo (fd, temp, None); free (temp); x_fd = XConnectionNumber (dpy); fd_width = GetFdWidth (); XSetErrorHandler (error_handler); if (global_config_file != NULL) temp = PutHome (global_config_file); else { memset (tmp, 128, '\0'); sprintf (tmp, "%s/Gnome", AFTER_DIR); temp = PutHome (tmp); if ((fp = fopen (temp, "r")) == NULL) { sprintf (tmp, "%s/Gnome", AFTER_SHAREDIR); free (temp); temp = PutHome (tmp); } } if (fp) fclose (fp); parse_config (temp); free (temp); gnome_compliance_init (); window_list = s_list_new (); set_as_mask ((long unsigned) mask_reg); SendInfo (fd, "Send_WindowList\n", 0); XSelectInput (dpy, root_win, PropertyChangeMask | SubstructureNotifyMask); XSelectInput (dpy, gnome_win, PropertyChangeMask); EndLessLoop (); return 0; }