libk  Check-in [8d478e0b3c]

Overview
Comment:add posix signal numbers; continue work on kcli
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8d478e0b3c5cfb908682422070cf5bb969d92752b74ee24b30240b4841318464
User & Date: lexi on 2019-11-19 05:06:20
Other Links: manifest | tags
Context
2019-11-19
05:23
specialize signal numbers for MIPS check-in: 164a1a5cfe user: lexi tags: trunk
05:06
add posix signal numbers; continue work on kcli check-in: 8d478e0b3c user: lexi tags: trunk
2019-11-01
07:52
Disable PDF docs on NixOS. As it seems groff PDF support is currently broken on NixOS (https://github.com/NixOS/nixpkgs/issues/53056), disable the building of PDFs in the NixOS build. check-in: 9408112a57 user: glowpelt tags: trunk
Changes

Modified arch/posix.h from [4c89ca109f] to [093468646d].

    39     39   #elif KVos == KA_os_fbsd
    40     40   	posix_flag_anonymous = 0x1000,
    41     41   #endif
    42     42   
    43     43   	/* platform flags */
    44     44   	posix_flag_linux_hugetlb = 0x40000
    45     45   };
           46  +
           47  +enum posix_signal {
           48  +	/* these numbers appear to be consistent across all
           49  +	 * platforms; we may have to specialize them if this
           50  +	 * assumption turns out to be untrue however. */
           51  +	posix_signal_hangup = 1,
           52  +	posix_signal_interrupt = 2,
           53  +	posix_signal_quit = 3,
           54  +	posix_signal_illegal = 4,
           55  +	posix_signal_trap = 5,
           56  +	posix_signal_abort = 6,
           57  +	posix_signal_bus = 7,
           58  +	posix_signal_float = 8,
           59  +	posix_signal_kill = 9,
           60  +	posix_signal_user_a = 10,
           61  +	posix_signal_user_b = 12,
           62  +	posix_signal_segfault = 11,
           63  +	posix_signal_pipe = 13,
           64  +	posix_signal_alarm = 14,
           65  +	posix_signal_terminate = 15,
           66  +	posix_signal_stack_fault = 16,
           67  +	posix_signal_child = 17,
           68  +	posix_signal_continue = 18,
           69  +	posix_signal_stop = 19,
           70  +	posix_signal_terminal_stop = 20,
           71  +	posix_signal_tty_input = 21,
           72  +	posix_signal_tty_output = 22,
           73  +	posix_signal_io_urgent = 23,
           74  +	posix_signal_limit_cpu = 24,
           75  +	posix_signal_limit_space = 25,
           76  +	posix_signal_vt_alarm = 26,
           77  +	posix_signal_profile = 27,
           78  +	posix_signal_winch = 28,
           79  +	posix_signal_poll = 29,
           80  +	posix_signal_power = 30,
           81  +	posix_signal_system = 31,
           82  +};
    46     83   
    47     84   #endif
    48     85   #ifdef KFplatform_define_types
    49     86   
    50     87   /* platform types */
    51     88   
    52     89   typedef s64 k_platform_syscall_return;

Modified mod/kcli/cli.h from [5126e2cc55] to [fa27906c88].

    71     71   
    72     72   typedef enum kcli_cond {
    73     73   	kcli_cond_ok = kcli_cond_id,
    74     74   	kcli_cond_extra /* parse succeded, but arguments or
    75     75   	                   flags were left over */,
    76     76   	kcli_cond_fail /* unspecified error */,
    77     77   	kcli_cond_parse /* bad syntax, parse failed */,
           78  +	kcli_cond_spec /* the configuration structure is invalid */,
    78     79   	kcli_cond_overlong /* a string in the configuration structures is longer than allowed */,
    79     80   } kcli_cond;
    80     81   
    81     82   typedef enum kcli_flag {
    82     83   	kcli_flag_off = 0,
    83     84   	kcli_flag_on = 1,
    84     85   } kcli_flag;

