📄 atom.cc
字号:
//#include "null.h"#include "atom.h"#include "context.h"#include <stdlib.h> // NULL//#define row_this_cx cursors[ x * cursor + y ]atom::~atom(){}atom::atom( atom& that ): parent( that.parent ), cx( that.cx ), id_mask( that.id_mask ){}atom::atom( atom* _parent ): parent( _parent ){ cx = NULL;}#include "line.h" // line, line_s#include "script.h" // script#include <math.h> // log10#include <string.h> // strcat, strlen#include <stdio.h> // snprintfchar* atom::ptrtocx( atom* object ){ switch( object -> id_mask ) { case ID_MAIN: // already at root { char* name = new char[ 1 ]; name[ 0 ] = '\0'; return name; } break; case ID_LINE: case ID_LINE_S: { char* _name,* pname = ptrtocx( object -> parent ); int size; if( object -> cx == NULL ) { register line* here = ( line* )object; register int it = 0; line* done = ( ( script* )( object -> parent ) ) -> top; for(; here != done; here = here -> last, ++it ); int size; if( it == 0 ) size = 1; else size = ( int )log10( it ) + 1; _name = new char[ size + 1 + strlen( pname ) ]; snprintf( _name, size + 1, "%d", it ); } else { int size = strlen( object -> cx -> name ); _name = new char[ size + 1 + strlen( pname ) ]; strcpy( _name, object -> cx -> name ); } if( pname[ 0 ] != '\0' ) // root { strcat( _name, "." ); strcat( _name, pname ); } delete pname; return _name; } break; case ID_SCRIPT: { char* pname = ptrtocx( object -> parent ); if( object -> parent -> id_mask == ID_LINE_S ) return pname; char* name = new char[ 15 ]; strcpy( name, "unknown script" ); return name; } break; case ID_SCRIPT_DIR: { char* name,* pname; //if( object -> parent -> parent -> id_mask == ID_SCRIPT_DIR ) pname = ptrtocx( object -> parent -> parent ); int size;/* if( object -> cx == NULL ) { context* target = object -> parent -> cx; line* here = ( ( script* )object ) -> top; register int it = 0; for(; here != NULL; here = here -> next, ++it ) { if( here -> id_mask != ID_LINE_S ) continue; if( ( ( line_s* )here ) -> scr == object ) break; } int size; if( it == 0 ) size = 1; else size = ( int )log10( it ) + 1; name = new char[ size + 1 + strlen( pname ) ]; snprintf( name, size + 1, "%d", it ); }*/ if( object -> cx == NULL ) { int size = strlen( ( ( line* )( object -> parent ) ) -> text ); name = new char[ size + 1 + strlen( pname ) ]; strcpy( name, ( ( line_s* )( object -> parent ) ) -> text ); char* _c = strchr( name, '.' ); if( _c ) *_c = '\0'; } else { int size = strlen( object -> cx -> name ); name = new char[ size + 1 + strlen( pname ) ]; strcpy( name, object -> cx -> name ); } if( pname[ 0 ] != '\0' ) // root { strcat( name, "." ); strcat( name, pname ); } delete pname; return name; } break; }}struct cx_item{ char* name; struct cx_item* up;};atom* cx_item_to_atom( cx_item* cx_list, atom* a ){ context* here = a -> cx -> first; for(; here != NULL; here = here -> next ) { if( strcmp( cx_list -> name, here -> name ) == 0 ) break; } if( here != NULL ) { return here -> a; } line* lx = NULL; switch( a -> id_mask ) { case ID_LINE: { return NULL; // nothing below here (or try line attributes) } break; case ID_LINE_S: lx = ( ( line_s* )lx ) -> scr -> top; case ID_SCRIPT: { int num = strtol( cx_list -> name, NULL, 10 ); if( lx == NULL ) lx = ( ( script* )a ) -> top; register int it = 0; for(; lx != NULL && it < num; lx = lx -> next, ++it ); if( lx != NULL ) { return lx; } else return NULL; // expired } break; };}atom* cxtoptr( char* context, script* top ){ char* local,* name = strtok_r( context, ".", &local ); cx_item* cx_list = NULL; do // this is backwards { cx_item* temp = new cx_item; temp -> name = name; temp -> up = cx_list; cx_list = temp; name = strtok_r( NULL, ".", &local ); } while( name != NULL ); atom* a = top; while( cx_list != NULL ) { a = cx_item_to_atom( cx_list, a ); if( top == NULL ) return NULL; // didn't work cx_item* temp = cx_list; cx_list = temp -> up; delete temp; } return a;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -