/* * Copyright (C) 2004-2005 Vadim Berezniker * http://www.kryptolus.com * * This Program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ #include "stdafx.h" #include "common.h" #include "sabbu.h" #include "krySubSSA.h" #include "krySubWriter.h" #include "krySubWriterSRT.h" extern struct krySubSSAColumnInfo *sub_ssa_save_ssa_columns; krySubWriterSRT::krySubWriterSRT(kryScript *script, char *filename) : krySubWriter(script, filename) { } char *krySubWriterSRT::WriteScript() { if(!this->Open()) return strerror(errno); this->WriteHeaders(); this->SetEventFilter(kryEvent::EVENT_DIALOG); int index = 1; while(kryEvent *event = this->GetNextEvent()) { char *buffer = kry_strdup_printf(KRY_LOC "%d\n", index); this->WriteString(buffer); kry_free(buffer); char *time_start = time_mili_to_string(event->GetStart(), TRUE, TRUE); char *time_end = time_mili_to_string(event->GetEnd(), TRUE, TRUE); buffer = kry_strdup_printf(KRY_LOC "%s --> %s\n", time_start, time_end); this->WriteString(buffer); kry_free(buffer); kry_free(time_end); kry_free(time_start); buffer = event->GetText(); if(!buffer) buffer = ""; int len = strlen(buffer); int last_pos = 0; for(int i = 0; i <= len; i++) { if(i == len || buffer[i] == 10 && last_pos != i) { if(i < len) buffer[i] = 0; this->WriteString(buffer + last_pos); this->WriteString("\n"); last_pos = i + 1; if(i < len) buffer[i] = 10; } } this->WriteString("\n"); index++; } return NULL; }