/* Calcola il costo mensile dei collegamenti con il proprio Provider Internet. */ sec = Time(s) /* Legge i dati dal file di configurazione */ IF ~Open('cfg','Env:Scatti.cfg','r') THEN CALL ERRORE1 temp = ReadLn('cfg') log = ReadLn('cfg') lav = ReadLn('cfg') pun = ReadLn('cfg') int = ReadLn('cfg') ser = ReadLn('cfg') not = ReadLn('cfg') unit = ReadLn('cfg') con = ReadLn('cfg') pb = ReadLn('cfg') Close('cfg') IF Right(temp,1) ~= '/' & Right(temp,1) ~= ':' THEN temp = temp||'/' IF Right(log,1) ~= '/' & Right(log,1) ~= ':' THEN log = log||'/' IF Right(lav,1) ~= '/' & Right(lav,1) ~= ':' THEN lav = lav||'/' temp = temp||'temp' /* Legge i dati dal file temporaneo */ IF ~Open('temp',temp,'r') THEN CALL ERRORE1(temp) sec0 = ReadLn('temp') /* legge i secondi da temp */ giorno = ReadLn('temp') /* legge il giorno da temp */ ora = ReadLn('temp') /* legge l'ora da temp */ data = ReadLn('temp') /* legge la data da temp */ IF ~Close('temp') THEN CALL ERRORE2(temp) mese = SubStr(data,4) app = Translate(mese,'_','/') /* stringa da appendere al nome del file */ log1 = log||'Scatti.log' /* nome file phonebill */ log = log||'Scatti_'||app||'.log' /* nome file log */ lav = lav||'lav' /* nome file lavoro */ /* Scrive il file per phonebill */ IF pb = 'si' THEN DO IF Exists(log1) THEN DO IF ~Open('log1',log1,'a') THEN CALL ERRORE1(log1) END ELSE DO IF ~Open('log1',log1,'w') THEN CALL ERRORE1(log1) END WriteLn('log1','>>> '||data||' '||ora||' Inizio Sessione Internet') WriteLn('log1',' 'Date(e)' 'Time(n)' Fine Sessione') WriteLn('log1','') IF ~Close('log1') THEN CALL ERRORE2(log1) END /* Scrive il file di log */ IF ~Exists(log) THEN DO IF ~Open('log',log,'w') THEN CALL ERRORE1(log) WriteLn('log',' ¨ LOGFILE GENERATO DA SCATTI 1.0') WriteLn('log',' di Giovanni Addabbo') WriteLn('log','') WriteLn('log',' Dati relativi al mese: '||mese) WriteLn('log','') WriteLn('log',' +----------+----------+--------------+--------+--------+') WriteLn('log',' | Data | Ora | Durata | Scatti | Costo |') WriteLn('log',' +----------+----------+--------------+--------+--------+') WriteLn('log','#') WriteLn('log','# TOTALE 0h 0'' 0" 0 0') t= Close('log') END IF sec < sec0 THEN sec = sec + (24*3600) online = (sec - sec0) + con /* durata connessione */ /* Verifica se è Domenica, Sabato o Festivo */ data1 = Left(data,5) SELECT WHEN data1 = "08/04" THEN CALL FESTIVO() /* Pasquetta: varia negli anni --> aggiustare */ WHEN data1 = "01/01" | data1 = "06/01" | data1 = "25/04" THEN CALL FESTIVO() WHEN data1 = "01/05" | data1 = "15/08" | data1 = "01/11" | data1 = "25/12" | data1 = "26/12" THEN CALL FESTIVO() WHEN giorno = "Sunday" THEN CALL FESTIVO() WHEN giorno = "Saturday" THEN CALL PREFESTIVO() OTHERWISE CALL FERIALE() END /* Aggiorna il file di log */ scatti = online % tar + 1 /* Aggiunge lo scatto alla risposta */ costo = scatti * unit /* Calcola il costo della chiamata */ IF ~Open('log',log,'r') THEN CALL ERRORE1(log) /* Apre file log */ IF ~Open('lav',lav,'w') THEN CALL ERRORE1(lav) /* Apre file lavoro */ DO UNTIL Left(ti,6) = 'TOTALE' ti = ReadLn('log') IF Left(ti,1) ~= '#' THEN WriteLn('lav',ti) /* Copia su file lavoro */ ti = SubStr(ti,19,40) END IF ~Close('log') THEN CALL ERRORE2(log) IF ~Close('lav') THEN CALL ERRORE2(lav) totco = Strip(Right(ti,6)) totsc = Strip(SubStr(ti,26,6)) totore = Strip(SubStr(ti,11,3)) totmin = Strip(SubStr(ti,16,2)) totsec = Strip(SubStr(ti,20,2)) totco = totco + costo /* Calcola i nuovi totali */ totsc = totsc + scatti minuti = online % 60 secondi = online // 60 ore = minuti % 60 minuti = minuti // 60 totsec = totsec + secondi ; addmin = totsec % 60 ; totsec = totsec // 60 totmin = addmin + minuti + totmin ; addore = totmin % 60 ; totmin = totmin //60 totore = totore + ore + addore totco = Right(totco,6,' ') totsc = Right(totsc,6,' ') totsec = Right(totsec,2,' ') totmin = Right(totmin,2,' ') totore = Right(totore,3,' ') totdur = totore'h 'totmin''' 'totsec'"' costo = Right(costo,6,' ') scatti = Right(scatti,6,' ') minuti = Right(minuti,2,' ') secondi= Right(secondi,2,' ') ore = Right(ore,3,' ') durata = ore||'h 'minuti||"' "||secondi'"' linea = ' | 'data' | 'ora' | 'durata' | 'scatti' | 'costo' |' IF ~Open('lav',lav,'a') THEN CALL ERRORE1(lav) WriteLn('lav',linea) WriteLn('lav',' +----------+----------+--------------+--------+--------+') WriteLn('lav','#') WriteLn('lav','# TOTALE 'totdur' 'totsc' 'totco) IF ~Close('lav') THEN CALL ERRORE2(lav) ADDRESS command 'copy >nil:' lav log /* Copia il file lavoro su log */ 'delete >nil:' lav /* Cancella file lavoro */ 'delete >nil:' temp /* Cancella file temporaneo */ EXIT FESTIVO: SELECT WHEN ora >= "08:00:00" & ora < "22:00:00" THEN tar = ser OTHERWISE tar = not END RETURN PREFESTIVO: SELECT WHEN ora >= "08:00:00" & ora < "13:00:00" THEN tar = int WHEN ora >= "13:00:00" & ora < "22:00:00" THEN tar = ser OTHERWISE tar = not END RETURN FERIALE: SELECT WHEN ora >= "08:00:00" & ora < "08:30:00" THEN tar = int WHEN ora >= "08:30:00" & ora < "13:00:00" THEN tar = pun WHEN ora >= "13:00:00" & ora < "18:30:00" THEN tar = int WHEN ora >= "18:30:00" & ora < "22:00:00" THEN tar = ser OTHERWISE tar = not END RETURN ERRORE1: /* Non si può aprire il file */ ARG file SAY 'Errore!!' SAY 'Non è possibile aprire il file: "'file'"' EXIT ERRORE2: /* Non si può chiudere il file */ ARG file SAY 'Errore!!' SAY 'Non è possibile chiudere il file: "'file'"' EXIT