外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。
gccで文字を書く
:gccで文字を書く
@echo off
if not exist %~dpn0.exe (
for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
more +%%n %0 > %~dpn0.c
gcc -Os %~dpn0.c -o %~dpn0.exe -s
)
)
call %~dp0set "s" "%*" %~dpn0.txt
if not defined s set s=こんにちは
%~dpn0
goto:eof
REM #jww
REM #0 位置を指示して下さい
REM #c 文字 =
REM #e
#!この次の行からプログラムを書いてください
#include "jw.h"
int main(void)
{
FILE *f, *g;
char S_[256], *F[20];
char str[256];
double lx, ly, hk, d;
if ( (f = fopen("jwc_temp.txt", "r") ) != NULL) {
strcpy(str, getenv("s"));
if (str == NULL) { strcpy(str, "こんにちは"); }
g = fopen("myfiles", "w");
while (fgets(S_, 256, f) != NULL) {
split(chomp(S_), F);
if (strncmp(S_, "hk", 2) == 0) hk = atof(F[1]);
}
} else {
exit(MISSING_JWC_TEMP_TXT);
}
d = rad(hk); lx = cos(d); ly = sin(d);
fprintf(g, "ch 0.0 0.0 %.15g %.15g \"%s\n", lx, ly, str);
fclose(g);
fclose(f);
remove("jwc_temp.txt");
rename("myfiles", "jwc_temp.txt");
return 0;
}
○jw.h
/* jw.h : JW_CAD 外部変形 例題用ヘッダファイル
動作確認
MinGW + gcc / g++ 4.5.0
Borland C++ 5.5.1 for Win32
Visual C++ 2005 Express Edition
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define PI 3.1415926535897932384626433832795
#define MISSING_JWC_TEMP_TXT printf("jwc_temp.txt が 見当たりません\n")
#define NO_OPERATION printf("処理できませんでした\n")
int split(char *S_, char **F)
{ /* char S_[256], *F[20]; */
int i, NF;
for (i = 0; i < 20; i++) {
if ( (F[i] = strtok(S_, " ") ) == NULL) { NF = i; break; }
S_ = NULL;
}
return NF;
}
char *substr(char *src, int off, int len, char *buf)
{
return strncpy(buf, src+off, len);
}
char *chomp(char *str)
{
int l = strlen(str);
if( l > 0 && str[l-1] == '\n' )
{
str[l-1] = '\0';
}
return str;
}
double rad(double x)
{
return x * PI / 180.0;
}
double hypot(double x, double y)
{
return sqrt(x * x + y * y);
}