#11 Article 2436 Posted at 1989/01/20 21:59:28 by NOZOMU (MAP041) [PRG.C]
Subject: mkhead.c
X68000用のheadder-file切り出しプログラムのソースです。
次のアーティクルには、mkhead.cとmkhead.xをzooしてishした物を
uploadしてありますので、X68000ユーザでzooとishを持っている人は、
このアーティクルをdownloadする必要はありません。
/*
BOSS君のmsx用Headder切り出しプログラムを、XCに移植した物です。
int instr(n,str1,str2)
int n;
char *str1,*str2;
と言う関数は、str1のn番目からstr2と同じ文字列をさがし、あった場合は
その位置(str1[0]を1番目とした位置)が戻り、なかった場合は0が戻ります。
これ以外はごく普通に書いてありますから、他のCコンパイラに移植するのも
簡単だと思います。
MAP041 NOZOMU
*/
#include <stdio.h>
#include <basic.h>
FILE *logptr,*headptr;
unsigned char x1[256],x2[256],x3[256];
void makeheader(void);
void main(argc,argv)
int argc;
unsigned char *argv[];
{
unsigned char temp[80],logfile[80],headfile[80];
strcpy(logfile,"MAPLOG");
strcpy(headfile,"MAPMAP");
if (argc==1)
{ printf("mkhead.x ver 1.0 copyright 1989 by MAP041 NOZOMU.\n");
printf("\n");
printf("Mapletown-Networkのlog-fileからCG・TechボードのHeadder-fileを作成します。\n");
printf("log-fileのfile-nameを入れて下さい。リターンのみで'MAPLOG'です。\n:");
gets(temp);
if (temp[0]!=0) strcpy(logfile,temp);
printf("Headder-fileのfile-nameを入れて下さい。リターンのみで'MAPMAP'です。\n:");
gets(temp);
if (temp[0]!=0) strcpy(headfile,temp);
}
else
{ strcpy(logfile,argv[1]);
if (--argc!=1) strcpy(headfile,argv[2]);
}
if ((logptr =fopen(logfile ,"rt"))==NULL)
{ printf("log-fileが見付かりませんでした。\n");
return;
}
if ((headptr=fopen(headfile,"at"))==NULL)
{ printf("headder-fileがopen出来ませんでした。\n");
return;
}
for (;feof(logptr)==0;fgets(x1,256,logptr))
if ((strncmp(x1,"Article ",8)==0)&&(instr(1,x1," in CG・Tech [")!=0))
makeheader();
fclose(logptr);
fclose(headptr);
return;
}
void makeheader(void)
{
short int i ,j ,l1,l2,l3 ,a1 ,b1;
char a[256] ,b[256] ,c[256] ,d[256] ,e[256] ,f[256] ,g[256] ,h[256];
fgets(x2,256,logptr);
fgets(x3,256,logptr);
l1=strlen(x1);
l2=strlen(x2);
l3=strlen(x3);
a1=instr(1,x1," of "); /* Number */
for (i=0;i<13-a1;++i)
a[i]=' ';
a[i]=0;
strncat(a,&x1[8],a1-9);
if (!strncmp(x2,"(canceled ",10)) /* Canceled */
{ fprintf(headptr,"%s %s",a,x2);
return;
}
b1=a1+a1+8; /* Keyword */
strcpy(b," ");
if (l1>b1+1) strncpy(b,&x1[b1-1],l1-b1-1);
strncpy(c,&x2[10],17); /* Date & Time */
c[17]=0;
strncpy(d,&x2[31],12); /* Name */
d[12]=0;
strncpy(e,&x2[45],6); /* ID */
e[6]=0;
strncpy(f,&x2[59],5); /* Charactor */
f[5]=0;
if ((strcmp(f,"ASCII")==0)||(strcmp(f,"KANJI")==0)) j=66;
if (strcmp(f,"KANA ")==0) j=65;
strcpy(g," "); /* lines */
strncpy(&g[3-(l2-j-7)],&x2[j-1],l2-j-7);
g[3]=0;
strncpy(h,&x3[9],l3-9); /* Subject */
h[l3-9]=0;
fprintf(headptr,"%s %s %s %s %s %s %s %s",a,b,c,d,e,f,g,h); /* OUTPUT */
return;
}