Revert "If we don't have a realm, use server FQDN; only portable thing we can do"
[cyrus-sasl.git] / mac / mac_lib / parse_cmd_line.c
1 /*
2  * prompt for a command line
3  */
4 /* $Id: parse_cmd_line.c,v 1.3 2003/02/13 19:55:59 rjs3 Exp $
5  * Copyright (c) 1998-2003 Carnegie Mellon University.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer. 
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * 3. The name "Carnegie Mellon University" must not be used to
20  *    endorse or promote products derived from this software without
21  *    prior written permission. For permission or any other legal
22  *    details, please contact  
23  *      Office of Technology Transfer
24  *      Carnegie Mellon University
25  *      5000 Forbes Avenue
26  *      Pittsburgh, PA  15213-3890
27  *      (412) 268-4387, fax: (412) 268-7395
28  *      tech-transfer@andrew.cmu.edu
29  *
30  * 4. Redistributions of any form whatsoever must retain the following
31  *    acknowledgment:
32  *    "This product includes software developed by Computing Services
33  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
34  *
35  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
36  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
37  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
38  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
39  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
40  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
41  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42  */
43
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include <ctype.h>
48
49 #include <parse_cmd_line.h>
50
51 static char *skip_blanks(char *s)
52 {
53         while(isspace(*s))
54                 s++;
55         return s;
56 }
57
58 static void chomp(char *dst,char ch)
59 {
60         dst=strchr(dst,ch);
61         if(dst!=0)
62                 *dst=0;
63 }
64
65 int parse_cmd_line(int max_argc,char **argv,int line_size,char *line)
66 {
67         int argc=1;
68         memset(line,0,line_size);
69         fprintf(stdout,"cmd>");
70         fflush(stdout);
71         fgets(line,line_size-1,stdin);
72         *argv++="prg";
73         chomp(line,'\n');
74         max_argc-=2;
75         while(line[0]!=0) {
76                 line=skip_blanks(line);
77                 if(line[0]==0)
78                         break;
79                 if(argc>=max_argc)
80                         break;
81                 *argv++=line;
82                 argc++;
83                 line=strchr(line,' ');
84                 if(line==0)
85                         break;
86                 *line++=0;
87         }
88         *argv=0;
89         return argc;
90 }