• Авторизация


Вспомнил Си. 26-08-2008 12:26 к комментариям - к полной версии - понравилось!


Вспомнил, чему учили в универе. И написал на Си конвертер через командную строку файлов RCWV в формат WAV.
Блин, пришлось повозиться. Си уже порядком забыл, хорошая встряска для моска.
Сначала парился в турбо-си досовском еще, но этот си не воспринимал длинные имена файлов, пришлось перейти на виндовый си, найти компиль и сконвертить.

1800Message.com file forma RCWV converter by Fixin 2008
http://fixin.com.ru
ICQ: 203-136-830, fixin@mail.ru

Supports UTF encoding in contact name
Free dotationware, WebMoney: Z667446785248, R883290290994

Example of use: rcwv myfile.rcwv
This converts file "myfile.rcwv" to "myfile;AbonentName;AbonentNumber.wav"


// =============================================================
// (-C) Fixin aka Genius Of 1s, 2008
// =============================================================

#include
#include
#include
#include
#include
#include
#define UNICODE
#include "windows.h"


char TranslateChar(char c1, char c2) {
char r;
//char str_src[2];
//char str_res[2];
WCHAR chSrc;
((char *) &chSrc)[0] = c1;
((char *) &chSrc)[1] = c2;
//WideCharToMultiByte(CP_ACP, 0, &chSrc, 1, &r, 1, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, &chSrc, 1, &r, 1, NULL, NULL);


//str_src[1]=0;
//str_src[0]=r;
//OemToAnsiBuff(&r, &r, 1);
//OEMToAnsi(str_src, str_res);
//r = str_res[0];

//printf("Convert: %x %x -> %c \n", c1, c2 ,r);
if (r==0) r=' ';

return r;
}


int main(int argc, char *argv[]) {

char MajorVersion=0;
char MinorVersion=0;
char Revision=0;

FILE* FromHandle;
FILE* ToHandle;
long BytesCopied;
int ccode;
int i;
char call_number[1024];
char call_name[1024];
char ch;
char dst_name[2000];
char a[100];
char prev = 0;
char fch = 0;
char buffer[6]; //6 symbols
int fl_media=0;
int fl_len =0;

printf("1800Message.com file format RCWV converter by Fixin 2008, http://fixin.com.ru ICQ:203-136-830, fixin@mail.ru\n");
printf("Supports UTF encoding in contact name\n");
printf("Free dotationware, WebMoney: Z667446785248, R883290290994 \n\n");

if(argc < 2) {
printf("You must specify a source file name!\nExample: rcwv myfile.rcwv\nThis converts file \"myfile.rcwv\" to \"myfile;AbonentName;AbonentNumber.wav\"");
return 1;
}


if ((FromHandle = fopen(argv[1], "rb")) == NULL)
{
printf("Cannot open source file: %s\n ", argv[1]);
return 1;
}
for (i = 0; i < strlen(argv[1]); i ++) {
dst_name [i] = argv[1][i];
}

int dst_len = strlen(argv[1])-5;



int pos = 0;
int pos_b = 0, pos_c = 0, pos_d = 0;

while (1) {
ch=fgetc(FromHandle);
if (feof(FromHandle)) break;
buffer[5]=buffer[4];
buffer[4]=buffer[3];
buffer[3]=buffer[2];
buffer[2]=buffer[1];
buffer[1]=buffer[0];
buffer[0]=ch;

//Check position C
if (
buffer[0] == 'c' &&
(pos == 23)
){
pos_c = pos;
printf("Find pos C (abonent name): %i, filename size = %i\n", pos_c, dst_len);
dst_name[dst_len++]=';'; //Add space
}
//Waiting for block d

/* if (
(buffer[0] == 'd') &&
(buffer[1] == 0) &&
(buffer[2] == 0) &&
(buffer[3] == 0) &&
pos_d == 0){
pos_d = pos;
printf("Find pos D (phone number): %i filename size = %i \n", pos_d, dst_len);
dst_name[dst_len++]='#'; //Add space
}
*/

//Read block c
if ((pos_c>0) && ((pos - pos_c) % 2 == 0) && (pos > pos_c)) {


if (
(buffer[0] == 0) &&
(buffer[1] == 0)) {
pos_d = pos+1;
printf("Find pos D (phone number): %i filename size = %i \n", pos_d, dst_len);
dst_name[dst_len++]=';'; //Add space
pos_c = -1;

} //Finish of block C
else {
fch = TranslateChar(buffer[1], buffer[0]);
dst_name[dst_len++]=fch;
printf("Pos c : %i -> %i = %x %x : %c \n", pos, pos_c, buffer[1], buffer[0], fch);
}
}

//printf("Pos , dst_name : %pos -> %s ", pos, dst_name);


//Read block d
if ((pos_d>0) && ((pos - pos_d) % 2 == 0) && (pos > pos_d)) {


if (
(buffer[0] == 0) &&
(buffer[1] == 0)) { pos_d = -1; } //Finish of block D
else {
fch = TranslateChar(buffer[1], buffer[0]);
printf("Pos d : %i -> %i = %x %x : %c \n", pos, pos_d, buffer[1], buffer[0], fch);
dst_name[dst_len++]=fch;
}
}

if (dst_len == 1000) {
if (!fl_len) {
printf("File name length so long, more then 1000 symbols, so truncate! \n");
fl_len = 1;
}
else
dst_len --;
}

if (
(buffer[0] == 'F') &&
(buffer[1] == 'F') &&
(buffer[2] == 'I') &&
(buffer[3] == 'R') && fl_media ==0){
fl_media = 1;
//Add extension WAV
dst_name[dst_len++] = '.';
dst_name[dst_len++] = 'w';
dst_name[dst_len++] = 'a';
dst_name[dst_len++] = 'v';
dst_name[dst_len++] = 0;
dst_name[dst_len++] = 0;
if ((ToHandle = fopen(dst_name, "wb")) == NULL) {
printf("Can'not open destination file: %s \n", dst_name);
return 1;
}
putc('R', ToHandle);
putc('I', ToHandle);
putc('F', ToHandle);
putc('F', ToHandle);

printf("Write to dst file: %s \n", dst_name);

}
else
if (fl_media == 1) {
putc(ch, ToHandle);
}

pos++;
}

fclose(FromHandle);
fclose(ToHandle);
return 0;
}

В колонках играет: Gaurangi devi dasi - Track01 {01 Beautiful}

LI 7.05.22 beta
вверх^ к полной версии понравилось! в evernote


Вы сейчас не можете прокомментировать это сообщение.

Дневник Вспомнил Си. | fixin - Дневник fixin | Лента друзей fixin / Полная версия Добавить в друзья Страницы: раньше»