home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / pmmutl12.zip / change.c next >
C/C++ Source or Header  |  1998-11-18  |  2KB  |  76 lines

  1. /* PMMail 1.5-2.0 attachement striper 1.2 (C) 1996-1998 Samuel Audet <guardia@cam.org> */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7.  
  8. #define BAGNAME "FOLDER.BAG"
  9. #define BAGBAKNAME "FOLDER.BAK"
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.    char *bagpath;
  14.    char newbagname[512], oldbagname[512], line[512];
  15.    FILE *newbag, *oldbag;
  16.    int i;
  17.  
  18.    printf("Sent Status Changer 1.2 for PMMail 1.5-2.0 - Copyright 1996-1998 Samuel Audet\n");
  19.    if(argc > 1)
  20.    {
  21.       char *temp;
  22.       bagpath = argv[1];
  23.       temp = strrchr(bagpath,'\\')+1;
  24.       if(*(temp+1) == 0) *temp = 0;
  25.    }
  26.    else
  27.       bagpath = ".";
  28.  
  29.    strcpy(newbagname,bagpath);
  30.    strcat(newbagname,"\\");
  31.    strcat(newbagname,BAGNAME);
  32.  
  33.    strcpy(oldbagname,bagpath);
  34.    strcat(oldbagname,"\\");
  35.    strcat(oldbagname,BAGBAKNAME);
  36.  
  37.    if(rename(newbagname,oldbagname))
  38.    {
  39.       fprintf(stderr,"Error, could not rename %s to %s.\n", newbagname,oldbagname);
  40.       return 1;
  41.    }
  42.  
  43.    newbag = fopen(newbagname,"w");
  44.    if(!newbag)
  45.    {
  46.       fprintf(stderr,"Error opening %s for writing.\n",newbagname);
  47.       return 2;
  48.    }
  49.    oldbag = fopen(oldbagname,"r");
  50.    if(!oldbag)
  51.    {
  52.       fprintf(stderr,"Error opening %s for reading.\n",oldbagname);
  53.       return 3;
  54.    }
  55.  
  56.    i = 0;
  57.    while(fgets(line, sizeof(line), oldbag))
  58.    {
  59.       /* enum {unread=0,read,replied,sent,unsent} status; */
  60.  
  61.       i++; /* line counter */
  62.  
  63.       line[0] = '3'; /* the first column is the status byte */
  64.       fputs(line, newbag);
  65.    }
  66.  
  67.    fclose(newbag);
  68.    fclose(oldbag);
  69.  
  70.    remove(oldbagname);
  71.  
  72.    printf("%d entries processed.\n",i);
  73.  
  74.    return 0;
  75. }
  76.