Changeset b2a91b6 for zephyr.c


Ignore:
Timestamp:
Jun 22, 2003, 2:00:25 AM (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:
73624b4
Parents:
9381782
Message:
Use new function to delete zephyr subs from file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zephyr.c

    r9381782 rb2a91b6  
    545545{
    546546#ifdef HAVE_LIBZEPHYR
    547   char *line, subsfile[LINE], buff[LINE], *text;
    548   char backupfilename[LINE];
    549   FILE *file, *backupfile;
    550   int size;
     547  char *line, *subsfile;
    551548 
    552549  line=owl_zephyr_makesubline(class, inst, recip);
    553 
    554   /* open the subsfile for reading */
    555   if (filename==NULL) {
    556     sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".zephyr.subs");
    557   } else {
    558     strcpy(subsfile, filename);
    559   }
    560   file=fopen(subsfile, "r");
    561   if (!file) {
    562     owl_function_makemsg("Error opening file %s", subsfile);
    563     owl_free(line);
    564     return;
    565   }
    566 
    567   /* open the backup file for writing */
    568   sprintf(backupfilename, "%s.backup", subsfile);
    569   backupfile=fopen(backupfilename, "w");
    570   if (!backupfile) {
    571     owl_function_makemsg("Error opening file %s for writing", backupfilename);
    572     owl_free(line);
    573     return;
    574   }
    575 
    576   /* we'll read the entire file into memory, minus the line we don't want and
    577    * and at the same time create a backup file */
    578   text=owl_malloc(LINE);
    579   strcpy(text, "");
    580   size=LINE;
    581   while (fgets(buff, LINE, file)!=NULL) {
    582     /* if we don't match the line, add to text */
    583     if (strcasecmp(buff, line)) {
    584       size+=LINE;
    585       text=owl_realloc(text, size);
    586       strcat(text, buff);
    587     }
    588 
    589     /* write to backupfile */
    590     fputs(buff, backupfile);
    591   }
    592   fclose(backupfile);
    593   fclose(file);
    594 
    595   /* now open the original subs file for writing and write out the
    596    * subs */
    597   file=fopen(subsfile, "w");
    598   if (!file) {
    599     owl_function_makemsg("WARNING: Error opening %s to rewrite subscriptions.  Use %s to restore", subsfile, backupfilename);
    600     owl_function_beep();
    601     owl_free(line);
    602     return;
    603   }
    604 
    605   fputs(text, file);
    606   fclose(file);
     550  line[strlen(line)-1]='\0';
     551
     552  if (!filename) {
     553    subsfile=owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g));
     554  } else {
     555    subsfile=owl_strdup(filename);
     556  }
     557 
     558  owl_util_file_deleteline(subsfile, line, 1);
     559  owl_free(subsfile);
    607560  owl_free(line);
    608 
    609561  owl_function_makemsg("Subscription removed");
    610562#endif
    611563}
    612564
     565/* caller must free the return */
    613566char *owl_zephyr_makesubline(char *class, char *inst, char *recip)
    614567{
    615   /* caller must free the return */
    616568  char *out;
    617569
Note: See TracChangeset for help on using the changeset viewer.