Modified mod/kcli/kcli.md from [0390b41ce1] to [5e7f6f38dd].

     1      1   # kcli
     2      2   **kcli** is a module that implements common routines used by command-line utilities, such as option parsing, usage display, and more.
     3      3   
     4      4   # syntax
     5         -kcli implements the unspoken standard for command line parsing that is adhered to by many UNIX programs. it operates on an array of tokens, whose role depends on their content and on preceeding flags. note that in flag names, dashes and underscores are equivalent. this is to prevent obnoxious behavior and enable the macros to define multi-word long flags.
            5  +kcli implements the unwritten standard for command line parsing that is adhered to by many UNIX programs. it operates on an array of tokens, whose role depends on their content and on preceeding flags. note that in flag names, dashes and underscores are equivalent. this is to prevent obnoxious behavior and enable the macros to define multi-word long flags.
     6      6   
     7      7   1. if the argument `--` preceded the current argument, it is interpreted as a parameter.
     8      8   2. if an argument begins with `-` and is followed by any symbol besides `-`, the remainder of the its characters are interpreted as short flags.
     9      9   3. if an argument consists solely of `--`, it is ignored, and all further arguments are treated as parameters regardless of their form.
    10         -4. if an argument begins with `--` and is longer than two characters, it is interpreted as a long flag.
           10  +4. if an argument begins with `--` is longer than two characters, and does not begin with `--@`, it is interpreted as a long flag.
    11     11   5. if a flag takes a parameter, the cursor is incremented and the field it points to is interpreted as its parameter. if there are not enough arguments, parse fails.
    12     12   6. if an argument consists solely of `@`, it is treated as in step 7, except flags and parameters are read from standard in.
    13     13   7. if an argument begins with `@`, the remainder is interpreted as a filename. this file is loaded and interpreted according to this same set of rules, where spaces separate each parameter, and double or single quote marks can be used to escape strings. newlines are ignored.
    14         -8. if an argument consists solely of `=@`, it is treated as in step 9, except flags and parameters are read from standard in.
    15         -9. if an argument begins with `=@`, the remainder is interpreted as a filename. this file is loaded and interpreted according to this same set of rules, where newlines separate each parameter.
    16         -8. if an argument consists solely of `:@`, lines will be read from stdin and interpreted as individual parameters, not as flags.
    17         -8. if an argument begins with `:@`, the remainder is interpreted as a filename. all of the file's lines will be interpreted as individual parameters, not as flags.
    18         -10. if no other rules apply, the argument is added to the parameter list.
           14  +8. if an argument consists solely of `-@`, it is treated as in step 11, except flags and parameters are read from standard in.
           15  +9. if an argument consists solely of `--@`, lines will be read from stdin and interpreted as individual parameters, not as flags.
           16  +10. if an argument begins with `--@`, the remainder is interpreted as a filename. all of the file's lines will be interpreted as individual parameters, not as flags.
           17  +11. if an argument begins with `-@`, the remainder is interpreted as a filename. this file is loaded and interpreted under the assumption that newlines separate each parameter.
           18  +12. if no other rules apply, the argument is added to the parameter list.
    19     19   
    20     20   **note:** in the future, `kcore` will parse arguments at startup before passing them on to the application. all libk control arguments are prefixed with `-:`. these will not be passed onto the application, and so will not be available for kcli to parse.
    21     21   
    22     22   consider the following examples:
    23     23   1. `--no-arg-flag --arg-flag --other-flag` will set the flag `no-arg-flag`, and set the field `arg-flag` to `"--other-flag"`.
    24     24   2. if `-a` names a flag and `-b` and `-c` name string fields, `-abc b-field-value c-field-value parameter` sets the short flag `a`, set the field `b` to `"b-field-value"`, set `c` to `"c-field-value"`, and add the parameter `parameter`
    25     25   3. `-s --long @args -- -s --long @args` sets the flags `s`, `long`, and parses the file `args` for further parameters, then adds the parameters `"-s"``"--long"``"@args"` to the parameter list.

Modified mod/kcli/parse.fn.c from [1d4ed1c3cd] to [ff83a12d45].

     1      1   #include <k/cli.h>
     2      2   
     3      3   kcli_cond
     4      4   kcli_parse(kcli_set prg) {
            5  +	bool no_more_opts = false;
            6  +	const kcli_param* param = prg.params;
            7  +
            8  +	for (sz i = 0; (i < prg.argc) && (prg.args[i] != null); ++i) {
            9  +		if (no_more_opts) goto is_param;
           10  +
           11  +		const char* const arg = prg.args[i];
           12  +		if (arg[0] == '-') {
           13  +			if(arg[1] == '-') {
           14  +				if (arg[2] == 0) { no_more_opts = true; continue; }
           15  +				else if (arg[2] == '@') {
           16  +					// TODO: implement reading parameters from files
           17  +					continue;
           18  +				} else goto is_long_opt;
           19  +			} else if (arg[1] == '@') {
           20  +				// TODO: implement newline-separated file reading behavior
           21  +				continue;
           22  +			} else if (arg[1] == 0) {
           23  +				goto is_param;
           24  +			} else {
           25  +				goto is_short_opt;
           26  +			}
           27  +		} else if (arg[0] == '@') {
           28  +			// TODO: implement parsing file for options and parameters
           29  +			continue;
           30  +		} else {
           31  +			goto is_param;
           32  +		}
     5     33   
           34  +		is_short_opt: {
           35  +			continue;
           36  +		}
           37  +		is_long_opt: {
           38  +			continue;
           39  +		}
           40  +		is_param: {
           41  +			void* val = param -> val;
           42  +			if (param -> kind & kcli_param_int) {
           43  +				ubyte base = param->kind & ~kcli_param_int;
           44  +				/* TODO: parse integer */
           45  +			} else switch (param -> kind) {
           46  +				case kcli_param_none: continue;
           47  +				case kcli_param_string: *(char const**)val = arg; break;
           48  +				case kcli_param_enum: /* TODO */ break;
           49  +				default: return kcli_cond_spec;
           50  +			}
           51  +		}
           52  +	}
     6     53   }

