1 /*
2 	�ãġݣңϣ͸������ե�	CDROM2.EXE ��
3 	�����ե���������ץ����ʥ���ǥ������б���
4 
5 			by �ҡ�������Ϻ	jiro@math.keio.ac.jp
6 */
7 
8 #include <stdio.h>
9 #include <string.h>
10 #include <ctype.h>
11 #include <fcntl.h>
12 #include <unistd.h>
13 #include <stdlib.h>
14 #ifdef  MSC
15 #include <sys/types.h>
16 #define size_t  off_t
17 #endif  /* MSC */
18 #include <sys/stat.h>
19 #ifdef  UNIX
20 #define O_BINARY        0
21 #define EUC
22 #else
23 #include <io.h>
24 #endif  /* UNIX */
25 #ifdef  LSI_C
26 #define O_BINARY        0
27 #endif  /* LSI_C */
28 
29 #define	OFLAG	(O_CREAT|O_TRUNC|O_RDWR|O_BINARY)
30 #define	PMODE	(S_IREAD|S_IWRITE)
31 
usage(cmd)32 void usage(cmd)
33 char	*cmd;
34 {
35 	puts("CDROM2.EXE �ѡ���������ե���������ץ���� 1995/05/14");
36 	puts("\t\t\tby �ҡ�������Ϻ\tjiro@math.keio.ac.jp");
37 	printf("%s from [to]\n",cmd);
38 	puts("\tto ���ά����ȡ�from �γ�ĥ�Ҥ�'.DMP'���Ѥ�����ΤȤʤ�");
39 }
40 
41 char	data[]={255,255,0};
42 
main(argc,argv)43 void main(argc,argv)
44 int argc;
45 char *argv[];
46 {
47 	char	buff[BUFSIZ];
48 	FILE	*from;
49 	int	to;
50 	unsigned int	i,c,l;
51 	unsigned char	*p;
52 	unsigned char b[BUFSIZ];
53 
54 	if(argc<2||argc>3)
55 		usage(argv[0]),
56 		exit(0);
57 	if((from=fopen(argv[1],"r"))==NULL)
58 		perror(argv[1]),
59 		exit(1);
60 	if(argc==2)
61 	{
62 		strcpy(buff,argv[1]);
63 		if((p=strrchr(buff,'.'))==NULL)
64 			strcat(buff,".DMP");
65 		else
66 			strcpy(p,".DMP");
67 		if((to=open(buff,OFLAG,PMODE))<0)
68 			perror(buff),
69 			exit(2);
70 	}
71 	else
72 		if((to=open(argv[2],OFLAG,PMODE))<0)
73 			perror(argv[2]),
74 			exit(3);
75 	l=0;
76 	while(fgets(buff,BUFSIZ,from))
77 	{
78 		if((p=strrchr(buff,'\n'))!=NULL)	/* chop */
79 			*p='\0';
80 		for(p=buff;((c=*p)!='\0')&&(c<=' ');p++);	/* skip spase */
81 		if(*p=='*')	/* ������ */
82 			continue;
83 		if(*p=='\0')	/* ���� */
84 			continue;
85 		for(i=0;isxdigit(*p);p++)	/* HEX digit */
86 			i*=16,
87 			i+=isdigit(*p)?*p-'0':toupper(*p)-'7';
88 		if(i==0)	/* ̵�� */
89 			continue;
90 		printf("%04X\t",i);
91 		if(i<l)
92 		{
93 			puts("�����Ȥ���Ƥ��ޤ���");
94 			break;
95 		}
96 		l=i;
97 		for(;((c=*p)!='\0')&&(c<=' ');p++);	/* skip space */
98 		b[0]=i & 255;	/* low BYTE */
99 		b[1]=i >> 8;	/* high BYTE */
100 		if(write(to,b,2)!=2)
101 			perror(buff),
102 			exit(4);
103 		for(i=0;*p;)
104 		{
105 			if(*p!='\\')
106 				b[i++]=*p++;
107 			else
108 			{
109 				/* OCTAL digit */
110 				p++;
111 				for(c=0;*p>='0'&&*p<='7';p++)
112 					c*=8,
113 					c+=*p-'0';
114 				if(c==0)
115 					break;
116 				b[i++]=c;
117 			}
118 		}
119 		b[i++]='\0';
120 		puts(b);
121 		if(write(to,b,i)!=i)
122 			perror(buff),
123 			exit(5);
124 	}
125 	if(write(to,data,sizeof data)!=sizeof data)
126 		perror("-EOF-"),
127 		exit(6);
128 	close(to);
129 	fclose(from);
130 }
131