157694Sbostic /*- 257694Sbostic * Copyright (c) 1992 The Regents of the University of California. 357694Sbostic * All rights reserved. 457694Sbostic * 557694Sbostic * This code is derived from software contributed to Berkeley by 657694Sbostic * Rodney Ruddock of the University of Guelph. 757694Sbostic * 857694Sbostic * %sccs.include.redist.c% 957694Sbostic */ 1057694Sbostic 1157694Sbostic #ifndef lint 12*58315Sbostic static char sccsid[] = "@(#)m.c 5.3 (Berkeley) 02/28/93"; 1357694Sbostic #endif /* not lint */ 1457694Sbostic 1557710Sbostic #include <sys/types.h> 1657710Sbostic 1757710Sbostic #include <regex.h> 1857710Sbostic #include <setjmp.h> 1957710Sbostic #include <stdio.h> 2057710Sbostic #include <string.h> 2157710Sbostic 22*58315Sbostic #ifdef DBI 23*58315Sbostic #include <db.h> 24*58315Sbostic #endif 25*58315Sbostic 2657694Sbostic #include "ed.h" 2757710Sbostic #include "extern.h" 2857694Sbostic 2957694Sbostic /* 3057694Sbostic * Move the specified lines to the new location. It's quick 'cause 3157694Sbostic * just a couple of pointers are redirected. 3257694Sbostic */ 3357694Sbostic void 3457694Sbostic m(inputt, errnum) 3557710Sbostic FILE *inputt; 3657710Sbostic int *errnum; 3757694Sbostic { 38*58315Sbostic LINE *l_dest=NULL, *l_old_top, *l_old_bottom; 3957694Sbostic 4057710Sbostic /* Set l_dest here. */ 4157710Sbostic if (((ss = getc(inputt)) != '\n') && (ss != EOF)) { 4257710Sbostic for (;;) { 4357710Sbostic if (ss != ' ') { 4457710Sbostic ungetc(ss, inputt); 4557710Sbostic break; 4657710Sbostic } 4757710Sbostic ss = getc(inputt); 4857710Sbostic } 4957710Sbostic l_dest = address_conv(NULL, inputt, errnum); 5057710Sbostic } else 5157710Sbostic (ungetc(ss, inputt), *errnum = -1); 5257710Sbostic if (*errnum < 0) { 5357710Sbostic strcpy(help_msg, "bad destination address"); 5457710Sbostic return; 5557710Sbostic } 5657710Sbostic *errnum = 0; 5757710Sbostic if (rol(inputt, errnum)) 5857710Sbostic return; 5957694Sbostic 6057710Sbostic if (start_default && End_default) 6157710Sbostic start = End = current; 6257710Sbostic else 6357710Sbostic if (start_default) 6457710Sbostic start = End; 6557710Sbostic if (start == NULL) { 66*58315Sbostic strcpy(help_msg, "buffer empty"); 6757710Sbostic *errnum = -1; 6857710Sbostic return; 6957710Sbostic } 7057710Sbostic start_default = End_default = 0; 7157694Sbostic 7257710Sbostic /* Do some address checking. */ 7357710Sbostic if ((l_dest) && ((l_dest == start) || 7457710Sbostic (address_check(l_dest, start) == -1)) && 7557710Sbostic (address_check(End, l_dest) == -1)) { 7657710Sbostic ungetc(ss, inputt); 7757710Sbostic *errnum = -1; 7857710Sbostic strcpy(help_msg, "destination address in address range"); 7957710Sbostic return; 8057710Sbostic } 8157710Sbostic change_flag = 1; 8257710Sbostic if (g_flag == 0) 8357710Sbostic u_clr_stk(); 8457694Sbostic 8557710Sbostic /* 8657710Sbostic * Some more address checking. These are "legal" command constructions 8757710Sbostic * but are kind-a useless since the buffer doesn't change. 8857710Sbostic */ 89*58315Sbostic *errnum = 1; 9057710Sbostic if ((start == l_dest) || (End == l_dest)) 9157710Sbostic return; 9257710Sbostic if ((start == top) && (End == bottom)) 9357710Sbostic return; 9457710Sbostic if ((start == top) && (l_dest == NULL)) 9557710Sbostic return; 96*58315Sbostic *errnum = 0; 9757694Sbostic 9857710Sbostic l_old_top = top; 9957710Sbostic l_old_bottom = bottom; 10057694Sbostic 101*58315Sbostic sigspecial++; 102*58315Sbostic 10357710Sbostic if (start == top) { 10457710Sbostic top = End->below; 10557710Sbostic u_add_stk(&(End->below->above)); 10657710Sbostic top->above = NULL; 10757710Sbostic } else 10857710Sbostic if (End == bottom) { 10957710Sbostic bottom = start->above; 11057710Sbostic u_add_stk(&(start->above->below)); 11157710Sbostic bottom->below = NULL; 11257710Sbostic } else { 11357710Sbostic u_add_stk(&(start->above->below)); 11457710Sbostic start->above->below = End->below; 11557710Sbostic u_add_stk(&(End->below->above)); 11657710Sbostic End->below->above = start->above; 11757710Sbostic } 11857694Sbostic 11957710Sbostic if (l_dest == NULL) { 12057710Sbostic u_add_stk(&(start->above)); 12157710Sbostic start->above = NULL; 12257710Sbostic u_add_stk(&(End->below)); 12357710Sbostic End->below = l_old_top; 12457710Sbostic u_add_stk(&(l_old_top->above)); 12557710Sbostic l_old_top->above = End; 12657710Sbostic top = start; 12757710Sbostic } else 12857710Sbostic if (l_dest == l_old_bottom) { 12957710Sbostic u_add_stk(&(End->below)); 13057710Sbostic End->below = NULL; 13157710Sbostic u_add_stk(&(start->above)); 13257710Sbostic start->above = l_dest; 13357710Sbostic u_add_stk(&(l_dest->below)); 13457710Sbostic l_dest->below = start; 13557710Sbostic bottom = End; 13657710Sbostic } else { 13757710Sbostic u_add_stk(&(start->above)); 13857710Sbostic start->above = l_dest; 13957710Sbostic u_add_stk(&(End->below)); 14057710Sbostic End->below = l_dest->below; 14157710Sbostic u_add_stk(&(l_dest->below->above)); 14257710Sbostic l_dest->below->above = End; 14357710Sbostic u_add_stk(&(l_dest->below)); 14457710Sbostic l_dest->below = start; 14557710Sbostic } 14657694Sbostic 14757710Sbostic if (l_dest) 14857710Sbostic l_dest->below = start; 14957710Sbostic current = start; 15057694Sbostic 151*58315Sbostic sigspecial--; 152*58315Sbostic 15357710Sbostic *errnum = 1; 15457710Sbostic } 155