home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / sarg1221.zip / util.c < prev   
C/C++ Source or Header  |  2002-10-14  |  15KB  |  798 lines

  1. #include "include/conf.h"
  2.  
  3. static char mtab1[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
  4. static char mtab2[12][3]={"01","02","03","04","05","06","07","08","09","10","11","12"};
  5.  
  6. char* encode_filename( char* to, const char* from )
  7. {
  8.   int i;
  9.  
  10.   #if defined(__OS2__)
  11.     strncpy( to, from, 128 );
  12.     to[128] = 0;
  13.   #else
  14.     strcpy ( to, from );
  15.   #endif
  16.  
  17.   for( i=0; i<strlen(to); i++ )
  18.     if( strchr( "-.:/?*|><\"\\", to[i] ))
  19.        to[i]='_';
  20.  
  21.   return to;
  22. }
  23.  
  24. void getword(char *word, char *line, int stop)
  25. {
  26.   int x = 0,y;
  27.   int loop=0;
  28.   int limit=10000;
  29.   char wline[MAXLEN];
  30.  
  31.   strcpy(wline,line);
  32.  
  33.   if(strlen(line) < 3) {
  34.      word[0]='\0';
  35.      return;
  36.   }
  37.  
  38.   for(x=0;((line[x]) && (line[x] != stop ));x++) {
  39.      loop++;
  40.      if(loop>=limit) {
  41.         printf("SARG: getword loop detected.\n");
  42.         printf("SARG: Record=\"%s\"\n",wline);
  43.         printf("SARG: searching for \'x%x\'\n",stop);
  44.         printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
  45.         word[0]='\0';
  46.         exit(1);
  47.      }
  48.      word[x] = line[x];
  49.   }
  50.  
  51.   word[x] = '\0';
  52.   if(line[x]) ++x;
  53.     y=0;
  54.  
  55.   while((line[y++] = line[x++]));
  56. }
  57.  
  58. // BMG (bguillory@email.com)
  59. // 3 August 1999
  60. long long int my_atoll (const char *nptr)
  61. #define MAXLLL 30 //maximum number of digits in long long (a guess)
  62. {
  63.   int offset=0, x;
  64.   long long int returnval=0;
  65.   char one_digit[2];
  66.  
  67.   one_digit[1]='\0';
  68.  
  69.   // Soak up all the white space
  70.   while (isspace(nptr[offset])) {
  71.     offset++;
  72.   } //while
  73.  
  74.   //For each character left to right
  75.   //change the character to a single digit
  76.   //multiply what we had before by 10 and add the new digit
  77.   for(x=offset; x<=MAXLLL+offset && isdigit(nptr[x]); x++) {
  78.     sprintf(one_digit, "%c", nptr[x]); //I don't know how else to do this
  79.     returnval = (returnval * 10) + atoi(one_digit);
  80.   } //for
  81.  
  82.   return returnval;
  83.  
  84. } //my_atoll
  85.  
  86.  
  87. void my_lltoa(unsigned long long int n, char s[], int len)
  88. {
  89.   int i = 0;
  90.   int x = 0;
  91.   char ww[50];
  92.   do {
  93.     s[i++] = (n % 10) + '0';
  94.   } while ((n /= 10) > 0);
  95.   s[i] = '\0';
  96.   {
  97.     int c,i,j;
  98.     for (i = 0, j = strlen(s)-1; i<j; i++, j--)
  99.       {
  100.         c = s[i];
  101.         s[i] = s[j];
  102.         s[j] = c;
  103.       }
  104.   }
  105.   
  106.   if(len) {
  107.      bzero(ww,50);
  108.      i=len-strlen(s)-1;
  109.      for(x=0; x<=i; x++)
  110.         ww[x]='0';
  111.      strncat(ww,s,strlen(s));
  112.      strcpy(s,ww);
  113.   }
  114.     
  115. }
  116.  
  117.  
  118. void builddia(char *dia, char *mes, char *ano, char *df, char *wdata)
  119. {
  120.    char ndia[9];
  121.    char nmes[3];
  122.    int  x;
  123.  
  124.    ndia[0]='\0';
  125.    nmes[0]='\0';
  126.  
  127.    for(x=0; x<=12; x++) {
  128.       if(strcmp(mtab1[x],mes) == 0)
  129.          strcpy(nmes,mtab2[x]);
  130.    }
  131.  
  132.    sprintf(wdata,"%s%s%s",ano,nmes,dia);
  133.  
  134.    if(strncmp(df,"u",1) != 0)
  135.       sprintf(ndia,"%s/%s/%s",dia,nmes,ano);
  136.     else
  137.       sprintf(ndia,"%s/%s/%s",nmes,dia,ano);
  138.  
  139.    strcpy(dia,ndia);
  140.  
  141.    return;
  142.  
  143. }
  144.  
  145.  
  146. void fixper(char *tbuf, char *periodo, char *duntil)
  147. {
  148.  
  149.    char warea[50];
  150.    char dia[3];
  151.    char mes[4]; // DAS: 3 characters + '\0'
  152.    char ano[5];
  153.    int  x;
  154.  
  155.    warea[0]='\0';
  156.  
  157.    // DAS: allways YYYYMMDD after date_from()
  158.    strncpy(dia,duntil+6,2);
  159.    dia[2]='\0';
  160.    strncpy(mes,duntil+4,2);
  161.    mes[2]='\0';
  162.    strncpy(ano,duntil,4);
  163.    ano[4]='\0';
  164.  
  165.    for(x=0; x<=12; x++) {
  166.       if(strcmp(mtab2[x],mes) == 0)
  167.          strcpy(mes,mtab1[x]);
  168.    }
  169.  
  170.    if(strcmp(df,"e") == 0)
  171.       sprintf(warea,"%s%s%s",dia,mes,ano);
  172.    if(strcmp(df,"u") == 0)
  173.       sprintf(warea,"%s%s%s",ano,mes,dia);
  174.  
  175.    strcat(periodo,warea);
  176.    return;
  177. }
  178.  
  179.  
  180. void debuga(char *msg)
  181. {
  182.   fprintf(stderr, "SARG: %s\n",msg);
  183.  
  184.   return;
  185. }
  186.  
  187.  
  188. void debugaz(char *head, char *msg)
  189. {
  190.   fprintf(stderr, "SARG: (util) %s=%s\n",head, msg);
  191.  
  192.   return;
  193. }
  194.  
  195.  
  196. void fixip(char *ip)
  197. {
  198.    char n1[MAXLEN], n2[MAXLEN], n3[MAXLEN];
  199.    char wip[MAXLEN];
  200.    char sep[2]=".";
  201.    int iflag=0;
  202.  
  203.    strcpy(wip,ip);
  204.  
  205.    if(strstr(ip,".") != 0) {
  206.       strcpy(sep,"_");
  207.       iflag++;
  208.    }
  209.  
  210.    if(iflag) {
  211.       getword(n1,wip,'.');
  212.       getword(n2,wip,'.');
  213.       getword(n3,wip,'.');
  214.    } else {
  215.       getword(n1,wip,'_');
  216.       getword(n2,wip,'_');
  217.       getword(n3,wip,'_');
  218.    }
  219.    ip[0]='\0';
  220.    sprintf(ip,"%s%s%s%s%s%s%s",n1,sep,n2,sep,n3,sep,wip);
  221.  
  222.    return;
  223. }
  224.  
  225.  
  226. char *fixnum(long long int inteiro)
  227. #define MAXIMO 1024
  228. {
  229.    char num[MAXIMO];
  230.    char buf[MAXIMO * 2];
  231.    char *pbuf;
  232.    char ret[MAXIMO * 2];
  233.    char *pret;
  234.    register int i, j, k;
  235.  
  236.    my_lltoa(inteiro, num, 0);
  237.  
  238.    for(i=0;i<MAXIMO*2;i++)
  239.    buf[i]='\0';
  240.  
  241.    pbuf = buf;
  242.    pret = ret;
  243.    k = 0;
  244.  
  245.    for ( i = strlen(num) - 1, j = 0 ; i > -1; i--) {
  246.       if ( k == 2 && i != 0 )  {
  247.          k = 0;
  248.          pbuf[j++] = num[i];
  249.          if(strcmp(UseComma,"yes") == 0)
  250.             pbuf[j++] = ',';
  251.          else pbuf[j++] = '.';
  252.          continue;
  253.       }
  254.       pbuf[j] = num[i];
  255.       j++;
  256.       k++;
  257.    }
  258.  
  259.    pret[0]='\0';
  260.  
  261.    for ( i = strlen(pbuf) - 1, j = 0 ; i > -1; i--, j++)
  262.       pret[j] = pbuf[i];
  263.  
  264.       pret[j] = '\0';
  265.  
  266.       return pret;
  267. }
  268.  
  269.  
  270. void buildhref(char * href)
  271. {
  272.    char whref[MAXLEN];
  273.  
  274.    if(strcmp(href,"./") == 0){
  275.       href[0]='\0';
  276.       strcat(href,"<a href='");
  277.       return;
  278.    }
  279.  
  280.    href[strlen(href)-1]='\0';
  281.    sprintf(whref,"%s",strrchr(href,'/'));
  282.  
  283.    strcpy(href,"<a href='");
  284.    strcat(href,whref);
  285.    strcat(href,"/");
  286.  
  287.    return;
  288.  
  289. }
  290.  
  291.  
  292. char *buildtime(long long int elap)
  293. {
  294.  
  295.    int num = elap / 1000;
  296.    int hor = 0;
  297.    int min = 0;
  298.    int sec = 0;
  299.    static char buf[12];
  300.  
  301.    buf[0]='\0';
  302.  
  303.    hor=num / 3600;
  304.    min=(num % 3600) / 60;
  305.    sec=num % 60;
  306.    sprintf(buf,"%02d:%02d:%02d",hor,min,sec);
  307.  
  308.    return(buf);
  309.  
  310. }
  311.  
  312.  
  313. void obtdate(char *dirname, char *name, char *data)
  314. {
  315.  
  316.    FILE *fp_in;
  317.    char wdir[MAXLEN];
  318.  
  319.    sprintf(wdir,"%s%s/date",dirname,name);
  320.    if ((fp_in = fopen(wdir, "r")) == 0) {
  321.       data[0]='\0';
  322.       return;
  323.    }
  324.  
  325.    fgets(data,80,fp_in);
  326.    fclose(fp_in);
  327.    data[strlen(data)-1]='\0';
  328.  
  329.    return;
  330.  
  331. }
  332.  
  333.  
  334. void obtuser(char *dirname, char *name, char *tuser)
  335. {
  336.  
  337.    FILE *fp_in;
  338.    char wdir[MAXLEN];
  339.  
  340.    sprintf(wdir,"%s%s/usuarios",dirname,name);
  341.    if((fp_in=fopen(wdir,"r"))==NULL){    
  342.       tuser[0]='\0';
  343.       return;
  344.    }
  345.  
  346.    fgets(tuser,20,fp_in);
  347.    tuser[strlen(tuser)-1]='\0';
  348.    fclose(fp_in);
  349.  
  350.    return;
  351.  
  352. }
  353.  
  354.  
  355. void obttotal(char *dirname, char *name, char *tbytes, char *tuser, char *media)
  356. {
  357.  
  358.    FILE *fp_in;
  359.    char wdir[MAXLEN];
  360.    long long int med=0;
  361.    long long int wtuser=0;
  362.  
  363.    sprintf(wdir,"%s%s/geral",dirname,name);
  364.  
  365.    if ((fp_in = fopen(wdir, "r")) == 0) {
  366.       tbytes=0;
  367.       return;
  368.    }
  369.  
  370.    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
  371.       getword(warea,buf,' ');
  372.       if(strcmp(warea,"TOTAL") != 0)
  373.          continue;
  374.       getword(warea,buf,' ');
  375.       getword(warea,buf,' ');
  376.       twork=my_atoll(warea);
  377.       sprintf(tbytes,"%s",fixnum(twork));
  378.    }
  379.    fclose(fp_in);
  380.  
  381.    if(tuser[0] == '\0') {
  382.       wtuser=0;
  383.       sprintf(media,"%s","0");
  384.       fclose(fp_in);
  385.       return;
  386.    }
  387.    
  388.    wtuser=my_atoll(tuser);
  389.    med=my_atoll(warea) / wtuser;
  390.    sprintf(media,"%s",fixnum(med));
  391.  
  392.    return;
  393.  
  394. }
  395.  
  396.  
  397. void gperiodo(char *dirname, const char *periodo, int debug)
  398. {
  399.  
  400.    FILE *fp_ou;
  401.  
  402.    char wdirname[MAXLEN];
  403.  
  404.    strcpy(wdirname,dirname);
  405.    strcat(wdirname,"/");
  406.    strcat(wdirname,"periodo");
  407.  
  408.    if((fp_ou=fopen(wdirname,"w"))==NULL){
  409.       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
  410.       exit(1);
  411.    }
  412.  
  413.    fputs(periodo,fp_ou);
  414.    fclose(fp_ou);
  415.  
  416.    if(debug)
  417.       debuga((char *)text[50]);
  418.  
  419.    return;
  420.  
  421. }
  422.  
  423. void vrfydir(char *dir, char *dirname, char *per1, char *addr, char *site, char *us, int debug, char *form)
  424. {
  425.    int  num=1, count=0;
  426.    char wdir[MAXLEN];
  427.    char per2[MAXLEN];
  428.  
  429.    #if defined(__OS2__)
  430.      FILE* fh;
  431.      time_t local_time;
  432.    #endif
  433.  
  434.    if(strcmp(OverwriteReport,"no") == 0) {
  435.       while(num) {
  436.          if(access(dirname,F_OK) == 0) {
  437.             sprintf(dirname,"%s.%d",dir,num);
  438.             sprintf(per2,"%s.%d",per1,num);
  439.             num++;
  440.             count++;
  441.          } else
  442.             break;
  443.       }
  444.    
  445.       if(count > 0) {
  446.          if(debug)
  447.             fprintf(stderr, "SARG: %s: %s %s %s\n",text[51],dir,text[52],dirname);
  448.          rename(dir,dirname);
  449.       }
  450.    } else {
  451.       if(access(dir,F_OK) == 0) {
  452.          sprintf(wdir, RM" -r %s",dir);
  453.          system(wdir);
  454.       }
  455.    }
  456.  
  457.    sprintf(wdir, MKDIR" -p %s",dir);
  458.    if(strlen(us) > 0) {
  459.       strcat(wdir,"-");
  460.       strcat(wdir,us);
  461.    }
  462.    if(strlen(addr) > 0) {
  463.       strcat(wdir,"-");
  464.       strcat(wdir,addr);
  465.    }
  466.    if(strlen(site) > 0) {
  467.       strcat(wdir,"-");
  468.       strcat(wdir,site);
  469.    }
  470.  
  471.    system(wdir);
  472.  
  473.    sprintf(dirname,"%s",wdir+sizeof(MKDIR)+3);
  474.  
  475.    #if defined(__OS2__)
  476.      sprintf( wdir,"%s/%s", dirname, "date" );
  477.      fh = fopen( wdir, "w" );
  478.      time( &local_time );
  479.      fprintf( fh, "%s\n", asctime( localtime( &local_time )));
  480.      fclose( fh );
  481.    #else
  482.      sprintf(wdir,"date >%s/%s",dirname,"date");
  483.      system(wdir);
  484.    #endif
  485.  
  486.    return;
  487.  
  488. }
  489.  
  490.  
  491. void strip_latin(char *line)
  492. {
  493.    char buf[255];
  494.    char warea[255];
  495.  
  496.    while(strstr(line,"&") != 0){
  497.       getword(warea,line,'&');
  498.       strncat(warea,line,1);
  499.       getword(buf,line,';');
  500.       strcat(warea,line);
  501.       strcpy(line,warea);
  502.    }
  503.  
  504.    return;
  505.  
  506. }
  507.  
  508. void zdate(char *ftime, char *DateFormat)
  509. {
  510.  
  511.    time_t t;
  512.    struct tm *local;
  513.  
  514.    t = time(NULL);
  515.    local = localtime(&t);
  516.    if(strcmp(DateFormat,"u") == 0)
  517.       strftime(ftime, 127, "%b/%d/%Y %H:%M", local);
  518.    if(strcmp(DateFormat,"e") == 0)
  519.       strftime(ftime, 127, "%d/%b/%Y-%H:%M", local);
  520.    if(strcmp(DateFormat,"w") == 0)
  521.       strftime(ftime, 127, "%V-%H-%M", local);
  522.  
  523.    return;
  524. }
  525.  
  526.  
  527. char *fixtime(long int elap)
  528. {
  529.  
  530.    int num = elap / 1000;
  531.    int hor = 0;
  532.    int min = 0;
  533.    int sec = 0;
  534.    static char buf[12];
  535.  
  536.    if(strcmp(datetimeby,"bytes") == 0) {
  537.       sprintf(buf,"%s",fixnum(elap));
  538.       return buf;
  539.    }
  540.  
  541.    buf[0]='\0';
  542.  
  543.    if(num<1) {
  544.       sprintf(buf,"00:00:%02ld",elap);
  545.       return buf;
  546.    }
  547.  
  548.    hor=num / 3600;
  549.    min=(num % 3600) / 60;
  550.    sec=num % 60;
  551.  
  552.    sprintf(buf,"%01d:%02d:%02d",hor,min,sec);
  553.  
  554.    if(strcmp(buf,"0:00:00") == 0)
  555.       strcpy(buf,"0");
  556.  
  557.    return buf;
  558.  
  559. }
  560.  
  561.  
  562. void date_from(char *date, char *dfrom, char *duntil)
  563. {
  564.  
  565.    char diaf[10];
  566.    char mesf[10];
  567.    char anof[10];
  568.    char diau[10];
  569.    char mesu[10];
  570.    char anou[10];
  571.    static char wdate[50];
  572.  
  573.  
  574.    strcpy(wdate,date);
  575.    if(strstr(wdate,"-") == 0) {
  576.       strcat(wdate,"-");
  577.       strcat(wdate,date);
  578.       strcpy(date,wdate);
  579.    }
  580.  
  581.    getword(diaf,wdate,'/');
  582.    getword(mesf,wdate,'/');
  583.    getword(anof,wdate,'-');
  584.    getword(diau,wdate,'/');
  585.    getword(mesu,wdate,'/');
  586.    strcpy(anou,wdate);
  587.  
  588.    sprintf(dfrom,"%s%s%s",anof,mesf,diaf);
  589.    sprintf(duntil,"%s%s%s",anou,mesu,diau);
  590.    return;
  591. }
  592.  
  593.  
  594. char *strlow(char *string)
  595. {
  596.       char *s;
  597.  
  598.       if (string)
  599.       {
  600.             for (s = string; *s; ++s)
  601.                   *s = tolower(*s);
  602.       }
  603.  
  604.       return string;
  605. }
  606.  
  607.  
  608.  
  609.  
  610. char *strup(char *string)
  611. {
  612.       char *s;
  613.  
  614.       if (string)
  615.       {
  616.             for (s = string; *s; ++s)
  617.                   *s = toupper(*s);
  618.       }
  619.  
  620.       return string;
  621. }
  622.  
  623.  
  624. char *subs(char *str, char *from, char *to)
  625. {
  626.    char *tmp;
  627.    char *ret;
  628.    unsigned int ss, st;
  629.  
  630.    if(strstr(str,from) == 0)
  631.       return (char *) str;
  632.  
  633.     ss = strlen(str); st = strlen(to);
  634.     ret = (char *) malloc(ss + st);
  635.     bzero(ret,ss+st);
  636.  
  637.     tmp = strstr(str, from);
  638.     if ( tmp == (char *) NULL )
  639.        return (char *) NULL;
  640.     strncpy(ret, str, ss - strlen(tmp));
  641.     strcat(ret, to);
  642.     strcat(ret, (tmp+strlen(from)));
  643.     return (char *) ret;
  644. }
  645.  
  646. void removetmp(char *outdir, int debug)
  647. {
  648.  
  649.    FILE *fp_in;
  650.    char warea[256];
  651.  
  652.    if(strcmp(RemoveTempFiles,"yes") != 0) {
  653.       return;
  654.    } else {
  655.       if(debug) {
  656.          sprintf(msg,"%s: geral, periodo",text[82]);
  657.          debuga(msg);
  658.       }
  659.       sprintf(warea,"%s/geral",outdir);
  660.       if((fp_in=fopen(warea,"r"))==NULL){
  661.          fprintf(stderr, "SARG: (removetmp) %s: %s\n",text[45],warea);
  662.          exit(1);
  663.       }
  664.       while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
  665.          if(strncmp(buf,"TOTAL",5) == 0)
  666.             break;
  667.       }
  668.       fclose(fp_in);
  669.       if((fp_in=fopen(warea,"w"))==NULL){
  670.          fprintf(stderr, "SARG: (removetmp) %s: %s\n",text[45],warea);
  671.          exit(1);
  672.       }
  673.       fputs(buf,fp_in);
  674.       fclose(fp_in);
  675.       sprintf(warea,"%s/periodo",outdir);
  676.       unlink(warea);
  677.    }
  678.   
  679.    return;
  680. }
  681.  
  682. void load_excludecodes()
  683. {
  684.  
  685.    FILE *fp_in;
  686.    char data[80];
  687.  
  688.    if((fp_in=fopen(ExcludeCodes,"r"))==NULL) {
  689.      fprintf(stderr, "SARG: (util) Cannot open file: %s (exclude_codes)\n",ExcludeCodes);
  690.      exit(1);
  691.    }
  692.  
  693.    while(fgets(data,80,fp_in)!=NULL) {
  694.       data[strlen(data)-1]='\0';
  695.       strcat(excludecode,data);
  696.       strcat(excludecode,";");
  697.       excode++;
  698.    }
  699.  
  700.    fclose(fp_in);
  701.    return;
  702.  
  703. }
  704.  
  705. int vercode(char *code)
  706. {
  707.    char warea[1024];
  708.    char cod[80];
  709.    int z;
  710.  
  711.    strcpy(warea,excludecode);
  712.    for(z=0; z<=excode-1; z++) {
  713.       getword(cod,warea,';');
  714.       if(strcmp(code,cod) == 0) 
  715.          return 1;
  716.    }
  717.    return 0;
  718. }
  719.  
  720. void fixnone(char *str)
  721. {
  722.    if(strstr(str,"\n") != 0)
  723.       str[strlen(str)-1]='\0';
  724.    if(strcmp(str,"none") == 0)
  725.       str[0]='\0';
  726.  
  727.    return;
  728. }
  729.  
  730. int testvaliduserchar(char *user)
  731. {
  732.  
  733.    int x=0;
  734.    int y=0;
  735.  
  736.    for (y=0; y<strlen(UserInvalidChar); y++) {
  737.       for (x=0; x<strlen(user); x++) {
  738.          if(user[x] == UserInvalidChar[y])
  739.             return 1;
  740.       }
  741.    }
  742.    return 0;
  743. }
  744.  
  745. int compar( const void *a, const void *b )
  746. { if( *(int *)a > *(int *)b ) return 1;
  747.   if( *(int *)a < *(int *)b ) return -1;
  748.   return 0;
  749. }
  750.  
  751. int getnumlist( char *buf, numlist *list, const int len, const int maxvalue )
  752. { int i, j, d, flag, r1, r2;
  753.   char *pbuf, **bp, *strbufs[ 24 ];
  754.   
  755.   bp = strbufs;
  756.   strtok( buf, " \t" );
  757.   for( *bp = strtok( NULL, "," ), list->len = 0; *bp; *bp = strtok( NULL, "," ) )
  758.    { if( ++bp >= &strbufs[ 24 ] )
  759.        break;
  760.      list->len++;
  761.    }
  762.   if( ! list->len )      
  763.      return -1;
  764.   d = 0;
  765.   for( i = 0; i < list->len; i++ )  
  766.    { if( strstr( strbufs[ i ], "-" ) != 0 )
  767.       { pbuf = strbufs[ i ];
  768.         strtok( pbuf, "-" );
  769.         pbuf = strtok( NULL, "\0" );
  770.         r1 = atoi( strbufs[ i ] );
  771.         if( ( r2 = atoi( pbuf ) ) >= maxvalue || r1 >= r2 )
  772.           return -1;
  773.         if( i + d + ( r2 - r1 ) + 1 <= len )
  774.          { for( j = r1; j <= r2; j++ )
  775.              list->list[ i + d++ ] = j;
  776.            d--;
  777.          }
  778.       }
  779.      else
  780.        if( ( list->list[ i + d ] = atoi( strbufs[ i ] ) ) >= maxvalue )
  781.           return 1;
  782.    }
  783.   list->len += d;
  784.   qsort( list->list, list->len, sizeof( int ), compar );
  785.   do
  786.    { flag = 0;
  787.      for( i = 0; i < list->len - 1; i++ )
  788.        if( list->list[ i ] == list->list[ i + 1 ] )
  789.         { for( j = i + 1; j < list->len; j++ )
  790.         list->list[ j - 1 ] = list->list[ j ];
  791.           list->len--;
  792.           flag = 1;
  793.           break;
  794.         }
  795.    } while( flag );
  796.   return 0;
  797. }
  798.