Esempio n. 1
0
char *MakeErrorLine(long lineNumber, const char *filename)
{
  char *tmp= errorLoc;
  errorLoc= 0;
  p_free(tmp);
  if (lineNumber<0) pErrorMsg[0]= '\0';
  else sprintf(pErrorMsg, "  LINE: %ld  FILE: ", lineNumber);
  errorLoc= p_strncat(pErrorMsg, filename, 0);
  return errorLoc;
}
Esempio n. 2
0
void Y_ml4search(int nArgs)
{
  char *filename=YGetString(sp-nArgs+1);
  char *varname=YGetString(sp-nArgs+2);

  FILE *fs;

  fs = openmat(filename);
  if (fs == NULL) YError(p_strncat("Can't open file ",filename,0));

  PushIntValue(matfind(fs,varname,50000));    
}
Esempio n. 3
0
p_scr *
g_connect(char *displayName)
{
  p_scr *s = 0;
  int i, j, i0=-1, len=0, number=0;

  /* split display into base name and screen number (separated by dot) */
  if (displayName) while (displayName[len]) len++;
  if (len) {
    for (i=len-1 ; i>=0 ; i--) if (displayName[i]=='.') break;
    if (i>=0) {
      int i0 = i;
      for (i++ ; i<len && displayName[i]<='9' && displayName[i]>='0' ; i++)
        number = 10*number + (displayName[i]-'0');
      if (i == len) len = i0;
      else number = 0;
    }
  }
  if (!len) displayName = 0;
  if (g_screens) {
    for (i=0 ; i<n_screens ; i++) {
      j = 0;
      if (g_screens[i].name) {
        for ( ; j<len ; j++)
          if (g_screens[i].s && g_screens[i].name[j]!=displayName[j]) break;
      }
      if (j==len && (len? (!g_screens[i].name[j]) : !g_screens[i].name)) {
        if (number == g_screens[i].number) break;
        else if (i0<0) i0 = i;
      }
    }
    if (i<n_screens) s = g_screens[i].s;
  }
  if (!s) {
    if (i0<0) s = p_connect(displayName);
    else s = p_multihead(g_screens[i0].s, number);
    if (!s) return s;
    g_test_pending(s);
    for (i=0 ; i<n_screens ; i++) if (!g_screens[i].s) break;
    if (i==n_screens && !(i & (i-1))) {
      int n = i? 2*i : 1;
      g_screens = p_realloc(g_screens, sizeof(g_scr)*n);
    }
    g_screens[i].number = number;
    g_screens[i].name = displayName? p_strncat(0, displayName, len) : 0;
    g_screens[i].s = s;
    if (i==n_screens) n_screens++;
  }

  return s;
}
Esempio n. 4
0
static p_file *PushInclude(const char *filename, int fullparse)
{
  p_file *file= 0;
  char *name= 0;
  long i;

  if (YIsAbsolute(filename)) {
    /* absolute pathname doesn't need any prefix */
    file= open_include(filename, fullparse);
    if (!file) return 0;
    name= p_strcpy(filename);

  } else {
    char *tmp;
    for (i=0 ; i<=nYpPrefixes ; i++) {
      if (i<nYpPrefixes) {
        tmp= p_strncat(ypPrefixes[i], filename, 0);
        name= YExpandName(tmp);
        p_free(tmp);
      } else {
        /* this branch is probably a bug --
         * if . is not on path probably should not find file...
         * maybe protects against empty path?
         */
        name= YExpandName(filename);
        if (!YIsAbsolute(name)) break;
      }
      file= open_include(name, fullparse);
      if (file) break;
      p_free(name);
    }
    if (!file) return 0;
  }

  if (nYpIncludes>=maxYpIncludes) {
    int newSize= maxYpIncludes+4;
    ypIncludes= p_realloc(ypIncludes, sizeof(IncludeFile)*newSize);
    maxYpIncludes= newSize;
  }

  if (fullparse) ClearSourceList(name);

  ypIncludes[nYpIncludes].file= file;
  ypIncludes[nYpIncludes].filename= name;
  ypIncludes[nYpIncludes].lastLineRead= 0;
  ypIncludes[nYpIncludes++].index = -1;
  prevErrLine= -1;
  return file;
}
Esempio n. 5
0
p_file *YpPop(void)
{
  char *filename;
  p_file *file;
  if (nYpInputs<=0) return 0;
  filename= ypInputs[--nYpInputs];
  file= YpPushInclude(filename);
  if (!file) {
    char *msg;
    msg= p_strncat("missing include file ", filename, 0);
    YpError(msg);
    p_free(msg);
  }
  p_free(filename);
  return file;
}
Esempio n. 6
0
static void
ympg_link(void)
{
  if (!ympg_initialized) {
    char *yavc_path[] = { 0, 0, "libavcodec", "/lib/libavcodec",
                          "/usr/lib/libavcodec", "/usr/local/lib/libavcodec",
                          "/sw/lib/libavcodec", 0 };
    char **yavc_name = yavc_path;
    char *yavc_env = Ygetenv("Y_LIBAVCODEC");
    void *dll = 0;
    /* look for libavcodec first at name in Y_LIBAVCODEC environment
     * variable (not including .so or other extension), then Y_HOME/lib,
     * then as simply "libavcodec" (current working directory?),
     * then in system places /lib, /usr/lib, /usr/local/lib
     */
    if (yavc_env && yavc_env[0]) yavc_path[0] = yavc_env;
    else yavc_name++;
    if (yHomeDir && yHomeDir[0]) {
      char *yhscan = yHomeDir;
      while (yhscan[1]) yhscan++;
      yavc_path[1] = p_strncat(yHomeDir, (yhscan[0]=='/')? "lib/libavcodec" :
                               "/lib/libavcodec", 0);
    } else {
      yavc_name++;
    }
    for ( ; *yavc_name ; yavc_name++) {
      dll = p_dlopen(*yavc_name);
      if (dll) {
        int i, mask;
        for (i=0,mask=1 ; i<NSYMS ; i++,mask=2)
          if (p_dlsym(dll, ympg_symadd[i].name, ympg_symadd[i].is_data,
                      ympg_symadd[i].paddr) != 0) break;
        if (i < NSYMS)
          YError("mpeg_create: found libavcodec, but missing symbols");
        break;
      }
    }
    if (yavc_env) p_free(yavc_env);
    p_free(yavc_path[1]);
    yavc_path[0] = yavc_path[1] = yavc_env = 0;

    /* is this wrong? do we want to allow user to install it later? */
    if (!dll) ympg_initialized = 2;
  }
  if (ympg_initialized)
    YError("mpeg_create: unable to find or dynamically link to libavcodec");
}
Esempio n. 7
0
void Y_ml4scan(int nArgs)
{
  char *filename=YGetString(sp-nArgs+1);
  int maxvar=0;
  int returnString=(1-yarg_subroutine());
  if (nArgs==1) {
    maxvar=10000;
  } else if (nArgs==2) {
    maxvar=YGetInteger(sp-nArgs+2);
  } else {
    YError("ml4scan takes one or two arguments");
  }
  
  FILE *fs;

  fs = openmat(filename);
  if (fs == NULL) YError(p_strncat("Can't open file ",filename,0));

  matscan(fs,maxvar,returnString);

  matclose(filename);
}
Esempio n. 8
0
void Y_ml4read(int nArgs)

