From 75007da068aac10fed90fc5234ab2d50deed3e61 Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Thu, 1 Mar 2001 00:22:23 +0000 Subject: Modified icons. Started NLS support. Added kpsion KDE2 application. Unified file-headers. --- lib/rpcs.cc | 469 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 243 insertions(+), 226 deletions(-) (limited to 'lib/rpcs.cc') diff --git a/lib/rpcs.cc b/lib/rpcs.cc index 837f235..2e1288d 100644 --- a/lib/rpcs.cc +++ b/lib/rpcs.cc @@ -1,19 +1,25 @@ -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program 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 General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// - +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + * Copyright (C) 1999-2001 Fritz Elfert + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -32,56 +38,61 @@ #include "Enum.h" ENUM_DEFINITION(rpcs::machs, rpcs::PSI_MACH_UNKNOWN) { - stringRep.add(rpcs::PSI_MACH_UNKNOWN, "Unknown device"); - stringRep.add(rpcs::PSI_MACH_PC, "PC"); - stringRep.add(rpcs::PSI_MACH_MC, "MC"); - stringRep.add(rpcs::PSI_MACH_HC, "HC"); - stringRep.add(rpcs::PSI_MACH_S3, "Series 3"); - stringRep.add(rpcs::PSI_MACH_S3A, "Series 3a, 3c or 3mx"); - stringRep.add(rpcs::PSI_MACH_WORKABOUT, "Workabout"); - stringRep.add(rpcs::PSI_MACH_SIENNA, "Sienna"); - stringRep.add(rpcs::PSI_MACH_S3C, "Series 3c"); - stringRep.add(rpcs::PSI_MACH_S5, "Series 5"); - stringRep.add(rpcs::PSI_MACH_WINC, "WinC"); + stringRep.add(rpcs::PSI_MACH_UNKNOWN, N_("Unknown device")); + stringRep.add(rpcs::PSI_MACH_PC, N_("PC")); + stringRep.add(rpcs::PSI_MACH_MC, N_("MC")); + stringRep.add(rpcs::PSI_MACH_HC, N_("HC")); + stringRep.add(rpcs::PSI_MACH_S3, N_("Series 3")); + stringRep.add(rpcs::PSI_MACH_S3A, N_("Series 3a, 3c or 3mx")); + stringRep.add(rpcs::PSI_MACH_WORKABOUT, N_("Workabout")); + stringRep.add(rpcs::PSI_MACH_SIENNA, N_("Sienna")); + stringRep.add(rpcs::PSI_MACH_S3C, N_("Series 3c")); + stringRep.add(rpcs::PSI_MACH_S5, N_("Series 5")); + stringRep.add(rpcs::PSI_MACH_WINC, N_("WinC")); } ENUM_DEFINITION(rpcs::batterystates, rpcs::PSI_BATT_DEAD) { - stringRep.add(rpcs::PSI_BATT_DEAD, "Empty"); - stringRep.add(rpcs::PSI_BATT_VERYLOW, "Very Low"); - stringRep.add(rpcs::PSI_BATT_LOW, "Low"); - stringRep.add(rpcs::PSI_BATT_GOOD, "Good"); + stringRep.add(rpcs::PSI_BATT_DEAD, N_("Empty")); + stringRep.add(rpcs::PSI_BATT_VERYLOW, N_("Very Low")); + stringRep.add(rpcs::PSI_BATT_LOW, N_("Low")); + stringRep.add(rpcs::PSI_BATT_GOOD, N_("Good")); } ENUM_DEFINITION(rpcs::languages, rpcs::PSI_LANG_TEST) { - stringRep.add(rpcs::PSI_LANG_TEST, "Test"); - stringRep.add(rpcs::PSI_LANG_en_GB, "English"); - stringRep.add(rpcs::PSI_LANG_de_DE, "German"); - stringRep.add(rpcs::PSI_LANG_fr_FR, "French"); - stringRep.add(rpcs::PSI_LANG_es_ES, "Spanish"); - stringRep.add(rpcs::PSI_LANG_it_IT, "Italian"); - stringRep.add(rpcs::PSI_LANG_sv_SE, "Swedish"); - stringRep.add(rpcs::PSI_LANG_da_DK, "Danish"); - stringRep.add(rpcs::PSI_LANG_no_NO, "Norwegian"); - stringRep.add(rpcs::PSI_LANG_fi_FI, "Finnish"); - stringRep.add(rpcs::PSI_LANG_en_US, "American"); - stringRep.add(rpcs::PSI_LANG_fr_CH, "Swiss French"); - stringRep.add(rpcs::PSI_LANG_de_CH, "Swiss German"); - stringRep.add(rpcs::PSI_LANG_pt_PT, "Portugese"); - stringRep.add(rpcs::PSI_LANG_tr_TR, "Turkish"); - stringRep.add(rpcs::PSI_LANG_is_IS, "Icelandic"); - stringRep.add(rpcs::PSI_LANG_ru_RU, "Russian"); - stringRep.add(rpcs::PSI_LANG_hu_HU, "Hungarian"); - stringRep.add(rpcs::PSI_LANG_nl_NL, "Dutch"); - stringRep.add(rpcs::PSI_LANG_nl_BE, "Belgian Flemish"); - stringRep.add(rpcs::PSI_LANG_en_AU, "Australian"); - stringRep.add(rpcs::PSI_LANG_fr_BE, "Belgish French"); - stringRep.add(rpcs::PSI_LANG_de_AT, "Austrian"); - stringRep.add(rpcs::PSI_LANG_en_NZ, "New Zealand"); // FIXME: not shure about ISO code - stringRep.add(rpcs::PSI_LANG_fr_CA, "International French"); // FIXME: not shure about ISO code - stringRep.add(rpcs::PSI_LANG_cs_CZ, "Czech"); - stringRep.add(rpcs::PSI_LANG_sk_SK, "Slovak"); - stringRep.add(rpcs::PSI_LANG_pl_PL, "Polish"); - stringRep.add(rpcs::PSI_LANG_sl_SI, "Slovenian"); + stringRep.add(rpcs::PSI_LANG_TEST, N_("Test")); + stringRep.add(rpcs::PSI_LANG_en_GB, N_("English")); + stringRep.add(rpcs::PSI_LANG_de_DE, N_("German")); + stringRep.add(rpcs::PSI_LANG_fr_FR, N_("French")); + stringRep.add(rpcs::PSI_LANG_es_ES, N_("Spanish")); + stringRep.add(rpcs::PSI_LANG_it_IT, N_("Italian")); + stringRep.add(rpcs::PSI_LANG_sv_SE, N_("Swedish")); + stringRep.add(rpcs::PSI_LANG_da_DK, N_("Danish")); + stringRep.add(rpcs::PSI_LANG_no_NO, N_("Norwegian")); + stringRep.add(rpcs::PSI_LANG_fi_FI, N_("Finnish")); + stringRep.add(rpcs::PSI_LANG_en_US, N_("American")); + stringRep.add(rpcs::PSI_LANG_fr_CH, N_("Swiss French")); + stringRep.add(rpcs::PSI_LANG_de_CH, N_("Swiss German")); + stringRep.add(rpcs::PSI_LANG_pt_PT, N_("Portugese")); + stringRep.add(rpcs::PSI_LANG_tr_TR, N_("Turkish")); + stringRep.add(rpcs::PSI_LANG_is_IS, N_("Icelandic")); + stringRep.add(rpcs::PSI_LANG_ru_RU, N_("Russian")); + stringRep.add(rpcs::PSI_LANG_hu_HU, N_("Hungarian")); + stringRep.add(rpcs::PSI_LANG_nl_NL, N_("Dutch")); + stringRep.add(rpcs::PSI_LANG_nl_BE, N_("Belgian Flemish")); + stringRep.add(rpcs::PSI_LANG_en_AU, N_("Australian")); + stringRep.add(rpcs::PSI_LANG_fr_BE, N_("Belgish French")); + stringRep.add(rpcs::PSI_LANG_de_AT, N_("Austrian")); + stringRep.add(rpcs::PSI_LANG_en_NZ, N_("New Zealand")); // FIXME: not shure about ISO code + stringRep.add(rpcs::PSI_LANG_fr_CA, N_("International French")); // FIXME: not shure about ISO code + stringRep.add(rpcs::PSI_LANG_cs_CZ, N_("Czech")); + stringRep.add(rpcs::PSI_LANG_sk_SK, N_("Slovak")); + stringRep.add(rpcs::PSI_LANG_pl_PL, N_("Polish")); + stringRep.add(rpcs::PSI_LANG_sl_SI, N_("Slovenian")); +} + +rpcs::~rpcs() +{ + skt->closeSocket(); } // @@ -90,35 +101,35 @@ ENUM_DEFINITION(rpcs::languages, rpcs::PSI_LANG_TEST) { void rpcs:: reconnect(void) { - skt->closeSocket(); - skt->reconnect(); - reset(); + //skt->closeSocket(); + skt->reconnect(); + reset(); } void rpcs:: reset(void) { - bufferStore a; - status = rfsv::E_PSI_FILE_DISC; - a.addStringT(getConnectName()); - if (skt->sendBufferStore(a)) { - if (skt->getBufferStore(a) == 1) { - if (!strcmp(a.getString(0), "Ok")) - status = rfsv::E_PSI_GEN_NONE; - } + bufferStore a; + status = rfsv::E_PSI_FILE_DISC; + a.addStringT(getConnectName()); + if (skt->sendBufferStore(a)) { + if (skt->getBufferStore(a) == 1) { + if (!strcmp(a.getString(0), "Ok")) + status = rfsv::E_PSI_GEN_NONE; } + } } Enum rpcs:: getStatus(void) { - return status; + return status; } const char *rpcs:: getConnectName(void) { - return "SYS$RPCS"; + return "SYS$RPCS"; } // @@ -127,45 +138,45 @@ getConnectName(void) bool rpcs:: sendCommand(enum commands cc, bufferStore & data) { - if (status == rfsv::E_PSI_FILE_DISC) { - reconnect(); - if (status == rfsv::E_PSI_FILE_DISC) - return false; - } - bool result; - bufferStore a; - a.addByte(cc); - a.addBuff(data); + if (status == rfsv::E_PSI_FILE_DISC) { + reconnect(); + if (status == rfsv::E_PSI_FILE_DISC) + return false; + } + bool result; + bufferStore a; + a.addByte(cc); + a.addBuff(data); + result = skt->sendBufferStore(a); + if (!result) { + reconnect(); result = skt->sendBufferStore(a); - if (!result) { - reconnect(); - result = skt->sendBufferStore(a); - if (!result) - status = rfsv::E_PSI_FILE_DISC; - } - return result; + if (!result) + status = rfsv::E_PSI_FILE_DISC; + } + return result; } Enum rpcs:: getResponse(bufferStore & data, bool statusIsFirstByte) { - Enum ret; - if (skt->getBufferStore(data) == 1) { - if (statusIsFirstByte) { - ret = (enum rfsv::errs)((char)data.getByte(0)); - data.discardFirstBytes(1); - } else { - int l = data.getLen(); - if (l > 0) { - ret = (enum rfsv::errs)((char)data.getByte(data.getLen() - 1)); - data.init((const unsigned char *)data.getString(), l - 1); - } else - ret = rfsv::E_PSI_GEN_FAIL; - } - return ret; - } else - status = rfsv::E_PSI_FILE_DISC; - return status; + Enum ret; + if (skt->getBufferStore(data) == 1) { + if (statusIsFirstByte) { + ret = (enum rfsv::errs)((char)data.getByte(0)); + data.discardFirstBytes(1); + } else { + int l = data.getLen(); + if (l > 0) { + ret = (enum rfsv::errs)((char)data.getByte(data.getLen() - 1)); + data.init((const unsigned char *)data.getString(), l - 1); + } else + ret = rfsv::E_PSI_GEN_FAIL; + } + return ret; + } else + status = rfsv::E_PSI_FILE_DISC; + return status; } // @@ -174,184 +185,190 @@ getResponse(bufferStore & data, bool statusIsFirstByte) Enum rpcs:: getNCPversion(int &major, int &minor) { - Enum res; - bufferStore a; - - if (!sendCommand(QUERY_NCP, a)) - return rfsv::E_PSI_FILE_DISC; - if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) - return res; - if (a.getLen() != 2) - return rfsv::E_PSI_GEN_FAIL; - major = a.getByte(0); - minor = a.getByte(1); + Enum res; + bufferStore a; + + if (!sendCommand(QUERY_NCP, a)) + return rfsv::E_PSI_FILE_DISC; + if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) return res; + if (a.getLen() != 2) + return rfsv::E_PSI_GEN_FAIL; + major = a.getByte(0); + minor = a.getByte(1); + return res; } Enum rpcs:: execProgram(const char *program, const char *args) { - bufferStore a; - - a.addStringT(program); - int l = strlen(program); - for (int i = 127; i > l; i--) - a.addByte(0); - - /** - * This is a hack for the jotter app on mx5 pro. (and probably others) - * Jotter seems to read it's arguments one char past normal apps. - * Without this hack, The Drive-Character gets lost. Other apps don't - * seem to be hurt by the additional blank. - */ - a.addByte(strlen(args) + 1); - a.addByte(' '); - - a.addStringT(args); - if (!sendCommand(EXEC_PROG, a)) - return rfsv::E_PSI_FILE_DISC; - return getResponse(a, true); + bufferStore a; + + a.addStringT(program); + int l = strlen(program); + for (int i = 127; i > l; i--) + a.addByte(0); + + /** + * This is a hack for the jotter app on mx5 pro. (and probably others) + * Jotter seems to read it's arguments one char past normal apps. + * Without this hack, The Drive-Character gets lost. Other apps don't + * seem to be hurt by the additional blank. + */ + a.addByte(strlen(args) + 1); + a.addByte(' '); + + a.addStringT(args); + if (!sendCommand(EXEC_PROG, a)) + return rfsv::E_PSI_FILE_DISC; + return getResponse(a, true); } Enum rpcs:: stopProgram(const char *program) { - bufferStore a; + bufferStore a; - a.addStringT(program); - if (!sendCommand(STOP_PROG, a)) - return rfsv::E_PSI_FILE_DISC; - return getResponse(a, true); + a.addStringT(program); + if (!sendCommand(STOP_PROG, a)) + return rfsv::E_PSI_FILE_DISC; + return getResponse(a, true); } Enum rpcs:: queryProgram(const char *program) { - bufferStore a; + bufferStore a; - a.addStringT(program); - if (!sendCommand(QUERY_PROG, a)) - return rfsv::E_PSI_FILE_DISC; - return getResponse(a, true); + a.addStringT(program); + if (!sendCommand(QUERY_PROG, a)) + return rfsv::E_PSI_FILE_DISC; + return getResponse(a, true); } Enum rpcs:: formatOpen(const char *drive, int &handle, int &count) { - Enum res; - bufferStore a; - - a.addStringT(drive); - if (!sendCommand(FORMAT_OPEN, a)) - return rfsv::E_PSI_FILE_DISC; - if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) - return res; - if (a.getLen() != 4) - return rfsv::E_PSI_GEN_FAIL; - handle = a.getWord(0); - count = a.getWord(2); + Enum res; + bufferStore a; + + a.addStringT(drive); + if (!sendCommand(FORMAT_OPEN, a)) + return rfsv::E_PSI_FILE_DISC; + if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) return res; + if (a.getLen() != 4) + return rfsv::E_PSI_GEN_FAIL; + handle = a.getWord(0); + count = a.getWord(2); + return res; } Enum rpcs:: formatRead(int handle) { - bufferStore a; + bufferStore a; - a.addWord(handle); - if (!sendCommand(FORMAT_READ, a)) - return rfsv::E_PSI_FILE_DISC; - return getResponse(a, true); + a.addWord(handle); + if (!sendCommand(FORMAT_READ, a)) + return rfsv::E_PSI_FILE_DISC; + return getResponse(a, true); } Enum rpcs:: getUniqueID(const char *device, long &id) { - Enum res; - bufferStore a; - - a.addStringT(device); - if (!sendCommand(GET_UNIQUEID, a)) - return rfsv::E_PSI_FILE_DISC; - if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) - return res; - if (a.getLen() != 4) - return rfsv::E_PSI_GEN_FAIL; - id = a.getDWord(0); + Enum res; + bufferStore a; + + a.addStringT(device); + if (!sendCommand(GET_UNIQUEID, a)) + return rfsv::E_PSI_FILE_DISC; + if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) return res; + if (a.getLen() != 4) + return rfsv::E_PSI_GEN_FAIL; + id = a.getDWord(0); + return res; } Enum rpcs:: getOwnerInfo(bufferArray &owner) { - Enum res; - bufferStore a; + Enum res; + bufferStore a; - if (!sendCommand(GET_OWNERINFO, a)) - return rfsv::E_PSI_FILE_DISC; - if ((res = (enum rfsv::errs)getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) - return res; - a.addByte(0); - int l = a.getLen(); - char *s = (char *)a.getString(0); - for (int i = 0; i < l; i++) - if (s[i] == 6) - s[i] = 0; - owner.clear(); - while (l > 0) { - if (*s != '\0') { - bufferStore b; - b.addStringT(s); - owner += b; - l -= (strlen(s) + 1); - s += (strlen(s) + 1); - } else { - l--; - s++; - } - } + if (!sendCommand(GET_OWNERINFO, a)) + return rfsv::E_PSI_FILE_DISC; + if ((res = (enum rfsv::errs)getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) return res; + a.addByte(0); + int l = a.getLen(); + char *s = (char *)a.getString(0); + for (int i = 0; i < l; i++) + if (s[i] == 6) + s[i] = 0; + owner.clear(); + while (l > 0) { + if (*s != '\0') { + bufferStore b; + b.addStringT(s); + owner += b; + l -= (strlen(s) + 1); + s += (strlen(s) + 1); + } else { + l--; + s++; + } + } + return res; } Enum rpcs:: getMachineType(Enum &type) { - Enum res; - bufferStore a; - - if (!sendCommand(GET_MACHINETYPE, a)) - return rfsv::E_PSI_FILE_DISC; - if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) - return res; - if (a.getLen() != 2) - return rfsv::E_PSI_GEN_FAIL; - type = (enum machs)a.getWord(0); + Enum res; + bufferStore a; + + if (!sendCommand(GET_MACHINETYPE, a)) + return rfsv::E_PSI_FILE_DISC; + if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) return res; + if (a.getLen() != 2) + return rfsv::E_PSI_GEN_FAIL; + type = (enum machs)a.getWord(0); + return res; } Enum rpcs:: fuser(const char *name, char *buf, int maxlen) { - Enum res; - bufferStore a; - char *p; - - a.addStringT(name); - if (!sendCommand(FUSER, a)) - return rfsv::E_PSI_FILE_DISC; - if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) - return res; - strncpy(buf, a.getString(0), maxlen - 1); - while ((p = strchr(buf, 6))) - *p = '\0'; + Enum res; + bufferStore a; + char *p; + + a.addStringT(name); + if (!sendCommand(FUSER, a)) + return rfsv::E_PSI_FILE_DISC; + if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) return res; + strncpy(buf, a.getString(0), maxlen - 1); + while ((p = strchr(buf, 6))) + *p = '\0'; + return res; } Enum rpcs:: quitServer(void) { - bufferStore a; - if (!sendCommand(QUIT_SERVER, a)) - return rfsv::E_PSI_FILE_DISC; - return getResponse(a, true); + bufferStore a; + if (!sendCommand(QUIT_SERVER, a)) + return rfsv::E_PSI_FILE_DISC; + return getResponse(a, true); } + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ -- cgit v1.2.3