"Fossies" - the Fresh Open Source Software Archive

Member "s-nail-14.9.22/src/mx/cmd-shortcut.c" (24 Feb 2021, 3433 Bytes) of package /linux/misc/s-nail-14.9.22.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cmd-shortcut.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 14.9.21_vs_14.9.22.

    1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
    2  *@ Implementation of cmd-shortcut.h.
    3  *@ TODO Support vput, i.e.: vput shortcut x what-this-expands-to
    4  *@ TODO _SCUT -> _CSCUT
    5  *
    6  * Copyright (c) 2017 - 2020 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
    7  * SPDX-License-Identifier: ISC
    8  *
    9  * Permission to use, copy, modify, and/or distribute this software for any
   10  * purpose with or without fee is hereby granted, provided that the above
   11  * copyright notice and this permission notice appear in all copies.
   12  *
   13  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   19  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   20  */
   21 #undef su_FILE
   22 #define su_FILE cmd_shortcut
   23 #define mx_SOURCE
   24 #define mx_SOURCE_CMD_SHORTCUT
   25 
   26 #ifndef mx_HAVE_AMALGAMATION
   27 # include "mx/nail.h"
   28 #endif
   29 
   30 #include <su/cs.h>
   31 #include <su/cs-dict.h>
   32 
   33 #include "mx/cmd.h"
   34 
   35 #include "mx/cmd-shortcut.h"
   36 #include "su/code-in.h"
   37 
   38 /* ..of a_scut_dp */
   39 #define a_SCUT_FLAGS (su_CS_DICT_OWNS | su_CS_DICT_HEAD_RESORT |\
   40       su_CS_DICT_AUTO_SHRINK | su_CS_DICT_ERR_PASS)
   41 #define a_SCUT_TRESHOLD_SHIFT 2
   42 
   43 static struct su_cs_dict *a_scut_dp, a_scut__d; /* XXX atexit _gut() (DVL()) */
   44 
   45 int
   46 c_shortcut(void *vp){
   47    struct su_cs_dict_view dv;
   48    int rv;
   49    char const **argv, *key, *dat;
   50    NYD_IN;
   51 
   52    if((key = *(argv = vp)) == NIL){
   53       struct n_strlist *slp;
   54 
   55       slp = NIL;
   56       rv = !(mx_xy_dump_dict("shortcut", a_scut_dp, &slp, NIL,
   57                &mx_xy_dump_dict_gen_ptf) &&
   58             mx_page_or_print_strlist("shortcut", slp, FAL0));
   59    }else if(argv[1] == NIL){
   60       if(a_scut_dp != NIL &&
   61             su_cs_dict_view_find(su_cs_dict_view_setup(&dv, a_scut_dp), key)){
   62          struct n_strlist *slp;
   63 
   64          slp = mx_xy_dump_dict_gen_ptf("shortcut", key,
   65                su_cs_dict_view_data(&dv));
   66          rv = (fputs(slp->sl_dat, n_stdout) == EOF);
   67          rv |= (putc('\n', n_stdout) == EOF);
   68       }else{
   69          n_err(_("No such shortcut: %s\n"), n_shexp_quote_cp(key, FAL0));
   70          rv = 1;
   71       }
   72    }else{
   73       if(a_scut_dp == NIL)
   74          a_scut_dp = su_cs_dict_set_treshold_shift(
   75                su_cs_dict_create(&a_scut__d, a_SCUT_FLAGS, &su_cs_toolbox),
   76                a_SCUT_TRESHOLD_SHIFT);
   77 
   78       for(rv = 0; key != NIL; argv += 2, key = *argv){
   79          if((dat = argv[1]) == NIL){
   80             mx_cmd_print_synopsis(mx_cmd_firstfit("shortcut"), NIL);
   81             rv = 1;
   82             break;
   83          }
   84 
   85          if(su_cs_dict_replace(a_scut_dp, key, C(char*,dat)) > 0){
   86             n_err(_("Failed to create `shortcut' storage: %s\n"),
   87                n_shexp_quote_cp(key, FAL0));
   88             rv = 1;
   89          }
   90       }
   91    }
   92 
   93    NYD_OU;
   94    return rv;
   95 }
   96 
   97 int
   98 c_unshortcut(void *vp){
   99    int rv;
  100    NYD_IN;
  101 
  102    rv = !mx_unxy_dict("shortcut", a_scut_dp, vp);
  103    NYD_OU;
  104    return rv;
  105 }
  106 
  107 char const *
  108 mx_shortcut_expand(char const *cp){
  109    NYD_IN;
  110 
  111    if(a_scut_dp != NIL)
  112       cp = S(char*,su_cs_dict_lookup(a_scut_dp, cp));
  113    else
  114       cp = NIL;
  115    NYD_OU;
  116    return cp;
  117 }
  118 
  119 #include "su/code-ou.h"
  120 /* s-it-mode */