void mouse_test(char *argv[], int argc) { set_opts(STDOUT, REQUEST_SET_COLOR, build_colour(COLOR_BLACK, COLOR_LIGHT_GREY)); clear(argv, argc); hang_for_click(); while (1) { if (!waiting_click) { set_opts(STDOUT, REQUEST_RESET, 0); clear(argv, argc); break; } } }
int light_command(int fd, char *argv[]) { int light = atoi(argv[0]) - 1; if (light > 2 || light < 0) { fprintf(stderr, "light can only be 1-3\n"); return -1; } struct Command cmd = { HEAD, 0, 0, 0 }; cmd.light = (char)light; int n = set_opts(&argv[1], &cmd); if (n != 0) { return -1; } if (cmd.cmd == CMD_ALL_CLEAR) { fprintf(stderr, "clear only works with 'all'"); return -1; } cmd.cmd -= 0x10; n = write(fd, &cmd, 4); if (n != 4) { perror("light_command: failed to send command"); return -1; } return 0; }
void setcolor(char** args, int argc) { int fore, back; if (argc != 2) { printf("usage: setcolor foreground background\n"); printf("\nColors are:\n"); printf("\tdarker | lighter\n"); printf("\tblack: 0 | light gray: 8\n"); printf("\tblue: 1 | celurean: 9\n"); printf("\tgreen: 2 | light green: 10\n"); printf("\tcyan: 3 | light cyan: 11\n"); printf("\tred: 4 | light red: 12\n"); printf("\tmagenta 1: 5 | magenta 2: 13\n"); printf("\tbrown: 6 | yellow: 14\n"); printf("\tgray 1: 7 | white: 15\n"); printf("\nnote: you might not choose two of the same.\n"); return; } fore = atoi(args[0]); back = atoi(args[1]); if (fore == back) { fprintf(STDERR, "Aaaand you chose two of the same...\n Nope.\n"); return; } if (fore >= 16 || back >= 16 || fore < 0 || back < 0) { fprintf(STDERR, "Invalid parameter: %d, %d\n", fore, back); return; } set_opts(STDOUT, REQUEST_SET_COLOR, build_colour(fore, back)); clear(args, argc); }
void mouse_sensitivity(char* argv[], int argc) { uint16_t sensitivty; if (argc != 1) { printf("usage: mouse_sensitivity [sensitivty]\n"); printf("0 < sensitivty <= 100\n"); return; } sensitivty = atoi(argv[0]); if (sensitivty < 0 || sensitivty > 100) { printf("usage: mouse_sensitivity [sensitivty]\n"); printf("0 < sensitivty <= 100\n"); return; } set_opts(STDMOUSE, REQUEST_SENSITIVTY, 101-sensitivty); }
void play_sound(char *argv[], int argc) { char songs[4096]; song_t parsed_songs[20]; int song_number = 0; int choice = -1; int i = 0; note_t current_note; uint32_t one_note_length; printf("Welcome to Sound Player 1.0\n"); printf("Fetching sounds...\n"); fgets(STDFILE, songs, 4096); printf("Parsing Sounds...\n"); song_number = parse_sounds(songs, parsed_songs); printf("Available Tunes are: \n"); for (int i = 0; i < song_number; i++) { printf("%d. %s\n", i+1, parsed_songs[i].title); } while (choice < 0) { printf("Insert a number from the list: "); scanf("%d", &choice); if (choice > song_number) choice = -1; } printf("Default Duration: %d\n", parsed_songs[choice-1].default_duration); printf("Default Octave: %d\n", parsed_songs[choice-1].default_octave); printf("Beat: %d\n", parsed_songs[choice-1].beat); printf("Read Notes: %d\n", parsed_songs[choice-1].read_notes); one_note_length = 60000 / parsed_songs[choice-1].beat * 4; for (; i < parsed_songs[choice-1].read_notes; i++) { current_note = parsed_songs[choice-1].notes[i]; beepwo( one_note_length / current_note.duration, base_frequencies[current_note.pitch] * (1 << current_note.octave) ); } set_opts(STDFILE, REQUEST_RESET, 0); }
int all_command(int fd, char *argv[]) { struct Command cmd = { HEAD, 0, 0, 0 }; int n = set_opts(argv, &cmd); if (n != 0) { return -1; } n = write(fd, &cmd, 4); if (n != 4) { perror("all_command: failed to send command"); return -1; } return 0; }
void credits(char *argv[], int argc) { char songs[4096]; song_t parsed_songs[20]; int choice = -1; int i = 0, j = 0; note_t current_note; uint32_t one_note_length; char **s = credit_text; clear(argv, argc); for (j = 0; j <= 25; j++){ printf("\n"); } fgets(STDFILE, songs, 4096); parse_sounds(songs, parsed_songs); // StarWars es la 6 choice = 6; one_note_length = 60000 / parsed_songs[choice-1].beat * 4; for (; i < parsed_songs[choice-1].read_notes; i++) { if (i % 11 == 0) { s = credit_text; } current_note = parsed_songs[choice-1].notes[i]; for (j = 0; j < padding(*s); j++) { putc(' '); } printf("%s\n", *s); s++; beepwo( one_note_length / current_note.duration, base_frequencies[current_note.pitch] * (1 << current_note.octave) ); } set_opts(STDFILE, REQUEST_RESET, 0); }
int main(int argc,char** argv,char *envp[]) { int a; f = stdin; if((a = set_opts(argc,argv)) < argc) f = fopen(argv[a],"r"); if(argfile != NULL) read_file(argfile); //printf("%d %d %s\n",ignore_errors,verbose,argfile); char input[128]; while(fgets(input,sizeof(input),f)!=NULL) { unsigned int j = 0; //input[strlen(input)-1] = '\0'; find_first_comment(input); char* toks[64]; char* token; token = strtok(input," "); while(token !=NULL) { toks[j++] = token; token = strtok(NULL," "); } toks[j] = NULL; char **args; if(argfile != NULL) args = append_args(j,toks); else args = toks; if(verbose) print_argv(args); int exitstat; switch(child_pid = fork()) { case -1: exit(1); case 0: child_stat = execvp(args[0],args); exit(child_stat); default: if (timeout) { exitstat = th(0); milliseconds = 0; } else { waitpid(child_pid, &child_stat,0); exitstat = WEXITSTATUS(child_stat); } if(argfile != NULL) free(args); } if (exitstat) { if(ignore_errors) error_seen = 1; else { if(exitstat == -2) exit(2); else exit(1); } } } return error_seen; }
int main(int argc,char** argv,char *envp[]) { int a; f = stdin; if((a = set_opts(argc,argv)) < argc) f = fopen(argv[a],"r"); if(argfile != NULL) read_file(argfile); //printf("%d %d %s\n",ignore_errors,verbose,argfile); char input[128]; int stat = 0; while(fgets(input,sizeof(input),f)!=NULL) { unsigned int j = 0; input[strlen(input)-1] = '\0'; if(input[0] !='#') { char* toks[64]; char* token; token = strtok(input," "); while(token !=NULL) { toks[j++] = token; token = strtok(NULL," "); } toks[j] = NULL; char **args; if(argfile != NULL) args = append_args(j,toks); else args = toks; if(verbose) print_argv(args); struct itimerval new; switch(child_pid = fork()) { case -1: exit(1); case 0: stat = execvp(args[0],args); exit(stat); default: /* memset(&sa,0,sizeof(sa)); sa.sa_handler = timeout_handler; sigaction(SIGALRM,&sa,NULL); */ signal(SIGALRM,timeout_handler); ualarm(1000,0); /* new.it_interval.tv_usec = 0; new.it_interval.tv_sec = 0; new.it_value.tv_sec = 1; new.it_value.tv_usec =(long int)1000*ms; setitimer(ITIMER_REAL, &new,NULL); */ waitpid(child_pid,&stat,0); if(argfile != NULL) free(args); } int exitstat = WEXITSTATUS(stat); if (exitstat) { if(ignore_errors) error_seen = 1; else exit(1); } } }
void clear(char** args, int argc) { set_opts(STDOUT, REQUEST_CLEAR_SCREEN, 0); }
void mouse_show(char* argv[], int argc) { set_opts(STDMOUSE, REQUEST_SHOW, 0); }
void mouse_hide(char* argv[], int argc) { set_opts(STDMOUSE, REQUEST_HIDE, 0); }