コード例 #1
0
ファイル: Scheduler.c プロジェクト: Iobotics/VexOS
static void printCommands(Command* cmd, DisplayLine* cache, unsigned char* line, int indent,
    Rect innerRect, unsigned char height, unsigned char width) 
{
    // make sure we don't overflow the window //
    if(*line >= height) return;

    // NULL indicates root node, print scheduler Commands //
    if(!cmd) {
        ListNode* node = runningList.firstNode;
        while(node != NULL) {
            printCommands(node->data, cache, line, indent, innerRect, height, width);
            node = node->next;
        }
        return;
    }
    
    // determine line color //
    Color color = Color_Black;
    if(cmd->startTime == -1) {
        color = Color_DarkYellow;
    } else if(Command_timeSinceInitialized(cmd) < 1000) {
        color = Color_DarkGreen;
    }

    // print this Command if changed //
    if(cmd->objectId != cache[*line].objectId || color != cache[*line].color) {
        // compute display characteristics: position //
        unsigned char top    = innerRect.top + *line;
        unsigned char left   = innerRect.left;
        unsigned char xwidth = width - indent;
        // print command and increment line counter //
        PrintTextToGD(top, left, color, "%*s%-*.*s\n", indent, "", xwidth, xwidth, 
                      Command_getName(cmd));
        cache[*line] = (DisplayLine) { .objectId = cmd->objectId, .color = color };
    }
    (*line)++;
    // test for CommandGroup //
    if(CommandGroup_isGroup(cmd)) {
        // print children //
        ListNode* node = CommandGroup_getChildList(cmd)->firstNode;
        while(node != NULL) {
            GroupEntry* entry = node->data;
            printCommands(entry->command, cache, line, indent + 2, innerRect, height, width);
            node = node->next;
        }
        // print current node last //
        Command* xcmd = CommandGroup_getCurrentCommand(cmd);
        if(xcmd) printCommands(xcmd, cache, line, indent + 2, innerRect, height, width);
    }
}
コード例 #2
0
ファイル: Scheduler.c プロジェクト: Iobotics/VexOS
static void addRunningNode(ListNode* node) {
    static bool adding = false;
    
    // validate //
    if(node == NULL) return;
    Command* cmd = (Command*) node->data;
    if(cmd == NULL) { freeNode(node); return; }
    
    if(adding) {
        Info("Cannot start command during cancel(). Ignoring: %s", Command_getName(cmd));
        freeNode(node);
        return;
    }
    
    // make sure command is not already running //
    ListNode* xnode = runningList.firstNode;
    while(xnode != NULL) {
        if((Command*)xnode->data == cmd) {
            freeNode(node);
            return;
        }
        xnode = xnode->next;
    }
    
    // check that required Subsystems are available //
    Command* current;
    xnode = cmd->requiresList.firstNode;
    while(xnode != NULL) {
        current = ((Subsystem*) xnode->data)->currentCommand;
        if(current && !current->interruptible) {
            freeNode(node);
            return;
        }
        xnode = xnode->next;
    }
    
    // claim required Subsystems //
    adding = true;
    xnode = cmd->requiresList.firstNode;
    while(xnode != NULL) {
        Subsystem* sys = (Subsystem*) xnode->data;
        current = sys->currentCommand;
        if(current) {
            Command_cancel(current);
            // find the node with the command and remove it //
            ListNode* xnode2 = runningList.firstNode;
            while(xnode2 != NULL) {
                if((Command*)xnode2->data == current) {
                    removeRunningNode(xnode2);
                    break;
                }
                xnode2 = xnode2->next;
            }
        }
        sys->currentCommand = cmd;
        xnode = xnode->next;
    }
    adding = false;
    
    // add to command list //
    List_insertLast(&runningList, node);
    Command_startRunning(cmd);
}
コード例 #3
0
int main(int argc, char *argv[])
{
   char *pcLine;
   DynArray_T oTokens;
   DynArray_T oArgs;
   int iArgLength;
   int i;
   Command_T oCommand;

   pcPgmName = argv[0];

   /* Write to stdout a prompt consisting of a percent sign 
      and a space. */
   fprintf(stdout, "%% ");

   /* Read a line (that is, an array of characters) from stdin. */
   while ((pcLine = Token_readLine(stdin)) != NULL)
   {
      /* Write that line (array of characters) to stdout, and 
         flush the stdout buffer. */
      fprintf(stdout, "%s\n", pcLine);
      fflush(stdout);

      /* Pass the line (array of characters) to your lexical 
         analyzer to create a DynArray object containing tokens. */
      oTokens = Lex_analyze(pcLine);

      oCommand = Syn_analyze(oTokens);
      if (oCommand != NULL) {
         if (Command_getName(oCommand) != NULL)
            fprintf(stdout, "Command name: %s\n", 
               Command_getName(oCommand));
         if (Command_getArgs(oCommand) != NULL) {
            oArgs = Command_getArgs(oCommand);
            iArgLength = DynArray_getLength(oArgs);
            for (i = 0; i < iArgLength; i++) {
               fprintf(stdout, "Command arg: %s\n",
                  (char *)DynArray_get(oArgs, i));
            }
         }
         if (Command_getStdIn(oCommand) != NULL) {
            fprintf(stdout, "Command stdin: %s\n", 
               Command_getStdIn(oCommand));
         }
         if (Command_getStdOut(oCommand) != NULL) {
            fprintf(stdout, "Command stdout: %s\n", 
               Command_getStdOut(oCommand));
         }
         Command_free(oCommand);
      }   

      if (oTokens != NULL) {
         Token_freeTokens(oTokens);
         DynArray_free(oTokens);
      }  
      
      fprintf(stdout, "%% ");
      free(pcLine);
   }
   fprintf(stdout, "\n");

   return 0;
}