home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / internet / freedomc_112 / sourcecode / freedomcall / freedom.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-27  |  31.4 KB  |  989 lines

  1. #include "freegui.h"
  2. #include "freemain.h"
  3. #include "freeextern.h"
  4.  
  5. #include <proto/muimaster.h>
  6. #include <clib/alib_protos.h>
  7. #include <libraries/mui.h>
  8. #include <libraries/asl.h>
  9.  
  10. char pilha[50][50];
  11. int pilhafim = 0;
  12.  
  13. char *TMsg(struct Hook *objeto)
  14. {
  15.   /* LE O CONTEUDO DE UM OBJETO, O TEXT */
  16.   char *teste;
  17.   get(objeto, MUIA_Text_Contents, &teste);
  18.   return teste;
  19. }
  20.  
  21. char *CalculaPrecoFREE(char arquivo[256], int hora1, int hora2, int semana)
  22. {
  23.   /* Este comando calcula o preco de uma determinada ligacao.
  24.  
  25.   Entrada : Arquivo da Categoria   --> Categories/Brazil.CRT (CHAR 256)
  26.             Hora Inicio (Segundos) --> 233445 (INT)
  27.             Hora Final  (Segundos) --> 255455 (INT)
  28.             Semana                 --> 0      (INT)
  29.   Obs     : A semana eh recebida de acordo com os valores da funcao
  30.             DiaSemana("01.02.1997", 2);
  31.   Saida   : O custo da ligacao     --> 0.234  (CHAR 256)
  32.             CalculaPrecoFREE("Categories/Brazil.CRT", 233445, 255455, 0);
  33.   */
  34.  
  35.   char teste[256], *valordefault;
  36.   int x = 0, fim = 0, h1 = 0, h2 = 0,
  37.       h3 = 0;
  38.   float valor = 0, hvalor = 0, hvalorpadrao = 0, diferenca = 0, hhh = 0;
  39.  
  40.   get(App->CategValorDefault, MUIA_String_Contents, &valordefault);
  41.   hvalorpadrao = atof(valordefault);
  42.  
  43.   /* FILTRA OS HORARIOS CASO TROQUE O DIA */
  44.   if(hora2 < hora1)
  45.   {
  46.     diferenca = hora2;
  47.     hora2 = 86399;
  48.   }
  49.  
  50.   /* CASE PARA ACERTAR O DIA DA SEMANA DE ACORDO COM O COMBO */
  51.   switch (semana)
  52.   {
  53.     case  0: semana = 6; break;
  54.     case  1: semana = 7; break;
  55.     case  2: semana = 1; break;
  56.     case  3: semana = 2; break;
  57.     case  4: semana = 3; break;
  58.     case  5: semana = 4; break;
  59.     case  6: semana = 5; break;
  60.   }
  61.  
  62.   /* PILHA ONDE SERAO ARMAZENADOS LIMITES (pilha) MAXIMO 50 LIMITES
  63.   A VARIAVEL QUE GUARDA O NUMERO DE LIMITES NA PILHA EH (xpilha) */
  64.  
  65.   LOOP:
  66.   for(x = 0; x < pilhafim; x++)
  67.   {
  68.     strcpy(teste, pilha[x]);
  69.  
  70.     h1 = atoi(Corta(teste, ' ', 0));
  71.     h2 = atoi(Corta(teste, ' ', 1));
  72.     h3 = atoi(Corta(teste, ' ', 3));
  73.     hvalor = atof(Corta(teste, ' ', 2));
  74.  
  75.     if(h3 == 0 || h3 == semana)
  76.     {
  77.       /* 5, 10 SELECIONADO (6, 9) ou (5, 10) ou (5, 9) ou (6, 10) */
  78.       if((hora1 >= h1 && hora1 < h2) &&
  79.          (hora2 <= h2 && hora2 > h1)) { 
  80.         hhh = hora2 - hora1;
  81.         valor = valor + ((hhh / 60) * hvalor); fim = 1; break; }
  82.  
  83.       /* 5, 10 SELECIONADO (4, 9) ou (4, 10) */
  84.       if((hora1 < h1 && hora1 < h2) &&
  85.          (hora2 <= h2 && hora2 > h1)) {
  86.         hhh = hora2 - h1;
  87.         valor = valor + ((hhh  / 60) * hvalor);
  88.         hora2 = h1; x = -1; }
  89.     
  90.       /* 5, 10 SELECIONADO (5, 11) ou (6, 11) */
  91.       /* 5, 10 SELECIONADO (4, 11) */
  92.       if(((hora1 >= h1 && hora1 < h2) &&
  93.           (hora2 > h2 && hora2 > h1)) ||
  94.          ((hora1 < h1 && hora1 < h2) &&
  95.           (hora2 > h2 && hora2 > h1))) {
  96.         hhh = h2 - hora1;
  97.         valor = valor + ((hhh / 60) * hvalor);
  98.         hora1 = h2; x = -1; }
  99.     }
  100.   }
  101.   if(diferenca > 0)
  102.   {
  103.     hora1 = 0;
  104.     hora2 = diferenca;
  105.     diferenca = 0;
  106.     goto LOOP;
  107.   }
  108.   if(fim == 0)
  109.   {
  110.     hhh = hora2 - hora1;
  111.     valor = valor + ((hhh / 60) * hvalorpadrao);
  112.   }
  113.   sprintf(teste, "%f", valor);
  114.   return teste;
  115. }
  116.  
  117. int TestaExisteFone(char fone[256])
  118. {
  119.   /*
  120.   Esta funcao testa se existe o telefone para ignorar nas
  121.   estatisticas.
  122.  
  123.   Entrada : Fone --> 0800128001 (CHAR 256)
  124.   Saida   : -1 se existe e 0 se nao existe (INT)
  125.             TestaExisteFone("0800128001");
  126.   */
  127.  
  128.   char teste[256], *linhafone;
  129.   int x = 0, y = 0;
  130.   long check = 0;
  131.  
  132.   /* TESTA SE A OPCAO ESTA HABILITADA OU NAO */
  133.   get(App->GrupoFoneInputCheck, MUIA_Selected, &check);
  134.   if(check == 0)
  135.     return 0;
  136.  
  137.   get(App->GrupoFoneInput, MUIA_String_Contents, &linhafone);
  138.   for(x = 0; x <= strlen(linhafone); x++)
  139.   {
  140.     teste[y++] = linhafone[x];
  141.     if(linhafone[x] == ',' || linhafone[x] == '\0' && strcmp(teste, ""))
  142.     {
  143.       teste[--y] = '\0';
  144.       if(!strcmp(teste, fone))
  145.         return -1;
  146.       teste[0] = '\0'; y = 0;
  147.     }
  148.   }
  149.   return 0;
  150. }
  151.  
  152. char *TotalHoras(char var[256])
  153. {
  154.   /*
  155.   Comando para retirar do arquivo 'FREEDOM.IN' o total
  156.   de horas gastas por um determinado mes.
  157.  
  158.   Entrada : Mes.Ano  --> 03.1997
  159.   Saida   : Segundos --> 764534 "Passar rotina SEGUNDOHORA()
  160.   */
  161.  
  162.   char teste[256], a;
  163.   char dat[10], seg[30], linha[256];
  164.   int x, total;
  165.   FILE *entrada;
  166.  
  167.   if(!(entrada = fopen("freedom.in", "r")))
  168.   {
  169.     return "ERRO";
  170.   }
  171.   else
  172.   {
  173.     x = 0; total = 0;
  174.     while(a = getc(entrada), ! feof(entrada))
  175.     {
  176.       teste[x++] = a;
  177.       if(a == '\n')
  178.       {
  179.         teste[--x] = '\0';
  180.         strcpy(linha, teste);
  181.         strcpy(dat, Corta(teste, ',', 1));
  182.         sprintf(dat, "%s.%s", Corta(dat, '.', 1), Corta(dat, '.', 2));
  183.         if(!(strcmp(dat, var)))
  184.         {
  185.           strcpy(seg, Corta(linha, ',', 6));
  186.           total = total + atoi(seg);
  187.         }
  188.         teste[0] = '\0';
  189.         x = 0;
  190.       } 
  191.     }
  192.     fclose(entrada);
  193.     sprintf(teste, "%d", total);
  194.     return teste;
  195.   }
  196. }
  197.  
  198. char *DadosMiami(char var[256])
  199. {
  200.   /*
  201.   Comando que retira do arquivo 'FREEDOM.IN' as quantidades
  202.   de ligacoes, numero de quedas de linha, e logouts com sucesso.
  203.  
  204.   Entrada: Mes.Ano --> 03.1997
  205.   Saida  : Total Ligacoes do arquivo
  206.      Numero de logouts com Sucesso
  207.      Numero de queda de linhas
  208.      50:22:28
  209.   */
  210.  
  211.   char a, teste[256], status[5], data[20], linha[256];
  212.   int caiu, totalarquivo, offnormal, x;
  213.   FILE *entrada;
  214.  
  215.   if(!(entrada = fopen("freedom.in", "r")))
  216.     return "ERRO";
  217.   else
  218.   {
  219.     x = 0; caiu = 0; totalarquivo = 0; offnormal = 0;
  220.     while(a = getc(entrada), ! feof(entrada))
  221.     {
  222.       teste[x++] = a;
  223.       if(a == '\n')
  224.       {
  225.         teste[--x] = '\0';
  226.         strcpy(linha, teste);
  227.         strcpy(status, Corta(linha, ',', 5));
  228.         strcpy(data,   Corta(linha, ',', 1));
  229.         sprintf(data, "%s.%s", Corta(data, '.', 1), Corta(data, '.', 2));
  230.         if(!(strcmp(data, var)))
  231.         {
  232.           if(!(strcmp(status, "Pas")))
  233.             offnormal++;
  234.           else
  235.             caiu++;
  236.           totalarquivo++;
  237.         }
  238.         if(var[0] == 0)
  239.         {
  240.           if(!(strcmp(status, "Pas")))
  241.             offnormal++;
  242.           else
  243.             caiu++;
  244.           totalarquivo++;
  245.         }
  246.         x = 0;
  247.       }
  248.     }
  249.     fclose(entrada);
  250.     sprintf(teste, "%d:%d:%d", totalarquivo, offnormal, caiu);
  251.     return teste;
  252.   }
  253. }
  254.  
  255. char *SemanaCount(char var[256])
  256. {
  257.   /*
  258.   Esta funcao gera as estatisticas semanais em uma arquivo
  259.   chamado Ram:Freedom.Week.
  260.   Obs: Rotina re-aproveitada para criar o arquivo com as
  261.        estatisticas de velocidade.
  262.  
  263.   Entrada : Path+Nome Arquivo --> Freedom.in (CHAR 256)
  264.   Saida   : Arquivo           --> Ram:Freedom.Week 
  265.   Erro    : ERRO (CHAR RETURN)
  266.   Obs     : Sera gerado 7 campos.
  267.             1 - Domingo
  268.             2 - Segunda
  269.             3 - Terca
  270.             4 - Quarta
  271.             5 - Quinta
  272.             6 - Sexta
  273.             0 - Sabado
  274.             7 - Total de ligacoes
  275.             SemanaCount("Freedom.In");
  276.   */
  277.  
  278.   char a, teste[256], status[256],
  279.        domi[100], segu[100], terc[100], quar[100],
  280.        quin[100], sext[100], saba[100], tota[100];
  281.  
  282.   int dom = 0, seg = 0, ter = 0, qua = 0,
  283.       qui = 0, sex = 0, sab = 0, x = 0,
  284.       domx = 0, segx = 0, terx = 0, quax = 0,
  285.       quix = 0, sexx = 0, sabx = 0, totalx,
  286.  
  287.       x300 = 0, x2400 = 0, x9600 = 0, x14400 = 0, x16800 = 0,
  288.       x19200 = 0, x21600 = 0, x24000 = 0, x26400 = 0, x28800 = 0,
  289.       x30666 = 0, x31200 = 0, x32000 = 0, x33333 = 0, x34666 = 0,
  290.       x33600 = 0, x31250 = 0, x38400 = 0, x45333 = 0, x50666 = 0,
  291.       x52000 = 0, x53333 = 0, x54666 = 0, x57600 = 0, x64000 = 0,
  292.       x46666 = 0, x48000 = 0, x49333 = 0,
  293.       x76800 = 0, x115200 = 0, x230400 = 0;
  294.  
  295.   float segC = 0, terC = 0, quaC= 0, quiC= 0, sexC= 0,
  296.         sabC = 0, domC = 0, total = 0, totalc = 0;
  297.       
  298.   FILE *entrada, *saida;
  299.   if(!(entrada = fopen(var, "r")))
  300.     return "ERRO";
  301.   while(a = getc(entrada), ! feof(entrada))
  302.   {
  303.     teste[x++] = a;
  304.     if(a == '\n')
  305.     {
  306.       teste[--x] = '\0';
  307.       strcpy(status, RetiraPontas(Corta(teste, ',', 7), 1));
  308.       strcpy(status, Corta(status, '/', 0));
  309.  
  310.       /* VERIFICA RATES */
  311.       if(!strcmp(status, "300")) x300++;
  312.       if(!strcmp(status, "2400")) x2400++;
  313.       if(!strcmp(status, "9600")) x9600++;
  314.       if(!strcmp(status, "14400")) x14400++;
  315.       if(!strcmp(status, "16800")) x16800++;
  316.       if(!strcmp(status, "19200")) x19200++;
  317.       if(!strcmp(status, "21600")) x21600++;
  318.       if(!strcmp(status, "24000")) x24000++;
  319.       if(!strcmp(status, "26400")) x26400++;
  320.       if(!strcmp(status, "28800")) x28800++;
  321.       if(!strcmp(status, "30666")) x30666++;
  322.       if(!strcmp(status, "31200")) x31200++;
  323.       if(!strcmp(status, "32000")) x32000++;
  324.       if(!strcmp(status, "33333")) x33333++;
  325.       if(!strcmp(status, "34666")) x34666++;
  326.       if(!strcmp(status, "31250")) x31250++;
  327.       if(!strcmp(status, "33600")) x33600++;
  328.       if(!strcmp(status, "38400")) x38400++;
  329.       if(!strcmp(status, "45333")) x45333++;
  330.       if(!strcmp(status, "46666")) x46666++;
  331.       if(!strcmp(status, "48000")) x48000++;
  332.       if(!strcmp(status, "49333")) x49333++;
  333.       if(!strcmp(status, "50666")) x50666++;
  334.       if(!strcmp(status, "52000")) x52000++;
  335.       if(!strcmp(status, "53333")) x53333++;
  336.       if(!strcmp(status, "54666")) x54666++;
  337.       if(!strcmp(status, "57600")) x57600++;
  338.       if(!strcmp(status, "64000")) x64000++;
  339.       if(!strcmp(status, "76800")) x76800++;
  340.       if(!strcmp(status, "115200")) x115200++;
  341.       if(!strcmp(status, "230400")) x230400++;
  342.  
  343.       switch (atoi(DiaSemana(Corta(teste, ',', 1), 2)))
  344.       {
  345.         case 1 : dom++; domx = domx + atoi(Corta(teste, ',', 6));
  346.                  domC = domC + atof(Corta(teste, ',', 8)); break;
  347.         case 2 : seg++; segx = segx + atoi(Corta(teste, ',', 6));
  348.                  segC = segC + atof(Corta(teste, ',', 8)); break;
  349.         case 3 : ter++; terx = terx + atoi(Corta(teste, ',', 6));
  350.                  terC = terC + atof(Corta(teste, ',', 8)); break;
  351.         case 4 : qua++; quax = quax + atoi(Corta(teste, ',', 6));
  352.                  quaC = quaC + atof(Corta(teste, ',', 8)); break;
  353.         case 5 : qui++; quix = quix + atoi(Corta(teste, ',', 6));
  354.                  quiC = quiC + atof(Corta(teste, ',', 8)); break;
  355.         case 6 : sex++; sexx = sexx + atoi(Corta(teste, ',', 6));
  356.                  sexC = sexC + atof(Corta(teste, ',', 8)); break;
  357.         case 0 : sab++; sabx = sabx + atoi(Corta(teste, ',', 6));
  358.                  sabC = sabC + atof(Corta(teste, ',', 8)); break;
  359.       }
  360.       teste[0] = '\0';
  361.       x = 0;
  362.     }
  363.   }
  364.   fclose(entrada);
  365.  
  366.   total  = dom + seg + ter + qua + qui + sex + sab;
  367.   totalx = domx + segx + terx + quax + quix + sexx + sabx;
  368.   totalc = domC + segC + terC + quaC + quiC + sexC + sabC;
  369.   
  370.   sprintf(domi, "%d@%f@%d@%f", dom, ((dom / total) * 100), domx, domC);
  371.   sprintf(segu, "%d@%f@%d@%f", seg, ((seg / total) * 100), segx, segC);
  372.   sprintf(terc, "%d@%f@%d@%f", ter, ((ter / total) * 100), terx, terC);
  373.   sprintf(quar, "%d@%f@%d@%f", qua, ((qua / total) * 100), quax, quaC);
  374.   sprintf(quin, "%d@%f@%d@%f", qui, ((qui / total) * 100), quix, quiC);
  375.   sprintf(sext, "%d@%f@%d@%f", sex, ((sex / total) * 100), sexx, sexC);
  376.   sprintf(saba, "%d@%f@%d@%f", sab, ((sab / total) * 100), sabx, sabC);
  377.   sprintf(tota,  "%f", total);
  378.   sprintf(tota, Corta(tota, '.', 0));
  379.   sprintf(tota, "%s@%d@%f", tota, totalx, totalc);
  380.  
  381.   if(!(saida = fopen("t:Freedom.Week", "w")))
  382.     return "";
  383.   fprintf(saida, "**>1:%s\n", domi);
  384.   fprintf(saida, "**>2:%s\n", segu);
  385.   fprintf(saida, "**>3:%s\n", terc);
  386.   fprintf(saida, "**>4:%s\n", quar);
  387.   fprintf(saida, "**>5:%s\n", quin);
  388.   fprintf(saida, "**>6:%s\n", sext);
  389.   fprintf(saida, "**>0:%s\n", saba);
  390.   fprintf(saida, "**>7:%s\n", tota);
  391.   fclose(saida);
  392.  
  393.   /* GRAVA O ARQUIVO COM O RESULTADO DOS RATES */
  394.   if(!(saida = fopen("t:freedom.rates", "w")))
  395.     return "";
  396.   fprintf(saida, "**>300:%d\n", x300);
  397.   fprintf(saida, "**>2400:%d\n", x2400);
  398.   fprintf(saida, "**>9600:%d\n", x9600);
  399.   fprintf(saida, "**>14400:%d\n", x14400);
  400.   fprintf(saida, "**>16800:%d\n", x16800);
  401.   fprintf(saida, "**>19200:%d\n", x19200);
  402.   fprintf(saida, "**>21600:%d\n", x21600);
  403.   fprintf(saida, "**>24000:%d\n", x24000);
  404.   fprintf(saida, "**>26400:%d\n", x26400);
  405.   fprintf(saida, "**>28800:%d\n", x28800);
  406.   fprintf(saida, "**>30666:%d\n", x30666);
  407.   fprintf(saida, "**>31200:%d\n", x31200);
  408.   fprintf(saida, "**>32000:%d\n", x32000);
  409.   fprintf(saida, "**>33333:%d\n", x33333);
  410.   fprintf(saida, "**>34666:%d\n", x34666);
  411.   fprintf(saida, "**>31250:%d\n", x31250);
  412.   fprintf(saida, "**>33600:%d\n", x33600);
  413.   fprintf(saida, "**>38400:%d\n", x38400);
  414.   fprintf(saida, "**>45333:%d\n", x45333);
  415.   fprintf(saida, "**>46666:%d\n", x46666);
  416.   fprintf(saida, "**>48000:%d\n", x48000);
  417.   fprintf(saida, "**>49333:%d\n", x49333);
  418.   fprintf(saida, "**>50666:%d\n", x50666);
  419.   fprintf(saida, "**>52000:%d\n", x52000);
  420.   fprintf(saida, "**>53333:%d\n", x53333);
  421.   fprintf(saida, "**>54666:%d\n", x54666);
  422.   fprintf(saida, "**>57600:%d\n", x57600);
  423.   fprintf(saida, "**>64000:%d\n", x64000);
  424.   fprintf(saida, "**>76800:%d\n", x76800);
  425.   fprintf(saida, "**>115200:%d\n", x115200);
  426.   fprintf(saida, "**>230400:%d\n", x230400);
  427.   fclose(saida);
  428.  
  429.   return "";
  430. }
  431.  
  432. int SelecionaIntervaloCampo(char arquivo1[256], char arquivo2[256], char tmp[256], char data1[256], char data2[256], char hora1[256], char hora2[256])
  433. {
  434.   /*
  435.   Esta funcao seleciona linhas de um arquivo por intervalo de data,
  436.   a linha deve estar em formato de campos, com um separador e a
  437.   data deve ter o seguinte formato [DD.MM.AAAA].
  438.  
  439.   Entrada : Path+Nome Arquivo Entrada  --> dh2:gallas.in (CHAR 256)
  440.             Path+Nome Arquivo Saida    --> dh2:gallas.out (CHAR 256)
  441.             Path+Nome Arquivo Temp     --> ram:gallas.temp (CHAR 256)
  442.             Data Inicial [DD.MM.AAAA]  --> 10.01.1997 (CHAR 256)
  443.             Data Final   [DD.MM.AAAA]  --> 10.02.1997 (CHAR 256)
  444.             Hora Inicial [HH:MM:SS]    --> "01:00:00" (CHAR 256)
  445.             Hora Final   [HH:MM:SS]    --> "02:00:00" (CHAR 256)
  446.   Saida   : 0 se erro -1 se sucesso. (INT)
  447.             Sera gerado arquivo de saida com o conteudo selecionado.
  448.   Obs     : O campo a selecionar inicia em 0.
  449.   SelecionaIntervaloCampo("dh2:gallas.in", "dh2:gallas.out", "ram:gallas.temp", "10.01.1997", "10.02.1997", "01:00:00", "02:00:00");
  450.   */
  451.  
  452.   char a, teste[256], horatmp[256], thora1[256], thora2[256],
  453.        horax1[256], horax2[256], fone[256], telefone[256],
  454.        cost[20], categoria[256], *categorydir, *categoryname;
  455.   int xx, x, tdata, datax1, datax2, diasx, sim = 0;
  456.   FILE *entrada, *saida;
  457.  
  458.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  459.   get(App->TextDefault, MUIA_Text_Contents, &categoryname);
  460.   sprintf(categoria, "%s/%s", categorydir, categoryname);
  461.  
  462.   datax1 = atoi(DiaJuliano(data1));
  463.   datax2 = atoi(DiaJuliano(data2));
  464.   strcpy(horax1, hora1);
  465.   strcpy(horax2, hora2);
  466.   if(strcmp(horax1, "00:00:00") || strcmp(horax2, "00:00:00"))
  467.     sim = 1;
  468.   if(!(entrada = fopen(arquivo1, "r")))
  469.     return 0;
  470.   if(!(saida = fopen(tmp, "w")))
  471.     return 0;
  472.   x = 0; xx = 0; diasx = 0;
  473.   while(a = getc(entrada), ! feof(entrada))
  474.   {
  475.     teste[x++] = a;
  476.     if(a == '\n')
  477.     {
  478.       teste[--x] = '\0';
  479.       strcpy(telefone, Corta(teste, ',', 0));
  480.       if(TestaExisteFone(telefone) == 0)
  481.       {
  482.         tdata = atoi(DiaJuliano(Corta(teste, ',', 1)));
  483.         strcpy(thora1, SegundoHora(Corta(teste, ',', 2)));
  484.         strcpy(thora2, SegundoHora(Corta(teste, ',', 4)));
  485.         if(sim == 1)
  486.         {
  487.           diasx = atoi(Corta(DiferencaDias(Corta(teste, ',', 1), Corta(teste, ',', 3)), ':', 0));
  488.           strcpy(horatmp, HoraSegundo(IntervaloPeriodo(horax1, horax2, thora1, thora2, diasx)));
  489.           if(strcmp(horatmp, Corta(teste, ',', 6)))
  490.             sprintf(fone, "+%s", Corta(teste, ',', 0));
  491.           else
  492.             sprintf(fone, " %s", Corta(teste, ',', 0));
  493.           strcpy(teste, AlteraCampo(teste, fone, ',', 0));
  494.           strcpy(teste, AlteraCampo(teste, horatmp, ',', 6));
  495.         }
  496.         if(tdata >= datax1 && tdata <= datax2)
  497.         {
  498.           /* ROTINA QUE CALCULA O PRECO DA LIGACAO */
  499.           strcpy(cost, CalculaPrecoFREE(categoria, atoi(Corta(teste, ',', 2)), atoi(Corta(teste, ',', 4)), atoi(DiaSemana(Corta(teste, ',', 1), 2))));
  500.           sprintf(teste, "%s,%s", teste, cost);
  501.           fprintf(saida, "%s\n", teste);
  502.         }
  503.       }
  504.       teste[0] = '\0'; x = 0; xx = 0;
  505.     }
  506.   }
  507.   fclose(entrada);
  508.   fclose(saida);
  509.   if(MoveArquivo(tmp, arquivo2) == -1)
  510.     return 0;
  511.   else
  512.     return -1;
  513. }
  514.  
  515. int DiretorioArquivoFREE(char var[256], char arquivo[256], int opcao)
  516. {
  517.   /*
  518.   Este comando lista o conteudo de um determinado diretorio
  519.   e gera um arquivo com o conteudo em si.
  520.  
  521.   Entrada : Path a listar --> dh0:c/ (CHAR 256)
  522.             Arquivo Saida --> ram:saida.tmp (CHAR 256)
  523.             Opcao         --> 1 (INT)
  524.           * Opcao 0, grava sem path absoluta, 1 grava com path.
  525.   Saida   : Sera gerado o arquivo com o conteudo do diretorio,
  526.             retorna um INT, -1 tudo ok, e 0 deu erro. (INT)
  527.   OBS     : Rotina retirada da SURROUND.H e alterada para nao
  528.             listar o Freedom.Out junto.
  529.             DiretorioArquivo("dh0:c/", "ram:saida.tmp", 1);
  530.   */
  531.  
  532.   char teste[256];
  533.   DIR *dfd;
  534.   FILE *saida;
  535.   struct dirent *dptr;
  536.   if(strcmp(Copia2(var, strlen(var), 1), ":") &&
  537.      strcmp(Copia2(var, strlen(var), 1), "/"))
  538.     sprintf(teste, "%s/", var);
  539.   else
  540.     strcpy(teste, var);
  541.   if(!ExisteDiretorio(teste))
  542.     return 0;
  543.   if(!(saida = fopen(arquivo, "w")))
  544.     return 0;
  545.   dfd = opendir(teste);
  546.  
  547.   while ((dptr = readdir(dfd)) != NULL)
  548.   {
  549.     if(!strcmp(LowerCase(Copia(dptr->d_name, 1, 8)), "freedom.") &&
  550.        strlen(dptr->d_name) == 15)
  551.     {
  552.       if(opcao == 0)
  553.         fprintf(saida, "%s\n", dptr->d_name);
  554.       else
  555.         fprintf(saida, "%s%s\n", teste, dptr->d_name);
  556.     }
  557.   }
  558.   closedir(dfd);
  559.   fclose(saida);
  560.   return -1;
  561. }
  562.  
  563. int ConsultaAnualFREE(char arquivo[256], char arquivosaida[256])
  564. {
  565.   /*
  566.   Esta funcao cria uma estatistica anual com as informacoes
  567.   de numero de coneccoes, tempo online, logouts regulares e
  568.   irregulares e media de coneccao.
  569.  
  570.   Entrada : Path+Arquivo Entrada --> gallas.txt (CHAR 256)
  571.             Path+Arquivo Saida   --> saida.txt  (CHAR 256)
  572.   Saida   : Sera gerado um arquivo de saida contendo:
  573.             mes,numero coneccoes,regular,irregular,media
  574.   Obs     : O comando retorna -1 se ok e 0 se der erro. (INT)
  575.             ConsultaAnualFREE("gallas.txt", "saida.txt");
  576.   */
  577.  
  578.   char a, teste[256], mes[10], online[30], status[5], telefone[30];
  579.   /* NUMERO DE LIGACOES */
  580.   int n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0,
  581.       n7 = 0, n8 = 0, n9 = 0, n10 = 0, n11 = 0, n12 = 0,
  582.   /* TEMPO ONLINE */
  583.       o1 = 0, o2 = 0, o3 = 0, o4 = 0, o5 = 0, o6 = 0,
  584.       o7 = 0, o8 = 0, o9 = 0, o10 = 0, o11 = 0, o12 = 0,
  585.   /* REGULAR */
  586.       r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0,
  587.       r7 = 0, r8 = 0, r9 = 0, r10 = 0, r11 = 0, r12 = 0,
  588.   /* IRREGULAR */
  589.       i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = 0, i6 = 0,
  590.       i7 = 0, i8 = 0, i9 = 0, i10 = 0, i11 = 0, i12 = 0;
  591.  
  592.   float c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0,
  593.         c7 = 0, c8 = 0, c9 = 0, c10 = 0, c11 = 0, c12 = 0, cost = 0;
  594.  
  595.   int x = 0, stat = 0;
  596.   FILE *entrada, *saida;
  597.  
  598.   if(!(entrada = fopen(arquivo, "r")))
  599.     return 0;
  600.  
  601.   x = 0;
  602.   while(a = getc(entrada), ! feof(entrada))
  603.   {
  604.     teste[x++] = a;
  605.     /* ROTINA QUE TESTA SE EH O ENTER E EXISTE O TELEFONE NA SENTENCA
  606.        DE EXCLUSAO */
  607.     if(a == '\n')
  608.     {
  609.       teste[--x] = '\0';
  610.       strcpy(telefone, Corta(teste, ',', 0));
  611.       if(TestaExisteFone(telefone) == 0)
  612.       {
  613.         /* MES */
  614.         strcpy(mes, Corta(teste, ',', 1));
  615.         strcpy(mes, Corta(mes, '.', 1));
  616.  
  617.         /* TEMPO ONLINE */
  618.         strcpy(online, Corta(teste, ',', 6));
  619.  
  620.         /* STATUS LIGACAO */
  621.         strcpy(status, Corta(teste, ',', 5));
  622.         if(!strcmp(status, "Act"))
  623.           stat = 0;
  624.         else
  625.           stat = 1;
  626.        
  627.         /* PRECO DA LIGACAO */
  628.         cost = atof(Corta(teste, ',', 8));
  629.  
  630.         switch (atoi(mes))
  631.         {
  632.           case  12: n12++; if(stat == 0) i12++; else r12++; o12 = o12 + atoi(online); c12 = c12 + cost; break;
  633.           case  11: n11++; if(stat == 0) i11++; else r11++; o11 = o11 + atoi(online); c11 = c11 + cost; break;
  634.           case  10: n10++; if(stat == 0) i10++; else r10++; o10 = o10 + atoi(online); c10 = c10 + cost; break;
  635.           case  9: n9++; if(stat == 0) i9++; else r9++; o9 = o9 + atoi(online);  c9 = c9 + cost; break;
  636.           case  8: n8++; if(stat == 0) i8++; else r8++; o8 = o8 + atoi(online); c8 = c8 + cost; break;
  637.           case  7: n7++; if(stat == 0) i7++; else r7++; o7 = o7 + atoi(online); c7 = c7 + cost; break;
  638.           case  6: n6++; if(stat == 0) i6++; else r6++; o6 = o6 + atoi(online); c6 = c6 + cost; break;
  639.           case  5: n5++; if(stat == 0) i5++; else r5++; o5 = o5 + atoi(online); c5 = c5 + cost; break;
  640.           case  4: n4++; if(stat == 0) i4++; else r4++; o4 = o4 + atoi(online); c4 = c4 + cost; break;
  641.           case  3: n3++; if(stat == 0) i3++; else r3++; o3 = o3 + atoi(online); c3 = c3 + cost; break;
  642.           case  2: n2++; if(stat == 0) i2++; else r2++; o2 = o2 + atoi(online); c2 = c2 + cost; break;
  643.           case  1: n1++; if(stat == 0) i1++; else r1++; o1 = o1 + atoi(online); c1 = c1 + cost; break;
  644.         }
  645.       }
  646.       teste[0] = '\0'; x = 0;  
  647.     }
  648.   }
  649.   fclose(entrada);
  650.   if(!(saida = fopen(arquivosaida, "w")))
  651.     return 0;
  652.  
  653.   if(n1 > 0)
  654.     fprintf(saida, "1,%d,%d,%d,%d,%d,%f\n", n1, o1, r1, i1, (o1 / n1), c1);
  655.   if(n2 > 0)
  656.     fprintf(saida, "2,%d,%d,%d,%d,%d,%f\n", n2, o2, r2, i2, (o2 / n2), c2);
  657.   if(n3 > 0)
  658.     fprintf(saida, "3,%d,%d,%d,%d,%d,%f\n", n3, o3, r3, i3, (o3 / n3), c3);
  659.   if(n4 > 0)
  660.     fprintf(saida, "4,%d,%d,%d,%d,%d,%f\n", n4, o4, r4, i4, (o4 / n4), c4);
  661.   if(n5 > 0)
  662.     fprintf(saida, "5,%d,%d,%d,%d,%d,%f\n", n5, o5, r5, i5, (o5 / n5), c5);
  663.   if(n6 > 0)
  664.     fprintf(saida, "6,%d,%d,%d,%d,%d,%f\n", n6, o6, r6, i6, (o6 / n6), c6);
  665.   if(n7 > 0)
  666.     fprintf(saida, "7,%d,%d,%d,%d,%d,%f\n", n7, o7, r7, i7, (o7 / n7), c7);
  667.   if(n8 > 0)
  668.     fprintf(saida, "8,%d,%d,%d,%d,%d,%f\n", n8, o8, r8, i8, (o8 / n8), c8);
  669.   if(n9 > 0)
  670.     fprintf(saida, "9,%d,%d,%d,%d,%d,%f\n", n9, o9, r9, i9, (o9 / n9), c9);
  671.   if(n10 > 0)
  672.     fprintf(saida, "10,%d,%d,%d,%d,%d,%f\n", n10, o10, r10, i10, (o10 / n10), c10);
  673.   if(n11 > 0)
  674.     fprintf(saida, "11,%d,%d,%d,%d,%d,%f\n", n11, o11, r11, i11, (o11 / n11), c11);
  675.   if(n12 > 0)
  676.     fprintf(saida, "12,%d,%d,%d,%d,%d,%f\n", n12, o12, r12, i12, (o12 / n12), c12);
  677.   fclose(saida);
  678.   return -1;
  679. }
  680.  
  681. int FiltraCampoParaArquivoFREE(char var[256], char arq1[256], char arq2[256], char caracter, int numero, char caracter2)
  682. {
  683.   /*
  684.   Este comando filtra um determinado campo de um arquivo, e grava
  685.   outro arquivo com o conteudo igual ao argumento passado.
  686.  
  687.   Entrada : String a comparar     --> 01.02.1997 (CHAR 256)
  688.             Arquivo de Entrada    --> dh1:gallas.txt (CHAR 256)
  689.             Arquivo de Saida      --> dh1:filtro.txt (CHAR 256)
  690.             Delimitador do Arquivo Entrada --> , (CHAR 1)
  691.             Numero do Campo       --> 1 (INT)
  692.             Delimitador da String --> . (CHAR 1)
  693.   Saida   : Eh gerado o arquivo de saida com o conteudo da linha toda
  694.   Erro    : -1 (INT) Caso de problema de abrir arquivo entrada, saida
  695.   Obs     : Este comando foi feito para filtrar datas que seguem o
  696.             formato [XX.XX.XX] [01.02.1997], deve ser passado o deli-
  697.             mitador da data, nesse caso eh ., pode ser comparado ate
  698.             3 campos, ex: [ANO], [MES.ANO], [DIA.MES.ANO]. So 3 campos.
  699.             FiltraCampoParaArquivo("01.02.1997", "dh1:gallas.txt",
  700.                                    "dh1:filtro.txt", ',', 1, '.');
  701.   */
  702.  
  703.   char teste[256], a, mes[20], telefone[256], cost[20], categoria[256],
  704.        *categorydir, *categoryname;
  705.   int x, opcao;
  706.   FILE *entrada, *saida;
  707.  
  708.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  709.   get(App->TextDefault, MUIA_Text_Contents, &categoryname);
  710.   sprintf(categoria, "%s/%s", categorydir, categoryname);
  711.  
  712.   if(!(entrada = fopen(arq1, "r")))
  713.     return -1;
  714.   if(!(saida = fopen(arq2, "w")))
  715.     return -1;
  716.  
  717.   opcao = QtdCaracter(var, caracter2);
  718.   x = 0;
  719.   while(a = getc(entrada), ! feof(entrada))
  720.   {
  721.     teste[x++] = a;
  722.     if(a == '\n')
  723.     {
  724.       teste[--x] = '\0';
  725.       strcpy(telefone, Corta(teste, ',', 0));
  726.       if(TestaExisteFone(telefone) == 0)
  727.       {
  728.         if(opcao == 0)
  729.           strcpy(mes, AposCaracter(AposCaracter(Corta(teste, caracter, numero), caracter2, 1), caracter2, 1));
  730.         if(opcao == 1)
  731.           strcpy(mes, AposCaracter(Corta(teste, caracter, numero), caracter2, 1));
  732.         if(opcao == 2)
  733.           strcpy(mes, Corta(teste, caracter, numero));
  734.         if(!(strcmp(var, mes)))
  735.         {
  736.           /* ROTINA QUE CALCULA O PRECO DA LIGACAO */
  737.           strcpy(cost, CalculaPrecoFREE(categoria, atoi(Corta(teste, ',', 2)), atoi(Corta(teste, ',', 4)), atoi(DiaSemana(Corta(teste, ',', 1), 2))));
  738.           sprintf(teste, "%s,%s", teste, cost);
  739.           fprintf(saida, "%s\n", teste);
  740.         }
  741.       }
  742.       teste[0] = '\0'; x = 0;
  743.     }
  744.   }
  745.   fclose(entrada);
  746.   fclose(saida);
  747.   return 0;
  748. }
  749.  
  750. int VerificaFoneArquivo(char arquivo[256], char temp[256])
  751. {
  752.   /*
  753.   Esta funcao verifica um determinado arquivo filtrando 
  754.   de acordo com a configuracao do Freedom Call os telefones
  755.   que devem ser ignorados na consulta.
  756.  
  757.   Entrada : Path+Nome Arquivo --> freedom.in (CHAR 256)
  758.             Path+Arquivo Temp --> RAM:Freedom.Temp (CHAR 256)
  759.   Saida   : Retorna -1 se ok e 0 se der erro (INT)
  760.             VerificaFoneArquivo("freedom.in", "RAM:freedom.temp");
  761.   */
  762.  
  763.   char teste[256], a, telefone[256];
  764.   int x = 0;
  765.   FILE *entrada, *saida;
  766.  
  767.   if(!(entrada = fopen(arquivo, "r")))
  768.     return 0;
  769.   if(!(saida = fopen(temp, "w")))
  770.     return 0;
  771.   x = 0;
  772.   while(a = getc(entrada), ! feof(entrada))
  773.   {
  774.     teste[x++] = a;
  775.     if(a == '\n')
  776.     {
  777.       teste[--x] = '\0';
  778.       strcpy(telefone, Corta(teste, ',', 0));
  779.       if(TestaExisteFone(telefone) == 0)
  780.         fprintf(saida, "%s\n", teste);
  781.       teste[0] = '\0'; x = 0;
  782.     }
  783.   }
  784.   fclose(entrada);
  785.   fclose(saida);
  786.   MoveArquivo(temp, arquivo);
  787.   return -1;
  788. }
  789.  
  790. int ArrumaArquivoFREE(char arquivo[256], char tmp[256])
  791. {
  792.   /* Essa rotina arruma um determinado arquivo acrescentando
  793.      o campo numero 8 de custo da ligacao, repassa todas as linhas
  794.      e gera esse campo.
  795.  
  796.   Entrada : Arquivo a arrumar --> dh2:gallas.txt (CHAR 256)
  797.             Arquivo tmp       --> ram:tmp.txt    (CHAR 256)
  798.   Saida   : 0 se acontecer algum erro, e -1 se der tudo ok.
  799.             ArrumaArquivoFREE("dh2:gallas.txt", "ram:tmp.txt");
  800.   */
  801.  
  802.   char a, teste[256], cost[256], categoria[256], *categorydir,
  803.        *categoryname;
  804.   int x = 0;
  805.   FILE *entrada, *saida;
  806.  
  807.   if(!(entrada = fopen(arquivo, "r")))
  808.     return 0;
  809.   if(!(saida = fopen(tmp, "w")))
  810.     return 0;
  811.  
  812.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  813.   get(App->TextDefault, MUIA_Text_Contents, &categoryname);
  814.   sprintf(categoria, "%s/%s", categorydir, categoryname);
  815.  
  816.   x = 0;
  817.   while(a = getc(entrada), ! feof(entrada))
  818.   {
  819.     teste[x++] = a;
  820.     if(a == '\n')
  821.     {
  822.       teste[--x] = '\0';
  823.       /* ROTINA QUE CALCULA O PRECO DA LIGACAO */
  824.       strcpy(cost, CalculaPrecoFREE(categoria, atoi(Corta(teste, ',', 2)), atoi(Corta(teste, ',', 4)), atoi(DiaSemana(Corta(teste, ',', 1), 2))));
  825.       sprintf(teste, "%s,%s", teste, cost);
  826.       fprintf(saida, "%s\n", teste);
  827.       teste[0] = '\0'; x = 0;
  828.     }
  829.   }
  830.   fclose(entrada);
  831.   fclose(saida);
  832.   MoveArquivo(tmp, arquivo);
  833.   return -1;
  834. }
  835.  
  836. int InsereArquivoFREE(char var1[256], char var2[256])
  837. {
  838.   /*
  839.   Este comando insere um arquivo em outro. Alterado especialmente para
  840.   o Freedom Call.
  841.  
  842.   Entrada : Path+Nome arquivo origem  --> dh2:gallas.txt (CHAR 256)
  843.             Path+Nome arquivo destino --> dh2:gallas.tmp (CHAR 256)
  844.   Saida   : -1 Erro abertura na origem ou criacao destino, 0 OK (INT)
  845.             InsereArquivo("dh2:gallas.txt", "dh2:gallas.tmp");
  846.   */
  847.  
  848.   char a, teste[256], cost[256], *categorydir, *categoryname,
  849.        categoria[256];
  850.   int x = 0;
  851.   FILE *entrada, *saida;
  852.   if(!(entrada = fopen(var1, "r")))
  853.     return -1;
  854.   if(!(saida = fopen(var2, "a")))
  855.     return -1;
  856.  
  857.   /* LE INFORMACOES DA CONFIGURACAO SOBRE A CATEGORIA */
  858.   get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
  859.   get(App->TextDefault, MUIA_Text_Contents, &categoryname);
  860.   sprintf(categoria, "%s/%s", categorydir, categoryname);
  861.  
  862.   while(a = getc(entrada), ! feof(entrada))
  863.   {
  864.     teste[x++] = a;
  865.     if(a == '\n')
  866.     {
  867.       teste[--x] = '\0';
  868.       /* ROTINA QUE CALCULA O PRECO DA LIGACAO */
  869.       strcpy(cost, CalculaPrecoFREE(categoria, atoi(Corta(teste, ',', 2)), atoi(Corta(teste, ',', 4)), atoi(DiaSemana(Corta(teste, ',', 1), 2))));
  870.       sprintf(teste, "%s,%s", teste, cost);
  871.       fprintf(saida, "%s\n", teste);
  872.       teste[0] = '\0'; x = 0;
  873.     }
  874.   }
  875.   fclose(entrada);
  876.   fclose(saida);
  877.   return 0;
  878. }
  879.  
  880. int UnirArquivosFREE(char saida[256], char lista[256]) 
  881. {
  882.   /*
  883.   Este comando uni arquivos apartir de uma lista. Alterada especialmente
  884.   para o Freedom Call.
  885.  
  886.   Entrada : Path+Nome Arquivo Saida --> gallas.txt (CHAR 256)
  887.             Path+Nome Arquivo Lista --> lista.txt (CHAR 256)
  888.   Saida   : Sera gerado o arquivo de saida contendo todos os
  889.             arquivos incluidos na lista. O comando retorna
  890.             0 se ocorrer erro e -1 se sucesso. (INT)
  891.   Obs     : A lista eh um arquivo texto, ex:
  892.             Arquivo1.txt
  893.             Arquivo2.txt
  894.             Arquivo3.txt
  895.             UnirArquivos("gallas.txt", "lista.txt");
  896.   */
  897.  
  898.   char a, teste[256];
  899.   int x = 0;
  900.   FILE *entrada;
  901.   if(!(entrada = fopen(lista, "r")))
  902.     return 0;
  903.   x = 0;
  904.   while(a = getc(entrada), ! feof(entrada))
  905.   {
  906.     teste[x++] = a;
  907.     if(a == '\n')
  908.     {
  909.       teste[--x] = '\0';
  910.       InsereArquivoFREE(teste, saida);   
  911.       teste[0] = '\0'; x = 0;
  912.     }
  913.   } 
  914.   fclose(entrada);
  915.   return -1;
  916. }
  917.  
  918. char *DescricaoMesFREE(int mes, int opcao)
  919. {
  920.   /*
  921.   Este comando fornece o mes em formato extenso, se passa o
  922.   numero do mes e a opcao e sera retornado o nome do mes.
  923.   Rotina modificada especificamente para o Freedom Call, funcao
  924.   original tirado do SuRRouND.h.
  925.  
  926.   Entrada : Numero do mes  --> 2 (INT)
  927.             Opcao a listar --> 0 (INT)
  928.   Obs     : Opcao 0 retorna em Portugues e 1 em Ingles.
  929.   Saida   : Fevereiro (CHAR RETURN)
  930.   Erro    : ERRO (CHAR RETURN) Mes invalido! < 0 e > 12
  931.   Obs     : Caso seja necessario abrevidado use:
  932.             Esquerda(DescricaoMes(2, 0), 3);
  933.   */
  934.  
  935.   switch (mes)
  936.   {
  937.     case  1: return TMsg(App->MsgJaneiro);
  938.     case  2: return TMsg(App->MsgFevereiro);
  939.     case  3: return TMsg(App->MsgMarco);
  940.     case  4: return TMsg(App->MsgAbril);
  941.     case  5: return TMsg(App->MsgMaio);
  942.     case  6: return TMsg(App->MsgJunho);
  943.     case  7: return TMsg(App->MsgJulho);
  944.     case  8: return TMsg(App->MsgAgosto);
  945.     case  9: return TMsg(App->MsgSetembro);
  946.     case 10: return TMsg(App->MsgOutubro);
  947.     case 11: return TMsg(App->MsgNovembro);
  948.     case 12: return TMsg(App->MsgDezembro);
  949.   }
  950.   return "ERRO";
  951. }
  952.  
  953. char *DiaSemanaFREE(char var[20], int opcao) 
  954. {
  955.   /*
  956.   Este comando recebe uma data e retorna o dia da semana.
  957.   Rotina modificada especificamente para o Freedom Call, funcao
  958.   original tirado do SuRRouND.h.
  959.  
  960.   Entrada : Data  --> 01.02.1997 (CHAR 20)
  961.             Opcao --> 0 (INT)
  962.   Obs     : 0 retorna em portugues
  963.             1 ingles
  964.             2 o numero do dia, inicio em 1 -> domingo.
  965.   Saida   : Dia da Semana -> Segunda (CHAR RETURN)
  966.             DiaSemana("01.02.1997", 0);
  967.   */
  968.  
  969.   char teste[256];
  970.   int x = 0;
  971.   x = fmod(atof(Arredondar(DiaJuliano(var))), 7.0);
  972.   if(opcao == 2)
  973.   {
  974.     sprintf(teste, "%d", x);
  975.     return teste;
  976.   }
  977.   switch(x)
  978.   {
  979.     case 1: return TMsg(App->MsgDomingo);
  980.     case 2: return TMsg(App->MsgSegunda);
  981.     case 3: return TMsg(App->MsgTerca);
  982.     case 4: return TMsg(App->MsgQuarta);
  983.     case 5: return TMsg(App->MsgQuinta);
  984.     case 6: return TMsg(App->MsgSexta);
  985.     case 0: return TMsg(App->MsgSabado);
  986.   }
  987.   return "ERRO";
  988. }
  989.