chiark / gitweb /
Various manual fixes.
[mLib] / pquis.c
CommitLineData
4a74ab73 1/* -*-c-*-
2 *
8656dc50 3 * $Id: pquis.c,v 1.2 2004/04/08 01:36:13 mdw Exp $
4a74ab73 4 *
5 * Print strings, substituting the program name
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the mLib utilities library.
13 *
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
28 */
29
4a74ab73 30/*----- Header files ------------------------------------------------------*/
31
32#include <stdio.h>
33#include <string.h>
34
35#include "quis.h"
36
37/*----- Main code ---------------------------------------------------------*/
38
39/* --- @pquis@ --- *
40 *
41 * Arguments: @FILE *fp@ = output stream to write on
42 * @const char *p@ = pointer to string to write
43 *
44 * Returns: Zero if everything worked, EOF if not.
45 *
46 * Use: Writes the string @p@ to the output stream @fp@. Occurrences
47 * of the character `$' in @p@ are replaced by the program name
48 * as reported by @quis@. A `$$' is replaced by a single `$'
49 * sign.
50 */
51
52int pquis(FILE *fp, const char *p)
53{
54 size_t sz;
55
56 while (*p) {
57 sz = strcspn(p, "$");
58 if (sz) {
59 if (fwrite(p, 1, sz, fp) < sz)
60 return (EOF);
61 p += sz;
62 }
63 if (*p == '$') {
64 p++;
65 if (*p == '$') {
66 if (fputc('$', fp) == EOF)
67 return (EOF);
68 p++;
69 } else {
70 if (fputs(pn__name, fp) == EOF)
71 return (EOF);
72 }
73 }
74 }
75 return (0);
76}
77
78/*----- That's all, folks -------------------------------------------------*/