MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at type-hints-typescript 49 lines 1.8 kB view raw
1#include "cli/misc.h" 2#include "messages.h" 3 4#include <stdio.h> 5#include <argtable3.h> 6#include <crprintf.h> 7 8void print_flag(FILE *fp, flag_help_t f) { 9 const char *s = f.s, *l = f.l, *d = f.d, *g = f.g; 10 int opt = f.opt; 11 12 char syn[200]; 13 crsprintf(syn, sizeof(syn), 14 "<cyan>%s</cyan>%s<cyan>%s%s%s%s</cyan>", 15 s ? (char[]){'-', s[0], '\0'} : (l ? " " : ""), 16 s && l ? ", " : "", 17 l ? "--" : "", 18 l ? l : "", 19 d && l && opt ? "[=" : 20 d && l ? "=" : 21 d && s ? " " : "", 22 d ? d : ""); 23 24 crfprintf(fp, "<space=2/><pad=32>%s</pad> %s</>\n", syn, g); 25} 26 27void print_flags_help(FILE *fp, void **argtable) { 28 struct arg_hdr **table = (struct arg_hdr **)argtable; 29 for (int i = 0; !(table[i]->flag & ARG_TERMINATOR); i++) { 30 struct arg_hdr *hdr = table[i]; 31 if (!hdr->glossary) continue; 32 print_flag(fp, (flag_help_t){ 33 .s = hdr->shortopts, .l = hdr->longopts, 34 .d = hdr->datatype, .g = hdr->glossary, 35 .opt = hdr->flag & ARG_HASOPTVALUE, 36 });} 37} 38 39void print_errors(FILE *fp, struct arg_end *end) { 40 for (int i = 0; i < end->count; i++) { 41 int error = end->error[i]; 42 const char *argval = end->argval[i] ? end->argval[i] : ""; 43 switch (error) { 44 case ARG_ENOMATCH: { crfprintf(fp, msg.arg_unexpected, argval); break; } 45 case ARG_EMISSARG: { crfprintf(fp, msg.arg_opt_needed, argval); break; } 46 case ARG_ELONGOPT: { crfprintf(fp, msg.arg_invalid, argval); break; } 47 default: { if (error > 0) crfprintf(fp, msg.opt_invalid, error); break; } 48 }} fputc('\n', fp); 49}