struct llmne_instr* getMacroInstr( int nline, int *size, int arg, char** args ) { char* line = xmalloc( 256 ); struct llmne_instr* instr = xmalloc(sizeof(struct llmne_instr)); TokenCtx in; int i; char* tmp, *rep; *size = 0; tmp = xmalloc( 10 ); memset( tmp, 0, 10 ); while(fgets(line, 256, i_stream)) { if(!strncmp( line, "@ENDM", 4 )) break; line[strlen(line)-1] = '\0'; if(strchr(line, '#')) *((char*)strchr(line, '#')) = 0; /* if( line[0] == '%' ) die("* Syntax error, couldn't use recursive macro at line %d.\n",nline); */ line++; for(i = 0;i < arg;i++) { memset( tmp, 0, strlen(tmp) ); sprintf(tmp, "$%d", i ); if(strstr(line, tmp)) { rep = strreplace( line , tmp, args[i] ); line = strdup(rep); } } TokenParse( &in, line ); instr = realloc( instr, ++*size * sizeof(struct llmne_instr)); instr[*size - 1] = InstrParse( &in ); } return instr; }
int main(int argc,char *argv[]) { int i; char* line; TokenCtx ctx; struct hgame_rc * rc = malloc(sizeof(struct hgame_rc)); char* home = getenv("HOME"); char * hash = malloc(16); pthread_t thread; signal(SIGINT,sighandler); signal(SIGSEGV,sighandler); if(argv[1] && (!strcmp(argv[1],"-v") || !strcmp(argv[1],"-V") || !strcmp(argv[1],"--version"))) { printf("%s",VERSION_TEXT); return 0; } rc_path = malloc(26 + strlen(home)); sprintf(rc_path,"%s/.hgame/.hgamerc",home); if(!access(rc_path,F_OK)) { rc = getResource(rc_path); printf("[%s] password: "******""); MD5((unsigned char*)line,strlen(line),(unsigned char*)hash); if(strcmp(hash,rc->pass)) die("Incorrect password, try again.\n"); } else { char* pass; printf("W0W, it is your first access...Well, we start...\n"); printf("Your real name: "); rc->name = malloc(20); i = scanf("%20s",rc->name); rc->money = rc->level = rc->mode = 0; printf("Username: "******"%10s",rc->user); pass = getpass("Password:"******"OS name: "); rc->os = malloc(20); i = scanf("%20s",rc->os); printf("Hostname: "); rc->hostname = malloc(20); i = scanf("%20s",rc->hostname); rc->kernel = strdup(DEF_KERNEL); rcSave(rc,rc_path); getchar(); } hgame_main.connected = hgame_main.pc.net.conn = hgame_main.program_c = hgame_main.device_c = hgame_main.host_c = 0; setHgameResource(rc); callbacks[ON_INIT](NULL); load_programs(); pthread_create(&thread,NULL,(void* (*)(void*))callbacks[ON_NEWMAIL],NULL); KnownHostparse(); while(1) { line = getline(PROMPT,rc->user,rc->hostname); if(!line || line[0] == '\0') continue; fflush(stdin); add_history(line); TokenParse(&ctx,line); if(!strcmp(ctx.args[0],"exit")) { callbacks[ON_EXIT]((struct hgame_data*)rc); exit(0); } LineParse(&ctx); for(i = 0;i < ctx.argc;i++) free(ctx.args[i]); free(ctx.args); free(line); } return 0; }