コード例 #1
0
ファイル: Fun.c プロジェクト: penguiner/compiler
TreeNode* CreatNode(char *name, char *context, char* type)
{
  if(debug)
    printf("CreateNode %s\n",context);
  TreeNode *tmp = (TreeNode *) malloc(sizeof(TreeNode));
  tmp->terminal = 1;
  tmp->sibling = NULL;
  tmp->child = NULL;
  tmp->name = NULL;
  tmp->type=NULL;
  tmp->name = MyStrCpy(name);
  
  tmp->type = MyStrCpy(type);
  //tmp->type = type;
  assert(strcmp(tmp->name,name)==0);
  

  if(strcmp(type,"INT")==0)
    tmp->val.f = atoi(context);
  else  if(strcmp(type,"FLOAT")==0)
    tmp->val.f = atof(context);
  else  if(context != NULL)
    tmp->val.s = MyStrCpy(context);
    /*
  switch(type)
  {
    case INT: tmp->val.i = atoi(context); break;
    case FLOAT: tmp->val.f = atof(context); break;
    default:  if(context != NULL) MyStrCpy(tmp->val.s=NULL, context);
  }*/

  return tmp;
}
コード例 #2
0
ファイル: AmpCmds.c プロジェクト: GSI-CS-CO/kernel_modules
int ParseIbuf(char sep) {

unsigned char *cp;
unsigned char *ep, cks, c;
int i, err, len;

   InitItems();
   bcopy((void *) ibuf, icpy, IBUF_SIZE);

   len = 0;
   for (i=0; i<IBUF_SIZE; i++) {
      c = icpy[i];
      if (c == 0) icpy[i] = ' ';
      if (c == ETX) {
	 icpy[i] = 0;
	 len = i + 1;
	 break;
      }
   }

   err = 0;
   if (len > 4) {
      cks = 0; for (i=0; i<len -2; i++) cks ^= ibuf[i];
      if (cks != ibuf[i]) err++;
      else                icpy[i] = 0;
   } else err++;
   if (err) return 0; /* Illegal string length or checksum error */

   cp = &(icpy[4]);          /* Skip STX 99 c */
   for (i=0; i<ITEMS; i++) {
      ep = index(cp,sep);
      if (ep) {
	 *ep = 0;
	 MyStrCpy(items[i],cp);
	 cp = ++ep;
      } else break;
   }
   MyStrCpy(items[i],cp); item = i+1;
   return item;
}
コード例 #3
0
ファイル: Fun.c プロジェクト: penguiner/compiler
TreeNode *CreatNonTreeNode(char *name)
{
    if(debug)
      printf("CreateNonTreeNode %s\n",name);
    TreeNode *tmp = (TreeNode *) malloc(sizeof(TreeNode));
    if(tmp == NULL)
      printf("err in malloc\n");
    tmp->terminal = 0;
    tmp->sibling = NULL;
    tmp->child = NULL;
    //tmp->buf = NULL;
    //tmp->name = NULL;
    //tmp->buf = malloc((strlen(context)+1)*sizeof(char));
    //strcpy(tmp->buf,context);
    tmp->name = MyStrCpy(name);
    DEBUG printf("name is %s\n", tmp->name);
    assert(strcmp(tmp->name,name)==0);
    return tmp;
}
コード例 #4
0
void Shell()
{
   int term_num, stdin_pid, stdout_pid, print_driver_pid, 
		file_system_pid;
   char login[50], passwd[50], cmd_str[50];
   msg_t msg;
   MsgRcv(&msg); 
   msg.sender = msg.nums[0];
   term_num = msg.nums[1];
   print_driver_pid = msg.nums[2];
   file_system_pid = msg.nums[3];
   msg.nums[4] = ECHO_ON;
 
   
   stdin_pid = Spawn(Stdin); 
   stdout_pid = Spawn(Stdout);	
   MsgSnd(stdin_pid, &msg);	
   MsgSnd(stdout_pid, &msg);	
   TerminalInit(term_num);
   
   while(1){
      while(1){
         MyStrCpy(msg.bytes, "login : "******"password: "******"Illegal login and password!\n");
         MsgSnd(stdout_pid, &msg);
         MsgRcv(&msg);
      }
      
      while(1){
         MyStrCpy(msg.bytes, "\nOS Alpha > ");
         MsgSnd(stdout_pid, &msg);
         MsgRcv(&msg);
         
         MsgSnd(stdin_pid, &msg);
         MsgRcv(&msg);
         MyStrCpy(cmd_str, msg.bytes);
         
         if( StrCmpLen(cmd_str, "print", 5) == 1 ){
            ShellPrint(cmd_str, print_driver_pid, file_system_pid);
            MyStrCpy(msg.bytes, cmd_str);
            MsgSnd(stdout_pid, &msg);
            MsgRcv(&msg);            
         }
         else if( StrCmp(cmd_str, "bye") == 1){
            break;
         }
         else if( StrCmp(cmd_str, "\n")){
            continue;
         }
         else if(StrCmp(cmd_str, "help")){
            ShellHelp(stdout_pid);
         }
         else if(StrCmp(cmd_str, "who")){
            ShellWho(stdout_pid);
         }
         else if(StrCmpLen(cmd_str, "dir", 3)){
            ShellDir(cmd_str, stdout_pid,file_system_pid);            
         }
         else if(StrCmpLen(cmd_str, "type", 4)){
            ShellType(cmd_str, stdout_pid, file_system_pid);
         }
         else {
            MyStrCpy(msg.bytes, "Invalid command!\n");
            MsgSnd(stdout_pid, &msg);
            MsgRcv(&msg);
         }
      }
   }
}