PrintManStrFile.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. #if DOC
  24. /*===================================================================
  25. $FILEBEG$: PrintManStrFile.c
  26. $COMPONENT$: dthelpprint
  27. $PROJECT$: Cde1
  28. $SYSTEM$: HPUX 9.0; AIX 3.2; SunOS 5.3
  29. $REVISION$: $XConsortium: PrintManStrFile.c /main/4 1996/10/30 11:35:27 drk $
  30. $CHGLOG$:
  31. $COPYRIGHT$:
  32. (c) Copyright 1993, 1994 Hewlett-Packard Company
  33. (c) Copyright 1993, 1994 International Business Machines Corp.
  34. (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  35. (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
  36. ==$END$==============================================================*/
  37. #endif
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <unistd.h>
  42. #if defined(sun)
  43. #include <locale.h>
  44. #else
  45. #include <langinfo.h>
  46. #endif
  47. #include "HelpPrintI.h"
  48. /*======== boundary values ==============*/
  49. #define MAX_COMMAND_LENGTH 5120 /* max system can handle */
  50. /*======== dthelpprint.sh options ==============*/
  51. /*======== helper values ===============*/
  52. #define EOS '\0'
  53. #define EMPTY_STR s_EmptyStr
  54. #define PMSET 4 /* message catalog set */
  55. /*======== helper variables ===============*/
  56. static char s_EmptyStr[1] = { EOS };
  57. /*======== data structs ==============*/
  58. /*======== static variables ===============*/
  59. /*======== functions ==============*/
  60. #if DOC
  61. ===================================================================
  62. $FUNBEG$: _DtHPrPrintStringData()
  63. $1LINER$: Writes string data to file and then sends to printer
  64. $DESCRIPT$:
  65. Writes string data to file and then sends to printer
  66. $RETURNS$:
  67. $ARGS$:
  68. ========================================================$SKIP$=====*/
  69. #endif /*DOC*/
  70. int _DtHPrPrintStringData(
  71. Display *dpy,
  72. _DtHPrOptions * options)
  73. { /*$CODE$*/
  74. char *printCommand;
  75. char cmdFormat[100];
  76. char prOffsetArg[30];
  77. int status;
  78. int retval;
  79. if ( NULL == options->stringData )
  80. {
  81. fprintf(stderr, _DTGETMESSAGE(PMSET,1,
  82. "%s: Error: helpType is string, "
  83. "but no stringData specified.\n"),
  84. options->programName);
  85. return 1; /* RETURN */
  86. }
  87. /* Alloc max shell command line len */
  88. printCommand = malloc(MAX_COMMAND_LENGTH*sizeof(char));
  89. if (printCommand == NULL)
  90. {
  91. fprintf(stderr, _DTGETMESSAGE(PMSET,5,
  92. "%s: Error: memory allocation failed\n"),
  93. options->programName );
  94. return 2; /* RETURN error */
  95. }
  96. /** generate the command **/
  97. _DtHPrGetPrOffsetArg(options,prOffsetArg);
  98. sprintf(cmdFormat, "%s %s|%s %s|%s %s %s", /* echo | fold | pr */
  99. options->echoCommand, options->echoArgs,
  100. options->foldCommand, options->foldArgs,
  101. options->prCommand, prOffsetArg, options->prArgs);
  102. sprintf(printCommand, cmdFormat,
  103. options->stringData, /* echo */
  104. options->colsTextWidth, EMPTY_STR, /* fold */
  105. options->topicTitle, options->rowsHeight, EMPTY_STR); /* pr */
  106. retval = _DtHPrGenFileOrPrint(options,"String",printCommand);
  107. free(printCommand);
  108. return retval;
  109. } /*$END$*/
  110. #if DOC
  111. ===================================================================
  112. $FUNBEG$: _DtHPrPrintDynamicStringData()
  113. $1LINER$: Writes string data to file, formats it, then sends to printer
  114. $DESCRIPT$:
  115. Writes string data to file, formats it, then sends to printer
  116. $RETURNS$:
  117. $ARGS$:
  118. ========================================================$SKIP$=====*/
  119. #endif /*DOC*/
  120. int _DtHPrPrintDynamicStringData(
  121. Display *dpy,
  122. _DtHPrOptions * options)
  123. { /*$CODE$*/
  124. char *printCommand;
  125. char cmdFormat[100];
  126. char prOffsetArg[30];
  127. int status;
  128. int retval;
  129. if ( NULL == options->stringData )
  130. {
  131. fprintf(stderr, _DTGETMESSAGE(PMSET,2,
  132. "%s: Error: helpType is dynamic string, "
  133. "but no stringData specified.\n"),
  134. options->programName);
  135. return 1; /* RETURN */
  136. }
  137. /* Alloc max shell command line len */
  138. printCommand = malloc(MAX_COMMAND_LENGTH*sizeof(char));
  139. if (printCommand == NULL)
  140. {
  141. fprintf(stderr, _DTGETMESSAGE(PMSET,5,
  142. "%s: Error: memory allocation failed\n"),
  143. options->programName );
  144. return 2; /* RETURN error */
  145. }
  146. /** generate the command **/
  147. _DtHPrGetPrOffsetArg(options,prOffsetArg);
  148. sprintf(cmdFormat, "%s %s|%s %s|%s %s %s", /* echo | fold | pr */
  149. options->echoCommand, options->echoArgs,
  150. options->foldCommand, options->foldArgs,
  151. options->prCommand, prOffsetArg, options->prArgs);
  152. sprintf(printCommand, cmdFormat,
  153. options->stringData, /* echo */
  154. options->colsTextWidth, EMPTY_STR, /* fold */
  155. options->topicTitle, options->rowsHeight, EMPTY_STR); /* pr */
  156. retval = _DtHPrGenFileOrPrint(options,"String",printCommand);
  157. free(printCommand);
  158. return retval;
  159. } /*$END$*/
  160. #if DOC
  161. ===================================================================
  162. $FUNBEG$: _DtHPrPrintManPage()
  163. $1LINER$: Dumps formatted man page to file and then sends to printer
  164. $DESCRIPT$:
  165. Dumps formatted man page to file and then sends to printer
  166. $RETURNS$:
  167. $ARGS$:
  168. ========================================================$SKIP$=====*/
  169. #endif /*DOC*/
  170. int _DtHPrPrintManPage(
  171. Display *dpy,
  172. _DtHPrOptions * options)
  173. { /*$CODE$*/
  174. char *printCommand;
  175. char cmdFormat[100];
  176. int status;
  177. int retval;
  178. if ( NULL == options->manPage )
  179. {
  180. fprintf(stderr, _DTGETMESSAGE(PMSET,3,
  181. "%s: Error: helpType is man page, "
  182. "but no manPage specified.\n"),
  183. options->programName);
  184. return 1; /* RETURN */
  185. }
  186. /* Alloc max shell command line len */
  187. printCommand = malloc(MAX_COMMAND_LENGTH);
  188. if (printCommand == NULL)
  189. {
  190. fprintf(stderr, _DTGETMESSAGE(PMSET,5,
  191. "%s: Error: memory allocation failed\n"),
  192. options->programName );
  193. return 2; /* RETURN error */
  194. }
  195. /** generate the command **/
  196. snprintf(cmdFormat, sizeof(cmdFormat), "%s %s", /* man */
  197. options->manCommand, options->manArgs);
  198. snprintf(printCommand, MAX_COMMAND_LENGTH, cmdFormat,
  199. options->manPage); /* man */
  200. retval = _DtHPrGenFileOrPrint(options,options->manPage,printCommand);
  201. free(printCommand);
  202. return retval;
  203. } /*$END$*/
  204. #if DOC
  205. ===================================================================
  206. $FUNBEG$: _DtHPrPrintHelpFile()
  207. $1LINER$: Format file and then sends to printer
  208. $DESCRIPT$:
  209. Format file and then sends to printer
  210. $RETURNS$:
  211. $ARGS$:
  212. ========================================================$SKIP$=====*/
  213. #endif /*DOC*/
  214. int _DtHPrPrintHelpFile(
  215. Display *dpy,
  216. _DtHPrOptions * options)
  217. { /*$CODE$*/
  218. char *printCommand;
  219. char cmdFormat[100];
  220. char prOffsetArg[30];
  221. int status;
  222. int retval;
  223. if ( NULL == options->helpFile )
  224. {
  225. fprintf(stderr, _DTGETMESSAGE(PMSET,4,
  226. "%s: Error: helpType is file, "
  227. "but no helpFile specified.\n"),
  228. options->programName);
  229. return 1; /* RETURN error */
  230. }
  231. /* Alloc max shell command line len */
  232. printCommand = malloc(MAX_COMMAND_LENGTH*sizeof(char));
  233. if (printCommand == NULL)
  234. {
  235. fprintf(stderr, _DTGETMESSAGE(PMSET,5,
  236. "%s: Error: memory allocation failed\n"),
  237. options->programName );
  238. return 2; /* RETURN error */
  239. }
  240. /** generate the command **/
  241. _DtHPrGetPrOffsetArg(options,prOffsetArg);
  242. sprintf(cmdFormat, "%s %s|%s %s %s", /* fold | pr */
  243. options->foldCommand, options->foldArgs,
  244. options->prCommand, prOffsetArg, options->prArgs);
  245. sprintf(printCommand, cmdFormat,
  246. options->colsTextWidth, options->helpFile, /* fold */
  247. options->topicTitle, options->rowsHeight, EMPTY_STR); /* pr */
  248. retval = _DtHPrGenFileOrPrint(options,options->helpFile,printCommand);
  249. free(printCommand);
  250. return retval;
  251. } /*$END$*/