flnk_startform.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Copyright (C) Mikhail Tentyukov.
  3. This file is part of FORMLINK interface to the Symbolic Manipulation
  4. System FORM (http://www.nikhef.nl/~form).
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are met:
  7. 1. Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. 2. Redistributions of modified source code should refer to its origin as
  10. follows: "This code is based on the source code of FORMLINK interface to
  11. the Symbolic Manipulation System FORM".
  12. 3. Provided this code was used in any form in scientific work that
  13. leads to publication in a scientific journal, this work should refer
  14. to the paper M.~Tentyukov, J.A.M.~Vermaseren "Extension of the
  15. functionality of the symbolic program FORM by external software",
  16. cs.SC/0604052
  17. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY; WITHOUT EVEN
  18. THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
  19. PURPOSE.
  20. */
  21. /*See comments in the file flnk_startform.c*/
  22. #ifndef FLNK_STARTFORM
  23. #define FLNK_STARTFORM
  24. #ifndef INLINE
  25. #define INLINE inline
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /*Error codes: the most significant bits are set, to be negative,
  32. and two less significant bytes are used as a single-bit flag:*/
  33. #define FLINK_ALLOCERR (pid_t)( ((-1)^0xFFFF)|2 )
  34. #define FLINK_PIPEERR (pid_t)( ((-1)^0xFFFF)|4 )
  35. #define FLINK_FORKEERR (pid_t)( ((-1)^0xFFFF)|8 )
  36. #define FLINK_EXECEERR (pid_t)( ((-1)^0xFFFF)|16 )
  37. #define FLINK_DAEMONERR (pid_t)( ((-1)^0xFFFF)|32 )
  38. #define FLNK_DOPENERR (pid_t)( ((-1)^0xFFFF)|64 )
  39. #define FLINK_INVCMD (pid_t)( ((-1)^0xFFFF)|128 )
  40. #define FLNK_INITERR (pid_t)( ((-1)^0xFFFF)|256 )
  41. #define FLNK_INITTMERR (pid_t)( ((-1)^0xFFFF)|512 )
  42. #define FLNK_INITPIDERR (pid_t)( ((-1)^0xFFFF)|1024 )
  43. /*One argument must be a constant representing FLNK error, and
  44. another one is a code returned by flnk_do_runcmd() of flnk_runcmd().
  45. Macro returns TRUE if the returned code contains the corresponding
  46. error:*/
  47. #define FLNK_ISERR(x,y) (((x)<0)&&(y<0)&&(0xFFFF&(x)&(y)))
  48. /*Timeout for the channel initialization, in millisecs:*/
  49. #define FLNK_TIMEOUT 1100
  50. /*Name of the environment variable used to pass a list of
  51. descriptors:*/
  52. #define FORM_PIPES "FORM_PIPES"
  53. /*See comments in flnk_startform.c:*/
  54. pid_t flnk_do_runcmd(
  55. /*--Input parameters:--*/
  56. int nchannels,/*number of i/o cahnnels*/
  57. int ttymode,/*0 - nothing,
  58. &1 - stdin</dev/null
  59. &2 - stdout>/dev/null
  60. &4 - stderr>/dev/null
  61. &8 - daemonizeing
  62. &16 - setsid()*/
  63. char *cmd,/*filename to execute*/
  64. char *argv[],/*arguments, argv[0] is the name of the started process*/
  65. int nopt,/*if >0, order number of the option to be replaced by pipe info*/
  66. char *envnam,/* if not NULL, export the pipe info into this env. variable*/
  67. int fdstart,/*How many standard descriptors are opened?
  68. (usually 3 -- stdin, stdout and stderr*/
  69. /*--Output parameters:--*/
  70. int *fdread,/*array of read descriptors*/
  71. int *fdwrite,/*array of write descriptors*/
  72. int *formPID/*FORM PID obtained during initialization*/
  73. );
  74. /*See comments in flnk_startform.c:*/
  75. pid_t flnk_runcmd(
  76. FILE **freceive,/*get from running program*/
  77. FILE **fsend,/*send to running program*/
  78. int daemonize,/*0 - not, !=0 - yes*/
  79. char *cmd/*command to execute, may contain '-pipe'; if not,
  80. FORM_PIPES environment variable will be used*/
  81. );
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif
  86. /* end of flnk_startform.h */