Example #1
0
int generateOp2op(const char* opcodes_def) {
    int i = 0, retval = 1;
    char left[32], right[32];
    int readcount = 0, linenum = 0;

    FILE* F = (opcodes_def == NULL) ? stdout : fopen(opcodes_def, "rt");
    if (F == NULL) cannot("open", opcodes_def);

    for (i = 0; i < OP2OP_SIZE; i++) {
        op2op[i] = i;
    }

    while ((readcount = fscanf(F, "%30s %30s\n", left, right)) != EOF) {
        linenum++;
        if (readcount == 2) {
            int li = getOpIndex(left);
            int ri = getOpIndex(right);
            if (0 <= li && li < OP2OP_SIZE && 0 <= ri && ri < OP2OP_SIZE) {
                op2op[li] = ri;
            } else {
                fprintf(stderr, " error in line %d : cannot find OpCode or OpNumber not in range(0 - %d).\n", linenum, OP2OP_SIZE);
                retval = 0;
                break;
            }
        } else if (readcount == 1 || readcount > 2) {
            fprintf(stderr, " error in line %d : One line must have 2 OpCode or OpNumber.\n", linenum);
            retval = 0;
            break;
        }
    }

    if (fclose(F)) cannot("close", opcodes_def);
    return retval;
}
Example #2
0
void
VixMntMsgQue::receiveMsgOp(VixMntMsgOp *msg_op,
                                unsigned *msg_prio)
{
   this->getattr(&this->vixMntMsgAttr);

   char *buf = new char[this->vixMntMsgAttr.mq_msgsize];
   // if not memeset, it may be old value
   memset(buf, 0, this->vixMntMsgAttr.mq_msgsize);

   if (receive(buf, this->vixMntMsgAttr.mq_msgsize, msg_prio) < 0) {
      *msg_op = VixMntOp(ERROR);
   } else {
      *msg_op = getOpIndex(buf);
   }

   delete[] buf;
}