Exemplo n.º 1
0
Arquivo: gen.c Projeto: irori/8cc
static void emit_func_call(Node *node) {
    SAVE;
    int opos = stackpos;
    bool isptr = (node->type == AST_FUNCPTR_CALL);
    Ctype *ftype = isptr ? node->fptr->ctype->ptr : node->ftype;

    List *ints = make_list();
    List *floats = make_list();
    List *rest = make_list();
    classify_args(ints, floats, rest, node->args);
    save_arg_regs(list_len(ints), list_len(floats));

    bool padding = stackpos % 16;
    if (padding) {
        emit("sub $8, %%rsp");
        stackpos += 8;
    }

    emit_args(list_reverse(rest));
    if (isptr) {
        emit_expr(node->fptr);
        push("rax");
    }
    emit_args(ints);
    emit_args(floats);
    pop_float_args(list_len(floats));
    pop_int_args(list_len(ints));

    if (isptr) pop("r11");
    if (ftype->hasva)
        emit("mov $%d, %%eax", list_len(floats));

    if (isptr)
        emit("call *%%r11");
    else
        emit("call %s", node->fname);
    maybe_booleanize_retval(node->ctype);
    if (list_len(rest) > 0) {
        emit("add $%d, %%rsp", list_len(rest) * 8);
        stackpos -= list_len(rest) * 8;
    }
    if (padding) {
        emit("add $8, %%rsp");
        stackpos -= 8;
    }
    restore_arg_regs(list_len(ints), list_len(floats));
    assert(opos == stackpos);
}
Exemplo n.º 2
0
Arquivo: gen.c Projeto: 4ker/8cc
static void emit_func_call(Node *node) {
    SAVE;
    int opos = stackpos;
    bool isptr = (node->kind == AST_FUNCPTR_CALL);
    Type *ftype = isptr ? node->fptr->ty->ptr : node->ftype;

    Vector *ints = make_vector();
    Vector *floats = make_vector();
    Vector *rest = make_vector();
    classify_args(ints, floats, rest, node->args);
    save_arg_regs(vec_len(ints), vec_len(floats));

    bool padding = stackpos % 16;
    if (padding) {
        emit("sub $8, #rsp");
        stackpos += 8;
    }

    int restsize = emit_args(vec_reverse(rest));
    if (isptr) {
        emit_expr(node->fptr);
        push("rax");
    }
    emit_args(ints);
    emit_args(floats);
    pop_float_args(vec_len(floats));
    pop_int_args(vec_len(ints));

    if (isptr) pop("r11");
    if (ftype->hasva)
        emit("mov $%u, #eax", vec_len(floats));

    if (isptr)
        emit("call *#r11");
    else
        emit("call %s", node->fname);
    maybe_booleanize_retval(node->ty);
    if (restsize > 0) {
        emit("add $%d, #rsp", restsize);
        stackpos -= restsize;
    }
    if (padding) {
        emit("add $8, #rsp");
        stackpos -= 8;
    }
    restore_arg_regs(vec_len(ints), vec_len(floats));
    assert(opos == stackpos);
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    char ans[2];
    char *fileargs[64];
    char *optargs[64];
    int n_options;
    int index;
    int help_flag = 0;

#ifdef __TURBOC__
    setvect(0x23, ctrlc_hndlr);
#else
    _dos_setvect(0x23, ctrlc_hndlr);
#endif
    atexit(on_exit);
    n_options = classify_args(argc, argv, fileargs, optargs);
    for (index=0;index<n_options;index++)
        {
        if (optargs[index][0] == '?') help_flag=1;
        else
            {
            myprintf("Invalid parameter - /",0);
            myprintf(optargs[index],0); /* removed strupr */
            myprintf("\r\n",0);
            exit(1);
            } /* end else. */

        } /* end for. */

    if (help_flag)
        {
        myprintf("\r\nLABEL Version " VERSION "\r\n", 0);
        myprintf("Creates, changes or deletes the volume label of a disk.\r\n",0);
        myprintf("\r\n",0);
        myprintf("Syntax: LABEL [drive:][label] [/?]\r\n",0);
        myprintf("  [drive:]  Specifies which drive you want to label\r\n",0);
        myprintf("  [label]   Specifies the new label you want to label the drive\r\n",0);
        myprintf("  /?        Displays this help message\r\n",0);
        return 0;
        } /* end if. */

    do_cmdline(argc, argv);
    if (*Drive == '?')  /* If no drive specified, use current. */
        GetDrive();

    /* Save current directory and move to root. */
    GetCurDir(curdir);
    if (curdir[0] != 0)
        {
        *rootdir = *Drive;
        SetCurDir(rootdir);
        } /* end if. */

    /* If no label was specified, show current one first and then get new one. */
    if (*Label == '\0')
        {
        disp_label();
        get_label();
        } /* end if. */

    /* If they entered an empty label, then ask them if they want to */
    /* delete the existing volume label. */
    if ((*Label == '\0') && (!NoLabel))
        {
        do
            {
            myprintf("\nDelete current volume label (Y/N)? ",0);
            mygets(ans,2); /* WHY not use getch? ??? */
            } /* end do. */
        while (((*ans=(char)toupper(*ans)) != 'Y') && (*ans != 'N'));

        if (toupper(*ans) == 'N')
            exit(1);

        } /* end if. */

    /* Delete the old volume label. */
    del_label();

    /* Create the new one, if there is one to create. */
    if (*Label != '\0')
        {
        if (make_label())
            {
            exit(1);
            } /* end if. */

        } /* end if. */

    exit(0);
    return 0;

} /* end main. */
Exemplo n.º 4
0
Arquivo: xcopy.c Projeto: FDOS/xcopy
/*-------------------------------------------------------------------------*/
int main(int argc, const char **argv) {
  int fileargc, 
	  switchargc;
  char *fileargv[255],
       *switchargv[255],
       env_prompt[MAXSWITCH],
       tmp_switch[MAXSWITCH] = "",
       src_pathname[MYMAXPATH] = "",
       src_filename[MAXFILE + MAXEXT] = "",
       dest_pathname[MYMAXPATH] = "",
       dest_filename[MAXFILE + MAXEXT] = "",
       *ptr,
       ch;
  int i, length;
  THEDATE dt;
#ifdef __WATCOMC__
  struct dostime_t tm;
#else
  struct time tm;
#endif

  cat = catopen ("xcopy", 0);	/* initialize kitten */

  classify_args(argc, argv, &fileargc, fileargv, &switchargc, switchargv);

  if (fileargc < 1 || switchargv[0] == "?") {
    print_help();
    catclose(cat);
    exit(4);
  }

  if (fileargc > 2) {
    printf("%s\n",catgets(cat, 1, 1, "Invalid number of parameters"));
    catclose(cat);
    exit(4);
  }

  /* activate termination function */
  /* (writes no. of copied files at exit) */
  atexit(exit_fn);

  /* read environment variable COPYCMD to set confirmation switch */
  strmcpy(env_prompt, getenv("COPYCMD"), sizeof(env_prompt));
  if (env_prompt[0] != '\0') {
    strupr(env_prompt);
    if (strcmp(env_prompt, "/Y") == 0)
      /* overwrite existing file(s) */
      switch_confirm = 0;
    else if (strcmp(env_prompt, "/N") == 0)
      /* skip existing file(s) */
      switch_confirm = 1;
    else
      /* ask for confirmation */
      switch_confirm = 2;
  }

  /* get switches */
  for (i = 0; i < switchargc; i++) {
    strmcpy(tmp_switch, switchargv[i], sizeof(tmp_switch));
    strupr(tmp_switch);
    if (strcmp(tmp_switch, "A") == 0)
      switch_archive = -1;
    else if (strcmp(tmp_switch, "C") == 0)
      switch_continue = -1;
    else if (strcmp(tmp_switch, "D") == 0)
      switch_date = -1;
    else if (strncmp(tmp_switch, "D:", 2) == 0) {
      if (strtodate(tmp_switch+2, &dt) != 0 ||
          !datevalid(&dt)) {
        printf("%s\n",catgets(cat, 1, 2, "Invalid date"));
        catclose(cat);
        exit(4);
      }
#ifdef __WATCOMC__
      memset((void *)&tm, 0, sizeof(struct dostime_t));
      /* tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; tm.tm_hund = 0; */
#else
      memset((void *)&tm, 0, sizeof(struct time));
      /* tm.ti_hour = 0; tm.ti_min = 0; tm.ti_sec = 0; tm.ti_hund = 0; */
#endif
      switch_date = dostounix(&dt, &tm);
    }
    else if (strcmp(tmp_switch, "E") == 0)
      switch_emptydir = -1;
    else if (strcmp(tmp_switch, "F") == 0)
      switch_fullnames = -1;
    else if (strcmp(tmp_switch, "H") == 0)
      switch_hidden = -1;
    else if (strcmp(tmp_switch, "I") == 0)
      switch_intodir = -1;
    else if (strcmp(tmp_switch, "L") == 0)
      switch_listmode = -1;
    else if (strcmp(tmp_switch, "M") == 0)
      switch_archive_reset = -1;
    else if (strcmp(tmp_switch, "N") == 0)
      switch_confirm = 1;
    else if (strcmp(tmp_switch, "P") == 0)
      switch_prompt = -1;
    else if (strcmp(tmp_switch, "Q") == 0)
      switch_quiet = -1;
    else if (strcmp(tmp_switch, "R") == 0)
      switch_readonly = -1;
    else if (strcmp(tmp_switch, "S") == 0)
      switch_subdir = -1;
    else if (strcmp(tmp_switch, "T") == 0)
      switch_tree = -1;
    else if (strcmp(tmp_switch, "V") == 0) {
      switch_verify = -1;
      bak_verify = getverify();
      setverify(1);
    }
    else if (strcmp(tmp_switch, "W") == 0)
      switch_wait = -1;
    else if (strcmp(tmp_switch, "Y") == 0)
      switch_confirm = 0;
    else if (strcmp(tmp_switch, "-Y") == 0)
      switch_confirm = 2;
    else {
      printf("%s - %s\n", catgets(cat, 1, 3, "Invalid switch"), switchargv[i]);
      catclose(cat);
      exit(4);
    }
  }

  /* get source pathname (with trailing backspace) and filename/-pattern */
  length = strlen(fileargv[0]);
  if (length > (MAXPATH - 1)) {
    printf("%s\n", catgets(cat, 1, 4, "Source path too long"));
    catclose(cat);
    exit(4);
  }
  _fullpath(src_pathname, fileargv[0], MYMAXPATH);
  if (src_pathname[0] == '\0') {
    printf("%s\n", catgets(cat, 1, 5, "Invalid source drive specification"));
    catclose(cat);
    exit(4);
  }
  /* check source path */
  if (!dir_exists(src_pathname)) {
    /* source path contains a filename/-pattern -> separate it */
    ptr = strrchr(src_pathname, *DIR_SEPARATOR);
    ptr++;
    strmcpy(src_filename, ptr, sizeof(src_filename));
    *ptr = '\0';
    if (!dir_exists(src_pathname)) {
      printf("%s - %s\n", catgets(cat, 1, 6, "Source path not found"), src_pathname);
      catclose(cat);
      exit(4);
    }
  }
  else {
    /* source is a directory -> filepattern = "*.*" */
    strmcpy(src_filename, "*.*", sizeof(src_filename));
  }
  cat_separator(src_pathname);
  length = strlen(src_pathname);
  if (length > (MAXDRIVE - 1 + MAXDIR - 1)) {
    printf("%s\n", catgets(cat, 1, 7, "Source path too long"));
    catclose(cat);
    exit(4);
  }

  /* get destination pathname (with trailing backspace) and */
  /* filename/-pattern */
  if (fileargc < 2) {
    /* no destination path specified -> use current */
    getcwd(dest_pathname, MAXPATH);
    strmcpy(dest_filename, "*.*", sizeof(dest_filename));
  }
  else {
    /* destination path specified */
    length = strlen(fileargv[1]);
    if (length > (MAXPATH - 1)) {
      printf("%s\n", catgets(cat, 1, 8, "Destination path too long"));
      catclose(cat);
      exit(4);
    }
    _fullpath(dest_pathname, fileargv[1], MYMAXPATH);
    if (dest_pathname[0] == '\0') {
      printf("%s\n", catgets(cat, 1, 9, "Invalid destination drive specification"));
      catclose(cat);
      exit(4);
    }
    /* check destination path */
    if (fileargv[1][length - 1] != *DIR_SEPARATOR &&
        !dir_exists(dest_pathname)) {
      ptr = strrchr(dest_pathname, *DIR_SEPARATOR);
      ptr++;
      strmcpy(dest_filename, ptr, sizeof(dest_filename));
      *ptr = '\0';
      if ((ptr = strchr(dest_filename, '*')) == NULL &&
          (ptr = strchr(dest_filename, '?')) == NULL) {
        /* last destination entry is not a filepattern -> does it specify */
        /* a file or directory? */
        if (((ptr = strchr(src_filename, '*')) == NULL &&
             (ptr = strchr(src_filename, '?')) == NULL) ||
            !switch_intodir) {
          /* source is a single file or switch /I was not specified -> ask */
          /* user if destination should be a file or a directory */
          printf("%s %s %s\n",
            catgets(cat, 1, 10, "Does"),
            dest_filename,
            catgets(cat, 1, 11, "specify a file name"));
          ch = confirm(
            catgets(cat, 1, 12, "or directory name on the target"),
            catgets(cat, 1, 13, "File"),
            catgets(cat, 1, 14, "Directory"), NULL, NULL);
          switch (ch) {
            case 1: /* 'F' */
              /* file */
              switch_file = -1;
              break;
            case 2: /* 'D' */
              /* directory */
              switch_intodir = -1;
              break;
          }
        }
        if (switch_intodir) {
          /* destination is a directory -> filepattern = "*.*" */
          strmcat(dest_pathname, dest_filename, sizeof(dest_pathname));
          strmcpy(dest_filename, "*.*", sizeof(dest_filename));
        }
      }
    }
    else {
      /* destination is a directory -> filepattern = "*.*" */
      strmcpy(dest_filename, "*.*", sizeof(dest_filename));
    }
  }
  cat_separator(dest_pathname);
  length = strlen(dest_pathname);
  if (length > (MAXDRIVE - 1 + MAXDIR - 1)) {
    printf("%s\n",catgets(cat, 1, 15, "Destination path too long"));
    catclose(cat);
    exit(4);
  }

  /* check for cyclic path */
  if ((switch_emptydir || switch_subdir) &&
      cyclic_path(src_pathname, dest_pathname)) {
    printf("%s\n",catgets(cat, 1, 16, "Cannot perform a cyclic copy"));
    catclose(cat);
    exit(4);
  }

  /* get destination drive (1 = A, 2 = B, 3 = C, ...) */
  dest_drive = toupper(dest_pathname[0]) - 64;

  if (switch_wait) {
    printf("%s\n",catgets(cat, 1, 17, "Press enter to continue..."));
    (void)getchar(); /* getch(); would need conio.h */
    fflush(stdin);
  }

  xcopy_files(src_pathname, src_filename, dest_pathname, dest_filename);
  if (!file_found) {
    printf("%s - %s\n",catgets(cat, 1, 18, "File not found"), src_filename);
    catclose(cat);
    exit(1);
  }

  catclose(cat);
  return 0;
}