Modified mod/knum/num.h from [982620d249] to [91c37b49e7].

    14     14   
    15     15   	/* error states */
    16     16   	kncond_fail,
    17     17   	kncond_fail_io,
    18     18   	kncond_overflow,
    19     19   	kncond_underflow,
    20     20   	kncond_bad_domain,
           21  +	kncond_bad_base,
           22  + 
    21     23   } kncond;
    22     24   
    23     25   /* this "hard" random number generator
    24     26    * returns a block of random data that
    25     27    * can be used safely in cryptographic
    26     28    * pseudorandom number algorithms such
    27     29    * as e.g. knrands() */
................................................................................
    57     59    * fixed point & floating point numbers
    58     60    * should also be added eventually.
    59     61    * note that these functions use either
    60     62    * two's complement or one's complement
    61     63    * for signed */
    62     64   
    63     65   typedef enum knmode {
    64         -	knmode_saturate = 0x0001, /* 0b001 */
    65         -	knmode_wrap     = 0x0002, /* 0b010 */
    66         -	knmode_fail     = 0x0003, /* 0b011 */
           66  +	/* knmode operations may be or'd with a base;
           67  +	 * base will be inferred by prefix otherwise */
           68  +	knmode_saturate = 0x0001 << 7, /* 0b001 */
           69  +	knmode_wrap     = 0x0002 << 7, /* 0b010 */
           70  +	knmode_fail     = 0x0003 << 7, /* 0b011 */
    67     71   
    68         -	knmode_signed   = 1 << 2, /* 0b100*/
           72  +	knmode_signed   = 1 << 6, /* 0b100*/
    69     73   	knmode_unsigned = 0 /* default */
    70     74   } knmode;
    71     75   
    72         -/* it is legal for src and dest to be the
    73         - * same location in memory. this will not
    74         - * produce incorrect output. although the
    75         - * functions formally take pointers to u8,
    76         - * they are converted  appropriately with
    77         - * regard to sign and size within the fn */
           76  +/* it is legal for  src and dest to be the
           77  + * same location in memory.  this will not
           78  + * produce incorrect output.  although the
           79  + * functions  formally   take  pointers to
           80  + * ubyte, they are converted appropriately
           81  + * with  regard  to sign  and  size within
           82  + * the fn */
    78     83   
    79         -kncond kniadd(knmode, sz, u8* dest, u8* src, u8* delta);
    80         -kncond knisub(knmode, sz, u8* dest, u8* src, u8* delta);
    81         -kncond knimul(knmode, sz, u8* dest, u8* src, u8* delta);
           84  +kncond kniadd(knmode, sz, ubyte* dest, ubyte* src, ubyte* delta);
           85  +kncond knisub(knmode, sz, ubyte* dest, ubyte* src, ubyte* delta);
           86  +kncond knimul(knmode, sz, ubyte* dest, ubyte* src, ubyte* delta);
    82     87   kncond knidiv(knmode, sz,
    83         -	/* output */ u8* ratio, u8* remainder,
    84         -	/*  input */ u8* src, u8* delta);
           88  +	/* output */ ubyte* ratio, ubyte* remainder,
           89  +	/*  input */ ubyte* src, ubyte delta);
    85     90   
    86     91   /* we should probably also offer a bignum
    87     92    * type eventually, tho this will need to
    88     93    * be integrated with kmem for allocation. */
           94  +
           95  +kncond knstr(knmode, sz, char* dest_begin, char* dest_end, ubyte* src);
           96  +kncond knparse(knmode, sz, ubyte* dest, ksraw src);
    89     97   
    90     98   #ifdef __cplusplus
    91     99   	}
    92    100   #endif
    93    101   
    94    102   #endif