chiark / gitweb /
New function `pquis'.
authormdw <mdw>
Mon, 4 Oct 1999 21:45:27 +0000 (21:45 +0000)
committermdw <mdw>
Mon, 4 Oct 1999 21:45:27 +0000 (21:45 +0000)
man/quis.3
pquis.c [new file with mode: 0644]
quis.h

index 96e5d492c42c698a99db66caba69708759215795..30e95caf49f9496293c0467625a469a8db363dfa 100644 (file)
@@ -5,6 +5,7 @@ quis \- remember the program's name for use in messages
 .\" @quis
 .\" @ego
 .\" @QUIS
 .\" @quis
 .\" @ego
 .\" @QUIS
+.\" @pquis
 .SH SYNOPSIS
 .nf
 .B "#include <mLib/quis.h>"
 .SH SYNOPSIS
 .nf
 .B "#include <mLib/quis.h>"
@@ -12,6 +13,7 @@ quis \- remember the program's name for use in messages
 .BI "void ego(const char *" p );
 .B "const char *quis(void);"
 .B "const char *QUIS;"
 .BI "void ego(const char *" p );
 .B "const char *quis(void);"
 .B "const char *QUIS;"
+.BI "int pquis(FILE *" fp ", const char *" p );
 .fi
 .SH DESCRIPTION
 The
 .fi
 .SH DESCRIPTION
 The
@@ -34,6 +36,22 @@ returned by
 Don't ask why it's done this way.  There are raisins, but they're mostly
 hysterical.
 .PP
 Don't ask why it's done this way.  There are raisins, but they're mostly
 hysterical.
 .PP
+The function
+.B pquis
+is passed a file pointer
+.I fp
+and a string
+.IR p :
+it writes the string to the file, replacing every lone occurrence of the
+character
+.RB ` $ '
+by the program name.  Pairs
+.RB (` $$ ')
+are written as single dollar signs.  The return value is zero if
+everything went OK, or the constant
+.B EOF
+if there was an error.
+.PP
 The program name is used in the messages produced by the
 .BR die (3)
 and
 The program name is used in the messages produced by the
 .BR die (3)
 and
diff --git a/pquis.c b/pquis.c
new file mode 100644 (file)
index 0000000..bbd16cd
--- /dev/null
+++ b/pquis.c
@@ -0,0 +1,86 @@
+/* -*-c-*-
+ *
+ * $Id: pquis.c,v 1.1 1999/10/04 21:43:29 mdw Exp $
+ *
+ * Print strings, substituting the program name
+ *
+ * (c) 1999 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the mLib utilities library.
+ *
+ * mLib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * mLib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Library General Public
+ * License along with mLib; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: pquis.c,v $
+ * Revision 1.1  1999/10/04 21:43:29  mdw
+ * New function `pquis'.
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <stdio.h>
+#include <string.h>
+
+#include "quis.h"
+
+/*----- Main code ---------------------------------------------------------*/
+
+/* --- @pquis@ --- *
+ *
+ * Arguments:  @FILE *fp@ = output stream to write on
+ *             @const char *p@ = pointer to string to write
+ *
+ * Returns:    Zero if everything worked, EOF if not.
+ *
+ * Use:                Writes the string @p@ to the output stream @fp@.  Occurrences
+ *             of the character `$' in @p@ are replaced by the program name
+ *             as reported by @quis@.  A `$$' is replaced by a single `$'
+ *             sign.
+ */
+
+int pquis(FILE *fp, const char *p)
+{
+  size_t sz;
+
+  while (*p) {
+    sz = strcspn(p, "$");
+    if (sz) {
+      if (fwrite(p, 1, sz, fp) < sz)
+       return (EOF);
+      p += sz;
+    }
+    if (*p == '$') {
+      p++;
+      if (*p == '$') {
+       if (fputc('$', fp) == EOF)
+         return (EOF);
+       p++;
+      } else {
+       if (fputs(pn__name, fp) == EOF)
+         return (EOF);
+      }
+    }
+  }
+  return (0);
+}
+
+/*----- That's all, folks -------------------------------------------------*/
diff --git a/quis.h b/quis.h
index 0f6ab29ae92b69f975d51dbf17ac08b7f4e215c4..e2ba2eeb18414ec08c16cc69385cf4d1a3547467 100644 (file)
--- a/quis.h
+++ b/quis.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
 /* -*-c-*-
  *
- * $Id: quis.h,v 1.3 1999/05/06 19:51:35 mdw Exp $
+ * $Id: quis.h,v 1.4 1999/10/04 21:43:29 mdw Exp $
  *
  * Setting the program name
  *
  *
  * Setting the program name
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: quis.h,v $
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: quis.h,v $
+ * Revision 1.4  1999/10/04 21:43:29  mdw
+ * New function `pquis'.
+ *
  * Revision 1.3  1999/05/06 19:51:35  mdw
  * Reformatted the LGPL notice a little bit.
  *
  * Revision 1.3  1999/05/06 19:51:35  mdw
  * Reformatted the LGPL notice a little bit.
  *
   extern "C" {
 #endif
 
   extern "C" {
 #endif
 
+/*----- Header files ------------------------------------------------------*/
+
+#include <stdio.h>
+
 /*----- Global variables --------------------------------------------------*/
 
 extern const char *pn__name;
 /*----- Global variables --------------------------------------------------*/
 
 extern const char *pn__name;
@@ -77,6 +84,21 @@ extern const char *quis(void);
 
 extern void ego(const char */*p*/);
 
 
 extern void ego(const char */*p*/);
 
+/* --- @pquis@ --- *
+ *
+ * Arguments:  @FILE *fp@ = output stream to write on
+ *             @const char *p@ = pointer to string to write
+ *
+ * Returns:    Zero if everything worked, EOF if not.
+ *
+ * Use:                Writes the string @p@ to the output stream @fp@.  Occurrences
+ *             of the character `$' in @p@ are replaced by the program name
+ *             as reported by @quis@.  A `$$' is replaced by a single `$'
+ *             sign.
+ */
+
+extern int pquis(FILE */*fp*/, const char */*p*/);
+
 /*----- That's all, folks -------------------------------------------------*/
 
 #ifdef __cplusplus
 /*----- That's all, folks -------------------------------------------------*/
 
 #ifdef __cplusplus