chiark / gitweb /
Useful functions (u_daemon and versioncmp) moved to mLib.
[tripe] / common / util.c
CommitLineData
410c8acf 1/* -*-c-*-
2 *
b4e56668 3 * $Id: util.c,v 1.3 2004/04/08 01:36:17 mdw Exp $
410c8acf 4 *
5 * Utilities for the client and the server
6 *
7 * (c) 2001 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Trivial IP Encryption (TrIPE).
13 *
14 * TrIPE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * TrIPE 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 General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with TrIPE; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
410c8acf 29/*----- Header files ------------------------------------------------------*/
30
31#include <errno.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35
0ed0735f
MW
36#include <mLib/dstr.h>
37
410c8acf 38#include "util.h"
39
410c8acf 40/*----- Main code ---------------------------------------------------------*/
41
0ed0735f
MW
42/* --- @u_quotify@ --- *
43 *
44 * Arguments: @dstr *d@ = where to write the answer
45 * @const char *p@ = string to quotify
46 *
47 * Returns: ---
48 *
49 * Use: Quotes the given string if necessary, according to our
50 * quoting rules.
51 */
52
53void u_quotify(dstr *d, const char *p)
54{
55 if (d->len)
56 dstr_putc(d, ' ');
57 if (*p && !p[strcspn(p, "\"' \t\n\v")])
58 dstr_puts(d, p);
59 else {
60 dstr_putc(d, '\"');
61 while (*p) {
62 if (*p == '\\' || *p == '\"')
63 dstr_putc(d, '\\');
64 dstr_putc(d, *p++);
65 }
66 dstr_putc(d, '\"');
67 }
68}
69
410c8acf 70/*----- That's all, folks -------------------------------------------------*/