landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 1 | /* vi: set ts=4 :*/ |
| 2 | /* Toybox infrastructure. |
| 3 | * |
| 4 | * Copyright 2006 Rob Landley <rob@landley.net> |
| 5 | * |
| 6 | * Licensed under GPL version 2, see file LICENSE in this tarball for details. |
| 7 | */ |
| 8 | |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 9 | #include <limits.h> |
| 10 | #include <stdarg.h> |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 11 | #include <stdio.h> |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 14 | #include <strings.h> |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 15 | #include <unistd.h> |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 16 | |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 17 | #include "lib/lib.h" |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 18 | |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 19 | int cd_main(void); |
landley | cd9dfc3 | 2006-10-18 18:38:16 -0400 | [diff] [blame^] | 20 | int df_main(void); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 21 | int exit_main(void); |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 22 | int toybox_main(void); |
| 23 | int toysh_main(void); |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 24 | |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 25 | #define TOYFLAG_USR (1<<0) |
| 26 | #define TOYFLAG_BIN (1<<1) |
| 27 | #define TOYFLAG_SBIN (1<<2) |
| 28 | #define TOYMASK_LOCATION ((1<<4)-1) |
| 29 | |
| 30 | #define TOYFLAG_NOFORK (1<<4) |
| 31 | |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 32 | extern struct toy_list { |
| 33 | char *name; |
| 34 | int (*toy_main)(void); |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 35 | int flags; |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 36 | } toy_list[]; |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 37 | struct toy_list *toy_find(char *name); |
landley | cd9dfc3 | 2006-10-18 18:38:16 -0400 | [diff] [blame^] | 38 | void toy_init(struct toy_list *which, char *argv[]); |
| 39 | void toy_exec(char *argv[]); |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 40 | |
| 41 | // Global context for this applet. |
| 42 | |
| 43 | extern struct toy_context { |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 44 | struct toy_list *which; // Which entry in toy_list is this one? |
| 45 | int exitval; // Value error_exit feeds to exit() |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 46 | int argc; |
| 47 | char **argv; |
| 48 | char buf[4096]; |
| 49 | } toys; |
| 50 | |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 51 | struct exit_data {;}; |
| 52 | struct cd_data {;}; |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 53 | struct toybox_data {;}; |
| 54 | struct toysh_data {;}; |
| 55 | struct df_data {;}; |
| 56 | |
| 57 | union toy_union { |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 58 | struct exit_data exit; |
| 59 | struct cd_data cd; |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 60 | struct toybox_data toybox; |
| 61 | struct toysh_data toysh; |
| 62 | struct df_data df; |
| 63 | } toy; |
| 64 | |
landley | cd9dfc3 | 2006-10-18 18:38:16 -0400 | [diff] [blame^] | 65 | // Pending the addition of menuconfig... |
| 66 | |
| 67 | #define CFG_TOYS_FREE 0 |
| 68 | |
| 69 | #define CFG_TOYSH_TTY 0 // Terminal control |
| 70 | #define CFG_TOYSH_JOBCTL 0 // &, fg, bg, jobs. ctrl-z with tty. |
| 71 | #define CFG_TOYSH_FLOWCTL 0 // if, while, for, functions { } |
| 72 | #define CFG_TOYSH_ENVVARS 0 // Environment variables |
| 73 | #define CFG_TOYSH_LOCVARS 0 // Local, synthetic, fancy prompts, set, $? |
| 74 | #define CFG_TOYSH_PIPES 0 // Pipes and redirects: | > < >> << && || & () ; |