jw_cad 外部変形 - (1008) gccで曲線データを確認する(pl) -

外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。

 

gccで曲線データを確認する(pl)

:gccで曲線データを確認する(pl)
@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
  )
)
%~dpn0
goto:eof

REM #jww
REM #h1
REM #hc 曲線を選択してください
REM #e

#!この次の行からプログラムを書いてください
#include "jw.h"

int main(void)
{
  FILE *f, *g;
  int i, j, NF, pln = 0, k = 0;
  int plflg = 0;
  char S_[256], *F[20];
  char SS[256];
  double pl[20][256][4];
  int plno[20];
  double x1, y1, x2, y2;
  if ( (f = fopen("jwc_temp.txt", "r")) != NULL) {
    g = fopen("myfiles", "w");
    while (fgets(S_, 256, f) != NULL) {
      strcpy(SS, chomp(S_));
      NF = split(SS, F);
      if (strncmp(S_, "hq", 2) == 0) { 
        fprintf(g, "hd\n");
        continue;
      }
      if (strncmp(S_, "pl", 2) == 0) {
        plflg = 1;
        pln += 1;
        continue;
      }
      if (strncmp(S_, " ", 1) == 0 && NF == 4 && plflg == 1) {
        pl[pln][k][0] = atof(F[0]);
        pl[pln][k][1] = atof(F[1]);
        pl[pln][k][2] = atof(F[2]);
        pl[pln][k][3] = atof(F[3]);
        k++;
        continue;
      }
      if (strncmp(S_, "#", 1) == 0) {
        if (plflg == 1) {
          plflg = 0;
          plno[pln] = k;
          k = 0;
        }
        continue;
      }
    }
  } else {
    exit(MISSING_JWC_TEMP_TXT);
  }
  for (i = 1; i <= pln; i++) {
    fprintf(g, "pl\n");
    fprintf(g, "lc%d\n", (6+i));
    for (j = 0; j < plno[i]; j++) {
      x1 = pl[i][j][0];
      y1 = pl[i][j][1];
      x2 = pl[i][j][2];
      y2 = pl[i][j][3];
      fprintf(g, "%.15lg %.15lg %.15lg %.15lg\n", x1, y1, x2, y2);
    }
    fprintf(g, "#\n");
  }
  fclose(g);
  fclose(f);
  remove("jwc_temp.txt");
  rename("myfiles", "jwc_temp.txt");
  return 0;
}