/* * CDE - Common Desktop Environment * * Copyright (c) 1993-2012, The Open Group. All rights reserved. * * These libraries and programs are free software; you can * redistribute them and/or modify them under the terms of the GNU * Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version. * * These libraries and programs are distributed in the hope that * they will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public * License along with these libraries and programs; if not, write * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth * Floor, Boston, MA 02110-1301 USA */ /* * $XConsortium: load.c /main/3 1995/11/06 18:29:57 rswiston $ * * @(#)load.c 1.18 03 Apr 1995 cde_app_builder/src/libABil * * RESTRICTED CONFIDENTIAL INFORMATION: * * The information in this document is subject to special * restrictions in a confidential disclosure agreement between * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this * document outside HP, IBM, Sun, USL, SCO, or Univel without * Sun's specific written approval. This document and all copies * and derivative works thereof must be returned or destroyed at * Sun's request. * * Copyright 1993 Sun Microsystems, Inc. All rights reserved. * */ /* * load.c - load c file. */ #include #include #include "loadP.h" #include "bilP.h" #define MAX_NAME_LEN 256 static char Current_Object[MAX_NAME_LEN]= ""; static char Attribute[MAX_NAME_LEN]= ""; static char Action_Attr[MAX_NAME_LEN]= ""; static char File[MAX_NAME_LEN]= ""; static AbilErrorMessage Errormsg[BIL_ERRMSG_COUNT]; static AbilGetLineNumberCallback getLineNumberCB = NULL; int abilP_err_line_number = -1; static int abil_load_errmsg_table(); /* * Build a status message including the current object, the current * attribute, and the specified message. * * The userMessage argument passed is is an index into the internal * error message table. */ STRING abil_loadmsg(STRING userMessage) { static char msg[256]; char tmpMsg[256]; int lineNumber = abil_loadmsg_get_line_number(); *msg= 0; *tmpMsg= 0; if (*File != 0) { sprintf(tmpMsg, catgets(ABIL_MESSAGE_CATD, ABIL_MESSAGE_SET, 27, "file: %s"), File); strcat(msg, tmpMsg); } if (lineNumber > 0) { sprintf(tmpMsg, catgets(ABIL_MESSAGE_CATD, ABIL_MESSAGE_SET, 28, ", line: %d"), lineNumber); strcat(msg, tmpMsg); } if (*Current_Object != 0) { sprintf(tmpMsg, catgets(ABIL_MESSAGE_CATD, ABIL_MESSAGE_SET,29, ", object: %s"), Current_Object); strcat(msg, tmpMsg); } if (*Attribute != 0) { sprintf(tmpMsg, catgets(ABIL_MESSAGE_CATD, ABIL_MESSAGE_SET, 30, ", attribute: %s"), Attribute); strcat(msg, tmpMsg); } if (*Action_Attr != 0) { sprintf(tmpMsg, catgets(ABIL_MESSAGE_CATD, ABIL_MESSAGE_SET, 31, ", action-attribute: %s"), Action_Attr); strcat(msg, tmpMsg); } strcat(msg, catgets(ABIL_MESSAGE_CATD, ABIL_MESSAGE_SET, 32, ", ")); if ( (userMessage == 0) || (*userMessage == 0) ) { strcat(msg, catgets(ABIL_MESSAGE_CATD, ABIL_MESSAGE_SET, 33, "syntax error")); } else { strcat(msg, userMessage); } strcat(msg, catgets(ABIL_MESSAGE_CATD, ABIL_MESSAGE_SET, 34, "\n")); return msg; } static int move_string(STRING to, STRING from) { if (from == NULL) { *to= 0; } else { strcpy(to, from); } return 0; } int abil_loadmsg_clear(void) { move_string(Current_Object, NULL); move_string(Attribute, NULL); move_string(Action_Attr, NULL); move_string(File, NULL); return 0; } int abil_loadmsg_set_object(STRING objname) { return move_string(Current_Object, objname); } int abil_loadmsg_set_att(STRING attname) { return move_string(Attribute, attname); } int abil_loadmsg_set_action_att(STRING actattname) { return move_string(Action_Attr, actattname); } int abil_loadmsg_set_file(STRING filename) { return move_string(File, filename); } BOOL abil_loadmsg_err_printed(void) { int cur_err_line = bilP_load_get_line_number(); if ((abilP_err_line_number == cur_err_line) || (cur_err_line == -1)) return TRUE; else return FALSE; } int abil_loadmsg_set_err_printed(BOOL printed) { /* If the yacc error has been printed out, then * set the global error line number to the current * line number in the bil file, else reset it. */ if (printed) abilP_err_line_number = bilP_load_get_line_number(); else abilP_err_line_number = -1; return 0; } /* ** This routine prints one of the standard BIL load error messages by ** looking it up in the error message table, fetching the right string ** from the message catalog, and passing it to abil_loadmsg() to be output. ** ** All the I18N has to happen here (before abil_loadmsg() is called)... */ int abil_print_load_err(int errmsg) { static BOOL errmsg_tbl_init = FALSE; char msg[1024] = ""; int msgLen = 0; /* ** Load up the error message table if this is the first time we've ** needed to output an error message. */ if(errmsg_tbl_init == FALSE) { abil_load_errmsg_table(); errmsg_tbl_init = TRUE; } if ((errmsg == ERR_NOT_IMPL) && (!util_be_verbose())) { return 0; } if (!abil_loadmsg_err_printed()) { if(Errormsg[errmsg].msg_id < 0) { snprintf(msg, sizeof(msg), "%s", catgets(ABIL_MESSAGE_CATD, ABIL_MESSAGE_SET, 33, "syntax error")); } else { snprintf(msg, sizeof(msg), "%s", catgets(ABIL_MESSAGE_CATD, ABIL_MESSAGE_SET, Errormsg[errmsg].msg_id, Errormsg[errmsg].def_str)); } if ((msgLen = strlen(msg)) > 0) { if (msg[msgLen-1] == '\n') { msg[msgLen-1] = 0; } } util_error(abil_loadmsg(msg)); abil_loadmsg_set_err_printed(TRUE); } return 0; } /* ** This routine prints a custom error message rather than one of the standard ** ones from the BIL error message table. It takes the message string as ** an argument and then passes it off to abil_loadmsg() to be output. ** ** This routine assumes the custom error message has been I18Nized beforehand. */ int abil_print_custom_load_err(STRING errmsgstr) { if (!abil_loadmsg_err_printed()) { util_error(abil_loadmsg(errmsgstr)); abil_loadmsg_set_err_printed(TRUE); } return 0; } /* Macro to make it easier to do error message table initialization */ #define blet(i,m,s) \ Errormsg[i].msg_id = m; \ Errormsg[i].def_str = s /* Load the BIL error message table with message set and default text */ static int abil_load_errmsg_table() { int i; /* "Clear" out the error message table by setting message id to -1 */ for(i=0;i