Exemplo n.º 1
0
int getparamstat(string name)
{
  param *par;

  par = findparam(name, paramvec);
  return (par != NULL ? par->flags : 0);
}
Exemplo n.º 2
0
local void savehistory(param *pvec)
{
  param *pp;
  int hlen;
  char *hist;

  pp = findparam("HISTORY", pvec);		// look for a history entry
  if (pp != NULL && ! strnull(pp->value)) 	// is history data present?
    add_history(pp->value);			// just send to history pkg
  else {					// format history data
    hlen = strlen(pvec->value);			// count length of argv0
    for (pp = pvec+1; pp->name != NULL; pp++)
						// sum length of others
      if ((pp->flags & ARGPARAM) || streq(pp->name, "VERSION"))
						// actual arg or version?
	hlen += 2 + strlen(pp->name) + strlen(pp->value);
						// add length required
    hist = (char *) allocate(hlen+1);		// get memory for history
    strcpy(hist, pvec->value);			// store program name
    for (pp = pvec+1; pp->name != NULL; pp++)
						// loop over other params
      if ((pp->flags & ARGPARAM) || streq(pp->name, "VERSION")) {
						// actual arg or version?
	strcat(hist, " ");			// insert a space
	strcat(hist, pp->name);			// and the argument name
	strcat(hist, "=");			// and a equals sign
	strcat(hist, pp->value);		// and the argument value
      }
    add_history(hist);				// invoke history package
  }
}
Exemplo n.º 3
0
local void setarguments(param *pvec, string *argv)
{
  bool scanpos;
  param *pp;
  string *ap, name;

  scanpos = TRUE;				// start scan by position
  pp = pvec;					// start with 0th param
  for (ap = argv + 1; *ap != NULL; ap++) {	// loop over the arguments
    name = parname(*ap);			// get param name, if any
    scanpos = scanpos && (name == NULL);	// see how to match args
    if (scanpos) {				// match by position?
      pp++;					// move to next param
      if (pp->name == NULL)			// past last parameter?
	error("%s.initparam: too many arguments\n", progname);
      pp->value = strdup(*ap);			// set new param value
    } else {					// matching by name?
      if (name == NULL)				// but no name given?
	error("%s.initparam: arg %s must be named\n", progname, *ap);
      pp = findparam(name, pvec);		// look for named param
      if (pp == NULL)				// an unknown param?
	error("%s.initparam: parameter %s unknown\n", progname, name);
      if (pp->flags & ARGPARAM)			// already on arg list?
	error("%s.initparam: parameter %s duplicated\n", progname, name);
      pp->value = strdup(parvalue(*ap));	// set new param value
    }
    pp->flags = (pp->flags & ~DEFPARAM) | ARGPARAM;
						// switch source flag
  }
}
Exemplo n.º 4
0
/*-----------------------------------------------------
        Parameters:

        Returns value:

        Description
------------------------------------------------------*/
int
ImageFWrite(IMAGE *I, FILE *fp, const char*fname)
{
  byte    *image ;
  int     ecode, type, frame;
  char    buf[100] ;

  if (!fname)
    fname = "ImageFWrite" ;

  strcpy(buf, fname) ;   /* don't destroy callers string */
 
  ImageUnpackFileName(buf, &frame, &type, buf) ;

  switch (type)
  {
  case RGBI_IMAGE:
    RGBwrite(I, buf, frame) ;
    break ;
  case TIFF_IMAGE:
    TiffWriteImage(I, buf, frame) ;
    break ;
  default:
  case JPEG_IMAGE:
    JPEGWriteImage(I, buf, frame);
    break;
  case PGM_IMAGE:
    PGMWriteImage(I, buf, frame);
    break;
  case PPM_IMAGE:
    PPMWriteImage(I, buf, frame);
    break;
  case HIPS_IMAGE:
    if (endian == END_UNDEF)
      endian = FindMachineEndian();

    if (findparam(I,"endian"))
      clearparam(I,"endian"); /* Clear any existing endian parameter */
    setparam(I, "endian", PFBYTE, 1, endian);

    ecode = fwrite_header(fp,I,"fwrite") ;
    if (ecode != HIPS_OK)
      ErrorExit(ERROR_NO_FILE,"ImageFWrite: fwrite_header failed (%d)\n",ecode);

    image = I->image ;
    for (frame = 0 ; frame < I->num_frame ; frame++)
    {
      ecode = fwrite_image(fp, I, frame, "fwrite") ;
      if (ecode != HIPS_OK)
        ErrorExit(ERROR_NO_FILE,
                  "ImageFWrite: fwrite_image frame %d failed (%d)\n",ecode,frame);
      I->image += I->sizeimage ;  /* next frame */
    }
    I->image = image ;
    break ;
  }
  return(0) ;
}
Exemplo n.º 5
0
Arquivo: scot.c Projeto: eddyc/csound
static                          /* puts parameter in plist */
void addparam(int n,            /* number of param to change */
              char *s,          /* parameter */
              Strlist **ptop)
{                               /* top of list */
    char   *ps;

    ps = findparam(n, ptop);
    if (strcmp(s, "."))
      strncpy(ps, s, 1+strlen(s));
}
Exemplo n.º 6
0
string getparam(string name)
{
  param *par;

  if (paramvec == NULL)	{			// called during init?
    if (streq(name, "argv0") && progname != NULL)
      return (progname);			// handle "argv0" specially
    error("getparam: called before initparam\n");
						// program name unknown
  }
  par = findparam(name, paramvec);		// look up value by name
  if (par == NULL)
    error("%s.getparam: parameter %s unknown\n", progname, name);
  return (par->value);
}
Exemplo n.º 7
0
/*
 * Return the type of a variable name.
 * This is either local, parameter, global, static, or undefined.
 *
 * given:
 *	name		variable name to find
 */
