X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=init.c;h=e8c3b0a7f95750e2d1075378996245e7faf9d67f;hb=5e53f9e5f65aa5b3af6f5af9d868403536534afb;hp=32f913b4ecd60ed8943940b9269e4a1045d131e8;hpb=d6988dab6bd378ccdf0f17aaa16de8aee1ceaf43;p=apps%2Fmadmutt.git diff --git a/init.c b/init.c index 32f913b..e8c3b0a 100644 --- a/init.c +++ b/init.c @@ -53,15 +53,6 @@ #include #include -#define CHECK_PAGER \ - if ((CurrentMenu == MENU_PAGER) && \ - (!option || (option->flags & R_RESORT))) \ - { \ - snprintf (err->data, err->dsize, \ - _("Not available in this menu.")); \ - return (-1); \ - } else - /* * prototypes */ @@ -266,7 +257,7 @@ static void user_to_string (char* dst, size_t dstlen, static void sys_to_string (char* dst, size_t dstlen, struct option_t* option) { - char* val = NULL, *t = NULL; + char *val = NULL, *t = NULL; int clean = 0; /* get some $muttng_ values dynamically */ @@ -279,10 +270,26 @@ static void sys_to_string (char* dst, size_t dstlen, val = CurrentFolder; } else if (ascii_strcmp ("muttng_folder_name", option->option) == 0 && CurrentFolder && *CurrentFolder) { - if ((t = strrchr (CurrentFolder, '/')) != NULL) + + size_t Maildirlength = str_len (Maildir); + + /* + * if name starts with $folder, just strip it to keep hierarchy + * $folder=imap://host, path=imap://host/inbox/b -> inbox/b + */ + if (Maildirlength > 0 && str_ncmp (CurrentFolder, Maildir, + Maildirlength) == 0 && + str_len (CurrentFolder) > Maildirlength) { + val = CurrentFolder + Maildirlength; + if (Maildir[strlen(Maildir)-1]!='/') + val += 1; + /* if not $folder, just use everything after last / */ + } else if ((t = strrchr (CurrentFolder, '/')) != NULL) val = t+1; + /* default: use as-is */ else val = CurrentFolder; + } else val = option->init; @@ -342,7 +349,7 @@ static int user_from_string (struct option_t* dst, const char* val, static void quad_to_string (char* dst, size_t dstlen, struct option_t* option) { - char *vals[] = { "no", "yes", "ask-no", "ask-yes" }; + const char *vals[] = { "no", "yes", "ask-no", "ask-yes" }; snprintf (dst, dstlen, "%s=%s", option->option, vals[quadoption (option->data)]); } @@ -1208,7 +1215,7 @@ static int parse_unattach_list (BUFFER *buf, BUFFER *s, LIST **ldata, BUFFER *er return 0; } -static int print_attach_list (LIST *lp, char op, char *name) { +static int print_attach_list (LIST *lp, char op, const char *name) { while (lp) { printf("attachments %c%s %s/%s\n", op, name, ((ATTACH_MATCH *)lp->data)->major, @@ -1591,7 +1598,7 @@ static void mutt_set_default (const char* name, void* p, unsigned long more) { } static struct option_t* add_option (const char* name, const char* init, - short type, short dup) { + short type, short dodup) { struct option_t* option = mem_calloc (1, sizeof (struct option_t)); debug_print (1, ("adding $%s\n", name)); @@ -1599,7 +1606,7 @@ static struct option_t* add_option (const char* name, const char* init, option->option = str_dup (name); option->type = type; if (init) - option->init = dup ? str_dup (init) : (char*) init; + option->init = dodup ? str_dup (init) : (char*) init; return (option); } @@ -1803,6 +1810,15 @@ static const struct mapping_t* get_sortmap (struct option_t* option) { return (map); } +#define CHECK_PAGER \ + if ((CurrentMenu == MENU_PAGER) && \ + (!option || (option->flags & R_RESORT))) \ + { \ + snprintf (err->data, err->dsize, \ + _("Not available in this menu.")); \ + return (-1); \ + } + static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, BUFFER * err) { @@ -2204,7 +2220,7 @@ char *Matches[MAX (NUMVARS, NUMCOMMANDS) + 1]; /* all the matches + User_typed try == user entered data for completion. len == length of dest buffer. */ -static void candidate (char *dest, char *try, char *src, int len) +static void candidate (char *dest, char *try, const char *src, int len) { int l; @@ -2269,7 +2285,7 @@ int mutt_command_complete (char *buffer, size_t len, int pos, int numtabs) || !str_ncmp (buffer, "unset", 5) || !str_ncmp (buffer, "reset", 5) || !str_ncmp (buffer, "toggle", 6)) { /* complete variables */ - char *prefixes[] = { "no", "inv", "?", "&", 0 }; + const char *prefixes[] = { "no", "inv", "?", "&", NULL }; pt++; /* loop through all the possible prefixes (no, inv, ...) */ @@ -2392,7 +2408,7 @@ int mutt_var_value_complete (char *buffer, size_t len, int pos) char tmp[LONG_STRING], tmp2[LONG_STRING]; char *s, *d; size_t dlen = buffer + len - pt - spaces; - char *vals[] = { "no", "yes", "ask-no", "ask-yes" }; + const char *vals[] = { "no", "yes", "ask-no", "ask-yes" }; tmp[0] = '\0'; @@ -2442,7 +2458,7 @@ int mutt_var_value_complete (char *buffer, size_t len, int pos) "", p); } else if (DTYPE (option->type) == DT_MAGIC) { - char *p; + const char *p; switch (DefaultMagic) { case M_MBOX: p = "mbox"; @@ -2513,7 +2529,7 @@ int mutt_query_variables (LIST * queries) return 0; } -char *mutt_getnamebyvalue (int val, const struct mapping_t *map) +const char *mutt_getnamebyvalue (int val, const struct mapping_t *map) { int i; @@ -2557,7 +2573,8 @@ void mutt_init (int skip_sys_rc, LIST * commands) { struct passwd *pw; struct utsname utsname; - char *p, buffer[STRING], error[STRING]; + const char *p; + char buffer[STRING], error[STRING]; int i, default_rc = 0, need_pause = 0; BUFFER err; @@ -2645,18 +2662,17 @@ void mutt_init (int skip_sys_rc, LIST * commands) #ifdef USE_NNTP { FILE *f; - char *i; + char *q; if ((f = safe_fopen (SYSCONFDIR "/nntpserver", "r"))) { buffer[0] = '\0'; fgets (buffer, sizeof (buffer), f); - p = (char*) &buffer; + p = (char*)&buffer; SKIPWS (p); - i = p; - while (*i && (*i != ' ') && (*i != '\t') && (*i != '\r') - && (*i != '\n')) - i++; - *i = '\0'; + q = p; + while (*q && !isspace(*q)) + q++; + *q = '\0'; NewsServer = str_dup (p); fclose (f); }