Changeset ec6ff52 for functions.c


Ignore:
Timestamp:
Oct 17, 2003, 5:16:25 PM (21 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
836ea3a3
Parents:
a053de8
Message:
Added the 'show errors' command
Added the error queue
Converted most makemsg's to error instead
Started writing an internal VT style (far from done)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r8a54409 rec6ff52  
    6767  v=owl_global_get_current_view(&g);
    6868  if (viewname && strcmp(viewname, owl_view_get_name(v))) {
    69     owl_function_makemsg("No view named '%s'", viewname);
     69    owl_function_error("No view named '%s'", viewname);
    7070    return;
    7171  }
     
    218218  ret=owl_zwrite_create_from_line(&z, line);
    219219  if (ret) {
    220     owl_function_makemsg("Error in zwrite arugments");
     220    owl_function_error("Error in zwrite arugments");
    221221    owl_zwrite_free(&z);
    222222    return;
     
    343343  ret=owl_zcrypt_encrypt(cryptmsg, mymsg, owl_zwrite_get_class(&z), owl_zwrite_get_instance(&z));
    344344  if (ret) {
    345     owl_function_makemsg("Error in zcrypt, possibly no key found.  Message not sent.");
     345    owl_function_error("Error in zcrypt, possibly no key found.  Message not sent.");
    346346    owl_function_beep();
    347347    owl_free(cryptmsg);
     
    379379void owl_function_aimwrite(char *to)
    380380{
     381  int ret;
     382 
    381383  /*  send the message */
    382   owl_aim_send_im(to, owl_editwin_get_text(owl_global_get_typwin(&g)));
    383   owl_function_makemsg("AIM message sent.");
     384  ret=owl_aim_send_im(to, owl_editwin_get_text(owl_global_get_typwin(&g)));
     385  if (!ret) {
     386    owl_function_makemsg("AIM message sent.");
     387  } else {
     388    owl_function_error("Could not send AIM message.");
     389  }
    384390
    385391  /* display the message as an outgoing message in the receive window */
     
    410416    f=owl_global_get_filter(&g, filter);
    411417    if (!f) {
    412       owl_function_makemsg("No %s filter defined", filter);
     418      owl_function_error("No %s filter defined", filter);
    413419      return;
    414420    }
     
    434440
    435441  if (!found) {
    436     owl_function_makemsg("already at last%s message%s%s",
     442    owl_function_error("already at last%s message%s%s",
    437443                         skip_deleted?" non-deleted":"",
    438444                         filter?" in ":"", filter?filter:"");
     
    460466    f=owl_global_get_filter(&g, filter);
    461467    if (!f) {
    462       owl_function_makemsg("No %s filter defined", filter);
     468      owl_function_error("No %s filter defined", filter);
    463469      return;
    464470    }
     
    483489
    484490  if (!found) {
    485     owl_function_makemsg("already at first%s message%s%s",
     491    owl_function_error("already at first%s message%s%s",
    486492                         skip_deleted?" non-deleted":"",
    487493                         filter?" in ":"", filter?filter:"");
     
    538544  /* bail if there's no current message */
    539545  if (owl_view_get_size(v) < 1) {
    540     owl_function_makemsg("No current message to delete");
     546    owl_function_error("No current message to delete");
    541547    return;
    542548  }
     
    565571 
    566572  if (owl_view_get_size(v) < 1) {
    567     owl_function_makemsg("No current message to undelete");
     573    owl_function_error("No current message to undelete");
    568574    return;
    569575  }
     
    677683  } else {
    678684    owl_function_beep();
    679     owl_function_makemsg("Already full left");
     685    owl_function_error("Already full left");
    680686  }
    681687}
     
    697703    owl_function_makemsg("Subscribed to messages from file.");
    698704  } else if (ret==-1) {
    699     owl_function_makemsg("Could not open file.");
     705    owl_function_error("Could not open file.");
    700706  } else {
    701     owl_function_makemsg("Error subscribing to messages from file.");
     707    owl_function_error("Error subscribing to messages from file.");
    702708  }
    703709}
     
    713719    owl_function_makemsg("Subscribed to login messages from file.");
    714720  } else if (ret==-1) {
    715     owl_function_makemsg("Could not open file for login subscriptions.");
     721    owl_function_error("Could not open file for login subscriptions.");
    716722  } else {
    717     owl_function_makemsg("Error subscribing to login messages from file.");
     723    owl_function_error("Error subscribing to login messages from file.");
    718724  }
    719725}
     
    776782}
    777783
    778 void owl_function_makemsg(char *fmt, ...)
    779 {
    780   va_list ap;
    781   char buff[2048];
    782 
    783   if (!owl_global_get_curs_msgwin(&g)) return;
    784 
    785   va_start(ap, fmt);
    786   werase(owl_global_get_curs_msgwin(&g));
    787  
    788   vsnprintf(buff, 2048, fmt, ap);
    789   owl_function_debugmsg("makemsg: %s", buff);
    790   waddstr(owl_global_get_curs_msgwin(&g), buff); 
    791   wnoutrefresh(owl_global_get_curs_msgwin(&g));
    792   owl_global_set_needrefresh(&g);
    793   va_end(ap);
    794 }
    795 
    796 void owl_function_errormsg(char *fmt, ...)
    797 {
    798   va_list ap;
    799   char buff[2048];
    800 
    801   if (!owl_global_get_curs_msgwin(&g)) return;
    802 
    803   va_start(ap, fmt);
    804   werase(owl_global_get_curs_msgwin(&g));
    805  
    806   vsnprintf(buff, 2048, fmt, ap);
    807   owl_function_debugmsg("ERROR: %s", buff);
    808   waddstr(owl_global_get_curs_msgwin(&g), buff); 
    809   waddstr(owl_global_get_curs_msgwin(&g), "ERROR: "); 
    810   wnoutrefresh(owl_global_get_curs_msgwin(&g));
    811   owl_global_set_needrefresh(&g);
    812   va_end(ap);
    813 }
    814 
    815784void owl_function_openurl()
    816785{
     
    824793
    825794  if (webbrowser < 0 || webbrowser == OWL_WEBBROWSER_NONE) {
    826     owl_function_makemsg("No browser selected");
     795    owl_function_error("No browser selected");
    827796    return;
    828797  }
     
    833802
    834803  if (!m || owl_view_get_size(v)==0) {
    835     owl_function_makemsg("No current message selected");
     804    owl_function_error("No current message selected");
    836805    return;
    837806  }
     
    882851  } else {
    883852    owl_function_beep();
    884     owl_function_makemsg("Could not find URL to open.");
     853    owl_function_error("Could not find URL to open.");
    885854    return;
    886855  }
     
    890859    if (*ptr1 == '"' || *ptr1 == '\\') {
    891860      owl_function_beep();
    892       owl_function_makemsg("URL contains invalid characters.");
     861      owl_function_error("URL contains invalid characters.");
    893862      return;
    894863    }
     
    11621131  ret=owl_zephyr_sub(class, inst, recip);
    11631132  if (ret) {
    1164     owl_function_makemsg("Error subscribing.");
     1133    owl_function_error("Error subscribing.");
    11651134  } else {
    11661135    owl_function_makemsg("Subscribed.");
     
    11741143  ret=owl_zephyr_unsub(class, inst, recip);
    11751144  if (ret) {
    1176     owl_function_makemsg("Error subscribing.");
     1145    owl_function_error("Error subscribing.");
    11771146  } else {
    11781147    owl_function_makemsg("Unsubscribed.");
     
    12781247  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
    12791248  if (!m || owl_view_get_size(v)==0) {
    1280     owl_function_makemsg("No message selected\n");
     1249    owl_function_error("No message selected\n");
    12811250    return;
    12821251  }
     
    14431412
    14441413  if (!m || owl_view_get_size(v)==0) {
    1445     owl_function_makemsg("No current message");
     1414    owl_function_error("No current message");
    14461415    return;
    14471416  }
     
    14721441    /* Bail if the curmsg isn't the last one displayed */
    14731442    if (curmsg != owl_mainwin_get_last_msg(owl_global_get_mainwin(&g))) {
    1474       owl_function_makemsg("The entire message is already displayed");
     1443      owl_function_error("The entire message is already displayed");
    14751444      return;
    14761445    }
     
    14781447    /* Bail if we're not truncated */
    14791448    if (!owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) {
    1480       owl_function_makemsg("The entire message is already displayed");
     1449      owl_function_error("The entire message is already displayed");
    14811450      return;
    14821451    }
     
    16471616    owl_global_set_needrefresh(&g);
    16481617  } else {
    1649     owl_function_makemsg("No message with id %d: unable to mark for (un)delete",id);
     1618    owl_function_error("No message with id %d: unable to mark for (un)delete",id);
    16501619  }
    16511620}
     
    16641633  f=owl_global_get_filter(&g, "trash");
    16651634  if (!f) {
    1666     owl_function_makemsg("No trash filter defined");
     1635    owl_function_error("No trash filter defined");
    16671636    return;
    16681637  }
     
    17871756 
    17881757  if (owl_view_get_size(owl_global_get_current_view(&g))==0) {
    1789     owl_function_makemsg("No message selected");
     1758    owl_function_error("No message selected");
    17901759  } else {
    17911760    char *class, *inst, *to, *cc=NULL;
     
    17931762    m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g));
    17941763    if (!m) {
    1795       owl_function_makemsg("No message selected");
     1764      owl_function_error("No message selected");
    17961765      return;
    17971766    }
     
    18011770    if (f) {
    18021771      if (owl_filter_message_match(f, m)) {
    1803         owl_function_makemsg("Sorry, replies to this message have been disabled by the reply-lockout filter");
     1772        owl_function_error("Sorry, replies to this message have been disabled by the reply-lockout filter");
    18041773        return;
    18051774      }
     
    18081777    /* admin */
    18091778    if (owl_message_is_type_admin(m)) {
    1810       owl_function_makemsg("You cannot reply to an admin message");
     1779      owl_function_error("You cannot reply to an admin message");
    18111780      return;
    18121781    }
     
    20041973
    20051974  if (argc<2) {
    2006     owl_function_makemsg("Wrong number of arguments to the exec command");
     1975    owl_function_error("Wrong number of arguments to the exec command");
    20071976    return NULL;
    20081977  }
     
    20472016
    20482017  if (argc<2) {
    2049     owl_function_makemsg("Wrong number of arguments to perl command");
     2018    owl_function_error("Wrong number of arguments to perl command");
    20502019    return NULL;
    20512020  }
     
    20932062  f=owl_global_get_filter(&g, filtname);
    20942063  if (!f) {
    2095     owl_function_makemsg("Unknown filter");
     2064    owl_function_error("Unknown filter %s", filtname);
    20962065    return;
    20972066  }
     
    21422111  f=owl_global_get_filter(&g, filtname);
    21432112  if (!f) {
    2144     owl_function_makemsg("Unknown filter");
     2113    owl_function_error("Unknown filter %s", filtname);
    21452114    return;
    21462115  }
     
    21722141
    21732142  if (argc < 2) {
    2174     owl_function_makemsg("Wrong number of arguments to filter command");
     2143    owl_function_error("Wrong number of arguments to filter command");
    21752144    return;
    21762145  }
     
    21802149  /* don't touch the all filter */
    21812150  if (!strcmp(argv[1], "all")) {
    2182     owl_function_makemsg("You may not change the 'all' filter.");
     2151    owl_function_error("You may not change the 'all' filter.");
    21832152    return;
    21842153  }
     
    21882157    f=owl_global_get_filter(&g, argv[1]);
    21892158    if (!f) {
    2190       owl_function_makemsg("The filter '%s' does not exist.", argv[1]);
     2159      owl_function_error("The filter '%s' does not exist.", argv[1]);
    21912160      return;
    21922161    }
     
    22022171  if (ret==-1) {
    22032172    owl_free(f);
    2204     owl_function_makemsg("Invalid filter syntax");
     2173    owl_function_error("Invalid filter syntax");
    22052174    return;
    22062175  }
     
    22622231  f=owl_global_get_filter(&g, name);
    22632232  if (!f) {
    2264     owl_function_makemsg("There is no filter with that name");
     2233    owl_function_error("There is no filter named %s", name);
    22652234    return;
    22662235  }
     
    25102479
    25112480  if (!m || owl_view_get_size(v)==0) {
    2512     owl_function_makemsg("No message selected\n");
     2481    owl_function_error("No message selected\n");
    25132482    return(NULL);
    25142483  }
     
    25712540
    25722541  if (!m || owl_view_get_size(v)==0) {
    2573     owl_function_makemsg("No message selected\n");
     2542    owl_function_error("No message selected\n");
    25742543    return;
    25752544  }
     
    25792548      || owl_message_is_loginout(m)
    25802549      || !owl_message_is_type_zephyr(m)) {
    2581     owl_function_makemsg("smartzpunt doesn't support this message type.");
     2550    owl_function_error("smartzpunt doesn't support this message type.");
    25822551    return;
    25832552  }
     
    25882557      || (!strcasecmp(mclass, "message") && !strcasecmp(minst, "personal"))
    25892558      || (type && (!minst || !*minst|| *minst==' '))) {
    2590     owl_function_makemsg("smartzpunt can't safely do this for <%s,%s>",
     2559    owl_function_error("smartzpunt can't safely do this for <%s,%s>",
    25912560                         mclass, minst);
    25922561  } else {
     
    26142583  f=owl_global_get_filter(&g, name);
    26152584  if (!f) {
    2616     owl_function_makemsg("Unknown filter");
     2585    owl_function_error("Unknown filter");
    26172586    return;
    26182587  }
     
    26202589  /* don't touch the all filter */
    26212590  if (!strcmp(name, "all")) {
    2622     owl_function_makemsg("You may not change the 'all' filter.");
     2591    owl_function_error("You may not change the 'all' filter.");
    26232592    return;
    26242593  }
     
    26832652  owl_free(buff);
    26842653  if (ret) {
    2685     owl_function_makemsg("Error creating filter for zpunt");
     2654    owl_function_error("Error creating filter for zpunt");
    26862655    owl_filter_free(f);
    26872656    return;
     
    27162685{
    27172686  if (!owl_keyhandler_activate(owl_global_get_keyhandler(&g), keymap)) {
    2718     owl_function_makemsg("Unable to activate keymap '%s'", keymap);
     2687    owl_function_error("Unable to activate keymap '%s'", keymap);
    27192688  }
    27202689}
     
    28182787 
    28192788  if (viewsize==0) {
    2820     owl_function_makemsg("No messages present");
     2789    owl_function_error("No messages present");
    28212790    return;
    28222791  }
     
    28322801  /* bounds check */
    28332802  if (start>=viewsize || start<0) {
    2834     owl_function_makemsg("No further matches found");
     2803    owl_function_error("No further matches found");
    28352804    return;
    28362805  }
     
    28562825  }
    28572826  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    2858   owl_function_makemsg("No matches found");
     2827  owl_function_error("No matches found");
    28592828}
    28602829
     
    29182887      tmp=owl_global_get_homedir(&g);
    29192888      if (!tmp) {
    2920         owl_function_makemsg("Could not determine home directory");
     2889        owl_function_error("Could not determine home directory");
    29212890        return;
    29222891      }
     
    29292898    f=fopen(ourfile, "r");
    29302899    if (!f) {
    2931       owl_function_makemsg("Error opening file %s: %s",
     2900      owl_function_error("Error opening file %s: %s",
    29322901                           ourfile,
    29332902                           strerror(errno) ? strerror(errno) : "");
     
    29622931      ret=ZLocateUser(buff, &numlocs, ZAUTH);
    29632932      if (ret!=ZERR_NONE) {
    2964         owl_function_makemsg("Error getting location for %s", buff);
     2933        owl_function_error("Error getting location for %s", buff);
    29652934        continue;
    29662935      }
     
    30152984  file=fopen(filename, "w");
    30162985  if (!file) {
    3017     owl_function_makemsg("Error opening file");
     2986    owl_function_error("Error opening file");
    30182987    return;
    30192988  }
     
    31073076  file=fopen(filename, "a");
    31083077  if (!file) {
    3109     owl_function_makemsg("Error opening startupfile for new command");
     3078    owl_function_error("Error opening startupfile for new command");
    31103079    owl_free(filename);
    31113080    return;
     
    31633132  s=owl_global_get_style_by_name(&g, stylename);
    31643133  if (!s) {
    3165     owl_function_makemsg("No style named %s", stylename);
     3134    owl_function_error("No style named %s", stylename);
    31663135    return;
    31673136  }
     
    31703139  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
    31713140  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    3172  
    31733141}
    31743142
     
    31913159  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    31923160}
     3161
     3162void owl_function_error(char *fmt, ...)
     3163{
     3164  va_list ap;
     3165  char buff[2048], buff2[2048];
     3166  char *date;
     3167  time_t now;
     3168
     3169  now=time(NULL);
     3170  date=owl_strdup(ctime(&now));
     3171  date[strlen(date)-1]='\0';
     3172
     3173  va_start(ap, fmt);
     3174
     3175  vsnprintf(buff, 2048, fmt, ap);
     3176  sprintf(buff2, "%s %s", date, buff);
     3177  owl_function_debugmsg("ERROR: %s", buff);
     3178  if (owl_global_get_curs_msgwin(&g)) {
     3179    werase(owl_global_get_curs_msgwin(&g));
     3180    waddstr(owl_global_get_curs_msgwin(&g), buff); 
     3181    wnoutrefresh(owl_global_get_curs_msgwin(&g));
     3182    owl_global_set_needrefresh(&g);
     3183  }
     3184  owl_errqueue_append_err(owl_global_get_errqueue(&g), buff2);
     3185  va_end(ap);
     3186  owl_free(date);
     3187}
     3188
     3189void owl_function_showerrs()
     3190{
     3191  owl_fmtext fm;
     3192
     3193  owl_fmtext_init_null(&fm);
     3194  owl_fmtext_append_normal(&fm, "Errors:\n\n");
     3195  owl_errqueue_to_fmtext(owl_global_get_errqueue(&g), &fm);
     3196  owl_function_popless_fmtext(&fm);
     3197}
     3198
     3199void owl_function_makemsg(char *fmt, ...)
     3200{
     3201  va_list ap;
     3202  char buff[2048];
     3203
     3204  if (!owl_global_get_curs_msgwin(&g)) return;
     3205
     3206  va_start(ap, fmt);
     3207  werase(owl_global_get_curs_msgwin(&g));
     3208 
     3209  vsnprintf(buff, 2048, fmt, ap);
     3210  owl_function_debugmsg("makemsg: %s", buff);
     3211  waddstr(owl_global_get_curs_msgwin(&g), buff); 
     3212  wnoutrefresh(owl_global_get_curs_msgwin(&g));
     3213  owl_global_set_needrefresh(&g);
     3214  va_end(ap);
     3215}
Note: See TracChangeset for help on using the changeset viewer.