sms_address.c
上传用户:mei_mei897
上传日期:2007-01-05
资源大小:82k
文件大小:4k
- /* -------------------------------------------------------------------- */
- /* SMS Client, send messages to mobile phones and pagers */
- /* */
- /* sms_address.c */
- /* */
- /* Copyright (C) 1997,1998 Angelo Masci */
- /* */
- /* This library 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. */
- /* */
- /* This library 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 this library; if not, write to the Free */
- /* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
- /* */
- /* You can contact the author at this e-mail address: */
- /* */
- /* angelo@styx.demon.co.uk */
- /* */
- /* -------------------------------------------------------------------- */
- /* $Id: sms_address.c,v 1.5 1998/01/17 22:49:15 root Exp $
- -------------------------------------------------------------------- */
- #include <stdio.h>
- #include <errno.h>
- #include <unistd.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- #if defined(LINUX)
- #include <getopt.h>
- #endif
- #if defined(NEXT)
- #include <libc.h>
- #endif
- #include "sms_list.h"
- #include "parserc.h"
- #include "common.h"
- /* -------------------------------------------------------------------- */
- #if !defined(MVERSION)
- #error "MVERSION undefined"
- #else
- #define VERSION MVERSION
- #endif
- /* -------------------------------------------------------------------- */
- void usage(char *file);
- int main(int, char *[]);
- /* -------------------------------------------------------------------- */
- /* -------------------------------------------------------------------- */
- void usage(char *file)
- {
- printf("Usage: %s [-v]n", file);
- printf(" %s [-l] [-d delimeter] name[,name]n", file);
- }
- /* -------------------------------------------------------------------- */
- /* -------------------------------------------------------------------- */
- int main(int argc, char *argv[])
- {
- int c,
- long_flag,
- delimeter;
- SMS_list
- *node,
- *numbers;
- FILE *fp[2];
- char
- *sms_default_service = NULL;
- /* ---------------------------- */
- delimeter = ':';
- long_flag = FALSE;
- while ((c = getopt (argc, argv, "vld:")) != -1)
- {
- switch (c)
- { case 'v':
- printf("%s %sn", argv[0], VERSION);
- exit(0);
- case 'l':
- long_flag = TRUE;
- break;
- case 'd':
- if (sms_strlen(optarg) > 1)
- { fprintf(stderr, "Invalid delimeter `%s'n", optarg);
- usage(argv[0]);
- exit(-1);
- }
- delimeter = optarg[0];
- break;
- case '?':
- #if !defined(NEXT)
- fprintf(stderr, "Unknown option `-%c'n", optopt);
- #endif
- usage(argv[0]);
- exit(-1);
- default:
- abort ();
- }
- }
-
- /* ---------------------------- */
- /* Get Default SERVICE */
- SMS_dual_openrc(fp);
- if (sms_default_service == NULL)
- {
- sms_default_service = SMS_dual_get_smsrc_value(fp, "SMS_default_service");
- if (sms_default_service == NULL)
- {
- fprintf(stderr, "Could not find SMS_default_servicen");
- exit(-1);
- }
- }
- SMS_dual_closerc(fp);
- /* ---------------------------- */
- /* Get and expand NAMES|NUMBERS */
-
- SMS_dual_openrc(fp);
- numbers = SMS_expandnumber(fp, "<NULL>", argv[optind], sms_default_service);
- SMS_dual_closerc(fp);
- /* ---------------------------- */
- /* Check NAMES|NUMBERS */
- if (validate_expanded_numbers(numbers))
- {
- fprintf(stderr, "ERROR: Expanding namesn");
- exit(-1);
- }
- /* ---------------------------- */
- node = get_first(numbers);
- while (node != NULL)
- {
- printf("%s%c%s%c%sn", node->name,
- delimeter,
- node->service,
- delimeter,
- node->number);
- node = get_next(node);
- }
- free_list(numbers);
- return 0;
- }