Esempio n. 1
0
pstr  STDCALL getmodulepath( pstr name, pstr additional )
{
   str  temp;

   str_init( &temp );

#ifdef LINUX
   //Only for linux ???
   uint len = readlink( "/proc/self/exe", additional, 512 ) - 1;
   //uint sep1 = str_find(additionaļ,0,'\304',1);
   uint   separ = str_find( additional, 0, SLASH, 1 );
   //pCopyStr=strrchr(additionaļ,SLASH);
   //while ( len && (additional[ len ] != '/') ) len--;
   //if ( str_findch(filename,SLASH) != 0 )
   mem_copyuntilzero((pubyte) (additional + separ + 1), name );
   //strcpy(str_ptr(name),pCopyStr);
   //mem_copyuntilzero( additional + len + 1, name );
#else
   getmodulename( name );
   str_getdirfile( name, &temp, NULL );
   str_dirfile( &temp, additional, name );
#endif
   str_delete( &temp );
   return name;
}
Esempio n. 2
0
static void
hash_format_digest(string_t *dest, const struct hash_format_list *list,
		   const unsigned char *digest)
{
	unsigned int i, orig_len, size = list->bits / 8;
	
	i_assert(list->bits % 8 == 0);

	switch (list->encoding) {
	case HASH_ENCODING_HEX:
		binary_to_hex_append(dest, digest, size);
		break;
	case HASH_ENCODING_HEX_SHORT:
		orig_len = str_len(dest);
		binary_to_hex_append(dest, digest, size);
		/* drop leading zeros, except if it's the only one */
		for (i = orig_len; i < str_len(dest); i++) {
			if (str_data(dest)[i] != '0')
				break;
		}
		if (i == str_len(dest)) i--;
		str_delete(dest, orig_len, i-orig_len);
		break;
	case HASH_ENCODING_BASE64:
		orig_len = str_len(dest);
		base64_encode(digest, size, dest);
		/* drop trailing '=' chars */
		while (str_len(dest) > orig_len &&
		       str_data(dest)[str_len(dest)-1] == '=')
			str_truncate(dest, str_len(dest)-1);
		break;
	}
}
Esempio n. 3
0
void http_client_request_remove_header(struct http_client_request *req,
				       const char *key)
{
	const unsigned char *data, *p;
	size_t size, line_len, line_start_pos;
	unsigned int key_len = strlen(key);

	i_assert(req->state == HTTP_REQUEST_STATE_NEW ||
		 /* allow calling for retries */
		 req->state == HTTP_REQUEST_STATE_GOT_RESPONSE ||
		 req->state == HTTP_REQUEST_STATE_ABORTED);

	data = str_data(req->headers);
	size = str_len(req->headers);
	while ((p = memchr(data, '\n', size)) != NULL) {
		line_len = (p+1) - data;
		if (size > key_len && i_memcasecmp(data, key, key_len) == 0 &&
		    data[key_len] == ':' && data[key_len+1] == ' ') {
			/* key was found from header, replace its value */
			line_start_pos = str_len(req->headers) - size;
			str_delete(req->headers, line_start_pos, line_len);
			break;
		}
		size -= line_len;
		data += line_len;
	}
}
Esempio n. 4
0
pstr  STDCALL gettempdir( pstr name )
{
   if ( !str_len( &_gentee.tempdir ))
   {
      uint   id = 0;
      str    path;
      pstr   ps;

      ps = &_gentee.tempdir;

      os_tempdir( str_init( &path ));

      while ( 1 )
      {
         str_clear( ps );
         str_printf( ps, (pubyte)("%s%cgentee%02X.tmp"), str_ptr( &path ), SLASH, id );
         _gentee.tempfile = os_fileopen( ps, FOP_CREATE | FOP_EXCLUSIVE );

         if ( !_gentee.tempfile )
         {
            if ( id++ > 0xFFFF )
               msg( MFileopen | MSG_STR | MSG_EXIT, ps );
         }
         else
            break;
      }
      os_dircreate( str_setlen( ps, str_len( ps ) - 4 ));
      str_delete( &path );
   }
   return str_copy( name, &_gentee.tempdir );

   //return str_copy( name, os_gettemp());
}
Esempio n. 5
0
uint     STDCALL os_dirdeletefull( pstr name )
{
 #ifdef WINDOWS
   str  stemp;
   WIN32_FIND_DATA  data;
   pvoid            find;

   str_init( &stemp );
   str_printf( &stemp, "%s%c*.*", str_ptr( name ), SLASH );
   find = FindFirstFile( str_ptr( &stemp ), &data );
   if ( find != INVALID_HANDLE_VALUE )
   {
      do {
         if ( data.cFileName[0] == '.' && ( !data.cFileName[1] ||
            ( data.cFileName[1] == '.' && !data.cFileName[2] )))
            continue;

         str_printf( &stemp, "%s%c%s", str_ptr( name ), SLASH, data.cFileName );

         if ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
            os_dirdeletefull( &stemp );
         else
            os_filedelete( &stemp );

      } while ( FindNextFile( find, &data ));

      FindClose( find );
   }
   str_delete( &stemp );
 #endif
   return os_dirdelete( name );
}
Esempio n. 6
0
int __cdecl main( int argc, char *argv[] )
{
   lex ilex;
   plexitem pil;
   buf in;
   str fn;
   arr out;
   uint i;
   uint fout;

   gentee_init();
   printf("Start\n");
   str_init( &fn );

   str_copyzero( &fn, "gttbl.dat");
   fout = os_fileopen( &fn, FOP_CREATE );
   printf("Fout=%i %s\n", fout, str_ptr( &fn ));
   os_filewrite( fout, ( pubyte )&tbl_gt, 97 * sizeof( uint ));
   os_fileclose( ( pvoid )fout );

   str_copyzero( &fn, "gtdotbl.dat");
   fout = os_fileopen( &fn, FOP_CREATE );
   printf("Fout=%i %s\n", fout, str_ptr( &fn ));
   str_delete( &fn );
   os_filewrite( fout, ( pubyte )&tbl_gtdo, 81 * sizeof( uint ));
   os_fileclose( ( pvoid )fout );

   arr_init( &out, sizeof( lexitem ));
   buf_init( &in );
   buf_copyzero( &in, 
      "</r/&xfa;&#10;&#3;&#1&xfa; #ap/dfield( 'qwer ()ty' , \"my , name\" , qqq)#asdf.fgwsw/# se# &xaa;"
      "<2 qqq> </2><1 a2345=&xf0;> 223&</1><-qwe-rty->"
      "<mygt /asd = \"qwerty sese'\" qq21 = 'dedxd' 'esese;' aqaq=325623/>"
      "<a asdff /a>   <mygtdd><a /><-ooops-><ad />< qq</>"
      "xxx  </r/nm <_aa aqaqa /_aaaa /_a/_aa><a22222/ >"
      "<*abc ></abc><|*aaa = qqqq></aaa>ooops aaa</eee>\"\r\n</>");
//   buf_copyzero( &in, "<mygt > <aaa asdff>qqqq</>      </mygtdd>qq </> xxx  </r/nm <_aa aqaqa /_aaaa /_aa> <a22222/ /> </ >  ");
   printf("lex_init\n");
   lex_init( &ilex, (puint)&tbl_gtdo );
   printf("gentee_lex\n");
   gentee_lex( &in, &ilex, &out );
   if (arr_count(&ilex.state))
      printf("================= State=%x/%i \n", arr_getuint( &ilex.state,
          arr_count(&ilex.state) - 1 ), arr_count(&ilex.state));
   for ( i = 0; i < arr_count( &out ); i++ )
   {
      pil = ( plexitem )arr_ptr( &out, i );
      printf("ID=%x pos=%i len=%i \n", pil->type, pil->pos, pil->len,
             buf_ptr( &in ) + pil->pos );
   }
//   gentee_compile();
   lex_delete( &ilex );
   buf_delete( &in );
   arr_delete( &out );
   gentee_deinit();
   printf("OK\n");
   getch();
   return 0;
}
Esempio n. 7
0
void SrcFile_fini( SrcFile *self )
{
    if ( self->file != NULL )
        myfclose( self->file );

	str_delete(self->line);
    OBJ_DELETE( self->line_stack );
    OBJ_DELETE( self->file_stack );
}
Esempio n. 8
0
pstr  STDCALL gettempfile( pstr name, pstr additional )
{
   str     tempdir;

   str_init( &tempdir );
   gettempdir( &tempdir );
   str_dirfile( &tempdir, additional, name );
   str_delete( &tempdir );

   return name;
}
Esempio n. 9
0
int main(int argc, char **args)
{
	char *str = (char *) malloc(100);

	str_copy(str, "Hello World!");
	printf("%s\n", str);

	int cmp0 = str_compare("abcde", "abcde");
	int cmp1 = str_compare("abcde", "abcdf");
	int cmp2 = str_compare("abcdf", "abcde");
	int cmp3 = str_compare("abcde", "abcdef");
	int cmp4 = str_compare("abcdef", "abcde");
	printf("%d %d %d %d %d\n", cmp0, cmp1, cmp2, cmp3, cmp4);

	str_concat(str, "Hello ", "World!");
	printf("%s\n", str);

	str_sub(str, "Hello World!", 7, 2);
	printf("%s\n", str);

	int ind0 = str_index("Hello World!", "o", 0);
	int ind1 = str_index("Hello World!", "o", 5);
	printf("%d %d\n", ind0, ind1);

	str_copy(str, "Hello World!");
	str_insert(str, "My Beautiful ", 6);
	printf("%s\n", str);

	str_delete(str, 6, 3);
	printf("%s\n", str);

	str_delete(str, 6, 10);
	printf("%s\n", str);

	free(str);

	return 0;
}
void mbox_sync_move_buffer(struct mbox_sync_mail_context *ctx,
			   size_t pos, size_t need, size_t have)
{
	ssize_t diff = (ssize_t)need - (ssize_t)have;
	int i;

	i_assert(have < SSIZE_T_MAX);

	if (diff == 0) {
		if (ctx->header_last_change < pos + have ||
		    ctx->header_last_change == (size_t)-1)
			ctx->header_last_change = pos + have;
	} else {
		/* FIXME: if (diff < ctx->space && pos < ctx->offset) then
		   move the data only up to space offset and give/take the
		   space from there. update header_last_change accordingly.
		   (except pos and offset can't be compared directly) */
		ctx->header_last_change = (size_t)-1;
		for (i = 0; i < MBOX_HDR_COUNT; i++) {
			if (ctx->hdr_pos[i] > pos &&
			    ctx->hdr_pos[i] != (size_t)-1)
				ctx->hdr_pos[i] += diff;
		}

		if (ctx->mail.space > 0) {
			i_assert(ctx->mail.offset + ctx->mail.space <=
				 ctx->hdr_offset + pos ||
				 ctx->mail.offset > ctx->hdr_offset + pos + have);
			if (ctx->mail.offset > ctx->hdr_offset + pos) {
				/* free space offset moves */
				ctx->mail.offset += diff;
			}
		}

		if (diff < 0)
			str_delete(ctx->header, pos, -diff);
		else {
			ctx->header_last_change = (size_t)-1;
			buffer_copy(ctx->header, pos + diff,
				    ctx->header, pos, (size_t)-1);
		}
	}
}
Esempio n. 11
0
static int find_landmark(JSONRD_T *jsonrd, const char *chunk, size_t size) {
  int len, pos;

  len = str_len(jsonrd->buf);
  // check for previous partial matches
  if (len > 0) {
    // append up to landmark size -1 characters to the buffer
    str_append(jsonrd->buf, chunk, (size < bmstr_length(jsonrd->landmark) ? size : bmstr_length(jsonrd->landmark) - 1));
    // now look for the landmark
    pos = bmstr_substring(jsonrd->landmark, str_internal(jsonrd->buf), str_len(jsonrd->buf));
    if (pos >= 0) { //match
      pos = pos + bmstr_length(jsonrd->landmark) - len;
      jsonrd->state = PS_READ_VAR;
      return pos;
    } else { //possible partial match
      pos = -(pos + 1);
      if (pos < len) {
        // apparently the chunk wasn't large enough to actually test everything
        // in the buffer. As there's nothing more to test we'll just delete the
        // bits that definately don't match at the front of the buffer
        if (pos > 0) str_delete(jsonrd->buf, 0, pos);
        return size;
      } else {
        // possible partial match, but we don't care because we'll find it when
        // we look at the chunk
        str_clear(jsonrd->buf);
      }
    }
  }
  pos = bmstr_substring(jsonrd->landmark, chunk, size);
  if (pos >= 0) {
    pos = pos + bmstr_length(jsonrd->landmark);
    jsonrd->state = PS_READ_VAR;
    return pos;
  }
  pos = -(pos + 1);
  if (pos < size) {
    str_append(jsonrd->buf, chunk+pos, size - pos);  
  }
  return size;
}
Esempio n. 12
0
pbuf STDCALL file2buf( pstr name, pbuf ret, uint pos )
{
   str       filename;
   uint      search = 0;
   uint      handle, size;
   parrdata  pad;

   str_init( &filename );
   os_filefullname( name, &filename );

   if ( _compile && str_findch( name, SLASH ) >= str_len( name ))
   {
      search = 1;
      pad = &_compile->libdirs;
   }
again:
   handle = os_fileopen( &filename, FOP_READONLY );
   if ( !handle )
   {
      if ( search && search <= arr_count( pad ))
      {
         str_dirfile( arrdata_get( pad, search++ - 1 ), name, &filename );
         goto again;
      }
      msg( MFileopen | MSG_STR | MSG_EXIT | MSG_POS, &filename, pos );
   }
   size = ( uint )os_filesize( handle );
   buf_reserve( ret, size );

   if ( size && !os_fileread( handle, buf_ptr( ret ), size ))
      msg( MFileread | MSG_STR | MSG_EXIT | MSG_POS, &filename, pos );

   buf_setlen( ret, size );
   os_fileclose( handle );

   str_copy( name, &filename );

   str_delete( &filename );

   return ret;
}
Esempio n. 13
0
static ssize_t
o_stream_escaped_send_outbuf(struct escaped_ostream *estream)
{
	ssize_t ret;

	if (estream->flushed)
		return 1; /* nothing to send */
	ret = o_stream_send(estream->ostream.parent, str_data(estream->buf), str_len(estream->buf));
	if (ret < 0) {
		o_stream_copy_error_from_parent(&estream->ostream);
		return -1;
	}
	if ((size_t)ret != str_len(estream->buf)) {
		/* move data */
		str_delete(estream->buf, 0, ret);
		return 0;
	}
	str_truncate(estream->buf, 0);
	estream->flushed = TRUE;
	return 1;
}
Esempio n. 14
0
uint  STDCALL buf2file( pstr name, pbuf out )
{
   str       filename;
   uint      handle;

   str_init( &filename );
   os_filefullname( name, &filename );

   handle = os_fileopen( &filename, FOP_CREATE );
   if ( !handle )
      msg( MFileopen | MSG_STR | MSG_EXIT, &filename );

   if ( !os_filewrite( handle, buf_ptr( out ), buf_len( out ) ))
      msg( MFileread | MSG_STR | MSG_EXIT, &filename );

   os_fileclose( handle );

   str_copy( name, &filename );
   str_delete( &filename );

   return 1;
}
Esempio n. 15
0
int main(int argc, char **argv)
{
    FILE *pf, *pr;
    char str[100];
    char filed[100];
    char nums[100];
    strcpy(filed,argv[1]);
    strcat(filed,".js");
    pf=fopen(filed,"w");
    pr=fopen(argv[1],"r");
    fprintf(pf,"var mass =[");
    while(fgets(str,100,pr))
    {
    char** strspl= str_split(str,';');
    memset(nums,0,sizeof(nums));
    str_delete(strspl[1],nums,'\"');
    str_replace(nums,',','.');
    if(nums[0]!='0') fprintf(pf,"\n{name:%s,value:%s},",strspl[0],nums);
    }
    fprintf(pf,"\n{name:\"0\",value:0} ]");
    fclose(pf);
    fclose(pr);
	return 0;
}
Esempio n. 16
0
static void test_str_delete(void)
{
	string_t *str = t_str_new(32);

	test_begin("str_delete()");
	str_delete(str, 0, 100);
	str_append(str, "123456");
	str_delete(str, 0, 1);
	str_delete(str, 4, 1);
	str_delete(str, 1, 1);
	test_assert(str->used == 3 && memcmp(str_data(str), "245", 3) == 0);

	str_delete(str, 1, 2);
	test_assert(str->used == 1 && memcmp(str_data(str), "2", 1) == 0);

	str_append(str, "bar");
	str_delete(str, 1, 100);
	test_assert(str->used == 1 && memcmp(str_data(str), "2", 1) == 0);

	test_end();
}
Esempio n. 17
0
void editor (char *filename, int startpos)
{
    int stop    = FALSE; // exit main loop?
    int fline   = 0;     // no. of first displayed line
    int cline   = 0;     // no. of line with cursor
    int shift   = 0;     // shift to the right
    int ccol    = 0;     // column of the cursor position in the file window

    int        k, i, ndisp, rc, reply;
    char       *p, buf[1024];

    if (editor_open_file (filename) < 0) return;
    cline = min1 (startpos, nl-1);
    fline = max1 (0, cline - video_vsize()/2);

    // enter the loop
    while (1)
    {
        if (stop)
        {
            rc = 0;
            if (changed)
            {
                rc = -1;
                reply = fly_ask (0, "   Save file `%s'?   ", " Yes \n No \n Cancel ", filename);
                if (reply == 1) rc = editor_save_file (filename);
                if (reply == 2) rc = 0;
                if (reply == 3) stop = FALSE;
            }
            if (rc == 0) break;
        }
        
        ndisp = video_vsize()-1;
        // draw the screen
        for (i=0; i<ndisp; i++)
        {
            video_put_n_cell (' ', _BackWhite+_Black, video_hsize(), i, 0);
            if (i+fline < nl)
                editor_display_line (i, fline+i, shift);
        }
        video_put_n_cell (' ', _BackBlue+_White, video_hsize(), video_vsize()-1, 0);
        snprintf1 (buf, sizeof(buf), "L%d:C%d:S%d %c %s%s", cline, ccol, shift, fl_sym.v,
                 changed ? "*" : "", filename);
        video_put (buf, video_vsize()-1, 0);
        video_set_cursor (cline-fline, ccol-shift);
        video_update (0);

        // get a keyboard/mouse event and process it
        k = getmessage (-1);
        if (IS_KEY(k))
        {
            switch (k)
            {
                // Navigation keys
                
            case _Up:
            case _Down:
            case _PgUp:
            case _PgDn:
                fly_scroll_it (k, &fline, &cline, nl, video_vsize()-1);
                break;

            case _Right:
                ccol++;
                if (ccol-shift > video_hsize()-1) shift = ccol-video_hsize()+1;
                break;

            case _Left:
                ccol = max1 (ccol-1, 0);
                if (ccol < shift) shift = ccol;
                break;

            case _Home:
                ccol = 0; shift = 0;
                break;

            case _End:
                ccol = strlen(lines[cline]);
                if (ccol-shift > video_hsize()-1) shift = ccol-video_hsize()+1;
                break;

            case _CtrlHome:
                fline = 0; cline = 0; ccol = 0; shift = 0; break;

            case _CtrlEnd:
                fline = max1 (0, nl-video_vsize()+1);
                cline = min1 (fline+video_vsize()-1, nl-1);
                shift = 0;
                ccol = 0;
                break;

                // Action keys

            case _CtrlY:
                put_clipboard (lines[cline]);
                free (lines[cline]);
                for (i=cline; i<nl-1; i++)
                    lines[i] = lines[i+1];
                nl--;
                changed = TRUE;
                break;

            case _ShiftInsert:
            case _CtrlV:
                p = get_clipboard ();
                if (p == NULL || *p == '\0') break;
                if (nl == na)
                {
                    na *= 2;
                    lines = realloc (lines, sizeof(char *) * na);
                }
                for (i=nl-1; i>cline; i--)
                    lines[i+1] = lines[i];
                lines[cline+1] = p;
                ccol = 0;
                shift = 0;
                cline++;
                if (cline-fline == video_vsize()-1) fline++;
                nl++;
                changed = TRUE;
                break;

            case _BackSpace:
                if (ccol == 0)
                {
                    // ccol == 0: glue this line to the previous
                    if (cline == 0) break;
                    p = malloc (strlen (lines[cline])+strlen(lines[cline-1])+1);
                    strcpy (p, lines[cline-1]);
                    strcat (p, lines[cline]);
                    ccol = strlen (lines[cline-1]);
                    if (ccol-shift > video_hsize()-1) shift = ccol-video_hsize()+1;
                    free (lines[cline-1]);
                    free (lines[cline]);
                    lines[cline-1] = p;
                    for (i=cline; i<nl-1; i++)
                        lines[i] = lines[i+1];
                    cline--;
                    nl--;
                }
                else
                {
                    // ccol != 0: delete char at ccol-1, move cursor left
                    str_delete (lines[cline], lines[cline]+ccol-1);
                    ccol--;
                    if (ccol < shift) shift = ccol;
                }
                changed = TRUE;
                break;

            case _Enter:
                if (nl == na)
                {
                    na *= 2;
                    lines = realloc (lines, sizeof(char *) * na);
                }
                for (i=nl-1; i>cline; i--)
                    lines[i+1] = lines[i];
                if (ccol < strlen (lines[cline]))
                {
                    lines[cline+1] = strdup (lines[cline]+ccol);
                    lines[cline][ccol] = '\0';
                }
                else
                {
                    lines[cline+1] = strdup ("");
                }
                ccol = 0;
                shift = 0;
                cline++;
                if (cline-fline == video_vsize()-1) fline++;
                nl++;
                changed = TRUE;
                break;

            case _Delete:
                if (ccol >= strlen (lines[cline]))
                {
                    // glue previous line to this one
                    if (cline == nl-1) break;
                    p = malloc (ccol+strlen(lines[cline+1])+1);
                    strcpy (p, lines[cline]);
                    memset (p+strlen(lines[cline]), ' ', ccol-strlen(lines[cline]));
                    strcpy (p+ccol, lines[cline+1]);
                    free (lines[cline]);
                    free (lines[cline+1]);
                    lines[cline] = p;
                    for (i=cline+1; i<nl-1; i++)
                        lines[i] = lines[i+1];
                    nl--;
                }
                else
                {
                    // ccol != 0: delete char at ccol-1, move cursor left
                    str_delete (lines[cline], lines[cline]+ccol);
                }
                changed = TRUE;
                break;

            case _F2:
                rc = editor_save_file (filename);
                if (rc == 0) changed = FALSE;
                break;
                
            case _Esc:
            case _F10:
                stop = TRUE; break;

                // character keys
                
            default:
                if (k >= ' ' && k <= 255)
                {
                    str_insert_at (cline, k, ccol);
                    ccol++;
                    changed = TRUE;
                }
            }
        }
        else if (IS_MOUSE(k))
        {
        }
        else if (IS_SYSTEM(k))
        {
            switch (SYS_TYPE(k))
            {
            case SYSTEM_QUIT:
                stop = TRUE; break;
            }
        }
    }

    if (nl != 0 && lines != NULL)
        for (i=0; i<nl; i++)
            free (lines[i]);
    if (na != 0 && lines != NULL) free (lines);
    na = 0;
    lines = NULL;
}
Esempio n. 18
0
uint STDCALL ge_save( pvmEngine pThis, char* fileName, char* isSave)
{
    gehead   head;
    pgehead  phead;
    uint     i, ii, count;
    pvmobj   pvmo;
    buf       out;
    str  filename;
    if ( setjmp( pThis->stack_state) == -1 ) 
        return 0;

    str_init( pThis, &filename );
    str_copyzero( pThis, &filename, fileName );
    buf_init( pThis, &out );

    pThis->gesave = &out;
    buf_reserve( pThis, &out, 0x1ffff );

   *( puint )&head.idname = GE_STRING;//0x00004547;   // строка GE
   head.flags = 0;
   head.crc = 0;
   head.headsize = sizeof( gehead );
   head.size = 0;
   head.vermajor = GEVER_MAJOR; 
   head.verminor = GEVER_MINOR; 
   
   buf_append( pThis, &out, ( pubyte )&head, sizeof( gehead ));
   // Save resources at the first !
   gesave_resource(pThis);

   count = arr_count( pThis, &pThis->_vm.objtbl );
   for ( i = KERNEL_COUNT; i < count ; i++ )
   {
      if(isSave && isSave[i] == 0)
      {
         /* gesave_addubyte( pThis, OVM_NONE );
          gesave_adduint( pThis, GHCOM_PACK);
          gesave_bwd( pThis, 6 );*/
          pThis->popravka ++;
          continue;
      }

      pvmo = ( pvmobj )PCMD( i );
      pvmo->id -= pThis->popravka;
      //@init @delete @array @oftype @index -не удалять имена
      if(pThis->isDelName&&(pvmo->flag&GHCOM_NAME)&&pvmo->name&&lstrcmpA("@init",pvmo->name)&&
          lstrcmpA("@delete",pvmo->name)&&lstrcmpA("@array",pvmo->name)&&
          lstrcmpA("@oftype",pvmo->name)&&lstrcmpA("@index",pvmo->name))
      {
          pvmo->flag &= ~GHCOM_NAME;
      }else
          if(pvmo->name)
             pvmo->flag |= ~GHCOM_NAME;

      gesave_head( pThis, pvmo->type, pvmo->flag & GHCOM_NAME ? 
          pvmo->name : NULL, pvmo->flag );
      
      switch ( pvmo->type )
      {
         case OVM_NONE:
            break;
         case OVM_BYTECODE:
            gesave_bytecode( pThis, ( povmbcode )pvmo );
            break;
         case OVM_EXFUNC:
            ((povmfunc)pvmo)->import = ((pvmobj)PCMD(((povmfunc)pvmo)->import))->id;
            gesave_exfunc( pThis, ( povmfunc )pvmo );
            break;
         case OVM_TYPE:
             {
                for(ii = 0; ii<((povmtype)pvmo)->count; ii++)
                {
                    if(pThis->isDelName)
                        ((povmtype)pvmo)->children[ii].flag &=~GHCOM_NAME;
                    else if(((povmtype)pvmo)->children[ii].name)
                        ((povmtype)pvmo)->children[ii].flag |=GHCOM_NAME;
                }
                gesave_type( pThis, ( povmtype )pvmo );
             }break;
         case OVM_GLOBAL:
            gesave_var( pThis, (( povmglobal )pvmo)->type );
            break;
         case OVM_DEFINE:
            gesave_define( pThis, ( povmdefine )pvmo );
            break;
         case OVM_IMPORT:
            gesave_import( pThis, ( povmimport )pvmo );
            break;
         case OVM_ALIAS:
            gesave_bwd( pThis, (( povmalias )pvmo)->idlink );
            break;
      }
      gesave_finish(pThis);
   }
   // Specify the full size and crc
   phead = ( pgehead )buf_ptr( pThis, &out );
   phead->size = buf_len( pThis, &out );
   phead->crc = crc( pThis, ( pubyte )phead + 12, phead->size - 12, 0xFFFFFFFF );
   buf2file( pThis, &filename, &out );
   buf_delete( pThis, &out );
   str_delete( pThis, &filename );
   return 1;
}
Esempio n. 19
0
int test_str(void)
{
	STR_DEFINE( s3, 10 );
	Str *s4, *s5;
	STR_DEFINE(s6, 10);
	STR_DEFINE(s7, 10);

	dump_str( s1, "s1" );
	dump_str( s2, "s2" );
	dump_str( s3, "s3" );

	/* check static strings keep their value */
	mu_assert_str( static_str(4),  ==, "4" );
	mu_assert_str( static_str(-1), ==, "4" );
	mu_assert_str( static_str(-1), ==, "4" );

	mu_assert_str( static_str(7),  ==, "7" );
	mu_assert_str( static_str(-1), ==, "7" );
	mu_assert_str( static_str(-1), ==, "7" );

	T_STR(s4, s4 = str_new(6));		/* alloc, keep memory leak */

	T_STR(s5, s5 = str_new(6));
	
	/* expand */
	T_STR(s3, str_clear(s3));
	T_STR(s3, str_reserve(s3, 9));
	T_STR(s3, str_reserve(s3, 10));
	T_STR(s3, str_reserve(s3, 11));
	T_STR(s3, str_clear(s3));

	/* char */
	T_STR(s4, str_set(s4, "xxxx"));
	T_STR(s4, str_set_char(s4, 0));
	T_STR(s4, str_append_char(s4, 1));
	T_STR(s4, str_append_char(s4, 2));
	T_STR(s4, str_append_char(s4, 3));
	T_STR(s4, str_append_char(s4, 4));
	T_STR(s4, str_append_char(s4, 5));
	T_STR(s4, str_append_char(s4, 6));
	T_STR(s4, str_append_char(s4, 7));
	T_STR(s4, str_append_char(s4, 8));
	T_STR(s4, str_append_char(s4, 9));
	T_STR(s4, str_append_char(s4, 10));
	T_STR(s4, str_clear(s4));

	/* string */
	T_STR(s5, str_set(s5, "1234"));
	T_STR(s5, str_append(s5, "56789"));
	T_STR(s5, str_append(s5, "0"));
	T_STR(s5, str_clear(s5));

	/* substring */
	T_STR(s5, str_set_n(s5, "1234xx", 4));
	T_STR(s5, str_append_n(s5, "56789xx", 5));
	T_STR(s5, str_append_n(s5, "01234567890xx", 11));
	T_STR(s5, str_clear(s5));

	/* bytes */
	T_STR(s5, str_set_bytes(s5, "\0\1\2\3x", 3));
	T_STR(s5, str_append_bytes(s5, "\4\5\6x", 3));
	T_STR(s5, str_clear(s5));

	/* sprintf - test repeated call to vsprintf when buffer grows, needs va_copy in MacOS */
	T_STR(s6, str_set(s6, "xxxx"));
	T_STR(s6, str_sprintf(s6, "%s %d", "hello", 123));
	T_STR(s6, str_sprintf(s6, "%s %d", "hello", 1234));
	T_STR(s6, str_append_sprintf(s6, "%s %d", "hello", 12345));
	T_STR(s6, str_clear(s6));

	/* vsprintf - test repeated call to vsprintf when buffer grows, needs va_copy in MacOS */
	T_STR(s7, str_set(s7, "xxxx"));
	T_STR(s7, call_vsprintf(s7, "%s %d", "hello", 123));
	T_STR(s7, call_vsprintf(s7, "%s %d", "hello", 1234));
	T_STR(s7, call_append_vsprintf(s7, "%s %d", "hello", 12345));
	T_STR(s7, str_clear(s7));

	str_delete(s5);
	mu_assert_ptr_null(s5);

	STR_DELETE(s3);
	mu_assert_ptr_null(s3);

	STR_DELETE(s6);
	mu_assert_ptr_null(s6);

	STR_DELETE(s7);
	mu_assert_ptr_null(s7);

	return MU_PASS;
}
Esempio n. 20
0
DEFINE_dtor_module()
{
	str_delete(input_buf);
	OBJ_DELETE(input_stack);
	utarray_free(scan_state);
}
Esempio n. 21
0
void  STDCALL str_destroy( pstr ps )
{
   str_delete( ps );
   mem_free( ps );
}
Esempio n. 22
0
File: corb.c Progetto: marcom/corb
int main(int argc,char *argv[])
{
   Str* tool = NULL;
   struct gengetopt_args_info crb_args;
   int retval = 0;

   if (set_progname ("corb"))
   {
      return EXIT_FAILURE;
   }

   crb_cmdline_parser_init (&crb_args);
   retval = crb_cmdline_parser (argc, argv, &crb_args);
   
   if (retval == 0)
   {
      retval = crb_cmdline_parser_required(&crb_args, get_progname());
   }   

   /* post-process parsed options */
   if (crb_args.inputs_num != 1)
   {
      THROW_ERROR_MSG ("Exactly one application string is needed, try "
                       "`%s --help` for more information.",
                       get_progname());
      retval = 1;
   }

   /* parse toolname from command string */
   if (retval == 0)
   {
      tool = parse_toolname (crb_args.inputs[0]);
      if (tool == NULL)
      {
         THROW_ERROR_MSG ("No application name found in string provided: "
                          "\"%s\", try %s --help` for more information.",
                          crb_args.inputs[0], get_progname());
         retval = 1;
      }
   }

   /* inspect tool chosen */
   if (retval == 0)
   {
      retval = verify_tool (tool);
   }

   if (retval == 0)
   {
      retval = add_name_2_progname (str_get (tool));
   }

   /* start tool */
   if (retval == 0)
   {
      if (str_compare_cstr (tool, "brot") == 0)
      {
         retval = brot_main(crb_args.inputs[0]/*  + str_length (tool) */);
      }
      else if (str_compare_cstr (tool, "fold") == 0)
      {
         retval = fold_main(crb_args.inputs[0]);
      }
      else if (str_compare_cstr (tool, "er2de") == 0)
      {
         retval = er2de_main(crb_args.inputs[0]);
      }      
   }

   /* finalise */
   crb_cmdline_parser_free (&crb_args);
   str_delete (tool);
   free_progname();
   FREE_MEMORY_MANAGER;

   if (retval == 0)
   {
      return EXIT_SUCCESS;
   }
   else
   {
      return EXIT_FAILURE;
   }
}