home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume17 / xtexcad1 / part05 < prev    next >
Encoding:
Text File  |  1992-04-20  |  50.2 KB  |  2,123 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!zaphod.mps.ohio-state.edu!mips!msi!dcmartin
  3. From: Fritz Haubensak <hsk@informatik.uni-wuerzburg.de>
  4. Subject: v17i069: TeXcad (X) version 1.2, Part05/10
  5. Message-ID: <1992Apr21.131021.2357@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Nntp-Posting-Host: fascet
  9. Organization: Molecular Simulations, Inc.
  10. References: <csx-17i065-xtexcad-1.2@uunet.UU.NET>
  11. Date: Tue, 21 Apr 1992 13:10:21 GMT
  12. Approved: dcmartin@msi.com
  13. Lines: 2108
  14.  
  15. Submitted-by: Fritz Haubensak <hsk@informatik.uni-wuerzburg.de>
  16. Posting-number: Volume 17, Issue 69
  17. Archive-name: xtexcad-1.2/part05
  18.  
  19. # this is part.05 (part 5 of a multipart archive)
  20. # do not concatenate these parts, unpack them in order with /bin/sh
  21. # file graphics.c continued
  22. #
  23. if test ! -r _shar_seq_.tmp; then
  24.     echo 'Please unpack part 1 first!'
  25.     exit 1
  26. fi
  27. (read Scheck
  28.  if test "$Scheck" != 5; then
  29.     echo Please unpack part "$Scheck" next!
  30.     exit 1
  31.  else
  32.     exit 0
  33.  fi
  34. ) < _shar_seq_.tmp || exit 1
  35. if test ! -f _shar_wnt_.tmp; then
  36.     echo 'x - still skipping graphics.c'
  37. else
  38. echo 'x - continuing file graphics.c'
  39. sed 's/^X//' << 'SHAR_EOF' >> 'graphics.c' &&
  40. X  int anz_text;
  41. X  XtTranslations  trans_table,trans_table2;
  42. X  char          leave_str[100]="<LeaveNotify> : fb_beende_textedit() fb_correct_text_error()\n";
  43. X  char          ok_str[100]="<ButtonRelease> : fb_beende_textedit() fb_correct_text_error()\n";
  44. X  char          more_str[100]="<ButtonRelease>    : fb_beende_textedit() fb_textedit()\n";
  45. X  char          del_str[100]="<ButtonRelease>    : fb_delete_textedit() fb_beende_textedit() fb_textedit()\n";
  46. X
  47. X  char            temp_str2[100] = 
  48. X            "<KeyPress>Return    : dummy() \n";
  49. X  
  50. X  static XtActionsRec actions[200] = {{"dummy", dummy},
  51. X                      {"fb_textedit", fb_textedit},
  52. X                      {"fb_beende_textedit", fb_beende_textedit},
  53. X                      {"fb_delete_textedit", fb_delete_textedit},
  54. X                      {"fb_correct_text_error",fb_correct_text_error}};
  55. X  Position x_rel, y_rel, x, y;
  56. X    
  57. X
  58. X    fb_muschel=XtCreatePopupShell("Edit/Delete", transientShellWidgetClass, canvas, NULL, 0);
  59. X
  60. X    trans_table = XtParseTranslationTable(leave_str);
  61. X    XtOverrideTranslations(fb_muschel, trans_table);
  62. X
  63. X    perle=XtCreateManagedWidget("behaelter", boxWidgetClass, fb_muschel, NULL, 0);
  64. X    
  65. X    n=0;
  66. X    XtSetArg(args[n], XtNlabel,"Edit Text: FRAMED BOX");n++;
  67. X    XtSetArg(args[n], XtNjustify,XtJustifyCenter);n++;
  68. X    XtSetArg(args[n], XtNwidth,560);n++;
  69. X    XtSetArg(args[n], XtNheight,40);n++;
  70. X    
  71. X    XtCreateManagedWidget("", labelWidgetClass, perle, args, n);
  72. X
  73. X
  74. X    n=0;
  75. X    XtSetArg(args[n], XtNlabel,"Accept");n++;
  76. X    XtSetArg(args[n], XtNjustify,XtJustifyCenter);n++;
  77. X    XtSetArg(args[n], XtNwidth,130);n++;
  78. X    XtSetArg(args[n], XtNheight,40);n++;
  79. X    XtSetArg(args[n], XtNshapeStyle,XmuShapeOval);n++;
  80. X    
  81. X    ok=XtCreateManagedWidget("ok", commandWidgetClass, perle, args, n);
  82. X    trans_table = XtParseTranslationTable(ok_str);
  83. X    XtOverrideTranslations(ok, trans_table);
  84. X
  85. X
  86. X    /* compute number of text-entries */
  87. X    anz_text=fb_number_of_text();
  88. X
  89. X    if (anz_text==0)
  90. X    {
  91. X        leave_pick("Sorry - No text available !\n");
  92. X        return;
  93. X    }    
  94. X
  95. X
  96. X    if (anz_text>10)
  97. X    {
  98. X        n=0;
  99. X        XtSetArg(args[n], XtNlabel,"More");n++;
  100. X        XtSetArg(args[n], XtNjustify,XtJustifyCenter);n++;
  101. X        XtSetArg(args[n], XtNwidth,130);n++;
  102. X        XtSetArg(args[n], XtNheight,40);n++;
  103. X        XtSetArg(args[n], XtNshapeStyle, XmuShapeOval);n++;
  104. X        
  105. X    
  106. X        more=XtCreateManagedWidget("more", commandWidgetClass, perle, args, n);
  107. X        trans_table = XtParseTranslationTable(more_str);
  108. X        XtOverrideTranslations(more, trans_table);
  109. X    }
  110. X
  111. X
  112. X    n=0;
  113. X    XtSetArg(args[n], XtNlabel,"Delete");n++;
  114. X    XtSetArg(args[n], XtNjustify,XtJustifyCenter);n++;
  115. X    XtSetArg(args[n], XtNwidth,130);n++;
  116. X    XtSetArg(args[n], XtNheight,40);n++;
  117. X    XtSetArg(args[n], XtNshapeStyle,XmuShapeOval);n++;
  118. X    
  119. X    del=XtCreateManagedWidget("del", commandWidgetClass, perle, args, n);
  120. X    trans_table = XtParseTranslationTable(del_str);
  121. X    XtOverrideTranslations(del, trans_table);
  122. X    
  123. X    
  124. X    if (ab>anz_text) ab=-9;
  125. X    ab+=10; /* ab was initially -9 */
  126. X    if (ab>anz_text) ab=1;
  127. X
  128. X    /* framedBox_marker must point to the "ab"th text! */
  129. X
  130. X    framedBox_marker=framedBox_start;
  131. X    for (i=2; i<=ab; i++) framedBox_marker=framedBox_marker->next;
  132. X
  133. X    for (i=ab; ( (i<=anz_text) && (i-ab<10) ); i++)
  134. X    {
  135. X        n=0;
  136. X        XtSetArg(args[n],XtNorientation,XtorientHorizontal);n++;
  137. X        XtSetArg(args[n],XtNborderWidth,0);n++;
  138. X        kiste=XtCreateManagedWidget("drin", boxWidgetClass, perle, args, n);
  139. X        n=0;
  140. X        XtSetArg(args[n],XtNstate,False);n++;
  141. X        XtSetArg(args[n],XtNheight,20);n++;
  142. X        XtSetArg(args[n],XtNwidth,20);n++;
  143. X        XtSetArg(args[n],XtNshapeStyle,XmuShapeOval);n++;
  144. X        toggle=XtCreateManagedWidget("!", toggleWidgetClass, kiste, args, n);
  145. X        n=0;
  146. X        XtSetArg(args[n],XtNuseStringInPlace,True);n++;
  147. X        XtSetArg(args[n],XtNstring,framedBox_marker->text);n++;
  148. X        XtSetArg(args[n],XtNwidth,500);n++;
  149. X        if (lenn<1+strlen(framedBox_marker->text)) lenn=1+strlen(framedBox_marker->text);
  150. X        XtSetArg(args[n],XtNlength,lenn);n++; 
  151. X        /* warning, this is constant */
  152. X    /* it is a fact, that each of these pointers point to a memory-location, which */
  153. X    /* is at last exactly 80 Bytes big. */
  154. X    /* Well, this is an arbitrary restriction */
  155. X        XtSetArg(args[n],XtNeditType,XawtextEdit);n++;
  156. X        
  157. X    
  158. X        blabla=XtCreateManagedWidget("text", asciiTextWidgetClass, kiste, args, n);
  159. X        XtAddActions(actions, XtNumber(actions));
  160. X        trans_table2 = XtParseTranslationTable(temp_str2);
  161. X        XtOverrideTranslations(blabla, trans_table2);
  162. X
  163. X        /* Store the pointers, used for a delete action */
  164. X        mem[i-ab].tg=toggle;
  165. X        mem[i-ab].obj=(struct fig3 *)framedBox_marker;
  166. X        mem[i-ab+1].tg=NULL;
  167. X        mem[i-ab+1].obj=NULL;
  168. X
  169. X        framedBox_marker=framedBox_marker->next;
  170. X        
  171. X    }
  172. X
  173. X    XtAddActions(actions, XtNumber(actions));
  174. X    
  175. X    
  176. X
  177. X    /* setting position of widget */
  178. X    n = 0;
  179. X    XtSetArg(args[n], XtNx, &x_rel);
  180. X    n++;
  181. X    XtSetArg(args[n], XtNy, &y_rel);
  182. X    n++;
  183. X    XtGetValues(canvas, args, n);    /* get the relative coordinates of
  184. X                     * widget: canvas */
  185. X    XtTranslateCoords(canvas, x_rel, y_rel, &x, &y);
  186. X    n = 0;
  187. X    XtSetArg(args[n], XtNx, x + cmd_btn_width);
  188. X    n++;
  189. X    XtSetArg(args[n], XtNy, y + 2 * cmd_btn_height);
  190. X    n++;
  191. X    XtSetValues(fb_muschel, args, n);
  192. X    /* position set ! */
  193. X
  194. X
  195. X    XtPopupSpringLoaded(fb_muschel);
  196. X
  197. X    
  198. }
  199. X
  200. void fb_correct_text_error()
  201. {
  202. X
  203. X    /* remove special chars from text */
  204. X
  205. X    framedBox_marker=framedBox_start;
  206. X    if (framedBox_marker==NULL) return;
  207. X
  208. X    while (framedBox_marker!=NULL)
  209. X    {
  210. X        transform(framedBox_marker->text);
  211. X        framedBox_marker=framedBox_marker->next;
  212. X    }
  213. X    
  214. X    ab=-9; /* for a new start */
  215. X    
  216. }
  217. X        
  218. void fb_beende_textedit()    
  219. {
  220. X    XtPopdown(fb_muschel);
  221. X    XtDestroyWidget(fb_muschel); /* and its children ! */
  222. }    
  223. X
  224. X
  225. X
  226. void fb_delete_textedit()
  227. {
  228. X    /* perform an erase on the selected (toggled) text */
  229. X
  230. X int i=0; /* counter */
  231. X Boolean offon;
  232. X struct fig3 * three;
  233. X
  234. X    while ( (mem[i].tg!=NULL) && (i<10) )
  235. X    {
  236. X        /* was the toggle active ? */
  237. X        n=0;
  238. X        XtSetArg(args[n],XtNstate,&offon);n++;
  239. X        XtGetValues(mem[i].tg, args, n);
  240. X
  241. X        if (offon==True) /* it was selected - delete text ! */
  242. X        {
  243. X            framedBox_marker = (struct fig3 *)mem[i].obj;
  244. X            if (framedBox_start == mem[i].obj)
  245. X            {    /* first entry */
  246. X                if (framedBox_curr == framedBox_start)
  247. X                {    /* exactly 1 entry */
  248. X
  249. X                    framedBox_start = NULL;
  250. X                    framedBox_curr = NULL;
  251. X
  252. X                } else
  253. X                    framedBox_start = framedBox_start->next;
  254. X
  255. X                free(framedBox_marker);
  256. X            } else
  257. X            {
  258. X                framedBox_marker = framedBox_start;
  259. X                do
  260. X                {
  261. X                    three = (struct fig3 *) framedBox_marker;
  262. X                    /* remember the last object */
  263. X                    framedBox_marker = framedBox_marker->next;
  264. X
  265. X                } while (framedBox_marker != mem[i].obj);
  266. X                /* <framedBox_marker> points to the desired object and */
  267. X                /* <three> to the object before */
  268. X
  269. X                /* last entry ? */
  270. X                if (framedBox_marker == framedBox_curr)
  271. X                {
  272. X                    framedBox_marker = NULL;
  273. X                    free(framedBox_curr);
  274. X                    framedBox_curr = three;
  275. X                    three->next=NULL;
  276. X                } else
  277. X                    /* no! the object was somewhere in the middle */
  278. X                {
  279. X                    three->next = framedBox_marker->next;
  280. X                    free(framedBox_marker);
  281. X                }
  282. X            } /* else */
  283. X        
  284. X
  285. X            
  286. X        } /* if offon */
  287. X
  288. X        i++;
  289. X
  290. X    } /* while */
  291. } /* proc */
  292. X
  293. X
  294. /* ------- */
  295. X
  296. X
  297. int db_number_of_text()
  298. {
  299. X  int i;
  300. X    /* compute number of text-entries */
  301. X    i=1;
  302. X    if (dashedBox_start==NULL) return 0;
  303. X    if (dashedBox_start==dashedBox_curr) return 1;
  304. X    dashedBox_marker=dashedBox_start;
  305. X    do
  306. X    {
  307. X        i++;
  308. X        if (dashedBox_marker!=dashedBox_curr) dashedBox_marker=dashedBox_marker->next;
  309. X    } while (dashedBox_marker!=dashedBox_curr);
  310. X
  311. X    return i;
  312. }
  313. X
  314. X
  315. X
  316. void db_textedit()
  317. {
  318. X  Widget perle;
  319. X  Widget kiste,toggle,blabla;
  320. X  Widget ok,del,more;
  321. X  int i,lenn=81;
  322. X  int anz_text;
  323. X  XtTranslations  trans_table,trans_table2;
  324. X  char          leave_str[100]="<LeaveNotify> : db_beende_textedit() db_correct_text_error()\n";
  325. X  char          ok_str[100]="<ButtonRelease> : db_beende_textedit() db_correct_text_error()\n";
  326. X  char          more_str[100]="<ButtonRelease>    : db_beende_textedit() db_textedit()\n";
  327. X  char          del_str[100]="<ButtonRelease>    : db_delete_textedit() db_beende_textedit() db_textedit()\n";
  328. X
  329. X  char            temp_str2[100] = 
  330. X            "<KeyPress>Return    : dummy() \n";
  331. X  
  332. X  static XtActionsRec actions[200] = {{"dummy", dummy},
  333. X                      {"db_textedit", db_textedit},
  334. X                      {"db_beende_textedit", db_beende_textedit},
  335. X                      {"db_delete_textedit", db_delete_textedit},
  336. X                      {"db_correct_text_error",db_correct_text_error}};
  337. X  Position x_rel, y_rel, x, y;
  338. X    
  339. X
  340. X    db_muschel=XtCreatePopupShell("Edit/Delete", transientShellWidgetClass, canvas, NULL, 0);
  341. X
  342. X    trans_table = XtParseTranslationTable(leave_str);
  343. X    XtOverrideTranslations(db_muschel, trans_table);
  344. X
  345. X    perle=XtCreateManagedWidget("behaelter", boxWidgetClass, db_muschel, NULL, 0);
  346. X    
  347. X    n=0;
  348. X    XtSetArg(args[n], XtNlabel,"Edit Text: DASHED BOX");n++;
  349. X    XtSetArg(args[n], XtNjustify,XtJustifyCenter);n++;
  350. X    XtSetArg(args[n], XtNwidth,560);n++;
  351. X    XtSetArg(args[n], XtNheight,40);n++;
  352. X    
  353. X    XtCreateManagedWidget("", labelWidgetClass, perle, args, n);
  354. X
  355. X
  356. X    n=0;
  357. X    XtSetArg(args[n], XtNlabel,"Accept");n++;
  358. X    XtSetArg(args[n], XtNjustify,XtJustifyCenter);n++;
  359. X    XtSetArg(args[n], XtNwidth,130);n++;
  360. X    XtSetArg(args[n], XtNheight,40);n++;
  361. X    XtSetArg(args[n], XtNshapeStyle,XmuShapeOval);n++;
  362. X    
  363. X    ok=XtCreateManagedWidget("ok", commandWidgetClass, perle, args, n);
  364. X    trans_table = XtParseTranslationTable(ok_str);
  365. X    XtOverrideTranslations(ok, trans_table);
  366. X
  367. X
  368. X    /* compute number of text-entries */
  369. X    anz_text=db_number_of_text();
  370. X
  371. X    if (anz_text==0)
  372. X    {
  373. X        leave_pick("Sorry - No text available !\n");
  374. X        return;
  375. X    }    
  376. X
  377. X
  378. X    if (anz_text>10)
  379. X    {
  380. X        n=0;
  381. X        XtSetArg(args[n], XtNlabel,"More");n++;
  382. X        XtSetArg(args[n], XtNjustify,XtJustifyCenter);n++;
  383. X        XtSetArg(args[n], XtNwidth,130);n++;
  384. X        XtSetArg(args[n], XtNheight,40);n++;
  385. X        XtSetArg(args[n], XtNshapeStyle, XmuShapeOval);n++;
  386. X        
  387. X        more=XtCreateManagedWidget("more", commandWidgetClass, perle, args, n);
  388. X        trans_table = XtParseTranslationTable(more_str);
  389. X        XtOverrideTranslations(more, trans_table);
  390. X    }
  391. X
  392. X
  393. X    n=0;
  394. X    XtSetArg(args[n], XtNlabel,"Delete");n++;
  395. X    XtSetArg(args[n], XtNjustify,XtJustifyCenter);n++;
  396. X    XtSetArg(args[n], XtNwidth,130);n++;
  397. X    XtSetArg(args[n], XtNheight,40);n++;
  398. X    XtSetArg(args[n], XtNshapeStyle,XmuShapeOval);n++;
  399. X    
  400. X    del=XtCreateManagedWidget("del", commandWidgetClass, perle, args, n);
  401. X    trans_table = XtParseTranslationTable(del_str);
  402. X    XtOverrideTranslations(del, trans_table);
  403. X    
  404. X    
  405. X    if (ab>anz_text) ab=-9;
  406. X    ab+=10; /* ab was initially -9 */
  407. X    if (ab>anz_text) ab=1;
  408. X
  409. X    /* dashedBox_marker must point to the "ab"th text! */
  410. X
  411. X    dashedBox_marker=dashedBox_start;
  412. X    for (i=2; i<=ab; i++) dashedBox_marker=dashedBox_marker->next;
  413. X
  414. X    for (i=ab; ( (i<=anz_text) && (i-ab<10) ); i++)
  415. X    {
  416. X        n=0;
  417. X        XtSetArg(args[n],XtNorientation,XtorientHorizontal);n++;
  418. X        XtSetArg(args[n],XtNborderWidth,0);n++;
  419. X        kiste=XtCreateManagedWidget("drin", boxWidgetClass, perle, args, n);
  420. X        n=0;
  421. X        XtSetArg(args[n],XtNstate,False);n++;
  422. X        XtSetArg(args[n],XtNheight,20);n++;
  423. X        XtSetArg(args[n],XtNwidth,20);n++;
  424. X        XtSetArg(args[n],XtNshapeStyle,XmuShapeOval);n++;
  425. X        toggle=XtCreateManagedWidget("!", toggleWidgetClass, kiste, args, n);
  426. X        n=0;
  427. X        XtSetArg(args[n],XtNuseStringInPlace,True);n++;
  428. X        XtSetArg(args[n],XtNstring,dashedBox_marker->text);n++;
  429. X        XtSetArg(args[n],XtNwidth,500);n++;
  430. X        if (lenn<1+strlen(dashedBox_marker->text)) lenn=1+strlen(dashedBox_marker->text);
  431. X        XtSetArg(args[n],XtNlength,lenn);n++; 
  432. X        /* warning, this is constant */
  433. X    /* it is a fact, that each of these pointers point to a memory-location, which */
  434. X    /* is at last exactly 80 Bytes big. */
  435. X    /* Well, this is an arbitrary restriction */
  436. X        XtSetArg(args[n],XtNeditType,XawtextEdit);n++;
  437. X        
  438. X    
  439. X        blabla=XtCreateManagedWidget("text", asciiTextWidgetClass, kiste, args, n);
  440. X        XtAddActions(actions, XtNumber(actions));
  441. X        trans_table2 = XtParseTranslationTable(temp_str2);
  442. X        XtOverrideTranslations(blabla, trans_table2);
  443. X
  444. X        /* Store the pointers, used for a delete action */
  445. X        mem[i-ab].tg=toggle;
  446. X        mem[i-ab].obj=(struct fig4 *)dashedBox_marker;
  447. X        mem[i-ab+1].tg=NULL;
  448. X        mem[i-ab+1].obj=NULL;
  449. X
  450. X        dashedBox_marker=dashedBox_marker->next;
  451. X        
  452. X    }
  453. X
  454. X    XtAddActions(actions, XtNumber(actions));
  455. X    
  456. X    
  457. X
  458. X    /* setting position of widget */
  459. X    n = 0;
  460. X    XtSetArg(args[n], XtNx, &x_rel);
  461. X    n++;
  462. X    XtSetArg(args[n], XtNy, &y_rel);
  463. X    n++;
  464. X    XtGetValues(canvas, args, n);    /* get the relative coordinates of
  465. X                     * widget: canvas */
  466. X    XtTranslateCoords(canvas, x_rel, y_rel, &x, &y);
  467. X    n = 0;
  468. X    XtSetArg(args[n], XtNx, x + cmd_btn_width);
  469. X    n++;
  470. X    XtSetArg(args[n], XtNy, y + 2 * cmd_btn_height);
  471. X    n++;
  472. X    XtSetValues(db_muschel, args, n);
  473. X    /* position set ! */
  474. X
  475. X
  476. X    XtPopupSpringLoaded(db_muschel);
  477. X
  478. X    
  479. }
  480. X
  481. void db_correct_text_error()
  482. {
  483. X
  484. X    /* remove special chars from text */
  485. X
  486. X    dashedBox_marker=dashedBox_start;
  487. X    if (dashedBox_marker==NULL) return;
  488. X
  489. X    while (dashedBox_marker!=NULL)
  490. X    {
  491. X        transform(dashedBox_marker->text);
  492. X        dashedBox_marker=dashedBox_marker->next;
  493. X    }
  494. X    
  495. X    ab=-9; /* for a new start */
  496. X    
  497. }
  498. X        
  499. void db_beende_textedit()    
  500. {
  501. X    XtPopdown(db_muschel);
  502. X    XtDestroyWidget(db_muschel); /* and its children ! */
  503. }    
  504. X
  505. X
  506. X
  507. void db_delete_textedit()
  508. {
  509. X    /* perform an erase on the selected (toggled) text */
  510. X
  511. X int i=0; /* counter */
  512. X Boolean offon;
  513. X struct fig4 * four;
  514. X
  515. X    while ( (mem[i].tg!=NULL) && (i<10) )
  516. X    {
  517. X        /* was the toggle active ? */
  518. X        n=0;
  519. X        XtSetArg(args[n],XtNstate,&offon);n++;
  520. X        XtGetValues(mem[i].tg, args, n);
  521. X
  522. X        if (offon==True) /* it was selected - delete text ! */
  523. X        {
  524. X            dashedBox_marker = (struct fig4 *)mem[i].obj;
  525. X            if (dashedBox_start == mem[i].obj)
  526. X            {    /* first entry */
  527. X                if (dashedBox_curr == dashedBox_start)
  528. X                {    /* exactly 1 entry */
  529. X
  530. X                    dashedBox_start = NULL;
  531. X                    dashedBox_curr = NULL;
  532. X
  533. X                } else
  534. X                    dashedBox_start = dashedBox_start->next;
  535. X
  536. X                free(dashedBox_marker);
  537. X            } else
  538. X            {
  539. X                dashedBox_marker = dashedBox_start;
  540. X                do
  541. X                {
  542. X                    four = (struct fig4 *) dashedBox_marker;
  543. X                    /* remember the last object */
  544. X                    dashedBox_marker = dashedBox_marker->next;
  545. X
  546. X                } while (dashedBox_marker != mem[i].obj);
  547. X                /* <dashedBox_marker> points to the desired object and */
  548. X                /* <four> to the object before */
  549. X
  550. X                /* last entry ? */
  551. X                if (dashedBox_marker == dashedBox_curr)
  552. X                {
  553. X                    dashedBox_marker = NULL;
  554. X                    free(dashedBox_curr);
  555. X                    dashedBox_curr = four;
  556. X                    four->next=NULL;
  557. X                } else
  558. X                    /* no! the object was somewhere in the middle */
  559. X                {
  560. X                    four->next = dashedBox_marker->next;
  561. X                    free(dashedBox_marker);
  562. X                }
  563. X            } /* else */
  564. X        
  565. X
  566. X            
  567. X        } /* if offon */
  568. X
  569. X        i++;
  570. X
  571. X    } /* while */
  572. } /* proc */
  573. X
  574. X
  575. X
  576. void move_base(Widget cmd, char typ, caddr_t call_data)
  577. {
  578. X int xsteps = 10;
  579. X int ysteps = 10;
  580. X FILE *fd; /* dummy */
  581. X int             btn1 = 256, btn2 = 512, btn3 = 1024;
  582. X unsigned int mask;
  583. X int x,y;
  584. X  do 
  585. X  {
  586. X     /* global */
  587. X     xmotion=0;
  588. X     ymotion=0;
  589. X     
  590. X     /* resetting values, global */
  591. X     dim_x_max = -99999.0;
  592. X    dim_x_min = 99999.0;
  593. X    dim_y_max = -99999.0;
  594. X    dim_y_min = 99999.0;
  595. X    switch (typ)
  596. X    {
  597. X        case 'U':    ymotion=ysteps;
  598. X                break;
  599. X        case 'D':    ymotion=-ysteps;
  600. X                break;
  601. X        case 'L':    xmotion=xsteps;
  602. X                break;
  603. X        case 'R':    xmotion=-xsteps;
  604. X                break;
  605. X        default:     /* compute the dimension of the image */
  606. X                /* this is the center image function */
  607. X                manage_line(0, fd);
  608. X                manage_vector(0, fd);
  609. X                manage_filled(0, fd);
  610. X                manage_framed(0, fd);
  611. X                manage_dashed(0, fd);
  612. X                manage_kreis(0, fd);
  613. X                manage_disc(0, fd);
  614. X                manage_oval(0, fd);
  615. X                manage_text(0, fd);
  616. X                manage_bezier(0, fd);
  617. X                /* dimensions are set ! */
  618. X                
  619. X                /* compute the move steps */
  620. X                xmotion=(x_A4_max-dim_x_max+dim_x_min)/2;
  621. X                ymotion=(y_A4_max-dim_y_max+dim_y_min)/2;
  622. X                xmotion=xmotion-dim_x_min;
  623. X                ymotion=ymotion-dim_y_min;
  624. X                break;
  625. X    } /* eoswitch */
  626. X    
  627. X    /* move the objects now */
  628. X    
  629. X    manage_line(2, fd);
  630. X    manage_vector(2, fd);
  631. X    manage_filled(2, fd);
  632. X    manage_framed(2, fd);
  633. X    manage_dashed(2, fd);
  634. X    manage_kreis(2, fd);
  635. X    manage_disc(2, fd);
  636. X    manage_oval(2, fd);
  637. X    manage_text(2, fd);
  638. X    manage_bezier(2, fd);
  639. X
  640. X    /* redraw screen by refresh */
  641. X    refresh((Widget)DUMMY, '?', (caddr_t)DUMMY);    /* force refresh */
  642. X
  643. X    
  644. X    PointerPosition(&x,&y,&mask);
  645. X    
  646. X    
  647. X    
  648. X
  649. X
  650. X   } while ( ((mask&btn1) || (mask&btn2) || (mask&btn3)) && (typ!='Z') );
  651. X    
  652. }
  653. X
  654. X
  655. X
  656. X
  657. X
  658. X
  659. void DrawBezier(float ax, float ay, float ex, float ey, float sx, float sy)
  660. {
  661. X /* ax,ay,ex,ey are expected to be always in real coordinate system */
  662. X /* sx,sy depends on variable 'zoomed' !!! : if (zoomed==True), sx,sy are */
  663. X /* expected to be zoomed coordinates */
  664. X    float u=0;
  665. X    Display *disp=XtDisplay(pboard);
  666. X    Window win=XtWindow(pboard);
  667. X    float x,y,x_old,y_old;
  668. X    float steps=0.04;
  669. X    
  670. X  if (zoomed==True)
  671. X  {
  672. X    real2zoomed(&ax,&ay);
  673. X    real2zoomed(&ex,&ey);
  674. X  } 
  675. X
  676. X  /* draw from u=0, the first point of the curve (that is ax,ay) */
  677. X  x_old=ax;
  678. X  y_old=ay;
  679. X
  680. X  do
  681. X  {
  682. X        u+=steps;
  683. X
  684. X        x=ax*(1-u)*(1-u)+sx*(1-u)*2*u+ex*u*u;
  685. X        y=ay*(1-u)*(1-u)+sy*(1-u)*2*u+ey*u*u;
  686. X        
  687. X        XDrawLine(disp,win,gc,(int)x_old,(int)y_old,(int)x,(int)y);
  688. X
  689. X        x_old=x;
  690. X        y_old=y;
  691. X  } while (u<1-steps);
  692. X
  693. X  /* draw to u=1, the last point of the curve (that is ex,ey) */
  694. X  XDrawLine(disp,win,gc,(int)x_old,(int)y_old,(int)ex,(int)ey);
  695. X  
  696. }
  697. X
  698. X
  699. void set_lastBezier_press()
  700. {
  701. X    /* Override Translation Manager */
  702. X    XtTranslations  trans_table;
  703. X    char            destination[200] = "<Btn1Down>: entry_bezier()\n\
  704. X                       <Btn2Down>: cancel_curve()\n\
  705. X                       <Btn3Down>: cancel_curve()\n\
  706. X                       <LeaveNotify>:exit_curve()";
  707. X    char            destination2[80] = "<MotionNotify>: manage_curve()";
  708. X    static XtActionsRec actions[80] = {{"manage_curve", manage_curve},
  709. X                       {"entry_bezier", entry_bezier},
  710. X                       {"cancel_curve", cancel_curve},
  711. X                       {"exit_curve", exit_curve}
  712. X                      };
  713. X
  714. X    XtAddActions(actions, XtNumber(actions));
  715. X
  716. X    trans_table = XtParseTranslationTable(destination);
  717. X    XtOverrideTranslations(pboard, trans_table);
  718. X
  719. X    trans_table = XtParseTranslationTable(destination2);
  720. X    XtOverrideTranslations(pboard, trans_table);
  721. }
  722. X
  723. X
  724. void manage_curve()
  725. {
  726. X /* controlling the curve */
  727. X
  728. X unsigned int mask;
  729. X int x,y;
  730. X
  731. X
  732. X    snapPointerPosition(&x,&y,&mask);
  733. X
  734. X    if ( (x!=(int)bezier_curr->sx) || (y!=(int)bezier_curr->sy) ) /* redraw necessary */
  735. X    {
  736. X    /* delete old curve, if exists */
  737. X    if (bezier_curr->sx!=-999.0) /* ax,ay,ex,ey are in real coordinate system */
  738. X        DrawBezier(bezier_curr->ax,bezier_curr->ay,
  739. X               bezier_curr->ex,bezier_curr->ey,
  740. X               bezier_curr->sx,bezier_curr->sy);
  741. X
  742. X    bezier_curr->sx=(float)x;
  743. X    bezier_curr->sy=(float)y;
  744. X
  745. X    /* draw the curve */
  746. X    DrawBezier(bezier_curr->ax,bezier_curr->ay,
  747. X        bezier_curr->ex,bezier_curr->ey,
  748. X        bezier_curr->sx,bezier_curr->sy);
  749. X    }
  750. }
  751. X
  752. void entry_bezier()
  753. {
  754. X    if (bezier_curr->sx==-999.0) return; /* MotionNotify first, please */
  755. X    XtUninstallTranslations(pboard);
  756. X    if (zoomed==True) zoomed2real(&bezier_curr->sx,&bezier_curr->sy);
  757. X    set_first(); /* for the next curve */
  758. }
  759. X    
  760. X
  761. void cancel_curve()
  762. {
  763. X /* btn3 or btn2 was pressed */
  764. X
  765. X    if (bezier_curr->sx!=-999.0) /* delete curve */
  766. X        DrawBezier(bezier_curr->ax,bezier_curr->ay,
  767. X               bezier_curr->ex,bezier_curr->ey,
  768. X               bezier_curr->sx,bezier_curr->sy);
  769. X    
  770. X    XDrawLine(XtDisplay(pboard),XtWindow(pboard),gc,
  771. X        (int)bezier_curr->ax,(int)bezier_curr->ay,(int)bezier_curr->ex,(int)bezier_curr->ey);    
  772. X    newline();
  773. }
  774. X
  775. void exit_curve()
  776. {
  777. X    cancel_curve();
  778. X    XtUninstallTranslations(pboard);
  779. X    graph_action='?';
  780. X    headline(pboard,titlename);
  781. X    
  782. }
  783. X
  784. X
  785. X
  786. X
  787. X
  788. X
  789. X
  790. X
  791. X
  792. SHAR_EOF
  793. echo 'File graphics.c is complete' &&
  794. chmod 0644 graphics.c ||
  795. echo 'restore of graphics.c failed'
  796. Wc_c="`wc -c < 'graphics.c'`"
  797. test 134559 -eq "$Wc_c" ||
  798.     echo 'graphics.c: original size 134559, current size' "$Wc_c"
  799. rm -f _shar_wnt_.tmp
  800. fi
  801. # ============= graphics.h ==============
  802. if test -f 'graphics.h' -a X"$1" != X"-c"; then
  803.     echo 'x - skipping graphics.h (File already exists)'
  804.     rm -f _shar_wnt_.tmp
  805. else
  806. > _shar_wnt_.tmp
  807. echo 'x - extracting graphics.h (Text)'
  808. sed 's/^X//' << 'SHAR_EOF' > 'graphics.h' &&
  809. /* xtexcad  V1.2 - graphic editor for LaTeX */
  810. /* 1991 by K.Zitzmann */
  811. /* header-file graphics.h */
  812. X
  813. #ifndef GRAPHICSH
  814. #define GRAPHICSH
  815. X
  816. X
  817. /* patch for Data General by JM , all patches by JM are marked with JM ! */
  818. extern int black_white_patch;
  819. X
  820. X
  821. /* prototypes */
  822. X
  823. void shorten(int *x, int *y);
  824. void make_GCcontext(void);
  825. void PointerPosition(int *x, int *y, unsigned int *mask);
  826. void set_TM_btn1_first(Widget w, XEvent *event, String *id, Cardinal *num); 
  827. void btn1_press_first(Widget w, XEvent *event, String *id, Cardinal *num);
  828. void set_TM_btn1_second(void);
  829. void btn1_press_second(Widget w, XEvent *event, String *id, Cardinal *num);
  830. void set_first(void);
  831. void enable_tracker(void);
  832. void disable_tracker(void);
  833. void track_it(int *xo, int *yo);
  834. void dummy(void);
  835. void leaving(void);
  836. void zoomed2real(float *x, float *y);
  837. void real2zoomed(float *x, float *y);
  838. int ggt(int a, int b);
  839. int valid_line_coords(int x_or, int y_or, int *x_ret, int *y_ret);
  840. int valid_vector_coords(int x_or, int y_or, int *x_ret, int *y_ret);
  841. void init_l_slope(void);
  842. void l_insert(float value, int x, int y);
  843. void init_a_slope(void);
  844. void a_insert(float value, int x, int y);
  845. void graphics_init(void);
  846. void left(void);
  847. void set_zoom_window(void);
  848. void frame_track(int *x0, int *y0);
  849. void zoom_it(void);
  850. void clear_zoom(void);
  851. void cancel_zoom(void);
  852. int sorry_msg(void);
  853. void refresh(Widget cmd, char id, caddr_t call_data);
  854. void init_prompt_text();
  855. void cancel_text();
  856. void ok_text();
  857. void manage_text_input();
  858. void show_zoomed_objects();
  859. void set_text_input();
  860. void valid_length(int x_or, int y_or, int *x_ret, int *y_ret);
  861. void draw_vector_marker(float a1, float a2, float e1, float e2);
  862. void norm_rectangle(float *x, float *y, float *h, float *v);
  863. void init_text_and_position(void);
  864. void box_text(Widget cmd, char id, caddr_t call_data);
  865. void query_box_text_and_position(void);
  866. void print_box_text(char *a,float b, float c, float d, float e, char *f);
  867. void valid_kreis_coords(int x, int y, int *h, int *v,int *rad);
  868. void valid_disc_coords(int x, int y, int *h, int *v,int *rad);
  869. void DrawOval(int x_old,int y_old,int h_old,int v_old);
  870. void query_ask_erase(void);
  871. void perform_erase(void);
  872. void init_ask_erase(void);
  873. void valid_snap_coords(int *x, int *y);
  874. void snapPointerPosition(int *x, int *y, unsigned int *mask);
  875. void draw_the_shadow(void *object,char id);
  876. void init_text_adjustment(void);
  877. void adjust_text(Widget cmd, char id, caddr_t call_data);
  878. void query_text_adjustment(void);
  879. void newline(void);
  880. void print_head(char ch);
  881. void leave_translation(void);
  882. void textedit(void);
  883. int number_of_text(void);
  884. void correct_text_error(void);
  885. void beende_textedit(void);    
  886. void fb_textedit(void);
  887. int fb_number_of_text(void);
  888. void fb_correct_text_error(void);
  889. void fb_beende_textedit(void);    
  890. void fb_delete_textedit(void);
  891. void db_textedit(void);
  892. int db_number_of_text(void);
  893. void db_correct_text_error(void);
  894. void db_beende_textedit(void);    
  895. void db_delete_textedit(void);
  896. void print_text_text_marker(char *pos, float x, float y, char *txt);
  897. void delete_textedit(void);
  898. void move_base(Widget cmd, char typ, caddr_t call_data);
  899. void manage_curve();
  900. void entry_bezier();
  901. void DrawBezier(float ax, float ay, float ex, float ey, float sx, float sy);
  902. void set_lastBezier_press(void);
  903. void cancel_curve(void);
  904. void exit_curve();
  905. X
  906. X
  907. X
  908. X
  909. extern int line_slope;
  910. extern int slope_line;
  911. extern int arrow_slope;
  912. extern int slope_arrow;
  913. extern int line_length;
  914. extern int circle_diameter[];
  915. extern int disc_diameter[];
  916. extern int rast_height;
  917. extern Boolean visible;
  918. X
  919. #endif
  920. SHAR_EOF
  921. chmod 0644 graphics.h ||
  922. echo 'restore of graphics.h failed'
  923. Wc_c="`wc -c < 'graphics.h'`"
  924. test 3541 -eq "$Wc_c" ||
  925.     echo 'graphics.h: original size 3541, current size' "$Wc_c"
  926. rm -f _shar_wnt_.tmp
  927. fi
  928. # ============= io_trans.c ==============
  929. if test -f 'io_trans.c' -a X"$1" != X"-c"; then
  930.     echo 'x - skipping io_trans.c (File already exists)'
  931.     rm -f _shar_wnt_.tmp
  932. else
  933. > _shar_wnt_.tmp
  934. echo 'x - extracting io_trans.c (Text)'
  935. sed 's/^X//' << 'SHAR_EOF' > 'io_trans.c' &&
  936. /* xtexcad  V1.2 - graphic editor for LaTeX */
  937. /* 1991 by K.Zitzmann */
  938. /* io_trans.c */
  939. X
  940. X
  941. #include "x_stuff.h"
  942. #include "oberfl.h"
  943. #include "graphics.h"/* xtexcad  V1.1 - graphic editor for LaTeX */
  944. /* 1991 by K.Zitzmann */
  945. /* io_trans.c */
  946. X
  947. X
  948. #include "x_stuff.h"
  949. #include "oberfl.h"
  950. #include "graphics.h"
  951. #include "io_trans.h"
  952. #include "yyscan.h"
  953. X
  954. X
  955. float    dim_x_max = -99999.0, dim_x_min = 99999.0, dim_y_max = -99999.0, dim_y_min = 99999.0;
  956. X
  957. static struct object_buffer
  958. {
  959. X    float           xpos, ypos, hpos, vpos, dash_length;
  960. X    float        sxpos,sypos; /* for curves only ! */
  961. X    char            text[256];    /* that should be enough !!! */
  962. X    char            textpos[2];
  963. X    int             radius;
  964. }               buffer;    /* the buffer struct - used while scanning
  965. X             * LaTeX-sources */
  966. X
  967. X
  968. int      unit = 1;    /* 1=pt 2=cm 3=mm 4=pc 5=in */
  969. float    ulen = 1.0;    /* unitlength */
  970. X
  971. X
  972. X
  973. X
  974. Boolean
  975. file_exists(char *fn)
  976. {
  977. X    FILE           *fd;
  978. X    Boolean         res;
  979. X    if ((fd = fopen(fn, "r")) == NULL)
  980. X        res = False;
  981. X    else
  982. X    {
  983. X        res = True;
  984. X        fclose(fd);
  985. X    }
  986. X    return res;
  987. }
  988. X
  989. X
  990. X
  991. void
  992. error(char *name)
  993. {/* prints error messages to report window */
  994. X
  995. X    fprintf(stderr, "while scanning: ");
  996. X    fprintf(stderr, "%s", name);
  997. X    fprintf(stderr, "......skipping to next known token !\n");
  998. X
  999. }
  1000. X
  1001. X
  1002. X
  1003. X
  1004. void
  1005. load_it(char *fn)
  1006. /* opening, creating, error handling, etc. */
  1007. /* be sure, database is empty, all memory is given back */
  1008. {
  1009. X    FILE           *fd;
  1010. X    int             t;    /* token */
  1011. X    float           c;
  1012. X    int         store_unit;
  1013. X
  1014. X    if (file_exists(fn) == False)
  1015. X    {
  1016. X        leave_pick("ERROR - file not found.");
  1017. X        return;
  1018. X    }
  1019. X    /* open file */
  1020. X    fd = fopen(fn, "r");
  1021. X    /* file pointer points to the beginning of this file */
  1022. X
  1023. X    /* scan it ! */
  1024. X
  1025. X    yyinitscan(fd); /* init scanner */
  1026. X
  1027. X    t = TOK_BEGIN;    /* now a dummy */
  1028. X    while (t != TOK_END)
  1029. X    {
  1030. X
  1031. X        buffer.textpos[0] = 'c';
  1032. X        buffer.textpos[1] = 'c';
  1033. X
  1034. X        switch (t = yylex())
  1035. X        {
  1036. X
  1037. X        case TOK_BEGIN:
  1038. X            if ((t = yylex()) == TOK_FLOAT)
  1039. X            {    /* the x dimension; not used ! */
  1040. X                if ((t = yylex()) == TOK_FLOAT)
  1041. X                {    /* the y-dimension; not used */
  1042. X                    if ((t = yylex()) == TOK_FLOAT)
  1043. X                    {    /* optional: reference
  1044. X                         * x-coordinate */
  1045. X                        xur = yyfloatval;
  1046. X                        if ((t = yylex()) == TOK_FLOAT)
  1047. X                        {    /* optional: reference
  1048. X                             * y-coordinate */
  1049. X                            yur = yyfloatval;
  1050. X                            break;
  1051. X                        } else
  1052. X                            error("missing y-coordinate !\n");
  1053. X                    }
  1054. X                } else
  1055. X                    error("missing y-dimension !\n");
  1056. X            } else
  1057. X                error("float/int expected (dimension)!\n");
  1058. X
  1059. X        case TOK_PUT:
  1060. X            if ((t = yylex()) == TOK_FLOAT)
  1061. X            {
  1062. X                buffer.xpos = yyfloatval;
  1063. X                if ((t = yylex()) == TOK_FLOAT)
  1064. X                {
  1065. X                    buffer.ypos = yyfloatval;
  1066. X                    break;
  1067. X                } else
  1068. X                    error("missing y-coordinate of PUT-command.\n");
  1069. X            } else
  1070. X                error("missing x-coordinate of PUT-command.\n");
  1071. X
  1072. X        case TOK_TEXT:
  1073. X            strcpy(buffer.text, yystrval);
  1074. X            buffer.textpos[1] = 'b';
  1075. X            buffer.textpos[1] = 'l';
  1076. X            read_message();
  1077. X            break;
  1078. X
  1079. X        case TOK_FRAMEBOX:
  1080. X            if ((t = yylex()) == TOK_FLOAT)
  1081. X            {
  1082. X                buffer.hpos = yyfloatval;
  1083. X                if ((t = yylex()) == TOK_FLOAT)
  1084. X                {
  1085. X                    buffer.vpos = yyfloatval;
  1086. X                    if ((t = yylex()) == TOK_LETTERS_OPT)
  1087. X                    {
  1088. X                        buffer.textpos[0] = yystrval[0];
  1089. X                        buffer.textpos[1] = yystrval[1];
  1090. X                    } else
  1091. X                    {
  1092. X                        buffer.textpos[0] = 'c';
  1093. X                        buffer.textpos[1] = 'c';
  1094. X                    }
  1095. X                    if ((t = yylex()) == TOK_TEXT)
  1096. X                    {
  1097. X                        strcpy(buffer.text, yystrval);
  1098. X                        read_framebox();
  1099. X                        break;
  1100. X                    } else
  1101. X                        error("text expected...\n");
  1102. X                } else
  1103. X                    error("height of framebox not found.\n");
  1104. X            } else
  1105. X                error("width of framebox not found.\n");
  1106. X
  1107. X        case TOK_MAKEBOX:
  1108. X            if ((t = yylex()) == TOK_FLOAT)
  1109. X            {
  1110. X                buffer.hpos = yyfloatval;    /* dummy; not used here */
  1111. X                if ((t = yylex()) == TOK_FLOAT)
  1112. X                {
  1113. X                    buffer.vpos = yyfloatval;    /* dummy; not used here */
  1114. X                    if ((t = yylex()) == TOK_LETTERS_OPT)
  1115. X                    {
  1116. X                        buffer.textpos[0] = yystrval[0];
  1117. X                        buffer.textpos[1] = yystrval[1];
  1118. X                    } else
  1119. X                    {
  1120. X                        buffer.textpos[0] = 'c';
  1121. X                        buffer.textpos[1] = 'c';
  1122. X                    }
  1123. X                    if ((t = yylex()) == TOK_TEXT)
  1124. X                    {
  1125. X                        strcpy(buffer.text, yystrval);
  1126. X                        read_message();
  1127. X                        break;
  1128. X                    } else
  1129. X                        error("text expected...\n");
  1130. X                } else
  1131. X                    error("height of box not found.\n");
  1132. X            } else
  1133. X                error("width of box not found.\n");
  1134. X
  1135. X        case TOK_DASHBOX:
  1136. X            if ((t = yylex()) == TOK_FLOAT)
  1137. X            {    /* read dash-length */
  1138. X                buffer.dash_length = yyfloatval;
  1139. X            } else
  1140. X                error("missing dashlength...\n");
  1141. X            if ((t = yylex()) == TOK_FLOAT)
  1142. X            {
  1143. X                buffer.hpos = yyfloatval;
  1144. X                if ((t = yylex()) == TOK_FLOAT)
  1145. X                {
  1146. X                    buffer.vpos = yyfloatval;
  1147. X                    if ((t = yylex()) == TOK_LETTERS_OPT)
  1148. X                    {
  1149. X                        buffer.textpos[0] = yystrval[0];
  1150. X                        buffer.textpos[1] = yystrval[1];
  1151. X                    } else
  1152. X                    {
  1153. X                        buffer.textpos[0] = 'c';
  1154. X                        buffer.textpos[1] = 'c';
  1155. X                    }
  1156. X                    if ((t = yylex()) == TOK_TEXT)
  1157. X                    {
  1158. X                        strcpy(buffer.text, yystrval);
  1159. X                        read_dashbox();
  1160. X                        break;
  1161. X                    } else
  1162. X                        error("dashbox: text expected...\n");
  1163. X                } else
  1164. X                    error("height of dashbox not found.\n");
  1165. X            } else
  1166. X                error("width of dashbox not found.\n");
  1167. X
  1168. X
  1169. X        case TOK_LINE:
  1170. X            if ((t = yylex()) == TOK_FLOAT)
  1171. X            {
  1172. X                buffer.hpos = yyfloatval;
  1173. X                if ((t = yylex()) == TOK_FLOAT)
  1174. X                {
  1175. X                    buffer.vpos = yyfloatval;
  1176. X                    if ((t = yylex()) == TOK_FLOAT)
  1177. X                    {
  1178. X                        buffer.dash_length = yyfloatval;    /* line length !!! */
  1179. X                        read_line();
  1180. X                        break;
  1181. X                    } else
  1182. X                        error("length of line not specified...\n");
  1183. X                } else
  1184. X                    error("line slope error (denominator) !\n");
  1185. X            } else
  1186. X                error("line slope error (nominator) !\n");
  1187. X
  1188. X        case TOK_VECTOR:
  1189. X            if ((t = yylex()) == TOK_FLOAT)
  1190. X            {
  1191. X                buffer.hpos = yyfloatval;
  1192. X                if ((t = yylex()) == TOK_FLOAT)
  1193. X                {
  1194. X                    buffer.vpos = yyfloatval;
  1195. X                    if ((t = yylex()) == TOK_FLOAT)
  1196. X                    {
  1197. X                        buffer.dash_length = yyfloatval;    /* vector length !!! */
  1198. X                        read_vector();
  1199. X                        break;
  1200. X                    } else
  1201. X                        error("length of vector not specified...\n");
  1202. X                } else
  1203. X                    error("vector slope error (denominator) !\n");
  1204. X            } else
  1205. X                error("vector slope error (nominator) !\n");
  1206. X
  1207. X        case TOK_CIRCLE:
  1208. X            if ((t = yylex()) == TOK_FLOAT)
  1209. X            {
  1210. X                buffer.radius = (int) yyfloatval;
  1211. X                read_circle();
  1212. X                break;
  1213. X            } else
  1214. X                error("missing circle diameter.\n");
  1215. X
  1216. X        case TOK_CIRCLE_AST:
  1217. X            if ((t = yylex()) == TOK_FLOAT)
  1218. X            {
  1219. X                buffer.radius = (int) yyfloatval;
  1220. X                read_disc();
  1221. X                break;
  1222. X            } else
  1223. X                error("missing (filled) circle diameter.\n");
  1224. X
  1225. X        case TOK_OVAL:
  1226. X            if ((t = yylex()) == TOK_FLOAT)
  1227. X            {
  1228. X                buffer.hpos = yyfloatval;
  1229. X                if ((t = yylex()) == TOK_FLOAT)
  1230. X                {
  1231. X                    buffer.vpos = yyfloatval;
  1232. X                    read_oval();
  1233. X                    break;
  1234. X                } else
  1235. X                    error("height of oval not found.\n");
  1236. X            } else
  1237. X                error("width of oval not found.\n");
  1238. X
  1239. X        case TOK_RULE: /* werte werden direkt im richtigen masstab gespeichert... */
  1240. X            if ((t = yylex()) == TOK_FLOAT)
  1241. X            {
  1242. X              buffer.hpos = yyfloatval;
  1243. X              t=yylex(); /* entweder es kommt eine einheit oder "unitlength" */
  1244. X              if (t!=TOK_DIM_UNITLENGTH) /* 1=pt 2=cm 3=mm 4=pc 5=in */
  1245. X              {
  1246. X                store_unit=unit;
  1247. X                switch (t){
  1248. X                 case TOK_DIM_PT  :    unit=1;  
  1249. X                             break;     
  1250. X                 case TOK_DIM_CM  : unit=2;
  1251. X                             break;     
  1252. X                 case TOK_DIM_MM  : unit=3;
  1253. X                             break; 
  1254. X                 case TOK_DIM_PC  : unit=4;
  1255. X                             break;    
  1256. X                 case TOK_DIM_IN  : unit=5;
  1257. X                             break;
  1258. X                 default:error("See LaTeX manual for proper use of the rule command...\n");
  1259. X                          break;
  1260. X                 } /* switch */   
  1261. X                 buffer.hpos=compute_length(buffer.hpos); 
  1262. X                 unit=store_unit;
  1263. X              } else buffer.hpos=compute_length(buffer.hpos); 
  1264. X    
  1265. X                if ((t = yylex()) == TOK_FLOAT)
  1266. X                {
  1267. X                    buffer.vpos = yyfloatval;
  1268. X                    t=yylex(); /* s.o. */
  1269. X                    if (t!=TOK_DIM_UNITLENGTH) /* 1=pt 2=cm 3=mm 4=pc 5=in */
  1270. X                    {
  1271. X                        store_unit=unit;
  1272. X                        switch (t){
  1273. X                        case TOK_DIM_PT  :    unit=1;  
  1274. X                                         break;     
  1275. X                             case TOK_DIM_CM  :     unit=2;
  1276. X                                         break;     
  1277. X                             case TOK_DIM_MM  :     unit=3;
  1278. X                                         break; 
  1279. X                             case TOK_DIM_PC  :     unit=4;
  1280. X                                         break;    
  1281. X                             case TOK_DIM_IN  :     unit=5;
  1282. X                                         break;
  1283. X                             default:error("See LaTeX manual for proper use of the rule command...\n");
  1284. X                                     break;
  1285. X                             } /* switch */ 
  1286. X                             buffer.vpos=compute_length(buffer.vpos);
  1287. X                             unit=store_unit;  
  1288. X                    } else buffer.vpos=compute_length(buffer.vpos); 
  1289. X                    
  1290. X                        
  1291. X                            read_filledbox(); /* .hpos und .vpos sind bereits im richtigen format */
  1292. X                            break; /* switch,case global */
  1293. X                            
  1294. X                
  1295. X                } else
  1296. X                    error("height of filled box (rule) not found.\n");
  1297. X            } else
  1298. X                error("width of filled Box (rule) not found.\n");
  1299. X
  1300. X        case TOK_BEZIER:
  1301. X            if ((t = yylex()) == TOK_FLOAT) buffer.dash_length=yyfloatval;
  1302. X            /* the number of points, the curve consists of, is stored in <dash_length> */
  1303. X            /* no further use ! */
  1304. X            if ((t = yylex()) == TOK_FLOAT)
  1305. X            {
  1306. X              buffer.xpos = yyfloatval;
  1307. X              if ((t = yylex()) == TOK_FLOAT)
  1308. X              {
  1309. X                 buffer.ypos = yyfloatval;
  1310. X                 if ((t = yylex()) == TOK_FLOAT)
  1311. X                 {
  1312. X                    buffer.hpos = yyfloatval;
  1313. X                if ((t = yylex()) == TOK_FLOAT)
  1314. X                  {
  1315. X                        buffer.vpos = yyfloatval;
  1316. X                        if ((t = yylex()) == TOK_FLOAT)
  1317. X                        {
  1318. X                          buffer.sxpos = yyfloatval;
  1319. X                      if ((t = yylex()) == TOK_FLOAT)
  1320. X                        {
  1321. X                             buffer.sypos = yyfloatval;
  1322. X                     read_bezier();
  1323. X                     break;
  1324. X                      } else
  1325. X                           error("missing last number.\n");
  1326. X                   } else
  1327. X                       error("missing fifth number.\n");
  1328. X                } else
  1329. X                    error("missing fourth number.\n");
  1330. X                 } else
  1331. X                 error("missing third number.\n");        
  1332. X              } else
  1333. X                  error("missing second number.\n");
  1334. X            } else
  1335. X                error("missing first number.\n");
  1336. X
  1337. X        case TOK_UNITLENGTH:
  1338. X            ulen = yyfloatval;
  1339. X            switch (t = yylex())
  1340. X            {
  1341. X            case TOK_DIM_PT:
  1342. X                unit = 1;
  1343. X                break;
  1344. X            case TOK_DIM_IN:
  1345. X                unit = 2;
  1346. X                break;
  1347. X            case TOK_DIM_CM:
  1348. X                unit = 3;
  1349. X                break;
  1350. X            case TOK_DIM_MM:
  1351. X                unit = 4;
  1352. X                break;
  1353. X            case TOK_DIM_PC:
  1354. X                unit = 5;
  1355. X                break;
  1356. X            default:
  1357. X                error("unit not found !\n");
  1358. X                break;
  1359. X            }
  1360. X            break;
  1361. X
  1362. X
  1363. X        default:
  1364. X            break;
  1365. X
  1366. X
  1367. X
  1368. X        }    /* switch */
  1369. X
  1370. X    }    /* while */
  1371. X
  1372. X
  1373. X    fclose(fd);
  1374. X
  1375. X
  1376. }
  1377. X
  1378. X
  1379. X
  1380. float
  1381. compute_length(float inp)
  1382. {
  1383. X    /* int unit: 1=pt 2=in 3=cm 4=mm 5=pc */
  1384. X
  1385. X
  1386. X
  1387. X    float           outp;
  1388. X    switch (unit)
  1389. X    {
  1390. X    case 1:
  1391. X        outp = inp * ulen;    /* 1pt remains 1pt */
  1392. X        /* unitlength=1.0pt */
  1393. X        break;
  1394. X    case 2:
  1395. X        outp = inp * ulen * 72.27;    /* 1inch=72.27pt */
  1396. X        /* unitlength=1.0pt */
  1397. X        break;
  1398. X    case 3:
  1399. X        outp = inp * ulen * 28.35;    /* 1cm=28.35pt */
  1400. X        /* unitlength=1.0pt */
  1401. X        break;
  1402. X    case 4:
  1403. X        outp = inp * ulen * 2.835;    /* 1mm=2.835pt */
  1404. X        /* unitlength=1.0pt */
  1405. X        break;
  1406. X    case 5:
  1407. X        outp = inp * ulen * 12;            /* 1pica=12pt */
  1408. X        /* unitlength=1.0pt */
  1409. X        break;
  1410. X
  1411. X    default:
  1412. X        outp = 1;    /* dummy */
  1413. X        fprintf(stderr, "in function compute_length: default-case must not occur !!!\n\n");
  1414. X        break;
  1415. X    }
  1416. X
  1417. X    return outp;
  1418. X
  1419. }
  1420. X
  1421. X
  1422. X
  1423. X
  1424. X
  1425. X
  1426. X
  1427. /* the following read_xxx - routines insert a new object into the database */
  1428. /* and then return to the scanner... */
  1429. X
  1430. void
  1431. read_framebox()
  1432. {
  1433. X    struct fig3    *drei = (struct fig3 *) malloc(sizeof(framedBox));
  1434. X    /* fill the struct */
  1435. X    drei->x = compute_length(buffer.xpos);
  1436. X    drei->y = compute_length(buffer.ypos);
  1437. X
  1438. X    drei->h = drei->x + compute_length(buffer.hpos);
  1439. X    drei->v = drei->y + compute_length(buffer.vpos);
  1440. X
  1441. X    drei->text = (char *) malloc(strlen(buffer.text) + 1);
  1442. X    strcpy(drei->text, buffer.text);
  1443. X
  1444. X    if (
  1445. X        (buffer.textpos[0] != 'b') &&
  1446. X        (buffer.textpos[0] != 't') &&
  1447. X        (buffer.textpos[0] != 'l') &&
  1448. X        (buffer.textpos[0] != 'r')
  1449. X        )
  1450. X        buffer.textpos[0] = '\0';
  1451. X
  1452. X    if (
  1453. X        (buffer.textpos[1] != 'b') &&
  1454. X        (buffer.textpos[1] != 't') &&
  1455. X        (buffer.textpos[1] != 'l') &&
  1456. X        (buffer.textpos[1] != 'r')
  1457. X        )
  1458. X        buffer.textpos[1] = '\0';
  1459. X
  1460. X    drei->textpos[0] = buffer.textpos[0];
  1461. X    drei->textpos[1] = buffer.textpos[1];
  1462. X    drei->next = NULL;
  1463. X
  1464. X    /* use internal coordinate system */
  1465. X    drei->y = oldy(drei->y);
  1466. X    drei->v = oldy(drei->v);
  1467. X
  1468. X    norm_rectangle(&drei->x, &drei->y, &drei->h, &drei->v);
  1469. X
  1470. X    /* insert the struct into database */
  1471. X
  1472. X    if (framedBox_start == NULL)
  1473. X    {
  1474. X        framedBox_start = drei;
  1475. X        framedBox_curr = drei;
  1476. X    } else
  1477. X    {
  1478. X        framedBox_curr->next = drei;
  1479. X        framedBox_curr = drei;
  1480. X    }
  1481. X
  1482. }
  1483. X
  1484. void
  1485. read_dashbox()
  1486. {
  1487. X    struct fig4    *vier = (struct fig4 *) malloc(sizeof(dashedBox));
  1488. X    /* fill the struct */
  1489. X    vier->x = compute_length(buffer.xpos);
  1490. X    vier->y = compute_length(buffer.ypos);
  1491. X
  1492. X    vier->h = vier->x + compute_length(buffer.hpos);
  1493. X    vier->v = vier->y + compute_length(buffer.vpos);
  1494. X
  1495. X    vier->text = (char *) malloc(strlen(buffer.text) + 1);
  1496. X    strcpy(vier->text, buffer.text);
  1497. X
  1498. X    if (
  1499. X        (buffer.textpos[0] != 'b') &&
  1500. X        (buffer.textpos[0] != 't') &&
  1501. X        (buffer.textpos[0] != 'l') &&
  1502. X        (buffer.textpos[0] != 'r')
  1503. X        )
  1504. X        buffer.textpos[0] = '\0';
  1505. X
  1506. X    if (
  1507. X        (buffer.textpos[1] != 'b') &&
  1508. X        (buffer.textpos[1] != 't') &&
  1509. X        (buffer.textpos[1] != 'l') &&
  1510. X        (buffer.textpos[1] != 'r')
  1511. X        )
  1512. X        buffer.textpos[1] = '\0';
  1513. X
  1514. X    vier->textpos[0] = buffer.textpos[0];
  1515. X    vier->textpos[1] = buffer.textpos[1];
  1516. X
  1517. X    vier->dashlength = compute_length(buffer.dash_length);
  1518. X
  1519. X    vier->next = NULL;
  1520. X
  1521. X    /* use internal coordinate system */
  1522. X    vier->y = oldy(vier->y);
  1523. X    vier->v = oldy(vier->v);
  1524. X
  1525. X    norm_rectangle(&vier->x, &vier->y, &vier->h, &vier->v);
  1526. X
  1527. X    /* insert the struct into database */
  1528. X
  1529. X    if (dashedBox_start == NULL)
  1530. X    {
  1531. X        dashedBox_start = vier;
  1532. X        dashedBox_curr = vier;
  1533. X    } else
  1534. X    {
  1535. X        dashedBox_curr->next = vier;
  1536. X        dashedBox_curr = vier;
  1537. X    }
  1538. }
  1539. X
  1540. void
  1541. read_filledbox()
  1542. {
  1543. X /* buffer.hpos und buffer.vpos sind bereits waehrend des scannens ins richtige format konvertiert worden */
  1544. X    struct fig2    *zwei = (struct fig2 *) malloc(sizeof(filledBox));
  1545. X    /* fill the struct */
  1546. X    zwei->x = compute_length(buffer.xpos);
  1547. X    zwei->y = compute_length(buffer.ypos);
  1548. X
  1549. X    zwei->h = zwei->x + buffer.hpos;
  1550. X    zwei->v = zwei->y + buffer.vpos;
  1551. X
  1552. X    zwei->next = NULL;
  1553. X
  1554. X    /* use internal coordinate system */
  1555. X    zwei->y = oldy(zwei->y);
  1556. X    zwei->v = oldy(zwei->v);
  1557. X
  1558. X    norm_rectangle(&zwei->x, &zwei->y, &zwei->h, &zwei->v);
  1559. X
  1560. X    /* insert the struct into database */
  1561. X
  1562. X    if (filledBox_start == NULL)
  1563. X    {
  1564. X        filledBox_start = zwei;
  1565. X        filledBox_curr = zwei;
  1566. X    } else
  1567. X    {
  1568. X        filledBox_curr->next = zwei;
  1569. X        filledBox_curr = zwei;
  1570. X    }
  1571. }
  1572. X
  1573. void
  1574. read_line()
  1575. {
  1576. X    struct fig2    *zwei = (struct fig2 *) malloc(sizeof(strich));
  1577. X    /* fill the struct */
  1578. X    zwei->x = compute_length(buffer.xpos);
  1579. X    zwei->y = compute_length(buffer.ypos);
  1580. X
  1581. X    /* the vector */
  1582. X    zwei->h = buffer.hpos;
  1583. X    zwei->v = buffer.vpos;
  1584. X
  1585. X    compute_end_coords(zwei->x, zwei->y, &zwei->h, &zwei->v, compute_length(buffer.dash_length));
  1586. X
  1587. X    zwei->next = NULL;
  1588. X
  1589. X    /* use internal coordinate system */
  1590. X    zwei->y = oldy(zwei->y);
  1591. X    zwei->v = oldy(zwei->v);
  1592. X
  1593. X
  1594. X    /* insert the struct into database */
  1595. X
  1596. X    if (strich_start == NULL)
  1597. X    {
  1598. X        strich_start = zwei;
  1599. X        strich_curr = zwei;
  1600. X    } else
  1601. X    {
  1602. X        strich_curr->next = zwei;
  1603. X        strich_curr = zwei;
  1604. X    }
  1605. }
  1606. X
  1607. void
  1608. read_vector()
  1609. {
  1610. X    struct fig2    *zwei = (struct fig2 *) malloc(sizeof(pfeil));
  1611. X    /* fill the struct */
  1612. X    zwei->x = compute_length(buffer.xpos);
  1613. X    zwei->y = compute_length(buffer.ypos);
  1614. X
  1615. X    /* the vector */
  1616. X    zwei->h = buffer.hpos;
  1617. X    zwei->v = buffer.vpos;
  1618. X
  1619. X    compute_end_coords(zwei->x, zwei->y, &zwei->h, &zwei->v, compute_length(buffer.dash_length));
  1620. X
  1621. X    zwei->next = NULL;
  1622. X
  1623. X    /* use internal coordinate system */
  1624. X    zwei->y = oldy(zwei->y);
  1625. X    zwei->v = oldy(zwei->v);
  1626. X
  1627. X    /* insert the struct into database */
  1628. X
  1629. X    if (pfeil_start == NULL)
  1630. X    {
  1631. X        pfeil_start = zwei;
  1632. X        pfeil_curr = zwei;
  1633. X    } else
  1634. X    {
  1635. X        pfeil_curr->next = zwei;
  1636. X        pfeil_curr = zwei;
  1637. X    }
  1638. }
  1639. X
  1640. X
  1641. void
  1642. read_circle()
  1643. {
  1644. X    struct fig2    *zwei = (struct fig2 *) malloc(sizeof(kreis));
  1645. X    /* fill the struct */
  1646. X    zwei->x = compute_length(buffer.xpos);
  1647. X    zwei->y = compute_length(buffer.ypos);
  1648. X    zwei->radius = (int) compute_length((float) buffer.radius / 2);
  1649. X
  1650. X    zwei->next = NULL;
  1651. X
  1652. X    /* use internal coordinate system */
  1653. X    zwei->y = oldy(zwei->y);
  1654. X
  1655. X    /* insert the struct into database */
  1656. X
  1657. X    if (kreis_start == NULL)
  1658. X    {
  1659. X        kreis_start = zwei;
  1660. X        kreis_curr = zwei;
  1661. X    } else
  1662. X    {
  1663. X        kreis_curr->next = zwei;
  1664. X        kreis_curr = zwei;
  1665. X    }
  1666. }
  1667. X
  1668. void
  1669. read_disc()
  1670. {
  1671. X    struct fig2    *zwei = (struct fig2 *) malloc(sizeof(disc));
  1672. X    /* fill the struct */
  1673. X    zwei->x = compute_length(buffer.xpos);
  1674. X    zwei->y = compute_length(buffer.ypos);
  1675. X    zwei->radius = (int) compute_length((float) buffer.radius / 2);
  1676. X
  1677. X    zwei->next = NULL;
  1678. X
  1679. X    /* use internal coordinate system */
  1680. X    zwei->y = oldy(zwei->y);
  1681. X
  1682. X    /* insert the struct into database */
  1683. X
  1684. X    if (disc_start == NULL)
  1685. X    {
  1686. X        disc_start = zwei;
  1687. X        disc_curr = zwei;
  1688. X    } else
  1689. X    {
  1690. X        disc_curr->next = zwei;
  1691. X        disc_curr = zwei;
  1692. X    }
  1693. }
  1694. X
  1695. void
  1696. read_oval()
  1697. {
  1698. X    struct fig1    *eins = (struct fig1 *) malloc(sizeof(oval));
  1699. X    /* fill the struct */
  1700. X    eins->x = compute_length(buffer.xpos);
  1701. X    eins->y = compute_length(buffer.ypos);
  1702. X
  1703. X    eins->h = compute_length(buffer.hpos);
  1704. X    eins->v = compute_length(buffer.vpos);
  1705. X
  1706. X    (eins->x) -= (eins->h / 2);
  1707. X    (eins->y) -= (eins->v / 2);
  1708. X
  1709. X    eins->h = eins->h + eins->x;
  1710. X    eins->v = eins->v + eins->y;
  1711. X
  1712. X    eins->next = NULL;
  1713. X
  1714. X    /* use internal coordinate system */
  1715. X    eins->y = oldy(eins->y);
  1716. X    eins->v = oldy(eins->v);
  1717. X
  1718. X    norm_rectangle(&eins->x, &eins->y, &eins->h, &eins->v);
  1719. X
  1720. X    /* insert the struct into database */
  1721. X
  1722. X    if (oval_start == NULL)
  1723. X    {
  1724. X        oval_start = eins;
  1725. X        oval_curr = eins;
  1726. X    } else
  1727. X    {
  1728. X        oval_curr->next = eins;
  1729. X        oval_curr = eins;
  1730. X    }
  1731. }
  1732. X
  1733. void
  1734. read_message()
  1735. {
  1736. X  int lenn=81;
  1737. X
  1738. X    struct fig5    *fuenf = (struct fig5 *) malloc(sizeof(message));
  1739. X    /* fill the struct */
  1740. X
  1741. X    if (1+strlen(buffer.text)>lenn) lenn=1+strlen(buffer.text);
  1742. X
  1743. X    fuenf->x = compute_length(buffer.xpos);
  1744. X    fuenf->y = compute_length(buffer.ypos);
  1745. X
  1746. X    fuenf->text = (char *) malloc(lenn);
  1747. X    strcpy(fuenf->text, buffer.text);
  1748. X
  1749. X    if (
  1750. X        (buffer.textpos[0] != 'b') &&
  1751. X        (buffer.textpos[0] != 't') &&
  1752. X        (buffer.textpos[0] != 'l') &&
  1753. X        (buffer.textpos[0] != 'r')
  1754. X        )
  1755. X        buffer.textpos[0] = 'c';
  1756. X
  1757. X    if (
  1758. X        (buffer.textpos[1] != 'b') &&
  1759. X        (buffer.textpos[1] != 't') &&
  1760. X        (buffer.textpos[1] != 'l') &&
  1761. X        (buffer.textpos[1] != 'r')
  1762. X        )
  1763. X        buffer.textpos[1] = 'c';
  1764. X
  1765. X    fuenf->textpos[0] = buffer.textpos[0];
  1766. X    fuenf->textpos[1] = buffer.textpos[1];
  1767. X
  1768. X    fuenf->next = NULL;
  1769. X
  1770. X    /* use internal coordinate system */
  1771. X    fuenf->y = oldy(fuenf->y);
  1772. X
  1773. X    /* insert the struct into database */
  1774. X
  1775. X    if (message_start == NULL)
  1776. X    {
  1777. X        message_start = fuenf;
  1778. X        message_curr = fuenf;
  1779. X    } else
  1780. X    {
  1781. X        message_curr->next = fuenf;
  1782. X        message_curr = fuenf;
  1783. X    }
  1784. }
  1785. X
  1786. void
  1787. read_bezier()
  1788. {
  1789. X    struct fig6    *six = (struct fig6 *) malloc(sizeof(bezier));
  1790. X    /* fill the struct */
  1791. X    six->ax = compute_length(buffer.xpos);
  1792. X    six->ay = compute_length(buffer.ypos);
  1793. X
  1794. X    six->sx = compute_length(buffer.hpos);
  1795. X    six->sy = compute_length(buffer.vpos);
  1796. X
  1797. X    six->ex = compute_length(buffer.sxpos);
  1798. X    six->ey = compute_length(buffer.sypos);
  1799. X
  1800. X    six->next = NULL;
  1801. X
  1802. X    /* use internal coordinate system */
  1803. X    six->ay = oldy(six->ay);
  1804. X    six->ey = oldy(six->ey);
  1805. X    six->sy = oldy(six->sy);
  1806. X
  1807. X    /* insert the struct into database */
  1808. X
  1809. X    if (bezier_start == NULL)
  1810. X    {
  1811. X        bezier_start = six;
  1812. X        bezier_curr = six;
  1813. X    } else
  1814. X    {
  1815. X        bezier_curr->next = six;
  1816. X        bezier_curr = six;
  1817. X    }
  1818. }
  1819. X
  1820. void
  1821. compute_end_coords(float x, float y, float *h, float *v, float len)
  1822. {
  1823. X    int             sgn;
  1824. X    float           ziel, lambda;
  1825. X    /* vertical ? */
  1826. X    if ((*h) == 0)
  1827. X    {
  1828. X        sgn = ((*v) < 0) ? -1 : 1;
  1829. X        (*v) = y + (float) sgn *len;
  1830. X        (*h) = x;
  1831. X    } else
  1832. X    {
  1833. X        len = ((*h) > 0) ? len : -len;
  1834. X        ziel = x + len;
  1835. X        lambda = (ziel - x) / (*h);
  1836. X        (*h) = ziel;
  1837. X        (*v) = y + lambda * (*v);
  1838. X    }
  1839. X    return;
  1840. }
  1841. X
  1842. X
  1843. X
  1844. X
  1845. X
  1846. void
  1847. trans_it(char *fn)
  1848. {
  1849. X    char            name[256];
  1850. X    FILE           *fd;
  1851. X    int             i;
  1852. X    float           xdim, ydim;
  1853. X
  1854. X    dim_x_max = 0;
  1855. X    dim_x_min = 999;
  1856. X    dim_y_max = 0;
  1857. X    dim_y_min = 999;
  1858. X
  1859. X    if (file_exists(fn) == True)
  1860. X    {
  1861. X        strcpy(name, fn);
  1862. X        strcat(name, ".old");
  1863. X        rename(fn, name);
  1864. X    }
  1865. X    fd = fopen(fn, "w+");
  1866. X    manage_line(0, fd);
  1867. X    manage_vector(0, fd);
  1868. X    manage_filled(0, fd);
  1869. X    manage_framed(0, fd);
  1870. X    manage_dashed(0, fd);
  1871. X    manage_kreis(0, fd);
  1872. X    manage_disc(0, fd);
  1873. X    manage_oval(0, fd);
  1874. X    manage_text(0, fd);
  1875. X    manage_bezier(0, fd);
  1876. X
  1877. X    xdim = dim_x_max - dim_x_min;
  1878. X    ydim = dim_y_max - dim_y_min;
  1879. X    xur = (xur == 0.0) ? dim_x_min : xur;
  1880. X    yur = (yur == 0.0) ? newy(dim_y_max) : yur;
  1881. X
  1882. X    
  1883. X    if ((dina4 == True) && (xdim > 300))
  1884. X    {
  1885. X        fprintf(fd, "%% ...images, whose extensions are to large for the\n");
  1886. X        fprintf(fd, "%% current style, can be centered with one of the following\n");
  1887. X        fprintf(fd, "%% modifications\n");
  1888. X        fprintf(fd, "%%    -  if there is only one page to translate:\n");
  1889. X        fprintf(fd, "%%       in the preamble: \\setlength{\\textheight}{%ipt}\n", y_A4_max);
  1890. X        fprintf(fd, "%%                        \\setlength{\\textwidth}{%ipt}\n", x_A4_max);
  1891. X        fprintf(fd, "%%    -  use the 2nd coordinate of the \\picture-command to adjust\n");
  1892. X        fprintf(fd, "%%       your image! X-Dimension is %3.2f, Y-Dimension is %3.2f\n", xdim, ydim);
  1893. X        fprintf(fd, "%% small images can be centered with the 'center'-environment.\n");
  1894. X    }
  1895. X    /* write header */
  1896. X
  1897. X    
  1898. X
  1899. X    fprintf(fd, "\\unitlength=1.0pt\n");
  1900. X    if (dina4 == True)
  1901. X        fprintf(fd, "\\begin{center}\n");
  1902. X    fprintf(fd, "\\begin{picture}(%3.2f,%3.2f)(%3.2f,%3.2f)\n",
  1903. X        xdim, ydim, xur, yur);
  1904. X
  1905. X
  1906. X    /* objects */
  1907. X
  1908. X    manage_line(1, fd);
  1909. X    manage_vector(1, fd);
  1910. X    manage_filled(1, fd);
  1911. X    manage_framed(1, fd);
  1912. X    manage_dashed(1, fd);
  1913. X    manage_kreis(1, fd);
  1914. X    manage_disc(1, fd);
  1915. X    manage_oval(1, fd);
  1916. X    manage_text(1, fd);
  1917. X    manage_bezier(1, fd);
  1918. X
  1919. X    fprintf(fd, "\\end{picture}\n");
  1920. X
  1921. X    if (dina4 == True)
  1922. X        fprintf(fd, "\\end{center}\n");
  1923. X
  1924. X    
  1925. X    fclose(fd);
  1926. X
  1927. }
  1928. X
  1929. X
  1930. void
  1931. dimension_update(float x, float y)
  1932. {
  1933. X    dim_x_min = (x < dim_x_min) ? x : dim_x_min;
  1934. X    dim_x_max = (x > dim_x_max) ? x : dim_x_max;
  1935. X
  1936. X    dim_y_min = (y < dim_y_min) ? y : dim_y_min;
  1937. X    dim_y_max = (y > dim_y_max) ? y : dim_y_max;
  1938. X
  1939. /*
  1940. X    if (dim_y_min < 0)
  1941. X        dim_y_min = 0;
  1942. X    if (dim_y_max > y_A4_max)
  1943. X        dim_y_max = y_A4_max;
  1944. X    if (dim_x_min < 0)
  1945. X        dim_x_min = 0;
  1946. X    if (dim_x_max > x_A4_max)
  1947. X        dim_x_max = x_A4_max;
  1948. */
  1949. X
  1950. }
  1951. X
  1952. X
  1953. float
  1954. newy(float y)
  1955. {/* compute new y-coordinate for LaTeX' coord.-system */
  1956. X
  1957. X    return y_A4_max - y;
  1958. }
  1959. X
  1960. float
  1961. oldy(float y)
  1962. {/* does the opposite... */
  1963. X
  1964. X    return newy(y);
  1965. }
  1966. X
  1967. X
  1968. void
  1969. get_line_info(float x, float y, float h, float v, int *x_slp, int *y_slp, float *len)
  1970. {
  1971. X    int             t, a, b, i;
  1972. X
  1973. X
  1974. X    if (line_slope == 0)
  1975. X    {    /* unlimited slopes */
  1976. X        y = newy(y);
  1977. X        v = newy(v);
  1978. X
  1979. X        if ((abs((int) (h - x)) != 0) && (abs((int) (v - y)) != 0))
  1980. X        {    /* not horizontal; not vertical */
  1981. X            a = abs((int) (h - x));
  1982. X            b = abs((int) (v - y));
  1983. X            t = ggt(a, b);
  1984. X
  1985. X            a = a / t;
  1986. X            b = b / t;
  1987. X            a = (x < h) ? a : -a;
  1988. X            b = (y < v) ? b : -b;
  1989. X            (*x_slp) = a;
  1990. X            (*y_slp) = b;
  1991. X            (*len) = (x < h) ? (h - x) : (x - h);
  1992. X        } else
  1993. X        {
  1994. X            if ((abs((int) (h - x)) != 0))
  1995. X            {    /* horizontal line */
  1996. X                (*x_slp) = (x < h) ? 1 : -1;
  1997. X                (*y_slp) = 0;
  1998. X                (*len) = (x < h) ? (h - x) : (x - h);
  1999. X            } else
  2000. X            {    /* vertical line */
  2001. X                (*x_slp) = 0;
  2002. X                (*y_slp) = (y < v) ? 1 : -1;
  2003. X                (*len) = (y < v) ? (v - y) : (y - v);
  2004. X            }
  2005. X        }
  2006. X    }
  2007. X    /* line_slope unlimited ! */
  2008. X    else
  2009. X    {    /* normal LaTex slopes... */
  2010. X        a = (int) h;
  2011. X        b = (int) v;
  2012. X        i = valid_line_coords((int) x, (int) y, &a, &b);
  2013. X
  2014. X
  2015. X        /* use LaTeX coordinate-system: */
  2016. X        y = newy(y);
  2017. X        v = newy(v);
  2018. X
  2019. X        /* horizontal, vertical line ? */
  2020. X
  2021. X        if (abs((int) (v - y)) == 0)
  2022. X        {    /* horizontal */
  2023. X            (*x_slp) = (x < h) ? 1 : -1;
  2024. X            (*y_slp) = 0;
  2025. X            (*len) = (x < h) ? (h - x) : (x - h);
  2026. X        } else if (abs((int) (h - x)) == 0)
  2027. X        {    /* vertical */
  2028. X            (*y_slp) = (y < v) ? 1 : -1;
  2029. X            (*x_slp) = 0;
  2030. X            (*len) = (y < v) ? (v - y) : (y - v);
  2031. X        } else
  2032. X        {    /* normal line */
  2033. X            (*x_slp) = (x < h) ? l_slope[i][1] : -l_slope[i][1];
  2034. X            (*y_slp) = (y < v) ? l_slope[i][2] : -l_slope[i][2];
  2035. X            (*len) = (x < h) ? (h - x) : (x - h);
  2036. X        }
  2037. X    }    /* else */
  2038. X
  2039. X    /* (*len)+=1.0; */
  2040. X
  2041. }
  2042. X
  2043. X
  2044. X
  2045. X
  2046. void
  2047. get_vector_info(float x, float y, float h, float v, int *x_slp, int *y_slp, float *len)
  2048. {
  2049. X    int             t, a, b, i;
  2050. X
  2051. X
  2052. X    if (arrow_slope == 0)
  2053. X    {    /* unlimited slopes */
  2054. X        y = newy(y);
  2055. X        v = newy(v);
  2056. X
  2057. X        if ((abs((int) (h - x)) != 0) && (abs((int) (v - y)) != 0))
  2058. X        {    /* not horizontal; not vertical */
  2059. X            a = abs((int) (h - x));
  2060. X            b = abs((int) (v - y));
  2061. X            t = ggt(a, b);
  2062. X
  2063. X            a = a / t;
  2064. X            b = b / t;
  2065. X            a = (x < h) ? a : -a;
  2066. X            b = (y < v) ? b : -b;
  2067. X            (*x_slp) = a;
  2068. X            (*y_slp) = b;
  2069. X            (*len) = (x < h) ? (h - x) : (x - h);
  2070. X        } else
  2071. X        {
  2072. X            if ((abs((int) (h - x)) != 0))
  2073. X            {    /* horizontal line */
  2074. X                (*x_slp) = (x < h) ? 1 : -1;
  2075. X                (*y_slp) = 0;
  2076. X                (*len) = (x < h) ? (h - x) : (x - h);
  2077. X            } else
  2078. X            {    /* vertical line */
  2079. X                (*x_slp) = 0;
  2080. X                (*y_slp) = (y < v) ? 1 : -1;
  2081. X                (*len) = (y < v) ? (v - y) : (y - v);
  2082. X            }
  2083. X        }
  2084. X    }
  2085. X    /* arrow_slope unlimited ! */
  2086. X    else
  2087. X    {    /* normal LaTeX slopes... */
  2088. X        a = (int) h;
  2089. X        b = (int) v;
  2090. X        i = valid_vector_coords((int) x, (int) y, &a, &b);
  2091. X
  2092. X
  2093. X
  2094. X        /* use LaTeX coordinate-system: */
  2095. X        y = newy(y);
  2096. X        v = newy(v);
  2097. X
  2098. X        /* horizontal, vertical line ? */
  2099. X
  2100. X        if (abs((int) (v - y)) == 0)
  2101. X        {    /* horizontal */
  2102. X            (*x_slp) = (x < h) ? 1 : -1;
  2103. SHAR_EOF
  2104. true || echo 'restore of io_trans.c failed'
  2105. fi
  2106. echo 'End of  part 5'
  2107. echo 'File io_trans.c is continued in part 6'
  2108. echo 6 > _shar_seq_.tmp
  2109. exit 0
  2110. -- 
  2111. --
  2112. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  2113. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  2114. Sunnyvale, California 94086            at&t: 408/522-9236
  2115.