Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, October 15, 2026

Diff for libplaton/utils/getmails/getmails.c between version 1.6 and 1.7

version 1.6, 2002/12/04 18:40:49 version 1.7, 2003/01/04 10:10:31
Line 19 
Line 19 
   #include<ctype.h>    #include<ctype.h>
   #define isemail(__c)\    #define isemail(__c)\
     (isalpha(__c)||isdigit(__c)||(__c)=='-'||(__c)=='_'||(__c)=='@'||(__c)=='.')      (isalpha(__c)||isdigit(__c)||(__c)=='-'||(__c)=='_'||(__c)=='@'||(__c)=='.')
 #endif // #ifndef isemail  #endif
   
 /* Funkcne prototypy. */  /* Function prototypes */
 int isvalidemail(const char*s);  int isvalidemail(const char*s);
 int extract(const char*fin_name,const char*fout_name);  int extract(const char*fin_name,const char*fout_name);
 int sort(const char*filename);  int sort(const char*filename);
   
 int main(int argc,char*argv[]){  int main(int argc,char*argv[])
   {
   /* Vypisanie informacii a helpu. */    /* Information and help */
   printf("GETMAILS - Dos/Unix e-mail address extractor v1.2 / %s %s\n",__DATE__,__TIME__);    printf("GETMAILS - MS-Dos/Unix e-mail address extractor v1.2 / %s %s\n",__DATE__,__TIME__);
   if(argc<3){    if (argc<3) {
     puts("Programmed by Ondrej Jombik, e-mail: Jombik@pobox.sk, Web: http://Jombik.w3.to");      puts("Programmed by Ondrej Jombik, e-mail: nepto@pobox.sk, web: http://nepto.sk/");
     puts("(c) Copyright 2000 Condy software inc., All rights reserved.");      puts("Copyright (c) 2000 Condy software inc., All rights reserved.");
     puts("\nUsage: GETMAILS <input_file> <output_file>");      puts("\nUsage: GETMAILS <input_file> <output_file>");
     return(1);      return(1);
   }    }
   
   /* Kontrola existencie suborov. */    /* Files check */
   {    {
     FILE*f;      FILE*f;
     if((f=fopen(argv[1],INPUT_FMODE))==NULL){      if ((f=fopen(argv[1],INPUT_FMODE))==NULL) {
       printf("Can't open input file. [%s]\n",argv[1]);        printf("Can't open input file. [%s]\n",argv[1]);
       return(1);        return(1);
     }      }
     fclose(f);      fclose(f);
   
     if((f=fopen(argv[2],OUTPUT_FMODE))==NULL){      if ((f=fopen(argv[2],OUTPUT_FMODE))==NULL) {
       printf("Can't open output file. [%s]\n",argv[2]);        printf("Can't open output file. [%s]\n",argv[2]);
       return(1);        return(1);
     }      }
Line 54  int main(int argc,char*argv[]){
Line 54  int main(int argc,char*argv[]){
   }    }
   printf("Appending data from '%s' to '%s'.\n",argv[1],argv[2]);    printf("Appending data from '%s' to '%s'.\n",argv[1],argv[2]);
   
   /* Extrahovanie. */    /* E-mail addresses extracting */
   printf("Extracting... ");    printf("Extracting... ");
   if(extract(argv[1],argv[2])){    if (extract(argv[1],argv[2])) {
     puts("fail.");      puts("fail.");
     return(1);      return(1);
   }    }
   else puts("OK.");    else puts("OK.");
   
   /* Triedenie. */    /* Sorting */
   printf("Sorting... ");    printf("Sorting... ");
   if(sort(argv[2])){    if (sort(argv[2])) {
     puts("fail.");      puts("fail.");
     return(1);      return(1);
   }    }
   else puts("OK.");    else puts("OK.");
   
   /* Odstranovanie rovnakych prvkov. */    /* Removing multiple items */
   
   printf("Optimalization... ");    printf("Optimalization... ");
   if(frmsort(argv[2],strrcmp)){    if (frmsort(argv[2],strrcmp)) {
     puts("fail.");      puts("fail.");
     return(1);      return(1);
   }    }
Line 81  int main(int argc,char*argv[]){
Line 80  int main(int argc,char*argv[]){
   
   puts("All done.");    puts("All done.");
   return(0);    return(0);
 } // main()  }
   
   /* Function checks valid e-mail address constraints
   
 /* Funkcia specifikuje podmienky pre platnu e-mailovu adresu.     1. Address must contain just one '@' character
  *     2. On the right side of '@' there must be at least one '.' character
  * 1.) Adresa musi obsahovat prave jeden znak '@'.     3. On the left side of '@' there can be no more than one '.' character
  * 2.) Vpravo od '@' musi byt aspon jeden znak '.'.     4. Behind the last point '.' there can be 2, 3 or 4 characters
  * 3.) Vlavo od '@' moze byt najviac jeden znak '.'.  
  * 4.) Za poslednou bodkou mozu ist najviac 4 a najmenej dva znaky.  
  */  
   
 int isvalidemail(const char*s){  */
   
   int isvalidemail(const char *s)
   {
   char*ms;    char*ms;
   if((ms=strchr(s,'@'))==NULL)return(0);    if ((ms=strchr(s,'@'))==NULL)return(0);
   if(strchr(ms+1,'@')!=NULL)return(0);    if (strchr(ms+1,'@')!=NULL)return(0);
   if(strchr(ms+1,'.')==NULL)return(0);    if (strchr(ms+1,'.')==NULL)return(0);
   if(strchr(s,'.')<ms)if(strchr(strchr(s,'.')+1,'.')<ms)return(0);    if (strchr(s,'.')<ms)if (strchr(strchr(s,'.')+1,'.')<ms)return(0);
   if(strlen(strrchr(s,'.')+1)>4||strlen(strrchr(s,'.')+1)<2)return(0);    if (strlen(strrchr(s,'.')+1)>4||strlen(strrchr(s,'.')+1)<2)return(0);
   return(1);    return(1);
 }  }
   
 int extract(const char*fin_name,const char*fout_name){  int extract(const char *fin_name, const char *fout_name)
   {
   char buf[BUFSIZE],*xbuf;    char buf[BUFSIZE],*xbuf;
   FILE*fin,*fout;    FILE*fin,*fout;
   
   if((fin=fopen(fin_name,INPUT_FMODE))==NULL)return(1);    if ((fin=fopen(fin_name,INPUT_FMODE))==NULL)return(1);
   if((fout=fopen(fout_name,OUTPUT_FMODE))==NULL)return(1);    if ((fout=fopen(fout_name,OUTPUT_FMODE))==NULL)return(1);
   
   memset((void*)buf,'\0',sizeof(buf));    memset((void*)buf,'\0',sizeof(buf));
   while(fscanf(fin,"%300s",buf)!=EOF){    while (fscanf(fin,"%300s",buf)!=EOF) {
     strlwr(buf);      strlwr(buf);
     while((xbuf=strchr(buf,'@'))!=NULL){      while ((xbuf=strchr(buf,'@'))!=NULL) {
       while(xbuf>buf&&isemail(xbuf[-1]))xbuf--;        while (xbuf>buf&&isemail(xbuf[-1]))xbuf--;
       while(xbuf>buf){        while (xbuf>buf) {
         strdel(buf);          strdel(buf);
         xbuf--;          xbuf--;
       }        }
       xbuf=strchr(buf,'@');        xbuf=strchr(buf,'@');
       while(isemail(xbuf[0]))xbuf++;        while (isemail(xbuf[0]))xbuf++;
       if(xbuf[0]=='\0')xbuf[1]='\0';        if (xbuf[0]=='\0')xbuf[1]='\0';
       else xbuf[0]='\0';        else xbuf[0]='\0';
   
       while(buf[0]=='.')strdel(buf);        while (buf[0]=='.')strdel(buf);
       while(buf[strlen(buf)-1]=='.')strdel(buf+strlen(buf)-1);        while (buf[strlen(buf)-1]=='.')strdel(buf+strlen(buf)-1);
   
       if(isvalidemail(buf)){        if (isvalidemail(buf)) {
         fputs(buf,fout);          fputs(buf,fout);
         fputc('\n',fout);          fputc('\n',fout);
       }        }
Line 140  int extract(const char*fin_name,const ch
Line 142  int extract(const char*fin_name,const ch
   return(0);    return(0);
 }  }
   
 int sort(const char*filename){  int sort(const char*filename)
   char buf[BUFSIZE],ftmpname[L_tmpnam];  {
     char buf[BUFSIZE];
   FILE*f,*ftmp;    FILE*f,*ftmp;
   
   #ifdef __MSDOS__
     char ftmpname[L_tmpnam + 1];
   tmpnam(ftmpname);    tmpnam(ftmpname);
   #else
   if((f=fopen(filename,"rt"))==NULL)return(-1);    /* This case is not possible for MS-DOS systems
   if((ftmp=fopen(ftmpname,"wt"))==NULL)return(-1);           because maximum length of filename is 12 (8 + 3 + 1) */
     char ftmpname[] = "_libplaton_utils_getmails_getmails_c_XXXXXX";
   /* Zapiseme e-mailove adresy obratene, aby sme ich mohli lahko utriedit. */    close(mkstemp(ftmpname));
   while(fgets(buf,sizeof(buf),f)!=NULL){  #endif
     if(fputs(strrev(strrmeol(buf)),ftmp)==EOF)return(-1);  
     if(fputc('\n',ftmp)==EOF)return(-1);    if ((f=fopen(filename,"rt"))==NULL)return(-1);
     if ((ftmp=fopen(ftmpname,"wt"))==NULL)return(-1);
   
     /* We will write e-mail adresses reversed, thus they can be easily sorted */
     while (fgets(buf,sizeof(buf),f)!=NULL) {
       if (fputs(strrev(strrmeol(buf)),ftmp)==EOF)return(-1);
       if (fputc('\n',ftmp)==EOF)return(-1);
   }    }
   
   if(fclose(ftmp)==EOF)return(-1);    if (fclose(ftmp)==EOF)return(-1);
   if(fclose(f)==EOF)return(-1);    if (fclose(f)==EOF)return(-1);
   
   /* Systemove triedenie. */    /* Sorting using operating system call */
   #ifdef __MSDOS__    #ifdef __MSDOS__
     sprintf(buf,"type %s | sort > %s",ftmpname,ftmpname);      sprintf(buf,"type %s | sort > %s",ftmpname,ftmpname);
   #else    #else
     sprintf(buf,"cat %s | sort > %s",ftmpname,ftmpname);      sprintf(buf,"cat %s | sort > %s",ftmpname,ftmpname);
   #endif    #endif
   if(system(buf)<0){    if (system(buf) < 0) {
     #if DEBUG      #if DEBUG
       fprintf(stderr,"sort() WARNING: System call failed. [ftmpname=%s]\n",ftmpname);        fprintf(stderr,"sort() WARNING: System call failed. [ftmpname=%s]\n",ftmpname);
     #endif      #endif
   }    }
   
   if((f=fopen(filename,"wt"))==NULL)return(-1);    if ((f=fopen(filename,"wt"))==NULL)return(-1);
   if((ftmp=fopen(ftmpname,"rt"))==NULL)return(-1);    if ((ftmp=fopen(ftmpname,"rt"))==NULL)return(-1);
   
   /* Prevratime naspat. */    /* Reverting back */
   while(fgets(buf,sizeof(buf),ftmp)!=NULL){    while (fgets(buf,sizeof(buf),ftmp)!=NULL) {
     if(fputs(strrev(strrmeol(buf)),f)==EOF)return(-1);      if (fputs(strrev(strrmeol(buf)),f)==EOF)return(-1);
     if(fputc('\n',f)==EOF)return(-1);      if (fputc('\n',f)==EOF)return(-1);
   }    }
   
   if(fclose(ftmp)==EOF)return(-1);    if (fclose(ftmp)==EOF)return(-1);
   if(fclose(f)==EOF)return(-1);    if (fclose(f)==EOF)return(-1);
   
   if(remove(ftmpname))return(-1);    if (remove(ftmpname))return(-1);
   
   return(0);    return(0);
 }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top