ArchWizard

DGD/

source navigation ]
diff markup ]
identifier search ]
file search ]
Version: [ 1.0.a0 ] [ 1.1 ] [ 1.2 ] [ 1.2p1 ] [ 1.2p2 ] [ 1.2p3 ] [ 1.2p4 ] [ 1.2.151 ]

  1 # include "dgd.h"
  2 # include "str.h"
  3 # include "array.h"
  4 # include "object.h"
  5 # include "xfloat.h"
  6 # include "interpret.h"
  7 # include "data.h"
  8 # include "path.h"
  9 # include "node.h"
 10 # include "compile.h"
 11 
 12 /*
 13  * NAME:        path->resolve()
 14  * DESCRIPTION: resolve a path
 15  */
 16 char *path_resolve(buf, file)
 17 char *buf, *file;
 18 {
 19     register char *p, *q, *d;
 20 
 21     strncpy(buf, file, STRINGSZ - 1);
 22     buf[STRINGSZ - 1] = '\0';
 23     d = p = q = buf;
 24     for (;;) {
 25         if (*p == '/' || *p == '\0') {
 26             /* reached a directory separator */
 27             if (q - 1 == d && d[0] == '.') {
 28                 /* . */
 29                 q = d;
 30             } else if (q - 2 == d && d[0] == '.' && d[1] == '.') {
 31                 /* .. */
 32                 q = d;
 33                 if (q != buf) {
 34                     for (--q; q != buf && *--q != '/'; ) ;
 35                 }
 36             }
 37             if (q != buf) {
 38                 if (q[-1] == '/') {
 39                     /* // or path/ */
 40                     --q;
 41                 }
 42                 *q++ = *p;
 43             }
 44             d = q;
 45             if (*p == '\0') {
 46                 break;
 47             }
 48             p++;
 49         } else {
 50             *q++ = *p++;
 51         }
 52     }
 53 
 54     if (q == buf) {
 55         /* "" -> "." */
 56         *q++ = '.';
 57         *q = '\0';
 58     }
 59     return buf;
 60 }
 61 
 62 /*
 63  * NAME:        path_string()
 64  * DESCRIPTION: check and resolve a string path
 65  */
 66 char *path_string(buf, file, len)
 67 char *buf, *file;
 68 unsigned int len;
 69 {
 70     if (len >= STRINGSZ || strlen(file) != len) {
 71         return (char *) NULL;
 72     }
 73     return path_resolve(buf, file);
 74 }
 75 
 76 /*
 77  * NAME:        path->from()
 78  * DESCRIPTION: resolve a (possibly relative) path
 79  */
 80 char *path_from(buf, from, file)
 81 register char *buf, *from, *file;
 82 {
 83     char buf2[STRINGSZ];
 84 
 85     if (file[0] != '/' && strlen(from) + strlen(file) < STRINGSZ - 4) {
 86         sprintf(buf2, "%s/../%s", from, file);
 87         file = buf2;
 88     }
 89     return path_resolve(buf, file);
 90 }
 91 
 92 /*
 93  * NAME:        path->ed_read()
 94  * DESCRIPTION: resolve an editor read file path
 95  */
 96 char *path_ed_read(buf, file)
 97 char *buf, *file;
 98 {
 99     register frame *f;
100 
101     f = cframe;
102     if (OBJR(f->oindex)->flags & O_DRIVER) {
103         return path_resolve(buf, file);
104     } else {
105         PUSH_STRVAL(f, str_new(file, (long) strlen(file)));
106         call_driver_object(f, "path_read", 1);
107         if (f->sp->type != T_STRING) {
108             i_del_value(f->sp++);
109             return (char *) NULL;
110         }
111         path_resolve(buf, f->sp->u.string->text);
112         str_del((f->sp++)->u.string);
113         return buf;
114     }
115 }
116 
117 /*
118  * NAME:        path->ed_write()
119  * DESCRIPTION: resolve an editor write file path
120  */
121 char *path_ed_write(buf, file)
122 char *buf, *file;
123 {
124     register frame *f;
125 
126     f = cframe;
127     if (OBJR(f->oindex)->flags & O_DRIVER) {
128         return path_resolve(buf, file);
129     } else {
130         PUSH_STRVAL(f, str_new(file, (long) strlen(file)));
131         call_driver_object(f, "path_write", 1);
132         if (f->sp->type != T_STRING) {
133             i_del_value(f->sp++);
134             return (char *) NULL;
135         }
136         path_resolve(buf, f->sp->u.string->text);
137         str_del((f->sp++)->u.string);
138         return buf;
139     }
140 }
141 
142 /*
143  * NAME:        path->include()
144  * DESCRIPTION: resolve an include path
145  */
146 char *path_include(buf, from, file)
147 char *buf, *from, *file;
148 {
149     register frame *f;
150 
151     if (c_autodriver()) {
152         return path_from(buf, from, file);
153     }
154     f = cframe;
155     PUSH_STRVAL(f, str_new((char *) NULL, strlen(from) + 1L));
156     f->sp->u.string->text[0] = '/';
157     strcpy(f->sp->u.string->text + 1, from);
158     PUSH_STRVAL(f, str_new(file, (long) strlen(file)));
159     if (!call_driver_object(f, "path_include", 2)) {
160         f->sp++;
161         return path_from(buf, from, file);
162     }
163     if (f->sp->type != T_STRING) {
164         i_del_value(f->sp++);
165         return (char *) NULL;
166     }
167     path_resolve(buf, f->sp->u.string->text);
168     str_del((f->sp++)->u.string);
169     return buf;
170 }
171 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.