home *** CD-ROM | disk | FTP | other *** search
- #include "freegui.h"
- #include "freemain.h"
- #include "freeextern.h"
-
- #include <proto/muimaster.h>
- #include <clib/alib_protos.h>
- #include <libraries/mui.h>
- #include <libraries/asl.h>
-
- char pilha[50][50];
- int pilhafim = 0;
-
- char *TMsg(struct Hook *objeto)
- {
- /* LE O CONTEUDO DE UM OBJETO, O TEXT */
- char *teste;
- get(objeto, MUIA_Text_Contents, &teste);
- return teste;
- }
-
- char *CalculaPrecoFREE(char arquivo[256], int hora1, int hora2, int semana)
- {
- /* Este comando calcula o preco de uma determinada ligacao.
-
- Entrada : Arquivo da Categoria --> Categories/Brazil.CRT (CHAR 256)
- Hora Inicio (Segundos) --> 233445 (INT)
- Hora Final (Segundos) --> 255455 (INT)
- Semana --> 0 (INT)
- Obs : A semana eh recebida de acordo com os valores da funcao
- DiaSemana("01.02.1997", 2);
- Saida : O custo da ligacao --> 0.234 (CHAR 256)
- CalculaPrecoFREE("Categories/Brazil.CRT", 233445, 255455, 0);
- */
-
- char teste[256], *valordefault;
- int x = 0, fim = 0, h1 = 0, h2 = 0,
- h3 = 0;
- float valor = 0, hvalor = 0, hvalorpadrao = 0, diferenca = 0, hhh = 0;
-
- get(App->CategValorDefault, MUIA_String_Contents, &valordefault);
- hvalorpadrao = atof(valordefault);
-
- /* FILTRA OS HORARIOS CASO TROQUE O DIA */
- if(hora2 < hora1)
- {
- diferenca = hora2;
- hora2 = 86399;
- }
-
- /* CASE PARA ACERTAR O DIA DA SEMANA DE ACORDO COM O COMBO */
- switch (semana)
- {
- case 0: semana = 6; break;
- case 1: semana = 7; break;
- case 2: semana = 1; break;
- case 3: semana = 2; break;
- case 4: semana = 3; break;
- case 5: semana = 4; break;
- case 6: semana = 5; break;
- }
-
- /* PILHA ONDE SERAO ARMAZENADOS LIMITES (pilha) MAXIMO 50 LIMITES
- A VARIAVEL QUE GUARDA O NUMERO DE LIMITES NA PILHA EH (xpilha) */
-
- LOOP:
- for(x = 0; x < pilhafim; x++)
- {
- strcpy(teste, pilha[x]);
-
- h1 = atoi(Corta(teste, ' ', 0));
- h2 = atoi(Corta(teste, ' ', 1));
- h3 = atoi(Corta(teste, ' ', 3));
- hvalor = atof(Corta(teste, ' ', 2));
-
- if(h3 == 0 || h3 == semana)
- {
- /* 5, 10 SELECIONADO (6, 9) ou (5, 10) ou (5, 9) ou (6, 10) */
- if((hora1 >= h1 && hora1 < h2) &&
- (hora2 <= h2 && hora2 > h1)) {
- hhh = hora2 - hora1;
- valor = valor + ((hhh / 60) * hvalor); fim = 1; break; }
-
- /* 5, 10 SELECIONADO (4, 9) ou (4, 10) */
- if((hora1 < h1 && hora1 < h2) &&
- (hora2 <= h2 && hora2 > h1)) {
- hhh = hora2 - h1;
- valor = valor + ((hhh / 60) * hvalor);
- hora2 = h1; x = -1; }
-
- /* 5, 10 SELECIONADO (5, 11) ou (6, 11) */
- /* 5, 10 SELECIONADO (4, 11) */
- if(((hora1 >= h1 && hora1 < h2) &&
- (hora2 > h2 && hora2 > h1)) ||
- ((hora1 < h1 && hora1 < h2) &&
- (hora2 > h2 && hora2 > h1))) {
- hhh = h2 - hora1;
- valor = valor + ((hhh / 60) * hvalor);
- hora1 = h2; x = -1; }
- }
- }
- if(diferenca > 0)
- {
- hora1 = 0;
- hora2 = diferenca;
- diferenca = 0;
- goto LOOP;
- }
- if(fim == 0)
- {
- hhh = hora2 - hora1;
- valor = valor + ((hhh / 60) * hvalorpadrao);
- }
- sprintf(teste, "%f", valor);
- return teste;
- }
-
- int TestaExisteFone(char fone[256])
- {
- /*
- Esta funcao testa se existe o telefone para ignorar nas
- estatisticas.
-
- Entrada : Fone --> 0800128001 (CHAR 256)
- Saida : -1 se existe e 0 se nao existe (INT)
- TestaExisteFone("0800128001");
- */
-
- char teste[256], *linhafone;
- int x = 0, y = 0;
- long check = 0;
-
- /* TESTA SE A OPCAO ESTA HABILITADA OU NAO */
- get(App->GrupoFoneInputCheck, MUIA_Selected, &check);
- if(check == 0)
- return 0;
-
- get(App->GrupoFoneInput, MUIA_String_Contents, &linhafone);
- for(x = 0; x <= strlen(linhafone); x++)
- {
- teste[y++] = linhafone[x];
- if(linhafone[x] == ',' || linhafone[x] == '\0' && strcmp(teste, ""))
- {
- teste[--y] = '\0';
- if(!strcmp(teste, fone))
- return -1;
- teste[0] = '\0'; y = 0;
- }
- }
- return 0;
- }
-
- char *TotalHoras(char var[256])
- {
- /*
- Comando para retirar do arquivo 'FREEDOM.IN' o total
- de horas gastas por um determinado mes.
-
- Entrada : Mes.Ano --> 03.1997
- Saida : Segundos --> 764534 "Passar rotina SEGUNDOHORA()
- */
-
- char teste[256], a;
- char dat[10], seg[30], linha[256];
- int x, total;
- FILE *entrada;
-
- if(!(entrada = fopen("freedom.in", "r")))
- {
- return "ERRO";
- }
- else
- {
- x = 0; total = 0;
- while(a = getc(entrada), ! feof(entrada))
- {
- teste[x++] = a;
- if(a == '\n')
- {
- teste[--x] = '\0';
- strcpy(linha, teste);
- strcpy(dat, Corta(teste, ',', 1));
- sprintf(dat, "%s.%s", Corta(dat, '.', 1), Corta(dat, '.', 2));
- if(!(strcmp(dat, var)))
- {
- strcpy(seg, Corta(linha, ',', 6));
- total = total + atoi(seg);
- }
- teste[0] = '\0';
- x = 0;
- }
- }
- fclose(entrada);
- sprintf(teste, "%d", total);
- return teste;
- }
- }
-
- char *DadosMiami(char var[256])
- {
- /*
- Comando que retira do arquivo 'FREEDOM.IN' as quantidades
- de ligacoes, numero de quedas de linha, e logouts com sucesso.
-
- Entrada: Mes.Ano --> 03.1997
- Saida : Total Ligacoes do arquivo
- Numero de logouts com Sucesso
- Numero de queda de linhas
- 50:22:28
- */
-
- char a, teste[256], status[5], data[20], linha[256];
- int caiu, totalarquivo, offnormal, x;
- FILE *entrada;
-
- if(!(entrada = fopen("freedom.in", "r")))
- return "ERRO";
- else
- {
- x = 0; caiu = 0; totalarquivo = 0; offnormal = 0;
- while(a = getc(entrada), ! feof(entrada))
- {
- teste[x++] = a;
- if(a == '\n')
- {
- teste[--x] = '\0';
- strcpy(linha, teste);
- strcpy(status, Corta(linha, ',', 5));
- strcpy(data, Corta(linha, ',', 1));
- sprintf(data, "%s.%s", Corta(data, '.', 1), Corta(data, '.', 2));
- if(!(strcmp(data, var)))
- {
- if(!(strcmp(status, "Pas")))
- offnormal++;
- else
- caiu++;
- totalarquivo++;
- }
- if(var[0] == 0)
- {
- if(!(strcmp(status, "Pas")))
- offnormal++;
- else
- caiu++;
- totalarquivo++;
- }
- x = 0;
- }
- }
- fclose(entrada);
- sprintf(teste, "%d:%d:%d", totalarquivo, offnormal, caiu);
- return teste;
- }
- }
-
- char *SemanaCount(char var[256])
- {
- /*
- Esta funcao gera as estatisticas semanais em uma arquivo
- chamado Ram:Freedom.Week.
- Obs: Rotina re-aproveitada para criar o arquivo com as
- estatisticas de velocidade.
-
- Entrada : Path+Nome Arquivo --> Freedom.in (CHAR 256)
- Saida : Arquivo --> Ram:Freedom.Week
- Erro : ERRO (CHAR RETURN)
- Obs : Sera gerado 7 campos.
- 1 - Domingo
- 2 - Segunda
- 3 - Terca
- 4 - Quarta
- 5 - Quinta
- 6 - Sexta
- 0 - Sabado
- 7 - Total de ligacoes
- SemanaCount("Freedom.In");
- */
-
- char a, teste[256], status[256],
- domi[100], segu[100], terc[100], quar[100],
- quin[100], sext[100], saba[100], tota[100];
-
- int dom = 0, seg = 0, ter = 0, qua = 0,
- qui = 0, sex = 0, sab = 0, x = 0,
- domx = 0, segx = 0, terx = 0, quax = 0,
- quix = 0, sexx = 0, sabx = 0, totalx,
-
- x300 = 0, x2400 = 0, x9600 = 0, x14400 = 0, x16800 = 0,
- x19200 = 0, x21600 = 0, x24000 = 0, x26400 = 0, x28800 = 0,
- x30666 = 0, x31200 = 0, x32000 = 0, x33333 = 0, x34666 = 0,
- x33600 = 0, x31250 = 0, x38400 = 0, x45333 = 0, x50666 = 0,
- x52000 = 0, x53333 = 0, x54666 = 0, x57600 = 0, x64000 = 0,
- x46666 = 0, x48000 = 0, x49333 = 0,
- x76800 = 0, x115200 = 0, x230400 = 0;
-
- float segC = 0, terC = 0, quaC= 0, quiC= 0, sexC= 0,
- sabC = 0, domC = 0, total = 0, totalc = 0;
-
- FILE *entrada, *saida;
- if(!(entrada = fopen(var, "r")))
- return "ERRO";
- while(a = getc(entrada), ! feof(entrada))
- {
- teste[x++] = a;
- if(a == '\n')
- {
- teste[--x] = '\0';
- strcpy(status, RetiraPontas(Corta(teste, ',', 7), 1));
- strcpy(status, Corta(status, '/', 0));
-
- /* VERIFICA RATES */
- if(!strcmp(status, "300")) x300++;
- if(!strcmp(status, "2400")) x2400++;
- if(!strcmp(status, "9600")) x9600++;
- if(!strcmp(status, "14400")) x14400++;
- if(!strcmp(status, "16800")) x16800++;
- if(!strcmp(status, "19200")) x19200++;
- if(!strcmp(status, "21600")) x21600++;
- if(!strcmp(status, "24000")) x24000++;
- if(!strcmp(status, "26400")) x26400++;
- if(!strcmp(status, "28800")) x28800++;
- if(!strcmp(status, "30666")) x30666++;
- if(!strcmp(status, "31200")) x31200++;
- if(!strcmp(status, "32000")) x32000++;
- if(!strcmp(status, "33333")) x33333++;
- if(!strcmp(status, "34666")) x34666++;
- if(!strcmp(status, "31250")) x31250++;
- if(!strcmp(status, "33600")) x33600++;
- if(!strcmp(status, "38400")) x38400++;
- if(!strcmp(status, "45333")) x45333++;
- if(!strcmp(status, "46666")) x46666++;
- if(!strcmp(status, "48000")) x48000++;
- if(!strcmp(status, "49333")) x49333++;
- if(!strcmp(status, "50666")) x50666++;
- if(!strcmp(status, "52000")) x52000++;
- if(!strcmp(status, "53333")) x53333++;
- if(!strcmp(status, "54666")) x54666++;
- if(!strcmp(status, "57600")) x57600++;
- if(!strcmp(status, "64000")) x64000++;
- if(!strcmp(status, "76800")) x76800++;
- if(!strcmp(status, "115200")) x115200++;
- if(!strcmp(status, "230400")) x230400++;
-
- switch (atoi(DiaSemana(Corta(teste, ',', 1), 2)))
- {
- case 1 : dom++; domx = domx + atoi(Corta(teste, ',', 6));
- domC = domC + atof(Corta(teste, ',', 8)); break;
- case 2 : seg++; segx = segx + atoi(Corta(teste, ',', 6));
- segC = segC + atof(Corta(teste, ',', 8)); break;
- case 3 : ter++; terx = terx + atoi(Corta(teste, ',', 6));
- terC = terC + atof(Corta(teste, ',', 8)); break;
- case 4 : qua++; quax = quax + atoi(Corta(teste, ',', 6));
- quaC = quaC + atof(Corta(teste, ',', 8)); break;
- case 5 : qui++; quix = quix + atoi(Corta(teste, ',', 6));
- quiC = quiC + atof(Corta(teste, ',', 8)); break;
- case 6 : sex++; sexx = sexx + atoi(Corta(teste, ',', 6));
- sexC = sexC + atof(Corta(teste, ',', 8)); break;
- case 0 : sab++; sabx = sabx + atoi(Corta(teste, ',', 6));
- sabC = sabC + atof(Corta(teste, ',', 8)); break;
- }
- teste[0] = '\0';
- x = 0;
- }
- }
- fclose(entrada);
-
- total = dom + seg + ter + qua + qui + sex + sab;
- totalx = domx + segx + terx + quax + quix + sexx + sabx;
- totalc = domC + segC + terC + quaC + quiC + sexC + sabC;
-
- sprintf(domi, "%d@%f@%d@%f", dom, ((dom / total) * 100), domx, domC);
- sprintf(segu, "%d@%f@%d@%f", seg, ((seg / total) * 100), segx, segC);
- sprintf(terc, "%d@%f@%d@%f", ter, ((ter / total) * 100), terx, terC);
- sprintf(quar, "%d@%f@%d@%f", qua, ((qua / total) * 100), quax, quaC);
- sprintf(quin, "%d@%f@%d@%f", qui, ((qui / total) * 100), quix, quiC);
- sprintf(sext, "%d@%f@%d@%f", sex, ((sex / total) * 100), sexx, sexC);
- sprintf(saba, "%d@%f@%d@%f", sab, ((sab / total) * 100), sabx, sabC);
- sprintf(tota, "%f", total);
- sprintf(tota, Corta(tota, '.', 0));
- sprintf(tota, "%s@%d@%f", tota, totalx, totalc);
-
- if(!(saida = fopen("t:Freedom.Week", "w")))
- return "";
- fprintf(saida, "**>1:%s\n", domi);
- fprintf(saida, "**>2:%s\n", segu);
- fprintf(saida, "**>3:%s\n", terc);
- fprintf(saida, "**>4:%s\n", quar);
- fprintf(saida, "**>5:%s\n", quin);
- fprintf(saida, "**>6:%s\n", sext);
- fprintf(saida, "**>0:%s\n", saba);
- fprintf(saida, "**>7:%s\n", tota);
- fclose(saida);
-
- /* GRAVA O ARQUIVO COM O RESULTADO DOS RATES */
- if(!(saida = fopen("t:freedom.rates", "w")))
- return "";
- fprintf(saida, "**>300:%d\n", x300);
- fprintf(saida, "**>2400:%d\n", x2400);
- fprintf(saida, "**>9600:%d\n", x9600);
- fprintf(saida, "**>14400:%d\n", x14400);
- fprintf(saida, "**>16800:%d\n", x16800);
- fprintf(saida, "**>19200:%d\n", x19200);
- fprintf(saida, "**>21600:%d\n", x21600);
- fprintf(saida, "**>24000:%d\n", x24000);
- fprintf(saida, "**>26400:%d\n", x26400);
- fprintf(saida, "**>28800:%d\n", x28800);
- fprintf(saida, "**>30666:%d\n", x30666);
- fprintf(saida, "**>31200:%d\n", x31200);
- fprintf(saida, "**>32000:%d\n", x32000);
- fprintf(saida, "**>33333:%d\n", x33333);
- fprintf(saida, "**>34666:%d\n", x34666);
- fprintf(saida, "**>31250:%d\n", x31250);
- fprintf(saida, "**>33600:%d\n", x33600);
- fprintf(saida, "**>38400:%d\n", x38400);
- fprintf(saida, "**>45333:%d\n", x45333);
- fprintf(saida, "**>46666:%d\n", x46666);
- fprintf(saida, "**>48000:%d\n", x48000);
- fprintf(saida, "**>49333:%d\n", x49333);
- fprintf(saida, "**>50666:%d\n", x50666);
- fprintf(saida, "**>52000:%d\n", x52000);
- fprintf(saida, "**>53333:%d\n", x53333);
- fprintf(saida, "**>54666:%d\n", x54666);
- fprintf(saida, "**>57600:%d\n", x57600);
- fprintf(saida, "**>64000:%d\n", x64000);
- fprintf(saida, "**>76800:%d\n", x76800);
- fprintf(saida, "**>115200:%d\n", x115200);
- fprintf(saida, "**>230400:%d\n", x230400);
- fclose(saida);
-
- return "";
- }
-
- int SelecionaIntervaloCampo(char arquivo1[256], char arquivo2[256], char tmp[256], char data1[256], char data2[256], char hora1[256], char hora2[256])
- {
- /*
- Esta funcao seleciona linhas de um arquivo por intervalo de data,
- a linha deve estar em formato de campos, com um separador e a
- data deve ter o seguinte formato [DD.MM.AAAA].
-
- Entrada : Path+Nome Arquivo Entrada --> dh2:gallas.in (CHAR 256)
- Path+Nome Arquivo Saida --> dh2:gallas.out (CHAR 256)
- Path+Nome Arquivo Temp --> ram:gallas.temp (CHAR 256)
- Data Inicial [DD.MM.AAAA] --> 10.01.1997 (CHAR 256)
- Data Final [DD.MM.AAAA] --> 10.02.1997 (CHAR 256)
- Hora Inicial [HH:MM:SS] --> "01:00:00" (CHAR 256)
- Hora Final [HH:MM:SS] --> "02:00:00" (CHAR 256)
- Saida : 0 se erro -1 se sucesso. (INT)
- Sera gerado arquivo de saida com o conteudo selecionado.
- Obs : O campo a selecionar inicia em 0.
- SelecionaIntervaloCampo("dh2:gallas.in", "dh2:gallas.out", "ram:gallas.temp", "10.01.1997", "10.02.1997", "01:00:00", "02:00:00");
- */
-
- char a, teste[256], horatmp[256], thora1[256], thora2[256],
- horax1[256], horax2[256], fone[256], telefone[256],
- cost[20], categoria[256], *categorydir, *categoryname;
- int xx, x, tdata, datax1, datax2, diasx, sim = 0;
- FILE *entrada, *saida;
-
- get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
- get(App->TextDefault, MUIA_Text_Contents, &categoryname);
- sprintf(categoria, "%s/%s", categorydir, categoryname);
-
- datax1 = atoi(DiaJuliano(data1));
- datax2 = atoi(DiaJuliano(data2));
- strcpy(horax1, hora1);
- strcpy(horax2, hora2);
- if(strcmp(horax1, "00:00:00") || strcmp(horax2, "00:00:00"))
- sim = 1;
- if(!(entrada = fopen(arquivo1, "r")))
- return 0;
- if(!(saida = fopen(tmp, "w")))
- return 0;
- x = 0; xx = 0; diasx = 0;
- while(a = getc(entrada), ! feof(entrada))
- {
- teste[x++] = a;
- if(a == '\n')
- {
- teste[--x] = '\0';
- strcpy(telefone, Corta(teste, ',', 0));
- if(TestaExisteFone(telefone) == 0)
- {
- tdata = atoi(DiaJuliano(Corta(teste, ',', 1)));
- strcpy(thora1, SegundoHora(Corta(teste, ',', 2)));
- strcpy(thora2, SegundoHora(Corta(teste, ',', 4)));
- if(sim == 1)
- {
- diasx = atoi(Corta(DiferencaDias(Corta(teste, ',', 1), Corta(teste, ',', 3)), ':', 0));
- strcpy(horatmp, HoraSegundo(IntervaloPeriodo(horax1, horax2, thora1, thora2, diasx)));
- if(strcmp(horatmp, Corta(teste, ',', 6)))
- sprintf(fone, "+%s", Corta(teste, ',', 0));
- else
- sprintf(fone, " %s", Corta(teste, ',', 0));
- strcpy(teste, AlteraCampo(teste, fone, ',', 0));
- strcpy(teste, AlteraCampo(teste, horatmp, ',', 6));
- }
- if(tdata >= datax1 && tdata <= datax2)
- {
- /* ROTINA QUE CALCULA O PRECO DA LIGACAO */
- strcpy(cost, CalculaPrecoFREE(categoria, atoi(Corta(teste, ',', 2)), atoi(Corta(teste, ',', 4)), atoi(DiaSemana(Corta(teste, ',', 1), 2))));
- sprintf(teste, "%s,%s", teste, cost);
- fprintf(saida, "%s\n", teste);
- }
- }
- teste[0] = '\0'; x = 0; xx = 0;
- }
- }
- fclose(entrada);
- fclose(saida);
- if(MoveArquivo(tmp, arquivo2) == -1)
- return 0;
- else
- return -1;
- }
-
- int DiretorioArquivoFREE(char var[256], char arquivo[256], int opcao)
- {
- /*
- Este comando lista o conteudo de um determinado diretorio
- e gera um arquivo com o conteudo em si.
-
- Entrada : Path a listar --> dh0:c/ (CHAR 256)
- Arquivo Saida --> ram:saida.tmp (CHAR 256)
- Opcao --> 1 (INT)
- * Opcao 0, grava sem path absoluta, 1 grava com path.
- Saida : Sera gerado o arquivo com o conteudo do diretorio,
- retorna um INT, -1 tudo ok, e 0 deu erro. (INT)
- OBS : Rotina retirada da SURROUND.H e alterada para nao
- listar o Freedom.Out junto.
- DiretorioArquivo("dh0:c/", "ram:saida.tmp", 1);
- */
-
- char teste[256];
- DIR *dfd;
- FILE *saida;
- struct dirent *dptr;
- if(strcmp(Copia2(var, strlen(var), 1), ":") &&
- strcmp(Copia2(var, strlen(var), 1), "/"))
- sprintf(teste, "%s/", var);
- else
- strcpy(teste, var);
- if(!ExisteDiretorio(teste))
- return 0;
- if(!(saida = fopen(arquivo, "w")))
- return 0;
- dfd = opendir(teste);
-
- while ((dptr = readdir(dfd)) != NULL)
- {
- if(!strcmp(LowerCase(Copia(dptr->d_name, 1, 8)), "freedom.") &&
- strlen(dptr->d_name) == 15)
- {
- if(opcao == 0)
- fprintf(saida, "%s\n", dptr->d_name);
- else
- fprintf(saida, "%s%s\n", teste, dptr->d_name);
- }
- }
- closedir(dfd);
- fclose(saida);
- return -1;
- }
-
- int ConsultaAnualFREE(char arquivo[256], char arquivosaida[256])
- {
- /*
- Esta funcao cria uma estatistica anual com as informacoes
- de numero de coneccoes, tempo online, logouts regulares e
- irregulares e media de coneccao.
-
- Entrada : Path+Arquivo Entrada --> gallas.txt (CHAR 256)
- Path+Arquivo Saida --> saida.txt (CHAR 256)
- Saida : Sera gerado um arquivo de saida contendo:
- mes,numero coneccoes,regular,irregular,media
- Obs : O comando retorna -1 se ok e 0 se der erro. (INT)
- ConsultaAnualFREE("gallas.txt", "saida.txt");
- */
-
- char a, teste[256], mes[10], online[30], status[5], telefone[30];
- /* NUMERO DE LIGACOES */
- int n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0,
- n7 = 0, n8 = 0, n9 = 0, n10 = 0, n11 = 0, n12 = 0,
- /* TEMPO ONLINE */
- o1 = 0, o2 = 0, o3 = 0, o4 = 0, o5 = 0, o6 = 0,
- o7 = 0, o8 = 0, o9 = 0, o10 = 0, o11 = 0, o12 = 0,
- /* REGULAR */
- r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0,
- r7 = 0, r8 = 0, r9 = 0, r10 = 0, r11 = 0, r12 = 0,
- /* IRREGULAR */
- i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = 0, i6 = 0,
- i7 = 0, i8 = 0, i9 = 0, i10 = 0, i11 = 0, i12 = 0;
-
- float c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0,
- c7 = 0, c8 = 0, c9 = 0, c10 = 0, c11 = 0, c12 = 0, cost = 0;
-
- int x = 0, stat = 0;
- FILE *entrada, *saida;
-
- if(!(entrada = fopen(arquivo, "r")))
- return 0;
-
- x = 0;
- while(a = getc(entrada), ! feof(entrada))
- {
- teste[x++] = a;
- /* ROTINA QUE TESTA SE EH O ENTER E EXISTE O TELEFONE NA SENTENCA
- DE EXCLUSAO */
- if(a == '\n')
- {
- teste[--x] = '\0';
- strcpy(telefone, Corta(teste, ',', 0));
- if(TestaExisteFone(telefone) == 0)
- {
- /* MES */
- strcpy(mes, Corta(teste, ',', 1));
- strcpy(mes, Corta(mes, '.', 1));
-
- /* TEMPO ONLINE */
- strcpy(online, Corta(teste, ',', 6));
-
- /* STATUS LIGACAO */
- strcpy(status, Corta(teste, ',', 5));
- if(!strcmp(status, "Act"))
- stat = 0;
- else
- stat = 1;
-
- /* PRECO DA LIGACAO */
- cost = atof(Corta(teste, ',', 8));
-
- switch (atoi(mes))
- {
- case 12: n12++; if(stat == 0) i12++; else r12++; o12 = o12 + atoi(online); c12 = c12 + cost; break;
- case 11: n11++; if(stat == 0) i11++; else r11++; o11 = o11 + atoi(online); c11 = c11 + cost; break;
- case 10: n10++; if(stat == 0) i10++; else r10++; o10 = o10 + atoi(online); c10 = c10 + cost; break;
- case 9: n9++; if(stat == 0) i9++; else r9++; o9 = o9 + atoi(online); c9 = c9 + cost; break;
- case 8: n8++; if(stat == 0) i8++; else r8++; o8 = o8 + atoi(online); c8 = c8 + cost; break;
- case 7: n7++; if(stat == 0) i7++; else r7++; o7 = o7 + atoi(online); c7 = c7 + cost; break;
- case 6: n6++; if(stat == 0) i6++; else r6++; o6 = o6 + atoi(online); c6 = c6 + cost; break;
- case 5: n5++; if(stat == 0) i5++; else r5++; o5 = o5 + atoi(online); c5 = c5 + cost; break;
- case 4: n4++; if(stat == 0) i4++; else r4++; o4 = o4 + atoi(online); c4 = c4 + cost; break;
- case 3: n3++; if(stat == 0) i3++; else r3++; o3 = o3 + atoi(online); c3 = c3 + cost; break;
- case 2: n2++; if(stat == 0) i2++; else r2++; o2 = o2 + atoi(online); c2 = c2 + cost; break;
- case 1: n1++; if(stat == 0) i1++; else r1++; o1 = o1 + atoi(online); c1 = c1 + cost; break;
- }
- }
- teste[0] = '\0'; x = 0;
- }
- }
- fclose(entrada);
- if(!(saida = fopen(arquivosaida, "w")))
- return 0;
-
- if(n1 > 0)
- fprintf(saida, "1,%d,%d,%d,%d,%d,%f\n", n1, o1, r1, i1, (o1 / n1), c1);
- if(n2 > 0)
- fprintf(saida, "2,%d,%d,%d,%d,%d,%f\n", n2, o2, r2, i2, (o2 / n2), c2);
- if(n3 > 0)
- fprintf(saida, "3,%d,%d,%d,%d,%d,%f\n", n3, o3, r3, i3, (o3 / n3), c3);
- if(n4 > 0)
- fprintf(saida, "4,%d,%d,%d,%d,%d,%f\n", n4, o4, r4, i4, (o4 / n4), c4);
- if(n5 > 0)
- fprintf(saida, "5,%d,%d,%d,%d,%d,%f\n", n5, o5, r5, i5, (o5 / n5), c5);
- if(n6 > 0)
- fprintf(saida, "6,%d,%d,%d,%d,%d,%f\n", n6, o6, r6, i6, (o6 / n6), c6);
- if(n7 > 0)
- fprintf(saida, "7,%d,%d,%d,%d,%d,%f\n", n7, o7, r7, i7, (o7 / n7), c7);
- if(n8 > 0)
- fprintf(saida, "8,%d,%d,%d,%d,%d,%f\n", n8, o8, r8, i8, (o8 / n8), c8);
- if(n9 > 0)
- fprintf(saida, "9,%d,%d,%d,%d,%d,%f\n", n9, o9, r9, i9, (o9 / n9), c9);
- if(n10 > 0)
- fprintf(saida, "10,%d,%d,%d,%d,%d,%f\n", n10, o10, r10, i10, (o10 / n10), c10);
- if(n11 > 0)
- fprintf(saida, "11,%d,%d,%d,%d,%d,%f\n", n11, o11, r11, i11, (o11 / n11), c11);
- if(n12 > 0)
- fprintf(saida, "12,%d,%d,%d,%d,%d,%f\n", n12, o12, r12, i12, (o12 / n12), c12);
- fclose(saida);
- return -1;
- }
-
- int FiltraCampoParaArquivoFREE(char var[256], char arq1[256], char arq2[256], char caracter, int numero, char caracter2)
- {
- /*
- Este comando filtra um determinado campo de um arquivo, e grava
- outro arquivo com o conteudo igual ao argumento passado.
-
- Entrada : String a comparar --> 01.02.1997 (CHAR 256)
- Arquivo de Entrada --> dh1:gallas.txt (CHAR 256)
- Arquivo de Saida --> dh1:filtro.txt (CHAR 256)
- Delimitador do Arquivo Entrada --> , (CHAR 1)
- Numero do Campo --> 1 (INT)
- Delimitador da String --> . (CHAR 1)
- Saida : Eh gerado o arquivo de saida com o conteudo da linha toda
- Erro : -1 (INT) Caso de problema de abrir arquivo entrada, saida
- Obs : Este comando foi feito para filtrar datas que seguem o
- formato [XX.XX.XX] [01.02.1997], deve ser passado o deli-
- mitador da data, nesse caso eh ., pode ser comparado ate
- 3 campos, ex: [ANO], [MES.ANO], [DIA.MES.ANO]. So 3 campos.
- FiltraCampoParaArquivo("01.02.1997", "dh1:gallas.txt",
- "dh1:filtro.txt", ',', 1, '.');
- */
-
- char teste[256], a, mes[20], telefone[256], cost[20], categoria[256],
- *categorydir, *categoryname;
- int x, opcao;
- FILE *entrada, *saida;
-
- get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
- get(App->TextDefault, MUIA_Text_Contents, &categoryname);
- sprintf(categoria, "%s/%s", categorydir, categoryname);
-
- if(!(entrada = fopen(arq1, "r")))
- return -1;
- if(!(saida = fopen(arq2, "w")))
- return -1;
-
- opcao = QtdCaracter(var, caracter2);
- x = 0;
- while(a = getc(entrada), ! feof(entrada))
- {
- teste[x++] = a;
- if(a == '\n')
- {
- teste[--x] = '\0';
- strcpy(telefone, Corta(teste, ',', 0));
- if(TestaExisteFone(telefone) == 0)
- {
- if(opcao == 0)
- strcpy(mes, AposCaracter(AposCaracter(Corta(teste, caracter, numero), caracter2, 1), caracter2, 1));
- if(opcao == 1)
- strcpy(mes, AposCaracter(Corta(teste, caracter, numero), caracter2, 1));
- if(opcao == 2)
- strcpy(mes, Corta(teste, caracter, numero));
- if(!(strcmp(var, mes)))
- {
- /* ROTINA QUE CALCULA O PRECO DA LIGACAO */
- strcpy(cost, CalculaPrecoFREE(categoria, atoi(Corta(teste, ',', 2)), atoi(Corta(teste, ',', 4)), atoi(DiaSemana(Corta(teste, ',', 1), 2))));
- sprintf(teste, "%s,%s", teste, cost);
- fprintf(saida, "%s\n", teste);
- }
- }
- teste[0] = '\0'; x = 0;
- }
- }
- fclose(entrada);
- fclose(saida);
- return 0;
- }
-
- int VerificaFoneArquivo(char arquivo[256], char temp[256])
- {
- /*
- Esta funcao verifica um determinado arquivo filtrando
- de acordo com a configuracao do Freedom Call os telefones
- que devem ser ignorados na consulta.
-
- Entrada : Path+Nome Arquivo --> freedom.in (CHAR 256)
- Path+Arquivo Temp --> RAM:Freedom.Temp (CHAR 256)
- Saida : Retorna -1 se ok e 0 se der erro (INT)
- VerificaFoneArquivo("freedom.in", "RAM:freedom.temp");
- */
-
- char teste[256], a, telefone[256];
- int x = 0;
- FILE *entrada, *saida;
-
- if(!(entrada = fopen(arquivo, "r")))
- return 0;
- if(!(saida = fopen(temp, "w")))
- return 0;
- x = 0;
- while(a = getc(entrada), ! feof(entrada))
- {
- teste[x++] = a;
- if(a == '\n')
- {
- teste[--x] = '\0';
- strcpy(telefone, Corta(teste, ',', 0));
- if(TestaExisteFone(telefone) == 0)
- fprintf(saida, "%s\n", teste);
- teste[0] = '\0'; x = 0;
- }
- }
- fclose(entrada);
- fclose(saida);
- MoveArquivo(temp, arquivo);
- return -1;
- }
-
- int ArrumaArquivoFREE(char arquivo[256], char tmp[256])
- {
- /* Essa rotina arruma um determinado arquivo acrescentando
- o campo numero 8 de custo da ligacao, repassa todas as linhas
- e gera esse campo.
-
- Entrada : Arquivo a arrumar --> dh2:gallas.txt (CHAR 256)
- Arquivo tmp --> ram:tmp.txt (CHAR 256)
- Saida : 0 se acontecer algum erro, e -1 se der tudo ok.
- ArrumaArquivoFREE("dh2:gallas.txt", "ram:tmp.txt");
- */
-
- char a, teste[256], cost[256], categoria[256], *categorydir,
- *categoryname;
- int x = 0;
- FILE *entrada, *saida;
-
- if(!(entrada = fopen(arquivo, "r")))
- return 0;
- if(!(saida = fopen(tmp, "w")))
- return 0;
-
- get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
- get(App->TextDefault, MUIA_Text_Contents, &categoryname);
- sprintf(categoria, "%s/%s", categorydir, categoryname);
-
- x = 0;
- while(a = getc(entrada), ! feof(entrada))
- {
- teste[x++] = a;
- if(a == '\n')
- {
- teste[--x] = '\0';
- /* ROTINA QUE CALCULA O PRECO DA LIGACAO */
- strcpy(cost, CalculaPrecoFREE(categoria, atoi(Corta(teste, ',', 2)), atoi(Corta(teste, ',', 4)), atoi(DiaSemana(Corta(teste, ',', 1), 2))));
- sprintf(teste, "%s,%s", teste, cost);
- fprintf(saida, "%s\n", teste);
- teste[0] = '\0'; x = 0;
- }
- }
- fclose(entrada);
- fclose(saida);
- MoveArquivo(tmp, arquivo);
- return -1;
- }
-
- int InsereArquivoFREE(char var1[256], char var2[256])
- {
- /*
- Este comando insere um arquivo em outro. Alterado especialmente para
- o Freedom Call.
-
- Entrada : Path+Nome arquivo origem --> dh2:gallas.txt (CHAR 256)
- Path+Nome arquivo destino --> dh2:gallas.tmp (CHAR 256)
- Saida : -1 Erro abertura na origem ou criacao destino, 0 OK (INT)
- InsereArquivo("dh2:gallas.txt", "dh2:gallas.tmp");
- */
-
- char a, teste[256], cost[256], *categorydir, *categoryname,
- categoria[256];
- int x = 0;
- FILE *entrada, *saida;
- if(!(entrada = fopen(var1, "r")))
- return -1;
- if(!(saida = fopen(var2, "a")))
- return -1;
-
- /* LE INFORMACOES DA CONFIGURACAO SOBRE A CATEGORIA */
- get(App->CategDiretorio, MUIA_String_Contents, &categorydir);
- get(App->TextDefault, MUIA_Text_Contents, &categoryname);
- sprintf(categoria, "%s/%s", categorydir, categoryname);
-
- while(a = getc(entrada), ! feof(entrada))
- {
- teste[x++] = a;
- if(a == '\n')
- {
- teste[--x] = '\0';
- /* ROTINA QUE CALCULA O PRECO DA LIGACAO */
- strcpy(cost, CalculaPrecoFREE(categoria, atoi(Corta(teste, ',', 2)), atoi(Corta(teste, ',', 4)), atoi(DiaSemana(Corta(teste, ',', 1), 2))));
- sprintf(teste, "%s,%s", teste, cost);
- fprintf(saida, "%s\n", teste);
- teste[0] = '\0'; x = 0;
- }
- }
- fclose(entrada);
- fclose(saida);
- return 0;
- }
-
- int UnirArquivosFREE(char saida[256], char lista[256])
- {
- /*
- Este comando uni arquivos apartir de uma lista. Alterada especialmente
- para o Freedom Call.
-
- Entrada : Path+Nome Arquivo Saida --> gallas.txt (CHAR 256)
- Path+Nome Arquivo Lista --> lista.txt (CHAR 256)
- Saida : Sera gerado o arquivo de saida contendo todos os
- arquivos incluidos na lista. O comando retorna
- 0 se ocorrer erro e -1 se sucesso. (INT)
- Obs : A lista eh um arquivo texto, ex:
- Arquivo1.txt
- Arquivo2.txt
- Arquivo3.txt
- UnirArquivos("gallas.txt", "lista.txt");
- */
-
- char a, teste[256];
- int x = 0;
- FILE *entrada;
- if(!(entrada = fopen(lista, "r")))
- return 0;
- x = 0;
- while(a = getc(entrada), ! feof(entrada))
- {
- teste[x++] = a;
- if(a == '\n')
- {
- teste[--x] = '\0';
- InsereArquivoFREE(teste, saida);
- teste[0] = '\0'; x = 0;
- }
- }
- fclose(entrada);
- return -1;
- }
-
- char *DescricaoMesFREE(int mes, int opcao)
- {
- /*
- Este comando fornece o mes em formato extenso, se passa o
- numero do mes e a opcao e sera retornado o nome do mes.
- Rotina modificada especificamente para o Freedom Call, funcao
- original tirado do SuRRouND.h.
-
- Entrada : Numero do mes --> 2 (INT)
- Opcao a listar --> 0 (INT)
- Obs : Opcao 0 retorna em Portugues e 1 em Ingles.
- Saida : Fevereiro (CHAR RETURN)
- Erro : ERRO (CHAR RETURN) Mes invalido! < 0 e > 12
- Obs : Caso seja necessario abrevidado use:
- Esquerda(DescricaoMes(2, 0), 3);
- */
-
- switch (mes)
- {
- case 1: return TMsg(App->MsgJaneiro);
- case 2: return TMsg(App->MsgFevereiro);
- case 3: return TMsg(App->MsgMarco);
- case 4: return TMsg(App->MsgAbril);
- case 5: return TMsg(App->MsgMaio);
- case 6: return TMsg(App->MsgJunho);
- case 7: return TMsg(App->MsgJulho);
- case 8: return TMsg(App->MsgAgosto);
- case 9: return TMsg(App->MsgSetembro);
- case 10: return TMsg(App->MsgOutubro);
- case 11: return TMsg(App->MsgNovembro);
- case 12: return TMsg(App->MsgDezembro);
- }
- return "ERRO";
- }
-
- char *DiaSemanaFREE(char var[20], int opcao)
- {
- /*
- Este comando recebe uma data e retorna o dia da semana.
- Rotina modificada especificamente para o Freedom Call, funcao
- original tirado do SuRRouND.h.
-
- Entrada : Data --> 01.02.1997 (CHAR 20)
- Opcao --> 0 (INT)
- Obs : 0 retorna em portugues
- 1 ingles
- 2 o numero do dia, inicio em 1 -> domingo.
- Saida : Dia da Semana -> Segunda (CHAR RETURN)
- DiaSemana("01.02.1997", 0);
- */
-
- char teste[256];
- int x = 0;
- x = fmod(atof(Arredondar(DiaJuliano(var))), 7.0);
- if(opcao == 2)
- {
- sprintf(teste, "%d", x);
- return teste;
- }
- switch(x)
- {
- case 1: return TMsg(App->MsgDomingo);
- case 2: return TMsg(App->MsgSegunda);
- case 3: return TMsg(App->MsgTerca);
- case 4: return TMsg(App->MsgQuarta);
- case 5: return TMsg(App->MsgQuinta);
- case 6: return TMsg(App->MsgSexta);
- case 0: return TMsg(App->MsgSabado);
- }
- return "ERRO";
- }
-