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