Changeset 95474d7 for zephyr.c


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]
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.