{
  char *filename="";
  char *varname="";
  int leave_open = 0;
  
  if (nArgs==2) {
    filename=YGetString(sp-nArgs+1);
    varname=YGetString(sp-nArgs+2);
    leave_open = 0;
  } else if (nArgs==3) {
    filename=YGetString(sp-nArgs+1);
    varname=YGetString(sp-nArgs+2);
    leave_open=YGetInteger(sp-nArgs+3);
  }

  unsigned long bytes_read;
  int type,namelen;
  unsigned long nElements,nBytesToRead;
  int mrows,mcols,imagf;
  FILE *fs;
  int fileptr;
  int endian = 'L';
  int size=0,i;

  fs = openmat(filename);
  if (fs == NULL) YError(p_strncat("Can't open file ",filename,0));

  if (!matfind(fs,varname,50000)) YError(p_strncat("No Such variable ",varname,0));

  fileptr = ftell(fs);
  if (DEBUG) printf("@ position %d\n",fileptr);
  
  bytes_read = fread(&type,sizeof(int),1,fs);
  if (bytes_read==0) {
    matclose(filename);
    YError("Premature end of file");; // end of file
  }
  fread(&mrows,sizeof(int),1,fs);
  fread(&mcols,sizeof(int),1,fs);
  fread(&imagf,sizeof(int),1,fs);
    
  fread(&namelen,sizeof(int),1,fs);

  if (namelen & 0xffff0000) {
    if (DEBUG) printf("Big endian file\n");
    endian = 'B';
    SWAP_INT(type);
    SWAP_INT(mrows);
    SWAP_INT(mcols);
    SWAP_INT(imagf);
    SWAP_INT(namelen);
  }
  type = type%1000;

  if (DEBUG) printf("rows,cols,namelen= %d %d %d\n",mrows,mcols,namelen);

  if (namelen>255) {
    fseek(fs,fileptr,SEEK_SET);  // leave file ptr at begginning of this variable
    matclose(filename);
    YError("Variable name too long!");
  }

  fread(tempvarname,(unsigned int)namelen,1,fs);
  //  if ((*varname!='*') && strcmp(varname,tempvarname)) {  // error if not same varname
  if (!matchvarname(tempvarname,varname)) {  // error if not same varname
    fseek(fs,fileptr,SEEK_SET);  // leave file ptr at begginning of this variable
    matclose(filename);
    YError(p_strncat("Can't find variable",varname,0));
  }

  nElements = (unsigned)mrows*(unsigned)mcols;
  
  Dimension *tmp=tmpDims;
  tmpDims=0;
  FreeDimension(tmp);
  if (mrows<=1) {
    tmpDims= NewDimension(mcols, 1L, (Dimension *)0);
  } else if (mcols<=1) {
    tmpDims= NewDimension(mrows, 1L, (Dimension *)0);
  } else {
    tmpDims= NewDimension(mrows, 1L, (Dimension *)0);
    tmpDims= NewDimension(mcols, 1L, tmpDims);
  }
  
  if (type==0) {
    // 8-byte doubles
    size = 8;
    Array *a= PushDataBlock(NewArray(&doubleStruct, tmpDims));
    double *data = a->value.d;
    bytes_read = fread((void *)data,size,nElements,fs);
    if (endian=='B') { for (i=0;i<nElements;i++) SWAP_DOUBLE(data[i]); }

  } else if (type==10) {
    // 4-byte reals
    size = 4;
    Array *a= PushDataBlock(NewArray(&floatStruct, tmpDims));
    float *data = a->value.f;
    bytes_read = fread((void *)data,size,nElements,fs);
    if (endian=='B') { for (i=0;i<nElements;i++) SWAP_FLOAT(data[i]); }

  } else if ((type==120) || (type==20)) {
    // 4-byte int
    size = 4;
    Array *a= PushDataBlock(NewArray(&intStruct, tmpDims));
    int *data = a->value.l;
    bytes_read = fread((void *)data,size,nElements,fs);
    if (endian=='B') { for (i=0;i<nElements;i++) SWAP_INT(data[i]); }

  } else if (type==30) {
    // 2-byte signed (30) shorts
    size = 2;
    Array *a= PushDataBlock(NewArray(&shortStruct, tmpDims));
    short *data = a->value.s;
    bytes_read = fread((void *)data,size,nElements,fs);
    if (endian=='B') { for (i=0;i<nElements;i++) SWAP_SHORT(data[i]); }

  } else if (type==40) {
    // 2-byte unsigned (40) shorts
    size = 2;
    Array *a= PushDataBlock(NewArray(&shortStruct, tmpDims));
    short *data = a->value.s;
    Array *b= PushDataBlock(NewArray(&longStruct, tmpDims));
    long *data2 = b->value.l;
    bytes_read = fread((void *)data,size,nElements,fs);
    if (endian=='B') { for (i=0;i<nElements;i++) SWAP_SHORT(data[i]); }
    for (i=1;i<=nElements;i++) *(data2++) = (((long)*(data++))|0xFFFF0000)+65535;

  } else if (type==50) {
    // 1-byte signed or unsigned chars (50)
    size = 1;
    Array *a= PushDataBlock(NewArray(&charStruct, tmpDims));
    char *data = a->value.c;
    bytes_read = fread((void *)data,size,nElements,fs);

  } else if (type==51) {
    // text (51)
    size = 1;
    Array *a= PushDataBlock(NewArray(&stringStruct, (Dimension *)0));
    char *buf;
    a->value.q[0] = buf = p_malloc(nElements+1);
    if (DEBUG) printf("strlen: %d\n",(int)strlen((void *)a->value.q[0]));
    //    bytes_read = fread(a->value.q[0],1,nElements,fs);
    bytes_read = fread(buf,1,nElements,fs);
    *((char *)buf + nElements) = 0;  // append a NULL to text string

  } else {
    matclose(filename);
    sprintf(message,"Unknown type %d",type);
    YError(message);
  }

  if (bytes_read!=nElements) {
    fseek(fs,nElements*size,SEEK_CUR);
    matclose(filename);
    if (DEBUG) printf("read:%ld expected:%ld\n",bytes_read,nBytesToRead);
    YError("Premature end of file");
  }

  if (!leave_open) matclose(filename);
}
Esempio n. 9
0
/* possible results:
 * 0 -- this line was not #include (or ypSkipIncludes), #if, or #endif
 *      or was a syntax error
 * 1 bit means get next line (successful include, #if 1, or #endif)
 * 2 -- this line was #include, file missing (YpError called)
 * 3 -- this line was #include, file pushed successfully
 * 4 -- this line was #if 0, no matching #endif
 * 5 -- this line was #if 0, skipped past matching #endif (in ypBuffer)
 * 7 -- this line was #if 1
 * 9 -- this line was #endif
 */
