📄 raw2sco.c
字号:
/* * raw2sco.c * * Author : Lionetti Salvatore <salvatorelionetti@yahoo.it> * License: GPL * * 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 of the License, 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include<fcntl.h> /* open().*/#include<unistd.h> /* read()/close().*/#include<stdio.h>#include<string.h> /* To have memcpy().*/int main(int argc, char* argv[]) { int ritorno; char scoHandle[2]; int fd; /* Get sco handle.*/ { ritorno = 1; int fd=open("data.txt",O_RDONLY,0666); if (fd>0) { char handles[8]; if (read(fd,handles,8)==8) { scoHandle[0]=handles[6]; scoHandle[1]=handles[7]; ritorno = 0; } close(fd); } } fd=0; if (argc>1) { fd=open(argv[1],O_RDONLY,0666); ritorno=(fd<=0); } /* Read from sco file.*/ if (ritorno == 0) { /* * Tipical frame: * handle len * 2b 00 30 ... (48 bytes) */ ritorno = 1; /* on 0 return, driver is ok.*/ while (ritorno>0) { char data[48]; unsigned char len=48; unsigned char l; int nTenta=100; int headWr=0; l=0; while (ritorno>=0 && l<len && nTenta) { ritorno=read(fd,data+l,len-l); if (ritorno>0) { if (!headWr) { headWr=1; write(1,scoHandle,2); write(1,&len,1); } write(1,data+l,ritorno); nTenta=100; } else nTenta--; l+=ritorno; } if (ritorno>=0 && headWr) { memset(data+l,0,len-l); write(1,data+l,len-l); } } } fprintf(stderr,"ritorno(%d)",ritorno); return ritorno;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -