home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / distributed-c-2.1 / part12 < prev    next >
Text File  |  1993-12-22  |  93KB  |  2,337 lines

  1. Newsgroups: comp.sources.unix
  2. From: pleierc@informatik.tu-muenchen.de (Christoph Pleier)
  3. Subject: v27i186: distributed-c-2.1 - Distributed C Development Environment, V2.1, Part12/18
  4. References: <1.756634932.28500@gw.home.vix.com>
  5. Sender: unix-sources-moderator@gw.home.vix.com
  6. Approved: vixie@gw.home.vix.com
  7.  
  8. Submitted-By: pleierc@informatik.tu-muenchen.de (Christoph Pleier)
  9. Posting-Number: Volume 27, Issue 186
  10. Archive-Name: distributed-c-2.1/part12
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 12 (of 18)."
  19. # Contents:  dcc/attr_general.c dcc/code_trans.c
  20. #   examples/travel/travel.dc include/config.h lib/convert.c
  21. # Wrapped by vixie@gw.home.vix.com on Thu Dec 23 00:12:04 1993
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'dcc/attr_general.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'dcc/attr_general.c'\"
  25. else
  26. echo shar: Extracting \"'dcc/attr_general.c'\" \(16526 characters\)
  27. sed "s/^X//" >'dcc/attr_general.c' <<'END_OF_FILE'
  28. X/***************************************************************************
  29. X *                                                                         *
  30. X * @@@@  @@@ @@@@@ @@@@@ @@@@@ @@@ @@@@  @   @ @@@@@ @@@@@ @@@@       @@@  *
  31. X * @   @  @  @       @   @   @  @  @   @ @   @   @   @     @   @     @   @ *
  32. X * @   @  @  @@@@@   @   @@@@@  @  @@@@@ @   @   @   @@@@@ @   @     @     *
  33. X * @   @  @      @   @   @ @    @  @   @ @   @   @   @     @   @     @   @ *
  34. X * @@@@  @@@ @@@@@   @   @  @  @@@ @@@@  @@@@@   @   @@@@@ @@@@       @@@  *
  35. X *                                                                         *
  36. X *              A compiler for distributed programming with C              *
  37. X *                                                                         *
  38. X *                       a t t r _ g e n e r a l . c                       *
  39. X *                                                                         *
  40. X *                            Package : Compiler                           *
  41. X *                            Version : 1.0                                *
  42. X *                       CreationDate : 28.07.90                           *
  43. X *                         LastUpDate : 08.11.91                           *
  44. X *                                                                         *
  45. X *     All routines used for administrating and handling attributes.       *
  46. X *                                                                         *
  47. X *                  Portions Copyright 1990 Franz Distler                  *
  48. X *               Copyright (C) 1990-1994 by Christoph Pleier               *
  49. X *                          All rights reserved!                           *
  50. X ***************************************************************************/
  51. X
  52. X/*
  53. X * This file is part of the Distributed C Development Environment (DCDE).
  54. X * DCDE is free software; you can redistribute it and/or modify
  55. X * it under the terms written in the README-file. 
  56. X * DCDE is distributed in the hope that it will be useful,
  57. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  58. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  59. X * See the file README for more details.
  60. X */
  61. X
  62. X#include <stdio.h>
  63. X#include "config.h"
  64. X#include "extern.h"
  65. X#include "functions.h"
  66. X
  67. X/******************************************************************************
  68. X * create_arg_list_elem()                                                     *
  69. X *                                                                            *
  70. X * Allocates memory for an argument expression list element and initializes   *
  71. X * it.                                                                        *
  72. X *                                                                            *
  73. X * Return values: pointer to new created attribute upon success /             *
  74. X *                NULL during error handling                                  *
  75. X ******************************************************************************/
  76. XARG_LIST *
  77. Xcreate_arg_list_elem(codestr)
  78. Xchar *codestr;
  79. X{
  80. X    register ARG_LIST *ptr;
  81. X
  82. X    if (errflag)    /* error handling! */
  83. X    return(NULL);
  84. X#ifdef ATTRDEBUG
  85. X    fputs("[attr] ***** create_arg_list_elem():\n", debugfile);
  86. X    fprintf(debugfile, "[attr]       params: codestr = %s\n", codestr);
  87. X#endif /* ATTRDEBUG /**/
  88. X    ptr = (ARG_LIST *) Malloc(sizeof(ARG_LIST));
  89. X#ifdef ATTRDEBUG
  90. X    fprintf(debugfile, "[attr]       address of new arg list is %d\n", ptr);
  91. X#endif /* ATTRDEBUG /**/
  92. X    ptr->code = strsave(codestr);
  93. X    ptr->next = (ARG_LIST *) NULL;
  94. X    return(ptr);
  95. X} /* create_arg_list_elem */
  96. X
  97. X/******************************************************************************
  98. X * link_arguments()                                                           *
  99. X *                                                                            *
  100. X * Links two argument expression list elements.                               *
  101. X *                                                                            *
  102. X * Return values: pointer to the first of the linked elements /               *
  103. X *                NULL during error handling                                  *
  104. X ******************************************************************************/
  105. XARG_LIST *
  106. Xlink_arguments(arg1, arg2)
  107. XARG_LIST *arg1, *arg2;
  108. X{
  109. X    if (errflag || !arg1 || !arg2) /* error handling! */
  110. X    return(NULL);
  111. X#ifdef ATTRDEBUG
  112. X    fprintf(debugfile, "[attr] ***** link_arguments(): params: arg1 = %d, arg2 = %d\n",
  113. X        arg1, arg2);
  114. X#endif /* ATTRDEBUG /**/
  115. X    arg1->next = arg2;
  116. X    return(arg1);
  117. X} /* link_arguments */
  118. X
  119. X/******************************************************************************
  120. X * create_compound_attribute()                                                *
  121. X *                                                                            *
  122. X * Allocates memory for a compound statement attribute and initializes it.    *
  123. X *                                                                            *
  124. X * Return values: pointer to new created attribute upon success /             *
  125. X *                dummy allocated attribute during error handling             *
  126. X ******************************************************************************/
  127. XCOMPATTR *
  128. Xcreate_compound_attribute(declarations, statements)
  129. Xchar *declarations, *statements;
  130. X{
  131. X    register COMPATTR *ptr;
  132. X
  133. X    if (errflag) /* error handling! */
  134. X    return((COMPATTR *) Malloc(sizeof(COMPATTR)));
  135. X#ifdef ATTRDEBUG
  136. X    fputs("[attr] ***** create_compound_attribute():\n", debugfile);
  137. X#endif /* ATTRDEBUG /**/
  138. X    ptr = (COMPATTR *) Malloc(sizeof(COMPATTR));
  139. X#ifdef ATTRDEBUG
  140. X    fprintf(debugfile, "[attr]       address of new attribute = %d\n", ptr);
  141. X#endif /* ATTRDEBUG /**/
  142. X    ptr->decls = declarations;
  143. X    ptr->stats = statements;
  144. X    return(ptr);
  145. X} /* create_compound_attribute */
  146. X
  147. X/******************************************************************************
  148. X * add_includefile_to_list()                                                  *
  149. X *                                                                            *
  150. X * Adds the include filename 'name' to the include filename list.             *
  151. X *                                                                            *
  152. X * Return values: always OK for success                                       *
  153. X ******************************************************************************/
  154. Xint
  155. Xadd_includefile_to_list(name)
  156. Xchar *name;
  157. X{
  158. X    register struct include_list *ptr;
  159. X
  160. X#ifdef ATTRDEBUG
  161. X    fputs("[attr] ***** add_includefile_to_list():\n", debugfile);
  162. X    fprintf(debugfile, "[attr]       params: name = %s\n", name);
  163. X#endif /* ATTRDEBUG /**/
  164. X
  165. X    /* check if include file is already in the list */
  166. X    for(ptr = first_includename; ptr; ptr = ptr->next) 
  167. X    if (!strcmp(name, ptr->name))
  168. X        return(OK);
  169. X
  170. X    /* allocate heap space for the new element */
  171. X    ptr = (struct include_list *) Malloc(sizeof(struct include_list));
  172. X
  173. X    /* initialize new element */
  174. X    ptr->name = strsave(name);
  175. X    ptr->next = NULL;
  176. X
  177. X    /* chain new element in list */
  178. X    if (!first_includename) {
  179. X    first_includename = last_includename = ptr;
  180. X    } else {
  181. X    last_includename->next = ptr;
  182. X    last_includename = ptr;
  183. X    }
  184. X
  185. X    return(OK);
  186. X} /* add_includefile_to_list */
  187. X
  188. X/******************************************************************************
  189. X * create_accept_attribute()                                                  *
  190. X *                                                                            *
  191. X * Allocates memory for an accept statement attribute and initializes it.     *
  192. X *                                                                            *
  193. X * Return values: pointer to new created attribute upon success /             *
  194. X *                dummy allocated attribute during error handling             *
  195. X ******************************************************************************/
  196. XACCEPTATTR *
  197. Xcreate_accept_attribute(transaction, comp_attr)
  198. XSYMBTABEL *transaction;
  199. XCOMPATTR *comp_attr;
  200. X{
  201. X    register ACCEPTATTR *ptr;
  202. X
  203. X    if (errflag || !transaction || !comp_attr) /* error handling! */
  204. X    return((ACCEPTATTR *) Malloc(sizeof(ACCEPTATTR)));
  205. X#ifdef ATTRDEBUG
  206. X    fputs("[attr] ***** create_accept_attribute():\n", debugfile);
  207. X#endif /* ATTRDEBUG /**/
  208. X    ptr = (ACCEPTATTR *) Malloc(sizeof(ACCEPTATTR));
  209. X#ifdef ATTRDEBUG
  210. X    fprintf(debugfile, "[attr]       address of new attribute = %d\n", ptr);
  211. X#endif /* ATTRDEBUG /**/
  212. X    ptr->transaction = transaction;
  213. X    ptr->comp_attr   = comp_attr;
  214. X    return(ptr);
  215. X} /* create_accept_attribute */
  216. X
  217. X/******************************************************************************
  218. X * create_select_attribute()                                                  *
  219. X *                                                                            *
  220. X * Allocates memory for a select statement sttribute and initializes it.      *
  221. X *                                                                            *
  222. X * Return values: pointer to new created attribute upon success /             *
  223. X *                dummy allocated attribute during error handling             *
  224. X ******************************************************************************/
  225. XSELECTATTR *
  226. Xcreate_select_attribute(type, accept_attr, statements)
  227. Xint type;
  228. XACCEPTATTR *accept_attr;
  229. Xchar *statements;
  230. X{
  231. X    register SELECTATTR *ptr;
  232. X
  233. X    if (errflag || type == ERROR || (!accept_attr)) { /* error handling! */
  234. X    ptr = (SELECTATTR *) Malloc(sizeof(SELECTATTR));
  235. X    ptr->type = ERROR;
  236. X    }
  237. X#ifdef ATTRDEBUG
  238. X    fputs("[attr] ***** create_select_attribute():\n", debugfile);
  239. X#endif /* ATTRDEBUG /**/
  240. X    ptr = (SELECTATTR *) Malloc(sizeof(SELECTATTR));
  241. X#ifdef ATTRDEBUG
  242. X    fprintf(debugfile, "[attr]       address of new attribute = %d\n", ptr);
  243. X#endif /* ATTRDEBUG /**/
  244. X    ptr->type        = type;
  245. X    ptr->guard       = (char *) NULL;
  246. X    ptr->accept_attr = accept_attr;
  247. X    ptr->stats       = statements;
  248. X    ptr->next        = (SELECTATTR *) NULL;
  249. X    return(ptr);
  250. X} /* create_select_attribute */
  251. X
  252. X/******************************************************************************
  253. X * add_guard_to_attr()                                                        *
  254. X *                                                                            *
  255. X * Updates the component 'guard' of a select statement attribute.             *
  256. X *                                                                            *
  257. X * Return values: pointer to updated attribute upon success /                 *
  258. X *                NULL during error handling                                  *
  259. X ******************************************************************************/
  260. XSELECTATTR *
  261. Xadd_guard_to_attr(select_attr, guard)
  262. XSELECTATTR *select_attr;
  263. Xchar *guard;
  264. X{
  265. X    if (errflag || !select_attr) /* error handling! */
  266. X    return(NULL);
  267. X#ifdef ATTRDEBUG
  268. X    fputs("[attr] ***** add_guard_to_attr():\n", debugfile);
  269. X    fprintf(debugfile, "[attr] params: select_attr = %d\n", select_attr);
  270. X    fprintf(debugfile, "[attr]         guard = %s\n", guard);
  271. X#endif /* ATTRDEBUG /**/
  272. X    select_attr->guard = guard;
  273. X    return(select_attr);
  274. X} /* add_guard_to_attr */
  275. X
  276. X/******************************************************************************
  277. X * link_select_attributes()                                                   *
  278. X *                                                                            *
  279. X * Links two select statement attributes.                                     *
  280. X *                                                                            *
  281. X * Return values: pointer to the first of the linked elements                 *
  282. X ******************************************************************************/
  283. XSELECTATTR *
  284. Xlink_select_attributes(attr1, attr2)
  285. XSELECTATTR *attr1, *attr2;
  286. X{
  287. X    if (errflag || !attr1 || !attr2 || (attr1->type == ERROR)
  288. X    || (attr2->type == ERROR)) {
  289. X    /* error handling! */
  290. X    attr1->type = ERROR;
  291. X    return(attr1);
  292. X    }
  293. X#ifdef ATTRDEBUG
  294. X    fputs("[attr] ***** link_select_attributes():\n", debugfile);
  295. X    fprintf(debugfile, "[attr] params: attr1 = %d\n", attr1);
  296. X    fprintf(debugfile, "[attr]         attr2 = %d\n", attr2);
  297. X#endif /* ATTRDEBUG /**/
  298. X    attr1->next = attr2;
  299. X    return(attr1);
  300. X} /* link_select_attributes */
  301. X
  302. X/******************************************************************************
  303. X * create_post_expr_attr()                                                    *
  304. X *                                                                            *
  305. X * Allocates memory for postfix expression attribute and initializes it.      *
  306. X *                                                                            *
  307. X * Return values: pointer to new created attribute upon success /             *
  308. X *                dummy allocated attribute during error handling             *
  309. X ******************************************************************************/
  310. XPOSTATTR *
  311. Xcreate_post_expr_attr(name)
  312. Xchar *name;
  313. X{
  314. X    register POSTATTR *ptr;
  315. X    SYMBTABEL *symbol;
  316. X
  317. X    if (errflag || (!name)) {
  318. X        ptr = (POSTATTR *) Malloc(sizeof(POSTATTR));
  319. X    ptr->codestr = strmalloc("");
  320. X    return(ptr);
  321. X    }
  322. X#ifdef ATTRDEBUG
  323. X    fprintf(debugfile,"[attr] ***** create_post_expr_attr():\n");
  324. X    fprintf(debugfile,"[attr] name = %s\n", name);
  325. X#endif /* ATTRDEBUG /**/
  326. X    ptr = (POSTATTR *) Malloc(sizeof(POSTATTR));
  327. X    ptr->idents = (IDENTCHAIN *) Malloc(sizeof(IDENTCHAIN));
  328. X    ptr->codestr = (char *) strmalloc("");
  329. X    if (!(symbol = lookup_symbtabel(name))) {
  330. X#ifdef ATTRDEBUG
  331. X    fprintf(debugfile, "no entry found in symbol table\n");
  332. X#endif /* ATTRDEBUG /**/
  333. X    strcpy(ptr->codestr, name);
  334. X    ptr->idents->symbol = (SYMBTABEL *) NULL;
  335. X    ptr->idents->next = (IDENTCHAIN *) NULL;
  336. X    return(ptr);
  337. X    }
  338. X#ifdef ATTRDEBUG
  339. X    fprintf(debugfile, "entry found in symbol table\n");
  340. X#endif /* ATTRDEBUG /**/
  341. X    strcpy(ptr->codestr, symbol->name);
  342. X    ptr->idents->symbol = symbol;
  343. X    ptr->idents->next = NULL;
  344. X    return(ptr);
  345. X} /* create_post_expr_attr */
  346. X
  347. X/******************************************************************************
  348. X * update_post_expr_attr()                                                    *
  349. X *                                                                            *
  350. X * Updates a postfix expression attribute.                                    *
  351. X *                                                                            *
  352. X * Return values: pointer to the updated attribute upon success /             *
  353. X *                NULL during error handling                                  *
  354. X ******************************************************************************/
  355. XIDENTCHAIN *
  356. Xupdate_post_expr_attr(first, ident)
  357. XIDENTCHAIN *first;
  358. XSYMBTABEL *ident;
  359. X{
  360. X    register IDENTCHAIN *ptr;
  361. X
  362. X    if (errflag || (!first) || (!ident))
  363. X    return(NULL);
  364. X#ifdef ATTRDEBUG
  365. X    fprintf(debugfile,"[attr] ***** update_post_expr_attr():\n");
  366. X#endif /* ATTRDEBUG /**/
  367. X    for(ptr = first; ptr->next; ptr = ptr->next)
  368. X    ;
  369. X    ptr->next = (IDENTCHAIN *) Malloc(sizeof(IDENTCHAIN));
  370. X    ptr->next->symbol = (SYMBTABEL *) Malloc(sizeof(SYMBTABEL));
  371. X    ptr = ptr->next;
  372. X    ptr->symbol = ident;
  373. X    ptr->next = (IDENTCHAIN *) NULL;
  374. X    return(first);
  375. X} /* update_post_expr_attr */
  376. X
  377. X/******************************************************************************
  378. X * create_trans_attr()                                                        *
  379. X *                                                                            *
  380. X * Allocates memory for transaction call attribute and initializes it.        *
  381. X *                                                                            *
  382. X * Return values: pointer to new created attribute upon success /             *
  383. X *                dummy allocated attribute during error handling             *
  384. X ******************************************************************************/
  385. XTRANSATTR *
  386. Xcreate_trans_attr(postattr, symbol, arg)
  387. XPOSTATTR *postattr;
  388. XSYMBTABEL *symbol;
  389. XARG_LIST *arg;
  390. X{
  391. X    register TRANSATTR *ptr;
  392. X
  393. X    if (errflag) {
  394. X        ptr = (TRANSATTR *) Malloc(sizeof(TRANSATTR));
  395. X    return(ptr);
  396. X    }
  397. X#ifdef ATTRDEBUG
  398. X    fprintf(debugfile,"[attr] ***** create_trans_attr():\n");
  399. X    fprintf(debugfile,"[attr]       postattr->codestr = %s\n", postattr->codestr);
  400. X    fprintf(debugfile,"[attr]       symbol->name = %s\n", symbol->name);
  401. X#endif /* ATTRDEBUG /**/
  402. X    ptr = (TRANSATTR *) Malloc(sizeof(TRANSATTR));
  403. X    ptr->target = postattr->codestr;
  404. X    ptr->symbol = symbol;
  405. X    ptr->arg    = arg;
  406. X    return(ptr);
  407. X} /* create_trans_attr */
  408. END_OF_FILE
  409. if test 16526 -ne `wc -c <'dcc/attr_general.c'`; then
  410.     echo shar: \"'dcc/attr_general.c'\" unpacked with wrong size!
  411. fi
  412. # end of 'dcc/attr_general.c'
  413. fi
  414. if test -f 'dcc/code_trans.c' -a "${1}" != "-c" ; then 
  415.   echo shar: Will not clobber existing file \"'dcc/code_trans.c'\"
  416. else
  417. echo shar: Extracting \"'dcc/code_trans.c'\" \(17142 characters\)
  418. sed "s/^X//" >'dcc/code_trans.c' <<'END_OF_FILE'
  419. X/***************************************************************************
  420. X *                                                                         *
  421. X * @@@@  @@@ @@@@@ @@@@@ @@@@@ @@@ @@@@  @   @ @@@@@ @@@@@ @@@@       @@@  *
  422. X * @   @  @  @       @   @   @  @  @   @ @   @   @   @     @   @     @   @ *
  423. X * @   @  @  @@@@@   @   @@@@@  @  @@@@@ @   @   @   @@@@@ @   @     @     *
  424. X * @   @  @      @   @   @ @    @  @   @ @   @   @   @     @   @     @   @ *
  425. X * @@@@  @@@ @@@@@   @   @  @  @@@ @@@@  @@@@@   @   @@@@@ @@@@       @@@  *
  426. X *                                                                         *
  427. X *              A compiler for distributed programming with C              *
  428. X *                                                                         *
  429. X *                         c o d e _ t r a n s . c                         *
  430. X *                                                                         *
  431. X *                            Package : Compiler                           *
  432. X *                            Version : 1.1                                *
  433. X *                       CreationDate : 26.07.90                           *
  434. X *                         LastUpDate : 08.06.91                           *
  435. X *                                                                         *
  436. X * The functions to generate the code and routines for transactions and    *
  437. X * the build the code and routines to call transactions.                   *
  438. X *                                                                         *
  439. X *               Copyright (C) 1990-1994 by Christoph Pleier               *
  440. X *                          All rights reserved!                           *
  441. X ***************************************************************************/
  442. X
  443. X/*
  444. X * This file is part of the Distributed C Development Environment (DCDE).
  445. X * DCDE is free software; you can redistribute it and/or modify
  446. X * it under the terms written in the README-file. 
  447. X * DCDE is distributed in the hope that it will be useful,
  448. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  449. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  450. X * See the file README for more details.
  451. X */
  452. X
  453. X#include <stdio.h>
  454. X#include <sys/types.h>
  455. X#include "config.h"
  456. X#include "extern.h"
  457. X#include "functions.h"
  458. X#include "com_Errno.h"
  459. X#include "timeout.h"
  460. X
  461. X/******************************************************************************
  462. X * gen_call_transaction_routines()                                            *
  463. X *                                                                            *
  464. X * Generates the call transaction routine for the transaction specified by    *
  465. X * the symbol table element 'symbol'. The generated call transaction routine  *
  466. X * is called at runtime to call the specified transaction, pass the arguments *
  467. X * and get the result.                                                        *
  468. X *                                                                            *
  469. X * Return values: OK upon success / ERROR upon error or during error handling *
  470. X ******************************************************************************/
  471. Xint
  472. Xgen_call_transaction_routines(symbol)
  473. XSYMBTABEL *symbol;
  474. X{
  475. X    char        *piname,
  476. X                *ptiname, 
  477. X                *uptiname,
  478. X                 tmpstr[20];
  479. X    SYMBTABEL   *actions,
  480. X                *params;
  481. X
  482. X    if (errflag || !symbol)    /* error handling! */
  483. X        return(ERROR);
  484. X#ifdef CODEDEBUG
  485. X    fputs("[code] ***** gen_call_transaction_routines():\n", debugfile);
  486. X    fprintf(debugfile, "[code]       params: symbol = %d\n", symbol);
  487. X#endif  /* CODEDEBUG /**/
  488. X    for(actions=symbol->info.process.FirstTrans; actions; actions=actions->info.trans.NextTrans) {
  489. X    ptiname  = actions->info.trans.ptiname;
  490. X    uptiname = actions->info.trans.uptiname;
  491. X        if (infoflag) {
  492. X        printf("%s generating calling routine for transaction '%s' of process '%s'\n", 
  493. X        infoprefix, actions->name, symbol->name);
  494. X        fflush(stdout);
  495. X        }
  496. X    /* transaction code */
  497. X    sprintf(tmpstr, " %d\n", ++transnum);
  498. X    fprintf(creatfile,"\n/* specific routine to call transaction '%s' */\n",
  499. X        actions->name);
  500. X    *convert_buffer = 0;
  501. X    convert_buffer = convert_ds_to_string(convert_buffer, actions->info.trans.ReturnType);
  502. X    fprintf(creatfile, "%s\ncall_%s(p_descr", convert_buffer, ptiname);
  503. X    for(params=actions->info.trans.FirstParam; params; params=params->info.varorpar.NextParam) {
  504. X        fprintf(creatfile, ", %s", params->name);
  505. X    }
  506. X    fputs(", mode)\n", creatfile);
  507. X    fputs("PROCESSDESCR p_descr;\n", creatfile);
  508. X    for(params=actions->info.trans.FirstParam; params; params=params->info.varorpar.NextParam) {
  509. X        *convert_buffer = 0;
  510. X        convert_buffer = convert_ds_to_string(convert_buffer, params->info.varorpar.DataType);
  511. X        fprintf(creatfile, "%s %s;\n", convert_buffer, params->name);
  512. X    }
  513. X    fputs("int mode;\n", creatfile);
  514. X    fputs("{\n", creatfile);
  515. X    fputs("\tif (mode == CALL) {\n", creatfile);
  516. X    fputs("\t\t/* call process and request transaction */\n", creatfile);
  517. X    fprintf(creatfile, "\t\tif (_make_transaction_call(p_descr.port, \"%s\", 0))\n",
  518. X        uptiname);
  519. X    fprintf(creatfile, "\t\t\t_RuntimeError(\"requesting transaction (%s@%s)\");\n",
  520. X        symbol->name, actions->name);
  521. X    fputs("\t}\n", creatfile);
  522. X    if (actions->info.trans.FirstParam) {
  523. X        fputs("\t/* o.k. transaction permitted, now send arguments */\n", 
  524. X            creatfile);
  525. X            for(params=actions->info.trans.FirstParam; params; params=params->info.varorpar.NextParam)
  526. X            fprintf(creatfile,"\tdcc_par.%s.%s = %s;\n", ptiname, params->name,
  527. X            params->name);
  528. X            fprintf(creatfile, "\tif (_send_data");
  529. X#ifdef HETEROGENEOUS
  530. X            fprintf(creatfile, "_encoded");
  531. X#endif
  532. X            fprintf(creatfile, "(&_con_port, (char *) &dcc_par.%s, ", ptiname);
  533. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  534. X            fprintf(creatfile, "sizeof(%s%s)", uptiname, POSTFIXTRANSPAR);
  535. X#else /* HETEROGENEOUS */
  536. X            fprintf(creatfile, "xdr_%s%s", uptiname, POSTFIXTRANSPAR);
  537. X#endif
  538. X            fprintf(creatfile, ", %d) < 0) {\n", TRANSARGTIME);
  539. X            fputs("\t\tif (Errno == ETIMEOUT)\n", creatfile);
  540. X            fputs("\t\t\tErrno = ETTSENDARGS;\n", creatfile);
  541. X            fprintf(creatfile, "\t\t_RuntimeError(\"sending arguments (%s@%s)\");\n",
  542. X        symbol->name, actions->name);
  543. X        fputs("\t}\n", creatfile);
  544. X    }
  545. X#ifdef HETEROGENEOUS
  546. X    /* We must clear the memory where the received data will be stored in,
  547. X     * because the xdr routines allocate storage for pointers only if
  548. X     * the pointer values equal the NULL pointer!!!
  549. X     */
  550. X    fputs("\t/* clear structure to handle pointers correctly */\n", creatfile);
  551. X    fprintf(creatfile, "\tbzero(&dcc_res.%s, sizeof(%s%s));\n", 
  552. X        ptiname, uptiname, POSTFIXTRANSRES);
  553. X#endif
  554. X        fprintf(creatfile, "\tif (_recv_data");
  555. X#ifdef HETEROGENEOUS
  556. X        fprintf(creatfile, "_encoded");
  557. X#endif
  558. X        fprintf(creatfile, "(&_con_port, (char *) &dcc_res.%s, ", ptiname);
  559. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  560. X        fprintf(creatfile, "sizeof(%s%s)", uptiname, POSTFIXTRANSRES);
  561. X#else /* HETEROGENEOUS */
  562. X        fprintf(creatfile, "xdr_%s%s", uptiname, POSTFIXTRANSRES);
  563. X#endif
  564. X        fprintf(creatfile, ", %d) < 0) {\n", TRANSRESTIME);
  565. X        fputs("\t\tif (Errno != ETIMEOUT)\n", creatfile);
  566. X        fprintf(creatfile, "\t\t\t_RuntimeError(\"receiving transaction result (%s@%s)\");\n",
  567. X        symbol->name, actions->name);
  568. X    fputs("\t}\n", creatfile);
  569. X    fputs("\tif (_close_connection(&_con_port))\n", creatfile);
  570. X        fprintf(creatfile, "\t\t_RuntimeError(\"during %s@%s\");\n",
  571. X        symbol->name, actions->name);
  572. X    fputs("\t/* check for error */\n", creatfile);
  573. X    fprintf(creatfile, "\tif (dcc_res.%s.Errno != OK) {\n", ptiname);
  574. X    fprintf(creatfile, "\t\terrno = dcc_res.%s.errno;\n", ptiname);
  575. X        fprintf(creatfile, "\t\t_RuntimeError(\"transaction error (%s@%s)\");\n\t}\n",
  576. X        symbol->name, actions->name);
  577. X    fputs("\t/* return result */\n", creatfile);
  578. X        fprintf(creatfile, "\treturn(dcc_res.%s.result);\n", ptiname);
  579. X        fprintf(creatfile, "} /* call_%s */\n", ptiname);
  580. X    } /* for */
  581. X    return(OK);
  582. X} /* gen_call_transaction_routines */
  583. X
  584. X/******************************************************************************
  585. X * generate_call_transaction_code()                                           *
  586. X *                                                                            *
  587. X * Generates the code to call a particular transaction.                       *
  588. X *                                                                            *
  589. X * Return values: pointer to generated code string upon success /             *
  590. X *                NULL upon error or during error handling                    *
  591. X ******************************************************************************/
  592. Xchar *
  593. Xgenerate_call_transaction_code(duration, target, symbol, arg, expr)
  594. Xchar      *duration,    /* time limit */
  595. X          *target,    /* called process */
  596. X          *expr;    /* expression to execute if timeout */
  597. XSYMBTABEL *symbol;    /* pointer to transaction declaration */
  598. XARG_LIST  *arg;        /* arguments */
  599. X{
  600. X    int        i;
  601. X    char      *cmd;
  602. X    ARG_LIST  *hptr;
  603. X    SYMBTABEL *params;
  604. X
  605. X    if (errflag || !symbol) /* error handling! */
  606. X        return(NULL);
  607. X#ifdef CODEDEBUG
  608. X    fputs("[code] ***** generate_call_transaction_code():\n", debugfile);
  609. X    fprintf(debugfile, "[code] params: duration = %s\n", duration);
  610. X    fprintf(debugfile, "[code]         target   = %s\n", target);
  611. X    fprintf(debugfile, "[code]         expr     = %s\n", expr);
  612. X    fprintf(debugfile, "[code]         symbol = %d, arg = %d\n", symbol, arg);
  613. X    if (arg)
  614. X        fputs("[code]    the arguments are:\n", debugfile);
  615. X    for(hptr = arg, i = 1; hptr; hptr = hptr->next, ++i) 
  616. X        fprintf(debugfile, "[code]    arg %d: %s\n", i, hptr->code);
  617. X#endif /* CODEDEBUG /**/
  618. X    if (!duration) {
  619. X    /* transaction call without time limit */
  620. X        cmd = strmalloc("call_");
  621. X        cmd = Strcatmany(cmd, 3, symbol->info.trans.ptiname, "(", target);
  622. X        for(params=symbol->info.trans.FirstParam, hptr=arg; params;
  623. X                params=params->info.varorpar.NextParam, hptr=hptr->next) {
  624. X        if (!hptr) {
  625. X            strcpy(yytext, "");
  626. X            Errno = WTRANSARGS;
  627. X            Warning("");
  628. X            break;
  629. X        }
  630. X        cmd = Strcatmany(cmd, 2, ", ", hptr->code);
  631. X        }
  632. X        cmd = Strcat(cmd, ", CALL)");
  633. X    } else {
  634. X    /* transaction call with time limit */
  635. X    cmd = strmalloc("(!_make_transaction_call((");
  636. X    cmd = Strcatmany(cmd, 9, target, ").port, \"",
  637. X        symbol->info.trans.uptiname, "\", ", duration, ")) ? (call_",
  638. X        symbol->info.trans.ptiname, "(", target);
  639. X        for(params=symbol->info.trans.FirstParam, hptr=arg; params;
  640. X                params=params->info.varorpar.NextParam, hptr=hptr->next) {
  641. X        if (!hptr) {
  642. X            strcpy(yytext, "");
  643. X            Errno = WTRANSARGS;
  644. X            Warning("");
  645. X            break;
  646. X        }
  647. X        cmd = Strcatmany(cmd, 2, ", ", hptr->code);
  648. X        }
  649. X        cmd = Strcatmany(cmd, 2, ", DONTCALL)) : ", expr);
  650. X    Free(duration);
  651. X        Free(expr);
  652. X    }
  653. X    Free(target);
  654. X    return(cmd);
  655. X} /* generate_call_transaction_code */
  656. X
  657. X/******************************************************************************
  658. X * generate_transaction_code()                                                *
  659. X *                                                                            *
  660. X * Generates the code for accepting a particular transaction.                 *
  661. X *                                                                            *
  662. X * Return values: pointer to generated code string upon success /             *
  663. X *                NULL upon error or during error handling                    *
  664. X ******************************************************************************/
  665. Xchar *
  666. Xgenerate_transaction_code(attr)
  667. XACCEPTATTR *attr;
  668. X{
  669. X    char      *cs, 
  670. X               tmpstr[20],
  671. X          *processname,
  672. X              *ptiname,
  673. X              *uptiname; 
  674. X    SYMBTABEL *symbol,
  675. X              *params;
  676. X    COMPATTR  *comp_attr;
  677. X
  678. X    if (errflag || !attr) /* error handling! */
  679. X    return(NULL);
  680. X#ifdef CODEDEBUG
  681. X    fputs("[code] ***** generate_transaction_code():\n", debugfile);
  682. X#endif /* CODEDEBUG /**/
  683. X    processname = attr->transaction->info.trans.Process->name;
  684. X    ptiname     = attr->transaction->info.trans.ptiname;
  685. X    uptiname    = attr->transaction->info.trans.uptiname;
  686. X    symbol      = attr->transaction;
  687. X    comp_attr   = attr->comp_attr;
  688. X
  689. X    cs = strmalloc("\n/* accept transaction ");
  690. X    cs = Strcatmany(cs, 2, attr->transaction->name, " */\n{\n");
  691. X
  692. X    if (symbol->info.trans.FirstParam) {
  693. X        for(params=symbol->info.trans.FirstParam; params; params=params->info.varorpar.NextParam) {
  694. X        cs = convert_ds_to_string(cs, params->info.varorpar.DataType); 
  695. X        cs = Strcatmany(cs, 2, params->name, ";\n");
  696. X    }
  697. X    }
  698. X    cs = convert_ds_to_string(cs, symbol->info.trans.ReturnType);
  699. X    cs = Strcat(cs, "_transaction_result;\n\n");
  700. X
  701. X    cs = Strcat(cs, "if (_get_transaction_call(\"");
  702. X    cs = Strcatmany(cs, 2, uptiname, "\"))\n");
  703. X    cs = Strcatmany(cs, 3, "_RuntimeError(\"", processname, ": accepting transaction\");\n");
  704. X
  705. X    if (symbol->info.trans.FirstParam) {
  706. X#ifdef HETEROGENEOUS
  707. X    /* We must clear the memory where the received data will be 
  708. X     * stored in, because the xdr routines allocate storage for 
  709. X     * pointers only if the pointer values equal the NULL pointer!!
  710. X     */
  711. X    cs = Strcat(cs, "/* clear structure to handle pointers correctly */\n");
  712. X    cs = Strcatmany(cs, 6, "bzero(&dcc_par.", ptiname, ", sizeof(",
  713. X        uptiname, POSTFIXTRANSPAR, "));\n");
  714. X#endif
  715. X    cs = Strcat(cs, "/* transaction was called, now get parameters */\n");
  716. X    sprintf(tmpstr, "%d", ACCEPTPARTIME);
  717. X    cs = Strcat(cs, "if (_recv_data");
  718. X#ifdef HETEROGENEOUS
  719. X    cs = Strcat(cs, "_encoded");
  720. X#endif
  721. X    cs = Strcatmany(cs, 2, "(&_con_port, (char *) &dcc_par.", ptiname);
  722. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  723. X    cs = Strcatmany(cs, 4, ", sizeof(", uptiname, POSTFIXTRANSPAR, ")");
  724. X#else /* HETEROGENEOUS */
  725. X    cs = Strcatmany(cs, 3, ", xdr_", uptiname, POSTFIXTRANSPAR);
  726. X#endif
  727. X    cs = Strcatmany(cs, 3, ",", tmpstr, ") < 0){\n");
  728. X    cs = Strcat(cs, "if (Errno == ETIMEOUT)\nErrno = ETARCVPARAMS;\n");
  729. X        cs = Strcatmany(cs, 5, "_RuntimeError(\"", processname, ": ", 
  730. X        symbol->name, "\");\n}\n");
  731. X        cs = Strcat(cs, "/* initialize parameters */\n");
  732. X        for(params=symbol->info.trans.FirstParam; params; params=params->info.varorpar.NextParam)
  733. X        cs = Strcatmany(cs, 6, params->name, " = dcc_par.", ptiname, ".", 
  734. X        params->name, ";\n");
  735. X    }
  736. X
  737. X    if (*comp_attr->decls != 0 || *comp_attr->stats != 0) {
  738. X        cs = Strcat(cs, "/* execute transaction */\n");
  739. X        cs = Strcatmany(cs, 5, "{\n", comp_attr->decls, "\n", comp_attr->stats, "\n}\n"); 
  740. X        sprintf(tmpstr, "tlabel_%d:\n", symbol->info.trans.labnum);
  741. X        cs = Strcat(cs, tmpstr);
  742. X    }
  743. X
  744. X    cs = Strcat(cs, "/* send result back to caller */\n");
  745. X    cs = Strcatmany(cs, 3, "dcc_res.", ptiname, ".result = _transaction_result;\n");
  746. X    cs = Strcatmany(cs, 3, "dcc_res.", ptiname, ".Errno = OK;\n");
  747. X    sprintf(tmpstr, "%d", ACCEPTRESTIME);
  748. X    cs = Strcat(cs, "if (_send_data");
  749. X#ifdef HETEROGENEOUS
  750. X    cs = Strcat(cs, "_encoded");
  751. X#endif
  752. X    cs = Strcatmany(cs, 2, "(&_con_port, (char *) &dcc_res.", ptiname);
  753. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  754. X    cs = Strcatmany(cs, 4, ", sizeof(", uptiname, POSTFIXTRANSRES, ")");
  755. X#else /* HETEROGENEOUS */
  756. X    cs = Strcatmany(cs, 3, ", xdr_", uptiname, POSTFIXTRANSRES);
  757. X#endif
  758. X    cs = Strcatmany(cs, 3, ",", tmpstr, ") < 0){\n");
  759. X    cs = Strcat(cs, "if (Errno == ETIMEOUT)\nErrno = ETASNDRESULT;\n");
  760. X    cs = Strcatmany(cs, 5, "_RuntimeError(\"", processname, ": ", symbol->name,
  761. X    "\");\n}\n");
  762. X
  763. X    cs = Strcat(cs, "if (_close_connection(&_con_port))\n");
  764. X    cs = Strcatmany(cs, 3, "_RuntimeError(\"", processname, "\");\n");
  765. X    cs = Strcatmany(cs, 3, "} /* accept transaction ", attr->transaction->name, " */\n");
  766. X    return(cs);
  767. X} /* generate_transaction_code */
  768. X
  769. X/******************************************************************************
  770. X * generate_treturn_code()                                                    *
  771. X *                                                                            *
  772. X * Generates the code for the statement 'treturn'.                            *
  773. X *                                                                            *
  774. X * Return values: pointer to generated code string upon success /             *
  775. X *                NULL upon error or during error handling                    *
  776. X ******************************************************************************/
  777. Xchar *
  778. Xgenerate_treturn_code(expression)
  779. Xchar *expression;
  780. X{
  781. X    char *cs, tmpstr[20];
  782. X
  783. X    if (errflag) /* error handling! */
  784. X    return(NULL);
  785. X#ifdef CODEDEBUG
  786. X    fputs("[code] ***** generate_treturn_code():\n", debugfile);
  787. X#endif /* CODEDEBUG /**/
  788. X    cs = strmalloc("{ ");
  789. X    if (expression)
  790. X    cs = Strcatmany(cs, 3, "_transaction_result = ", expression, "; "); 
  791. X    sprintf(tmpstr, "tlabel_%d", translabel);
  792. X    cs = Strcatmany(cs, 3, "goto ", tmpstr, "; }\n");
  793. X    return(cs);
  794. X} /* generate_treturn_code */
  795. END_OF_FILE
  796. if test 17142 -ne `wc -c <'dcc/code_trans.c'`; then
  797.     echo shar: \"'dcc/code_trans.c'\" unpacked with wrong size!
  798. fi
  799. # end of 'dcc/code_trans.c'
  800. fi
  801. if test -f 'examples/travel/travel.dc' -a "${1}" != "-c" ; then 
  802.   echo shar: Will not clobber existing file \"'examples/travel/travel.dc'\"
  803. else
  804. echo shar: Extracting \"'examples/travel/travel.dc'\" \(16790 characters\)
  805. sed "s/^X//" >'examples/travel/travel.dc' <<'END_OF_FILE'
  806. X/***************************************************************************
  807. X *                                                                         *
  808. X * @@@@  @@@ @@@@@ @@@@@ @@@@@ @@@ @@@@  @   @ @@@@@ @@@@@ @@@@       @@@  *
  809. X * @   @  @  @       @   @   @  @  @   @ @   @   @   @     @   @     @   @ *
  810. X * @   @  @  @@@@@   @   @@@@@  @  @@@@@ @   @   @   @@@@@ @   @     @     *
  811. X * @   @  @      @   @   @ @    @  @   @ @   @   @   @     @   @     @   @ *
  812. X * @@@@  @@@ @@@@@   @   @  @  @@@ @@@@  @@@@@   @   @@@@@ @@@@       @@@  *
  813. X *                                                                         *
  814. X *              A compiler for distributed programming with C              *
  815. X *                                                                         *
  816. X *                          t r a v e l . d c                              *
  817. X *                                                                         *
  818. X *                 Version 1.0      CreationDate: 29.07.91                 *
  819. X *                                    LastUpDate: 29.07.91                 *
  820. X *                                                                         *
  821. X *                     The traveling salesman problem.                     *
  822. X *                 A solution implemented in Distributed C.                *
  823. X *                                                                         *
  824. X *                Copyright (C) 1991 by Christoph Pleier.                  *
  825. X *                          All rights reserved!                           *
  826. X ***************************************************************************/
  827. X
  828. X#include <stdio.h>
  829. X#undef stdin
  830. X#undef stdout
  831. X#undef stderr
  832. X#include <stdlib.h>
  833. X#include "config.h"
  834. X
  835. X#define DEBUG /**/
  836. X
  837. X/****************************************************************************
  838. X *         name : print_route                                               *
  839. X *         type : function definition                                       *
  840. X *   returntype : void                                                      *
  841. X *   parameters : WAYINFO way                                               *
  842. X *  description : Prints the names of the cities stored as way in 'way'.    *
  843. X ****************************************************************************/
  844. Xvoid print_route(comment, way)
  845. Xchar *comment;
  846. XWAYINFO way;
  847. X{
  848. X    register int i;
  849. X    static char str[2000];
  850. X    extern char *unity;
  851. X    extern NAMEINFO data_cities[CITYNUM];
  852. X
  853. X    str[0] = '\0';
  854. X    for(i = 0; i < way.num; ) {
  855. X    strcat(str, data_cities[way.way[i]].name); 
  856. X    if (++i < way.num)
  857. X        strcat(str, " -> ");
  858. X    }
  859. X    printf("%s %s%s, length = %d %s\n", _processprefix, comment, str, 
  860. X    way.length, unity);
  861. X} /* print_route */
  862. X/****************************************************************************
  863. X *         name : relate_name                                               *
  864. X *         type : function definition                                       *
  865. X *   returntype : int                                                       *
  866. X *   parameters : char *name                                                *
  867. X *  description : Relates a real name to an intern name and returns the     *
  868. X *                result or -1 if the name was not found in the data_table. *
  869. X ****************************************************************************/
  870. Xint relate_name(name)
  871. Xchar *name;
  872. X{
  873. X    register int i;
  874. X    extern NAMEINFO data_cities[CITYNUM];
  875. X
  876. X    for (i = 0; i < CITYNUM; i++)
  877. X    if (!strcmp(name, data_cities[i].name))
  878. X        return(data_cities[i].num);
  879. X    return(-1);
  880. X} /* relate_name */
  881. X
  882. X/****************************************************************************
  883. X *         name : find_route                                                *
  884. X *         type : function definition                                       *
  885. X *   returntype : WAYINFO                                                   *
  886. X *   parameters : WAYINFO hitherto_way, CITYLIST choosen_cities             *
  887. X *  description : Finds a shortest possible way and returns it as result.   *
  888. X ****************************************************************************/
  889. XWAYINFO find_route(hitherto_way, choosen_cities)
  890. XWAYINFO hitherto_way;    /* the already worked out route */
  891. XCITYLIST *choosen_cities;
  892. X{
  893. X    int     act_city,         /* act_city for visited cities array */
  894. X            i,            /* loop counter */
  895. X            j,            /* loop counter */ 
  896. X            already_visited;    /* city was already visited */
  897. X    WAYINFO res_way,        /* the resulting way */
  898. X            new_way,        /* the new way to test */
  899. X            best_way;        /* the best way found */
  900. X    extern int d_tab[CITYNUM][CITYNUM];
  901. X
  902. X    if (hitherto_way.num >= choosen_cities->citynum) {
  903. X    /* All choosen cities visited. Add starting city to route and return
  904. X     * the result!
  905. X     */
  906. X    res_way = hitherto_way;
  907. X    res_way.way[res_way.num] = res_way.way[0];
  908. X    res_way.length += distance(res_way.way[res_way.num-1], res_way.way[0]);
  909. X    ++res_way.num;
  910. X    return(res_way);
  911. X    } else {
  912. X    /* Determine the shortest possible route by testing all possible
  913. X     * ways through the remainding cities.
  914. X     */
  915. X    best_way.num = 0;
  916. X    for(act_city = 0; act_city < choosen_cities->citynum; act_city++) {
  917. X        i = choosen_cities->cities[act_city];
  918. X
  919. X        /* If the actual city has already been visited, continue with 
  920. X         * the next city stored in the array 'cities'.
  921. X         */
  922. X        already_visited = 0;
  923. X        for(j = 0; j < hitherto_way.num; j++)
  924. X        if (hitherto_way.way[j] == i) {
  925. X            already_visited = 1;
  926. X            break;
  927. X        }
  928. X        if (already_visited)
  929. X        continue;
  930. X
  931. X        /* Determine route with regard to the actual city.
  932. X         */
  933. X        new_way = hitherto_way;
  934. X        new_way.way[new_way.num] = i;
  935. X        new_way.length += distance(new_way.way[new_way.num-1], i);
  936. X        ++new_way.num;
  937. X        res_way = find_route(new_way, choosen_cities);
  938. X
  939. X        /* If the found route is shorter than the stored route, store
  940. X         * this route as best path.
  941. X         */
  942. X        if (best_way.num == 0)
  943. X        best_way = res_way;
  944. X        else
  945. X        if (best_way.length > res_way.length)
  946. X            best_way = res_way;
  947. X    } /* for(act_city) */
  948. X    return(best_way);
  949. X    }
  950. X} /* find_route */
  951. X
  952. X/****************************************************************************
  953. X *         name : choose_cities                                             *
  954. X *         type : function definition                                       *
  955. X *   returntype : none                                                      *
  956. X *   parameters : none                                                      *
  957. X *  description : Function to enter a list of availible cities.             *
  958. X ****************************************************************************/
  959. Xvoid choose_cities(choosen_cities)
  960. XCITYLIST *choosen_cities;
  961. X{
  962. X    register int j;
  963. X    int          i = 0, 
  964. X                 intern_name,
  965. X                 flag;
  966. X    char         input[100];
  967. X    extern NAMEINFO data_cities[CITYNUM];
  968. X
  969. X    puts("\nEnter city names and press return after each name!");
  970. X    puts("Type 'list' to list availible cities!");
  971. X    puts("Type 'done' to finish input!");
  972. X    do {
  973. X        printf("%d. city? ", i + 1);
  974. X        scanf("%s", input);
  975. X
  976. X        if (!strcmp(input, "done"))
  977. X        break;
  978. X
  979. X    if (!strcmp(input, "list")) {
  980. X            for(j = 0; j < CITYNUM; j++)
  981. X                printf("%s, ", data_cities[j].name);
  982. X            puts("\b\b.   ");
  983. X        continue;
  984. X    }
  985. X
  986. X        if ((intern_name = relate_name(input)) == -1) {
  987. X        puts("This city is not availible in the table! Try another one.");
  988. X        continue;
  989. X    }
  990. X
  991. X    for(flag = j = 0; j < i; j++)
  992. X        if (intern_name == choosen_cities->cities[j]) {
  993. X        flag = 1;
  994. X        break;
  995. X        }
  996. X    if (flag) {
  997. X        puts("This city is already in the route! Try another one.");
  998. X        continue;
  999. X    }
  1000. X
  1001. X    choosen_cities->cities[i] = relate_name(input);
  1002. X    i++;
  1003. X    } while(i < CITYNUM);
  1004. X    choosen_cities->citynum = i;
  1005. X} /* choose_cities */
  1006. X
  1007. X/****************************************************************************
  1008. X *         name : collect_results                                           *
  1009. X *         type : process specification                                     *
  1010. X *   returntype : impossible                                                *
  1011. X *   parameters : long processnum                                           *
  1012. X *  description :                                                           *
  1013. X ****************************************************************************/
  1014. Xprocess spec collect_results(long processnum)
  1015. X{
  1016. X    trans void write_route(WAYINFO way);
  1017. X}
  1018. X
  1019. X/****************************************************************************
  1020. X *         name : collect_results                                           *
  1021. X *         type : process definition                                        *
  1022. X *   returntype : impossible                                                *
  1023. X *   parameters : long processnum                                           *
  1024. X *  description :                                                           *
  1025. X ****************************************************************************/
  1026. Xprocess body collect_results(processnum)
  1027. X{
  1028. X    int i;
  1029. X    WAYINFO best_way;
  1030. X    extern char *unity;
  1031. X    extern NAMEINFO data_cities[CITYNUM];
  1032. X    extern int d_tab[CITYNUM][CITYNUM];
  1033. X
  1034. X#ifdef DEBUG
  1035. X    printf("%s started!\n", _processprefix);
  1036. X    fflush(stdout);
  1037. X#endif /* DEBUG /**/
  1038. X    best_way.length = 0;
  1039. X    do {
  1040. X    accept write_route(way) {
  1041. X        if (best_way.length > way.length || best_way.length == 0)
  1042. X            best_way = way;
  1043. X    }
  1044. X    processnum--;
  1045. X    } while(processnum > 0);
  1046. X    puts("\nOne possible shortest way is: ");
  1047. X    for(i = 0; i < best_way.num; i++) {
  1048. X    printf("%s -> ", data_cities[best_way.way[i]].name); 
  1049. X    }
  1050. X    printf("\b\b\b\b.    \nThe length is %d %s.\n", best_way.length, unity); 
  1051. X    exit(0);
  1052. X} /* process collect_results */
  1053. X
  1054. X/****************************************************************************
  1055. X *         name : build_route                                               *
  1056. X *         type : process specification                                     *
  1057. X *   returntype : impossible                                                *
  1058. X *   parameters :                                                           *
  1059. X *  description :                                                           *
  1060. X ****************************************************************************/
  1061. Xprocess spec build_route(process collect_results cr_descr,
  1062. X             WAYINFO hitherto_way,
  1063. X             CITYLIST choosen_cities,
  1064. X             int stage);
  1065. X
  1066. X/****************************************************************************
  1067. X *         name : build_route                                               *
  1068. X *         type : process definition                                        *
  1069. X *   returntype : impossible                                                *
  1070. X *   parameters :                                                           *
  1071. X *  description :                                                           *
  1072. X ****************************************************************************/
  1073. Xprocess body build_route(cr_descr, hitherto_way, choosen_cities, stage)
  1074. X{
  1075. X    int     act_city,              /* act_city for visited cities array */
  1076. X            i,                  /* loop counter */
  1077. X            j,                  /* loop counter */
  1078. X            already_visited;    /* city was already visited */
  1079. X    WAYINFO new_way;            /* the new way to test */
  1080. X    extern char *unity;
  1081. X    extern NAMEINFO data_cities[CITYNUM];
  1082. X    extern int d_tab[CITYNUM][CITYNUM];
  1083. X           
  1084. X#ifdef DEBUG
  1085. X    printf("%s started!\n", _processprefix);
  1086. X    print_route("hitherto route is ", hitherto_way);
  1087. X    fflush(stdout);
  1088. X#endif /* DEBUG /**/
  1089. X    if (stage == 0) {
  1090. X    /* No more processes to start. Determine the shortest route with
  1091. X     * regard to all remainding cities and send the result to the 
  1092. X     * process 'collect_results'.
  1093. X     */
  1094. X    cr_descr@write_route(find_route(hitherto_way, &choosen_cities));
  1095. X    } else {
  1096. X    /* Still Processes to start. Create for each possible next city on
  1097. X     * the route a process.
  1098. X     */
  1099. X     for(act_city = 0; act_city < choosen_cities.citynum; act_city++) {
  1100. X            i = choosen_cities.cities[act_city];
  1101. X
  1102. X            /* If the actual city has already been visited, continue with
  1103. X             * the next city stored in the array 'cities'.
  1104. X             */
  1105. X            already_visited = 0;
  1106. X            for(j = 0; j < hitherto_way.num; j++)
  1107. X                if (hitherto_way.way[j] == i) {
  1108. X                        already_visited = 1;
  1109. X                        break;
  1110. X                }
  1111. X            if (already_visited)
  1112. X                continue;
  1113. X
  1114. X            /* Create a new process to determine the shortest route with 
  1115. X         * the actual city as next city on path.
  1116. X             */
  1117. X            new_way = hitherto_way;
  1118. X            new_way.way[new_way.num] = i;
  1119. X            new_way.length += distance(new_way.way[new_way.num-1], i);
  1120. X            ++new_way.num;
  1121. X            create build_route(cr_descr, new_way, choosen_cities, stage -1);
  1122. X    } /* for(act_city) */
  1123. X    }
  1124. X    exit(0);
  1125. X} /* process build_route */
  1126. X
  1127. X/****************************************************************************
  1128. X *         name : main                                                      *
  1129. X *         type : function definition                                       *
  1130. X *   returntype : int                                                       *
  1131. X *   parameters : none                                                      *
  1132. X *  description : Definition of the main function building the main program.*
  1133. X ****************************************************************************/
  1134. Xmain()
  1135. X{
  1136. X    int      i,            /* loop counter */
  1137. X             intern_name,    /* intern name of a city */
  1138. X             flag,        /* dummy flag handling error check */
  1139. X             stage,        /* stage of parallesim */
  1140. X             max_stage,        /* maximal allowed stage */
  1141. X             res;        /* dummy result variable */
  1142. X    char     input[100];    /* to store various user input */
  1143. X    CITYLIST choosen_cities;    /* the choosen cities */
  1144. X    WAYINFO  way;        /* to store the first way */
  1145. X    extern char *unity;
  1146. X    extern NAMEINFO data_cities[CITYNUM];
  1147. X
  1148. X    puts("\nThe traveling salesman problem.");
  1149. X    puts("Solution implemented by Christoph Pleier using Distributed C");
  1150. X    puts("At the chair for compiler construction of Professor Dr. J. Eickel.");
  1151. X    puts("Technische Universitaet Muenchen.\n");
  1152. X    printf("This is %s. The cities are\n", DESCRIPTION);
  1153. X    for(i = 0; i < CITYNUM; i++)
  1154. X        printf("%s, ", data_cities[i].name);
  1155. X    puts("\b\b.");
  1156. X
  1157. X    printf("\nIs this a round trip through all cities? (y/n) ");
  1158. X    scanf("%s", input);
  1159. X    if (input[0] == 'y' || input[0] == 'Y') {
  1160. X        for(i = 0; i < CITYNUM; i++)
  1161. X        choosen_cities.cities[i] = data_cities[i].num;
  1162. X    choosen_cities.citynum = CITYNUM;
  1163. X    } else
  1164. X    choose_cities(&choosen_cities);
  1165. X
  1166. X    do {
  1167. X    flag = 0;
  1168. X        printf("\nStarting city? ");
  1169. X        scanf("%s", input);
  1170. X    intern_name = relate_name(input);
  1171. X    if (intern_name == -1)
  1172. X        continue;
  1173. X        for(i = 0; i < choosen_cities.citynum; i++)
  1174. X        if (choosen_cities.cities[i] == intern_name)
  1175. X        flag = 1;
  1176. X    if (flag == 0)
  1177. X        puts("This city has not been choosen out. Try another one!");
  1178. X    } while(intern_name == -1 || flag == 0);
  1179. X
  1180. X    way.num    = 1;
  1181. X    way.way[0] = intern_name;
  1182. X    way.length = 0;
  1183. X
  1184. X    for(res = i = 1; i < choosen_cities.citynum; i++)
  1185. X    res *= i;
  1186. X    printf("\nNumber of possible routes is %d.\n", res);
  1187. X
  1188. X    printf("\nDo you want to determine the result sequential or parallel? (s/p) ");
  1189. X    scanf("%s", input);
  1190. X    if (input[0] == 's' || input[0] == 'S') {
  1191. X    way = find_route(way, &choosen_cities);
  1192. X        puts("\nOne possible shortest way is: ");
  1193. X        for(i = 0; i < way.num; i++)
  1194. X        printf("%s -> ", data_cities[way.way[i]].name); 
  1195. X        printf("\b\b\b\b.    \nThe length is %d %s.\n", way.length, unity); 
  1196. X    exit(0);
  1197. X    }
  1198. X
  1199. X    puts("\nNumber of processes to create with regard to the state of parallism:\n");
  1200. X    puts("    ---------------------------");
  1201. X    puts("    | stage  | process number |");
  1202. X    puts("    |--------|----------------|");
  1203. X    for(res = i = 1; i < choosen_cities.citynum-1 && res < MAXPNUM; i++) {
  1204. X    res *= choosen_cities.citynum - i;
  1205. X    printf("    | %6d | %14d |\n", i+1, res);
  1206. X    }
  1207. X    puts("    ---------------------------");
  1208. X    max_stage = i;
  1209. X
  1210. X    do {
  1211. X        do {
  1212. X            printf("\nStage of parallelism? (2..%d) ", max_stage);
  1213. X            scanf("%d", &stage);
  1214. X        } while(stage < 2 || stage > max_stage);
  1215. X        for(res = i = 1; i < stage; i++)
  1216. X        res *= choosen_cities.citynum - i;
  1217. X        printf("Do you really want to generate %d processes? (y/n) ", res);
  1218. X        scanf("%s", input);
  1219. X    } while(input[0] != 'y' && input[0] != 'Y');
  1220. X
  1221. X    create build_route(create collect_results(res) local, way, choosen_cities, stage-1);
  1222. X
  1223. X    exit(0);
  1224. X}
  1225. END_OF_FILE
  1226. if test 16790 -ne `wc -c <'examples/travel/travel.dc'`; then
  1227.     echo shar: \"'examples/travel/travel.dc'\" unpacked with wrong size!
  1228. fi
  1229. # end of 'examples/travel/travel.dc'
  1230. fi
  1231. if test -f 'include/config.h' -a "${1}" != "-c" ; then 
  1232.   echo shar: Will not clobber existing file \"'include/config.h'\"
  1233. else
  1234. echo shar: Extracting \"'include/config.h'\" \(17581 characters\)
  1235. sed "s/^X//" >'include/config.h' <<'END_OF_FILE'
  1236. X/***************************************************************************
  1237. X *                                                                         *
  1238. X * @@@@  @@@ @@@@@ @@@@@ @@@@@ @@@ @@@@  @   @ @@@@@ @@@@@ @@@@       @@@  *
  1239. X * @   @  @  @       @   @   @  @  @   @ @   @   @   @     @   @     @   @ *
  1240. X * @   @  @  @@@@@   @   @@@@@  @  @@@@@ @   @   @   @@@@@ @   @     @     *
  1241. X * @   @  @      @   @   @ @    @  @   @ @   @   @   @     @   @     @   @ *
  1242. X * @@@@  @@@ @@@@@   @   @  @  @@@ @@@@  @@@@@   @   @@@@@ @@@@       @@@  *
  1243. X *                                                                         *
  1244. X *              A compiler for distributed programming with C              *
  1245. X *                                                                         *
  1246. X *                             c o n f i g . h                             *
  1247. X *                                                                         *
  1248. X *                            Package : Include files                      *
  1249. X *                            Version : 1.0                                *
  1250. X *                       CreationDate : 05.07.90                           *
  1251. X *                         LastUpDate : 06.12.93                           *
  1252. X *                                                                         *
  1253. X * The main configuration file of the compiler containing preprocessor     *
  1254. X * definitions, macros, type and structure definitions.                    *
  1255. X *                                                                         *
  1256. X *      Copyright (C) 1990-1994 by Franz Distler and Christoph Pleier.     *
  1257. X *                          All rights reserved!                           *
  1258. X ***************************************************************************/
  1259. X
  1260. X/*
  1261. X * This file is part of the Distributed C Development Environment (DCDE).
  1262. X * DCDE is free software; you can redistribute it and/or modify
  1263. X * it under the terms written in the README-file. 
  1264. X * DCDE is distributed in the hope that it will be useful,
  1265. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1266. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  1267. X * See the file README for more details.
  1268. X */
  1269. X
  1270. X#ifndef __config_h
  1271. X#define __config_h
  1272. X
  1273. X/* ------------------------------ constants ------------------------------ */ 
  1274. X
  1275. X/* general return codes */
  1276. X#define OK        0
  1277. X#define ERROR        -1
  1278. X
  1279. X/* exit codes */
  1280. X#define EXIT_OK        0    /* no error */
  1281. X#define EXIT_FOPEN    1    /* error during opening of a file */
  1282. X#define EXIT_PARSEOPT    2    /* error during parsing of command line args */
  1283. X#define EXIT_INPUTFILE    3    /* error: inputfile does not exist */
  1284. X#define EXIT_CPP    4    /* error: cpp does not work */
  1285. X#define EXIT_PARSING    5    /* error during parsing of input file */
  1286. X#define EXIT_BUILDING    6    /* error during compilation and linking */
  1287. X#define EXIT_HOSTNAME    7    /* error: unable to determine name of host */
  1288. X#define EXIT_FATAL    8     /* fatal error during compilation */
  1289. X#define EXIT_PANIC    9     /* normally impossible error */
  1290. X
  1291. X/* boolean constants */
  1292. X#ifndef TRUE
  1293. X# define TRUE        1
  1294. X# define FALSE        0
  1295. X#endif
  1296. X
  1297. X/* maximal length of  */
  1298. X#define MAXFILENAMELEN    14    /* a filename */
  1299. X#define MAXPATHNAMELEN    256    /* a path name */
  1300. X#define MAXIDLEN    30    /* an identifier */
  1301. X/* NOTE: MAXIDLEN must be smaller than 'request' of 'TRANSDATA' in dcc.h! */
  1302. X
  1303. X/* postfixes of generated names */
  1304. X#define POSTFIXSPECPAR    "_PPAR"    /* process creation parameter types */
  1305. X#define POSTFIXTRANSPAR    "_TPAR"    /* transaction parameter types */
  1306. X#define POSTFIXTRANSRES    "_TRES"    /* transaction result types */
  1307. X
  1308. X/* postfixes of generated filenames */
  1309. X#define MAINFILEEXT    "_dc.c"
  1310. X#define SPECFILEEXT    "_sr.c"    
  1311. X#define FUNCFILEEXT    "_fn.c"
  1312. X#define XDRFILEEXT    "_xdr.c"
  1313. X
  1314. X/* sizes of the symbol table arrays */
  1315. X#define MAXIDNUM    1451    /* size of the ID list table (prime number!) */
  1316. X#define MAXPSTNUM    100    /* size of the PST table */
  1317. X
  1318. X/* the maximal size of code storing strings */
  1319. X#define CODESTRLEN    2000
  1320. X
  1321. X/* To avoid stupid memory allocation errors especially under UNIX SYSTEM V we 
  1322. X * add for safety reasons an additional value to the requested size during 
  1323. X * memory allocation in Malloc().
  1324. X */
  1325. X#if defined(SYSTEM_V) || defined(CONVEX)
  1326. X# define MALLOCADDVAL    100
  1327. X#else
  1328. X# define MALLOCADDVAL    0
  1329. X#endif /* SYSTEM_V /**/
  1330. X
  1331. X/* valid symbol table entry types */
  1332. X#define UDEC        0    /* not declared */
  1333. X#define PROCESSDECL    1    /* process */
  1334. X#define VARORPAR    2    /* variable or parameter */
  1335. X#define TRANSACTION    3    /* transaction */ 
  1336. X#define FUNCTIONDEF    4    /* function definition */
  1337. X#define PROCESSVAR    5    /* process variable */
  1338. X#define TYPEDEFNAME    6    /* type definition */
  1339. X#define STRUCTDECL    7    /* structure declaration */
  1340. X
  1341. X/* name of administration process */
  1342. X#define ADMINPATH    "dcadmin"
  1343. X
  1344. X/* types of alternatives */
  1345. X#define ALT_ACCEPT    1
  1346. X#define ALT_TERMINATE    2
  1347. X#define ALT_IMMEDIATE    3
  1348. X
  1349. X#ifdef iPSC
  1350. X/* nodes and pids of main and admin process */
  1351. X# define MAIN_NODE    0L
  1352. X# define MAIN_PID    0L
  1353. X# define ADMIN_NODE    1L
  1354. X# define ADMIN_PID    1L
  1355. X#endif /* iPSC /**/
  1356. X
  1357. X/* attribute types */
  1358. X#define SCS_ATTR_AUTO        0
  1359. X#define SCS_ATTR_REGISTER    1
  1360. X#define SCS_ATTR_STATIC        2
  1361. X#define SCS_ATTR_EXTERN        3
  1362. X#define SCS_ATTR_TYPEDEF    4
  1363. X#define TS_ATTR_VOID        5
  1364. X#define TS_ATTR_CHAR        6
  1365. X#define TS_ATTR_SHORT        7
  1366. X#define TS_ATTR_INT        8
  1367. X#define TS_ATTR_LONG        9
  1368. X#define TS_ATTR_FLOAT        10
  1369. X#define TS_ATTR_DOUBLE        11
  1370. X#define TS_ATTR_PROCESS        12
  1371. X#define TS_ATTR_SIGNED        13
  1372. X#define TS_ATTR_UNSIGNED    14
  1373. X#define TS_ATTR_ENUM        15
  1374. X#define TS_ATTR_STRUCT        16
  1375. X#define TS_ATTR_TYPENAME    17
  1376. X#define TQ_ATTR_CONST         18
  1377. X#define TQ_ATTR_VOLATILE     19
  1378. X#define SU_ATTR_STRUCT        20
  1379. X#define SU_ATTR_UNION        21
  1380. X#define P_ATTR_1        22
  1381. X#define P_ATTR_2        23
  1382. X#define P_ATTR_3        24
  1383. X#define P_ATTR_4        25
  1384. X#define DD_ATTR_IDENT        26
  1385. X#define DD_ATTR_FUNC        27
  1386. X#define DD_ATTR_ARRAY        28
  1387. X#define DD_ATTR_BRACED        29
  1388. X#define SQL_ATTR_SPECIFIER    30
  1389. X#define SQL_ATTR_QUALIFIER    31
  1390. X
  1391. X#if defined(ATTRDEBUG) || defined(CODEDEBUG) || defined(DECLDEBUG) \
  1392. X    || defined(DEBUG) || defined(STRUCTDEBUG) || defined(SYMBDEBUG) \
  1393. X    || defined(XDRDEBUG) || defined(YYDEBUG)
  1394. X# define DEBUGFLAG
  1395. X#endif
  1396. X
  1397. X/* ------------------------------- macros ------------------------------- */ 
  1398. X
  1399. X#if defined(__STDC__) && !defined(NO_PROTOTYPE)
  1400. X# define FUNCPROTO(type,id,args)    extern type id args
  1401. X#else
  1402. X# define FUNCPROTO(type,id,args)    extern type id()
  1403. X#endif /* __STDC__ /**/
  1404. X
  1405. X#define PRINTERROR(s, c)        Errno = c; Error(NULL, s)
  1406. X
  1407. X#ifdef SYSTEM_V
  1408. X# define bzero(s, n)            memset((char *)(s), '\0', (unsigned)(n))
  1409. X# define bcopy(src, dst, num)        memcpy((dst), (src), (num))
  1410. X#endif /* SYSTEM_V /**/
  1411. X
  1412. X/* -------------------------- type definitions -------------------------- */ 
  1413. X
  1414. X/* the type of a symbol table element */
  1415. Xtypedef struct symbtabel {
  1416. X    char *name;        /* the name of the identifier */
  1417. X    short type;        /* the type of the entry */
  1418. X    int blknum;        /* block depth */
  1419. X    short WasInSysIncl; /* symbol was declared in system include file */
  1420. X
  1421. X    union {
  1422. X
  1423. X        /* variable or parameter:
  1424. X         * ----------------------
  1425. X         * The components are:
  1426. X         * 'DataType' (data type)
  1427. X         *     The type of the variable or parameter (int, long, ...)
  1428. X         *     as declaration specifiers attribute.
  1429. X         * 'NextParam' (next parameter):
  1430. X         *     Pointer to the next parameter in the parameter list
  1431. X         *     (parameters only).
  1432. X         */
  1433. X        struct {
  1434. X            struct ds_attr_t *DataType;
  1435. X            struct symbtabel *NextParam;
  1436. X        } varorpar;
  1437. X
  1438. X        /* transaction:
  1439. X         * ------------
  1440. X         * The components are:
  1441. X         * 'IsDecl' (is declaration):
  1442. X         *     Specifying entry is a declaration or not.
  1443. X         * 'ReturnType' (return type):
  1444. X         *     The return type of the transaction (int, long, ...)
  1445. X         *     as declaration specifiers attribute.
  1446. X         * 'labnum' (label number):
  1447. X         *     The label number used for building the end label 
  1448. X         * 'ptiname' (process transaction intern name):
  1449. X         *     The process transaction intern name (needed for naming).
  1450. X         * 'uptiname' (upcase process transaction intern name):
  1451. X         *     The process transaction intern name in upcase letters 
  1452. X         *     (needed for naming).
  1453. X         * 'Process' (process):
  1454. X         *     Pointer to the process containing this transaction.
  1455. X         * 'FirstParam' (first parameter):
  1456. X         *     Pointer to the first transaction parameter.
  1457. X         * 'NextTrans' (next transaction):
  1458. X         *     Pointer to the next transaction in transaction list.
  1459. X         * 'ReturnType' (return type):
  1460. X         *     Pointer to the declaration_specifiers_attribute
  1461. X         *     specifying the return type.
  1462. X         */
  1463. X        struct {
  1464. X            short IsDecl;
  1465. X            struct ds_attr_t *ReturnType;
  1466. X            int labnum;
  1467. X            char ptiname[MAXIDLEN+1],
  1468. X                 uptiname[MAXIDLEN+1];
  1469. X            struct symbtabel *Process,
  1470. X                             *FirstParam,
  1471. X                             *NextTrans;
  1472. X        } trans;
  1473. X
  1474. X        /* process specification:
  1475. X         * ----------------------
  1476. X         * The components are:
  1477. X         * 'IsSpec' (is specification):
  1478. X         *     Specifying entry is specification or not.
  1479. X         * 'FirstParam' (first parameter):
  1480. X         *     Pointer to the first process parameter.
  1481. X         * 'FirstTrans' (first transaction):
  1482. X         *     Pointer to the first process transaction.
  1483. X         * 'filename' (filename):
  1484. X         *     Name of the file to write the process code into.
  1485. X         * 'piname' (process intern name):
  1486. X         *     The process intern name (for naming).
  1487. X         * 'upiname' (upcase process intern name):
  1488. X         *     The process intern name in upcase letters (for naming).
  1489. X         * 'codefile' (codefile):
  1490. X         *     The file handler to write the process code into.
  1491. X         */
  1492. X        struct {
  1493. X            short IsSpec;
  1494. X            struct symbtabel *FirstParam,
  1495. X                             *FirstTrans;
  1496. X            char filename[MAXFILENAMELEN+1],
  1497. X                 piname[MAXIDLEN+1], 
  1498. X                 upiname[MAXIDLEN+1]; 
  1499. X            FILE *codefile;
  1500. X        } process;
  1501. X
  1502. X        /* function definition:
  1503. X         * --------------------
  1504. X         * The components are:
  1505. X         * 'Returntype' (return type):
  1506. X         *     The return type of the function as string.
  1507. X         */
  1508. X        struct {
  1509. X            char *ReturnType;
  1510. X        } functiondef;
  1511. X
  1512. X        /* type definition:
  1513. X         * ----------------
  1514. X         * The components are:
  1515. X         * 'IsPointer' (is a pointer)
  1516. X         *     Specifying if type definition is a pointer or not.
  1517. X         * 'BuildXDRRoutine' (build XDR routine):
  1518. X         *     Specifying a special XDR routine must be created for
  1519. X         *     this type definition or not.
  1520. X         * 'decl_spec' (declaration specifiers):
  1521. X         *     The corresponding declaration specifiers.
  1522. X         * 'id_list' (init declarator list):
  1523. X         *     The corresponding declarator list.
  1524. X         * 'ErrPos' (error position):
  1525. X         *     The source code position of the definition.
  1526. X         */
  1527. X        struct {
  1528. X            short IsPointer,
  1529. X                      BuildXDRRoutine;
  1530. X            struct ds_attr_t *decl_spec;
  1531. X            struct idl_attr_t *id_list;
  1532. X            char *ErrPos;
  1533. X        } typedefname;
  1534. X
  1535. X        /* structure declaration:
  1536. X         * ----------------------
  1537. X         * The components are:
  1538. X         * 'IsStruct' (is structure)
  1539. X         *     Specifying if entry is struct or union.
  1540. X         * 'BuildXDRRoutine' (build XDR routine):
  1541. X         *     Specifying a special XDR routine must be created for
  1542. X         *     this type definition or not.
  1543. X         * 'StruDeclList' (struct declaration list):
  1544. X         *     The corresponding struct declaration list.
  1545. X         * 'ErrPos' (error position):
  1546. X         *     The source code position of the definition.
  1547. X         */
  1548. X        struct {
  1549. X            short IsStruct,
  1550. X                      BuildXDRRoutine;
  1551. X            struct stl_attr_t *StruDeclList;
  1552. X            char *ErrPos;
  1553. X        } structdecl;
  1554. X
  1555. X    } info;
  1556. X
  1557. X    struct symbtabel *IdNext,    /* next entry in ID list */
  1558. X                     *PstNext;    /* next entry in PST list */
  1559. X} SYMBTABEL;
  1560. X
  1561. X/* the type of the symbol table */
  1562. Xtypedef struct {
  1563. X    struct symbtabel *IdTab[MAXIDNUM],
  1564. X                     *PstTab[MAXPSTNUM];
  1565. X} SYMBTAB;
  1566. X
  1567. Xtypedef struct {
  1568. X    SYMBTABEL *symbol;
  1569. X    char name[MAXIDLEN];
  1570. X} IDENTINFO;
  1571. X
  1572. X/* identifier chain:
  1573. X * this structure is used to chain identifiers
  1574. X */
  1575. Xtypedef struct ident_chain_t {
  1576. X    SYMBTABEL            *symbol;
  1577. X    struct ident_chain_t *next;
  1578. X} IDENTCHAIN;
  1579. X
  1580. X/* argument expression list:
  1581. X * this structure is used to store the code of the several actual parameters
  1582. X * during process creation or transaction calls
  1583. X */
  1584. Xtypedef struct arg_list {
  1585. X    char            *code;    /* code of the argument */
  1586. X    struct arg_list *next;    /* next argument */
  1587. X} ARG_LIST;
  1588. X
  1589. X/* compound statement attribute:
  1590. X * this structure contains the two parts of a compound statement as strings
  1591. X */
  1592. Xtypedef struct comp_attr_t {
  1593. X    char *decls,        /* declarations */
  1594. X         *stats;        /* statements */
  1595. X} COMPATTR;
  1596. X
  1597. X/* accept statement attribute:
  1598. X * contains the peculiar information of an accept statement
  1599. X */
  1600. Xtypedef struct accept_attr_t {
  1601. X    SYMBTABEL          *transaction; /* transaction */
  1602. X    struct comp_attr_t *comp_attr;   /* body */
  1603. X} ACCEPTATTR;
  1604. X
  1605. X/* select statement attribute:
  1606. X * contains the peculiar information of an select statement alternative
  1607. X */
  1608. Xtypedef struct select_attr_t {
  1609. X    int                   type;        /* type of the alternative */
  1610. X    char                 *guard,       /* guard */
  1611. X                         *stats;       /* additional alternative code */
  1612. X    struct accept_attr_t *accept_attr; /* info of an accept alternative */
  1613. X    struct select_attr_t *next;        /* pointer to next alternative */
  1614. X} SELECTATTR;
  1615. X
  1616. X/* postfix statement attribute:
  1617. X * this structure is used to store the code of the postfix expression
  1618. X * and a pointer to the valid symbols in the symbol table
  1619. X */
  1620. Xtypedef struct post_attr_t {
  1621. X    char       *codestr;
  1622. X    IDENTCHAIN *idents;
  1623. X} POSTATTR;
  1624. X
  1625. X/* transaction attribute:
  1626. X * this structure is used to collect the information of a transaction call
  1627. X */
  1628. Xtypedef struct trans_attr_t {
  1629. X    char      *target;    /* code of the postfix expression */
  1630. X    SYMBTABEL *symbol;    /* pointer to the specified transaction */
  1631. X    ARG_LIST  *arg;        /* transaction arguments */
  1632. X} TRANSATTR;
  1633. X
  1634. X/* storage class specifier attribute:
  1635. X */
  1636. Xtypedef struct scs_attr_t {
  1637. X    char type;        /* auto, register, static, extern, typedef */
  1638. X} SCS_ATTR;
  1639. X
  1640. X/* type specifier attribute:
  1641. X */
  1642. Xtypedef struct ts_attr_t {
  1643. X    char type;    /* elementar, struct/union, typedefname */
  1644. X    union {
  1645. X        struct es_attr_t  *enuminfo; 
  1646. X        struct sus_attr_t *structinfo;
  1647. X        SYMBTABEL *typedefname,
  1648. X                  *process;
  1649. X    } info;
  1650. X} TS_ATTR;
  1651. X
  1652. X/* type qualifier attribute:
  1653. X */
  1654. Xtypedef struct tq_attr_t {
  1655. X    char type;        /* const, volatile */
  1656. X} TQ_ATTR;
  1657. X
  1658. X/* enumeration attribute:
  1659. X */
  1660. Xtypedef struct es_attr_t {
  1661. X    char *codestr;
  1662. X} ES_ATTR;
  1663. X
  1664. X/* struct or union attribute:
  1665. X */
  1666. Xtypedef struct su_attr_t {
  1667. X    char type;        /* struct, union */
  1668. X} SU_ATTR;
  1669. X
  1670. X/* type qualifier list attribute:
  1671. X */
  1672. Xtypedef struct tql_attr_t {
  1673. X    TQ_ATTR *type_qualifier;
  1674. X    struct tql_attr_t *tq_list;
  1675. X} TQL_ATTR;
  1676. X
  1677. X/* pointer attribute:
  1678. X */
  1679. Xtypedef struct p_attr_t {
  1680. X    char type;
  1681. X    TQL_ATTR *quali_list;
  1682. X    struct p_attr_t *pointer;
  1683. X} P_ATTR;
  1684. X
  1685. X/* direct declarator attribute:
  1686. X */
  1687. Xtypedef struct dd_attr_t {
  1688. X    char type;
  1689. X    SYMBTABEL *ident;
  1690. X    union {
  1691. X        struct d_attr_t *declarator;
  1692. X        struct {
  1693. X            struct dd_attr_t *direct_decl;
  1694. X            char *spec_str;
  1695. X        } comp;
  1696. X    } info;
  1697. X} DD_ATTR;
  1698. X
  1699. X/* declarator attribute:
  1700. X */
  1701. Xtypedef struct d_attr_t {
  1702. X    P_ATTR  *pointer;
  1703. X    DD_ATTR *direct_decl;
  1704. X} D_ATTR;
  1705. X
  1706. X/* struct declarator attribute:
  1707. X */
  1708. Xtypedef struct sd_attr_t {
  1709. X    D_ATTR *decl;
  1710. X    char   *const_expr;
  1711. X} SD_ATTR;
  1712. X
  1713. X/* struct declarator list attribute:
  1714. X */
  1715. Xtypedef struct sdl_attr_t {
  1716. X    SD_ATTR           *struct_declarator;
  1717. X    struct sdl_attr_t *sd_list;
  1718. X} SDL_ATTR;
  1719. X
  1720. X/* specifier qualifier list attribute:
  1721. X */
  1722. Xtypedef struct sql_attr_t {
  1723. X    char type;     /* specifier or qualifier */
  1724. X    union {
  1725. X        TS_ATTR *type_specifier;
  1726. X        TQ_ATTR *type_qualifier;
  1727. X    } info;
  1728. X    struct sql_attr_t *sq_list;
  1729. X} SQL_ATTR;
  1730. X
  1731. X/* struct declaration attribute:
  1732. X */
  1733. Xtypedef struct st_attr_t {
  1734. X    SQL_ATTR *spec_qual_list;
  1735. X    SDL_ATTR *struct_decl_list;
  1736. X} ST_ATTR;
  1737. X
  1738. X/* struct declaration list attribute:
  1739. X */
  1740. Xtypedef struct stl_attr_t {
  1741. X    ST_ATTR           *struct_decl;
  1742. X    struct stl_attr_t *st_list;
  1743. X} STL_ATTR;
  1744. X
  1745. X/* struct or union specifier attribute:
  1746. X */
  1747. Xtypedef struct sus_attr_t {
  1748. X    SU_ATTR   *struct_or_union;
  1749. X    SYMBTABEL *tag;
  1750. X    STL_ATTR  *struct_decl_list;
  1751. X} SUS_ATTR;
  1752. X
  1753. X/* init_declarator_attribute:
  1754. X */
  1755. Xtypedef struct id_attr_t {
  1756. X    D_ATTR *d;    /* declarator */
  1757. X    char   *inistr;    /* initializer */
  1758. X} ID_ATTR;
  1759. X    
  1760. X/* init declarator list attribute:
  1761. X */
  1762. Xtypedef struct idl_attr_t {
  1763. X    struct idl_attr_t *id_list;    /* init declarator list */
  1764. X    ID_ATTR           *id;        /* init declarator */
  1765. X} IDL_ATTR;
  1766. X
  1767. X/* declaration specifiers attribute:
  1768. X */
  1769. Xtypedef struct ds_attr_t {
  1770. X    SCS_ATTR         *scs;    /* storage class specifier */
  1771. X    TS_ATTR          *ts;    /* type specifier */
  1772. X    TQ_ATTR          *tq;    /* type qualifier */
  1773. X    struct ds_attr_t *ds;     /* declaration specifiers */
  1774. X} DS_ATTR;
  1775. X
  1776. X/* ------------------------ structure definitions ------------------------ */ 
  1777. X
  1778. X/* process filename list:
  1779. X * the names of the processfiles are stored in this list
  1780. X */
  1781. Xstruct process_list {
  1782. X    char                *name;    /* process filename */
  1783. X    FILE                *file;    /* process file */
  1784. X    struct process_list *next;    /* next element */
  1785. X};
  1786. X
  1787. X/* include filename list:
  1788. X * the names of the includefiles are stored in this list
  1789. X */
  1790. Xstruct include_list {
  1791. X    char                *name;    /* include filename */
  1792. X    struct include_list *next;    /* next element */
  1793. X};
  1794. X
  1795. X/* include filename list:
  1796. X * the names of additional include paths are stored in this list
  1797. X */
  1798. Xstruct include_path_list {
  1799. X    char                     *path;    /* path name */
  1800. X    struct include_path_list *next;    /* next element */
  1801. X};
  1802. X
  1803. X/* preprocessor definition list:
  1804. X * the names of additional preprocessor definitions are stored in this list
  1805. X */
  1806. Xstruct cpp_def_list {
  1807. X    char                *def;    /* preprocessor definition */
  1808. X    struct cpp_def_list *next;    /* next element */
  1809. X};
  1810. X
  1811. X/* structure and typedef list:
  1812. X * pointer to symbol table entries of structure and type definitions are 
  1813. X * collected in this list in the order of their appearance
  1814. X */
  1815. Xstruct struct_type_list {
  1816. X    SYMBTABEL               *symbol; /* pointer to symbol table entry */
  1817. X    struct struct_type_list *next;     /* next element */
  1818. X};
  1819. X
  1820. X#endif /* !__config_h /**/
  1821. END_OF_FILE
  1822. if test 17581 -ne `wc -c <'include/config.h'`; then
  1823.     echo shar: \"'include/config.h'\" unpacked with wrong size!
  1824. fi
  1825. # end of 'include/config.h'
  1826. fi
  1827. if test -f 'lib/convert.c' -a "${1}" != "-c" ; then 
  1828.   echo shar: Will not clobber existing file \"'lib/convert.c'\"
  1829. else
  1830. echo shar: Extracting \"'lib/convert.c'\" \(18797 characters\)
  1831. sed "s/^X//" >'lib/convert.c' <<'END_OF_FILE'
  1832. X/***************************************************************************
  1833. X *                                                                         *
  1834. X * @@@@  @@@ @@@@@ @@@@@ @@@@@ @@@ @@@@  @   @ @@@@@ @@@@@ @@@@       @@@  *
  1835. X * @   @  @  @       @   @   @  @  @   @ @   @   @   @     @   @     @   @ *
  1836. X * @   @  @  @@@@@   @   @@@@@  @  @@@@@ @   @   @   @@@@@ @   @     @     *
  1837. X * @   @  @      @   @   @ @    @  @   @ @   @   @   @     @   @     @   @ *
  1838. X * @@@@  @@@ @@@@@   @   @  @  @@@ @@@@  @@@@@   @   @@@@@ @@@@       @@@  *
  1839. X *                                                                         *
  1840. X *              A compiler for distributed programming with C              *
  1841. X *                                                                         *
  1842. X *                           c o n v e r t . c                             *
  1843. X *                                                                         *
  1844. X *                            Package : Runtime Library                    *
  1845. X *                            Version : 2.0                                *
  1846. X *                       CreationDate : 27.07.90                           *
  1847. X *                         LastUpDate : 26.09.91                           *
  1848. X *                                                                         *
  1849. X *       The runtime library functions used to transform structures.       *
  1850. X *                                                                         *
  1851. X *                  Portions Copyright 1990 Franz Distler                  *
  1852. X *                  Portions Copyright 1990 Markus Pleier                  *
  1853. X *               Copyright (C) 1990-1994 by Christoph Pleier               *
  1854. X *                          All rights reserved!                           *
  1855. X ***************************************************************************/
  1856. X
  1857. X/*
  1858. X * This file is part of the Distributed C Development Environment (DCDE).
  1859. X * DCDE is free software; you can redistribute it and/or modify
  1860. X * it under the terms written in the README-file. 
  1861. X * DCDE is distributed in the hope that it will be useful,
  1862. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1863. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  1864. X * See the file README for more details.
  1865. X */
  1866. X
  1867. X#include <stdio.h>
  1868. X#include <sys/types.h>
  1869. X#ifdef HETEROGENEOUS
  1870. X# include <rpc/rpc.h>
  1871. X#endif
  1872. X#ifdef SYSTEM_V
  1873. X# include <memory.h>
  1874. X#endif /* SYSTEM_V /**/
  1875. X#include "ipc.h"
  1876. X#include "dcc.h"
  1877. X#include "run_Errno.h"
  1878. X
  1879. X#define DEBUG_CONVERT /**/
  1880. X
  1881. X#ifdef DEBUG_CONVERT
  1882. X/* the flag to control the debug messages output */
  1883. Xint _debug_convert = 0;
  1884. X#endif /* DEBUG_CONVERT /**/
  1885. X
  1886. X#ifdef DEBUG_CONVERT
  1887. X# define DEBUGPUTS(msg)        if (_debug_convert) { \
  1888. X                    fprintf(_debugout, "[cvt] %s %s\n", \
  1889. X                        _processprefix, msg); \
  1890. X                    if (_debugflush) \
  1891. X                        fflush(_debugout); \
  1892. X                }
  1893. X# define DEBUGDISPERR(msg)    if (_debug_convert) { \
  1894. X                    fprintf(_debugout, "[cvt] %s error: %s\n", \
  1895. X                        _processprefix, msg); \
  1896. X                    fprintf(_debugout, "[cvt] %s reason: %s\n",\
  1897. X                        _processprefix, sys_errlist[errno]); \
  1898. X                    if (_debugflush) \
  1899. X                        fflush(_debugout); \
  1900. X                }
  1901. X#else
  1902. X# define DEBUGPUTS(msg)        { /* nothing */ }
  1903. X# define DEBUGDISPERR(msg)    { /* nothing */ }
  1904. X#endif
  1905. X
  1906. X#ifdef HETEROGENEOUS
  1907. X
  1908. X/******************************************************************************
  1909. X * _allocate_encode_decode_buffer()                                           *
  1910. X *                                                                            *
  1911. X * Allocates the heap space to perform the encode/decode actions.             *
  1912. X * Note: This function is used only in the heterogenous version!              *
  1913. X *                                                                            *
  1914. X * Return values: OK upon success / ERROR upon error                          *
  1915. X ******************************************************************************/
  1916. Xint
  1917. X_allocate_encode_decode_buffer(size)
  1918. Xunsigned  size;
  1919. X{
  1920. X#ifdef DEBUG_CONVERT
  1921. X    if (_debug_convert) {
  1922. X        fprintf(_debugout, "[cvt] %s ***** _allocate_encode_decode_buffer():\n",
  1923. X        _processprefix);
  1924. X        fprintf(_debugout, "[cvt] %s size = %d\n", _processprefix, size);
  1925. X        if (_debugflush)
  1926. X            fflush(_debugout);
  1927. X    }
  1928. X#endif /* DEBUG_CONVERT /**/
  1929. X    _dcc_buf      = (char *) malloc(size);
  1930. X    _xdr_size_buf = (char *) malloc(SIZEOFLONG);
  1931. X    if (_dcc_buf == NULL || _xdr_size_buf == NULL) {
  1932. X        Errno = EMALLOCBUF;
  1933. X    return(ERROR);
  1934. X    } else {
  1935. X        xdrmem_create(&encode_xdrs, _dcc_buf, size, XDR_ENCODE);
  1936. X        xdrmem_create(&decode_xdrs, _dcc_buf, size, XDR_DECODE);
  1937. X        xdrmem_create(&_xdr_encode_size_xdrs, _xdr_size_buf, SIZEOFLONG, XDR_ENCODE);
  1938. X        xdrmem_create(&_xdr_decode_size_xdrs, _xdr_size_buf, SIZEOFLONG, XDR_DECODE);
  1939. X    return(OK);
  1940. X    }
  1941. X} /* _allocate_encode_decode_buffer */
  1942. X
  1943. X/******************************************************************************
  1944. X * _encode()                                                                  *
  1945. X *                                                                            *
  1946. X * Transforms the structure pointed to by 'ptr' into XDR format. The result   *
  1947. X * will be stored in the memory pointed to by the global variable '_dcc_buf'. *
  1948. X * 'size' specifies the size of the processed structure.                      *
  1949. X * Note: This function is used only in the heterogenous version!              *
  1950. X *                                                                            *
  1951. X * Return values: OK upon success / ERROR upon error                          *
  1952. X ******************************************************************************/
  1953. Xint
  1954. X_encode(ptr, xdr_func, size)
  1955. Xchar          *ptr;
  1956. Xint           (*xdr_func)();
  1957. Xunsigned long *size;
  1958. X{
  1959. X#ifdef DEBUG_CONVERT
  1960. X    if (_debug_convert) {
  1961. X        fprintf(_debugout, "[cvt] %s ***** _encode():\n", _processprefix);
  1962. X        fprintf(_debugout, "[cvt] %s ptr = %d, xdr_func = %d\n",
  1963. X            _processprefix, ptr, xdr_func);
  1964. X        if (_debugflush)
  1965. X            fflush(_debugout);
  1966. X    }
  1967. X#endif /* DEBUG_CONVERT /**/
  1968. X    /* encode to XDR format */
  1969. X    if ((*xdr_func)(&encode_xdrs, ptr) == FALSE) {
  1970. X        Errno = EENCODE;
  1971. X    return(ERROR); 
  1972. X    }
  1973. X    /* determine size of encoded data */
  1974. X    if ((*size = xdr_getpos(&encode_xdrs)) == 0) {
  1975. X    Errno = EENCODESIZE;
  1976. X    return(ERROR);
  1977. X    }
  1978. X    /* rewind memory stream */
  1979. X    if (xdr_setpos(&encode_xdrs, 0) == 0) {
  1980. X    Errno = EXDRSETPOS;
  1981. X    return(ERROR);
  1982. X    }
  1983. X#ifdef DEBUG_CONVERT
  1984. X    if (_debug_convert) {
  1985. X        fprintf(_debugout, "[cvt] %s       resulting size = %d\n", 
  1986. X        _processprefix, *size);
  1987. X        if (_debugflush)
  1988. X            fflush(_debugout);
  1989. X    }
  1990. X#endif /* DEBUG_CONVERT /**/
  1991. X    return(OK);
  1992. X} /* _encode */
  1993. X
  1994. X/******************************************************************************
  1995. X * _decode()                                                                  *
  1996. X *                                                                            *
  1997. X * Transforms the XDR formated memory block pointed to by the global variable *
  1998. X * '_dcc_buf' into the structure pointed to by 'ptr'. 'size' specifies the    *
  1999. X * size of the structure in bytes.                                            *
  2000. X * Note: This function is used only in the heterogenous version!              *
  2001. X *                                                                            *
  2002. X * Return values: OK upon success / ERROR upon error                          *
  2003. X ******************************************************************************/
  2004. Xint
  2005. X_decode(ptr, xdr_func)
  2006. Xchar *ptr;
  2007. Xint  (*xdr_func)();
  2008. X{
  2009. X#ifdef DEBUG_CONVERT
  2010. X    if (_debug_convert) {
  2011. X        fprintf(_debugout, "[cvt] %s ***** _decode():\n", _processprefix);
  2012. X        fprintf(_debugout, "[cvt] %s ptr = %d, xdr_func = %d\n",
  2013. X            _processprefix, ptr, xdr_func);
  2014. X        if (_debugflush)
  2015. X            fflush(_debugout);
  2016. X    }
  2017. X#endif /* DEBUG_CONVERT /**/
  2018. X    /* decode from XDR format */
  2019. X    if ((*xdr_func)(&decode_xdrs, ptr) == FALSE) {
  2020. X        Errno = EDECODE;
  2021. X    return(ERROR);
  2022. X    }
  2023. X    /* rewind memory stream */
  2024. X    if (xdr_setpos(&decode_xdrs, 0) == 0) {
  2025. X    Errno = EXDRSETPOS;
  2026. X    return(ERROR);
  2027. X    }
  2028. X    return(OK);
  2029. X} /* _decode */
  2030. X
  2031. X/******************************************************************************
  2032. X * _send_data_encoded()                                                       *
  2033. X *                                                                            *
  2034. X * ????                                                                       *
  2035. X *                                                                            *
  2036. X * Return values: OK upon success / ERROR upon error                          *
  2037. X ******************************************************************************/
  2038. Xint
  2039. X_send_data_encoded(con_port, data, xdr_func, timeout)
  2040. XCONNECTIONDESCR *con_port;
  2041. Xchar            *data;
  2042. Xint             (*xdr_func)();
  2043. Xint             timeout;
  2044. X{
  2045. X    unsigned long _xdr_size;
  2046. X
  2047. X#ifdef DEBUG_CONVERT
  2048. X    if (_debug_convert) {
  2049. X        fprintf(_debugout, "[cvt] %s ***** _send_data_encoded():\n", 
  2050. X        _processprefix);
  2051. X        fprintf(_debugout, "[cvt] %s data = %d, xdr_func = %d\n",
  2052. X            _processprefix, data, xdr_func);
  2053. X        if (_debugflush)
  2054. X            fflush(_debugout);
  2055. X    }
  2056. X#endif /* DEBUG_CONVERT /**/
  2057. X    /* encode data to XDR format and store it in _dcc_buf */
  2058. X    if (_encode(data, xdr_func, &_xdr_size))
  2059. X        return(ERROR);
  2060. X    /* encode size of encoded data and store it in _xdr_size_buf */
  2061. X    if (!xdr_u_long(&_xdr_encode_size_xdrs, &_xdr_size)) {
  2062. X        Errno = EENCODE;
  2063. X        return(ERROR);
  2064. X    }
  2065. X    /* rewind memory stream */
  2066. X    if (xdr_setpos(&_xdr_encode_size_xdrs, 0) == 0) {
  2067. X        Errno = EXDRSETPOS;
  2068. X        return(ERROR);
  2069. X    }
  2070. X#ifdef DEBUG_CONVERT
  2071. X    if (_debug_convert) {
  2072. X        fprintf(_debugout, "[cvt] %s       size of encoded data: %d\n",
  2073. X            _processprefix, _xdr_size);
  2074. X        if (_debugflush)
  2075. X            fflush(_debugout);
  2076. X    }
  2077. X#endif /* DEBUG_CONVERT /**/
  2078. X    /* send size of encoded data */
  2079. X    if (_send_data(con_port, _xdr_size_buf, SIZEOFLONG, timeout) < 0)
  2080. X        return(ERROR);
  2081. X    if (_send_data(con_port, _dcc_buf, _xdr_size, timeout) < 0)
  2082. X        return(ERROR);
  2083. X    Errno = -1;
  2084. X    return(OK);
  2085. X} /* _send_data_encoded */
  2086. X
  2087. X/******************************************************************************
  2088. X * _recv_data_encoded()                                                       *
  2089. X *                                                                            *
  2090. X * ????                                                                       *
  2091. X *                                                                            *
  2092. X * Return values: OK upon success / ERROR upon error                          *
  2093. X ******************************************************************************/
  2094. Xint
  2095. X_recv_data_encoded(con_port, data, xdr_func, timeout)
  2096. XCONNECTIONDESCR *con_port;
  2097. Xchar            *data;
  2098. Xint             (*xdr_func)();
  2099. Xint             timeout;
  2100. X{
  2101. X    unsigned long _xdr_size;
  2102. X
  2103. X#ifdef DEBUG_CONVERT
  2104. X    if (_debug_convert) {
  2105. X        fprintf(_debugout, "[cvt] %s ***** _recv_data_encoded():\n", 
  2106. X        _processprefix);
  2107. X        fprintf(_debugout, "[cvt] %s data = %d, xdr_func = %d\n",
  2108. X            _processprefix, data, xdr_func);
  2109. X        if (_debugflush)
  2110. X            fflush(_debugout);
  2111. X    }
  2112. X#endif /* DEBUG_CONVERT /**/
  2113. X    /* receive size of encoded data */
  2114. X    if (_recv_data(con_port, _xdr_size_buf, SIZEOFLONG, timeout) < 0)
  2115. X        return(ERROR);
  2116. X    /* decode size of encoded data and store it in _xdr_size */
  2117. X    if (!xdr_u_long(&_xdr_decode_size_xdrs, &_xdr_size))
  2118. X        return(ERROR);
  2119. X    /* rewind memory stream */
  2120. X    if (xdr_setpos(&_xdr_decode_size_xdrs, 0) == 0) {
  2121. X        Errno = EXDRSETPOS;
  2122. X        return(ERROR);
  2123. X    }
  2124. X    /* receive data */
  2125. X    if (_recv_data(con_port, _dcc_buf, _xdr_size, timeout) < 0)
  2126. X        return(ERROR);
  2127. X    /* decode data from _dcc_buf and store it */
  2128. X    if (_decode(data, xdr_func))
  2129. X        return(ERROR);
  2130. X    Errno = -1;
  2131. X    return(OK);
  2132. X} /* _recv_data_encoded */
  2133. X
  2134. X#endif /* HETEROGENEOUS /**/
  2135. X
  2136. X/******************************************************************************
  2137. X * _convert_port_to_argv()                                                    *
  2138. X *                                                                            *
  2139. X * Transforms the system dependent port information of 'port' into strings    *
  2140. X * pointed to by 'parv'. These strings are used as arguments during process   *
  2141. X * creation.                                                                  *
  2142. X *                                                                            *
  2143. X * Return values: none!                                                       *
  2144. X ******************************************************************************/
  2145. Xint
  2146. X_convert_port_to_argv(parv, port1, port2)
  2147. Xchar      *parv[];
  2148. XPORTDESCR  port1,
  2149. X           port2;
  2150. X{
  2151. X    int i;
  2152. X    static char parstr[5][256];
  2153. X
  2154. X#ifdef DEBUG_CONVERT
  2155. X    if (_debug_convert) {
  2156. X        fprintf(_debugout, "[cvt] %s ***** _convert_port_to_argv():\n",
  2157. X            _processprefix);
  2158. X        _display_port_info("[cvt]", "port1", port1);
  2159. X        _display_port_info("[cvt]", "port2", port2);
  2160. X    }
  2161. X#endif /* DEBUG_CONVERT /**/
  2162. X#ifdef MSGSEM
  2163. X    sprintf(parstr[0], "%d", port1.msqid);
  2164. X    sprintf(parstr[1], "%d", port1.semid);
  2165. X    sprintf(parstr[2], "%d", port2.msqid);
  2166. X    sprintf(parstr[3], "%d", port2.semid);
  2167. X#endif /* MSGSEM /**/
  2168. X#ifdef SOCKET
  2169. X    sprintf(parstr[0], "%d", port1.portnum);
  2170. X    strcpy(parstr[1], port1.hostname);
  2171. X    sprintf(parstr[2], "%d", port2.portnum);
  2172. X    strcpy(parstr[3], port2.hostname);
  2173. X#endif /* SOCKET /**/
  2174. X    parv[1] = parstr[0];
  2175. X    parv[2] = parstr[1];
  2176. X    parv[3] = parstr[2];
  2177. X    parv[4] = parstr[3];
  2178. X    parv[5] = NULL;
  2179. X#ifdef DEBUG_CONVERT
  2180. X    if (_debug_convert) {
  2181. X        fprintf(_debugout, "[cvt] %s arguments:\n", _processprefix); 
  2182. X        for(i=1; parv[i]; i++) {
  2183. X            fprintf(_debugout, "[cvt] %s    \"%s\"\n",
  2184. X            _processprefix, parv[i]);
  2185. X        }
  2186. X        if (_debugflush)
  2187. X        fflush(_debugout);
  2188. X    }
  2189. X#endif /* DEBUG_CONVERT /**/
  2190. X} /* _convert_port_to_argv */
  2191. X
  2192. X/******************************************************************************
  2193. X * _convert_argv_to_port()                                                    *
  2194. X *                                                                            *
  2195. X * Transforms the system dependent port information stored in strings pointed *
  2196. X * to by 'parv' into 'port'.                                                  *
  2197. X *                                                                            *
  2198. X * Return values: none!                                                       *
  2199. X ******************************************************************************/
  2200. Xint
  2201. X_convert_argv_to_port(port1, port2, parv)
  2202. XPORTDESCR *port1,
  2203. X          *port2;
  2204. Xchar      *parv[];
  2205. X{
  2206. X    DEBUGPUTS("***** _convert_argv_to_port():");
  2207. X#ifdef MSGSEM
  2208. X    port1->msqid = atoi(parv[1]);
  2209. X    port1->semid = atoi(parv[2]);
  2210. X    port2->msqid = atoi(parv[3]);
  2211. X    port2->semid = atoi(parv[4]);
  2212. X#endif /* MSGSEM /**/
  2213. X#ifdef SOCKET
  2214. X    port1->portnum = atoi(parv[1]);
  2215. X    strcpy(port1->hostname, parv[2]);
  2216. X    port2->portnum = atoi(parv[3]);
  2217. X    strcpy(port2->hostname, parv[4]);
  2218. X#endif /* SOCKET /**/
  2219. X#ifdef DEBUG_CONVERT
  2220. X    if (_debug_convert) {
  2221. X        _display_port_info("[cvt]", "port1", *port1);
  2222. X        _display_port_info("[cvt]", "port2", *port2);
  2223. X        if (_debugflush)
  2224. X        fflush(_debugout);
  2225. X    }
  2226. X#endif /* DEBUG_CONVERT /**/
  2227. X} /* _convert_argv_to_port */
  2228. X
  2229. X#ifdef MSGSEM
  2230. X/******************************************************************************
  2231. X * init_port()                                                                *
  2232. X *                                                                            *
  2233. X * Initializes a port.                                                        *
  2234. X * NOTE: This is the version for use with message queues and semaphores.      *
  2235. X *                                                                            *
  2236. X * Return values: none!                                                       *
  2237. X ******************************************************************************/
  2238. Xint
  2239. Xinit_port(port, msqid, semid)
  2240. XPORTDESCR *port;
  2241. Xint msqid, semid;
  2242. X{
  2243. X    port->msqid = msqid;
  2244. X    port->semid = semid;
  2245. X# ifdef DEBUG_CONVERT
  2246. X    if (_debug_convert) {
  2247. X        fprintf(_debugout, "[cvt] %s ***** init_port():\n", _processprefix);
  2248. X        _display_port_info("[cvt]", "port", *port);
  2249. X        if (_debugflush)
  2250. X        fflush(_debugout);
  2251. X    }
  2252. X# endif /* DEBUG_CONVERT /**/
  2253. X} /* init_port (message queues and semaphores version) */
  2254. X#endif /* MSGSEM /**/
  2255. X
  2256. X#ifdef iPSC
  2257. X/******************************************************************************
  2258. X * init_port()                                                                *
  2259. X *                                                                            *
  2260. X * Initializes a port.                                                        *
  2261. X * NOTE: This is the version for use on Intel Hypercube.                      *
  2262. X *                                                                            *
  2263. X * Return values: none!                                                       *
  2264. X ******************************************************************************/
  2265. Xint
  2266. Xinit_port(port, node, pid)
  2267. XPORTDESCR *port;
  2268. Xlong node, pid;
  2269. X{
  2270. X    port->node = node;
  2271. X    port->pid  = pid;
  2272. X# ifdef DEBUG_CONVERT
  2273. X    if (_debug_convert) {
  2274. X        fprintf(_debugout, "[cvt] %s ***** init_port():\n", _processprefix);
  2275. X        _display_port_info("[cvt]", "port", *port);
  2276. X        if (_debugflush)
  2277. X        fflush(_debugout);
  2278. X    }
  2279. X# endif /* DEBUG_CONVERT /**/
  2280. X} /* init_port (Intel Hypercube version) */
  2281. X#endif /* iPSC /**/
  2282. X
  2283. X#ifdef SOCKET
  2284. X/******************************************************************************
  2285. X * init_port()                                                                *
  2286. X *                                                                            *
  2287. X * Initializes a port.                                                        *
  2288. X * NOTE: This is the version for use with stream sockets.                     *
  2289. X *                                                                            *
  2290. X * Return values: none!                                                       *
  2291. X ******************************************************************************/
  2292. Xint
  2293. Xinit_port(port, socket, portnum, hostname)
  2294. XPORTDESCR *port;
  2295. Xint socket, portnum;
  2296. Xchar hostname[];
  2297. X{
  2298. X    port->state    = -1;
  2299. X    port->acc_sock = -1;
  2300. X    port->con_sock = -1;
  2301. X    port->portnum  = portnum;
  2302. X    strcpy(port->hostname, hostname);
  2303. X# ifdef DEBUG_CONVERT
  2304. X    if (_debug_convert) {
  2305. X        fprintf(_debugout, "[cvt] %s ***** init_port():\n", _processprefix);
  2306. X        _display_port_info("[cvt]", "port", *port);
  2307. X        if (_debugflush)
  2308. X        fflush(_debugout);
  2309. X    }
  2310. X# endif /* DEBUG_CONVERT /**/
  2311. X} /* init_port (socket version) */
  2312. X#endif /* SOCKET /**/
  2313. END_OF_FILE
  2314. if test 18797 -ne `wc -c <'lib/convert.c'`; then
  2315.     echo shar: \"'lib/convert.c'\" unpacked with wrong size!
  2316. fi
  2317. # end of 'lib/convert.c'
  2318. fi
  2319. echo shar: End of archive 12 \(of 18\).
  2320. cp /dev/null ark12isdone
  2321. MISSING=""
  2322. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  2323.     if test ! -f ark${I}isdone ; then
  2324.     MISSING="${MISSING} ${I}"
  2325.     fi
  2326. done
  2327. if test "${MISSING}" = "" ; then
  2328.     echo You have unpacked all 18 archives.
  2329.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2330. else
  2331.     echo You still need to unpack the following archives:
  2332.     echo "        " ${MISSING}
  2333. fi
  2334. ##  End of shell archive.
  2335. exit 0
  2336.