static int
yp_chk_hash(p_file *file, int context, char *line)
{
  /* Check whether this is an include line or an if line.
   * Correct format is ([OWS] means optional whitespace characters):
   * [OWS]#[OWS]include[OWS]"filename"[OWS]
   * or
   * [OWS]#[OWS]include[OWS]<filename>[OWS]
   */
  while (*line && (*line==' ' || *line=='\t' || *line=='\f')) line++;
  if (*line=='#' && line[1]) {
    char *incl= "include";
    line++;
    while (*line && (*line==' ' || *line=='\t')) line++;
    while (*line && *incl && (*line++ == *incl++));
    if (!*incl && context<NL_CONTINUE) {
      char delim;
      if (ypSkipIncludes) return 0;
      while (*line && (*line==' ' || *line=='\t')) line++;
      delim= *line;
      if (delim=='\"' || delim=='<') {
        char *filename= ++line;
        if (delim=='<') delim = '>';
        while (*line && *line!=delim) line++;
        if (*line && line>filename) {
          *line++= '\0';  /* 0-terminate filename */
          while (*line && (*line==' ' || *line=='\t')) line++;
          if (!*line) {
            char *msg;
            if ((file= YpPushInclude(filename))) return 3;
            msg= p_strncat("missing include file ", filename, 0);
            YpError(msg);
            p_free(msg);
            return 2;
          }
        }
      }

    } else if (incl[-1]=='n' && line[-1]=='f' &&
               (line[0]==' ' || line[0]=='\t') && file) {
      /* this is #if line, maybe should skip to matching #endif */
      line++;
      while (*line && (*line==' ' || *line=='\t')) line++;
      if ((line[0]=='0' || line[0]=='1')
          && (!line[1] || line[1]==' ' || line[1]=='\t')) {
        if (line[0]=='0') {
          int count = 0;
          for (;;) {
            if (p_signalling) p_abort();
            if (!GetNextLine(file, context)) return 4;
            line = ypBuffer.line;
            while (*line && (*line==' ' || *line=='\t' || *line=='\f'))
              line++;
            if (*line=='#') {
              line++;
              while (*line && (*line==' ' || *line=='\t')) line++;
              if (line[0]=='i' && line[1]=='f' &&
                  (line[2]==' ' || line[2]=='\t')) {
                count++;        /* nested #if (don't bother checking 0) */
              } else {
                char *endi = "endif";
                while (*line && *endi && (*line++ == *endi++));
                if (!*endi &&
                    (!line[0] || line[0]==' ' || line[0]=='\t') &&
                    !count--) return 5;
              }
            }
          }
        } else {  /* #if 1 */
          need_endif++;
          return 7;
        }
      }

    } else if (need_endif && incl[-1]=='i' && line[-1]=='e' &&
               line[0]=='n' && line[1]=='d' && line[2]=='i' &&
               line[3]=='f' &&
               (!line[4] || line[4]==' ' || line[4]=='\t')) {
      need_endif--;
      return 9;  /* read line after #endif */
    }
  }
  return 0;
}