Changeset 95474d7


Ignore:
Timestamp:
Jan 3, 2005, 10:34:02 PM (16 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
15b34fd
Parents:
4e0f545
Message:
In load-subs: Print an error message if the file is unreadable or
doesn't exist, UNLESS load-subs is called with no arguments.  In that
case only print an error if the file exists but isn't readable.  Still
prints an error either way if zephyr reports a failure. [BZ 19]
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4e0f545 r95474d7  
    44        Don't crash doing zlocate with bad tickets. [BZ 12]
    55        Metion the path for the owlconf in intro.txt [BZ 54]
    6         Print Better error message if startup fails due to unreadable
     6        Print better error message if startup fails due to unreadable
    77           .owlconf [BZ 57]
     8        In load-subs: Print an error message if the file is unreadable or
     9          doesn't exist, UNLESS load-subs is called with no arguments.  In
     10          that case only print an error if the file exists but isn't
     11          readable.  Still prints an error either way if zephyr reports a
     12          failure. [BZ 19]
    813
    9142.1.10
  • functions.c

    r8232149 r95474d7  
    854854}
    855855
     856
     857/* Load zephyr subscriptions from the named 'file' and load zephyr's
     858 * default subscriptions as well.  An error message is printed if
     859 * 'file' can't be opened or if zephyr reports an error in
     860 * subscribing.
     861 *
     862 * If 'file' is NULL, this look for the default filename
     863 * $HOME/.zephyr.subs.  If the file can not be opened in this case
     864 * only, no error message is printed.
     865 */
    856866void owl_function_loadsubs(char *file)
    857867{
    858868  int ret, ret2;
    859 
    860   ret=owl_zephyr_loadsubs(file);
     869  char *foo;
     870
     871  if (file==NULL) {
     872    ret=owl_zephyr_loadsubs(NULL, 0);
     873  } else {
     874    ret=owl_zephyr_loadsubs(file, 1);
     875  }
    861876
    862877  /* for backwards compatibility for now */
     
    864879
    865880  if (!owl_context_is_interactive(owl_global_get_context(&g))) return;
    866   if (ret==0) {
    867     owl_function_makemsg("Subscribed to messages from file.");
     881
     882  foo=file?file:"file";
     883  if (ret==0 && ret2==0) {
     884    if (!file) {
     885      owl_function_makemsg("Subscribed to messages.");
     886    } else {
     887      owl_function_makemsg("Subscribed to messages from %s", file);
     888    }
    868889  } else if (ret==-1) {
    869     owl_function_error("Could not open file.");
     890    owl_function_error("Could not read %s", foo);
    870891  } else {
    871     owl_function_error("Error subscribing to messages from file.");
     892    owl_function_error("Error subscribing to messages");
    872893  }
    873894}
  • owl.c

    r4e0f545 r95474d7  
    373373   
    374374    /* load subscriptions from subs file */
    375     ret2=owl_zephyr_loadsubs(NULL);
     375    ret2=owl_zephyr_loadsubs(NULL, 0);
    376376
    377377    if (ret || ret2) {
  • zephyr.c

    r667a1b6 r95474d7  
    6767}
    6868
    69 /* return 0  on success
    70  *        -1 on file error
    71  *        -2 on subscription error
     69/* Load zephyr subscriptions form 'filename'.  If 'filename' is NULL,
     70 * the default file $HOME/.zephyr.subs will be used.
     71 *
     72 * Returns 0 on success.  If the file does not exist, return -1 if
     73 * 'error_on_nofile' is 1, otherwise return 0.  Return -1 if the file
     74 * exists but can not be read.  Return -2 if there is a failure from
     75 * zephyr to load the subscriptions.
    7276 */
    73 int owl_zephyr_loadsubs(char *filename)
     77int owl_zephyr_loadsubs(char *filename, int error_on_nofile)
    7478{
    7579#ifdef HAVE_LIBZEPHYR
     
    8892
    8993  ret=stat(subsfile, &statbuff);
    90   if (ret) return(0);
    91 
    92   ret=0;
     94  if (ret) {
     95    if (error_on_nofile==1) return(-1);
     96    return(0);
     97  }
    9398
    9499  ZResetAuthentication();
     
    96101  count=0;
    97102  file=fopen(subsfile, "r");
    98   if (file) {
    99     while ( fgets(buffer, 1024, file)!=NULL ) {
    100       if (buffer[0]=='#' || buffer[0]=='\n' || buffer[0]=='\n') continue;
    101 
    102       if (buffer[0]=='-') {
    103         start=buffer+1;
    104       } else {
    105         start=buffer;
    106       }
    107      
    108       if (count >= 3000) break; /* also tell the user */
    109 
    110       /* add it to the list of subs */
    111       if ((tmp=(char *) strtok(start, ",\n\r"))==NULL) continue;
    112       subs[count].zsub_class=owl_strdup(tmp);
    113       if ((tmp=(char *) strtok(NULL, ",\n\r"))==NULL) continue;
    114       subs[count].zsub_classinst=owl_strdup(tmp);
    115       if ((tmp=(char *) strtok(NULL, " \t\n\r"))==NULL) continue;
    116       subs[count].zsub_recipient=owl_strdup(tmp);
    117 
    118       /* if it started with '-' then add it to the global punt list */
    119       if (buffer[0]=='-') {
    120         owl_function_zpunt(subs[count].zsub_class, subs[count].zsub_classinst, subs[count].zsub_recipient, 0);
    121       }
    122      
    123       count++;
    124     }
    125     fclose(file);
    126   } else {
    127     count=0;
    128     ret=-1;
    129   }
     103  if (!file) return(-1);
     104  while ( fgets(buffer, 1024, file)!=NULL ) {
     105    if (buffer[0]=='#' || buffer[0]=='\n' || buffer[0]=='\n') continue;
     106   
     107    if (buffer[0]=='-') {
     108      start=buffer+1;
     109    } else {
     110      start=buffer;
     111    }
     112   
     113    if (count >= 3000) break; /* also tell the user */
     114   
     115    /* add it to the list of subs */
     116    if ((tmp=(char *) strtok(start, ",\n\r"))==NULL) continue;
     117    subs[count].zsub_class=owl_strdup(tmp);
     118    if ((tmp=(char *) strtok(NULL, ",\n\r"))==NULL) continue;
     119    subs[count].zsub_classinst=owl_strdup(tmp);
     120    if ((tmp=(char *) strtok(NULL, " \t\n\r"))==NULL) continue;
     121    subs[count].zsub_recipient=owl_strdup(tmp);
     122   
     123    /* if it started with '-' then add it to the global punt list */
     124    if (buffer[0]=='-') {
     125      owl_function_zpunt(subs[count].zsub_class, subs[count].zsub_classinst, subs[count].zsub_recipient, 0);
     126    }
     127   
     128    count++;
     129  }
     130  fclose(file);
    130131
    131132  /* sub without defaults */
     133  ret=0;
    132134  if (ZSubscribeToSansDefaults(subs,count,0) != ZERR_NONE) {
    133135    owl_function_error("Error subscribing to zephyr notifications.");
Note: See TracChangeset for help on using the changeset viewer.