int
symboltype(char *name)
{
	GLOBAL *sp;

	if (findparam(name) >= 0)
		return SYM_PARAM;
	if (findlocal(name) >= 0)
		return SYM_LOCAL;
	sp = findglobal(name);
	if (sp) {
		if (sp->g_filescope == SCOPE_GLOBAL)
			return SYM_GLOBAL;
		return SYM_STATIC;
	}
	return SYM_UNDEFINED;
}
Exemplo n.º 8
0
Arquivo: scot.c Projeto: eddyc/csound
static                          /* reads score{} section */
void readscore(Inst *insttop)
{
    char    s[128];
    Inst   *p;
    Rat     grpmul, timesig, curtime, lastbar, lastnote, rattmp;
    Tempo  *tempotop, *tempop;
    Note   *notetop, *pn, *qn, *ln;
    Nextp  *nextlist, *nextpp;
    int     accidentals,
            octaves,
            vertical, key[PITCHCLASSES], barkey[PITCHCLASSES], transpose, z;
    double  maxtime, fcurtime;

#ifdef DEBUG
    printf("Reading score section\n");
#endif

    maxtime = 0.0;
    if (expectchar('{'))
      scotferror(Str("Syntax error: no {"));
    tempotop = (Tempo *) malloc(sizeof(Tempo));
    tempotop->time.num = 0;
    tempotop->time.denom = 1;
    tempotop->val = 60;
    tempotop->next = NULL;
    for (;;) {
      tempop = tempotop;
      efindword(s);
      if (s[0] == '}')
        break;
      if (s[0] != '$')
        scotferror(Str("No instrument specified"));
      p = insttop;
      while ((p != NULL) && (strcmp(&s[1], p->name)))
        p = p->next;
      if (p == NULL)
        scotferror(Str("Instrument not defined"));
      notetop = ln = NULL;
      grpmul.num = 1;
      grpmul.denom = 1;
      timesig.num = 0;
      timesig.denom = 1;
      curtime.num = 0;
      curtime.denom = 1;
      lastbar.num = 0;
      lastbar.denom = 1;
      lastnote.num = 0;
      lastnote.denom = 1;
      accidentals = octaves = vertical = TRUE;
      for (z = 0; z < PITCHCLASSES; z++)
        key[z] = barkey[z] = 0;
      transpose = 0;
      nextlist = NULL;
      readinstsec(p, &nextlist, &grpmul, &timesig, &curtime,
                  &lastbar, &lastnote, &notetop, &ln, &tempop, &accidentals,
                  &octaves, &vertical, key, barkey, &transpose, "}$");
      for (pn = notetop; pn; pn = pn->next) {
        if (!pn->written) {
          char   *ps, *ps2;

          for (nextpp = nextlist; nextpp; nextpp = nextpp->next) {
            ps = findparam(nextpp->dst, &pn->carryp);
            if (!strcmp(ps, NEXTP)) {
              ps2 = findparam(nextpp->src, &pn->p);
              if (!strcmp(ps2, "."))
                ps2 = findparam(nextpp->src, &pn->carryp);
              strcpy(ps, ps2);
            }
          }
          writenote(pn);
        }
        if (pn->tie)
          scoterror(Str("unresolved tie"));
        if (pn->slur & 1)
          scoterror(Str("unresolved slur"));
        ratadd(&rattmp, &pn->start, &pn->dur);
        if (ratcmp(&rattmp, &curtime) > 0)
          ratass(&curtime, &rattmp);

#ifdef DEBUG
        if (pn == pn->next)
          scotferror(Str("Circular note list\n"));
#endif

      }
      while (nextlist) {
        nextpp = nextlist;
        nextlist = nextlist->next;
        free((char *) nextpp);
      }
      pn = notetop;
      while (pn) {
        qn = pn;
        pn = pn->next;
        freenote(qn);
      }
      fcurtime = ratval(&curtime);
      if (fcurtime > maxtime)
        maxtime = fcurtime;
    }
    tempop = tempotop;
    putc('t', outfile);
    for (;;) {
      tempotop = tempop;
      tempop = tempop->next;
      fprintf(outfile, "%g %d", ratval(&tempotop->time), tempotop->val);
      free((char *) tempotop);
      if (!tempop)
        break;
      putc(' ', outfile);
    }
    fprintf(outfile, "\nf0 %g\ns\n", maxtime);
}
Exemplo n.º 9
0
Arquivo: scot.c Projeto: eddyc/csound
static                          /* reads from one $instrument to the next */
void readinstsec(Inst *inst,
                 Nextp **nextlist,
                 Rat *grpmul,
                 Rat *timesig,
                 Rat *curtime,
                 Rat *lastbar,
                 Rat *lastnote,
                 Note **notetop,
                 Note **ln,
                 Tempo **tempop,
                 int *accidentals,
                 int *octaves,
                 int *vertical,
                 int *key, int *barkey, int *transpose, char *endchar)
{
    static Rat durdiv = { 4L, 1L };

    int     c, z, lastpitchclass;
    char    s[128], *sp;
    Rat     ratstack, rattmp;
    Note   *pn, *nn, *pn2 = NULL;
    Strlist *ps;
    Nextp  *nextpp;

#ifdef DEBUG
    printf("Reading instrument section: %s\n", inst->name);
#endif

    pn = (*notetop);
    for (;;) {
      findchar(&c);
      if (strchr(endchar, c))
        break;

#ifdef DEBUG
      printf("Processing char: %c\n", c);
#endif

      switch (c) {
      case 't':
        if (findint(&c)) {
          scoterror(Str("Tempo must be specified"));
          break;
        }
        if ((*tempop)->next) {
          scoterror(Str("Redefinition of tempo"));
          break;
        }
        (*tempop)->next = (Tempo *) malloc(sizeof(Tempo));
        *tempop = (*tempop)->next;
        (*tempop)->next = NULL;
        ratass(&((*tempop)->time), curtime);
        (*tempop)->val = c;
        break;
      case '!':
        efindword(s);
        if ((c = strlen(s)) < 2)
          scoterror(Str("Must specify 2 or more letters of keyword"));
        if (!strncmp(s, "accidentals", c)) {
          if (findonoff(accidentals))
            scoterror(Str("Must be \"on\" or \"off\""));

#ifdef DEBUG
          printf(" accidentals %s\n", accidentals ? "on" : "off");
#endif

        }
        else if (!strncmp(s, "octaves", c)) {
          if (findonoff(octaves))
            scoterror(Str("Must be \"on\" or \"off\""));

#ifdef DEBUG
          printf(" ocatves %s\n", *octaves ? "on" : "off");
#endif

        }
        else if (!strncmp(s, "vertical", c)) {
          if (findonoff(vertical))
            scoterror(Str("Must be \"on\" or \"off\""));

#ifdef DEBUG
          printf(" vertical %s\n", *vertical ? "on" : "off");
#endif

        }
        else if (!strncmp(s, "timesignature", c)) {
          efindword(s);

          if ((sscanf(s, "%lu/%lu", &timesig->num, &timesig->denom) != 2)
              ||
              (&(timesig->denom) == 0) ) {
            scoterror(Str("Invalid time signature"));
            timesig->num = 0;
            timesig->denom = 1;
          }

#ifdef DEBUG
          printf(" time sig=%lu/%lu\n", timesig->num, timesig->denom);
#endif

          ratstack.num = 4;
          ratstack.denom = 1;
          ratmul(timesig, timesig, &ratstack);

#ifdef DEBUG
          printf(" measure length=%f\n", ratval(timesig));
#endif

        }
        else if (!strncmp(s, "key", c)) {
          int     y;

          efindword(s);
          for (z = 0; z < PITCHCLASSES; z++)
            key[z] = 0;
          c = y = 0;
          for (z = 0; s[z] != (char) 0; z++)
            switch ((int) s[z]) {
            case '#':
              c = y + 1;
              y++;
              break;
            case '-':
              c = y - 1;
              y--;
              break;
            default:
              if (!isalpha(s[z]))
                scoterror(Str("Bad key signature"));
              key[letterval((int) s[z])] = c;
              y = 0;
            }
          for (z = 0; z < PITCHCLASSES; z++)
            barkey[z] = key[z];
        }
        else if (!strncmp(s, "transpose", c)) {
          efindword(s);
          *transpose = 0;
          for (z = 0; s[z]; z++) {
            switch (s[z]) {
            case ',':
              (*transpose) -= NOTESPEROCT;
              break;
            case '\'':
              (*transpose) += NOTESPEROCT;
              break;
            case '=':
              (*transpose) = 0;
              break;
            case '#':
              (*transpose)++;
              break;
            case '-':
              (*transpose)--;
              break;
            default:
              (*transpose) += naturals[letterval((int) s[z])];
            }
          }
        }
        else if (!strncmp(s, "next", c)) {
          efindword(s);
          if (sscanf(s, "p%d", &c) != 1) {
            scoterror(Str("Invalid field"));
            efindword(s);
            break;
          }
          efindword(s);
          if (sscanf(s, "p%d", &z) != 1) {
            scoterror(Str("Invalid field"));
            break;
          }
          if (*nextlist == NULL) {
            *nextlist = (Nextp *) malloc(sizeof(Nextp));
            nextpp = (*nextlist);
            nextpp->next = NULL;
          }
          else {
            nextpp = (*nextlist);
            if ((c == nextpp->dst) || (z == nextpp->src))
              scoterror(Str("Nested next-parameter passing"));
            while (nextpp->next) {
              nextpp = nextpp->next;
              if ((c == nextpp->dst) || (z == nextpp->src))
                scoterror(Str("Nested next-parameter passing"));
            }
            nextpp->next = (Nextp *) malloc(sizeof(Nextp));
            nextpp = nextpp->next;
            nextpp->next = NULL;
          }
          nextpp->src = c;
          nextpp->dst = z;
        }
        else
          scoterror(Str("Unrecognised keyword"));
        break;
      case '{':
        findint(&c);
        expectchar(':');
        if (!c) {
          ratstack.num = 2L;
          ratstack.denom = 3L;
        }
        else {
          ratstack.denom = (unsigned long) c;
          findint(&c);
          if (!c) {
            for (z = 1; (unsigned long) z < ratstack.denom; z *= 2);
            z /= 2;
            ratstack.num = (unsigned long) z;
          }
          else
            ratstack.num = (unsigned long) c;
          expectchar(':');
        }
        ratmul(grpmul, grpmul, &ratstack);
        readinstsec(inst, nextlist, grpmul, timesig, curtime,
                    lastbar, lastnote, notetop, ln, tempop, accidentals,
                    octaves, vertical, key, barkey, transpose, ":");
        ratdiv(grpmul, grpmul, &ratstack);
        expectchar(':');
        expectchar('}');
        break;
      case '(':
        ratass(&ratstack, curtime);
        if (pn == (*notetop)) {
          readinstsec(inst, nextlist, grpmul, timesig, curtime,
                      lastbar, lastnote, notetop, ln, tempop, accidentals,
                      octaves, vertical, key, barkey, transpose, ")");
          pn = (*notetop);
        }
        else {
          readinstsec(inst, nextlist, grpmul, timesig, curtime,
                      lastbar, lastnote, &pn2->next, ln, tempop, accidentals,
                      octaves, vertical, key, barkey, transpose, ")");
          pn = pn2->next;
        }
        expectchar(')');
        ratass(lastnote, &ratstack);
        break;
      case '/':
        ratadd(lastbar, lastbar, timesig);
        if ((timesig->num) && (ratcmp(lastbar, curtime))) {
          scoterror(Str("Wrong number of beats in bar"));
          ratass(lastbar, curtime);
        }
        for (z = 0; z < PITCHCLASSES; z++)
          barkey[z] = key[z];
        break;
      case '<':
        if (pn == NULL) {
          scoterror(Str("Syntax error: cannot back up"));
          break;
        }
        if (pn->next == NULL) {
          pn->next = (Note *) malloc(sizeof(Note));
          initnote(pn->next);
          pn->next->instrum = pn->instrum + 0.01;
        }
        pn2 = pn;
        pn = pn->next;
        ratass(curtime, lastnote);
        break;
      default:

#ifdef DEBUG
        printf("Reading note\n");
        printf(" time=%lu/%lu\n", curtime->num, curtime->denom);
        printf(" =%f\n", ratval(curtime));
#endif

        scotungetc();
        nn = (Note *) malloc(sizeof(Note));
        nn->p = NULL;
        nn->written = FALSE;
        if (*notetop == NULL) {
          pn = (*ln) = (*notetop) = (Note *) malloc(sizeof(Note));
          initnote(*notetop);
          (*notetop)->instrum = (double) inst->number + 0.01;
        }
        else if (ratcmp(curtime, lastnote))
          pn = (*notetop);
        nn->instrum = pn->instrum;

#ifdef DEBUG
        printf(" instrument #%f\n", nn->instrum);
#endif

        if (*vertical)
          strlistcopy(&nn->carryp, &(*ln)->carryp);
        else
          strlistcopy(&nn->carryp, &pn->carryp);
        for (nextpp = (*nextlist); nextpp; nextpp = nextpp->next) {
          sp = findparam(nextpp->dst, &nn->carryp);
          if (!strcmp(sp, "."))
            strcpy(sp, NEXTP);
        }
        ratass(&nn->start, curtime);
        if (!findint(&c)) {
          ratstack.num = (unsigned long) c;
          ratstack.denom = 1L;
          ratdiv(&nn->dur, &durdiv, &ratstack);
          ratass(&ratstack, &nn->dur);
          rattmp.num = 1L;
          rattmp.denom = 2L;
          for (;;) {
            findchar(&c);
            if (c != '.')
              break;
            ratmul(&ratstack, &ratstack, &rattmp);
            ratadd(&nn->dur, &nn->dur, &ratstack);
          }
        }
        else {
          if (*vertical)
            ratass(&nn->dur, &((*ln)->lastdur));
          else
            ratass(&nn->dur, &pn->lastdur);
          findchar(&c);
        }
        ratass(&nn->lastdur, &nn->dur);
        ratmul(&nn->dur, &nn->dur, grpmul);

#ifdef DEBUG
        printf(" duration=%f\n", ratval(&nn->dur));
        printf(" c=%c\n", c);
#endif

        if (c == '=') {
          nn->octave = 8;
          lastpitchclass = 0;
        }
        else {
          nn->octave = pn->octave;
          lastpitchclass = pn->pitchclass;
          scotungetc();
        }
        for (;;) {
          findchar(&c);
          if (c == '\'')
            nn->octave++;
          else if (c == ',')
            nn->octave--;
          else
            break;
        }
        if (c == 'r') {
          ratass(lastnote, curtime);
          ratmul(&rattmp, &nn->lastdur, grpmul);
          ratadd(curtime, curtime, &rattmp);
          ratass(&(*ln)->lastdur, &nn->lastdur);
          ratass(&pn->lastdur, &nn->lastdur);
          freenote(nn);
          break;
        }
        else {
          nn->pitchclass = letterval(c);
          if (*octaves) {
            c = nn->pitchclass - lastpitchclass;
            if (c < -(PITCHCLASSES / 2))
              nn->octave++;
            else if (c > PITCHCLASSES / 2)
              nn->octave--;
          }
        }
        nn->accid = 0;
        nn->accmod = FALSE;
        for (;;) {
          findchar(&c);
          if (c == '#') {
            nn->accid++;
            nn->accmod = TRUE;
          }
          else if (c == '-') {
            nn->accid--;
            nn->accmod = TRUE;
          }
          else if (c == 'n') {
            nn->accid = 0;
            nn->accmod = TRUE;
          }
          else
            break;
        }
        if (!nn->accmod)
          nn->accid = barkey[nn->pitchclass];
        else if (*accidentals)
          barkey[nn->pitchclass] = nn->accid;

#ifdef DEBUG
        printf(" transpose=%d\n", *transpose);
        printf(" octave=%d pitchclass=%d accid=%d transpose=%d pitch=%f\n",
               nn->octave, nn->pitchclass, nn->accid, *transpose,
               pitchval(nn->octave, nn->pitchclass, nn->accid, *transpose));
#endif

        if (c == '_') {
          findchar(&c);
          if (c == '_') {
            nn->tie = TRUE;
            nn->slur = 0;
            findchar(&c);
          }
          else {
            nn->slur = 1;
            nn->tie = FALSE;
          }
        }
        else {
          nn->slur = 0;
          nn->tie = FALSE;
        }
        if (pn->slur & 1)
          nn->slur += 2;

#ifdef DEBUG
        printf(" slur=%d tie=%d\n", nn->slur, nn->tie);
#endif

        if (pn->tie) {
          ratadd(&rattmp, &pn->start, &pn->dur);
          if (ratcmp(&rattmp, curtime))
            scoterror(Str("Improper tie"));
          if (((nn->octave != pn->octave) ||
               (nn->pitchclass != pn->pitchclass) ||
               ((nn->accid != pn->accid) && (nn->accmod))) &&
              (pitchval(nn->octave, nn->pitchclass, nn->accid, *transpose) !=
               pitchval(pn->octave, pn->pitchclass, pn->accid, *transpose)))
            scoterror(Str("Tie between different pitches"));
          ratadd(&pn->dur, &pn->dur, &nn->dur);
          ratass(&pn->lastdur, &nn->lastdur);
          pn->slur += nn->slur;
          pn->tie = nn->tie;
          freenote(nn);
          nn = pn;
          if (c == (char) '[')
            scoterror(Str("Warning: params changed on tie"));
        }
        else {
          ps = nn->p = (Strlist *) malloc(sizeof(Strlist));
          for (z = 0; z < 4; z++) {
            ps->next = (Strlist *) malloc(sizeof(Strlist));
            ps = ps->next;
          }
          ps->next = NULL;
        }
        ps = nn->p;
        sprintf(ps->str, "%.02f", nn->instrum);
        ps = ps->next;
        sprintf(ps->str, "%g", ratval(&nn->start));
        ps = ps->next;
        sprintf(ps->str, "%g", ratval(&nn->dur));
        ps = ps->next;
        sprintf(ps->str, "%d", nn->slur);
        ps = ps->next;
        sprintf(ps->str, "%.02f",
                pitchval(nn->octave, nn->pitchclass, nn->accid, *transpose));
        if (c == '[') {
          char   *pars;
          int     pnum;

          pars = readparams(inst);

#ifdef DEBUG
          printf("Params: %s\n", pars);
#endif

          z = 0;
          pnum = 6;
          while (strchr(" \t\r\n", (int) pars[z]))
            z++;
          for (;;) {
            if (pars[z] == (char) ']')
              break;
            c = 0;
            while (!strchr(" \t\r\n:]", (int) pars[z]))
              s[c++] = pars[z++];
            s[c] = (char) 0;

#ifdef DEBUG
            printf("Read: %s\n", s);
#endif

            while (strchr(" \t\r\n", (int) pars[z]))
              z++;
            if (pars[z] == (char) ':') {
              pnum = atoi(s);
              if (pnum < 6)
                scoterror(Str("Parameter number out of range"));
              z++;
              while (strchr(" \t\r\n", (int) pars[z]))
                z++;
              continue;
            }

#ifdef DEBUG
            printf("Param #%d: %s\n", pnum, s);
#endif

            if (s[0] == (char) '\'') {
              addparam(pnum, &s[1], &nn->p);
              addparam(pnum, ".", &nn->carryp);
            }
            else {
              addparam(pnum, s, &nn->p);
              addparam(pnum, s, &nn->carryp);
            }
            pnum++;
          }
          free(pars);
        }
        else
          scotungetc();
        if ((nn != pn) && (!pn->written)) {

#ifdef DEBUG
          printf("  doing nextp stuff:\n");
#endif

          for (nextpp = (*nextlist); nextpp; nextpp = nextpp->next) {

#ifdef DEBUG
            printf("   carrying p%d to p%d?\n", nextpp->src, nextpp->dst);
#endif

            if (!strcmp(findparam(nextpp->dst, &pn->carryp), NEXTP)) {
              sp = findparam(nextpp->dst, &pn->p);
              if (!strcmp(sp, ".")) {
                char   *sp2;

                sp2 = findparam(nextpp->src, &nn->p);
                if (!strcmp(sp2, "."))
                  sp2 = findparam(nextpp->src, &nn->carryp);
                strcpy(sp, sp2);

#ifdef DEBUG
                printf("   Yes.\n");
#endif

              }
            }
          }
          writenote(pn);
        }
        if ((!(*nextlist)) && (!nn->tie))
          writenote(nn);
        if (nn != pn) {
          if (!pn->written)
            scoterror(Str("Lost previous note: not written"));

#ifdef DEBUG
          if (pn->next == nn)
            printf("* pn->next==nn\n");
#endif

          nn->next = pn->next;

#ifdef DEBUG
          if (pn2 == nn)
            printf("* pn2==nn\n");
#endif

          if (pn == *notetop)
            *notetop = nn;
          else
            pn2->next = nn;
          freenote(pn);
          pn = nn;

#ifdef DEBUG
          if (nn->next == nn)
            printf("* Circular list created\n");
#endif

        }

#ifdef DEBUG
        printf(" nn linked into note list\n");
        printf(" curtime=%lu/%lu\n", curtime->num, curtime->denom);
        printf(" nn->dur=%lu/%lu\n", nn->dur.num, nn->dur.denom);
#endif

        *ln = nn;
        ratass(lastnote, curtime);
        ratmul(&rattmp, &nn->lastdur, grpmul);
        ratadd(curtime, curtime, &rattmp);

#ifdef DEBUG
        printf(" curtime=%lu/%lu\n", curtime->num, curtime->denom);
        printf(" Done with note\n");
#endif

      }
    }
    scotungetc();
}
Exemplo n.º 10
0
/*-----------------------------------------------------
        Parameters:

        Returns value:

        Description
------------------------------------------------------*/
IMAGE *
ImageFRead(FILE *fp, const char*fname, int start, int nframes)
{
  int    ecode, end_frame, frame, count = 1;
  IMAGE  *I ;
  byte   *startpix, end = END_UNDEF;

  if (!fname)
    fname = "ImageFRead" ;

  I = (IMAGE *)calloc(1, sizeof(IMAGE)) ;
  if (!I)
    ErrorExit(ERROR_NO_MEMORY,"ImageFRead: could not allocate header\n") ;

  ecode = fread_header(fp, I, fname) ;
  if (ecode != HIPS_OK)
    ErrorExit(ERROR_NO_FILE, "ImageFRead: fread_header failed (%d)\n",ecode);

  if (endian == END_UNDEF)
    endian = FindMachineEndian();

  if (findparam(I, "endian"))
    getparam(I, "endian", PFBYTE, &count, &end);

  if (start < 0)    /* read all frames */
  {
    start = 0 ;
    nframes = I->num_frame ;
  }
  else              /* read only specified frames */
  {
    if (fseek(fp, (long)I->sizeimage*(long)start, SEEK_CUR) < 0)
    {
      ImageFree(&I) ;
      ErrorReturn(NULL,
                  (ERROR_BADFILE,
                   "ImageFRead(%s, %d) - could not seek to specified frame",
                   fname, start)) ;
    }
  }

  if (nframes < 0)
    nframes = I->num_frame - start + 1 ;

  end_frame = start + nframes - 1 ;
  if (end_frame >= I->num_frame)
    ErrorReturn(NULL,
                (ERROR_BADFILE,
                 "ImageFRead(%s, %d) - frame out of bounds", fname,end_frame));
  I->num_frame = nframes ;
  if (ImageAllocBuffer(I) != NO_ERROR)
    ErrorExit(Gerror, "ImageAllocBuffer failed") ;

  startpix = I->image ;
  for (frame = start ; frame <= end_frame ; frame++)
  {
    ecode = fread_image(fp, I, frame, fname) ;
    if (ecode != HIPS_OK)
      ErrorExit(ERROR_NO_FILE, "ImageFRead: fread_image failed (%d)\n", ecode);
    I->image += I->sizeimage ;
  }
  I->image = startpix ;

  /* We only swap endians if there wasn't an endian parameter and the image is
     invalid (ie.  values in the image seem to be extreme) OR the endian of
     the machine does not match the endian of the image */

  switch (end)
  {
  case END_UNDEF:
    if (!ImageValid(I))
      ImageSwapEndian(I);
    break;
  case END_BIG:
  case END_SMALL:
    if (end != endian)
      ImageSwapEndian(I);
    break;
  }

  return(I) ;
}
Exemplo n.º 11
0
int destroy_cmd(unit * u, struct order *ord)
{
    char token[128];
    ship *sh;
    unit *u2;
    region *r = u->region;
    const construction *con = NULL;
    int size = 0;
    const char *s;
    int n = INT_MAX;

    if (u->number < 1)
        return 0;

    init_order(ord);
    s = gettoken(token, sizeof(token));

    if (findparam(s, u->faction->locale) == P_ROAD) {
        destroy_road(u, INT_MAX, ord);
        return 0;
    }

    if (s && *s) {
        n = atoi((const char *)s);
        if (n <= 0) {
            cmistake(u, ord, 288, MSG_PRODUCE);
            return 0;
        }
    }

    if (getparam(u->faction->locale) == P_ROAD) {
        destroy_road(u, n, ord);
        return 0;
    }

    if (u->building) {
        building *b = u->building;

        if (u != building_owner(b)) {
            cmistake(u, ord, 138, MSG_PRODUCE);
            return 0;
        }
        if (fval(b->type, BTF_INDESTRUCTIBLE)) {
            cmistake(u, ord, 138, MSG_PRODUCE);
            return 0;
        }
        if (n >= b->size) {
            /* destroy completly */
            /* all units leave the building */
            for (u2 = r->units; u2; u2 = u2->next) {
                if (u2->building == b) {
                    leave_building(u2);
                }
            }
            ADDMSG(&u->faction->msgs, msg_message("destroy", "building unit", b, u));
            con = b->type->construction;
            remove_building(&r->buildings, b);
        }
        else {
            /* partial destroy */
            b->size -= n;
            ADDMSG(&u->faction->msgs, msg_message("destroy_partial",
                "building unit", b, u));
        }
    }
    else if (u->ship) {
        sh = u->ship;

        if (u != ship_owner(sh)) {
            cmistake(u, ord, 138, MSG_PRODUCE);
            return 0;
        }
        if (fval(r->terrain, SEA_REGION)) {
            cmistake(u, ord, 14, MSG_EVENT);
            return 0;
        }

        if (n >= (sh->size * 100) / sh->type->construction->maxsize) {
            /* destroy completly */
            /* all units leave the ship */
            for (u2 = r->units; u2; u2 = u2->next) {
                if (u2->ship == sh) {
                    leave_ship(u2);
                }
            }
            ADDMSG(&u->faction->msgs, msg_message("shipdestroy",
                "unit region ship", u, r, sh));
            con = sh->type->construction;
            remove_ship(&sh->region->ships, sh);
        }
        else {
            /* partial destroy */
            sh->size -= (sh->type->construction->maxsize * n) / 100;
            ADDMSG(&u->faction->msgs, msg_message("shipdestroy_partial",
                "unit region ship", u, r, sh));
        }
    }
    else {
        cmistake(u, ord, 138, MSG_PRODUCE);
        return 0;
    }

    if (con) {
        /* TODO: Nicht an ZERSTÖRE mit Punktangabe angepaßt! */
        int c;
        for (c = 0; con->materials[c].number; ++c) {
            const requirement *rq = con->materials + c;
            int recycle = (rq->number * size / con->reqsize) / 2;
            if (recycle) {
                change_resource(u, rq->rtype, recycle);
            }
        }
    }
    return 0;
}