| 1 | // | 
|---|
| 2 | // ipv2_error.cc | 
|---|
| 3 | // | 
|---|
| 4 | // Copyright (C) 1996 Limit Point Systems, Inc. | 
|---|
| 5 | // | 
|---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com> | 
|---|
| 7 | // Maintainer: LPS | 
|---|
| 8 | // | 
|---|
| 9 | // This file is part of the SC Toolkit. | 
|---|
| 10 | // | 
|---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify | 
|---|
| 12 | // it under the terms of the GNU Library General Public License as published by | 
|---|
| 13 | // the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 14 | // any later version. | 
|---|
| 15 | // | 
|---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful, | 
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 19 | // GNU Library General Public License for more details. | 
|---|
| 20 | // | 
|---|
| 21 | // You should have received a copy of the GNU Library General Public License | 
|---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to | 
|---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
| 24 | // | 
|---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7. | 
|---|
| 26 | // | 
|---|
| 27 |  | 
|---|
| 28 | #include <stdlib.h> | 
|---|
| 29 | #include <stdarg.h> | 
|---|
| 30 | #include <string.h> | 
|---|
| 31 |  | 
|---|
| 32 | #include <util/misc/formio.h> | 
|---|
| 33 | #include <util/keyval/ipv2.h> | 
|---|
| 34 |  | 
|---|
| 35 | using namespace std; | 
|---|
| 36 | using namespace sc; | 
|---|
| 37 |  | 
|---|
| 38 | /* Returns some text for an errcod. */ | 
|---|
| 39 | const char* | 
|---|
| 40 | IPV2::error_message(IPV2::Status errcod) | 
|---|
| 41 | { | 
|---|
| 42 | const char *ipe_ok = "No problem has been detected."; | 
|---|
| 43 | const char *ipe_key_not_found = "No match was found for the given keyword."; | 
|---|
| 44 | const char *ipe_out_of_bounds = "An array index is out of bounds."; | 
|---|
| 45 | const char *ipe_malloc = "Memory allocation failed."; | 
|---|
| 46 | const char *ipe_not_an_array = "An index was given for a scalar quantity."; | 
|---|
| 47 | const char *ipe_not_a_scalar = "Expected a scalar, but found an array."; | 
|---|
| 48 | const char *ipe_type = "The datum is not of the appropiate type."; | 
|---|
| 49 | const char *ipe_has_no_value = "The keyword has no value."; | 
|---|
| 50 | const char *ipe_val_not_expd = "A value was not expected for the keyword."; | 
|---|
| 51 | const char *huh = "The nature of the problem is unknown."; | 
|---|
| 52 |  | 
|---|
| 53 | if (errcod == OK) return ipe_ok; | 
|---|
| 54 | if (errcod == KeyNotFound) return ipe_key_not_found; | 
|---|
| 55 | if (errcod == OutOfBounds) return ipe_out_of_bounds; | 
|---|
| 56 | if (errcod == Malloc) return ipe_malloc; | 
|---|
| 57 | if (errcod == NotAnArray) return ipe_not_an_array; | 
|---|
| 58 | if (errcod == NotAScalar) return ipe_not_a_scalar; | 
|---|
| 59 | if (errcod == Type) return ipe_type; | 
|---|
| 60 | if (errcod == HasNoValue) return ipe_has_no_value; | 
|---|
| 61 | if (errcod == ValNotExpd) return ipe_val_not_expd; | 
|---|
| 62 | return huh; | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | void | 
|---|
| 66 | IPV2::error(const char *msg) | 
|---|
| 67 | { | 
|---|
| 68 | ExEnv::errn() << "IPV2::error: "; | 
|---|
| 69 | ExEnv::errn() << msg; | 
|---|
| 70 | ExEnv::errn() << endl; | 
|---|
| 71 | showpos(); | 
|---|
| 72 | exit(1); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | void | 
|---|
| 76 | IPV2::warn(const char *msg) | 
|---|
| 77 | { | 
|---|
| 78 | char *newmsg; | 
|---|
| 79 | const char *poskey; | 
|---|
| 80 |  | 
|---|
| 81 | /* If msg has a %k in it, then substitute in the last keyword. */ | 
|---|
| 82 | #if defined(NCUBE)||defined(DEC)||defined(I860) | 
|---|
| 83 | /* The NCUBE and DEC are missing the strstr function. */ | 
|---|
| 84 | for (poskey=msg; *poskey!='\0'; poskey++) { | 
|---|
| 85 | if (poskey[0] == '%' && poskey[1] == 'k') break; | 
|---|
| 86 | } | 
|---|
| 87 | if (poskey[0] != '%') poskey = NULL; | 
|---|
| 88 | #else | 
|---|
| 89 | poskey = ::strstr(msg,"%k"); | 
|---|
| 90 | #endif | 
|---|
| 91 | if (poskey) { | 
|---|
| 92 | newmsg = (char *) malloc(strlen(msg)-1 + strlen(lastkeyword)); | 
|---|
| 93 | strcpy(newmsg,msg); | 
|---|
| 94 | newmsg[poskey-msg] = '\0'; | 
|---|
| 95 | strcat(newmsg,lastkeyword); | 
|---|
| 96 | strcat(newmsg,&poskey[2]); | 
|---|
| 97 | ExEnv::errn() << "IPV2::warn: "; | 
|---|
| 98 | ExEnv::errn() << newmsg; | 
|---|
| 99 | ExEnv::errn() << endl; | 
|---|
| 100 | if (poskey) free(newmsg); | 
|---|
| 101 | } | 
|---|
| 102 | else { | 
|---|
| 103 | ExEnv::errn() << "IPV2::warn: "; | 
|---|
| 104 | ExEnv::errn() << msg; | 
|---|
| 105 | ExEnv::errn() << endl; | 
|---|
| 106 | } | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | void | 
|---|
| 110 | IPV2::ip_lastkeyword(const char*keyword) | 
|---|
| 111 | { | 
|---|
| 112 | strncpy(lastkeyword,keyword, KEYWORD_LENGTH-1); | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | void | 
|---|
| 116 | IPV2::ip_lastkeywordtree(ip_keyword_tree_t*kt) | 
|---|
| 117 | { | 
|---|
| 118 | lastkeyword[0] = '\0'; | 
|---|
| 119 | ip_lastkeyword_(kt); | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | void | 
|---|
| 123 | IPV2::ip_lastkeyword_(ip_keyword_tree_t*kt) | 
|---|
| 124 | { | 
|---|
| 125 | if (kt->up) ip_lastkeyword_(kt->up); | 
|---|
| 126 | if (strlen(lastkeyword) + strlen(kt->keyword) + 2 > KEYWORD_LENGTH) { | 
|---|
| 127 | ExEnv::errn() << "IPV2: keyword too big" << endl; | 
|---|
| 128 | abort(); | 
|---|
| 129 | } | 
|---|
| 130 | strcat(lastkeyword,":"); | 
|---|
| 131 | strcat(lastkeyword,kt->keyword); | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 135 |  | 
|---|
| 136 | // Local Variables: | 
|---|
| 137 | // mode: c++ | 
|---|
| 138 | // c-file-style: "CLJ" | 
|---|
| 139 | // End: | 
|---|