/*\ * libLB - The LBPP support library * Copyright (C) 2001 Anthony Liguori * * libLB is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * libLB 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \*/ #include #include #include #include #include #include #include #include #include #include "lb.h" void LB_PRINT_0(LBContext *cxt) { printf("\n"); } void LB_PRINT_1(LBContext *cxt, LBVarArg *arg) { LBVarArg *node = arg; while (node->next) { switch (node->type.var_type) { case STRING: printf("%s", node->data.str->data); break; case DOUBLE: printf("%f", node->data.db); break; default: break; } node = node->next; } if (node->type.end_type == VA_END_HARD) { printf("\n"); } lb_va_destroy(arg); } void LB_PRINT_2(LBContext *cxt, LBHandle hnd) { LBString nl = lbstr_cstr("\n"); assert(hnd.dev->dev_type & LB_DEV_WRITE); hnd.dev->write_str(cxt, hnd.data, nl); lbstr_destroy(nl); } void LB_PRINT_3(LBContext *cxt, LBHandle hnd, LBVarArg *arg) { LBVarArg *node = arg; assert(hnd.dev->dev_type & LB_DEV_WRITE); while (node->next) { switch (node->type.var_type) { case STRING: hnd.dev->write_str(cxt, hnd.data, node->data.str); break; case DOUBLE: hnd.dev->write_db(cxt, hnd.data, node->data.db); break; default: break; } node = node->next; } if (node->type.end_type == VA_END_HARD) { LBString nl = lbstr_cstr("\n"); hnd.dev->write_str(cxt, hnd.data, nl); lbstr_destroy(nl); } lb_va_destroy(arg); } void LB_CLOSE_1(LBContext *cxt, Variable *hnd) { hnd->data.hnd.dev->close(cxt, hnd->data.hnd.data); } void LB_OPEN_5(LBContext *cxt, LBString name, char *type, Variable *hnd) { LBDevice *dev = lb_get_dev(cxt, type); assert(dev); hnd->data.hnd.dev = dev; if (!dev->open(cxt, name->data, hnd)) { LB_NOTICE_1(cxt, lbstr_cat(lbstr_cstr("Could Not Open "), name)); LB_END_0(cxt); } lbstr_destroy(name); } void LB_INPUT_3(LBContext *cxt, LBHandle hnd, LBVarArg *arg) { LBVarArg *node = arg; assert(hnd.dev->dev_type & LB_DEV_READ); while (node->next) { assert(node->reference); switch (node->type.var_type) { case STRING: lbstr_set(&(node->data.var->data.str), hnd.dev->read_str(cxt, hnd.data, 0)); break; case DOUBLE: node->data.var->data.db = hnd.dev->read_db(cxt, hnd.data); break; default: break; } node = node->next; } } void LB_LINE_4(LBContext *cxt, LBHandle hnd, Variable *lvalue) { if (lvalue->type == STRING) { lbstr_set(&(lvalue->data.str), hnd.dev->read_str(cxt, hnd.data, 0)); } } void LB_END_0(LBContext *cxt) { exit(0); } void LB_BEEP_0(LBContext *cxt) { printf("\a"); } void LB_KILL_1(LBContext *cxt, LBString file) { unlink(file->data); lbstr_destroy(file); }